guy ergas
guy ergas

Reputation: 135

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.

Upvotes: 3

Views: 5452

Answers (5)

mkkhedawat
mkkhedawat

Reputation: 1717

If you are at linux platform , You can directly use json.h library for serialization. Here is sample code i have come across :)

Json Serializer

Upvotes: 0

bazza
bazza

Reputation: 8414

You may be interested in ASN.1. It's not necessarily the easiest to use and tools/libraries are a little hard to come by (Objective Systems at http://www.obj-sys.com/index.php is worth a look, though not free).

However the big advantage is that it is very heavily standardised (so no trouble with library version incompatibilities) and most languages are supported one way or another. Handy if you need support across multiple platforms. It also does binary encodings, so its way less bloaty than XML (which it also supports). I chose it for these reasons and didn't regret it.

Upvotes: 1

Roee Gavirel
Roee Gavirel

Reputation: 19445

Boost Serialization
Although I haven't used it my self, it is very popular around my peers at work.
More info about it can be found in "Boost (1.54.00) Serialization"

Thrift
Thrift have a very limited serialize functionality which I don't think fits your requirements. But it can help you "move" the data from one client to anther even if they are using different languages.
More info about it can be found in "Thrift: The Missing Guide"

Upvotes: 2

plan9assembler
plan9assembler

Reputation: 2984

try s11n or nosjob

s11n (an abbreviation for serialization) is an Open Source project focused on the generic serialization of objects (i.e., object persistence) in the C++ programming language.

nosjob, a C++ library for generating and consuming JSON data.

Upvotes: 1

Duncan Smith
Duncan Smith

Reputation: 538

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/

Upvotes: 2

Related Questions