Files
h2/src/frame/reset.rs
Oliver Gould 897bf84163 Use rustfmt to enforce consistent formatting
This change adds a .rustfmt.toml that includes ALL supported settings,
12 of which we have overridden to attempt to cater to our own
proclivities.

rustfmt is checked in the rust-nightly CI job.
2017-09-12 22:29:35 +00:00

55 lines
1.3 KiB
Rust

use frame::{self, Error, Head, Kind, Reason, StreamId};
use bytes::{BigEndian, BufMut};
#[derive(Debug, Eq, PartialEq)]
pub struct Reset {
stream_id: StreamId,
error_code: u32,
}
impl Reset {
pub fn new(stream_id: StreamId, error: Reason) -> Reset {
Reset {
stream_id,
error_code: error.into(),
}
}
pub fn stream_id(&self) -> StreamId {
self.stream_id
}
pub fn reason(&self) -> Reason {
self.error_code.into()
}
pub fn load(head: Head, payload: &[u8]) -> Result<Reset, Error> {
if payload.len() != 4 {
return Err(Error::InvalidPayloadLength);
}
let error_code = unpack_octets_4!(payload, 0, u32);
Ok(Reset {
stream_id: head.stream_id(),
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);
}
}
impl<B> From<Reset> for frame::Frame<B> {
fn from(src: Reset) -> Self {
frame::Frame::Reset(src)
}
}