CISTA ++ เป็นวิธีที่เรียบง่าย, โอเพ่นซอร์ส (ใบอนุญาต MIT) C ++ 17 วิธีที่เข้ากันได้ของ (de-) โครงสร้างข้อมูล 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ดูที่พื้นที่เก็บข้อมูลมาตรฐานสำหรับรายละเอียดเพิ่มเติม
| ห้องสมุด | ทำให้เป็นอันดับ | deserialialial | deserialize อย่างรวดเร็ว | การสำรวจ | deserialize & traverse | ขนาด |
|---|---|---|---|---|---|---|
| cap'n proto | 105 มิลลิวินาที | 0.002 ms | 0.0 ms | 356 ms | 353 ms | 50.5m |
| ซีเรียล | 239 ms | 197.000 ms | - | 125 มิลลิวินาที | 322 ms | 37.8m |
offset Cista ++ | 72 มิลลิวินาที | 0.053 ms | 0.0 ms | 132 มิลลิวินาที | 132 มิลลิวินาที | 25.3m |
cista ++ raw | 3555 ms | 68.900 มิลลิวินาที | 21.5 มิลลิวินาที | 112 มิลลิวินาที | 133 ms | 176.4m |
| นักทำนาย | 2349 ms | 15.400 มิลลิวินาที | 0.0 ms | 136 มิลลิวินาที | 133 ms | 63.0m |
ผู้อ่านและนักเขียนควรมีความกว้างตัวชี้เดียวกัน รองรับการโหลดข้อมูลเกี่ยวกับระบบที่มีคำสั่งไบต์ที่แตกต่างกัน (Endianess) ตัวอย่าง:
ปัจจุบันซอฟต์แวร์ C ++ 17 เท่านั้นที่สามารถอ่าน/เขียนข้อมูลได้ แต่ควรเป็นไปได้ที่จะสร้าง accessors สำหรับภาษาการเขียนโปรแกรมอื่น ๆ ด้วย
หากคุณต้องการเข้ากันได้กับภาษาการเขียนโปรแกรมอื่น ๆ หรือต้องการวิวัฒนาการของโปรโตคอล (ความเข้ากันได้ลดลง) คุณควรมองหาวิธีแก้ปัญหาอื่น:
อย่าลังเลที่จะมีส่วนร่วม (รายงานข้อผิดพลาดการดึงคำขอ ฯลฯ )!