klingtnet / rosc

An OSC library for Rust.
Apache License 2.0
173 stars 25 forks source link

Support OSC array type #5

Closed bitzl closed 5 years ago

bitzl commented 5 years ago

The OSC specification allows to send arrays of values. The tag [ marks the start of an array type definition followed by the type tags of each value until it is closed by a ] tag.

Why is this useful? In my case, I'd need to send a list of frequencies (float values) to a Supercollider synth. The number of frequencies can vary, so a fixed number of fields would be an ugly workaround.

Note that nesting isn't exactly specified (it's "the tags following are for the data", but also "until a close brace tag is reached"), so I assume it's fine to go with whatever is easier to implement.

I'm happy to help. A recursive type would look nice, but I'm not sure if that's the best way to go:

pub enum OscType {
    // ...
    Array(Vec<OscType>),
    // ...
}
mitchmindtree commented 5 years ago

@bitzl could you possibly work around this using serde to serialize your type (perhaps via bincode or serde_json) to bytes and use the Blob variant to send your data, then deserialize on the other end using the aforementioned crates? This way you can work with almost arbitrary data without having to add any further complexity to the rosc crate itself. We ran a networked laser installation a while back using this same technique with rosc.

bitzl commented 5 years ago

@mitchmindtree That would mean parsing byte arrays into floats using the SuperCollider language (that's not Rust, so Serde wouldn't work on that side, see https://supercollider.github.io/). Right now I'm not sure if that's even possible, but I'll check. Thank's for the suggestion!

PR #6 would be an experimental draft how the encoding could look like.

klingtnet commented 5 years ago

@mitchmindtree This is a clever idea, maybe I will pick this up for some other project, thanks!

@bitzl Thank you for providing the draft implementation, I will try to review it today. Contributions are always welcome.

bitzl commented 5 years ago

Resolved with PR #6.