/rust/registry/src/index.crates.io-1949cf8c6b5b557f/h2-0.4.13/src/frame/reset.rs
Line | Count | Source |
1 | | use crate::frame::{self, Error, Head, Kind, Reason, StreamId}; |
2 | | |
3 | | use bytes::BufMut; |
4 | | |
5 | | #[derive(Copy, Clone, Debug, Eq, PartialEq)] |
6 | | pub struct Reset { |
7 | | stream_id: StreamId, |
8 | | error_code: Reason, |
9 | | } |
10 | | |
11 | | impl Reset { |
12 | 0 | pub fn new(stream_id: StreamId, error: Reason) -> Reset { |
13 | 0 | Reset { |
14 | 0 | stream_id, |
15 | 0 | error_code: error, |
16 | 0 | } |
17 | 0 | } |
18 | | |
19 | 0 | pub fn stream_id(&self) -> StreamId { |
20 | 0 | self.stream_id |
21 | 0 | } |
22 | | |
23 | 0 | pub fn reason(&self) -> Reason { |
24 | 0 | self.error_code |
25 | 0 | } |
26 | | |
27 | 0 | pub fn load(head: Head, payload: &[u8]) -> Result<Reset, Error> { |
28 | 0 | if payload.len() != 4 { |
29 | 0 | return Err(Error::InvalidPayloadLength); |
30 | 0 | } |
31 | | |
32 | 0 | let error_code = unpack_octets_4!(payload, 0, u32); |
33 | | |
34 | 0 | Ok(Reset { |
35 | 0 | stream_id: head.stream_id(), |
36 | 0 | error_code: error_code.into(), |
37 | 0 | }) |
38 | 0 | } |
39 | | |
40 | 0 | pub fn encode<B: BufMut>(&self, dst: &mut B) { |
41 | 0 | tracing::trace!( |
42 | | "encoding RESET; id={:?} code={:?}", |
43 | | self.stream_id, |
44 | | self.error_code |
45 | | ); |
46 | 0 | let head = Head::new(Kind::Reset, 0, self.stream_id); |
47 | 0 | head.encode(4, dst); |
48 | 0 | dst.put_u32(self.error_code.into()); |
49 | 0 | } Unexecuted instantiation: <h2::frame::reset::Reset>::encode::<bytes::bytes_mut::BytesMut> Unexecuted instantiation: <h2::frame::reset::Reset>::encode::<_> |
50 | | } |
51 | | |
52 | | impl<B> From<Reset> for frame::Frame<B> { |
53 | 0 | fn from(src: Reset) -> Self { |
54 | 0 | frame::Frame::Reset(src) |
55 | 0 | } Unexecuted instantiation: <h2::frame::Frame<hyper::proto::h2::SendBuf<bytes::bytes::Bytes>> as core::convert::From<h2::frame::reset::Reset>>::from Unexecuted instantiation: <h2::frame::Frame<h2::proto::streams::prioritize::Prioritized<hyper::proto::h2::SendBuf<bytes::bytes::Bytes>>> as core::convert::From<h2::frame::reset::Reset>>::from Unexecuted instantiation: <h2::frame::Frame as core::convert::From<h2::frame::reset::Reset>>::from |
56 | | } |