Crates.io | binary_modifier |
lib.rs | binary_modifier |
version | 0.3.3 |
source | src |
created_at | 2023-08-28 14:59:16.195638 |
updated_at | 2023-08-28 21:46:57.473085 |
description | binary_modifier is a simple library to read & write to buffer |
homepage | |
repository | |
max_upload_size | |
id | 957073 |
size | 20,732 |
BinaryModifier is a Rust library designed to simplify working with binary data streams. It provides a set of tools for reading and writing various data types in binary format, handling endianness, seeking within streams, and more. This crate is particularly useful when dealing with tasks such as parsing binary file formats or implementing network protocols.
The Binary Modifier crate is centered around two main structs: BinaryReader and BinaryWriter. Both of these structs interact with an underlying MemoryStream, which abstracts a byte buffer for efficient in-memory manipulation of binary data.
The BinaryReader struct is used for reading data from binary streams
Example of reading an integer from the stream:
use binary_modifier::{BinaryReader, Endian};
let data = vec![0x01, 0x02, 0x03, 0x04];
let mut reader = BinaryReader::new_vec(&mut data, Endian::Big);
let value: i32 = reader.read_i32().unwrap();
println!("Read integer: {}", value);
The BinaryWriter struct is used for writing data to binary streams.
Example of writing a string to the stream:
use binary_modifier::{BinaryWriter, Endian};
let mut data = Vec::new();
let mut writer = BinaryWriter::new_vec(&mut data, Endian::Little);
let text = "Hello, Binary!";
writer.write_string(text).unwrap();
println!("Data written: {:?}", data);
To use the Binary Modifier crate in your Rust project, add the following dependency to your Cargo.toml file:
binary_modifier = "0.2.1"
Or use cargo to install it using
cargo add binary_modifier
This crate is licensed under the MIT License.
If you encounter any issues or have suggestions for improvements, please don't hesitate to contribute or report issues on GitHub.