#protobuf #google #varint

varint

A Rust implementation of Google Protobuf's Variable-Length Integers

4 releases (breaking)

Uses old Rust 2015

0.9.0 Oct 22, 2015
0.2.0 Aug 8, 2015
0.1.0 Aug 7, 2015
0.0.0 Aug 3, 2015

#1271 in Encoding

Download history 154/week @ 2023-10-14 132/week @ 2023-10-21 134/week @ 2023-10-28 134/week @ 2023-11-04 121/week @ 2023-11-11 145/week @ 2023-11-18 143/week @ 2023-11-25 106/week @ 2023-12-02 152/week @ 2023-12-09 119/week @ 2023-12-16 118/week @ 2023-12-23 233/week @ 2023-12-30 128/week @ 2024-01-06 164/week @ 2024-01-13 101/week @ 2024-01-20 126/week @ 2024-01-27

543 downloads per month
Used in 21 crates (11 directly)

MIT license

20KB
394 lines

Varint-rs

[API Documentation]
##Variable-length integer implementation in Rust

Build Status Crates.io Coverage Status

###Notes for 0.9

  • Reading and writing 64-bit Varints is currently unsupported, but will be added in 1.0 after testing current functionality
  • If you're using the io-operations feature for IoOperations 0.2 integration, please note that it will be refactored in the next release.
  • Real-world tests are still in progress. Theoretically, however, everything should work.

###List of feature flags

  • io-operations - Preliminary integration with the IO-Operations library

###Examples

extern crate varint;
use varint::{ VarintRead, VarintWrite }; //Using IO-Operations? Replace with VarintReader and VarintWriter, the functions are the same

use std::io::Cursor; //Currently supports Cursor<Vec<u8>> and TcpStream, but should be okay to implement in any Read/Write trait

let mut vector = Cursor::new(vec![0u8; 0]);

assert!(vector.write_signed_varint_32(2346784).is_ok()); //You can check this however you like. Try! could work. I'll check it out in Netherrack and update this by 1.0

//Do whatever you need to do.
vector.set_position(0); //If you're using a TcpStream, you'd probably switch sides and into a different codebase. This is just a quick example before I fall asleep :)

assert_eq!(2346784, vector.read_signed_varint_32().unwrap()); //You could also use try! here. Again, I'll test it in a real world project and update later

Dependencies

~30KB