Skip to content
Marc edited this page Oct 29, 2018 · 52 revisions

Cereal (pronounced Serial) is a serialization library written by raresica1234 and marcizhu. The library is based on TheCherno's serialization library for Java. The library is really simple and fully customizable to fit all your needs.

Resources

Introduction

Cereal allows you to read and write serialized data from both memory and files, so you can use it to store anything your program needs into a single file.
The main purpose of this library was to be used in games to store player data and make multiplayer support much easier, but it can be used for any purpose.

Key features

  • No external dependencies
  • Cross-platform: works on Linux, Windows and MacOS
  • Lightweight
  • Uses only standard C++11 code
  • Has a C# port
  • Header-only library: it doesn't need any .c/.cpp files! Just one include file
  • Easy to use
  • Up to 256 databases in a single file

API Reference

Cereal is made up of small classes that work together. The classes you will find inside the library are the following:

  • Cereal::Field: A field is the simplest serialized data object. It has a name, and stores a single data type. The valid data types are: bool, char, byte, short, int, long long, float, double and std::string
  • Cereal::Array: An array also has a name, but it can store up to 4.294.967.296 items in it (theoretically, in reality the maximum is 1.073.741.824 items because of the x86 architecture). The data types it can store are: bool, char, byte, short, int, long long, float, double and std::string
  • Cereal::Object: An object is a bit more advanced. It has a name, and can store up to 65536 fields plus 65536 arrays.
  • Cereal::Database: A database is a collection of objects. It can store up to 65536 objects, but keep in mind that the maximum size of a database is 4 gigabytes, and here's why.
  • Cereal::Header: Headers are completely optional. Headers allow to store up to 255 databases in a single file or memory block, so if you need more than a single database, this is definitely a solution to that.
  • Cereal::Buffer: Buffers don't store data. Instead, they can be used as a temporary storage while serializing or deserializing data. Also they can read or write to files.
  • Cereal::Reader/Cereal::Writer: Those classes are used internally by the code. They allow to serialize and deserialize basic data types. You don't have to use them, but you definitely can.

Supported environments

The library is fully cross-platform, and it works perfectly in any environment such as Linux, Windows or Macintosh, as it only uses standard C++11 code and has no external dependencies. If you have tested it in other environments, please edit this page.

Operating System Environment Supported? Notes
Microsoft Visual Studio 2015 Community Edition -
Microsoft Visual Studio 2017 Community Edition -
GCC (G++) 5.4.0 (20160609) -
GCC (G++) 8.2.0 -
Apple LLVM version 9.1.0 (clang-902.0.39.2) -
Apple LLVM version 10.0.0 (clang-1000.10.44.2) -

Known issues

As far as we know, there aren't any issues with the library. If you discover a bug, please open an issue here and we will fix it as soon as possible.