1

Suppose you want to be able to serialize and de-serialize and bunch of types and classes. If they're close enough together semantically, you might be able to use some domain-specific facility like structured markup documents, graphs, etc. But for the general case - what are our options?

The C++ standard library does not provide generic serialization facilities. Boost has Boost.Serialization, which may still be relevant, but is, after all, almost 20 years old, and its "TODO" list was last revised in 2008.

Required features:

  • Actively maintained
  • Is C++11-cognizant (to the extent C++1 features are relevant to serialization)
  • Gratis
  • Libre
  • Multi-platform

Desired features:

  • Is cognizant of C++14, 17 and 20 features
1

For C++11 I can recommend cereal. To some extent it even works as a drop-in replacement for Boost.Serialization with only minimal code changes. In my experience the documentation is pretty good and it is header-only. https://uscilab.github.io/cereal/

1
  • 1. If it's C++11, why are changes only minimal? I'd expect some API differences. 2. So, is the idea to have the same functionality as Boost::Serial but without Boost? Or are there aspects which are markedly better than its inspiration?
    – einpoklum
    May 4 at 10:37
1

For C++17 there is the library Cista, which borrows inspiration from Protobuf but without having to compile protocol buffers in an intermediate step. It features things like zero-copy and uses C++17 structured bindings to implement rudimentary reflection. This unfortunately requires significant code changes because you have to replace STL containers with Cista equivalents to make use of zero-copy. https://cista.rocks/

2
  • 1. "zero-copy" - in what context? 2. What is its benefit relative to cereal, if here you have to replace your containers? Does it offer better speed? Compilation time? Other metrics?
    – einpoklum
    May 4 at 10:38
  • @einpoklum If I understand it correctly, allocations are performed on memory-mapped files, which means that serialization and deserialization boils down to copying a pointer. The benefit over cereal is mainly speed. I haven't used Cista extensively myself, so I can't make any statement about other metrics, but there are some benchmarks on their website. May 4 at 12:17

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.