Is it safe to use boost serialization to serialize

2019-02-23 14:56发布

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.

3条回答
我欲成王,谁敢阻挡
2楼-- · 2019-02-23 15:24

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

查看更多
对你真心纯属浪费
3楼-- · 2019-02-23 15:36

It's available, I've been hearing a lot about Google's protobuf. It has a C and C++ binding.

查看更多
一夜七次
4楼-- · 2019-02-23 15:36

You should check out Apache Thrift. It was designed by Facebook for cross platform serialization/deserialization.

查看更多
登录 后发表回答