/// An enum that lists all valid settings that can be sent in a SETTINGS /// frame. /// /// Each setting has a value that is a 32 bit unsigned integer (6.5.1.). #[derive(Debug)] pubenum Setting {
HeaderTableSize(u32),
EnablePush(u32),
MaxConcurrentStreams(u32),
InitialWindowSize(u32),
MaxFrameSize(u32),
MaxHeaderListSize(u32),
EnableConnectProtocol(u32),
}
for raw in payload.chunks(6) { match Setting::load(raw) {
Some(HeaderTableSize(val)) => {
settings.header_table_size = Some(val);
}
Some(EnablePush(val)) => match val { 0 | 1 => {
settings.enable_push = Some(val);
}
_ => { return Err(Error::InvalidSettingValue);
}
},
Some(MaxConcurrentStreams(val)) => {
settings.max_concurrent_streams = Some(val);
}
Some(InitialWindowSize(val)) => { if val as usize > MAX_INITIAL_WINDOW_SIZE { return Err(Error::InvalidSettingValue);
} else {
settings.initial_window_size = Some(val);
}
}
Some(MaxFrameSize(val)) => { if DEFAULT_MAX_FRAME_SIZE <= val && val <= MAX_MAX_FRAME_SIZE {
settings.max_frame_size = Some(val);
} else { return Err(Error::InvalidSettingValue);
}
}
Some(MaxHeaderListSize(val)) => {
settings.max_header_list_size = Some(val);
}
Some(EnableConnectProtocol(val)) => match val { 0 | 1 => {
settings.enable_connect_protocol = Some(val);
}
_ => { return Err(Error::InvalidSettingValue);
}
},
None => {}
}
}
Ok(settings)
}
fn payload_len(&self) -> usize { letmut len = 0; self.for_each(|_| len += 6);
len
}
pubfn encode(&self, dst: &mut BytesMut) { // Create & encode an appropriate frame head let head = Head::new(Kind::Settings, self.flags.into(), StreamId::zero()); let payload_len = self.payload_len();
impl Setting { /// Creates a new `Setting` with the correct variant corresponding to the /// given setting id, based on the settings IDs defined in section /// 6.5.2. pubfn from_id(id: u16, val: u32) -> Option<Setting> { useself::Setting::*;
/// Creates a new `Setting` by parsing the given buffer of 6 bytes, which /// contains the raw byte representation of the setting, according to the /// "SETTINGS format" defined in section 6.5.1. /// /// The `raw` parameter should have length at least 6 bytes, since the /// length of the raw setting is exactly 6 bytes. /// /// # Panics /// /// If given a buffer shorter than 6 bytes, the function will panic. fn load(raw: &[u8]) -> Option<Setting> { let id: u16 = (u16::from(raw[0]) << 8) | u16::from(raw[1]); let val: u32 = unpack_octets_4!(raw, 2, u32);
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.