OxiCode
A modern binary serialization library for Rust - the successor to bincode.
About
OxiCode is a compact encoder/decoder pair that uses a binary zero-fluff encoding scheme. The size of the encoded object will be the same or smaller than the size that the object takes up in memory in a running Rust program.
This project serves as the spiritual successor to bincode, maintaining 100% binary compatibility while introducing modern improvements and advanced features that make it 150% better.
Features
Core Features (100% Bincode Compatible)
- Compact encoding: Minimal overhead in serialized format
- Fast: Optimized for performance with zero-copy operations where possible
- Flexible: Support for various encoding configurations
- Safe: Strict no-unwrap policy, comprehensive error handling
- Modern: Built with latest Rust practices and 2021 edition features
- no_std support: Works in embedded and resource-constrained environments
- Bincode compatibility: 100% binary format compatibility with bincode 2.0
150% Enhancement Features (Beyond Bincode)
- ⚡ SIMD Optimization: Hardware-accelerated array encoding (2-4x speedup)
- 🗜️ Compression: LZ4 (fast) and Zstd (better ratio) support
- 📦 Schema Evolution: Version tracking and automatic migration
- 🌊 Streaming: Chunked encoding/decoding for large datasets
- ⏱️ Async Streaming: Non-blocking async I/O with tokio
- ✅ Validation: Constraint-based validation middleware
See Feature Comparison below for detailed breakdown.
Why OxiCode?
While bincode has served the Rust community well, OxiCode brings:
- 100% Binary Compatibility: Drop-in replacement with identical binary format
- Modern Rust practices: Built from the ground up with Rust 2021 edition
- Safety first: Strict no-unwrap policy throughout the codebase
- Better error handling: More informative error messages and comprehensive error types
- Advanced features: SIMD, compression, streaming, async, validation - features bincode lacks
- Active maintenance: Dedicated to long-term support and evolution
Installation
Add this to your Cargo.toml:
[]
= "0.1"
# With serde support (for serde::Serialize/Deserialize types)
= { = "0.1", = ["serde"] }
# Optional features
= { = "0.1", = ["simd", "compression", "async-tokio"] }
Feature Flags
= ["std", "derive"]
= ["alloc"] # Standard library support
= [] # Heap allocations (for no_std + alloc)
= [] # Derive macros for Encode/Decode
= [] # Serde integration (optional)
= [] # SIMD-accelerated array encoding
= [] # LZ4 compression (fast)
= [] # Zstd compression (better ratio)
= ["compression-lz4"] # Default compression
= ["tokio"] # Async streaming with tokio
= ["futures-io"] # Generic async IO traits
Quick Start
use ;
Using with Serde
OxiCode provides optional serde integration for types that implement serde::Serialize and serde::Deserialize:
use ;
Enable serde feature in Cargo.toml:
[]
= { = "0.1", = ["serde"] }
= { = "1.0", = ["derive"] }
Configuration
OxiCode supports various encoding configurations:
use config;
// Standard configuration (default): little-endian + varint
let cfg = standard;
// Legacy bincode 1.0-compatible: little-endian + fixed-int
let cfg = legacy;
// Custom configuration
let cfg = standard
.with_big_endian
.with_fixed_int_encoding
.; // 1MB limit
// Use with encoding/decoding
let bytes = encode_to_vec_with_config?;
let = decode_from_slice_with_config?;
Advanced Features
SIMD-Accelerated Arrays
Hardware acceleration for large array operations (2-4x speedup):
use ;
// Enable with features = ["simd"]
// Auto-detects CPU capabilities (SSE2, AVX2, AVX-512)
See examples/simd_arrays.rs for detailed usage.
Compression
Reduce size with LZ4 or Zstd compression:
use ;
// LZ4 - fast compression
let mut encoder = new?;
value.encode?;
// Zstd - better compression ratio
let mut encoder = new?;
value.encode?;
See examples/compression.rs for detailed usage.
Streaming Serialization
Process large datasets incrementally:
use ;
// Encode items one at a time
let mut encoder = new?;
for item in large_dataset
encoder.finish?;
// Decode items incrementally
let mut decoder = new?;
while let Some = decoder.?
See examples/streaming.rs for detailed usage.
Async Streaming
Non-blocking async I/O with tokio:
use AsyncStreamingEncoder;
// Async encoding
let mut encoder = new;
for item in dataset
let writer = encoder.finish.await?;
See examples/async_streaming.rs for detailed usage.
Validation Middleware
Validate data during decoding:
use ;
// Create validator with constraints
let mut validator = new;
validator.add_constraint;
validator.add_constraint;
// Validate decoded data
validator.validate?;
See examples/validation.rs for detailed usage.
Schema Evolution
Version your data formats and migrate gracefully:
use ;
let version = new;
let mut encoder = new?;
value.encode?;
// Decoder automatically validates version compatibility
See examples/versioning.rs for detailed usage.
Migration from bincode
OxiCode is 100% binary-compatible with bincode. Migration is straightforward:
// Before (bincode 2.0)
use ;
let bytes = encode_to_vec?;
let = decode_from_slice?;
// After (oxicode) - same API!
use ;
let bytes = encode_to_vec?;
let = decode_from_slice?;
Binary data is 100% compatible - you can mix libraries:
- Data encoded with bincode can be decoded with oxicode ✓
- Data encoded with oxicode can be decoded with bincode ✓
For detailed migration guide, see MIGRATION.md.
Feature Comparison
| Feature | bincode | rkyv | postcard | borsh | oxicode |
|---|---|---|---|---|---|
| Binary Compatibility | ✓ | ✗ | ✗ | ✗ | ✓ |
| Zero-copy | ✗ | ✓ | ✗ | ✗ | ✓ |
| no_std | ✓ | ✓ | ✓ | ✓ | ✓ |
| SIMD Optimization | ✗ | ✗ | ✗ | ✗ | ✓ |
| Compression | ✗ | ✗ | ✗ | ✗ | ✓ |
| Async Streaming | ✗ | ✗ | ✗ | ✗ | ✓ |
| Validation | ✗ | ✗ | ✗ | ✗ | ✓ |
| Schema Evolution | ✗ | ✗ | ✗ | ✗ | ✓ |
| Varint Encoding | ✓ | ✗ | ✓ | ✗ | ✓ |
Project Status
🎯 Version 0.1.0 - Production Ready
All core features and enhancements complete. See CHANGELOG.md for details.
Statistics (as of 2025-12-28):
- Lines of Code: 10,860 (Rust source, excluding tests)
- Files: 61 Rust files
- Test Coverage: 211 tests passing (100% pass rate)
- 18 binary compatibility tests (100% byte-for-byte identical to bincode)
- 193+ feature and integration tests
- Type Coverage: 112+ types with full Encode/Decode support
- Binary Compatibility: 100% verified through cross-library testing
- Code Quality: ✓ Zero unwrap(), ✓ Zero warnings, ✓ All files < 2000 lines
Project Structure
This is a workspace with the following crates:
oxicode: Main library crateoxicode_derive: Procedural macros for deriving Encode/Decodeoxicode_compatibility: Compatibility tests and bincode interop
Development Principles
OxiCode follows strict development principles:
- No warnings policy: All code must compile without warnings
- No unwrap policy: All error cases must be properly handled
- Latest crates policy: Use latest versions of dependencies
- Workspace policy: Proper workspace structure with shared dependencies
- Refactoring policy: Keep individual files under 2000 lines
Performance
OxiCode is designed for performance:
- SIMD acceleration: 2-4x speedup for large arrays (with
simdfeature) - Zero-copy deserialization: Where possible
- Efficient varint encoding: For integers
- Minimal allocations: During encoding/decoding
- Benchmark suite: Included in
benches/
Run benchmarks:
Testing
# Run all tests
# Run specific feature tests
# Run with no-std
Examples
The examples/ directory contains comprehensive examples:
basic_usage.rs- Simple encoding/decodingconfiguration.rs- Configuration optionszero_copy.rs- Zero-copy deserializationsimd_arrays.rs- SIMD-accelerated arrayscompression.rs- LZ4 and Zstd compressionstreaming.rs- Chunked streamingasync_streaming.rs- Async tokio streamingvalidation.rs- Validation middlewareversioning.rs- Schema evolution
Run examples:
Contributing
Contributions are welcome! Please feel free to submit a Pull Request.
License
Licensed under the MIT license. See LICENSE for details.
Acknowledgments
This project builds upon the excellent work done by the bincode team and community. We're grateful for their contributions to the Rust ecosystem.