Expand description
§pw_varint
pw_varint provides support for encoding and decoding variable length
integers. Small values require less memory than they do with fixed
encoding. Signed integers are first zig-zag encoded to allow small
negative numbers to realize the memory savings. For more information see
Pigweed’s pw_varint documentation.
The encoding format used is compatible with Protocol Buffers.
Encoding and decoding is provided through the VarintEncode and VarintDecode traits.
§Example
use pw_varint::{VarintEncode, VarintDecode};
let mut buffer = [0u8; 64];
let encoded_len = (-1i64).varint_encode(&mut buffer).unwrap();
let (decoded_len, val) = i64::varint_decode(&buffer ).unwrap();Constants§
- MAX_
VARINT_ SIZE_ BYTES - Maximum encoded size in bytes of a 64-bit LEB128 varint.
Traits§
- Varint
Decode - A trait for objects that can be decoded from a varint.
- Varint
Encode - A trait for objects that can be encoded into a varint.
Functions§
- zig_
zag_ decode - Decodes a zig-zag encoded 64-bit signed integer.
- zig_
zag_ encode - ZigZag encodes a signed integer. This maps small negative numbers to small, unsigned positive numbers, which improves their density for LEB128 encoding.