User defined Class Serialization, C++ and msgpack
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.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.
精彩评论