1#[cfg(test)]
2#[path = "../../tests/tailer/flags.rs"]
3mod tests;
4
5use bitflags::bitflags;
6
7bitflags! {
8 #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
11 pub struct PacketFlags: u8 {
12 const HANDSHAKE = 0b1000_0000;
14 const HEALTH_CHECK = 0b0100_0000;
16 const DATA = 0b0010_0000;
18 const DECOY = 0b0001_0000;
20 const TERMINATION = 0b0000_1000;
22 }
23}
24
25impl PacketFlags {
26 #[inline]
28 pub fn is_shadowride(&self) -> bool {
29 self.contains(Self::DATA | Self::HEALTH_CHECK)
30 }
31
32 #[inline]
34 pub fn has_payload(&self) -> bool {
35 self.contains(Self::DATA)
36 }
37
38 #[inline]
40 pub fn is_discardable(&self) -> bool {
41 self.contains(Self::DECOY)
42 }
43
44 #[inline]
46 pub fn is_termination(&self) -> bool {
47 self.contains(Self::TERMINATION)
48 }
49}
50
51#[derive(Debug, Clone, Copy, PartialEq, Eq)]
53#[repr(u8)]
54pub enum ReturnCode {
55 Success = 0,
57 VersionMismatch = 1,
59 ConnectionDecayed = 2,
61 UnknownError = 101,
63}
64
65impl From<u8> for ReturnCode {
66 fn from(value: u8) -> Self {
67 match value {
68 0 => ReturnCode::Success,
69 1 => ReturnCode::VersionMismatch,
70 2 => ReturnCode::ConnectionDecayed,
71 _ => ReturnCode::UnknownError,
72 }
73 }
74}
75
76impl From<ReturnCode> for u8 {
77 fn from(code: ReturnCode) -> Self {
78 code as u8
79 }
80}