| Crates.io | osc-codec-json |
| lib.rs | osc-codec-json |
| version | 0.1.0-alpha.5 |
| created_at | 2025-10-27 02:58:51.961583+00 |
| updated_at | 2025-10-27 04:33:05.270489+00 |
| description | Experimental JSON codec for osc-ir intermediate representation |
| homepage | https://github.com/Nagitch/osc-data-model |
| repository | https://github.com/Nagitch/osc-data-model |
| max_upload_size | |
| id | 1902163 |
| size | 15,127 |
⚠️ 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.
IrValue to/from JSONAdd this to your Cargo.toml:
[dependencies]
osc-codec-json = "0.1.0-alpha.1"
use osc_ir::{IrValue, IrBundle, IrTimetag};
use osc_codec_json::{to_json, from_json};
// Create some data
let mut bundle = IrBundle::new(IrTimetag::from_ntp(12345));
bundle.add_message(IrValue::from("hello"));
bundle.add_message(IrValue::from(42));
let value = IrValue::Bundle(bundle);
// Convert to JSON
let json = to_json(&value);
println!("{}", serde_json::to_string_pretty(&json).unwrap());
// Convert back from JSON
let restored = from_json(&json);
assert_eq!(value, restored);
The codec handles OSC-specific types with special JSON representations:
let binary = IrValue::Binary(vec![0xAA, 0xBB, 0xCC]);
let json = to_json(&binary);
// Results in: {"$type": "binary", "data": "qrvM"}
let timestamp = IrValue::from(osc_ir::IrTimestamp {
seconds: 1234567890,
nanos: 500_000_000
});
let json = to_json(×tamp);
// Results in: {"$type": "timestamp", "seconds": 1234567890, "nanos": 500000000}
let ext = IrValue::Ext {
type_id: 42,
data: vec![1, 2, 3, 4]
};
let json = to_json(&ext);
// Results in: {"$type": "ext", "ext": 42, "data": "AQIDBA=="}
Bundles are represented with nested structure preservation:
let mut root = IrBundle::immediate();
root.add_message(IrValue::from("root message"));
let mut nested = IrBundle::new(IrTimetag::from_ntp(1000));
nested.add_message(IrValue::from("nested message"));
root.add_bundle(nested);
let json = to_json(&IrValue::Bundle(root));
// Results in properly nested JSON structure with timetags
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.
to_json(value: &IrValue) -> serde_json::Value - Convert IR to JSONfrom_json(json: &serde_json::Value) -> IrValue - Convert JSON to IRLicensed under either of
at your option.