summaryrefslogtreecommitdiffstats
path: root/third_party/rust/h2/src/frame/reset.rs
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-07 19:33:14 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-07 19:33:14 +0000
commit36d22d82aa202bb199967e9512281e9a53db42c9 (patch)
tree105e8c98ddea1c1e4784a60a5a6410fa416be2de /third_party/rust/h2/src/frame/reset.rs
parentInitial commit. (diff)
downloadfirefox-esr-36d22d82aa202bb199967e9512281e9a53db42c9.tar.xz
firefox-esr-36d22d82aa202bb199967e9512281e9a53db42c9.zip
Adding upstream version 115.7.0esr.upstream/115.7.0esrupstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'third_party/rust/h2/src/frame/reset.rs')
-rw-r--r--third_party/rust/h2/src/frame/reset.rs56
1 files changed, 56 insertions, 0 deletions
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<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.into(),
+ })
+ }
+
+ pub fn encode<B: BufMut>(&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<B> From<Reset> for frame::Frame<B> {
+ fn from(src: Reset) -> Self {
+ frame::Frame::Reset(src)
+ }
+}