Crate const_varint

Source
Expand description

const-varint

Protocolbuf’s varint encoding/decoding with full const context operations supports.

github LoC Build codecov

docs.rs crates.io crates.io license

§Installation

[dependencies]
const-varint = "0.1"
  • For ruint::Uint<BITS, LBITS> support (not compatible in const context)

    const-varint = { version = "0.1", features = ["ruint_1"] }
§License

const-varint is under the terms of both the MIT license and the Apache License (Version 2.0).

See LICENSE-APACHE, LICENSE-MIT for details.

Copyright (c) 2025 Al Liu.

Structs§

I16VarintBuffer
A buffer for storing LEB128 encoded i16 values.
I32VarintBuffer
A buffer for storing LEB128 encoded i32 values.
I64VarintBuffer
A buffer for storing LEB128 encoded i64 values.
I128VarintBuffer
A buffer for storing LEB128 encoded i128 values.
U16VarintBuffer
A buffer for storing LEB128 encoded u16 values.
U32VarintBuffer
A buffer for storing LEB128 encoded u32 values.
U64VarintBuffer
A buffer for storing LEB128 encoded u64 values.
U128VarintBuffer
A buffer for storing LEB128 encoded u128 values.

Enums§

DecodeError
Decoding varint error.
EncodeError
Encode varint error

Traits§

Varint
A trait for types that can be encoded as variable-length integers (varints).

Functions§

decode_i16_varint
Decodes a u16 in LEB128 encoded format from the buffer.
decode_i32_varint
Decodes a u32 in LEB128 encoded format from the buffer.
decode_i64_varint
Decodes a u64 in LEB128 encoded format from the buffer.
decode_i128_varint
Decodes a u128 in LEB128 encoded format from the buffer.
decode_u16_varint
Decodes a i16 in LEB128 encoded format from the buffer.
decode_u32_varint
Decodes a i32 in LEB128 encoded format from the buffer.
decode_u64_varint
Decodes a i64 in LEB128 encoded format from the buffer.
decode_u128_varint
Decodes a i128 in LEB128 encoded format from the buffer.
encode_i16_varint
Encodes an i16 value into LEB128 variable length format, and writes it to the buffer.
encode_i32_varint
Encodes an i32 value into LEB128 variable length format, and writes it to the buffer.
encode_i64_varint
Encodes an i64 value into LEB128 variable length format, and writes it to the buffer.
encode_i128_varint
Encodes an i128 value into LEB128 variable length format, and writes it to the buffer.
encode_u16_varint
Encodes an u16 value into LEB128 variable length format, and writes it to the buffer.
encode_u32_varint
Encodes an u32 value into LEB128 variable length format, and writes it to the buffer.
encode_u64_varint
Encodes an u64 value into LEB128 variable length format, and writes it to the buffer.
encode_u128_varint
Encodes an u128 value into LEB128 variable length format, and writes it to the buffer.
encoded_i16_varint_len
Returns the encoded length of the value in LEB128 variable length format. The returned value will be in range of i16::ENCODED_LEN_RANGE.
encoded_i32_varint_len
Returns the encoded length of the value in LEB128 variable length format. The returned value will be in range of i32::ENCODED_LEN_RANGE.
encoded_i64_varint_len
Returns the encoded length of the value in LEB128 variable length format. The returned value will be in range i64::ENCODED_LEN_RANGE.
encoded_i128_varint_len
Returns the encoded length of the value in LEB128 variable length format. The returned value will be in range i128::ENCODED_LEN_RANGE.
encoded_u16_varint_len
Returns the encoded length of the value in LEB128 variable length format. The returned value will be in range of u16::ENCODED_LEN_RANGE.
encoded_u32_varint_len
Returns the encoded length of the value in LEB128 variable length format. The returned value will be in range of u32::ENCODED_LEN_RANGE.
encoded_u64_varint_len
Returns the encoded length of the value in LEB128 variable length format. The returned value will be in range u64::ENCODED_LEN_RANGE.
encoded_u128_varint_len
Returns the encoded length of the value in LEB128 variable length format. The returned value will be in range u128::ENCODED_LEN_RANGE.