resets too
This commit is contained in:
@@ -1,5 +1,7 @@
|
||||
use frame::{Head, Error};
|
||||
use super::{StreamId};
|
||||
use error::Reason;
|
||||
use frame::{self, Head, Error, Kind, StreamId};
|
||||
|
||||
use bytes::{BufMut, BigEndian};
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct Reset {
|
||||
@@ -8,11 +10,15 @@ pub struct Reset {
|
||||
}
|
||||
|
||||
impl Reset {
|
||||
pub fn new(stream_id: StreamId, error: Reason) -> Reset {
|
||||
Reset {
|
||||
stream_id,
|
||||
error_code: error.into(),
|
||||
}
|
||||
}
|
||||
pub fn load(head: Head, payload: &[u8]) -> Result<Reset, Error> {
|
||||
if payload.len() != 4 {
|
||||
// Invalid payload len
|
||||
// TODO: Handle error
|
||||
unimplemented!();
|
||||
return Err(Error::InvalidPayloadLength);
|
||||
}
|
||||
|
||||
let error_code = unpack_octets_4!(payload, 0, u32);
|
||||
@@ -22,4 +28,25 @@ impl Reset {
|
||||
error_code: error_code,
|
||||
})
|
||||
}
|
||||
|
||||
pub fn encode<B: BufMut>(&self, dst: &mut B) {
|
||||
trace!("encoding RESET; id={:?} code={}", self.stream_id, self.error_code);
|
||||
let head = Head::new(Kind::Reset, 0, self.stream_id);
|
||||
head.encode(4, dst);
|
||||
dst.put_u32::<BigEndian>(self.error_code);
|
||||
}
|
||||
|
||||
pub fn stream_id(&self) -> StreamId {
|
||||
self.stream_id
|
||||
}
|
||||
|
||||
pub fn reason(&self) -> Reason {
|
||||
self.error_code.into()
|
||||
}
|
||||
}
|
||||
|
||||
impl<B> From<Reset> for frame::Frame<B> {
|
||||
fn from(src: Reset) -> Self {
|
||||
frame::Frame::Reset(src)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user