C++ Serialization & Reflection
Cista++ is a simple, open source (MIT license) C++17 compatible
way of
(de-)serializing C++ data structures.
Single header. No macros. No source code generation.
- Raw performance - use your native structs.
Supports modification/resizing of deserialized data! - Supports complex and cyclic data structures including cyclic references, recursive data structures, etc.
- Save 50% memory: serialize directly to the filesystem if needed, no intermediate buffer required.
- Fuzzing-checked though continuous fuzzing using LLVMs LibFuzzer.
- Comes with a serializable high-performance hash map and hash set implementation based on Google's Swiss Table technique.
- Reduce boilerplate code: automatic derivation of hash and equality functions.
- Optional: built-in automatic data structure versioning through recursive type hashing.
- Optional: check sum to prevent deserialization of corrupt data.
- Compatible with Clang, GCC, and MSVC
compile
& run
namespace data = cista::raw;
struct my_struct { // Define your struct.
int a_{0};
struct inner {
data::string b_;
} j;
};
std::vector<unsigned char> buf;
{ // Serialize.
my_struct obj{1, {data::string{"test"}}};
buf = cista::serialize(obj);
}
// Deserialize.
auto deserialized = cista::deserialize<my_struct>(buf);
assert(deserialized->j.b_ == data::string{"test"});
compile
& run
namespace data = cista::offset;
constexpr auto const MODE = // opt. versioning + check sum
cista::mode::WITH_VERSION | cista::mode::WITH_INTEGRITY;
struct pos { int x, y; };
using pos_map = // Automatic deduction of hash & equality
data::hash_map<data::vector<pos>,
data::hash_set<data::string>>;
{ // Serialize.
auto positions =
pos_map{{{{1, 2}, {3, 4}}, {"hello", "cista"}},
{{{5, 6}, {7, 8}}, {"hello", "world"}}};
cista::buf mmap{cista::mmap{"data"}};
cista::serialize<MODE>(mmap, positions);
}
// Deserialize.
auto b = cista::mmap("data", cista::mmap::protection::READ);
auto positions = cista::deserialize<pos_map, MODE>(b);