summaryrefslogtreecommitdiff
path: root/pkg/binstruct
diff options
context:
space:
mode:
authorLuke Shumaker <lukeshu@lukeshu.com>2022-06-11 22:30:35 -0600
committerLuke Shumaker <lukeshu@lukeshu.com>2022-06-11 22:38:48 -0600
commit6fc5d416a289235dd4bb56d29fb96c5a003ea89f (patch)
treee35bb16c46c2ad8d8563b42e12a1e95cbd936dc7 /pkg/binstruct
parentf1a212cddb8dc051c510327c365da42e30b23ab9 (diff)
use %v when possible
Exceptions are - the occasional %x when the type is a basic int - %w - %q - %T - whenever print_tree.go needs to be dumb for compatibility with C
Diffstat (limited to 'pkg/binstruct')
-rw-r--r--pkg/binstruct/binint/builtins.go2
-rw-r--r--pkg/binstruct/structs.go20
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