diff options
author | Luke Shumaker <lukeshu@lukeshu.com> | 2023-01-01 20:48:22 -0700 |
---|---|---|
committer | Luke Shumaker <lukeshu@lukeshu.com> | 2023-01-01 22:42:08 -0700 |
commit | 97fa22c161056c289a9978f20e3fb6b05d779a23 (patch) | |
tree | aabf3ec9a0f4b8f659f4d12f4c9a31a9ddfdc247 /lib/binstruct/size.go | |
parent | b261c2a4f5f028c9d83cef208ccc7d829f841bad (diff) |
lint: Turn on gomnd
Diffstat (limited to 'lib/binstruct/size.go')
-rw-r--r-- | lib/binstruct/size.go | 15 |
1 files changed, 11 insertions, 4 deletions
diff --git a/lib/binstruct/size.go b/lib/binstruct/size.go index 52fa380..d6d70c6 100644 --- a/lib/binstruct/size.go +++ b/lib/binstruct/size.go @@ -28,6 +28,13 @@ var ( unmarshalerType = reflect.TypeOf((*Unmarshaler)(nil)).Elem() ) +const ( + sizeof8 = 1 + sizeof16 = 2 + sizeof32 = 4 + sizeof64 = 8 +) + func staticSize(typ reflect.Type) (int, error) { if typ.Implements(staticSizerType) { //nolint:forcetypeassert // Already did a type check via reflection. @@ -43,13 +50,13 @@ func staticSize(typ reflect.Type) (int, error) { } switch typ.Kind() { case reflect.Uint8, reflect.Int8: - return 1, nil + return sizeof8, nil case reflect.Uint16, reflect.Int16: - return 2, nil + return sizeof16, nil case reflect.Uint32, reflect.Int32: - return 4, nil + return sizeof32, nil case reflect.Uint64, reflect.Int64: - return 8, nil + return sizeof64, nil case reflect.Ptr: return staticSize(typ.Elem()) case reflect.Array: |