varint_bytes 0.1.0

Helper library for reading/writing variable length integers
Documentation
  • Coverage
  • 88.89%
    8 out of 9 items documented3 out of 8 items with examples
  • Size
  • Source code size: 9.37 kB This is the summed size of all the files inside the crates.io package for this release.
  • Documentation size: 179.18 kB This is the summed size of all files generated by rustdoc for all configured targets
  • Ø build duration
  • this release: 10s Average build duration of successful builds.
  • all releases: 10s Average build duration of successful builds in releases after 2024-10-23.
  • Links
  • benaubin/varint_bytes
    1 0 0
  • crates.io
  • Dependencies
  • Versions
  • Owners
  • benaubin

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 and forbid(unsafe_code)