Open fillest opened 6 years ago
What happens when you use TopicIDs map[string]bool
in your struct?
There is not really a reason for msgp to not allow other types as keys seeing as encoding/json
supports this now as well.
The online editor on https://msgpack.org/ doesn't seem to allow int keys either.
You can manually decode it using an extension. This means msgp will pass a raw []byte
to your extension code which then has to determine by itself how to decode this. You can use functions like ReadMapHeaderBytes
, ReadMapKeyZC
, ReadBoolBytes
and ReadIntBytes
to parse the data.
Has anyone figured out how to actually do this (marshalling or unmarshalling a map with non-string keys). The wiki page for custom extensions seems geared towards single, custom types. Not sure how to set the struct tags on a field that is a composite type (which in my case is a type alias for the map composed of my custom type as key and integers as values). Are we supposed to write the custom extension for the map as a whole, or only for the key type? (I did it for the key type but it's not getting picked up by the library when running go generate
)
I was going to try to (back then), but never-ending tasks with higher priority don't ever end :) And in the meantime, our CPU bottlenecks shifted a lot, so I have no idea when I'll get to it..
BTW I agree
You can still manually decode arbitrary maps with the primitives built into the library.
this could use some expanding. which primitives? custom shims? extensions? on the map level or the key level? can we get an example for both encoding and decoding? thanks.
Hello. We have some data that is currently encoded with msgpack/msgpack-python and decoded with vmihailenco/msgpack. I'm trying to switch the decoding to msgp. I've added duplicate decoding code and
reflect.DeepEqual
the results and diffing them when it fails. Where I'm getting with vmihailenco/msgpack:with msgp I'm getting
TopicIDs: (map[int]bool) <nil>
silently. The docs say map must havestr
orbin
keys, is that right? It also says "You can still manually decode arbitrary maps with the primitives built into the library", but how? So: