diff options
Diffstat (limited to 'pkg')
-rw-r--r-- | pkg/binstruct/binint/builtins.go | 16 | ||||
-rw-r--r-- | pkg/binstruct/binstruct_test.go | 4 |
2 files changed, 11 insertions, 9 deletions
diff --git a/pkg/binstruct/binint/builtins.go b/pkg/binstruct/binint/builtins.go index 3272ed9..9af3c35 100644 --- a/pkg/binstruct/binint/builtins.go +++ b/pkg/binstruct/binint/builtins.go @@ -57,7 +57,7 @@ func (x *U32le) UnmarshalBinary(dat []byte) (int, error) { return 0, err } *x = U32le(binary.LittleEndian.Uint32(dat)) - return 2, nil + return 4, nil } type U64le uint64 @@ -73,7 +73,7 @@ func (x *U64le) UnmarshalBinary(dat []byte) (int, error) { return 0, err } *x = U64le(binary.LittleEndian.Uint64(dat)) - return 2, nil + return 8, nil } // unsigned big endian @@ -107,7 +107,7 @@ func (x *U32be) UnmarshalBinary(dat []byte) (int, error) { return 0, err } *x = U32be(binary.BigEndian.Uint32(dat)) - return 2, nil + return 4, nil } type U64be uint64 @@ -123,7 +123,7 @@ func (x *U64be) UnmarshalBinary(dat []byte) (int, error) { return 0, err } *x = U64be(binary.BigEndian.Uint64(dat)) - return 2, nil + return 8, nil } // signed @@ -171,7 +171,7 @@ func (x *I32le) UnmarshalBinary(dat []byte) (int, error) { return 0, err } *x = I32le(binary.LittleEndian.Uint32(dat)) - return 2, nil + return 4, nil } type I64le int64 @@ -187,7 +187,7 @@ func (x *I64le) UnmarshalBinary(dat []byte) (int, error) { return 0, err } *x = I64le(binary.LittleEndian.Uint64(dat)) - return 2, nil + return 8, nil } // signed big endian @@ -221,7 +221,7 @@ func (x *I32be) UnmarshalBinary(dat []byte) (int, error) { return 0, err } *x = I32be(binary.BigEndian.Uint32(dat)) - return 2, nil + return 4, nil } type I64be int64 @@ -237,5 +237,5 @@ func (x *I64be) UnmarshalBinary(dat []byte) (int, error) { return 0, err } *x = I64be(binary.BigEndian.Uint64(dat)) - return 2, nil + return 8, nil } diff --git a/pkg/binstruct/binstruct_test.go b/pkg/binstruct/binstruct_test.go index 00c9e37..83a1747 100644 --- a/pkg/binstruct/binstruct_test.go +++ b/pkg/binstruct/binstruct_test.go @@ -41,6 +41,8 @@ func TestSmoke(t *testing.T) { binstruct.End `bin:"off=0x6F"` } + assert.Equal(t, 0x6F, binstruct.StaticSize(TestType{})) + input := TestType{} copy(input.Magic[:], "mAgIc") input.Dev.DeviceID = 12 @@ -48,7 +50,7 @@ func TestSmoke(t *testing.T) { bs, err := binstruct.Marshal(input) assert.NoError(t, err) - assert.True(t, len(bs) == 0x6F, "len(bs)=0x%x", len(bs)) + assert.Equal(t, 0x6F, len(bs)) var output TestType n, err := binstruct.Unmarshal(bs, &output) |