From 43a97878ce14b72f0981164f87f2e35e14151312 Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Sun, 7 Apr 2024 11:22:09 +0200 Subject: Adding upstream version 110.0.1. Signed-off-by: Daniel Baumann --- third_party/rust/h2/src/frame/reset.rs | 56 ++++++++++++++++++++++++++++++++++ 1 file changed, 56 insertions(+) create mode 100644 third_party/rust/h2/src/frame/reset.rs (limited to 'third_party/rust/h2/src/frame/reset.rs') diff --git a/third_party/rust/h2/src/frame/reset.rs b/third_party/rust/h2/src/frame/reset.rs new file mode 100644 index 0000000000..39f6ac2022 --- /dev/null +++ b/third_party/rust/h2/src/frame/reset.rs @@ -0,0 +1,56 @@ +use crate::frame::{self, Error, Head, Kind, Reason, StreamId}; + +use bytes::BufMut; + +#[derive(Copy, Clone, Debug, Eq, PartialEq)] +pub struct Reset { + stream_id: StreamId, + error_code: Reason, +} + +impl Reset { + pub fn new(stream_id: StreamId, error: Reason) -> Reset { + Reset { + stream_id, + error_code: error, + } + } + + pub fn stream_id(&self) -> StreamId { + self.stream_id + } + + pub fn reason(&self) -> Reason { + self.error_code + } + + pub fn load(head: Head, payload: &[u8]) -> Result { + 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.into(), + }) + } + + pub fn encode(&self, dst: &mut B) { + tracing::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(self.error_code.into()); + } +} + +impl From for frame::Frame { + fn from(src: Reset) -> Self { + frame::Frame::Reset(src) + } +} -- cgit v1.2.3