moqtail 0.11.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/dist/client.js CHANGED
@@ -129,6 +129,7 @@ var TerminationError = class extends MOQtailError {
129
129
 
130
130
  // src/model/common/pair.ts
131
131
  var MAX_VALUE_LENGTH = 2 ** 16 - 1;
132
+ var MAX_U64 = 2n ** 64n - 1n;
132
133
  var KeyValuePair = class _KeyValuePair {
133
134
  /**
134
135
  * The key/type identifier for this pair.
@@ -188,11 +189,29 @@ var KeyValuePair = class _KeyValuePair {
188
189
  }
189
190
  /**
190
191
  * Serializes this key-value pair to a frozen byte buffer.
192
+ * Equivalent to {@link KeyValuePair.serializeDelta} with `prevType = 0n`.
191
193
  * @returns The serialized buffer.
192
194
  */
193
195
  serialize() {
196
+ return this.serializeDelta(0n);
197
+ }
198
+ /**
199
+ * Serializes this pair's wire form, encoding the Type as a delta from
200
+ * `prevType` (the type of the previous KVP in the same list, or 0n if this
201
+ * is the first entry).
202
+ * @param prevType - The type of the previous KVP in the same list.
203
+ * @throws ProtocolViolationError if this pair's type is less than prevType
204
+ * (Delta Type is an unsigned varint, so the list must be sorted ascending).
205
+ */
206
+ serializeDelta(prevType) {
207
+ if (this.typeValue < prevType) {
208
+ throw new ProtocolViolationError(
209
+ "KeyValuePair.serializeDelta",
210
+ `type ${this.typeValue} is less than previous type ${prevType}; a KVP list must be sorted by ascending type to be delta-encoded`
211
+ );
212
+ }
194
213
  const buf = new ByteBuffer();
195
- buf.putVI(this.typeValue);
214
+ buf.putVI(this.typeValue - prevType);
196
215
  if (isVarInt(this)) {
197
216
  buf.putVI(this.value);
198
217
  } else if (isBytes(this)) {
@@ -202,13 +221,32 @@ var KeyValuePair = class _KeyValuePair {
202
221
  }
203
222
  /**
204
223
  * Deserializes a KeyValuePair from a buffer.
224
+ * Equivalent to {@link KeyValuePair.deserializeDelta} with `prevType = 0n`.
205
225
  * @param buf - The buffer to read from.
206
226
  * @returns The deserialized KeyValuePair.
207
227
  * @throws LengthExceedsMaxError if blob length exceeds 65535 bytes.
208
228
  * @throws NotEnoughBytesError if buffer does not contain enough bytes.
209
229
  */
210
230
  static deserialize(buf) {
211
- const typeValue = buf.getVI();
231
+ return _KeyValuePair.deserializeDelta(buf, 0n);
232
+ }
233
+ /**
234
+ * Deserializes a wire-form KVP whose Type field is a delta from `prevType`
235
+ * (the type of the previous KVP in the same list, or 0n if this is the
236
+ * first entry).
237
+ * @param buf - The buffer to read from.
238
+ * @param prevType - The type of the previous KVP in the same list.
239
+ * @throws ProtocolViolationError if prevType + delta exceeds 2^64 - 1.
240
+ */
241
+ static deserializeDelta(buf, prevType) {
242
+ const deltaType = buf.getVI();
243
+ const typeValue = prevType + deltaType;
244
+ if (typeValue > MAX_U64) {
245
+ throw new ProtocolViolationError(
246
+ "KeyValuePair.deserializeDelta",
247
+ `previous type ${prevType} plus delta type ${deltaType} exceeds 2^64 - 1`
248
+ );
249
+ }
212
250
  if (typeValue % 2n === 0n) {
213
251
  const value = buf.getVI();
214
252
  return new _KeyValuePair(typeValue, value);
@@ -243,6 +281,37 @@ var KeyValuePair = class _KeyValuePair {
243
281
  return false;
244
282
  }
245
283
  };
284
+ function serializeKvpList(items) {
285
+ const sorted = [...items].sort((a, b) => a.typeValue < b.typeValue ? -1 : a.typeValue > b.typeValue ? 1 : 0);
286
+ const buf = new ByteBuffer();
287
+ let prevType = 0n;
288
+ for (const kvp of sorted) {
289
+ buf.putBytes(kvp.serializeDelta(prevType).toUint8Array());
290
+ prevType = kvp.typeValue;
291
+ }
292
+ return buf.freeze();
293
+ }
294
+ function deserializeKvpList(buf, count) {
295
+ const n = typeof count === "bigint" ? Number(count) : count;
296
+ const items = new Array(n);
297
+ let prevType = 0n;
298
+ for (let i = 0; i < n; i++) {
299
+ const kvp = KeyValuePair.deserializeDelta(buf, prevType);
300
+ prevType = kvp.typeValue;
301
+ items[i] = kvp;
302
+ }
303
+ return items;
304
+ }
305
+ function deserializeKvpListUntilEmpty(buf) {
306
+ const items = [];
307
+ let prevType = 0n;
308
+ while (buf.remaining > 0) {
309
+ const kvp = KeyValuePair.deserializeDelta(buf, prevType);
310
+ prevType = kvp.typeValue;
311
+ items.push(kvp);
312
+ }
313
+ return items;
314
+ }
246
315
  function isVarInt(pair) {
247
316
  return pair.typeValue % 2n === 0n;
248
317
  }
@@ -845,13 +914,7 @@ var Datagram = class _Datagram {
845
914
  buf.putU8(this.publisherPriority);
846
915
  }
847
916
  if (ObjectDatagramType.hasExtensions(this.type)) {
848
- const extBuf = new ByteBuffer();
849
- if (this.extensionHeaders) {
850
- for (const header of this.extensionHeaders) {
851
- extBuf.putKeyValuePair(header);
852
- }
853
- }
854
- const extBytes = extBuf.toUint8Array();
917
+ const extBytes = this.extensionHeaders ? serializeKvpList(this.extensionHeaders).toUint8Array() : new Uint8Array(0);
855
918
  buf.putLengthPrefixedBytes(extBytes);
856
919
  }
857
920
  if (ObjectDatagramType.isStatus(this.type)) {
@@ -882,10 +945,7 @@ var Datagram = class _Datagram {
882
945
  if (ObjectDatagramType.hasExtensions(msgType)) {
883
946
  const extBytes = buf.getLengthPrefixedBytes();
884
947
  const headerBytes = new FrozenByteBuffer5(extBytes);
885
- extensionHeaders = [];
886
- while (headerBytes.remaining > 0) {
887
- extensionHeaders.push(headerBytes.getKeyValuePair());
888
- }
948
+ extensionHeaders = deserializeKvpListUntilEmpty(headerBytes);
889
949
  }
890
950
  let payload = null;
891
951
  let objectStatus = null;
@@ -1052,9 +1112,7 @@ var FetchObject = class _FetchObject {
1052
1112
  if (hasObjectId) buf.putVI(this.objectId);
1053
1113
  if (hasPriority) buf.putU8(this.publisherPriority);
1054
1114
  if (hasExtensions) {
1055
- const extBuf = new ByteBuffer();
1056
- for (const h of this.extensionHeaders) extBuf.putKeyValuePair(h);
1057
- buf.putLengthPrefixedBytes(extBuf.toUint8Array());
1115
+ buf.putLengthPrefixedBytes(serializeKvpList(this.extensionHeaders).toUint8Array());
1058
1116
  }
1059
1117
  const payloadBytes = this.payload ?? new Uint8Array(0);
1060
1118
  buf.putLengthPrefixedBytes(payloadBytes);
@@ -1140,10 +1198,7 @@ var FetchObject = class _FetchObject {
1140
1198
  if (hasExtensions) {
1141
1199
  const extLen = buf.getNumberVI();
1142
1200
  const headerBytes = new FrozenByteBuffer5(buf.getBytes(extLen));
1143
- extensionHeaders = [];
1144
- while (headerBytes.remaining > 0) {
1145
- extensionHeaders.push(headerBytes.getKeyValuePair());
1146
- }
1201
+ extensionHeaders = deserializeKvpListUntilEmpty(headerBytes);
1147
1202
  }
1148
1203
  const payloadLen = buf.getNumberVI();
1149
1204
  const payload = buf.getBytes(payloadLen);
@@ -1604,26 +1659,18 @@ var ImmutableExtensionsExtension = class _ImmutableExtensionsExtension {
1604
1659
  extensions;
1605
1660
  static TYPE = 11 /* ImmutableExtensions */;
1606
1661
  toKeyValuePair() {
1607
- const inner = new ByteBuffer();
1608
- for (const kvp of this.extensions) {
1609
- inner.putBytes(kvp.serialize().toUint8Array());
1610
- }
1611
- return KeyValuePair.tryNewBytes(_ImmutableExtensionsExtension.TYPE, inner.toUint8Array());
1662
+ return KeyValuePair.tryNewBytes(_ImmutableExtensionsExtension.TYPE, serializeKvpList(this.extensions).toUint8Array());
1612
1663
  }
1613
1664
  static fromKeyValuePair(pair) {
1614
1665
  if (Number(pair.typeValue) !== _ImmutableExtensionsExtension.TYPE || !(pair.value instanceof Uint8Array))
1615
1666
  return void 0;
1616
1667
  const buf = new FrozenByteBuffer5(pair.value);
1617
- const extensions = [];
1618
- while (buf.remaining > 0) {
1619
- const inner = KeyValuePair.deserialize(buf);
1620
- if (Number(inner.typeValue) === 11 /* ImmutableExtensions */) {
1621
- throw new ProtocolViolationError(
1622
- "ImmutableExtensionsExtension.fromKeyValuePair",
1623
- "ImmutableExtensions must not contain nested ImmutableExtensions (0x0B)"
1624
- );
1625
- }
1626
- extensions.push(inner);
1668
+ const extensions = deserializeKvpListUntilEmpty(buf);
1669
+ if (extensions.some((inner) => Number(inner.typeValue) === 11 /* ImmutableExtensions */)) {
1670
+ throw new ProtocolViolationError(
1671
+ "ImmutableExtensionsExtension.fromKeyValuePair",
1672
+ "ImmutableExtensions must not contain nested ImmutableExtensions (0x0B)"
1673
+ );
1627
1674
  }
1628
1675
  return new _ImmutableExtensionsExtension(extensions);
1629
1676
  }
@@ -1710,18 +1757,11 @@ var TrackExtension;
1710
1757
  }
1711
1758
  TrackExtension2.toKeyValuePair = toKeyValuePair;
1712
1759
  function deserializeAll(buf) {
1713
- const result = [];
1714
- while (buf.remaining > 0) {
1715
- const kvp = KeyValuePair.deserialize(buf);
1716
- result.push(fromKeyValuePair(kvp));
1717
- }
1718
- return result;
1760
+ return deserializeKvpListUntilEmpty(buf).map(fromKeyValuePair);
1719
1761
  }
1720
1762
  TrackExtension2.deserializeAll = deserializeAll;
1721
1763
  function serializeInto(exts, payload) {
1722
- for (const ext of exts) {
1723
- payload.putBytes(ext.toKeyValuePair().serialize().toUint8Array());
1724
- }
1764
+ payload.putBytes(serializeKvpList(exts.map((ext) => ext.toKeyValuePair())).toUint8Array());
1725
1765
  }
1726
1766
  TrackExtension2.serializeInto = serializeInto;
1727
1767
  function isDeliveryTimeout(ext) {
@@ -1762,26 +1802,21 @@ var ImmutableExtensionsObjectExtension = class _ImmutableExtensionsObjectExtensi
1762
1802
  extensions;
1763
1803
  static TYPE = 11 /* ImmutableExtensions */;
1764
1804
  toKeyValuePair() {
1765
- const inner = new ByteBuffer();
1766
- for (const kvp of this.extensions) {
1767
- inner.putBytes(kvp.serialize().toUint8Array());
1768
- }
1769
- return KeyValuePair.tryNewBytes(_ImmutableExtensionsObjectExtension.TYPE, inner.toUint8Array());
1805
+ return KeyValuePair.tryNewBytes(
1806
+ _ImmutableExtensionsObjectExtension.TYPE,
1807
+ serializeKvpList(this.extensions).toUint8Array()
1808
+ );
1770
1809
  }
1771
1810
  static fromKeyValuePair(pair) {
1772
1811
  if (Number(pair.typeValue) !== _ImmutableExtensionsObjectExtension.TYPE || !(pair.value instanceof Uint8Array))
1773
1812
  return void 0;
1774
1813
  const buf = new FrozenByteBuffer5(pair.value);
1775
- const extensions = [];
1776
- while (buf.remaining > 0) {
1777
- const inner = KeyValuePair.deserialize(buf);
1778
- if (Number(inner.typeValue) === 11 /* ImmutableExtensions */) {
1779
- throw new ProtocolViolationError(
1780
- "ImmutableExtensionsObjectExtension.fromKeyValuePair",
1781
- "ImmutableExtensions must not contain nested ImmutableExtensions (0x0B)"
1782
- );
1783
- }
1784
- extensions.push(inner);
1814
+ const extensions = deserializeKvpListUntilEmpty(buf);
1815
+ if (extensions.some((inner) => Number(inner.typeValue) === 11 /* ImmutableExtensions */)) {
1816
+ throw new ProtocolViolationError(
1817
+ "ImmutableExtensionsObjectExtension.fromKeyValuePair",
1818
+ "ImmutableExtensions must not contain nested ImmutableExtensions (0x0B)"
1819
+ );
1785
1820
  }
1786
1821
  return new _ImmutableExtensionsObjectExtension(extensions);
1787
1822
  }
@@ -1834,18 +1869,11 @@ var ObjectExtension;
1834
1869
  }
1835
1870
  ObjectExtension2.toKeyValuePair = toKeyValuePair;
1836
1871
  function deserializeAll(buf) {
1837
- const result = [];
1838
- while (buf.remaining > 0) {
1839
- const kvp = KeyValuePair.deserialize(buf);
1840
- result.push(fromKeyValuePair(kvp));
1841
- }
1842
- return result;
1872
+ return deserializeKvpListUntilEmpty(buf).map(fromKeyValuePair);
1843
1873
  }
1844
1874
  ObjectExtension2.deserializeAll = deserializeAll;
1845
1875
  function serializeInto(exts, payload) {
1846
- for (const ext of exts) {
1847
- payload.putBytes(ext.toKeyValuePair().serialize().toUint8Array());
1848
- }
1876
+ payload.putBytes(serializeKvpList(exts.map((ext) => ext.toKeyValuePair())).toUint8Array());
1849
1877
  }
1850
1878
  ObjectExtension2.serializeInto = serializeInto;
1851
1879
  function isImmutableExtensions(ext) {
@@ -1867,6 +1895,12 @@ var ObjectExtension;
1867
1895
  })(ObjectExtension || (ObjectExtension = {}));
1868
1896
 
1869
1897
  // src/model/data/subgroup_object.ts
1898
+ function normalizeExtensionHeaders(extensionHeaders) {
1899
+ if (extensionHeaders === null || extensionHeaders.length === 0) {
1900
+ return null;
1901
+ }
1902
+ return extensionHeaders;
1903
+ }
1870
1904
  var SubgroupObject = class _SubgroupObject {
1871
1905
  constructor(objectId, extensionHeaders, objectStatus, payload) {
1872
1906
  this.extensionHeaders = extensionHeaders;
@@ -1879,22 +1913,17 @@ var SubgroupObject = class _SubgroupObject {
1879
1913
  payload;
1880
1914
  objectId;
1881
1915
  static newWithStatus(objectId, extensionHeaders, objectStatus) {
1882
- return new _SubgroupObject(objectId, extensionHeaders, objectStatus, null);
1916
+ return new _SubgroupObject(objectId, normalizeExtensionHeaders(extensionHeaders), objectStatus, null);
1883
1917
  }
1884
1918
  static newWithPayload(objectId, extensionHeaders, payload) {
1885
- return new _SubgroupObject(objectId, extensionHeaders, null, payload);
1919
+ return new _SubgroupObject(objectId, normalizeExtensionHeaders(extensionHeaders), null, payload);
1886
1920
  }
1887
1921
  serialize(previousObjectId) {
1888
1922
  let objectIdDelta = previousObjectId ? this.objectId - previousObjectId - BigInt(1) : this.objectId;
1889
1923
  const buf = new ByteBuffer();
1890
1924
  buf.putVI(objectIdDelta);
1891
- const extensionHeaders = new ByteBuffer();
1892
- if (this.extensionHeaders) {
1893
- for (const header of this.extensionHeaders) {
1894
- extensionHeaders.putKeyValuePair(header);
1895
- }
1896
- const headerBytes = extensionHeaders.toUint8Array();
1897
- buf.putLengthPrefixedBytes(headerBytes);
1925
+ if (this.extensionHeaders !== null) {
1926
+ buf.putLengthPrefixedBytes(serializeKvpList(this.extensionHeaders).toUint8Array());
1898
1927
  }
1899
1928
  if (this.payload) {
1900
1929
  buf.putLengthPrefixedBytes(this.payload);
@@ -1909,12 +1938,9 @@ var SubgroupObject = class _SubgroupObject {
1909
1938
  let objectId = previousObjectId !== void 0 ? previousObjectId + objectDelta + BigInt(1) : objectDelta;
1910
1939
  let extensionHeaders = null;
1911
1940
  if (hasExtensions) {
1912
- extensionHeaders = [];
1913
1941
  const extLen = buf.getNumberVI();
1914
1942
  const headerBytes = new FrozenByteBuffer5(buf.getBytes(extLen));
1915
- while (headerBytes.remaining > 0) {
1916
- extensionHeaders.push(headerBytes.getKeyValuePair());
1917
- }
1943
+ extensionHeaders = deserializeKvpListUntilEmpty(headerBytes);
1918
1944
  }
1919
1945
  const payloadLen = buf.getNumberVI();
1920
1946
  let objectStatus = null;
@@ -1924,7 +1950,7 @@ var SubgroupObject = class _SubgroupObject {
1924
1950
  } else {
1925
1951
  payload = buf.getBytes(payloadLen);
1926
1952
  }
1927
- return new _SubgroupObject(objectId, extensionHeaders, objectStatus, payload);
1953
+ return new _SubgroupObject(objectId, normalizeExtensionHeaders(extensionHeaders), objectStatus, payload);
1928
1954
  }
1929
1955
  };
1930
1956
 
@@ -3080,9 +3106,7 @@ var PublishNamespace = class _PublishNamespace {
3080
3106
  payload.putVI(this.requestId);
3081
3107
  payload.putTuple(this.trackNamespace);
3082
3108
  payload.putVI(this.parameters.length);
3083
- for (const param of this.parameters) {
3084
- payload.putKeyValuePair(param.toKeyValuePair());
3085
- }
3109
+ payload.putBytes(serializeKvpList(this.parameters.map((p) => p.toKeyValuePair())).toUint8Array());
3086
3110
  const payloadBytes = payload.toUint8Array();
3087
3111
  if (payloadBytes.length > 65535) {
3088
3112
  throw new LengthExceedsMaxError("PublishNamespace::serialize(payloadBytes.length)", 65535, payloadBytes.length);
@@ -3103,10 +3127,7 @@ var PublishNamespace = class _PublishNamespace {
3103
3127
  const requestId = buf.getVI();
3104
3128
  const trackNamespace = buf.getTuple();
3105
3129
  const paramCount = buf.getNumberVI();
3106
- const rawParams = new Array(paramCount);
3107
- for (let i = 0; i < paramCount; i++) {
3108
- rawParams[i] = buf.getKeyValuePair();
3109
- }
3130
+ const rawParams = deserializeKvpList(buf, paramCount);
3110
3131
  const parameters = MessageParameters.fromKeyValuePairs(rawParams);
3111
3132
  return new _PublishNamespace(requestId, trackNamespace, parameters);
3112
3133
  }
@@ -3223,9 +3244,7 @@ var ClientSetup = class _ClientSetup {
3223
3244
  buf.putVI(32 /* ClientSetup */);
3224
3245
  const payload = new ByteBuffer();
3225
3246
  payload.putVI(this.setupParameters.length);
3226
- for (const param of this.setupParameters) {
3227
- payload.putKeyValuePair(param);
3228
- }
3247
+ payload.putBytes(serializeKvpList(this.setupParameters).toUint8Array());
3229
3248
  const payloadBytes = payload.toUint8Array();
3230
3249
  if (payloadBytes.length > 65535) {
3231
3250
  throw new LengthExceedsMaxError("ClientSetup::serialize(payload_length)", 65535, payloadBytes.length);
@@ -3236,10 +3255,7 @@ var ClientSetup = class _ClientSetup {
3236
3255
  }
3237
3256
  static parsePayload(buf) {
3238
3257
  const paramCount = buf.getNumberVI();
3239
- const setupParameters = new Array(paramCount);
3240
- for (let i = 0; i < paramCount; i++) {
3241
- setupParameters[i] = buf.getKeyValuePair();
3242
- }
3258
+ const setupParameters = deserializeKvpList(buf, paramCount);
3243
3259
  return new _ClientSetup(setupParameters);
3244
3260
  }
3245
3261
  };
@@ -3278,9 +3294,7 @@ var Fetch = class _Fetch {
3278
3294
  }
3279
3295
  }
3280
3296
  payload.putVI(this.parameters.length);
3281
- for (const param of this.parameters) {
3282
- payload.putKeyValuePair(param.toKeyValuePair());
3283
- }
3297
+ payload.putBytes(serializeKvpList(this.parameters.map((p) => p.toKeyValuePair())).toUint8Array());
3284
3298
  const payloadBytes = payload.toUint8Array();
3285
3299
  if (payloadBytes.length > 65535) {
3286
3300
  throw new LengthExceedsMaxError("Fetch::serialize(payload_length)", 65535, payloadBytes.length);
@@ -3319,10 +3333,7 @@ var Fetch = class _Fetch {
3319
3333
  throw new Error(`Unknown fetch type: ${fetchType}`);
3320
3334
  }
3321
3335
  const paramCount = buf.getNumberVI();
3322
- const rawParams = new Array(paramCount);
3323
- for (let i = 0; i < paramCount; i++) {
3324
- rawParams[i] = buf.getKeyValuePair();
3325
- }
3336
+ const rawParams = deserializeKvpList(buf, paramCount);
3326
3337
  const parameters = MessageParameters.fromKeyValuePairs(rawParams);
3327
3338
  return new _Fetch(requestId, props, parameters);
3328
3339
  }
@@ -3378,9 +3389,7 @@ var FetchOk = class _FetchOk {
3378
3389
  payload.putU8(this.endOfTrack ? 1 : 0);
3379
3390
  payload.putLocation(this.endLocation);
3380
3391
  payload.putVI(this.parameters.length);
3381
- for (const param of this.parameters) {
3382
- payload.putKeyValuePair(param.toKeyValuePair());
3383
- }
3392
+ payload.putBytes(serializeKvpList(this.parameters.map((p) => p.toKeyValuePair())).toUint8Array());
3384
3393
  TrackExtension.serializeInto(this.trackExtensions, payload);
3385
3394
  const payloadBytes = payload.toUint8Array();
3386
3395
  if (payloadBytes.length > 65535) {
@@ -3409,10 +3418,7 @@ var FetchOk = class _FetchOk {
3409
3418
  }
3410
3419
  const endLocation = buf.getLocation();
3411
3420
  const paramCount = buf.getNumberVI();
3412
- const rawParams = new Array(paramCount);
3413
- for (let i = 0; i < paramCount; i++) {
3414
- rawParams[i] = buf.getKeyValuePair();
3415
- }
3421
+ const rawParams = deserializeKvpList(buf, paramCount);
3416
3422
  const parameters = MessageParameters.fromKeyValuePairs(rawParams);
3417
3423
  const trackExtensions = TrackExtension.deserializeAll(buf);
3418
3424
  return new _FetchOk(requestId, endOfTrack, endLocation, parameters, trackExtensions);
@@ -3524,9 +3530,7 @@ var ServerSetup = class _ServerSetup {
3524
3530
  buf.putVI(33 /* ServerSetup */);
3525
3531
  const payload = new ByteBuffer();
3526
3532
  payload.putVI(this.setupParameters.length);
3527
- for (const param of this.setupParameters) {
3528
- payload.putKeyValuePair(param);
3529
- }
3533
+ payload.putBytes(serializeKvpList(this.setupParameters).toUint8Array());
3530
3534
  const payloadBytes = payload.toUint8Array();
3531
3535
  if (payloadBytes.length > 65535) {
3532
3536
  throw new LengthExceedsMaxError("ServerSetup::serialize(payloadBytes.length)", 65535, payloadBytes.length);
@@ -3537,10 +3541,7 @@ var ServerSetup = class _ServerSetup {
3537
3541
  }
3538
3542
  static parsePayload(buf) {
3539
3543
  const paramCount = buf.getNumberVI();
3540
- const setupParameters = new Array(paramCount);
3541
- for (let i = 0; i < paramCount; i++) {
3542
- setupParameters[i] = buf.getKeyValuePair();
3543
- }
3544
+ const setupParameters = deserializeKvpList(buf, paramCount);
3544
3545
  return new _ServerSetup(setupParameters);
3545
3546
  }
3546
3547
  };
@@ -3583,9 +3584,7 @@ var Subscribe = class _Subscribe {
3583
3584
  payload.putVI(this.requestId);
3584
3585
  payload.putBytes(this.fullTrackName.serialize().toUint8Array());
3585
3586
  payload.putVI(this.parameters.length);
3586
- for (const param of this.parameters) {
3587
- payload.putBytes(param.toKeyValuePair().serialize().toUint8Array());
3588
- }
3587
+ payload.putBytes(serializeKvpList(this.parameters.map((p) => p.toKeyValuePair())).toUint8Array());
3589
3588
  const payloadBytes = payload.toUint8Array();
3590
3589
  buf.putU16(payloadBytes.length);
3591
3590
  buf.putBytes(payloadBytes);
@@ -3596,8 +3595,7 @@ var Subscribe = class _Subscribe {
3596
3595
  const fullTrackName = buf.getFullTrackName();
3597
3596
  const paramCount = Number(buf.getVI());
3598
3597
  const parameters = [];
3599
- for (let i = 0; i < paramCount; i++) {
3600
- const kvp = KeyValuePair.deserialize(buf);
3598
+ for (const kvp of deserializeKvpList(buf, paramCount)) {
3601
3599
  const param = MessageParameter.fromKeyValuePair(kvp);
3602
3600
  if (param !== void 0) parameters.push(param);
3603
3601
  }
@@ -3674,9 +3672,7 @@ var Publish = class _Publish {
3674
3672
  payload.putBytes(this.fullTrackName.serialize().toUint8Array());
3675
3673
  payload.putVI(this.trackAlias);
3676
3674
  payload.putVI(this.parameters.length);
3677
- for (const param of this.parameters) {
3678
- payload.putKeyValuePair(param.toKeyValuePair());
3679
- }
3675
+ payload.putBytes(serializeKvpList(this.parameters.map((p) => p.toKeyValuePair())).toUint8Array());
3680
3676
  TrackExtension.serializeInto(this.trackExtensions, payload);
3681
3677
  const payloadBytes = payload.toUint8Array();
3682
3678
  if (payloadBytes.length > 65535) {
@@ -3691,10 +3687,7 @@ var Publish = class _Publish {
3691
3687
  const fullTrackName = buf.getFullTrackName();
3692
3688
  const trackAlias = buf.getVI();
3693
3689
  const paramCount = buf.getNumberVI();
3694
- const rawParams = new Array(paramCount);
3695
- for (let i = 0; i < paramCount; i++) {
3696
- rawParams[i] = buf.getKeyValuePair();
3697
- }
3690
+ const rawParams = deserializeKvpList(buf, paramCount);
3698
3691
  const parameters = MessageParameters.fromKeyValuePairs(rawParams);
3699
3692
  const trackExtensions = TrackExtension.deserializeAll(buf);
3700
3693
  return new _Publish(requestId, fullTrackName, trackAlias, parameters, trackExtensions);
@@ -3718,9 +3711,7 @@ var PublishOk = class _PublishOk {
3718
3711
  const payload = new ByteBuffer();
3719
3712
  payload.putVI(this.requestId);
3720
3713
  payload.putVI(this.parameters.length);
3721
- for (const param of this.parameters) {
3722
- payload.putKeyValuePair(param.toKeyValuePair());
3723
- }
3714
+ payload.putBytes(serializeKvpList(this.parameters.map((p) => p.toKeyValuePair())).toUint8Array());
3724
3715
  const payloadBytes = payload.toUint8Array();
3725
3716
  if (payloadBytes.length > 65535) {
3726
3717
  throw new LengthExceedsMaxError("PublishOk::serialize(payloadBytes.length)", 65535, payloadBytes.length);
@@ -3732,10 +3723,7 @@ var PublishOk = class _PublishOk {
3732
3723
  static parsePayload(buf) {
3733
3724
  const requestId = buf.getVI();
3734
3725
  const paramCount = buf.getVI();
3735
- const kvps = [];
3736
- for (let i = 0; i < paramCount; i++) {
3737
- kvps.push(buf.getKeyValuePair());
3738
- }
3726
+ const kvps = deserializeKvpList(buf, paramCount);
3739
3727
  const parameters = MessageParameters.fromKeyValuePairs(kvps);
3740
3728
  return new _PublishOk(requestId, parameters);
3741
3729
  }
@@ -3763,9 +3751,7 @@ var SubscribeOk = class _SubscribeOk {
3763
3751
  payload.putVI(this.requestId);
3764
3752
  payload.putVI(this.trackAlias);
3765
3753
  payload.putVI(this.parameters.length);
3766
- for (const param of this.parameters) {
3767
- payload.putKeyValuePair(param.toKeyValuePair());
3768
- }
3754
+ payload.putBytes(serializeKvpList(this.parameters.map((p) => p.toKeyValuePair())).toUint8Array());
3769
3755
  TrackExtension.serializeInto(this.trackExtensions, payload);
3770
3756
  const payloadBytes = payload.toUint8Array();
3771
3757
  if (payloadBytes.length > 65535) {
@@ -3779,10 +3765,7 @@ var SubscribeOk = class _SubscribeOk {
3779
3765
  const requestId = buf.getVI();
3780
3766
  const trackAlias = buf.getVI();
3781
3767
  const paramCount = buf.getNumberVI();
3782
- const rawParams = new Array(paramCount);
3783
- for (let i = 0; i < paramCount; i++) {
3784
- rawParams[i] = buf.getKeyValuePair();
3785
- }
3768
+ const rawParams = deserializeKvpList(buf, paramCount);
3786
3769
  const parameters = MessageParameters.fromKeyValuePairs(rawParams);
3787
3770
  const trackExtensions = TrackExtension.deserializeAll(buf);
3788
3771
  return new _SubscribeOk(requestId, trackAlias, parameters, trackExtensions);
@@ -3809,9 +3792,7 @@ var RequestUpdate = class _RequestUpdate {
3809
3792
  payload.putVI(this.requestId);
3810
3793
  payload.putVI(this.existingRequestId);
3811
3794
  payload.putVI(this.parameters.length);
3812
- for (const param of this.parameters) {
3813
- payload.putBytes(param.toKeyValuePair().serialize().toUint8Array());
3814
- }
3795
+ payload.putBytes(serializeKvpList(this.parameters.map((p) => p.toKeyValuePair())).toUint8Array());
3815
3796
  const payloadBytes = payload.toUint8Array();
3816
3797
  if (payloadBytes.length > 65535) {
3817
3798
  throw new LengthExceedsMaxError("RequestUpdate::serialize(payloadBytes)", 65535, payloadBytes.length);
@@ -3829,8 +3810,7 @@ var RequestUpdate = class _RequestUpdate {
3829
3810
  throw new CastingError("RequestUpdate.deserialize paramCount", "bigint", "number", `${paramCountBig}`);
3830
3811
  }
3831
3812
  const parameters = [];
3832
- for (let i = 0; i < paramCount; i++) {
3833
- const kvp = KeyValuePair.deserialize(buf);
3813
+ for (const kvp of deserializeKvpList(buf, paramCount)) {
3834
3814
  const param = MessageParameter.fromKeyValuePair(kvp);
3835
3815
  if (param !== void 0) parameters.push(param);
3836
3816
  }
@@ -3987,9 +3967,7 @@ var TrackStatus = class _TrackStatus {
3987
3967
  payload.putVI(this.endGroup);
3988
3968
  }
3989
3969
  payload.putVI(this.subscribeParameters.length);
3990
- for (const param of this.subscribeParameters) {
3991
- payload.putKeyValuePair(param.toKeyValuePair());
3992
- }
3970
+ payload.putBytes(serializeKvpList(this.subscribeParameters.map((p) => p.toKeyValuePair())).toUint8Array());
3993
3971
  const payloadBytes = payload.toUint8Array();
3994
3972
  buf.putU16(payloadBytes.length);
3995
3973
  buf.putBytes(payloadBytes);
@@ -4012,10 +3990,7 @@ var TrackStatus = class _TrackStatus {
4012
3990
  endGroup = buf.getVI();
4013
3991
  }
4014
3992
  const paramCount = Number(buf.getVI());
4015
- const rawParams = new Array(paramCount);
4016
- for (let i = 0; i < paramCount; i++) {
4017
- rawParams[i] = buf.getKeyValuePair();
4018
- }
3993
+ const rawParams = deserializeKvpList(buf, paramCount);
4019
3994
  const subscribeParameters = MessageParameters.fromKeyValuePairs(rawParams);
4020
3995
  return new _TrackStatus(
4021
3996
  requestId,
@@ -4133,9 +4108,7 @@ var SubscribeNamespace = class _SubscribeNamespace {
4133
4108
  payload.putTuple(this.trackNamespacePrefix);
4134
4109
  payload.putVI(this.subscribeOptions);
4135
4110
  payload.putVI(this.parameters.length);
4136
- for (const param of this.parameters) {
4137
- payload.putKeyValuePair(param.toKeyValuePair());
4138
- }
4111
+ payload.putBytes(serializeKvpList(this.parameters.map((p) => p.toKeyValuePair())).toUint8Array());
4139
4112
  const payloadBytes = payload.toUint8Array();
4140
4113
  if (payloadBytes.length > 65535) {
4141
4114
  throw new LengthExceedsMaxError("SubscribeNamespace::serialize(payloadBytes.length)", 65535, payloadBytes.length);
@@ -4149,10 +4122,7 @@ var SubscribeNamespace = class _SubscribeNamespace {
4149
4122
  const trackNamespacePrefix = buf.getTuple();
4150
4123
  const subscribeOptions = Number(buf.getVI());
4151
4124
  const paramCount = buf.getNumberVI();
4152
- const rawParams = new Array(paramCount);
4153
- for (let i = 0; i < paramCount; i++) {
4154
- rawParams[i] = buf.getKeyValuePair();
4155
- }
4125
+ const rawParams = deserializeKvpList(buf, paramCount);
4156
4126
  const parameters = MessageParameters.fromKeyValuePairs(rawParams);
4157
4127
  return new _SubscribeNamespace(requestId, trackNamespacePrefix, subscribeOptions, parameters);
4158
4128
  }
@@ -4203,9 +4173,7 @@ var RequestOk = class _RequestOk {
4203
4173
  const payload = new ByteBuffer();
4204
4174
  payload.putVI(this.requestId);
4205
4175
  payload.putVI(BigInt(this.parameters.length));
4206
- for (const param of this.parameters) {
4207
- payload.putBytes(param.toKeyValuePair().serialize().toUint8Array());
4208
- }
4176
+ payload.putBytes(serializeKvpList(this.parameters.map((p) => p.toKeyValuePair())).toUint8Array());
4209
4177
  const payloadBytes = payload.toUint8Array();
4210
4178
  if (payloadBytes.length > 65535) {
4211
4179
  throw new LengthExceedsMaxError("RequestOk::serialize(payloadBytes)", 65535, payloadBytes.length);
@@ -4222,8 +4190,7 @@ var RequestOk = class _RequestOk {
4222
4190
  throw new CastingError("RequestOk.parsePayload numParams", "bigint", "number", `${numParamsBig}`);
4223
4191
  }
4224
4192
  const parameters = [];
4225
- for (let i = 0; i < numParams; i++) {
4226
- const kvp = KeyValuePair.deserialize(buf);
4193
+ for (const kvp of deserializeKvpList(buf, numParams)) {
4227
4194
  const param = MessageParameter.fromKeyValuePair(kvp);
4228
4195
  if (param !== void 0) parameters.push(param);
4229
4196
  }
@@ -4365,9 +4332,7 @@ var Switch = class _Switch {
4365
4332
  payload.putBytes(this.fullTrackName.serialize().toUint8Array());
4366
4333
  payload.putVI(this.subscriptionRequestId);
4367
4334
  payload.putVI(this.parameters.length);
4368
- for (const param of this.parameters) {
4369
- payload.putBytes(param.serialize().toUint8Array());
4370
- }
4335
+ payload.putBytes(serializeKvpList(this.parameters).toUint8Array());
4371
4336
  const payloadBytes = payload.toUint8Array();
4372
4337
  buf.putU16(payloadBytes.length);
4373
4338
  buf.putBytes(payloadBytes);
@@ -4378,10 +4343,7 @@ var Switch = class _Switch {
4378
4343
  const fullTrackName = buf.getFullTrackName();
4379
4344
  const subscriptionRequestId = buf.getVI();
4380
4345
  const paramCount = Number(buf.getVI());
4381
- const parameters = [];
4382
- for (let i = 0; i < paramCount; i++) {
4383
- parameters.push(KeyValuePair.deserialize(buf));
4384
- }
4346
+ const parameters = deserializeKvpList(buf, paramCount);
4385
4347
  return new _Switch(requestId, fullTrackName, subscriptionRequestId, parameters);
4386
4348
  }
4387
4349
  };
@@ -7001,7 +6963,6 @@ var MOQtailClient = class _MOQtailClient {
7001
6963
  * // Register the track for live subscription
7002
6964
  * client.addOrUpdateTrack({
7003
6965
  * fullTrackName: { namespace: ["camera"], name: "main" },
7004
- * forwardingPreference: ObjectForwardingPreference.Latest,
7005
6966
  * trackSource: { live: liveReadableStream },
7006
6967
  * publisherPriority: 0 // highest priority
7007
6968
  * });
@@ -7011,7 +6972,6 @@ var MOQtailClient = class _MOQtailClient {
7011
6972
  * const cache = new MemoryObjectCache(); // Caches are not yet fully supported
7012
6973
  * client.addOrUpdateTrack({
7013
6974
  * fullTrackName: { namespace: ["camera"], name: "main" },
7014
- * forwardingPreference: ObjectForwardingPreference.Latest,
7015
6975
  * trackSource: { live: liveReadableStream, past: cache },
7016
6976
  * publisherPriority: 8
7017
6977
  * });