use std::io;
use std::io::ErrorKind;
#[derive(Clone, Copy, Debug, Eq, Hash, PartialEq, thiserror::Error)]
pub enum Decode {
#[error("Too few bytes to decode.")]
TooFewBytes,
#[error("Frame ID mismatch: Expected {expected:#06X}, found {found:#06X}.")]
FrameIdMismatch {
expected: u16,
found: u16,
},
#[error("Invalid frame ID: {0:#06X}.")]
InvalidFrameId(u16),
}
impl From<Decode> for io::Error {
fn from(error: Decode) -> Self {
let kind = match error {
Decode::TooFewBytes => ErrorKind::UnexpectedEof,
Decode::FrameIdMismatch { .. } | Decode::InvalidFrameId(_) => ErrorKind::InvalidData,
};
Self::new(kind, error)
}
}