A Rust crate for convenient serialization and deserialization of byte-oriented data.
byteable is a Rust crate providing traits and utilities for seamless conversion between data structures and byte arrays, handling both synchronous and asynchronous I/O operations, and managing endianness.
Features
ByteableTrait: The core trait for types that can be converted to and from a byte array.ReadByteable&WriteByteableTraits: Extension traits forstd::io::Readandstd::io::Write, enabling convenient reading and writing ofByteabletypes.AsyncReadByteable&AsyncWriteByteableTraits (withtokiofeature): Asynchronous counterparts toReadByteableandWriteByteable, designed for use withtokio's async I/O.EndianableTrait & Wrappers: Provides methods for converting primitive types between different endianness (little-endian and big-endian), along withBigEndian<T>andLittleEndian<T>wrapper types.#[derive(Byteable)](withderivefeature): A procedural macro that automatically implements theByteabletrait for structs, significantly simplifying boilerplate.
Installation
Add byteable to your Cargo.toml:
[]
= "*" # Or specify the latest version
To enable the derive macro and tokio integration, you can specify features:
[]
= { = "*", = ["derive", "tokio"] }
Usage
Basic Byteable Conversion
Implement the Byteable trait manually or use the #[derive(Byteable)] macro (with the derive feature enabled):
use ;
use Cursor;
// For single-field structs
;
Endianness Conversion
use ;
Asynchronous I/O (with tokio feature)
async
Contributing
Feel free to open issues or submit pull requests.
License
This project is licensed under MIT.