Skip to content

varint encoding and decoding

License

Apache-2.0, MIT licenses found

Licenses found

Apache-2.0
LICENSE-APACHE
MIT
LICENSE-MIT
Notifications You must be signed in to change notification settings

mattsse/varintbuf

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

varintbuf

Build Crates.io Documentation

This crate provides varint encoding/decoding and is based on the varinteger crate, but is adapted for bytes.

Usage

Decode

    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)

Encode

    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());

License

Licensed under either of these:

About

varint encoding and decoding

Resources

License

Apache-2.0, MIT licenses found

Licenses found

Apache-2.0
LICENSE-APACHE
MIT
LICENSE-MIT

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages