use std::fmt;
use http2::flags::Flags;
use http2::frame_type::FrameType;
#[derive(Clone,Copy,PartialEq)]
pub struct FrameFormat {
flags: u8,
payload_length_frame_type: u32,
stream_id: u32
}
impl FrameFormat {
pub fn new(&mut self, payload_length: u32, frame_type: u8, flags: u8, stream_id: u32)
-> FrameFormat {
FrameFormat{
flags: flags,
payload_length_frame_type: (payload_length << 8) | frame_type as u32,
stream_id: stream_id
}
}
pub fn flags(&self) -> Flags {
Flags::from_u8(self.flags)
}
fn format(&self, formatter: &mut fmt::Formatter) -> fmt::Result {
write!(
formatter,
"<FrameFormat: flags: {}, frame_type: {}, payload_length: {}, stream_id: {}>",
self.flags(),
self.frame_type(),
self.payload_length(),
self.stream_id
)
}
pub fn frame_type(&self) -> FrameType {
FrameType::from_u8((self.payload_length_frame_type & 0xFF) as u8)
}
pub fn payload_length(&self) -> u32 {
self.payload_length_frame_type >> 8
}
pub fn stream_id(&self) -> u32 {
self.stream_id
}
}
impl fmt::Debug for FrameFormat {
fn fmt(&self, formatter: &mut fmt::Formatter) -> fmt::Result {
self.format(formatter)
}
}
impl fmt::Display for FrameFormat {
fn fmt(&self, formatter: &mut fmt::Formatter) -> fmt::Result {
self.format(formatter)
}
}