moqtail 0.10.1 → 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/model.cjs CHANGED
@@ -344,6 +344,7 @@ var TerminationError = class extends MOQtailError {
344
344
 
345
345
  // src/model/common/pair.ts
346
346
  var MAX_VALUE_LENGTH = 2 ** 16 - 1;
347
+ var MAX_U64 = 2n ** 64n - 1n;
347
348
  var KeyValuePair = class _KeyValuePair {
348
349
  /**
349
350
  * The key/type identifier for this pair.
@@ -403,11 +404,29 @@ var KeyValuePair = class _KeyValuePair {
403
404
  }
404
405
  /**
405
406
  * Serializes this key-value pair to a frozen byte buffer.
407
+ * Equivalent to {@link KeyValuePair.serializeDelta} with `prevType = 0n`.
406
408
  * @returns The serialized buffer.
407
409
  */
408
410
  serialize() {
411
+ return this.serializeDelta(0n);
412
+ }
413
+ /**
414
+ * Serializes this pair's wire form, encoding the Type as a delta from
415
+ * `prevType` (the type of the previous KVP in the same list, or 0n if this
416
+ * is the first entry).
417
+ * @param prevType - The type of the previous KVP in the same list.
418
+ * @throws ProtocolViolationError if this pair's type is less than prevType
419
+ * (Delta Type is an unsigned varint, so the list must be sorted ascending).
420
+ */
421
+ serializeDelta(prevType) {
422
+ if (this.typeValue < prevType) {
423
+ throw new ProtocolViolationError(
424
+ "KeyValuePair.serializeDelta",
425
+ `type ${this.typeValue} is less than previous type ${prevType}; a KVP list must be sorted by ascending type to be delta-encoded`
426
+ );
427
+ }
409
428
  const buf = new ByteBuffer();
410
- buf.putVI(this.typeValue);
429
+ buf.putVI(this.typeValue - prevType);
411
430
  if (isVarInt(this)) {
412
431
  buf.putVI(this.value);
413
432
  } else if (isBytes(this)) {
@@ -417,13 +436,32 @@ var KeyValuePair = class _KeyValuePair {
417
436
  }
418
437
  /**
419
438
  * Deserializes a KeyValuePair from a buffer.
439
+ * Equivalent to {@link KeyValuePair.deserializeDelta} with `prevType = 0n`.
420
440
  * @param buf - The buffer to read from.
421
441
  * @returns The deserialized KeyValuePair.
422
442
  * @throws LengthExceedsMaxError if blob length exceeds 65535 bytes.
423
443
  * @throws NotEnoughBytesError if buffer does not contain enough bytes.
424
444
  */
425
445
  static deserialize(buf) {
426
- const typeValue = buf.getVI();
446
+ return _KeyValuePair.deserializeDelta(buf, 0n);
447
+ }
448
+ /**
449
+ * Deserializes a wire-form KVP whose Type field is a delta from `prevType`
450
+ * (the type of the previous KVP in the same list, or 0n if this is the
451
+ * first entry).
452
+ * @param buf - The buffer to read from.
453
+ * @param prevType - The type of the previous KVP in the same list.
454
+ * @throws ProtocolViolationError if prevType + delta exceeds 2^64 - 1.
455
+ */
456
+ static deserializeDelta(buf, prevType) {
457
+ const deltaType = buf.getVI();
458
+ const typeValue = prevType + deltaType;
459
+ if (typeValue > MAX_U64) {
460
+ throw new ProtocolViolationError(
461
+ "KeyValuePair.deserializeDelta",
462
+ `previous type ${prevType} plus delta type ${deltaType} exceeds 2^64 - 1`
463
+ );
464
+ }
427
465
  if (typeValue % 2n === 0n) {
428
466
  const value = buf.getVI();
429
467
  return new _KeyValuePair(typeValue, value);
@@ -458,6 +496,37 @@ var KeyValuePair = class _KeyValuePair {
458
496
  return false;
459
497
  }
460
498
  };
499
+ function serializeKvpList(items) {
500
+ const sorted = [...items].sort((a, b) => a.typeValue < b.typeValue ? -1 : a.typeValue > b.typeValue ? 1 : 0);
501
+ const buf = new ByteBuffer();
502
+ let prevType = 0n;
503
+ for (const kvp of sorted) {
504
+ buf.putBytes(kvp.serializeDelta(prevType).toUint8Array());
505
+ prevType = kvp.typeValue;
506
+ }
507
+ return buf.freeze();
508
+ }
509
+ function deserializeKvpList(buf, count) {
510
+ const n = typeof count === "bigint" ? Number(count) : count;
511
+ const items = new Array(n);
512
+ let prevType = 0n;
513
+ for (let i = 0; i < n; i++) {
514
+ const kvp = KeyValuePair.deserializeDelta(buf, prevType);
515
+ prevType = kvp.typeValue;
516
+ items[i] = kvp;
517
+ }
518
+ return items;
519
+ }
520
+ function deserializeKvpListUntilEmpty(buf) {
521
+ const items = [];
522
+ let prevType = 0n;
523
+ while (buf.remaining > 0) {
524
+ const kvp = KeyValuePair.deserializeDelta(buf, prevType);
525
+ prevType = kvp.typeValue;
526
+ items.push(kvp);
527
+ }
528
+ return items;
529
+ }
461
530
  function isVarInt(pair) {
462
531
  return pair.typeValue % 2n === 0n;
463
532
  }
@@ -1060,13 +1129,7 @@ var Datagram = class _Datagram {
1060
1129
  buf.putU8(this.publisherPriority);
1061
1130
  }
1062
1131
  if (exports.ObjectDatagramType.hasExtensions(this.type)) {
1063
- const extBuf = new ByteBuffer();
1064
- if (this.extensionHeaders) {
1065
- for (const header of this.extensionHeaders) {
1066
- extBuf.putKeyValuePair(header);
1067
- }
1068
- }
1069
- const extBytes = extBuf.toUint8Array();
1132
+ const extBytes = this.extensionHeaders ? serializeKvpList(this.extensionHeaders).toUint8Array() : new Uint8Array(0);
1070
1133
  buf.putLengthPrefixedBytes(extBytes);
1071
1134
  }
1072
1135
  if (exports.ObjectDatagramType.isStatus(this.type)) {
@@ -1097,10 +1160,7 @@ var Datagram = class _Datagram {
1097
1160
  if (exports.ObjectDatagramType.hasExtensions(msgType)) {
1098
1161
  const extBytes = buf.getLengthPrefixedBytes();
1099
1162
  const headerBytes = new FrozenByteBuffer5(extBytes);
1100
- extensionHeaders = [];
1101
- while (headerBytes.remaining > 0) {
1102
- extensionHeaders.push(headerBytes.getKeyValuePair());
1103
- }
1163
+ extensionHeaders = deserializeKvpListUntilEmpty(headerBytes);
1104
1164
  }
1105
1165
  let payload = null;
1106
1166
  let objectStatus = null;
@@ -1272,9 +1332,7 @@ var FetchObject = class _FetchObject {
1272
1332
  if (hasObjectId) buf.putVI(this.objectId);
1273
1333
  if (hasPriority) buf.putU8(this.publisherPriority);
1274
1334
  if (hasExtensions) {
1275
- const extBuf = new ByteBuffer();
1276
- for (const h of this.extensionHeaders) extBuf.putKeyValuePair(h);
1277
- buf.putLengthPrefixedBytes(extBuf.toUint8Array());
1335
+ buf.putLengthPrefixedBytes(serializeKvpList(this.extensionHeaders).toUint8Array());
1278
1336
  }
1279
1337
  const payloadBytes = this.payload ?? new Uint8Array(0);
1280
1338
  buf.putLengthPrefixedBytes(payloadBytes);
@@ -1360,10 +1418,7 @@ var FetchObject = class _FetchObject {
1360
1418
  if (hasExtensions) {
1361
1419
  const extLen = buf.getNumberVI();
1362
1420
  const headerBytes = new FrozenByteBuffer5(buf.getBytes(extLen));
1363
- extensionHeaders = [];
1364
- while (headerBytes.remaining > 0) {
1365
- extensionHeaders.push(headerBytes.getKeyValuePair());
1366
- }
1421
+ extensionHeaders = deserializeKvpListUntilEmpty(headerBytes);
1367
1422
  }
1368
1423
  const payloadLen = buf.getNumberVI();
1369
1424
  const payload = buf.getBytes(payloadLen);
@@ -2027,26 +2082,18 @@ var ImmutableExtensionsExtension = class _ImmutableExtensionsExtension {
2027
2082
  extensions;
2028
2083
  static TYPE = 11 /* ImmutableExtensions */;
2029
2084
  toKeyValuePair() {
2030
- const inner = new ByteBuffer();
2031
- for (const kvp of this.extensions) {
2032
- inner.putBytes(kvp.serialize().toUint8Array());
2033
- }
2034
- return KeyValuePair.tryNewBytes(_ImmutableExtensionsExtension.TYPE, inner.toUint8Array());
2085
+ return KeyValuePair.tryNewBytes(_ImmutableExtensionsExtension.TYPE, serializeKvpList(this.extensions).toUint8Array());
2035
2086
  }
2036
2087
  static fromKeyValuePair(pair) {
2037
2088
  if (Number(pair.typeValue) !== _ImmutableExtensionsExtension.TYPE || !(pair.value instanceof Uint8Array))
2038
2089
  return void 0;
2039
2090
  const buf = new FrozenByteBuffer5(pair.value);
2040
- const extensions = [];
2041
- while (buf.remaining > 0) {
2042
- const inner = KeyValuePair.deserialize(buf);
2043
- if (Number(inner.typeValue) === 11 /* ImmutableExtensions */) {
2044
- throw new ProtocolViolationError(
2045
- "ImmutableExtensionsExtension.fromKeyValuePair",
2046
- "ImmutableExtensions must not contain nested ImmutableExtensions (0x0B)"
2047
- );
2048
- }
2049
- extensions.push(inner);
2091
+ const extensions = deserializeKvpListUntilEmpty(buf);
2092
+ if (extensions.some((inner) => Number(inner.typeValue) === 11 /* ImmutableExtensions */)) {
2093
+ throw new ProtocolViolationError(
2094
+ "ImmutableExtensionsExtension.fromKeyValuePair",
2095
+ "ImmutableExtensions must not contain nested ImmutableExtensions (0x0B)"
2096
+ );
2050
2097
  }
2051
2098
  return new _ImmutableExtensionsExtension(extensions);
2052
2099
  }
@@ -2133,18 +2180,11 @@ exports.TrackExtension = void 0;
2133
2180
  }
2134
2181
  TrackExtension2.toKeyValuePair = toKeyValuePair;
2135
2182
  function deserializeAll(buf) {
2136
- const result = [];
2137
- while (buf.remaining > 0) {
2138
- const kvp = KeyValuePair.deserialize(buf);
2139
- result.push(fromKeyValuePair(kvp));
2140
- }
2141
- return result;
2183
+ return deserializeKvpListUntilEmpty(buf).map(fromKeyValuePair);
2142
2184
  }
2143
2185
  TrackExtension2.deserializeAll = deserializeAll;
2144
2186
  function serializeInto(exts, payload) {
2145
- for (const ext of exts) {
2146
- payload.putBytes(ext.toKeyValuePair().serialize().toUint8Array());
2147
- }
2187
+ payload.putBytes(serializeKvpList(exts.map((ext) => ext.toKeyValuePair())).toUint8Array());
2148
2188
  }
2149
2189
  TrackExtension2.serializeInto = serializeInto;
2150
2190
  function isDeliveryTimeout(ext) {
@@ -2185,26 +2225,21 @@ var ImmutableExtensionsObjectExtension = class _ImmutableExtensionsObjectExtensi
2185
2225
  extensions;
2186
2226
  static TYPE = 11 /* ImmutableExtensions */;
2187
2227
  toKeyValuePair() {
2188
- const inner = new ByteBuffer();
2189
- for (const kvp of this.extensions) {
2190
- inner.putBytes(kvp.serialize().toUint8Array());
2191
- }
2192
- return KeyValuePair.tryNewBytes(_ImmutableExtensionsObjectExtension.TYPE, inner.toUint8Array());
2228
+ return KeyValuePair.tryNewBytes(
2229
+ _ImmutableExtensionsObjectExtension.TYPE,
2230
+ serializeKvpList(this.extensions).toUint8Array()
2231
+ );
2193
2232
  }
2194
2233
  static fromKeyValuePair(pair) {
2195
2234
  if (Number(pair.typeValue) !== _ImmutableExtensionsObjectExtension.TYPE || !(pair.value instanceof Uint8Array))
2196
2235
  return void 0;
2197
2236
  const buf = new FrozenByteBuffer5(pair.value);
2198
- const extensions = [];
2199
- while (buf.remaining > 0) {
2200
- const inner = KeyValuePair.deserialize(buf);
2201
- if (Number(inner.typeValue) === 11 /* ImmutableExtensions */) {
2202
- throw new ProtocolViolationError(
2203
- "ImmutableExtensionsObjectExtension.fromKeyValuePair",
2204
- "ImmutableExtensions must not contain nested ImmutableExtensions (0x0B)"
2205
- );
2206
- }
2207
- extensions.push(inner);
2237
+ const extensions = deserializeKvpListUntilEmpty(buf);
2238
+ if (extensions.some((inner) => Number(inner.typeValue) === 11 /* ImmutableExtensions */)) {
2239
+ throw new ProtocolViolationError(
2240
+ "ImmutableExtensionsObjectExtension.fromKeyValuePair",
2241
+ "ImmutableExtensions must not contain nested ImmutableExtensions (0x0B)"
2242
+ );
2208
2243
  }
2209
2244
  return new _ImmutableExtensionsObjectExtension(extensions);
2210
2245
  }
@@ -2257,18 +2292,11 @@ exports.ObjectExtension = void 0;
2257
2292
  }
2258
2293
  ObjectExtension2.toKeyValuePair = toKeyValuePair;
2259
2294
  function deserializeAll(buf) {
2260
- const result = [];
2261
- while (buf.remaining > 0) {
2262
- const kvp = KeyValuePair.deserialize(buf);
2263
- result.push(fromKeyValuePair(kvp));
2264
- }
2265
- return result;
2295
+ return deserializeKvpListUntilEmpty(buf).map(fromKeyValuePair);
2266
2296
  }
2267
2297
  ObjectExtension2.deserializeAll = deserializeAll;
2268
2298
  function serializeInto(exts, payload) {
2269
- for (const ext of exts) {
2270
- payload.putBytes(ext.toKeyValuePair().serialize().toUint8Array());
2271
- }
2299
+ payload.putBytes(serializeKvpList(exts.map((ext) => ext.toKeyValuePair())).toUint8Array());
2272
2300
  }
2273
2301
  ObjectExtension2.serializeInto = serializeInto;
2274
2302
  function isImmutableExtensions(ext) {
@@ -2290,6 +2318,12 @@ exports.ObjectExtension = void 0;
2290
2318
  })(exports.ObjectExtension || (exports.ObjectExtension = {}));
2291
2319
 
2292
2320
  // src/model/data/subgroup_object.ts
2321
+ function normalizeExtensionHeaders(extensionHeaders) {
2322
+ if (extensionHeaders === null || extensionHeaders.length === 0) {
2323
+ return null;
2324
+ }
2325
+ return extensionHeaders;
2326
+ }
2293
2327
  var SubgroupObject = class _SubgroupObject {
2294
2328
  constructor(objectId, extensionHeaders, objectStatus, payload) {
2295
2329
  this.extensionHeaders = extensionHeaders;
@@ -2302,22 +2336,17 @@ var SubgroupObject = class _SubgroupObject {
2302
2336
  payload;
2303
2337
  objectId;
2304
2338
  static newWithStatus(objectId, extensionHeaders, objectStatus) {
2305
- return new _SubgroupObject(objectId, extensionHeaders, objectStatus, null);
2339
+ return new _SubgroupObject(objectId, normalizeExtensionHeaders(extensionHeaders), objectStatus, null);
2306
2340
  }
2307
2341
  static newWithPayload(objectId, extensionHeaders, payload) {
2308
- return new _SubgroupObject(objectId, extensionHeaders, null, payload);
2342
+ return new _SubgroupObject(objectId, normalizeExtensionHeaders(extensionHeaders), null, payload);
2309
2343
  }
2310
2344
  serialize(previousObjectId) {
2311
2345
  let objectIdDelta = previousObjectId ? this.objectId - previousObjectId - BigInt(1) : this.objectId;
2312
2346
  const buf = new ByteBuffer();
2313
2347
  buf.putVI(objectIdDelta);
2314
- const extensionHeaders = new ByteBuffer();
2315
- if (this.extensionHeaders) {
2316
- for (const header of this.extensionHeaders) {
2317
- extensionHeaders.putKeyValuePair(header);
2318
- }
2319
- const headerBytes = extensionHeaders.toUint8Array();
2320
- buf.putLengthPrefixedBytes(headerBytes);
2348
+ if (this.extensionHeaders !== null) {
2349
+ buf.putLengthPrefixedBytes(serializeKvpList(this.extensionHeaders).toUint8Array());
2321
2350
  }
2322
2351
  if (this.payload) {
2323
2352
  buf.putLengthPrefixedBytes(this.payload);
@@ -2332,12 +2361,9 @@ var SubgroupObject = class _SubgroupObject {
2332
2361
  let objectId = previousObjectId !== void 0 ? previousObjectId + objectDelta + BigInt(1) : objectDelta;
2333
2362
  let extensionHeaders = null;
2334
2363
  if (hasExtensions) {
2335
- extensionHeaders = [];
2336
2364
  const extLen = buf.getNumberVI();
2337
2365
  const headerBytes = new FrozenByteBuffer5(buf.getBytes(extLen));
2338
- while (headerBytes.remaining > 0) {
2339
- extensionHeaders.push(headerBytes.getKeyValuePair());
2340
- }
2366
+ extensionHeaders = deserializeKvpListUntilEmpty(headerBytes);
2341
2367
  }
2342
2368
  const payloadLen = buf.getNumberVI();
2343
2369
  let objectStatus = null;
@@ -2347,7 +2373,7 @@ var SubgroupObject = class _SubgroupObject {
2347
2373
  } else {
2348
2374
  payload = buf.getBytes(payloadLen);
2349
2375
  }
2350
- return new _SubgroupObject(objectId, extensionHeaders, objectStatus, payload);
2376
+ return new _SubgroupObject(objectId, normalizeExtensionHeaders(extensionHeaders), objectStatus, payload);
2351
2377
  }
2352
2378
  };
2353
2379
 
@@ -3568,9 +3594,7 @@ var PublishNamespace = class _PublishNamespace {
3568
3594
  payload.putVI(this.requestId);
3569
3595
  payload.putTuple(this.trackNamespace);
3570
3596
  payload.putVI(this.parameters.length);
3571
- for (const param of this.parameters) {
3572
- payload.putKeyValuePair(param.toKeyValuePair());
3573
- }
3597
+ payload.putBytes(serializeKvpList(this.parameters.map((p) => p.toKeyValuePair())).toUint8Array());
3574
3598
  const payloadBytes = payload.toUint8Array();
3575
3599
  if (payloadBytes.length > 65535) {
3576
3600
  throw new LengthExceedsMaxError("PublishNamespace::serialize(payloadBytes.length)", 65535, payloadBytes.length);
@@ -3591,10 +3615,7 @@ var PublishNamespace = class _PublishNamespace {
3591
3615
  const requestId = buf.getVI();
3592
3616
  const trackNamespace = buf.getTuple();
3593
3617
  const paramCount = buf.getNumberVI();
3594
- const rawParams = new Array(paramCount);
3595
- for (let i = 0; i < paramCount; i++) {
3596
- rawParams[i] = buf.getKeyValuePair();
3597
- }
3618
+ const rawParams = deserializeKvpList(buf, paramCount);
3598
3619
  const parameters = MessageParameters.fromKeyValuePairs(rawParams);
3599
3620
  return new _PublishNamespace(requestId, trackNamespace, parameters);
3600
3621
  }
@@ -3638,9 +3659,7 @@ var Subscribe = class _Subscribe {
3638
3659
  payload.putVI(this.requestId);
3639
3660
  payload.putBytes(this.fullTrackName.serialize().toUint8Array());
3640
3661
  payload.putVI(this.parameters.length);
3641
- for (const param of this.parameters) {
3642
- payload.putBytes(param.toKeyValuePair().serialize().toUint8Array());
3643
- }
3662
+ payload.putBytes(serializeKvpList(this.parameters.map((p) => p.toKeyValuePair())).toUint8Array());
3644
3663
  const payloadBytes = payload.toUint8Array();
3645
3664
  buf.putU16(payloadBytes.length);
3646
3665
  buf.putBytes(payloadBytes);
@@ -3651,8 +3670,7 @@ var Subscribe = class _Subscribe {
3651
3670
  const fullTrackName = buf.getFullTrackName();
3652
3671
  const paramCount = Number(buf.getVI());
3653
3672
  const parameters = [];
3654
- for (let i = 0; i < paramCount; i++) {
3655
- const kvp = KeyValuePair.deserialize(buf);
3673
+ for (const kvp of deserializeKvpList(buf, paramCount)) {
3656
3674
  const param = exports.MessageParameter.fromKeyValuePair(kvp);
3657
3675
  if (param !== void 0) parameters.push(param);
3658
3676
  }
@@ -3680,9 +3698,7 @@ var Switch = class _Switch {
3680
3698
  payload.putBytes(this.fullTrackName.serialize().toUint8Array());
3681
3699
  payload.putVI(this.subscriptionRequestId);
3682
3700
  payload.putVI(this.parameters.length);
3683
- for (const param of this.parameters) {
3684
- payload.putBytes(param.serialize().toUint8Array());
3685
- }
3701
+ payload.putBytes(serializeKvpList(this.parameters).toUint8Array());
3686
3702
  const payloadBytes = payload.toUint8Array();
3687
3703
  buf.putU16(payloadBytes.length);
3688
3704
  buf.putBytes(payloadBytes);
@@ -3693,10 +3709,7 @@ var Switch = class _Switch {
3693
3709
  const fullTrackName = buf.getFullTrackName();
3694
3710
  const subscriptionRequestId = buf.getVI();
3695
3711
  const paramCount = Number(buf.getVI());
3696
- const parameters = [];
3697
- for (let i = 0; i < paramCount; i++) {
3698
- parameters.push(KeyValuePair.deserialize(buf));
3699
- }
3712
+ const parameters = deserializeKvpList(buf, paramCount);
3700
3713
  return new _Switch(requestId, fullTrackName, subscriptionRequestId, parameters);
3701
3714
  }
3702
3715
  };
@@ -3812,9 +3825,7 @@ var ClientSetup = class _ClientSetup {
3812
3825
  buf.putVI(32 /* ClientSetup */);
3813
3826
  const payload = new ByteBuffer();
3814
3827
  payload.putVI(this.setupParameters.length);
3815
- for (const param of this.setupParameters) {
3816
- payload.putKeyValuePair(param);
3817
- }
3828
+ payload.putBytes(serializeKvpList(this.setupParameters).toUint8Array());
3818
3829
  const payloadBytes = payload.toUint8Array();
3819
3830
  if (payloadBytes.length > 65535) {
3820
3831
  throw new LengthExceedsMaxError("ClientSetup::serialize(payload_length)", 65535, payloadBytes.length);
@@ -3825,10 +3836,7 @@ var ClientSetup = class _ClientSetup {
3825
3836
  }
3826
3837
  static parsePayload(buf) {
3827
3838
  const paramCount = buf.getNumberVI();
3828
- const setupParameters = new Array(paramCount);
3829
- for (let i = 0; i < paramCount; i++) {
3830
- setupParameters[i] = buf.getKeyValuePair();
3831
- }
3839
+ const setupParameters = deserializeKvpList(buf, paramCount);
3832
3840
  return new _ClientSetup(setupParameters);
3833
3841
  }
3834
3842
  };
@@ -3867,9 +3875,7 @@ var Fetch = class _Fetch {
3867
3875
  }
3868
3876
  }
3869
3877
  payload.putVI(this.parameters.length);
3870
- for (const param of this.parameters) {
3871
- payload.putKeyValuePair(param.toKeyValuePair());
3872
- }
3878
+ payload.putBytes(serializeKvpList(this.parameters.map((p) => p.toKeyValuePair())).toUint8Array());
3873
3879
  const payloadBytes = payload.toUint8Array();
3874
3880
  if (payloadBytes.length > 65535) {
3875
3881
  throw new LengthExceedsMaxError("Fetch::serialize(payload_length)", 65535, payloadBytes.length);
@@ -3908,10 +3914,7 @@ var Fetch = class _Fetch {
3908
3914
  throw new Error(`Unknown fetch type: ${fetchType}`);
3909
3915
  }
3910
3916
  const paramCount = buf.getNumberVI();
3911
- const rawParams = new Array(paramCount);
3912
- for (let i = 0; i < paramCount; i++) {
3913
- rawParams[i] = buf.getKeyValuePair();
3914
- }
3917
+ const rawParams = deserializeKvpList(buf, paramCount);
3915
3918
  const parameters = MessageParameters.fromKeyValuePairs(rawParams);
3916
3919
  return new _Fetch(requestId, props, parameters);
3917
3920
  }
@@ -3967,9 +3970,7 @@ var FetchOk = class _FetchOk {
3967
3970
  payload.putU8(this.endOfTrack ? 1 : 0);
3968
3971
  payload.putLocation(this.endLocation);
3969
3972
  payload.putVI(this.parameters.length);
3970
- for (const param of this.parameters) {
3971
- payload.putKeyValuePair(param.toKeyValuePair());
3972
- }
3973
+ payload.putBytes(serializeKvpList(this.parameters.map((p) => p.toKeyValuePair())).toUint8Array());
3973
3974
  exports.TrackExtension.serializeInto(this.trackExtensions, payload);
3974
3975
  const payloadBytes = payload.toUint8Array();
3975
3976
  if (payloadBytes.length > 65535) {
@@ -3998,10 +3999,7 @@ var FetchOk = class _FetchOk {
3998
3999
  }
3999
4000
  const endLocation = buf.getLocation();
4000
4001
  const paramCount = buf.getNumberVI();
4001
- const rawParams = new Array(paramCount);
4002
- for (let i = 0; i < paramCount; i++) {
4003
- rawParams[i] = buf.getKeyValuePair();
4004
- }
4002
+ const rawParams = deserializeKvpList(buf, paramCount);
4005
4003
  const parameters = MessageParameters.fromKeyValuePairs(rawParams);
4006
4004
  const trackExtensions = exports.TrackExtension.deserializeAll(buf);
4007
4005
  return new _FetchOk(requestId, endOfTrack, endLocation, parameters, trackExtensions);
@@ -4113,9 +4111,7 @@ var ServerSetup = class _ServerSetup {
4113
4111
  buf.putVI(33 /* ServerSetup */);
4114
4112
  const payload = new ByteBuffer();
4115
4113
  payload.putVI(this.setupParameters.length);
4116
- for (const param of this.setupParameters) {
4117
- payload.putKeyValuePair(param);
4118
- }
4114
+ payload.putBytes(serializeKvpList(this.setupParameters).toUint8Array());
4119
4115
  const payloadBytes = payload.toUint8Array();
4120
4116
  if (payloadBytes.length > 65535) {
4121
4117
  throw new LengthExceedsMaxError("ServerSetup::serialize(payloadBytes.length)", 65535, payloadBytes.length);
@@ -4126,10 +4122,7 @@ var ServerSetup = class _ServerSetup {
4126
4122
  }
4127
4123
  static parsePayload(buf) {
4128
4124
  const paramCount = buf.getNumberVI();
4129
- const setupParameters = new Array(paramCount);
4130
- for (let i = 0; i < paramCount; i++) {
4131
- setupParameters[i] = buf.getKeyValuePair();
4132
- }
4125
+ const setupParameters = deserializeKvpList(buf, paramCount);
4133
4126
  return new _ServerSetup(setupParameters);
4134
4127
  }
4135
4128
  };
@@ -4203,9 +4196,7 @@ var Publish = class _Publish {
4203
4196
  payload.putBytes(this.fullTrackName.serialize().toUint8Array());
4204
4197
  payload.putVI(this.trackAlias);
4205
4198
  payload.putVI(this.parameters.length);
4206
- for (const param of this.parameters) {
4207
- payload.putKeyValuePair(param.toKeyValuePair());
4208
- }
4199
+ payload.putBytes(serializeKvpList(this.parameters.map((p) => p.toKeyValuePair())).toUint8Array());
4209
4200
  exports.TrackExtension.serializeInto(this.trackExtensions, payload);
4210
4201
  const payloadBytes = payload.toUint8Array();
4211
4202
  if (payloadBytes.length > 65535) {
@@ -4220,10 +4211,7 @@ var Publish = class _Publish {
4220
4211
  const fullTrackName = buf.getFullTrackName();
4221
4212
  const trackAlias = buf.getVI();
4222
4213
  const paramCount = buf.getNumberVI();
4223
- const rawParams = new Array(paramCount);
4224
- for (let i = 0; i < paramCount; i++) {
4225
- rawParams[i] = buf.getKeyValuePair();
4226
- }
4214
+ const rawParams = deserializeKvpList(buf, paramCount);
4227
4215
  const parameters = MessageParameters.fromKeyValuePairs(rawParams);
4228
4216
  const trackExtensions = exports.TrackExtension.deserializeAll(buf);
4229
4217
  return new _Publish(requestId, fullTrackName, trackAlias, parameters, trackExtensions);
@@ -4247,9 +4235,7 @@ var PublishOk = class _PublishOk {
4247
4235
  const payload = new ByteBuffer();
4248
4236
  payload.putVI(this.requestId);
4249
4237
  payload.putVI(this.parameters.length);
4250
- for (const param of this.parameters) {
4251
- payload.putKeyValuePair(param.toKeyValuePair());
4252
- }
4238
+ payload.putBytes(serializeKvpList(this.parameters.map((p) => p.toKeyValuePair())).toUint8Array());
4253
4239
  const payloadBytes = payload.toUint8Array();
4254
4240
  if (payloadBytes.length > 65535) {
4255
4241
  throw new LengthExceedsMaxError("PublishOk::serialize(payloadBytes.length)", 65535, payloadBytes.length);
@@ -4261,10 +4247,7 @@ var PublishOk = class _PublishOk {
4261
4247
  static parsePayload(buf) {
4262
4248
  const requestId = buf.getVI();
4263
4249
  const paramCount = buf.getVI();
4264
- const kvps = [];
4265
- for (let i = 0; i < paramCount; i++) {
4266
- kvps.push(buf.getKeyValuePair());
4267
- }
4250
+ const kvps = deserializeKvpList(buf, paramCount);
4268
4251
  const parameters = MessageParameters.fromKeyValuePairs(kvps);
4269
4252
  return new _PublishOk(requestId, parameters);
4270
4253
  }
@@ -4292,9 +4275,7 @@ var SubscribeOk = class _SubscribeOk {
4292
4275
  payload.putVI(this.requestId);
4293
4276
  payload.putVI(this.trackAlias);
4294
4277
  payload.putVI(this.parameters.length);
4295
- for (const param of this.parameters) {
4296
- payload.putKeyValuePair(param.toKeyValuePair());
4297
- }
4278
+ payload.putBytes(serializeKvpList(this.parameters.map((p) => p.toKeyValuePair())).toUint8Array());
4298
4279
  exports.TrackExtension.serializeInto(this.trackExtensions, payload);
4299
4280
  const payloadBytes = payload.toUint8Array();
4300
4281
  if (payloadBytes.length > 65535) {
@@ -4308,10 +4289,7 @@ var SubscribeOk = class _SubscribeOk {
4308
4289
  const requestId = buf.getVI();
4309
4290
  const trackAlias = buf.getVI();
4310
4291
  const paramCount = buf.getNumberVI();
4311
- const rawParams = new Array(paramCount);
4312
- for (let i = 0; i < paramCount; i++) {
4313
- rawParams[i] = buf.getKeyValuePair();
4314
- }
4292
+ const rawParams = deserializeKvpList(buf, paramCount);
4315
4293
  const parameters = MessageParameters.fromKeyValuePairs(rawParams);
4316
4294
  const trackExtensions = exports.TrackExtension.deserializeAll(buf);
4317
4295
  return new _SubscribeOk(requestId, trackAlias, parameters, trackExtensions);
@@ -4338,9 +4316,7 @@ var RequestUpdate = class _RequestUpdate {
4338
4316
  payload.putVI(this.requestId);
4339
4317
  payload.putVI(this.existingRequestId);
4340
4318
  payload.putVI(this.parameters.length);
4341
- for (const param of this.parameters) {
4342
- payload.putBytes(param.toKeyValuePair().serialize().toUint8Array());
4343
- }
4319
+ payload.putBytes(serializeKvpList(this.parameters.map((p) => p.toKeyValuePair())).toUint8Array());
4344
4320
  const payloadBytes = payload.toUint8Array();
4345
4321
  if (payloadBytes.length > 65535) {
4346
4322
  throw new LengthExceedsMaxError("RequestUpdate::serialize(payloadBytes)", 65535, payloadBytes.length);
@@ -4358,8 +4334,7 @@ var RequestUpdate = class _RequestUpdate {
4358
4334
  throw new CastingError("RequestUpdate.deserialize paramCount", "bigint", "number", `${paramCountBig}`);
4359
4335
  }
4360
4336
  const parameters = [];
4361
- for (let i = 0; i < paramCount; i++) {
4362
- const kvp = KeyValuePair.deserialize(buf);
4337
+ for (const kvp of deserializeKvpList(buf, paramCount)) {
4363
4338
  const param = exports.MessageParameter.fromKeyValuePair(kvp);
4364
4339
  if (param !== void 0) parameters.push(param);
4365
4340
  }
@@ -4516,9 +4491,7 @@ var TrackStatus = class _TrackStatus {
4516
4491
  payload.putVI(this.endGroup);
4517
4492
  }
4518
4493
  payload.putVI(this.subscribeParameters.length);
4519
- for (const param of this.subscribeParameters) {
4520
- payload.putKeyValuePair(param.toKeyValuePair());
4521
- }
4494
+ payload.putBytes(serializeKvpList(this.subscribeParameters.map((p) => p.toKeyValuePair())).toUint8Array());
4522
4495
  const payloadBytes = payload.toUint8Array();
4523
4496
  buf.putU16(payloadBytes.length);
4524
4497
  buf.putBytes(payloadBytes);
@@ -4541,10 +4514,7 @@ var TrackStatus = class _TrackStatus {
4541
4514
  endGroup = buf.getVI();
4542
4515
  }
4543
4516
  const paramCount = Number(buf.getVI());
4544
- const rawParams = new Array(paramCount);
4545
- for (let i = 0; i < paramCount; i++) {
4546
- rawParams[i] = buf.getKeyValuePair();
4547
- }
4517
+ const rawParams = deserializeKvpList(buf, paramCount);
4548
4518
  const subscribeParameters = MessageParameters.fromKeyValuePairs(rawParams);
4549
4519
  return new _TrackStatus(
4550
4520
  requestId,
@@ -4662,9 +4632,7 @@ var SubscribeNamespace = class _SubscribeNamespace {
4662
4632
  payload.putTuple(this.trackNamespacePrefix);
4663
4633
  payload.putVI(this.subscribeOptions);
4664
4634
  payload.putVI(this.parameters.length);
4665
- for (const param of this.parameters) {
4666
- payload.putKeyValuePair(param.toKeyValuePair());
4667
- }
4635
+ payload.putBytes(serializeKvpList(this.parameters.map((p) => p.toKeyValuePair())).toUint8Array());
4668
4636
  const payloadBytes = payload.toUint8Array();
4669
4637
  if (payloadBytes.length > 65535) {
4670
4638
  throw new LengthExceedsMaxError("SubscribeNamespace::serialize(payloadBytes.length)", 65535, payloadBytes.length);
@@ -4678,10 +4646,7 @@ var SubscribeNamespace = class _SubscribeNamespace {
4678
4646
  const trackNamespacePrefix = buf.getTuple();
4679
4647
  const subscribeOptions = Number(buf.getVI());
4680
4648
  const paramCount = buf.getNumberVI();
4681
- const rawParams = new Array(paramCount);
4682
- for (let i = 0; i < paramCount; i++) {
4683
- rawParams[i] = buf.getKeyValuePair();
4684
- }
4649
+ const rawParams = deserializeKvpList(buf, paramCount);
4685
4650
  const parameters = MessageParameters.fromKeyValuePairs(rawParams);
4686
4651
  return new _SubscribeNamespace(requestId, trackNamespacePrefix, subscribeOptions, parameters);
4687
4652
  }
@@ -4732,9 +4697,7 @@ var RequestOk = class _RequestOk {
4732
4697
  const payload = new ByteBuffer();
4733
4698
  payload.putVI(this.requestId);
4734
4699
  payload.putVI(BigInt(this.parameters.length));
4735
- for (const param of this.parameters) {
4736
- payload.putBytes(param.toKeyValuePair().serialize().toUint8Array());
4737
- }
4700
+ payload.putBytes(serializeKvpList(this.parameters.map((p) => p.toKeyValuePair())).toUint8Array());
4738
4701
  const payloadBytes = payload.toUint8Array();
4739
4702
  if (payloadBytes.length > 65535) {
4740
4703
  throw new LengthExceedsMaxError("RequestOk::serialize(payloadBytes)", 65535, payloadBytes.length);
@@ -4751,8 +4714,7 @@ var RequestOk = class _RequestOk {
4751
4714
  throw new CastingError("RequestOk.parsePayload numParams", "bigint", "number", `${numParamsBig}`);
4752
4715
  }
4753
4716
  const parameters = [];
4754
- for (let i = 0; i < numParams; i++) {
4755
- const kvp = KeyValuePair.deserialize(buf);
4717
+ for (const kvp of deserializeKvpList(buf, numParams)) {
4756
4718
  const param = exports.MessageParameter.fromKeyValuePair(kvp);
4757
4719
  if (param !== void 0) parameters.push(param);
4758
4720
  }
@@ -5095,6 +5057,8 @@ exports.VideoConfig = VideoConfig;
5095
5057
  exports.VideoFrameMarking = VideoFrameMarking;
5096
5058
  exports.applyMessageParameterUpdate = applyMessageParameterUpdate;
5097
5059
  exports.controlMessageTypeFromBigInt = controlMessageTypeFromBigInt;
5060
+ exports.deserializeKvpList = deserializeKvpList;
5061
+ exports.deserializeKvpListUntilEmpty = deserializeKvpListUntilEmpty;
5098
5062
  exports.fetchTypeFromBigInt = fetchTypeFromBigInt;
5099
5063
  exports.filterTypeFromBigInt = filterTypeFromBigInt;
5100
5064
  exports.groupOrderFromNumber = groupOrderFromNumber;
@@ -5104,6 +5068,7 @@ exports.locHeaderExtensionIdFromNumber = locHeaderExtensionIdFromNumber;
5104
5068
  exports.messageParameterTypeFromNumber = messageParameterTypeFromNumber;
5105
5069
  exports.publishDoneStatusCodeFromBigInt = publishDoneStatusCodeFromBigInt;
5106
5070
  exports.requestErrorCodeFromBigInt = requestErrorCodeFromBigInt;
5071
+ exports.serializeKvpList = serializeKvpList;
5107
5072
  exports.setupParameterTypeFromNumber = setupParameterTypeFromNumber;
5108
5073
  exports.tokenAliasTypeFromNumber = tokenAliasTypeFromNumber;
5109
5074
  exports.trackStatusCodeFromBigInt = trackStatusCodeFromBigInt;
package/dist/model.d.cts CHANGED
@@ -1,5 +1,5 @@
1
- import { u as FullTrackName, K as KeyValuePair, t as FrozenByteBuffer, B as BaseByteBuffer, L as LOCHeaderExtensionId, av as TrackExtensionType, b as ByteBuffer } from './setup_parameter-BOeGq6Mv.cjs';
2
- export { A as AuthTokenVariant, a as AuthorizationToken, C as ClientSetup, c as ControlMessage, d as ControlMessageType, D as Datagram, e as DefaultPublisherGroupOrderExtension, f as DefaultPublisherPriorityExtension, g as DeliveryTimeout, h as DeliveryTimeoutExtension, i as DynamicGroupsExtension, E as EndOfRangeKind, j as Expires, F as Fetch, k as FetchCancel, l as FetchHeader, m as FetchHeaderType, n as FetchObject, o as FetchObjectContext, p as FetchOk, q as FetchType, r as FilterType, s as Forward, G as GoAway, v as GroupOrder, w as GroupOrderParam, H as Header, I as ImmutableExtensionsExtension, x as LargestObject, y as Location, M as MAX_FULL_TRACK_NAME_LENGTH, z as MAX_NAMESPACE_TUPLE_COUNT, J as MAX_REASON_PHRASE_LEN, N as MaxAuthTokenCacheSize, O as MaxCacheDurationExtension, P as MaxRequestId, Q as MaxRequestIdParameter, R as MessageParameter, S as MessageParameterType, T as MessageParameters, U as MoqtObject, V as Namespace, W as NamespaceDone, X as NamespaceSubscribeOptions, Y as NewGroupRequest, Z as ObjectDatagramType, _ as ObjectForwardingPreference, $ as ObjectStatus, a0 as Parameter, a1 as Path, a2 as Publish, a3 as PublishDone, a4 as PublishDoneStatusCode, a5 as PublishNamespace, a6 as PublishNamespaceCancel, a7 as PublishNamespaceDone, a8 as PublishOk, a9 as ReasonPhrase, aa as RequestError, ab as RequestErrorCode, ac as RequestIdMap, ad as RequestOk, ae as RequestUpdate, af as RequestsBlocked, ag as SUPPORTED_VERSIONS, ah as ServerSetup, ai as SetupParameter, aj as SetupParameterType, ak as SetupParameters, al as SubgroupHeader, am as SubgroupHeaderType, an as SubgroupObject, ao as Subscribe, ap as SubscribeNamespace, aq as SubscribeOk, ar as SubscriberPriority, as as SubscriptionFilter, at as TokenAliasType, au as TrackExtension, aw as TrackStatus, ax as TrackStatusCode, ay as Tuple, az as TupleField, aA as UnknownTrackExtension, aB as Unsubscribe, aC as UnsubscribeNamespace, aD as applyMessageParameterUpdate, aE as controlMessageTypeFromBigInt, aF as fetchTypeFromBigInt, aG as filterTypeFromBigInt, aH as groupOrderFromNumber, aI as isBytes, aJ as isVarInt, aK as locHeaderExtensionIdFromNumber, aL as messageParameterTypeFromNumber, aM as publishDoneStatusCodeFromBigInt, aN as requestErrorCodeFromBigInt, aO as setupParameterTypeFromNumber, aP as tokenAliasTypeFromNumber, aQ as trackStatusCodeFromBigInt } from './setup_parameter-BOeGq6Mv.cjs';
1
+ import { u as FullTrackName, K as KeyValuePair, t as FrozenByteBuffer, B as BaseByteBuffer, L as LOCHeaderExtensionId, av as TrackExtensionType, b as ByteBuffer } from './setup_parameter-BgNrJRDS.cjs';
2
+ export { A as AuthTokenVariant, a as AuthorizationToken, C as ClientSetup, c as ControlMessage, d as ControlMessageType, D as Datagram, e as DefaultPublisherGroupOrderExtension, f as DefaultPublisherPriorityExtension, g as DeliveryTimeout, h as DeliveryTimeoutExtension, i as DynamicGroupsExtension, E as EndOfRangeKind, j as Expires, F as Fetch, k as FetchCancel, l as FetchHeader, m as FetchHeaderType, n as FetchObject, o as FetchObjectContext, p as FetchOk, q as FetchType, r as FilterType, s as Forward, G as GoAway, v as GroupOrder, w as GroupOrderParam, H as Header, I as ImmutableExtensionsExtension, x as LargestObject, y as Location, M as MAX_FULL_TRACK_NAME_LENGTH, z as MAX_NAMESPACE_TUPLE_COUNT, J as MAX_REASON_PHRASE_LEN, N as MaxAuthTokenCacheSize, O as MaxCacheDurationExtension, P as MaxRequestId, Q as MaxRequestIdParameter, R as MessageParameter, S as MessageParameterType, T as MessageParameters, U as MoqtObject, V as Namespace, W as NamespaceDone, X as NamespaceSubscribeOptions, Y as NewGroupRequest, Z as ObjectDatagramType, _ as ObjectForwardingPreference, $ as ObjectStatus, a0 as Parameter, a1 as Path, a2 as Publish, a3 as PublishDone, a4 as PublishDoneStatusCode, a5 as PublishNamespace, a6 as PublishNamespaceCancel, a7 as PublishNamespaceDone, a8 as PublishOk, a9 as ReasonPhrase, aa as RequestError, ab as RequestErrorCode, ac as RequestIdMap, ad as RequestOk, ae as RequestUpdate, af as RequestsBlocked, ag as SUPPORTED_VERSIONS, ah as ServerSetup, ai as SetupParameter, aj as SetupParameterType, ak as SetupParameters, al as SubgroupHeader, am as SubgroupHeaderType, an as SubgroupObject, ao as Subscribe, ap as SubscribeNamespace, aq as SubscribeOk, ar as SubscriberPriority, as as SubscriptionFilter, at as TokenAliasType, au as TrackExtension, aw as TrackStatus, ax as TrackStatusCode, ay as Tuple, az as TupleField, aA as UnknownTrackExtension, aB as Unsubscribe, aC as UnsubscribeNamespace, aD as applyMessageParameterUpdate, aE as controlMessageTypeFromBigInt, aF as deserializeKvpList, aG as deserializeKvpListUntilEmpty, aH as fetchTypeFromBigInt, aI as filterTypeFromBigInt, aJ as groupOrderFromNumber, aK as isBytes, aL as isVarInt, aM as locHeaderExtensionIdFromNumber, aN as messageParameterTypeFromNumber, aO as publishDoneStatusCodeFromBigInt, aP as requestErrorCodeFromBigInt, aQ as serializeKvpList, aR as setupParameterTypeFromNumber, aS as tokenAliasTypeFromNumber, aT as trackStatusCodeFromBigInt } from './setup_parameter-BgNrJRDS.cjs';
3
3
 
4
4
  /**
5
5
  * Copyright 2025 The MOQtail Authors