moqtail 0.7.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.
@@ -0,0 +1,864 @@
1
+ /**
2
+ * Copyright 2025 The MOQtail Authors
3
+ *
4
+ * Licensed under the Apache License, Version 2.0 (the "License");
5
+ * you may not use this file except in compliance with the License.
6
+ * You may obtain a copy of the License at
7
+ *
8
+ * http://www.apache.org/licenses/LICENSE-2.0
9
+ *
10
+ * Unless required by applicable law or agreed to in writing, software
11
+ * distributed under the License is distributed on an "AS IS" BASIS,
12
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ * See the License for the specific language governing permissions and
14
+ * limitations under the License.
15
+ */
16
+
17
+ /**
18
+ * @public
19
+ * Represents a key-value pair for MOQT protocol parameters.
20
+ *
21
+ * - If `typeValue` is **even**, the value is a varint (`bigint`).
22
+ * - If `typeValue` is **odd**, the value is a binary blob (`Uint8Array`) with a maximum length of 65535 bytes.
23
+ *
24
+ * Use {@link KeyValuePair.tryNewVarInt} for varint pairs and {@link KeyValuePair.tryNewBytes} for blob pairs.
25
+ */
26
+ declare class KeyValuePair {
27
+ /**
28
+ * The key/type identifier for this pair.
29
+ * - Even: value is a varint.
30
+ * - Odd: value is a blob.
31
+ */
32
+ readonly typeValue: bigint;
33
+ /**
34
+ * The value for this pair.
35
+ * - If `typeValue` is even: a varint (`bigint`).
36
+ * - If `typeValue` is odd: a binary blob (`Uint8Array`).
37
+ */
38
+ readonly value: bigint | Uint8Array;
39
+ /**
40
+ * Constructs a new KeyValuePair.
41
+ * @param typeValue - The key/type identifier.
42
+ * @param value - The value (varint or blob).
43
+ * @internal Use static factory methods instead.
44
+ */
45
+ private constructor();
46
+ /**
47
+ * Creates a new varint KeyValuePair.
48
+ * @param typeValue - Must be even.
49
+ * @param value - The varint value.
50
+ * @returns A KeyValuePair with varint value.
51
+ * @throws KeyValueFormattingError if typeValue is not even.
52
+ */
53
+ static tryNewVarInt(typeValue: bigint | number, value: bigint | number): KeyValuePair;
54
+ /**
55
+ * Creates a new blob KeyValuePair.
56
+ * @param typeValue - Must be odd.
57
+ * @param value - The binary blob value.
58
+ * @returns A KeyValuePair with blob value.
59
+ * @throws KeyValueFormattingError if typeValue is not odd.
60
+ * @throws LengthExceedsMaxError if value length exceeds 65535 bytes.
61
+ */
62
+ static tryNewBytes(typeValue: bigint | number, value: Uint8Array): KeyValuePair;
63
+ /**
64
+ * Serializes this key-value pair to a frozen byte buffer.
65
+ * @returns The serialized buffer.
66
+ */
67
+ serialize(): FrozenByteBuffer;
68
+ /**
69
+ * Deserializes a KeyValuePair from a buffer.
70
+ * @param buf - The buffer to read from.
71
+ * @returns The deserialized KeyValuePair.
72
+ * @throws LengthExceedsMaxError if blob length exceeds 65535 bytes.
73
+ * @throws NotEnoughBytesError if buffer does not contain enough bytes.
74
+ */
75
+ static deserialize(buf: BaseByteBuffer): KeyValuePair;
76
+ /**
77
+ * Checks if this pair is equal to another.
78
+ * @param other - The other KeyValuePair.
79
+ * @returns True if both type and value are equal.
80
+ */
81
+ equals(other: KeyValuePair): boolean;
82
+ }
83
+ /**
84
+ * Checks if the KeyValuePair is a varint pair (even typeValue).
85
+ * @param pair - The KeyValuePair to check.
86
+ * @returns True if value is a varint.
87
+ */
88
+ declare function isVarInt(pair: KeyValuePair): pair is KeyValuePair & {
89
+ value: bigint;
90
+ };
91
+ /**
92
+ * Checks if the KeyValuePair is a blob pair (odd typeValue).
93
+ * @param pair - The KeyValuePair to check.
94
+ * @returns True if value is a Uint8Array.
95
+ */
96
+ declare function isBytes(pair: KeyValuePair): pair is KeyValuePair & {
97
+ value: Uint8Array;
98
+ };
99
+
100
+ /**
101
+ * Copyright 2025 The MOQtail Authors
102
+ *
103
+ * Licensed under the Apache License, Version 2.0 (the "License");
104
+ * you may not use this file except in compliance with the License.
105
+ * You may obtain a copy of the License at
106
+ *
107
+ * http://www.apache.org/licenses/LICENSE-2.0
108
+ *
109
+ * Unless required by applicable law or agreed to in writing, software
110
+ * distributed under the License is distributed on an "AS IS" BASIS,
111
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
112
+ * See the License for the specific language governing permissions and
113
+ * limitations under the License.
114
+ */
115
+
116
+ /**
117
+ * @public
118
+ * Represents a position in a MOQT track, consisting of a group and object index.
119
+ *
120
+ * Used for specifying start/end positions in subscription and fetch requests.
121
+ * - `group`: The group index (e.g. segment, GOP, or logical group).
122
+ * - `object`: The object index within the group (e.g. frame, chunk).
123
+ */
124
+ declare class Location {
125
+ /**
126
+ * The group index for this location.
127
+ */
128
+ readonly group: bigint;
129
+ /**
130
+ * The object index within the group for this location.
131
+ */
132
+ readonly object: bigint;
133
+ /**
134
+ * Constructs a new Location.
135
+ * @param group - The group index (number or bigint).
136
+ * @param object - The object index (number or bigint).
137
+ */
138
+ constructor(group: bigint | number, object: bigint | number);
139
+ /**
140
+ * Serializes this Location to a FrozenByteBuffer.
141
+ * @returns The serialized buffer.
142
+ * @throws CastingError if group or object is negative.
143
+ * @throws VarIntOverflowError if group or object exceeds varint encoding limits.
144
+ */
145
+ serialize(): FrozenByteBuffer;
146
+ /**
147
+ * Deserializes a Location from a buffer.
148
+ * @param buf - The buffer to read from.
149
+ * @returns The deserialized Location.
150
+ * @throws NotEnoughBytesError if buffer does not contain enough bytes.
151
+ */
152
+ static deserialize(buf: BaseByteBuffer): Location;
153
+ /**
154
+ * Checks if this Location is equal to another.
155
+ * @param other - The other Location to compare.
156
+ * @returns True if both group and object are equal.
157
+ */
158
+ equals(other: Location): boolean;
159
+ /**
160
+ * Compares this Location to another for ordering.
161
+ * @param other - The other Location to compare.
162
+ * @returns -1 if this \< other, 1 if this \> other, 0 if equal.
163
+ */
164
+ compare(other: Location): number;
165
+ }
166
+
167
+ /**
168
+ * Copyright 2025 The MOQtail Authors
169
+ *
170
+ * Licensed under the Apache License, Version 2.0 (the "License");
171
+ * you may not use this file except in compliance with the License.
172
+ * You may obtain a copy of the License at
173
+ *
174
+ * http://www.apache.org/licenses/LICENSE-2.0
175
+ *
176
+ * Unless required by applicable law or agreed to in writing, software
177
+ * distributed under the License is distributed on an "AS IS" BASIS,
178
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
179
+ * See the License for the specific language governing permissions and
180
+ * limitations under the License.
181
+ */
182
+
183
+ /**
184
+ * @public
185
+ * Represents a single field in a Tuple, storing a value as a UTF-8 encoded byte array.
186
+ *
187
+ * Used for path segments or protocol fields in MOQT.
188
+ */
189
+ declare class TupleField {
190
+ readonly value: Uint8Array;
191
+ /**
192
+ * The raw value of the field as a byte array.
193
+ */
194
+ constructor(value: Uint8Array);
195
+ /**
196
+ * Creates a TupleField from a UTF-8 string.
197
+ * @param str - The string to encode.
198
+ * @returns A new TupleField containing the encoded value.
199
+ */
200
+ static fromUtf8(str: string): TupleField;
201
+ /**
202
+ * Decodes the field value to a UTF-8 string.
203
+ * @returns The decoded string.
204
+ */
205
+ toUtf8(): string;
206
+ /**
207
+ * Serializes this field to a length-prefixed byte array.
208
+ * @returns The serialized bytes.
209
+ */
210
+ serialize(): Uint8Array;
211
+ /**
212
+ * Deserializes a TupleField from a buffer.
213
+ * @param buf - The buffer to read from.
214
+ * @returns The deserialized TupleField.
215
+ * @throws CastingError if the length cannot be safely cast to number.
216
+ * @throws NotEnoughBytesError if buffer does not contain enough bytes.
217
+ */
218
+ static deserialize(buf: BaseByteBuffer): TupleField;
219
+ }
220
+ /**
221
+ * @public
222
+ * Represents a sequence of TupleFields, typically used for hierarchical paths or protocol tuples in MOQT.
223
+ */
224
+ declare class Tuple {
225
+ readonly fields: TupleField[];
226
+ /**
227
+ * The ordered list of fields in this tuple.
228
+ */
229
+ constructor(fields?: TupleField[]);
230
+ /**
231
+ * Creates a Tuple from a path string, splitting on '/'.
232
+ * @param path - The path string (e.g. '/foo/bar').
233
+ * @returns A Tuple with each segment as a field.
234
+ */
235
+ static fromUtf8Path(path: string): Tuple;
236
+ /**
237
+ * Converts the tuple to a path string, joining fields with '/'.
238
+ * @returns The path string (e.g. '/foo/bar').
239
+ */
240
+ toUtf8Path(): string;
241
+ /**
242
+ * Adds a field to the tuple.
243
+ * @param field - The TupleField to add.
244
+ */
245
+ add(field: TupleField): void;
246
+ /**
247
+ * Gets the field at the specified index.
248
+ * @param index - The field index.
249
+ * @returns The TupleField at the index.
250
+ * @throws Error if no field exists at the index.
251
+ */
252
+ get(index: number): TupleField;
253
+ /**
254
+ * Sets the field at the specified index.
255
+ * @param index - The field index.
256
+ * @param field - The TupleField to set.
257
+ */
258
+ set(index: number, field: TupleField): void;
259
+ /**
260
+ * Clears all fields from the tuple.
261
+ */
262
+ clear(): void;
263
+ /**
264
+ * Serializes the tuple to a FrozenByteBuffer.
265
+ * @returns The serialized buffer.
266
+ */
267
+ serialize(): FrozenByteBuffer;
268
+ /**
269
+ * Deserializes a Tuple from a buffer.
270
+ * @param buf - The buffer to read from.
271
+ * @returns The deserialized Tuple.
272
+ * @throws CastingError if the count cannot be safely cast to number.
273
+ * @throws NotEnoughBytesError if buffer does not contain enough bytes.
274
+ */
275
+ static deserialize(buf: BaseByteBuffer): Tuple;
276
+ /**
277
+ * Checks if this tuple is equal to another.
278
+ * @param other - The other Tuple to compare.
279
+ * @returns True if all fields are equal.
280
+ */
281
+ equals(other: Tuple): boolean;
282
+ }
283
+
284
+ /**
285
+ * Copyright 2025 The MOQtail Authors
286
+ *
287
+ * Licensed under the Apache License, Version 2.0 (the "License");
288
+ * you may not use this file except in compliance with the License.
289
+ * You may obtain a copy of the License at
290
+ *
291
+ * http://www.apache.org/licenses/LICENSE-2.0
292
+ *
293
+ * Unless required by applicable law or agreed to in writing, software
294
+ * distributed under the License is distributed on an "AS IS" BASIS,
295
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
296
+ * See the License for the specific language governing permissions and
297
+ * limitations under the License.
298
+ */
299
+
300
+ /**
301
+ * The maximum allowed length (in bytes) for a ReasonPhrase.
302
+ * @public
303
+ */
304
+ declare const MAX_REASON_PHRASE_LEN = 1024;
305
+ /**
306
+ * Represents a protocol ReasonPhrase, a short UTF-8 string used for error or status reporting.
307
+ * Enforces a maximum byte length and validates encoding.
308
+ *
309
+ * @public
310
+ */
311
+ declare class ReasonPhrase {
312
+ #private;
313
+ /**
314
+ * Constructs a ReasonPhrase, validating UTF-8 encoding and length.
315
+ *
316
+ * @param phrase - The string to use as the reason phrase.
317
+ * @throws {@link InvalidUTF8Error} if encoding fails.
318
+ * @throws {@link LengthExceedsMaxError} if the encoded phrase exceeds {@link MAX_REASON_PHRASE_LEN} bytes.
319
+ * @public
320
+ */
321
+ constructor(phrase: string);
322
+ /**
323
+ * Returns the phrase string.
324
+ * @public
325
+ */
326
+ get phrase(): string;
327
+ /**
328
+ * Serializes the ReasonPhrase into a {@link FrozenByteBuffer} containing:
329
+ * varint(length_of_phrase_bytes) || phrase_bytes
330
+ *
331
+ * @returns The serialized buffer.
332
+ * @public
333
+ */
334
+ serialize(): FrozenByteBuffer;
335
+ /**
336
+ * Deserializes a ReasonPhrase from the given buffer.
337
+ * Reads varint(length) || utf8‑bytes.
338
+ *
339
+ * @param buf - The buffer to read from.
340
+ * @returns The deserialized ReasonPhrase.
341
+ * @throws :{@link CastingError} if the length cannot be safely cast to a number.
342
+ * @throws :{@link LengthExceedsMaxError} if the length exceeds {@link MAX_REASON_PHRASE_LEN}.
343
+ * @throws :{@link NotEnoughBytesError} if the buffer does not contain enough bytes.
344
+ * @throws :{@link InvalidUTF8Error} if decoding fails.
345
+ * @public
346
+ */
347
+ static deserialize(buf: BaseByteBuffer): ReasonPhrase;
348
+ }
349
+
350
+ /**
351
+ * Copyright 2025 The MOQtail Authors
352
+ *
353
+ * Licensed under the Apache License, Version 2.0 (the "License");
354
+ * you may not use this file except in compliance with the License.
355
+ * You may obtain a copy of the License at
356
+ *
357
+ * http://www.apache.org/licenses/LICENSE-2.0
358
+ *
359
+ * Unless required by applicable law or agreed to in writing, software
360
+ * distributed under the License is distributed on an "AS IS" BASIS,
361
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
362
+ * See the License for the specific language governing permissions and
363
+ * limitations under the License.
364
+ */
365
+ /**
366
+ * @public
367
+ * Object datagram status types for MOQT objects.
368
+ * - `WithoutExtensions`: Object datagram without extensions.
369
+ * - `WithExtensions`: Object datagram with extensions.
370
+ */
371
+ declare enum ObjectDatagramStatusType {
372
+ WithoutExtensions = 2,
373
+ WithExtensions = 3
374
+ }
375
+ /**
376
+ * @public
377
+ * Namespace for ObjectDatagramStatusType utilities.
378
+ */
379
+ declare namespace ObjectDatagramStatusType {
380
+ /**
381
+ * Converts a number or bigint to ObjectDatagramStatusType.
382
+ * @param value - The value to convert.
383
+ * @returns The corresponding ObjectDatagramStatusType.
384
+ * @throws Error if the value is not valid.
385
+ */
386
+ function tryFrom(value: number | bigint): ObjectDatagramStatusType;
387
+ }
388
+ /**
389
+ * @public
390
+ * Object datagram types for MOQT objects.
391
+ * - `WithoutExtensions`: Object datagram without extensions.
392
+ * - `WithExtensions`: Object datagram with extensions.
393
+ */
394
+ declare enum ObjectDatagramType {
395
+ WithoutExtensions = 0,
396
+ WithExtensions = 1
397
+ }
398
+ /**
399
+ * @public
400
+ * Namespace for ObjectDatagramType utilities.
401
+ */
402
+ declare namespace ObjectDatagramType {
403
+ /**
404
+ * Converts a number or bigint to ObjectDatagramType.
405
+ * @param value - The value to convert.
406
+ * @returns The corresponding ObjectDatagramType.
407
+ * @throws Error if the value is not valid.
408
+ */
409
+ function tryFrom(value: number | bigint): ObjectDatagramType;
410
+ }
411
+ /**
412
+ * @public
413
+ * Fetch header types for MOQT fetch requests.
414
+ */
415
+ declare enum FetchHeaderType {
416
+ Type0x05 = 5
417
+ }
418
+ /**
419
+ * Namespace for FetchHeaderType utilities.
420
+ */
421
+ declare namespace FetchHeaderType {
422
+ /**
423
+ * Converts a number or bigint to FetchHeaderType.
424
+ * @param value - The value to convert.
425
+ * @returns The corresponding FetchHeaderType.
426
+ * @throws Error if the value is not valid.
427
+ */
428
+ function tryFrom(value: number | bigint): FetchHeaderType;
429
+ }
430
+ /**
431
+ * @public
432
+ * Subgroup header types for MOQT subgroups.
433
+ */
434
+ declare enum SubgroupHeaderType {
435
+ Type0x10 = 16,
436
+ Type0x11 = 17,
437
+ Type0x12 = 18,
438
+ Type0x13 = 19,
439
+ Type0x14 = 20,
440
+ Type0x15 = 21,
441
+ Type0x18 = 24,
442
+ Type0x19 = 25,
443
+ Type0x1A = 26,
444
+ Type0x1B = 27,
445
+ Type0x1C = 28,
446
+ Type0x1D = 29
447
+ }
448
+ /**
449
+ * Namespace for SubgroupHeaderType utilities.
450
+ */
451
+ declare namespace SubgroupHeaderType {
452
+ /**
453
+ * Returns true if the header type has an explicit subgroup ID.
454
+ * @param t - The SubgroupHeaderType.
455
+ */
456
+ function hasExplicitSubgroupId(t: SubgroupHeaderType): boolean;
457
+ /**
458
+ * Returns true if the header type implies a subgroup ID of zero.
459
+ * @param t - The SubgroupHeaderType.
460
+ */
461
+ function isSubgroupIdZero(t: SubgroupHeaderType): boolean;
462
+ /**
463
+ * Returns true if the header type has extensions.
464
+ * @param t - The SubgroupHeaderType.
465
+ */
466
+ function hasExtensions(t: SubgroupHeaderType): boolean;
467
+ /**
468
+ * Converts a number or bigint to SubgroupHeaderType.
469
+ * @param value - The value to convert.
470
+ * @returns The corresponding SubgroupHeaderType.
471
+ * @throws Error if the value is not valid.
472
+ */
473
+ function tryFrom(value: number | bigint): SubgroupHeaderType;
474
+ }
475
+ /**
476
+ * @public
477
+ * Publisher's preferred object delivery mechanism for a track.
478
+ * - `Subgroup`: Use ordered subgroups (reliable).
479
+ * - `Datagram`: Use unreliable datagrams when feasible.
480
+ *
481
+ * The preference is advisory: the relay/transport layer MAY override based on negotiated capabilities.
482
+ */
483
+ declare enum ObjectForwardingPreference {
484
+ Subgroup = "Subgroup",
485
+ Datagram = "Datagram"
486
+ }
487
+ /**
488
+ * Namespace for ObjectForwardingPreference utilities.
489
+ */
490
+ declare namespace ObjectForwardingPreference {
491
+ /**
492
+ * Converts a number, bigint, or string to ObjectForwardingPreference.
493
+ * @param value - The value to convert.
494
+ * @returns The corresponding ObjectForwardingPreference.
495
+ * @throws Error if the value is not valid.
496
+ */
497
+ function tryFrom(value: number | bigint | string): ObjectForwardingPreference;
498
+ }
499
+ /**
500
+ * @public
501
+ * Object status codes for MOQT objects.
502
+ * - `Normal`: Object exists and is available.
503
+ * - `DoesNotExist`: Object does not exist.
504
+ * - `EndOfGroup`: End of group marker.
505
+ * - `EndOfTrack`: End of track marker.
506
+ */
507
+ declare enum ObjectStatus {
508
+ Normal = 0,
509
+ DoesNotExist = 1,
510
+ EndOfGroup = 3,
511
+ EndOfTrack = 4
512
+ }
513
+ /**
514
+ * Namespace for ObjectStatus utilities.
515
+ */
516
+ declare namespace ObjectStatus {
517
+ /**
518
+ * Converts a number or bigint to ObjectStatus.
519
+ * @param value - The value to convert.
520
+ * @returns The corresponding ObjectStatus.
521
+ * @throws Error if the value is not valid.
522
+ */
523
+ function tryFrom(value: number | bigint): ObjectStatus;
524
+ }
525
+
526
+ /**
527
+ * Copyright 2025 The MOQtail Authors
528
+ *
529
+ * Licensed under the Apache License, Version 2.0 (the "License");
530
+ * you may not use this file except in compliance with the License.
531
+ * You may obtain a copy of the License at
532
+ *
533
+ * http://www.apache.org/licenses/LICENSE-2.0
534
+ *
535
+ * Unless required by applicable law or agreed to in writing, software
536
+ * distributed under the License is distributed on an "AS IS" BASIS,
537
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
538
+ * See the License for the specific language governing permissions and
539
+ * limitations under the License.
540
+ */
541
+
542
+ declare class DatagramObject {
543
+ readonly type: ObjectDatagramType;
544
+ readonly publisherPriority: number;
545
+ readonly extensionHeaders: KeyValuePair[] | null;
546
+ readonly payload: Uint8Array;
547
+ readonly trackAlias: bigint;
548
+ readonly location: Location;
549
+ private constructor();
550
+ get groupId(): bigint;
551
+ get objectId(): bigint;
552
+ static newWithExtensions(trackAlias: bigint, groupId: bigint, objectId: bigint, publisherPriority: number, extensionHeaders: KeyValuePair[], payload: Uint8Array): DatagramObject;
553
+ static newWithoutExtensions(trackAlias: bigint, groupId: bigint, objectId: bigint, publisherPriority: number, payload: Uint8Array): DatagramObject;
554
+ serialize(): FrozenByteBuffer;
555
+ static deserialize(buf: BaseByteBuffer): DatagramObject;
556
+ }
557
+
558
+ /**
559
+ * Copyright 2025 The MOQtail Authors
560
+ *
561
+ * Licensed under the Apache License, Version 2.0 (the "License");
562
+ * you may not use this file except in compliance with the License.
563
+ * You may obtain a copy of the License at
564
+ *
565
+ * http://www.apache.org/licenses/LICENSE-2.0
566
+ *
567
+ * Unless required by applicable law or agreed to in writing, software
568
+ * distributed under the License is distributed on an "AS IS" BASIS,
569
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
570
+ * See the License for the specific language governing permissions and
571
+ * limitations under the License.
572
+ */
573
+
574
+ declare class DatagramStatus {
575
+ readonly type: ObjectDatagramStatusType;
576
+ readonly publisherPriority: number;
577
+ readonly extensionHeaders: KeyValuePair[] | null;
578
+ readonly objectStatus: ObjectStatus;
579
+ readonly trackAlias: bigint;
580
+ readonly location: Location;
581
+ private constructor();
582
+ get groupId(): bigint;
583
+ get objectId(): bigint;
584
+ static withExtensions(trackAlias: bigint | number, location: Location, publisherPriority: number, extensionHeaders: KeyValuePair[], objectStatus: ObjectStatus): DatagramStatus;
585
+ static newWithoutExtensions(trackAlias: bigint | number, location: Location, publisherPriority: number, objectStatus: ObjectStatus): DatagramStatus;
586
+ serialize(): FrozenByteBuffer;
587
+ static deserialize(buf: BaseByteBuffer): DatagramStatus;
588
+ }
589
+
590
+ /**
591
+ * Copyright 2025 The MOQtail Authors
592
+ *
593
+ * Licensed under the Apache License, Version 2.0 (the "License");
594
+ * you may not use this file except in compliance with the License.
595
+ * You may obtain a copy of the License at
596
+ *
597
+ * http://www.apache.org/licenses/LICENSE-2.0
598
+ *
599
+ * Unless required by applicable law or agreed to in writing, software
600
+ * distributed under the License is distributed on an "AS IS" BASIS,
601
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
602
+ * See the License for the specific language governing permissions and
603
+ * limitations under the License.
604
+ */
605
+
606
+ declare class FetchObject {
607
+ readonly publisherPriority: number;
608
+ readonly extensionHeaders: KeyValuePair[] | null;
609
+ readonly objectStatus: ObjectStatus | null;
610
+ readonly payload: Uint8Array | null;
611
+ readonly location: Location;
612
+ readonly subgroupId: bigint;
613
+ private constructor();
614
+ get groupId(): bigint;
615
+ get objectId(): bigint;
616
+ static newWithStatus(groupId: bigint | number, subgroupId: bigint | number, objectId: bigint | number, publisherPriority: number, extensionHeaders: KeyValuePair[] | null, objectStatus: ObjectStatus): FetchObject;
617
+ static newWithPayload(groupId: bigint | number, subgroupId: bigint | number, objectId: bigint | number, publisherPriority: number, extensionHeaders: KeyValuePair[] | null, payload: Uint8Array): FetchObject;
618
+ serialize(_previousObjectId?: BigInt): FrozenByteBuffer;
619
+ static deserialize(buf: BaseByteBuffer): FetchObject;
620
+ }
621
+
622
+ /**
623
+ * Copyright 2025 The MOQtail Authors
624
+ *
625
+ * Licensed under the Apache License, Version 2.0 (the "License");
626
+ * you may not use this file except in compliance with the License.
627
+ * You may obtain a copy of the License at
628
+ *
629
+ * http://www.apache.org/licenses/LICENSE-2.0
630
+ *
631
+ * Unless required by applicable law or agreed to in writing, software
632
+ * distributed under the License is distributed on an "AS IS" BASIS,
633
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
634
+ * See the License for the specific language governing permissions and
635
+ * limitations under the License.
636
+ */
637
+
638
+ declare const MAX_NAMESPACE_TUPLE_COUNT = 32;
639
+ declare const MAX_FULL_TRACK_NAME_LENGTH = 4096;
640
+ /**
641
+ * Fully-qualified track identifier = hierarchical namespace (tuple) + leaf name bytes.
642
+ *
643
+ * Constraints enforced (throws {@link TrackNameError}):
644
+ * - Namespace tuple field count: 1 .. {@link MAX_NAMESPACE_TUPLE_COUNT} (must not be empty).
645
+ * - Total serialized length (namespace tuple + raw name bytes) less than or equals {@link MAX_FULL_TRACK_NAME_LENGTH} bytes.
646
+ *
647
+ * Namespace input may be:
648
+ * - `string` path with segments separated by `/` (converted via {@link Tuple.fromUtf8Path}). Empty segments are preserved
649
+ * except leading/trailing slashes are treated as empty fields and will be rejected by the length check if result is 0.
650
+ * - Existing {@link Tuple} instance.
651
+ *
652
+ * Name input may be:
653
+ * - UTF-8 string (encoded)
654
+ * - Raw `Uint8Array` (used directly)
655
+ *
656
+ * Instances are created via {@link FullTrackName.tryNew} (validates) or {@link FullTrackName.deserialize}.
657
+ * Use {@link FullTrackName.serialize} for wire encoding and {@link FullTrackName.toString} for a human friendly
658
+ * diagnostic format: `namespace/segments:hexname` (name rendered as lowercase hex, no 0x prefix).
659
+ *
660
+ * The string form is intended for logs/debug only; do not parse it for protocol operations.
661
+ */
662
+ declare class FullTrackName {
663
+ readonly namespace: Tuple;
664
+ readonly name: Uint8Array;
665
+ private constructor();
666
+ /**
667
+ * Human-readable representation: `\<namespace path joined by '/'\>:\<name as lowercase hex\>`.
668
+ * If the underlying {@link Tuple} exposes `toUtf8Path`, it's used; otherwise the raw fields are joined.
669
+ * This is lossy only in the sense that name bytes are hex encoded; round-tripping requires serialization.
670
+ */
671
+ toString(): string;
672
+ /**
673
+ * Construct a validated full track name.
674
+ *
675
+ * Validation steps:
676
+ * 1. Convert namespace string -\> {@link Tuple} (split on '/') if needed.
677
+ * 2. Reject if namespace tuple field count is 0 or \> {@link MAX_NAMESPACE_TUPLE_COUNT}.
678
+ * 3. Encode name string to UTF-8 if needed.
679
+ * 4. Reject if total serialized length (namespace tuple + name bytes) \> {@link MAX_FULL_TRACK_NAME_LENGTH}.
680
+ *
681
+ * @throws :{@link TrackNameError} on any constraint violation.
682
+ * @example
683
+ * ```ts
684
+ * const full = FullTrackName.tryNew('media/video', 'keyframe')
685
+ * console.log(full.toString()) // media/video:6b65796672616d65
686
+ * ```
687
+ */
688
+ static tryNew(namespace: string | Tuple, name: string | Uint8Array): FullTrackName;
689
+ /**
690
+ * Serialize to a frozen buffer: tuple (namespace) followed by length‑prefixed name bytes.
691
+ * Consumers needing raw bytes should call `.toUint8Array()` on the returned {@link FrozenByteBuffer}.
692
+ */
693
+ serialize(): FrozenByteBuffer;
694
+ /**
695
+ * Parse a serialized full track name. Performs the same validations as {@link FullTrackName.tryNew}.
696
+ * The provided buffer's read cursor advances accordingly.
697
+ * @throws :{@link TrackNameError} if constraints are violated.
698
+ */
699
+ static deserialize(buf: BaseByteBuffer): FullTrackName;
700
+ }
701
+
702
+ /**
703
+ * Copyright 2025 The MOQtail Authors
704
+ *
705
+ * Licensed under the Apache License, Version 2.0 (the "License");
706
+ * you may not use this file except in compliance with the License.
707
+ * You may obtain a copy of the License at
708
+ *
709
+ * http://www.apache.org/licenses/LICENSE-2.0
710
+ *
711
+ * Unless required by applicable law or agreed to in writing, software
712
+ * distributed under the License is distributed on an "AS IS" BASIS,
713
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
714
+ * See the License for the specific language governing permissions and
715
+ * limitations under the License.
716
+ */
717
+
718
+ declare class SubgroupObject {
719
+ readonly extensionHeaders: KeyValuePair[] | null;
720
+ readonly objectStatus: ObjectStatus | null;
721
+ readonly payload: Uint8Array | null;
722
+ readonly objectId: bigint;
723
+ private constructor();
724
+ static newWithStatus(objectId: bigint | number, extensionHeaders: KeyValuePair[] | null, objectStatus: ObjectStatus): SubgroupObject;
725
+ static newWithPayload(objectId: bigint | number, extensionHeaders: KeyValuePair[] | null, payload: Uint8Array): SubgroupObject;
726
+ serialize(previousObjectId: bigint | undefined): FrozenByteBuffer;
727
+ static deserialize(buf: BaseByteBuffer, hasExtensions: boolean, previousObjectId: bigint | undefined): SubgroupObject;
728
+ }
729
+
730
+ /**
731
+ * Copyright 2025 The MOQtail Authors
732
+ *
733
+ * Licensed under the Apache License, Version 2.0 (the "License");
734
+ * you may not use this file except in compliance with the License.
735
+ * You may obtain a copy of the License at
736
+ *
737
+ * http://www.apache.org/licenses/LICENSE-2.0
738
+ *
739
+ * Unless required by applicable law or agreed to in writing, software
740
+ * distributed under the License is distributed on an "AS IS" BASIS,
741
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
742
+ * See the License for the specific language governing permissions and
743
+ * limitations under the License.
744
+ */
745
+
746
+ declare class MoqtObject {
747
+ readonly fullTrackName: FullTrackName;
748
+ readonly publisherPriority: number;
749
+ readonly objectForwardingPreference: ObjectForwardingPreference;
750
+ readonly objectStatus: ObjectStatus;
751
+ readonly extensionHeaders: KeyValuePair[] | null;
752
+ readonly payload: Uint8Array | null;
753
+ readonly location: Location;
754
+ readonly subgroupId: bigint | null;
755
+ private constructor();
756
+ get groupId(): bigint;
757
+ get objectId(): bigint;
758
+ getSubgroupHeaderType(containsEnd: boolean): SubgroupHeaderType;
759
+ isDatagram(): boolean;
760
+ isSubgroup(): boolean;
761
+ isEndOfGroup(): boolean;
762
+ isEndOfTrack(): boolean;
763
+ doesNotExist(): boolean;
764
+ hasPayload(): boolean;
765
+ hasStatus(): boolean;
766
+ static newWithPayload(fullTrackName: FullTrackName, location: Location, publisherPriority: number, objectForwardingPreference: ObjectForwardingPreference, subgroupId: bigint | number | null, extensionHeaders: KeyValuePair[] | null, payload: Uint8Array): MoqtObject;
767
+ static newWithStatus(fullTrackName: FullTrackName, location: Location, publisherPriority: number, objectForwardingPreference: ObjectForwardingPreference, subgroupId: bigint | number | null, extensionHeaders: KeyValuePair[] | null, objectStatus: ObjectStatus): MoqtObject;
768
+ static fromDatagramObject(datagramObject: DatagramObject, fullTrackName: FullTrackName): MoqtObject;
769
+ static fromDatagramStatus(datagramStatus: DatagramStatus, fullTrackName: FullTrackName): MoqtObject;
770
+ static fromFetchObject(fetchObject: FetchObject, fullTrackName: FullTrackName): MoqtObject;
771
+ static fromSubgroupObject(subgroupObject: SubgroupObject, groupId: bigint | number, publisherPriority: number, subgroupId: bigint | number, fullTrackName: FullTrackName): MoqtObject;
772
+ tryIntoDatagramObject(trackAlias: bigint | number): DatagramObject;
773
+ tryIntoDatagramStatus(trackAlias: bigint | number): DatagramStatus;
774
+ tryIntoFetchObject(): FetchObject;
775
+ tryIntoSubgroupObject(): SubgroupObject;
776
+ }
777
+
778
+ /**
779
+ * Copyright 2025 The MOQtail Authors
780
+ *
781
+ * Licensed under the Apache License, Version 2.0 (the "License");
782
+ * you may not use this file except in compliance with the License.
783
+ * You may obtain a copy of the License at
784
+ *
785
+ * http://www.apache.org/licenses/LICENSE-2.0
786
+ *
787
+ * Unless required by applicable law or agreed to in writing, software
788
+ * distributed under the License is distributed on an "AS IS" BASIS,
789
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
790
+ * See the License for the specific language governing permissions and
791
+ * limitations under the License.
792
+ */
793
+
794
+ declare abstract class BaseByteBuffer {
795
+ protected buf: Uint8Array;
796
+ protected view: DataView;
797
+ protected _offset: number;
798
+ protected _checkpoint: number;
799
+ constructor(buf: Uint8Array);
800
+ get offset(): number;
801
+ abstract get length(): number;
802
+ get remaining(): number;
803
+ /**
804
+ * Save current read position for potential rollback
805
+ */
806
+ checkpoint(): void;
807
+ /**
808
+ * Restore read position to last checkpoint
809
+ */
810
+ restore(): void;
811
+ toUint8Array(): Uint8Array;
812
+ getU8(): number;
813
+ getU16(): number;
814
+ getVI(): bigint;
815
+ getNumberVI(): number;
816
+ getBytes(len: number): Uint8Array;
817
+ getLengthPrefixedBytes(): Uint8Array;
818
+ getKeyValuePair(): KeyValuePair;
819
+ getReasonPhrase(): ReasonPhrase;
820
+ getLocation(): Location;
821
+ getTuple(): Tuple;
822
+ getFullTrackName(): FullTrackName;
823
+ }
824
+ declare class ByteBuffer extends BaseByteBuffer {
825
+ private _length;
826
+ constructor(initialSize?: number);
827
+ get length(): number;
828
+ /**
829
+ * Clear all data and reset all positions
830
+ */
831
+ clear(): void;
832
+ /**
833
+ * Drop all data before current offset and reset positions
834
+ * This is the key method for memory management - removes processed data
835
+ */
836
+ commit(): void;
837
+ private ensureCapacity;
838
+ putU8(v: number): void;
839
+ putU16(v: number): void;
840
+ /**
841
+ * Write a variable-length integer (QUIC-style varint)
842
+ * Encoding:
843
+ * - 2 MSB = 00: 1 byte (6 bits) for values 0-63
844
+ * - 2 MSB = 01: 2 bytes (14 bits) for values 0-16383
845
+ * - 2 MSB = 10: 4 bytes (30 bits) for values 0-1073741823
846
+ * - 2 MSB = 11: 8 bytes (62 bits) for values 0-4611686018427387903
847
+ */
848
+ putVI(v: bigint | number): void;
849
+ putBytes(src: Uint8Array): void;
850
+ putLengthPrefixedBytes(src: Uint8Array): void;
851
+ putKeyValuePair(pair: KeyValuePair): void;
852
+ putReasonPhrase(reason: ReasonPhrase): void;
853
+ toUint8Array(): Uint8Array;
854
+ freeze(): FrozenByteBuffer;
855
+ putLocation(loc: Location): void;
856
+ putTuple(tuple: Tuple): void;
857
+ putFullTrackName(fullTrackName: FullTrackName): void;
858
+ }
859
+ declare class FrozenByteBuffer extends BaseByteBuffer {
860
+ constructor(buf: Uint8Array);
861
+ get length(): number;
862
+ }
863
+
864
+ export { BaseByteBuffer as B, DatagramObject as D, FrozenByteBuffer as F, KeyValuePair as K, Location as L, MAX_REASON_PHRASE_LEN as M, ObjectDatagramStatusType as O, ReasonPhrase as R, SubgroupHeaderType as S, TupleField as T, ByteBuffer as a, isBytes as b, Tuple as c, ObjectDatagramType as d, FetchHeaderType as e, ObjectForwardingPreference as f, ObjectStatus as g, DatagramStatus as h, isVarInt as i, FetchObject as j, MAX_NAMESPACE_TUPLE_COUNT as k, MAX_FULL_TRACK_NAME_LENGTH as l, FullTrackName as m, MoqtObject as n, SubgroupObject as o };