I am trying to convert a struct into msgpack in C or C++. Please find the code below:
struct your_type {
int a;
float b;
MSGPACK_DEFINE(a, b);
};
int main() {
// packing
std::stringstream ss;
std::vector<std::map<std::string, your_type>> v
{
{
{ "t", {1,2.7} }
},
{
{"value", {2, 6.8} }
}
};
msgpack::pack(ss, v);
}
I understand how to transform this output to object using msgpack::object_handle
. But I want to print the packed output in C, so to verify if it does look like the format we obtain after converting a dataframe into msgpack
in Python. How can I display the msgpack::pack
output?
Edited: hex_dump() as mentioned answer provided in the comments actually helps in obtaining the answer.
struct your_type {
int a;
int b;
MSGPACK_DEFINE(a, b);
};
int main() {
std::stringstream ss;
std::vector<std::map<std::string, your_type>> v
{
{
{ "t",{ 1, 2 } }
},
{
{ "value",{ 3, 6 } }
}
};
msgpack::pack(ss, v);
hex_dump(std::cout, ss.str()) << std::endl;
}
I am able to convert this struct into hexvalues. But I am trying to make a float value for b in struct, so that "value" can take float values. I am not able to do so though. Could anyone please guide me in this?