Crate const_varint

Source
Expand description

§Note: This crate is renamed to varing.

const-varint

Protobuf’s varint encoding/decoding with full const context operations supports. (This project is renamed to varing)

github LoC Build codecov

docs.rs crates.io crates.io license

§Installation

[dependencies]
const-varint = "0.4"
  • For u1, u2, u3, .., u127

    const-varint = { version = "0.4", features = "arbitrary-int" }
  • For ruint::Uint<BITS, LBITS> support (not compatible in const context)

    const-varint = { version = "0.4", features = ["ruint"] }
  • For primitive-types support (not compatible in const context)

    const-varint = { version = "0.4", features = ["primitive-types"] }
  • For ethereum-types support (not compatible in const context)

    const-varint = { version = "0.4", features = ["ethereum-types"] }
§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.

Modules§

arbitrary_intarbitrary-int
LEB128 encoding/decoding for u1, u2 .. u127

Structs§

I8VarintBuffer
A buffer for storing LEB128 encoded i8 values.
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.
U8VarintBuffer
A buffer for storing LEB128 encoded u8 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§

consume_varint
Calculates the number of bytes occupied by a varint encoded value in the buffer.
decode_char
Decodes a char in LEB128 encoded format from the buffer.
decode_duration
Decodes a Duration in LEB128 encoded format from the buffer.
decode_i8_varint
Decodes an u8 in LEB128 encoded format from the buffer.
decode_i16_varint
Decodes an u16 in LEB128 encoded format from the buffer.
decode_i32_varint
Decodes an u32 in LEB128 encoded format from the buffer.
decode_i64_varint
Decodes an u64 in LEB128 encoded format from the buffer.
decode_i128_varint
Decodes an u128 in LEB128 encoded format from the buffer.
decode_u8_varint
Decodes an i8 in LEB128 encoded format from the buffer.
decode_u16_varint
Decodes an i16 in LEB128 encoded format from the buffer.
decode_u32_varint
Decodes an i32 in LEB128 encoded format from the buffer.
decode_u64_varint
Decodes an i64 in LEB128 encoded format from the buffer.
decode_u128_varint
Decodes an i128 in LEB128 encoded format from the buffer.
encode_char
Encodes a char value into LEB128 variable length format, and writes it to the buffer.
encode_char_to
Encodes a char value into LEB128 variable length format, and writes it to the buffer.
encode_duration
Encodes a Duration value into LEB128 variable length format, and writes it to the buffer.
encode_duration_to
Encodes a Duration value into LEB128 variable length format, and writes it to the buffer.
encode_i8_varint
Encodes an i8 value into LEB128 variable length format, and writes it to the buffer.
encode_i8_varint_to
Encodes an i8 value into LEB128 variable length format, and writes it to the buffer.
encode_i16_varint
Encodes an i16 value into LEB128 variable length format, and writes it to the buffer.
encode_i16_varint_to
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_i32_varint_to
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_i64_varint_to
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_i128_varint_to
Encodes an i128 value into LEB128 variable length format, and writes it to the buffer.
encode_u8_varint
Encodes an u8 value into LEB128 variable length format, and writes it to the buffer.
encode_u8_varint_to
Encodes an u8 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_u16_varint_to
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_u32_varint_to
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_u64_varint_to
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.
encode_u128_varint_to
Encodes an u128 value into LEB128 variable length format, and writes it to the buffer.
encoded_char_len
Returns the encoded length of the value in LEB128 variable length format. The returned value will be in range char::ENCODED_LEN_RANGE.
encoded_duration_len
Returns the encoded length of the value in LEB128 variable length format. The returned value will be in range Duration::ENCODED_LEN_RANGE.
encoded_i8_varint_len
Returns the encoded length of the value in LEB128 variable length format. The returned value will be in range of i8::ENCODED_LEN_RANGE.
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_u8_varint_len
Returns the encoded length of the value in LEB128 variable length format. The returned value will be in range of u8::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.

Type Aliases§

CharBuffer
A buffer for storing LEB128 encoded char value.
DurationBuffer
A buffer for storing LEB128 encoded Duration value.