3Hren/msgpack-rust

Support for deterministic serialization

mehcode opened this issue · 3 comments

Is it possible to add a flag or similar to rmp-serde that would tweak the code generation to sort the map keys before encoding?

At the moment, we are using rmp directly as the fields must be sorted A-Z for hashing of the resultant binary to equal the equivalent serialization from Go.

Can you use BTreeMap?

Sorry by "Map" I meant the Map in MsgPack which structs become when you do to_vec_named. The struct fields aren't sorted when they are serialized.

I don't see a simple way to implement this. Fields are serialized from a callback in SerializeStruct::serialize_field, so it keeps Serde's order.

If you control the structs, sort their fields.

https://stackoverflow.com/questions/67789198/how-can-i-sort-fields-in-alphabetic-order-when-serializing-with-serde

Otherwise you can try parsing as rmpv::Value (add with-value feature), and manipulate raw msgpack model they way you want.