Merge branch 'master' into ver/flowio
This commit is contained in:
		| @@ -1,23 +1,21 @@ | ||||
| use StreamId; | ||||
| use byteorder::{ByteOrder, NetworkEndian}; | ||||
| use byteorder::NetworkEndian; | ||||
| use bytes::{BufMut}; | ||||
| use frame::{self, Head, Kind, Error}; | ||||
|  | ||||
| const INCREMENT_MASK: u32 = 1 << 31; | ||||
|  | ||||
| type Increment = u32; | ||||
| const SIZE_INCREMENT_MASK: u32 = 1 << 31; | ||||
|  | ||||
| #[derive(Debug)] | ||||
| pub struct WindowUpdate { | ||||
|     stream_id: StreamId, | ||||
|     increment: Increment, | ||||
|     size_increment: u32, | ||||
| } | ||||
|  | ||||
| impl WindowUpdate { | ||||
|     pub fn new(stream_id: StreamId, increment: Increment) -> WindowUpdate { | ||||
|     pub fn new(stream_id: StreamId, size_increment: u32) -> WindowUpdate { | ||||
|         WindowUpdate { | ||||
|             stream_id, | ||||
|             increment, | ||||
|             size_increment, | ||||
|         } | ||||
|     } | ||||
|  | ||||
| @@ -25,18 +23,24 @@ impl WindowUpdate { | ||||
|         self.stream_id | ||||
|     } | ||||
|  | ||||
|     pub fn increment(&self) -> Increment { | ||||
|         self.increment | ||||
|     pub fn size_increment(&self) -> u32 { | ||||
|         self.size_increment | ||||
|     } | ||||
|  | ||||
|     /// Builds a `WindowUpdate` frame from a raw frame. | ||||
|     pub fn load(head: Head, bytes: &[u8]) -> Result<WindowUpdate, Error> { | ||||
|     pub fn load(head: Head, payload: &[u8]) -> Result<WindowUpdate, Error> { | ||||
|         debug_assert_eq!(head.kind(), ::frame::Kind::WindowUpdate); | ||||
|         if payload.len() != 4 { | ||||
|             return Err(Error::BadFrameSize); | ||||
|         } | ||||
|  | ||||
|         // Clear the most significant bit, as that is reserved and MUST be ignored | ||||
|         // when received. | ||||
|         let size_increment = unpack_octets_4!(payload, 0, u32) & !SIZE_INCREMENT_MASK; | ||||
|  | ||||
|         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, | ||||
|             size_increment, | ||||
|         }) | ||||
|     } | ||||
|  | ||||
| @@ -44,7 +48,7 @@ impl WindowUpdate { | ||||
|         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); | ||||
|         dst.put_u32::<NetworkEndian>(self.size_increment); | ||||
|     } | ||||
| } | ||||
|  | ||||
|   | ||||
		Reference in New Issue
	
	Block a user