开发者

User defined Class Serialization, C++ and msgpack

I am quite new trying msgpack. I need to serialize an object (instance of an user defined class), that cont开发者_C百科ains 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.


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜