use std::fmt;
pub const FR_CONTINUATION: u8 = 0x9;
pub const FR_DATA: u8 = 0x0;
pub const FR_GO_AWAY: u8 = 0x7;
pub const FR_HEADERS: u8 = 0x1;
pub const FR_PING: u8 = 0x6;
pub const FR_PRIORITY: u8 = 0x2;
pub const FR_PUSH_PROMISE: u8 = 0x5;
pub const FR_RST_STREAM: u8 = 0x3;
pub const FR_SETTINGS: u8 = 0x4;
pub const FR_WINDOW_UPDATE: u8 = 0x8;
pub const FR_UNSUPPORTED: u8 = 0xFF;
#[derive(Clone,Copy,PartialEq)]
#[repr(u8)]
pub enum FrameType {
Continuation = FR_CONTINUATION,
Data = FR_DATA,
GoAway = FR_GO_AWAY,
Headers = FR_HEADERS,
Ping = FR_PING,
Priority = FR_PRIORITY,
PushPromise = FR_PUSH_PROMISE,
RstStream = FR_RST_STREAM,
Settings = FR_SETTINGS,
WindowUpdate = FR_WINDOW_UPDATE,
Unsupported = FR_UNSUPPORTED
}
impl FrameType {
pub fn from_u8(byte: u8) -> FrameType {
match byte {
FR_DATA => FrameType::Data,
FR_HEADERS => FrameType::Headers,
FR_PRIORITY => FrameType::Priority,
FR_RST_STREAM => FrameType::RstStream,
FR_SETTINGS => FrameType::Settings,
FR_PUSH_PROMISE => FrameType::PushPromise,
FR_PING => FrameType::Ping,
FR_GO_AWAY => FrameType::GoAway,
FR_WINDOW_UPDATE => FrameType::WindowUpdate,
FR_CONTINUATION => FrameType::Continuation,
_ => FrameType::Unsupported
}
}
pub fn as_byte(&self) -> u8 {
match *self {
FrameType::Continuation => FR_CONTINUATION,
FrameType::Data => FR_DATA,
FrameType::GoAway => FR_GO_AWAY,
FrameType::Headers => FR_HEADERS,
FrameType::Ping => FR_PING,
FrameType::PushPromise => FR_PUSH_PROMISE,
FrameType::Priority => FR_PRIORITY,
FrameType::RstStream => FR_RST_STREAM,
FrameType::Settings => FR_SETTINGS,
FrameType::WindowUpdate => FR_WINDOW_UPDATE,
_ => FR_UNSUPPORTED
}
}
fn format(&self, formatter: &mut fmt::Formatter) -> fmt::Result {
match *self {
FrameType::Continuation => {
write!(formatter, "<FrameType::Continuation>")
},
FrameType::Data => {
write!(formatter, "<FrameType::Data>")
},
FrameType::GoAway => {
write!(formatter, "<FrameType::GoAway>")
},
FrameType::Headers => {
write!(formatter, "<FrameType::Headers>")
},
FrameType::Ping => {
write!(formatter, "<FrameType::Ping>")
},
FrameType::Priority => {
write!(formatter, "<FrameType::Priority>")
},
FrameType::PushPromise => {
write!(formatter, "<FrameType::PushPromise>")
},
FrameType::RstStream => {
write!(formatter, "<FrameType::RstStream>")
},
FrameType::Settings => {
write!(formatter, "<FrameType::Settings>")
},
FrameType::WindowUpdate => {
write!(formatter, "<FrameType::WindowUpdate>")
},
FrameType::Unsupported => {
write!(formatter, "<FrameType::Unsupported>")
}
}
}
pub fn is_continuation(&self) -> bool {
match *self {
FrameType::Continuation => true,
_ => false
}
}
pub fn is_data(&self) -> bool {
match *self {
FrameType::Data => true,
_ => false
}
}
pub fn is_go_away(&self) -> bool {
match *self {
FrameType::GoAway => true,
_ => false
}
}
pub fn is_headers(&self) -> bool {
match *self {
FrameType::Headers => true,
_ => false
}
}
pub fn is_push_ping(&self) -> bool {
match *self {
FrameType::Ping => true,
_ => false
}
}
pub fn is_priority(&self) -> bool {
match *self {
FrameType::Priority => true,
_ => false
}
}
pub fn is_push_promise(&self) -> bool {
match *self {
FrameType::PushPromise => true,
_ => false
}
}
pub fn is_rst_stream(&self) -> bool {
match *self {
FrameType::RstStream => true,
_ => false
}
}
pub fn is_settings(&self) -> bool {
match *self {
FrameType::Settings => true,
_ => false
}
}
pub fn is_unsupported(&self) -> bool {
match *self {
FrameType::Unsupported => true,
_ => false
}
}
pub fn is_window_update(&self) -> bool {
match *self {
FrameType::WindowUpdate => true,
_ => false
}
}
}
impl fmt::Debug for FrameType {
fn fmt(&self, formatter: &mut fmt::Formatter) -> fmt::Result {
self.format(formatter)
}
}
impl fmt::Display for FrameType {
fn fmt(&self, formatter: &mut fmt::Formatter) -> fmt::Result {
self.format(formatter)
}
}