#[derive(Debug, Clone, Copy, PartialEq, Eq, Default)]
pub struct FrameFlags(u8);
impl FrameFlags {
pub const END_STREAM: u8 = 0x01;
pub const ACK: u8 = 0x01;
pub const END_HEADERS: u8 = 0x04;
pub const PADDED: u8 = 0x08;
pub const PRIORITY: u8 = 0x20;
#[must_use]
pub const fn empty() -> Self {
Self(0)
}
#[must_use]
pub const fn from_bits(bits: u8) -> Self {
Self(bits)
}
#[must_use]
pub const fn bits(self) -> u8 {
self.0
}
#[must_use]
pub const fn contains(self, flag: u8) -> bool {
(self.0 & flag) == flag
}
#[must_use]
pub const fn set(self, flag: u8) -> Self {
Self(self.0 | flag)
}
#[must_use]
pub const fn clear(self, flag: u8) -> Self {
Self(self.0 & !flag)
}
#[must_use]
pub const fn is_end_stream(self) -> bool {
self.contains(Self::END_STREAM)
}
#[must_use]
pub const fn is_ack(self) -> bool {
self.contains(Self::ACK)
}
#[must_use]
pub const fn is_end_headers(self) -> bool {
self.contains(Self::END_HEADERS)
}
#[must_use]
pub const fn is_padded(self) -> bool {
self.contains(Self::PADDED)
}
#[must_use]
pub const fn is_priority(self) -> bool {
self.contains(Self::PRIORITY)
}
}
impl From<u8> for FrameFlags {
fn from(bits: u8) -> Self {
Self::from_bits(bits)
}
}
impl From<FrameFlags> for u8 {
fn from(flags: FrameFlags) -> Self {
flags.bits()
}
}