Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

OscBundle example / implementation #1

Open
andrewcsmith opened this issue Oct 24, 2017 · 4 comments
Open

OscBundle example / implementation #1

andrewcsmith opened this issue Oct 24, 2017 · 4 comments

Comments

@andrewcsmith
Copy link
Contributor

We have a situation where we'd like to use this crate, but require bundles of osc messages to implement it the way we would like. Do you have an example of how to do that, or rather is this something that would need to be implemented?

@Wallacoloo
Copy link
Owner

Wallacoloo commented Oct 24, 2017

@andrewcsmith The underlying serde_osc library does support bundle serialization and deserialization. I was able to dig up an example (well, technically a test) in that crate for how to format bundles.

The just of it is to create a struct like this:

#[derive(Serialize, Deserialize)]
struct Bundle {
    timestamp: (u32, u32),
    messages: (Msg1, Msg2),
};

serde_osc treats structs/arrays/tuples (i.e. collections) uniformly: the important part is that the first field of the bundle must be two u32's (it could be a tuple of (u32, u32) as above, an array of [u32; 2] or something like struct Time{ word1: u32, word2: u32 }). The second field must be a collection of messages (either in the form of an array, tuple, or struct just like before). Each individual message is a type that #[derive]s OscMessage.

It seems to me that you could probably generalize this to something like:

#[derive(Serialize, Deserialize)]
struct Bundle<MsgType: Serialize + Deserialize> {
    timestamp: (u32, u32),
    messages: Vec<MsgType>,
};

and that should (I didn't test it) accommodate a variable number of messages. I think the OSC spec might support nested bundles though, even though they don't quite make sense, so that would take a bit more thinking about.

Development on my end is very sadly stalled :-( But if you come up with an interface for abstracting bundles nicely (or documentation fixes!) please do file a pull request & I'll be happy to merge any improvements.

I'll leave this issue open until osc_address has a good bundle abstraction :-)

@Wallacoloo
Copy link
Owner

Wallacoloo commented Oct 24, 2017

Oh, and I just discovered that we already have a struct in place that abstracts the timestamp field: https://docs.rs/osc_address/0.2.2/osc_address/struct.AbsOscTime.html

So you should prefer something like

#[derive(Serialize, Deserialize)]
struct Bundle<MsgType: Serialize + Deserialize> {
    timestamp: AbsOscTime,
    messages: Vec<MsgType>,
};

@Wallacoloo
Copy link
Owner

Oh, hah. It'd be helpful if I just read my own documentation. Yeah, we have an OscBundle type: https://docs.rs/osc_address/0.2.2/osc_address/struct.OscBundle.html

And then this is abstracted to an OscPacket in order to accept either messages or bundles. Usage examples are still definitely needed for these two though.

@andrewcsmith
Copy link
Contributor Author

Ooooookay I wrote an example, but it won't compile.

https://github.com/andrewcsmith/osc_server_example/blob/master/src/main.rs

It uses the OscBundle abstraction, but hits a recursion limit. Thoughts on why that might be? I'm not at all a macro derive expert.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants