osc-codec-json
⚠️ EXPERIMENTAL ⚠️
This crate is experimental and APIs may change significantly between versions.
JSON codec for the osc-ir intermediate representation, enabling seamless conversion between OSC data structures and JSON format.
Features
- Bidirectional Conversion: Convert
IrValueto/from JSON - Bundle Support: Full support for OSC bundles with nested structures
- Type Preservation: Special handling for binary data, timestamps, and extended types
- OSC Compatibility: Support for OSC 1.0 and 1.1 features via feature flags
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;
let value = Bundle;
// Convert to JSON
let json = to_json;
println!;
// Convert back from JSON
let restored = from_json;
assert_eq!;
Special Type Handling
The codec handles OSC-specific types with special JSON representations:
Binary Data
let binary = Binary;
let json = to_json;
// Results in: {"$type": "binary", "data": "qrvM"}
Timestamps
let timestamp = from;
let json = to_json;
// Results in: {"$type": "timestamp", "seconds": 1234567890, "nanos": 500000000}
Extended Types
let ext = Ext ;
let json = to_json;
// Results in: {"$type": "ext", "ext": 42, "data": "AQIDBA=="}
OSC Bundles
Bundles are represented with nested structure preservation:
let mut root = immediate;
root.add_message;
let mut nested = new;
nested.add_message;
root.add_bundle;
let json = to_json;
// Results in properly nested JSON structure with timetags
Feature Flags
osc10(default): OSC 1.0 supportosc11: OSC 1.1 support (includes Color and MIDI types)
Note: OSC 1.1 Color and MIDI types are currently marked as TODO and serialize to null.
API Reference
Functions
to_json(value: &IrValue) -> serde_json::Value- Convert IR to JSONfrom_json(json: &serde_json::Value) -> IrValue- Convert JSON to IR
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.