Skip to content

Conversation

@klauspost
Copy link
Collaborator

@klauspost klauspost commented Aug 10, 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.

* 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.
@klauspost
Copy link
Collaborator Author

klauspost commented Aug 10, 2025

(considered adding automatic string shimming of built-in types as an option - as the stdlib json encoder does now, but leaving that for later)

@klauspost
Copy link
Collaborator Author

klauspost commented Aug 13, 2025

Probably adding autoshim for Uint, Uint8, Uint16, Uint32, Uint64, Int, Int8, Int16, Int32, Int64, Bool, Float32, Float64 as map keys.

Aliases may not be covered yet.

@klauspost
Copy link
Collaborator Author

Added. top post updated.

@klauspost
Copy link
Collaborator Author

@philhofer I will be merging this soon-ish unless you have major objections.

@klauspost klauspost merged commit 60fdfdb into tinylib:master Aug 22, 2025
4 checks passed
@klauspost klauspost deleted the shim-map-keys branch August 22, 2025 10:22
This was referenced Aug 22, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant