@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.
Files changed (51) hide show
  1. package/dist/{chunk-5XZKO2U5.js → chunk-2XH6PHXR.js} +62 -51
  2. package/dist/{chunk-APTV6F72.js → chunk-3YAR3I3S.js} +67 -51
  3. package/dist/{chunk-BQHLUT37.cjs → chunk-7ENEWAMZ.cjs} +2 -6
  4. package/dist/{chunk-MD2OA7SE.js → chunk-BV6MITLO.js} +15 -8
  5. package/dist/{chunk-B56AG5HU.cjs → chunk-EVCPBFSR.cjs} +6 -4
  6. package/dist/{chunk-KNLPX3YA.js → chunk-H6DTAIWM.js} +6 -4
  7. package/dist/{chunk-J3ASFPCX.cjs → chunk-IADVBKEJ.cjs} +15 -8
  8. package/dist/{chunk-I55J3KXD.js → chunk-NH4L6NIY.js} +48 -33
  9. package/dist/{chunk-EQAYMCXO.cjs → chunk-PU2KV7VP.cjs} +48 -33
  10. package/dist/{chunk-HEO2JG6C.js → chunk-TMXRYOBS.js} +100 -92
  11. package/dist/{chunk-IEJULBKB.cjs → chunk-UA5XFP4O.cjs} +100 -92
  12. package/dist/{chunk-KTVN4P6J.cjs → chunk-UZO5Z2XT.cjs} +62 -51
  13. package/dist/{chunk-MH7537FB.cjs → chunk-VWXUT5R2.cjs} +67 -51
  14. package/dist/{chunk-JJEN2VG5.js → chunk-XQGEOFGE.js} +2 -6
  15. package/dist/{codec-BnamSx7L.d.cts → codec-N3g1lxQQ.d.cts} +1 -1
  16. package/dist/{codec-CFhUGTu2.d.ts → codec-v6Vloc7H.d.ts} +1 -1
  17. package/dist/draft12.cjs +2 -2
  18. package/dist/draft12.js +1 -1
  19. package/dist/draft14-session.d.cts +1 -1
  20. package/dist/draft14-session.d.ts +1 -1
  21. package/dist/draft14.cjs +2 -2
  22. package/dist/draft14.d.cts +3 -3
  23. package/dist/draft14.d.ts +3 -3
  24. package/dist/draft14.js +1 -1
  25. package/dist/draft15.cjs +2 -2
  26. package/dist/draft15.js +1 -1
  27. package/dist/draft16.cjs +2 -2
  28. package/dist/draft16.js +1 -1
  29. package/dist/draft17.cjs +2 -2
  30. package/dist/draft17.js +1 -1
  31. package/dist/draft18.cjs +2 -2
  32. package/dist/draft18.js +1 -1
  33. package/dist/draft19.cjs +2 -2
  34. package/dist/draft19.js +1 -1
  35. package/dist/index.cjs +14 -14
  36. package/dist/index.d.cts +2 -2
  37. package/dist/index.d.ts +2 -2
  38. package/dist/index.js +7 -7
  39. package/dist/session.d.cts +1 -1
  40. package/dist/session.d.ts +1 -1
  41. package/dist/{types-CVeKIk7A.d.cts → types-HI_bbXka.d.cts} +0 -2
  42. package/dist/{types-CVeKIk7A.d.ts → types-HI_bbXka.d.ts} +0 -2
  43. package/package.json +2 -2
  44. package/src/drafts/draft12/data-streams.ts +13 -4
  45. package/src/drafts/draft14/codec.ts +2 -6
  46. package/src/drafts/draft14/types.ts +0 -2
  47. package/src/drafts/draft15/data-streams.ts +30 -16
  48. package/src/drafts/draft16/codec.ts +116 -93
  49. package/src/drafts/draft17/codec.ts +72 -35
  50. package/src/drafts/draft18/codec.ts +89 -53
  51. package/src/drafts/draft19/codec.ts +94 -53
@@ -1103,6 +1103,33 @@ var PARAM_SUBSCRIPTION_FILTER = 0x21n;
1103
1103
  var PARAM_GROUP_ORDER = 0x22n;
1104
1104
  var PARAM_NEW_GROUP_REQUEST = 0x32n;
1105
1105
  var PARAM_TRACK_NAMESPACE_PREFIX = 0x34n;
1106
+ var PARAMETER_SCOPE = /* @__PURE__ */ new Map([
1107
+ [0x02n, /* @__PURE__ */ new Set(["request_ok", "subscribe", "request_update"])],
1108
+ [
1109
+ 0x03n,
1110
+ /* @__PURE__ */ new Set([
1111
+ "publish",
1112
+ "subscribe",
1113
+ "request_update",
1114
+ "subscribe_namespace",
1115
+ "subscribe_tracks",
1116
+ "publish_namespace",
1117
+ "track_status",
1118
+ "fetch"
1119
+ ])
1120
+ ],
1121
+ [0x04n, /* @__PURE__ */ new Set(["subscribe"])],
1122
+ [0x06n, /* @__PURE__ */ new Set(["request_ok", "subscribe", "request_update"])],
1123
+ [0x08n, /* @__PURE__ */ new Set(["subscribe_ok", "publish", "request_ok"])],
1124
+ [0x09n, /* @__PURE__ */ new Set(["subscribe_ok", "publish", "request_ok"])],
1125
+ [0x0an, /* @__PURE__ */ new Set(["fetch"])],
1126
+ [0x10n, /* @__PURE__ */ new Set(["subscribe", "request_update", "publish", "request_ok", "subscribe_tracks"])],
1127
+ [0x20n, /* @__PURE__ */ new Set(["subscribe", "fetch", "request_update", "request_ok"])],
1128
+ [0x21n, /* @__PURE__ */ new Set(["subscribe", "request_ok", "request_update"])],
1129
+ [0x22n, /* @__PURE__ */ new Set(["subscribe", "request_ok", "fetch"])],
1130
+ [0x32n, /* @__PURE__ */ new Set(["request_ok", "subscribe", "request_update"])],
1131
+ [0x34n, /* @__PURE__ */ new Set(["request_update"])]
1132
+ ]);
1106
1133
  function encodeParams(params, writer) {
1107
1134
  const entries = [];
1108
1135
  if (params.object_delivery_timeout !== void 0) {
@@ -1144,13 +1171,12 @@ function encodeParams(params, writer) {
1144
1171
  if (params.largest_object !== void 0) {
1145
1172
  entries.push({
1146
1173
  type: PARAM_LARGEST_OBJECT,
1174
+ // A Location is "Two consecutive varints (Group, Object)", which is a
1175
+ // different value encoding from "Length-prefixed". Nothing states the
1176
+ // length, so nothing writes one.
1147
1177
  encode: (w) => {
1148
- const tmpW = new MoqtBufferWriter(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);
1178
+ w.writeVarInt(params.largest_object.group);
1179
+ w.writeVarInt(params.largest_object.object);
1154
1180
  }
1155
1181
  });
1156
1182
  }
@@ -1207,12 +1233,11 @@ function encodeParams(params, writer) {
1207
1233
  if (params.track_namespace_prefix !== void 0) {
1208
1234
  entries.push({
1209
1235
  type: PARAM_TRACK_NAMESPACE_PREFIX,
1236
+ // The parameter "uses the Track Namespace encoding", which is a tuple
1237
+ // that states its own field count. That is not the Length-prefixed
1238
+ // encoding, so there is no byte length ahead of it.
1210
1239
  encode: (w) => {
1211
- const tmpW = new MoqtBufferWriter(32);
1212
- encodeNamespaceTuple(params.track_namespace_prefix, tmpW);
1213
- const raw = tmpW.finish();
1214
- w.writeVarInt(BigInt(raw.byteLength));
1215
- w.writeBytes(raw);
1240
+ encodeNamespaceTuple(params.track_namespace_prefix, w);
1216
1241
  }
1217
1242
  });
1218
1243
  }
@@ -1237,15 +1262,22 @@ function encodeParams(params, writer) {
1237
1262
  prevType = entry.type;
1238
1263
  }
1239
1264
  }
1240
- function decodeParams(reader) {
1265
+ function decodeParams(reader, messageType) {
1241
1266
  const count = Number(reader.readVarInt());
1242
1267
  const result = {};
1243
- const unknown = [];
1244
1268
  let prevType = 0n;
1245
1269
  for (let i = 0; i < count; i++) {
1246
1270
  const delta = reader.readVarInt();
1247
1271
  const paramType = prevType + delta;
1248
1272
  prevType = paramType;
1273
+ const scope = PARAMETER_SCOPE.get(paramType);
1274
+ if (scope !== void 0 && !scope.has(messageType)) {
1275
+ throw new DecodeError(
1276
+ "CONSTRAINT_VIOLATION",
1277
+ `Message Parameter 0x${paramType.toString(16)} may not appear in ${messageType}`,
1278
+ reader.offset
1279
+ );
1280
+ }
1249
1281
  if (paramType === PARAM_OBJECT_DELIVERY_TIMEOUT) {
1250
1282
  result.object_delivery_timeout = reader.readVarInt();
1251
1283
  } else if (paramType === PARAM_AUTHORIZATION_TOKEN) {
@@ -1259,12 +1291,8 @@ function decodeParams(reader) {
1259
1291
  } else if (paramType === PARAM_EXPIRES) {
1260
1292
  result.expires = reader.readVarInt();
1261
1293
  } else if (paramType === PARAM_LARGEST_OBJECT) {
1262
- const length = Number(reader.readVarInt());
1263
- const startOff = reader.offset;
1264
1294
  const group = reader.readVarInt();
1265
1295
  const object = reader.readVarInt();
1266
- const consumed = reader.offset - startOff;
1267
- if (consumed < length) reader.readBytes(length - consumed);
1268
1296
  result.largest_object = { group, object };
1269
1297
  } else if (paramType === PARAM_FILL_TIMEOUT) {
1270
1298
  result.fill_timeout = reader.readVarInt();
@@ -1292,32 +1320,15 @@ function decodeParams(reader) {
1292
1320
  } else if (paramType === PARAM_NEW_GROUP_REQUEST) {
1293
1321
  result.new_group_request = reader.readVarInt();
1294
1322
  } 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 MoqtBufferReader(bytes));
1323
+ result.track_namespace_prefix = decodeNamespaceTuple(reader);
1298
1324
  } else {
1299
- if (paramType % 2n === 0n) {
1300
- const value = reader.readVarInt();
1301
- const tmpWriter = new MoqtBufferWriter(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: bytesToHex(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: bytesToHex(bytes)
1316
- });
1317
- }
1325
+ throw new DecodeError(
1326
+ "INVALID_PARAMETER",
1327
+ `Unknown Message Parameter type 0x${paramType.toString(16)}`,
1328
+ reader.offset
1329
+ );
1318
1330
  }
1319
1331
  }
1320
- if (unknown.length > 0) result.unknown = unknown;
1321
1332
  return result;
1322
1333
  }
1323
1334
  var TPROP_OBJECT_DELIVERY_TIMEOUT = 0x02n;
@@ -1579,7 +1590,7 @@ function decodeSubscribePayload(r) {
1579
1590
  const request_id = r.readVarInt();
1580
1591
  const track_namespace = r.readTuple();
1581
1592
  const track_name = r.readString();
1582
- const parameters = decodeParams(r);
1593
+ const parameters = decodeParams(r, "subscribe");
1583
1594
  return {
1584
1595
  type: "subscribe",
1585
1596
  request_id,
@@ -1590,13 +1601,13 @@ function decodeSubscribePayload(r) {
1590
1601
  }
1591
1602
  function decodeSubscribeOkPayload(r, payloadEnd) {
1592
1603
  const track_alias = r.readVarInt();
1593
- const parameters = decodeParams(r);
1604
+ const parameters = decodeParams(r, "subscribe_ok");
1594
1605
  const track_properties = decodeTrackProperties(r, payloadEnd);
1595
1606
  return { type: "subscribe_ok", track_alias, parameters, track_properties };
1596
1607
  }
1597
1608
  function decodeRequestUpdatePayload(r) {
1598
1609
  const request_id = r.readVarInt();
1599
- const parameters = decodeParams(r);
1610
+ const parameters = decodeParams(r, "request_update");
1600
1611
  return {
1601
1612
  type: "request_update",
1602
1613
  request_id,
@@ -1608,7 +1619,7 @@ function decodePublishPayload(r, payloadEnd) {
1608
1619
  const track_namespace = r.readTuple();
1609
1620
  const track_name = r.readString();
1610
1621
  const track_alias = r.readVarInt();
1611
- const parameters = decodeParams(r);
1622
+ const parameters = decodeParams(r, "publish");
1612
1623
  const track_properties = decodeTrackProperties(r, payloadEnd);
1613
1624
  return {
1614
1625
  type: "publish",
@@ -1629,7 +1640,7 @@ function decodePublishDonePayload(r) {
1629
1640
  function decodePublishNamespacePayload(r) {
1630
1641
  const request_id = r.readVarInt();
1631
1642
  const track_namespace = r.readTuple();
1632
- const parameters = decodeParams(r);
1643
+ const parameters = decodeParams(r, "publish_namespace");
1633
1644
  return {
1634
1645
  type: "publish_namespace",
1635
1646
  request_id,
@@ -1648,7 +1659,7 @@ function decodeNamespaceDonePayload(r) {
1648
1659
  function decodeSubscribeNamespacePayload(r) {
1649
1660
  const request_id = r.readVarInt();
1650
1661
  const namespace_prefix = r.readTuple();
1651
- const parameters = decodeParams(r);
1662
+ const parameters = decodeParams(r, "subscribe_namespace");
1652
1663
  return {
1653
1664
  type: "subscribe_namespace",
1654
1665
  request_id,
@@ -1659,7 +1670,7 @@ function decodeSubscribeNamespacePayload(r) {
1659
1670
  function decodeSubscribeTracksPayload(r) {
1660
1671
  const request_id = r.readVarInt();
1661
1672
  const namespace_prefix = r.readTuple();
1662
- const parameters = decodeParams(r);
1673
+ const parameters = decodeParams(r, "subscribe_tracks");
1663
1674
  return {
1664
1675
  type: "subscribe_tracks",
1665
1676
  request_id,
@@ -1701,7 +1712,7 @@ function decodeFetchPayload(r) {
1701
1712
  const joining_start = r.readVarInt();
1702
1713
  joining = { joining_request_id, joining_start };
1703
1714
  }
1704
- const parameters = decodeParams(r);
1715
+ const parameters = decodeParams(r, "fetch");
1705
1716
  return {
1706
1717
  type: "fetch",
1707
1718
  request_id,
@@ -1715,7 +1726,7 @@ function decodeFetchOkPayload(r, payloadEnd) {
1715
1726
  const end_of_track = r.readUint8();
1716
1727
  const end_group = r.readVarInt();
1717
1728
  const end_object = r.readVarInt();
1718
- const parameters = decodeParams(r);
1729
+ const parameters = decodeParams(r, "fetch_ok");
1719
1730
  const track_properties = decodeTrackProperties(r, payloadEnd);
1720
1731
  return {
1721
1732
  type: "fetch_ok",
@@ -1730,7 +1741,7 @@ function decodeTrackStatusPayload(r) {
1730
1741
  const request_id = r.readVarInt();
1731
1742
  const track_namespace = r.readTuple();
1732
1743
  const track_name = r.readString();
1733
- const parameters = decodeParams(r);
1744
+ const parameters = decodeParams(r, "track_status");
1734
1745
  return {
1735
1746
  type: "track_status",
1736
1747
  request_id,
@@ -1740,7 +1751,7 @@ function decodeTrackStatusPayload(r) {
1740
1751
  };
1741
1752
  }
1742
1753
  function decodeRequestOkPayload(r, payloadEnd) {
1743
- const parameters = decodeParams(r);
1754
+ const parameters = decodeParams(r, "request_ok");
1744
1755
  const track_properties = decodeTrackProperties(r, payloadEnd);
1745
1756
  return { type: "request_ok", parameters, track_properties };
1746
1757
  }
@@ -1173,6 +1173,38 @@ function decodeRangeFilter(reader, hasProperty) {
1173
1173
  }
1174
1174
  return property_type !== void 0 ? { set_id, property_type, ranges } : { set_id, ranges };
1175
1175
  }
1176
+ var PARAMETER_SCOPE = /* @__PURE__ */ new Map([
1177
+ [0x02n, /* @__PURE__ */ new Set(["request_ok", "subscribe", "request_update", "subscribe_tracks"])],
1178
+ [
1179
+ 0x03n,
1180
+ /* @__PURE__ */ new Set([
1181
+ "publish",
1182
+ "subscribe",
1183
+ "request_update",
1184
+ "subscribe_namespace",
1185
+ "subscribe_tracks",
1186
+ "publish_namespace",
1187
+ "track_status",
1188
+ "fetch"
1189
+ ])
1190
+ ],
1191
+ [0x04n, /* @__PURE__ */ new Set(["subscribe", "subscribe_tracks"])],
1192
+ [0x06n, /* @__PURE__ */ new Set(["request_ok", "subscribe", "request_update", "subscribe_tracks"])],
1193
+ [0x08n, /* @__PURE__ */ new Set(["subscribe_ok", "publish", "request_ok"])],
1194
+ [0x09n, /* @__PURE__ */ new Set(["subscribe_ok", "publish", "request_ok"])],
1195
+ [0x0an, /* @__PURE__ */ new Set(["fetch"])],
1196
+ [0x10n, /* @__PURE__ */ new Set(["subscribe", "request_update", "publish", "request_ok", "subscribe_tracks"])],
1197
+ [0x20n, /* @__PURE__ */ new Set(["subscribe", "fetch", "request_update", "request_ok", "subscribe_tracks"])],
1198
+ [0x21n, /* @__PURE__ */ new Set(["subscribe", "request_ok", "request_update", "subscribe_tracks"])],
1199
+ [0x22n, /* @__PURE__ */ new Set(["subscribe", "subscribe_tracks", "fetch"])],
1200
+ [0x25n, /* @__PURE__ */ new Set(["fetch", "subscribe", "subscribe_tracks", "request_ok", "request_update"])],
1201
+ [0x26n, /* @__PURE__ */ new Set(["fetch", "subscribe", "subscribe_tracks", "request_ok", "request_update"])],
1202
+ [0x27n, /* @__PURE__ */ new Set(["fetch", "subscribe", "subscribe_tracks", "request_ok", "request_update"])],
1203
+ [0x28n, /* @__PURE__ */ new Set(["fetch", "subscribe", "subscribe_tracks", "request_ok", "request_update"])],
1204
+ [0x29n, /* @__PURE__ */ new Set(["subscribe_tracks", "request_update"])],
1205
+ [0x32n, /* @__PURE__ */ new Set(["request_ok", "subscribe", "request_update", "subscribe_tracks"])],
1206
+ [0x34n, /* @__PURE__ */ new Set(["request_update"])]
1207
+ ]);
1176
1208
  function encodeParams(params, writer) {
1177
1209
  const entries = [];
1178
1210
  if (params.object_delivery_timeout !== void 0) {
@@ -1214,13 +1246,12 @@ function encodeParams(params, writer) {
1214
1246
  if (params.largest_object !== void 0) {
1215
1247
  entries.push({
1216
1248
  type: PARAM_LARGEST_OBJECT,
1249
+ // A Location is "Two consecutive varints (Group, Object)", which is a
1250
+ // different value encoding from "Length-prefixed". Nothing states the
1251
+ // length, so nothing writes one.
1217
1252
  encode: (w) => {
1218
- const tmpW = new MoqtBufferWriter(16);
1219
- tmpW.writeVarInt(params.largest_object.group);
1220
- tmpW.writeVarInt(params.largest_object.object);
1221
- const raw = tmpW.finish();
1222
- w.writeVarInt(BigInt(raw.byteLength));
1223
- w.writeBytes(raw);
1253
+ w.writeVarInt(params.largest_object.group);
1254
+ w.writeVarInt(params.largest_object.object);
1224
1255
  }
1225
1256
  });
1226
1257
  }
@@ -1307,12 +1338,11 @@ function encodeParams(params, writer) {
1307
1338
  if (params.track_namespace_prefix !== void 0) {
1308
1339
  entries.push({
1309
1340
  type: PARAM_TRACK_NAMESPACE_PREFIX,
1341
+ // The parameter "uses the Track Namespace encoding", which is a tuple
1342
+ // that states its own field count. That is not the Length-prefixed
1343
+ // encoding, so there is no byte length ahead of it.
1310
1344
  encode: (w) => {
1311
- const tmpW = new MoqtBufferWriter(32);
1312
- encodeNamespaceTuple(params.track_namespace_prefix, tmpW);
1313
- const raw = tmpW.finish();
1314
- w.writeVarInt(BigInt(raw.byteLength));
1315
- w.writeBytes(raw);
1345
+ encodeNamespaceTuple(params.track_namespace_prefix, w);
1316
1346
  }
1317
1347
  });
1318
1348
  }
@@ -1337,15 +1367,22 @@ function encodeParams(params, writer) {
1337
1367
  prevType = entry.type;
1338
1368
  }
1339
1369
  }
1340
- function decodeParams(reader) {
1370
+ function decodeParams(reader, messageType) {
1341
1371
  const count = Number(reader.readVarInt());
1342
1372
  const result = {};
1343
- const unknown = [];
1344
1373
  let prevType = 0n;
1345
1374
  for (let i = 0; i < count; i++) {
1346
1375
  const delta = reader.readVarInt();
1347
1376
  const paramType = prevType + delta;
1348
1377
  prevType = paramType;
1378
+ const scope = PARAMETER_SCOPE.get(paramType);
1379
+ if (scope !== void 0 && !scope.has(messageType)) {
1380
+ throw new DecodeError(
1381
+ "CONSTRAINT_VIOLATION",
1382
+ `Message Parameter 0x${paramType.toString(16)} may not appear in ${messageType}`,
1383
+ reader.offset
1384
+ );
1385
+ }
1349
1386
  if (paramType === PARAM_OBJECT_DELIVERY_TIMEOUT) {
1350
1387
  result.object_delivery_timeout = reader.readVarInt();
1351
1388
  } else if (paramType === PARAM_AUTHORIZATION_TOKEN) {
@@ -1359,12 +1396,8 @@ function decodeParams(reader) {
1359
1396
  } else if (paramType === PARAM_EXPIRES) {
1360
1397
  result.expires = reader.readVarInt();
1361
1398
  } else if (paramType === PARAM_LARGEST_OBJECT) {
1362
- const length = Number(reader.readVarInt());
1363
- const startOff = reader.offset;
1364
1399
  const group = reader.readVarInt();
1365
1400
  const object = reader.readVarInt();
1366
- const consumed = reader.offset - startOff;
1367
- if (consumed < length) reader.readBytes(length - consumed);
1368
1401
  result.largest_object = { group, object };
1369
1402
  } else if (paramType === PARAM_FILL_TIMEOUT) {
1370
1403
  result.fill_timeout = reader.readVarInt();
@@ -1402,32 +1435,15 @@ function decodeParams(reader) {
1402
1435
  } else if (paramType === PARAM_NEW_GROUP_REQUEST) {
1403
1436
  result.new_group_request = reader.readVarInt();
1404
1437
  } else if (paramType === PARAM_TRACK_NAMESPACE_PREFIX) {
1405
- const length = Number(reader.readVarInt());
1406
- const bytes = reader.readBytes(length);
1407
- result.track_namespace_prefix = decodeNamespaceTuple(new MoqtBufferReader(bytes));
1438
+ result.track_namespace_prefix = decodeNamespaceTuple(reader);
1408
1439
  } else {
1409
- if (paramType % 2n === 0n) {
1410
- const value = reader.readVarInt();
1411
- const tmpWriter = new MoqtBufferWriter(16);
1412
- tmpWriter.writeVarInt(value);
1413
- const raw = tmpWriter.finish();
1414
- unknown.push({
1415
- id: `0x${paramType.toString(16)}`,
1416
- length: raw.byteLength,
1417
- raw_hex: bytesToHex(raw)
1418
- });
1419
- } else {
1420
- const length = Number(reader.readVarInt());
1421
- const bytes = reader.readBytes(length);
1422
- unknown.push({
1423
- id: `0x${paramType.toString(16)}`,
1424
- length,
1425
- raw_hex: bytesToHex(bytes)
1426
- });
1427
- }
1440
+ throw new DecodeError(
1441
+ "INVALID_PARAMETER",
1442
+ `Unknown Message Parameter type 0x${paramType.toString(16)}`,
1443
+ reader.offset
1444
+ );
1428
1445
  }
1429
1446
  }
1430
- if (unknown.length > 0) result.unknown = unknown;
1431
1447
  return result;
1432
1448
  }
1433
1449
  var TPROP_OBJECT_DELIVERY_TIMEOUT = 0x02n;
@@ -1686,7 +1702,7 @@ function decodeSubscribePayload(r) {
1686
1702
  const request_id = r.readVarInt();
1687
1703
  const track_namespace = r.readTuple();
1688
1704
  const track_name = r.readString();
1689
- const parameters = decodeParams(r);
1705
+ const parameters = decodeParams(r, "subscribe");
1690
1706
  return {
1691
1707
  type: "subscribe",
1692
1708
  request_id,
@@ -1697,13 +1713,13 @@ function decodeSubscribePayload(r) {
1697
1713
  }
1698
1714
  function decodeSubscribeOkPayload(r, payloadEnd) {
1699
1715
  const track_alias = r.readVarInt();
1700
- const parameters = decodeParams(r);
1716
+ const parameters = decodeParams(r, "subscribe_ok");
1701
1717
  const track_properties = decodeTrackProperties(r, payloadEnd);
1702
1718
  return { type: "subscribe_ok", track_alias, parameters, track_properties };
1703
1719
  }
1704
1720
  function decodeRequestUpdatePayload(r) {
1705
1721
  const request_id = r.readVarInt();
1706
- const parameters = decodeParams(r);
1722
+ const parameters = decodeParams(r, "request_update");
1707
1723
  return {
1708
1724
  type: "request_update",
1709
1725
  request_id,
@@ -1715,7 +1731,7 @@ function decodePublishPayload(r, payloadEnd) {
1715
1731
  const track_namespace = r.readTuple();
1716
1732
  const track_name = r.readString();
1717
1733
  const track_alias = r.readVarInt();
1718
- const parameters = decodeParams(r);
1734
+ const parameters = decodeParams(r, "publish");
1719
1735
  const track_properties = decodeTrackProperties(r, payloadEnd);
1720
1736
  return {
1721
1737
  type: "publish",
@@ -1736,7 +1752,7 @@ function decodePublishDonePayload(r) {
1736
1752
  function decodePublishNamespacePayload(r) {
1737
1753
  const request_id = r.readVarInt();
1738
1754
  const track_namespace = r.readTuple();
1739
- const parameters = decodeParams(r);
1755
+ const parameters = decodeParams(r, "publish_namespace");
1740
1756
  return {
1741
1757
  type: "publish_namespace",
1742
1758
  request_id,
@@ -1755,7 +1771,7 @@ function decodeNamespaceDonePayload(r) {
1755
1771
  function decodeSubscribeNamespacePayload(r) {
1756
1772
  const request_id = r.readVarInt();
1757
1773
  const namespace_prefix = r.readTuple();
1758
- const parameters = decodeParams(r);
1774
+ const parameters = decodeParams(r, "subscribe_namespace");
1759
1775
  return {
1760
1776
  type: "subscribe_namespace",
1761
1777
  request_id,
@@ -1766,7 +1782,7 @@ function decodeSubscribeNamespacePayload(r) {
1766
1782
  function decodeSubscribeTracksPayload(r) {
1767
1783
  const request_id = r.readVarInt();
1768
1784
  const namespace_prefix = r.readTuple();
1769
- const parameters = decodeParams(r);
1785
+ const parameters = decodeParams(r, "subscribe_tracks");
1770
1786
  return {
1771
1787
  type: "subscribe_tracks",
1772
1788
  request_id,
@@ -1808,7 +1824,7 @@ function decodeFetchPayload(r) {
1808
1824
  const joining_start = r.readVarInt();
1809
1825
  joining = { joining_request_id, joining_start };
1810
1826
  }
1811
- const parameters = decodeParams(r);
1827
+ const parameters = decodeParams(r, "fetch");
1812
1828
  return {
1813
1829
  type: "fetch",
1814
1830
  request_id,
@@ -1822,7 +1838,7 @@ function decodeFetchOkPayload(r, payloadEnd) {
1822
1838
  const end_of_track = r.readUint8();
1823
1839
  const end_group = r.readVarInt();
1824
1840
  const end_object = r.readVarInt();
1825
- const parameters = decodeParams(r);
1841
+ const parameters = decodeParams(r, "fetch_ok");
1826
1842
  const track_properties = decodeTrackProperties(r, payloadEnd);
1827
1843
  return {
1828
1844
  type: "fetch_ok",
@@ -1837,7 +1853,7 @@ function decodeTrackStatusPayload(r) {
1837
1853
  const request_id = r.readVarInt();
1838
1854
  const track_namespace = r.readTuple();
1839
1855
  const track_name = r.readString();
1840
- const parameters = decodeParams(r);
1856
+ const parameters = decodeParams(r, "track_status");
1841
1857
  return {
1842
1858
  type: "track_status",
1843
1859
  request_id,
@@ -1847,7 +1863,7 @@ function decodeTrackStatusPayload(r) {
1847
1863
  };
1848
1864
  }
1849
1865
  function decodeRequestOkPayload(r, payloadEnd) {
1850
- const parameters = decodeParams(r);
1866
+ const parameters = decodeParams(r, "request_ok");
1851
1867
  const track_properties = decodeTrackProperties(r, payloadEnd);
1852
1868
  return { type: "request_ok", parameters, track_properties };
1853
1869
  }
@@ -1121,7 +1121,6 @@ function encodePublishNamespacePayload(msg, w) {
1121
1121
  }
1122
1122
  function encodePublishNamespaceOkPayload(msg, w) {
1123
1123
  w.writeVarInt(msg.request_id);
1124
- encodeMessageParams(msg.parameters, w);
1125
1124
  }
1126
1125
  function encodePublishNamespaceErrorPayload(msg, w) {
1127
1126
  w.writeVarInt(msg.request_id);
@@ -1143,7 +1142,6 @@ function encodeSubscribeNamespacePayload(msg, w) {
1143
1142
  }
1144
1143
  function encodeSubscribeNamespaceOkPayload(msg, w) {
1145
1144
  w.writeVarInt(msg.request_id);
1146
- encodeMessageParams(msg.parameters, w);
1147
1145
  }
1148
1146
  function encodeSubscribeNamespaceErrorPayload(msg, w) {
1149
1147
  w.writeVarInt(msg.request_id);
@@ -1431,8 +1429,7 @@ function decodePublishNamespacePayload(r) {
1431
1429
  }
1432
1430
  function decodePublishNamespaceOkPayload(r) {
1433
1431
  const request_id = r.readVarInt();
1434
- const parameters = decodeMessageParams(r);
1435
- return { type: "publish_namespace_ok", request_id, parameters };
1432
+ return { type: "publish_namespace_ok", request_id };
1436
1433
  }
1437
1434
  function decodePublishNamespaceErrorPayload(r) {
1438
1435
  const request_id = r.readVarInt();
@@ -1473,8 +1470,7 @@ function decodeSubscribeNamespacePayload(r) {
1473
1470
  }
1474
1471
  function decodeSubscribeNamespaceOkPayload(r) {
1475
1472
  const request_id = r.readVarInt();
1476
- const parameters = decodeMessageParams(r);
1477
- return { type: "subscribe_namespace_ok", request_id, parameters };
1473
+ return { type: "subscribe_namespace_ok", request_id };
1478
1474
  }
1479
1475
  function decodeSubscribeNamespaceErrorPayload(r) {
1480
1476
  const request_id = r.readVarInt();
@@ -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
- w.writeUint8(dg.publisherPriority);
116
+ if (!defaultPriority) {
117
+ w.writeUint8(dg.publisherPriority);
118
+ }
116
119
  if (extensionsPresent) {
117
120
  const extData = 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 BufferReader(bytes);
156
159
  const streamType = Number(r.readVarInt());
157
- if (!(streamType >= 16 && streamType <= 23 || streamType >= 48 && streamType <= 55)) {
160
+ if (!(streamType >= 16 && streamType <= 31 || streamType >= 48 && streamType <= 63) || (streamType & 6) === 6) {
158
161
  return {
159
162
  ok: false,
160
163
  error: new DecodeError(
161
164
  "CONSTRAINT_VIOLATION",
162
- `Expected subgroup stream type 0x10-0x17/0x30-0x37, got 0x${streamType.toString(16)}`,
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 & 2) !== 0;
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
- const publisherPriority = r.readUint8();
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 BufferReader(buffer.subarray(offset));
474
481
  const streamType = Number(r.readVarInt());
475
- if (!(streamType >= 16 && streamType <= 23 || streamType >= 48 && streamType <= 55)) {
482
+ if (!(streamType >= 16 && streamType <= 31 || streamType >= 48 && streamType <= 63)) {
476
483
  controller.error(
477
484
  new 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 <= 23 || firstByte >= 48 && firstByte <= 55) {
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 <= 23 || firstByte >= 48 && firstByte <= 55) {
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);
@@ -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 === 2 || dg.streamTypeId === 3;
49
+ const isStatus = dg.streamTypeId >= 4;
50
50
  if (isStatus) {
51
51
  w.writeVarInt(_nullishCoalesce(dg.objectStatus, () => ( 0n)));
52
52
  } else {
@@ -162,18 +162,19 @@ function decodeDatagram(bytes) {
162
162
  try {
163
163
  const r = new (0, _chunk4XLYCT5Qcjs.BufferReader)(bytes);
164
164
  const streamTypeId = Number(r.readVarInt());
165
- if (streamTypeId < 0 || streamTypeId > 3) {
165
+ if (streamTypeId < 0 || streamTypeId > 5) {
166
166
  return {
167
167
  ok: false,
168
168
  error: new (0, _chunk4XLYCT5Qcjs.DecodeError)(
169
169
  "CONSTRAINT_VIOLATION",
170
- `Expected datagram type 0x00-0x03, got 0x${streamTypeId.toString(16)}`,
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 isStatus = streamTypeId === 2 || streamTypeId === 3;
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)