From ff2b982ba0034e76397e89e1ad2a19e47899fb47 Mon Sep 17 00:00:00 2001 From: whyrusleeping Date: Thu, 1 Feb 2024 13:10:25 -0800 Subject: [PATCH] turn max length consts into global vars --- gen.go | 16 ++-- testing/cbor_gen.go | 36 ++++----- testing/cbor_map_gen.go | 164 ++++++++++++++++++++-------------------- 3 files changed, 108 insertions(+), 108 deletions(-) diff --git a/gen.go b/gen.go index 1155c04..3c52b29 100644 --- a/gen.go +++ b/gen.go @@ -13,9 +13,9 @@ import ( cid "github.com/ipfs/go-cid" ) -const MaxLength = 8192 +var MaxLength = uint64(8192) -const ByteArrayMaxLen = 2 << 20 +var ByteArrayMaxLen = uint64(2 << 20) const MaxLenTag = "maxlen" const NoUsrMaxLen = -1 @@ -318,7 +318,7 @@ func emitCborMarshalStringField(w io.Writer, f Field) error { return err } } else { - if len(*{{ .Name }}) > {{ MaxLen .MaxLen "cbg.MaxLength" }} { + if uint64(len(*{{ .Name }})) > {{ MaxLen .MaxLen "cbg.MaxLength" }} { return xerrors.Errorf("Value in field {{ .Name | js }} was too long") } @@ -341,7 +341,7 @@ func emitCborMarshalStringField(w io.Writer, f Field) error { } return doTemplate(w, f, ` - if len({{ .Name }}) > {{ MaxLen .MaxLen "cbg.MaxLength" }} { + if uint64(len({{ .Name }})) > {{ MaxLen .MaxLen "cbg.MaxLength" }} { return xerrors.Errorf("Value in field {{ .Name | js }} was too long") } @@ -532,7 +532,7 @@ func emitCborMarshalSliceField(w io.Writer, f Field) error { if e.Kind() == reflect.Uint8 { return doTemplate(w, f, ` - if len({{ .Name }}) > {{ MaxLen .MaxLen "cbg.ByteArrayMaxLen" }} { + if uint64(len({{ .Name }})) > {{ MaxLen .MaxLen "cbg.ByteArrayMaxLen" }} { return xerrors.Errorf("Byte array in field {{ .Name }} was too long") } @@ -562,7 +562,7 @@ func emitCborMarshalSliceField(w io.Writer, f Field) error { } err := doTemplate(w, f, ` - if len({{ .Name }}) > {{ MaxLen .MaxLen "cbg.MaxLength" }} { + if uint64(len({{ .Name }})) > {{ MaxLen .MaxLen "cbg.MaxLength" }} { return xerrors.Errorf("Slice value in field {{ .Name }} was too long") } @@ -623,7 +623,7 @@ func emitCborMarshalArrayField(w io.Writer, f Field) error { // Note: this re-slices the slice to deal with arrays. if e.Kind() == reflect.Uint8 { return doTemplate(w, f, ` - if len({{ .Name }}) > {{ MaxLen .MaxLen "cbg.ByteArrayMaxLen" }} { + if uint64(len({{ .Name }})) > {{ MaxLen .MaxLen "cbg.ByteArrayMaxLen" }} { return xerrors.Errorf("Byte array in field {{ .Name }} was too long") } @@ -642,7 +642,7 @@ func emitCborMarshalArrayField(w io.Writer, f Field) error { } err := doTemplate(w, f, ` - if len({{ .Name }}) > {{ MaxLen .MaxLen "cbg.MaxLength" }} { + if uint64(len({{ .Name }})) > {{ MaxLen .MaxLen "cbg.MaxLength" }} { return xerrors.Errorf("Slice value in field {{ .Name }} was too long") } diff --git a/testing/cbor_gen.go b/testing/cbor_gen.go index e25a5d2..f45ca85 100644 --- a/testing/cbor_gen.go +++ b/testing/cbor_gen.go @@ -33,7 +33,7 @@ func (t *SignedArray) MarshalCBOR(w io.Writer) error { } // t.Signed ([]uint64) (slice) - if len(t.Signed) > cbg.MaxLength { + if uint64(len(t.Signed)) > cbg.MaxLength { return xerrors.Errorf("Slice value in field t.Signed was too long") } @@ -134,7 +134,7 @@ func (t *SimpleTypeOne) MarshalCBOR(w io.Writer) error { } // t.Foo (string) (string) - if len(t.Foo) > cbg.MaxLength { + if uint64(len(t.Foo)) > cbg.MaxLength { return xerrors.Errorf("Value in field t.Foo was too long") } @@ -152,7 +152,7 @@ func (t *SimpleTypeOne) MarshalCBOR(w io.Writer) error { } // t.Binary ([]uint8) (slice) - if len(t.Binary) > cbg.ByteArrayMaxLen { + if uint64(len(t.Binary)) > cbg.ByteArrayMaxLen { return xerrors.Errorf("Byte array in field t.Binary was too long") } @@ -176,7 +176,7 @@ func (t *SimpleTypeOne) MarshalCBOR(w io.Writer) error { } // t.NString (testing.NamedString) (string) - if len(t.NString) > cbg.MaxLength { + if uint64(len(t.NString)) > cbg.MaxLength { return xerrors.Errorf("Value in field t.NString was too long") } @@ -188,7 +188,7 @@ func (t *SimpleTypeOne) MarshalCBOR(w io.Writer) error { } // t.Strings ([]string) (slice) - if len(t.Strings) > cbg.MaxLength { + if uint64(len(t.Strings)) > cbg.MaxLength { return xerrors.Errorf("Slice value in field t.Strings was too long") } @@ -196,7 +196,7 @@ func (t *SimpleTypeOne) MarshalCBOR(w io.Writer) error { return err } for _, v := range t.Strings { - if len(v) > cbg.MaxLength { + if uint64(len(v)) > cbg.MaxLength { return xerrors.Errorf("Value in field v was too long") } @@ -377,7 +377,7 @@ func (t *SimpleTypeTwo) MarshalCBOR(w io.Writer) error { } // t.Others ([]uint64) (slice) - if len(t.Others) > cbg.MaxLength { + if uint64(len(t.Others)) > cbg.MaxLength { return xerrors.Errorf("Slice value in field t.Others was too long") } @@ -393,7 +393,7 @@ func (t *SimpleTypeTwo) MarshalCBOR(w io.Writer) error { } // t.SignedOthers ([]int64) (slice) - if len(t.SignedOthers) > cbg.MaxLength { + if uint64(len(t.SignedOthers)) > cbg.MaxLength { return xerrors.Errorf("Slice value in field t.SignedOthers was too long") } @@ -414,7 +414,7 @@ func (t *SimpleTypeTwo) MarshalCBOR(w io.Writer) error { } // t.Test ([][]uint8) (slice) - if len(t.Test) > cbg.MaxLength { + if uint64(len(t.Test)) > cbg.MaxLength { return xerrors.Errorf("Slice value in field t.Test was too long") } @@ -422,7 +422,7 @@ func (t *SimpleTypeTwo) MarshalCBOR(w io.Writer) error { return err } for _, v := range t.Test { - if len(v) > cbg.ByteArrayMaxLen { + if uint64(len(v)) > cbg.ByteArrayMaxLen { return xerrors.Errorf("Byte array in field v was too long") } @@ -437,7 +437,7 @@ func (t *SimpleTypeTwo) MarshalCBOR(w io.Writer) error { } // t.Dog (string) (string) - if len(t.Dog) > cbg.MaxLength { + if uint64(len(t.Dog)) > cbg.MaxLength { return xerrors.Errorf("Value in field t.Dog was too long") } @@ -449,7 +449,7 @@ func (t *SimpleTypeTwo) MarshalCBOR(w io.Writer) error { } // t.Numbers ([]testing.NamedNumber) (slice) - if len(t.Numbers) > cbg.MaxLength { + if uint64(len(t.Numbers)) > cbg.MaxLength { return xerrors.Errorf("Slice value in field t.Numbers was too long") } @@ -489,7 +489,7 @@ func (t *SimpleTypeTwo) MarshalCBOR(w io.Writer) error { } // t.Arrrrrghay ([3]testing.SimpleTypeOne) (array) - if len(t.Arrrrrghay) > cbg.MaxLength { + if uint64(len(t.Arrrrrghay)) > cbg.MaxLength { return xerrors.Errorf("Slice value in field t.Arrrrrghay was too long") } @@ -952,7 +952,7 @@ func (t *FixedArrays) MarshalCBOR(w io.Writer) error { } // t.Bytes ([20]uint8) (array) - if len(t.Bytes) > cbg.ByteArrayMaxLen { + if uint64(len(t.Bytes)) > cbg.ByteArrayMaxLen { return xerrors.Errorf("Byte array in field t.Bytes was too long") } @@ -965,7 +965,7 @@ func (t *FixedArrays) MarshalCBOR(w io.Writer) error { } // t.Uint8 ([20]uint8) (array) - if len(t.Uint8) > cbg.ByteArrayMaxLen { + if uint64(len(t.Uint8)) > cbg.ByteArrayMaxLen { return xerrors.Errorf("Byte array in field t.Uint8 was too long") } @@ -978,7 +978,7 @@ func (t *FixedArrays) MarshalCBOR(w io.Writer) error { } // t.Uint64 ([20]uint64) (array) - if len(t.Uint64) > cbg.MaxLength { + if uint64(len(t.Uint64)) > cbg.MaxLength { return xerrors.Errorf("Slice value in field t.Uint64 was too long") } @@ -1137,7 +1137,7 @@ func (t *ThingWithSomeTime) MarshalCBOR(w io.Writer) error { } // t.CatName (string) (string) - if len(t.CatName) > cbg.MaxLength { + if uint64(len(t.CatName)) > cbg.MaxLength { return xerrors.Errorf("Value in field t.CatName was too long") } @@ -1235,7 +1235,7 @@ func (t *BigField) MarshalCBOR(w io.Writer) error { } // t.LargeBytes ([]uint8) (slice) - if len(t.LargeBytes) > 10000000 { + if uint64(len(t.LargeBytes)) > 10000000 { return xerrors.Errorf("Byte array in field t.LargeBytes was too long") } diff --git a/testing/cbor_map_gen.go b/testing/cbor_map_gen.go index 10fc666..7b19b85 100644 --- a/testing/cbor_map_gen.go +++ b/testing/cbor_map_gen.go @@ -31,7 +31,7 @@ func (t *SimpleTypeTree) MarshalCBOR(w io.Writer) error { } // t.Dog (string) (string) - if len("Dog") > cbg.MaxLength { + if uint64(len("Dog")) > cbg.MaxLength { return xerrors.Errorf("Value in field \"Dog\" was too long") } @@ -42,7 +42,7 @@ func (t *SimpleTypeTree) MarshalCBOR(w io.Writer) error { return err } - if len(t.Dog) > cbg.MaxLength { + if uint64(len(t.Dog)) > cbg.MaxLength { return xerrors.Errorf("Value in field t.Dog was too long") } @@ -54,7 +54,7 @@ func (t *SimpleTypeTree) MarshalCBOR(w io.Writer) error { } // t.Test ([][]uint8) (slice) - if len("Test") > cbg.MaxLength { + if uint64(len("Test")) > cbg.MaxLength { return xerrors.Errorf("Value in field \"Test\" was too long") } @@ -65,7 +65,7 @@ func (t *SimpleTypeTree) MarshalCBOR(w io.Writer) error { return err } - if len(t.Test) > cbg.MaxLength { + if uint64(len(t.Test)) > cbg.MaxLength { return xerrors.Errorf("Slice value in field t.Test was too long") } @@ -73,7 +73,7 @@ func (t *SimpleTypeTree) MarshalCBOR(w io.Writer) error { return err } for _, v := range t.Test { - if len(v) > cbg.ByteArrayMaxLen { + if uint64(len(v)) > cbg.ByteArrayMaxLen { return xerrors.Errorf("Byte array in field v was too long") } @@ -88,7 +88,7 @@ func (t *SimpleTypeTree) MarshalCBOR(w io.Writer) error { } // t.Stuff (testing.SimpleTypeTree) (struct) - if len("Stuff") > cbg.MaxLength { + if uint64(len("Stuff")) > cbg.MaxLength { return xerrors.Errorf("Value in field \"Stuff\" was too long") } @@ -104,7 +104,7 @@ func (t *SimpleTypeTree) MarshalCBOR(w io.Writer) error { } // t.Others ([]uint64) (slice) - if len("Others") > cbg.MaxLength { + if uint64(len("Others")) > cbg.MaxLength { return xerrors.Errorf("Value in field \"Others\" was too long") } @@ -115,7 +115,7 @@ func (t *SimpleTypeTree) MarshalCBOR(w io.Writer) error { return err } - if len(t.Others) > cbg.MaxLength { + if uint64(len(t.Others)) > cbg.MaxLength { return xerrors.Errorf("Slice value in field t.Others was too long") } @@ -131,7 +131,7 @@ func (t *SimpleTypeTree) MarshalCBOR(w io.Writer) error { } // t.Stufff (testing.SimpleTypeTwo) (struct) - if len("Stufff") > cbg.MaxLength { + if uint64(len("Stufff")) > cbg.MaxLength { return xerrors.Errorf("Value in field \"Stufff\" was too long") } @@ -147,7 +147,7 @@ func (t *SimpleTypeTree) MarshalCBOR(w io.Writer) error { } // t.BoolPtr (bool) (bool) - if len("BoolPtr") > cbg.MaxLength { + if uint64(len("BoolPtr")) > cbg.MaxLength { return xerrors.Errorf("Value in field \"BoolPtr\" was too long") } @@ -169,7 +169,7 @@ func (t *SimpleTypeTree) MarshalCBOR(w io.Writer) error { } // t.NotPizza (uint64) (uint64) - if len("NotPizza") > cbg.MaxLength { + if uint64(len("NotPizza")) > cbg.MaxLength { return xerrors.Errorf("Value in field \"NotPizza\" was too long") } @@ -191,7 +191,7 @@ func (t *SimpleTypeTree) MarshalCBOR(w io.Writer) error { } // t.StringPtr (string) (string) - if len("StringPtr") > cbg.MaxLength { + if uint64(len("StringPtr")) > cbg.MaxLength { return xerrors.Errorf("Value in field \"StringPtr\" was too long") } @@ -207,7 +207,7 @@ func (t *SimpleTypeTree) MarshalCBOR(w io.Writer) error { return err } } else { - if len(*t.StringPtr) > cbg.MaxLength { + if uint64(len(*t.StringPtr)) > cbg.MaxLength { return xerrors.Errorf("Value in field t.StringPtr was too long") } @@ -220,7 +220,7 @@ func (t *SimpleTypeTree) MarshalCBOR(w io.Writer) error { } // t.SixtyThreeBitIntegerWithASignBit (int64) (int64) - if len("SixtyThreeBitIntegerWithASignBit") > cbg.MaxLength { + if uint64(len("SixtyThreeBitIntegerWithASignBit")) > cbg.MaxLength { return xerrors.Errorf("Value in field \"SixtyThreeBitIntegerWithASignBit\" was too long") } @@ -554,7 +554,7 @@ func (t *NeedScratchForMap) MarshalCBOR(w io.Writer) error { } // t.Thing (bool) (bool) - if len("Thing") > cbg.MaxLength { + if uint64(len("Thing")) > cbg.MaxLength { return xerrors.Errorf("Value in field \"Thing\" was too long") } @@ -649,7 +649,7 @@ func (t *SimpleStructV1) MarshalCBOR(w io.Writer) error { } // t.OldMap (map[string]testing.SimpleTypeOne) (map) - if len("OldMap") > cbg.MaxLength { + if uint64(len("OldMap")) > cbg.MaxLength { return xerrors.Errorf("Value in field \"OldMap\" was too long") } @@ -677,7 +677,7 @@ func (t *SimpleStructV1) MarshalCBOR(w io.Writer) error { for _, k := range keys { v := t.OldMap[k] - if len(k) > cbg.MaxLength { + if uint64(len(k)) > cbg.MaxLength { return xerrors.Errorf("Value in field k was too long") } @@ -696,7 +696,7 @@ func (t *SimpleStructV1) MarshalCBOR(w io.Writer) error { } // t.OldNum (uint64) (uint64) - if len("OldNum") > cbg.MaxLength { + if uint64(len("OldNum")) > cbg.MaxLength { return xerrors.Errorf("Value in field \"OldNum\" was too long") } @@ -712,7 +712,7 @@ func (t *SimpleStructV1) MarshalCBOR(w io.Writer) error { } // t.OldPtr (cid.Cid) (struct) - if len("OldPtr") > cbg.MaxLength { + if uint64(len("OldPtr")) > cbg.MaxLength { return xerrors.Errorf("Value in field \"OldPtr\" was too long") } @@ -734,7 +734,7 @@ func (t *SimpleStructV1) MarshalCBOR(w io.Writer) error { } // t.OldStr (string) (string) - if len("OldStr") > cbg.MaxLength { + if uint64(len("OldStr")) > cbg.MaxLength { return xerrors.Errorf("Value in field \"OldStr\" was too long") } @@ -745,7 +745,7 @@ func (t *SimpleStructV1) MarshalCBOR(w io.Writer) error { return err } - if len(t.OldStr) > cbg.MaxLength { + if uint64(len(t.OldStr)) > cbg.MaxLength { return xerrors.Errorf("Value in field t.OldStr was too long") } @@ -757,7 +757,7 @@ func (t *SimpleStructV1) MarshalCBOR(w io.Writer) error { } // t.OldArray ([]testing.SimpleTypeOne) (slice) - if len("OldArray") > cbg.MaxLength { + if uint64(len("OldArray")) > cbg.MaxLength { return xerrors.Errorf("Value in field \"OldArray\" was too long") } @@ -768,7 +768,7 @@ func (t *SimpleStructV1) MarshalCBOR(w io.Writer) error { return err } - if len(t.OldArray) > cbg.MaxLength { + if uint64(len(t.OldArray)) > cbg.MaxLength { return xerrors.Errorf("Slice value in field t.OldArray was too long") } @@ -783,7 +783,7 @@ func (t *SimpleStructV1) MarshalCBOR(w io.Writer) error { } // t.OldBytes ([]uint8) (slice) - if len("OldBytes") > cbg.MaxLength { + if uint64(len("OldBytes")) > cbg.MaxLength { return xerrors.Errorf("Value in field \"OldBytes\" was too long") } @@ -794,7 +794,7 @@ func (t *SimpleStructV1) MarshalCBOR(w io.Writer) error { return err } - if len(t.OldBytes) > cbg.ByteArrayMaxLen { + if uint64(len(t.OldBytes)) > cbg.ByteArrayMaxLen { return xerrors.Errorf("Byte array in field t.OldBytes was too long") } @@ -807,7 +807,7 @@ func (t *SimpleStructV1) MarshalCBOR(w io.Writer) error { } // t.OldStruct (testing.SimpleTypeOne) (struct) - if len("OldStruct") > cbg.MaxLength { + if uint64(len("OldStruct")) > cbg.MaxLength { return xerrors.Errorf("Value in field \"OldStruct\" was too long") } @@ -823,7 +823,7 @@ func (t *SimpleStructV1) MarshalCBOR(w io.Writer) error { } // t.OldCidArray ([]cid.Cid) (slice) - if len("OldCidArray") > cbg.MaxLength { + if uint64(len("OldCidArray")) > cbg.MaxLength { return xerrors.Errorf("Value in field \"OldCidArray\" was too long") } @@ -834,7 +834,7 @@ func (t *SimpleStructV1) MarshalCBOR(w io.Writer) error { return err } - if len(t.OldCidArray) > cbg.MaxLength { + if uint64(len(t.OldCidArray)) > cbg.MaxLength { return xerrors.Errorf("Slice value in field t.OldCidArray was too long") } @@ -850,7 +850,7 @@ func (t *SimpleStructV1) MarshalCBOR(w io.Writer) error { } // t.OldCidPtrArray ([]*cid.Cid) (slice) - if len("OldCidPtrArray") > cbg.MaxLength { + if uint64(len("OldCidPtrArray")) > cbg.MaxLength { return xerrors.Errorf("Value in field \"OldCidPtrArray\" was too long") } @@ -861,7 +861,7 @@ func (t *SimpleStructV1) MarshalCBOR(w io.Writer) error { return err } - if len(t.OldCidPtrArray) > cbg.MaxLength { + if uint64(len(t.OldCidPtrArray)) > cbg.MaxLength { return xerrors.Errorf("Slice value in field t.OldCidPtrArray was too long") } @@ -1201,7 +1201,7 @@ func (t *SimpleStructV2) MarshalCBOR(w io.Writer) error { } // t.NewMap (map[string]testing.SimpleTypeOne) (map) - if len("NewMap") > cbg.MaxLength { + if uint64(len("NewMap")) > cbg.MaxLength { return xerrors.Errorf("Value in field \"NewMap\" was too long") } @@ -1229,7 +1229,7 @@ func (t *SimpleStructV2) MarshalCBOR(w io.Writer) error { for _, k := range keys { v := t.NewMap[k] - if len(k) > cbg.MaxLength { + if uint64(len(k)) > cbg.MaxLength { return xerrors.Errorf("Value in field k was too long") } @@ -1248,7 +1248,7 @@ func (t *SimpleStructV2) MarshalCBOR(w io.Writer) error { } // t.NewNum (uint64) (uint64) - if len("NewNum") > cbg.MaxLength { + if uint64(len("NewNum")) > cbg.MaxLength { return xerrors.Errorf("Value in field \"NewNum\" was too long") } @@ -1264,7 +1264,7 @@ func (t *SimpleStructV2) MarshalCBOR(w io.Writer) error { } // t.NewPtr (cid.Cid) (struct) - if len("NewPtr") > cbg.MaxLength { + if uint64(len("NewPtr")) > cbg.MaxLength { return xerrors.Errorf("Value in field \"NewPtr\" was too long") } @@ -1286,7 +1286,7 @@ func (t *SimpleStructV2) MarshalCBOR(w io.Writer) error { } // t.NewStr (string) (string) - if len("NewStr") > cbg.MaxLength { + if uint64(len("NewStr")) > cbg.MaxLength { return xerrors.Errorf("Value in field \"NewStr\" was too long") } @@ -1297,7 +1297,7 @@ func (t *SimpleStructV2) MarshalCBOR(w io.Writer) error { return err } - if len(t.NewStr) > cbg.MaxLength { + if uint64(len(t.NewStr)) > cbg.MaxLength { return xerrors.Errorf("Value in field t.NewStr was too long") } @@ -1309,7 +1309,7 @@ func (t *SimpleStructV2) MarshalCBOR(w io.Writer) error { } // t.OldMap (map[string]testing.SimpleTypeOne) (map) - if len("OldMap") > cbg.MaxLength { + if uint64(len("OldMap")) > cbg.MaxLength { return xerrors.Errorf("Value in field \"OldMap\" was too long") } @@ -1337,7 +1337,7 @@ func (t *SimpleStructV2) MarshalCBOR(w io.Writer) error { for _, k := range keys { v := t.OldMap[k] - if len(k) > cbg.MaxLength { + if uint64(len(k)) > cbg.MaxLength { return xerrors.Errorf("Value in field k was too long") } @@ -1356,7 +1356,7 @@ func (t *SimpleStructV2) MarshalCBOR(w io.Writer) error { } // t.OldNum (uint64) (uint64) - if len("OldNum") > cbg.MaxLength { + if uint64(len("OldNum")) > cbg.MaxLength { return xerrors.Errorf("Value in field \"OldNum\" was too long") } @@ -1372,7 +1372,7 @@ func (t *SimpleStructV2) MarshalCBOR(w io.Writer) error { } // t.OldPtr (cid.Cid) (struct) - if len("OldPtr") > cbg.MaxLength { + if uint64(len("OldPtr")) > cbg.MaxLength { return xerrors.Errorf("Value in field \"OldPtr\" was too long") } @@ -1394,7 +1394,7 @@ func (t *SimpleStructV2) MarshalCBOR(w io.Writer) error { } // t.OldStr (string) (string) - if len("OldStr") > cbg.MaxLength { + if uint64(len("OldStr")) > cbg.MaxLength { return xerrors.Errorf("Value in field \"OldStr\" was too long") } @@ -1405,7 +1405,7 @@ func (t *SimpleStructV2) MarshalCBOR(w io.Writer) error { return err } - if len(t.OldStr) > cbg.MaxLength { + if uint64(len(t.OldStr)) > cbg.MaxLength { return xerrors.Errorf("Value in field t.OldStr was too long") } @@ -1417,7 +1417,7 @@ func (t *SimpleStructV2) MarshalCBOR(w io.Writer) error { } // t.NewArray ([]testing.SimpleTypeOne) (slice) - if len("NewArray") > cbg.MaxLength { + if uint64(len("NewArray")) > cbg.MaxLength { return xerrors.Errorf("Value in field \"NewArray\" was too long") } @@ -1428,7 +1428,7 @@ func (t *SimpleStructV2) MarshalCBOR(w io.Writer) error { return err } - if len(t.NewArray) > cbg.MaxLength { + if uint64(len(t.NewArray)) > cbg.MaxLength { return xerrors.Errorf("Slice value in field t.NewArray was too long") } @@ -1443,7 +1443,7 @@ func (t *SimpleStructV2) MarshalCBOR(w io.Writer) error { } // t.NewBytes ([]uint8) (slice) - if len("NewBytes") > cbg.MaxLength { + if uint64(len("NewBytes")) > cbg.MaxLength { return xerrors.Errorf("Value in field \"NewBytes\" was too long") } @@ -1454,7 +1454,7 @@ func (t *SimpleStructV2) MarshalCBOR(w io.Writer) error { return err } - if len(t.NewBytes) > cbg.ByteArrayMaxLen { + if uint64(len(t.NewBytes)) > cbg.ByteArrayMaxLen { return xerrors.Errorf("Byte array in field t.NewBytes was too long") } @@ -1467,7 +1467,7 @@ func (t *SimpleStructV2) MarshalCBOR(w io.Writer) error { } // t.OldArray ([]testing.SimpleTypeOne) (slice) - if len("OldArray") > cbg.MaxLength { + if uint64(len("OldArray")) > cbg.MaxLength { return xerrors.Errorf("Value in field \"OldArray\" was too long") } @@ -1478,7 +1478,7 @@ func (t *SimpleStructV2) MarshalCBOR(w io.Writer) error { return err } - if len(t.OldArray) > cbg.MaxLength { + if uint64(len(t.OldArray)) > cbg.MaxLength { return xerrors.Errorf("Slice value in field t.OldArray was too long") } @@ -1493,7 +1493,7 @@ func (t *SimpleStructV2) MarshalCBOR(w io.Writer) error { } // t.OldBytes ([]uint8) (slice) - if len("OldBytes") > cbg.MaxLength { + if uint64(len("OldBytes")) > cbg.MaxLength { return xerrors.Errorf("Value in field \"OldBytes\" was too long") } @@ -1504,7 +1504,7 @@ func (t *SimpleStructV2) MarshalCBOR(w io.Writer) error { return err } - if len(t.OldBytes) > cbg.ByteArrayMaxLen { + if uint64(len(t.OldBytes)) > cbg.ByteArrayMaxLen { return xerrors.Errorf("Byte array in field t.OldBytes was too long") } @@ -1517,7 +1517,7 @@ func (t *SimpleStructV2) MarshalCBOR(w io.Writer) error { } // t.NewStruct (testing.SimpleTypeOne) (struct) - if len("NewStruct") > cbg.MaxLength { + if uint64(len("NewStruct")) > cbg.MaxLength { return xerrors.Errorf("Value in field \"NewStruct\" was too long") } @@ -1533,7 +1533,7 @@ func (t *SimpleStructV2) MarshalCBOR(w io.Writer) error { } // t.OldStruct (testing.SimpleTypeOne) (struct) - if len("OldStruct") > cbg.MaxLength { + if uint64(len("OldStruct")) > cbg.MaxLength { return xerrors.Errorf("Value in field \"OldStruct\" was too long") } @@ -1936,7 +1936,7 @@ func (t *RenamedFields) MarshalCBOR(w io.Writer) error { } // t.Foo (int64) (int64) - if len("foo") > cbg.MaxLength { + if uint64(len("foo")) > cbg.MaxLength { return xerrors.Errorf("Value in field \"foo\" was too long") } @@ -1958,7 +1958,7 @@ func (t *RenamedFields) MarshalCBOR(w io.Writer) error { } // t.Bar (string) (string) - if len("beep") > cbg.MaxLength { + if uint64(len("beep")) > cbg.MaxLength { return xerrors.Errorf("Value in field \"beep\" was too long") } @@ -1969,7 +1969,7 @@ func (t *RenamedFields) MarshalCBOR(w io.Writer) error { return err } - if len(t.Bar) > cbg.MaxLength { + if uint64(len(t.Bar)) > cbg.MaxLength { return xerrors.Errorf("Value in field t.Bar was too long") } @@ -2088,7 +2088,7 @@ func (t *TestEmpty) MarshalCBOR(w io.Writer) error { } // t.Cat (int64) (int64) - if len("Cat") > cbg.MaxLength { + if uint64(len("Cat")) > cbg.MaxLength { return xerrors.Errorf("Value in field \"Cat\" was too long") } @@ -2112,7 +2112,7 @@ func (t *TestEmpty) MarshalCBOR(w io.Writer) error { // t.Foo (string) (string) if t.Foo != nil { - if len("Foo") > cbg.MaxLength { + if uint64(len("Foo")) > cbg.MaxLength { return xerrors.Errorf("Value in field \"Foo\" was too long") } @@ -2128,7 +2128,7 @@ func (t *TestEmpty) MarshalCBOR(w io.Writer) error { return err } } else { - if len(*t.Foo) > cbg.MaxLength { + if uint64(len(*t.Foo)) > cbg.MaxLength { return xerrors.Errorf("Value in field t.Foo was too long") } @@ -2144,7 +2144,7 @@ func (t *TestEmpty) MarshalCBOR(w io.Writer) error { // t.Beep (string) (string) if t.Beep != "" { - if len("Beep") > cbg.MaxLength { + if uint64(len("Beep")) > cbg.MaxLength { return xerrors.Errorf("Value in field \"Beep\" was too long") } @@ -2155,7 +2155,7 @@ func (t *TestEmpty) MarshalCBOR(w io.Writer) error { return err } - if len(t.Beep) > cbg.MaxLength { + if uint64(len(t.Beep)) > cbg.MaxLength { return xerrors.Errorf("Value in field t.Beep was too long") } @@ -2287,7 +2287,7 @@ func (t *TestConstField) MarshalCBOR(w io.Writer) error { } // t.Cats (string) (string) - if len("Cats") > cbg.MaxLength { + if uint64(len("Cats")) > cbg.MaxLength { return xerrors.Errorf("Value in field \"Cats\" was too long") } @@ -2306,7 +2306,7 @@ func (t *TestConstField) MarshalCBOR(w io.Writer) error { } // t.Thing (int64) (int64) - if len("Thing") > cbg.MaxLength { + if uint64(len("Thing")) > cbg.MaxLength { return xerrors.Errorf("Value in field \"Thing\" was too long") } @@ -2426,7 +2426,7 @@ func (t *TestCanonicalFieldOrder) MarshalCBOR(w io.Writer) error { } // t.Zp (string) (string) - if len("ap") > cbg.MaxLength { + if uint64(len("ap")) > cbg.MaxLength { return xerrors.Errorf("Value in field \"ap\" was too long") } @@ -2437,7 +2437,7 @@ func (t *TestCanonicalFieldOrder) MarshalCBOR(w io.Writer) error { return err } - if len(t.Zp) > cbg.MaxLength { + if uint64(len(t.Zp)) > cbg.MaxLength { return xerrors.Errorf("Value in field t.Zp was too long") } @@ -2449,7 +2449,7 @@ func (t *TestCanonicalFieldOrder) MarshalCBOR(w io.Writer) error { } // t.Foo (int64) (int64) - if len("foo") > cbg.MaxLength { + if uint64(len("foo")) > cbg.MaxLength { return xerrors.Errorf("Value in field \"foo\" was too long") } @@ -2471,7 +2471,7 @@ func (t *TestCanonicalFieldOrder) MarshalCBOR(w io.Writer) error { } // t.Bar (string) (string) - if len("beep") > cbg.MaxLength { + if uint64(len("beep")) > cbg.MaxLength { return xerrors.Errorf("Value in field \"beep\" was too long") } @@ -2482,7 +2482,7 @@ func (t *TestCanonicalFieldOrder) MarshalCBOR(w io.Writer) error { return err } - if len(t.Bar) > cbg.MaxLength { + if uint64(len(t.Bar)) > cbg.MaxLength { return xerrors.Errorf("Value in field t.Bar was too long") } @@ -2494,7 +2494,7 @@ func (t *TestCanonicalFieldOrder) MarshalCBOR(w io.Writer) error { } // t.Drond (int64) (int64) - if len("Drond") > cbg.MaxLength { + if uint64(len("Drond")) > cbg.MaxLength { return xerrors.Errorf("Value in field \"Drond\" was too long") } @@ -2651,7 +2651,7 @@ func (t *MapStringString) MarshalCBOR(w io.Writer) error { } // t.Snorkleblump (map[string]string) (map) - if len("Snorkleblump") > cbg.MaxLength { + if uint64(len("Snorkleblump")) > cbg.MaxLength { return xerrors.Errorf("Value in field \"Snorkleblump\" was too long") } @@ -2679,7 +2679,7 @@ func (t *MapStringString) MarshalCBOR(w io.Writer) error { for _, k := range keys { v := t.Snorkleblump[k] - if len(k) > cbg.MaxLength { + if uint64(len(k)) > cbg.MaxLength { return xerrors.Errorf("Value in field k was too long") } @@ -2690,7 +2690,7 @@ func (t *MapStringString) MarshalCBOR(w io.Writer) error { return err } - if len(v) > cbg.MaxLength { + if uint64(len(v)) > cbg.MaxLength { return xerrors.Errorf("Value in field v was too long") } @@ -2809,7 +2809,7 @@ func (t *TestSliceNilPreserve) MarshalCBOR(w io.Writer) error { } // t.Cat (string) (string) - if len("Cat") > cbg.MaxLength { + if uint64(len("Cat")) > cbg.MaxLength { return xerrors.Errorf("Value in field \"Cat\" was too long") } @@ -2820,7 +2820,7 @@ func (t *TestSliceNilPreserve) MarshalCBOR(w io.Writer) error { return err } - if len(t.Cat) > cbg.MaxLength { + if uint64(len(t.Cat)) > cbg.MaxLength { return xerrors.Errorf("Value in field t.Cat was too long") } @@ -2832,7 +2832,7 @@ func (t *TestSliceNilPreserve) MarshalCBOR(w io.Writer) error { } // t.Not ([]uint64) (slice) - if len("Not") > cbg.MaxLength { + if uint64(len("Not")) > cbg.MaxLength { return xerrors.Errorf("Value in field \"Not\" was too long") } @@ -2843,7 +2843,7 @@ func (t *TestSliceNilPreserve) MarshalCBOR(w io.Writer) error { return err } - if len(t.Not) > cbg.MaxLength { + if uint64(len(t.Not)) > cbg.MaxLength { return xerrors.Errorf("Slice value in field t.Not was too long") } @@ -2868,7 +2868,7 @@ func (t *TestSliceNilPreserve) MarshalCBOR(w io.Writer) error { } // t.Beep (int64) (int64) - if len("Beep") > cbg.MaxLength { + if uint64(len("Beep")) > cbg.MaxLength { return xerrors.Errorf("Value in field \"Beep\" was too long") } @@ -2890,7 +2890,7 @@ func (t *TestSliceNilPreserve) MarshalCBOR(w io.Writer) error { } // t.Other ([]uint8) (slice) - if len("Other") > cbg.MaxLength { + if uint64(len("Other")) > cbg.MaxLength { return xerrors.Errorf("Value in field \"Other\" was too long") } @@ -2901,7 +2901,7 @@ func (t *TestSliceNilPreserve) MarshalCBOR(w io.Writer) error { return err } - if len(t.Other) > cbg.ByteArrayMaxLen { + if uint64(len(t.Other)) > cbg.ByteArrayMaxLen { return xerrors.Errorf("Byte array in field t.Other was too long") } @@ -2914,7 +2914,7 @@ func (t *TestSliceNilPreserve) MarshalCBOR(w io.Writer) error { } // t.Stuff ([]uint64) (slice) - if len("Stuff") > cbg.MaxLength { + if uint64(len("Stuff")) > cbg.MaxLength { return xerrors.Errorf("Value in field \"Stuff\" was too long") } @@ -2925,7 +2925,7 @@ func (t *TestSliceNilPreserve) MarshalCBOR(w io.Writer) error { return err } - if len(t.Stuff) > cbg.MaxLength { + if uint64(len(t.Stuff)) > cbg.MaxLength { return xerrors.Errorf("Slice value in field t.Stuff was too long") } @@ -2941,7 +2941,7 @@ func (t *TestSliceNilPreserve) MarshalCBOR(w io.Writer) error { } // t.NotOther ([]uint8) (slice) - if len("NotOther") > cbg.MaxLength { + if uint64(len("NotOther")) > cbg.MaxLength { return xerrors.Errorf("Value in field \"NotOther\" was too long") } @@ -2952,7 +2952,7 @@ func (t *TestSliceNilPreserve) MarshalCBOR(w io.Writer) error { return err } - if len(t.NotOther) > cbg.ByteArrayMaxLen { + if uint64(len(t.NotOther)) > cbg.ByteArrayMaxLen { return xerrors.Errorf("Byte array in field t.NotOther was too long") }