ByteCraft
A high-performance, type-safe binary data reading and writing library for Rust with compile-time endianness support and zero-cost abstractions.
Features
Powerful Trait System
- Readable/Writable traits - Composable serialization/deserialization
- Peekable trait - Non-consuming data inspection
- Type safety - Full bounds checking and error handling
High Performance
- Zero-copy operations - Direct buffer access
- Minimal allocations - Efficient memory usage
Safety First
- Complete bounds checking - Prevents buffer overflows
- Detailed error types - Informative error messages
- Memory safety - Idiomatic Rust safety guarantees
- Thread safe - Send + Sync where appropriate
Ergonomic API
- Intuitive navigation - Skip, rewind, seek operations
- Flexible buffer support - Works with Vec, slices, arrays, custom types
- Rich ecosystem - Built-in support for standard types
- Symmetric design - Consistent Reader/Writer APIs
Installation
Add this to your Cargo.toml:
[]
= "0.2"
Change Log
See ChangeLog.md.
Supported Rust Versions
The bytecraft crate now supports 1.89.0 rust version.
Examples
Quick start:
use ;
// Reading binary data
let data = ;
let mut reader = new;
let first_byte: u8 = reader.read.unwrap;
let word: u16 = reader.read.unwrap;
// Writing binary data
let mut buffer = ;
let mut writer = new;
writer.write.unwrap;
writer.write_exact.unwrap;
// Complex structures
Navigation and Positioning:
use ;
let mut reader = new;
reader.skip?; // Skip 10 bytes forward
reader.rewind?; // Rewind 5 bytes backward
reader.seek?; // Seek to beginning
reader.seek?; // Seek 4 bytes from end
Endianness Control:
use ;
let mut reader = with_endian;
let value: u32 = reader.read?; // Big-endian reading
reader.set_endian;
let value: u32 = reader.read?; // Little-endian reading
Peeking Operations:
// Peek at data without consuming it
let preview: u32 = reader.peek?;
assert_eq!; // Position unchanged
// Read and consume
let actual: u32 = reader.read?;
assert_eq!;
Collection Support:
// Length-prefixed collections
let vec: = reader.read?; // Reads length + elements
let string: String = reader.read?; // Reads length + UTF-8 data
let cstring: CString = reader.read?; // Reads null-terminated data
TODO
no_stdsupport.
Related Projects
Other crates for byte manipulation, reading, writing:
- byteorder: A library with read/write operations for primitives in ByteBuffer with support for bit operations
- bytebuffer: The crate provides methods for encoding and decoding numbers in either big-endian or little-endian order
- bytes: The crate provides a byte buffer structure (Bytes) and functions for working with buffer implementations (Buf, BufMut).
- binary_util: Crate provides structures: ByteReader and ByteWriter, which are based on the bytes crate
License
Bytecraft is under the terms of:
- the MIT License; and/or
- the Apache License v2.0.