#[cfg(test)]
#[path = "../../tests/tailer/flags.rs"]
mod tests;
use bitflags::bitflags;
bitflags! {
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
pub struct PacketFlags: u8 {
const HANDSHAKE = 0b1000_0000;
const HEALTH_CHECK = 0b0100_0000;
const DATA = 0b0010_0000;
const DECOY = 0b0001_0000;
const TERMINATION = 0b0000_1000;
}
}
impl PacketFlags {
#[inline]
pub fn is_shadowride(&self) -> bool {
self.contains(Self::DATA | Self::HEALTH_CHECK)
}
#[inline]
pub fn has_payload(&self) -> bool {
self.contains(Self::DATA)
}
#[inline]
pub fn is_discardable(&self) -> bool {
self.contains(Self::DECOY)
}
#[inline]
pub fn is_termination(&self) -> bool {
self.contains(Self::TERMINATION)
}
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
#[repr(u8)]
pub enum ReturnCode {
Success = 0,
VersionMismatch = 1,
ConnectionDecayed = 2,
UnknownError = 101,
}
impl From<u8> for ReturnCode {
fn from(value: u8) -> Self {
match value {
0 => ReturnCode::Success,
1 => ReturnCode::VersionMismatch,
2 => ReturnCode::ConnectionDecayed,
_ => ReturnCode::UnknownError,
}
}
}
impl From<ReturnCode> for u8 {
fn from(code: ReturnCode) -> Self {
code as u8
}
}