s2n_quic_core/frame/
reset_stream.rs

1// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
2// SPDX-License-Identifier: Apache-2.0
3
4use crate::varint::VarInt;
5
6//= https://www.rfc-editor.org/rfc/rfc9000#section-19.4
7//# An endpoint uses a RESET_STREAM frame (type=0x04) to abruptly
8//# terminate the sending part of a stream.
9
10macro_rules! reset_stream_tag {
11    () => {
12        0x04u8
13    };
14}
15
16//= https://www.rfc-editor.org/rfc/rfc9000#section-19.4
17//# RESET_STREAM Frame {
18//#   Type (i) = 0x04,
19//#   Stream ID (i),
20//#   Application Protocol Error Code (i),
21//#   Final Size (i),
22//# }
23
24//= https://www.rfc-editor.org/rfc/rfc9000#section-19.4
25//# RESET_STREAM frames contain the following fields:
26//#
27//# Stream ID:  A variable-length integer encoding of the stream ID of
28//# the stream being terminated.
29//#
30//# Application Protocol Error Code:  A variable-length integer
31//# containing the application protocol error code (see Section 20.2)
32//# that indicates why the stream is being closed.
33//#
34//# Final Size:  A variable-length integer indicating the final size of
35//# the stream by the RESET_STREAM sender, in units of bytes; see
36//# Section 4.5.
37
38#[derive(Copy, Clone, Debug, PartialEq, Eq)]
39pub struct ResetStream {
40    /// A variable-length integer encoding of the Stream ID of the
41    /// stream being terminated.
42    pub stream_id: VarInt,
43
44    /// A variable-length integer containing the application protocol
45    /// error code which indicates why the stream is being closed.
46    pub application_error_code: VarInt,
47
48    /// A variable-length integer indicating the final size of
49    /// the stream by the RESET_STREAM sender, in unit of bytes.
50    pub final_size: VarInt,
51}
52
53impl ResetStream {
54    pub const fn tag(&self) -> u8 {
55        reset_stream_tag!()
56    }
57}
58
59simple_frame_codec!(
60    ResetStream {
61        stream_id,
62        application_error_code,
63        final_size
64    },
65    reset_stream_tag!()
66);