Crates.io | fleabit |
lib.rs | fleabit |
version | 0.1.2 |
source | src |
created_at | 2022-12-12 02:06:34.792844 |
updated_at | 2022-12-12 05:12:06.741578 |
description | Read and write unaligned bytes. |
homepage | |
repository | https://github.com/gak/fleabit |
max_upload_size | |
id | 734610 |
size | 25,250 |
fleabit is a Rust crate that allows reading and writing unaligned bytes. It provides a simple API and is built on top of bitvec.
It is intended for a multiplayer game library that's in development.
Note that this crate is probably not production ready. Use at your own discretion.
use fleabit::{FleaBitReader, FleaBitWriter};
let mut writer = FleaBitWriter::new();
writer.bool(false);
assert_eq!(writer.to_string(), ".......0");
writer.u8(135);
assert_eq!(writer.to_string(), "00001110_.......1");
let bytes = writer.into_vec();
assert_eq!(bytes, vec![0x0e, 0x01]);
let mut reader = FleaBitReader::from_slice(&bytes);
assert_eq!(reader.bool(), false);
assert_eq!(reader.u8(), 135);
fleabit is licensed under either the MIT license or the Apache-2.0 license, at your discretion.