VarUInt

Trait VarUInt 

Source
pub trait VarUInt: Sized {
    // Required methods
    fn varu_encoded_len(&self) -> u8;
    fn varu_decoded_len(first_byte: u8) -> u8;
    fn varu_to_writer(&self, writer: impl WriteBytes) -> Result;
    fn varu_from_reader(reader: impl ReadBytes) -> Result<Self>;
    fn varu_from_slice(bytes: &[u8]) -> Result<(Self, u8)>;
    fn varu_to_slice(&self, bytes: &mut [u8]) -> u8;
}
Expand description

Methods for variable length serializaiton of unsigned integers

Required Methods§

Source

fn varu_encoded_len(&self) -> u8

Get the length of an varint-encoded value in bytes

Source

fn varu_decoded_len(first_byte: u8) -> u8

Get the byte length of varint-encoded value from the first byte

Source

fn varu_to_writer(&self, writer: impl WriteBytes) -> Result

Encode as variable length integer to writer

Source

fn varu_from_reader(reader: impl ReadBytes) -> Result<Self>

Read variable length integer from reader

Source

fn varu_from_slice(bytes: &[u8]) -> Result<(Self, u8)>

Decode variable length integer from slice

Source

fn varu_to_slice(&self, bytes: &mut [u8]) -> u8

Encode variable length integer into slice

Slice must be of enough length, and can be calculated with varu_encoded_len(). Returns actual length of encoded varint.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementations on Foreign Types§

Source§

impl VarUInt for u32

Source§

fn varu_encoded_len(&self) -> u8

Source§

fn varu_decoded_len(first_byte: u8) -> u8

Source§

fn varu_to_writer(&self, writer: impl WriteBytes) -> Result

Source§

fn varu_from_reader(reader: impl ReadBytes) -> Result<Self>

Source§

fn varu_from_slice(bytes: &[u8]) -> Result<(Self, u8)>

Source§

fn varu_to_slice(&self, bytes: &mut [u8]) -> u8

Source§

impl VarUInt for u64

Source§

fn varu_encoded_len(&self) -> u8

Source§

fn varu_decoded_len(first_byte: u8) -> u8

Source§

fn varu_to_writer(&self, writer: impl WriteBytes) -> Result

Source§

fn varu_from_reader(reader: impl ReadBytes) -> Result<Self>

Source§

fn varu_from_slice(bytes: &[u8]) -> Result<(Self, u8)>

Source§

fn varu_to_slice(&self, bytes: &mut [u8]) -> u8

Implementors§