Reputation: 257
in the message pack website :
there is "Try" link above where it shows me how long is the representing string for the data.
I have a small script that is based on the examples presented in the message pack git hub
#include <msgpack.hpp>
#include <vector>
#include <string>
#include <iostream>
int main(void) {
using namespace std;
msgpack::sbuffer buffer;
msgpack::packer<msgpack::sbuffer> pk(&buffer);
pk.pack_map(2);
pk.pack(string("SerialNumber"));
pk.pack(123456789);
pk.pack(string("Date"));
pk.pack("1.4.14");
//deserialize
msgpack::unpacker pac;
pac.reserve_buffer(buffer.size());
memcpy(pac.buffer(),buffer.data(),buffer.size());
pac.buffer_consumed(buffer.size());
msgpack::unpacked result;
while(pac.next(&result))
{
cout<<result.get()<<endl<<endl;
}
works great but I want to retrive the String that is represented behind the packed data. just like in the "Try!" link. how can I find it ?
thank you
Upvotes: 1
Views: 303
Reputation: 16121
I want to retrieve the String that is represented behind the packed data
What you can do is print the content of the simple buffer in hex format:
const char *data = buffer.data();
for (int i = 0; i < buffer.size(); i++)
printf("%02x ", (unsigned char) data[i]);
Upvotes: 1