1 unstable release
0.1.0 | Nov 26, 2020 |
---|
#7 in #reading-writing
9KB
151 lines
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)
Dependencies
~220KB