This commit is contained in:
Oliver Gould
2017-07-09 06:01:42 +00:00
parent 7632a016df
commit d7b82cd50b
7 changed files with 151 additions and 13 deletions

View File

@@ -32,6 +32,7 @@ mod reset;
mod settings;
mod stream_id;
mod util;
mod window_update;
pub use self::data::Data;
pub use self::go_away::GoAway;
@@ -41,6 +42,7 @@ pub use self::ping::Ping;
pub use self::reset::Reset;
pub use self::settings::{Settings, SettingSet};
pub use self::stream_id::StreamId;
pub use self::window_update::WindowUpdate;
// Re-export some constants
pub use self::settings::{
@@ -56,7 +58,8 @@ pub enum Frame {
Headers(Headers),
PushPromise(PushPromise),
Settings(Settings),
Ping(Ping)
Ping(Ping),
WindowUpdate(WindowUpdate)
}
/// Errors that can occur during parsing an HTTP/2 frame.

View File

@@ -0,0 +1,48 @@
use StreamId;
use byteorder::{ByteOrder, NetworkEndian};
use bytes::{BufMut};
use frame::{self, Head, Kind, Error};
const INCREMENT_MASK: u32 = 1 << 31;
type Increment = u32;
#[derive(Debug)]
pub struct WindowUpdate {
stream_id: StreamId,
increment: Increment,
}
impl WindowUpdate {
pub fn stream_id(&self) -> StreamId {
self.stream_id
}
pub fn increment(&self) -> Increment {
self.increment
}
/// Builds a `Ping` frame from a raw frame.
pub fn load(head: Head, bytes: &[u8]) -> Result<WindowUpdate, Error> {
debug_assert_eq!(head.kind(), ::frame::Kind::WindowUpdate);
Ok(WindowUpdate {
stream_id: head.stream_id(),
// Clear the most significant bit, as that is reserved and MUST be ignored when
// received.
increment: NetworkEndian::read_u32(bytes) & !INCREMENT_MASK,
})
}
pub fn encode<B: BufMut>(&self, dst: &mut B) {
trace!("encoding WINDOW_UPDATE; id={:?}", self.stream_id);
let head = Head::new(Kind::Ping, 0, self.stream_id);
head.encode(4, dst);
dst.put_u32::<NetworkEndian>(self.increment);
}
}
impl From<WindowUpdate> for frame::Frame {
fn from(src: WindowUpdate) -> frame::Frame {
frame::Frame::WindowUpdate(src)
}
}