Skip to content
Marc edited this page Aug 13, 2018 · 12 revisions

Cereal (pronounced Serial) is a serialization library written by raresica1234 and marcizhu. The library is a C# port of Cereal, and it's also 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 pupose.

Key features

  • No external dependencies
  • Cross-platform: works on Linux, Windows and MacOS
  • Lightweight
  • Uses only standard C# code
  • Has a C++ version
  • Easy to use
  • Up to 256 databases in a single file

API Reference

Cereal is made up of small clases that work toghether. 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 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 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 are able of reading or writing 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 was entirely made in Microsoft Visual Studio 2015 Community Edition, but it should work in any other environment, as it only uses standard C# code. 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 -
Microsoft Visual Studio Code 1.25.1 (x64) -

This library is fully compatible with its C++ version. This means that files made using the C++ version can be opened by the C# port, and of course files made with the C# port can be read by the C++ version.

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.