Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/phill030/binarymodifier
https://github.com/phill030/binarymodifier
Last synced: 14 days ago
JSON representation
- Host: GitHub
- URL: https://github.com/phill030/binarymodifier
- Owner: Phill030
- License: mit
- Created: 2023-06-17T22:39:12.000Z (over 1 year ago)
- Default Branch: main
- Last Pushed: 2023-10-17T12:38:11.000Z (over 1 year ago)
- Last Synced: 2023-10-17T14:51:56.748Z (over 1 year ago)
- Language: Rust
- Size: 24.4 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# BinaryModifier
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.# Features
- Read and write primitive data types like integers, floats, characters, and more in binary format.
- Read and write length-prefixed strings from and to binary streams.
- Seek within the stream to a specific position.
- Handle endianness swapping during reading and writing processes.
- Support different data types and conversions based on the target architecture.# Usage
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.## BinaryReader
The BinaryReader struct is used for reading data from binary streamsExample of reading an integer from the stream:
```rs
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);
```## BinaryWriter
The BinaryWriter struct is used for writing data to binary streams.Example of writing a string to the stream:
```rs
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);
```# Usage
To use the Binary Modifier crate in your Rust project, add the following dependency to your Cargo.toml file:
```toml
binary_modifier = "0.3.3"
```
Or use cargo to install it using
```
cargo add binary_modifier
```# License
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.