Expand description
varing
Protobuf’s varint encoding/decoding for LEB128 friendly types with full const context operations supports.
§Installation
[dependencies]
varing = "0.10"§Optional Features
arbitrary-int: Support encode/decodearbitrary-inttypes by using LEB128.bnum: Support encode/decodebnumtypes by using LEB128.chrono: Support encode/decodechronotypes by using LEB128 (not fully compatible inconstcontext).chrono-tz: Support encode/decodechrono-tztypes by using LEB128.ethereum-types: Support encode/decodeethereum-typestypes by using LEB128.float8: Support encode/decodefloat8types by using LEB128.half: Support encode/decodehalftypes by using LEB128.num-complex: Support encode/decodenum-complextypes by using LEB128.num-rational: Support encode/decodenum-rationaltypes by using LEB128.primitive-types: Support encode/decodeprimitive-typestypes by using LEB128.ruint: Support encode/decoderuinttypes by using LEB128 (not compatible inconstcontext).time: Support encode/decodetimetypes by using LEB128.
§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_
int arbitrary-int - LEB128 encoding/decoding for
u1,u2..u127 - bnum
bnum_0_13 - LEB128 encoding/decoding for
bnumtypes. - chrono
chrono_0_4 - LEB128 encoding/decoding for
chronotypes. - chrono_
tz chrono-tz_0_10 - LEB128 encoding/decoding for
chrono-tztypes. - ethereum_
types ethereum-types_0_15 - LEB128 encoding/decoding for
ethereum-typestypes. - num_
complex num-complex_0_4 - LEB128 encoding/decoding for
num-complextypes. - num_
rational num-rational_0_4 - LEB128 encoding/decoding for
num-rationaltypes. - packable
- Packable trait for types that can be packed into a single value.
- primitive_
types primitive-types_0_13 - LEB128 encoding/decoding for
primitive-typestypes. - time
time_0_3 - LEB128 encoding/decoding for
timetypes. - utils
- Utilities for encoding and decoding LEB128 variable length integers.
Structs§
- Insufficient
Space - An error that occurs when trying to write data to a buffer with insufficient space.
- MapDecoder
- An iterator that decodes a sequence of varint values from a buffer.
- Sequence
Decoder - An iterator that decodes a sequence of varint values from a buffer.
Enums§
- Const
Decode Error - Decoding varint error.
- Const
Encode Error - Encode varint error
- Decode
Error - Decoding varint error.
- Encode
Error - 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.
- consume_
varint_ checked - Calculates the number of bytes occupied by a varint encoded value in the buffer.
- decode_
char - Decodes a
charin LEB128 encoded format from the buffer. - decode_
duration - Decodes a
Durationin LEB128 encoded format from the buffer. - decode_
f8e4m3_ varint - Decodes an
F8E4M3in LEB128 encoded format from the buffer. - decode_
f8e5m2_ varint - Decodes an
F8E5M2in LEB128 encoded format from the buffer. - decode_
f16_ varint - Decodes an
f16in LEB128 encoded format from the buffer. - decode_
f32_ varint - Decodes an
f32in LEB128 encoded format from the buffer. - decode_
f64_ varint - Decodes an
f64in LEB128 encoded format from the buffer. - decode_
i8_ varint - Decodes an
u8in LEB128 encoded format from the buffer. - decode_
i16_ varint - Decodes an
u16in LEB128 encoded format from the buffer. - decode_
i32_ varint - Decodes an
u32in LEB128 encoded format from the buffer. - decode_
i64_ varint - Decodes an
u64in LEB128 encoded format from the buffer. - decode_
i128_ varint - Decodes an
u128in 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
i8in LEB128 encoded format from the buffer. - decode_
u16_ varint - Decodes an
i16in LEB128 encoded format from the buffer. - decode_
u32_ varint - Decodes an
i32in LEB128 encoded format from the buffer. - decode_
u64_ varint - Decodes an
i64in LEB128 encoded format from the buffer. - decode_
u128_ varint - Decodes an
i128in LEB128 encoded format from the buffer. - encode_
char - Encodes a
charvalue into LEB128 variable length format, and writes it to the buffer. - encode_
char_ to - Encodes a
charvalue into LEB128 variable length format, and writes it to the buffer. - encode_
duration - Encodes a
Durationvalue into LEB128 variable length format, and writes it to the buffer. - encode_
duration_ to - Encodes a
Durationvalue into LEB128 variable length format, and writes it to the buffer. - encode_
f8e4m3_ sequence_ to - Encodes a sequence of
F8E4M3to the buffer. - encode_
f8e4m3_ varint - Encodes a
F8E4M3value into LEB128 variable length format, and writes it to the buffer. - encode_
f8e4m3_ varint_ to - Encodes a
F8E4M3value into LEB128 variable length format, and writes it to the buffer. - encode_
f8e5m2_ sequence_ to - Encodes a sequence of
F8E5M2to the buffer. - encode_
f8e5m2_ varint - Encodes a
F8E5M2value into LEB128 variable length format, and writes it to the buffer. - encode_
f8e5m2_ varint_ to - Encodes a
F8E5M2value into LEB128 variable length format, and writes it to the buffer. - encode_
f16_ sequence_ to - Encodes a sequence of
f16to the buffer. - encode_
f16_ varint - Encodes an
f16value into LEB128 variable length format, and writes it to the buffer. - encode_
f16_ varint_ to - Encodes an
f16value into LEB128 variable length format, and writes it to the buffer. - encode_
f32_ sequence_ to - Encodes a sequence of
f32to the buffer. - encode_
f32_ varint - Encodes an
f32value into LEB128 variable length format, and writes it to the buffer. - encode_
f32_ varint_ to - Encodes an
f32value into LEB128 variable length format, and writes it to the buffer. - encode_
f64_ sequence_ to - Encodes a sequence of
f64to the buffer. - encode_
f64_ varint - Encodes an
f64value into LEB128 variable length format, and writes it to the buffer. - encode_
f64_ varint_ to - Encodes an
f64value into LEB128 variable length format, and writes it to the buffer. - encode_
i8_ sequence_ to - Encodes a sequence of
i8to the buffer. - encode_
i8_ varint - Encodes an
i8value into LEB128 variable length format, and writes it to the buffer. - encode_
i8_ varint_ to - Encodes an
i8value into LEB128 variable length format, and writes it to the buffer. - encode_
i16_ sequence_ to - Encodes a sequence of
i16to the buffer. - encode_
i16_ varint - Encodes an
i16value into LEB128 variable length format, and writes it to the buffer. - encode_
i16_ varint_ to - Encodes an
i16value into LEB128 variable length format, and writes it to the buffer. - encode_
i32_ sequence_ to - Encodes a sequence of
i32to the buffer. - encode_
i32_ varint - Encodes an
i32value into LEB128 variable length format, and writes it to the buffer. - encode_
i32_ varint_ to - Encodes an
i32value into LEB128 variable length format, and writes it to the buffer. - encode_
i64_ sequence_ to - Encodes a sequence of
i64to the buffer. - encode_
i64_ varint - Encodes an
i64value into LEB128 variable length format, and writes it to the buffer. - encode_
i64_ varint_ to - Encodes an
i64value into LEB128 variable length format, and writes it to the buffer. - encode_
i128_ sequence_ to - Encodes a sequence of
i128to the buffer. - encode_
i128_ varint - Encodes an
i128value into LEB128 variable length format, and writes it to the buffer. - encode_
i128_ varint_ to - Encodes an
i128value 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
u8to the buffer. - encode_
u8_ varint - Encodes an
u8value into LEB128 variable length format, and writes it to the buffer. - encode_
u8_ varint_ to - Encodes an
u8value into LEB128 variable length format, and writes it to the buffer. - encode_
u16_ sequence_ to - Encodes a sequence of
u16to the buffer. - encode_
u16_ varint - Encodes an
u16value into LEB128 variable length format, and writes it to the buffer. - encode_
u16_ varint_ to - Encodes an
u16value into LEB128 variable length format, and writes it to the buffer. - encode_
u32_ sequence_ to - Encodes a sequence of
u32to the buffer. - encode_
u32_ varint - Encodes an
u32value into LEB128 variable length format, and writes it to the buffer. - encode_
u32_ varint_ to - Encodes an
u32value into LEB128 variable length format, and writes it to the buffer. - encode_
u64_ sequence_ to - Encodes a sequence of
u64to the buffer. - encode_
u64_ varint - Encodes an
u64value into LEB128 variable length format, and writes it to the buffer. - encode_
u64_ varint_ to - Encodes an
u64value into LEB128 variable length format, and writes it to the buffer. - encode_
u128_ sequence_ to - Encodes a sequence of
u128to the buffer. - encode_
u128_ varint - Encodes an
u128value into LEB128 variable length format, and writes it to the buffer. - encode_
u128_ varint_ to - Encodes an
u128value 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_
f8e4m3_ sequence_ len - Returns the encoded length of a sequence of
F8E4M3values. - encoded_
f8e4m3_ varint_ len - Returns the encoded length of the value in LEB128 variable length format. The returned value will be in range of
F8E4M3::ENCODED_LEN_RANGE - encoded_
f8e5m2_ sequence_ len - Returns the encoded length of a sequence of
F8E5M2values. - encoded_
f8e5m2_ varint_ len - Returns the encoded length of the value in LEB128 variable length format. The returned value will be in range of
F8E5M2::ENCODED_LEN_RANGE - encoded_
f16_ sequence_ len - Returns the encoded length of a sequence of
f16values - 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
f32values - 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
f64values - 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
i8values - 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
i16values - 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
i32values - 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
i64values - 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
i128values - 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
u8values - 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
u16values - 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
u32values - 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
u64values - 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
u128values - 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.
- try_
consume_ varint - Calculates the number of bytes occupied by a varint encoded value in the buffer.
Type Aliases§
- Char
Buffer - A buffer for storing LEB128 encoded
charvalue.