Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it safe to use boost serialization to serialize objects in C++ to a binary format for use over a socket?

I know that you can use boost serialization to serialize to a text format and then push over a socket, but I'd like to serialize a class of statistics data into a binary format (both for size and encoding/decoding overhead reasons). Is it safe to use boost serialization for this?

My specific worries are:

  1. Differences between integer type sizes on different platforms (mainly 32-bit vs 64-bit).
    Though I can largely get around this by using exactly-sized integer from stdint, I'd still like to understand the behavior.
  2. Differences in endianness between systems, does boost serialize into a standard endian-ness (eg: network ordering), and then deserialize using the host's endianness?

It's a very nice library, but unfortunately documentation on it's binary capabilities is somewhat limited, so I just want to make sure that using it this way would be safe.

like image 252
gct Avatar asked Feb 20 '10 22:02

gct


People also ask

What is Boost serialization?

The library Boost. Serialization makes it possible to convert objects in a C++ program to a sequence of bytes that can be saved and loaded to restore the objects. There are different data formats available to define the rules for generating sequences of bytes. All of the formats supported by Boost.

How do you serialize data in CPP?

Object Serialization with the Boost C++ Library Boost serialization works in two ways: one is called the intrusive method and another is the non-intrusive method. The intrusive method is the simplest one where we build mechanism of serialization in the object itself.


1 Answers

No, in general boost binary serialization is not machine-independent. See here.

like image 65
rlbond Avatar answered Nov 11 '22 02:11

rlbond