serde_columnar
is a crate that provides columnar storage for List and Map with compressible serialization and deserialization capabilities.
Columnar storage is very useful when you want to compress serialized data and you know that one or more fields of consecutive structs in the array have the same or equal difference values.
For example, you want to store this array:
plain
[{a: 1, b: 1}, {a: 1, b: 2}, {a: 1, b: 3}, ...]
After columnar storage, it can be stored as:
plain
a: [1, 1, 1,...] ---Rle---> [N, 1]
b: [1, 2, 3,...] ---DeltaRle---> [N, 1] (each value is 1 greater than the previous one)
```rust ignore type ID = u64;
pub struct Data { #[columnar(strategy = "Rle")] num: u32, #[columnar(strategy = "DeltaRle", original_type = "u64")] id: ID, #[columnar(strategy = "Rle")] gender: String, #[columnar(strategy = "BoolRle")] married: bool }
pub struct VecStore { #[columnar(type = "vec")] pub data: Vec }
let store = VecStore::new(...);
let bytes = serdecolumnar::tovec(&store).unwrap();
let store = serdecolumnar::frombytes::
```
#[columnar]
means that some fields (marked by #[columnar(type = "vec"|"map")]
) of this structure can be serialized and deserialized by columnar encoding#[columnar(vec, map)]
means the struct can be a row inside Vec-like
or Map-like
#[columnar(ser, de)]
means the struct can be serialized or deserialized or both by columnar encoding#[columnar(type = "vec"|"map")]
:
&T: IntoIter<Item=&Value>
T: FromIterator<Value>
&T: IntoIter<Item=(&K, &Value)>
T: FromIterator<(K, Value)>
#[columnar(strategy = "Rle"|"BoolRle"|"DeltaRle")]
: You can only choose one from the three
#[columnar(original_type="u32")]
: this attribute is used to tell the columnar encoding the original type of the field, which is used when the field is a number#[columnar(skip)]
: the same as the skip attribute in serdecompress
feature)#[columnar(compress)]
: compress the columnar encoded bytes by
default settings of Deflate algorithm.
more compress options:
#[columnar(compress(min_size=N))]
: compress the columnar encoded bytes when the size of the bytes is larger than N, default N is 256.#[columnar(compress(level=N))]
: compress the columnar encoded bytes by Deflate algorithm with level N, N is in [0, 9], default N is 6,
0 is no compression, 9 is the best compression. See flate2 for more details.#[columnar(compress(method="fast"|"best"|"default"))]
: compress the columnar encoded bytes by Deflate algorithm with method "fast", "best" or "default",
this attribute is equivalent to #[columnar(compress(level=1|9|6))]
.level
and method
can not be used at the same time.