From 3825cf60fd652f22acc438d50028701d27a7402d Mon Sep 17 00:00:00 2001 From: Luke Shumaker Date: Wed, 1 Jun 2022 01:27:19 -0600 Subject: wow --- pkg/binstruct/size.go | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) (limited to 'pkg/binstruct') 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()) -- cgit v1.2.3-2-g168b