U64Coder1234

U64Coder1234 stores u64 values using 1–4 bytes, the same byte-width table as U32Classic. Values must fit within u32::MAX (4294967295); values above that are silently truncated on encode.

The wire format is identical to U32Classic; only the element type differs. This means a U64Coder1234-encoded buffer can be decoded by U32Classic (values are zero-extended on decode).

Tag table

TagByte widthValue range
010–255
12256–65535
2365536–16777215
3416777216–4294967295

Example

#![allow(unused)]
fn main() {
use svb::u64::U64Coder1234;

let values: Vec<u64> = vec![1, 500, 70_000, u32::MAX as u64];

// check_range returns the index of the first out-of-range value, if any.
assert_eq!(U64Coder1234.check_range(&values), None);

let encoded = U64Coder1234.encode(&values);
let decoded = U64Coder1234.decode(&encoded, values.len()).unwrap();
assert_eq!(decoded, values);
}

Range checking

Call check_range before encoding if the input may contain values above u32::MAX:

#![allow(unused)]
fn main() {
use svb::u64::U64Coder1234;

let values: Vec<u64> = vec![1, u64::MAX, 3];
if let Some(idx) = U64Coder1234.check_range(&values) {
    eprintln!("value at index {idx} exceeds u32::MAX");
}
}

When to use

Use U64Coder1234 when your data is logically u64 but all values fit within 32 bits. It produces a more compact encoding than U64Coder1248 for such data because values never consume 8 bytes.