1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
// //! LABEL
// //!
// //! > description
// use crate::{Buf, BufError, BufMut, BufResult, Codec, Cursor, ietf::quicv1::VarInt};
// /// A Frame Types following [Section 12.4].
// ///
// /// The `Type` field values of all frames.
// ///
// /// [Section 12.4](https://datatracker.ietf.org/doc/html/rfc9000#section-12.4).
// #[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
// #[repr(u64)]
// pub enum FrameType {
// /// (PADDING frame)[PaddingFrame].
// Padding = 0x00,
// /// (PING frame)[PaddingFrame].
// Ping = 0x01,
// /// (PING frame)[PaddingFrame].
// Ack = 0x02,
// /// (PING frame)[PaddingFrame].
// ResetStream = 0x04,
// /// (PING frame)[PaddingFrame].
// StopSending = 0x05,
// /// (PING frame)[PaddingFrame].
// Crypto = 0x06,
// /// (PING frame)[PaddingFrame].
// NewToken = 0x07,
// /// (PING frame)[PaddingFrame].
// Stream = 0x08,
// /// The (MAX_DATA frame)[MaxDataFrame].
// MaxData = 0x10,
// /// The (MaxStreamData frame)[MaxStreamDataFrame].
// MaxStreamData = 0x11,
// /// The (MaxStreams frame)[MaxStreamsFrame].
// MaxStreams = 0x12,
// /// The (DataBlocked frame)[DataBlockedFrame].
// DataBlocked = 0x14,
// /// The (StreamDataBlocked frame)[StreamDataBlockedFrame].
// StreamDataBlocked = 0x15,
// /// The (StreamsBlocked frame)[StreamsBlockedFrame].
// StreamsBlocked = 0x16,
// /// The (NewConnectionId frame)[NewConnectionIdFrame].
// NewConnectionId = 0x18,
// /// The (RetireConnectionId frame)[RetireConnectionIdFrame].
// RetireConnectionId = 0x19,
// /// The (PathChallenge frame)[PathChallengeFrame].
// PathChallenge = 0x1a,
// /// The (PathResponse frame)[PathResponseFrame].
// PathResponse = 0x1b,
// /// The (ConnectionClose frame)[ConnectionCloseFrame].
// ConnectionClose = 0x1c,
// /// The (HandshakeDone frame)[HandshakeDoneFrame].
// HandshakeDone = 0x1e,
// }
// impl Codec for FrameType {
// fn encode<W: BufMut>(&self, writer: &mut Cursor<W>, _: ()) -> BufResult<()> {
// (*self as u8).encode(writer, ())
// }
// fn decode<R: Buf>(reader: &mut Cursor<R>, _: ()) -> BufResult<Self> {
// match u8::decode(reader, ())? {
// x if x == (Self::Padding as u8) => Ok(Self::Padding),
// _ => Err(BufError::UnexpectedValue),
// }
// }
// }
// /// A frame following [Section 7.1].
// ///
// /// > descrption
// ///
// /// [Section 7.1]: https://datatracker.ietf.org/doc/html/rfc9114#section-7.1
// #[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
// pub struct Frame {
// ///
// pub r#type: VarInt,
// ///
// pub frame_payload: Vec<u8>,
// }
// impl Codec for Frame {
// fn encode<W: BufMut>(&self, writer: &mut Cursor<W>, _: ()) -> BufResult<()> {
// self.r#type.encode(writer, ())?;
// self.frame_payload.encode(writer, ())
// }
// fn decode<R: Buf>(reader: &mut Cursor<R>, _: ()) -> BufResult<Self> {
// let r#type = VarInt::decode(reader, ())?;
// let _length = VarInt::decode(reader, ())?;
// let frame_payload = Vec::decode(reader, ())?;
// Ok(Self {
// r#type,
// frame_payload,
// })
// }
// }
// /// A DATA frame following [Section 7.2.1].
// ///
// /// > descrption
// ///
// /// [Section 7.2.1]: https://datatracker.ietf.org/doc/html/rfc9114#section-7.2.1
// #[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
// pub struct DataFrame {
// ///
// pub r#type: VarInt,
// ///
// pub frame_payload: Vec<u8>,
// }
// impl Codec for DataFrame {
// fn encode<W: BufMut>(&self, writer: &mut Cursor<W>, _: ()) -> BufResult<()> {
// self.r#type.encode(writer, ())?;
// self.frame_payload.encode(writer, ())
// }
// fn decode<R: Buf>(reader: &mut Cursor<R>, _: ()) -> BufResult<Self> {
// let r#type = VarInt::decode(reader, ())?;
// let _length = VarInt::decode(reader, ())?;
// let frame_payload = Vec::decode(reader, ())?;
// Ok(Self {
// r#type,
// frame_payload,
// })
// }
// }
// /// A HEADERS frame following [Section 7.2.2].
// ///
// /// > descrption
// ///
// /// [Section 7.2.2]: https://datatracker.ietf.org/doc/html/rfc9114#section-7.2.2
// #[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
// pub struct HeadersFrame {
// ///
// pub r#type: VarInt,
// ///
// pub frame_payload: Vec<u8>,
// }
// impl Codec for HeadersFrame {
// fn encode<W: BufMut>(&self, writer: &mut Cursor<W>, _: ()) -> BufResult<()> {
// self.r#type.encode(writer, ())?;
// self.frame_payload.encode(writer, ())
// }
// fn decode<R: Buf>(reader: &mut Cursor<R>, _: ()) -> BufResult<Self> {
// let r#type = VarInt::decode(reader, ())?;
// let _length = VarInt::decode(reader, ())?;
// let frame_payload = Vec::decode(reader, ())?;
// Ok(Self {
// r#type,
// frame_payload,
// })
// }
// }
// /// A CANCEL_PUSH frame following [Section 7.2.3].
// ///
// /// > descrption
// ///
// /// [Section 7.2.3]: https://datatracker.ietf.org/doc/html/rfc9114#section-7.2.3
// #[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
// pub struct CancelPush {
// ///
// pub r#type: VarInt,
// ///
// pub frame_payload: Vec<u8>,
// }
// impl Codec for CancelPush {
// fn encode<W: BufMut>(&self, writer: &mut Cursor<W>, _: ()) -> BufResult<()> {
// self.r#type.encode(writer, ())?;
// self.frame_payload.encode(writer, ())
// }
// fn decode<R: Buf>(reader: &mut Cursor<R>, _: ()) -> BufResult<Self> {
// let r#type = VarInt::decode(reader, ())?;
// let _length = VarInt::decode(reader, ())?;
// let frame_payload = Vec::decode(reader, ())?;
// Ok(Self {
// r#type,
// frame_payload,
// })
// }
// }
// /// A SETTINGS frame following [Section 7.2.4].
// ///
// /// > descrption
// ///
// /// [Section 7.2.4]: https://datatracker.ietf.org/doc/html/rfc9114#section-7.2.4
// #[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
// pub struct SettingsFrame {
// ///
// pub r#type: VarInt,
// ///
// pub frame_payload: Vec<u8>,
// }
// impl Codec for SettingsFrame {
// fn encode<W: BufMut>(&self, writer: &mut Cursor<W>, _: ()) -> BufResult<()> {
// self.r#type.encode(writer, ())?;
// self.frame_payload.encode(writer, ())
// }
// fn decode<R: Buf>(reader: &mut Cursor<R>, _: ()) -> BufResult<Self> {
// let r#type = VarInt::decode(reader, ())?;
// let _length = VarInt::decode(reader, ())?;
// let frame_payload = Vec::decode(reader, ())?;
// Ok(Self {
// r#type,
// frame_payload,
// })
// }
// }
// /// A PUSH_PROMISE frame following [Section 7.2.5].
// ///
// /// > descrption
// ///
// /// [Section 7.2.5]: https://datatracker.ietf.org/doc/html/rfc9114#section-7.2.5
// #[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
// pub struct PushPromise {
// ///
// pub r#type: VarInt,
// ///
// pub frame_payload: Vec<u8>,
// }
// impl Codec for PushPromise {
// fn encode<W: BufMut>(&self, writer: &mut Cursor<W>, _: ()) -> BufResult<()> {
// self.r#type.encode(writer, ())?;
// self.frame_payload.encode(writer, ())
// }
// fn decode<R: Buf>(reader: &mut Cursor<R>, _: ()) -> BufResult<Self> {
// let r#type = VarInt::decode(reader, ())?;
// let _length = VarInt::decode(reader, ())?;
// let frame_payload = Vec::decode(reader, ())?;
// Ok(Self {
// r#type,
// frame_payload,
// })
// }
// }
// /// A GOAWAY frame following [Section 7.2.6].
// ///
// /// > descrption
// ///
// /// [Section 7.2.6]: https://datatracker.ietf.org/doc/html/rfc9114#section-7.2.6
// #[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
// pub struct Goaway {
// ///
// pub r#type: VarInt,
// ///
// pub frame_payload: Vec<u8>,
// }
// impl Codec for Goaway {
// fn encode<W: BufMut>(&self, writer: &mut Cursor<W>, _: ()) -> BufResult<()> {
// self.r#type.encode(writer, ())?;
// self.frame_payload.encode(writer, ())
// }
// fn decode<R: Buf>(reader: &mut Cursor<R>, _: ()) -> BufResult<Self> {
// let r#type = VarInt::decode(reader, ())?;
// let _length = VarInt::decode(reader, ())?;
// let frame_payload = Vec::decode(reader, ())?;
// Ok(Self {
// r#type,
// frame_payload,
// })
// }
// }
// /// A MAX_PUSH_ID frame following [Section 7.2.7].
// ///
// /// > descrption
// ///
// /// [Section 7.2.7]: https://datatracker.ietf.org/doc/html/rfc9114#section-7.2.7
// #[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
// pub struct MaxPushId {
// ///
// pub r#type: VarInt,
// ///
// pub frame_payload: Vec<u8>,
// }
// impl Codec for MaxPushId {
// fn encode<W: BufMut>(&self, writer: &mut Cursor<W>, _: ()) -> BufResult<()> {
// self.r#type.encode(writer, ())?;
// self.frame_payload.encode(writer, ())
// }
// fn decode<R: Buf>(reader: &mut Cursor<R>, _: ()) -> BufResult<Self> {
// let r#type = VarInt::decode(reader, ())?;
// let _length = VarInt::decode(reader, ())?;
// let frame_payload = Vec::decode(reader, ())?;
// Ok(Self {
// r#type,
// frame_payload,
// })
// }
// }
// /// Error Codes of the [CONNECTION_CLOSE frame] by [Section 8.1].
// ///
// /// > description
// ///
// /// [CONNECTION_CLOSE frame]: ConnectionCloseFrame
// /// [Section 8.1]: https://datatracker.ietf.org/doc/html/rfc9114#section-8.1
// #[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
// #[repr(u64)]
// pub enum ErrorCode {
// /// NO_ERROR 0x00: No error
// /// [Section 8.1](https://datatracker.ietf.org/doc/html/rfc9114#section-8.1)
// H3NoError = 0x0100,
// /// INTERNAL_ERROR 0x01: Implementation error
// /// [Section 8.1](https://datatracker.ietf.org/doc/html/rfc9114#section-8.1)
// H3GeneralProtocolError = 0x0101,
// /// CONNECTION_REFUSED 0x02: Server refuses a connection
// /// [Section 8.1](https://datatracker.ietf.org/doc/html/rfc9114#section-8.1)
// H3InternalError = 0x0102,
// /// FLOW_CONTROL_ERROR 0x03: Flow control error
// /// [Section 8.1](https://datatracker.ietf.org/doc/html/rfc9114#section-8.1)
// FlowControlError = 0x0103,
// /// STREAM_LIMIT_ERROR 0x04: Too many streams opened
// /// [Section 8.1](https://datatracker.ietf.org/doc/html/rfc9114#section-8.1)
// StreamLimitError = 0x0104,
// /// STREAM_STATE_ERROR 0x05: Frame received in invalid stream state
// /// [Section 8.1](https://datatracker.ietf.org/doc/html/rfc9114#section-8.1)
// StreamStateError = 0x0105,
// /// FINAL_SIZE_ERROR 0x06: Change to final size
// /// [Section 8.1](https://datatracker.ietf.org/doc/html/rfc9114#section-8.1)
// FinalSizeError = 0x0106,
// /// FRAME_ENCODING_ERROR 0x07: Frame encoding error
// /// [Section 8.1](https://datatracker.ietf.org/doc/html/rfc9114#section-8.1)
// FrameEncodingError = 0x0107,
// /// TRANSPORT_PARAMETER_ERROR 0x08: Error in transport parameters
// /// [Section 8.1](https://datatracker.ietf.org/doc/html/rfc9114#section-8.1)
// TransportParameterError = 0x0108,
// /// CONNECTION_ID_LIMIT_ERROR 0x09: Too many connection IDs received
// /// [Section 8.1](https://datatracker.ietf.org/doc/html/rfc9114#section-8.1)
// ConnectionIdLimitError = 0x0109,
// /// PROTOCOL_VIOLATION 0x0a: Generic protocol violation
// /// [Section 8.1](https://datatracker.ietf.org/doc/html/rfc9114#section-8.1)
// ProtocolViolation = 0x010a,
// /// INVALID_TOKEN 0x0b: Invalid Token received
// /// [Section 8.1](https://datatracker.ietf.org/doc/html/rfc9114#section-8.1)
// InvalidToken = 0x010b,
// /// APPLICATION_ERROR 0x0c: Application error
// /// [Section 8.1](https://datatracker.ietf.org/doc/html/rfc9114#section-8.1)
// ApplicationError = 0x010c,
// /// CRYPTO_BUFFER_EXCEEDED 0x0d: CRYPTO data buffer overflowed
// /// [Section 8.1](https://datatracker.ietf.org/doc/html/rfc9114#section-8.1)
// CryptoBufferExceeded = 0x010d,
// /// KEY_UPDATE_ERROR 0x0e: Invalid packet protection update
// /// [Section 8.1](https://datatracker.ietf.org/doc/html/rfc9114#section-8.1)
// KeyUpdateError = 0x010e,
// /// AEAD_LIMIT_REACHED 0x0f: Excessive use of packet protection keys
// /// [Section 8.1](https://datatracker.ietf.org/doc/html/rfc9114#section-8.1)
// AeadLimitReached = 0x010f,
// /// NO_VIABLE_PATH 0x10: No viable network path exists
// /// [Section 8.1](https://datatracker.ietf.org/doc/html/rfc9114#section-8.1)
// NoViablePath = 0x0110,
// }
// impl From<ErrorCode> for VarInt {
// fn from(value: ErrorCode) -> Self {
// Self(value as u64)
// }
// }
// impl TryFrom<VarInt> for ErrorCode {
// type Error = BufError;
// fn try_from(value: VarInt) -> Result<Self, Self::Error> {
// Self::try_from(value.into_inner())
// }
// }
// impl From<ErrorCode> for u64 {
// fn from(value: ErrorCode) -> Self {
// value as u64
// }
// }
// impl TryFrom<u64> for ErrorCode {
// type Error = BufError;
// fn try_from(value: u64) -> Result<Self, Self::Error> {
// match value {
// x if x == Self::H3NoError as u64 => Ok(Self::H3NoError),
// x if x == Self::H3GeneralProtocolError as u64 => Ok(Self::H3GeneralProtocolError),
// x if x == Self::H3InternalError as u64 => Ok(Self::H3InternalError),
// x if x == Self::FlowControlError as u64 => Ok(Self::FlowControlError),
// x if x == Self::StreamLimitError as u64 => Ok(Self::StreamLimitError),
// x if x == Self::StreamStateError as u64 => Ok(Self::StreamStateError),
// x if x == Self::FinalSizeError as u64 => Ok(Self::FinalSizeError),
// x if x == Self::FrameEncodingError as u64 => Ok(Self::FrameEncodingError),
// x if x == Self::TransportParameterError as u64 => Ok(Self::TransportParameterError),
// x if x == Self::ConnectionIdLimitError as u64 => Ok(Self::ConnectionIdLimitError),
// x if x == Self::ProtocolViolation as u64 => Ok(Self::ProtocolViolation),
// x if x == Self::InvalidToken as u64 => Ok(Self::InvalidToken),
// x if x == Self::ApplicationError as u64 => Ok(Self::ApplicationError),
// x if x == Self::CryptoBufferExceeded as u64 => Ok(Self::CryptoBufferExceeded),
// x if x == Self::KeyUpdateError as u64 => Ok(Self::KeyUpdateError),
// x if x == Self::AeadLimitReached as u64 => Ok(Self::AeadLimitReached),
// x if x == Self::NoViablePath as u64 => Ok(Self::NoViablePath),
// _ => Err(BufError::UnexpectedValue),
// }
// }
// }
// #[cfg(test)]
// mod tests {
// #[test]
// fn test() {}
// }