-
Notifications
You must be signed in to change notification settings - Fork 19
Description
Description
In Go, the built-in map type does not guarantee iteration order. When unmarshaling data structures (such as those encoded via MessagePack), the key iteration order of a map is non-deterministic. This is often acceptable for many use cases, but in some scenarios, preserving the original key order is essential.
My use case involves processing MessagePack data where the ordering of keys carries semantic meaning (e.g., Convert msgpack data into JSON data). For these cases, I need to unmarshal directly into an orderedMap type (such as github.com/iancoleman/orderedmap), rather than a standard Go map[string]interface{}.
At the moment, msgpack decoding always uses the Go map type for map objects, resulting in loss of ordering. It would be very helpful if the library could support unmarshaling into a user-defined ordered map type, either by:
- Detecting a known orderedMap type and populating it accordingly, or
- Providing a customizable decode hook / interface that allows users to define how map entries should be stored when decoded.
Code Example
var m orderedmap.OrderedMap
err := msgpack.Unmarshal(data, &m)
if err != nil {
return err
}This feature would allow applications that depend on key order to use this library more reliably.
Thank you for your work on this project!