Ultra-fast binary serialization with multi-format compression and zero-copy deserialization
Perfect
nanobit is a high-performance binary serialization library designed for maximum efficiency and minimal overhead. Built with zero-copy deserialization, multi-format compression support, and seamless serde integration, it's perfect for database storage, network protocols, and high-throughput applications.
Features
- 🚀 Ultra-Fast Performance - Zero-copy deserialization where possible with minimal allocations
- 🗜️ Multi-Format Compression - Built-in support for LZ4, ZSTD, and Snappy compression
- 🔧 Auto-Format Detection - Intelligent decompression that automatically detects compression formats
- 🎯 Zero Dependencies - Core library works without std, perfect for embedded systems
- 📦 Serde Compatible - Seamless integration with the serde ecosystem
- 🔒 Memory Safe - No unsafe code in the core library
- ⚙️ Configurable - Feature flags for optional dependencies and compression algorithms
- 🔄 Future-Ready - Extensible architecture for custom compression formats
Installation
Add nanobit to your Cargo.toml:
[]
= "0.2"
Feature Flags
Enable specific compression formats:
[]
= { = "0.2", = ["compression", "multi-compression"] }
Available features:
std- Standard library support (enabled by default)serde- Serde integration (enabled by default)compression- LZ4 compression support (enabled by default)multi-compression- ZSTD and Snappy support (enabled by default)async- Async serialization support
Quick Start
use ;
use ;
Usage Examples
Basic Serialization
use ;
// Serialize any serde-compatible type
let data = vec!;
let bytes = serialize?;
let recovered: = deserialize?;
Compression Support
use ;
let data = b"Hello, world!".repeat;
// Compress with specific format and level
let compressed = compress?;
// Automatic format detection during decompression
let decompressed = decompress?;
Zero-Copy String Deserialization
use ;
let message = "Hello, nanobit!";
let serialized = to_bytes?;
// Zero-copy deserialization - borrows from serialized data
let text: &str = from_bytes?;
println!; // No allocation!
Compression Formats
use ;
let data = b"Compressible data".repeat;
// LZ4 - Fastest compression/decompression
let lz4_data = compress?;
// ZSTD - Best compression ratio
let zstd_data = compress?;
// Snappy - Balanced speed and compression
let snappy_data = compress?;
Checking Serialized Data
use ;
let data = "test data";
let serialized = to_bytes?;
if is_serialized
Working with Streams
use ;
use ;
let data = vec!;
let mut buffer = Vecnew;
// Serialize to writer
to_writer?;
// Deserialize from reader
let cursor = new;
let recovered: = from_reader?;
Performance
nanobit is designed for maximum performance:
- Zero-copy deserialization for strings and byte slices
- Efficient varint encoding for space optimization
- Minimal allocations during serialization/deserialization
- Fast compression with multiple algorithm choices
- Optimized for database storage with compact binary format
Typical performance characteristics:
- Serialization: ~2-5 GB/s depending on data complexity
- Deserialization: ~3-8 GB/s with zero-copy optimizations
- Compression: Format-dependent (LZ4: fastest, ZSTD: best ratio)
Format Specification
nanobit uses a compact binary format:
[MAGIC: 4 bytes]["NANO"] [VERSION: 1 byte] [PAYLOAD: variable]
- Header: 5 bytes total (magic + version)
- Magic Bytes:
"NANO"for format identification - Version: Currently
0x01for forward compatibility - Payload: Serde-serialized data with varint encoding
Error Handling
use ;
match
no_std Support
nanobit works in no_std environments:
[]
= { = "0.1", = false, = ["serde"] }
Contributing
We welcome contributions! Please see our Contributing Guide for details.
- Fork the repository
- Create your feature branch (
git checkout -b feature/amazing-feature) - Commit your changes (
git commit -m 'Add amazing feature') - Push to the branch (
git push origin feature/amazing-feature) - Open a Pull Request
License
This project is licensed under the Apache-2.0 License - see the LICENSE file for details.
Benchmarks
See benchmarks for detailed performance comparisons with other serialization libraries including bincode, postcard, and rmp-serde.
Built with ❤️ for high-performance applications