Expand description
Big-endian key encoding for RocksDB with correct lexicographic ordering.
Keys are encoded as entity_id (8B) + space_id (4B) + timestamp (8B) = 20 bytes.
All integers use big-endian encoding so that lexicographic byte comparison
matches numeric ordering.
Timestamps (i64) use a sign-bit flip (XOR 0x80 on the first byte) so
that negative timestamps sort correctly:
- Without flip:
-1=FF..FFsorts after1=00..01(wrong) - With flip:
-1=7F..FFsorts before1=80..01(correct)
§Example
use cvx_storage::keys;
let key = keys::encode_key(42, 0, 1_000_000);
let (entity_id, space_id, timestamp) = keys::decode_key(&key);
assert_eq!(entity_id, 42);
assert_eq!(space_id, 0);
assert_eq!(timestamp, 1_000_000);Constants§
- KEY_
SIZE - Total size of an encoded key in bytes.
- PREFIX_
SIZE - Prefix size for entity_id + space_id (used for prefix bloom filters).
Functions§
- decode_
key - Decode a 20-byte key back into its components.
- decode_
timestamp 🔒 - Decode a sign-bit-flipped timestamp.
- encode_
key - Encode a key as 20 big-endian bytes with sign-bit flip on timestamp.
- encode_
prefix - Encode an entity_id + space_id prefix (12 bytes) for prefix scans.
- encode_
timestamp 🔒 - Encode a timestamp with sign-bit flip for correct lexicographic ordering.