Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Simple C++ Serialization & Reflection.

License

NotificationsYou must be signed in to change notification settings

cflaviu/cista

 
 

Repository files navigation

Simple C++ Serialization & Reflection.

Cista++ is a simple, open source (MIT license) C++17 compatible way of (de-)serializing C++ data structures.

Single header - no dependencies. 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 onGoogle's Swiss Table.
  • Reduce boilerplate code: automatic derivation of hash and equality functions.
  • Built-in optional automatic data structure versioning through recursive type hashing.
  • Optional check sum to prevent deserialization of corrupt data.
  • Compatible with Clang, GCC, and MSVC

The underlying reflection mechanism can be used inother ways, too!

Examples:

Download thelatest release and try it out.

Simple example writing to a buffer:

namespacedata= cista::raw;structmy_struct {// Define your struct.int a_{0};structinner {      data::string b_;  } j;};std::vector<unsignedchar> 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"});

Advanced example writing a hash map to a memory mapped file:

namespacedata= cista::offset;constexprautoconst MODE =// opt. versioning + check sum    cista::mode::WITH_VERSION | cista::mode::WITH_INTEGRITY;structpos {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);

Benchmarks

Have a look at thebenchmark repository for more details.

LibrarySerializeDeserializeFast DeserializeTraverseDeserialize & TraverseSize
Cap’n Proto105 ms0.002 ms0.0 ms356 ms353 ms50.5M
cereal239 ms197.000 ms-125 ms322 ms37.8M
Cista++offset72 ms0.053 ms0.0 ms132 ms132 ms25.3M
Cista++raw3555 ms68.900 ms21.5 ms112 ms133 ms176.4M
Flatbuffers2349 ms15.400 ms0.0 ms136 ms133 ms63.0M

Use Cases

Reader and writer should have the same pointer width. Loading data on systems with a different byte order (endianess) is supported.Examples:

  • Asset loading for all kinds of applications (i.e. game assets, GIS data, large graphs, etc.)
  • Transferring data over network
  • shared memory applications

Currently, only C++17 software can read/write data.But it should be possible to generate accessorsfor other programming languages, too.

Alternatives

If you need to be compatible with other programming languagesor require protocol evolution (downward compatibility)you should look for another solution:

Documentation

Contribute

Feel free to contribute (bug reports, pull requests, etc.)!

About

Simple C++ Serialization & Reflection.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • C++80.6%
  • C16.9%
  • Python1.6%
  • CMake0.9%

[8]ページ先頭

©2009-2025 Movatter.jp