use minicbor::decode::Decoder;
use minicbor::Decode;
#[derive(Clone, Copy, Debug, Eq, Hash, Ord, PartialEq, PartialOrd)]
pub struct Ignore();
impl<'buffer, Context> Decode<'buffer, Context> for Ignore {
fn decode(_: &mut Decoder<'buffer>, _: &mut Context) -> Result<Self, minicbor::decode::Error> {
Ok(Self())
}
}
pub const fn max_usize(x: usize, y: usize) -> usize {
if x > y {
x
} else {
y
}
}
pub const fn max_of_usizes(x: &[usize]) -> usize {
if let Some((&first, rest)) = x.split_first() {
max_usize(first, max_of_usizes(rest))
} else {
0
}
}
pub fn decode_u16_from_signal(d: &mut Decoder<'_>) -> Result<u16, minicbor::decode::Error> {
Ok(match d.datatype()? {
minicbor::data::Type::F64 => {
#[allow(clippy::cast_possible_truncation, clippy::cast_sign_loss)]
let ret = d.f64()? as u16;
ret
}
_ => d.u16()?,
})
}
pub fn decode_u32_from_signal(d: &mut Decoder<'_>) -> Result<u32, minicbor::decode::Error> {
Ok(match d.datatype()? {
minicbor::data::Type::F64 => {
#[allow(clippy::cast_possible_truncation, clippy::cast_sign_loss)]
let ret = d.f64()? as u32;
ret
}
_ => d.u32()?,
})
}