#[repr(u8)]
#[derive(Debug, Default, PartialEq, Eq)]
pub enum RejectReason {
#[default]
Reserved = 0x01,
DataDigestError = 0x02,
SnackReject = 0x03,
ProtocolError = 0x04,
CommandNotSupported = 0x05,
ImmediateCmdReject = 0x06,
TaskInProgress = 0x07,
InvalidDataAck = 0x08,
InvalidPduField = 0x09,
LongOpReject = 0x0A,
DeprecatedNegotiReset = 0x0B,
WaitingForLogout = 0x0C,
Other(u8),
}
impl TryFrom<u8> for RejectReason {
type Error = anyhow::Error;
fn try_from(b: u8) -> Result<Self, Self::Error> {
Ok(match b {
0x01 => RejectReason::Reserved,
0x02 => RejectReason::DataDigestError,
0x03 => RejectReason::SnackReject,
0x04 => RejectReason::ProtocolError,
0x05 => RejectReason::CommandNotSupported,
0x06 => RejectReason::ImmediateCmdReject,
0x07 => RejectReason::TaskInProgress,
0x08 => RejectReason::InvalidDataAck,
0x09 => RejectReason::InvalidPduField,
0x0A => RejectReason::LongOpReject,
0x0B => RejectReason::DeprecatedNegotiReset,
0x0C => RejectReason::WaitingForLogout,
other => RejectReason::Other(other),
})
}
}
impl From<&RejectReason> for u8 {
fn from(r: &RejectReason) -> u8 {
match *r {
RejectReason::Reserved => 0x01,
RejectReason::DataDigestError => 0x02,
RejectReason::SnackReject => 0x03,
RejectReason::ProtocolError => 0x04,
RejectReason::CommandNotSupported => 0x05,
RejectReason::ImmediateCmdReject => 0x06,
RejectReason::TaskInProgress => 0x07,
RejectReason::InvalidDataAck => 0x08,
RejectReason::InvalidPduField => 0x09,
RejectReason::LongOpReject => 0x0A,
RejectReason::DeprecatedNegotiReset => 0x0B,
RejectReason::WaitingForLogout => 0x0C,
RejectReason::Other(code) => code,
}
}
}