summaryrefslogtreecommitdiff
path: root/pkg/binstruct
diff options
context:
space:
mode:
authorLuke Shumaker <lukeshu@lukeshu.com>2022-06-01 01:27:19 -0600
committerLuke Shumaker <lukeshu@lukeshu.com>2022-06-01 01:27:19 -0600
commit3825cf60fd652f22acc438d50028701d27a7402d (patch)
tree24b86afb8513891274dfaa8b982c4c94c1a65a5d /pkg/binstruct
parent2348cdbe2a3417990a2088f9e4e91adf0c45617d (diff)
wow
Diffstat (limited to 'pkg/binstruct')
-rw-r--r--pkg/binstruct/size.go11
1 files changed, 9 insertions, 2 deletions
diff --git a/pkg/binstruct/size.go b/pkg/binstruct/size.go
index 8846c23..0119a7a 100644
--- a/pkg/binstruct/size.go
+++ b/pkg/binstruct/size.go
@@ -17,7 +17,11 @@ func StaticSize(obj any) int {
return sz
}
-var staticSizerType = reflect.TypeOf((*StaticSizer)(nil)).Elem()
+var (
+ staticSizerType = reflect.TypeOf((*StaticSizer)(nil)).Elem()
+ marshalerType = reflect.TypeOf((*Marshaler)(nil)).Elem()
+ unmarshalerType = reflect.TypeOf((*Unmarshaler)(nil)).Elem()
+)
func staticSize(typ reflect.Type) (int, error) {
if typ.Implements(staticSizerType) {
@@ -41,7 +45,10 @@ func staticSize(typ reflect.Type) (int, error) {
}
return elemSize * typ.Len(), nil
case reflect.Struct:
- return getStructHandler(typ).Size, nil
+ if !(typ.Implements(marshalerType) || typ.Implements(unmarshalerType)) {
+ return getStructHandler(typ).Size, nil
+ }
+ fallthrough
default:
return 0, fmt.Errorf("type=%v does not implement binfmt.StaticSizer and kind=%v is not a supported statically-sized kind",
typ, typ.Kind())