@moqtap/codec 0.8.0 → 0.8.1
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/dist/{chunk-5XZKO2U5.js → chunk-2XH6PHXR.js} +62 -51
- package/dist/{chunk-APTV6F72.js → chunk-3YAR3I3S.js} +67 -51
- package/dist/{chunk-BQHLUT37.cjs → chunk-7ENEWAMZ.cjs} +2 -6
- package/dist/{chunk-MD2OA7SE.js → chunk-BV6MITLO.js} +15 -8
- package/dist/{chunk-B56AG5HU.cjs → chunk-EVCPBFSR.cjs} +6 -4
- package/dist/{chunk-KNLPX3YA.js → chunk-H6DTAIWM.js} +6 -4
- package/dist/{chunk-J3ASFPCX.cjs → chunk-IADVBKEJ.cjs} +15 -8
- package/dist/{chunk-I55J3KXD.js → chunk-NH4L6NIY.js} +48 -33
- package/dist/{chunk-EQAYMCXO.cjs → chunk-PU2KV7VP.cjs} +48 -33
- package/dist/{chunk-HEO2JG6C.js → chunk-TMXRYOBS.js} +100 -92
- package/dist/{chunk-IEJULBKB.cjs → chunk-UA5XFP4O.cjs} +100 -92
- package/dist/{chunk-KTVN4P6J.cjs → chunk-UZO5Z2XT.cjs} +62 -51
- package/dist/{chunk-MH7537FB.cjs → chunk-VWXUT5R2.cjs} +67 -51
- package/dist/{chunk-JJEN2VG5.js → chunk-XQGEOFGE.js} +2 -6
- package/dist/{codec-BnamSx7L.d.cts → codec-N3g1lxQQ.d.cts} +1 -1
- package/dist/{codec-CFhUGTu2.d.ts → codec-v6Vloc7H.d.ts} +1 -1
- package/dist/draft12.cjs +2 -2
- package/dist/draft12.js +1 -1
- package/dist/draft14-session.d.cts +1 -1
- package/dist/draft14-session.d.ts +1 -1
- package/dist/draft14.cjs +2 -2
- package/dist/draft14.d.cts +3 -3
- package/dist/draft14.d.ts +3 -3
- package/dist/draft14.js +1 -1
- package/dist/draft15.cjs +2 -2
- package/dist/draft15.js +1 -1
- package/dist/draft16.cjs +2 -2
- package/dist/draft16.js +1 -1
- package/dist/draft17.cjs +2 -2
- package/dist/draft17.js +1 -1
- package/dist/draft18.cjs +2 -2
- package/dist/draft18.js +1 -1
- package/dist/draft19.cjs +2 -2
- package/dist/draft19.js +1 -1
- package/dist/index.cjs +14 -14
- package/dist/index.d.cts +2 -2
- package/dist/index.d.ts +2 -2
- package/dist/index.js +7 -7
- package/dist/session.d.cts +1 -1
- package/dist/session.d.ts +1 -1
- package/dist/{types-CVeKIk7A.d.cts → types-HI_bbXka.d.cts} +0 -2
- package/dist/{types-CVeKIk7A.d.ts → types-HI_bbXka.d.ts} +0 -2
- package/package.json +2 -2
- package/src/drafts/draft12/data-streams.ts +13 -4
- package/src/drafts/draft14/codec.ts +2 -6
- package/src/drafts/draft14/types.ts +0 -2
- package/src/drafts/draft15/data-streams.ts +30 -16
- package/src/drafts/draft16/codec.ts +116 -93
- package/src/drafts/draft17/codec.ts +72 -35
- package/src/drafts/draft18/codec.ts +89 -53
- package/src/drafts/draft19/codec.ts +94 -53
|
@@ -46,7 +46,7 @@ function encodeDatagram(dg) {
|
|
|
46
46
|
w.writeVarInt(extData.byteLength);
|
|
47
47
|
if (extData.byteLength > 0) w.writeBytes(extData);
|
|
48
48
|
}
|
|
49
|
-
const isStatus = dg.streamTypeId
|
|
49
|
+
const isStatus = dg.streamTypeId >= 4;
|
|
50
50
|
if (isStatus) {
|
|
51
51
|
w.writeVarInt(dg.objectStatus ?? 0n);
|
|
52
52
|
} else {
|
|
@@ -162,18 +162,19 @@ function decodeDatagram(bytes) {
|
|
|
162
162
|
try {
|
|
163
163
|
const r = new BufferReader(bytes);
|
|
164
164
|
const streamTypeId = Number(r.readVarInt());
|
|
165
|
-
if (streamTypeId < 0 || streamTypeId >
|
|
165
|
+
if (streamTypeId < 0 || streamTypeId > 5) {
|
|
166
166
|
return {
|
|
167
167
|
ok: false,
|
|
168
168
|
error: new DecodeError(
|
|
169
169
|
"CONSTRAINT_VIOLATION",
|
|
170
|
-
`Expected datagram type 0x00-
|
|
170
|
+
`Expected datagram type 0x00-0x05, got 0x${streamTypeId.toString(16)}`,
|
|
171
171
|
0
|
|
172
172
|
)
|
|
173
173
|
};
|
|
174
174
|
}
|
|
175
175
|
const extensionsPresent = (streamTypeId & 1) !== 0;
|
|
176
|
-
const
|
|
176
|
+
const endOfGroup = (streamTypeId & 2) !== 0 && streamTypeId < 4;
|
|
177
|
+
const isStatus = streamTypeId >= 4;
|
|
177
178
|
const trackAlias = r.readVarInt();
|
|
178
179
|
const groupId = r.readVarInt();
|
|
179
180
|
const objectId = r.readVarInt();
|
|
@@ -202,6 +203,7 @@ function decodeDatagram(bytes) {
|
|
|
202
203
|
payloadLength: payload.byteLength,
|
|
203
204
|
payload
|
|
204
205
|
};
|
|
206
|
+
if (endOfGroup) result.endOfGroup = true;
|
|
205
207
|
if (extensionHeadersLength !== void 0)
|
|
206
208
|
result.extensionHeadersLength = extensionHeadersLength;
|
|
207
209
|
if (extensionData !== void 0)
|
|
@@ -108,11 +108,14 @@ function encodeDatagram(dg) {
|
|
|
108
108
|
w.writeVarInt(dg.groupId);
|
|
109
109
|
const extensionsPresent = (dgType & 1) !== 0;
|
|
110
110
|
const objectIdAbsent = (dgType & 4) !== 0;
|
|
111
|
+
const defaultPriority = (dgType & 8) !== 0;
|
|
111
112
|
const isStatus = (dgType & 32) !== 0;
|
|
112
113
|
if (!objectIdAbsent) {
|
|
113
114
|
w.writeVarInt(dg.objectId);
|
|
114
115
|
}
|
|
115
|
-
|
|
116
|
+
if (!defaultPriority) {
|
|
117
|
+
w.writeUint8(dg.publisherPriority);
|
|
118
|
+
}
|
|
116
119
|
if (extensionsPresent) {
|
|
117
120
|
const extData = _nullishCoalesce(dg.extensionData, () => ( new Uint8Array(0)));
|
|
118
121
|
w.writeVarInt(BigInt(extData.length));
|
|
@@ -154,18 +157,18 @@ function decodeSubgroupStream(bytes) {
|
|
|
154
157
|
try {
|
|
155
158
|
const r = new (0, _chunk4XLYCT5Qcjs.BufferReader)(bytes);
|
|
156
159
|
const streamType = Number(r.readVarInt());
|
|
157
|
-
if (!(streamType >= 16 && streamType <=
|
|
160
|
+
if (!(streamType >= 16 && streamType <= 31 || streamType >= 48 && streamType <= 63) || (streamType & 6) === 6) {
|
|
158
161
|
return {
|
|
159
162
|
ok: false,
|
|
160
163
|
error: new (0, _chunk4XLYCT5Qcjs.DecodeError)(
|
|
161
164
|
"CONSTRAINT_VIOLATION",
|
|
162
|
-
`Expected subgroup stream type 0x10-
|
|
165
|
+
`Expected subgroup stream type 0x10-0x1F/0x30-0x3F, got 0x${streamType.toString(16)}`,
|
|
163
166
|
0
|
|
164
167
|
)
|
|
165
168
|
};
|
|
166
169
|
}
|
|
167
170
|
const extensionsPresent = (streamType & 1) !== 0;
|
|
168
|
-
const endOfGroup = (streamType &
|
|
171
|
+
const endOfGroup = (streamType & 8) !== 0;
|
|
169
172
|
const hasSubgroupField = (streamType & 4) !== 0;
|
|
170
173
|
const hasPriority = streamType < 48;
|
|
171
174
|
const trackAlias = r.readVarInt();
|
|
@@ -248,6 +251,7 @@ function decodeDatagram(bytes) {
|
|
|
248
251
|
const extensionsPresent = (dgType & 1) !== 0;
|
|
249
252
|
const objectIdAbsent = (dgType & 4) !== 0;
|
|
250
253
|
const endOfGroup = (dgType & 2) !== 0;
|
|
254
|
+
const defaultPriority = (dgType & 8) !== 0;
|
|
251
255
|
const isStatus = (dgType & 32) !== 0;
|
|
252
256
|
const trackAlias = r.readVarInt();
|
|
253
257
|
const groupId = r.readVarInt();
|
|
@@ -255,7 +259,10 @@ function decodeDatagram(bytes) {
|
|
|
255
259
|
if (!objectIdAbsent) {
|
|
256
260
|
objectId = r.readVarInt();
|
|
257
261
|
}
|
|
258
|
-
|
|
262
|
+
let publisherPriority = 128;
|
|
263
|
+
if (!defaultPriority) {
|
|
264
|
+
publisherPriority = r.readUint8();
|
|
265
|
+
}
|
|
259
266
|
let extensionData;
|
|
260
267
|
if (extensionsPresent) {
|
|
261
268
|
const extLen = Number(r.readVarInt());
|
|
@@ -472,7 +479,7 @@ function createSubgroupStreamDecoder() {
|
|
|
472
479
|
try {
|
|
473
480
|
const r = new (0, _chunk4XLYCT5Qcjs.BufferReader)(buffer.subarray(offset));
|
|
474
481
|
const streamType = Number(r.readVarInt());
|
|
475
|
-
if (!(streamType >= 16 && streamType <=
|
|
482
|
+
if (!(streamType >= 16 && streamType <= 31 || streamType >= 48 && streamType <= 63)) {
|
|
476
483
|
controller.error(
|
|
477
484
|
new (0, _chunk4XLYCT5Qcjs.DecodeError)(
|
|
478
485
|
"CONSTRAINT_VIOLATION",
|
|
@@ -667,7 +674,7 @@ function createDataStreamDecoder() {
|
|
|
667
674
|
if (inner === null) {
|
|
668
675
|
if (offset >= buffer.length) return;
|
|
669
676
|
const firstByte = buffer[offset];
|
|
670
|
-
if (firstByte >= 16 && firstByte <=
|
|
677
|
+
if (firstByte >= 16 && firstByte <= 31 || firstByte >= 48 && firstByte <= 63) {
|
|
671
678
|
const decoder = createSubgroupStreamDecoder();
|
|
672
679
|
inner = decoder;
|
|
673
680
|
} else if (firstByte === 5) {
|
|
@@ -690,7 +697,7 @@ function createDataStreamDecoder() {
|
|
|
690
697
|
const view = buffer.subarray(offset);
|
|
691
698
|
const firstByte = view[0];
|
|
692
699
|
let result;
|
|
693
|
-
if (firstByte >= 16 && firstByte <=
|
|
700
|
+
if (firstByte >= 16 && firstByte <= 31 || firstByte >= 48 && firstByte <= 63) {
|
|
694
701
|
result = decodeSubgroupStream(view);
|
|
695
702
|
} else if (firstByte === 5) {
|
|
696
703
|
result = decodeFetchStream(view);
|
|
@@ -1060,6 +1060,29 @@ var PARAM_SUBSCRIBER_PRIORITY = 0x20n;
|
|
|
1060
1060
|
var PARAM_SUBSCRIPTION_FILTER = 0x21n;
|
|
1061
1061
|
var PARAM_GROUP_ORDER = 0x22n;
|
|
1062
1062
|
var PARAM_NEW_GROUP_REQUEST = 0x32n;
|
|
1063
|
+
var PARAMETER_SCOPE = /* @__PURE__ */ new Map([
|
|
1064
|
+
[0x02n, /* @__PURE__ */ new Set(["publish_ok", "subscribe", "request_update"])],
|
|
1065
|
+
[
|
|
1066
|
+
0x03n,
|
|
1067
|
+
/* @__PURE__ */ new Set([
|
|
1068
|
+
"publish",
|
|
1069
|
+
"subscribe",
|
|
1070
|
+
"request_update",
|
|
1071
|
+
"subscribe_namespace",
|
|
1072
|
+
"publish_namespace",
|
|
1073
|
+
"track_status",
|
|
1074
|
+
"fetch"
|
|
1075
|
+
])
|
|
1076
|
+
],
|
|
1077
|
+
[0x04n, /* @__PURE__ */ new Set(["subscribe"])],
|
|
1078
|
+
[0x08n, /* @__PURE__ */ new Set(["subscribe_ok", "publish", "publish_ok", "request_ok"])],
|
|
1079
|
+
[0x09n, /* @__PURE__ */ new Set(["subscribe_ok", "publish", "request_ok"])],
|
|
1080
|
+
[0x10n, /* @__PURE__ */ new Set(["subscribe", "request_update", "publish", "publish_ok", "subscribe_namespace"])],
|
|
1081
|
+
[0x20n, /* @__PURE__ */ new Set(["subscribe", "fetch", "request_update", "publish_ok"])],
|
|
1082
|
+
[0x21n, /* @__PURE__ */ new Set(["subscribe", "publish_ok", "request_update"])],
|
|
1083
|
+
[0x22n, /* @__PURE__ */ new Set(["subscribe", "publish_ok", "fetch"])],
|
|
1084
|
+
[0x32n, /* @__PURE__ */ new Set(["publish_ok", "subscribe", "request_update"])]
|
|
1085
|
+
]);
|
|
1063
1086
|
function encodeParams(params, writer) {
|
|
1064
1087
|
const entries = [];
|
|
1065
1088
|
if (params.delivery_timeout !== void 0) {
|
|
@@ -1166,15 +1189,22 @@ function encodeParams(params, writer) {
|
|
|
1166
1189
|
prevType = entry.type;
|
|
1167
1190
|
}
|
|
1168
1191
|
}
|
|
1169
|
-
function decodeParams(reader) {
|
|
1192
|
+
function decodeParams(reader, messageType) {
|
|
1170
1193
|
const count = Number(reader.readVarInt());
|
|
1171
1194
|
const result = {};
|
|
1172
|
-
const unknown = [];
|
|
1173
1195
|
let prevType = 0n;
|
|
1174
1196
|
for (let i = 0; i < count; i++) {
|
|
1175
1197
|
const delta = reader.readVarInt();
|
|
1176
1198
|
const paramType = prevType + delta;
|
|
1177
1199
|
prevType = paramType;
|
|
1200
|
+
const scope = PARAMETER_SCOPE.get(paramType);
|
|
1201
|
+
if (scope !== void 0 && !scope.has(messageType)) {
|
|
1202
|
+
throw new DecodeError(
|
|
1203
|
+
"CONSTRAINT_VIOLATION",
|
|
1204
|
+
`Message Parameter 0x${paramType.toString(16)} may not appear in ${messageType}`,
|
|
1205
|
+
reader.offset
|
|
1206
|
+
);
|
|
1207
|
+
}
|
|
1178
1208
|
if (paramType === PARAM_DELIVERY_TIMEOUT) {
|
|
1179
1209
|
result.delivery_timeout = reader.readVarInt();
|
|
1180
1210
|
} else if (paramType === PARAM_AUTHORIZATION_TOKEN) {
|
|
@@ -1213,28 +1243,13 @@ function decodeParams(reader) {
|
|
|
1213
1243
|
} else if (paramType === PARAM_NEW_GROUP_REQUEST) {
|
|
1214
1244
|
result.new_group_request = reader.readVarInt();
|
|
1215
1245
|
} else {
|
|
1216
|
-
|
|
1217
|
-
|
|
1218
|
-
|
|
1219
|
-
|
|
1220
|
-
|
|
1221
|
-
unknown.push({
|
|
1222
|
-
id: `0x${paramType.toString(16)}`,
|
|
1223
|
-
length: raw.byteLength,
|
|
1224
|
-
raw_hex: bytesToHex(raw)
|
|
1225
|
-
});
|
|
1226
|
-
} else {
|
|
1227
|
-
const length = Number(reader.readVarInt());
|
|
1228
|
-
const bytes = reader.readBytes(length);
|
|
1229
|
-
unknown.push({
|
|
1230
|
-
id: `0x${paramType.toString(16)}`,
|
|
1231
|
-
length,
|
|
1232
|
-
raw_hex: bytesToHex(bytes)
|
|
1233
|
-
});
|
|
1234
|
-
}
|
|
1246
|
+
throw new DecodeError(
|
|
1247
|
+
"INVALID_PARAMETER",
|
|
1248
|
+
`Unknown Message Parameter type 0x${paramType.toString(16)}`,
|
|
1249
|
+
reader.offset
|
|
1250
|
+
);
|
|
1235
1251
|
}
|
|
1236
1252
|
}
|
|
1237
|
-
if (unknown.length > 0) result.unknown = unknown;
|
|
1238
1253
|
return result;
|
|
1239
1254
|
}
|
|
1240
1255
|
var TPROP_DELIVERY_TIMEOUT = 0x02n;
|
|
@@ -1472,7 +1487,7 @@ function decodeSubscribePayload(r) {
|
|
|
1472
1487
|
const required_request_id_delta = r.readVarInt();
|
|
1473
1488
|
const track_namespace = r.readTuple();
|
|
1474
1489
|
const track_name = r.readString();
|
|
1475
|
-
const parameters = decodeParams(r);
|
|
1490
|
+
const parameters = decodeParams(r, "subscribe");
|
|
1476
1491
|
return {
|
|
1477
1492
|
type: "subscribe",
|
|
1478
1493
|
request_id,
|
|
@@ -1484,14 +1499,14 @@ function decodeSubscribePayload(r) {
|
|
|
1484
1499
|
}
|
|
1485
1500
|
function decodeSubscribeOkPayload(r, payloadEnd) {
|
|
1486
1501
|
const track_alias = r.readVarInt();
|
|
1487
|
-
const parameters = decodeParams(r);
|
|
1502
|
+
const parameters = decodeParams(r, "subscribe_ok");
|
|
1488
1503
|
const track_properties = decodeTrackProperties(r, payloadEnd);
|
|
1489
1504
|
return { type: "subscribe_ok", track_alias, parameters, track_properties };
|
|
1490
1505
|
}
|
|
1491
1506
|
function decodeRequestUpdatePayload(r) {
|
|
1492
1507
|
const request_id = r.readVarInt();
|
|
1493
1508
|
const required_request_id_delta = r.readVarInt();
|
|
1494
|
-
const parameters = decodeParams(r);
|
|
1509
|
+
const parameters = decodeParams(r, "request_update");
|
|
1495
1510
|
return {
|
|
1496
1511
|
type: "request_update",
|
|
1497
1512
|
request_id,
|
|
@@ -1505,7 +1520,7 @@ function decodePublishPayload(r, payloadEnd) {
|
|
|
1505
1520
|
const track_namespace = r.readTuple();
|
|
1506
1521
|
const track_name = r.readString();
|
|
1507
1522
|
const track_alias = r.readVarInt();
|
|
1508
|
-
const parameters = decodeParams(r);
|
|
1523
|
+
const parameters = decodeParams(r, "publish");
|
|
1509
1524
|
const track_properties = decodeTrackProperties(r, payloadEnd);
|
|
1510
1525
|
return {
|
|
1511
1526
|
type: "publish",
|
|
@@ -1519,7 +1534,7 @@ function decodePublishPayload(r, payloadEnd) {
|
|
|
1519
1534
|
};
|
|
1520
1535
|
}
|
|
1521
1536
|
function decodePublishOkPayload(r) {
|
|
1522
|
-
const parameters = decodeParams(r);
|
|
1537
|
+
const parameters = decodeParams(r, "publish_ok");
|
|
1523
1538
|
return { type: "publish_ok", parameters };
|
|
1524
1539
|
}
|
|
1525
1540
|
function decodePublishDonePayload(r) {
|
|
@@ -1532,7 +1547,7 @@ function decodePublishNamespacePayload(r) {
|
|
|
1532
1547
|
const request_id = r.readVarInt();
|
|
1533
1548
|
const required_request_id_delta = r.readVarInt();
|
|
1534
1549
|
const track_namespace = r.readTuple();
|
|
1535
|
-
const parameters = decodeParams(r);
|
|
1550
|
+
const parameters = decodeParams(r, "publish_namespace");
|
|
1536
1551
|
return {
|
|
1537
1552
|
type: "publish_namespace",
|
|
1538
1553
|
request_id,
|
|
@@ -1554,7 +1569,7 @@ function decodeSubscribeNamespacePayload(r) {
|
|
|
1554
1569
|
const required_request_id_delta = r.readVarInt();
|
|
1555
1570
|
const namespace_prefix = r.readTuple();
|
|
1556
1571
|
const subscribe_options = r.readVarInt();
|
|
1557
|
-
const parameters = decodeParams(r);
|
|
1572
|
+
const parameters = decodeParams(r, "subscribe_namespace");
|
|
1558
1573
|
return {
|
|
1559
1574
|
type: "subscribe_namespace",
|
|
1560
1575
|
request_id,
|
|
@@ -1599,7 +1614,7 @@ function decodeFetchPayload(r) {
|
|
|
1599
1614
|
const joining_start = r.readVarInt();
|
|
1600
1615
|
joining = { joining_request_id, joining_start };
|
|
1601
1616
|
}
|
|
1602
|
-
const parameters = decodeParams(r);
|
|
1617
|
+
const parameters = decodeParams(r, "fetch");
|
|
1603
1618
|
return {
|
|
1604
1619
|
type: "fetch",
|
|
1605
1620
|
request_id,
|
|
@@ -1614,7 +1629,7 @@ function decodeFetchOkPayload(r, payloadEnd) {
|
|
|
1614
1629
|
const end_of_track = r.readUint8();
|
|
1615
1630
|
const end_group = r.readVarInt();
|
|
1616
1631
|
const end_object = r.readVarInt();
|
|
1617
|
-
const parameters = decodeParams(r);
|
|
1632
|
+
const parameters = decodeParams(r, "fetch_ok");
|
|
1618
1633
|
const track_properties = decodeTrackProperties(r, payloadEnd);
|
|
1619
1634
|
return {
|
|
1620
1635
|
type: "fetch_ok",
|
|
@@ -1630,7 +1645,7 @@ function decodeTrackStatusPayload(r) {
|
|
|
1630
1645
|
const required_request_id_delta = r.readVarInt();
|
|
1631
1646
|
const track_namespace = r.readTuple();
|
|
1632
1647
|
const track_name = r.readString();
|
|
1633
|
-
const parameters = decodeParams(r);
|
|
1648
|
+
const parameters = decodeParams(r, "track_status");
|
|
1634
1649
|
return {
|
|
1635
1650
|
type: "track_status",
|
|
1636
1651
|
request_id,
|
|
@@ -1641,7 +1656,7 @@ function decodeTrackStatusPayload(r) {
|
|
|
1641
1656
|
};
|
|
1642
1657
|
}
|
|
1643
1658
|
function decodeRequestOkPayload(r) {
|
|
1644
|
-
const parameters = decodeParams(r);
|
|
1659
|
+
const parameters = decodeParams(r, "request_ok");
|
|
1645
1660
|
return { type: "request_ok", parameters };
|
|
1646
1661
|
}
|
|
1647
1662
|
function decodeRequestErrorPayload(r) {
|
|
@@ -1060,6 +1060,29 @@ var PARAM_SUBSCRIBER_PRIORITY = 0x20n;
|
|
|
1060
1060
|
var PARAM_SUBSCRIPTION_FILTER = 0x21n;
|
|
1061
1061
|
var PARAM_GROUP_ORDER = 0x22n;
|
|
1062
1062
|
var PARAM_NEW_GROUP_REQUEST = 0x32n;
|
|
1063
|
+
var PARAMETER_SCOPE = /* @__PURE__ */ new Map([
|
|
1064
|
+
[0x02n, /* @__PURE__ */ new Set(["publish_ok", "subscribe", "request_update"])],
|
|
1065
|
+
[
|
|
1066
|
+
0x03n,
|
|
1067
|
+
/* @__PURE__ */ new Set([
|
|
1068
|
+
"publish",
|
|
1069
|
+
"subscribe",
|
|
1070
|
+
"request_update",
|
|
1071
|
+
"subscribe_namespace",
|
|
1072
|
+
"publish_namespace",
|
|
1073
|
+
"track_status",
|
|
1074
|
+
"fetch"
|
|
1075
|
+
])
|
|
1076
|
+
],
|
|
1077
|
+
[0x04n, /* @__PURE__ */ new Set(["subscribe"])],
|
|
1078
|
+
[0x08n, /* @__PURE__ */ new Set(["subscribe_ok", "publish", "publish_ok", "request_ok"])],
|
|
1079
|
+
[0x09n, /* @__PURE__ */ new Set(["subscribe_ok", "publish", "request_ok"])],
|
|
1080
|
+
[0x10n, /* @__PURE__ */ new Set(["subscribe", "request_update", "publish", "publish_ok", "subscribe_namespace"])],
|
|
1081
|
+
[0x20n, /* @__PURE__ */ new Set(["subscribe", "fetch", "request_update", "publish_ok"])],
|
|
1082
|
+
[0x21n, /* @__PURE__ */ new Set(["subscribe", "publish_ok", "request_update"])],
|
|
1083
|
+
[0x22n, /* @__PURE__ */ new Set(["subscribe", "publish_ok", "fetch"])],
|
|
1084
|
+
[0x32n, /* @__PURE__ */ new Set(["publish_ok", "subscribe", "request_update"])]
|
|
1085
|
+
]);
|
|
1063
1086
|
function encodeParams(params, writer) {
|
|
1064
1087
|
const entries = [];
|
|
1065
1088
|
if (params.delivery_timeout !== void 0) {
|
|
@@ -1166,15 +1189,22 @@ function encodeParams(params, writer) {
|
|
|
1166
1189
|
prevType = entry.type;
|
|
1167
1190
|
}
|
|
1168
1191
|
}
|
|
1169
|
-
function decodeParams(reader) {
|
|
1192
|
+
function decodeParams(reader, messageType) {
|
|
1170
1193
|
const count = Number(reader.readVarInt());
|
|
1171
1194
|
const result = {};
|
|
1172
|
-
const unknown = [];
|
|
1173
1195
|
let prevType = 0n;
|
|
1174
1196
|
for (let i = 0; i < count; i++) {
|
|
1175
1197
|
const delta = reader.readVarInt();
|
|
1176
1198
|
const paramType = prevType + delta;
|
|
1177
1199
|
prevType = paramType;
|
|
1200
|
+
const scope = PARAMETER_SCOPE.get(paramType);
|
|
1201
|
+
if (scope !== void 0 && !scope.has(messageType)) {
|
|
1202
|
+
throw new (0, _chunk4XLYCT5Qcjs.DecodeError)(
|
|
1203
|
+
"CONSTRAINT_VIOLATION",
|
|
1204
|
+
`Message Parameter 0x${paramType.toString(16)} may not appear in ${messageType}`,
|
|
1205
|
+
reader.offset
|
|
1206
|
+
);
|
|
1207
|
+
}
|
|
1178
1208
|
if (paramType === PARAM_DELIVERY_TIMEOUT) {
|
|
1179
1209
|
result.delivery_timeout = reader.readVarInt();
|
|
1180
1210
|
} else if (paramType === PARAM_AUTHORIZATION_TOKEN) {
|
|
@@ -1213,28 +1243,13 @@ function decodeParams(reader) {
|
|
|
1213
1243
|
} else if (paramType === PARAM_NEW_GROUP_REQUEST) {
|
|
1214
1244
|
result.new_group_request = reader.readVarInt();
|
|
1215
1245
|
} else {
|
|
1216
|
-
|
|
1217
|
-
|
|
1218
|
-
|
|
1219
|
-
|
|
1220
|
-
|
|
1221
|
-
unknown.push({
|
|
1222
|
-
id: `0x${paramType.toString(16)}`,
|
|
1223
|
-
length: raw.byteLength,
|
|
1224
|
-
raw_hex: _chunk4XLYCT5Qcjs.bytesToHex.call(void 0, raw)
|
|
1225
|
-
});
|
|
1226
|
-
} else {
|
|
1227
|
-
const length = Number(reader.readVarInt());
|
|
1228
|
-
const bytes = reader.readBytes(length);
|
|
1229
|
-
unknown.push({
|
|
1230
|
-
id: `0x${paramType.toString(16)}`,
|
|
1231
|
-
length,
|
|
1232
|
-
raw_hex: _chunk4XLYCT5Qcjs.bytesToHex.call(void 0, bytes)
|
|
1233
|
-
});
|
|
1234
|
-
}
|
|
1246
|
+
throw new (0, _chunk4XLYCT5Qcjs.DecodeError)(
|
|
1247
|
+
"INVALID_PARAMETER",
|
|
1248
|
+
`Unknown Message Parameter type 0x${paramType.toString(16)}`,
|
|
1249
|
+
reader.offset
|
|
1250
|
+
);
|
|
1235
1251
|
}
|
|
1236
1252
|
}
|
|
1237
|
-
if (unknown.length > 0) result.unknown = unknown;
|
|
1238
1253
|
return result;
|
|
1239
1254
|
}
|
|
1240
1255
|
var TPROP_DELIVERY_TIMEOUT = 0x02n;
|
|
@@ -1472,7 +1487,7 @@ function decodeSubscribePayload(r) {
|
|
|
1472
1487
|
const required_request_id_delta = r.readVarInt();
|
|
1473
1488
|
const track_namespace = r.readTuple();
|
|
1474
1489
|
const track_name = r.readString();
|
|
1475
|
-
const parameters = decodeParams(r);
|
|
1490
|
+
const parameters = decodeParams(r, "subscribe");
|
|
1476
1491
|
return {
|
|
1477
1492
|
type: "subscribe",
|
|
1478
1493
|
request_id,
|
|
@@ -1484,14 +1499,14 @@ function decodeSubscribePayload(r) {
|
|
|
1484
1499
|
}
|
|
1485
1500
|
function decodeSubscribeOkPayload(r, payloadEnd) {
|
|
1486
1501
|
const track_alias = r.readVarInt();
|
|
1487
|
-
const parameters = decodeParams(r);
|
|
1502
|
+
const parameters = decodeParams(r, "subscribe_ok");
|
|
1488
1503
|
const track_properties = decodeTrackProperties(r, payloadEnd);
|
|
1489
1504
|
return { type: "subscribe_ok", track_alias, parameters, track_properties };
|
|
1490
1505
|
}
|
|
1491
1506
|
function decodeRequestUpdatePayload(r) {
|
|
1492
1507
|
const request_id = r.readVarInt();
|
|
1493
1508
|
const required_request_id_delta = r.readVarInt();
|
|
1494
|
-
const parameters = decodeParams(r);
|
|
1509
|
+
const parameters = decodeParams(r, "request_update");
|
|
1495
1510
|
return {
|
|
1496
1511
|
type: "request_update",
|
|
1497
1512
|
request_id,
|
|
@@ -1505,7 +1520,7 @@ function decodePublishPayload(r, payloadEnd) {
|
|
|
1505
1520
|
const track_namespace = r.readTuple();
|
|
1506
1521
|
const track_name = r.readString();
|
|
1507
1522
|
const track_alias = r.readVarInt();
|
|
1508
|
-
const parameters = decodeParams(r);
|
|
1523
|
+
const parameters = decodeParams(r, "publish");
|
|
1509
1524
|
const track_properties = decodeTrackProperties(r, payloadEnd);
|
|
1510
1525
|
return {
|
|
1511
1526
|
type: "publish",
|
|
@@ -1519,7 +1534,7 @@ function decodePublishPayload(r, payloadEnd) {
|
|
|
1519
1534
|
};
|
|
1520
1535
|
}
|
|
1521
1536
|
function decodePublishOkPayload(r) {
|
|
1522
|
-
const parameters = decodeParams(r);
|
|
1537
|
+
const parameters = decodeParams(r, "publish_ok");
|
|
1523
1538
|
return { type: "publish_ok", parameters };
|
|
1524
1539
|
}
|
|
1525
1540
|
function decodePublishDonePayload(r) {
|
|
@@ -1532,7 +1547,7 @@ function decodePublishNamespacePayload(r) {
|
|
|
1532
1547
|
const request_id = r.readVarInt();
|
|
1533
1548
|
const required_request_id_delta = r.readVarInt();
|
|
1534
1549
|
const track_namespace = r.readTuple();
|
|
1535
|
-
const parameters = decodeParams(r);
|
|
1550
|
+
const parameters = decodeParams(r, "publish_namespace");
|
|
1536
1551
|
return {
|
|
1537
1552
|
type: "publish_namespace",
|
|
1538
1553
|
request_id,
|
|
@@ -1554,7 +1569,7 @@ function decodeSubscribeNamespacePayload(r) {
|
|
|
1554
1569
|
const required_request_id_delta = r.readVarInt();
|
|
1555
1570
|
const namespace_prefix = r.readTuple();
|
|
1556
1571
|
const subscribe_options = r.readVarInt();
|
|
1557
|
-
const parameters = decodeParams(r);
|
|
1572
|
+
const parameters = decodeParams(r, "subscribe_namespace");
|
|
1558
1573
|
return {
|
|
1559
1574
|
type: "subscribe_namespace",
|
|
1560
1575
|
request_id,
|
|
@@ -1599,7 +1614,7 @@ function decodeFetchPayload(r) {
|
|
|
1599
1614
|
const joining_start = r.readVarInt();
|
|
1600
1615
|
joining = { joining_request_id, joining_start };
|
|
1601
1616
|
}
|
|
1602
|
-
const parameters = decodeParams(r);
|
|
1617
|
+
const parameters = decodeParams(r, "fetch");
|
|
1603
1618
|
return {
|
|
1604
1619
|
type: "fetch",
|
|
1605
1620
|
request_id,
|
|
@@ -1614,7 +1629,7 @@ function decodeFetchOkPayload(r, payloadEnd) {
|
|
|
1614
1629
|
const end_of_track = r.readUint8();
|
|
1615
1630
|
const end_group = r.readVarInt();
|
|
1616
1631
|
const end_object = r.readVarInt();
|
|
1617
|
-
const parameters = decodeParams(r);
|
|
1632
|
+
const parameters = decodeParams(r, "fetch_ok");
|
|
1618
1633
|
const track_properties = decodeTrackProperties(r, payloadEnd);
|
|
1619
1634
|
return {
|
|
1620
1635
|
type: "fetch_ok",
|
|
@@ -1630,7 +1645,7 @@ function decodeTrackStatusPayload(r) {
|
|
|
1630
1645
|
const required_request_id_delta = r.readVarInt();
|
|
1631
1646
|
const track_namespace = r.readTuple();
|
|
1632
1647
|
const track_name = r.readString();
|
|
1633
|
-
const parameters = decodeParams(r);
|
|
1648
|
+
const parameters = decodeParams(r, "track_status");
|
|
1634
1649
|
return {
|
|
1635
1650
|
type: "track_status",
|
|
1636
1651
|
request_id,
|
|
@@ -1641,7 +1656,7 @@ function decodeTrackStatusPayload(r) {
|
|
|
1641
1656
|
};
|
|
1642
1657
|
}
|
|
1643
1658
|
function decodeRequestOkPayload(r) {
|
|
1644
|
-
const parameters = decodeParams(r);
|
|
1659
|
+
const parameters = decodeParams(r, "request_ok");
|
|
1645
1660
|
return { type: "request_ok", parameters };
|
|
1646
1661
|
}
|
|
1647
1662
|
function decodeRequestErrorPayload(r) {
|