| Crates.io | oxicode |
| lib.rs | oxicode |
| version | 0.1.1 |
| created_at | 2025-12-28 16:44:28.420484+00 |
| updated_at | 2025-12-28 17:34:41.086499+00 |
| description | A modern binary serialization library - successor to bincode |
| homepage | |
| repository | https://github.com/cool-japan/oxicode |
| max_upload_size | |
| id | 2009127 |
| size | 528,028 |
A modern binary serialization library for Rust - the successor to bincode.
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.
See Feature Comparison below for detailed breakdown.
While bincode has served the Rust community well, OxiCode brings:
Add this to your Cargo.toml:
[dependencies]
oxicode = "0.1"
# With serde support (for serde::Serialize/Deserialize types)
oxicode = { version = "0.1", features = ["serde"] }
# Optional features
oxicode = { version = "0.1", features = ["simd", "compression", "async-tokio"] }
default = ["std", "derive"]
std = ["alloc"] # Standard library support
alloc = [] # Heap allocations (for no_std + alloc)
derive = [] # Derive macros for Encode/Decode
serde = [] # Serde integration (optional)
simd = [] # SIMD-accelerated array encoding
compression-lz4 = [] # LZ4 compression (fast)
compression-zstd = [] # Zstd compression (better ratio)
compression = ["compression-lz4"] # Default compression
async-tokio = ["tokio"] # Async streaming with tokio
async-io = ["futures-io"] # Generic async IO traits
use oxicode::{Encode, Decode};
#[derive(Encode, Decode, PartialEq, Debug)]
struct Point {
x: f32,
y: f32,
}
fn main() -> Result<(), Box<dyn std::error::Error>> {
let point = Point { x: 1.0, y: 2.0 };
// Encode to bytes
let encoded = oxicode::encode_to_vec(&point)?;
// Decode from bytes
let (decoded, _): (Point, _) = oxicode::decode_from_slice(&encoded)?;
assert_eq!(point, decoded);
Ok(())
}
OxiCode provides optional serde integration for types that implement serde::Serialize and serde::Deserialize:
use serde::{Serialize, Deserialize};
#[derive(Serialize, Deserialize, Debug, PartialEq)]
struct Person {
name: String,
age: u32,
}
fn main() -> Result<(), Box<dyn std::error::Error>> {
let person = Person {
name: "Alice".to_string(),
age: 30,
};
// Encode using serde integration
let encoded = oxicode::serde::encode_to_vec(&person, oxicode::config::standard())?;
// Decode using serde integration
let (decoded, _): (Person, _) = oxicode::serde::decode_from_slice(&encoded, oxicode::config::standard())?;
assert_eq!(person.name, decoded.name);
assert_eq!(person.age, decoded.age);
Ok(())
}
Enable serde feature in Cargo.toml:
[dependencies]
oxicode = { version = "0.1", features = ["serde"] }
serde = { version = "1.0", features = ["derive"] }
OxiCode supports various encoding configurations:
use oxicode::config;
// Standard configuration (default): little-endian + varint
let cfg = config::standard();
// Legacy bincode 1.0-compatible: little-endian + fixed-int
let cfg = config::legacy();
// Custom configuration
let cfg = config::standard()
.with_big_endian()
.with_fixed_int_encoding()
.with_limit::<1048576>(); // 1MB limit
// Use with encoding/decoding
let bytes = oxicode::encode_to_vec_with_config(&value, cfg)?;
let (decoded, _) = oxicode::decode_from_slice_with_config(&bytes, cfg)?;
Hardware acceleration for large array operations (2-4x speedup):
use oxicode::{Encode, Decode};
#[derive(Encode, Decode)]
struct LargeDataset {
readings: Vec<f64>, // SIMD-accelerated when feature enabled
}
// Enable with features = ["simd"]
// Auto-detects CPU capabilities (SSE2, AVX2, AVX-512)
See examples/simd_arrays.rs for detailed usage.
Reduce size with LZ4 or Zstd compression:
use oxicode::compression::{CompressedEncoder, CompressedDecoder, CompressionType};
// LZ4 - fast compression
let mut encoder = CompressedEncoder::new(writer, CompressionType::Lz4)?;
value.encode(&mut encoder)?;
// Zstd - better compression ratio
let mut encoder = CompressedEncoder::new(writer, CompressionType::Zstd(10))?;
value.encode(&mut encoder)?;
See examples/compression.rs for detailed usage.
Process large datasets incrementally:
use oxicode::streaming::{StreamingEncoder, StreamingDecoder};
// Encode items one at a time
let mut encoder = StreamingEncoder::new(writer, config)?;
for item in large_dataset {
encoder.write_item(&item)?;
}
encoder.finish()?;
// Decode items incrementally
let mut decoder = StreamingDecoder::new(reader, config)?;
while let Some(item) = decoder.read_item::<MyType>()? {
process(item);
}
See examples/streaming.rs for detailed usage.
Non-blocking async I/O with tokio:
use oxicode::streaming::AsyncStreamingEncoder;
// Async encoding
let mut encoder = AsyncStreamingEncoder::new(writer, config);
for item in dataset {
encoder.write_item(&item).await?;
}
let writer = encoder.finish().await?;
See examples/async_streaming.rs for detailed usage.
Validate data during decoding:
use oxicode::validation::{Validator, Constraints};
// Create validator with constraints
let mut validator = Validator::new();
validator.add_constraint("name", Constraints::max_len(100));
validator.add_constraint("age", Constraints::range(Some(0), Some(120)));
// Validate decoded data
validator.validate(&person)?;
See examples/validation.rs for detailed usage.
Version your data formats and migrate gracefully:
use oxicode::versioning::{Version, VersionedEncoder};
let version = Version::new(1, 0, 0);
let mut encoder = VersionedEncoder::new(writer, version, config)?;
value.encode(&mut encoder)?;
// Decoder automatically validates version compatibility
See examples/versioning.rs for detailed usage.
OxiCode is 100% binary-compatible with bincode. Migration is straightforward:
// Before (bincode 2.0)
use bincode::{Encode, Decode, config};
let bytes = bincode::encode_to_vec(&value, config::standard())?;
let (decoded, _) = bincode::decode_from_slice(&bytes, config::standard())?;
// After (oxicode) - same API!
use oxicode::{Encode, Decode, config};
let bytes = oxicode::encode_to_vec(&value, config::standard())?;
let (decoded, _) = oxicode::decode_from_slice(&bytes, config::standard())?;
Binary data is 100% compatible - you can mix libraries:
For detailed migration guide, see MIGRATION.md.
| Feature | bincode | rkyv | postcard | borsh | oxicode |
|---|---|---|---|---|---|
| Binary Compatibility | ✓ | ✗ | ✗ | ✗ | ✓ |
| Zero-copy | ✗ | ✓ | ✗ | ✗ | ✓ |
| no_std | ✓ | ✓ | ✓ | ✓ | ✓ |
| SIMD Optimization | ✗ | ✗ | ✗ | ✗ | ✓ |
| Compression | ✗ | ✗ | ✗ | ✗ | ✓ |
| Async Streaming | ✗ | ✗ | ✗ | ✗ | ✓ |
| Validation | ✗ | ✗ | ✗ | ✗ | ✓ |
| Schema Evolution | ✗ | ✗ | ✗ | ✗ | ✓ |
| Varint Encoding | ✓ | ✗ | ✓ | ✗ | ✓ |
🎯 Version 0.1.0 - Production Ready
All core features and enhancements complete. See CHANGELOG.md for details.
Statistics (as of 2025-12-28):
This is a workspace with the following crates:
oxicode: Main library crateoxicode_derive: Procedural macros for deriving Encode/Decodeoxicode_compatibility: Compatibility tests and bincode interopOxiCode follows strict development principles:
OxiCode is designed for performance:
simd feature)benches/Run benchmarks:
cargo bench
# Run all tests
cargo nextest run --all-features
# Run specific feature tests
cargo test --features simd
cargo test --features compression
cargo test --features async-tokio
# Run with no-std
cargo test --no-default-features --features alloc
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 evolutionRun examples:
cargo run --example basic_usage
cargo run --example simd_arrays --features simd
cargo run --example compression --features compression
cargo run --example async_streaming --features async-tokio
Contributions are welcome! Please feel free to submit a Pull Request.
Licensed under the MIT license. See LICENSE for details.
This project builds upon the excellent work done by the bincode team and community. We're grateful for their contributions to the Rust ecosystem.