msgpack
msgpack copied to clipboard
Feature request: option to sort all map-like constructs
This could use an option to sort all map-like constructs including struct members. This would allow you to use this in combination with hashing and signature algorithms to reproducibly sign structs, and those signatures would remain valid even if the order of struct keys changed (as long as their names remained the same). As it stands I think the order of struct entries in the serialized output is undefined.
Struct fields are encoded in the order they are defined and order does not change as long as you don't re-order struct fields. I don't mind adding SortStructFields
option because it is trivial to implement but TBH I don't think it will be widely useful.
For maps we have SortMapKeys which is implemented only for certain map types. I think we can some general implementation if there is a need.
It's useful if you want to have repeatable encoding where msgpack-encoded records will always hash / checksum the same even if someone editing source reorders the fields in a struct.