Skip to content

Commit 0146c03

Browse files
authored
Fix limits and combinations with other params (#424)
* Fix limits and combinations with other params * Read header before decoding (effectively unrolls reads) * Fix duplicated error checks * Limited fields now reuse destiantion registers if possible. * Add (generated) tests. Removes output changes from 1.5.0 (tested against larger codebase) * We already handled nil, no need for special case. * Simplify more.
1 parent 00e7bb0 commit 0146c03

File tree

5 files changed

+825
-72
lines changed

5 files changed

+825
-72
lines changed

_generated/def.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@ type Fixed struct {
3131
B bool
3232
}
3333

34+
type StandaloneBytes []byte
35+
3436
type AliasedType = Fixed
3537
type AliasedType2 = *Fixed
3638
type AliasedType3 = uint64

_generated/limits.go

Lines changed: 34 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,38 @@ type LimitTestData struct {
2626
// Test field limits vs file limits precedence
2727
// File limits: arrays:100 maps:50
2828
type FieldOverrideTestData struct {
29-
TightSlice []int `msg:"tight_slice,limit=10"` // Field limit (10) < file limit (100)
30-
LooseSlice []string `msg:"loose_slice,limit=200"` // Field limit (200) > file limit (100)
31-
TightMap map[string]int `msg:"tight_map,limit=5"` // Field limit (5) < file limit (50)
32-
LooseMap map[int]string `msg:"loose_map,limit=80"` // Field limit (80) > file limit (50)
33-
DefaultSlice []byte `msg:"default_slice"` // No field limit, uses file limit (100)
34-
DefaultMap map[string]string `msg:"default_map"` // No field limit, uses file limit (50)
29+
TightSlice []int `msg:"tight_slice,limit=10"` // Field limit (10) < file limit (100)
30+
LooseSlice []string `msg:"loose_slice,limit=200"` // Field limit (200) > file limit (100)
31+
TightMap map[string]int `msg:"tight_map,limit=5"` // Field limit (5) < file limit (50)
32+
LooseMap map[int]string `msg:"loose_map,limit=80"` // Field limit (80) > file limit (50)
33+
DefaultSlice []byte `msg:"default_slice"` // No field limit, uses file limit (100)
34+
DefaultMap map[string]string `msg:"default_map"` // No field limit, uses file limit (50)
3535
}
36+
37+
// Test allownil functionality with limits
38+
// File limits: arrays:100 maps:50
39+
type AllowNilTestData struct {
40+
NilSlice []byte `msg:"nil_slice,allownil"` // Can be nil, uses file limit (100)
41+
NilTightSlice []int `msg:"nil_tight_slice,allownil,limit=5"` // Can be nil, field limit (5) < file limit (100)
42+
NilLooseSlice []string `msg:"nil_loose_slice,allownil,limit=200"` // Can be nil, field limit (200) > file limit (100)
43+
NilZCSlice []byte `msg:"nil_zc_slice,allownil,zerocopy"` // Can be nil, zerocopy, uses file limit (100)
44+
NilZCTightSlice []byte `msg:"nil_zc_tight_slice,allownil,zerocopy,limit=5"` // Can be nil, zerocopy, field limit (5)
45+
NilMap map[string]int `msg:"nil_map,allownil"` // Can be nil, uses file limit (50)
46+
NilTightMap map[string]int `msg:"nil_tight_map,allownil,limit=3"` // Can be nil, field limit (3) < file limit (50)
47+
NilLooseMap map[int]string `msg:"nil_loose_map,allownil,limit=75"` // Can be nil, field limit (75) > file limit (50)
48+
RegularSlice []byte `msg:"regular_slice"` // Cannot be nil, uses file limit (100)
49+
RegularMap map[string]int `msg:"regular_map"` // Cannot be nil, uses file limit (50)
50+
ObjSlice []LimitedData `msg:"obj_slice"` // Cannot be nil, uses file limit (100)
51+
ObjMap map[string]LimitedData `msg:"obj_map"` // Cannot be nil, uses file limit (50)
52+
}
53+
54+
type ObjSlices []LimitedData
55+
type ObjMaps map[string]LimitedData
56+
57+
// Test allownil with zero-sized allocations
58+
type AllowNilZeroTestData struct {
59+
NilBytes []byte `msg:"nil_bytes,allownil"` // Can be nil, should allocate zero-sized slice
60+
RegularBytes []byte `msg:"regular_bytes"` // Cannot be nil
61+
}
62+
63+
type StandaloneBytesLimited []byte

0 commit comments

Comments
 (0)