use std::fmt;
pub const S_ENABLE_PUSH: u16 = 0x2;
pub const S_HEADER_TABLE_SIZE: u16 = 0x1;
pub const S_INITIAL_WINDOW_SIZE: u16 = 0x4;
pub const S_MAX_CONCURRENT_STREAMS: u16 = 0x3;
pub const S_MAX_FRAME_SIZE: u16 = 0x5;
pub const S_MAX_HEADER_LIST_SIZE: u16 = 0x6;
pub enum Setting {
EnablePush(u32),
HeaderTableSize(u32),
InitialWindowSize(u32),
MaxConcurrentStreams(u32),
MaxFrameSize(u32),
MaxHeaderListSize(u32),
Unsupported(u32)
}
impl Setting {
pub fn new(&mut self, id: u16, value: u32) -> Setting {
match id {
S_HEADER_TABLE_SIZE => Setting::HeaderTableSize(value),
S_ENABLE_PUSH => Setting::EnablePush(value),
S_MAX_CONCURRENT_STREAMS => Setting::MaxConcurrentStreams(value),
S_INITIAL_WINDOW_SIZE => Setting::InitialWindowSize(value),
S_MAX_FRAME_SIZE => Setting::MaxFrameSize(value),
S_MAX_HEADER_LIST_SIZE => Setting::MaxHeaderListSize(value),
_ => Setting::Unsupported(value)
}
}
fn format(&self, formatter: &mut fmt::Formatter) -> fmt::Result {
match *self {
Setting::EnablePush(x) => {
write!(
formatter,
"<Setting::EnablePush: {}>",
x
)
},
Setting::HeaderTableSize(x) => {
write!(
formatter,
"<Setting::HeaderTableSize: {}>",
x
)
},
Setting::InitialWindowSize(x) => {
write!(
formatter,
"<Setting::InitialWindowSize: {}>",
x
)
},
Setting::MaxConcurrentStreams(x) => {
write!(
formatter,
"<Setting::MaxConcurrentStreams: {}>",
x
)
},
Setting::MaxFrameSize(x) => {
write!(
formatter,
"<Setting::MaxFrameSize: {}>",
x
)
},
Setting::MaxHeaderListSize(x) => {
write!(
formatter,
"<Setting::MaxHeaderListSize: {}>",
x
)
},
Setting::Unsupported(x) => {
write!(
formatter,
"<Setting::Unsupported: {}>",
x
)
}
}
}
pub fn is_enable_push(&self) -> bool {
match *self {
Setting::EnablePush(_) => true,
_ => false
}
}
pub fn is_header_table_size(&self) -> bool {
match *self {
Setting::HeaderTableSize(_) => true,
_ => false
}
}
pub fn is_initial_window_size(&self) -> bool {
match *self {
Setting::InitialWindowSize(_) => true,
_ => false
}
}
pub fn is_max_concurrent_streams(&self) -> bool {
match *self {
Setting::MaxConcurrentStreams(_) => true,
_ => false
}
}
pub fn is_max_frame_size(&self) -> bool {
match *self {
Setting::MaxFrameSize(_) => true,
_ => false
}
}
pub fn is_max_header_list_size(&self) -> bool {
match *self {
Setting::MaxHeaderListSize(_) => true,
_ => false
}
}
pub fn is_unsupported(&self) -> bool {
match *self {
Setting::Unsupported(_) => true,
_ => false
}
}
pub fn value(&self) -> u32 {
match *self {
Setting::EnablePush(x)
| Setting::HeaderTableSize(x)
| Setting::InitialWindowSize(x)
| Setting::MaxConcurrentStreams(x)
| Setting::MaxFrameSize(x)
| Setting::MaxHeaderListSize(x)
| Setting::Unsupported(x) => {
x
}
}
}
}
impl fmt::Debug for Setting {
fn fmt(&self, formatter: &mut fmt::Formatter) -> fmt::Result {
self.format(formatter)
}
}
impl fmt::Display for Setting {
fn fmt(&self, formatter: &mut fmt::Formatter) -> fmt::Result {
self.format(formatter)
}
}