Cista++ 是一个开源的简单C++序列化/反序列化库

网友投稿 1705 2022-11-04

Cista++ 是一个开源的简单C++序列化/反序列化库

Cista++ 是一个开源的简单C++序列化/反序列化库

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 on Google'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 in other ways, too!

Examples:

Download the latest release and try it out.

Simple example writing to a buffer:

namespace data = cista::raw;struct my_struct { // Define your struct. int a_{0}; struct inner { data::string b_; } j;};std::vector buf;{ // Serialize. my_struct obj{1, {data::string{"test"}}}; buf = cista::serialize(obj);}// Deserialize.auto deserialized = cista::deserialize(buf);assert(deserialized->j.b_ == data::string{"test"});

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

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::hash_set>;{ // 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(mmap, positions);}// Deserialize.auto b = cista::mmap("data", cista::mmap::protection::READ);auto positions = cista::deserialize(b);

Benchmarks

Have a look at the benchmark 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 ms378.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 networkshared memory applications

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

Alternatives

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

Protocol BuffersCap’n ProtoFlatbufferscerealBoost SerializationMessagePack... many more

Documentation

Installation and UsageSerialization ReferenceCustom (De-)Serialization FunctionsData Structure VersioningHash ContainersHashing FrameworkEquality FrameworkBenchmark Security

Contribute

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

版权声明:本文内容由网络用户投稿,版权归原作者所有,本站不拥有其著作权,亦不承担相应法律责任。如果您发现本站中有涉嫌抄袭或描述失实的内容,请联系我们jiasou666@gmail.com 处理,核实后本网站将在24小时内删除侵权内容。

上一篇:铁路基边坡滑坡隧道监测解决方案
下一篇:工程设备NLM5中继采集仪如何才能更省电?
相关文章

 发表评论

暂时没有评论,来抢沙发吧~