Add binary map key and shimming#398
Merged
klauspost merged 3 commits intotinylib:masterfrom Aug 22, 2025
Merged
Conversation
* Allows for binary map keys * Allows for non-string map keys to be shimmed as well as cast from string type aliases. Adds directive `maps` * `//msgp:maps shim|binary` Not adding the directive will retain current behaviour where maps without string keys are ignored. 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 `binary` 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.
This was referenced Aug 10, 2025
Collaborator
Author
|
(considered adding automatic string shimming of built-in types as an option - as the stdlib json encoder does now, but leaving that for later) |
Collaborator
Author
|
Probably adding autoshim for Aliases may not be covered yet. |
Collaborator
Author
|
Added. top post updated. |
Collaborator
Author
|
@philhofer I will be merging this soon-ish unless you have major objections. |
This was referenced Aug 22, 2025
Closed
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.
Adds directive
maps//msgp:maps binkeys|shim|autoshimNot adding the directive will retain current behaviour where maps without string keys are ignored.
Adding
binkeyswill 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.gofor examples.Adding
shimwill require you to add shims to custom map key types. Shims must be with string type. See_generated/map_shim_key.gofor examples.Adding
autoshimwill add automatic shimming to map keys that areuint, uint8, uint16, uint32, uint64, int, int8, int16, int32, int64, bool, float32, float64, byte- so these are written as a string. Standardstrconv.Parse/Formatfunctions are used. Aliased types are not supported, butmsgp:replace MyInt with:intdirective can be used and this will be picked up.Adds
witherr:true|falseto//msgp:shimdirectives, so shim de-serializing can return errors.Updates/Resolves: #331 #345 #305 #257 #232
Quirks: