cista
v0.15
CISTA ++는 간단한 오픈 소스 (MIT 라이센스) C ++ 17 호환 C ++ 데이터 구조를 직렬화하는 방법입니다.
단일 헤더 - 종속성 없음. 매크로가 없습니다. 소스 코드 생성이 없습니다.
기본 반사 메커니즘은 다른 방식으로도 사용할 수 있습니다!
예 :
최신 릴리스를 다운로드하고 시도해보십시오.
버퍼에 쓰기 간단한 예 :
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 " });고급 예제 메모리 매핑 파일에 해시 맵을 작성합니다.
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);파생 클래스 또는 사용자 정의 생성자가있는 클래스와 같은 비 응집 유형에 대한 지원을 보여주는 고급 예 :
namespace data = cista::offset;
constexpr auto MODE = cista::mode::WITH_VERSION;
struct parent {
parent () = default ;
explicit parent ( int a) : x_{a}, y_{a} {}
auto cista_members () { return std::tie (x_, y_); }
int x_, y_;
};
struct child : parent {
child () = default ;
explicit child ( int a) : parent{a}, z_{a} {}
auto cista_members () {
return std::tie (* static_cast <parent*>( this ), z_);
}
int z_;
};
/*
* Automatically defaulted for you:
* - de/serialization
* - hashing (use child in hash containers)
* - equality comparison
* - data structure version ("type hash")
*/
using t = data::hash_map<child, int >;
// ... usage, serialization as in the previous examples자세한 내용은 벤치 마크 리포지토리를 살펴보십시오.
| 도서관 | 직렬화 | 사형화 | 빠른 사제 | 횡단 | 사제 및 트래버스 | 크기 |
|---|---|---|---|---|---|---|
| Cap'n 프로토 | 105ms | 0.002ms | 0.0ms | 356ms | 353ms | 50.5m |
| 시리얼 | 239ms | 197.000ms | - | 125ms | 322ms | 37.8m |
Cista ++ offset | 72ms | 0.053 ms | 0.0ms | 132ms | 132ms | 25.3m |
Cista ++ raw | 3555ms | 68.900ms | 21.5ms | 112ms | 133ms | 176.4m |
| 플랫 버퍼 | 2349ms | 15.400ms | 0.0ms | 136ms | 133ms | 63.0m |
독자와 작가는 동일한 포인터 너비를 가져야합니다. 다른 바이트 순서 (Endianess)가있는 시스템에 데이터를로드하는 것이 지원됩니다. 예 :
현재 C ++ 17 소프트웨어만이 데이터를 읽고 쓸 수 있습니다. 그러나 다른 프로그래밍 언어에 대한 액세서를 생성 할 수 있어야합니다.
다른 프로그래밍 언어와 호환되거나 프로토콜 진화 (하향 호환성)가 필요한 경우 다른 솔루션을 찾아야합니다.
자유롭게 기여하십시오 (버그 보고서, 요청 등)!