In the C API for MsgPack, why are keys (for example the key field of msgpack_object_kv) of type msgpack_object?
https://github.com/msgpack/msgpack-c/blob/master/src/msgpack/object.h
Why aren’t they just msgpack_object_raw? Can they be any type?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Can they be any type?
Yes. And that’s precisely why keys are represented as
msgpack_object-s.If you look at the maps format specification you can see that maps are defined by
N= number of pairs within the map where:So you are free to use whatever kind of object for keys.
Here’s an example (with a map made of 2 pairs) from
test/msgpackc_test.cpp:As you can see the first key is a
MSGPACK_OBJECT_BOOLEANand the second one is aMSGPACK_OBJECT_POSITIVE_INTEGER.