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.EndianConvertTrait & Wrappers: Provides methods for converting primitive types between different endianness (little-endian and big-endian), along withBigEndian<T>andLittleEndian<T>wrapper types.#[derive(UnsafeByteable)](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
Here's a quick example demonstrating basic usage with file I/O:
use ;
use File;
The same ReadByteable and WriteByteable traits work with any Read/Write implementor, including TCP streams, in-memory buffers, and more. For more examples, check out the examples/ directory.
Contributing
Feel free to open issues or submit pull requests.
License
This project is licensed under MIT.