osc-codec-msgpack
⚠️ EXPERIMENTAL ⚠️
This crate is experimental and APIs may change significantly between versions.
MessagePack codec for the osc-ir intermediate representation, enabling efficient binary serialization of OSC data structures.
Features
- Bidirectional Conversion: Convert
IrValueto/from MessagePack binary format - Efficient Storage: Compact binary representation with MessagePack
- Bundle Support: Full support for OSC bundles with nested structures
- Type Preservation: Native support for binary data, timestamps, and all OSC types
- Cross-Format Compatibility: Works seamlessly with JSON codec for the same data
Usage
Add this to your Cargo.toml:
[]
= "0.1.0-alpha.1"
Basic Example
use ;
use ;
// Create some data
let mut bundle = new;
bundle.add_message;
bundle.add_message;
bundle.add_message; // binary data
let value = Bundle;
// Convert to MessagePack
let msgpack_data = to_msgpack;
println!;
// Convert back from MessagePack
let restored = from_msgpack;
assert_eq!;
Cross-Codec Compatibility
MessagePack and JSON codecs produce equivalent results:
use IrValue;
use ;
use ;
let original = from;
// Both codecs produce equivalent results
let from_json = from_json;
let from_msgpack = from_msgpack;
assert_eq!;
assert_eq!;
assert_eq!;
Complex Nested Bundles
MessagePack efficiently handles deeply nested bundle structures:
let mut root = immediate;
root.add_message;
let mut level1 = new;
level1.add_message;
let mut level2 = new;
level2.add_message;
level2.add_message;
level1.add_bundle;
root.add_bundle;
let msgpack_data = to_msgpack;
// Efficiently serialized with preserved structure
Binary Data Handling
MessagePack natively supports binary data without base64 encoding:
let binary_data = Binary; // 1KB of data
let msgpack = to_msgpack;
// No base64 overhead - stored as native MessagePack binary
Performance
MessagePack typically provides:
- Smaller size than JSON (especially for binary data)
- Faster serialization/deserialization than JSON
- Native binary support without encoding overhead
API Reference
Functions
to_msgpack(value: &IrValue) -> Vec<u8>- Convert IR to MessagePack binaryfrom_msgpack(data: &[u8]) -> IrValue- Convert MessagePack binary to IR
Error Handling
Functions currently use .unwrap() for simplicity but will be improved with proper error handling in future versions.
License
Licensed under either of
- Apache License, Version 2.0 (LICENSE-APACHE or http://www.apache.org/licenses/LICENSE-2.0)
- MIT license (LICENSE-MIT or http://opensource.org/licenses/MIT)
at your option.