user788171
user788171

Reputation: 17553

C++ serializing and compressing vector<structs> in platform independent way

I'm looking to serialize a vector to send as a message in zeromq. The struct will only contain basic types (bool, string, int, float).

Since I am transferring over the network, I would like to use some sort of compression to save bandwidth.

I'd also like this to be somewhat platform agnostic. I will be broadcasting from a Linux box, but recipients could be either Windows or Linux.

Third party libraries are OK, so long as it will be possible for them to work under both Windows and Linux.

To send the zeromq message, typically something like memcpy is used to 'load' the data. http://api.zeromq.org/2-1:zmq-msg-data

Can somebody point me to the appropriate libraries and provide a simple sample code of the serialization/compression and ensuing de-serialization/decompression. The structs I'd like to send look something like the following:

struct sampledata {
  string testing_text;
  int testing_int;
  float testing_number;
  bool testing_bool;
}

I feel this must be a common C++ programming problem and there should be good solutions already developed for it.

Upvotes: 1

Views: 1452

Answers (2)

Jerry Coffin
Jerry Coffin

Reputation: 490408

I'd at least consider Boost Serialization in conjunction with a Boost gzip-filtered stream.

Upvotes: 1

Escualo
Escualo

Reputation: 42132

What you are looking for is a general-purpose serialization library; there are many available options.

I like two in particular: Google's Protocol Buffers and Apache's Avro. You can use either with ZMQ.

If you visit the ZMQ FAQ (go to the "general" section), you will find that Protocol Buffers is one of the mentioned serialization formats for the broker.

Upvotes: 2

Related Questions