Repository navigation
Add noduplicates directive #438
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
+1,556
−30
Merged
Changes from 1 commit
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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"` | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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"` | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.