@moqtap/codec 0.6.0 → 0.8.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.
Files changed (82) hide show
  1. package/README.md +28 -2
  2. package/dist/{chunk-CXFAQKL3.js → chunk-23KRITJ6.js} +1 -1
  3. package/dist/{chunk-JL3NEW3O.cjs → chunk-4XLYCT5Q.cjs} +90 -1
  4. package/dist/{chunk-DLSGOZ6P.js → chunk-5XZKO2U5.js} +34 -34
  5. package/dist/{chunk-62LYLROG.js → chunk-APTV6F72.js} +35 -35
  6. package/dist/{chunk-JB5VDJ2V.cjs → chunk-B56AG5HU.cjs} +37 -37
  7. package/dist/{chunk-JTRU76JN.cjs → chunk-BQHLUT37.cjs} +109 -111
  8. package/dist/{chunk-4HBKHNU2.cjs → chunk-CZNW3R5E.cjs} +37 -37
  9. package/dist/{chunk-OGZTQA24.cjs → chunk-EQAYMCXO.cjs} +64 -64
  10. package/dist/{chunk-HYI6LFMD.js → chunk-HEO2JG6C.js} +1 -1
  11. package/dist/{chunk-UP4XPH4J.js → chunk-I55J3KXD.js} +31 -31
  12. package/dist/{chunk-HZHSO7EW.cjs → chunk-IDV2JYJ6.cjs} +39 -39
  13. package/dist/{chunk-BAG6YWCP.cjs → chunk-IEJULBKB.cjs} +63 -63
  14. package/dist/{chunk-Y6KCSM3V.js → chunk-IJAF6PAY.js} +1 -1
  15. package/dist/{chunk-WMJVSBBE.cjs → chunk-J3ASFPCX.cjs} +57 -57
  16. package/dist/{chunk-Q5D6OW6Q.js → chunk-JJEN2VG5.js} +51 -53
  17. package/dist/{chunk-COWGGUL4.js → chunk-JKMYAUGY.js} +1 -1
  18. package/dist/{chunk-SIYYMFCC.cjs → chunk-KCH4BQXK.cjs} +37 -37
  19. package/dist/{chunk-VOU7PNHI.js → chunk-KLPWJU6W.js} +89 -0
  20. package/dist/{chunk-NZ7GYEMT.js → chunk-KNLPX3YA.js} +1 -1
  21. package/dist/{chunk-A33U4WVS.cjs → chunk-KTVN4P6J.cjs} +67 -67
  22. package/dist/{chunk-7KBAWOBA.js → chunk-KYVTM5VI.js} +1 -1
  23. package/dist/{chunk-RZ3UML47.js → chunk-MD2OA7SE.js} +1 -1
  24. package/dist/{chunk-MSG2FXJ2.cjs → chunk-MH7537FB.cjs} +68 -68
  25. package/dist/{chunk-SHMA4PBY.js → chunk-N2V7Z37J.js} +1 -1
  26. package/dist/{chunk-HO44OANK.cjs → chunk-QGIHC6BA.cjs} +36 -36
  27. package/dist/{chunk-PKEOQSSZ.cjs → chunk-RIIA4ALQ.cjs} +37 -37
  28. package/dist/{chunk-XZE5R57R.cjs → chunk-VZHL2U2N.cjs} +37 -37
  29. package/dist/{chunk-RW4UG7CN.js → chunk-XHAP2YST.js} +1 -1
  30. package/dist/{codec-B1snaM9L.d.cts → codec-BnamSx7L.d.cts} +1 -1
  31. package/dist/{codec-D49OofBr.d.ts → codec-CFhUGTu2.d.ts} +1 -1
  32. package/dist/draft07.cjs +4 -4
  33. package/dist/draft07.js +2 -2
  34. package/dist/draft08.cjs +3 -3
  35. package/dist/draft08.js +2 -2
  36. package/dist/draft09.cjs +3 -3
  37. package/dist/draft09.js +2 -2
  38. package/dist/draft10.cjs +3 -3
  39. package/dist/draft10.js +2 -2
  40. package/dist/draft11.cjs +3 -3
  41. package/dist/draft11.js +2 -2
  42. package/dist/draft12.cjs +3 -3
  43. package/dist/draft12.js +2 -2
  44. package/dist/draft13.cjs +3 -3
  45. package/dist/draft13.js +2 -2
  46. package/dist/draft14-session.d.cts +1 -1
  47. package/dist/draft14-session.d.ts +1 -1
  48. package/dist/draft14.cjs +3 -3
  49. package/dist/draft14.d.cts +3 -3
  50. package/dist/draft14.d.ts +3 -3
  51. package/dist/draft14.js +2 -2
  52. package/dist/draft15.cjs +3 -3
  53. package/dist/draft15.js +2 -2
  54. package/dist/draft16.cjs +3 -3
  55. package/dist/draft16.js +2 -2
  56. package/dist/draft17.cjs +3 -3
  57. package/dist/draft17.js +2 -2
  58. package/dist/draft18.cjs +3 -3
  59. package/dist/draft18.js +2 -2
  60. package/dist/draft19.cjs +3 -3
  61. package/dist/draft19.js +2 -2
  62. package/dist/index.cjs +81 -29
  63. package/dist/index.d.cts +73 -3
  64. package/dist/index.d.ts +73 -3
  65. package/dist/index.js +67 -15
  66. package/dist/session.d.cts +1 -1
  67. package/dist/session.d.ts +1 -1
  68. package/dist/{types-DjmrHp_s.d.cts → types-CVeKIk7A.d.cts} +29 -21
  69. package/dist/{types-DjmrHp_s.d.ts → types-CVeKIk7A.d.ts} +29 -21
  70. package/package.json +2 -2
  71. package/src/core/accessors.ts +120 -0
  72. package/src/core/buffer-reader.ts +74 -2
  73. package/src/core/buffer-writer.ts +56 -4
  74. package/src/drafts/draft14/codec.ts +50 -52
  75. package/src/drafts/draft14/types.ts +31 -23
  76. package/src/drafts/draft17/codec.ts +2 -2
  77. package/src/drafts/draft17/data-streams.ts +2 -2
  78. package/src/drafts/draft18/codec.ts +2 -2
  79. package/src/drafts/draft18/data-streams.ts +2 -2
  80. package/src/drafts/draft19/codec.ts +2 -2
  81. package/src/drafts/draft19/data-streams.ts +2 -2
  82. package/src/index.ts +8 -0
package/README.md CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  MoQT (Media over QUIC Transport) wire-format codec and session state machine for JavaScript/TypeScript.
4
4
 
5
- - Multi-draft support (drafts 07 through 17)
5
+ - Multi-draft support (drafts 07 through 19)
6
6
  - Stateless encode/decode of all MoQT control messages and data streams
7
7
  - Protocol session state machine with FSM-based validation per draft
8
8
  - Zero runtime dependencies
@@ -43,7 +43,7 @@ Or use the factory if your application supports multiple drafts:
43
43
  ```typescript
44
44
  import { createCodec, DRAFT_VERSIONS } from '@moqtap/codec'
45
45
 
46
- const codec = createCodec({ draft: '17' }) // '07' through '17'
46
+ const codec = createCodec({ draft: '19' }) // '07' through '19'
47
47
 
48
48
  // DRAFT_VERSIONS provides wire version numbers under short aliases:
49
49
  // DRAFT_VERSIONS['07'] — 0xff000007n
@@ -67,6 +67,8 @@ Each draft is available as a subpath import with its own codec and session state
67
67
  | `@moqtap/codec/draft15` | Draft-15 codec |
68
68
  | `@moqtap/codec/draft16` | Draft-16 codec |
69
69
  | `@moqtap/codec/draft17` | Draft-17 codec |
70
+ | `@moqtap/codec/draft18` | Draft-18 codec |
71
+ | `@moqtap/codec/draft19` | Draft-19 codec |
70
72
  | `@moqtap/codec/draft{N}/session` | Session state machine for draft N |
71
73
 
72
74
  > **Note:** A default (versionless) codec will be available once the MoQT specification reaches RFC status. Until then, always specify a draft version.
@@ -80,6 +82,30 @@ import { createDraft17Codec } from '@moqtap/codec/draft17'
80
82
  import { createDraft17SessionState } from '@moqtap/codec/draft17/session'
81
83
  ```
82
84
 
85
+ ## Reading Across Drafts
86
+
87
+ Each draft gets its own message model, because the drafts genuinely differ — a
88
+ track alias travels in SUBSCRIBE through draft-11 and in SUBSCRIBE_OK from
89
+ draft-12; a request is a `subscribe_id` through draft-10 and a `request_id`
90
+ after it. Code that spans drafts can ask for the answer instead of tracking
91
+ where each version keeps it:
92
+
93
+ ```typescript
94
+ import { joiningRequestIdOf, requestIdOf, trackAliasOf, trackOf } from '@moqtap/codec'
95
+
96
+ const decoded = codec.decodeMessage(bytes)
97
+ if (decoded.ok) {
98
+ requestIdOf(decoded.value) // bigint, whichever name this draft uses
99
+ trackAliasOf(decoded.value) // bigint, or undefined if not assigned yet
100
+ trackOf(decoded.value) // { namespace, name }, or undefined if none is named
101
+ joiningRequestIdOf(decoded.value) // for a joining FETCH: the request it continues
102
+ }
103
+ ```
104
+
105
+ Each returns `undefined` when the message does not carry the field, including
106
+ when the draft has not assigned it yet — `trackAliasOf` on a draft-14 SUBSCRIBE
107
+ is `undefined` because the publisher chooses the alias in SUBSCRIBE_OK.
108
+
83
109
  ## Session State Machine
84
110
 
85
111
  Validate protocol message sequences without transport coupling:
@@ -4,7 +4,7 @@ import {
4
4
  DecodeError,
5
5
  bytesToHex,
6
6
  hexToBytes
7
- } from "./chunk-VOU7PNHI.js";
7
+ } from "./chunk-KLPWJU6W.js";
8
8
 
9
9
  // src/drafts/draft13/data-streams.ts
10
10
  var FETCH_STREAM_TYPE = 0x05n;
@@ -124,6 +124,54 @@ var BufferReader = class {
124
124
  return params;
125
125
  }
126
126
  };
127
+ var MoqtBufferReader = class extends BufferReader {
128
+ /** Draft-17 omits the 7-byte length; draft-18 restored it. */
129
+ get allowSevenByte() {
130
+ return true;
131
+ }
132
+ readVarInt() {
133
+ if (this.remaining < 1) {
134
+ throw new DecodeError("UNEXPECTED_END", "Not enough bytes for varint", this.pos);
135
+ }
136
+ const first = this.view.getUint8(this.pos);
137
+ if (first === 255) {
138
+ if (this.remaining < 9) {
139
+ throw new DecodeError("UNEXPECTED_END", "Not enough bytes for 9-byte varint", this.pos);
140
+ }
141
+ const value2 = this.view.getBigUint64(this.pos + 1);
142
+ this.pos += 9;
143
+ return value2;
144
+ }
145
+ let leadingOnes = 0;
146
+ while (leadingOnes < 8 && (first & 128 >> leadingOnes) !== 0) leadingOnes++;
147
+ const length = leadingOnes + 1;
148
+ if (length === 7 && !this.allowSevenByte) {
149
+ throw new DecodeError(
150
+ "INVALID_VARINT",
151
+ "The 7-byte varint is not defined in draft-17",
152
+ this.pos
153
+ );
154
+ }
155
+ if (this.remaining < length) {
156
+ throw new DecodeError(
157
+ "UNEXPECTED_END",
158
+ `Not enough bytes for ${length}-byte varint`,
159
+ this.pos
160
+ );
161
+ }
162
+ let value = BigInt(first & (1 << 8 - length) - 1);
163
+ for (let i = 1; i < length; i++) {
164
+ value = value << 8n | BigInt(this.view.getUint8(this.pos + i));
165
+ }
166
+ this.pos += length;
167
+ return value;
168
+ }
169
+ };
170
+ var Draft17BufferReader = class extends MoqtBufferReader {
171
+ get allowSevenByte() {
172
+ return false;
173
+ }
174
+ };
127
175
 
128
176
  // src/core/buffer-writer.ts
129
177
  var textEncoder = /* @__PURE__ */ new TextEncoder();
@@ -211,6 +259,43 @@ var BufferWriter = class {
211
259
  return this.buffer.subarray(0, this.pos);
212
260
  }
213
261
  };
262
+ var MoqtBufferWriter = class extends BufferWriter {
263
+ /** Draft-17 omits the 7-byte length; draft-18 restored it. */
264
+ get allowSevenByte() {
265
+ return true;
266
+ }
267
+ writeVarInt(value) {
268
+ const v = BigInt(value);
269
+ if (v < 0n) throw new Error("VarInt value must be non-negative");
270
+ if (v > 0xffffffffffffffffn) throw new Error("VarInt value exceeds 64-bit range");
271
+ let length = 9;
272
+ for (let n = 1; n <= 8; n++) {
273
+ if (n === 7 && !this.allowSevenByte) continue;
274
+ if (v < 1n << BigInt(7 * n)) {
275
+ length = n;
276
+ break;
277
+ }
278
+ }
279
+ this.ensureCapacity(length);
280
+ if (length === 9) {
281
+ this.view.setUint8(this.pos, 255);
282
+ this.view.setBigUint64(this.pos + 1, v);
283
+ this.pos += 9;
284
+ return;
285
+ }
286
+ const prefix = BigInt((1 << length - 1) - 1 << 9 - length) & 0xffn;
287
+ const combined = prefix << BigInt(8 * (length - 1)) | v;
288
+ for (let i = 0; i < length; i++) {
289
+ this.view.setUint8(this.pos + i, Number(combined >> BigInt(8 * (length - 1 - i)) & 0xffn));
290
+ }
291
+ this.pos += length;
292
+ }
293
+ };
294
+ var Draft17BufferWriter = class extends MoqtBufferWriter {
295
+ get allowSevenByte() {
296
+ return false;
297
+ }
298
+ };
214
299
 
215
300
  // src/core/hex.ts
216
301
  var HEX_TABLE = /* @__PURE__ */ Array.from(
@@ -238,4 +323,8 @@ function hexToBytes(hex) {
238
323
 
239
324
 
240
325
 
241
- exports.DecodeError = DecodeError; exports.BufferReader = BufferReader; exports.BufferWriter = BufferWriter; exports.bytesToHex = bytesToHex; exports.hexToBytes = hexToBytes;
326
+
327
+
328
+
329
+
330
+ exports.DecodeError = DecodeError; exports.BufferReader = BufferReader; exports.MoqtBufferReader = MoqtBufferReader; exports.Draft17BufferReader = Draft17BufferReader; exports.BufferWriter = BufferWriter; exports.MoqtBufferWriter = MoqtBufferWriter; exports.Draft17BufferWriter = Draft17BufferWriter; exports.bytesToHex = bytesToHex; exports.hexToBytes = hexToBytes;
@@ -1,10 +1,10 @@
1
1
  import {
2
- BufferReader,
3
- BufferWriter,
4
2
  DecodeError,
3
+ MoqtBufferReader,
4
+ MoqtBufferWriter,
5
5
  bytesToHex,
6
6
  hexToBytes
7
- } from "./chunk-VOU7PNHI.js";
7
+ } from "./chunk-KLPWJU6W.js";
8
8
 
9
9
  // src/drafts/draft18/messages.ts
10
10
  var MSG_REQUEST_UPDATE = 0x02n;
@@ -108,7 +108,7 @@ function isValidSubgroupType(streamType) {
108
108
  return (streamType & 6) !== 6;
109
109
  }
110
110
  function encodeSubgroupStream(stream) {
111
- const w = new BufferWriter();
111
+ const w = new MoqtBufferWriter();
112
112
  const streamType = stream.headerType;
113
113
  w.writeUint8(streamType);
114
114
  const propertiesPresent = (streamType & 1) !== 0;
@@ -129,7 +129,7 @@ function encodeSubgroupStream(stream) {
129
129
  w.writeVarInt(delta);
130
130
  if (propertiesPresent) {
131
131
  if (obj.objectProperties && Object.keys(obj.objectProperties).length > 0) {
132
- const tmpW = new BufferWriter(32);
132
+ const tmpW = new MoqtBufferWriter(32);
133
133
  encodeObjectProperties(obj.objectProperties, tmpW);
134
134
  const raw = tmpW.finish();
135
135
  w.writeVarInt(BigInt(raw.byteLength));
@@ -149,7 +149,7 @@ function encodeSubgroupStream(stream) {
149
149
  return w.finish();
150
150
  }
151
151
  function encodeDatagram(dg) {
152
- const w = new BufferWriter();
152
+ const w = new MoqtBufferWriter();
153
153
  const dgType = dg.datagramType;
154
154
  w.writeUint8(dgType);
155
155
  w.writeVarInt(dg.trackAlias);
@@ -166,7 +166,7 @@ function encodeDatagram(dg) {
166
166
  }
167
167
  if (propertiesPresent) {
168
168
  if (dg.objectProperties && Object.keys(dg.objectProperties).length > 0) {
169
- const tmpW = new BufferWriter(32);
169
+ const tmpW = new MoqtBufferWriter(32);
170
170
  encodeObjectProperties(dg.objectProperties, tmpW);
171
171
  const raw = tmpW.finish();
172
172
  w.writeVarInt(BigInt(raw.byteLength));
@@ -183,7 +183,7 @@ function encodeDatagram(dg) {
183
183
  return w.finish();
184
184
  }
185
185
  function encodeFetchStream(stream) {
186
- const w = new BufferWriter();
186
+ const w = new MoqtBufferWriter();
187
187
  w.writeVarInt(FETCH_STREAM_TYPE);
188
188
  w.writeVarInt(stream.requestId);
189
189
  let prevGroupId = 0n;
@@ -205,7 +205,7 @@ function encodeFetchStream(stream) {
205
205
  if (flags & 16) w.writeUint8(obj.publisherPriority);
206
206
  if (flags & 32) {
207
207
  if (obj.objectProperties && Object.keys(obj.objectProperties).length > 0) {
208
- const tmpW = new BufferWriter(32);
208
+ const tmpW = new MoqtBufferWriter(32);
209
209
  encodeObjectProperties(obj.objectProperties, tmpW);
210
210
  const raw = tmpW.finish();
211
211
  w.writeVarInt(BigInt(raw.byteLength));
@@ -229,7 +229,7 @@ function encodeFetchStream(stream) {
229
229
  if (flags & 16) w.writeUint8(obj.publisherPriority);
230
230
  if (flags & 32) {
231
231
  if (obj.objectProperties && Object.keys(obj.objectProperties).length > 0) {
232
- const tmpW = new BufferWriter(32);
232
+ const tmpW = new MoqtBufferWriter(32);
233
233
  encodeObjectProperties(obj.objectProperties, tmpW);
234
234
  const raw = tmpW.finish();
235
235
  w.writeVarInt(BigInt(raw.byteLength));
@@ -252,7 +252,7 @@ function encodeFetchStream(stream) {
252
252
  }
253
253
  function decodeSubgroupStream(bytes) {
254
254
  try {
255
- const r = new BufferReader(bytes);
255
+ const r = new MoqtBufferReader(bytes);
256
256
  const streamType = r.readUint8();
257
257
  if (!isValidSubgroupType(streamType)) {
258
258
  return {
@@ -355,7 +355,7 @@ function decodeSubgroupStream(bytes) {
355
355
  }
356
356
  function decodeDatagram(bytes) {
357
357
  try {
358
- const r = new BufferReader(bytes);
358
+ const r = new MoqtBufferReader(bytes);
359
359
  const dgType = r.readUint8();
360
360
  const objectIdAbsent = (dgType & 4) !== 0;
361
361
  const endOfGroup = (dgType & 2) !== 0;
@@ -411,7 +411,7 @@ function decodeDatagram(bytes) {
411
411
  }
412
412
  function decodeFetchStream(bytes) {
413
413
  try {
414
- const r = new BufferReader(bytes);
414
+ const r = new MoqtBufferReader(bytes);
415
415
  const streamType = r.readVarInt();
416
416
  if (streamType !== FETCH_STREAM_TYPE) {
417
417
  return {
@@ -659,7 +659,7 @@ function createSubgroupStreamDecoder() {
659
659
  buffer = newBuffer;
660
660
  if (!headerEmitted) {
661
661
  try {
662
- const r = new BufferReader(buffer.subarray(offset));
662
+ const r = new MoqtBufferReader(buffer.subarray(offset));
663
663
  const streamType = r.readUint8();
664
664
  if (!isValidSubgroupType(streamType)) {
665
665
  controller.error(
@@ -704,7 +704,7 @@ function createSubgroupStreamDecoder() {
704
704
  }
705
705
  while (offset < buffer.length) {
706
706
  try {
707
- const r = new BufferReader(buffer.subarray(offset));
707
+ const r = new MoqtBufferReader(buffer.subarray(offset));
708
708
  const delta = r.readVarInt();
709
709
  let objectId;
710
710
  if (firstObject) {
@@ -764,7 +764,7 @@ function createFetchStreamDecoder() {
764
764
  buffer = newBuffer;
765
765
  if (!headerEmitted) {
766
766
  try {
767
- const r = new BufferReader(buffer.subarray(offset));
767
+ const r = new MoqtBufferReader(buffer.subarray(offset));
768
768
  const streamType = r.readVarInt();
769
769
  if (streamType !== FETCH_STREAM_TYPE) {
770
770
  controller.error(
@@ -790,7 +790,7 @@ function createFetchStreamDecoder() {
790
790
  }
791
791
  while (offset < buffer.length) {
792
792
  try {
793
- const r = new BufferReader(buffer.subarray(offset));
793
+ const r = new MoqtBufferReader(buffer.subarray(offset));
794
794
  const flags = Number(r.readVarInt());
795
795
  const objectIdPresent = (flags & 4) !== 0;
796
796
  const groupIdPresent = (flags & 8) !== 0;
@@ -939,7 +939,7 @@ function encodeSetupOptions(opts, writer) {
939
939
  entries.push({
940
940
  type: SETUP_OPT_AUTHORIZATION_TOKEN,
941
941
  encode: (w) => {
942
- const tmpW = new BufferWriter(64);
942
+ const tmpW = new MoqtBufferWriter(64);
943
943
  encodeAuthorizationToken(opts.authorization_token, tmpW);
944
944
  const raw = tmpW.finish();
945
945
  w.writeVarInt(BigInt(raw.byteLength));
@@ -981,7 +981,7 @@ function encodeSetupOptions(opts, writer) {
981
981
  encode: (w) => {
982
982
  if (id % 2n === 0n) {
983
983
  const raw = hexToBytes(u.raw_hex);
984
- const tmpReader = new BufferReader(raw);
984
+ const tmpReader = new MoqtBufferReader(raw);
985
985
  w.writeVarInt(tmpReader.readVarInt());
986
986
  } else {
987
987
  const raw = hexToBytes(u.raw_hex);
@@ -1013,7 +1013,7 @@ function decodeSetupOptions(reader, payloadEnd) {
1013
1013
  if (optType === SETUP_OPT_MAX_AUTH_TOKEN_CACHE_SIZE) {
1014
1014
  result.max_auth_token_cache_size = value;
1015
1015
  } else {
1016
- const tmpWriter = new BufferWriter(16);
1016
+ const tmpWriter = new MoqtBufferWriter(16);
1017
1017
  tmpWriter.writeVarInt(value);
1018
1018
  const raw = tmpWriter.finish();
1019
1019
  unknown.push({
@@ -1028,7 +1028,7 @@ function decodeSetupOptions(reader, payloadEnd) {
1028
1028
  if (optType === SETUP_OPT_PATH) {
1029
1029
  result.path = textDecoder.decode(bytes);
1030
1030
  } else if (optType === SETUP_OPT_AUTHORIZATION_TOKEN) {
1031
- result.authorization_token = decodeAuthorizationToken(new BufferReader(bytes));
1031
+ result.authorization_token = decodeAuthorizationToken(new MoqtBufferReader(bytes));
1032
1032
  } else if (optType === SETUP_OPT_AUTHORITY) {
1033
1033
  result.authority = textDecoder.decode(bytes);
1034
1034
  } else if (optType === SETUP_OPT_MOQT_IMPLEMENTATION) {
@@ -1115,7 +1115,7 @@ function encodeParams(params, writer) {
1115
1115
  entries.push({
1116
1116
  type: PARAM_AUTHORIZATION_TOKEN,
1117
1117
  encode: (w) => {
1118
- const tmpW = new BufferWriter(64);
1118
+ const tmpW = new MoqtBufferWriter(64);
1119
1119
  encodeAuthorizationToken(params.authorization_token, tmpW);
1120
1120
  const raw = tmpW.finish();
1121
1121
  w.writeVarInt(BigInt(raw.byteLength));
@@ -1145,7 +1145,7 @@ function encodeParams(params, writer) {
1145
1145
  entries.push({
1146
1146
  type: PARAM_LARGEST_OBJECT,
1147
1147
  encode: (w) => {
1148
- const tmpW = new BufferWriter(16);
1148
+ const tmpW = new MoqtBufferWriter(16);
1149
1149
  tmpW.writeVarInt(params.largest_object.group);
1150
1150
  tmpW.writeVarInt(params.largest_object.object);
1151
1151
  const raw = tmpW.finish();
@@ -1177,7 +1177,7 @@ function encodeParams(params, writer) {
1177
1177
  type: PARAM_SUBSCRIPTION_FILTER,
1178
1178
  encode: (w) => {
1179
1179
  const f = params.subscription_filter;
1180
- const tmpW = new BufferWriter(32);
1180
+ const tmpW = new MoqtBufferWriter(32);
1181
1181
  tmpW.writeVarInt(f.filter_type);
1182
1182
  if (f.filter_type === 3n || f.filter_type === 4n) {
1183
1183
  tmpW.writeVarInt(f.start_group);
@@ -1208,7 +1208,7 @@ function encodeParams(params, writer) {
1208
1208
  entries.push({
1209
1209
  type: PARAM_TRACK_NAMESPACE_PREFIX,
1210
1210
  encode: (w) => {
1211
- const tmpW = new BufferWriter(32);
1211
+ const tmpW = new MoqtBufferWriter(32);
1212
1212
  encodeNamespaceTuple(params.track_namespace_prefix, tmpW);
1213
1213
  const raw = tmpW.finish();
1214
1214
  w.writeVarInt(BigInt(raw.byteLength));
@@ -1251,7 +1251,7 @@ function decodeParams(reader) {
1251
1251
  } else if (paramType === PARAM_AUTHORIZATION_TOKEN) {
1252
1252
  const length = Number(reader.readVarInt());
1253
1253
  const bytes = reader.readBytes(length);
1254
- result.authorization_token = decodeAuthorizationToken(new BufferReader(bytes));
1254
+ result.authorization_token = decodeAuthorizationToken(new MoqtBufferReader(bytes));
1255
1255
  } else if (paramType === PARAM_RENDEZVOUS_TIMEOUT) {
1256
1256
  result.rendezvous_timeout = reader.readVarInt();
1257
1257
  } else if (paramType === PARAM_SUBGROUP_DELIVERY_TIMEOUT) {
@@ -1294,11 +1294,11 @@ function decodeParams(reader) {
1294
1294
  } else if (paramType === PARAM_TRACK_NAMESPACE_PREFIX) {
1295
1295
  const length = Number(reader.readVarInt());
1296
1296
  const bytes = reader.readBytes(length);
1297
- result.track_namespace_prefix = decodeNamespaceTuple(new BufferReader(bytes));
1297
+ result.track_namespace_prefix = decodeNamespaceTuple(new MoqtBufferReader(bytes));
1298
1298
  } else {
1299
1299
  if (paramType % 2n === 0n) {
1300
1300
  const value = reader.readVarInt();
1301
- const tmpWriter = new BufferWriter(16);
1301
+ const tmpWriter = new MoqtBufferWriter(16);
1302
1302
  tmpWriter.writeVarInt(value);
1303
1303
  const raw = tmpWriter.finish();
1304
1304
  unknown.push({
@@ -1383,7 +1383,7 @@ function encodeTrackProperties(props, writer) {
1383
1383
  encode: (w) => {
1384
1384
  if (id % 2n === 0n) {
1385
1385
  const raw = hexToBytes(u.raw_hex);
1386
- const tmpReader = new BufferReader(raw);
1386
+ const tmpReader = new MoqtBufferReader(raw);
1387
1387
  w.writeVarInt(tmpReader.readVarInt());
1388
1388
  } else {
1389
1389
  const raw = hexToBytes(u.raw_hex);
@@ -1425,7 +1425,7 @@ function decodeTrackProperties(reader, payloadEnd) {
1425
1425
  } else if (propType === TPROP_DYNAMIC_GROUPS) {
1426
1426
  result.dynamic_groups = value;
1427
1427
  } else {
1428
- const tmpWriter = new BufferWriter(16);
1428
+ const tmpWriter = new MoqtBufferWriter(16);
1429
1429
  tmpWriter.writeVarInt(value);
1430
1430
  const raw = tmpWriter.finish();
1431
1431
  unknown.push({
@@ -1774,13 +1774,13 @@ function encodeMessage(message) {
1774
1774
  if (typeId === void 0) {
1775
1775
  throw new Error(`Unknown message type: ${message.type}`);
1776
1776
  }
1777
- const payloadWriter = new BufferWriter();
1777
+ const payloadWriter = new MoqtBufferWriter();
1778
1778
  encodePayload(message, payloadWriter);
1779
1779
  const payload = payloadWriter.finishView();
1780
1780
  if (payload.byteLength > 65535) {
1781
1781
  throw new Error(`Payload too large for 16-bit length: ${payload.byteLength}`);
1782
1782
  }
1783
- const writer = new BufferWriter(payload.byteLength + 16);
1783
+ const writer = new MoqtBufferWriter(payload.byteLength + 16);
1784
1784
  writer.writeVarInt(typeId);
1785
1785
  writer.writeUint8(payload.byteLength >> 8 & 255);
1786
1786
  writer.writeUint8(payload.byteLength & 255);
@@ -1833,13 +1833,13 @@ function encodePayload(msg, w) {
1833
1833
  }
1834
1834
  function decodeMessage(bytes) {
1835
1835
  try {
1836
- const reader = new BufferReader(bytes);
1836
+ const reader = new MoqtBufferReader(bytes);
1837
1837
  const typeId = reader.readVarInt();
1838
1838
  const lenHi = reader.readUint8();
1839
1839
  const lenLo = reader.readUint8();
1840
1840
  const payloadLength = lenHi << 8 | lenLo;
1841
1841
  const payloadBytes = reader.readBytes(payloadLength);
1842
- const payloadReader = new BufferReader(payloadBytes);
1842
+ const payloadReader = new MoqtBufferReader(payloadBytes);
1843
1843
  let message;
1844
1844
  if (typeId === MSG_SETUP) {
1845
1845
  message = decodeSetupPayload(payloadReader, payloadLength);