Skip to content

Commit 3bb571f

Browse files
committed
Package non-compiling bundle example
1 parent cc3cd64 commit 3bb571f

File tree

1 file changed

+26
-15
lines changed

1 file changed

+26
-15
lines changed

src/main.rs

Lines changed: 26 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,13 @@ extern crate tokio_service;
2121
extern crate osc_address;
2222
#[macro_use] extern crate osc_address_derive;
2323

24-
use osc_address::OscMessage;
24+
use osc_address::{OscMessage, OscBundle, OscPacket};
2525

2626
use std::io;
2727
use std::net::{IpAddr, Ipv4Addr, SocketAddr};
2828
use std::error::Error;
2929

30-
use bytes::{BytesMut, BufMut};
30+
use bytes::{Buf, BytesMut, BufMut};
3131
use futures::{Future, BoxFuture, Sink, Stream};
3232
use tokio_core::net::{UdpSocket, UdpCodec};
3333
use tokio_core::reactor::Core;
@@ -46,7 +46,7 @@ enum OscMsg {
4646
struct OSCCodec;
4747

4848
impl UdpCodec for OSCCodec {
49-
type In = (SocketAddr, OscMsg);
49+
type In = (SocketAddr, OscBundle<OscMsg>);
5050
type Out = (SocketAddr, Vec<u8>);
5151

5252
fn decode(&mut self, addr: &SocketAddr, buf: &[u8]) -> io::Result<Self::In> {
@@ -75,21 +75,32 @@ fn go() -> Result<(), Box<Error>> {
7575

7676
let sock_stream = sock_stream
7777
.or_else::<_, Result<_, io::Error>>(|err| {
78-
println!("error: {:?}", err);
79-
Ok((addr.clone(), OscMsg::Error((), (err.description().to_string(),))))
78+
// TODO: We need a way to bundle these errors back into an OscBundle and pass them along
79+
// println!("error: {:?}", err);
80+
// Ok((addr.clone(), OscMsg::Error((), (err.description().to_string(),))))
81+
Err(err)
8082
})
81-
.for_each(|(addr, msg)| {
82-
match msg {
83-
OscMsg::Freq((), (new_freq,)) => {
84-
println!("new_freq: {:?}", &new_freq);
85-
}
86-
OscMsg::Error((), (err,)) => {
87-
println!("error: {}", &err);
88-
}
89-
_ => {
90-
println!("message: {:?}", &msg);
83+
.for_each(|(addr, bundle)| {
84+
for packet in bundle.messages() {
85+
match packet {
86+
OscPacket::Message(msg) => {
87+
match msg {
88+
OscMsg::Freq((), (new_freq,)) => {
89+
println!("new_freq: {:?}", &new_freq);
90+
}
91+
OscMsg::Error((), (err,)) => {
92+
println!("error: {}", &err);
93+
}
94+
_ => {
95+
println!("message: {:?}", &msg);
96+
}
97+
}
98+
}
99+
100+
OscPacket::Bundle(_) => println!("Sorry, we'll only nest one deep here")
91101
}
92102
}
103+
93104
Ok(())
94105
});
95106

0 commit comments

Comments
 (0)