A teeworlds variable int packer/unpacker in Rust.
Go to file
2023-02-26 11:49:32 +01:00
.github/workflows Create rust.yml 2022-11-12 17:43:26 +01:00
src correctness, inline 2023-02-06 18:39:38 +01:00
.gitignore initial 2022-11-11 15:38:19 +01:00
Cargo.toml 1.0 2023-02-26 11:49:32 +01:00
LICENSE-APACHE Create LICENSE-APACHE 2022-11-12 17:43:03 +01:00
LICENSE-MIT Create LICENSE-MIT 2022-11-12 17:42:39 +01:00
README.md better 2022-11-12 17:42:08 +01:00

teeint

Version Downloads License Rust Docs

A teeworlds variable integer packer/unpacker.

Packing

use std::io::Cursor;

let mut buff = Cursor::new([0; 2]);

teeint::pack(&mut buff, 64).unwrap();

let buff = buff.into_inner();
assert_eq!(buff[0], 0b1000_0000);
assert_eq!(buff[1], 0b0000_0001);

Or using the trait [PackTwInt]:

use std::io::Cursor;
use teeint::PackTwInt;

let mut buff = Cursor::new([0; 2]);

64.pack(&mut buff).unwrap();

let buff = buff.into_inner();
assert_eq!(buff[0], 0b1000_0000);
assert_eq!(buff[1], 0b0000_0001);

Or

use teeint::PackTwInt;

let mut buff = [0; 2];
64.pack(&mut buff.as_mut_slice()).unwrap();
assert_eq!(buff[0], 0b1000_0000);
assert_eq!(buff[1], 0b0000_0001);

Unpacking

use std::io::Cursor;

let mut buff = Cursor::new([0b1000_0000, 0b0000_0001]);
let data = teeint::unpack(&mut buff).unwrap();
assert_eq!(data, 64);

Or using the trait [UnPackTwInt]:

use teeint::UnPackTwInt;

let buff = [0b1000_0000, 0b0000_0001];
let result = buff.as_slice().unpack().unwrap();
assert_eq!(result, 64);

License: MIT OR Apache-2.0