Crates.io | varintbuf |
lib.rs | varintbuf |
version | 0.1.0 |
source | src |
created_at | 2020-06-11 21:06:24.82797 |
updated_at | 2020-06-11 21:06:24.82797 |
description | varinteger encoding/decoding with bytes |
homepage | |
repository | https://github.com/mattsse/varintbuf |
max_upload_size | |
id | 252990 |
size | 21,005 |
This crate provides varint encoding/decoding and is based on the varinteger crate, but is adapted for bytes.
extern crate bytes;
// decode a `u64` integer from a buffer
let mut buf = &[100u8, 232, 7][..];
let value = varintbuf::decode(&mut buf);
assert_eq!(value, 100);
let mut buf = Bytes::from(buf);
let value = varintbuf::decode(&mut buf);
assert_eq!(value, 1000)
extern crate bytes;
// encode a `u64` integer into a buffer
let mut buf = Vec::new();
let mut bytes_encoded = encode(100, &mut buf);
assert_eq!(buf[0], 100);
let mut buf = BytesMut::from(&*buf);
bytes_encoded += encode(1000, &mut buf);
assert_eq!(buf[1], 232);
assert_eq!(buf[2], 7);
assert_eq!(bytes_encoded, 3);
assert_eq!(bytes_encoded, buf.len());
Licensed under either of these: