custom message parsing errors #1

Merged
cassdlcm merged 22 commits from custom_errors into main 2023-12-31 19:36:26 +01:00
Showing only changes of commit 3f01f2f3fd - Show all commits

View File

@ -1316,9 +1316,9 @@ impl MessageBehavior for VmcExtSetEye {
] ]
}; };
} }
fn from_osc_message(msg: OscMessage) -> Result<Self, String> { fn from_osc_message(msg: OscMessage) -> Result<Self, FromMessageErr> {
if msg.args.len() != 4 { if msg.args.len() != 4 {
return Err(String::from("arg count invalid")); return Err(FromMessageErr::ArgCount(ArgCountErr { expected_in: vec![4], actual: msg.args.len(), addr: msg.addr}));
} }
let enable: i32; let enable: i32;
let x: f32; let x: f32;
@ -1326,20 +1326,20 @@ impl MessageBehavior for VmcExtSetEye {
let z: f32; let z: f32;
match msg.args[0] { match msg.args[0] {
OscType::Int(i) => enable = i, OscType::Int(i) => enable = i,
_ => return Err(String::from("arg type invalid")), _ => return Err(FromMessageErr::ArgType(ArgTypeErr { expected: vec![OscType::Int(0)], actual: msg.args[0], addr: msg.addr, arg_count: 0}))
} }
match msg.args[1] { match msg.args[1] {
OscType::Float(f) => x = f, OscType::Float(f) => x = f,
_ => return Err(String::from("arg type invalid")), _ => return Err(FromMessageErr::ArgType(ArgTypeErr { expected: vec![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) => y = f, OscType::Float(f) => y = f,
_ => return Err(String::from("arg type invalid")), _ => return Err(FromMessageErr::ArgType(ArgTypeErr { expected: vec![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) => z = f, OscType::Float(f) => z = f,
_ => return Err(String::from("arg type invalid")), _ => return Err(FromMessageErr::ArgType(ArgTypeErr { expected: vec![OscType::Float(0.0)], actual: msg.args[3], addr: msg.addr, arg_count: 3}))
} }
return Ok(VmcExtSetEye { enable, position: Vector3::new(x, y, z)}) return Ok(VmcExtSetEye { enable, position: Vector3::new(x, y, z)})
} }