C++ – Serialize/ Deserialize C++ classes

boostcjsonserializationthrift

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.

Best Answer

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/