lib/quic/src/frame/model.zig
daab053ee43316e1809a84551d573ddd1e5bf3d2
1 const quic = @import("../root.zig");
2
3 pub const ack_ranges_max: u8 = 64;
4
5 pub const Ecn = struct {
6 ect0: u62,
7 ect1: u62,
8 ce: u62,
9 };
10
11 pub const AckRange = struct {
12 gap: u62,
13 length: u62,
14 };
15
16 pub const AckIterator = struct {
17 input: quic.cursor.Read,
18 remaining: u8,
19
20 pub fn next(self: *AckIterator) quic.varint.DecodeError!?AckRange {
21 if (self.remaining == 0) return null;
22 self.remaining -= 1;
23 return .{
24 .gap = (try quic.varint.read(&self.input)).value,
25 .length = (try quic.varint.read(&self.input)).value,
26 };
27 }
28
29 pub fn exhausted(self: *const AckIterator) bool {
30 return self.remaining == 0 and self.input.remaining() == 0;
31 }
32 };
33
34 pub const Ack = struct {
35 largest: u62,
36 delay: u62,
37 first_range: u62,
38 range_count: u8,
39 ranges: []const u8,
40 ecn: ?Ecn,
41
42 pub fn iterator(self: Ack) AckIterator {
43 return .{
44 .input = quic.cursor.Read.init(self.ranges),
45 .remaining = self.range_count,
46 };
47 }
48 };
49
50 pub const ResetStream = struct {
51 stream_id: u62,
52 error_code: u62,
53 final_size: u62,
54 };
55
56 pub const StopSending = struct {
57 stream_id: u62,
58 error_code: u62,
59 };
60
61 pub const Crypto = struct {
62 offset: u62,
63 data: []const u8,
64 };
65
66 pub const Stream = struct {
67 stream_id: u62,
68 offset: u62,
69 offset_present: bool,
70 length_present: bool,
71 fin: bool,
72 data: []const u8,
73 };
74
75 pub const StreamData = struct {
76 stream_id: u62,
77 maximum: u62,
78 };
79
80 pub const StreamLimit = struct {
81 unidirectional: bool,
82 maximum: u62,
83 };
84
85 pub const NewConnectionId = struct {
86 sequence: u62,
87 retire_prior_to: u62,
88 connection_id: quic.packet.ConnectionId,
89 reset_token: [16]u8,
90 };
91
92 pub const ConnectionClose = struct {
93 application: bool,
94 error_code: u62,
95 frame_type: ?u62,
96 reason: []const u8,
97 };
98
99 pub const Datagram = struct {
100 length_present: bool,
101 data: []const u8,
102 };
103
104 pub const Frame = union(enum) {
105 padding: void,
106 ping: void,
107 ack: Ack,
108 reset_stream: ResetStream,
109 stop_sending: StopSending,
110 crypto: Crypto,
111 new_token: []const u8,
112 stream: Stream,
113 max_data: u62,
114 max_stream_data: StreamData,
115 max_streams: StreamLimit,
116 data_blocked: u62,
117 stream_data_blocked: StreamData,
118 streams_blocked: StreamLimit,
119 new_connection_id: NewConnectionId,
120 retire_connection_id: u62,
121 path_challenge: [8]u8,
122 path_response: [8]u8,
123 connection_close: ConnectionClose,
124 handshake_done: void,
125 datagram: Datagram,
126 };