@moqtap/codec 0.7.0 → 0.8.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (54) hide show
  1. package/README.md +24 -0
  2. package/dist/{chunk-5XZKO2U5.js → chunk-2XH6PHXR.js} +62 -51
  3. package/dist/{chunk-APTV6F72.js → chunk-3YAR3I3S.js} +67 -51
  4. package/dist/{chunk-Y4FRXYX6.cjs → chunk-7ENEWAMZ.cjs} +52 -58
  5. package/dist/{chunk-MD2OA7SE.js → chunk-BV6MITLO.js} +15 -8
  6. package/dist/{chunk-B56AG5HU.cjs → chunk-EVCPBFSR.cjs} +6 -4
  7. package/dist/{chunk-KNLPX3YA.js → chunk-H6DTAIWM.js} +6 -4
  8. package/dist/{chunk-J3ASFPCX.cjs → chunk-IADVBKEJ.cjs} +15 -8
  9. package/dist/{chunk-I55J3KXD.js → chunk-NH4L6NIY.js} +48 -33
  10. package/dist/{chunk-EQAYMCXO.cjs → chunk-PU2KV7VP.cjs} +48 -33
  11. package/dist/{chunk-HEO2JG6C.js → chunk-TMXRYOBS.js} +100 -92
  12. package/dist/{chunk-IEJULBKB.cjs → chunk-UA5XFP4O.cjs} +100 -92
  13. package/dist/{chunk-KTVN4P6J.cjs → chunk-UZO5Z2XT.cjs} +62 -51
  14. package/dist/{chunk-MH7537FB.cjs → chunk-VWXUT5R2.cjs} +67 -51
  15. package/dist/{chunk-DORX55MO.js → chunk-XQGEOFGE.js} +52 -58
  16. package/dist/{codec-B1snaM9L.d.cts → codec-N3g1lxQQ.d.cts} +1 -1
  17. package/dist/{codec-D49OofBr.d.ts → codec-v6Vloc7H.d.ts} +1 -1
  18. package/dist/draft12.cjs +2 -2
  19. package/dist/draft12.js +1 -1
  20. package/dist/draft14-session.d.cts +1 -1
  21. package/dist/draft14-session.d.ts +1 -1
  22. package/dist/draft14.cjs +2 -2
  23. package/dist/draft14.d.cts +3 -3
  24. package/dist/draft14.d.ts +3 -3
  25. package/dist/draft14.js +1 -1
  26. package/dist/draft15.cjs +2 -2
  27. package/dist/draft15.js +1 -1
  28. package/dist/draft16.cjs +2 -2
  29. package/dist/draft16.js +1 -1
  30. package/dist/draft17.cjs +2 -2
  31. package/dist/draft17.js +1 -1
  32. package/dist/draft18.cjs +2 -2
  33. package/dist/draft18.js +1 -1
  34. package/dist/draft19.cjs +2 -2
  35. package/dist/draft19.js +1 -1
  36. package/dist/index.cjs +68 -16
  37. package/dist/index.d.cts +73 -3
  38. package/dist/index.d.ts +73 -3
  39. package/dist/index.js +60 -8
  40. package/dist/session.d.cts +1 -1
  41. package/dist/session.d.ts +1 -1
  42. package/dist/{types-DjmrHp_s.d.cts → types-HI_bbXka.d.cts} +29 -23
  43. package/dist/{types-DjmrHp_s.d.ts → types-HI_bbXka.d.ts} +29 -23
  44. package/package.json +2 -2
  45. package/src/core/accessors.ts +120 -0
  46. package/src/drafts/draft12/data-streams.ts +13 -4
  47. package/src/drafts/draft14/codec.ts +52 -58
  48. package/src/drafts/draft14/types.ts +31 -25
  49. package/src/drafts/draft15/data-streams.ts +30 -16
  50. package/src/drafts/draft16/codec.ts +116 -93
  51. package/src/drafts/draft17/codec.ts +72 -35
  52. package/src/drafts/draft18/codec.ts +89 -53
  53. package/src/drafts/draft19/codec.ts +94 -53
  54. package/src/index.ts +8 -0
@@ -333,8 +333,8 @@ function encodeSubscribePayload(
333
333
  w.writeVarInt(msg.request_id)
334
334
  w.writeTuple(msg.track_namespace)
335
335
  w.writeString(msg.track_name)
336
- w.writeUint8(Number(msg.subscriber_priority))
337
- w.writeUint8(Number(msg.group_order))
336
+ w.writeUint8(msg.subscriber_priority)
337
+ w.writeUint8(msg.group_order)
338
338
  w.writeVarInt(msg.forward)
339
339
  w.writeVarInt(msg.filter_type)
340
340
  const ft = msg.filter_type
@@ -355,7 +355,7 @@ function encodeSubscribeOkPayload(
355
355
  w.writeVarInt(msg.request_id)
356
356
  w.writeVarInt(msg.track_alias)
357
357
  w.writeVarInt(msg.expires)
358
- w.writeUint8(Number(msg.group_order))
358
+ w.writeUint8(msg.group_order)
359
359
  w.writeVarInt(msg.content_exists)
360
360
  if (msg.content_exists === 1n) {
361
361
  w.writeVarInt(msg.largest_location!.group)
@@ -373,7 +373,7 @@ function encodeSubscribeUpdatePayload(
373
373
  w.writeVarInt(msg.start_group)
374
374
  w.writeVarInt(msg.start_object)
375
375
  w.writeVarInt(msg.end_group)
376
- w.writeUint8(Number(msg.subscriber_priority))
376
+ w.writeUint8(msg.subscriber_priority)
377
377
  w.writeVarInt(msg.forward)
378
378
  encodeMessageParams(msg.parameters, w)
379
379
  }
@@ -399,7 +399,7 @@ function encodePublishPayload(msg: Draft14Message & { type: 'publish' }, w: Buff
399
399
  w.writeTuple(msg.track_namespace)
400
400
  w.writeString(msg.track_name)
401
401
  w.writeVarInt(msg.track_alias)
402
- w.writeUint8(Number(msg.group_order))
402
+ w.writeUint8(msg.group_order)
403
403
  w.writeVarInt(msg.content_exists)
404
404
  if (msg.content_exists === 1n) {
405
405
  w.writeVarInt(msg.largest_location!.group)
@@ -415,8 +415,8 @@ function encodePublishOkPayload(
415
415
  ): void {
416
416
  w.writeVarInt(msg.request_id)
417
417
  w.writeVarInt(msg.forward)
418
- w.writeUint8(Number(msg.subscriber_priority))
419
- w.writeUint8(Number(msg.group_order))
418
+ w.writeUint8(msg.subscriber_priority)
419
+ w.writeUint8(msg.group_order)
420
420
  w.writeVarInt(msg.filter_type)
421
421
  const ft = msg.filter_type
422
422
  if (ft >= FilterType.AbsoluteStart) {
@@ -462,7 +462,6 @@ function encodePublishNamespaceOkPayload(
462
462
  w: BufferWriter,
463
463
  ): void {
464
464
  w.writeVarInt(msg.request_id)
465
- encodeMessageParams(msg.parameters, w)
466
465
  }
467
466
 
468
467
  function encodePublishNamespaceErrorPayload(
@@ -504,7 +503,6 @@ function encodeSubscribeNamespaceOkPayload(
504
503
  w: BufferWriter,
505
504
  ): void {
506
505
  w.writeVarInt(msg.request_id)
507
- encodeMessageParams(msg.parameters, w)
508
506
  }
509
507
 
510
508
  function encodeSubscribeNamespaceErrorPayload(
@@ -525,27 +523,27 @@ function encodeUnsubscribeNamespacePayload(
525
523
 
526
524
  function encodeFetchPayload(msg: Draft14Message & { type: 'fetch' }, w: BufferWriter): void {
527
525
  w.writeVarInt(msg.request_id)
528
- w.writeUint8(Number(msg.subscriber_priority))
529
- w.writeUint8(Number(msg.group_order))
526
+ w.writeUint8(msg.subscriber_priority)
527
+ w.writeUint8(msg.group_order)
530
528
  w.writeVarInt(msg.fetch_type)
531
529
  const ft = msg.fetch_type
532
- if (ft === FetchType.Standalone) {
533
- w.writeTuple(msg.track_namespace!)
534
- w.writeString(msg.track_name!)
535
- w.writeVarInt(msg.start_group!)
536
- w.writeVarInt(msg.start_object!)
537
- w.writeVarInt(msg.end_group!)
538
- w.writeVarInt(msg.end_object!)
539
- } else {
540
- w.writeVarInt(msg.joining_request_id!)
541
- w.writeVarInt(msg.joining_start!)
530
+ if (ft === FetchType.Standalone && msg.standalone) {
531
+ w.writeTuple(msg.standalone.track_namespace)
532
+ w.writeString(msg.standalone.track_name)
533
+ w.writeVarInt(msg.standalone.start_group)
534
+ w.writeVarInt(msg.standalone.start_object)
535
+ w.writeVarInt(msg.standalone.end_group)
536
+ w.writeVarInt(msg.standalone.end_object)
537
+ } else if (msg.joining) {
538
+ w.writeVarInt(msg.joining.joining_request_id)
539
+ w.writeVarInt(msg.joining.joining_start)
542
540
  }
543
541
  encodeMessageParams(msg.parameters, w)
544
542
  }
545
543
 
546
544
  function encodeFetchOkPayload(msg: Draft14Message & { type: 'fetch_ok' }, w: BufferWriter): void {
547
545
  w.writeVarInt(msg.request_id)
548
- w.writeUint8(Number(msg.group_order))
546
+ w.writeUint8(msg.group_order)
549
547
  w.writeVarInt(msg.end_of_track)
550
548
  w.writeVarInt(msg.end_location.group)
551
549
  w.writeVarInt(msg.end_location.object)
@@ -575,8 +573,8 @@ function encodeTrackStatusPayload(
575
573
  w.writeVarInt(msg.request_id)
576
574
  w.writeTuple(msg.track_namespace)
577
575
  w.writeString(msg.track_name)
578
- w.writeUint8(Number(msg.subscriber_priority))
579
- w.writeUint8(Number(msg.group_order))
576
+ w.writeUint8(msg.subscriber_priority)
577
+ w.writeUint8(msg.group_order)
580
578
  w.writeVarInt(msg.forward)
581
579
  w.writeVarInt(msg.filter_type)
582
580
  const ft = msg.filter_type
@@ -594,7 +592,7 @@ function encodeTrackStatusOkPayload(
594
592
  w.writeVarInt(msg.request_id)
595
593
  w.writeVarInt(msg.track_alias)
596
594
  w.writeVarInt(msg.expires)
597
- w.writeUint8(Number(msg.group_order))
595
+ w.writeUint8(msg.group_order)
598
596
  w.writeVarInt(msg.content_exists)
599
597
  if (msg.content_exists === 1n) {
600
598
  w.writeVarInt(msg.largest_location!.group)
@@ -659,8 +657,8 @@ function decodeSubscribePayload(r: BufferReader): Draft14Message {
659
657
  const request_id = r.readVarInt()
660
658
  const track_namespace = r.readTuple()
661
659
  const track_name = r.readString()
662
- const subscriber_priority = BigInt(r.readUint8())
663
- const group_order = BigInt(r.readUint8())
660
+ const subscriber_priority = r.readUint8()
661
+ const group_order = r.readUint8()
664
662
  const forward = r.readVarInt()
665
663
  const filter_type = r.readVarInt()
666
664
 
@@ -705,7 +703,7 @@ function decodeSubscribeOkPayload(r: BufferReader): Draft14Message {
705
703
  const request_id = r.readVarInt()
706
704
  const track_alias = r.readVarInt()
707
705
  const expires = r.readVarInt()
708
- const group_order = BigInt(r.readUint8())
706
+ const group_order = r.readUint8()
709
707
  const content_exists = r.readVarInt()
710
708
 
711
709
  let largest_location: Location | undefined
@@ -736,7 +734,7 @@ function decodeSubscribeUpdatePayload(r: BufferReader): Draft14Message {
736
734
  const start_group = r.readVarInt()
737
735
  const start_object = r.readVarInt()
738
736
  const end_group = r.readVarInt()
739
- const subscriber_priority = BigInt(r.readUint8())
737
+ const subscriber_priority = r.readUint8()
740
738
  const forward = r.readVarInt()
741
739
  const parameters = decodeMessageParams(r)
742
740
  return {
@@ -769,7 +767,7 @@ function decodePublishPayload(r: BufferReader): Draft14Message {
769
767
  const track_namespace = r.readTuple()
770
768
  const track_name = r.readString()
771
769
  const track_alias = r.readVarInt()
772
- const group_order = BigInt(r.readUint8())
770
+ const group_order = r.readUint8()
773
771
  const content_exists = r.readVarInt()
774
772
  let largest_location: Location | undefined
775
773
  if (content_exists === 1n) {
@@ -797,8 +795,8 @@ function decodePublishPayload(r: BufferReader): Draft14Message {
797
795
  function decodePublishOkPayload(r: BufferReader): Draft14Message {
798
796
  const request_id = r.readVarInt()
799
797
  const forward = r.readVarInt()
800
- const subscriber_priority = BigInt(r.readUint8())
801
- const group_order = BigInt(r.readUint8())
798
+ const subscriber_priority = r.readUint8()
799
+ const group_order = r.readUint8()
802
800
  const filter_type = r.readVarInt()
803
801
 
804
802
  let start_group: bigint | undefined
@@ -861,8 +859,7 @@ function decodePublishNamespacePayload(r: BufferReader): Draft14Message {
861
859
 
862
860
  function decodePublishNamespaceOkPayload(r: BufferReader): Draft14Message {
863
861
  const request_id = r.readVarInt()
864
- const parameters = decodeMessageParams(r)
865
- return { type: 'publish_namespace_ok', request_id, parameters }
862
+ return { type: 'publish_namespace_ok', request_id }
866
863
  }
867
864
 
868
865
  function decodePublishNamespaceErrorPayload(r: BufferReader): Draft14Message {
@@ -908,8 +905,7 @@ function decodeSubscribeNamespacePayload(r: BufferReader): Draft14Message {
908
905
 
909
906
  function decodeSubscribeNamespaceOkPayload(r: BufferReader): Draft14Message {
910
907
  const request_id = r.readVarInt()
911
- const parameters = decodeMessageParams(r)
912
- return { type: 'subscribe_namespace_ok', request_id, parameters }
908
+ return { type: 'subscribe_namespace_ok', request_id }
913
909
  }
914
910
 
915
911
  function decodeSubscribeNamespaceErrorPayload(r: BufferReader): Draft14Message {
@@ -931,8 +927,8 @@ function decodeUnsubscribeNamespacePayload(r: BufferReader): Draft14Message {
931
927
 
932
928
  function decodeFetchPayload(r: BufferReader): Draft14Message {
933
929
  const request_id = r.readVarInt()
934
- const subscriber_priority = BigInt(r.readUint8())
935
- const group_order = BigInt(r.readUint8())
930
+ const subscriber_priority = r.readUint8()
931
+ const group_order = r.readUint8()
936
932
  const fetch_type = r.readVarInt()
937
933
 
938
934
  if (fetch_type < FetchType.Standalone || fetch_type > FetchType.AbsoluteJoining) {
@@ -940,12 +936,14 @@ function decodeFetchPayload(r: BufferReader): Draft14Message {
940
936
  }
941
937
 
942
938
  if (fetch_type === FetchType.Standalone) {
943
- const track_namespace = r.readTuple()
944
- const track_name = r.readString()
945
- const start_group = r.readVarInt()
946
- const start_object = r.readVarInt()
947
- const end_group = r.readVarInt()
948
- const end_object = r.readVarInt()
939
+ const standalone = {
940
+ track_namespace: r.readTuple(),
941
+ track_name: r.readString(),
942
+ start_group: r.readVarInt(),
943
+ start_object: r.readVarInt(),
944
+ end_group: r.readVarInt(),
945
+ end_object: r.readVarInt(),
946
+ }
949
947
  const parameters = decodeMessageParams(r)
950
948
  return {
951
949
  type: 'fetch',
@@ -953,17 +951,14 @@ function decodeFetchPayload(r: BufferReader): Draft14Message {
953
951
  subscriber_priority,
954
952
  group_order,
955
953
  fetch_type,
956
- track_namespace,
957
- track_name,
958
- start_group,
959
- start_object,
960
- end_group,
961
- end_object,
954
+ standalone,
962
955
  parameters,
963
956
  }
964
957
  } else {
965
- const joining_request_id = r.readVarInt()
966
- const joining_start = r.readVarInt()
958
+ const joining = {
959
+ joining_request_id: r.readVarInt(),
960
+ joining_start: r.readVarInt(),
961
+ }
967
962
  const parameters = decodeMessageParams(r)
968
963
  return {
969
964
  type: 'fetch',
@@ -971,8 +966,7 @@ function decodeFetchPayload(r: BufferReader): Draft14Message {
971
966
  subscriber_priority,
972
967
  group_order,
973
968
  fetch_type,
974
- joining_request_id,
975
- joining_start,
969
+ joining,
976
970
  parameters,
977
971
  }
978
972
  }
@@ -980,7 +974,7 @@ function decodeFetchPayload(r: BufferReader): Draft14Message {
980
974
 
981
975
  function decodeFetchOkPayload(r: BufferReader): Draft14Message {
982
976
  const request_id = r.readVarInt()
983
- const group_order = BigInt(r.readUint8())
977
+ const group_order = r.readUint8()
984
978
  const end_of_track = r.readVarInt()
985
979
  const end_location: Location = {
986
980
  group: r.readVarInt(),
@@ -1013,8 +1007,8 @@ function decodeTrackStatusPayload(r: BufferReader): Draft14Message {
1013
1007
  const request_id = r.readVarInt()
1014
1008
  const track_namespace = r.readTuple()
1015
1009
  const track_name = r.readString()
1016
- const subscriber_priority = BigInt(r.readUint8())
1017
- const group_order = BigInt(r.readUint8())
1010
+ const subscriber_priority = r.readUint8()
1011
+ const group_order = r.readUint8()
1018
1012
  const forward = r.readVarInt()
1019
1013
  const filter_type = r.readVarInt()
1020
1014
 
@@ -1048,7 +1042,7 @@ function decodeTrackStatusOkPayload(r: BufferReader): Draft14Message {
1048
1042
  const request_id = r.readVarInt()
1049
1043
  const track_alias = r.readVarInt()
1050
1044
  const expires = r.readVarInt()
1051
- const group_order = BigInt(r.readUint8())
1045
+ const group_order = r.readUint8()
1052
1046
  const content_exists = r.readVarInt()
1053
1047
 
1054
1048
  let largest_location: Location | undefined
@@ -115,8 +115,8 @@ export interface Draft14Subscribe extends Draft14BaseMessage {
115
115
  readonly request_id: bigint
116
116
  readonly track_namespace: string[]
117
117
  readonly track_name: string
118
- readonly subscriber_priority: bigint
119
- readonly group_order: bigint
118
+ readonly subscriber_priority: number // uint8
119
+ readonly group_order: number // uint8
120
120
  readonly forward: bigint
121
121
  readonly filter_type: bigint
122
122
  readonly start_group?: bigint
@@ -130,7 +130,7 @@ export interface Draft14SubscribeOk extends Draft14BaseMessage {
130
130
  readonly request_id: bigint
131
131
  readonly track_alias: bigint
132
132
  readonly expires: bigint
133
- readonly group_order: bigint
133
+ readonly group_order: number // uint8
134
134
  readonly content_exists: bigint
135
135
  readonly largest_location?: Location
136
136
  readonly parameters: Draft14Params
@@ -143,7 +143,7 @@ export interface Draft14SubscribeUpdate extends Draft14BaseMessage {
143
143
  readonly start_group: bigint
144
144
  readonly start_object: bigint
145
145
  readonly end_group: bigint
146
- readonly subscriber_priority: bigint
146
+ readonly subscriber_priority: number // uint8
147
147
  readonly forward: bigint
148
148
  readonly parameters: Draft14Params
149
149
  }
@@ -167,7 +167,7 @@ export interface Draft14Publish extends Draft14BaseMessage {
167
167
  readonly track_namespace: string[]
168
168
  readonly track_name: string
169
169
  readonly track_alias: bigint
170
- readonly group_order: bigint
170
+ readonly group_order: number // uint8
171
171
  readonly content_exists: bigint
172
172
  readonly largest_location?: Location
173
173
  readonly forward: bigint
@@ -178,8 +178,8 @@ export interface Draft14PublishOk extends Draft14BaseMessage {
178
178
  readonly type: 'publish_ok'
179
179
  readonly request_id: bigint
180
180
  readonly forward: bigint
181
- readonly subscriber_priority: bigint
182
- readonly group_order: bigint
181
+ readonly subscriber_priority: number // uint8
182
+ readonly group_order: number // uint8
183
183
  readonly filter_type: bigint
184
184
  readonly start_group?: bigint
185
185
  readonly start_object?: bigint
@@ -213,7 +213,6 @@ export interface Draft14PublishNamespace extends Draft14BaseMessage {
213
213
  export interface Draft14PublishNamespaceOk extends Draft14BaseMessage {
214
214
  readonly type: 'publish_namespace_ok'
215
215
  readonly request_id: bigint
216
- readonly parameters: Draft14Params
217
216
  }
218
217
 
219
218
  export interface Draft14PublishNamespaceError extends Draft14BaseMessage {
@@ -245,7 +244,6 @@ export interface Draft14SubscribeNamespace extends Draft14BaseMessage {
245
244
  export interface Draft14SubscribeNamespaceOk extends Draft14BaseMessage {
246
245
  readonly type: 'subscribe_namespace_ok'
247
246
  readonly request_id: bigint
248
- readonly parameters: Draft14Params
249
247
  }
250
248
 
251
249
  export interface Draft14SubscribeNamespaceError extends Draft14BaseMessage {
@@ -261,29 +259,37 @@ export interface Draft14UnsubscribeNamespace extends Draft14BaseMessage {
261
259
  }
262
260
 
263
261
  // Fetch
262
+ export interface StandaloneFetch {
263
+ readonly track_namespace: string[]
264
+ readonly track_name: string
265
+ readonly start_group: bigint
266
+ readonly start_object: bigint
267
+ readonly end_group: bigint
268
+ readonly end_object: bigint
269
+ }
270
+
271
+ export interface JoiningFetch {
272
+ readonly joining_request_id: bigint
273
+ readonly joining_start: bigint
274
+ }
275
+
264
276
  export interface Draft14Fetch extends Draft14BaseMessage {
265
277
  readonly type: 'fetch'
266
278
  readonly request_id: bigint
267
- readonly subscriber_priority: bigint
268
- readonly group_order: bigint
279
+ readonly subscriber_priority: number // uint8
280
+ readonly group_order: number // uint8
269
281
  readonly fetch_type: bigint
270
- // Standalone fields (fetch_type=1)
271
- readonly track_namespace?: string[]
272
- readonly track_name?: string
273
- readonly start_group?: bigint
274
- readonly start_object?: bigint
275
- readonly end_group?: bigint
276
- readonly end_object?: bigint
277
- // Joining fields (fetch_type=2 or 3)
278
- readonly joining_request_id?: bigint
279
- readonly joining_start?: bigint
282
+ /** Present when fetch_type = 1 */
283
+ readonly standalone?: StandaloneFetch
284
+ /** Present when fetch_type = 2 or 3 */
285
+ readonly joining?: JoiningFetch
280
286
  readonly parameters: Draft14Params
281
287
  }
282
288
 
283
289
  export interface Draft14FetchOk extends Draft14BaseMessage {
284
290
  readonly type: 'fetch_ok'
285
291
  readonly request_id: bigint
286
- readonly group_order: bigint
292
+ readonly group_order: number // uint8
287
293
  readonly end_of_track: bigint
288
294
  readonly end_location: Location
289
295
  readonly parameters: Draft14Params
@@ -307,8 +313,8 @@ export interface Draft14TrackStatus extends Draft14BaseMessage {
307
313
  readonly request_id: bigint
308
314
  readonly track_namespace: string[]
309
315
  readonly track_name: string
310
- readonly subscriber_priority: bigint
311
- readonly group_order: bigint
316
+ readonly subscriber_priority: number // uint8
317
+ readonly group_order: number // uint8
312
318
  readonly forward: bigint
313
319
  readonly filter_type: bigint
314
320
  readonly start_group?: bigint
@@ -321,7 +327,7 @@ export interface Draft14TrackStatusOk extends Draft14BaseMessage {
321
327
  readonly request_id: bigint
322
328
  readonly track_alias: bigint
323
329
  readonly expires: bigint
324
- readonly group_order: bigint
330
+ readonly group_order: number // uint8
325
331
  readonly content_exists: bigint
326
332
  readonly largest_location?: Location
327
333
  readonly parameters: Draft14Params
@@ -75,19 +75,23 @@ export function encodeDatagram(dg: DatagramObject): Uint8Array {
75
75
  w.writeVarInt(dg.trackAlias)
76
76
  w.writeVarInt(dg.groupId)
77
77
 
78
- // Datagram type flags:
78
+ // Datagram type flags, Table 5:
79
79
  // bit 0 (0x01): extensions present
80
80
  // bit 1 (0x02): end-of-group
81
81
  // bit 2 (0x04): object_id ABSENT when set
82
+ // bit 3 (0x08): publisher priority ABSENT when set
82
83
  // bit 5 (0x20): status (replaces payload)
83
84
  const extensionsPresent = (dgType & 0x01) !== 0
84
85
  const objectIdAbsent = (dgType & 0x04) !== 0
86
+ const defaultPriority = (dgType & 0x08) !== 0
85
87
  const isStatus = (dgType & 0x20) !== 0
86
88
 
87
89
  if (!objectIdAbsent) {
88
90
  w.writeVarInt(dg.objectId)
89
91
  }
90
- w.writeUint8(dg.publisherPriority)
92
+ if (!defaultPriority) {
93
+ w.writeUint8(dg.publisherPriority)
94
+ }
91
95
 
92
96
  if (extensionsPresent) {
93
97
  const extData = dg.extensionData ?? new Uint8Array(0)
@@ -141,29 +145,34 @@ export function decodeSubgroupStream(bytes: Uint8Array): DecodeResult<SubgroupSt
141
145
  const r = new BufferReader(bytes)
142
146
  const streamType = Number(r.readVarInt())
143
147
 
144
- // Draft-15 valid subgroup types: 0x10-0x17, 0x30-0x37
145
- // bit 0: extensions, bit 1: end-of-group, bit 2: explicit subgroup_id
148
+ // Draft-15 Table 6 assigns 0x10-0x15, 0x18-0x1D, 0x30-0x35 and 0x38-0x3D:
149
+ // the end-of-group marker at 0x08 doubles the range the previous drafts
150
+ // used. What the table leaves out is every Type whose two Subgroup ID mode
151
+ // bits are 0b11. Draft-16 names those reserved in prose; draft-15 only
152
+ // omits them, which comes to the same refusal by a different route.
146
153
  if (
147
- !((streamType >= 0x10 && streamType <= 0x17) || (streamType >= 0x30 && streamType <= 0x37))
154
+ !((streamType >= 0x10 && streamType <= 0x1f) || (streamType >= 0x30 && streamType <= 0x3f)) ||
155
+ (streamType & 0x06) === 0x06
148
156
  ) {
149
157
  return {
150
158
  ok: false,
151
159
  error: new DecodeError(
152
160
  'CONSTRAINT_VIOLATION',
153
- `Expected subgroup stream type 0x10-0x17/0x30-0x37, got 0x${streamType.toString(16)}`,
161
+ `Expected subgroup stream type 0x10-0x1F/0x30-0x3F, got 0x${streamType.toString(16)}`,
154
162
  0,
155
163
  ),
156
164
  }
157
165
  }
158
166
 
159
167
  // Decode type flags
160
- // Draft-15 bit layout:
161
- // bit 0: extensions present
162
- // bit 1: end-of-group
163
- // bit 2: explicit subgroup_id field present
168
+ // Draft-15 Table 6, over the 0x10 base:
169
+ // bit 0 (0x01): extensions present
170
+ // bit 1 (0x02): subgroup id is the first Object ID, not transmitted
171
+ // bit 2 (0x04): explicit subgroup_id field present
172
+ // bit 3 (0x08): contains end of group
164
173
  // bit 5 (0x20): no priority (>= 0x30)
165
174
  const extensionsPresent = (streamType & 0x01) !== 0
166
- const endOfGroup = (streamType & 0x02) !== 0
175
+ const endOfGroup = (streamType & 0x08) !== 0
167
176
  const hasSubgroupField = (streamType & 0x04) !== 0
168
177
  const hasPriority = streamType < 0x30
169
178
 
@@ -260,10 +269,12 @@ export function decodeDatagram(bytes: Uint8Array): DecodeResult<DatagramObject>
260
269
  // bit 0 (0x01): extensions present
261
270
  // bit 1 (0x02): end-of-group
262
271
  // bit 2 (0x04): object_id ABSENT when set
272
+ // bit 3 (0x08): publisher priority ABSENT when set
263
273
  // bit 5 (0x20): status (replaces payload with status varint)
264
274
  const extensionsPresent = (dgType & 0x01) !== 0
265
275
  const objectIdAbsent = (dgType & 0x04) !== 0
266
276
  const endOfGroup = (dgType & 0x02) !== 0
277
+ const defaultPriority = (dgType & 0x08) !== 0
267
278
  const isStatus = (dgType & 0x20) !== 0
268
279
 
269
280
  const trackAlias = r.readVarInt()
@@ -272,7 +283,10 @@ export function decodeDatagram(bytes: Uint8Array): DecodeResult<DatagramObject>
272
283
  if (!objectIdAbsent) {
273
284
  objectId = r.readVarInt()
274
285
  }
275
- const publisherPriority = r.readUint8()
286
+ let publisherPriority = 128 // default
287
+ if (!defaultPriority) {
288
+ publisherPriority = r.readUint8()
289
+ }
276
290
 
277
291
  let extensionData: Uint8Array | undefined
278
292
  if (extensionsPresent) {
@@ -531,8 +545,8 @@ export function createSubgroupStreamDecoder(): TransformStream<
531
545
 
532
546
  if (
533
547
  !(
534
- (streamType >= 0x10 && streamType <= 0x17) ||
535
- (streamType >= 0x30 && streamType <= 0x37)
548
+ (streamType >= 0x10 && streamType <= 0x1f) ||
549
+ (streamType >= 0x30 && streamType <= 0x3f)
536
550
  )
537
551
  ) {
538
552
  controller.error(
@@ -760,7 +774,7 @@ export function createDataStreamDecoder(): TransformStream<Uint8Array, DataStrea
760
774
  if (offset >= buffer.length) return
761
775
  const firstByte = buffer[offset]!
762
776
 
763
- if ((firstByte >= 0x10 && firstByte <= 0x17) || (firstByte >= 0x30 && firstByte <= 0x37)) {
777
+ if ((firstByte >= 0x10 && firstByte <= 0x1f) || (firstByte >= 0x30 && firstByte <= 0x3f)) {
764
778
  // Subgroup — delegate to subgroup decoder
765
779
  // We need to feed the full buffer including the type byte
766
780
  const decoder = createSubgroupStreamDecoder()
@@ -796,7 +810,7 @@ export function createDataStreamDecoder(): TransformStream<Uint8Array, DataStrea
796
810
  const firstByte = view[0]!
797
811
  let result: DecodeResult<Draft15DataStream>
798
812
 
799
- if ((firstByte >= 0x10 && firstByte <= 0x17) || (firstByte >= 0x30 && firstByte <= 0x37)) {
813
+ if ((firstByte >= 0x10 && firstByte <= 0x1f) || (firstByte >= 0x30 && firstByte <= 0x3f)) {
800
814
  result = decodeSubgroupStream(view)
801
815
  } else if (firstByte === 0x05) {
802
816
  result = decodeFetchStream(view)