Serpent is a C++ serialization and runtime memory layout library, designed for game engines.
Every value in Serpent is defined by a Layout object, which defines the structure of the data. Layouts define how the data is arranged in memory, allowing Serpent to calculate memory offsets and alignments of values at runtime.
Unlike dynamic layouts used in scripting languages like Javascript, Serpent enforces static, typed memory structures. This is done for several reasons,
- To reduce memory usage
- Instead of having duplicated memory telling how an object is laid out, multiple objects can reference the same layout
- To improve cache locality
- Storing all the data for an object linearly reduces cache misses when accessing the same object
- To minimize surface area for bugs
- Weakly typed objects often defer mismatched types until far later than they occur.
Serpent is intended to be used in scripting systems, as a means to share data between native code and scripting engines. It can be used for various systems,
- Entity data and components
- Networking and packets
- Vertex buffers and other graphics data
- Save game data
- An intermediate representation for config / data formats, like JSON, and native C++ structs