STXXL
1.4.1
|
Some applications of STXXL will require variable data structures. Currently there is not much support for this in STXXL.
For serializing information into in-memory data blocks, the STXXL provides the helper classes binary_buffer and binary_reader. These provide functions binary_buffer::put<>() to append arbitrary integral data types and binary_reader::get<>() to read these again. Serialization and deserialization of variable data structures are then composed of identical sequences of put()/get().
Additionally, the classes already provide methods to serialize variable length strings (together with their lengths), and thereby also sub-block serialization. These functions are called binary_buffer::put_string() and binary_reader::get_string().
Furthermore, to squeeze small integers into fewer bytes, they classes also contain "varint" encoding, where each byte contains 7 data bits and one continuation bit. These functions are called binary_buffer::put_varint() and binary_reader::get_varint().
The following example fills a binary_buffer with some data elements:
And the following binary_reader example deserializes the data elements and check's their content.