From 7e9213c75b9361c174f4662ff3feb4104d2c8f07 Mon Sep 17 00:00:00 2001 From: Luke Shumaker Date: Wed, 11 May 2022 11:56:15 -0600 Subject: wip --- pkg/binstruct/binstruct_test.go | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) (limited to 'pkg/binstruct/binstruct_test.go') diff --git a/pkg/binstruct/binstruct_test.go b/pkg/binstruct/binstruct_test.go index 33a2f0a..fc7eab4 100644 --- a/pkg/binstruct/binstruct_test.go +++ b/pkg/binstruct/binstruct_test.go @@ -10,6 +10,7 @@ import ( func TestSmoke(t *testing.T) { type UUID [16]byte + type PhysicalAddr int64 type DevItem struct { DeviceID uint64 `bin:"off=0, siz=8, desc=device id"` @@ -33,17 +34,23 @@ func TestSmoke(t *testing.T) { binstruct.End `bin:"off=62"` } type TestType struct { - Magic [5]byte `bin:"off=0,siz=5"` - Dev DevItem `bin:"off=5,siz=62"` + Magic [5]byte `bin:"off=0,siz=5"` + Dev DevItem `bin:"off=5,siz=62"` + Addr PhysicalAddr `bin:"off=67, siz=8"` - binstruct.End `bin:"off=67"` + binstruct.End `bin:"off=6F"` } input := TestType{} copy(input.Magic[:], "mAgIc") input.Dev.DeviceID = 12 + input.Addr = 0xBEEF bs, err := binstruct.Marshal(input) assert.NoError(t, err) - assert.True(t, len(bs) == 0x67, "len(bs)=0x%x", len(bs)) + assert.True(t, len(bs) == 0x6F, "len(bs)=0x%x", len(bs)) + + var output TestType + assert.NoError(t, binstruct.Unmarshal(bs, &output)) + assert.Equal(t, input, output) } -- cgit v1.2.3-2-g168b