rwebtransport 0.1.0 → 0.1.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (113) hide show
  1. package/Cargo.lock +666 -666
  2. package/Cargo.toml +31 -31
  3. package/LICENSE +202 -202
  4. package/NOTICE +41 -41
  5. package/README.md +550 -550
  6. package/crates/echo-server/Cargo.toml +20 -20
  7. package/crates/echo-server/src/main.rs +666 -666
  8. package/crates/native/Cargo.toml +23 -23
  9. package/crates/native/src/config.rs +129 -129
  10. package/crates/native/src/driver.rs +463 -463
  11. package/crates/native/src/lib.rs +821 -821
  12. package/crates/native/src/server.rs +718 -718
  13. package/crates/native/src/session.rs +1191 -1191
  14. package/crates/native/src/tls.rs +96 -96
  15. package/crates/wtcore/Cargo.toml +15 -15
  16. package/crates/wtcore/src/h3.rs +226 -226
  17. package/crates/wtcore/src/lib.rs +9 -9
  18. package/dist/index.js.map +1 -1
  19. package/dist/index.mjs.map +1 -1
  20. package/package.json +80 -79
  21. package/prebuilds/darwin-arm64/rwebtransport.node +0 -0
  22. package/prebuilds/linux-arm64/rwebtransport.node +0 -0
  23. package/prebuilds/linux-x64/rwebtransport.node +0 -0
  24. package/prebuilds/win32-x64/rwebtransport.node +0 -0
  25. package/scripts/bench.mjs +180 -180
  26. package/scripts/build.js +67 -67
  27. package/scripts/postinstall.js +67 -67
  28. package/scripts/setup-unix.sh +129 -129
  29. package/scripts/setup-windows.ps1 +229 -229
  30. package/vendor/quiche/AGENTS.md +75 -75
  31. package/vendor/quiche/COPYING +23 -23
  32. package/vendor/quiche/Cargo.lock +1212 -1212
  33. package/vendor/quiche/Cargo.toml +215 -215
  34. package/vendor/quiche/README.md +466 -466
  35. package/vendor/quiche/examples/Makefile +46 -46
  36. package/vendor/quiche/examples/README.md +20 -20
  37. package/vendor/quiche/examples/cert-big.crt +90 -90
  38. package/vendor/quiche/examples/cert.crt +18 -18
  39. package/vendor/quiche/examples/cert.key +28 -28
  40. package/vendor/quiche/examples/client.c +343 -343
  41. package/vendor/quiche/examples/client.rs +281 -281
  42. package/vendor/quiche/examples/gen-certs.sh +15 -15
  43. package/vendor/quiche/examples/http3-client.c +473 -473
  44. package/vendor/quiche/examples/http3-client.rs +349 -349
  45. package/vendor/quiche/examples/http3-server.c +614 -614
  46. package/vendor/quiche/examples/http3-server.rs +680 -680
  47. package/vendor/quiche/examples/qpack-decode.rs +87 -87
  48. package/vendor/quiche/examples/qpack-encode.rs +88 -88
  49. package/vendor/quiche/examples/rootca.crt +21 -21
  50. package/vendor/quiche/examples/server.c +529 -529
  51. package/vendor/quiche/examples/server.rs +529 -529
  52. package/vendor/quiche/include/quiche.h +1282 -1282
  53. package/vendor/quiche/src/buffers.rs +105 -105
  54. package/vendor/quiche/src/build.rs +66 -66
  55. package/vendor/quiche/src/cid.rs +1079 -1079
  56. package/vendor/quiche/src/crypto/boringssl.rs +373 -373
  57. package/vendor/quiche/src/crypto/mod.rs +671 -671
  58. package/vendor/quiche/src/dgram.rs +118 -118
  59. package/vendor/quiche/src/error.rs +263 -263
  60. package/vendor/quiche/src/ffi.rs +2290 -2290
  61. package/vendor/quiche/src/flowcontrol.rs +246 -246
  62. package/vendor/quiche/src/frame.rs +2172 -2172
  63. package/vendor/quiche/src/h3/AGENTS.md +54 -54
  64. package/vendor/quiche/src/h3/ffi.rs +442 -442
  65. package/vendor/quiche/src/h3/frame.rs +1404 -1404
  66. package/vendor/quiche/src/h3/mod.rs +8223 -8223
  67. package/vendor/quiche/src/h3/qpack/decoder.rs +288 -288
  68. package/vendor/quiche/src/h3/qpack/encoder.rs +235 -235
  69. package/vendor/quiche/src/h3/qpack/mod.rs +202 -202
  70. package/vendor/quiche/src/h3/qpack/static_table.rs +323 -323
  71. package/vendor/quiche/src/h3/stream.rs +1595 -1595
  72. package/vendor/quiche/src/lib.rs +9556 -9556
  73. package/vendor/quiche/src/minmax.rs +446 -446
  74. package/vendor/quiche/src/packet.rs +2334 -2334
  75. package/vendor/quiche/src/path.rs +1374 -1374
  76. package/vendor/quiche/src/pmtud.rs +652 -652
  77. package/vendor/quiche/src/rand.rs +64 -64
  78. package/vendor/quiche/src/range_buf.rs +186 -186
  79. package/vendor/quiche/src/ranges.rs +755 -755
  80. package/vendor/quiche/src/recovery/AGENTS.md +80 -80
  81. package/vendor/quiche/src/recovery/bandwidth.rs +565 -565
  82. package/vendor/quiche/src/recovery/bytes_in_flight.rs +179 -179
  83. package/vendor/quiche/src/recovery/congestion/cubic.rs +1038 -1038
  84. package/vendor/quiche/src/recovery/congestion/delivery_rate.rs +514 -514
  85. package/vendor/quiche/src/recovery/congestion/hystart.rs +241 -241
  86. package/vendor/quiche/src/recovery/congestion/mod.rs +361 -361
  87. package/vendor/quiche/src/recovery/congestion/prr.rs +238 -238
  88. package/vendor/quiche/src/recovery/congestion/recovery.rs +1170 -1170
  89. package/vendor/quiche/src/recovery/congestion/reno.rs +291 -291
  90. package/vendor/quiche/src/recovery/congestion/test_sender.rs +201 -201
  91. package/vendor/quiche/src/recovery/gcongestion/bbr/bandwidth_sampler.rs +1947 -1947
  92. package/vendor/quiche/src/recovery/gcongestion/bbr/windowed_filter.rs +158 -158
  93. package/vendor/quiche/src/recovery/gcongestion/bbr.rs +37 -37
  94. package/vendor/quiche/src/recovery/gcongestion/bbr2/drain.rs +120 -120
  95. package/vendor/quiche/src/recovery/gcongestion/bbr2/mode.rs +318 -318
  96. package/vendor/quiche/src/recovery/gcongestion/bbr2/network_model.rs +784 -784
  97. package/vendor/quiche/src/recovery/gcongestion/bbr2/probe_bw.rs +729 -729
  98. package/vendor/quiche/src/recovery/gcongestion/bbr2/probe_rtt.rs +175 -175
  99. package/vendor/quiche/src/recovery/gcongestion/bbr2/startup.rs +190 -190
  100. package/vendor/quiche/src/recovery/gcongestion/bbr2.rs +855 -855
  101. package/vendor/quiche/src/recovery/gcongestion/mod.rs +275 -275
  102. package/vendor/quiche/src/recovery/gcongestion/pacer.rs +294 -294
  103. package/vendor/quiche/src/recovery/gcongestion/recovery.rs +1384 -1384
  104. package/vendor/quiche/src/recovery/mod.rs +3086 -3086
  105. package/vendor/quiche/src/recovery/rtt.rs +152 -152
  106. package/vendor/quiche/src/stream/mod.rs +2210 -2210
  107. package/vendor/quiche/src/stream/recv_buf.rs +1236 -1236
  108. package/vendor/quiche/src/stream/send_buf.rs +849 -849
  109. package/vendor/quiche/src/test_utils.rs +681 -681
  110. package/vendor/quiche/src/tests.rs +12922 -12922
  111. package/vendor/quiche/src/tls/boringssl.rs +375 -375
  112. package/vendor/quiche/src/tls/mod.rs +1245 -1245
  113. package/vendor/quiche/src/transport_params.rs +628 -628
@@ -1,235 +1,235 @@
1
- // Copyright (C) 2019, Cloudflare, Inc.
2
- // All rights reserved.
3
- //
4
- // Redistribution and use in source and binary forms, with or without
5
- // modification, are permitted provided that the following conditions are
6
- // met:
7
- //
8
- // * Redistributions of source code must retain the above copyright notice,
9
- // this list of conditions and the following disclaimer.
10
- //
11
- // * Redistributions in binary form must reproduce the above copyright
12
- // notice, this list of conditions and the following disclaimer in the
13
- // documentation and/or other materials provided with the distribution.
14
- //
15
- // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
16
- // IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
17
- // THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
18
- // PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
19
- // CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
20
- // EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
21
- // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
22
- // PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
23
- // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
24
- // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
25
- // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26
-
27
- use super::Result;
28
-
29
- use crate::h3::NameValue;
30
-
31
- use super::INDEXED;
32
- use super::LITERAL;
33
- use super::LITERAL_WITH_NAME_REF;
34
-
35
- /// A QPACK encoder.
36
- #[derive(Default)]
37
- pub struct Encoder {}
38
-
39
- impl Encoder {
40
- /// Creates a new QPACK encoder.
41
- pub fn new() -> Encoder {
42
- Encoder::default()
43
- }
44
-
45
- /// Encodes a list of headers into a QPACK header block.
46
- pub fn encode<T: NameValue>(
47
- &mut self, headers: &[T], out: &mut [u8],
48
- ) -> Result<usize> {
49
- let mut b = octets::OctetsMut::with_slice(out);
50
-
51
- // Required Insert Count.
52
- encode_int(0, 0, 8, &mut b)?;
53
-
54
- // Base.
55
- encode_int(0, 0, 7, &mut b)?;
56
-
57
- for h in headers {
58
- match lookup_static(h) {
59
- Some((idx, true)) => {
60
- const STATIC: u8 = 0x40;
61
-
62
- // Encode as statically indexed.
63
- encode_int(idx, INDEXED | STATIC, 6, &mut b)?;
64
- },
65
-
66
- Some((idx, false)) => {
67
- const STATIC: u8 = 0x10;
68
-
69
- // Encode value as literal with static name reference.
70
- encode_int(idx, LITERAL_WITH_NAME_REF | STATIC, 4, &mut b)?;
71
- encode_str::<false>(h.value(), 0, 7, &mut b)?;
72
- },
73
-
74
- None => {
75
- // Encode as fully literal.
76
-
77
- encode_str::<true>(h.name(), LITERAL, 3, &mut b)?;
78
- encode_str::<false>(h.value(), 0, 7, &mut b)?;
79
- },
80
- };
81
- }
82
-
83
- Ok(b.off())
84
- }
85
- }
86
-
87
- fn lookup_static<T: NameValue>(h: &T) -> Option<(u64, bool)> {
88
- // Fetch the right encoding table for this header length.
89
- let table_for_len =
90
- super::static_table::STATIC_ENCODE_TABLE.get(h.name().len())?;
91
-
92
- // Similar to [`eq_ignore_ascii_case`], but only lowercases the second
93
- // operand, as the entries in the table are already lower cased.
94
- let cmp_lowercase = |a: &[u8], b: &[u8]| {
95
- std::iter::zip(a, b).all(|(a, b)| a.eq(&b.to_ascii_lowercase()))
96
- };
97
-
98
- for (name, values) in table_for_len.iter() {
99
- // Match header name first.
100
- if cmp_lowercase(name, h.name()) {
101
- // Second iterate over possible values for the header.
102
- for (value, enc) in values.iter() {
103
- // Match header value.
104
- if value.is_empty() {
105
- return Some((*enc, false));
106
- }
107
-
108
- if h.value() == *value {
109
- return Some((*enc, true));
110
- }
111
- }
112
- // Only matched the header, not the value.
113
- return Some((values.first()?.1, false));
114
- }
115
- }
116
-
117
- None
118
- }
119
-
120
- pub fn encode_int(
121
- mut v: u64, first: u8, prefix: usize, b: &mut octets::OctetsMut,
122
- ) -> Result<()> {
123
- let mask = 2u64.pow(prefix as u32) - 1;
124
-
125
- // Encode I on N bits.
126
- if v < mask {
127
- b.put_u8(first | v as u8)?;
128
- return Ok(());
129
- }
130
-
131
- // Encode (2^N - 1) on N bits.
132
- b.put_u8(first | mask as u8)?;
133
-
134
- v -= mask;
135
-
136
- while v >= 128 {
137
- // Encode (I % 128 + 128) on 8 bits.
138
- b.put_u8((v % 128 + 128) as u8)?;
139
-
140
- v >>= 7;
141
- }
142
-
143
- // Encode I on 8 bits.
144
- b.put_u8(v as u8)?;
145
-
146
- Ok(())
147
- }
148
-
149
- #[inline]
150
- pub fn encode_str<const LOWER_CASE: bool>(
151
- v: &[u8], first: u8, prefix: usize, b: &mut octets::OctetsMut,
152
- ) -> Result<()> {
153
- // Huffman-encoding generally saves space but in some cases it doesn't, for
154
- // those just encode the literal string.
155
- match octets::huffman_encoding_len::<LOWER_CASE>(v) {
156
- Ok(len) => {
157
- encode_int(len as u64, first | (1 << prefix), prefix, b)?;
158
- b.put_huffman_encoded::<LOWER_CASE>(v)?;
159
- },
160
-
161
- Err(_) => {
162
- encode_int(v.len() as u64, first, prefix, b)?;
163
- if LOWER_CASE {
164
- b.put_bytes(&v.to_ascii_lowercase())?;
165
- } else {
166
- b.put_bytes(v)?;
167
- }
168
- },
169
- }
170
-
171
- Ok(())
172
- }
173
-
174
- #[cfg(test)]
175
- mod tests {
176
- use super::*;
177
-
178
- #[test]
179
- fn encode_int1() {
180
- let expected = [0b01010];
181
- let mut encoded = [0; 1];
182
- let mut b = octets::OctetsMut::with_slice(&mut encoded);
183
-
184
- assert!(encode_int(10, 0, 5, &mut b).is_ok());
185
-
186
- assert_eq!(expected, encoded);
187
- }
188
-
189
- #[test]
190
- fn encode_int2() {
191
- let expected = [0b11111, 0b10011010, 0b00001010];
192
- let mut encoded = [0; 3];
193
- let mut b = octets::OctetsMut::with_slice(&mut encoded);
194
-
195
- assert!(encode_int(1337, 0, 5, &mut b).is_ok());
196
-
197
- assert_eq!(expected, encoded);
198
- }
199
-
200
- #[test]
201
- fn encode_int3() {
202
- let expected = [0b101010];
203
- let mut encoded = [0; 1];
204
- let mut b = octets::OctetsMut::with_slice(&mut encoded);
205
-
206
- assert!(encode_int(42, 0, 8, &mut b).is_ok());
207
-
208
- assert_eq!(expected, encoded);
209
- }
210
-
211
- #[test]
212
- fn encode_static_header() {
213
- let mut encoded = [0; 3];
214
- Encoder::default()
215
- .encode(&[(b":method", b"GET")], &mut encoded)
216
- .unwrap();
217
- assert_eq!(encoded, [0, 0, INDEXED | 0x40 | 17]);
218
- }
219
-
220
- #[test]
221
- fn encode_static_header_name_only() {
222
- let mut encoded = [0; 11];
223
- let mut expected = [0; 11];
224
- let mut buf = octets::OctetsMut::with_slice(&mut expected[..]);
225
- buf.put_u16(0).unwrap();
226
- buf.put_u8(LITERAL_WITH_NAME_REF | 0x10 | 15).unwrap();
227
- buf.put_u8(0).unwrap();
228
- encode_str::<false>(b"FORGET", 0, 7, &mut buf).unwrap();
229
-
230
- Encoder::default()
231
- .encode(&[(b":method", b"FORGET")], &mut encoded)
232
- .unwrap();
233
- assert_eq!(encoded, expected);
234
- }
235
- }
1
+ // Copyright (C) 2019, Cloudflare, Inc.
2
+ // All rights reserved.
3
+ //
4
+ // Redistribution and use in source and binary forms, with or without
5
+ // modification, are permitted provided that the following conditions are
6
+ // met:
7
+ //
8
+ // * Redistributions of source code must retain the above copyright notice,
9
+ // this list of conditions and the following disclaimer.
10
+ //
11
+ // * Redistributions in binary form must reproduce the above copyright
12
+ // notice, this list of conditions and the following disclaimer in the
13
+ // documentation and/or other materials provided with the distribution.
14
+ //
15
+ // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
16
+ // IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
17
+ // THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
18
+ // PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
19
+ // CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
20
+ // EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
21
+ // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
22
+ // PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
23
+ // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
24
+ // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
25
+ // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26
+
27
+ use super::Result;
28
+
29
+ use crate::h3::NameValue;
30
+
31
+ use super::INDEXED;
32
+ use super::LITERAL;
33
+ use super::LITERAL_WITH_NAME_REF;
34
+
35
+ /// A QPACK encoder.
36
+ #[derive(Default)]
37
+ pub struct Encoder {}
38
+
39
+ impl Encoder {
40
+ /// Creates a new QPACK encoder.
41
+ pub fn new() -> Encoder {
42
+ Encoder::default()
43
+ }
44
+
45
+ /// Encodes a list of headers into a QPACK header block.
46
+ pub fn encode<T: NameValue>(
47
+ &mut self, headers: &[T], out: &mut [u8],
48
+ ) -> Result<usize> {
49
+ let mut b = octets::OctetsMut::with_slice(out);
50
+
51
+ // Required Insert Count.
52
+ encode_int(0, 0, 8, &mut b)?;
53
+
54
+ // Base.
55
+ encode_int(0, 0, 7, &mut b)?;
56
+
57
+ for h in headers {
58
+ match lookup_static(h) {
59
+ Some((idx, true)) => {
60
+ const STATIC: u8 = 0x40;
61
+
62
+ // Encode as statically indexed.
63
+ encode_int(idx, INDEXED | STATIC, 6, &mut b)?;
64
+ },
65
+
66
+ Some((idx, false)) => {
67
+ const STATIC: u8 = 0x10;
68
+
69
+ // Encode value as literal with static name reference.
70
+ encode_int(idx, LITERAL_WITH_NAME_REF | STATIC, 4, &mut b)?;
71
+ encode_str::<false>(h.value(), 0, 7, &mut b)?;
72
+ },
73
+
74
+ None => {
75
+ // Encode as fully literal.
76
+
77
+ encode_str::<true>(h.name(), LITERAL, 3, &mut b)?;
78
+ encode_str::<false>(h.value(), 0, 7, &mut b)?;
79
+ },
80
+ };
81
+ }
82
+
83
+ Ok(b.off())
84
+ }
85
+ }
86
+
87
+ fn lookup_static<T: NameValue>(h: &T) -> Option<(u64, bool)> {
88
+ // Fetch the right encoding table for this header length.
89
+ let table_for_len =
90
+ super::static_table::STATIC_ENCODE_TABLE.get(h.name().len())?;
91
+
92
+ // Similar to [`eq_ignore_ascii_case`], but only lowercases the second
93
+ // operand, as the entries in the table are already lower cased.
94
+ let cmp_lowercase = |a: &[u8], b: &[u8]| {
95
+ std::iter::zip(a, b).all(|(a, b)| a.eq(&b.to_ascii_lowercase()))
96
+ };
97
+
98
+ for (name, values) in table_for_len.iter() {
99
+ // Match header name first.
100
+ if cmp_lowercase(name, h.name()) {
101
+ // Second iterate over possible values for the header.
102
+ for (value, enc) in values.iter() {
103
+ // Match header value.
104
+ if value.is_empty() {
105
+ return Some((*enc, false));
106
+ }
107
+
108
+ if h.value() == *value {
109
+ return Some((*enc, true));
110
+ }
111
+ }
112
+ // Only matched the header, not the value.
113
+ return Some((values.first()?.1, false));
114
+ }
115
+ }
116
+
117
+ None
118
+ }
119
+
120
+ pub fn encode_int(
121
+ mut v: u64, first: u8, prefix: usize, b: &mut octets::OctetsMut,
122
+ ) -> Result<()> {
123
+ let mask = 2u64.pow(prefix as u32) - 1;
124
+
125
+ // Encode I on N bits.
126
+ if v < mask {
127
+ b.put_u8(first | v as u8)?;
128
+ return Ok(());
129
+ }
130
+
131
+ // Encode (2^N - 1) on N bits.
132
+ b.put_u8(first | mask as u8)?;
133
+
134
+ v -= mask;
135
+
136
+ while v >= 128 {
137
+ // Encode (I % 128 + 128) on 8 bits.
138
+ b.put_u8((v % 128 + 128) as u8)?;
139
+
140
+ v >>= 7;
141
+ }
142
+
143
+ // Encode I on 8 bits.
144
+ b.put_u8(v as u8)?;
145
+
146
+ Ok(())
147
+ }
148
+
149
+ #[inline]
150
+ pub fn encode_str<const LOWER_CASE: bool>(
151
+ v: &[u8], first: u8, prefix: usize, b: &mut octets::OctetsMut,
152
+ ) -> Result<()> {
153
+ // Huffman-encoding generally saves space but in some cases it doesn't, for
154
+ // those just encode the literal string.
155
+ match octets::huffman_encoding_len::<LOWER_CASE>(v) {
156
+ Ok(len) => {
157
+ encode_int(len as u64, first | (1 << prefix), prefix, b)?;
158
+ b.put_huffman_encoded::<LOWER_CASE>(v)?;
159
+ },
160
+
161
+ Err(_) => {
162
+ encode_int(v.len() as u64, first, prefix, b)?;
163
+ if LOWER_CASE {
164
+ b.put_bytes(&v.to_ascii_lowercase())?;
165
+ } else {
166
+ b.put_bytes(v)?;
167
+ }
168
+ },
169
+ }
170
+
171
+ Ok(())
172
+ }
173
+
174
+ #[cfg(test)]
175
+ mod tests {
176
+ use super::*;
177
+
178
+ #[test]
179
+ fn encode_int1() {
180
+ let expected = [0b01010];
181
+ let mut encoded = [0; 1];
182
+ let mut b = octets::OctetsMut::with_slice(&mut encoded);
183
+
184
+ assert!(encode_int(10, 0, 5, &mut b).is_ok());
185
+
186
+ assert_eq!(expected, encoded);
187
+ }
188
+
189
+ #[test]
190
+ fn encode_int2() {
191
+ let expected = [0b11111, 0b10011010, 0b00001010];
192
+ let mut encoded = [0; 3];
193
+ let mut b = octets::OctetsMut::with_slice(&mut encoded);
194
+
195
+ assert!(encode_int(1337, 0, 5, &mut b).is_ok());
196
+
197
+ assert_eq!(expected, encoded);
198
+ }
199
+
200
+ #[test]
201
+ fn encode_int3() {
202
+ let expected = [0b101010];
203
+ let mut encoded = [0; 1];
204
+ let mut b = octets::OctetsMut::with_slice(&mut encoded);
205
+
206
+ assert!(encode_int(42, 0, 8, &mut b).is_ok());
207
+
208
+ assert_eq!(expected, encoded);
209
+ }
210
+
211
+ #[test]
212
+ fn encode_static_header() {
213
+ let mut encoded = [0; 3];
214
+ Encoder::default()
215
+ .encode(&[(b":method", b"GET")], &mut encoded)
216
+ .unwrap();
217
+ assert_eq!(encoded, [0, 0, INDEXED | 0x40 | 17]);
218
+ }
219
+
220
+ #[test]
221
+ fn encode_static_header_name_only() {
222
+ let mut encoded = [0; 11];
223
+ let mut expected = [0; 11];
224
+ let mut buf = octets::OctetsMut::with_slice(&mut expected[..]);
225
+ buf.put_u16(0).unwrap();
226
+ buf.put_u8(LITERAL_WITH_NAME_REF | 0x10 | 15).unwrap();
227
+ buf.put_u8(0).unwrap();
228
+ encode_str::<false>(b"FORGET", 0, 7, &mut buf).unwrap();
229
+
230
+ Encoder::default()
231
+ .encode(&[(b":method", b"FORGET")], &mut encoded)
232
+ .unwrap();
233
+ assert_eq!(encoded, expected);
234
+ }
235
+ }