@moqtap/codec 0.4.3 → 0.6.0

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 (133) hide show
  1. package/dist/chunk-62LYLROG.js +2095 -0
  2. package/dist/chunk-A33U4WVS.cjs +1993 -0
  3. package/dist/chunk-A655PHFX.cjs +446 -0
  4. package/dist/chunk-CQ65LKPQ.cjs +446 -0
  5. package/dist/chunk-DLSGOZ6P.js +1993 -0
  6. package/dist/chunk-IWYKDCXP.js +446 -0
  7. package/dist/chunk-MSG2FXJ2.cjs +2095 -0
  8. package/dist/chunk-O5DQ44TM.js +446 -0
  9. package/dist/{codec-C7UzTYSS.d.cts → codec-B1snaM9L.d.cts} +1 -1
  10. package/dist/{codec-ZwV-Njt6.d.ts → codec-BLYAy2OP.d.ts} +1 -1
  11. package/dist/{codec-B2lYE0YA.d.ts → codec-BNS3gS77.d.ts} +1 -1
  12. package/dist/{codec-BbbLDSKA.d.cts → codec-BOtv3R5j.d.cts} +1 -1
  13. package/dist/{codec-DDUBJGn0.d.cts → codec-BOyrk_C9.d.cts} +1 -1
  14. package/dist/{codec-BWQ5Jlap.d.cts → codec-BqqoYdh_.d.cts} +1 -1
  15. package/dist/{codec-3Ppy_5Gd.d.ts → codec-CI0BjmHc.d.ts} +1 -1
  16. package/dist/{codec-DftaRuVz.d.ts → codec-CWj5iTxA.d.ts} +1 -1
  17. package/dist/{codec-B_QST4y1.d.cts → codec-CyApDKwf.d.cts} +1 -1
  18. package/dist/{codec-BFg5xnrJ.d.ts → codec-D2JbI2tp.d.ts} +1 -1
  19. package/dist/{codec-DFU-6Rax.d.ts → codec-D47r_-Rl.d.ts} +1 -1
  20. package/dist/{codec-Db-0pk38.d.ts → codec-D49OofBr.d.ts} +1 -1
  21. package/dist/codec-D89DWXbv.d.cts +30 -0
  22. package/dist/{codec-R9TJCq-E.d.cts → codec-D95gT98n.d.cts} +1 -1
  23. package/dist/codec-DAePx2NL.d.ts +30 -0
  24. package/dist/{codec-CpZrZ3ok.d.ts → codec-DJmV04i0.d.ts} +1 -1
  25. package/dist/{codec-Va_wZCF_.d.ts → codec-DL0njGkL.d.ts} +1 -1
  26. package/dist/{codec-CFWQY9Lj.d.cts → codec-DQWQSam3.d.cts} +1 -1
  27. package/dist/{codec-wtt6WF1K.d.ts → codec-DplRgIKq.d.ts} +1 -1
  28. package/dist/{codec-CewFCsEy.d.ts → codec-DujHf55Z.d.ts} +1 -1
  29. package/dist/{codec-j819z_hL.d.cts → codec-DvcJgYKq.d.cts} +1 -1
  30. package/dist/{codec-C8aSvE41.d.cts → codec-NMsTK0GX.d.cts} +1 -1
  31. package/dist/codec-WwwUipaU.d.ts +30 -0
  32. package/dist/{codec-CAbm9d_n.d.cts → codec-cou9XBMF.d.cts} +1 -1
  33. package/dist/{codec-lqDowbyT.d.cts → codec-hvkJfCF5.d.cts} +1 -1
  34. package/dist/codec-xeuGZY77.d.cts +30 -0
  35. package/dist/draft07-session.d.cts +3 -3
  36. package/dist/draft07-session.d.ts +3 -3
  37. package/dist/draft07.d.cts +3 -3
  38. package/dist/draft07.d.ts +3 -3
  39. package/dist/draft08-session.d.cts +3 -3
  40. package/dist/draft08-session.d.ts +3 -3
  41. package/dist/draft08.d.cts +4 -4
  42. package/dist/draft08.d.ts +4 -4
  43. package/dist/draft09-session.d.cts +3 -3
  44. package/dist/draft09-session.d.ts +3 -3
  45. package/dist/draft09.d.cts +4 -4
  46. package/dist/draft09.d.ts +4 -4
  47. package/dist/draft10-session.d.cts +3 -3
  48. package/dist/draft10-session.d.ts +3 -3
  49. package/dist/draft10.d.cts +4 -4
  50. package/dist/draft10.d.ts +4 -4
  51. package/dist/draft11-session.d.cts +3 -3
  52. package/dist/draft11-session.d.ts +3 -3
  53. package/dist/draft11.d.cts +4 -4
  54. package/dist/draft11.d.ts +4 -4
  55. package/dist/draft12-session.d.cts +3 -3
  56. package/dist/draft12-session.d.ts +3 -3
  57. package/dist/draft12.d.cts +4 -4
  58. package/dist/draft12.d.ts +4 -4
  59. package/dist/draft13-session.d.cts +3 -3
  60. package/dist/draft13-session.d.ts +3 -3
  61. package/dist/draft13.d.cts +4 -4
  62. package/dist/draft13.d.ts +4 -4
  63. package/dist/draft14-session.d.cts +3 -3
  64. package/dist/draft14-session.d.ts +3 -3
  65. package/dist/draft14.d.cts +4 -4
  66. package/dist/draft14.d.ts +4 -4
  67. package/dist/draft15-session.d.cts +3 -3
  68. package/dist/draft15-session.d.ts +3 -3
  69. package/dist/draft15.d.cts +4 -4
  70. package/dist/draft15.d.ts +4 -4
  71. package/dist/draft16-session.d.cts +3 -3
  72. package/dist/draft16-session.d.ts +3 -3
  73. package/dist/draft16.d.cts +4 -4
  74. package/dist/draft16.d.ts +4 -4
  75. package/dist/draft17-session.d.cts +3 -3
  76. package/dist/draft17-session.d.ts +3 -3
  77. package/dist/draft17.d.cts +3 -3
  78. package/dist/draft17.d.ts +3 -3
  79. package/dist/draft18-session.cjs +8 -0
  80. package/dist/draft18-session.d.cts +50 -0
  81. package/dist/draft18-session.d.ts +50 -0
  82. package/dist/draft18-session.js +8 -0
  83. package/dist/draft18.cjs +179 -0
  84. package/dist/draft18.d.cts +126 -0
  85. package/dist/draft18.d.ts +126 -0
  86. package/dist/draft18.js +179 -0
  87. package/dist/draft19-session.cjs +8 -0
  88. package/dist/draft19-session.d.cts +50 -0
  89. package/dist/draft19-session.d.ts +50 -0
  90. package/dist/draft19-session.js +8 -0
  91. package/dist/draft19.cjs +189 -0
  92. package/dist/draft19.d.cts +130 -0
  93. package/dist/draft19.d.ts +130 -0
  94. package/dist/draft19.js +189 -0
  95. package/dist/index.cjs +13 -1
  96. package/dist/index.d.cts +24 -14
  97. package/dist/index.d.ts +24 -14
  98. package/dist/index.js +13 -1
  99. package/dist/{session-types-X-IYEGoG.d.ts → session-types-C0l_-Ups.d.ts} +1 -1
  100. package/dist/{session-types-C7UONex5.d.cts → session-types-KsqyVp6y.d.cts} +1 -1
  101. package/dist/session.cjs +9 -1
  102. package/dist/session.d.cts +7 -3
  103. package/dist/session.d.ts +7 -3
  104. package/dist/session.js +9 -1
  105. package/dist/{types-DuIO7cWK.d.cts → types-CdCSIfvI.d.cts} +1 -1
  106. package/dist/{types-DuIO7cWK.d.ts → types-CdCSIfvI.d.ts} +1 -1
  107. package/dist/types-Cqp10JtB.d.cts +249 -0
  108. package/dist/types-Cqp10JtB.d.ts +249 -0
  109. package/dist/types-zHgCS6o5.d.cts +265 -0
  110. package/dist/types-zHgCS6o5.d.ts +265 -0
  111. package/package.json +26 -2
  112. package/src/core/types.ts +14 -1
  113. package/src/drafts/draft17/error-codes.ts +72 -0
  114. package/src/drafts/draft18/codec.ts +1310 -0
  115. package/src/drafts/draft18/data-streams.ts +996 -0
  116. package/src/drafts/draft18/error-codes.ts +75 -0
  117. package/src/drafts/draft18/index.ts +122 -0
  118. package/src/drafts/draft18/messages.ts +56 -0
  119. package/src/drafts/draft18/rules.ts +85 -0
  120. package/src/drafts/draft18/session-fsm.ts +451 -0
  121. package/src/drafts/draft18/session.ts +15 -0
  122. package/src/drafts/draft18/types.ts +347 -0
  123. package/src/drafts/draft19/codec.ts +1425 -0
  124. package/src/drafts/draft19/data-streams.ts +996 -0
  125. package/src/drafts/draft19/error-codes.ts +78 -0
  126. package/src/drafts/draft19/index.ts +126 -0
  127. package/src/drafts/draft19/messages.ts +58 -0
  128. package/src/drafts/draft19/rules.ts +85 -0
  129. package/src/drafts/draft19/session-fsm.ts +451 -0
  130. package/src/drafts/draft19/session.ts +15 -0
  131. package/src/drafts/draft19/types.ts +368 -0
  132. package/src/index.ts +17 -1
  133. package/src/session.ts +8 -0
@@ -0,0 +1,1993 @@
1
+ "use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } }
2
+
3
+
4
+
5
+
6
+
7
+ var _chunkJL3NEW3Ocjs = require('./chunk-JL3NEW3O.cjs');
8
+
9
+ // src/drafts/draft18/messages.ts
10
+ var MSG_REQUEST_UPDATE = 0x02n;
11
+ var MSG_SUBSCRIBE = 0x03n;
12
+ var MSG_SUBSCRIBE_OK = 0x04n;
13
+ var MSG_REQUEST_ERROR = 0x05n;
14
+ var MSG_PUBLISH_NAMESPACE = 0x06n;
15
+ var MSG_REQUEST_OK = 0x07n;
16
+ var MSG_NAMESPACE = 0x08n;
17
+ var MSG_PUBLISH_DONE = 0x0bn;
18
+ var MSG_TRACK_STATUS = 0x0dn;
19
+ var MSG_NAMESPACE_DONE = 0x0en;
20
+ var MSG_PUBLISH_BLOCKED = 0x0fn;
21
+ var MSG_GOAWAY = 0x10n;
22
+ var MSG_FETCH = 0x16n;
23
+ var MSG_FETCH_OK = 0x18n;
24
+ var MSG_PUBLISH = 0x1dn;
25
+ var MSG_PUBLISH_OK = MSG_REQUEST_OK;
26
+ var MSG_SUBSCRIBE_NAMESPACE = 0x50n;
27
+ var MSG_SUBSCRIBE_TRACKS = 0x51n;
28
+ var MSG_SETUP = 0x2f00n;
29
+ var SETUP_OPT_PATH = 0x01n;
30
+ var SETUP_OPT_AUTHORIZATION_TOKEN = 0x03n;
31
+ var SETUP_OPT_MAX_AUTH_TOKEN_CACHE_SIZE = 0x04n;
32
+ var SETUP_OPT_AUTHORITY = 0x05n;
33
+ var SETUP_OPT_MOQT_IMPLEMENTATION = 0x07n;
34
+ var MESSAGE_TYPE_MAP = /* @__PURE__ */ new Map([
35
+ [MSG_SETUP, "setup"],
36
+ [MSG_SUBSCRIBE, "subscribe"],
37
+ [MSG_SUBSCRIBE_OK, "subscribe_ok"],
38
+ [MSG_REQUEST_UPDATE, "request_update"],
39
+ [MSG_PUBLISH, "publish"],
40
+ [MSG_PUBLISH_DONE, "publish_done"],
41
+ [MSG_PUBLISH_NAMESPACE, "publish_namespace"],
42
+ [MSG_NAMESPACE, "namespace"],
43
+ [MSG_NAMESPACE_DONE, "namespace_done"],
44
+ [MSG_SUBSCRIBE_NAMESPACE, "subscribe_namespace"],
45
+ [MSG_SUBSCRIBE_TRACKS, "subscribe_tracks"],
46
+ [MSG_PUBLISH_BLOCKED, "publish_blocked"],
47
+ [MSG_FETCH, "fetch"],
48
+ [MSG_FETCH_OK, "fetch_ok"],
49
+ [MSG_TRACK_STATUS, "track_status"],
50
+ [MSG_REQUEST_OK, "request_ok"],
51
+ [MSG_REQUEST_ERROR, "request_error"],
52
+ [MSG_GOAWAY, "goaway"]
53
+ ]);
54
+ var MESSAGE_ID_MAP = new Map(
55
+ [...MESSAGE_TYPE_MAP.entries()].map(([id, name]) => [name, id])
56
+ );
57
+
58
+ // src/drafts/draft18/data-streams.ts
59
+ var FETCH_STREAM_TYPE = 0x05n;
60
+ var OBJPROP_PRIOR_GROUP_ID_GAP = 0x3cn;
61
+ var OBJPROP_PRIOR_OBJECT_ID_GAP = 0x3en;
62
+ var KNOWN_OBJ_PROPS = /* @__PURE__ */ new Map([
63
+ [OBJPROP_PRIOR_OBJECT_ID_GAP, "prior_object_id_gap"],
64
+ [OBJPROP_PRIOR_GROUP_ID_GAP, "prior_group_id_gap"]
65
+ ]);
66
+ function decodeObjectProperties(r, propsLength) {
67
+ const endOff = r.offset + propsLength;
68
+ const props = {};
69
+ let prevType = 0n;
70
+ while (r.offset < endOff) {
71
+ const delta = r.readVarInt();
72
+ const propType = prevType + delta;
73
+ prevType = propType;
74
+ if (propType % 2n === 0n) {
75
+ const value = r.readVarInt();
76
+ const name = _nullishCoalesce(KNOWN_OBJ_PROPS.get(propType), () => ( `0x${propType.toString(16)}`));
77
+ props[name] = value;
78
+ } else {
79
+ const length = Number(r.readVarInt());
80
+ r.readBytes(length);
81
+ }
82
+ }
83
+ return props;
84
+ }
85
+ function encodeObjectProperties(props, w) {
86
+ const reverseMap = /* @__PURE__ */ new Map();
87
+ for (const [id, name] of KNOWN_OBJ_PROPS) {
88
+ reverseMap.set(name, id);
89
+ }
90
+ const entries = [];
91
+ for (const [name, value] of Object.entries(props)) {
92
+ const typeId = reverseMap.get(name);
93
+ if (typeId !== void 0) {
94
+ entries.push({ type: typeId, value });
95
+ }
96
+ }
97
+ entries.sort((a, b) => a.type < b.type ? -1 : a.type > b.type ? 1 : 0);
98
+ let prevType = 0n;
99
+ for (const entry of entries) {
100
+ w.writeVarInt(entry.type - prevType);
101
+ w.writeVarInt(entry.value);
102
+ prevType = entry.type;
103
+ }
104
+ }
105
+ function isValidSubgroupType(streamType) {
106
+ const inRange = streamType >= 16 && streamType <= 31 || streamType >= 48 && streamType <= 63 || streamType >= 80 && streamType <= 95 || streamType >= 112 && streamType <= 127;
107
+ if (!inRange) return false;
108
+ return (streamType & 6) !== 6;
109
+ }
110
+ function encodeSubgroupStream(stream) {
111
+ const w = new (0, _chunkJL3NEW3Ocjs.BufferWriter)();
112
+ const streamType = stream.headerType;
113
+ w.writeUint8(streamType);
114
+ const propertiesPresent = (streamType & 1) !== 0;
115
+ const subgroupMode = (streamType & 6) >> 1;
116
+ const hasSubgroupField = subgroupMode === 2;
117
+ const hasPriority = (streamType & 32) === 0;
118
+ w.writeVarInt(stream.trackAlias);
119
+ w.writeVarInt(stream.groupId);
120
+ if (hasSubgroupField) {
121
+ w.writeVarInt(stream.subgroupId);
122
+ }
123
+ if (hasPriority) {
124
+ w.writeUint8(stream.publisherPriority);
125
+ }
126
+ let prevObjectId = -1n;
127
+ for (const obj of stream.objects) {
128
+ const delta = prevObjectId < 0n ? obj.objectId : obj.objectId - prevObjectId - 1n;
129
+ w.writeVarInt(delta);
130
+ if (propertiesPresent) {
131
+ if (obj.objectProperties && Object.keys(obj.objectProperties).length > 0) {
132
+ const tmpW = new (0, _chunkJL3NEW3Ocjs.BufferWriter)(32);
133
+ encodeObjectProperties(obj.objectProperties, tmpW);
134
+ const raw = tmpW.finish();
135
+ w.writeVarInt(BigInt(raw.byteLength));
136
+ w.writeBytes(raw);
137
+ } else {
138
+ w.writeVarInt(0n);
139
+ }
140
+ }
141
+ w.writeVarInt(BigInt(obj.payloadLength));
142
+ if (obj.payloadLength === 0) {
143
+ w.writeVarInt(_nullishCoalesce(obj.status, () => ( 0n)));
144
+ } else {
145
+ w.writeBytes(obj.payload);
146
+ }
147
+ prevObjectId = obj.objectId;
148
+ }
149
+ return w.finish();
150
+ }
151
+ function encodeDatagram(dg) {
152
+ const w = new (0, _chunkJL3NEW3Ocjs.BufferWriter)();
153
+ const dgType = dg.datagramType;
154
+ w.writeUint8(dgType);
155
+ w.writeVarInt(dg.trackAlias);
156
+ w.writeVarInt(dg.groupId);
157
+ const objectIdAbsent = (dgType & 4) !== 0;
158
+ const isStatus = (dgType & 32) !== 0;
159
+ const defaultPriority = (dgType & 8) !== 0;
160
+ const propertiesPresent = (dgType & 1) !== 0;
161
+ if (!objectIdAbsent) {
162
+ w.writeVarInt(dg.objectId);
163
+ }
164
+ if (!defaultPriority) {
165
+ w.writeUint8(dg.publisherPriority);
166
+ }
167
+ if (propertiesPresent) {
168
+ if (dg.objectProperties && Object.keys(dg.objectProperties).length > 0) {
169
+ const tmpW = new (0, _chunkJL3NEW3Ocjs.BufferWriter)(32);
170
+ encodeObjectProperties(dg.objectProperties, tmpW);
171
+ const raw = tmpW.finish();
172
+ w.writeVarInt(BigInt(raw.byteLength));
173
+ w.writeBytes(raw);
174
+ } else {
175
+ w.writeVarInt(0n);
176
+ }
177
+ }
178
+ if (isStatus) {
179
+ w.writeVarInt(_nullishCoalesce(dg.objectStatus, () => ( 0n)));
180
+ } else {
181
+ w.writeBytes(dg.payload);
182
+ }
183
+ return w.finish();
184
+ }
185
+ function encodeFetchStream(stream) {
186
+ const w = new (0, _chunkJL3NEW3Ocjs.BufferWriter)();
187
+ w.writeVarInt(FETCH_STREAM_TYPE);
188
+ w.writeVarInt(stream.requestId);
189
+ let prevGroupId = 0n;
190
+ let prevObjectId = 0n;
191
+ let first = true;
192
+ for (const obj of stream.objects) {
193
+ w.writeVarInt(BigInt(obj.serializationFlags));
194
+ const flags = obj.serializationFlags;
195
+ if (flags >= 128) {
196
+ w.writeVarInt(obj.groupId);
197
+ w.writeVarInt(obj.objectId);
198
+ w.writeVarInt(BigInt(obj.payloadLength));
199
+ } else if (flags & 64) {
200
+ if (flags & 8) {
201
+ if (first) w.writeVarInt(obj.groupId);
202
+ else w.writeVarInt(obj.groupId - prevGroupId - 1n);
203
+ }
204
+ if (flags & 4) w.writeVarInt(obj.objectId);
205
+ if (flags & 16) w.writeUint8(obj.publisherPriority);
206
+ if (flags & 32) {
207
+ if (obj.objectProperties && Object.keys(obj.objectProperties).length > 0) {
208
+ const tmpW = new (0, _chunkJL3NEW3Ocjs.BufferWriter)(32);
209
+ encodeObjectProperties(obj.objectProperties, tmpW);
210
+ const raw = tmpW.finish();
211
+ w.writeVarInt(BigInt(raw.byteLength));
212
+ w.writeBytes(raw);
213
+ } else {
214
+ w.writeVarInt(0n);
215
+ }
216
+ }
217
+ w.writeVarInt(BigInt(obj.payloadLength));
218
+ if (obj.payloadLength > 0) {
219
+ w.writeBytes(obj.payload);
220
+ }
221
+ } else {
222
+ if (flags & 8) {
223
+ if (first) w.writeVarInt(obj.groupId);
224
+ else w.writeVarInt(obj.groupId - prevGroupId - 1n);
225
+ }
226
+ const subgroupEncoding = flags & 3;
227
+ if (subgroupEncoding === 3) w.writeVarInt(obj.subgroupId);
228
+ if (flags & 4) w.writeVarInt(obj.objectId);
229
+ if (flags & 16) w.writeUint8(obj.publisherPriority);
230
+ if (flags & 32) {
231
+ if (obj.objectProperties && Object.keys(obj.objectProperties).length > 0) {
232
+ const tmpW = new (0, _chunkJL3NEW3Ocjs.BufferWriter)(32);
233
+ encodeObjectProperties(obj.objectProperties, tmpW);
234
+ const raw = tmpW.finish();
235
+ w.writeVarInt(BigInt(raw.byteLength));
236
+ w.writeBytes(raw);
237
+ } else {
238
+ w.writeVarInt(0n);
239
+ }
240
+ }
241
+ w.writeVarInt(BigInt(obj.payloadLength));
242
+ if (obj.payloadLength > 0) {
243
+ w.writeBytes(obj.payload);
244
+ }
245
+ }
246
+ prevGroupId = obj.groupId;
247
+ prevObjectId = obj.objectId;
248
+ first = false;
249
+ }
250
+ void prevObjectId;
251
+ return w.finish();
252
+ }
253
+ function decodeSubgroupStream(bytes) {
254
+ try {
255
+ const r = new (0, _chunkJL3NEW3Ocjs.BufferReader)(bytes);
256
+ const streamType = r.readUint8();
257
+ if (!isValidSubgroupType(streamType)) {
258
+ return {
259
+ ok: false,
260
+ error: new (0, _chunkJL3NEW3Ocjs.DecodeError)(
261
+ "CONSTRAINT_VIOLATION",
262
+ `Invalid subgroup stream type 0x${streamType.toString(16)}`,
263
+ 0
264
+ )
265
+ };
266
+ }
267
+ const propertiesPresent = (streamType & 1) !== 0;
268
+ const subgroupMode = (streamType & 6) >> 1;
269
+ const hasSubgroupField = subgroupMode === 2;
270
+ const subgroupIsFirstObjId = subgroupMode === 1;
271
+ const endOfGroup = (streamType & 8) !== 0;
272
+ const hasPriority = (streamType & 32) === 0;
273
+ const firstObject = (streamType & 64) !== 0;
274
+ const trackAlias = r.readVarInt();
275
+ const groupId = r.readVarInt();
276
+ let subgroupId = 0n;
277
+ if (hasSubgroupField) {
278
+ subgroupId = r.readVarInt();
279
+ }
280
+ let publisherPriority = 128;
281
+ if (hasPriority) {
282
+ publisherPriority = r.readUint8();
283
+ }
284
+ const objects = [];
285
+ let prevObjectId = -1n;
286
+ let isFirst = true;
287
+ while (r.remaining > 0) {
288
+ const byteOffset = r.offset;
289
+ const delta = r.readVarInt();
290
+ let objectId;
291
+ if (isFirst) {
292
+ objectId = delta;
293
+ if (subgroupIsFirstObjId) {
294
+ subgroupId = objectId;
295
+ }
296
+ isFirst = false;
297
+ } else {
298
+ objectId = prevObjectId + 1n + delta;
299
+ }
300
+ const extensionData = new Uint8Array(0);
301
+ let objectProperties;
302
+ if (propertiesPresent) {
303
+ const propsLen = Number(r.readVarInt());
304
+ if (propsLen > 0) {
305
+ objectProperties = decodeObjectProperties(r, propsLen);
306
+ }
307
+ }
308
+ const payloadLength = Number(r.readVarInt());
309
+ let payload;
310
+ let status;
311
+ let payloadByteOffset;
312
+ if (payloadLength === 0) {
313
+ status = r.readVarInt();
314
+ payloadByteOffset = r.offset;
315
+ payload = new Uint8Array(0);
316
+ } else {
317
+ payloadByteOffset = r.offset;
318
+ payload = r.readBytesView(payloadLength);
319
+ }
320
+ const obj = {
321
+ type: "object",
322
+ byteOffset,
323
+ payloadByteOffset,
324
+ objectId,
325
+ payloadLength,
326
+ payload,
327
+ extensionData
328
+ };
329
+ if (status !== void 0) obj.status = status;
330
+ if (objectProperties !== void 0)
331
+ obj.objectProperties = objectProperties;
332
+ objects.push(obj);
333
+ prevObjectId = objectId;
334
+ }
335
+ const result = {
336
+ type: "subgroup",
337
+ headerType: streamType,
338
+ trackAlias,
339
+ groupId,
340
+ subgroupId,
341
+ publisherPriority,
342
+ objects
343
+ };
344
+ if (endOfGroup) result.endOfGroup = true;
345
+ if (firstObject) result.firstObject = true;
346
+ return {
347
+ ok: true,
348
+ value: result,
349
+ bytesRead: r.offset
350
+ };
351
+ } catch (e) {
352
+ if (e instanceof _chunkJL3NEW3Ocjs.DecodeError) return { ok: false, error: e };
353
+ throw e;
354
+ }
355
+ }
356
+ function decodeDatagram(bytes) {
357
+ try {
358
+ const r = new (0, _chunkJL3NEW3Ocjs.BufferReader)(bytes);
359
+ const dgType = r.readUint8();
360
+ const objectIdAbsent = (dgType & 4) !== 0;
361
+ const endOfGroup = (dgType & 2) !== 0;
362
+ const isStatus = (dgType & 32) !== 0;
363
+ const defaultPriority = (dgType & 8) !== 0;
364
+ const propertiesPresent = (dgType & 1) !== 0;
365
+ const trackAlias = r.readVarInt();
366
+ const groupId = r.readVarInt();
367
+ let objectId = 0n;
368
+ if (!objectIdAbsent) {
369
+ objectId = r.readVarInt();
370
+ }
371
+ let publisherPriority = 128;
372
+ if (!defaultPriority) {
373
+ publisherPriority = r.readUint8();
374
+ }
375
+ let objectProperties;
376
+ if (propertiesPresent) {
377
+ const propsLen = Number(r.readVarInt());
378
+ if (propsLen > 0) {
379
+ objectProperties = decodeObjectProperties(r, propsLen);
380
+ }
381
+ }
382
+ let objectStatus;
383
+ let payload;
384
+ if (isStatus) {
385
+ objectStatus = r.readVarInt();
386
+ payload = new Uint8Array(0);
387
+ } else {
388
+ payload = r.readBytesView(r.remaining);
389
+ }
390
+ const payloadLength = payload.byteLength;
391
+ const result = {
392
+ type: "datagram",
393
+ datagramType: dgType,
394
+ trackAlias,
395
+ groupId,
396
+ objectId,
397
+ publisherPriority,
398
+ payloadLength,
399
+ payload
400
+ };
401
+ if (endOfGroup) result.endOfGroup = true;
402
+ if (objectStatus !== void 0)
403
+ result.objectStatus = objectStatus;
404
+ if (objectProperties !== void 0)
405
+ result.objectProperties = objectProperties;
406
+ return { ok: true, value: result, bytesRead: r.offset };
407
+ } catch (e) {
408
+ if (e instanceof _chunkJL3NEW3Ocjs.DecodeError) return { ok: false, error: e };
409
+ throw e;
410
+ }
411
+ }
412
+ function decodeFetchStream(bytes) {
413
+ try {
414
+ const r = new (0, _chunkJL3NEW3Ocjs.BufferReader)(bytes);
415
+ const streamType = r.readVarInt();
416
+ if (streamType !== FETCH_STREAM_TYPE) {
417
+ return {
418
+ ok: false,
419
+ error: new (0, _chunkJL3NEW3Ocjs.DecodeError)(
420
+ "CONSTRAINT_VIOLATION",
421
+ `Expected fetch stream type 0x05, got 0x${streamType.toString(16)}`,
422
+ 0
423
+ )
424
+ };
425
+ }
426
+ const requestId = r.readVarInt();
427
+ const objects = [];
428
+ let prevGroupId = 0n;
429
+ let prevSubgroupId = 0n;
430
+ let prevObjectId = 0n;
431
+ let prevPriority = 128;
432
+ let first = true;
433
+ while (r.remaining > 0) {
434
+ const byteOffset = r.offset;
435
+ const flags = Number(r.readVarInt());
436
+ let groupId = prevGroupId;
437
+ let subgroupId = prevSubgroupId;
438
+ let objectId = prevObjectId + 1n;
439
+ let payloadLength;
440
+ let payload;
441
+ let payloadByteOffset;
442
+ const extensionData = new Uint8Array(0);
443
+ if (flags >= 128) {
444
+ if (flags !== 140 && flags !== 268) {
445
+ return {
446
+ ok: false,
447
+ error: new (0, _chunkJL3NEW3Ocjs.DecodeError)(
448
+ "CONSTRAINT_VIOLATION",
449
+ `Unknown serialization flags value: 0x${flags.toString(16)}`,
450
+ r.offset
451
+ )
452
+ };
453
+ }
454
+ groupId = r.readVarInt();
455
+ objectId = r.readVarInt();
456
+ payloadLength = Number(r.readVarInt());
457
+ payloadByteOffset = r.offset;
458
+ payload = payloadLength > 0 ? r.readBytesView(payloadLength) : new Uint8Array(0);
459
+ } else if (flags & 64) {
460
+ const objectIdPresent = (flags & 4) !== 0;
461
+ const groupIdPresent = (flags & 8) !== 0;
462
+ const priorityPresent = (flags & 16) !== 0;
463
+ const propsPresent = (flags & 32) !== 0;
464
+ if (groupIdPresent) {
465
+ const groupDelta = r.readVarInt();
466
+ groupId = first ? groupDelta : prevGroupId + groupDelta + 1n;
467
+ }
468
+ if (objectIdPresent) {
469
+ objectId = r.readVarInt();
470
+ }
471
+ if (priorityPresent) {
472
+ prevPriority = r.readUint8();
473
+ }
474
+ let objectProperties;
475
+ if (propsPresent) {
476
+ const propsLen = Number(r.readVarInt());
477
+ if (propsLen > 0) {
478
+ objectProperties = decodeObjectProperties(r, propsLen);
479
+ }
480
+ }
481
+ payloadLength = Number(r.readVarInt());
482
+ payloadByteOffset = r.offset;
483
+ payload = payloadLength > 0 ? r.readBytesView(payloadLength) : new Uint8Array(0);
484
+ const obj2 = {
485
+ type: "object",
486
+ byteOffset,
487
+ payloadByteOffset,
488
+ serializationFlags: flags,
489
+ groupId,
490
+ subgroupId: 0n,
491
+ objectId,
492
+ publisherPriority: prevPriority,
493
+ payloadLength,
494
+ payload,
495
+ extensionData
496
+ };
497
+ if (objectProperties)
498
+ obj2.objectProperties = objectProperties;
499
+ objects.push(obj2);
500
+ prevGroupId = groupId;
501
+ prevObjectId = objectId;
502
+ first = false;
503
+ continue;
504
+ } else {
505
+ const subgroupEncoding = flags & 3;
506
+ const objectIdPresent = (flags & 4) !== 0;
507
+ const groupIdPresent = (flags & 8) !== 0;
508
+ const priorityPresent = (flags & 16) !== 0;
509
+ const propsPresent = (flags & 32) !== 0;
510
+ if (groupIdPresent) {
511
+ const groupDelta = r.readVarInt();
512
+ groupId = first ? groupDelta : prevGroupId + groupDelta + 1n;
513
+ } else if (first) {
514
+ return {
515
+ ok: false,
516
+ error: new (0, _chunkJL3NEW3Ocjs.DecodeError)(
517
+ "CONSTRAINT_VIOLATION",
518
+ "First fetch object must include groupId",
519
+ r.offset
520
+ )
521
+ };
522
+ }
523
+ if (subgroupEncoding === 0) {
524
+ subgroupId = 0n;
525
+ } else if (subgroupEncoding === 1) {
526
+ if (first) {
527
+ return {
528
+ ok: false,
529
+ error: new (0, _chunkJL3NEW3Ocjs.DecodeError)(
530
+ "CONSTRAINT_VIOLATION",
531
+ "First fetch object cannot reference prior subgroupId",
532
+ r.offset
533
+ )
534
+ };
535
+ }
536
+ subgroupId = prevSubgroupId;
537
+ } else if (subgroupEncoding === 2) {
538
+ if (first) {
539
+ return {
540
+ ok: false,
541
+ error: new (0, _chunkJL3NEW3Ocjs.DecodeError)(
542
+ "CONSTRAINT_VIOLATION",
543
+ "First fetch object cannot reference prior subgroupId",
544
+ r.offset
545
+ )
546
+ };
547
+ }
548
+ subgroupId = prevSubgroupId + 1n;
549
+ } else if (subgroupEncoding === 3) {
550
+ subgroupId = r.readVarInt();
551
+ }
552
+ if (objectIdPresent) {
553
+ objectId = r.readVarInt();
554
+ } else if (first) {
555
+ return {
556
+ ok: false,
557
+ error: new (0, _chunkJL3NEW3Ocjs.DecodeError)(
558
+ "CONSTRAINT_VIOLATION",
559
+ "First fetch object must include objectId",
560
+ r.offset
561
+ )
562
+ };
563
+ }
564
+ if (priorityPresent) {
565
+ prevPriority = r.readUint8();
566
+ }
567
+ let objectProperties;
568
+ if (propsPresent) {
569
+ const propsLen = Number(r.readVarInt());
570
+ if (propsLen > 0) {
571
+ objectProperties = decodeObjectProperties(r, propsLen);
572
+ }
573
+ }
574
+ payloadLength = Number(r.readVarInt());
575
+ payloadByteOffset = r.offset;
576
+ payload = payloadLength > 0 ? r.readBytesView(payloadLength) : new Uint8Array(0);
577
+ if (objectProperties) {
578
+ const obj2 = {
579
+ type: "object",
580
+ byteOffset,
581
+ payloadByteOffset,
582
+ serializationFlags: flags,
583
+ groupId,
584
+ subgroupId,
585
+ objectId,
586
+ publisherPriority: prevPriority,
587
+ payloadLength,
588
+ payload,
589
+ extensionData
590
+ };
591
+ obj2.objectProperties = objectProperties;
592
+ objects.push(obj2);
593
+ prevGroupId = groupId;
594
+ prevSubgroupId = subgroupId;
595
+ prevObjectId = objectId;
596
+ first = false;
597
+ continue;
598
+ }
599
+ }
600
+ const obj = {
601
+ type: "object",
602
+ byteOffset,
603
+ payloadByteOffset,
604
+ serializationFlags: flags,
605
+ groupId,
606
+ subgroupId,
607
+ objectId,
608
+ publisherPriority: prevPriority,
609
+ payloadLength,
610
+ payload,
611
+ extensionData
612
+ };
613
+ objects.push(obj);
614
+ prevGroupId = groupId;
615
+ prevSubgroupId = subgroupId;
616
+ prevObjectId = objectId;
617
+ first = false;
618
+ }
619
+ return {
620
+ ok: true,
621
+ value: { type: "fetch", requestId, objects },
622
+ bytesRead: r.offset
623
+ };
624
+ } catch (e) {
625
+ if (e instanceof _chunkJL3NEW3Ocjs.DecodeError) return { ok: false, error: e };
626
+ throw e;
627
+ }
628
+ }
629
+ function decodeDataStream(streamType, bytes) {
630
+ switch (streamType) {
631
+ case "subgroup":
632
+ return decodeSubgroupStream(bytes);
633
+ case "datagram":
634
+ return decodeDatagram(bytes);
635
+ case "fetch":
636
+ return decodeFetchStream(bytes);
637
+ default: {
638
+ const _exhaustive = streamType;
639
+ throw new Error(`Unknown stream type: ${_exhaustive}`);
640
+ }
641
+ }
642
+ }
643
+ function createSubgroupStreamDecoder() {
644
+ let buffer = new Uint8Array(0);
645
+ let offset = 0;
646
+ let headerEmitted = false;
647
+ let prevObjectId = -1n;
648
+ let firstObject = true;
649
+ let _propertiesPresent = false;
650
+ return new TransformStream({
651
+ transform(chunk, controller) {
652
+ if (offset > 0) {
653
+ buffer = buffer.subarray(offset);
654
+ offset = 0;
655
+ }
656
+ const newBuffer = new Uint8Array(buffer.length + chunk.length);
657
+ newBuffer.set(buffer, 0);
658
+ newBuffer.set(chunk, buffer.length);
659
+ buffer = newBuffer;
660
+ if (!headerEmitted) {
661
+ try {
662
+ const r = new (0, _chunkJL3NEW3Ocjs.BufferReader)(buffer.subarray(offset));
663
+ const streamType = r.readUint8();
664
+ if (!isValidSubgroupType(streamType)) {
665
+ controller.error(
666
+ new (0, _chunkJL3NEW3Ocjs.DecodeError)(
667
+ "CONSTRAINT_VIOLATION",
668
+ `Invalid subgroup stream type 0x${streamType.toString(16)}`,
669
+ 0
670
+ )
671
+ );
672
+ return;
673
+ }
674
+ _propertiesPresent = (streamType & 1) !== 0;
675
+ const subgroupMode = (streamType & 6) >> 1;
676
+ const hasSubgroupField = subgroupMode === 2;
677
+ const hasPriority = (streamType & 32) === 0;
678
+ const trackAlias = r.readVarInt();
679
+ const groupId = r.readVarInt();
680
+ let subgroupId = 0n;
681
+ if (hasSubgroupField) {
682
+ subgroupId = r.readVarInt();
683
+ }
684
+ let publisherPriority = 128;
685
+ if (hasPriority) {
686
+ publisherPriority = r.readUint8();
687
+ }
688
+ controller.enqueue({
689
+ type: "subgroup_header",
690
+ trackAlias,
691
+ groupId,
692
+ subgroupId,
693
+ publisherPriority
694
+ });
695
+ headerEmitted = true;
696
+ offset += r.offset;
697
+ } catch (e) {
698
+ if (e instanceof _chunkJL3NEW3Ocjs.DecodeError && e.code === "UNEXPECTED_END") {
699
+ return;
700
+ }
701
+ controller.error(e);
702
+ return;
703
+ }
704
+ }
705
+ while (offset < buffer.length) {
706
+ try {
707
+ const r = new (0, _chunkJL3NEW3Ocjs.BufferReader)(buffer.subarray(offset));
708
+ const delta = r.readVarInt();
709
+ let objectId;
710
+ if (firstObject) {
711
+ objectId = delta;
712
+ firstObject = false;
713
+ } else {
714
+ objectId = prevObjectId + 1n + delta;
715
+ }
716
+ let extensionData = new Uint8Array(0);
717
+ if (_propertiesPresent) {
718
+ const extLen = Number(r.readVarInt());
719
+ extensionData = extLen > 0 ? r.readBytesView(extLen) : new Uint8Array(0);
720
+ }
721
+ const payloadLength = Number(r.readVarInt());
722
+ const payloadByteOffset = r.offset;
723
+ const payload = payloadLength > 0 ? r.readBytesView(payloadLength) : new Uint8Array(0);
724
+ controller.enqueue({
725
+ type: "object",
726
+ objectId,
727
+ payloadLength,
728
+ payload,
729
+ extensionData,
730
+ byteOffset: 0,
731
+ payloadByteOffset
732
+ });
733
+ offset += r.offset;
734
+ prevObjectId = objectId;
735
+ } catch (e) {
736
+ if (e instanceof _chunkJL3NEW3Ocjs.DecodeError && e.code === "UNEXPECTED_END") {
737
+ break;
738
+ }
739
+ controller.error(e);
740
+ return;
741
+ }
742
+ }
743
+ },
744
+ flush(controller) {
745
+ if (offset < buffer.length) {
746
+ controller.error(new (0, _chunkJL3NEW3Ocjs.DecodeError)("UNEXPECTED_END", "Stream ended with incomplete data", 0));
747
+ }
748
+ }
749
+ });
750
+ }
751
+ function createFetchStreamDecoder() {
752
+ let buffer = new Uint8Array(0);
753
+ let offset = 0;
754
+ let headerEmitted = false;
755
+ return new TransformStream({
756
+ transform(chunk, controller) {
757
+ if (offset > 0) {
758
+ buffer = buffer.subarray(offset);
759
+ offset = 0;
760
+ }
761
+ const newBuffer = new Uint8Array(buffer.length + chunk.length);
762
+ newBuffer.set(buffer, 0);
763
+ newBuffer.set(chunk, buffer.length);
764
+ buffer = newBuffer;
765
+ if (!headerEmitted) {
766
+ try {
767
+ const r = new (0, _chunkJL3NEW3Ocjs.BufferReader)(buffer.subarray(offset));
768
+ const streamType = r.readVarInt();
769
+ if (streamType !== FETCH_STREAM_TYPE) {
770
+ controller.error(
771
+ new (0, _chunkJL3NEW3Ocjs.DecodeError)(
772
+ "CONSTRAINT_VIOLATION",
773
+ `Expected fetch stream type 0x05, got 0x${streamType.toString(16)}`,
774
+ 0
775
+ )
776
+ );
777
+ return;
778
+ }
779
+ const requestId = r.readVarInt();
780
+ controller.enqueue({ type: "fetch_header", requestId });
781
+ headerEmitted = true;
782
+ offset += r.offset;
783
+ } catch (e) {
784
+ if (e instanceof _chunkJL3NEW3Ocjs.DecodeError && e.code === "UNEXPECTED_END") {
785
+ return;
786
+ }
787
+ controller.error(e);
788
+ return;
789
+ }
790
+ }
791
+ while (offset < buffer.length) {
792
+ try {
793
+ const r = new (0, _chunkJL3NEW3Ocjs.BufferReader)(buffer.subarray(offset));
794
+ const flags = Number(r.readVarInt());
795
+ const objectIdPresent = (flags & 4) !== 0;
796
+ const groupIdPresent = (flags & 8) !== 0;
797
+ const priorityPresent = (flags & 16) !== 0;
798
+ const extensionsPresent = (flags & 32) !== 0;
799
+ const subgroupEncoding = flags & 3;
800
+ if (groupIdPresent) r.readVarInt();
801
+ if (subgroupEncoding === 3) r.readVarInt();
802
+ let objectId = 0n;
803
+ if (objectIdPresent) objectId = r.readVarInt();
804
+ if (priorityPresent) r.readUint8();
805
+ let extensionData = new Uint8Array(0);
806
+ if (extensionsPresent) {
807
+ const extLen = Number(r.readVarInt());
808
+ extensionData = extLen > 0 ? r.readBytesView(extLen) : new Uint8Array(0);
809
+ }
810
+ const payloadLength = Number(r.readVarInt());
811
+ const payloadByteOffset = r.offset;
812
+ const payload = payloadLength > 0 ? r.readBytesView(payloadLength) : new Uint8Array(0);
813
+ controller.enqueue({
814
+ type: "object",
815
+ objectId,
816
+ payloadLength,
817
+ payload,
818
+ extensionData,
819
+ byteOffset: 0,
820
+ payloadByteOffset
821
+ });
822
+ offset += r.offset;
823
+ } catch (e) {
824
+ if (e instanceof _chunkJL3NEW3Ocjs.DecodeError && e.code === "UNEXPECTED_END") {
825
+ break;
826
+ }
827
+ controller.error(e);
828
+ return;
829
+ }
830
+ }
831
+ },
832
+ flush(controller) {
833
+ if (offset < buffer.length) {
834
+ controller.error(new (0, _chunkJL3NEW3Ocjs.DecodeError)("UNEXPECTED_END", "Stream ended with incomplete data", 0));
835
+ }
836
+ }
837
+ });
838
+ }
839
+ function createDataStreamDecoder() {
840
+ let buffer = new Uint8Array(0);
841
+ let offset = 0;
842
+ let inner = null;
843
+ return new TransformStream({
844
+ transform(chunk, controller) {
845
+ if (offset > 0) {
846
+ buffer = buffer.subarray(offset);
847
+ offset = 0;
848
+ }
849
+ const newBuffer = new Uint8Array(buffer.length + chunk.length);
850
+ newBuffer.set(buffer, 0);
851
+ newBuffer.set(chunk, buffer.length);
852
+ buffer = newBuffer;
853
+ if (inner === null) {
854
+ if (offset >= buffer.length) return;
855
+ const firstByte = buffer[offset];
856
+ if (isValidSubgroupType(firstByte)) {
857
+ const decoder = createSubgroupStreamDecoder();
858
+ inner = decoder;
859
+ } else if (firstByte === 5) {
860
+ const decoder = createFetchStreamDecoder();
861
+ inner = decoder;
862
+ } else {
863
+ controller.error(
864
+ new (0, _chunkJL3NEW3Ocjs.DecodeError)(
865
+ "CONSTRAINT_VIOLATION",
866
+ `Unknown data stream type: 0x${firstByte.toString(16)}`,
867
+ 0
868
+ )
869
+ );
870
+ return;
871
+ }
872
+ }
873
+ },
874
+ flush(controller) {
875
+ if (offset >= buffer.length) return;
876
+ const view = buffer.subarray(offset);
877
+ const firstByte = view[0];
878
+ let result;
879
+ if (isValidSubgroupType(firstByte)) {
880
+ result = decodeSubgroupStream(view);
881
+ } else if (firstByte === 5) {
882
+ result = decodeFetchStream(view);
883
+ } else {
884
+ controller.error(
885
+ new (0, _chunkJL3NEW3Ocjs.DecodeError)(
886
+ "CONSTRAINT_VIOLATION",
887
+ `Unknown data stream type: 0x${firstByte.toString(16)}`,
888
+ 0
889
+ )
890
+ );
891
+ return;
892
+ }
893
+ if (!result.ok) {
894
+ controller.error(result.error);
895
+ return;
896
+ }
897
+ const stream = result.value;
898
+ if (stream.type === "subgroup") {
899
+ controller.enqueue({
900
+ type: "subgroup_header",
901
+ trackAlias: stream.trackAlias,
902
+ groupId: stream.groupId,
903
+ subgroupId: stream.subgroupId,
904
+ publisherPriority: stream.publisherPriority
905
+ });
906
+ for (const obj of stream.objects) {
907
+ controller.enqueue(obj);
908
+ }
909
+ } else if (stream.type === "fetch") {
910
+ controller.enqueue({
911
+ type: "fetch_header",
912
+ requestId: stream.requestId
913
+ });
914
+ for (const obj of stream.objects) {
915
+ controller.enqueue(obj);
916
+ }
917
+ }
918
+ }
919
+ });
920
+ }
921
+
922
+ // src/drafts/draft18/codec.ts
923
+ var textEncoder = /* @__PURE__ */ new TextEncoder();
924
+ var textDecoder = /* @__PURE__ */ new TextDecoder();
925
+ var REQUEST_ERROR_REDIRECT = 0x34n;
926
+ function encodeSetupOptions(opts, writer) {
927
+ const entries = [];
928
+ if (opts.path !== void 0) {
929
+ entries.push({
930
+ type: SETUP_OPT_PATH,
931
+ encode: (w) => {
932
+ const encoded = textEncoder.encode(opts.path);
933
+ w.writeVarInt(BigInt(encoded.byteLength));
934
+ w.writeBytes(encoded);
935
+ }
936
+ });
937
+ }
938
+ if (opts.authorization_token !== void 0) {
939
+ entries.push({
940
+ type: SETUP_OPT_AUTHORIZATION_TOKEN,
941
+ encode: (w) => {
942
+ const tmpW = new (0, _chunkJL3NEW3Ocjs.BufferWriter)(64);
943
+ encodeAuthorizationToken(opts.authorization_token, tmpW);
944
+ const raw = tmpW.finish();
945
+ w.writeVarInt(BigInt(raw.byteLength));
946
+ w.writeBytes(raw);
947
+ }
948
+ });
949
+ }
950
+ if (opts.max_auth_token_cache_size !== void 0) {
951
+ entries.push({
952
+ type: SETUP_OPT_MAX_AUTH_TOKEN_CACHE_SIZE,
953
+ encode: (w) => w.writeVarInt(opts.max_auth_token_cache_size)
954
+ });
955
+ }
956
+ if (opts.authority !== void 0) {
957
+ entries.push({
958
+ type: SETUP_OPT_AUTHORITY,
959
+ encode: (w) => {
960
+ const encoded = textEncoder.encode(opts.authority);
961
+ w.writeVarInt(BigInt(encoded.byteLength));
962
+ w.writeBytes(encoded);
963
+ }
964
+ });
965
+ }
966
+ if (opts.moqt_implementation !== void 0) {
967
+ entries.push({
968
+ type: SETUP_OPT_MOQT_IMPLEMENTATION,
969
+ encode: (w) => {
970
+ const encoded = textEncoder.encode(opts.moqt_implementation);
971
+ w.writeVarInt(BigInt(encoded.byteLength));
972
+ w.writeBytes(encoded);
973
+ }
974
+ });
975
+ }
976
+ if (opts.unknown) {
977
+ for (const u of opts.unknown) {
978
+ const id = BigInt(u.id);
979
+ entries.push({
980
+ type: id,
981
+ encode: (w) => {
982
+ if (id % 2n === 0n) {
983
+ const raw = _chunkJL3NEW3Ocjs.hexToBytes.call(void 0, u.raw_hex);
984
+ const tmpReader = new (0, _chunkJL3NEW3Ocjs.BufferReader)(raw);
985
+ w.writeVarInt(tmpReader.readVarInt());
986
+ } else {
987
+ const raw = _chunkJL3NEW3Ocjs.hexToBytes.call(void 0, u.raw_hex);
988
+ w.writeVarInt(BigInt(raw.byteLength));
989
+ w.writeBytes(raw);
990
+ }
991
+ }
992
+ });
993
+ }
994
+ }
995
+ entries.sort((a, b) => a.type < b.type ? -1 : a.type > b.type ? 1 : 0);
996
+ let prevType = 0n;
997
+ for (const entry of entries) {
998
+ writer.writeVarInt(entry.type - prevType);
999
+ entry.encode(writer);
1000
+ prevType = entry.type;
1001
+ }
1002
+ }
1003
+ function decodeSetupOptions(reader, payloadEnd) {
1004
+ const result = {};
1005
+ const unknown = [];
1006
+ let prevType = 0n;
1007
+ while (reader.offset < payloadEnd) {
1008
+ const delta = reader.readVarInt();
1009
+ const optType = prevType + delta;
1010
+ prevType = optType;
1011
+ if (optType % 2n === 0n) {
1012
+ const value = reader.readVarInt();
1013
+ if (optType === SETUP_OPT_MAX_AUTH_TOKEN_CACHE_SIZE) {
1014
+ result.max_auth_token_cache_size = value;
1015
+ } else {
1016
+ const tmpWriter = new (0, _chunkJL3NEW3Ocjs.BufferWriter)(16);
1017
+ tmpWriter.writeVarInt(value);
1018
+ const raw = tmpWriter.finish();
1019
+ unknown.push({
1020
+ id: `0x${optType.toString(16)}`,
1021
+ length: raw.byteLength,
1022
+ raw_hex: _chunkJL3NEW3Ocjs.bytesToHex.call(void 0, raw)
1023
+ });
1024
+ }
1025
+ } else {
1026
+ const length = Number(reader.readVarInt());
1027
+ const bytes = reader.readBytes(length);
1028
+ if (optType === SETUP_OPT_PATH) {
1029
+ result.path = textDecoder.decode(bytes);
1030
+ } else if (optType === SETUP_OPT_AUTHORIZATION_TOKEN) {
1031
+ result.authorization_token = decodeAuthorizationToken(new (0, _chunkJL3NEW3Ocjs.BufferReader)(bytes));
1032
+ } else if (optType === SETUP_OPT_AUTHORITY) {
1033
+ result.authority = textDecoder.decode(bytes);
1034
+ } else if (optType === SETUP_OPT_MOQT_IMPLEMENTATION) {
1035
+ result.moqt_implementation = textDecoder.decode(bytes);
1036
+ } else {
1037
+ unknown.push({
1038
+ id: `0x${optType.toString(16)}`,
1039
+ length,
1040
+ raw_hex: _chunkJL3NEW3Ocjs.bytesToHex.call(void 0, bytes)
1041
+ });
1042
+ }
1043
+ }
1044
+ }
1045
+ if (unknown.length > 0) result.unknown = unknown;
1046
+ return result;
1047
+ }
1048
+ function encodeAuthorizationToken(token, w) {
1049
+ const aliasType = Number(token.alias_type);
1050
+ w.writeVarInt(token.alias_type);
1051
+ if (aliasType === 0 || aliasType === 1 || aliasType === 2) {
1052
+ w.writeVarInt(_nullishCoalesce(token.token_alias, () => ( 0n)));
1053
+ }
1054
+ if (aliasType === 1 || aliasType === 3) {
1055
+ w.writeVarInt(_nullishCoalesce(token.token_type, () => ( 0n)));
1056
+ const tv = _nullishCoalesce(token.token_value, () => ( new Uint8Array(0)));
1057
+ w.writeBytes(tv);
1058
+ }
1059
+ }
1060
+ function decodeAuthorizationToken(r) {
1061
+ const alias_type = r.readVarInt();
1062
+ const aliasType = Number(alias_type);
1063
+ const result = { alias_type };
1064
+ if (aliasType === 0 || aliasType === 1 || aliasType === 2) {
1065
+ ;
1066
+ result.token_alias = r.readVarInt();
1067
+ }
1068
+ if (aliasType === 1 || aliasType === 3) {
1069
+ ;
1070
+ result.token_type = r.readVarInt();
1071
+ const bytes = r.readBytes(r.remaining);
1072
+ result.token_value = bytes;
1073
+ }
1074
+ return result;
1075
+ }
1076
+ function encodeNamespaceTuple(ns, w) {
1077
+ w.writeVarInt(BigInt(ns.length));
1078
+ for (const part of ns) {
1079
+ const encoded = textEncoder.encode(part);
1080
+ w.writeVarInt(BigInt(encoded.byteLength));
1081
+ w.writeBytes(encoded);
1082
+ }
1083
+ }
1084
+ function decodeNamespaceTuple(r) {
1085
+ const count = Number(r.readVarInt());
1086
+ const parts = [];
1087
+ for (let i = 0; i < count; i++) {
1088
+ const len = Number(r.readVarInt());
1089
+ parts.push(textDecoder.decode(r.readBytes(len)));
1090
+ }
1091
+ return parts;
1092
+ }
1093
+ var PARAM_OBJECT_DELIVERY_TIMEOUT = 0x02n;
1094
+ var PARAM_AUTHORIZATION_TOKEN = 0x03n;
1095
+ var PARAM_RENDEZVOUS_TIMEOUT = 0x04n;
1096
+ var PARAM_SUBGROUP_DELIVERY_TIMEOUT = 0x06n;
1097
+ var PARAM_EXPIRES = 0x08n;
1098
+ var PARAM_LARGEST_OBJECT = 0x09n;
1099
+ var PARAM_FILL_TIMEOUT = 0x0an;
1100
+ var PARAM_FORWARD = 0x10n;
1101
+ var PARAM_SUBSCRIBER_PRIORITY = 0x20n;
1102
+ var PARAM_SUBSCRIPTION_FILTER = 0x21n;
1103
+ var PARAM_GROUP_ORDER = 0x22n;
1104
+ var PARAM_NEW_GROUP_REQUEST = 0x32n;
1105
+ var PARAM_TRACK_NAMESPACE_PREFIX = 0x34n;
1106
+ function encodeParams(params, writer) {
1107
+ const entries = [];
1108
+ if (params.object_delivery_timeout !== void 0) {
1109
+ entries.push({
1110
+ type: PARAM_OBJECT_DELIVERY_TIMEOUT,
1111
+ encode: (w) => w.writeVarInt(params.object_delivery_timeout)
1112
+ });
1113
+ }
1114
+ if (params.authorization_token !== void 0) {
1115
+ entries.push({
1116
+ type: PARAM_AUTHORIZATION_TOKEN,
1117
+ encode: (w) => {
1118
+ const tmpW = new (0, _chunkJL3NEW3Ocjs.BufferWriter)(64);
1119
+ encodeAuthorizationToken(params.authorization_token, tmpW);
1120
+ const raw = tmpW.finish();
1121
+ w.writeVarInt(BigInt(raw.byteLength));
1122
+ w.writeBytes(raw);
1123
+ }
1124
+ });
1125
+ }
1126
+ if (params.rendezvous_timeout !== void 0) {
1127
+ entries.push({
1128
+ type: PARAM_RENDEZVOUS_TIMEOUT,
1129
+ encode: (w) => w.writeVarInt(params.rendezvous_timeout)
1130
+ });
1131
+ }
1132
+ if (params.subgroup_delivery_timeout !== void 0) {
1133
+ entries.push({
1134
+ type: PARAM_SUBGROUP_DELIVERY_TIMEOUT,
1135
+ encode: (w) => w.writeVarInt(params.subgroup_delivery_timeout)
1136
+ });
1137
+ }
1138
+ if (params.expires !== void 0) {
1139
+ entries.push({
1140
+ type: PARAM_EXPIRES,
1141
+ encode: (w) => w.writeVarInt(params.expires)
1142
+ });
1143
+ }
1144
+ if (params.largest_object !== void 0) {
1145
+ entries.push({
1146
+ type: PARAM_LARGEST_OBJECT,
1147
+ encode: (w) => {
1148
+ const tmpW = new (0, _chunkJL3NEW3Ocjs.BufferWriter)(16);
1149
+ tmpW.writeVarInt(params.largest_object.group);
1150
+ tmpW.writeVarInt(params.largest_object.object);
1151
+ const raw = tmpW.finish();
1152
+ w.writeVarInt(BigInt(raw.byteLength));
1153
+ w.writeBytes(raw);
1154
+ }
1155
+ });
1156
+ }
1157
+ if (params.fill_timeout !== void 0) {
1158
+ entries.push({
1159
+ type: PARAM_FILL_TIMEOUT,
1160
+ encode: (w) => w.writeVarInt(params.fill_timeout)
1161
+ });
1162
+ }
1163
+ if (params.forward !== void 0) {
1164
+ entries.push({
1165
+ type: PARAM_FORWARD,
1166
+ encode: (w) => w.writeUint8(Number(params.forward))
1167
+ });
1168
+ }
1169
+ if (params.subscriber_priority !== void 0) {
1170
+ entries.push({
1171
+ type: PARAM_SUBSCRIBER_PRIORITY,
1172
+ encode: (w) => w.writeUint8(Number(params.subscriber_priority))
1173
+ });
1174
+ }
1175
+ if (params.subscription_filter !== void 0) {
1176
+ entries.push({
1177
+ type: PARAM_SUBSCRIPTION_FILTER,
1178
+ encode: (w) => {
1179
+ const f = params.subscription_filter;
1180
+ const tmpW = new (0, _chunkJL3NEW3Ocjs.BufferWriter)(32);
1181
+ tmpW.writeVarInt(f.filter_type);
1182
+ if (f.filter_type === 3n || f.filter_type === 4n) {
1183
+ tmpW.writeVarInt(f.start_group);
1184
+ tmpW.writeVarInt(f.start_object);
1185
+ }
1186
+ if (f.filter_type === 4n) {
1187
+ tmpW.writeVarInt(f.end_group);
1188
+ }
1189
+ const raw = tmpW.finish();
1190
+ w.writeVarInt(BigInt(raw.byteLength));
1191
+ w.writeBytes(raw);
1192
+ }
1193
+ });
1194
+ }
1195
+ if (params.group_order !== void 0) {
1196
+ entries.push({
1197
+ type: PARAM_GROUP_ORDER,
1198
+ encode: (w) => w.writeUint8(Number(params.group_order))
1199
+ });
1200
+ }
1201
+ if (params.new_group_request !== void 0) {
1202
+ entries.push({
1203
+ type: PARAM_NEW_GROUP_REQUEST,
1204
+ encode: (w) => w.writeVarInt(params.new_group_request)
1205
+ });
1206
+ }
1207
+ if (params.track_namespace_prefix !== void 0) {
1208
+ entries.push({
1209
+ type: PARAM_TRACK_NAMESPACE_PREFIX,
1210
+ encode: (w) => {
1211
+ const tmpW = new (0, _chunkJL3NEW3Ocjs.BufferWriter)(32);
1212
+ encodeNamespaceTuple(params.track_namespace_prefix, tmpW);
1213
+ const raw = tmpW.finish();
1214
+ w.writeVarInt(BigInt(raw.byteLength));
1215
+ w.writeBytes(raw);
1216
+ }
1217
+ });
1218
+ }
1219
+ if (params.unknown) {
1220
+ for (const u of params.unknown) {
1221
+ const id = BigInt(u.id);
1222
+ entries.push({
1223
+ type: id,
1224
+ encode: (w) => {
1225
+ const raw = _chunkJL3NEW3Ocjs.hexToBytes.call(void 0, u.raw_hex);
1226
+ w.writeBytes(raw);
1227
+ }
1228
+ });
1229
+ }
1230
+ }
1231
+ entries.sort((a, b) => a.type < b.type ? -1 : a.type > b.type ? 1 : 0);
1232
+ writer.writeVarInt(BigInt(entries.length));
1233
+ let prevType = 0n;
1234
+ for (const entry of entries) {
1235
+ writer.writeVarInt(entry.type - prevType);
1236
+ entry.encode(writer);
1237
+ prevType = entry.type;
1238
+ }
1239
+ }
1240
+ function decodeParams(reader) {
1241
+ const count = Number(reader.readVarInt());
1242
+ const result = {};
1243
+ const unknown = [];
1244
+ let prevType = 0n;
1245
+ for (let i = 0; i < count; i++) {
1246
+ const delta = reader.readVarInt();
1247
+ const paramType = prevType + delta;
1248
+ prevType = paramType;
1249
+ if (paramType === PARAM_OBJECT_DELIVERY_TIMEOUT) {
1250
+ result.object_delivery_timeout = reader.readVarInt();
1251
+ } else if (paramType === PARAM_AUTHORIZATION_TOKEN) {
1252
+ const length = Number(reader.readVarInt());
1253
+ const bytes = reader.readBytes(length);
1254
+ result.authorization_token = decodeAuthorizationToken(new (0, _chunkJL3NEW3Ocjs.BufferReader)(bytes));
1255
+ } else if (paramType === PARAM_RENDEZVOUS_TIMEOUT) {
1256
+ result.rendezvous_timeout = reader.readVarInt();
1257
+ } else if (paramType === PARAM_SUBGROUP_DELIVERY_TIMEOUT) {
1258
+ result.subgroup_delivery_timeout = reader.readVarInt();
1259
+ } else if (paramType === PARAM_EXPIRES) {
1260
+ result.expires = reader.readVarInt();
1261
+ } else if (paramType === PARAM_LARGEST_OBJECT) {
1262
+ const length = Number(reader.readVarInt());
1263
+ const startOff = reader.offset;
1264
+ const group = reader.readVarInt();
1265
+ const object = reader.readVarInt();
1266
+ const consumed = reader.offset - startOff;
1267
+ if (consumed < length) reader.readBytes(length - consumed);
1268
+ result.largest_object = { group, object };
1269
+ } else if (paramType === PARAM_FILL_TIMEOUT) {
1270
+ result.fill_timeout = reader.readVarInt();
1271
+ } else if (paramType === PARAM_FORWARD) {
1272
+ result.forward = BigInt(reader.readUint8());
1273
+ } else if (paramType === PARAM_SUBSCRIBER_PRIORITY) {
1274
+ result.subscriber_priority = BigInt(reader.readUint8());
1275
+ } else if (paramType === PARAM_SUBSCRIPTION_FILTER) {
1276
+ const length = Number(reader.readVarInt());
1277
+ const startOff = reader.offset;
1278
+ const filter_type = reader.readVarInt();
1279
+ const filter = { filter_type };
1280
+ if (filter_type === 3n || filter_type === 4n) {
1281
+ filter.start_group = reader.readVarInt();
1282
+ filter.start_object = reader.readVarInt();
1283
+ }
1284
+ if (filter_type === 4n) {
1285
+ filter.end_group = reader.readVarInt();
1286
+ }
1287
+ const consumed = reader.offset - startOff;
1288
+ if (consumed < length) reader.readBytes(length - consumed);
1289
+ result.subscription_filter = filter;
1290
+ } else if (paramType === PARAM_GROUP_ORDER) {
1291
+ result.group_order = BigInt(reader.readUint8());
1292
+ } else if (paramType === PARAM_NEW_GROUP_REQUEST) {
1293
+ result.new_group_request = reader.readVarInt();
1294
+ } else if (paramType === PARAM_TRACK_NAMESPACE_PREFIX) {
1295
+ const length = Number(reader.readVarInt());
1296
+ const bytes = reader.readBytes(length);
1297
+ result.track_namespace_prefix = decodeNamespaceTuple(new (0, _chunkJL3NEW3Ocjs.BufferReader)(bytes));
1298
+ } else {
1299
+ if (paramType % 2n === 0n) {
1300
+ const value = reader.readVarInt();
1301
+ const tmpWriter = new (0, _chunkJL3NEW3Ocjs.BufferWriter)(16);
1302
+ tmpWriter.writeVarInt(value);
1303
+ const raw = tmpWriter.finish();
1304
+ unknown.push({
1305
+ id: `0x${paramType.toString(16)}`,
1306
+ length: raw.byteLength,
1307
+ raw_hex: _chunkJL3NEW3Ocjs.bytesToHex.call(void 0, raw)
1308
+ });
1309
+ } else {
1310
+ const length = Number(reader.readVarInt());
1311
+ const bytes = reader.readBytes(length);
1312
+ unknown.push({
1313
+ id: `0x${paramType.toString(16)}`,
1314
+ length,
1315
+ raw_hex: _chunkJL3NEW3Ocjs.bytesToHex.call(void 0, bytes)
1316
+ });
1317
+ }
1318
+ }
1319
+ }
1320
+ if (unknown.length > 0) result.unknown = unknown;
1321
+ return result;
1322
+ }
1323
+ var TPROP_OBJECT_DELIVERY_TIMEOUT = 0x02n;
1324
+ var TPROP_MAX_CACHE_DURATION = 0x04n;
1325
+ var TPROP_SUBGROUP_DELIVERY_TIMEOUT = 0x06n;
1326
+ var TPROP_IMMUTABLE_PROPERTIES = 0x0bn;
1327
+ var TPROP_DEFAULT_PUBLISHER_PRIORITY = 0x0en;
1328
+ var TPROP_DEFAULT_PUBLISHER_GROUP_ORDER = 0x22n;
1329
+ var TPROP_DYNAMIC_GROUPS = 0x30n;
1330
+ function encodeTrackProperties(props, writer) {
1331
+ const entries = [];
1332
+ if (props.object_delivery_timeout !== void 0) {
1333
+ entries.push({
1334
+ type: TPROP_OBJECT_DELIVERY_TIMEOUT,
1335
+ encode: (w) => w.writeVarInt(props.object_delivery_timeout)
1336
+ });
1337
+ }
1338
+ if (props.max_cache_duration !== void 0) {
1339
+ entries.push({
1340
+ type: TPROP_MAX_CACHE_DURATION,
1341
+ encode: (w) => w.writeVarInt(props.max_cache_duration)
1342
+ });
1343
+ }
1344
+ if (props.subgroup_delivery_timeout !== void 0) {
1345
+ entries.push({
1346
+ type: TPROP_SUBGROUP_DELIVERY_TIMEOUT,
1347
+ encode: (w) => w.writeVarInt(props.subgroup_delivery_timeout)
1348
+ });
1349
+ }
1350
+ if (props.immutable_properties !== void 0) {
1351
+ entries.push({
1352
+ type: TPROP_IMMUTABLE_PROPERTIES,
1353
+ encode: (w) => {
1354
+ const raw = props.immutable_properties;
1355
+ w.writeVarInt(BigInt(raw.byteLength));
1356
+ w.writeBytes(raw);
1357
+ }
1358
+ });
1359
+ }
1360
+ if (props.default_publisher_priority !== void 0) {
1361
+ entries.push({
1362
+ type: TPROP_DEFAULT_PUBLISHER_PRIORITY,
1363
+ encode: (w) => w.writeVarInt(props.default_publisher_priority)
1364
+ });
1365
+ }
1366
+ if (props.default_publisher_group_order !== void 0) {
1367
+ entries.push({
1368
+ type: TPROP_DEFAULT_PUBLISHER_GROUP_ORDER,
1369
+ encode: (w) => w.writeVarInt(props.default_publisher_group_order)
1370
+ });
1371
+ }
1372
+ if (props.dynamic_groups !== void 0) {
1373
+ entries.push({
1374
+ type: TPROP_DYNAMIC_GROUPS,
1375
+ encode: (w) => w.writeVarInt(props.dynamic_groups)
1376
+ });
1377
+ }
1378
+ if (props.unknown) {
1379
+ for (const u of props.unknown) {
1380
+ const id = BigInt(u.id);
1381
+ entries.push({
1382
+ type: id,
1383
+ encode: (w) => {
1384
+ if (id % 2n === 0n) {
1385
+ const raw = _chunkJL3NEW3Ocjs.hexToBytes.call(void 0, u.raw_hex);
1386
+ const tmpReader = new (0, _chunkJL3NEW3Ocjs.BufferReader)(raw);
1387
+ w.writeVarInt(tmpReader.readVarInt());
1388
+ } else {
1389
+ const raw = _chunkJL3NEW3Ocjs.hexToBytes.call(void 0, u.raw_hex);
1390
+ w.writeVarInt(BigInt(raw.byteLength));
1391
+ w.writeBytes(raw);
1392
+ }
1393
+ }
1394
+ });
1395
+ }
1396
+ }
1397
+ entries.sort((a, b) => a.type < b.type ? -1 : a.type > b.type ? 1 : 0);
1398
+ let prevType = 0n;
1399
+ for (const entry of entries) {
1400
+ writer.writeVarInt(entry.type - prevType);
1401
+ entry.encode(writer);
1402
+ prevType = entry.type;
1403
+ }
1404
+ }
1405
+ function decodeTrackProperties(reader, payloadEnd) {
1406
+ const result = {};
1407
+ const unknown = [];
1408
+ let prevType = 0n;
1409
+ while (reader.offset < payloadEnd) {
1410
+ const delta = reader.readVarInt();
1411
+ const propType = prevType + delta;
1412
+ prevType = propType;
1413
+ if (propType % 2n === 0n) {
1414
+ const value = reader.readVarInt();
1415
+ if (propType === TPROP_OBJECT_DELIVERY_TIMEOUT) {
1416
+ result.object_delivery_timeout = value;
1417
+ } else if (propType === TPROP_MAX_CACHE_DURATION) {
1418
+ result.max_cache_duration = value;
1419
+ } else if (propType === TPROP_SUBGROUP_DELIVERY_TIMEOUT) {
1420
+ result.subgroup_delivery_timeout = value;
1421
+ } else if (propType === TPROP_DEFAULT_PUBLISHER_PRIORITY) {
1422
+ result.default_publisher_priority = value;
1423
+ } else if (propType === TPROP_DEFAULT_PUBLISHER_GROUP_ORDER) {
1424
+ result.default_publisher_group_order = value;
1425
+ } else if (propType === TPROP_DYNAMIC_GROUPS) {
1426
+ result.dynamic_groups = value;
1427
+ } else {
1428
+ const tmpWriter = new (0, _chunkJL3NEW3Ocjs.BufferWriter)(16);
1429
+ tmpWriter.writeVarInt(value);
1430
+ const raw = tmpWriter.finish();
1431
+ unknown.push({
1432
+ id: `0x${propType.toString(16)}`,
1433
+ length: raw.byteLength,
1434
+ raw_hex: _chunkJL3NEW3Ocjs.bytesToHex.call(void 0, raw)
1435
+ });
1436
+ }
1437
+ } else {
1438
+ const length = Number(reader.readVarInt());
1439
+ const bytes = reader.readBytes(length);
1440
+ if (propType === TPROP_IMMUTABLE_PROPERTIES) {
1441
+ result.immutable_properties = bytes;
1442
+ } else {
1443
+ unknown.push({
1444
+ id: `0x${propType.toString(16)}`,
1445
+ length,
1446
+ raw_hex: _chunkJL3NEW3Ocjs.bytesToHex.call(void 0, bytes)
1447
+ });
1448
+ }
1449
+ }
1450
+ }
1451
+ if (unknown.length > 0) result.unknown = unknown;
1452
+ return result;
1453
+ }
1454
+ function encodeRedirect(redirect, w) {
1455
+ const uri = textEncoder.encode(redirect.connect_uri);
1456
+ w.writeVarInt(BigInt(uri.byteLength));
1457
+ w.writeBytes(uri);
1458
+ w.writeTuple(redirect.track_namespace);
1459
+ w.writeString(redirect.track_name);
1460
+ }
1461
+ function decodeRedirect(r) {
1462
+ const uriLen = Number(r.readVarInt());
1463
+ const uriBytes = r.readBytes(uriLen);
1464
+ const connect_uri = textDecoder.decode(uriBytes);
1465
+ const track_namespace = r.readTuple();
1466
+ const track_name = r.readString();
1467
+ return { connect_uri, track_namespace, track_name };
1468
+ }
1469
+ function encodeSetupPayload(msg, w) {
1470
+ encodeSetupOptions(msg.options, w);
1471
+ }
1472
+ function encodeSubscribePayload(msg, w) {
1473
+ w.writeVarInt(msg.request_id);
1474
+ w.writeTuple(msg.track_namespace);
1475
+ w.writeString(msg.track_name);
1476
+ encodeParams(msg.parameters, w);
1477
+ }
1478
+ function encodeSubscribeOkPayload(msg, w) {
1479
+ w.writeVarInt(msg.track_alias);
1480
+ encodeParams(msg.parameters, w);
1481
+ encodeTrackProperties(msg.track_properties, w);
1482
+ }
1483
+ function encodeRequestUpdatePayload(msg, w) {
1484
+ w.writeVarInt(msg.request_id);
1485
+ encodeParams(msg.parameters, w);
1486
+ }
1487
+ function encodePublishPayload(msg, w) {
1488
+ w.writeVarInt(msg.request_id);
1489
+ w.writeTuple(msg.track_namespace);
1490
+ w.writeString(msg.track_name);
1491
+ w.writeVarInt(msg.track_alias);
1492
+ encodeParams(msg.parameters, w);
1493
+ encodeTrackProperties(msg.track_properties, w);
1494
+ }
1495
+ function encodePublishDonePayload(msg, w) {
1496
+ w.writeVarInt(msg.status_code);
1497
+ w.writeVarInt(msg.stream_count);
1498
+ w.writeString(msg.reason_phrase);
1499
+ }
1500
+ function encodePublishNamespacePayload(msg, w) {
1501
+ w.writeVarInt(msg.request_id);
1502
+ w.writeTuple(msg.track_namespace);
1503
+ encodeParams(msg.parameters, w);
1504
+ }
1505
+ function encodeNamespacePayload(msg, w) {
1506
+ w.writeTuple(msg.namespace_suffix);
1507
+ }
1508
+ function encodeNamespaceDonePayload(msg, w) {
1509
+ w.writeTuple(msg.namespace_suffix);
1510
+ }
1511
+ function encodeSubscribeNamespacePayload(msg, w) {
1512
+ w.writeVarInt(msg.request_id);
1513
+ w.writeTuple(msg.namespace_prefix);
1514
+ encodeParams(msg.parameters, w);
1515
+ }
1516
+ function encodeSubscribeTracksPayload(msg, w) {
1517
+ w.writeVarInt(msg.request_id);
1518
+ w.writeTuple(msg.namespace_prefix);
1519
+ encodeParams(msg.parameters, w);
1520
+ }
1521
+ function encodePublishBlockedPayload(msg, w) {
1522
+ w.writeTuple(msg.namespace_suffix);
1523
+ w.writeString(msg.track_name);
1524
+ }
1525
+ function encodeFetchPayload(msg, w) {
1526
+ w.writeVarInt(msg.request_id);
1527
+ w.writeVarInt(msg.fetch_type);
1528
+ const ft = Number(msg.fetch_type);
1529
+ if (ft === 1 && msg.standalone) {
1530
+ w.writeTuple(msg.standalone.track_namespace);
1531
+ w.writeString(msg.standalone.track_name);
1532
+ w.writeVarInt(msg.standalone.start_group);
1533
+ w.writeVarInt(msg.standalone.start_object);
1534
+ w.writeVarInt(msg.standalone.end_group);
1535
+ w.writeVarInt(msg.standalone.end_object);
1536
+ } else if ((ft === 2 || ft === 3) && msg.joining) {
1537
+ w.writeVarInt(msg.joining.joining_request_id);
1538
+ w.writeVarInt(msg.joining.joining_start);
1539
+ }
1540
+ encodeParams(msg.parameters, w);
1541
+ }
1542
+ function encodeFetchOkPayload(msg, w) {
1543
+ w.writeUint8(msg.end_of_track);
1544
+ w.writeVarInt(msg.end_group);
1545
+ w.writeVarInt(msg.end_object);
1546
+ encodeParams(msg.parameters, w);
1547
+ encodeTrackProperties(msg.track_properties, w);
1548
+ }
1549
+ function encodeTrackStatusPayload(msg, w) {
1550
+ w.writeVarInt(msg.request_id);
1551
+ w.writeTuple(msg.track_namespace);
1552
+ w.writeString(msg.track_name);
1553
+ encodeParams(msg.parameters, w);
1554
+ }
1555
+ function encodeRequestOkPayload(msg, w) {
1556
+ encodeParams(msg.parameters, w);
1557
+ encodeTrackProperties(msg.track_properties, w);
1558
+ }
1559
+ function encodeRequestErrorPayload(msg, w) {
1560
+ w.writeVarInt(msg.error_code);
1561
+ w.writeVarInt(msg.retry_interval);
1562
+ w.writeString(msg.reason_phrase);
1563
+ if (msg.error_code === REQUEST_ERROR_REDIRECT && msg.redirect) {
1564
+ encodeRedirect(msg.redirect, w);
1565
+ }
1566
+ }
1567
+ function encodeGoAwayPayload(msg, w) {
1568
+ w.writeString(msg.new_session_uri);
1569
+ w.writeVarInt(msg.timeout);
1570
+ if (msg.request_id !== void 0) {
1571
+ w.writeVarInt(msg.request_id);
1572
+ }
1573
+ }
1574
+ function decodeSetupPayload(r, payloadEnd) {
1575
+ const options = decodeSetupOptions(r, payloadEnd);
1576
+ return { type: "setup", options };
1577
+ }
1578
+ function decodeSubscribePayload(r) {
1579
+ const request_id = r.readVarInt();
1580
+ const track_namespace = r.readTuple();
1581
+ const track_name = r.readString();
1582
+ const parameters = decodeParams(r);
1583
+ return {
1584
+ type: "subscribe",
1585
+ request_id,
1586
+ track_namespace,
1587
+ track_name,
1588
+ parameters
1589
+ };
1590
+ }
1591
+ function decodeSubscribeOkPayload(r, payloadEnd) {
1592
+ const track_alias = r.readVarInt();
1593
+ const parameters = decodeParams(r);
1594
+ const track_properties = decodeTrackProperties(r, payloadEnd);
1595
+ return { type: "subscribe_ok", track_alias, parameters, track_properties };
1596
+ }
1597
+ function decodeRequestUpdatePayload(r) {
1598
+ const request_id = r.readVarInt();
1599
+ const parameters = decodeParams(r);
1600
+ return {
1601
+ type: "request_update",
1602
+ request_id,
1603
+ parameters
1604
+ };
1605
+ }
1606
+ function decodePublishPayload(r, payloadEnd) {
1607
+ const request_id = r.readVarInt();
1608
+ const track_namespace = r.readTuple();
1609
+ const track_name = r.readString();
1610
+ const track_alias = r.readVarInt();
1611
+ const parameters = decodeParams(r);
1612
+ const track_properties = decodeTrackProperties(r, payloadEnd);
1613
+ return {
1614
+ type: "publish",
1615
+ request_id,
1616
+ track_namespace,
1617
+ track_name,
1618
+ track_alias,
1619
+ parameters,
1620
+ track_properties
1621
+ };
1622
+ }
1623
+ function decodePublishDonePayload(r) {
1624
+ const status_code = r.readVarInt();
1625
+ const stream_count = r.readVarInt();
1626
+ const reason_phrase = r.readString();
1627
+ return { type: "publish_done", status_code, stream_count, reason_phrase };
1628
+ }
1629
+ function decodePublishNamespacePayload(r) {
1630
+ const request_id = r.readVarInt();
1631
+ const track_namespace = r.readTuple();
1632
+ const parameters = decodeParams(r);
1633
+ return {
1634
+ type: "publish_namespace",
1635
+ request_id,
1636
+ track_namespace,
1637
+ parameters
1638
+ };
1639
+ }
1640
+ function decodeNamespacePayload(r) {
1641
+ const namespace_suffix = r.readTuple();
1642
+ return { type: "namespace", namespace_suffix };
1643
+ }
1644
+ function decodeNamespaceDonePayload(r) {
1645
+ const namespace_suffix = r.readTuple();
1646
+ return { type: "namespace_done", namespace_suffix };
1647
+ }
1648
+ function decodeSubscribeNamespacePayload(r) {
1649
+ const request_id = r.readVarInt();
1650
+ const namespace_prefix = r.readTuple();
1651
+ const parameters = decodeParams(r);
1652
+ return {
1653
+ type: "subscribe_namespace",
1654
+ request_id,
1655
+ namespace_prefix,
1656
+ parameters
1657
+ };
1658
+ }
1659
+ function decodeSubscribeTracksPayload(r) {
1660
+ const request_id = r.readVarInt();
1661
+ const namespace_prefix = r.readTuple();
1662
+ const parameters = decodeParams(r);
1663
+ return {
1664
+ type: "subscribe_tracks",
1665
+ request_id,
1666
+ namespace_prefix,
1667
+ parameters
1668
+ };
1669
+ }
1670
+ function decodePublishBlockedPayload(r) {
1671
+ const namespace_suffix = r.readTuple();
1672
+ const track_name = r.readString();
1673
+ return { type: "publish_blocked", namespace_suffix, track_name };
1674
+ }
1675
+ function decodeFetchPayload(r) {
1676
+ const request_id = r.readVarInt();
1677
+ const fetch_type = r.readVarInt();
1678
+ const ft = Number(fetch_type);
1679
+ if (ft < 1 || ft > 3) {
1680
+ throw new (0, _chunkJL3NEW3Ocjs.DecodeError)("CONSTRAINT_VIOLATION", `Invalid fetch_type: ${ft}`, r.offset);
1681
+ }
1682
+ let standalone;
1683
+ let joining;
1684
+ if (ft === 1) {
1685
+ const track_namespace = r.readTuple();
1686
+ const track_name = r.readString();
1687
+ const start_group = r.readVarInt();
1688
+ const start_object = r.readVarInt();
1689
+ const end_group = r.readVarInt();
1690
+ const end_object = r.readVarInt();
1691
+ standalone = {
1692
+ track_namespace,
1693
+ track_name,
1694
+ start_group,
1695
+ start_object,
1696
+ end_group,
1697
+ end_object
1698
+ };
1699
+ } else {
1700
+ const joining_request_id = r.readVarInt();
1701
+ const joining_start = r.readVarInt();
1702
+ joining = { joining_request_id, joining_start };
1703
+ }
1704
+ const parameters = decodeParams(r);
1705
+ return {
1706
+ type: "fetch",
1707
+ request_id,
1708
+ fetch_type,
1709
+ standalone,
1710
+ joining,
1711
+ parameters
1712
+ };
1713
+ }
1714
+ function decodeFetchOkPayload(r, payloadEnd) {
1715
+ const end_of_track = r.readUint8();
1716
+ const end_group = r.readVarInt();
1717
+ const end_object = r.readVarInt();
1718
+ const parameters = decodeParams(r);
1719
+ const track_properties = decodeTrackProperties(r, payloadEnd);
1720
+ return {
1721
+ type: "fetch_ok",
1722
+ end_of_track,
1723
+ end_group,
1724
+ end_object,
1725
+ parameters,
1726
+ track_properties
1727
+ };
1728
+ }
1729
+ function decodeTrackStatusPayload(r) {
1730
+ const request_id = r.readVarInt();
1731
+ const track_namespace = r.readTuple();
1732
+ const track_name = r.readString();
1733
+ const parameters = decodeParams(r);
1734
+ return {
1735
+ type: "track_status",
1736
+ request_id,
1737
+ track_namespace,
1738
+ track_name,
1739
+ parameters
1740
+ };
1741
+ }
1742
+ function decodeRequestOkPayload(r, payloadEnd) {
1743
+ const parameters = decodeParams(r);
1744
+ const track_properties = decodeTrackProperties(r, payloadEnd);
1745
+ return { type: "request_ok", parameters, track_properties };
1746
+ }
1747
+ function decodeRequestErrorPayload(r, payloadEnd) {
1748
+ const error_code = r.readVarInt();
1749
+ const retry_interval = r.readVarInt();
1750
+ const reason_phrase = r.readString();
1751
+ let redirect;
1752
+ if (error_code === REQUEST_ERROR_REDIRECT && r.offset < payloadEnd) {
1753
+ redirect = decodeRedirect(r);
1754
+ }
1755
+ if (redirect !== void 0) {
1756
+ return { type: "request_error", error_code, retry_interval, reason_phrase, redirect };
1757
+ }
1758
+ return { type: "request_error", error_code, retry_interval, reason_phrase };
1759
+ }
1760
+ function decodeGoAwayPayload(r, payloadEnd) {
1761
+ const new_session_uri = r.readString();
1762
+ const timeout = r.readVarInt();
1763
+ let request_id;
1764
+ if (r.offset < payloadEnd) {
1765
+ request_id = r.readVarInt();
1766
+ }
1767
+ if (request_id !== void 0) {
1768
+ return { type: "goaway", new_session_uri, timeout, request_id };
1769
+ }
1770
+ return { type: "goaway", new_session_uri, timeout };
1771
+ }
1772
+ function encodeMessage(message) {
1773
+ const typeId = MESSAGE_ID_MAP.get(message.type);
1774
+ if (typeId === void 0) {
1775
+ throw new Error(`Unknown message type: ${message.type}`);
1776
+ }
1777
+ const payloadWriter = new (0, _chunkJL3NEW3Ocjs.BufferWriter)();
1778
+ encodePayload(message, payloadWriter);
1779
+ const payload = payloadWriter.finishView();
1780
+ if (payload.byteLength > 65535) {
1781
+ throw new Error(`Payload too large for 16-bit length: ${payload.byteLength}`);
1782
+ }
1783
+ const writer = new (0, _chunkJL3NEW3Ocjs.BufferWriter)(payload.byteLength + 16);
1784
+ writer.writeVarInt(typeId);
1785
+ writer.writeUint8(payload.byteLength >> 8 & 255);
1786
+ writer.writeUint8(payload.byteLength & 255);
1787
+ writer.writeBytes(payload);
1788
+ return writer.finish();
1789
+ }
1790
+ function encodePayload(msg, w) {
1791
+ switch (msg.type) {
1792
+ case "setup":
1793
+ return encodeSetupPayload(msg, w);
1794
+ case "subscribe":
1795
+ return encodeSubscribePayload(msg, w);
1796
+ case "subscribe_ok":
1797
+ return encodeSubscribeOkPayload(msg, w);
1798
+ case "request_update":
1799
+ return encodeRequestUpdatePayload(msg, w);
1800
+ case "publish":
1801
+ return encodePublishPayload(msg, w);
1802
+ case "publish_done":
1803
+ return encodePublishDonePayload(msg, w);
1804
+ case "publish_namespace":
1805
+ return encodePublishNamespacePayload(msg, w);
1806
+ case "namespace":
1807
+ return encodeNamespacePayload(msg, w);
1808
+ case "namespace_done":
1809
+ return encodeNamespaceDonePayload(msg, w);
1810
+ case "subscribe_namespace":
1811
+ return encodeSubscribeNamespacePayload(msg, w);
1812
+ case "subscribe_tracks":
1813
+ return encodeSubscribeTracksPayload(msg, w);
1814
+ case "publish_blocked":
1815
+ return encodePublishBlockedPayload(msg, w);
1816
+ case "fetch":
1817
+ return encodeFetchPayload(msg, w);
1818
+ case "fetch_ok":
1819
+ return encodeFetchOkPayload(msg, w);
1820
+ case "track_status":
1821
+ return encodeTrackStatusPayload(msg, w);
1822
+ case "request_ok":
1823
+ return encodeRequestOkPayload(msg, w);
1824
+ case "request_error":
1825
+ return encodeRequestErrorPayload(msg, w);
1826
+ case "goaway":
1827
+ return encodeGoAwayPayload(msg, w);
1828
+ default: {
1829
+ const _exhaustive = msg;
1830
+ throw new Error(`Unhandled message type: ${_exhaustive.type}`);
1831
+ }
1832
+ }
1833
+ }
1834
+ function decodeMessage(bytes) {
1835
+ try {
1836
+ const reader = new (0, _chunkJL3NEW3Ocjs.BufferReader)(bytes);
1837
+ const typeId = reader.readVarInt();
1838
+ const lenHi = reader.readUint8();
1839
+ const lenLo = reader.readUint8();
1840
+ const payloadLength = lenHi << 8 | lenLo;
1841
+ const payloadBytes = reader.readBytes(payloadLength);
1842
+ const payloadReader = new (0, _chunkJL3NEW3Ocjs.BufferReader)(payloadBytes);
1843
+ let message;
1844
+ if (typeId === MSG_SETUP) {
1845
+ message = decodeSetupPayload(payloadReader, payloadLength);
1846
+ } else if (typeId === MSG_SUBSCRIBE) {
1847
+ message = decodeSubscribePayload(payloadReader);
1848
+ } else if (typeId === MSG_SUBSCRIBE_OK) {
1849
+ message = decodeSubscribeOkPayload(payloadReader, payloadLength);
1850
+ } else if (typeId === MSG_REQUEST_UPDATE) {
1851
+ message = decodeRequestUpdatePayload(payloadReader);
1852
+ } else if (typeId === MSG_PUBLISH) {
1853
+ message = decodePublishPayload(payloadReader, payloadLength);
1854
+ } else if (typeId === MSG_PUBLISH_DONE) {
1855
+ message = decodePublishDonePayload(payloadReader);
1856
+ } else if (typeId === MSG_PUBLISH_NAMESPACE) {
1857
+ message = decodePublishNamespacePayload(payloadReader);
1858
+ } else if (typeId === MSG_NAMESPACE) {
1859
+ message = decodeNamespacePayload(payloadReader);
1860
+ } else if (typeId === MSG_NAMESPACE_DONE) {
1861
+ message = decodeNamespaceDonePayload(payloadReader);
1862
+ } else if (typeId === MSG_SUBSCRIBE_NAMESPACE) {
1863
+ message = decodeSubscribeNamespacePayload(payloadReader);
1864
+ } else if (typeId === MSG_SUBSCRIBE_TRACKS) {
1865
+ message = decodeSubscribeTracksPayload(payloadReader);
1866
+ } else if (typeId === MSG_PUBLISH_BLOCKED) {
1867
+ message = decodePublishBlockedPayload(payloadReader);
1868
+ } else if (typeId === MSG_FETCH) {
1869
+ message = decodeFetchPayload(payloadReader);
1870
+ } else if (typeId === MSG_FETCH_OK) {
1871
+ message = decodeFetchOkPayload(payloadReader, payloadLength);
1872
+ } else if (typeId === MSG_TRACK_STATUS) {
1873
+ message = decodeTrackStatusPayload(payloadReader);
1874
+ } else if (typeId === MSG_REQUEST_OK) {
1875
+ message = decodeRequestOkPayload(payloadReader, payloadLength);
1876
+ } else if (typeId === MSG_REQUEST_ERROR) {
1877
+ message = decodeRequestErrorPayload(payloadReader, payloadLength);
1878
+ } else if (typeId === MSG_GOAWAY) {
1879
+ message = decodeGoAwayPayload(payloadReader, payloadLength);
1880
+ } else {
1881
+ return {
1882
+ ok: false,
1883
+ error: new (0, _chunkJL3NEW3Ocjs.DecodeError)(
1884
+ "UNKNOWN_MESSAGE_TYPE",
1885
+ `Unknown message type ID: 0x${typeId.toString(16)}`,
1886
+ 0
1887
+ )
1888
+ };
1889
+ }
1890
+ return { ok: true, value: message, bytesRead: reader.offset };
1891
+ } catch (e) {
1892
+ if (e instanceof _chunkJL3NEW3Ocjs.DecodeError) {
1893
+ return { ok: false, error: e };
1894
+ }
1895
+ throw e;
1896
+ }
1897
+ }
1898
+ function createStreamDecoder() {
1899
+ let buffer = new Uint8Array(0);
1900
+ let offset = 0;
1901
+ return new TransformStream({
1902
+ transform(chunk, controller) {
1903
+ if (offset > 0) {
1904
+ buffer = buffer.subarray(offset);
1905
+ offset = 0;
1906
+ }
1907
+ const newBuffer = new Uint8Array(buffer.length + chunk.length);
1908
+ newBuffer.set(buffer, 0);
1909
+ newBuffer.set(chunk, buffer.length);
1910
+ buffer = newBuffer;
1911
+ while (offset < buffer.length) {
1912
+ const result = decodeMessage(buffer.subarray(offset));
1913
+ if (!result.ok) {
1914
+ if (result.error.code === "UNEXPECTED_END") {
1915
+ break;
1916
+ }
1917
+ controller.error(result.error);
1918
+ return;
1919
+ }
1920
+ controller.enqueue(result.value);
1921
+ offset += result.bytesRead;
1922
+ }
1923
+ },
1924
+ flush(controller) {
1925
+ if (offset < buffer.length) {
1926
+ controller.error(
1927
+ new (0, _chunkJL3NEW3Ocjs.DecodeError)("UNEXPECTED_END", "Stream ended with incomplete message data", 0)
1928
+ );
1929
+ }
1930
+ }
1931
+ });
1932
+ }
1933
+ function createDraft18Codec() {
1934
+ return {
1935
+ draft: "18",
1936
+ encodeMessage,
1937
+ decodeMessage,
1938
+ encodeSubgroupStream,
1939
+ encodeDatagram,
1940
+ encodeFetchStream,
1941
+ decodeSubgroupStream,
1942
+ decodeDatagram,
1943
+ decodeFetchStream,
1944
+ decodeDataStream,
1945
+ createStreamDecoder,
1946
+ createSubgroupStreamDecoder,
1947
+ createFetchStreamDecoder,
1948
+ createDataStreamDecoder
1949
+ };
1950
+ }
1951
+
1952
+
1953
+
1954
+
1955
+
1956
+
1957
+
1958
+
1959
+
1960
+
1961
+
1962
+
1963
+
1964
+
1965
+
1966
+
1967
+
1968
+
1969
+
1970
+
1971
+
1972
+
1973
+
1974
+
1975
+
1976
+
1977
+
1978
+
1979
+
1980
+
1981
+
1982
+
1983
+
1984
+
1985
+
1986
+
1987
+
1988
+
1989
+
1990
+
1991
+
1992
+
1993
+ exports.MSG_REQUEST_UPDATE = MSG_REQUEST_UPDATE; exports.MSG_SUBSCRIBE = MSG_SUBSCRIBE; exports.MSG_SUBSCRIBE_OK = MSG_SUBSCRIBE_OK; exports.MSG_REQUEST_ERROR = MSG_REQUEST_ERROR; exports.MSG_PUBLISH_NAMESPACE = MSG_PUBLISH_NAMESPACE; exports.MSG_REQUEST_OK = MSG_REQUEST_OK; exports.MSG_NAMESPACE = MSG_NAMESPACE; exports.MSG_PUBLISH_DONE = MSG_PUBLISH_DONE; exports.MSG_TRACK_STATUS = MSG_TRACK_STATUS; exports.MSG_NAMESPACE_DONE = MSG_NAMESPACE_DONE; exports.MSG_PUBLISH_BLOCKED = MSG_PUBLISH_BLOCKED; exports.MSG_GOAWAY = MSG_GOAWAY; exports.MSG_FETCH = MSG_FETCH; exports.MSG_FETCH_OK = MSG_FETCH_OK; exports.MSG_PUBLISH = MSG_PUBLISH; exports.MSG_PUBLISH_OK = MSG_PUBLISH_OK; exports.MSG_SUBSCRIBE_NAMESPACE = MSG_SUBSCRIBE_NAMESPACE; exports.MSG_SUBSCRIBE_TRACKS = MSG_SUBSCRIBE_TRACKS; exports.MSG_SETUP = MSG_SETUP; exports.SETUP_OPT_PATH = SETUP_OPT_PATH; exports.SETUP_OPT_AUTHORIZATION_TOKEN = SETUP_OPT_AUTHORIZATION_TOKEN; exports.SETUP_OPT_MAX_AUTH_TOKEN_CACHE_SIZE = SETUP_OPT_MAX_AUTH_TOKEN_CACHE_SIZE; exports.SETUP_OPT_AUTHORITY = SETUP_OPT_AUTHORITY; exports.SETUP_OPT_MOQT_IMPLEMENTATION = SETUP_OPT_MOQT_IMPLEMENTATION; exports.MESSAGE_TYPE_MAP = MESSAGE_TYPE_MAP; exports.MESSAGE_ID_MAP = MESSAGE_ID_MAP; exports.encodeSubgroupStream = encodeSubgroupStream; exports.encodeDatagram = encodeDatagram; exports.encodeFetchStream = encodeFetchStream; exports.decodeSubgroupStream = decodeSubgroupStream; exports.decodeDatagram = decodeDatagram; exports.decodeFetchStream = decodeFetchStream; exports.decodeDataStream = decodeDataStream; exports.createSubgroupStreamDecoder = createSubgroupStreamDecoder; exports.createFetchStreamDecoder = createFetchStreamDecoder; exports.createDataStreamDecoder = createDataStreamDecoder; exports.encodeMessage = encodeMessage; exports.decodeMessage = decodeMessage; exports.createStreamDecoder = createStreamDecoder; exports.createDraft18Codec = createDraft18Codec;