diff options
Diffstat (limited to 'pkg/binstruct')
-rw-r--r-- | pkg/binstruct/binint/builtins.go | 2 | ||||
-rw-r--r-- | pkg/binstruct/structs.go | 20 |
2 files changed, 11 insertions, 11 deletions
diff --git a/pkg/binstruct/binint/builtins.go b/pkg/binstruct/binint/builtins.go index 9af3c35..04fc477 100644 --- a/pkg/binstruct/binint/builtins.go +++ b/pkg/binstruct/binint/builtins.go @@ -7,7 +7,7 @@ import ( func needNBytes(t interface{}, dat []byte, n int) error { if len(dat) < n { - return fmt.Errorf("%T.UnmarshalBinary: need at least %d bytes, only have %d", t, n, len(dat)) + return fmt.Errorf("%T.UnmarshalBinary: need at least %v bytes, only have %v", t, n, len(dat)) } return nil } diff --git a/pkg/binstruct/structs.go b/pkg/binstruct/structs.go index 8ecea6a..ec2bb7d 100644 --- a/pkg/binstruct/structs.go +++ b/pkg/binstruct/structs.go @@ -76,11 +76,11 @@ func (sh structHandler) Unmarshal(dat []byte, dst reflect.Value) (int, error) { if _n >= 0 { n += _n } - return n, fmt.Errorf("struct %q field %d %q: %w", + return n, fmt.Errorf("struct %q field %v %q: %w", sh.name, i, field.name, err) } if _n != field.siz { - return n, fmt.Errorf("struct %q field %d %q: consumed %d bytes but should have consumed %d bytes", + return n, fmt.Errorf("struct %q field %v %q: consumed %v bytes but should have consumed %v bytes", sh.name, i, field.name, _n, field.siz) } n += _n @@ -97,7 +97,7 @@ func (sh structHandler) Marshal(val reflect.Value) ([]byte, error) { bs, err := Marshal(val.Field(i).Interface()) ret = append(ret, bs...) if err != nil { - return ret, fmt.Errorf("struct %q field %d %q: %w", + return ret, fmt.Errorf("struct %q field %v %q: %w", sh.name, i, field.name, err) } } @@ -115,13 +115,13 @@ func genStructHandler(structInfo reflect.Type) (structHandler, error) { if fieldInfo.Anonymous && fieldInfo.Type != endType { err := fmt.Errorf("binstruct does not support embedded fields") - return ret, fmt.Errorf("struct %q field %d %q: %w", + return ret, fmt.Errorf("struct %q field %v %q: %w", ret.name, i, fieldInfo.Name, err) } fieldTag, err := parseStructTag(fieldInfo.Tag.Get("bin")) if err != nil { - return ret, fmt.Errorf("struct %q field %d %q: %w", + return ret, fmt.Errorf("struct %q field %v %q: %w", ret.name, i, fieldInfo.Name, err) } if fieldTag.skip { @@ -133,8 +133,8 @@ func genStructHandler(structInfo reflect.Type) (structHandler, error) { } if fieldTag.off != curOffset { - err := fmt.Errorf("tag says off=0x%x but curOffset=0x%x", fieldTag.off, curOffset) - return ret, fmt.Errorf("struct %q field %d %q: %w", + err := fmt.Errorf("tag says off=%#x but curOffset=%#x", fieldTag.off, curOffset) + return ret, fmt.Errorf("struct %q field %v %q: %w", ret.name, i, fieldInfo.Name, err) } if fieldInfo.Type == endType { @@ -143,13 +143,13 @@ func genStructHandler(structInfo reflect.Type) (structHandler, error) { fieldSize, err := staticSize(fieldInfo.Type) if err != nil { - return ret, fmt.Errorf("struct %q field %d %q: %w", + return ret, fmt.Errorf("struct %q field %v %q: %w", ret.name, i, fieldInfo.Name, err) } if fieldTag.siz != fieldSize { - err := fmt.Errorf("tag says siz=0x%x but StaticSize(typ)=0x%x", fieldTag.siz, fieldSize) - return ret, fmt.Errorf("struct %q field %d %q: %w", + err := fmt.Errorf("tag says siz=%#x but StaticSize(typ)=%#x", fieldTag.siz, fieldSize) + return ret, fmt.Errorf("struct %q field %v %q: %w", ret.name, i, fieldInfo.Name, err) } curOffset += fieldTag.siz |