summaryrefslogtreecommitdiff
path: root/pkg/binstruct/binstruct_test.go
diff options
context:
space:
mode:
authorLuke Shumaker <lukeshu@lukeshu.com>2022-05-11 11:56:15 -0600
committerLuke Shumaker <lukeshu@lukeshu.com>2022-05-11 11:56:15 -0600
commit7e9213c75b9361c174f4662ff3feb4104d2c8f07 (patch)
tree46e37147b439add714cb6b49032ca38612596616 /pkg/binstruct/binstruct_test.go
parent2744e0700ca6fe956f569d47010fd4e693fedcfa (diff)
wip
Diffstat (limited to 'pkg/binstruct/binstruct_test.go')
-rw-r--r--pkg/binstruct/binstruct_test.go15
1 files changed, 11 insertions, 4 deletions
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)
}