4 个版本 (1 个稳定版)
1.0.0 | 2023年2月26日 |
---|---|
0.1.2 | 2023年2月6日 |
0.1.1 | 2022年11月13日 |
0.1.0 | 2022年11月12日 |
#1175 in 算法
14KB
236 行
teeint
一个 teeworlds 变量整数打包/解包器。
打包
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);
或者使用特质 [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);
或者
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);
解包
use std::io::Cursor;
let mut buff = Cursor::new([0b1000_0000, 0b0000_0001]);
let data = teeint::unpack(&mut buff).unwrap();
assert_eq!(data, 64);
或者使用特质 [UnPackTwInt]
use teeint::UnPackTwInt;
let buff = [0b1000_0000, 0b0000_0001];
let result = buff.as_slice().unpack().unwrap();
assert_eq!(result, 64);
许可证:MIT OR Apache-2.0