custom message parsing errors #1
14
src/lib.rs
14
src/lib.rs
|
@ -618,9 +618,9 @@ impl MessageBehavior for VmcExtMidiNote {
|
|||
args,
|
||||
};
|
||||
}
|
||||
fn from_osc_message(msg: OscMessage) -> Result<Self, String> {
|
||||
fn from_osc_message(msg: OscMessage) -> Result<Self, FromMessageErr> {
|
||||
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 active: bool;
|
||||
let channel: i32;
|
||||
|
@ -633,22 +633,22 @@ impl MessageBehavior for VmcExtMidiNote {
|
|||
} else if i == 0 {
|
||||
active = false;
|
||||
} else {
|
||||
return Err(String::from("arg value invalid"));
|
||||
return Err(FromMessageErr::IntRange(IntRangeErr { expected_lower: 0, expected_upper: 1, actual: i, addr: msg.addr, arg_count: 0}));
|
||||
}
|
||||
}
|
||||
_ => return Err(String::from("arg type invalid")),
|
||||
_ => return Err(FromMessageErr::ArgType(ArgTypeErr { expected: OscType::Int(0), actual: msg.args[0], addr: msg.addr, arg_count: 0})),
|
||||
}
|
||||
match msg.args[1] {
|
||||
OscType::Int(i) => channel = i,
|
||||
_ => return Err(String::from("arg type invalid")),
|
||||
_ => return Err(FromMessageErr::ArgType(ArgTypeErr { expected: OscType::Int(0), actual: msg.args[1], addr: msg.addr, arg_count: 1})),
|
||||
}
|
||||
match msg.args[2] {
|
||||
OscType::Int(i) => note = i,
|
||||
_ => return Err(String::from("arg type invalid")),
|
||||
_ => return Err(FromMessageErr::ArgType(ArgTypeErr { expected: OscType::Int(0), actual: msg.args[2], addr: msg.addr, arg_count: 2})),
|
||||
}
|
||||
match msg.args[3] {
|
||||
OscType::Float(f) => velocity = 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(VmcExtMidiNote {
|
||||
active,
|
||||
|
|
Loading…
Reference in New Issue
Block a user