Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/luojia65/mc-varint
Minecraft VarInt and VarLong implemetation in Rust, providing minimum memory usage and maximum performance.
https://github.com/luojia65/mc-varint
minecraft rust
Last synced: about 11 hours ago
JSON representation
Minecraft VarInt and VarLong implemetation in Rust, providing minimum memory usage and maximum performance.
- Host: GitHub
- URL: https://github.com/luojia65/mc-varint
- Owner: luojia65
- License: wtfpl
- Created: 2018-07-08T09:28:32.000Z (over 6 years ago)
- Default Branch: master
- Last Pushed: 2020-04-22T00:53:54.000Z (over 4 years ago)
- Last Synced: 2024-10-07T17:19:59.319Z (about 1 month ago)
- Topics: minecraft, rust
- Language: Rust
- Homepage:
- Size: 15.6 KB
- Stars: 12
- Watchers: 1
- Forks: 3
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# mc-varint
Minecraft VarInt and VarLong implemetation in Rust, providing minimum memory usage and maximum performance.[![Crates.io][crates-badge]][crates-url]
[![WTFPL licensed][pl-badge]][pl-url][crates-badge]: https://img.shields.io/crates/v/mc-varint.svg
[crates-url]: https://crates.io/crates/mc-varint
[pl-badge]: https://img.shields.io/badge/license-WTFPL-blue.svg
[pl-url]: LICENSE# Example
## Read a VarInt from a Read
```Rust
use mc_varint::VarIntRead;
use std::io::Cursor;
fn main() {
// firstly we create a Cursor
let mut cur = Cursor::new(vec![0xff, 0xff, 0xff, 0xff, 0x07]);
// secondly we read from it
let value = cur.read_var_i32().unwrap();
// the value is 2147483647
assert_eq!(value, 2147483647);
}
```## Write a VarInt to a Write
```Rust
use mc_varint::{VarInt, VarIntWrite};
use std::io::Cursor;
fn main() {
// firstly we create a Cursor and a VarInt
let mut cur = Cursor::new(Vec::with_capacity(5));
// secondly we write the VarInt to the Cursor
cur.write_var_i32(2147483647).unwrap();
// now the value is written to cur.
assert_eq!(cur.into_inner(), vec![0xff, 0xff, 0xff, 0xff, 0x07]);
}
```# Performance
Platform: 3.4GHz Intel Core i5
```
running 8 tests
test read_i32 ... bench: 5 ns/iter (+/- 1)
test read_i64 ... bench: 4 ns/iter (+/- 1)
test read_u32 ... bench: 4 ns/iter (+/- 1)
test read_u64 ... bench: 4 ns/iter (+/- 0)
test write_i32 ... bench: 4 ns/iter (+/- 0)
test write_i64 ... bench: 4 ns/iter (+/- 0)
test write_u32 ... bench: 4 ns/iter (+/- 0)
test write_u64 ... bench: 4 ns/iter (+/- 0)test result: ok. 0 passed; 0 failed; 0 ignored; 8 measured; 0 filtered out
```