Skip to content

std.leb128

7-bit varints (wasm, dwarf, protobuf); padded forms ok, >64 bits fails

pub LebError :: errors {
buffer_too_small,
truncated,
overflow,
}
  • buffer_too_small: out too small; nothing written
  • truncated: the bytes end in the middle of a number
  • overflow: more than 64 bits
pub MAX_LEN :: 10usize

max bytes for a 64-bit value

pub Unsigned :: struct {
value: u64,
len: usize,
}

decoded value + bytes used

pub Signed :: struct {
value: i64,
len: usize,
}
pub len_u64 :: fn(v: u64) -> usize

encoded size of v

pub len_i64 :: fn(v: i64) -> usize

encoded size of v, signed

pub encode_u64 :: fn(out: []u8, v: u64) -> usize ! LebError

encode v into out; returns len_u64(v)

pub encode_i64 :: fn(out: []u8, v: i64) -> usize ! LebError

encode signed v into out; returns len_i64(v)

pub decode_u64 :: fn(bytes: []const u8) -> Unsigned ! LebError

decode from the start of bytes

pub decode_i64 :: fn(bytes: []const u8) -> Signed ! LebError

decode signed from the start of bytes