Crates.io | varint |
lib.rs | varint |
version | 0.9.0 |
source | src |
created_at | 2015-08-03 06:02:41.9183 |
updated_at | 2015-12-11 23:59:34.806356 |
description | A Rust implementation of Google Protobuf's Variable-Length Integers |
homepage | |
repository | https://github.com/Techern/Varint-rs |
max_upload_size | |
id | 2749 |
size | 21,480 |
[API Documentation]
##Variable-length integer implementation in Rust
###Notes for 0.9
###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