I’m using MessagePack with C++ and I’m trying to deserialize the equivalent of this Python map:
{'metadata': {'date': '2014-06-25', 'user_id': 501},
'values': [3.0, 4.0, 5.0],
'version': 1}
The top-level object is a map with string keys, but the values are of completely different types. My code knows ahead of time what the structure of the object should be; I ought to be able to declare an integer and then tell my deserialization code, “The value of the version
key is an integer, so put the value of that integer into this memory address.”
The problem is that I’m not even sure how to get to the point where my C++ code can treat this structure as a map. I would expect to do something like
msgpack::unpacker unpacker;
// ...copy the data into unpacker's buffer...
msgpack::unpacked message;
std::map<std::string, anything> output_map;
unpacker.next(&message);
msgpack::object obj = message.get();
obj.convert(&output_map);
int version_number = output_map.at("version");
Is there any possible type (anything
) that would work here? The MessagePack documentation has only trivial examples, and this blog post is better but doesn’t cover this use case.