#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum KissCode {
Acst,
Auth,
Auto,
Bcst,
Cryp,
Deny,
Drop,
Rstr,
Init,
Mcst,
Nkey,
Rate,
Rmot,
Step,
Unknown([u8; 4]),
}
impl KissCode {
pub fn from_reference_id(id: u32) -> Self {
let bytes = id.to_be_bytes();
match &bytes {
b"ACST" => Self::Acst,
b"AUTH" => Self::Auth,
b"AUTO" => Self::Auto,
b"BCST" => Self::Bcst,
b"CRYP" => Self::Cryp,
b"DENY" => Self::Deny,
b"DROP" => Self::Drop,
b"RSTR" => Self::Rstr,
b"INIT" => Self::Init,
b"MCST" => Self::Mcst,
b"NKEY" => Self::Nkey,
b"RATE" => Self::Rate,
b"RMOT" => Self::Rmot,
b"STEP" => Self::Step,
_ => Self::Unknown(bytes),
}
}
pub fn is_fatal(&self) -> bool {
matches!(self, Self::Deny | Self::Rstr)
}
pub fn should_back_off(&self) -> bool {
matches!(self, Self::Rate)
}
}