Add GoAway support

This commit is contained in:
Carl Lerche
2017-08-10 14:19:46 -07:00
parent 1974780504
commit a61562f6b8
6 changed files with 36 additions and 9 deletions

View File

@@ -1,4 +1,7 @@
use frame::{Error, StreamId};
use error::Reason;
use frame::{self, Head, Error, Kind, StreamId};
use bytes::{BufMut, BigEndian};
#[derive(Debug)]
pub struct GoAway {
@@ -7,6 +10,10 @@ pub struct GoAway {
}
impl GoAway {
pub fn reason(&self) -> Reason {
self.error_code.into()
}
pub fn load(payload: &[u8]) -> Result<GoAway, Error> {
if payload.len() < 8 {
// Invalid payload len
@@ -22,4 +29,18 @@ impl GoAway {
error_code: error_code,
})
}
pub fn encode<B: BufMut>(&self, dst: &mut B) {
trace!("encoding GO_AWAY; code={}", self.error_code);
let head = Head::new(Kind::GoAway, 0, StreamId::zero());
head.encode(8, dst);
dst.put_u32::<BigEndian>(self.last_stream_id.into());
dst.put_u32::<BigEndian>(self.error_code);
}
}
impl<B> From<GoAway> for frame::Frame<B> {
fn from(src: GoAway) -> Self {
frame::Frame::GoAway(src)
}
}