Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Serialize/ Deserialize C++ classes

I'm looking for a way to send C++ class between 2 clients aptication. I was looking for a way doing so and all i can find is that I need to create for each Class Serialize/ Deserialize (to JSON for example) functions and send it over TCP/IP. The main problem I'm faceing is that I have ~600 classes (some are classes including instances of others) that I need to pass which mean I need to spent the next writing Serialize/ Deserialize functions.

Is there any generic way writing Serialize/Deserialize functions ? Is there any other way sending C++ classes ?

Thanks, Guy Ergas.

like image 324
guy ergas Avatar asked Sep 16 '26 23:09

guy ergas


1 Answers

Are you using a Framework at all? Qt and MFC for example have built in Serialization that would make your task easier. Otherwise I would guess that you'd need to spend at least some effort on each of the 600 classes.

As recommended above Boost Serialization is probably a good way to go, you can send the serialized class over Tcp using Boost Asio too: http://www.boost.org/doc/libs/1_54_0/doc/html/boost_asio.html

Alternatively, there is a C++ API for Google Protocol Buffers (protobuf): https://developers.google.com/protocol-buffers/docs/reference/cpp/

like image 57
Duncan Smith Avatar answered Sep 19 '26 13:09

Duncan Smith



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!