gitmyhub

cereal

C++ ★ 4.7k updated 3mo ago

A C++11 library for serialization

cereal is a header-only C++ library that serializes and deserializes data structures to binary, XML, or JSON formats. Drop in a folder of headers, add a serialize method to your types, and saving/loading program state or sending data over a network becomes straightforward with no external dependenci

C++C++11BinaryXMLJSONsetup: easycomplexity 2/5

cereal is a C++ library that converts data structures to a storable or transmittable format and then reconstructs them back to the original. This process is called serialization, and it is useful any time you need to save program state to a file, send data over a network, or exchange information between different programs. cereal supports three output formats: compact binary, XML, and JSON.

The library works with C++11, a version of the language from 2011 that became widely supported across compilers. It is header-only, which means you integrate it by copying a folder of header files into your project rather than compiling a separate library and linking to it. There are no external dependencies, so adding it to an existing codebase involves minimal setup.

To use it, you add a serialize method to your data types that lists which fields should be saved and loaded. cereal reads that method and handles the rest automatically. For cases where saving and loading require different logic, you can define separate save and load methods instead of a single combined one. The README includes a short working code example showing how to serialize a struct containing integers, a float, and a nested map.

The library is built and tested on Linux, macOS, and Windows. It is released under the BSD 3-Clause license, which permits use in commercial and open-source projects with few restrictions. Full documentation is available at the project's website at USCiLab.github.io/cereal, and there is a mailing list for support and discussion.

Where it fits