12 releases
| 0.0.12 | Oct 9, 2024 |
|---|---|
| 0.0.11 | Sep 26, 2024 |
| 0.0.6 | Aug 22, 2024 |
| 0.0.5 | May 27, 2024 |
| 0.0.3 | Jan 29, 2024 |
#574 in Parser implementations
171 downloads per month
Used in 34 crates
(28 directly)
22KB
423 lines
flood-rs
A Rust library for reading and writing octet streams, facilitating custom serialization and deserialization.
Overview
flood-rs provides traits and implementations for working with networked ordered, big endian octet streams.
It defines the WriteOctetStream and ReadOctetStream traits for writing to and reading from octet streams,
along with concrete implementations like OutOctetStream and InOctetStream.
This library is useful for scenarios requiring custom serialization logic, such as network protocols, file formats, or inter-process communication.
Features
- Custom Octet Stream Traits: Implement
WriteOctetStreamandReadOctetStreamto define your own serialization logic. - Built-in Implementations: Use
OutOctetStreamfor writing andInOctetStreamfor reading in-memory byte buffers. - Primitive Type Support: Read and write primitive types like u8, i8, u16, i16, u32, i32, u64, and i64.
- Serialization Traits: Implement
SerializeandDeserializefor custom data structures.
Installation
Add flood-rs to your Cargo.toml:
[dependencies]
flood-rs = "0.0.7"
Usage
Writing Data to an Octet Stream
use flood_rs::{OutOctetStream, WriteOctetStream};
use std::io::Result;
fn main() -> Result<()> {
let mut stream = OutOctetStream::new();
stream.write_u32(42)?;
stream.write_i16(-123)?;
stream.write_u8(255)?;
let octets = stream.octets();
Ok(())
}
Reading Data from an Octet Stream
use flood_rs::{InOctetStream, ReadOctetStream};
use std::io::Result;
fn main() -> Result<()> {
let data = &[0x00, 0x00, 0x00, 0x2A, 0xFF, 0x85, 0xFF];
let mut stream = InOctetStream::new(data);
let value_u32 = stream.read_u32()?;
let value_i16 = stream.read_i16()?;
let value_u8 = stream.read_u8()?;
// Use the deserialized values
println!("u32: {}, i16: {}, u8: {}", value_u32, value_i16, value_u8);
Ok(())
}
License
This project is licensed under the MIT License. See the LICENSE file for details.