@moqtap/codec 0.10.0 → 0.12.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.
- package/CHANGELOG.md +175 -0
- package/README.md +3 -2
- package/dist/auth-redaction-B9JJOlIY.d.cts +100 -0
- package/dist/auth-redaction-B9JJOlIY.d.ts +100 -0
- package/dist/{chunk-RYKQXBG6.cjs → chunk-27K5BUAG.cjs} +481 -517
- package/dist/{chunk-WCPENYNE.js → chunk-3RNQMGKA.js} +359 -390
- package/dist/{chunk-TSUZ6GJV.js → chunk-5AWIXOLB.js} +438 -469
- package/dist/{chunk-4XLYCT5Q.cjs → chunk-5IMHJIAZ.cjs} +52 -2
- package/dist/{chunk-KTNERCTZ.cjs → chunk-5JGZCKJO.cjs} +488 -518
- package/dist/{chunk-WCTMPDUX.cjs → chunk-73K4OSAN.cjs} +401 -432
- package/dist/{chunk-N2V7Z37J.js → chunk-7VQKRGRD.js} +19 -3
- package/dist/{chunk-BIBMDTU5.cjs → chunk-A3UCQOIB.cjs} +486 -517
- package/dist/{chunk-K2B3OVFK.js → chunk-A7PDMVXM.js} +24 -3
- package/dist/{chunk-VZHL2U2N.cjs → chunk-A7VQO6YC.cjs} +54 -38
- package/dist/{chunk-AQ445VV7.cjs → chunk-ACQHZLRZ.cjs} +66 -46
- package/dist/{chunk-L5DRACXS.js → chunk-BBICOMW6.js} +25 -3
- package/dist/{chunk-T4VWPKDG.cjs → chunk-BNIUVOCJ.cjs} +529 -599
- package/dist/{chunk-UKKDOOUO.cjs → chunk-CNC6ANS4.cjs} +58 -37
- package/dist/{chunk-OZRK73NQ.js → chunk-FDLQSWHK.js} +433 -469
- package/dist/{chunk-IJAF6PAY.js → chunk-FFNOE4UR.js} +19 -3
- package/dist/{chunk-CZNW3R5E.cjs → chunk-GMENT63T.cjs} +54 -38
- package/dist/{chunk-XCRCAUGI.cjs → chunk-HM7BLRVP.cjs} +291 -297
- package/dist/{chunk-XHAP2YST.js → chunk-HZONHFNO.js} +19 -3
- package/dist/{chunk-SDJTSMOW.cjs → chunk-ILYABWDK.cjs} +60 -38
- package/dist/{chunk-IDV2JYJ6.cjs → chunk-KRSFTZVO.cjs} +56 -40
- package/dist/{chunk-RIIA4ALQ.cjs → chunk-KSPH6KMH.cjs} +54 -38
- package/dist/{chunk-OUNN4IQB.cjs → chunk-KTY4LAUV.cjs} +482 -497
- package/dist/chunk-OBATJBNL.cjs +868 -0
- package/dist/{chunk-RZTLQAKF.js → chunk-OJNLJT5D.js} +0 -1
- package/dist/{chunk-FT3HDNIB.js → chunk-PJK2ZS3I.js} +467 -537
- package/dist/{chunk-G53WYUXL.js → chunk-PSMZKHOC.js} +441 -456
- package/dist/{chunk-7RE6KSIY.cjs → chunk-Q5JQGHWY.cjs} +0 -1
- package/dist/{chunk-BX2N7TZM.js → chunk-SQTUQY5E.js} +31 -11
- package/dist/chunk-T2TCLZZV.js +2304 -0
- package/dist/chunk-WB65UG7G.cjs +2304 -0
- package/dist/{chunk-CF5DDD3Q.js → chunk-WCRLAKDW.js} +239 -245
- package/dist/{chunk-KYVTM5VI.js → chunk-WL2YUEXH.js} +19 -3
- package/dist/chunk-XPCBPACE.js +868 -0
- package/dist/{chunk-KGDVC4O6.js → chunk-YCNIVZS7.js} +439 -469
- package/dist/{chunk-KLPWJU6W.js → chunk-YRZQVNZO.js} +50 -0
- package/dist/{codec-DOmAmFkI.d.ts → codec-B-oUU-cp.d.ts} +21 -2
- package/dist/{codec-DNmiG2e0.d.cts → codec-B3RpCI9k.d.cts} +21 -2
- package/dist/codec-B5pcOS3m.d.cts +38 -0
- package/dist/{codec-BNy5syCU.d.ts → codec-BLjxwK2f.d.ts} +21 -2
- package/dist/{codec-alVA27Uc.d.ts → codec-BV3CL_3m.d.ts} +21 -2
- package/dist/{codec-Czejcmxr.d.cts → codec-BYCDWgED.d.ts} +22 -3
- package/dist/{codec-DaXjRrOV.d.ts → codec-Bwqq7ZQT.d.ts} +22 -3
- package/dist/{codec-CFWu5KVT.d.cts → codec-BzWxOFby.d.cts} +22 -3
- package/dist/codec-C-nJhNNl.d.ts +38 -0
- package/dist/{codec-EvybrBuY.d.cts → codec-C11VEPbQ.d.cts} +21 -2
- package/dist/codec-C9U0Vzy9.d.cts +68 -0
- package/dist/{codec-Cm3D261p.d.ts → codec-CCx22jnd.d.ts} +21 -2
- package/dist/{codec-CwZ6OCPP.d.ts → codec-CP3zkfTv.d.ts} +22 -3
- package/dist/{codec-BxQTybUX.d.cts → codec-CRmOLDpt.d.ts} +22 -3
- package/dist/{codec-DzkdW4kO.d.cts → codec-CUu56DDU.d.cts} +21 -2
- package/dist/codec-Cb8mUre3.d.ts +68 -0
- package/dist/{codec-f7vxeVIS.d.cts → codec-CemqAQdR.d.cts} +22 -3
- package/dist/{codec-gl4_QEva.d.ts → codec-CxMvsVMS.d.ts} +21 -2
- package/dist/{codec-Bd60SGKH.d.cts → codec-DIgMVTi4.d.cts} +21 -2
- package/dist/{codec--CVeqGQv.d.ts → codec-DYzozF68.d.ts} +21 -2
- package/dist/{codec-CWnf8mn_.d.cts → codec-D_O9zxax.d.ts} +22 -3
- package/dist/{codec-08ZOr5wI.d.ts → codec-Ddc-QxV6.d.cts} +22 -3
- package/dist/{codec-CBdOIfMY.d.ts → codec-DoojMl2z.d.cts} +22 -3
- package/dist/{codec-BrTi4K7r.d.cts → codec-DqdjiOQF.d.ts} +22 -3
- package/dist/{codec-CXCjya_G.d.cts → codec-Dstemwrq.d.cts} +21 -2
- package/dist/{codec-Dl_QIXMz.d.ts → codec-Dt6nuejp.d.ts} +21 -2
- package/dist/{codec-Bux_Q40X.d.ts → codec-DuYhd8fP.d.cts} +22 -3
- package/dist/{codec-Cfo_z5ET.d.cts → codec-DwNOFgPU.d.cts} +21 -2
- package/dist/{codec-guzqtfMk.d.cts → codec-l01BpNhF.d.cts} +21 -2
- package/dist/{codec-C3mdsGx3.d.ts → codec-psN2vB6I.d.cts} +22 -3
- package/dist/draft07-session.d.cts +3 -3
- package/dist/draft07-session.d.ts +3 -3
- package/dist/draft07.cjs +48 -4
- package/dist/draft07.d.cts +44 -4
- package/dist/draft07.d.ts +44 -4
- package/dist/draft07.js +49 -5
- package/dist/draft08-session.d.cts +3 -3
- package/dist/draft08-session.d.ts +3 -3
- package/dist/draft08.cjs +76 -3
- package/dist/draft08.d.cts +73 -5
- package/dist/draft08.d.ts +73 -5
- package/dist/draft08.js +77 -4
- package/dist/draft09-session.d.cts +3 -3
- package/dist/draft09-session.d.ts +3 -3
- package/dist/draft09.cjs +76 -3
- package/dist/draft09.d.cts +73 -5
- package/dist/draft09.d.ts +73 -5
- package/dist/draft09.js +77 -4
- package/dist/draft10-session.d.cts +3 -3
- package/dist/draft10-session.d.ts +3 -3
- package/dist/draft10.cjs +76 -3
- package/dist/draft10.d.cts +73 -5
- package/dist/draft10.d.ts +73 -5
- package/dist/draft10.js +77 -4
- package/dist/draft11-session.d.cts +3 -3
- package/dist/draft11-session.d.ts +3 -3
- package/dist/draft11.cjs +104 -3
- package/dist/draft11.d.cts +101 -5
- package/dist/draft11.d.ts +101 -5
- package/dist/draft11.js +105 -4
- package/dist/draft12-session.d.cts +3 -3
- package/dist/draft12-session.d.ts +3 -3
- package/dist/draft12.cjs +113 -3
- package/dist/draft12.d.cts +110 -5
- package/dist/draft12.d.ts +110 -5
- package/dist/draft12.js +114 -4
- package/dist/draft13-session.d.cts +3 -3
- package/dist/draft13-session.d.ts +3 -3
- package/dist/draft13.cjs +105 -3
- package/dist/draft13.d.cts +102 -5
- package/dist/draft13.d.ts +102 -5
- package/dist/draft13.js +106 -4
- package/dist/draft14-session.d.cts +3 -3
- package/dist/draft14-session.d.ts +3 -3
- package/dist/draft14.cjs +107 -3
- package/dist/draft14.d.cts +104 -31
- package/dist/draft14.d.ts +104 -31
- package/dist/draft14.js +108 -4
- package/dist/draft15-session.d.cts +4 -4
- package/dist/draft15-session.d.ts +4 -4
- package/dist/draft15.cjs +69 -3
- package/dist/draft15.d.cts +68 -25
- package/dist/draft15.d.ts +68 -25
- package/dist/draft15.js +70 -4
- package/dist/draft16-session.cjs +2 -2
- package/dist/draft16-session.d.cts +4 -4
- package/dist/draft16-session.d.ts +4 -4
- package/dist/draft16-session.js +1 -1
- package/dist/draft16.cjs +76 -8
- package/dist/draft16.d.cts +70 -16
- package/dist/draft16.d.ts +70 -16
- package/dist/draft16.js +73 -5
- package/dist/draft17-session.d.cts +4 -4
- package/dist/draft17-session.d.ts +4 -4
- package/dist/draft17.cjs +77 -3
- package/dist/draft17.d.cts +75 -6
- package/dist/draft17.d.ts +75 -6
- package/dist/draft17.js +78 -4
- package/dist/draft18-session.d.cts +4 -4
- package/dist/draft18-session.d.ts +4 -4
- package/dist/draft18.cjs +8 -3
- package/dist/draft18.d.cts +6 -5
- package/dist/draft18.d.ts +6 -5
- package/dist/draft18.js +9 -4
- package/dist/draft19-session.d.cts +4 -4
- package/dist/draft19-session.d.ts +4 -4
- package/dist/draft19.cjs +11 -4
- package/dist/draft19.d.cts +6 -5
- package/dist/draft19.d.ts +6 -5
- package/dist/draft19.js +12 -5
- package/dist/draft20-session.d.cts +4 -4
- package/dist/draft20-session.d.ts +4 -4
- package/dist/draft20.cjs +8 -3
- package/dist/draft20.d.cts +6 -5
- package/dist/draft20.d.ts +6 -5
- package/dist/draft20.js +9 -4
- package/dist/draft21-session.cjs +8 -0
- package/dist/draft21-session.d.cts +195 -0
- package/dist/draft21-session.d.ts +195 -0
- package/dist/draft21-session.js +8 -0
- package/dist/draft21.cjs +222 -0
- package/dist/draft21.d.cts +176 -0
- package/dist/draft21.d.ts +176 -0
- package/dist/draft21.js +222 -0
- package/dist/index.cjs +37 -31
- package/dist/index.d.cts +29 -23
- package/dist/index.d.ts +29 -23
- package/dist/index.js +22 -16
- package/dist/{session-types-Dn7b3RZM.d.ts → session-types-Cxx7W8zZ.d.ts} +1 -1
- package/dist/{session-types-B9idsih-.d.cts → session-types-DZkI_qFG.d.cts} +1 -1
- package/dist/session.cjs +7 -3
- package/dist/session.d.cts +11 -9
- package/dist/session.d.ts +11 -9
- package/dist/session.js +6 -2
- package/dist/{types-DG5_iKuv.d.cts → types-2NisMA8_.d.cts} +1 -1
- package/dist/{types-DG5_iKuv.d.ts → types-2NisMA8_.d.ts} +1 -1
- package/dist/{types-C1rxh-id.d.cts → types-Btp416jt.d.cts} +8 -0
- package/dist/{types-C1rxh-id.d.ts → types-Btp416jt.d.ts} +8 -0
- package/dist/{types-CZTzbIzQ.d.cts → types-BxTL1NXw.d.cts} +7 -0
- package/dist/{types-CZTzbIzQ.d.ts → types-BxTL1NXw.d.ts} +7 -0
- package/dist/{types-pShrs3fN.d.cts → types-CuibHYcf.d.cts} +7 -0
- package/dist/{types-pShrs3fN.d.ts → types-CuibHYcf.d.ts} +7 -0
- package/dist/{types-CY-QWxd-.d.cts → types-CwN7AEoL.d.cts} +13 -1
- package/dist/{types-CY-QWxd-.d.ts → types-CwN7AEoL.d.ts} +13 -1
- package/dist/{types-D4bmW8rY.d.cts → types-DAnalt5K.d.cts} +7 -0
- package/dist/{types-D4bmW8rY.d.ts → types-DAnalt5K.d.ts} +7 -0
- package/dist/types-DDwidj2d.d.cts +371 -0
- package/dist/types-DDwidj2d.d.ts +371 -0
- package/dist/{types-Bg86GGVZ.d.cts → types-DxXNP32l.d.cts} +8 -0
- package/dist/{types-Bg86GGVZ.d.ts → types-DxXNP32l.d.ts} +8 -0
- package/package.json +15 -3
- package/src/core/auth-redaction.ts +190 -0
- package/src/core/types.ts +1 -0
- package/src/drafts/draft07/codec.ts +40 -0
- package/src/drafts/draft07/error-codes.ts +44 -0
- package/src/drafts/draft07/index.ts +15 -0
- package/src/drafts/draft08/codec.ts +40 -0
- package/src/drafts/draft08/error-codes.ts +76 -0
- package/src/drafts/draft08/index.ts +21 -0
- package/src/drafts/draft09/codec.ts +40 -0
- package/src/drafts/draft09/error-codes.ts +76 -0
- package/src/drafts/draft09/index.ts +21 -0
- package/src/drafts/draft10/codec.ts +40 -0
- package/src/drafts/draft10/error-codes.ts +76 -0
- package/src/drafts/draft10/index.ts +21 -0
- package/src/drafts/draft11/codec.ts +60 -0
- package/src/drafts/draft11/error-codes.ts +106 -0
- package/src/drafts/draft11/index.ts +23 -0
- package/src/drafts/draft12/codec.ts +61 -0
- package/src/drafts/draft12/error-codes.ts +116 -0
- package/src/drafts/draft12/index.ts +25 -0
- package/src/drafts/draft13/codec.ts +69 -11
- package/src/drafts/draft13/error-codes.ts +107 -0
- package/src/drafts/draft13/index.ts +23 -0
- package/src/drafts/draft13/types.ts +1 -1
- package/src/drafts/draft14/codec.ts +65 -4
- package/src/drafts/draft14/data-streams.ts +331 -259
- package/src/drafts/draft14/error-codes.ts +109 -0
- package/src/drafts/draft14/index.ts +23 -0
- package/src/drafts/draft15/codec.ts +65 -8
- package/src/drafts/draft15/data-streams.ts +489 -444
- package/src/drafts/draft15/error-codes.ts +66 -0
- package/src/drafts/draft15/index.ts +15 -0
- package/src/drafts/draft15/types.ts +7 -0
- package/src/drafts/draft16/codec.ts +146 -52
- package/src/drafts/draft16/data-streams.ts +513 -442
- package/src/drafts/draft16/error-codes.ts +68 -0
- package/src/drafts/draft16/index.ts +15 -0
- package/src/drafts/draft16/messages.ts +4 -4
- package/src/drafts/draft16/session-fsm.ts +0 -1
- package/src/drafts/draft16/types.ts +22 -8
- package/src/drafts/draft17/codec.ts +73 -12
- package/src/drafts/draft17/data-streams.ts +567 -488
- package/src/drafts/draft17/index.ts +15 -0
- package/src/drafts/draft17/types.ts +7 -0
- package/src/drafts/draft18/codec.ts +66 -9
- package/src/drafts/draft18/data-streams.ts +570 -482
- package/src/drafts/draft18/index.ts +3 -0
- package/src/drafts/draft18/types.ts +16 -8
- package/src/drafts/draft19/codec.ts +70 -10
- package/src/drafts/draft19/data-streams.ts +570 -482
- package/src/drafts/draft19/error-codes.ts +3 -1
- package/src/drafts/draft19/index.ts +3 -0
- package/src/drafts/draft19/messages.ts +3 -1
- package/src/drafts/draft19/types.ts +22 -11
- package/src/drafts/draft20/codec.ts +90 -23
- package/src/drafts/draft20/data-streams.ts +610 -563
- package/src/drafts/draft20/index.ts +3 -0
- package/src/drafts/draft20/types.ts +14 -2
- package/src/drafts/draft21/codec.ts +1816 -0
- package/src/drafts/draft21/data-streams.ts +1338 -0
- package/src/drafts/draft21/error-codes.ts +135 -0
- package/src/drafts/draft21/index.ts +168 -0
- package/src/drafts/draft21/messages.ts +68 -0
- package/src/drafts/draft21/rules.ts +107 -0
- package/src/drafts/draft21/session-fsm.ts +1063 -0
- package/src/drafts/draft21/session.ts +21 -0
- package/src/drafts/draft21/types.ts +473 -0
- package/src/index.ts +9 -1
- package/src/session.ts +4 -0
- package/dist/codec-BJ7BHuiZ.d.ts +0 -18
- package/dist/codec-C6Mx4bwz.d.cts +0 -18
|
@@ -1,10 +1,12 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } } function _optionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; }
|
|
1
|
+
"use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } } function _optionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; } var _class;
|
|
2
2
|
|
|
3
3
|
|
|
4
4
|
|
|
5
5
|
|
|
6
6
|
|
|
7
|
-
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
var _chunk5IMHJIAZcjs = require('./chunk-5IMHJIAZ.cjs');
|
|
8
10
|
|
|
9
11
|
// src/drafts/draft15/messages.ts
|
|
10
12
|
var MSG_SUBSCRIBE_UPDATE = 0x02n;
|
|
@@ -68,7 +70,7 @@ var MESSAGE_ID_MAP = new Map(
|
|
|
68
70
|
// src/drafts/draft15/data-streams.ts
|
|
69
71
|
var FETCH_STREAM_TYPE = 0x05n;
|
|
70
72
|
function encodeSubgroupStream(stream) {
|
|
71
|
-
const w = new (0,
|
|
73
|
+
const w = new (0, _chunk5IMHJIAZcjs.BufferWriter)();
|
|
72
74
|
const streamType = stream.headerType;
|
|
73
75
|
w.writeVarInt(BigInt(streamType));
|
|
74
76
|
const extensionsPresent = (streamType & 1) !== 0;
|
|
@@ -101,7 +103,7 @@ function encodeSubgroupStream(stream) {
|
|
|
101
103
|
return w.finish();
|
|
102
104
|
}
|
|
103
105
|
function encodeDatagram(dg) {
|
|
104
|
-
const w = new (0,
|
|
106
|
+
const w = new (0, _chunk5IMHJIAZcjs.BufferWriter)();
|
|
105
107
|
const dgType = dg.datagramType;
|
|
106
108
|
w.writeVarInt(BigInt(dgType));
|
|
107
109
|
w.writeVarInt(dg.trackAlias);
|
|
@@ -129,7 +131,7 @@ function encodeDatagram(dg) {
|
|
|
129
131
|
return w.finish();
|
|
130
132
|
}
|
|
131
133
|
function encodeFetchStream(stream) {
|
|
132
|
-
const w = new (0,
|
|
134
|
+
const w = new (0, _chunk5IMHJIAZcjs.BufferWriter)();
|
|
133
135
|
w.writeVarInt(FETCH_STREAM_TYPE);
|
|
134
136
|
w.writeVarInt(stream.requestId);
|
|
135
137
|
for (const obj of stream.objects) {
|
|
@@ -153,100 +155,112 @@ function encodeFetchStream(stream) {
|
|
|
153
155
|
}
|
|
154
156
|
return w.finish();
|
|
155
157
|
}
|
|
158
|
+
function readSubgroupHeader(r) {
|
|
159
|
+
const streamType = Number(r.readVarInt());
|
|
160
|
+
if (!(streamType >= 16 && streamType <= 31 || streamType >= 48 && streamType <= 63) || (streamType & 6) === 6) {
|
|
161
|
+
throw new (0, _chunk5IMHJIAZcjs.DecodeError)(
|
|
162
|
+
"CONSTRAINT_VIOLATION",
|
|
163
|
+
`Expected subgroup stream type 0x10-0x1F/0x30-0x3F, got 0x${streamType.toString(16)}`,
|
|
164
|
+
0
|
|
165
|
+
);
|
|
166
|
+
}
|
|
167
|
+
const extensionsPresent = (streamType & 1) !== 0;
|
|
168
|
+
const endOfGroup = (streamType & 8) !== 0;
|
|
169
|
+
const hasSubgroupField = (streamType & 4) !== 0;
|
|
170
|
+
const hasPriority = streamType < 48;
|
|
171
|
+
const subgroupIsFirstObjId = false;
|
|
172
|
+
const trackAlias = r.readVarInt();
|
|
173
|
+
const groupId = r.readVarInt();
|
|
174
|
+
let subgroupId = 0n;
|
|
175
|
+
if (hasSubgroupField) {
|
|
176
|
+
subgroupId = r.readVarInt();
|
|
177
|
+
}
|
|
178
|
+
let publisherPriority = 128;
|
|
179
|
+
if (hasPriority) {
|
|
180
|
+
publisherPriority = r.readUint8();
|
|
181
|
+
}
|
|
182
|
+
return {
|
|
183
|
+
streamType,
|
|
184
|
+
extensionsPresent,
|
|
185
|
+
subgroupIsFirstObjId,
|
|
186
|
+
endOfGroup,
|
|
187
|
+
trackAlias,
|
|
188
|
+
groupId,
|
|
189
|
+
subgroupId,
|
|
190
|
+
publisherPriority
|
|
191
|
+
};
|
|
192
|
+
}
|
|
193
|
+
function readSubgroupObject(r, extensionsPresent, isFirst, prevObjectId, base) {
|
|
194
|
+
const byteOffset = base + r.offset;
|
|
195
|
+
const delta = r.readVarInt();
|
|
196
|
+
const objectId = isFirst ? delta : prevObjectId + 1n + delta;
|
|
197
|
+
let extensionData = new Uint8Array(0);
|
|
198
|
+
if (extensionsPresent) {
|
|
199
|
+
const extLen = Number(r.readVarInt());
|
|
200
|
+
extensionData = extLen > 0 ? r.readBytesView(extLen) : new Uint8Array(0);
|
|
201
|
+
}
|
|
202
|
+
const payloadLength = Number(r.readVarInt());
|
|
203
|
+
let payload;
|
|
204
|
+
let status;
|
|
205
|
+
let payloadByteOffset;
|
|
206
|
+
if (payloadLength === 0) {
|
|
207
|
+
status = r.readVarInt();
|
|
208
|
+
payloadByteOffset = base + r.offset;
|
|
209
|
+
payload = new Uint8Array(0);
|
|
210
|
+
} else {
|
|
211
|
+
payloadByteOffset = base + r.offset;
|
|
212
|
+
payload = r.readBytesView(payloadLength);
|
|
213
|
+
}
|
|
214
|
+
const obj = {
|
|
215
|
+
type: "object",
|
|
216
|
+
byteOffset,
|
|
217
|
+
payloadByteOffset,
|
|
218
|
+
objectId,
|
|
219
|
+
payloadLength,
|
|
220
|
+
payload,
|
|
221
|
+
extensionData
|
|
222
|
+
};
|
|
223
|
+
if (status !== void 0) obj.status = status;
|
|
224
|
+
return obj;
|
|
225
|
+
}
|
|
156
226
|
function decodeSubgroupStream(bytes) {
|
|
157
227
|
try {
|
|
158
|
-
const r = new (0,
|
|
159
|
-
const
|
|
160
|
-
if (!(streamType >= 16 && streamType <= 31 || streamType >= 48 && streamType <= 63) || (streamType & 6) === 6) {
|
|
161
|
-
return {
|
|
162
|
-
ok: false,
|
|
163
|
-
error: new (0, _chunk4XLYCT5Qcjs.DecodeError)(
|
|
164
|
-
"CONSTRAINT_VIOLATION",
|
|
165
|
-
`Expected subgroup stream type 0x10-0x1F/0x30-0x3F, got 0x${streamType.toString(16)}`,
|
|
166
|
-
0
|
|
167
|
-
)
|
|
168
|
-
};
|
|
169
|
-
}
|
|
170
|
-
const extensionsPresent = (streamType & 1) !== 0;
|
|
171
|
-
const endOfGroup = (streamType & 8) !== 0;
|
|
172
|
-
const hasSubgroupField = (streamType & 4) !== 0;
|
|
173
|
-
const hasPriority = streamType < 48;
|
|
174
|
-
const trackAlias = r.readVarInt();
|
|
175
|
-
const groupId = r.readVarInt();
|
|
176
|
-
let subgroupId = 0n;
|
|
177
|
-
if (hasSubgroupField) {
|
|
178
|
-
subgroupId = r.readVarInt();
|
|
179
|
-
}
|
|
180
|
-
let publisherPriority = 128;
|
|
181
|
-
if (hasPriority) {
|
|
182
|
-
publisherPriority = r.readUint8();
|
|
183
|
-
}
|
|
228
|
+
const r = new (0, _chunk5IMHJIAZcjs.BufferReader)(bytes);
|
|
229
|
+
const h = readSubgroupHeader(r);
|
|
184
230
|
const objects = [];
|
|
185
231
|
let prevObjectId = -1n;
|
|
186
|
-
let
|
|
232
|
+
let isFirst = true;
|
|
233
|
+
let subgroupId = h.subgroupId;
|
|
187
234
|
while (r.remaining > 0) {
|
|
188
|
-
const
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
if (firstObject) {
|
|
192
|
-
objectId = delta;
|
|
193
|
-
firstObject = false;
|
|
194
|
-
} else {
|
|
195
|
-
objectId = prevObjectId + 1n + delta;
|
|
196
|
-
}
|
|
197
|
-
let extensionData = new Uint8Array(0);
|
|
198
|
-
if (extensionsPresent) {
|
|
199
|
-
const extLen = Number(r.readVarInt());
|
|
200
|
-
extensionData = extLen > 0 ? r.readBytesView(extLen) : new Uint8Array(0);
|
|
201
|
-
}
|
|
202
|
-
const payloadLength = Number(r.readVarInt());
|
|
203
|
-
let payload;
|
|
204
|
-
let status;
|
|
205
|
-
let payloadByteOffset;
|
|
206
|
-
if (payloadLength === 0) {
|
|
207
|
-
status = r.readVarInt();
|
|
208
|
-
payloadByteOffset = r.offset;
|
|
209
|
-
payload = new Uint8Array(0);
|
|
210
|
-
} else {
|
|
211
|
-
payloadByteOffset = r.offset;
|
|
212
|
-
payload = r.readBytesView(payloadLength);
|
|
213
|
-
}
|
|
214
|
-
const obj = {
|
|
215
|
-
type: "object",
|
|
216
|
-
byteOffset,
|
|
217
|
-
payloadByteOffset,
|
|
218
|
-
objectId,
|
|
219
|
-
payloadLength,
|
|
220
|
-
extensionData,
|
|
221
|
-
payload
|
|
222
|
-
};
|
|
223
|
-
if (status !== void 0) obj.status = status;
|
|
235
|
+
const obj = readSubgroupObject(r, h.extensionsPresent, isFirst, prevObjectId, 0);
|
|
236
|
+
if (isFirst && h.subgroupIsFirstObjId) subgroupId = obj.objectId;
|
|
237
|
+
isFirst = false;
|
|
224
238
|
objects.push(obj);
|
|
225
|
-
prevObjectId = objectId;
|
|
239
|
+
prevObjectId = obj.objectId;
|
|
226
240
|
}
|
|
227
241
|
const result = {
|
|
228
242
|
type: "subgroup",
|
|
229
|
-
headerType: streamType,
|
|
230
|
-
trackAlias,
|
|
231
|
-
groupId,
|
|
243
|
+
headerType: h.streamType,
|
|
244
|
+
trackAlias: h.trackAlias,
|
|
245
|
+
groupId: h.groupId,
|
|
232
246
|
subgroupId,
|
|
233
|
-
publisherPriority,
|
|
234
|
-
objects
|
|
247
|
+
publisherPriority: h.publisherPriority,
|
|
248
|
+
objects,
|
|
249
|
+
...h.endOfGroup ? { endOfGroup: true } : {}
|
|
235
250
|
};
|
|
236
|
-
if (endOfGroup) result.endOfGroup = true;
|
|
237
251
|
return {
|
|
238
252
|
ok: true,
|
|
239
253
|
value: result,
|
|
240
254
|
bytesRead: r.offset
|
|
241
255
|
};
|
|
242
256
|
} catch (e) {
|
|
243
|
-
if (e instanceof
|
|
257
|
+
if (e instanceof _chunk5IMHJIAZcjs.DecodeError) return { ok: false, error: e };
|
|
244
258
|
throw e;
|
|
245
259
|
}
|
|
246
260
|
}
|
|
247
261
|
function decodeDatagram(bytes) {
|
|
248
262
|
try {
|
|
249
|
-
const r = new (0,
|
|
263
|
+
const r = new (0, _chunk5IMHJIAZcjs.BufferReader)(bytes);
|
|
250
264
|
const dgType = Number(r.readVarInt());
|
|
251
265
|
const extensionsPresent = (dgType & 1) !== 0;
|
|
252
266
|
const objectIdAbsent = (dgType & 4) !== 0;
|
|
@@ -294,18 +308,120 @@ function decodeDatagram(bytes) {
|
|
|
294
308
|
result.extensionData = extensionData;
|
|
295
309
|
return { ok: true, value: result, bytesRead: r.offset };
|
|
296
310
|
} catch (e) {
|
|
297
|
-
if (e instanceof
|
|
311
|
+
if (e instanceof _chunk5IMHJIAZcjs.DecodeError) return { ok: false, error: e };
|
|
298
312
|
throw e;
|
|
299
313
|
}
|
|
300
314
|
}
|
|
315
|
+
function newFetchObjectState() {
|
|
316
|
+
return { prevGroupId: 0n, prevSubgroupId: 0n, prevObjectId: 0n, prevPriority: 128, first: true };
|
|
317
|
+
}
|
|
318
|
+
function readFetchObject(r, base, st) {
|
|
319
|
+
const byteOffset = base + r.offset;
|
|
320
|
+
const flags = r.readUint8();
|
|
321
|
+
const subgroupEncoding = flags & 3;
|
|
322
|
+
const objectIdPresent = (flags & 4) !== 0;
|
|
323
|
+
const groupIdPresent = (flags & 8) !== 0;
|
|
324
|
+
const priorityPresent = (flags & 16) !== 0;
|
|
325
|
+
const extensionsPresent = (flags & 32) !== 0;
|
|
326
|
+
if (flags & 192) {
|
|
327
|
+
throw new (0, _chunk5IMHJIAZcjs.DecodeError)(
|
|
328
|
+
"CONSTRAINT_VIOLATION",
|
|
329
|
+
"Reserved bits set in fetch object flags",
|
|
330
|
+
r.offset
|
|
331
|
+
);
|
|
332
|
+
}
|
|
333
|
+
let groupId = st.prevGroupId;
|
|
334
|
+
if (groupIdPresent) {
|
|
335
|
+
groupId = r.readVarInt();
|
|
336
|
+
} else if (st.first) {
|
|
337
|
+
throw new (0, _chunk5IMHJIAZcjs.DecodeError)(
|
|
338
|
+
"CONSTRAINT_VIOLATION",
|
|
339
|
+
"First fetch object must include groupId",
|
|
340
|
+
r.offset
|
|
341
|
+
);
|
|
342
|
+
}
|
|
343
|
+
let subgroupId;
|
|
344
|
+
if (subgroupEncoding === 0) {
|
|
345
|
+
subgroupId = 0n;
|
|
346
|
+
} else if (subgroupEncoding === 1) {
|
|
347
|
+
if (st.first) {
|
|
348
|
+
throw new (0, _chunk5IMHJIAZcjs.DecodeError)(
|
|
349
|
+
"CONSTRAINT_VIOLATION",
|
|
350
|
+
"First fetch object cannot reference prior subgroupId",
|
|
351
|
+
r.offset
|
|
352
|
+
);
|
|
353
|
+
}
|
|
354
|
+
subgroupId = st.prevSubgroupId;
|
|
355
|
+
} else if (subgroupEncoding === 2) {
|
|
356
|
+
if (st.first) {
|
|
357
|
+
throw new (0, _chunk5IMHJIAZcjs.DecodeError)(
|
|
358
|
+
"CONSTRAINT_VIOLATION",
|
|
359
|
+
"First fetch object cannot reference prior subgroupId",
|
|
360
|
+
r.offset
|
|
361
|
+
);
|
|
362
|
+
}
|
|
363
|
+
subgroupId = st.prevSubgroupId + 1n;
|
|
364
|
+
} else {
|
|
365
|
+
subgroupId = r.readVarInt();
|
|
366
|
+
}
|
|
367
|
+
let objectId = st.prevObjectId + 1n;
|
|
368
|
+
if (objectIdPresent) {
|
|
369
|
+
objectId = r.readVarInt();
|
|
370
|
+
} else if (st.first) {
|
|
371
|
+
throw new (0, _chunk5IMHJIAZcjs.DecodeError)(
|
|
372
|
+
"CONSTRAINT_VIOLATION",
|
|
373
|
+
"First fetch object must include objectId",
|
|
374
|
+
r.offset
|
|
375
|
+
);
|
|
376
|
+
}
|
|
377
|
+
if (priorityPresent) {
|
|
378
|
+
st.prevPriority = r.readUint8();
|
|
379
|
+
}
|
|
380
|
+
let extensionData = new Uint8Array(0);
|
|
381
|
+
if (extensionsPresent) {
|
|
382
|
+
const extLen = Number(r.readVarInt());
|
|
383
|
+
extensionData = extLen > 0 ? r.readBytesView(extLen) : new Uint8Array(0);
|
|
384
|
+
}
|
|
385
|
+
const payloadLength = Number(r.readVarInt());
|
|
386
|
+
let payload;
|
|
387
|
+
let status;
|
|
388
|
+
let payloadByteOffset;
|
|
389
|
+
if (payloadLength > 0) {
|
|
390
|
+
payloadByteOffset = base + r.offset;
|
|
391
|
+
payload = r.readBytesView(payloadLength);
|
|
392
|
+
} else {
|
|
393
|
+
status = r.readVarInt();
|
|
394
|
+
payloadByteOffset = base + r.offset;
|
|
395
|
+
payload = new Uint8Array(0);
|
|
396
|
+
}
|
|
397
|
+
const obj = {
|
|
398
|
+
type: "object",
|
|
399
|
+
byteOffset,
|
|
400
|
+
payloadByteOffset,
|
|
401
|
+
serializationFlags: flags,
|
|
402
|
+
groupId,
|
|
403
|
+
subgroupId,
|
|
404
|
+
objectId,
|
|
405
|
+
publisherPriority: st.prevPriority,
|
|
406
|
+
payloadLength,
|
|
407
|
+
extensionData,
|
|
408
|
+
payload
|
|
409
|
+
};
|
|
410
|
+
if (status !== void 0) obj.status = status;
|
|
411
|
+
st.prevGroupId = groupId;
|
|
412
|
+
st.prevSubgroupId = subgroupId;
|
|
413
|
+
st.prevObjectId = objectId;
|
|
414
|
+
st.first = false;
|
|
415
|
+
return obj;
|
|
416
|
+
}
|
|
301
417
|
function decodeFetchStream(bytes) {
|
|
302
418
|
try {
|
|
303
|
-
const r = new (0,
|
|
419
|
+
const r = new (0, _chunk5IMHJIAZcjs.BufferReader)(bytes);
|
|
304
420
|
const streamType = r.readVarInt();
|
|
305
421
|
if (streamType !== FETCH_STREAM_TYPE) {
|
|
306
422
|
return {
|
|
307
423
|
ok: false,
|
|
308
|
-
error: new (0,
|
|
424
|
+
error: new (0, _chunk5IMHJIAZcjs.DecodeError)(
|
|
309
425
|
"CONSTRAINT_VIOLATION",
|
|
310
426
|
`Expected fetch stream type 0x05, got 0x${streamType.toString(16)}`,
|
|
311
427
|
0
|
|
@@ -314,124 +430,9 @@ function decodeFetchStream(bytes) {
|
|
|
314
430
|
}
|
|
315
431
|
const requestId = r.readVarInt();
|
|
316
432
|
const objects = [];
|
|
317
|
-
|
|
318
|
-
let prevSubgroupId = 0n;
|
|
319
|
-
let prevObjectId = 0n;
|
|
320
|
-
let prevPriority = 128;
|
|
321
|
-
let first = true;
|
|
433
|
+
const st = newFetchObjectState();
|
|
322
434
|
while (r.remaining > 0) {
|
|
323
|
-
|
|
324
|
-
const flags = r.readUint8();
|
|
325
|
-
const subgroupEncoding = flags & 3;
|
|
326
|
-
const objectIdPresent = (flags & 4) !== 0;
|
|
327
|
-
const groupIdPresent = (flags & 8) !== 0;
|
|
328
|
-
const priorityPresent = (flags & 16) !== 0;
|
|
329
|
-
const extensionsPresent = (flags & 32) !== 0;
|
|
330
|
-
if (flags & 192) {
|
|
331
|
-
return {
|
|
332
|
-
ok: false,
|
|
333
|
-
error: new (0, _chunk4XLYCT5Qcjs.DecodeError)(
|
|
334
|
-
"CONSTRAINT_VIOLATION",
|
|
335
|
-
"Reserved bits set in fetch object flags",
|
|
336
|
-
r.offset
|
|
337
|
-
)
|
|
338
|
-
};
|
|
339
|
-
}
|
|
340
|
-
let groupId = prevGroupId;
|
|
341
|
-
if (groupIdPresent) {
|
|
342
|
-
groupId = r.readVarInt();
|
|
343
|
-
} else if (first) {
|
|
344
|
-
return {
|
|
345
|
-
ok: false,
|
|
346
|
-
error: new (0, _chunk4XLYCT5Qcjs.DecodeError)(
|
|
347
|
-
"CONSTRAINT_VIOLATION",
|
|
348
|
-
"First fetch object must include groupId",
|
|
349
|
-
r.offset
|
|
350
|
-
)
|
|
351
|
-
};
|
|
352
|
-
}
|
|
353
|
-
let subgroupId;
|
|
354
|
-
if (subgroupEncoding === 0) {
|
|
355
|
-
subgroupId = 0n;
|
|
356
|
-
} else if (subgroupEncoding === 1) {
|
|
357
|
-
if (first) {
|
|
358
|
-
return {
|
|
359
|
-
ok: false,
|
|
360
|
-
error: new (0, _chunk4XLYCT5Qcjs.DecodeError)(
|
|
361
|
-
"CONSTRAINT_VIOLATION",
|
|
362
|
-
"First fetch object cannot reference prior subgroupId",
|
|
363
|
-
r.offset
|
|
364
|
-
)
|
|
365
|
-
};
|
|
366
|
-
}
|
|
367
|
-
subgroupId = prevSubgroupId;
|
|
368
|
-
} else if (subgroupEncoding === 2) {
|
|
369
|
-
if (first) {
|
|
370
|
-
return {
|
|
371
|
-
ok: false,
|
|
372
|
-
error: new (0, _chunk4XLYCT5Qcjs.DecodeError)(
|
|
373
|
-
"CONSTRAINT_VIOLATION",
|
|
374
|
-
"First fetch object cannot reference prior subgroupId",
|
|
375
|
-
r.offset
|
|
376
|
-
)
|
|
377
|
-
};
|
|
378
|
-
}
|
|
379
|
-
subgroupId = prevSubgroupId + 1n;
|
|
380
|
-
} else {
|
|
381
|
-
subgroupId = r.readVarInt();
|
|
382
|
-
}
|
|
383
|
-
let objectId = prevObjectId + 1n;
|
|
384
|
-
if (objectIdPresent) {
|
|
385
|
-
objectId = r.readVarInt();
|
|
386
|
-
} else if (first) {
|
|
387
|
-
return {
|
|
388
|
-
ok: false,
|
|
389
|
-
error: new (0, _chunk4XLYCT5Qcjs.DecodeError)(
|
|
390
|
-
"CONSTRAINT_VIOLATION",
|
|
391
|
-
"First fetch object must include objectId",
|
|
392
|
-
r.offset
|
|
393
|
-
)
|
|
394
|
-
};
|
|
395
|
-
}
|
|
396
|
-
if (priorityPresent) {
|
|
397
|
-
prevPriority = r.readUint8();
|
|
398
|
-
}
|
|
399
|
-
let extensionData = new Uint8Array(0);
|
|
400
|
-
if (extensionsPresent) {
|
|
401
|
-
const extLen = Number(r.readVarInt());
|
|
402
|
-
extensionData = extLen > 0 ? r.readBytesView(extLen) : new Uint8Array(0);
|
|
403
|
-
}
|
|
404
|
-
const payloadLength = Number(r.readVarInt());
|
|
405
|
-
let payload;
|
|
406
|
-
let status;
|
|
407
|
-
let payloadByteOffset;
|
|
408
|
-
if (payloadLength > 0) {
|
|
409
|
-
payloadByteOffset = r.offset;
|
|
410
|
-
payload = r.readBytesView(payloadLength);
|
|
411
|
-
} else {
|
|
412
|
-
status = r.readVarInt();
|
|
413
|
-
payloadByteOffset = r.offset;
|
|
414
|
-
payload = new Uint8Array(0);
|
|
415
|
-
}
|
|
416
|
-
const obj = {
|
|
417
|
-
type: "object",
|
|
418
|
-
byteOffset,
|
|
419
|
-
payloadByteOffset,
|
|
420
|
-
serializationFlags: flags,
|
|
421
|
-
groupId,
|
|
422
|
-
subgroupId,
|
|
423
|
-
objectId,
|
|
424
|
-
publisherPriority: prevPriority,
|
|
425
|
-
payloadLength,
|
|
426
|
-
extensionData,
|
|
427
|
-
payload
|
|
428
|
-
};
|
|
429
|
-
if (status !== void 0) obj.status = status;
|
|
430
|
-
objects.push(obj);
|
|
431
|
-
prevGroupId = groupId;
|
|
432
|
-
prevSubgroupId = subgroupId;
|
|
433
|
-
prevObjectId = objectId;
|
|
434
|
-
first = false;
|
|
435
|
+
objects.push(readFetchObject(r, 0, st));
|
|
435
436
|
}
|
|
436
437
|
return {
|
|
437
438
|
ok: true,
|
|
@@ -439,7 +440,7 @@ function decodeFetchStream(bytes) {
|
|
|
439
440
|
bytesRead: r.offset
|
|
440
441
|
};
|
|
441
442
|
} catch (e) {
|
|
442
|
-
if (e instanceof
|
|
443
|
+
if (e instanceof _chunk5IMHJIAZcjs.DecodeError) return { ok: false, error: e };
|
|
443
444
|
throw e;
|
|
444
445
|
}
|
|
445
446
|
}
|
|
@@ -457,137 +458,124 @@ function decodeDataStream(streamType, bytes) {
|
|
|
457
458
|
}
|
|
458
459
|
}
|
|
459
460
|
}
|
|
461
|
+
var StreamBuffer = (_class = class {constructor() { _class.prototype.__init.call(this);_class.prototype.__init2.call(this);_class.prototype.__init3.call(this);_class.prototype.__init4.call(this); }
|
|
462
|
+
__init() {this.buf = new Uint8Array(0)}
|
|
463
|
+
/** Bytes written into `buf`. */
|
|
464
|
+
__init2() {this.len = 0}
|
|
465
|
+
/** Consumed prefix of `buf`; `base + offset` is the position in the stream. */
|
|
466
|
+
__init3() {this.offset = 0}
|
|
467
|
+
/** Absolute position of `buf[0]` within the stream. */
|
|
468
|
+
__init4() {this.base = 0}
|
|
469
|
+
get unread() {
|
|
470
|
+
return this.len - this.offset;
|
|
471
|
+
}
|
|
472
|
+
append(chunk) {
|
|
473
|
+
if (this.len + chunk.length > this.buf.length) {
|
|
474
|
+
const live = this.len - this.offset;
|
|
475
|
+
const needed = live + chunk.length;
|
|
476
|
+
let cap = Math.max(4096, this.buf.length);
|
|
477
|
+
while (cap < needed * 2) cap *= 2;
|
|
478
|
+
const next = new Uint8Array(cap);
|
|
479
|
+
next.set(this.buf.subarray(this.offset, this.len), 0);
|
|
480
|
+
this.buf = next;
|
|
481
|
+
this.base += this.offset;
|
|
482
|
+
this.len = live;
|
|
483
|
+
this.offset = 0;
|
|
484
|
+
}
|
|
485
|
+
this.buf.set(chunk, this.len);
|
|
486
|
+
this.len += chunk.length;
|
|
487
|
+
}
|
|
488
|
+
/**
|
|
489
|
+
* The written bytes, for a reader positioned at `offset`. Bounded by `len`
|
|
490
|
+
* rather than by capacity, so `BufferReader.remaining` counts real bytes and
|
|
491
|
+
* not the spare room after them.
|
|
492
|
+
*/
|
|
493
|
+
written() {
|
|
494
|
+
return this.buf.subarray(0, this.len);
|
|
495
|
+
}
|
|
496
|
+
}, _class);
|
|
460
497
|
function createSubgroupStreamDecoder() {
|
|
461
|
-
|
|
462
|
-
let
|
|
498
|
+
const b = new StreamBuffer();
|
|
499
|
+
let header = null;
|
|
463
500
|
let headerEmitted = false;
|
|
464
501
|
let prevObjectId = -1n;
|
|
465
|
-
let
|
|
466
|
-
|
|
467
|
-
|
|
502
|
+
let isFirst = true;
|
|
503
|
+
function emitHeader(controller, h, subgroupId) {
|
|
504
|
+
controller.enqueue({
|
|
505
|
+
type: "subgroup_header",
|
|
506
|
+
headerType: h.streamType,
|
|
507
|
+
trackAlias: h.trackAlias,
|
|
508
|
+
groupId: h.groupId,
|
|
509
|
+
subgroupId,
|
|
510
|
+
publisherPriority: h.publisherPriority,
|
|
511
|
+
...h.endOfGroup ? { endOfGroup: true } : {}
|
|
512
|
+
});
|
|
513
|
+
headerEmitted = true;
|
|
514
|
+
}
|
|
468
515
|
return new TransformStream({
|
|
469
516
|
transform(chunk, controller) {
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
}
|
|
474
|
-
const newBuffer = new Uint8Array(buffer.length + chunk.length);
|
|
475
|
-
newBuffer.set(buffer, 0);
|
|
476
|
-
newBuffer.set(chunk, buffer.length);
|
|
477
|
-
buffer = newBuffer;
|
|
478
|
-
if (!headerEmitted) {
|
|
517
|
+
b.append(chunk);
|
|
518
|
+
const view = b.written();
|
|
519
|
+
if (header === null) {
|
|
479
520
|
try {
|
|
480
|
-
const
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
controller.error(
|
|
484
|
-
new (0, _chunk4XLYCT5Qcjs.DecodeError)(
|
|
485
|
-
"CONSTRAINT_VIOLATION",
|
|
486
|
-
`Expected subgroup stream type, got 0x${streamType.toString(16)}`,
|
|
487
|
-
0
|
|
488
|
-
)
|
|
489
|
-
);
|
|
490
|
-
return;
|
|
491
|
-
}
|
|
492
|
-
_extensionsPresent = (streamType & 1) !== 0;
|
|
493
|
-
const hasSubgroupField = (streamType & 4) !== 0;
|
|
494
|
-
_subgroupIsFirstObjId = false;
|
|
495
|
-
const hasPriority = streamType < 48;
|
|
496
|
-
const trackAlias = r.readVarInt();
|
|
497
|
-
const groupId = r.readVarInt();
|
|
498
|
-
let subgroupId = 0n;
|
|
499
|
-
if (hasSubgroupField) {
|
|
500
|
-
subgroupId = r.readVarInt();
|
|
501
|
-
}
|
|
502
|
-
let publisherPriority = 128;
|
|
503
|
-
if (hasPriority) {
|
|
504
|
-
publisherPriority = r.readUint8();
|
|
505
|
-
}
|
|
506
|
-
controller.enqueue({
|
|
507
|
-
type: "subgroup_header",
|
|
508
|
-
trackAlias,
|
|
509
|
-
groupId,
|
|
510
|
-
subgroupId,
|
|
511
|
-
publisherPriority
|
|
512
|
-
});
|
|
513
|
-
headerEmitted = true;
|
|
514
|
-
offset += r.offset;
|
|
521
|
+
const hr = new (0, _chunk5IMHJIAZcjs.BufferReader)(view, b.offset);
|
|
522
|
+
header = readSubgroupHeader(hr);
|
|
523
|
+
b.offset = hr.offset;
|
|
515
524
|
} catch (e) {
|
|
516
|
-
if (e instanceof
|
|
525
|
+
if (e instanceof _chunk5IMHJIAZcjs.DecodeError && e.code === "UNEXPECTED_END") {
|
|
517
526
|
return;
|
|
518
527
|
}
|
|
519
528
|
controller.error(e);
|
|
520
529
|
return;
|
|
521
530
|
}
|
|
531
|
+
if (!header.subgroupIsFirstObjId) emitHeader(controller, header, header.subgroupId);
|
|
522
532
|
}
|
|
523
|
-
|
|
533
|
+
const h = header;
|
|
534
|
+
if (h === null) return;
|
|
535
|
+
const r = new (0, _chunk5IMHJIAZcjs.BufferReader)(view, b.offset);
|
|
536
|
+
while (r.remaining > 0) {
|
|
537
|
+
const start = r.offset;
|
|
538
|
+
let obj;
|
|
524
539
|
try {
|
|
525
|
-
|
|
526
|
-
const byteOffset = r.offset;
|
|
527
|
-
const delta = r.readVarInt();
|
|
528
|
-
let objectId;
|
|
529
|
-
if (firstObject) {
|
|
530
|
-
objectId = delta;
|
|
531
|
-
firstObject = false;
|
|
532
|
-
} else {
|
|
533
|
-
objectId = prevObjectId + 1n + delta;
|
|
534
|
-
}
|
|
535
|
-
let extensionData = new Uint8Array(0);
|
|
536
|
-
if (_extensionsPresent) {
|
|
537
|
-
const extLen = Number(r.readVarInt());
|
|
538
|
-
extensionData = extLen > 0 ? r.readBytesView(extLen) : new Uint8Array(0);
|
|
539
|
-
}
|
|
540
|
-
const payloadLength = Number(r.readVarInt());
|
|
541
|
-
const payloadByteOffset = r.offset;
|
|
542
|
-
const payload = payloadLength > 0 ? r.readBytesView(payloadLength) : new Uint8Array(0);
|
|
543
|
-
controller.enqueue({
|
|
544
|
-
type: "object",
|
|
545
|
-
byteOffset,
|
|
546
|
-
payloadByteOffset,
|
|
547
|
-
objectId,
|
|
548
|
-
payloadLength,
|
|
549
|
-
extensionData,
|
|
550
|
-
payload
|
|
551
|
-
});
|
|
552
|
-
offset += r.offset;
|
|
553
|
-
prevObjectId = objectId;
|
|
540
|
+
obj = readSubgroupObject(r, h.extensionsPresent, isFirst, prevObjectId, b.base);
|
|
554
541
|
} catch (e) {
|
|
555
|
-
if (e instanceof
|
|
556
|
-
|
|
542
|
+
if (e instanceof _chunk5IMHJIAZcjs.DecodeError && e.code === "UNEXPECTED_END") {
|
|
543
|
+
b.offset = start;
|
|
544
|
+
return;
|
|
557
545
|
}
|
|
558
546
|
controller.error(e);
|
|
559
547
|
return;
|
|
560
548
|
}
|
|
549
|
+
if (!headerEmitted) emitHeader(controller, h, obj.objectId);
|
|
550
|
+
isFirst = false;
|
|
551
|
+
b.offset = r.offset;
|
|
552
|
+
prevObjectId = obj.objectId;
|
|
553
|
+
controller.enqueue(obj);
|
|
561
554
|
}
|
|
562
555
|
},
|
|
563
556
|
flush(controller) {
|
|
564
|
-
if (
|
|
565
|
-
|
|
557
|
+
if (header !== null && !headerEmitted) emitHeader(controller, header, 0n);
|
|
558
|
+
if (b.unread > 0) {
|
|
559
|
+
controller.error(new (0, _chunk5IMHJIAZcjs.DecodeError)("UNEXPECTED_END", "Stream ended with incomplete data", 0));
|
|
566
560
|
}
|
|
567
561
|
}
|
|
568
562
|
});
|
|
569
563
|
}
|
|
570
564
|
function createFetchStreamDecoder() {
|
|
571
|
-
|
|
572
|
-
let offset = 0;
|
|
565
|
+
const b = new StreamBuffer();
|
|
573
566
|
let headerEmitted = false;
|
|
567
|
+
const st = newFetchObjectState();
|
|
574
568
|
return new TransformStream({
|
|
575
569
|
transform(chunk, controller) {
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
offset = 0;
|
|
579
|
-
}
|
|
580
|
-
const newBuffer = new Uint8Array(buffer.length + chunk.length);
|
|
581
|
-
newBuffer.set(buffer, 0);
|
|
582
|
-
newBuffer.set(chunk, buffer.length);
|
|
583
|
-
buffer = newBuffer;
|
|
570
|
+
b.append(chunk);
|
|
571
|
+
const view = b.written();
|
|
584
572
|
if (!headerEmitted) {
|
|
585
573
|
try {
|
|
586
|
-
const
|
|
587
|
-
const streamType =
|
|
574
|
+
const r2 = new (0, _chunk5IMHJIAZcjs.BufferReader)(view, b.offset);
|
|
575
|
+
const streamType = r2.readVarInt();
|
|
588
576
|
if (streamType !== FETCH_STREAM_TYPE) {
|
|
589
577
|
controller.error(
|
|
590
|
-
new (0,
|
|
578
|
+
new (0, _chunk5IMHJIAZcjs.DecodeError)(
|
|
591
579
|
"CONSTRAINT_VIOLATION",
|
|
592
580
|
`Expected fetch stream type 0x05, got 0x${streamType.toString(16)}`,
|
|
593
581
|
0
|
|
@@ -595,115 +583,96 @@ function createFetchStreamDecoder() {
|
|
|
595
583
|
);
|
|
596
584
|
return;
|
|
597
585
|
}
|
|
598
|
-
const requestId =
|
|
586
|
+
const requestId = r2.readVarInt();
|
|
599
587
|
controller.enqueue({ type: "fetch_header", requestId });
|
|
600
588
|
headerEmitted = true;
|
|
601
|
-
offset
|
|
589
|
+
b.offset = r2.offset;
|
|
602
590
|
} catch (e) {
|
|
603
|
-
if (e instanceof
|
|
591
|
+
if (e instanceof _chunk5IMHJIAZcjs.DecodeError && e.code === "UNEXPECTED_END") {
|
|
604
592
|
return;
|
|
605
593
|
}
|
|
606
594
|
controller.error(e);
|
|
607
595
|
return;
|
|
608
596
|
}
|
|
609
597
|
}
|
|
610
|
-
|
|
598
|
+
const r = new (0, _chunk5IMHJIAZcjs.BufferReader)(view, b.offset);
|
|
599
|
+
while (r.remaining > 0) {
|
|
600
|
+
const start = r.offset;
|
|
601
|
+
let obj;
|
|
611
602
|
try {
|
|
612
|
-
|
|
613
|
-
const flags = r.readUint8();
|
|
614
|
-
const objectIdPresent = (flags & 4) !== 0;
|
|
615
|
-
const groupIdPresent = (flags & 8) !== 0;
|
|
616
|
-
const priorityPresent = (flags & 16) !== 0;
|
|
617
|
-
const extensionsPresent = (flags & 32) !== 0;
|
|
618
|
-
const subgroupEncoding = flags & 3;
|
|
619
|
-
if (groupIdPresent) r.readVarInt();
|
|
620
|
-
if (subgroupEncoding === 3) r.readVarInt();
|
|
621
|
-
let objectId = 0n;
|
|
622
|
-
if (objectIdPresent) objectId = r.readVarInt();
|
|
623
|
-
if (priorityPresent) r.readUint8();
|
|
624
|
-
let extensionData = new Uint8Array(0);
|
|
625
|
-
if (extensionsPresent) {
|
|
626
|
-
const extLen = Number(r.readVarInt());
|
|
627
|
-
extensionData = extLen > 0 ? r.readBytesView(extLen) : new Uint8Array(0);
|
|
628
|
-
}
|
|
629
|
-
const payloadLength = Number(r.readVarInt());
|
|
630
|
-
const payloadByteOffset = r.offset;
|
|
631
|
-
const payload = payloadLength > 0 ? r.readBytesView(payloadLength) : new Uint8Array(0);
|
|
632
|
-
controller.enqueue({
|
|
633
|
-
type: "object",
|
|
634
|
-
objectId,
|
|
635
|
-
payloadLength,
|
|
636
|
-
extensionData,
|
|
637
|
-
payload,
|
|
638
|
-
byteOffset: 0,
|
|
639
|
-
payloadByteOffset
|
|
640
|
-
});
|
|
641
|
-
offset += r.offset;
|
|
603
|
+
obj = readFetchObject(r, b.base, st);
|
|
642
604
|
} catch (e) {
|
|
643
|
-
if (e instanceof
|
|
644
|
-
|
|
605
|
+
if (e instanceof _chunk5IMHJIAZcjs.DecodeError && e.code === "UNEXPECTED_END") {
|
|
606
|
+
b.offset = start;
|
|
607
|
+
return;
|
|
645
608
|
}
|
|
646
609
|
controller.error(e);
|
|
647
610
|
return;
|
|
648
611
|
}
|
|
612
|
+
b.offset = r.offset;
|
|
613
|
+
controller.enqueue(obj);
|
|
649
614
|
}
|
|
650
615
|
},
|
|
651
616
|
flush(controller) {
|
|
652
|
-
if (
|
|
653
|
-
controller.error(new (0,
|
|
617
|
+
if (b.unread > 0) {
|
|
618
|
+
controller.error(new (0, _chunk5IMHJIAZcjs.DecodeError)("UNEXPECTED_END", "Stream ended with incomplete data", 0));
|
|
654
619
|
}
|
|
655
620
|
}
|
|
656
621
|
});
|
|
657
622
|
}
|
|
658
623
|
function createDataStreamDecoder() {
|
|
659
|
-
let
|
|
660
|
-
let
|
|
661
|
-
let
|
|
662
|
-
|
|
663
|
-
|
|
664
|
-
|
|
665
|
-
|
|
666
|
-
|
|
667
|
-
|
|
668
|
-
|
|
669
|
-
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
|
|
675
|
-
|
|
676
|
-
const firstByte = buffer[offset];
|
|
677
|
-
if (firstByte >= 16 && firstByte <= 31 || firstByte >= 48 && firstByte <= 63) {
|
|
678
|
-
const decoder = createSubgroupStreamDecoder();
|
|
679
|
-
inner = decoder;
|
|
680
|
-
} else if (firstByte === 5) {
|
|
681
|
-
const decoder = createFetchStreamDecoder();
|
|
682
|
-
inner = decoder;
|
|
683
|
-
} else {
|
|
684
|
-
controller.error(
|
|
685
|
-
new (0, _chunk4XLYCT5Qcjs.DecodeError)(
|
|
686
|
-
"CONSTRAINT_VIOLATION",
|
|
687
|
-
`Unknown data stream type: 0x${firstByte.toString(16)}`,
|
|
688
|
-
0
|
|
689
|
-
)
|
|
690
|
-
);
|
|
691
|
-
return;
|
|
624
|
+
let writer = null;
|
|
625
|
+
let pump = Promise.resolve();
|
|
626
|
+
let broken = false;
|
|
627
|
+
function attach(inner, controller) {
|
|
628
|
+
writer = inner.writable.getWriter();
|
|
629
|
+
const reader = inner.readable.getReader();
|
|
630
|
+
pump = (async () => {
|
|
631
|
+
try {
|
|
632
|
+
for (; ; ) {
|
|
633
|
+
const { done, value } = await reader.read();
|
|
634
|
+
if (done) break;
|
|
635
|
+
controller.enqueue(value);
|
|
636
|
+
}
|
|
637
|
+
} catch (e) {
|
|
638
|
+
if (!broken) {
|
|
639
|
+
broken = true;
|
|
640
|
+
controller.error(e);
|
|
692
641
|
}
|
|
693
642
|
}
|
|
694
|
-
}
|
|
695
|
-
|
|
696
|
-
|
|
697
|
-
|
|
698
|
-
|
|
699
|
-
|
|
643
|
+
})();
|
|
644
|
+
}
|
|
645
|
+
async function feed(bytes) {
|
|
646
|
+
if (writer === null || broken || bytes.length === 0) return;
|
|
647
|
+
try {
|
|
648
|
+
await writer.write(bytes);
|
|
649
|
+
} catch (e2) {
|
|
650
|
+
broken = true;
|
|
651
|
+
}
|
|
652
|
+
}
|
|
653
|
+
return new TransformStream({
|
|
654
|
+
async transform(chunk, controller) {
|
|
655
|
+
if (broken) return;
|
|
656
|
+
if (writer !== null) {
|
|
657
|
+
await feed(chunk);
|
|
658
|
+
return;
|
|
659
|
+
}
|
|
660
|
+
if (chunk.length === 0) return;
|
|
661
|
+
const firstByte = chunk[0];
|
|
700
662
|
if (firstByte >= 16 && firstByte <= 31 || firstByte >= 48 && firstByte <= 63) {
|
|
701
|
-
|
|
663
|
+
attach(
|
|
664
|
+
createSubgroupStreamDecoder(),
|
|
665
|
+
controller
|
|
666
|
+
);
|
|
702
667
|
} else if (firstByte === 5) {
|
|
703
|
-
|
|
668
|
+
attach(
|
|
669
|
+
createFetchStreamDecoder(),
|
|
670
|
+
controller
|
|
671
|
+
);
|
|
704
672
|
} else {
|
|
673
|
+
broken = true;
|
|
705
674
|
controller.error(
|
|
706
|
-
new (0,
|
|
675
|
+
new (0, _chunk5IMHJIAZcjs.DecodeError)(
|
|
707
676
|
"CONSTRAINT_VIOLATION",
|
|
708
677
|
`Unknown data stream type: 0x${firstByte.toString(16)}`,
|
|
709
678
|
0
|
|
@@ -711,31 +680,15 @@ function createDataStreamDecoder() {
|
|
|
711
680
|
);
|
|
712
681
|
return;
|
|
713
682
|
}
|
|
714
|
-
|
|
715
|
-
|
|
716
|
-
|
|
717
|
-
|
|
718
|
-
|
|
719
|
-
|
|
720
|
-
|
|
721
|
-
type: "subgroup_header",
|
|
722
|
-
trackAlias: stream.trackAlias,
|
|
723
|
-
groupId: stream.groupId,
|
|
724
|
-
subgroupId: stream.subgroupId,
|
|
725
|
-
publisherPriority: stream.publisherPriority
|
|
726
|
-
});
|
|
727
|
-
for (const obj of stream.objects) {
|
|
728
|
-
controller.enqueue(obj);
|
|
729
|
-
}
|
|
730
|
-
} else if (stream.type === "fetch") {
|
|
731
|
-
controller.enqueue({
|
|
732
|
-
type: "fetch_header",
|
|
733
|
-
requestId: stream.requestId
|
|
734
|
-
});
|
|
735
|
-
for (const obj of stream.objects) {
|
|
736
|
-
controller.enqueue(obj);
|
|
737
|
-
}
|
|
683
|
+
await feed(chunk);
|
|
684
|
+
},
|
|
685
|
+
async flush() {
|
|
686
|
+
if (writer === null) return;
|
|
687
|
+
try {
|
|
688
|
+
await writer.close();
|
|
689
|
+
} catch (e3) {
|
|
738
690
|
}
|
|
691
|
+
await pump;
|
|
739
692
|
}
|
|
740
693
|
});
|
|
741
694
|
}
|
|
@@ -765,7 +718,7 @@ function encodeSetupParams(params, writer) {
|
|
|
765
718
|
}
|
|
766
719
|
for (const token of _nullishCoalesce(params.authorization_token, () => ( []))) {
|
|
767
720
|
writer.writeVarInt(SETUP_PARAM_AUTHORIZATION_TOKEN);
|
|
768
|
-
const tmpW = new (0,
|
|
721
|
+
const tmpW = new (0, _chunk5IMHJIAZcjs.BufferWriter)(64);
|
|
769
722
|
encodeAuthorizationToken(token, tmpW);
|
|
770
723
|
const raw = tmpW.finish();
|
|
771
724
|
writer.writeVarInt(raw.byteLength);
|
|
@@ -792,12 +745,12 @@ function encodeSetupParams(params, writer) {
|
|
|
792
745
|
const id = BigInt(u.id);
|
|
793
746
|
writer.writeVarInt(id);
|
|
794
747
|
if (id % 2n === 0n) {
|
|
795
|
-
const raw =
|
|
796
|
-
const tmpReader = new (0,
|
|
748
|
+
const raw = _chunk5IMHJIAZcjs.hexToBytes.call(void 0, u.raw_hex);
|
|
749
|
+
const tmpReader = new (0, _chunk5IMHJIAZcjs.BufferReader)(raw);
|
|
797
750
|
const value = tmpReader.readVarInt();
|
|
798
751
|
writer.writeVarInt(value);
|
|
799
752
|
} else {
|
|
800
|
-
const raw =
|
|
753
|
+
const raw = _chunk5IMHJIAZcjs.hexToBytes.call(void 0, u.raw_hex);
|
|
801
754
|
writer.writeVarInt(raw.byteLength);
|
|
802
755
|
writer.writeBytes(raw);
|
|
803
756
|
}
|
|
@@ -817,13 +770,13 @@ function decodeSetupParams(reader) {
|
|
|
817
770
|
} else if (paramType === SETUP_PARAM_MAX_AUTH_TOKEN_CACHE_SIZE) {
|
|
818
771
|
result.max_auth_token_cache_size = value;
|
|
819
772
|
} else {
|
|
820
|
-
const tmpWriter = new (0,
|
|
773
|
+
const tmpWriter = new (0, _chunk5IMHJIAZcjs.BufferWriter)(16);
|
|
821
774
|
tmpWriter.writeVarInt(value);
|
|
822
775
|
const raw = tmpWriter.finish();
|
|
823
776
|
unknown.push({
|
|
824
777
|
id: `0x${paramType.toString(16)}`,
|
|
825
778
|
length: raw.byteLength,
|
|
826
|
-
raw_hex:
|
|
779
|
+
raw_hex: _chunk5IMHJIAZcjs.bytesToHex.call(void 0, raw)
|
|
827
780
|
});
|
|
828
781
|
}
|
|
829
782
|
} else {
|
|
@@ -832,10 +785,9 @@ function decodeSetupParams(reader) {
|
|
|
832
785
|
if (paramType === SETUP_PARAM_PATH) {
|
|
833
786
|
result.path = textDecoder.decode(bytes);
|
|
834
787
|
} else if (paramType === SETUP_PARAM_AUTHORIZATION_TOKEN) {
|
|
835
|
-
|
|
836
|
-
|
|
837
|
-
|
|
838
|
-
];
|
|
788
|
+
const token = decodeAuthorizationToken(new (0, _chunk5IMHJIAZcjs.BufferReader)(bytes));
|
|
789
|
+
noteAuthTokenValue(reader.offset - length, length, token.token_value);
|
|
790
|
+
result.authorization_token = [..._nullishCoalesce(result.authorization_token, () => ( [])), token];
|
|
839
791
|
} else if (paramType === SETUP_PARAM_AUTHORITY) {
|
|
840
792
|
result.authority = textDecoder.decode(bytes);
|
|
841
793
|
} else if (paramType === SETUP_PARAM_MOQT_IMPLEMENTATION) {
|
|
@@ -844,7 +796,7 @@ function decodeSetupParams(reader) {
|
|
|
844
796
|
unknown.push({
|
|
845
797
|
id: `0x${paramType.toString(16)}`,
|
|
846
798
|
length,
|
|
847
|
-
raw_hex:
|
|
799
|
+
raw_hex: _chunk5IMHJIAZcjs.bytesToHex.call(void 0, bytes)
|
|
848
800
|
});
|
|
849
801
|
}
|
|
850
802
|
}
|
|
@@ -911,7 +863,7 @@ function encodeParams(params, writer) {
|
|
|
911
863
|
}
|
|
912
864
|
for (const token of _nullishCoalesce(params.authorization_token, () => ( []))) {
|
|
913
865
|
writer.writeVarInt(PARAM_AUTHORIZATION_TOKEN);
|
|
914
|
-
const tmpW = new (0,
|
|
866
|
+
const tmpW = new (0, _chunk5IMHJIAZcjs.BufferWriter)(64);
|
|
915
867
|
encodeAuthorizationToken(token, tmpW);
|
|
916
868
|
const raw = tmpW.finish();
|
|
917
869
|
writer.writeVarInt(raw.byteLength);
|
|
@@ -927,7 +879,7 @@ function encodeParams(params, writer) {
|
|
|
927
879
|
}
|
|
928
880
|
if (params.largest_object !== void 0) {
|
|
929
881
|
writer.writeVarInt(PARAM_LARGEST_OBJECT);
|
|
930
|
-
const tmpW = new (0,
|
|
882
|
+
const tmpW = new (0, _chunk5IMHJIAZcjs.BufferWriter)(16);
|
|
931
883
|
tmpW.writeVarInt(params.largest_object.group);
|
|
932
884
|
tmpW.writeVarInt(params.largest_object.object);
|
|
933
885
|
const raw = tmpW.finish();
|
|
@@ -948,7 +900,7 @@ function encodeParams(params, writer) {
|
|
|
948
900
|
}
|
|
949
901
|
if (params.subscription_filter !== void 0) {
|
|
950
902
|
writer.writeVarInt(PARAM_SUBSCRIPTION_FILTER);
|
|
951
|
-
const tmpW = new (0,
|
|
903
|
+
const tmpW = new (0, _chunk5IMHJIAZcjs.BufferWriter)(32);
|
|
952
904
|
const f = params.subscription_filter;
|
|
953
905
|
tmpW.writeVarInt(f.filter_type);
|
|
954
906
|
if (f.filter_type === 3n || f.filter_type === 4n) {
|
|
@@ -979,12 +931,12 @@ function encodeParams(params, writer) {
|
|
|
979
931
|
const id = BigInt(u.id);
|
|
980
932
|
writer.writeVarInt(id);
|
|
981
933
|
if (id % 2n === 0n) {
|
|
982
|
-
const raw =
|
|
983
|
-
const tmpReader = new (0,
|
|
934
|
+
const raw = _chunk5IMHJIAZcjs.hexToBytes.call(void 0, u.raw_hex);
|
|
935
|
+
const tmpReader = new (0, _chunk5IMHJIAZcjs.BufferReader)(raw);
|
|
984
936
|
const value = tmpReader.readVarInt();
|
|
985
937
|
writer.writeVarInt(value);
|
|
986
938
|
} else {
|
|
987
|
-
const raw =
|
|
939
|
+
const raw = _chunk5IMHJIAZcjs.hexToBytes.call(void 0, u.raw_hex);
|
|
988
940
|
writer.writeVarInt(raw.byteLength);
|
|
989
941
|
writer.writeBytes(raw);
|
|
990
942
|
}
|
|
@@ -1002,10 +954,9 @@ function decodeParams(reader) {
|
|
|
1002
954
|
} else if (paramType === PARAM_AUTHORIZATION_TOKEN) {
|
|
1003
955
|
const length = Number(reader.readVarInt());
|
|
1004
956
|
const tokenBytes = reader.readBytes(length);
|
|
1005
|
-
|
|
1006
|
-
|
|
1007
|
-
|
|
1008
|
-
];
|
|
957
|
+
const token = decodeAuthorizationToken(new (0, _chunk5IMHJIAZcjs.BufferReader)(tokenBytes));
|
|
958
|
+
noteAuthTokenValue(reader.offset - length, length, token.token_value);
|
|
959
|
+
result.authorization_token = [..._nullishCoalesce(result.authorization_token, () => ( [])), token];
|
|
1009
960
|
} else if (paramType === PARAM_MAX_CACHE_DURATION) {
|
|
1010
961
|
result.max_cache_duration = reader.readVarInt();
|
|
1011
962
|
} else if (paramType === PARAM_EXPIRES) {
|
|
@@ -1047,13 +998,13 @@ function decodeParams(reader) {
|
|
|
1047
998
|
result.subscription_filter = filter;
|
|
1048
999
|
} else if (paramType % 2n === 0n) {
|
|
1049
1000
|
const value = reader.readVarInt();
|
|
1050
|
-
const tmpWriter = new (0,
|
|
1001
|
+
const tmpWriter = new (0, _chunk5IMHJIAZcjs.BufferWriter)(16);
|
|
1051
1002
|
tmpWriter.writeVarInt(value);
|
|
1052
1003
|
const raw = tmpWriter.finish();
|
|
1053
1004
|
unknown.push({
|
|
1054
1005
|
id: `0x${paramType.toString(16)}`,
|
|
1055
1006
|
length: raw.byteLength,
|
|
1056
|
-
raw_hex:
|
|
1007
|
+
raw_hex: _chunk5IMHJIAZcjs.bytesToHex.call(void 0, raw)
|
|
1057
1008
|
});
|
|
1058
1009
|
} else {
|
|
1059
1010
|
const length = Number(reader.readVarInt());
|
|
@@ -1061,7 +1012,7 @@ function decodeParams(reader) {
|
|
|
1061
1012
|
unknown.push({
|
|
1062
1013
|
id: `0x${paramType.toString(16)}`,
|
|
1063
1014
|
length,
|
|
1064
|
-
raw_hex:
|
|
1015
|
+
raw_hex: _chunk5IMHJIAZcjs.bytesToHex.call(void 0, bytes)
|
|
1065
1016
|
});
|
|
1066
1017
|
}
|
|
1067
1018
|
}
|
|
@@ -1300,7 +1251,7 @@ function decodeFetchPayload(r) {
|
|
|
1300
1251
|
const fetch_type = r.readVarInt();
|
|
1301
1252
|
const ft = Number(fetch_type);
|
|
1302
1253
|
if (ft < 1 || ft > 3) {
|
|
1303
|
-
throw new (0,
|
|
1254
|
+
throw new (0, _chunk5IMHJIAZcjs.DecodeError)("CONSTRAINT_VIOLATION", `Invalid fetch_type: ${ft}`, r.offset);
|
|
1304
1255
|
}
|
|
1305
1256
|
let standalone;
|
|
1306
1257
|
let joining;
|
|
@@ -1419,13 +1370,13 @@ function encodeMessage(message) {
|
|
|
1419
1370
|
if (typeId === void 0) {
|
|
1420
1371
|
throw new Error(`Unknown message type: ${message.type}`);
|
|
1421
1372
|
}
|
|
1422
|
-
const payloadWriter = new (0,
|
|
1373
|
+
const payloadWriter = new (0, _chunk5IMHJIAZcjs.BufferWriter)();
|
|
1423
1374
|
encodePayload(message, payloadWriter);
|
|
1424
1375
|
const payload = payloadWriter.finishView();
|
|
1425
1376
|
if (payload.byteLength > 65535) {
|
|
1426
1377
|
throw new Error(`Payload too large for 16-bit length: ${payload.byteLength}`);
|
|
1427
1378
|
}
|
|
1428
|
-
const writer = new (0,
|
|
1379
|
+
const writer = new (0, _chunk5IMHJIAZcjs.BufferWriter)(payload.byteLength + 16);
|
|
1429
1380
|
writer.writeVarInt(typeId);
|
|
1430
1381
|
writer.writeUint8(payload.byteLength >> 8 & 255);
|
|
1431
1382
|
writer.writeUint8(payload.byteLength & 255);
|
|
@@ -1488,18 +1439,18 @@ function encodePayload(msg, w) {
|
|
|
1488
1439
|
}
|
|
1489
1440
|
function decodeMessage(bytes) {
|
|
1490
1441
|
try {
|
|
1491
|
-
const reader = new (0,
|
|
1442
|
+
const reader = new (0, _chunk5IMHJIAZcjs.BufferReader)(bytes);
|
|
1492
1443
|
const typeId = reader.readVarInt();
|
|
1493
1444
|
const lenHi = reader.readUint8();
|
|
1494
1445
|
const lenLo = reader.readUint8();
|
|
1495
1446
|
const payloadLength = lenHi << 8 | lenLo;
|
|
1496
1447
|
const payloadBytes = reader.readBytes(payloadLength);
|
|
1497
|
-
const payloadReader = new (0,
|
|
1448
|
+
const payloadReader = new (0, _chunk5IMHJIAZcjs.BufferReader)(payloadBytes);
|
|
1498
1449
|
const decoder = payloadDecoders.get(typeId);
|
|
1499
1450
|
if (!decoder) {
|
|
1500
1451
|
return {
|
|
1501
1452
|
ok: false,
|
|
1502
|
-
error: new (0,
|
|
1453
|
+
error: new (0, _chunk5IMHJIAZcjs.DecodeError)(
|
|
1503
1454
|
"UNKNOWN_MESSAGE_TYPE",
|
|
1504
1455
|
`Unknown message type ID: 0x${typeId.toString(16)}`,
|
|
1505
1456
|
0
|
|
@@ -1509,7 +1460,7 @@ function decodeMessage(bytes) {
|
|
|
1509
1460
|
const message = decoder(payloadReader);
|
|
1510
1461
|
return { ok: true, value: message, bytesRead: reader.offset };
|
|
1511
1462
|
} catch (e) {
|
|
1512
|
-
if (e instanceof
|
|
1463
|
+
if (e instanceof _chunk5IMHJIAZcjs.DecodeError) {
|
|
1513
1464
|
return { ok: false, error: e };
|
|
1514
1465
|
}
|
|
1515
1466
|
throw e;
|
|
@@ -1544,7 +1495,7 @@ function createStreamDecoder() {
|
|
|
1544
1495
|
flush(controller) {
|
|
1545
1496
|
if (offset < buffer.length) {
|
|
1546
1497
|
controller.error(
|
|
1547
|
-
new (0,
|
|
1498
|
+
new (0, _chunk5IMHJIAZcjs.DecodeError)("UNEXPECTED_END", "Stream ended with incomplete message data", 0)
|
|
1548
1499
|
);
|
|
1549
1500
|
}
|
|
1550
1501
|
}
|
|
@@ -1568,6 +1519,24 @@ function createDraft15Codec() {
|
|
|
1568
1519
|
createDataStreamDecoder
|
|
1569
1520
|
};
|
|
1570
1521
|
}
|
|
1522
|
+
function noteAuthTokenValue(valueStart, valueLength, value) {
|
|
1523
|
+
if (value === void 0 || value.byteLength === 0) return;
|
|
1524
|
+
_chunk5IMHJIAZcjs.recordAuthValueSpan.call(void 0, valueStart + valueLength - value.byteLength, value.byteLength);
|
|
1525
|
+
}
|
|
1526
|
+
function redactAuthTokens(bytes) {
|
|
1527
|
+
let payloadStart;
|
|
1528
|
+
try {
|
|
1529
|
+
const probe = new (0, _chunk5IMHJIAZcjs.BufferReader)(bytes);
|
|
1530
|
+
probe.readVarInt();
|
|
1531
|
+
probe.readUint8();
|
|
1532
|
+
probe.readUint8();
|
|
1533
|
+
payloadStart = probe.offset;
|
|
1534
|
+
} catch (e4) {
|
|
1535
|
+
return { bytes, redacted: 0, incomplete: false, decoded: false };
|
|
1536
|
+
}
|
|
1537
|
+
return _chunk5IMHJIAZcjs.redactWith.call(void 0, bytes, payloadStart, () => decodeMessage(bytes).ok);
|
|
1538
|
+
}
|
|
1539
|
+
|
|
1571
1540
|
|
|
1572
1541
|
|
|
1573
1542
|
|
|
@@ -1614,4 +1583,4 @@ function createDraft15Codec() {
|
|
|
1614
1583
|
|
|
1615
1584
|
|
|
1616
1585
|
|
|
1617
|
-
exports.MSG_SUBSCRIBE_UPDATE = MSG_SUBSCRIBE_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_PUBLISH_NAMESPACE_DONE = MSG_PUBLISH_NAMESPACE_DONE; exports.MSG_UNSUBSCRIBE = MSG_UNSUBSCRIBE; exports.MSG_PUBLISH_DONE = MSG_PUBLISH_DONE; exports.MSG_PUBLISH_NAMESPACE_CANCEL = MSG_PUBLISH_NAMESPACE_CANCEL; exports.MSG_TRACK_STATUS = MSG_TRACK_STATUS; exports.MSG_GOAWAY = MSG_GOAWAY; exports.MSG_SUBSCRIBE_NAMESPACE = MSG_SUBSCRIBE_NAMESPACE; exports.MSG_UNSUBSCRIBE_NAMESPACE = MSG_UNSUBSCRIBE_NAMESPACE; exports.MSG_MAX_REQUEST_ID = MSG_MAX_REQUEST_ID; exports.MSG_FETCH = MSG_FETCH; exports.MSG_FETCH_CANCEL = MSG_FETCH_CANCEL; exports.MSG_FETCH_OK = MSG_FETCH_OK; exports.MSG_REQUESTS_BLOCKED = MSG_REQUESTS_BLOCKED; exports.MSG_PUBLISH = MSG_PUBLISH; exports.MSG_PUBLISH_OK = MSG_PUBLISH_OK; exports.MSG_CLIENT_SETUP = MSG_CLIENT_SETUP; exports.MSG_SERVER_SETUP = MSG_SERVER_SETUP; exports.SETUP_PARAM_PATH = SETUP_PARAM_PATH; exports.SETUP_PARAM_MAX_REQUEST_ID = SETUP_PARAM_MAX_REQUEST_ID; exports.SETUP_PARAM_MAX_AUTH_TOKEN_CACHE_SIZE = SETUP_PARAM_MAX_AUTH_TOKEN_CACHE_SIZE; exports.SETUP_PARAM_AUTHORITY = SETUP_PARAM_AUTHORITY; exports.SETUP_PARAM_MOQT_IMPLEMENTATION = SETUP_PARAM_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.createDraft15Codec = createDraft15Codec;
|
|
1586
|
+
exports.MSG_SUBSCRIBE_UPDATE = MSG_SUBSCRIBE_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_PUBLISH_NAMESPACE_DONE = MSG_PUBLISH_NAMESPACE_DONE; exports.MSG_UNSUBSCRIBE = MSG_UNSUBSCRIBE; exports.MSG_PUBLISH_DONE = MSG_PUBLISH_DONE; exports.MSG_PUBLISH_NAMESPACE_CANCEL = MSG_PUBLISH_NAMESPACE_CANCEL; exports.MSG_TRACK_STATUS = MSG_TRACK_STATUS; exports.MSG_GOAWAY = MSG_GOAWAY; exports.MSG_SUBSCRIBE_NAMESPACE = MSG_SUBSCRIBE_NAMESPACE; exports.MSG_UNSUBSCRIBE_NAMESPACE = MSG_UNSUBSCRIBE_NAMESPACE; exports.MSG_MAX_REQUEST_ID = MSG_MAX_REQUEST_ID; exports.MSG_FETCH = MSG_FETCH; exports.MSG_FETCH_CANCEL = MSG_FETCH_CANCEL; exports.MSG_FETCH_OK = MSG_FETCH_OK; exports.MSG_REQUESTS_BLOCKED = MSG_REQUESTS_BLOCKED; exports.MSG_PUBLISH = MSG_PUBLISH; exports.MSG_PUBLISH_OK = MSG_PUBLISH_OK; exports.MSG_CLIENT_SETUP = MSG_CLIENT_SETUP; exports.MSG_SERVER_SETUP = MSG_SERVER_SETUP; exports.SETUP_PARAM_PATH = SETUP_PARAM_PATH; exports.SETUP_PARAM_MAX_REQUEST_ID = SETUP_PARAM_MAX_REQUEST_ID; exports.SETUP_PARAM_MAX_AUTH_TOKEN_CACHE_SIZE = SETUP_PARAM_MAX_AUTH_TOKEN_CACHE_SIZE; exports.SETUP_PARAM_AUTHORITY = SETUP_PARAM_AUTHORITY; exports.SETUP_PARAM_MOQT_IMPLEMENTATION = SETUP_PARAM_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.createDraft15Codec = createDraft15Codec; exports.redactAuthTokens = redactAuthTokens;
|