custom message parsing errors #1
12
src/lib.rs
12
src/lib.rs
|
@ -1080,26 +1080,26 @@ impl MessageBehavior for VmcExtSettingColor {
|
||||||
],
|
],
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
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("argj count invalid"));
|
return Err(FromMessageErr::ArgCount(ArgCountErr { expected_in: vec![4], actual: msg.args.len(), addr: msg.addr}));
|
||||||
}
|
}
|
||||||
let mut color = Color::from_rgba(0.0, 0.0, 0.0, 0.0);
|
let mut color = Color::from_rgba(0.0, 0.0, 0.0, 0.0);
|
||||||
match msg.args[0] {
|
match msg.args[0] {
|
||||||
OscType::Float(f) => color.r = f,
|
OscType::Float(f) => color.r = f,
|
||||||
_ => return Err(String::from("arg type invalid")),
|
_ => return Err(FromMessageErr::ArgType(ArgTypeErr { expected: OscType::Float(0.0), actual: msg.args[0], addr: msg.addr, arg_count: 0})),
|
||||||
}
|
}
|
||||||
match msg.args[1] {
|
match msg.args[1] {
|
||||||
OscType::Float(f) => color.g = f,
|
OscType::Float(f) => color.g = 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) => color.b = f,
|
OscType::Float(f) => color.b = 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) => color.a = f,
|
OscType::Float(f) => color.a = 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})),
|
||||||
}
|
}
|
||||||
return Ok(VmcExtSettingColor { color });
|
return Ok(VmcExtSettingColor { color });
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user