Skip to main content Skip to main content
Pigweed's logo Pigweed
code_xml
  1. Home
  2. Reference
  3. Rust
  4. pw_varint

Crate pw_varint

Crate pw_varint 

Source
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§

VarintDecode
A trait for objects that can be decoded from a varint.
VarintEncode
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.