Crates.io | ordcode |
lib.rs | ordcode |
version | 0.2.2 |
source | src |
created_at | 2020-12-25 17:43:21.864912 |
updated_at | 2020-12-25 17:43:21.864912 |
description | Serialization format which preserves lexicographical ordering, for use with key-value databases |
homepage | |
repository | https://github.com/pantonov/ordcode |
max_upload_size | |
id | 327217 |
size | 119,210 |
A set of primitives and Serde serializers for fast, prefix-free encoding which preserves lexicographic ordering of values.
It is intended for encoding keys and values in key-value databases.
In most existing designs, prefix-free encoding of byte sequences is performed by escaping
"end-of-sequence" bytes. This takes extra space, and makes it difficult to know sequence length
without processing the whole input buffer; this also complicates memory allocation for
deserialized data. Instead, we take advantage of the fact that exact record size is always
known in key-value databases. This implementation relies on "two-sided" buffer design:
sequence lengths are varint-encoded and pushed to the tail end of the buffer, so
it is possible to get original length of serialized byte sequence(s) by deserializing
a few bytes only.
For serialization, this implementation provides (very fast) calculation of exact size
of serialized data length before serialization itself. These features
enable effective and predictable buffer management for repetitive scans and no-heap
(#[no-std]
) targets.
#[no_std]
environmentsserde
(on by default): include serde
serializer and deserializer.
If you need only primitives, you can opt out.std
(on by default): opt out for #[no-std]
use, you will lose some convenience methods
which use Vec<u8>
The underlying encoding format is simple and unlikely to change.
As a safeguard, Serializer
and Deserializer
implement FormatVersion
trait for all serializer parameter
pre-sets (params::AscendingOrder
, params::PortableBinary
, params::NativeBinary
).
Note: serializing with descending lexicographic order is particularly useful for key-value databases like rocksdb, where reverse iteration is slower than forward iteration.
Licensed under either of
at your option.
Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.