add constructors for VmcExtSetCalibExec and bounds checking

This commit is contained in:
Cassandra de la Cruz-Munoz 2024-01-01 14:09:16 -05:00
parent 7f4e0faf09
commit e772c9e817
Signed by: cassdlcm
GPG Key ID: BFEBACEA812DDA70

View File

@ -1896,7 +1896,7 @@ impl VmcExtSetRes {
}
#[derive(Debug)]
struct VmcExtSetCalibExec {
pub struct VmcExtSetCalibExec {
mode: i32
}
@ -1913,6 +1913,9 @@ impl VmcMessage for VmcExtSetCalibExec {
OscType::Int(i) => mode = i,
_ => return Err(FromMessageErr::ArgType(ArgTypeErr { expected: vec![OscType::Int(0)], actual: msg.args[0].to_owned(), addr: msg.addr, arg_count: 0}))
}
if mode < 0 || mode > 2 {
return Err(FromMessageErr::IntRange(FromIntRangeErr { expected_lower: 0, expected_upper: 2, actual: mode, addr: msg.addr, arg_count: 0}));
}
return Ok(Box::new(Self{mode}));
}
fn get_addr(&self) -> String {
@ -1920,6 +1923,21 @@ impl VmcMessage for VmcExtSetCalibExec {
}
}
impl VmcExtSetCalibExec {
pub fn new(mode: i32) ->MsgNewResult<Self> {
if mode < 0 || mode > 2 {
return Err(MessageCreationErr::IntRange(CreateIntRangeErr { expected_lower: 0, expected_upper: 2, actual: mode, calling_func: String::from("VmcExtSetCalibExec::new"), arg_name: String::from("mode")}));
}
Ok(Self { mode })
}
pub fn new_vmc_message(mode: i32) -> TraitMsgNewResult {
match Self::new(mode) {
Ok(val) => Ok(Box::new(val)),
Err(val) => Err(val)
}
}
}
#[derive(Debug)]
struct VmcExtSetConfig {
path: String