explaingit

uscilab/cereal

4,657C++Audience · developerComplexity · 2/5LicenseSetup · easy

TLDR

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 dependencies.

Mindmap

mindmap
  root((cereal))
    Formats
      Binary compact
      XML output
      JSON output
    Integration
      Header only
      No dependencies
      C++11 compatible
    Usage
      serialize method
      Separate save load
      Nested types
    Platforms
      Linux
      macOS
      Windows
    Use Cases
      Save program state
      Network transfer
      Data exchange
Click or tap to explore — scroll the page freely

Code map

Detail Auto

An interactive map of this repo's files and how they connect — its source is parsed live in your browser. Click Visualize to build it.

filefunction / class

Things people build with this

USE CASE 1

Save and restore program state to a file so users can pick up where they left off.

USE CASE 2

Send structured data between services or over a network by serializing to binary or JSON.

USE CASE 3

Exchange data between different programs that share the same C++ data structures.

USE CASE 4

Quickly add save/load support to an existing C++ project with minimal setup.

Tech stack

C++C++11BinaryXMLJSON

Getting it running

Difficulty · easy Time to first run · 30min

Copy the include folder into your project. No compilation or linking required. Works with any C++11-compatible compiler on Linux, macOS, or Windows.

BSD 3-Clause, you can use it freely in commercial and open-source projects. Just keep the copyright notice and don't use the project name to endorse your product.

In plain English

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.

Copy-paste prompts

Prompt 1
I have a C++ struct with several fields including nested containers. Show me how to add a cereal serialize method so I can save it to a JSON file and load it back.
Prompt 2
Using the cereal library, write a complete example that serializes a vector of custom objects to a binary archive and then deserializes them back into memory.
Prompt 3
I need save and load to do different things for one of my types in cereal. Show me how to define separate save and load methods instead of a single serialize method.
Prompt 4
How do I integrate the cereal header-only library into a CMake project? Show me the CMakeLists.txt changes needed.
Prompt 5
Compare cereal's three archive formats, binary, XML, and JSON, and explain when I should choose each one for my C++ application.
Open on GitHub → Explain another repo

← uscilab on gitmyhub — every repo by this author, as a profile.

Verify against the repo before relying on details.