PTWM
ptwm_core

ptwm_core::varint

Unsigned LEB128 varints and a bounds-checked byte cursor for the compact wire formats (the \x89PTWS frame and the compact chain wire).

ptwm_core::varint

Unsigned LEB128 varints and a bounds-checked byte cursor for the compact wire formats (the \x89PTWS frame and the compact chain wire).

rsmod

ptwm_core::varint

crates/ptwm-core/src/varint.rs:1
mod varint

Unsigned LEB128 varints and a bounds-checked byte cursor for the compact wire formats (the `\x89PTWS` frame and the compact chain wire).

Parsing is canonical: a varint must use the fewest bytes that hold its value (no trailing `0x80`/`0x00` groups), is at most 10 bytes long, and must fit in `u64`, so each value has one varint encoding. The compact formats build on this: each of their fields has one encoding for the value it holds. (A compact frame as a whole still leaves the writer some choices; see [`crate::compact`].)
rstype

ptwm_core::varint::Cursor

crates/ptwm-core/src/varint.rs:78
pub struct Cursor

A bounds-checked reader over one wire section. Every error is an [`PtwmCoreError::InvalidContainer`] prefixed with the cursor's context (for example `"compact frame"`).

rsconst

ptwm_core::varint::MAX_VARINT_LEN

crates/ptwm-core/src/varint.rs:14
pub const MAX_VARINT_LEN

Longest LEB128 encoding of a `u64`.

rsfn

ptwm_core::varint::read_varint

crates/ptwm-core/src/varint.rs:54
pub fn read_varint(buf: &[u8], pos: &mut usize) -> Result<u64, VarintError>

Read one canonical varint from `buf` at `*pos` and advance `*pos`.

rsfn

ptwm_core::varint::varint_len

crates/ptwm-core/src/varint.rs:26
pub fn varint_len(v: u64) -> usize

Number of bytes [`write_varint`] uses for `v`.

rstype

ptwm_core::varint::VarintError

crates/ptwm-core/src/varint.rs:33
pub enum VarintError

Why a varint did not parse.

rsfn

ptwm_core::varint::write_varint

crates/ptwm-core/src/varint.rs:17
pub fn write_varint(out: &mut Vec<u8>, v: u64)

Append `v` as an unsigned LEB128 varint.