Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/mattsse/varintbuf
varint encoding and decoding
https://github.com/mattsse/varintbuf
Last synced: 18 days ago
JSON representation
varint encoding and decoding
- Host: GitHub
- URL: https://github.com/mattsse/varintbuf
- Owner: mattsse
- License: apache-2.0
- Created: 2020-06-11T21:04:50.000Z (over 4 years ago)
- Default Branch: master
- Last Pushed: 2020-06-11T21:09:18.000Z (over 4 years ago)
- Last Synced: 2024-10-06T21:42:05.926Z (about 1 month ago)
- Language: Rust
- Size: 7.81 KB
- Stars: 0
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE-APACHE
Awesome Lists containing this project
README
varintbuf
=====================
![Build](https://github.com/mattsse/varintbuf/workflows/Continuous%20integration/badge.svg)
[![Crates.io](https://img.shields.io/crates/v/varintbuf.svg)](https://crates.io/crates/varintbuf)
[![Documentation](https://docs.rs/varintbuf/badge.svg)](https://docs.rs/varintbuf)This crate provides varint encoding/decoding and is based on the [varinteger](https://github.com/datrs/varinteger/) crate, but is adapted for [bytes](https://github.com/tokio-rs/bytes).
## Usage
## Decode
```rust
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
```rust
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:
* Apache License, Version 2.0, ([LICENSE-APACHE](LICENSE-APACHE) or
https://www.apache.org/licenses/LICENSE-2.0)
* MIT license ([LICENSE-MIT](LICENSE-MIT) or
https://opensource.org/licenses/MIT)