use std::fmt;
pub const FL_ACK: u8 = 0x1;
pub const FL_END_HEADERS: u8 = 0x4;
pub const FL_END_STREAM: u8 = 0x1;
pub const FL_PADDED: u8 = 0x8;
pub const FL_PRIORITY: u8 = 0x20;
#[derive(Clone,Copy,PartialEq)]
pub struct Flags {
flags: u8
}
impl Flags {
pub fn from_u8(byte: u8) -> Flags {
Flags {
flags: byte
}
}
pub fn as_byte(&self) -> u8 {
self.flags
}
fn format(&self, formatter: &mut fmt::Formatter) -> fmt::Result {
write!(
formatter,
"<Flags: ack: {}, end_headers: {}, end_stream: {}, padded: {}, priority: {}>",
self.flags & FL_ACK == FL_ACK,
self.flags & FL_END_HEADERS == FL_END_HEADERS,
self.flags & FL_END_STREAM == FL_END_STREAM,
self.flags & FL_PADDED == FL_PADDED,
self.flags & FL_PRIORITY == FL_PRIORITY
)
}
pub fn is_ack(&self) -> bool {
self.flags & FL_ACK == FL_ACK
}
pub fn is_empty(&self) -> bool {
self.flags == 0
}
pub fn is_end_headers(&self) -> bool {
self.flags & FL_END_HEADERS == FL_END_HEADERS
}
pub fn is_end_stream(&self) -> bool {
self.flags & FL_END_STREAM == FL_END_STREAM
}
pub fn is_padded(&self) -> bool {
self.flags & FL_PADDED == FL_PADDED
}
pub fn is_priority(&self) -> bool {
self.flags & FL_PRIORITY == FL_PRIORITY
}
}
impl fmt::Debug for Flags {
fn fmt(&self, formatter: &mut fmt::Formatter) -> fmt::Result {
self.format(formatter)
}
}
impl fmt::Display for Flags {
fn fmt(&self, formatter: &mut fmt::Formatter) -> fmt::Result {
self.format(formatter)
}
}