use thiserror::Error;
#[derive(Debug, Error)]
pub enum TlvError {
#[error("TLV read had different type {found}, expected {expected}")]
TypeMismatch {
expected: usize,
found: usize,
},
#[error("Unexpected end of stream")]
UnexpectedEndOfStream,
#[error("TLV Record had unexpected length")]
UnexpectedLength,
#[error("Data had unexpected format")]
FormatError,
#[error("IO Error")]
IOError(std::io::Error),
}
impl PartialEq for TlvError {
fn eq(&self, other: &Self) -> bool {
match (self, other) {
(
Self::TypeMismatch {
expected: l_expected,
found: l_found,
},
Self::TypeMismatch {
expected: r_expected,
found: r_found,
},
) => l_expected == r_expected && l_found == r_found,
(Self::IOError(_), Self::IOError(_)) => true,
_ => core::mem::discriminant(self) == core::mem::discriminant(other),
}
}
}