5


I am quite new trying msgpack. I need to serialize an object (instance of an user defined class), that contains pointers (internal tree, hashes,etc), and some basic types attributes.

Until now I can do what is done in the quick example of msgpack.org wiki, just serialize the class to a msgpack::sbuffer, and then read the buffer to unserialize.

But now, I want to send that buffer to a file, or the serialization result to a file and then unserialize it.
Can anyone give me some tip on how to do it? I browse and read enough to get tired of it :)

My code look like this:

msgpack::sbuffer sbuf;
msgpack::pack(sbuf, cluster); //cluster is the instance of my class clustering

//HERE I SHOULD SEND THE BUFFER TO A STREAM FILE, AND THEN LOAD IT IN THE UNPACK;

msgpack::unpacked msg;
msgpack::unpack(&msg, sbuf.data(), sbuf.size()); 
msgpack::object obj = msg.get();
clustering clustUnser
obj.convert(&clustUnser);

thanks everybody!
bests,
Luchux.

ildjarn
  • 62,044
  • 9
  • 127
  • 211
Luchux
  • 63
  • 1
  • 4

1 Answers1

3

From the example here:

http://wiki.msgpack.org/pages/viewpage.action?pageId=1081387

it looks like sbuf.data() would return the address, and sbuf.size() would return the size, of the data which you would write to the binary file.

When you want to load the data from a binary file, read it into a buffer you've allocated and then pass the address and size to the msgpack::unpack call.

MRAB
  • 20,356
  • 6
  • 40
  • 33
  • Thanks! I was in a hurry, so I implemented my own serialization methods. But I will be back soon on it, and try what you suggested! – Luchux Jun 10 '11 at 11:25