Expand description
varing
Protobuf’s varint encoding/decoding for LEB128 friendly types with full const context operations supports.
§Installation
[dependencies]
varing = "0.5"
§Optional Features
arbitrary-int
: Support encode/decodearbitrary-int
types by using LEB128.bnum
: Support encode/decodebnum
types by using LEB128.chrono
: Support encode/decodechrono
types by using LEB128 (not fully compatible inconst
context).chrono-tz
: Support encode/decodechrono-tz
types by using LEB128.ethereum-types
: Support encode/decodeethereum-types
types by using LEB128.half
: Support encode/decodehalf
types by using LEB128.num-complex
: Support encode/decodenum-complex
types by using LEB128.num-rational
: Support encode/decodenum-rational
types by using LEB128.primitive-types
: Support encode/decodeprimitive-types
types by using LEB128.ruint
: Support encode/decoderuint
types by using LEB128 (not compatible inconst
context).time
: Support encode/decodetime
types 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
bnum
types. - chrono
chrono_0_4
- LEB128 encoding/decoding for
chrono
types. - chrono_
tz chrono-tz_0_10
- LEB128 encoding/decoding for
chrono-tz
types. - ethereum_
types ethereum-types_0_15
- LEB128 encoding/decoding for
ethereum-types
types. - num_
complex num-complex_0_4
- LEB128 encoding/decoding for
num-complex
types. - num_
rational num-rational_0_4
- LEB128 encoding/decoding for
num-rational
types. - packable
- Packable trait for types that can be packed into a single value.
- primitive_
types primitive-types_0_13
- LEB128 encoding/decoding for
primitive-types
types. - time
time_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.
- Sequence
Decoder - An iterator that decodes a sequence of varint values from a buffer.
Enums§
- 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.
- 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§
- Char
Buffer - A buffer for storing LEB128 encoded
char
value.