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:
odd elements are key and next element of the key is its associate value
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
:
unsigned int map_size = 2;
/* ... */
msgpack_pack_map(&pk, map_size);
msgpack_pack_true(&pk);
msgpack_pack_false(&pk);
msgpack_pack_int(&pk, 10);
msgpack_pack_int(&pk, -10);
As you can see the first key is a MSGPACK_OBJECT_BOOLEAN
and the second one is a MSGPACK_OBJECT_POSITIVE_INTEGER
.