[−][src]Crate varint_bytes
Helper library for reading/writing variable length integers
use varint_bytes::{GetVarInt, PutVarInt}; use bytes::{BytesMut}; let mut bytes = &[0b1010_1100, 0b0000_0010][..]; let num: u32 = bytes.get_varint(); assert_eq!(num, 300); let mut bytes = BytesMut::new(); bytes.put_varint(300 as u32); assert_eq!(bytes[..], [0b1010_1100, 0b0000_0010][..]);
Advantages:
- Misuse resistant - won't read more than the maximum size of the output type or past the input
- Uses tokio/bytes's
Buf
no_std
andforbid(unsafe_code)
Traits
GetVarInt | Allows reading variable length integers from |
PutVarInt | Allows writing variable length integers to |
ZigZag | Handles zig-zag encoding |