custom message parsing errors #1
29
src/lib.rs
29
src/lib.rs
|
@ -756,53 +756,44 @@ impl MessageBehavior for DeviceTranform {
|
||||||
],
|
],
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
fn from_osc_message(msg: OscMessage) -> Result<Self, String> {
|
fn from_osc_message(msg: OscMessage) -> Result<Self, FromMessageErr> {
|
||||||
if msg.args.len() != 8 {
|
if msg.args.len() != 8 {
|
||||||
return Err(String::from("arg count invalid"));
|
return Err(FromMessageErr::ArgCount(ArgCountErr { expected_in: vec![8], actual: msg.args.len(), addr: msg.addr}));
|
||||||
}
|
|
||||||
match msg.addr.as_str() {
|
|
||||||
"/VMC/Ext/Hmd/Pos"
|
|
||||||
| "/VMC/Ext/Con/Pos"
|
|
||||||
| "/VMC/Ext/Tra/Pos"
|
|
||||||
| "/VMC/Ext/Hmd/Pos/Local"
|
|
||||||
| "/VMC/Ext/Con/Pos/Local"
|
|
||||||
| "/VMC/Ext/Tra/Pos/Local" => {}
|
|
||||||
_ => return Err(String::from("addr invalid")),
|
|
||||||
}
|
}
|
||||||
let serial: String;
|
let serial: String;
|
||||||
let mut origin = Vector3::new(0.0, 0.0, 0.0);
|
let mut origin = Vector3::new(0.0, 0.0, 0.0);
|
||||||
let mut quat = Quaternion::new(0.0, 0.0, 0.0, 0.0);
|
let mut quat = Quaternion::new(0.0, 0.0, 0.0, 0.0);
|
||||||
match &msg.args[0] {
|
match &msg.args[0] {
|
||||||
OscType::String(s) => serial = s.to_owned(),
|
OscType::String(s) => serial = s.to_owned(),
|
||||||
_ => return Err(String::from("arg type invalid")),
|
_ => return Err(FromMessageErr::ArgType(ArgTypeErr { expected: OscType::String(String::new()), actual: msg.args[0], addr: msg.addr, arg_count: 0})),
|
||||||
}
|
}
|
||||||
match msg.args[1] {
|
match msg.args[1] {
|
||||||
OscType::Float(f) => origin.x = f,
|
OscType::Float(f) => origin.x = f,
|
||||||
_ => return Err(String::from("arg type invalid")),
|
_ => return Err(FromMessageErr::ArgType(ArgTypeErr { expected: OscType::Float(0.0), actual: msg.args[1], addr: msg.addr, arg_count: 1})),
|
||||||
}
|
}
|
||||||
match msg.args[2] {
|
match msg.args[2] {
|
||||||
OscType::Float(f) => origin.y = f,
|
OscType::Float(f) => origin.y = f,
|
||||||
_ => return Err(String::from("arg type invalid")),
|
_ => return Err(FromMessageErr::ArgType(ArgTypeErr { expected: OscType::Float(0.0), actual: msg.args[2], addr: msg.addr, arg_count: 2})),
|
||||||
}
|
}
|
||||||
match msg.args[3] {
|
match msg.args[3] {
|
||||||
OscType::Float(f) => origin.z = f,
|
OscType::Float(f) => origin.z = f,
|
||||||
_ => return Err(String::from("arg type invalid")),
|
_ => return Err(FromMessageErr::ArgType(ArgTypeErr { expected: OscType::Float(0.0), actual: msg.args[3], addr: msg.addr, arg_count: 3})),
|
||||||
}
|
}
|
||||||
match msg.args[4] {
|
match msg.args[4] {
|
||||||
OscType::Float(f) => quat.x = f,
|
OscType::Float(f) => quat.x = f,
|
||||||
_ => return Err(String::from("arg type invalid")),
|
_ => return Err(FromMessageErr::ArgType(ArgTypeErr { expected: OscType::Float(0.0), actual: msg.args[4], addr: msg.addr, arg_count: 4})),
|
||||||
}
|
}
|
||||||
match msg.args[5] {
|
match msg.args[5] {
|
||||||
OscType::Float(f) => quat.y = f,
|
OscType::Float(f) => quat.y = f,
|
||||||
_ => return Err(String::from("arg type invalid")),
|
_ => return Err(FromMessageErr::ArgType(ArgTypeErr { expected: OscType::Float(0.0), actual: msg.args[5], addr: msg.addr, arg_count: 5})),
|
||||||
}
|
}
|
||||||
match msg.args[6] {
|
match msg.args[6] {
|
||||||
OscType::Float(f) => quat.z = f,
|
OscType::Float(f) => quat.z = f,
|
||||||
_ => return Err(String::from("arg type invalid")),
|
_ => return Err(FromMessageErr::ArgType(ArgTypeErr { expected: OscType::Float(0.0), actual: msg.args[6], addr: msg.addr, arg_count: 6})),
|
||||||
}
|
}
|
||||||
match msg.args[7] {
|
match msg.args[7] {
|
||||||
OscType::Float(f) => quat.w = f,
|
OscType::Float(f) => quat.w = f,
|
||||||
_ => return Err(String::from("arg type invalid")),
|
_ => return Err(FromMessageErr::ArgType(ArgTypeErr { expected: OscType::Float(0.0), actual: msg.args[7], addr: msg.addr, arg_count: 7})),
|
||||||
}
|
}
|
||||||
return Ok(DeviceTranform {
|
return Ok(DeviceTranform {
|
||||||
addr: msg.addr.to_owned(),
|
addr: msg.addr.to_owned(),
|
||||||
|
|
Loading…
Reference in New Issue
Block a user