Allow non-string-keyed maps by converting the keys#331
Closed
birneee wants to merge 3 commits intotinylib:masterfrom
Closed
Allow non-string-keyed maps by converting the keys#331birneee wants to merge 3 commits intotinylib:masterfrom
birneee wants to merge 3 commits intotinylib:masterfrom
Conversation
klauspost
added a commit
that referenced
this pull request
Aug 22, 2025
* Allows for binary map keys * Allows for non-string map keys to be shimmed as well as cast from string type aliases. * Allows automatic conversion of some map key types to/from string. Adds directive `maps` * `//msgp:maps binkeys|shim|autoshim` Not adding the directive will retain current behaviour where maps without string keys are ignored. Adding `binkeys` will allow for binary marshaling of map keys. Types are inferred with standard rules. Binary encoding can be shimmed and can return any standard type. See `_generated/map_bin_key.go` for examples. Adding `shim` will require you to add shims to custom map key types. Shims must be with string type. See `_generated/map_shim_key.go` for examples. Adding `autoshim` will add automatic shimming to map keys that are `uint, uint8, uint16, uint32, uint64, int, int8, int16, int32, int64, bool, float32, float64, byte` - so these are written as a string. Standard `strconv.Parse/Format` functions are used. Aliased types are not supported, but `msgp:replace MyInt with:int` directive can be used and this will be picked up. Adds `witherr:true|false` to `//msgp:shim` directives, so shim de-serializing can return errors. Updates/Resolves: #331 #345 #305 #257 #232 Quirks: * Sizing is not perfect and can sometimes be collapsed from a range to constant. * These maps are not currently readable by "Interface" functions.
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Non-string keys can be automatically converted to and from string by providing a NonStrMapKey interface implementation for that type.
Related to #232