fix nasty names
This commit is contained in:
@@ -8,7 +8,7 @@ import (
|
|||||||
"lukechampine.com/frand"
|
"lukechampine.com/frand"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestUint16Codec(t *testing.T) {
|
func TestUint16(t *testing.T) {
|
||||||
// Helper function to generate random 16-bit integers
|
// Helper function to generate random 16-bit integers
|
||||||
generateRandomUint16 := func() uint16 {
|
generateRandomUint16 := func() uint16 {
|
||||||
return uint16(frand.Intn(math.MaxUint16)) // math.MaxUint16 == 65535
|
return uint16(frand.Intn(math.MaxUint16)) // math.MaxUint16 == 65535
|
||||||
|
|||||||
@@ -8,14 +8,14 @@ import (
|
|||||||
// MaxUint24 is the maximum value of a 24-bit unsigned integer: 2^24 - 1.
|
// MaxUint24 is the maximum value of a 24-bit unsigned integer: 2^24 - 1.
|
||||||
const MaxUint24 uint32 = 1<<24 - 1
|
const MaxUint24 uint32 = 1<<24 - 1
|
||||||
|
|
||||||
// Uint24Codec is a codec for encoding and decoding 24-bit unsigned integers.
|
// Uint24 is a codec for encoding and decoding 24-bit unsigned integers.
|
||||||
type Uint24Codec struct {
|
type Uint24 struct {
|
||||||
value uint32
|
value uint32
|
||||||
}
|
}
|
||||||
|
|
||||||
// SetUint24 sets the value as a 24-bit unsigned integer.
|
// SetUint24 sets the value as a 24-bit unsigned integer.
|
||||||
// If the value exceeds the maximum allowable value for 24 bits, it returns an error.
|
// If the value exceeds the maximum allowable value for 24 bits, it returns an error.
|
||||||
func (c *Uint24Codec) SetUint24(value uint32) error {
|
func (c *Uint24) SetUint24(value uint32) error {
|
||||||
if value > MaxUint24 {
|
if value > MaxUint24 {
|
||||||
return errors.New("value exceeds 24-bit range")
|
return errors.New("value exceeds 24-bit range")
|
||||||
}
|
}
|
||||||
@@ -24,13 +24,13 @@ func (c *Uint24Codec) SetUint24(value uint32) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Uint24 gets the value as a 24-bit unsigned integer.
|
// Uint24 gets the value as a 24-bit unsigned integer.
|
||||||
func (c *Uint24Codec) Uint24() uint32 {
|
func (c *Uint24) Uint24() uint32 {
|
||||||
return c.value
|
return c.value
|
||||||
}
|
}
|
||||||
|
|
||||||
// SetInt sets the value as an int, converting it to a 24-bit unsigned integer.
|
// SetInt sets the value as an int, converting it to a 24-bit unsigned integer.
|
||||||
// If the value is out of the 24-bit range, it returns an error.
|
// If the value is out of the 24-bit range, it returns an error.
|
||||||
func (c *Uint24Codec) SetInt(value int) error {
|
func (c *Uint24) SetInt(value int) error {
|
||||||
if value < 0 || uint32(value) > MaxUint24 {
|
if value < 0 || uint32(value) > MaxUint24 {
|
||||||
return errors.New("value exceeds 24-bit range")
|
return errors.New("value exceeds 24-bit range")
|
||||||
}
|
}
|
||||||
@@ -39,13 +39,13 @@ func (c *Uint24Codec) SetInt(value int) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Int gets the value as an int, converted from the 24-bit unsigned integer.
|
// Int gets the value as an int, converted from the 24-bit unsigned integer.
|
||||||
func (c *Uint24Codec) Int() int {
|
func (c *Uint24) Int() int {
|
||||||
return int(c.value)
|
return int(c.value)
|
||||||
}
|
}
|
||||||
|
|
||||||
// MarshalWrite encodes the 24-bit unsigned integer and writes it directly to the provided io.Writer.
|
// MarshalWrite encodes the 24-bit unsigned integer and writes it directly to the provided io.Writer.
|
||||||
// The encoding uses 3 bytes in BigEndian order.
|
// The encoding uses 3 bytes in BigEndian order.
|
||||||
func (c *Uint24Codec) MarshalWrite(w io.Writer) error {
|
func (c *Uint24) MarshalWrite(w io.Writer) error {
|
||||||
if c.value > MaxUint24 {
|
if c.value > MaxUint24 {
|
||||||
return errors.New("value exceeds 24-bit range")
|
return errors.New("value exceeds 24-bit range")
|
||||||
}
|
}
|
||||||
@@ -61,7 +61,7 @@ func (c *Uint24Codec) MarshalWrite(w io.Writer) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// UnmarshalRead reads 3 bytes directly from the provided io.Reader and decodes it into a 24-bit unsigned integer.
|
// UnmarshalRead reads 3 bytes directly from the provided io.Reader and decodes it into a 24-bit unsigned integer.
|
||||||
func (c *Uint24Codec) UnmarshalRead(r io.Reader) error {
|
func (c *Uint24) UnmarshalRead(r io.Reader) error {
|
||||||
// Read 3 bytes directly from the reader
|
// Read 3 bytes directly from the reader
|
||||||
var buf [3]byte
|
var buf [3]byte
|
||||||
_, err := io.ReadFull(r, buf[:]) // Ensure exactly 3 bytes are read
|
_, err := io.ReadFull(r, buf[:]) // Ensure exactly 3 bytes are read
|
||||||
|
|||||||
@@ -5,7 +5,7 @@ import (
|
|||||||
"testing"
|
"testing"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestUint24Codec(t *testing.T) {
|
func TestUint24(t *testing.T) {
|
||||||
tests := []struct {
|
tests := []struct {
|
||||||
name string
|
name string
|
||||||
value uint32
|
value uint32
|
||||||
@@ -19,7 +19,7 @@ func TestUint24Codec(t *testing.T) {
|
|||||||
|
|
||||||
for _, tt := range tests {
|
for _, tt := range tests {
|
||||||
t.Run(tt.name, func(t *testing.T) {
|
t.Run(tt.name, func(t *testing.T) {
|
||||||
codec := new(Uint24Codec)
|
codec := new(Uint24)
|
||||||
|
|
||||||
// Test SetUint24
|
// Test SetUint24
|
||||||
err := codec.SetUint24(tt.value)
|
err := codec.SetUint24(tt.value)
|
||||||
@@ -53,14 +53,14 @@ func TestUint24Codec(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Decode from the buffer
|
// Decode from the buffer
|
||||||
decodedCodec := new(Uint24Codec)
|
decoded := new(Uint24)
|
||||||
if err := decodedCodec.UnmarshalRead(buf); err != nil {
|
if err := decoded.UnmarshalRead(buf); err != nil {
|
||||||
t.Fatalf("UnmarshalRead failed: %v", err)
|
t.Fatalf("UnmarshalRead failed: %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Validate decoded value
|
// Validate decoded value
|
||||||
if decodedCodec.Uint24() != tt.value {
|
if decoded.Uint24() != tt.value {
|
||||||
t.Errorf("Decoded value mismatch: got %d, expected %d", decodedCodec.Uint24(), tt.value)
|
t.Errorf("Decoded value mismatch: got %d, expected %d", decoded.Uint24(), tt.value)
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,38 +5,38 @@ import (
|
|||||||
"io"
|
"io"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Uint32Codec is a codec for encoding and decoding 32-bit unsigned integers.
|
// Uint32 is a codec for encoding and decoding 32-bit unsigned integers.
|
||||||
type Uint32Codec struct {
|
type Uint32 struct {
|
||||||
value uint32
|
value uint32
|
||||||
}
|
}
|
||||||
|
|
||||||
// SetUint32 sets the value as a uint32.
|
// SetUint32 sets the value as a uint32.
|
||||||
func (c *Uint32Codec) SetUint32(value uint32) {
|
func (c *Uint32) SetUint32(value uint32) {
|
||||||
c.value = value
|
c.value = value
|
||||||
}
|
}
|
||||||
|
|
||||||
// Uint32 gets the value as a uint32.
|
// Uint32 gets the value as a uint32.
|
||||||
func (c *Uint32Codec) Uint32() uint32 {
|
func (c *Uint32) Uint32() uint32 {
|
||||||
return c.value
|
return c.value
|
||||||
}
|
}
|
||||||
|
|
||||||
// SetInt sets the value as an int, converting it to uint32.
|
// SetInt sets the value as an int, converting it to uint32.
|
||||||
// Values outside the range of uint32 (0–4294967295) will be truncated.
|
// Values outside the range of uint32 (0–4294967295) will be truncated.
|
||||||
func (c *Uint32Codec) SetInt(value int) {
|
func (c *Uint32) SetInt(value int) {
|
||||||
c.value = uint32(value)
|
c.value = uint32(value)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Int gets the value as an int, converted from uint32.
|
// Int gets the value as an int, converted from uint32.
|
||||||
func (c *Uint32Codec) Int() int {
|
func (c *Uint32) Int() int {
|
||||||
return int(c.value)
|
return int(c.value)
|
||||||
}
|
}
|
||||||
|
|
||||||
// MarshalWrite writes the uint32 value to the provided writer in BigEndian order.
|
// MarshalWrite writes the uint32 value to the provided writer in BigEndian order.
|
||||||
func (c *Uint32Codec) MarshalWrite(w io.Writer) error {
|
func (c *Uint32) MarshalWrite(w io.Writer) error {
|
||||||
return binary.Write(w, binary.BigEndian, c.value)
|
return binary.Write(w, binary.BigEndian, c.value)
|
||||||
}
|
}
|
||||||
|
|
||||||
// UnmarshalRead reads a uint32 value from the provided reader in BigEndian order.
|
// UnmarshalRead reads a uint32 value from the provided reader in BigEndian order.
|
||||||
func (c *Uint32Codec) UnmarshalRead(r io.Reader) error {
|
func (c *Uint32) UnmarshalRead(r io.Reader) error {
|
||||||
return binary.Read(r, binary.BigEndian, &c.value)
|
return binary.Read(r, binary.BigEndian, &c.value)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -8,7 +8,7 @@ import (
|
|||||||
"lukechampine.com/frand"
|
"lukechampine.com/frand"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestUint32Codec(t *testing.T) {
|
func TestUint32(t *testing.T) {
|
||||||
// Helper function to generate random 32-bit integers
|
// Helper function to generate random 32-bit integers
|
||||||
generateRandomUint32 := func() uint32 {
|
generateRandomUint32 := func() uint32 {
|
||||||
return uint32(frand.Intn(math.MaxUint32)) // math.MaxUint32 == 4294967295
|
return uint32(frand.Intn(math.MaxUint32)) // math.MaxUint32 == 4294967295
|
||||||
@@ -20,7 +20,7 @@ func TestUint32Codec(t *testing.T) {
|
|||||||
randomInt := int(randomUint32)
|
randomInt := int(randomUint32)
|
||||||
|
|
||||||
// Create a new codec
|
// Create a new codec
|
||||||
codec := new(Uint32Codec)
|
codec := new(Uint32)
|
||||||
|
|
||||||
// Test UInt32 setter and getter
|
// Test UInt32 setter and getter
|
||||||
codec.SetUint32(randomUint32)
|
codec.SetUint32(randomUint32)
|
||||||
@@ -48,14 +48,14 @@ func TestUint32Codec(t *testing.T) {
|
|||||||
bufDec := bytes.NewBuffer(encoded)
|
bufDec := bytes.NewBuffer(encoded)
|
||||||
|
|
||||||
// Decode back the value
|
// Decode back the value
|
||||||
decodedCodec := new(Uint32Codec)
|
decoded := new(Uint32)
|
||||||
err = decodedCodec.UnmarshalRead(bufDec)
|
err = decoded.UnmarshalRead(bufDec)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("UnmarshalRead failed: %v", err)
|
t.Fatalf("UnmarshalRead failed: %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
if decodedCodec.Uint32() != randomUint32 {
|
if decoded.Uint32() != randomUint32 {
|
||||||
t.Fatalf("Decoded value mismatch: got %d, expected %d", decodedCodec.Uint32(), randomUint32)
|
t.Fatalf("Decoded value mismatch: got %d, expected %d", decoded.Uint32(), randomUint32)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Compare encoded bytes to ensure correctness
|
// Compare encoded bytes to ensure correctness
|
||||||
|
|||||||
@@ -8,12 +8,12 @@ import (
|
|||||||
// MaxUint40 is the maximum value of a 40-bit unsigned integer: 2^40 - 1.
|
// MaxUint40 is the maximum value of a 40-bit unsigned integer: 2^40 - 1.
|
||||||
const MaxUint40 uint64 = 1<<40 - 1
|
const MaxUint40 uint64 = 1<<40 - 1
|
||||||
|
|
||||||
// Uint40Codec is a codec for encoding and decoding 40-bit unsigned integers.
|
// Uint40 is a codec for encoding and decoding 40-bit unsigned integers.
|
||||||
type Uint40Codec struct{ value uint64 }
|
type Uint40 struct{ value uint64 }
|
||||||
|
|
||||||
// SetUint40 sets the value as a 40-bit unsigned integer.
|
// SetUint40 sets the value as a 40-bit unsigned integer.
|
||||||
// If the value exceeds the maximum allowable value for 40 bits, it returns an error.
|
// If the value exceeds the maximum allowable value for 40 bits, it returns an error.
|
||||||
func (c *Uint40Codec) SetUint40(value uint64) error {
|
func (c *Uint40) SetUint40(value uint64) error {
|
||||||
if value > MaxUint40 {
|
if value > MaxUint40 {
|
||||||
return errors.New("value exceeds 40-bit range")
|
return errors.New("value exceeds 40-bit range")
|
||||||
}
|
}
|
||||||
@@ -22,11 +22,11 @@ func (c *Uint40Codec) SetUint40(value uint64) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Uint40 gets the value as a 40-bit unsigned integer.
|
// Uint40 gets the value as a 40-bit unsigned integer.
|
||||||
func (c *Uint40Codec) Uint40() uint64 { return c.value }
|
func (c *Uint40) Uint40() uint64 { return c.value }
|
||||||
|
|
||||||
// SetInt sets the value as an int, converting it to a 40-bit unsigned integer.
|
// SetInt sets the value as an int, converting it to a 40-bit unsigned integer.
|
||||||
// If the value is out of the 40-bit range, it returns an error.
|
// If the value is out of the 40-bit range, it returns an error.
|
||||||
func (c *Uint40Codec) SetInt(value int) error {
|
func (c *Uint40) SetInt(value int) error {
|
||||||
if value < 0 || uint64(value) > MaxUint40 {
|
if value < 0 || uint64(value) > MaxUint40 {
|
||||||
return errors.New("value exceeds 40-bit range")
|
return errors.New("value exceeds 40-bit range")
|
||||||
}
|
}
|
||||||
@@ -36,11 +36,11 @@ func (c *Uint40Codec) SetInt(value int) error {
|
|||||||
|
|
||||||
// Int gets the value as an int, converted from the 40-bit unsigned integer.
|
// Int gets the value as an int, converted from the 40-bit unsigned integer.
|
||||||
// Note: If the value exceeds the int range, it will be truncated.
|
// Note: If the value exceeds the int range, it will be truncated.
|
||||||
func (c *Uint40Codec) Int() int { return int(c.value) }
|
func (c *Uint40) Int() int { return int(c.value) }
|
||||||
|
|
||||||
// MarshalWrite encodes the 40-bit unsigned integer and writes it to the provided writer.
|
// MarshalWrite encodes the 40-bit unsigned integer and writes it to the provided writer.
|
||||||
// The encoding uses 5 bytes in BigEndian order.
|
// The encoding uses 5 bytes in BigEndian order.
|
||||||
func (c *Uint40Codec) MarshalWrite(w io.Writer) (err error) {
|
func (c *Uint40) MarshalWrite(w io.Writer) (err error) {
|
||||||
if c.value > MaxUint40 {
|
if c.value > MaxUint40 {
|
||||||
return errors.New("value exceeds 40-bit range")
|
return errors.New("value exceeds 40-bit range")
|
||||||
}
|
}
|
||||||
@@ -57,7 +57,7 @@ func (c *Uint40Codec) MarshalWrite(w io.Writer) (err error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// UnmarshalRead reads 5 bytes from the provided reader and decodes it into a 40-bit unsigned integer.
|
// UnmarshalRead reads 5 bytes from the provided reader and decodes it into a 40-bit unsigned integer.
|
||||||
func (c *Uint40Codec) UnmarshalRead(r io.Reader) (err error) {
|
func (c *Uint40) UnmarshalRead(r io.Reader) (err error) {
|
||||||
// Buffer for the 5 bytes
|
// Buffer for the 5 bytes
|
||||||
buf := make([]byte, 5)
|
buf := make([]byte, 5)
|
||||||
_, err = r.Read(buf)
|
_, err = r.Read(buf)
|
||||||
|
|||||||
@@ -5,8 +5,8 @@ import (
|
|||||||
"testing"
|
"testing"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestUint40Codec(t *testing.T) {
|
func TestUint40(t *testing.T) {
|
||||||
// Test cases for Uint40Codec
|
// Test cases for Uint40
|
||||||
tests := []struct {
|
tests := []struct {
|
||||||
name string
|
name string
|
||||||
value uint64
|
value uint64
|
||||||
@@ -20,7 +20,7 @@ func TestUint40Codec(t *testing.T) {
|
|||||||
|
|
||||||
for _, tt := range tests {
|
for _, tt := range tests {
|
||||||
t.Run(tt.name, func(t *testing.T) {
|
t.Run(tt.name, func(t *testing.T) {
|
||||||
codec := new(Uint40Codec)
|
codec := new(Uint40)
|
||||||
|
|
||||||
// Test SetUint40
|
// Test SetUint40
|
||||||
err := codec.SetUint40(tt.value)
|
err := codec.SetUint40(tt.value)
|
||||||
@@ -54,14 +54,14 @@ func TestUint40Codec(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Decode from the buffer
|
// Decode from the buffer
|
||||||
decodedCodec := new(Uint40Codec)
|
decoded := new(Uint40)
|
||||||
if err = decodedCodec.UnmarshalRead(buf); err != nil {
|
if err = decoded.UnmarshalRead(buf); err != nil {
|
||||||
t.Fatalf("UnmarshalRead failed: %v", err)
|
t.Fatalf("UnmarshalRead failed: %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Validate decoded value
|
// Validate decoded value
|
||||||
if decodedCodec.Uint40() != tt.value {
|
if decoded.Uint40() != tt.value {
|
||||||
t.Errorf("Decoded value mismatch: got %d, expected %d", decodedCodec.Uint40(), tt.value)
|
t.Errorf("Decoded value mismatch: got %d, expected %d", decoded.Uint40(), tt.value)
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,38 +5,38 @@ import (
|
|||||||
"io"
|
"io"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Uint64Codec is a codec for encoding and decoding 64-bit unsigned integers.
|
// Uint64 is a codec for encoding and decoding 64-bit unsigned integers.
|
||||||
type Uint64Codec struct {
|
type Uint64 struct {
|
||||||
value uint64
|
value uint64
|
||||||
}
|
}
|
||||||
|
|
||||||
// SetUint64 sets the value as a uint64.
|
// SetUint64 sets the value as a uint64.
|
||||||
func (c *Uint64Codec) SetUint64(value uint64) {
|
func (c *Uint64) SetUint64(value uint64) {
|
||||||
c.value = value
|
c.value = value
|
||||||
}
|
}
|
||||||
|
|
||||||
// Uint64 gets the value as a uint64.
|
// Uint64 gets the value as a uint64.
|
||||||
func (c *Uint64Codec) Uint64() uint64 {
|
func (c *Uint64) Uint64() uint64 {
|
||||||
return c.value
|
return c.value
|
||||||
}
|
}
|
||||||
|
|
||||||
// SetInt sets the value as an int, converting it to uint64.
|
// SetInt sets the value as an int, converting it to uint64.
|
||||||
// Values outside the range of uint64 are truncated.
|
// Values outside the range of uint64 are truncated.
|
||||||
func (c *Uint64Codec) SetInt(value int) {
|
func (c *Uint64) SetInt(value int) {
|
||||||
c.value = uint64(value)
|
c.value = uint64(value)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Int gets the value as an int, converted from uint64. May truncate if the value exceeds the range of int.
|
// Int gets the value as an int, converted from uint64. May truncate if the value exceeds the range of int.
|
||||||
func (c *Uint64Codec) Int() int {
|
func (c *Uint64) Int() int {
|
||||||
return int(c.value)
|
return int(c.value)
|
||||||
}
|
}
|
||||||
|
|
||||||
// MarshalWrite writes the uint64 value to the provided writer in BigEndian order.
|
// MarshalWrite writes the uint64 value to the provided writer in BigEndian order.
|
||||||
func (c *Uint64Codec) MarshalWrite(w io.Writer) error {
|
func (c *Uint64) MarshalWrite(w io.Writer) error {
|
||||||
return binary.Write(w, binary.BigEndian, c.value)
|
return binary.Write(w, binary.BigEndian, c.value)
|
||||||
}
|
}
|
||||||
|
|
||||||
// UnmarshalRead reads a uint64 value from the provided reader in BigEndian order.
|
// UnmarshalRead reads a uint64 value from the provided reader in BigEndian order.
|
||||||
func (c *Uint64Codec) UnmarshalRead(r io.Reader) error {
|
func (c *Uint64) UnmarshalRead(r io.Reader) error {
|
||||||
return binary.Read(r, binary.BigEndian, &c.value)
|
return binary.Read(r, binary.BigEndian, &c.value)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -8,7 +8,7 @@ import (
|
|||||||
"lukechampine.com/frand"
|
"lukechampine.com/frand"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestUint64Codec(t *testing.T) {
|
func TestUint64(t *testing.T) {
|
||||||
// Helper function to generate random 64-bit integers
|
// Helper function to generate random 64-bit integers
|
||||||
generateRandomUint64 := func() uint64 {
|
generateRandomUint64 := func() uint64 {
|
||||||
return frand.Uint64n(math.MaxUint64) // math.MaxUint64 == 18446744073709551615
|
return frand.Uint64n(math.MaxUint64) // math.MaxUint64 == 18446744073709551615
|
||||||
@@ -20,7 +20,7 @@ func TestUint64Codec(t *testing.T) {
|
|||||||
randomInt := int(randomUint64)
|
randomInt := int(randomUint64)
|
||||||
|
|
||||||
// Create a new codec
|
// Create a new codec
|
||||||
codec := new(Uint64Codec)
|
codec := new(Uint64)
|
||||||
|
|
||||||
// Test UInt64 setter and getter
|
// Test UInt64 setter and getter
|
||||||
codec.SetUint64(randomUint64)
|
codec.SetUint64(randomUint64)
|
||||||
@@ -48,14 +48,14 @@ func TestUint64Codec(t *testing.T) {
|
|||||||
bufDec := bytes.NewBuffer(encoded)
|
bufDec := bytes.NewBuffer(encoded)
|
||||||
|
|
||||||
// Decode back the value
|
// Decode back the value
|
||||||
decodedCodec := new(Uint64Codec)
|
decoded := new(Uint64)
|
||||||
err = decodedCodec.UnmarshalRead(bufDec)
|
err = decoded.UnmarshalRead(bufDec)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("UnmarshalRead failed: %v", err)
|
t.Fatalf("UnmarshalRead failed: %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
if decodedCodec.Uint64() != randomUint64 {
|
if decoded.Uint64() != randomUint64 {
|
||||||
t.Fatalf("Decoded value mismatch: got %d, expected %d", decodedCodec.Uint64(), randomUint64)
|
t.Fatalf("Decoded value mismatch: got %d, expected %d", decoded.Uint64(), randomUint64)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Compare encoded bytes to ensure correctness
|
// Compare encoded bytes to ensure correctness
|
||||||
|
|||||||
Reference in New Issue
Block a user