Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion _generated/def.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ type X struct {
type TestType struct {
F *float64 `msg:"float"`
Els map[string]string `msg:"elements"`
Obj struct { // test anonymous struct
Obj struct { // test anonymous struct
ValueA string `msg:"value_a"`
ValueB []byte `msg:"value_b"`
} `msg:"object"`
Expand Down
4 changes: 2 additions & 2 deletions _generated/field_limits.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ type FieldLimitTestData struct {
LargeSlice []string `msg:"large_slice,limit=100"`
SmallMap map[string]int `msg:"small_map,limit=3"`
LargeMap map[int]string `msg:"large_map,limit=20"`
NoLimit []byte `msg:"no_limit"` // Uses file-level limits if any
NoLimit []byte `msg:"no_limit"` // Uses file-level limits if any
FixedArray [10]int `msg:"fixed_array,limit=2"` // Should be ignored
}

Expand All @@ -25,4 +25,4 @@ type AliasedFieldLimitTestData struct {
LargeAliasedMap AliasedMap `msg:"large_aliased_map,limit=25"`
IntSliceAlias AliasedIntSlice `msg:"int_slice_alias,limit=10"`
NoLimitAlias AliasedSlice `msg:"no_limit_alias"` // Uses file-level limits
}
}
20 changes: 10 additions & 10 deletions _generated/limits_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1027,7 +1027,7 @@ func TestAllowNilSecurityLimits(t *testing.T) {

// Try to send bytes that exceed file limit (100)
buf := msgp.AppendMapHeader(nil, 1)
buf = msgp.AppendString(buf, "nil_slice") // Uses file limit (100)
buf = msgp.AppendString(buf, "nil_slice") // Uses file limit (100)
buf = msgp.AppendBytes(buf, make([]byte, 150)) // Exceeds limit

_, err := data.UnmarshalMsg(buf)
Expand All @@ -1041,7 +1041,7 @@ func TestAllowNilSecurityLimits(t *testing.T) {

// Try to send bytes that exceed file limit (100)
buf := msgp.AppendMapHeader(nil, 1)
buf = msgp.AppendString(buf, "nil_slice") // Uses file limit (100)
buf = msgp.AppendString(buf, "nil_slice") // Uses file limit (100)
buf = msgp.AppendBytes(buf, make([]byte, 150)) // Exceeds limit

reader := msgp.NewReader(bytes.NewReader(buf))
Expand All @@ -1057,7 +1057,7 @@ func TestAllowNilSecurityLimits(t *testing.T) {
// Try to send slice that exceeds field limit
buf := msgp.AppendMapHeader(nil, 1)
buf = msgp.AppendString(buf, "nil_tight_slice") // Field limit = 5
buf = msgp.AppendArrayHeader(buf, 8) // Exceeds field limit
buf = msgp.AppendArrayHeader(buf, 8) // Exceeds field limit
for i := 0; i < 8; i++ {
buf = msgp.AppendInt(buf, i)
}
Expand All @@ -1074,7 +1074,7 @@ func TestAllowNilSecurityLimits(t *testing.T) {
// Try to send slice that exceeds field limit
buf := msgp.AppendMapHeader(nil, 1)
buf = msgp.AppendString(buf, "nil_tight_slice") // Field limit = 5
buf = msgp.AppendArrayHeader(buf, 8) // Exceeds field limit
buf = msgp.AppendArrayHeader(buf, 8) // Exceeds field limit
for i := 0; i < 8; i++ {
buf = msgp.AppendInt(buf, i)
}
Expand All @@ -1092,7 +1092,7 @@ func TestAllowNilSecurityLimits(t *testing.T) {
// Try to send map that exceeds field limit
buf := msgp.AppendMapHeader(nil, 1)
buf = msgp.AppendString(buf, "nil_tight_map") // Field limit = 3
buf = msgp.AppendMapHeader(buf, 5) // Exceeds field limit
buf = msgp.AppendMapHeader(buf, 5) // Exceeds field limit
for i := 0; i < 5; i++ {
buf = msgp.AppendString(buf, fmt.Sprintf("key%d", i))
buf = msgp.AppendInt(buf, i)
Expand All @@ -1110,7 +1110,7 @@ func TestAllowNilSecurityLimits(t *testing.T) {
// Try to send map that exceeds field limit
buf := msgp.AppendMapHeader(nil, 1)
buf = msgp.AppendString(buf, "nil_tight_map") // Field limit = 3
buf = msgp.AppendMapHeader(buf, 5) // Exceeds field limit
buf = msgp.AppendMapHeader(buf, 5) // Exceeds field limit
for i := 0; i < 5; i++ {
buf = msgp.AppendString(buf, fmt.Sprintf("key%d", i))
buf = msgp.AppendInt(buf, i)
Expand All @@ -1134,7 +1134,7 @@ func TestAllowNilSecurityLimits(t *testing.T) {

// Manually craft a message with a huge size header but don't include the data
// This should fail at the limit check, not during data reading
buf = append(buf, 0xc6) // bin32 format
buf = append(buf, 0xc6) // bin32 format
buf = append(buf, 0x00, 0x00, 0x27, 0x10) // size = 10000 (exceeds limit of 100)
// Don't append actual data - should fail before trying to read it

Expand All @@ -1155,7 +1155,7 @@ func TestAllowNilSecurityLimits(t *testing.T) {

// Manually craft a message with a huge size header but don't include the data
// This should fail at the limit check, not during data reading
buf = append(buf, 0xc6) // bin32 format
buf = append(buf, 0xc6) // bin32 format
buf = append(buf, 0x00, 0x00, 0x27, 0x10) // size = 10000 (exceeds limit of 100)
// Don't append actual data - should fail before trying to read it

Expand Down Expand Up @@ -1267,7 +1267,7 @@ func TestAllowNilZeroCopy(t *testing.T) {
buf = msgp.AppendString(buf, "nil_zc_slice")

// Manually craft message with huge header but no data
buf = append(buf, 0xc6) // bin32 format
buf = append(buf, 0xc6) // bin32 format
buf = append(buf, 0x00, 0x00, 0x27, 0x10) // size = 10000 (exceeds limit)

_, err := data.UnmarshalMsg(buf)
Expand Down Expand Up @@ -1375,7 +1375,7 @@ func TestAllowNilZeroCopy(t *testing.T) {
buf = msgp.AppendString(buf, "nil_zc_slice")

// Manually craft message with huge header but no data
buf = append(buf, 0xc6) // bin32 format
buf = append(buf, 0xc6) // bin32 format
buf = append(buf, 0x00, 0x00, 0x27, 0x10) // size = 10000 (exceeds limit)

reader := msgp.NewReader(bytes.NewReader(buf))
Expand Down
12 changes: 6 additions & 6 deletions _generated/marshal_limits.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@ type MarshalLimitTestData struct {
// Test field limits vs file limits precedence with marshal:true
// File limits: arrays:30 maps:20 marshal:true
type MarshalFieldOverrideTestData struct {
TightSlice []int `msg:"tight_slice,limit=10"` // Field limit (10) < file limit (30)
LooseSlice []string `msg:"loose_slice,limit=50"` // Field limit (50) > file limit (30)
TightMap map[string]int `msg:"tight_map,limit=5"` // Field limit (5) < file limit (20)
LooseMap map[int]string `msg:"loose_map,limit=40"` // Field limit (40) > file limit (20)
DefaultSlice []byte `msg:"default_slice"` // No field limit, uses file limit (30)
DefaultMap map[string]byte `msg:"default_map"` // No field limit, uses file limit (20)
TightSlice []int `msg:"tight_slice,limit=10"` // Field limit (10) < file limit (30)
LooseSlice []string `msg:"loose_slice,limit=50"` // Field limit (50) > file limit (30)
TightMap map[string]int `msg:"tight_map,limit=5"` // Field limit (5) < file limit (20)
LooseMap map[int]string `msg:"loose_map,limit=40"` // Field limit (40) > file limit (20)
DefaultSlice []byte `msg:"default_slice"` // No field limit, uses file limit (30)
DefaultMap map[string]byte `msg:"default_map"` // No field limit, uses file limit (20)
}
97 changes: 97 additions & 0 deletions _generated/noduplicates.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
//msgp:noduplicates

package _generated

//go:generate msgp

// NoDupSimple is a basic struct with a few fields.
type NoDupSimple struct {
Foo string `msg:"Foo"`
Bar int `msg:"Bar"`
Baz bool `msg:"Baz"`
}

// NoDupMap is a standalone map type.
type NoDupMap map[string]string

// NoDupNested has a struct with a map field.
type NoDupNested struct {
Name string `msg:"Name"`
Items map[string]int `msg:"Items"`
Tags map[string]string `msg:"Tags"`
}

// NoDupManyFields exercises the bitmask across byte boundaries (>8 fields).
type NoDupManyFields struct {
F01 string `msg:"f01"`
F02 string `msg:"f02"`
F03 string `msg:"f03"`
F04 string `msg:"f04"`
F05 string `msg:"f05"`
F06 string `msg:"f06"`
F07 string `msg:"f07"`
F08 string `msg:"f08"`
F09 string `msg:"f09"`
F10 string `msg:"f10"`
}

// NoDupMapInt is a map with int values.
type NoDupMapInt map[string]int

// NoDupRichTypes covers pointer, slice, bytes, float, and nested struct fields.
type NoDupRichTypes struct {
Str string `msg:"str"`
Num float64 `msg:"num"`
Data []byte `msg:"data"`
PtrStr *string `msg:"ptr_str"`
Strings []string `msg:"strings"`
Inner NoDupInner `msg:"inner"`
PtrInner *NoDupInner `msg:"ptr_inner"`
MapSlice map[string][]int `msg:"map_slice"`
}

// NoDupInner is used as a nested struct field.
type NoDupInner struct {
X int `msg:"x"`
Y string `msg:"y"`
}

// NoDupOmitempty has omitempty fields mixed with regular fields.
type NoDupOmitempty struct {
Required string `msg:"required"`
Optional string `msg:"optional,omitempty"`
Flag bool `msg:"flag,omitempty"`
Count int `msg:"count"`
}

// NoDupAllownil has allownil fields.
type NoDupAllownil struct {
Name string `msg:"name"`
Vals []byte `msg:"vals,allownil"`
Items []int `msg:"items,allownil"`
Mapping map[string]string `msg:"mapping,allownil"`
}

// NoDupMapComplex is a map with complex values.
type NoDupMapComplex map[string]NoDupInner

// NoDup17Fields tests 17 fields (3 bytes in bitmask).
type NoDup17Fields struct {
A01 int `msg:"a01"`
A02 int `msg:"a02"`
A03 int `msg:"a03"`
A04 int `msg:"a04"`
A05 int `msg:"a05"`
A06 int `msg:"a06"`
A07 int `msg:"a07"`
A08 int `msg:"a08"`
A09 int `msg:"a09"`
A10 int `msg:"a10"`
A11 int `msg:"a11"`
A12 int `msg:"a12"`
A13 int `msg:"a13"`
A14 int `msg:"a14"`
A15 int `msg:"a15"`
A16 int `msg:"a16"`
A17 int `msg:"a17"`
}
22 changes: 22 additions & 0 deletions _generated/noduplicates_binkey.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package _generated

//go:generate msgp -unexported -v

//msgp:maps binkeys
//msgp:noduplicates

// NoDupBinKeyInt is a map with int keys (binary-encoded).
type NoDupBinKeyInt map[int]string

// NoDupBinKeyUint32 is a map with uint32 keys (binary-encoded).
type NoDupBinKeyUint32 map[uint32]int

// NoDupBinKeyStruct has both string-keyed and binary-keyed maps.
type NoDupBinKeyStruct struct {
Name string `msg:"name"`
IntMap map[int]string `msg:"int_map"`
StrMap map[string]int `msg:"str_map"`
}

// NoDupBinKeyArray is a map with array keys.
type NoDupBinKeyArray map[[2]byte]int
26 changes: 26 additions & 0 deletions _generated/noduplicates_shim.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package _generated

import "strings"

//go:generate msgp -v

//msgp:maps shim
//msgp:noduplicates

//msgp:shim NoDupShimKey as:string using:noDupShimEnc/noDupShimDec

// NoDupShimKey is a key type that normalizes to lowercase.
type NoDupShimKey string

func noDupShimEnc(k NoDupShimKey) string { return strings.ToLower(string(k)) }
func noDupShimDec(s string) NoDupShimKey { return NoDupShimKey(strings.ToLower(s)) }

// NoDupShimMap is a map with shimmed keys that normalize to lowercase.
// Two different wire strings (e.g. "Foo" and "foo") shim to the same key.
type NoDupShimMap map[NoDupShimKey]int

// NoDupShimStruct has a shimmed-key map as a field.
type NoDupShimStruct struct {
Name string `msg:"name"`
Data map[NoDupShimKey]string `msg:"data"`
}
24 changes: 24 additions & 0 deletions _generated/noduplicates_specific.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package _generated

//go:generate msgp

//msgp:noduplicates NoDupTargeted NoDupTargetedMap

// NoDupTargeted has the directive applied - should reject duplicates.
type NoDupTargeted struct {
Alpha string `msg:"alpha"`
Beta int `msg:"beta"`
Gamma bool `msg:"gamma"`
}

// NoDupTargetedMap has the directive applied as a map type.
type NoDupTargetedMap map[string]int

// NoDupUntargeted does NOT have the directive - duplicates should be silently accepted.
type NoDupUntargeted struct {
Alpha string `msg:"alpha"`
Beta int `msg:"beta"`
}

// NoDupUntargetedMap does NOT have the directive - duplicates silently accepted.
type NoDupUntargetedMap map[string]string
Loading
Loading