Crate varing

Source
Expand description

varing

Protobuf’s varint encoding/decoding for LEB128 friendly types with full const context operations supports.

github LoC Build codecov

docs.rs crates.io crates.io license

§Installation

[dependencies]
varing = "0.5"

§Optional Features

§Testing

This crate is tested with the quickcheck crate and cargo fuzz (including all optional features).

§License

varing 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
bnumbnum_0_13
LEB128 encoding/decoding for bnum types.
chronochrono_0_4
LEB128 encoding/decoding for chrono types.
chrono_tzchrono-tz_0_10
LEB128 encoding/decoding for chrono-tz types.
ethereum_typesethereum-types_0_15
LEB128 encoding/decoding for ethereum-types types.
num_complexnum-complex_0_4
LEB128 encoding/decoding for num-complex types.
num_rationalnum-rational_0_4
LEB128 encoding/decoding for num-rational types.
packable
Packable trait for types that can be packed into a single value.
primitive_typesprimitive-types_0_13
LEB128 encoding/decoding for primitive-types types.
timetime_0_3
LEB128 encoding/decoding for time types.
utils
Utilities for encoding and decoding LEB128 variable length integers.

Structs§

MapDecoder
An iterator that decodes a sequence of varint values from a buffer.
SequenceDecoder
An iterator that decodes a sequence of varint values from a buffer.

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_f16_varint
Decodes an f16 in LEB128 encoded format from the buffer.
decode_f32_varint
Decodes an f32 in LEB128 encoded format from the buffer.
decode_f64_varint
Decodes an f64 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_map
Decodes a collection of entries from the buffer.
decode_sequence
Decodes a sequence of values 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_f16_sequence_to
Encodes a sequence of f16 to the buffer.
encode_f16_varint
Encodes an f16 value into LEB128 variable length format, and writes it to the buffer.
encode_f16_varint_to
Encodes an f16 value into LEB128 variable length format, and writes it to the buffer.
encode_f32_sequence_to
Encodes a sequence of f32 to the buffer.
encode_f32_varint
Encodes an f32 value into LEB128 variable length format, and writes it to the buffer.
encode_f32_varint_to
Encodes an f32 value into LEB128 variable length format, and writes it to the buffer.
encode_f64_sequence_to
Encodes a sequence of f64 to the buffer.
encode_f64_varint
Encodes an f64 value into LEB128 variable length format, and writes it to the buffer.
encode_f64_varint_to
Encodes an f64 value into LEB128 variable length format, and writes it to the buffer.
encode_i8_sequence_to
Encodes a sequence of i8 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_sequence_to
Encodes a sequence of i16 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_sequence_to
Encodes a sequence of i32 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_sequence_to
Encodes a sequence of i64 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_sequence_to
Encodes a sequence of i128 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_map
Encodes a map of entries as varints and writes them to the buffer.
encode_sequence
Encodes a sequence of values as varints and writes them to the buffer.
encode_u8_sequence_to
Encodes a sequence of u8 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_sequence_to
Encodes a sequence of u16 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_sequence_to
Encodes a sequence of u32 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_sequence_to
Encodes a sequence of u64 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_sequence_to
Encodes a sequence of u128 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_f16_sequence_len
Returns the encoded length of a sequence of f16 values
encoded_f16_varint_len
Returns the encoded length of the value in LEB128 variable length format. The returned value will be in range of [f16::ENCODED_LEN_RANGE].
encoded_f32_sequence_len
Returns the encoded length of a sequence of f32 values
encoded_f32_varint_len
Returns the encoded length of the value in LEB128 variable length format. The returned value will be in range of f32::ENCODED_LEN_RANGE.
encoded_f64_sequence_len
Returns the encoded length of a sequence of f64 values
encoded_f64_varint_len
Returns the encoded length of the value in LEB128 variable length format. The returned value will be in range of f64::ENCODED_LEN_RANGE.
encoded_i8_sequence_len
Returns the encoded length of a sequence of i8 values
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_sequence_len
Returns the encoded length of a sequence of i16 values
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_sequence_len
Returns the encoded length of a sequence of i32 values
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_sequence_len
Returns the encoded length of a sequence of i64 values
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_sequence_len
Returns the encoded length of a sequence of i128 values
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_map_len
Returns the total length of a map of entries.
encoded_sequence_len
Returns the total number of bytes needed to encode a sequence of values.
encoded_u8_sequence_len
Returns the encoded length of a sequence of u8 values
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_sequence_len
Returns the encoded length of a sequence of u16 values
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_sequence_len
Returns the encoded length of a sequence of u32 values
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_sequence_len
Returns the encoded length of a sequence of u64 values
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_sequence_len
Returns the encoded length of a sequence of u128 values
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.
map_decoder
Returns a sequence decoder for the given buffer.
sequence_decoder
Returns a sequence decoder for the given buffer.

Type Aliases§

CharBuffer
A buffer for storing LEB128 encoded char value.