Skip to main content

Module varint

Module varint 

Source
Expand description

Variable-length integer encoding.

Unsigned integers use LEB128 — little-endian base 128. Each byte carries 7 data bits; the high bit is 1 while more bytes follow and 0 on the last byte. Values 0..127 fit in one byte.

Signed integers use ZigZag mapping (positive and negative interleaved into the unsigned range) and are then LEB128-encoded. Small positive values like rowid=1 take one byte; small negative values do too.

These are the encodings used for lengths, column counts, rowids, and Integer cell values. Fixed-width encodings stay in place for tags (u8) and Real values (f64, 8 bytes).

Constants§

MAX_VARINT_BYTES
Upper bound on bytes for a 64-bit LEB128 value: ceil(64 / 7) = 10.

Functions§

i64_len
Same as u64_len for a zigzagged signed i64.
read_i64
Reads a ZigZag-encoded signed i64 (LEB128). Returns (value, bytes_consumed).
read_u64
Reads a LEB128 u64 from buf starting at pos. Returns (value, bytes_consumed).
u64_len
Returns the number of bytes write_u64(value) would produce, without writing.
write_i64
Writes a ZigZag-encoded signed i64 as LEB128. Returns bytes written.
write_u64
Appends a LEB128-encoded u64 to out. Returns the number of bytes written.