@moqtap/codec 0.2.2 → 0.3.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 (716) hide show
  1. package/LICENSE +21 -21
  2. package/README.md +100 -99
  3. package/dist/{chunk-RZHAPEXO.js → chunk-2A57DRXV.js} +36 -10
  4. package/dist/{chunk-PJRA2TQ5.js → chunk-2UTVXWFF.js} +388 -254
  5. package/dist/{chunk-IV2H5CFI.cjs → chunk-3XKO6PCR.cjs} +461 -322
  6. package/dist/{chunk-RVJAGE4S.cjs → chunk-4BDEU3D4.cjs} +415 -304
  7. package/dist/{chunk-XUUCOLWU.cjs → chunk-4HBKHNU2.cjs} +374 -329
  8. package/dist/{chunk-4RIXXEII.js → chunk-4IVZZOY3.js} +451 -312
  9. package/dist/{chunk-ZSPO2GF2.cjs → chunk-5O764MBD.cjs} +1320 -842
  10. package/dist/chunk-7KBAWOBA.js +1212 -0
  11. package/dist/{chunk-JSQM2MG3.js → chunk-7QOPNSDF.js} +44 -12
  12. package/dist/{chunk-SYHW3FLI.cjs → chunk-7RE6KSIY.cjs} +28 -8
  13. package/dist/{chunk-YG5KJESI.js → chunk-AY6IAHUM.js} +28 -8
  14. package/dist/{chunk-EFM5T7OM.js → chunk-BLQDWOSG.js} +36 -10
  15. package/dist/{chunk-KFTCU2P6.js → chunk-C6KUWLQC.js} +0 -3
  16. package/dist/{chunk-UYXTY6ZQ.cjs → chunk-E65QKRSN.cjs} +20 -12
  17. package/dist/{chunk-BISI45MN.cjs → chunk-EAHE3IOG.cjs} +44 -12
  18. package/dist/{chunk-IV2HRJVT.js → chunk-GCBFHZW6.js} +405 -294
  19. package/dist/{chunk-GXEW4COZ.cjs → chunk-H5NSL4MO.cjs} +36 -10
  20. package/dist/chunk-HZHSO7EW.cjs +1212 -0
  21. package/dist/{chunk-BPNL5YFQ.cjs → chunk-IILNSDEQ.cjs} +74 -46
  22. package/dist/{chunk-4XYGE53S.cjs → chunk-J3XCPBW3.cjs} +36 -10
  23. package/dist/{chunk-6AEHWULA.cjs → chunk-JKOEJZ5B.cjs} +28 -8
  24. package/dist/{chunk-FWISIR26.cjs → chunk-JL3NEW3O.cjs} +47 -4
  25. package/dist/{chunk-G7GI7LJA.js → chunk-LORZMJJB.js} +36 -10
  26. package/dist/{chunk-DUBCL3WF.cjs → chunk-LV5C6MEC.cjs} +36 -10
  27. package/dist/{chunk-ENURAVHI.cjs → chunk-MYXAD5JC.cjs} +44 -12
  28. package/dist/{chunk-FXZ2MYKJ.js → chunk-MZ7HUCGJ.js} +20 -12
  29. package/dist/{chunk-RWQ43Z4F.cjs → chunk-MZ7VU52O.cjs} +0 -3
  30. package/dist/{chunk-G26SJ6XS.cjs → chunk-OKG2HT25.cjs} +1193 -928
  31. package/dist/{chunk-IBVM4DMJ.cjs → chunk-PKEOQSSZ.cjs} +374 -329
  32. package/dist/{chunk-LH4NTURO.js → chunk-Q46ZURKX.js} +989 -602
  33. package/dist/{chunk-UR6JKS56.js → chunk-Q7IGWV3P.js} +41 -9
  34. package/dist/{chunk-ST24APEO.js → chunk-RW4UG7CN.js} +751 -682
  35. package/dist/{chunk-DWK5ZQZ4.js → chunk-RZTLQAKF.js} +28 -8
  36. package/dist/{chunk-UNS34PTA.cjs → chunk-S6IPIN66.cjs} +44 -12
  37. package/dist/{chunk-K4OLITS2.cjs → chunk-SDWRXXOO.cjs} +401 -267
  38. package/dist/{chunk-CXDHOMHG.js → chunk-SHMA4PBY.js} +476 -431
  39. package/dist/{chunk-U2B3B42P.js → chunk-U3ZVLT5L.js} +1176 -540
  40. package/dist/{chunk-HSVYF6XX.cjs → chunk-UJU63EFY.cjs} +1524 -1137
  41. package/dist/{chunk-A27S7HW7.js → chunk-VOU7PNHI.js} +47 -4
  42. package/dist/{chunk-E6E3NQYU.js → chunk-WRHGCVYN.js} +44 -12
  43. package/dist/chunk-XNWYLVGU.cjs +1854 -0
  44. package/dist/{chunk-NUX5BHWO.js → chunk-XS77RBY7.js} +1160 -895
  45. package/dist/{chunk-4YJANAXU.cjs → chunk-XZE5R57R.cjs} +829 -760
  46. package/dist/{chunk-NGVE2RZT.js → chunk-Y6KCSM3V.js} +476 -431
  47. package/dist/{chunk-TLYNOOQP.cjs → chunk-YTPZZI2M.cjs} +41 -9
  48. package/dist/{chunk-7DUBLRXC.js → chunk-YWRCSQBA.js} +44 -12
  49. package/dist/{chunk-MFAP7R6L.js → chunk-Z3VKP3PJ.js} +70 -42
  50. package/dist/{chunk-ZBKE2QRQ.js → chunk-Z6U26IRI.js} +1107 -629
  51. package/dist/codec-25u4_1HS.d.ts +35 -0
  52. package/dist/codec-3Ppy_5Gd.d.ts +23 -0
  53. package/dist/codec-BB0U8MF2.d.cts +34 -0
  54. package/dist/codec-BHHfBTnV.d.ts +34 -0
  55. package/dist/codec-BN6jk0Td.d.cts +30 -0
  56. package/dist/codec-BU0gaSZm.d.ts +29 -0
  57. package/dist/codec-C-Yk2RNa.d.ts +30 -0
  58. package/dist/codec-CFWQY9Lj.d.cts +18 -0
  59. package/dist/codec-COy4uuPO.d.cts +29 -0
  60. package/dist/codec-CewFCsEy.d.ts +18 -0
  61. package/dist/codec-Ck7ZwFF1.d.cts +35 -0
  62. package/dist/codec-D2QVSH9D.d.ts +30 -0
  63. package/dist/codec-DDUBJGn0.d.cts +23 -0
  64. package/dist/codec-DNfml-se.d.ts +27 -0
  65. package/dist/codec-DoOGjjDq.d.cts +29 -0
  66. package/dist/codec-J7ekOSMc.d.ts +29 -0
  67. package/dist/codec-R9TJCq-E.d.cts +31 -0
  68. package/dist/codec-ZwV-Njt6.d.ts +23 -0
  69. package/dist/codec-j819z_hL.d.cts +23 -0
  70. package/dist/codec-w8z2j_uo.d.cts +27 -0
  71. package/dist/codec-wtt6WF1K.d.ts +31 -0
  72. package/dist/codec-z6_2PSzi.d.cts +30 -0
  73. package/dist/draft10-session.cjs +2 -2
  74. package/dist/draft10-session.d.cts +6 -6
  75. package/dist/draft10-session.d.ts +6 -6
  76. package/dist/draft10-session.js +1 -1
  77. package/dist/draft10.cjs +8 -4
  78. package/dist/draft10.d.cts +23 -11
  79. package/dist/draft10.d.ts +23 -11
  80. package/dist/draft10.js +16 -12
  81. package/dist/draft11-session.cjs +2 -2
  82. package/dist/draft11-session.d.cts +6 -6
  83. package/dist/draft11-session.d.ts +6 -6
  84. package/dist/draft11-session.js +1 -1
  85. package/dist/draft11.cjs +8 -4
  86. package/dist/draft11.d.cts +21 -11
  87. package/dist/draft11.d.ts +21 -11
  88. package/dist/draft11.js +16 -12
  89. package/dist/draft12-session.cjs +2 -2
  90. package/dist/draft12-session.d.cts +6 -6
  91. package/dist/draft12-session.d.ts +6 -6
  92. package/dist/draft12-session.js +1 -1
  93. package/dist/draft12.cjs +8 -4
  94. package/dist/draft12.d.cts +23 -13
  95. package/dist/draft12.d.ts +23 -13
  96. package/dist/draft12.js +16 -12
  97. package/dist/draft13-session.cjs +2 -2
  98. package/dist/draft13-session.d.cts +6 -6
  99. package/dist/draft13-session.d.ts +6 -6
  100. package/dist/draft13-session.js +1 -1
  101. package/dist/draft13.cjs +8 -4
  102. package/dist/draft13.d.cts +23 -13
  103. package/dist/draft13.d.ts +23 -13
  104. package/dist/draft13.js +16 -12
  105. package/dist/draft14-session.cjs +2 -2
  106. package/dist/draft14-session.d.cts +6 -6
  107. package/dist/draft14-session.d.ts +6 -6
  108. package/dist/draft14-session.js +1 -1
  109. package/dist/draft14.cjs +14 -4
  110. package/dist/draft14.d.cts +67 -11
  111. package/dist/draft14.d.ts +67 -11
  112. package/dist/draft14.js +13 -3
  113. package/dist/draft15-session.cjs +2 -2
  114. package/dist/draft15-session.d.cts +6 -6
  115. package/dist/draft15-session.d.ts +6 -6
  116. package/dist/draft15-session.js +1 -1
  117. package/dist/draft15.cjs +8 -4
  118. package/dist/draft15.d.cts +56 -11
  119. package/dist/draft15.d.ts +56 -11
  120. package/dist/draft15.js +16 -12
  121. package/dist/draft16-session.cjs +2 -2
  122. package/dist/draft16-session.d.cts +6 -6
  123. package/dist/draft16-session.d.ts +6 -6
  124. package/dist/draft16-session.js +1 -1
  125. package/dist/draft16.cjs +8 -4
  126. package/dist/draft16.d.cts +45 -11
  127. package/dist/draft16.d.ts +45 -11
  128. package/dist/draft16.js +16 -12
  129. package/dist/draft17-session.cjs +2 -2
  130. package/dist/draft17-session.d.cts +7 -7
  131. package/dist/draft17-session.d.ts +7 -7
  132. package/dist/draft17-session.js +1 -1
  133. package/dist/draft17.cjs +8 -4
  134. package/dist/draft17.d.cts +21 -8
  135. package/dist/draft17.d.ts +21 -8
  136. package/dist/draft17.js +16 -12
  137. package/dist/draft7-session.cjs +3 -3
  138. package/dist/draft7-session.d.cts +6 -5
  139. package/dist/draft7-session.d.ts +6 -5
  140. package/dist/draft7-session.js +2 -2
  141. package/dist/draft7.cjs +83 -14
  142. package/dist/draft7.d.cts +59 -64
  143. package/dist/draft7.d.ts +59 -64
  144. package/dist/draft7.js +89 -20
  145. package/dist/draft8-session.cjs +2 -2
  146. package/dist/draft8-session.d.cts +6 -6
  147. package/dist/draft8-session.d.ts +6 -6
  148. package/dist/draft8-session.js +1 -1
  149. package/dist/draft8.cjs +8 -4
  150. package/dist/draft8.d.cts +23 -11
  151. package/dist/draft8.d.ts +23 -11
  152. package/dist/draft8.js +7 -3
  153. package/dist/draft9-session.cjs +2 -2
  154. package/dist/draft9-session.d.cts +6 -6
  155. package/dist/draft9-session.d.ts +6 -6
  156. package/dist/draft9-session.js +1 -1
  157. package/dist/draft9.cjs +8 -4
  158. package/dist/draft9.d.cts +23 -11
  159. package/dist/draft9.d.ts +23 -11
  160. package/dist/draft9.js +7 -3
  161. package/dist/index.cjs +52 -73
  162. package/dist/index.d.cts +41 -60
  163. package/dist/index.d.ts +55 -82
  164. package/dist/index.js +89 -93
  165. package/dist/{session-types-CJIFbTPd.d.ts → session-types-C7UONex5.d.cts} +28 -27
  166. package/dist/{session-types-Cbq8IGCP.d.cts → session-types-X-IYEGoG.d.ts} +28 -27
  167. package/dist/session.cjs +47 -14
  168. package/dist/session.d.cts +28 -9
  169. package/dist/session.d.ts +32 -9
  170. package/dist/session.js +59 -32
  171. package/dist/{types-4VxSL2Ho.d.ts → types--Q7_DcvP.d.cts} +49 -39
  172. package/dist/{types-4VxSL2Ho.d.cts → types--Q7_DcvP.d.ts} +49 -39
  173. package/dist/{types-Cw4WE9dh.d.ts → types-0IWbU9Z_.d.cts} +44 -36
  174. package/dist/{types-Cw4WE9dh.d.cts → types-0IWbU9Z_.d.ts} +44 -36
  175. package/dist/{types-D5gNQiDj.d.ts → types-B3g5G9KP.d.cts} +44 -36
  176. package/dist/{types-D5gNQiDj.d.cts → types-B3g5G9KP.d.ts} +44 -36
  177. package/dist/{types-B2afJZM-.d.cts → types-BFpFNM_m.d.cts} +60 -32
  178. package/dist/{types-B2afJZM-.d.ts → types-BFpFNM_m.d.ts} +60 -32
  179. package/dist/{types-ERexTpT8.d.ts → types-Br7fm2mf.d.cts} +51 -26
  180. package/dist/{types-ERexTpT8.d.cts → types-Br7fm2mf.d.ts} +51 -26
  181. package/dist/{types-Bg6QYNVt.d.cts → types-C2qKTRR_.d.cts} +55 -45
  182. package/dist/{types-Bg6QYNVt.d.ts → types-C2qKTRR_.d.ts} +55 -45
  183. package/dist/{types-BTFeKYCb.d.ts → types-DEaypVsD.d.cts} +133 -58
  184. package/dist/{types-BTFeKYCb.d.cts → types-DEaypVsD.d.ts} +133 -58
  185. package/dist/types-Dl4IaAHR.d.cts +282 -0
  186. package/dist/types-Dl4IaAHR.d.ts +282 -0
  187. package/dist/{types-C_1HrqBl.d.cts → types-DrQpTW1G.d.cts} +63 -50
  188. package/dist/{types-C_1HrqBl.d.ts → types-DrQpTW1G.d.ts} +63 -50
  189. package/dist/types-DuIO7cWK.d.cts +25 -0
  190. package/dist/types-DuIO7cWK.d.ts +25 -0
  191. package/dist/{types-DqCDFqgB.d.ts → types-DuxfOYiO.d.cts} +50 -31
  192. package/dist/{types-DqCDFqgB.d.cts → types-DuxfOYiO.d.ts} +50 -31
  193. package/dist/{types-r-CasCf1.d.cts → types-jV1yDDBA.d.cts} +43 -36
  194. package/dist/{types-r-CasCf1.d.ts → types-jV1yDDBA.d.ts} +43 -36
  195. package/package.json +15 -15
  196. package/src/core/buffer-reader.ts +69 -53
  197. package/src/core/buffer-writer.ts +55 -46
  198. package/src/core/errors.ts +1 -1
  199. package/src/core/hex.ts +21 -17
  200. package/src/core/session-types.ts +61 -59
  201. package/src/core/types.ts +18 -361
  202. package/src/drafts/draft07/codec.ts +1058 -933
  203. package/src/drafts/draft07/data-streams.ts +116 -116
  204. package/src/drafts/draft07/index.ts +124 -89
  205. package/src/drafts/draft07/messages.ts +76 -42
  206. package/src/drafts/draft07/rules.ts +107 -101
  207. package/src/drafts/draft07/session-fsm.ts +315 -287
  208. package/src/drafts/draft07/session.ts +8 -6
  209. package/src/drafts/draft07/types.ts +406 -72
  210. package/src/drafts/draft07/varint.ts +40 -12
  211. package/src/drafts/draft08/codec.ts +985 -944
  212. package/src/drafts/draft08/data-streams.ts +178 -174
  213. package/src/drafts/draft08/index.ts +10 -9
  214. package/src/drafts/draft08/messages.ts +59 -59
  215. package/src/drafts/draft08/rules.ts +73 -73
  216. package/src/drafts/draft08/session-fsm.ts +335 -303
  217. package/src/drafts/draft08/session.ts +6 -7
  218. package/src/drafts/draft08/types.ts +380 -384
  219. package/src/drafts/draft09/codec.ts +977 -936
  220. package/src/drafts/draft09/data-streams.ts +163 -159
  221. package/src/drafts/draft09/index.ts +10 -9
  222. package/src/drafts/draft09/messages.ts +59 -59
  223. package/src/drafts/draft09/rules.ts +73 -73
  224. package/src/drafts/draft09/session-fsm.ts +335 -303
  225. package/src/drafts/draft09/session.ts +6 -7
  226. package/src/drafts/draft09/types.ts +380 -384
  227. package/src/drafts/draft10/codec.ts +977 -936
  228. package/src/drafts/draft10/data-streams.ts +163 -159
  229. package/src/drafts/draft10/index.ts +10 -9
  230. package/src/drafts/draft10/messages.ts +59 -59
  231. package/src/drafts/draft10/rules.ts +73 -73
  232. package/src/drafts/draft10/session-fsm.ts +335 -303
  233. package/src/drafts/draft10/session.ts +6 -7
  234. package/src/drafts/draft10/types.ts +380 -384
  235. package/src/drafts/draft11/codec.ts +1054 -979
  236. package/src/drafts/draft11/data-streams.ts +189 -142
  237. package/src/drafts/draft11/index.ts +10 -9
  238. package/src/drafts/draft11/messages.ts +60 -59
  239. package/src/drafts/draft11/rules.ts +73 -73
  240. package/src/drafts/draft11/session-fsm.ts +359 -333
  241. package/src/drafts/draft11/session.ts +6 -7
  242. package/src/drafts/draft11/types.ts +385 -381
  243. package/src/drafts/draft12/codec.ts +1178 -1113
  244. package/src/drafts/draft12/data-streams.ts +192 -143
  245. package/src/drafts/draft12/index.ts +10 -9
  246. package/src/drafts/draft12/messages.ts +67 -66
  247. package/src/drafts/draft12/rules.ts +79 -79
  248. package/src/drafts/draft12/session-fsm.ts +384 -358
  249. package/src/drafts/draft12/session.ts +6 -7
  250. package/src/drafts/draft12/types.ts +424 -419
  251. package/src/drafts/draft13/codec.ts +1296 -1197
  252. package/src/drafts/draft13/data-streams.ts +194 -143
  253. package/src/drafts/draft13/index.ts +10 -9
  254. package/src/drafts/draft13/messages.ts +73 -68
  255. package/src/drafts/draft13/rules.ts +81 -81
  256. package/src/drafts/draft13/session-fsm.ts +392 -366
  257. package/src/drafts/draft13/session.ts +6 -7
  258. package/src/drafts/draft13/types.ts +447 -438
  259. package/src/drafts/draft14/codec.ts +1347 -1034
  260. package/src/drafts/draft14/data-streams.ts +429 -396
  261. package/src/drafts/draft14/index.ts +17 -9
  262. package/src/drafts/draft14/messages.ts +65 -65
  263. package/src/drafts/draft14/rules.ts +81 -81
  264. package/src/drafts/draft14/session-fsm.ts +415 -405
  265. package/src/drafts/draft14/session.ts +6 -7
  266. package/src/drafts/draft14/types.ts +451 -381
  267. package/src/drafts/draft15/codec.ts +1138 -969
  268. package/src/drafts/draft15/data-streams.ts +428 -364
  269. package/src/drafts/draft15/index.ts +10 -9
  270. package/src/drafts/draft15/messages.ts +54 -53
  271. package/src/drafts/draft15/rules.ts +67 -67
  272. package/src/drafts/draft15/session-fsm.ts +319 -299
  273. package/src/drafts/draft15/session.ts +6 -7
  274. package/src/drafts/draft15/types.ts +357 -339
  275. package/src/drafts/draft16/codec.ts +1242 -957
  276. package/src/drafts/draft16/data-streams.ts +433 -371
  277. package/src/drafts/draft16/index.ts +10 -9
  278. package/src/drafts/draft16/messages.ts +56 -55
  279. package/src/drafts/draft16/rules.ts +69 -69
  280. package/src/drafts/draft16/session-fsm.ts +319 -299
  281. package/src/drafts/draft16/session.ts +6 -7
  282. package/src/drafts/draft16/types.ts +386 -357
  283. package/src/drafts/draft17/codec.ts +1209 -962
  284. package/src/drafts/draft17/data-streams.ts +593 -366
  285. package/src/drafts/draft17/index.ts +9 -7
  286. package/src/drafts/draft17/messages.ts +43 -42
  287. package/src/drafts/draft17/rules.ts +58 -58
  288. package/src/drafts/draft17/session-fsm.ts +248 -216
  289. package/src/drafts/draft17/session.ts +5 -5
  290. package/src/drafts/draft17/types.ts +337 -313
  291. package/src/index.ts +85 -274
  292. package/src/session.ts +62 -23
  293. package/dist/chunk-7IVGHMKJ.cjs +0 -866
  294. package/dist/chunk-FUFTMAQD.cjs +0 -1218
  295. package/dist/chunk-TMNGRIPL.js +0 -866
  296. package/dist/codec-95k8CAu5.d.cts +0 -35
  297. package/dist/codec-AFuOxfsO.d.ts +0 -60
  298. package/dist/codec-B-UJ5Iow.d.cts +0 -75
  299. package/dist/codec-BC5jfvMb.d.ts +0 -35
  300. package/dist/codec-BECYPfY8.d.ts +0 -35
  301. package/dist/codec-BsPU1vNC.d.ts +0 -39
  302. package/dist/codec-BvpuF-6u.d.cts +0 -39
  303. package/dist/codec-C8jZI5Cx.d.cts +0 -39
  304. package/dist/codec-CAevkgf5.d.cts +0 -33
  305. package/dist/codec-CSUqCrRs.d.ts +0 -39
  306. package/dist/codec-C_HMXNK_.d.ts +0 -33
  307. package/dist/codec-CpuvYTSV.d.cts +0 -86
  308. package/dist/codec-D0x8-SCw.d.cts +0 -35
  309. package/dist/codec-D7ARhpG1.d.ts +0 -75
  310. package/dist/codec-DNAUGshO.d.cts +0 -60
  311. package/dist/codec-DPx_QNn0.d.ts +0 -31
  312. package/dist/codec-DRhCx_hw.d.ts +0 -86
  313. package/dist/codec-Db7YPe3l.d.ts +0 -31
  314. package/dist/codec-axkJpb7D.d.cts +0 -31
  315. package/dist/codec-ujAbFaep.d.cts +0 -31
  316. package/dist/core/buffer-reader.d.ts +0 -15
  317. package/dist/core/buffer-reader.d.ts.map +0 -1
  318. package/dist/core/buffer-reader.js +0 -98
  319. package/dist/core/buffer-reader.js.map +0 -1
  320. package/dist/core/buffer-writer.d.ts +0 -16
  321. package/dist/core/buffer-writer.d.ts.map +0 -1
  322. package/dist/core/buffer-writer.js +0 -86
  323. package/dist/core/buffer-writer.js.map +0 -1
  324. package/dist/core/errors.d.ts +0 -2
  325. package/dist/core/errors.d.ts.map +0 -1
  326. package/dist/core/errors.js +0 -2
  327. package/dist/core/errors.js.map +0 -1
  328. package/dist/core/hex.d.ts +0 -5
  329. package/dist/core/hex.d.ts.map +0 -1
  330. package/dist/core/hex.js +0 -17
  331. package/dist/core/hex.js.map +0 -1
  332. package/dist/core/session-types.d.ts +0 -99
  333. package/dist/core/session-types.d.ts.map +0 -1
  334. package/dist/core/session-types.js +0 -2
  335. package/dist/core/session-types.js.map +0 -1
  336. package/dist/core/types.d.ts +0 -235
  337. package/dist/core/types.d.ts.map +0 -1
  338. package/dist/core/types.js +0 -11
  339. package/dist/core/types.js.map +0 -1
  340. package/dist/drafts/draft07/announce-fsm.d.ts +0 -2
  341. package/dist/drafts/draft07/announce-fsm.d.ts.map +0 -1
  342. package/dist/drafts/draft07/announce-fsm.js +0 -2
  343. package/dist/drafts/draft07/announce-fsm.js.map +0 -1
  344. package/dist/drafts/draft07/codec.d.ts +0 -17
  345. package/dist/drafts/draft07/codec.d.ts.map +0 -1
  346. package/dist/drafts/draft07/codec.js +0 -722
  347. package/dist/drafts/draft07/codec.js.map +0 -1
  348. package/dist/drafts/draft07/data-streams.d.ts +0 -9
  349. package/dist/drafts/draft07/data-streams.d.ts.map +0 -1
  350. package/dist/drafts/draft07/data-streams.js +0 -228
  351. package/dist/drafts/draft07/data-streams.js.map +0 -1
  352. package/dist/drafts/draft07/index.d.ts +0 -14
  353. package/dist/drafts/draft07/index.d.ts.map +0 -1
  354. package/dist/drafts/draft07/index.js +0 -18
  355. package/dist/drafts/draft07/index.js.map +0 -1
  356. package/dist/drafts/draft07/messages.d.ts +0 -32
  357. package/dist/drafts/draft07/messages.d.ts.map +0 -1
  358. package/dist/drafts/draft07/messages.js +0 -42
  359. package/dist/drafts/draft07/messages.js.map +0 -1
  360. package/dist/drafts/draft07/parameters.d.ts +0 -4
  361. package/dist/drafts/draft07/parameters.d.ts.map +0 -1
  362. package/dist/drafts/draft07/parameters.js +0 -10
  363. package/dist/drafts/draft07/parameters.js.map +0 -1
  364. package/dist/drafts/draft07/rules.d.ts +0 -8
  365. package/dist/drafts/draft07/rules.d.ts.map +0 -1
  366. package/dist/drafts/draft07/rules.js +0 -95
  367. package/dist/drafts/draft07/rules.js.map +0 -1
  368. package/dist/drafts/draft07/session-fsm.d.ts +0 -38
  369. package/dist/drafts/draft07/session-fsm.d.ts.map +0 -1
  370. package/dist/drafts/draft07/session-fsm.js +0 -354
  371. package/dist/drafts/draft07/session-fsm.js.map +0 -1
  372. package/dist/drafts/draft07/session.d.ts +0 -4
  373. package/dist/drafts/draft07/session.d.ts.map +0 -1
  374. package/dist/drafts/draft07/session.js +0 -5
  375. package/dist/drafts/draft07/session.js.map +0 -1
  376. package/dist/drafts/draft07/subscription-fsm.d.ts +0 -2
  377. package/dist/drafts/draft07/subscription-fsm.d.ts.map +0 -1
  378. package/dist/drafts/draft07/subscription-fsm.js +0 -2
  379. package/dist/drafts/draft07/subscription-fsm.js.map +0 -1
  380. package/dist/drafts/draft07/types.d.ts +0 -61
  381. package/dist/drafts/draft07/types.d.ts.map +0 -1
  382. package/dist/drafts/draft07/types.js +0 -4
  383. package/dist/drafts/draft07/types.js.map +0 -1
  384. package/dist/drafts/draft07/varint.d.ts +0 -4
  385. package/dist/drafts/draft07/varint.d.ts.map +0 -1
  386. package/dist/drafts/draft07/varint.js +0 -22
  387. package/dist/drafts/draft07/varint.js.map +0 -1
  388. package/dist/drafts/draft08/codec.d.ts +0 -29
  389. package/dist/drafts/draft08/codec.d.ts.map +0 -1
  390. package/dist/drafts/draft08/codec.js +0 -729
  391. package/dist/drafts/draft08/codec.js.map +0 -1
  392. package/dist/drafts/draft08/data-streams.d.ts +0 -12
  393. package/dist/drafts/draft08/data-streams.d.ts.map +0 -1
  394. package/dist/drafts/draft08/data-streams.js +0 -345
  395. package/dist/drafts/draft08/data-streams.js.map +0 -1
  396. package/dist/drafts/draft08/index.d.ts +0 -9
  397. package/dist/drafts/draft08/index.d.ts.map +0 -1
  398. package/dist/drafts/draft08/index.js +0 -7
  399. package/dist/drafts/draft08/index.js.map +0 -1
  400. package/dist/drafts/draft08/messages.d.ts +0 -34
  401. package/dist/drafts/draft08/messages.d.ts.map +0 -1
  402. package/dist/drafts/draft08/messages.js +0 -66
  403. package/dist/drafts/draft08/messages.js.map +0 -1
  404. package/dist/drafts/draft08/rules.d.ts +0 -8
  405. package/dist/drafts/draft08/rules.d.ts.map +0 -1
  406. package/dist/drafts/draft08/rules.js +0 -83
  407. package/dist/drafts/draft08/rules.js.map +0 -1
  408. package/dist/drafts/draft08/session-fsm.d.ts +0 -47
  409. package/dist/drafts/draft08/session-fsm.d.ts.map +0 -1
  410. package/dist/drafts/draft08/session-fsm.js +0 -483
  411. package/dist/drafts/draft08/session-fsm.js.map +0 -1
  412. package/dist/drafts/draft08/session.d.ts +0 -5
  413. package/dist/drafts/draft08/session.d.ts.map +0 -1
  414. package/dist/drafts/draft08/session.js +0 -5
  415. package/dist/drafts/draft08/session.js.map +0 -1
  416. package/dist/drafts/draft08/types.d.ts +0 -268
  417. package/dist/drafts/draft08/types.d.ts.map +0 -1
  418. package/dist/drafts/draft08/types.js +0 -4
  419. package/dist/drafts/draft08/types.js.map +0 -1
  420. package/dist/drafts/draft09/codec.d.ts +0 -21
  421. package/dist/drafts/draft09/codec.d.ts.map +0 -1
  422. package/dist/drafts/draft09/codec.js +0 -721
  423. package/dist/drafts/draft09/codec.js.map +0 -1
  424. package/dist/drafts/draft09/data-streams.d.ts +0 -12
  425. package/dist/drafts/draft09/data-streams.d.ts.map +0 -1
  426. package/dist/drafts/draft09/data-streams.js +0 -307
  427. package/dist/drafts/draft09/data-streams.js.map +0 -1
  428. package/dist/drafts/draft09/index.d.ts +0 -9
  429. package/dist/drafts/draft09/index.d.ts.map +0 -1
  430. package/dist/drafts/draft09/index.js +0 -7
  431. package/dist/drafts/draft09/index.js.map +0 -1
  432. package/dist/drafts/draft09/messages.d.ts +0 -34
  433. package/dist/drafts/draft09/messages.d.ts.map +0 -1
  434. package/dist/drafts/draft09/messages.js +0 -66
  435. package/dist/drafts/draft09/messages.js.map +0 -1
  436. package/dist/drafts/draft09/rules.d.ts +0 -8
  437. package/dist/drafts/draft09/rules.d.ts.map +0 -1
  438. package/dist/drafts/draft09/rules.js +0 -83
  439. package/dist/drafts/draft09/rules.js.map +0 -1
  440. package/dist/drafts/draft09/session-fsm.d.ts +0 -47
  441. package/dist/drafts/draft09/session-fsm.d.ts.map +0 -1
  442. package/dist/drafts/draft09/session-fsm.js +0 -483
  443. package/dist/drafts/draft09/session-fsm.js.map +0 -1
  444. package/dist/drafts/draft09/session.d.ts +0 -5
  445. package/dist/drafts/draft09/session.d.ts.map +0 -1
  446. package/dist/drafts/draft09/session.js +0 -5
  447. package/dist/drafts/draft09/session.js.map +0 -1
  448. package/dist/drafts/draft09/types.d.ts +0 -268
  449. package/dist/drafts/draft09/types.d.ts.map +0 -1
  450. package/dist/drafts/draft09/types.js +0 -4
  451. package/dist/drafts/draft09/types.js.map +0 -1
  452. package/dist/drafts/draft10/codec.d.ts +0 -21
  453. package/dist/drafts/draft10/codec.d.ts.map +0 -1
  454. package/dist/drafts/draft10/codec.js +0 -721
  455. package/dist/drafts/draft10/codec.js.map +0 -1
  456. package/dist/drafts/draft10/data-streams.d.ts +0 -12
  457. package/dist/drafts/draft10/data-streams.d.ts.map +0 -1
  458. package/dist/drafts/draft10/data-streams.js +0 -307
  459. package/dist/drafts/draft10/data-streams.js.map +0 -1
  460. package/dist/drafts/draft10/index.d.ts +0 -9
  461. package/dist/drafts/draft10/index.d.ts.map +0 -1
  462. package/dist/drafts/draft10/index.js +0 -7
  463. package/dist/drafts/draft10/index.js.map +0 -1
  464. package/dist/drafts/draft10/messages.d.ts +0 -34
  465. package/dist/drafts/draft10/messages.d.ts.map +0 -1
  466. package/dist/drafts/draft10/messages.js +0 -66
  467. package/dist/drafts/draft10/messages.js.map +0 -1
  468. package/dist/drafts/draft10/rules.d.ts +0 -8
  469. package/dist/drafts/draft10/rules.d.ts.map +0 -1
  470. package/dist/drafts/draft10/rules.js +0 -83
  471. package/dist/drafts/draft10/rules.js.map +0 -1
  472. package/dist/drafts/draft10/session-fsm.d.ts +0 -47
  473. package/dist/drafts/draft10/session-fsm.d.ts.map +0 -1
  474. package/dist/drafts/draft10/session-fsm.js +0 -483
  475. package/dist/drafts/draft10/session-fsm.js.map +0 -1
  476. package/dist/drafts/draft10/session.d.ts +0 -5
  477. package/dist/drafts/draft10/session.d.ts.map +0 -1
  478. package/dist/drafts/draft10/session.js +0 -5
  479. package/dist/drafts/draft10/session.js.map +0 -1
  480. package/dist/drafts/draft10/types.d.ts +0 -268
  481. package/dist/drafts/draft10/types.d.ts.map +0 -1
  482. package/dist/drafts/draft10/types.js +0 -4
  483. package/dist/drafts/draft10/types.js.map +0 -1
  484. package/dist/drafts/draft11/codec.d.ts +0 -25
  485. package/dist/drafts/draft11/codec.d.ts.map +0 -1
  486. package/dist/drafts/draft11/codec.js +0 -775
  487. package/dist/drafts/draft11/codec.js.map +0 -1
  488. package/dist/drafts/draft11/data-streams.d.ts +0 -10
  489. package/dist/drafts/draft11/data-streams.d.ts.map +0 -1
  490. package/dist/drafts/draft11/data-streams.js +0 -253
  491. package/dist/drafts/draft11/data-streams.js.map +0 -1
  492. package/dist/drafts/draft11/index.d.ts +0 -9
  493. package/dist/drafts/draft11/index.d.ts.map +0 -1
  494. package/dist/drafts/draft11/index.js +0 -7
  495. package/dist/drafts/draft11/index.js.map +0 -1
  496. package/dist/drafts/draft11/messages.d.ts +0 -33
  497. package/dist/drafts/draft11/messages.d.ts.map +0 -1
  498. package/dist/drafts/draft11/messages.js +0 -65
  499. package/dist/drafts/draft11/messages.js.map +0 -1
  500. package/dist/drafts/draft11/rules.d.ts +0 -8
  501. package/dist/drafts/draft11/rules.d.ts.map +0 -1
  502. package/dist/drafts/draft11/rules.js +0 -88
  503. package/dist/drafts/draft11/rules.js.map +0 -1
  504. package/dist/drafts/draft11/session-fsm.d.ts +0 -52
  505. package/dist/drafts/draft11/session-fsm.d.ts.map +0 -1
  506. package/dist/drafts/draft11/session-fsm.js +0 -530
  507. package/dist/drafts/draft11/session-fsm.js.map +0 -1
  508. package/dist/drafts/draft11/session.d.ts +0 -5
  509. package/dist/drafts/draft11/session.d.ts.map +0 -1
  510. package/dist/drafts/draft11/session.js +0 -5
  511. package/dist/drafts/draft11/session.js.map +0 -1
  512. package/dist/drafts/draft11/types.d.ts +0 -266
  513. package/dist/drafts/draft11/types.d.ts.map +0 -1
  514. package/dist/drafts/draft11/types.js +0 -4
  515. package/dist/drafts/draft11/types.js.map +0 -1
  516. package/dist/drafts/draft12/codec.d.ts +0 -27
  517. package/dist/drafts/draft12/codec.d.ts.map +0 -1
  518. package/dist/drafts/draft12/codec.js +0 -918
  519. package/dist/drafts/draft12/codec.js.map +0 -1
  520. package/dist/drafts/draft12/data-streams.d.ts +0 -10
  521. package/dist/drafts/draft12/data-streams.d.ts.map +0 -1
  522. package/dist/drafts/draft12/data-streams.js +0 -254
  523. package/dist/drafts/draft12/data-streams.js.map +0 -1
  524. package/dist/drafts/draft12/index.d.ts +0 -9
  525. package/dist/drafts/draft12/index.d.ts.map +0 -1
  526. package/dist/drafts/draft12/index.js +0 -7
  527. package/dist/drafts/draft12/index.js.map +0 -1
  528. package/dist/drafts/draft12/messages.d.ts +0 -37
  529. package/dist/drafts/draft12/messages.d.ts.map +0 -1
  530. package/dist/drafts/draft12/messages.js +0 -77
  531. package/dist/drafts/draft12/messages.js.map +0 -1
  532. package/dist/drafts/draft12/rules.d.ts +0 -8
  533. package/dist/drafts/draft12/rules.d.ts.map +0 -1
  534. package/dist/drafts/draft12/rules.js +0 -94
  535. package/dist/drafts/draft12/rules.js.map +0 -1
  536. package/dist/drafts/draft12/session-fsm.d.ts +0 -55
  537. package/dist/drafts/draft12/session-fsm.d.ts.map +0 -1
  538. package/dist/drafts/draft12/session-fsm.js +0 -569
  539. package/dist/drafts/draft12/session-fsm.js.map +0 -1
  540. package/dist/drafts/draft12/session.d.ts +0 -5
  541. package/dist/drafts/draft12/session.d.ts.map +0 -1
  542. package/dist/drafts/draft12/session.js +0 -5
  543. package/dist/drafts/draft12/session.js.map +0 -1
  544. package/dist/drafts/draft12/types.d.ts +0 -294
  545. package/dist/drafts/draft12/types.d.ts.map +0 -1
  546. package/dist/drafts/draft12/types.js +0 -4
  547. package/dist/drafts/draft12/types.js.map +0 -1
  548. package/dist/drafts/draft13/codec.d.ts +0 -27
  549. package/dist/drafts/draft13/codec.d.ts.map +0 -1
  550. package/dist/drafts/draft13/codec.js +0 -1000
  551. package/dist/drafts/draft13/codec.js.map +0 -1
  552. package/dist/drafts/draft13/data-streams.d.ts +0 -10
  553. package/dist/drafts/draft13/data-streams.d.ts.map +0 -1
  554. package/dist/drafts/draft13/data-streams.js +0 -254
  555. package/dist/drafts/draft13/data-streams.js.map +0 -1
  556. package/dist/drafts/draft13/index.d.ts +0 -9
  557. package/dist/drafts/draft13/index.d.ts.map +0 -1
  558. package/dist/drafts/draft13/index.js +0 -7
  559. package/dist/drafts/draft13/index.js.map +0 -1
  560. package/dist/drafts/draft13/messages.d.ts +0 -38
  561. package/dist/drafts/draft13/messages.d.ts.map +0 -1
  562. package/dist/drafts/draft13/messages.js +0 -79
  563. package/dist/drafts/draft13/messages.js.map +0 -1
  564. package/dist/drafts/draft13/rules.d.ts +0 -8
  565. package/dist/drafts/draft13/rules.d.ts.map +0 -1
  566. package/dist/drafts/draft13/rules.js +0 -96
  567. package/dist/drafts/draft13/rules.js.map +0 -1
  568. package/dist/drafts/draft13/session-fsm.d.ts +0 -56
  569. package/dist/drafts/draft13/session-fsm.d.ts.map +0 -1
  570. package/dist/drafts/draft13/session-fsm.js +0 -581
  571. package/dist/drafts/draft13/session-fsm.js.map +0 -1
  572. package/dist/drafts/draft13/session.d.ts +0 -5
  573. package/dist/drafts/draft13/session.d.ts.map +0 -1
  574. package/dist/drafts/draft13/session.js +0 -5
  575. package/dist/drafts/draft13/session.js.map +0 -1
  576. package/dist/drafts/draft13/types.d.ts +0 -310
  577. package/dist/drafts/draft13/types.d.ts.map +0 -1
  578. package/dist/drafts/draft13/types.js +0 -4
  579. package/dist/drafts/draft13/types.js.map +0 -1
  580. package/dist/drafts/draft14/codec.d.ts +0 -34
  581. package/dist/drafts/draft14/codec.d.ts.map +0 -1
  582. package/dist/drafts/draft14/codec.js +0 -752
  583. package/dist/drafts/draft14/codec.js.map +0 -1
  584. package/dist/drafts/draft14/data-streams.d.ts +0 -56
  585. package/dist/drafts/draft14/data-streams.d.ts.map +0 -1
  586. package/dist/drafts/draft14/data-streams.js +0 -729
  587. package/dist/drafts/draft14/data-streams.js.map +0 -1
  588. package/dist/drafts/draft14/index.d.ts +0 -9
  589. package/dist/drafts/draft14/index.d.ts.map +0 -1
  590. package/dist/drafts/draft14/index.js +0 -7
  591. package/dist/drafts/draft14/index.js.map +0 -1
  592. package/dist/drafts/draft14/messages.d.ts +0 -36
  593. package/dist/drafts/draft14/messages.d.ts.map +0 -1
  594. package/dist/drafts/draft14/messages.js +0 -71
  595. package/dist/drafts/draft14/messages.js.map +0 -1
  596. package/dist/drafts/draft14/rules.d.ts +0 -8
  597. package/dist/drafts/draft14/rules.d.ts.map +0 -1
  598. package/dist/drafts/draft14/rules.js +0 -101
  599. package/dist/drafts/draft14/rules.js.map +0 -1
  600. package/dist/drafts/draft14/session-fsm.d.ts +0 -58
  601. package/dist/drafts/draft14/session-fsm.d.ts.map +0 -1
  602. package/dist/drafts/draft14/session-fsm.js +0 -648
  603. package/dist/drafts/draft14/session-fsm.js.map +0 -1
  604. package/dist/drafts/draft14/session.d.ts +0 -5
  605. package/dist/drafts/draft14/session.d.ts.map +0 -1
  606. package/dist/drafts/draft14/session.js +0 -5
  607. package/dist/drafts/draft14/session.js.map +0 -1
  608. package/dist/drafts/draft14/types.d.ts +0 -263
  609. package/dist/drafts/draft14/types.d.ts.map +0 -1
  610. package/dist/drafts/draft14/types.js +0 -4
  611. package/dist/drafts/draft14/types.js.map +0 -1
  612. package/dist/drafts/draft15/codec.d.ts +0 -33
  613. package/dist/drafts/draft15/codec.d.ts.map +0 -1
  614. package/dist/drafts/draft15/codec.js +0 -742
  615. package/dist/drafts/draft15/codec.js.map +0 -1
  616. package/dist/drafts/draft15/data-streams.d.ts +0 -45
  617. package/dist/drafts/draft15/data-streams.d.ts.map +0 -1
  618. package/dist/drafts/draft15/data-streams.js +0 -675
  619. package/dist/drafts/draft15/data-streams.js.map +0 -1
  620. package/dist/drafts/draft15/index.d.ts +0 -9
  621. package/dist/drafts/draft15/index.d.ts.map +0 -1
  622. package/dist/drafts/draft15/index.js +0 -7
  623. package/dist/drafts/draft15/index.js.map +0 -1
  624. package/dist/drafts/draft15/messages.d.ts +0 -31
  625. package/dist/drafts/draft15/messages.d.ts.map +0 -1
  626. package/dist/drafts/draft15/messages.js +0 -59
  627. package/dist/drafts/draft15/messages.js.map +0 -1
  628. package/dist/drafts/draft15/rules.d.ts +0 -8
  629. package/dist/drafts/draft15/rules.d.ts.map +0 -1
  630. package/dist/drafts/draft15/rules.js +0 -83
  631. package/dist/drafts/draft15/rules.js.map +0 -1
  632. package/dist/drafts/draft15/session-fsm.d.ts +0 -48
  633. package/dist/drafts/draft15/session-fsm.d.ts.map +0 -1
  634. package/dist/drafts/draft15/session-fsm.js +0 -479
  635. package/dist/drafts/draft15/session-fsm.js.map +0 -1
  636. package/dist/drafts/draft15/session.d.ts +0 -5
  637. package/dist/drafts/draft15/session.d.ts.map +0 -1
  638. package/dist/drafts/draft15/session.js +0 -5
  639. package/dist/drafts/draft15/session.js.map +0 -1
  640. package/dist/drafts/draft15/types.d.ts +0 -232
  641. package/dist/drafts/draft15/types.d.ts.map +0 -1
  642. package/dist/drafts/draft15/types.js +0 -4
  643. package/dist/drafts/draft15/types.js.map +0 -1
  644. package/dist/drafts/draft16/codec.d.ts +0 -29
  645. package/dist/drafts/draft16/codec.d.ts.map +0 -1
  646. package/dist/drafts/draft16/codec.js +0 -747
  647. package/dist/drafts/draft16/codec.js.map +0 -1
  648. package/dist/drafts/draft16/data-streams.d.ts +0 -34
  649. package/dist/drafts/draft16/data-streams.d.ts.map +0 -1
  650. package/dist/drafts/draft16/data-streams.js +0 -667
  651. package/dist/drafts/draft16/data-streams.js.map +0 -1
  652. package/dist/drafts/draft16/index.d.ts +0 -9
  653. package/dist/drafts/draft16/index.d.ts.map +0 -1
  654. package/dist/drafts/draft16/index.js +0 -7
  655. package/dist/drafts/draft16/index.js.map +0 -1
  656. package/dist/drafts/draft16/messages.d.ts +0 -32
  657. package/dist/drafts/draft16/messages.d.ts.map +0 -1
  658. package/dist/drafts/draft16/messages.js +0 -62
  659. package/dist/drafts/draft16/messages.js.map +0 -1
  660. package/dist/drafts/draft16/rules.d.ts +0 -8
  661. package/dist/drafts/draft16/rules.d.ts.map +0 -1
  662. package/dist/drafts/draft16/rules.js +0 -84
  663. package/dist/drafts/draft16/rules.js.map +0 -1
  664. package/dist/drafts/draft16/session-fsm.d.ts +0 -48
  665. package/dist/drafts/draft16/session-fsm.d.ts.map +0 -1
  666. package/dist/drafts/draft16/session-fsm.js +0 -474
  667. package/dist/drafts/draft16/session-fsm.js.map +0 -1
  668. package/dist/drafts/draft16/session.d.ts +0 -5
  669. package/dist/drafts/draft16/session.d.ts.map +0 -1
  670. package/dist/drafts/draft16/session.js +0 -5
  671. package/dist/drafts/draft16/session.js.map +0 -1
  672. package/dist/drafts/draft16/types.d.ts +0 -238
  673. package/dist/drafts/draft16/types.d.ts.map +0 -1
  674. package/dist/drafts/draft16/types.js +0 -4
  675. package/dist/drafts/draft16/types.js.map +0 -1
  676. package/dist/drafts/draft17/codec.d.ts +0 -29
  677. package/dist/drafts/draft17/codec.d.ts.map +0 -1
  678. package/dist/drafts/draft17/codec.js +0 -799
  679. package/dist/drafts/draft17/codec.js.map +0 -1
  680. package/dist/drafts/draft17/data-streams.d.ts +0 -13
  681. package/dist/drafts/draft17/data-streams.d.ts.map +0 -1
  682. package/dist/drafts/draft17/data-streams.js +0 -633
  683. package/dist/drafts/draft17/data-streams.js.map +0 -1
  684. package/dist/drafts/draft17/index.d.ts +0 -8
  685. package/dist/drafts/draft17/index.d.ts.map +0 -1
  686. package/dist/drafts/draft17/index.js +0 -6
  687. package/dist/drafts/draft17/index.js.map +0 -1
  688. package/dist/drafts/draft17/messages.d.ts +0 -25
  689. package/dist/drafts/draft17/messages.d.ts.map +0 -1
  690. package/dist/drafts/draft17/messages.js +0 -48
  691. package/dist/drafts/draft17/messages.js.map +0 -1
  692. package/dist/drafts/draft17/rules.d.ts +0 -8
  693. package/dist/drafts/draft17/rules.d.ts.map +0 -1
  694. package/dist/drafts/draft17/rules.js +0 -71
  695. package/dist/drafts/draft17/rules.js.map +0 -1
  696. package/dist/drafts/draft17/session-fsm.d.ts +0 -45
  697. package/dist/drafts/draft17/session-fsm.d.ts.map +0 -1
  698. package/dist/drafts/draft17/session-fsm.js +0 -328
  699. package/dist/drafts/draft17/session-fsm.js.map +0 -1
  700. package/dist/drafts/draft17/session.d.ts +0 -5
  701. package/dist/drafts/draft17/session.d.ts.map +0 -1
  702. package/dist/drafts/draft17/session.js +0 -6
  703. package/dist/drafts/draft17/session.js.map +0 -1
  704. package/dist/drafts/draft17/types.d.ts +0 -219
  705. package/dist/drafts/draft17/types.d.ts.map +0 -1
  706. package/dist/drafts/draft17/types.js +0 -3
  707. package/dist/drafts/draft17/types.js.map +0 -1
  708. package/dist/index.d.ts.map +0 -1
  709. package/dist/index.js.map +0 -1
  710. package/dist/session.d.ts.map +0 -1
  711. package/dist/session.js.map +0 -1
  712. package/dist/types-QNXoxC9Y.d.cts +0 -236
  713. package/dist/types-QNXoxC9Y.d.ts +0 -236
  714. package/src/drafts/draft07/announce-fsm.ts +0 -2
  715. package/src/drafts/draft07/parameters.ts +0 -12
  716. package/src/drafts/draft07/subscription-fsm.ts +0 -3
@@ -1,962 +1,1209 @@
1
- import { bytesToHex, hexToBytes } from "../../core/hex.js";
2
- import { BufferReader } from "../../core/buffer-reader.js";
3
- import { BufferWriter } from "../../core/buffer-writer.js";
4
- import type { BaseCodec, DecodeResult } from "../../core/types.js";
5
- import { DecodeError } from "../../core/types.js";
6
- import {
7
- MESSAGE_ID_MAP,
8
- MSG_FETCH,
9
- MSG_FETCH_OK,
10
- MSG_GOAWAY,
11
- MSG_NAMESPACE,
12
- MSG_NAMESPACE_DONE,
13
- MSG_PUBLISH,
14
- MSG_PUBLISH_BLOCKED,
15
- MSG_PUBLISH_DONE,
16
- MSG_PUBLISH_NAMESPACE,
17
- MSG_PUBLISH_OK,
18
- MSG_REQUEST_ERROR,
19
- MSG_REQUEST_OK,
20
- MSG_REQUEST_UPDATE,
21
- MSG_SETUP,
22
- MSG_SUBSCRIBE,
23
- MSG_SUBSCRIBE_NAMESPACE,
24
- MSG_SUBSCRIBE_OK,
25
- MSG_TRACK_STATUS,
26
- SETUP_OPT_AUTHORITY,
27
- SETUP_OPT_MAX_AUTH_TOKEN_CACHE_SIZE,
28
- SETUP_OPT_MOQT_IMPLEMENTATION,
29
- SETUP_OPT_PATH,
30
- } from "./messages.js";
31
- import type {
32
- DatagramObject,
33
- DataStreamEvent,
34
- Draft17DataStream,
35
- Draft17Fetch,
36
- Draft17Message,
37
- Draft17Params,
38
- Draft17SetupOptions,
39
- Draft17TrackProperties,
40
- FetchObjectPayload,
41
- FetchStream,
42
- FetchStreamHeader,
43
- JoiningFetch,
44
- ObjectPayload,
45
- StandaloneFetch,
46
- SubgroupStream,
47
- SubgroupStreamHeader,
48
- UnknownParam,
49
- } from "./types.js";
50
- // ─── Setup Options Encoding/Decoding (KVP, no count prefix) ─────────────────
51
-
52
- function encodeSetupOptions(opts: Draft17SetupOptions, writer: BufferWriter): void {
53
- // Collect all options sorted by type ID
54
- const entries: Array<{ type: bigint; encode: (w: BufferWriter) => void }> = [];
55
-
56
- if (opts.path !== undefined) {
57
- entries.push({
58
- type: SETUP_OPT_PATH,
59
- encode: (w) => {
60
- const encoded = new TextEncoder().encode(opts.path!);
61
- w.writeVarInt(BigInt(encoded.byteLength));
62
- w.writeBytes(encoded);
63
- },
64
- });
65
- }
66
- if (opts.max_auth_token_cache_size !== undefined) {
67
- entries.push({
68
- type: SETUP_OPT_MAX_AUTH_TOKEN_CACHE_SIZE,
69
- encode: (w) => w.writeVarInt(opts.max_auth_token_cache_size!),
70
- });
71
- }
72
- if (opts.authority !== undefined) {
73
- entries.push({
74
- type: SETUP_OPT_AUTHORITY,
75
- encode: (w) => {
76
- const encoded = new TextEncoder().encode(opts.authority!);
77
- w.writeVarInt(BigInt(encoded.byteLength));
78
- w.writeBytes(encoded);
79
- },
80
- });
81
- }
82
- if (opts.moqt_implementation !== undefined) {
83
- entries.push({
84
- type: SETUP_OPT_MOQT_IMPLEMENTATION,
85
- encode: (w) => {
86
- const encoded = new TextEncoder().encode(opts.moqt_implementation!);
87
- w.writeVarInt(BigInt(encoded.byteLength));
88
- w.writeBytes(encoded);
89
- },
90
- });
91
- }
92
- if (opts.unknown) {
93
- for (const u of opts.unknown) {
94
- const id = BigInt(u.id);
95
- entries.push({
96
- type: id,
97
- encode: (w) => {
98
- if (id % 2n === 0n) {
99
- const raw = hexToBytes(u.raw_hex);
100
- const tmpReader = new BufferReader(raw);
101
- w.writeVarInt(tmpReader.readVarInt());
102
- } else {
103
- const raw = hexToBytes(u.raw_hex);
104
- w.writeVarInt(BigInt(raw.byteLength));
105
- w.writeBytes(raw);
106
- }
107
- },
108
- });
109
- }
110
- }
111
-
112
- // Sort by type (ascending) and write with delta encoding
113
- entries.sort((a, b) => (a.type < b.type ? -1 : a.type > b.type ? 1 : 0));
114
- let prevType = 0n;
115
- for (const entry of entries) {
116
- writer.writeVarInt(entry.type - prevType);
117
- entry.encode(writer);
118
- prevType = entry.type;
119
- }
120
- }
121
-
122
- function decodeSetupOptions(reader: BufferReader, payloadEnd: number): Draft17SetupOptions {
123
- const result: Draft17SetupOptions = {};
124
- const unknown: UnknownParam[] = [];
125
- let prevType = 0n;
126
-
127
- while (reader.offset < payloadEnd) {
128
- const delta = reader.readVarInt();
129
- const optType = prevType + delta;
130
- prevType = optType;
131
-
132
- if (optType % 2n === 0n) {
133
- // Even: single varint value
134
- const value = reader.readVarInt();
135
- if (optType === SETUP_OPT_MAX_AUTH_TOKEN_CACHE_SIZE) {
136
- result.max_auth_token_cache_size = value;
137
- } else {
138
- const tmpWriter = new BufferWriter(16);
139
- tmpWriter.writeVarInt(value);
140
- const raw = tmpWriter.finish();
141
- unknown.push({
142
- id: `0x${optType.toString(16)}`,
143
- length: raw.byteLength,
144
- raw_hex: bytesToHex(raw),
145
- });
146
- }
147
- } else {
148
- // Odd: length-prefixed bytes
149
- const length = Number(reader.readVarInt());
150
- const bytes = reader.readBytes(length);
151
- if (optType === SETUP_OPT_PATH) {
152
- result.path = new TextDecoder().decode(bytes);
153
- } else if (optType === SETUP_OPT_AUTHORITY) {
154
- result.authority = new TextDecoder().decode(bytes);
155
- } else if (optType === SETUP_OPT_MOQT_IMPLEMENTATION) {
156
- result.moqt_implementation = new TextDecoder().decode(bytes);
157
- } else {
158
- unknown.push({ id: `0x${optType.toString(16)}`, length, raw_hex: bytesToHex(bytes) });
159
- }
160
- }
161
- }
162
-
163
- if (unknown.length > 0) result.unknown = unknown;
164
- return result;
165
- }
166
-
167
- // ─── Message Parameter Encoding/Decoding (delta types, count prefix) ─────────
168
-
169
- const PARAM_EXPIRES = 0x08n;
170
- const PARAM_LARGEST_OBJECT = 0x09n;
171
- const PARAM_SUBSCRIBER_PRIORITY = 0x20n;
172
- const PARAM_SUBSCRIPTION_FILTER = 0x21n;
173
- const PARAM_GROUP_ORDER = 0x22n;
174
-
175
- function encodeParams(params: Draft17Params, writer: BufferWriter): void {
176
- // Collect and sort params by type
177
- const entries: Array<{ type: bigint; encode: (w: BufferWriter) => void }> = [];
178
-
179
- if (params.expires !== undefined) {
180
- entries.push({ type: PARAM_EXPIRES, encode: (w) => w.writeVarInt(params.expires!) });
181
- }
182
- if (params.largest_object !== undefined) {
183
- entries.push({
184
- type: PARAM_LARGEST_OBJECT,
185
- encode: (w) => {
186
- w.writeVarInt(params.largest_object!.group);
187
- w.writeVarInt(params.largest_object!.object);
188
- },
189
- });
190
- }
191
- if (params.subscriber_priority !== undefined) {
192
- entries.push({
193
- type: PARAM_SUBSCRIBER_PRIORITY,
194
- encode: (w) => w.writeUint8(Number(params.subscriber_priority!)),
195
- });
196
- }
197
- if (params.subscription_filter !== undefined) {
198
- entries.push({
199
- type: PARAM_SUBSCRIPTION_FILTER,
200
- encode: (w) => {
201
- const f = params.subscription_filter!;
202
- const tmpW = new BufferWriter(32);
203
- tmpW.writeVarInt(f.filter_type);
204
- if (f.filter_type === 3n || f.filter_type === 4n) {
205
- tmpW.writeVarInt(f.start_group!);
206
- tmpW.writeVarInt(f.start_object!);
207
- }
208
- if (f.filter_type === 4n) {
209
- tmpW.writeVarInt(f.end_group!);
210
- }
211
- const raw = tmpW.finish();
212
- w.writeVarInt(BigInt(raw.byteLength));
213
- w.writeBytes(raw);
214
- },
215
- });
216
- }
217
- if (params.group_order !== undefined) {
218
- entries.push({
219
- type: PARAM_GROUP_ORDER,
220
- encode: (w) => w.writeUint8(Number(params.group_order!)),
221
- });
222
- }
223
-
224
- // Unknown params
225
- if (params.unknown) {
226
- for (const u of params.unknown) {
227
- const id = BigInt(u.id);
228
- entries.push({
229
- type: id,
230
- encode: (w) => {
231
- const raw = hexToBytes(u.raw_hex);
232
- // For unknown params, we store raw bytes and re-emit them
233
- w.writeBytes(raw);
234
- },
235
- });
236
- }
237
- }
238
-
239
- entries.sort((a, b) => (a.type < b.type ? -1 : a.type > b.type ? 1 : 0));
240
-
241
- writer.writeVarInt(BigInt(entries.length));
242
- let prevType = 0n;
243
- for (const entry of entries) {
244
- writer.writeVarInt(entry.type - prevType);
245
- entry.encode(writer);
246
- prevType = entry.type;
247
- }
248
- }
249
-
250
- function decodeParams(reader: BufferReader): Draft17Params {
251
- const count = Number(reader.readVarInt());
252
- const result: Draft17Params = {};
253
- const unknown: UnknownParam[] = [];
254
- let prevType = 0n;
255
-
256
- for (let i = 0; i < count; i++) {
257
- const delta = reader.readVarInt();
258
- const paramType = prevType + delta;
259
- prevType = paramType;
260
-
261
- if (paramType === PARAM_EXPIRES) {
262
- result.expires = reader.readVarInt();
263
- } else if (paramType === PARAM_LARGEST_OBJECT) {
264
- // Location: 2 bare varints (not length-prefixed)
265
- const group = reader.readVarInt();
266
- const object = reader.readVarInt();
267
- result.largest_object = { group, object };
268
- } else if (paramType === PARAM_SUBSCRIBER_PRIORITY) {
269
- // uint8: single raw byte
270
- result.subscriber_priority = BigInt(reader.readUint8());
271
- } else if (paramType === PARAM_SUBSCRIPTION_FILTER) {
272
- // Length-prefixed
273
- const length = Number(reader.readVarInt());
274
- const startOff = reader.offset;
275
- const filter_type = reader.readVarInt();
276
- const filter: {
277
- filter_type: bigint;
278
- start_group?: bigint;
279
- start_object?: bigint;
280
- end_group?: bigint;
281
- } = { filter_type };
282
- if (filter_type === 3n || filter_type === 4n) {
283
- filter.start_group = reader.readVarInt();
284
- filter.start_object = reader.readVarInt();
285
- }
286
- if (filter_type === 4n) {
287
- filter.end_group = reader.readVarInt();
288
- }
289
- const consumed = reader.offset - startOff;
290
- if (consumed < length) reader.readBytes(length - consumed);
291
- result.subscription_filter = filter;
292
- } else if (paramType === PARAM_GROUP_ORDER) {
293
- // uint8: single raw byte
294
- result.group_order = BigInt(reader.readUint8());
295
- } else {
296
- // Unknown parameter — we don't know the encoding, protocol violation per spec
297
- // But for robustness, attempt even/odd heuristic
298
- if (paramType % 2n === 0n) {
299
- const value = reader.readVarInt();
300
- const tmpWriter = new BufferWriter(16);
301
- tmpWriter.writeVarInt(value);
302
- const raw = tmpWriter.finish();
303
- unknown.push({
304
- id: `0x${paramType.toString(16)}`,
305
- length: raw.byteLength,
306
- raw_hex: bytesToHex(raw),
307
- });
308
- } else {
309
- const length = Number(reader.readVarInt());
310
- const bytes = reader.readBytes(length);
311
- unknown.push({ id: `0x${paramType.toString(16)}`, length, raw_hex: bytesToHex(bytes) });
312
- }
313
- }
314
- }
315
-
316
- if (unknown.length > 0) result.unknown = unknown;
317
- return result;
318
- }
319
-
320
- // ─── Track Properties Encoding/Decoding (KVP, no count prefix) ──────────────
321
-
322
- function encodeTrackProperties(props: Draft17TrackProperties, writer: BufferWriter): void {
323
- if (!props.unknown || props.unknown.length === 0) return;
324
-
325
- const entries = props.unknown.map((u) => ({ type: BigInt(u.id), raw: u }));
326
- entries.sort((a, b) => (a.type < b.type ? -1 : a.type > b.type ? 1 : 0));
327
-
328
- let prevType = 0n;
329
- for (const entry of entries) {
330
- writer.writeVarInt(entry.type - prevType);
331
- if (entry.type % 2n === 0n) {
332
- const raw = hexToBytes(entry.raw.raw_hex);
333
- const tmpReader = new BufferReader(raw);
334
- writer.writeVarInt(tmpReader.readVarInt());
335
- } else {
336
- const raw = hexToBytes(entry.raw.raw_hex);
337
- writer.writeVarInt(BigInt(raw.byteLength));
338
- writer.writeBytes(raw);
339
- }
340
- prevType = entry.type;
341
- }
342
- }
343
-
344
- function decodeTrackProperties(reader: BufferReader, payloadEnd: number): Draft17TrackProperties {
345
- const result: Draft17TrackProperties = {};
346
- const unknown: UnknownParam[] = [];
347
- let prevType = 0n;
348
-
349
- while (reader.offset < payloadEnd) {
350
- const delta = reader.readVarInt();
351
- const propType = prevType + delta;
352
- prevType = propType;
353
-
354
- if (propType % 2n === 0n) {
355
- const value = reader.readVarInt();
356
- const tmpWriter = new BufferWriter(16);
357
- tmpWriter.writeVarInt(value);
358
- const raw = tmpWriter.finish();
359
- unknown.push({
360
- id: `0x${propType.toString(16)}`,
361
- length: raw.byteLength,
362
- raw_hex: bytesToHex(raw),
363
- });
364
- } else {
365
- const length = Number(reader.readVarInt());
366
- const bytes = reader.readBytes(length);
367
- unknown.push({ id: `0x${propType.toString(16)}`, length, raw_hex: bytesToHex(bytes) });
368
- }
369
- }
370
-
371
- if (unknown.length > 0) result.unknown = unknown;
372
- return result;
373
- }
374
-
375
- // ─── Payload Encoders ──────────────────────────────────────────────────────────
376
-
377
- function encodeSetupPayload(msg: Draft17Message & { type: "setup" }, w: BufferWriter): void {
378
- encodeSetupOptions(msg.options, w);
379
- }
380
-
381
- function encodeSubscribePayload(
382
- msg: Draft17Message & { type: "subscribe" },
383
- w: BufferWriter,
384
- ): void {
385
- w.writeVarInt(msg.request_id);
386
- w.writeVarInt(msg.required_request_id_delta);
387
- w.writeTuple(msg.track_namespace);
388
- w.writeString(msg.track_name);
389
- encodeParams(msg.parameters, w);
390
- }
391
-
392
- function encodeSubscribeOkPayload(
393
- msg: Draft17Message & { type: "subscribe_ok" },
394
- w: BufferWriter,
395
- ): void {
396
- w.writeVarInt(msg.track_alias);
397
- encodeParams(msg.parameters, w);
398
- encodeTrackProperties(msg.track_properties, w);
399
- }
400
-
401
- function encodeRequestUpdatePayload(
402
- msg: Draft17Message & { type: "request_update" },
403
- w: BufferWriter,
404
- ): void {
405
- w.writeVarInt(msg.request_id);
406
- w.writeVarInt(msg.required_request_id_delta);
407
- encodeParams(msg.parameters, w);
408
- }
409
-
410
- function encodePublishPayload(msg: Draft17Message & { type: "publish" }, w: BufferWriter): void {
411
- w.writeVarInt(msg.request_id);
412
- w.writeVarInt(msg.required_request_id_delta);
413
- w.writeTuple(msg.track_namespace);
414
- w.writeString(msg.track_name);
415
- w.writeVarInt(msg.track_alias);
416
- encodeParams(msg.parameters, w);
417
- encodeTrackProperties(msg.track_properties, w);
418
- }
419
-
420
- function encodePublishOkPayload(
421
- msg: Draft17Message & { type: "publish_ok" },
422
- w: BufferWriter,
423
- ): void {
424
- encodeParams(msg.parameters, w);
425
- }
426
-
427
- function encodePublishDonePayload(
428
- msg: Draft17Message & { type: "publish_done" },
429
- w: BufferWriter,
430
- ): void {
431
- w.writeVarInt(msg.status_code);
432
- w.writeVarInt(msg.stream_count);
433
- w.writeString(msg.reason_phrase);
434
- }
435
-
436
- function encodePublishNamespacePayload(
437
- msg: Draft17Message & { type: "publish_namespace" },
438
- w: BufferWriter,
439
- ): void {
440
- w.writeVarInt(msg.request_id);
441
- w.writeVarInt(msg.required_request_id_delta);
442
- w.writeTuple(msg.track_namespace);
443
- encodeParams(msg.parameters, w);
444
- }
445
-
446
- function encodeNamespacePayload(
447
- msg: Draft17Message & { type: "namespace" },
448
- w: BufferWriter,
449
- ): void {
450
- w.writeTuple(msg.namespace_suffix);
451
- }
452
-
453
- function encodeNamespaceDonePayload(
454
- msg: Draft17Message & { type: "namespace_done" },
455
- w: BufferWriter,
456
- ): void {
457
- w.writeTuple(msg.namespace_suffix);
458
- }
459
-
460
- function encodeSubscribeNamespacePayload(
461
- msg: Draft17Message & { type: "subscribe_namespace" },
462
- w: BufferWriter,
463
- ): void {
464
- w.writeVarInt(msg.request_id);
465
- w.writeVarInt(msg.required_request_id_delta);
466
- w.writeTuple(msg.namespace_prefix);
467
- w.writeVarInt(msg.subscribe_options);
468
- encodeParams(msg.parameters, w);
469
- }
470
-
471
- function encodePublishBlockedPayload(
472
- msg: Draft17Message & { type: "publish_blocked" },
473
- w: BufferWriter,
474
- ): void {
475
- w.writeTuple(msg.namespace_suffix);
476
- w.writeString(msg.track_name);
477
- }
478
-
479
- function encodeFetchPayload(msg: Draft17Message & { type: "fetch" }, w: BufferWriter): void {
480
- w.writeVarInt(msg.request_id);
481
- w.writeVarInt(msg.required_request_id_delta);
482
- w.writeVarInt(msg.fetch_type);
483
- const ft = Number(msg.fetch_type);
484
- if (ft === 1 && msg.standalone) {
485
- w.writeTuple(msg.standalone.track_namespace);
486
- w.writeString(msg.standalone.track_name);
487
- w.writeVarInt(msg.standalone.start_group);
488
- w.writeVarInt(msg.standalone.start_object);
489
- w.writeVarInt(msg.standalone.end_group);
490
- w.writeVarInt(msg.standalone.end_object);
491
- } else if ((ft === 2 || ft === 3) && msg.joining) {
492
- w.writeVarInt(msg.joining.joining_request_id);
493
- w.writeVarInt(msg.joining.joining_start);
494
- }
495
- encodeParams(msg.parameters, w);
496
- }
497
-
498
- function encodeFetchOkPayload(msg: Draft17Message & { type: "fetch_ok" }, w: BufferWriter): void {
499
- w.writeUint8(msg.end_of_track);
500
- w.writeVarInt(msg.end_group);
501
- w.writeVarInt(msg.end_object);
502
- encodeParams(msg.parameters, w);
503
- encodeTrackProperties(msg.track_properties, w);
504
- }
505
-
506
- function encodeTrackStatusPayload(
507
- msg: Draft17Message & { type: "track_status" },
508
- w: BufferWriter,
509
- ): void {
510
- w.writeVarInt(msg.request_id);
511
- w.writeVarInt(msg.required_request_id_delta);
512
- w.writeTuple(msg.track_namespace);
513
- w.writeString(msg.track_name);
514
- encodeParams(msg.parameters, w);
515
- }
516
-
517
- function encodeRequestOkPayload(
518
- msg: Draft17Message & { type: "request_ok" },
519
- w: BufferWriter,
520
- ): void {
521
- encodeParams(msg.parameters, w);
522
- }
523
-
524
- function encodeRequestErrorPayload(
525
- msg: Draft17Message & { type: "request_error" },
526
- w: BufferWriter,
527
- ): void {
528
- w.writeVarInt(msg.error_code);
529
- w.writeVarInt(msg.retry_interval);
530
- w.writeString(msg.reason_phrase);
531
- }
532
-
533
- function encodeGoAwayPayload(msg: Draft17Message & { type: "goaway" }, w: BufferWriter): void {
534
- w.writeString(msg.new_session_uri);
535
- w.writeVarInt(msg.timeout);
536
- }
537
-
538
- // ─── Payload Decoders ──────────────────────────────────────────────────────────
539
-
540
- function decodeSetupPayload(r: BufferReader, payloadEnd: number): Draft17Message {
541
- const options = decodeSetupOptions(r, payloadEnd);
542
- return { type: "setup", options };
543
- }
544
-
545
- function decodeSubscribePayload(r: BufferReader): Draft17Message {
546
- const request_id = r.readVarInt();
547
- const required_request_id_delta = r.readVarInt();
548
- const track_namespace = r.readTuple();
549
- const track_name = r.readString();
550
- const parameters = decodeParams(r);
551
- return {
552
- type: "subscribe",
553
- request_id,
554
- required_request_id_delta,
555
- track_namespace,
556
- track_name,
557
- parameters,
558
- };
559
- }
560
-
561
- function decodeSubscribeOkPayload(r: BufferReader, payloadEnd: number): Draft17Message {
562
- const track_alias = r.readVarInt();
563
- const parameters = decodeParams(r);
564
- const track_properties = decodeTrackProperties(r, payloadEnd);
565
- return { type: "subscribe_ok", track_alias, parameters, track_properties };
566
- }
567
-
568
- function decodeRequestUpdatePayload(r: BufferReader): Draft17Message {
569
- const request_id = r.readVarInt();
570
- const required_request_id_delta = r.readVarInt();
571
- const parameters = decodeParams(r);
572
- return { type: "request_update", request_id, required_request_id_delta, parameters };
573
- }
574
-
575
- function decodePublishPayload(r: BufferReader, payloadEnd: number): Draft17Message {
576
- const request_id = r.readVarInt();
577
- const required_request_id_delta = r.readVarInt();
578
- const track_namespace = r.readTuple();
579
- const track_name = r.readString();
580
- const track_alias = r.readVarInt();
581
- const parameters = decodeParams(r);
582
- const track_properties = decodeTrackProperties(r, payloadEnd);
583
- return {
584
- type: "publish",
585
- request_id,
586
- required_request_id_delta,
587
- track_namespace,
588
- track_name,
589
- track_alias,
590
- parameters,
591
- track_properties,
592
- };
593
- }
594
-
595
- function decodePublishOkPayload(r: BufferReader): Draft17Message {
596
- const parameters = decodeParams(r);
597
- return { type: "publish_ok", parameters };
598
- }
599
-
600
- function decodePublishDonePayload(r: BufferReader): Draft17Message {
601
- const status_code = r.readVarInt();
602
- const stream_count = r.readVarInt();
603
- const reason_phrase = r.readString();
604
- return { type: "publish_done", status_code, stream_count, reason_phrase };
605
- }
606
-
607
- function decodePublishNamespacePayload(r: BufferReader): Draft17Message {
608
- const request_id = r.readVarInt();
609
- const required_request_id_delta = r.readVarInt();
610
- const track_namespace = r.readTuple();
611
- const parameters = decodeParams(r);
612
- return {
613
- type: "publish_namespace",
614
- request_id,
615
- required_request_id_delta,
616
- track_namespace,
617
- parameters,
618
- };
619
- }
620
-
621
- function decodeNamespacePayload(r: BufferReader): Draft17Message {
622
- const namespace_suffix = r.readTuple();
623
- return { type: "namespace", namespace_suffix };
624
- }
625
-
626
- function decodeNamespaceDonePayload(r: BufferReader): Draft17Message {
627
- const namespace_suffix = r.readTuple();
628
- return { type: "namespace_done", namespace_suffix };
629
- }
630
-
631
- function decodeSubscribeNamespacePayload(r: BufferReader): Draft17Message {
632
- const request_id = r.readVarInt();
633
- const required_request_id_delta = r.readVarInt();
634
- const namespace_prefix = r.readTuple();
635
- const subscribe_options = r.readVarInt();
636
- const parameters = decodeParams(r);
637
- return {
638
- type: "subscribe_namespace",
639
- request_id,
640
- required_request_id_delta,
641
- namespace_prefix,
642
- subscribe_options,
643
- parameters,
644
- };
645
- }
646
-
647
- function decodePublishBlockedPayload(r: BufferReader): Draft17Message {
648
- const namespace_suffix = r.readTuple();
649
- const track_name = r.readString();
650
- return { type: "publish_blocked", namespace_suffix, track_name };
651
- }
652
-
653
- function decodeFetchPayload(r: BufferReader): Draft17Message {
654
- const request_id = r.readVarInt();
655
- const required_request_id_delta = r.readVarInt();
656
- const fetch_type = r.readVarInt();
657
- const ft = Number(fetch_type);
658
-
659
- if (ft < 1 || ft > 3) {
660
- throw new DecodeError("CONSTRAINT_VIOLATION", `Invalid fetch_type: ${ft}`, r.offset);
661
- }
662
-
663
- let standalone: StandaloneFetch | undefined;
664
- let joining: JoiningFetch | undefined;
665
-
666
- if (ft === 1) {
667
- const track_namespace = r.readTuple();
668
- const track_name = r.readString();
669
- const start_group = r.readVarInt();
670
- const start_object = r.readVarInt();
671
- const end_group = r.readVarInt();
672
- const end_object = r.readVarInt();
673
- standalone = { track_namespace, track_name, start_group, start_object, end_group, end_object };
674
- } else {
675
- const joining_request_id = r.readVarInt();
676
- const joining_start = r.readVarInt();
677
- joining = { joining_request_id, joining_start };
678
- }
679
-
680
- const parameters = decodeParams(r);
681
-
682
- return {
683
- type: "fetch",
684
- request_id,
685
- required_request_id_delta,
686
- fetch_type,
687
- standalone,
688
- joining,
689
- parameters,
690
- } as Draft17Fetch;
691
- }
692
-
693
- function decodeFetchOkPayload(r: BufferReader, payloadEnd: number): Draft17Message {
694
- const end_of_track = r.readUint8();
695
- const end_group = r.readVarInt();
696
- const end_object = r.readVarInt();
697
- const parameters = decodeParams(r);
698
- const track_properties = decodeTrackProperties(r, payloadEnd);
699
- return { type: "fetch_ok", end_of_track, end_group, end_object, parameters, track_properties };
700
- }
701
-
702
- function decodeTrackStatusPayload(r: BufferReader): Draft17Message {
703
- const request_id = r.readVarInt();
704
- const required_request_id_delta = r.readVarInt();
705
- const track_namespace = r.readTuple();
706
- const track_name = r.readString();
707
- const parameters = decodeParams(r);
708
- return {
709
- type: "track_status",
710
- request_id,
711
- required_request_id_delta,
712
- track_namespace,
713
- track_name,
714
- parameters,
715
- };
716
- }
717
-
718
- function decodeRequestOkPayload(r: BufferReader): Draft17Message {
719
- const parameters = decodeParams(r);
720
- return { type: "request_ok", parameters };
721
- }
722
-
723
- function decodeRequestErrorPayload(r: BufferReader): Draft17Message {
724
- const error_code = r.readVarInt();
725
- const retry_interval = r.readVarInt();
726
- const reason_phrase = r.readString();
727
- return { type: "request_error", error_code, retry_interval, reason_phrase };
728
- }
729
-
730
- function decodeGoAwayPayload(r: BufferReader): Draft17Message {
731
- const new_session_uri = r.readString();
732
- const timeout = r.readVarInt();
733
- return { type: "goaway", new_session_uri, timeout };
734
- }
735
-
736
- // ─── Public API ────────────────────────────────────────────────────────────────
737
-
738
- /**
739
- * Encode a draft-17 control message with type(varint) + length(uint16 BE) + payload.
740
- */
741
- export function encodeMessage(message: Draft17Message): Uint8Array {
742
- const typeId = MESSAGE_ID_MAP.get(message.type);
743
- if (typeId === undefined) {
744
- throw new Error(`Unknown message type: ${message.type}`);
745
- }
746
-
747
- const payloadWriter = new BufferWriter();
748
- encodePayload(message, payloadWriter);
749
- const payload = payloadWriter.finish();
750
-
751
- if (payload.byteLength > 0xffff) {
752
- throw new Error(`Payload too large for 16-bit length: ${payload.byteLength}`);
753
- }
754
-
755
- const writer = new BufferWriter();
756
- writer.writeVarInt(typeId);
757
- writer.writeUint8((payload.byteLength >> 8) & 0xff);
758
- writer.writeUint8(payload.byteLength & 0xff);
759
- writer.writeBytes(payload);
760
-
761
- return writer.finish();
762
- }
763
-
764
- function encodePayload(msg: Draft17Message, w: BufferWriter): void {
765
- switch (msg.type) {
766
- case "setup":
767
- return encodeSetupPayload(msg, w);
768
- case "subscribe":
769
- return encodeSubscribePayload(msg, w);
770
- case "subscribe_ok":
771
- return encodeSubscribeOkPayload(msg, w);
772
- case "request_update":
773
- return encodeRequestUpdatePayload(msg, w);
774
- case "publish":
775
- return encodePublishPayload(msg, w);
776
- case "publish_ok":
777
- return encodePublishOkPayload(msg, w);
778
- case "publish_done":
779
- return encodePublishDonePayload(msg, w);
780
- case "publish_namespace":
781
- return encodePublishNamespacePayload(msg, w);
782
- case "namespace":
783
- return encodeNamespacePayload(msg, w);
784
- case "namespace_done":
785
- return encodeNamespaceDonePayload(msg, w);
786
- case "subscribe_namespace":
787
- return encodeSubscribeNamespacePayload(msg, w);
788
- case "publish_blocked":
789
- return encodePublishBlockedPayload(msg, w);
790
- case "fetch":
791
- return encodeFetchPayload(msg, w);
792
- case "fetch_ok":
793
- return encodeFetchOkPayload(msg, w);
794
- case "track_status":
795
- return encodeTrackStatusPayload(msg, w);
796
- case "request_ok":
797
- return encodeRequestOkPayload(msg, w);
798
- case "request_error":
799
- return encodeRequestErrorPayload(msg, w);
800
- case "goaway":
801
- return encodeGoAwayPayload(msg, w);
802
- default: {
803
- const _exhaustive: never = msg;
804
- throw new Error(`Unhandled message type: ${(_exhaustive as Draft17Message).type}`);
805
- }
806
- }
807
- }
808
-
809
- /**
810
- * Decode a draft-17 control message from bytes (type + uint16 length + payload).
811
- */
812
- export function decodeMessage(bytes: Uint8Array): DecodeResult<Draft17Message> {
813
- try {
814
- const reader = new BufferReader(bytes);
815
- const typeId = reader.readVarInt();
816
-
817
- const lenHi = reader.readUint8();
818
- const lenLo = reader.readUint8();
819
- const payloadLength = (lenHi << 8) | lenLo;
820
-
821
- const payloadStart = reader.offset;
822
- const _payloadEnd = payloadStart + payloadLength;
823
- const payloadBytes = reader.readBytes(payloadLength);
824
- const payloadReader = new BufferReader(payloadBytes);
825
-
826
- let message: Draft17Message;
827
-
828
- if (typeId === MSG_SETUP) {
829
- message = decodeSetupPayload(payloadReader, payloadLength);
830
- } else if (typeId === MSG_SUBSCRIBE) {
831
- message = decodeSubscribePayload(payloadReader);
832
- } else if (typeId === MSG_SUBSCRIBE_OK) {
833
- message = decodeSubscribeOkPayload(payloadReader, payloadLength);
834
- } else if (typeId === MSG_REQUEST_UPDATE) {
835
- message = decodeRequestUpdatePayload(payloadReader);
836
- } else if (typeId === MSG_PUBLISH) {
837
- message = decodePublishPayload(payloadReader, payloadLength);
838
- } else if (typeId === MSG_PUBLISH_OK) {
839
- message = decodePublishOkPayload(payloadReader);
840
- } else if (typeId === MSG_PUBLISH_DONE) {
841
- message = decodePublishDonePayload(payloadReader);
842
- } else if (typeId === MSG_PUBLISH_NAMESPACE) {
843
- message = decodePublishNamespacePayload(payloadReader);
844
- } else if (typeId === MSG_NAMESPACE) {
845
- message = decodeNamespacePayload(payloadReader);
846
- } else if (typeId === MSG_NAMESPACE_DONE) {
847
- message = decodeNamespaceDonePayload(payloadReader);
848
- } else if (typeId === MSG_SUBSCRIBE_NAMESPACE) {
849
- message = decodeSubscribeNamespacePayload(payloadReader);
850
- } else if (typeId === MSG_PUBLISH_BLOCKED) {
851
- message = decodePublishBlockedPayload(payloadReader);
852
- } else if (typeId === MSG_FETCH) {
853
- message = decodeFetchPayload(payloadReader);
854
- } else if (typeId === MSG_FETCH_OK) {
855
- message = decodeFetchOkPayload(payloadReader, payloadLength);
856
- } else if (typeId === MSG_TRACK_STATUS) {
857
- message = decodeTrackStatusPayload(payloadReader);
858
- } else if (typeId === MSG_REQUEST_OK) {
859
- message = decodeRequestOkPayload(payloadReader);
860
- } else if (typeId === MSG_REQUEST_ERROR) {
861
- message = decodeRequestErrorPayload(payloadReader);
862
- } else if (typeId === MSG_GOAWAY) {
863
- message = decodeGoAwayPayload(payloadReader);
864
- } else {
865
- return {
866
- ok: false,
867
- error: new DecodeError(
868
- "UNKNOWN_MESSAGE_TYPE",
869
- `Unknown message type ID: 0x${typeId.toString(16)}`,
870
- 0,
871
- ),
872
- };
873
- }
874
-
875
- return { ok: true, value: message, bytesRead: reader.offset };
876
- } catch (e) {
877
- if (e instanceof DecodeError) {
878
- return { ok: false, error: e };
879
- }
880
- throw e;
881
- }
882
- }
883
-
884
- // ─── Data Stream Encoding/Decoding (re-exported from data-streams.ts) ───────
885
-
886
- import { encodeSubgroupStream, decodeSubgroupStream, encodeDatagram, decodeDatagram, encodeFetchStream, decodeFetchStream, decodeDataStream, createSubgroupStreamDecoder, createFetchStreamDecoder, createDataStreamDecoder } from "./data-streams.js";
887
- export { encodeSubgroupStream, decodeSubgroupStream, encodeDatagram, decodeDatagram, encodeFetchStream, decodeFetchStream, decodeDataStream, createSubgroupStreamDecoder, createFetchStreamDecoder, createDataStreamDecoder };
888
-
889
- // ─── Stream Decoders ───────────────────────────────────────────────────────────
890
-
891
- export function createStreamDecoder(): TransformStream<Uint8Array, Draft17Message> {
892
- let buffer = new Uint8Array(0);
893
-
894
- return new TransformStream<Uint8Array, Draft17Message>({
895
- transform(chunk, controller) {
896
- const newBuffer = new Uint8Array(buffer.length + chunk.length);
897
- newBuffer.set(buffer, 0);
898
- newBuffer.set(chunk, buffer.length);
899
- buffer = newBuffer;
900
-
901
- while (buffer.length > 0) {
902
- const result = decodeMessage(buffer);
903
- if (!result.ok) {
904
- if (result.error.code === "UNEXPECTED_END") {
905
- break;
906
- }
907
- controller.error(result.error);
908
- return;
909
- }
910
- controller.enqueue(result.value);
911
- buffer = buffer.slice(result.bytesRead);
912
- }
913
- },
914
-
915
- flush(controller) {
916
- if (buffer.length > 0) {
917
- controller.error(
918
- new DecodeError("UNEXPECTED_END", "Stream ended with incomplete message data", 0),
919
- );
920
- }
921
- },
922
- });
923
- }
924
-
925
- // ─── Codec Factory ─────────────────────────────────────────────────────────────
926
-
927
- export interface Draft17Codec extends BaseCodec<Draft17Message> {
928
- readonly draft: "draft-ietf-moq-transport-17";
929
- encodeSubgroupStream(stream: SubgroupStream): Uint8Array;
930
- encodeDatagram(dg: DatagramObject): Uint8Array;
931
- encodeFetchStream(stream: FetchStream): Uint8Array;
932
- decodeSubgroupStream(bytes: Uint8Array): DecodeResult<SubgroupStream>;
933
- decodeDatagram(bytes: Uint8Array): DecodeResult<DatagramObject>;
934
- decodeFetchStream(bytes: Uint8Array): DecodeResult<FetchStream>;
935
- decodeDataStream(
936
- streamType: "subgroup" | "datagram" | "fetch",
937
- bytes: Uint8Array,
938
- ): DecodeResult<Draft17DataStream>;
939
- createStreamDecoder(): TransformStream<Uint8Array, Draft17Message>;
940
- createSubgroupStreamDecoder(): TransformStream<Uint8Array, SubgroupStreamHeader | ObjectPayload>;
941
- createFetchStreamDecoder(): TransformStream<Uint8Array, FetchStreamHeader | ObjectPayload>;
942
- createDataStreamDecoder(): TransformStream<Uint8Array, DataStreamEvent>;
943
- }
944
-
945
- export function createDraft17Codec(): Draft17Codec {
946
- return {
947
- draft: "draft-ietf-moq-transport-17",
948
- encodeMessage,
949
- decodeMessage,
950
- encodeSubgroupStream,
951
- encodeDatagram,
952
- encodeFetchStream,
953
- decodeSubgroupStream,
954
- decodeDatagram,
955
- decodeFetchStream,
956
- decodeDataStream,
957
- createStreamDecoder,
958
- createSubgroupStreamDecoder,
959
- createFetchStreamDecoder,
960
- createDataStreamDecoder,
961
- };
962
- }
1
+ import { BufferReader } from '../../core/buffer-reader.js'
2
+ import { BufferWriter } from '../../core/buffer-writer.js'
3
+ import { bytesToHex, hexToBytes } from '../../core/hex.js'
4
+ import type { BaseCodec, DecodeResult } from '../../core/types.js'
5
+ import { DecodeError } from '../../core/types.js'
6
+ import {
7
+ MESSAGE_ID_MAP,
8
+ MSG_FETCH,
9
+ MSG_FETCH_OK,
10
+ MSG_GOAWAY,
11
+ MSG_NAMESPACE,
12
+ MSG_NAMESPACE_DONE,
13
+ MSG_PUBLISH,
14
+ MSG_PUBLISH_BLOCKED,
15
+ MSG_PUBLISH_DONE,
16
+ MSG_PUBLISH_NAMESPACE,
17
+ MSG_PUBLISH_OK,
18
+ MSG_REQUEST_ERROR,
19
+ MSG_REQUEST_OK,
20
+ MSG_REQUEST_UPDATE,
21
+ MSG_SETUP,
22
+ MSG_SUBSCRIBE,
23
+ MSG_SUBSCRIBE_NAMESPACE,
24
+ MSG_SUBSCRIBE_OK,
25
+ MSG_TRACK_STATUS,
26
+ SETUP_OPT_AUTHORITY,
27
+ SETUP_OPT_AUTHORIZATION_TOKEN,
28
+ SETUP_OPT_MAX_AUTH_TOKEN_CACHE_SIZE,
29
+ SETUP_OPT_MOQT_IMPLEMENTATION,
30
+ SETUP_OPT_PATH,
31
+ } from './messages.js'
32
+ import type {
33
+ AuthorizationToken,
34
+ DatagramObject,
35
+ DataStreamEvent,
36
+ Draft17DataStream,
37
+ Draft17Fetch,
38
+ Draft17Message,
39
+ Draft17Params,
40
+ Draft17SetupOptions,
41
+ Draft17TrackProperties,
42
+ FetchStream,
43
+ FetchStreamHeader,
44
+ JoiningFetch,
45
+ ObjectPayload,
46
+ StandaloneFetch,
47
+ SubgroupStream,
48
+ SubgroupStreamHeader,
49
+ UnknownParam,
50
+ } from './types.js'
51
+
52
+ const textEncoder = /* @__PURE__ */ new TextEncoder()
53
+ const textDecoder = /* @__PURE__ */ new TextDecoder()
54
+
55
+ // ─── Setup Options Encoding/Decoding (KVP, no count prefix) ─────────────────
56
+
57
+ function encodeSetupOptions(opts: Draft17SetupOptions, writer: BufferWriter): void {
58
+ // Collect all options sorted by type ID
59
+ const entries: Array<{ type: bigint; encode: (w: BufferWriter) => void }> = []
60
+
61
+ if (opts.path !== undefined) {
62
+ entries.push({
63
+ type: SETUP_OPT_PATH,
64
+ encode: (w) => {
65
+ const encoded = textEncoder.encode(opts.path!)
66
+ w.writeVarInt(BigInt(encoded.byteLength))
67
+ w.writeBytes(encoded)
68
+ },
69
+ })
70
+ }
71
+ if (opts.authorization_token !== undefined) {
72
+ entries.push({
73
+ type: SETUP_OPT_AUTHORIZATION_TOKEN,
74
+ encode: (w) => {
75
+ const tmpW = new BufferWriter(64)
76
+ encodeAuthorizationToken(opts.authorization_token!, tmpW)
77
+ const raw = tmpW.finish()
78
+ w.writeVarInt(BigInt(raw.byteLength))
79
+ w.writeBytes(raw)
80
+ },
81
+ })
82
+ }
83
+ if (opts.max_auth_token_cache_size !== undefined) {
84
+ entries.push({
85
+ type: SETUP_OPT_MAX_AUTH_TOKEN_CACHE_SIZE,
86
+ encode: (w) => w.writeVarInt(opts.max_auth_token_cache_size!),
87
+ })
88
+ }
89
+ if (opts.authority !== undefined) {
90
+ entries.push({
91
+ type: SETUP_OPT_AUTHORITY,
92
+ encode: (w) => {
93
+ const encoded = textEncoder.encode(opts.authority!)
94
+ w.writeVarInt(BigInt(encoded.byteLength))
95
+ w.writeBytes(encoded)
96
+ },
97
+ })
98
+ }
99
+ if (opts.moqt_implementation !== undefined) {
100
+ entries.push({
101
+ type: SETUP_OPT_MOQT_IMPLEMENTATION,
102
+ encode: (w) => {
103
+ const encoded = textEncoder.encode(opts.moqt_implementation!)
104
+ w.writeVarInt(BigInt(encoded.byteLength))
105
+ w.writeBytes(encoded)
106
+ },
107
+ })
108
+ }
109
+ if (opts.unknown) {
110
+ for (const u of opts.unknown) {
111
+ const id = BigInt(u.id)
112
+ entries.push({
113
+ type: id,
114
+ encode: (w) => {
115
+ if (id % 2n === 0n) {
116
+ const raw = hexToBytes(u.raw_hex)
117
+ const tmpReader = new BufferReader(raw)
118
+ w.writeVarInt(tmpReader.readVarInt())
119
+ } else {
120
+ const raw = hexToBytes(u.raw_hex)
121
+ w.writeVarInt(BigInt(raw.byteLength))
122
+ w.writeBytes(raw)
123
+ }
124
+ },
125
+ })
126
+ }
127
+ }
128
+
129
+ // Sort by type (ascending) and write with delta encoding
130
+ entries.sort((a, b) => (a.type < b.type ? -1 : a.type > b.type ? 1 : 0))
131
+ let prevType = 0n
132
+ for (const entry of entries) {
133
+ writer.writeVarInt(entry.type - prevType)
134
+ entry.encode(writer)
135
+ prevType = entry.type
136
+ }
137
+ }
138
+
139
+ function decodeSetupOptions(reader: BufferReader, payloadEnd: number): Draft17SetupOptions {
140
+ const result: Draft17SetupOptions = {}
141
+ const unknown: UnknownParam[] = []
142
+ let prevType = 0n
143
+
144
+ while (reader.offset < payloadEnd) {
145
+ const delta = reader.readVarInt()
146
+ const optType = prevType + delta
147
+ prevType = optType
148
+
149
+ if (optType % 2n === 0n) {
150
+ // Even: single varint value
151
+ const value = reader.readVarInt()
152
+ if (optType === SETUP_OPT_MAX_AUTH_TOKEN_CACHE_SIZE) {
153
+ result.max_auth_token_cache_size = value
154
+ } else {
155
+ const tmpWriter = new BufferWriter(16)
156
+ tmpWriter.writeVarInt(value)
157
+ const raw = tmpWriter.finish()
158
+ unknown.push({
159
+ id: `0x${optType.toString(16)}`,
160
+ length: raw.byteLength,
161
+ raw_hex: bytesToHex(raw),
162
+ })
163
+ }
164
+ } else {
165
+ // Odd: length-prefixed bytes
166
+ const length = Number(reader.readVarInt())
167
+ const bytes = reader.readBytes(length)
168
+ if (optType === SETUP_OPT_PATH) {
169
+ result.path = textDecoder.decode(bytes)
170
+ } else if (optType === SETUP_OPT_AUTHORIZATION_TOKEN) {
171
+ result.authorization_token = decodeAuthorizationToken(new BufferReader(bytes))
172
+ } else if (optType === SETUP_OPT_AUTHORITY) {
173
+ result.authority = textDecoder.decode(bytes)
174
+ } else if (optType === SETUP_OPT_MOQT_IMPLEMENTATION) {
175
+ result.moqt_implementation = textDecoder.decode(bytes)
176
+ } else {
177
+ unknown.push({
178
+ id: `0x${optType.toString(16)}`,
179
+ length,
180
+ raw_hex: bytesToHex(bytes),
181
+ })
182
+ }
183
+ }
184
+ }
185
+
186
+ if (unknown.length > 0) result.unknown = unknown
187
+ return result
188
+ }
189
+
190
+ // ─── Authorization Token Encoding/Decoding ────────────────────────────────────
191
+
192
+ function encodeAuthorizationToken(token: AuthorizationToken, w: BufferWriter): void {
193
+ const aliasType = Number(token.alias_type)
194
+ w.writeVarInt(token.alias_type)
195
+ if (aliasType === 0 || aliasType === 1 || aliasType === 2) {
196
+ // DELETE, REGISTER, USE_ALIAS: token_alias present
197
+ w.writeVarInt(token.token_alias ?? 0n)
198
+ }
199
+ if (aliasType === 1 || aliasType === 3) {
200
+ // REGISTER, USE_VALUE: token_type + token_value present
201
+ w.writeVarInt(token.token_type ?? 0n)
202
+ const encoded = textEncoder.encode(token.token_value ?? '')
203
+ w.writeVarInt(BigInt(encoded.byteLength))
204
+ w.writeBytes(encoded)
205
+ }
206
+ }
207
+
208
+ function decodeAuthorizationToken(r: BufferReader): AuthorizationToken {
209
+ const alias_type = r.readVarInt()
210
+ const aliasType = Number(alias_type)
211
+ const result: AuthorizationToken = { alias_type }
212
+
213
+ if (aliasType === 0 || aliasType === 1 || aliasType === 2) {
214
+ ;(result as { token_alias: bigint }).token_alias = r.readVarInt()
215
+ }
216
+ if (aliasType === 1 || aliasType === 3) {
217
+ ;(result as { token_type: bigint }).token_type = r.readVarInt()
218
+ const len = Number(r.readVarInt())
219
+ const bytes = r.readBytes(len)
220
+ ;(result as { token_value: string }).token_value = textDecoder.decode(bytes)
221
+ }
222
+
223
+ return result
224
+ }
225
+
226
+ // ─── Message Parameter Encoding/Decoding (delta types, count prefix) ─────────
227
+
228
+ const PARAM_DELIVERY_TIMEOUT = 0x02n
229
+ const PARAM_AUTHORIZATION_TOKEN = 0x03n
230
+ const PARAM_RENDEZVOUS_TIMEOUT = 0x04n
231
+ const PARAM_EXPIRES = 0x08n
232
+ const PARAM_LARGEST_OBJECT = 0x09n
233
+ const PARAM_FORWARD = 0x10n
234
+ const PARAM_SUBSCRIBER_PRIORITY = 0x20n
235
+ const PARAM_SUBSCRIPTION_FILTER = 0x21n
236
+ const PARAM_GROUP_ORDER = 0x22n
237
+ const PARAM_NEW_GROUP_REQUEST = 0x32n
238
+
239
+ function encodeParams(params: Draft17Params, writer: BufferWriter): void {
240
+ // Collect and sort params by type
241
+ const entries: Array<{ type: bigint; encode: (w: BufferWriter) => void }> = []
242
+
243
+ if (params.delivery_timeout !== undefined) {
244
+ entries.push({
245
+ type: PARAM_DELIVERY_TIMEOUT,
246
+ encode: (w) => w.writeVarInt(params.delivery_timeout!),
247
+ })
248
+ }
249
+ if (params.authorization_token !== undefined) {
250
+ entries.push({
251
+ type: PARAM_AUTHORIZATION_TOKEN,
252
+ encode: (w) => {
253
+ const tmpW = new BufferWriter(64)
254
+ encodeAuthorizationToken(params.authorization_token!, tmpW)
255
+ const raw = tmpW.finish()
256
+ w.writeVarInt(BigInt(raw.byteLength))
257
+ w.writeBytes(raw)
258
+ },
259
+ })
260
+ }
261
+ if (params.rendezvous_timeout !== undefined) {
262
+ entries.push({
263
+ type: PARAM_RENDEZVOUS_TIMEOUT,
264
+ encode: (w) => w.writeVarInt(params.rendezvous_timeout!),
265
+ })
266
+ }
267
+ if (params.expires !== undefined) {
268
+ entries.push({
269
+ type: PARAM_EXPIRES,
270
+ encode: (w) => w.writeVarInt(params.expires!),
271
+ })
272
+ }
273
+ if (params.largest_object !== undefined) {
274
+ entries.push({
275
+ type: PARAM_LARGEST_OBJECT,
276
+ encode: (w) => {
277
+ w.writeVarInt(params.largest_object!.group)
278
+ w.writeVarInt(params.largest_object!.object)
279
+ },
280
+ })
281
+ }
282
+ if (params.forward !== undefined) {
283
+ entries.push({
284
+ type: PARAM_FORWARD,
285
+ encode: (w) => w.writeVarInt(params.forward!),
286
+ })
287
+ }
288
+ if (params.subscriber_priority !== undefined) {
289
+ entries.push({
290
+ type: PARAM_SUBSCRIBER_PRIORITY,
291
+ encode: (w) => w.writeUint8(Number(params.subscriber_priority!)),
292
+ })
293
+ }
294
+ if (params.subscription_filter !== undefined) {
295
+ entries.push({
296
+ type: PARAM_SUBSCRIPTION_FILTER,
297
+ encode: (w) => {
298
+ const f = params.subscription_filter!
299
+ const tmpW = new BufferWriter(32)
300
+ tmpW.writeVarInt(f.filter_type)
301
+ if (f.filter_type === 3n || f.filter_type === 4n) {
302
+ tmpW.writeVarInt(f.start_group!)
303
+ tmpW.writeVarInt(f.start_object!)
304
+ }
305
+ if (f.filter_type === 4n) {
306
+ tmpW.writeVarInt(f.end_group!)
307
+ }
308
+ const raw = tmpW.finish()
309
+ w.writeVarInt(BigInt(raw.byteLength))
310
+ w.writeBytes(raw)
311
+ },
312
+ })
313
+ }
314
+ if (params.group_order !== undefined) {
315
+ entries.push({
316
+ type: PARAM_GROUP_ORDER,
317
+ encode: (w) => w.writeUint8(Number(params.group_order!)),
318
+ })
319
+ }
320
+ if (params.new_group_request !== undefined) {
321
+ entries.push({
322
+ type: PARAM_NEW_GROUP_REQUEST,
323
+ encode: (w) => w.writeVarInt(params.new_group_request!),
324
+ })
325
+ }
326
+
327
+ // Unknown params
328
+ if (params.unknown) {
329
+ for (const u of params.unknown) {
330
+ const id = BigInt(u.id)
331
+ entries.push({
332
+ type: id,
333
+ encode: (w) => {
334
+ const raw = hexToBytes(u.raw_hex)
335
+ // For unknown params, we store raw bytes and re-emit them
336
+ w.writeBytes(raw)
337
+ },
338
+ })
339
+ }
340
+ }
341
+
342
+ entries.sort((a, b) => (a.type < b.type ? -1 : a.type > b.type ? 1 : 0))
343
+
344
+ writer.writeVarInt(BigInt(entries.length))
345
+ let prevType = 0n
346
+ for (const entry of entries) {
347
+ writer.writeVarInt(entry.type - prevType)
348
+ entry.encode(writer)
349
+ prevType = entry.type
350
+ }
351
+ }
352
+
353
+ function decodeParams(reader: BufferReader): Draft17Params {
354
+ const count = Number(reader.readVarInt())
355
+ const result: Draft17Params = {}
356
+ const unknown: UnknownParam[] = []
357
+ let prevType = 0n
358
+
359
+ for (let i = 0; i < count; i++) {
360
+ const delta = reader.readVarInt()
361
+ const paramType = prevType + delta
362
+ prevType = paramType
363
+
364
+ if (paramType === PARAM_DELIVERY_TIMEOUT) {
365
+ result.delivery_timeout = reader.readVarInt()
366
+ } else if (paramType === PARAM_AUTHORIZATION_TOKEN) {
367
+ const length = Number(reader.readVarInt())
368
+ const bytes = reader.readBytes(length)
369
+ result.authorization_token = decodeAuthorizationToken(new BufferReader(bytes))
370
+ } else if (paramType === PARAM_RENDEZVOUS_TIMEOUT) {
371
+ result.rendezvous_timeout = reader.readVarInt()
372
+ } else if (paramType === PARAM_EXPIRES) {
373
+ result.expires = reader.readVarInt()
374
+ } else if (paramType === PARAM_LARGEST_OBJECT) {
375
+ // Location: 2 bare varints (not length-prefixed)
376
+ const group = reader.readVarInt()
377
+ const object = reader.readVarInt()
378
+ result.largest_object = { group, object }
379
+ } else if (paramType === PARAM_SUBSCRIBER_PRIORITY) {
380
+ // uint8: single raw byte
381
+ result.subscriber_priority = BigInt(reader.readUint8())
382
+ } else if (paramType === PARAM_SUBSCRIPTION_FILTER) {
383
+ // Length-prefixed
384
+ const length = Number(reader.readVarInt())
385
+ const startOff = reader.offset
386
+ const filter_type = reader.readVarInt()
387
+ const filter: {
388
+ filter_type: bigint
389
+ start_group?: bigint
390
+ start_object?: bigint
391
+ end_group?: bigint
392
+ } = { filter_type }
393
+ if (filter_type === 3n || filter_type === 4n) {
394
+ filter.start_group = reader.readVarInt()
395
+ filter.start_object = reader.readVarInt()
396
+ }
397
+ if (filter_type === 4n) {
398
+ filter.end_group = reader.readVarInt()
399
+ }
400
+ const consumed = reader.offset - startOff
401
+ if (consumed < length) reader.readBytes(length - consumed)
402
+ result.subscription_filter = filter
403
+ } else if (paramType === PARAM_FORWARD) {
404
+ result.forward = reader.readVarInt()
405
+ } else if (paramType === PARAM_GROUP_ORDER) {
406
+ // uint8: single raw byte
407
+ result.group_order = BigInt(reader.readUint8())
408
+ } else if (paramType === PARAM_NEW_GROUP_REQUEST) {
409
+ result.new_group_request = reader.readVarInt()
410
+ } else {
411
+ // Unknown parameter — we don't know the encoding, protocol violation per spec
412
+ // But for robustness, attempt even/odd heuristic
413
+ if (paramType % 2n === 0n) {
414
+ const value = reader.readVarInt()
415
+ const tmpWriter = new BufferWriter(16)
416
+ tmpWriter.writeVarInt(value)
417
+ const raw = tmpWriter.finish()
418
+ unknown.push({
419
+ id: `0x${paramType.toString(16)}`,
420
+ length: raw.byteLength,
421
+ raw_hex: bytesToHex(raw),
422
+ })
423
+ } else {
424
+ const length = Number(reader.readVarInt())
425
+ const bytes = reader.readBytes(length)
426
+ unknown.push({
427
+ id: `0x${paramType.toString(16)}`,
428
+ length,
429
+ raw_hex: bytesToHex(bytes),
430
+ })
431
+ }
432
+ }
433
+ }
434
+
435
+ if (unknown.length > 0) result.unknown = unknown
436
+ return result
437
+ }
438
+
439
+ // ─── Track Properties Encoding/Decoding (KVP, no count prefix) ──────────────
440
+
441
+ const TPROP_DELIVERY_TIMEOUT = 0x02n
442
+ const TPROP_MAX_CACHE_DURATION = 0x04n
443
+ const TPROP_IMMUTABLE_PROPERTIES = 0x0bn
444
+ const TPROP_DEFAULT_PUBLISHER_PRIORITY = 0x0en
445
+ const TPROP_DEFAULT_PUBLISHER_GROUP_ORDER = 0x22n
446
+ const TPROP_DYNAMIC_GROUPS = 0x30n
447
+
448
+ function encodeTrackProperties(props: Draft17TrackProperties, writer: BufferWriter): void {
449
+ const entries: Array<{ type: bigint; encode: (w: BufferWriter) => void }> = []
450
+
451
+ if (props.delivery_timeout !== undefined) {
452
+ entries.push({
453
+ type: TPROP_DELIVERY_TIMEOUT,
454
+ encode: (w) => w.writeVarInt(props.delivery_timeout!),
455
+ })
456
+ }
457
+ if (props.max_cache_duration !== undefined) {
458
+ entries.push({
459
+ type: TPROP_MAX_CACHE_DURATION,
460
+ encode: (w) => w.writeVarInt(props.max_cache_duration!),
461
+ })
462
+ }
463
+ if (props.immutable_properties !== undefined) {
464
+ entries.push({
465
+ type: TPROP_IMMUTABLE_PROPERTIES,
466
+ encode: (w) => {
467
+ const raw = hexToBytes(props.immutable_properties!)
468
+ w.writeVarInt(BigInt(raw.byteLength))
469
+ w.writeBytes(raw)
470
+ },
471
+ })
472
+ }
473
+ if (props.default_publisher_priority !== undefined) {
474
+ entries.push({
475
+ type: TPROP_DEFAULT_PUBLISHER_PRIORITY,
476
+ encode: (w) => w.writeVarInt(props.default_publisher_priority!),
477
+ })
478
+ }
479
+ if (props.default_publisher_group_order !== undefined) {
480
+ entries.push({
481
+ type: TPROP_DEFAULT_PUBLISHER_GROUP_ORDER,
482
+ encode: (w) => w.writeVarInt(props.default_publisher_group_order!),
483
+ })
484
+ }
485
+ if (props.dynamic_groups !== undefined) {
486
+ entries.push({
487
+ type: TPROP_DYNAMIC_GROUPS,
488
+ encode: (w) => w.writeVarInt(props.dynamic_groups!),
489
+ })
490
+ }
491
+
492
+ if (props.unknown) {
493
+ for (const u of props.unknown) {
494
+ const id = BigInt(u.id)
495
+ entries.push({
496
+ type: id,
497
+ encode: (w) => {
498
+ if (id % 2n === 0n) {
499
+ const raw = hexToBytes(u.raw_hex)
500
+ const tmpReader = new BufferReader(raw)
501
+ w.writeVarInt(tmpReader.readVarInt())
502
+ } else {
503
+ const raw = hexToBytes(u.raw_hex)
504
+ w.writeVarInt(BigInt(raw.byteLength))
505
+ w.writeBytes(raw)
506
+ }
507
+ },
508
+ })
509
+ }
510
+ }
511
+
512
+ entries.sort((a, b) => (a.type < b.type ? -1 : a.type > b.type ? 1 : 0))
513
+
514
+ let prevType = 0n
515
+ for (const entry of entries) {
516
+ writer.writeVarInt(entry.type - prevType)
517
+ entry.encode(writer)
518
+ prevType = entry.type
519
+ }
520
+ }
521
+
522
+ function decodeTrackProperties(reader: BufferReader, payloadEnd: number): Draft17TrackProperties {
523
+ const result: Draft17TrackProperties = {}
524
+ const unknown: UnknownParam[] = []
525
+ let prevType = 0n
526
+
527
+ while (reader.offset < payloadEnd) {
528
+ const delta = reader.readVarInt()
529
+ const propType = prevType + delta
530
+ prevType = propType
531
+
532
+ if (propType % 2n === 0n) {
533
+ // Even: single varint value
534
+ const value = reader.readVarInt()
535
+ if (propType === TPROP_DELIVERY_TIMEOUT) {
536
+ result.delivery_timeout = value
537
+ } else if (propType === TPROP_MAX_CACHE_DURATION) {
538
+ result.max_cache_duration = value
539
+ } else if (propType === TPROP_DEFAULT_PUBLISHER_PRIORITY) {
540
+ result.default_publisher_priority = value
541
+ } else if (propType === TPROP_DEFAULT_PUBLISHER_GROUP_ORDER) {
542
+ result.default_publisher_group_order = value
543
+ } else if (propType === TPROP_DYNAMIC_GROUPS) {
544
+ result.dynamic_groups = value
545
+ } else {
546
+ const tmpWriter = new BufferWriter(16)
547
+ tmpWriter.writeVarInt(value)
548
+ const raw = tmpWriter.finish()
549
+ unknown.push({
550
+ id: `0x${propType.toString(16)}`,
551
+ length: raw.byteLength,
552
+ raw_hex: bytesToHex(raw),
553
+ })
554
+ }
555
+ } else {
556
+ // Odd: length-prefixed bytes
557
+ const length = Number(reader.readVarInt())
558
+ const bytes = reader.readBytes(length)
559
+ if (propType === TPROP_IMMUTABLE_PROPERTIES) {
560
+ result.immutable_properties = bytesToHex(bytes)
561
+ } else {
562
+ unknown.push({
563
+ id: `0x${propType.toString(16)}`,
564
+ length,
565
+ raw_hex: bytesToHex(bytes),
566
+ })
567
+ }
568
+ }
569
+ }
570
+
571
+ if (unknown.length > 0) result.unknown = unknown
572
+ return result
573
+ }
574
+
575
+ // ─── Payload Encoders ──────────────────────────────────────────────────────────
576
+
577
+ function encodeSetupPayload(msg: Draft17Message & { type: 'setup' }, w: BufferWriter): void {
578
+ encodeSetupOptions(msg.options, w)
579
+ }
580
+
581
+ function encodeSubscribePayload(
582
+ msg: Draft17Message & { type: 'subscribe' },
583
+ w: BufferWriter,
584
+ ): void {
585
+ w.writeVarInt(msg.request_id)
586
+ w.writeVarInt(msg.required_request_id_delta)
587
+ w.writeTuple(msg.track_namespace)
588
+ w.writeString(msg.track_name)
589
+ encodeParams(msg.parameters, w)
590
+ }
591
+
592
+ function encodeSubscribeOkPayload(
593
+ msg: Draft17Message & { type: 'subscribe_ok' },
594
+ w: BufferWriter,
595
+ ): void {
596
+ w.writeVarInt(msg.track_alias)
597
+ encodeParams(msg.parameters, w)
598
+ encodeTrackProperties(msg.track_properties, w)
599
+ }
600
+
601
+ function encodeRequestUpdatePayload(
602
+ msg: Draft17Message & { type: 'request_update' },
603
+ w: BufferWriter,
604
+ ): void {
605
+ w.writeVarInt(msg.request_id)
606
+ w.writeVarInt(msg.required_request_id_delta)
607
+ encodeParams(msg.parameters, w)
608
+ }
609
+
610
+ function encodePublishPayload(msg: Draft17Message & { type: 'publish' }, w: BufferWriter): void {
611
+ w.writeVarInt(msg.request_id)
612
+ w.writeVarInt(msg.required_request_id_delta)
613
+ w.writeTuple(msg.track_namespace)
614
+ w.writeString(msg.track_name)
615
+ w.writeVarInt(msg.track_alias)
616
+ encodeParams(msg.parameters, w)
617
+ encodeTrackProperties(msg.track_properties, w)
618
+ }
619
+
620
+ function encodePublishOkPayload(
621
+ msg: Draft17Message & { type: 'publish_ok' },
622
+ w: BufferWriter,
623
+ ): void {
624
+ encodeParams(msg.parameters, w)
625
+ }
626
+
627
+ function encodePublishDonePayload(
628
+ msg: Draft17Message & { type: 'publish_done' },
629
+ w: BufferWriter,
630
+ ): void {
631
+ w.writeVarInt(msg.status_code)
632
+ w.writeVarInt(msg.stream_count)
633
+ w.writeString(msg.reason_phrase)
634
+ }
635
+
636
+ function encodePublishNamespacePayload(
637
+ msg: Draft17Message & { type: 'publish_namespace' },
638
+ w: BufferWriter,
639
+ ): void {
640
+ w.writeVarInt(msg.request_id)
641
+ w.writeVarInt(msg.required_request_id_delta)
642
+ w.writeTuple(msg.track_namespace)
643
+ encodeParams(msg.parameters, w)
644
+ }
645
+
646
+ function encodeNamespacePayload(
647
+ msg: Draft17Message & { type: 'namespace' },
648
+ w: BufferWriter,
649
+ ): void {
650
+ w.writeTuple(msg.namespace_suffix)
651
+ }
652
+
653
+ function encodeNamespaceDonePayload(
654
+ msg: Draft17Message & { type: 'namespace_done' },
655
+ w: BufferWriter,
656
+ ): void {
657
+ w.writeTuple(msg.namespace_suffix)
658
+ }
659
+
660
+ function encodeSubscribeNamespacePayload(
661
+ msg: Draft17Message & { type: 'subscribe_namespace' },
662
+ w: BufferWriter,
663
+ ): void {
664
+ w.writeVarInt(msg.request_id)
665
+ w.writeVarInt(msg.required_request_id_delta)
666
+ w.writeTuple(msg.namespace_prefix)
667
+ w.writeVarInt(msg.subscribe_options)
668
+ encodeParams(msg.parameters, w)
669
+ }
670
+
671
+ function encodePublishBlockedPayload(
672
+ msg: Draft17Message & { type: 'publish_blocked' },
673
+ w: BufferWriter,
674
+ ): void {
675
+ w.writeTuple(msg.namespace_suffix)
676
+ w.writeString(msg.track_name)
677
+ }
678
+
679
+ function encodeFetchPayload(msg: Draft17Message & { type: 'fetch' }, w: BufferWriter): void {
680
+ w.writeVarInt(msg.request_id)
681
+ w.writeVarInt(msg.required_request_id_delta)
682
+ w.writeVarInt(msg.fetch_type)
683
+ const ft = Number(msg.fetch_type)
684
+ if (ft === 1 && msg.standalone) {
685
+ w.writeTuple(msg.standalone.track_namespace)
686
+ w.writeString(msg.standalone.track_name)
687
+ w.writeVarInt(msg.standalone.start_group)
688
+ w.writeVarInt(msg.standalone.start_object)
689
+ w.writeVarInt(msg.standalone.end_group)
690
+ w.writeVarInt(msg.standalone.end_object)
691
+ } else if ((ft === 2 || ft === 3) && msg.joining) {
692
+ w.writeVarInt(msg.joining.joining_request_id)
693
+ w.writeVarInt(msg.joining.joining_start)
694
+ }
695
+ encodeParams(msg.parameters, w)
696
+ }
697
+
698
+ function encodeFetchOkPayload(msg: Draft17Message & { type: 'fetch_ok' }, w: BufferWriter): void {
699
+ w.writeUint8(msg.end_of_track)
700
+ w.writeVarInt(msg.end_group)
701
+ w.writeVarInt(msg.end_object)
702
+ encodeParams(msg.parameters, w)
703
+ encodeTrackProperties(msg.track_properties, w)
704
+ }
705
+
706
+ function encodeTrackStatusPayload(
707
+ msg: Draft17Message & { type: 'track_status' },
708
+ w: BufferWriter,
709
+ ): void {
710
+ w.writeVarInt(msg.request_id)
711
+ w.writeVarInt(msg.required_request_id_delta)
712
+ w.writeTuple(msg.track_namespace)
713
+ w.writeString(msg.track_name)
714
+ encodeParams(msg.parameters, w)
715
+ }
716
+
717
+ function encodeRequestOkPayload(
718
+ msg: Draft17Message & { type: 'request_ok' },
719
+ w: BufferWriter,
720
+ ): void {
721
+ encodeParams(msg.parameters, w)
722
+ }
723
+
724
+ function encodeRequestErrorPayload(
725
+ msg: Draft17Message & { type: 'request_error' },
726
+ w: BufferWriter,
727
+ ): void {
728
+ w.writeVarInt(msg.error_code)
729
+ w.writeVarInt(msg.retry_interval)
730
+ w.writeString(msg.reason_phrase)
731
+ }
732
+
733
+ function encodeGoAwayPayload(msg: Draft17Message & { type: 'goaway' }, w: BufferWriter): void {
734
+ w.writeString(msg.new_session_uri)
735
+ w.writeVarInt(msg.timeout)
736
+ }
737
+
738
+ // ─── Payload Decoders ──────────────────────────────────────────────────────────
739
+
740
+ function decodeSetupPayload(r: BufferReader, payloadEnd: number): Draft17Message {
741
+ const options = decodeSetupOptions(r, payloadEnd)
742
+ return { type: 'setup', options }
743
+ }
744
+
745
+ function decodeSubscribePayload(r: BufferReader): Draft17Message {
746
+ const request_id = r.readVarInt()
747
+ const required_request_id_delta = r.readVarInt()
748
+ const track_namespace = r.readTuple()
749
+ const track_name = r.readString()
750
+ const parameters = decodeParams(r)
751
+ return {
752
+ type: 'subscribe',
753
+ request_id,
754
+ required_request_id_delta,
755
+ track_namespace,
756
+ track_name,
757
+ parameters,
758
+ }
759
+ }
760
+
761
+ function decodeSubscribeOkPayload(r: BufferReader, payloadEnd: number): Draft17Message {
762
+ const track_alias = r.readVarInt()
763
+ const parameters = decodeParams(r)
764
+ const track_properties = decodeTrackProperties(r, payloadEnd)
765
+ return { type: 'subscribe_ok', track_alias, parameters, track_properties }
766
+ }
767
+
768
+ function decodeRequestUpdatePayload(r: BufferReader): Draft17Message {
769
+ const request_id = r.readVarInt()
770
+ const required_request_id_delta = r.readVarInt()
771
+ const parameters = decodeParams(r)
772
+ return {
773
+ type: 'request_update',
774
+ request_id,
775
+ required_request_id_delta,
776
+ parameters,
777
+ }
778
+ }
779
+
780
+ function decodePublishPayload(r: BufferReader, payloadEnd: number): Draft17Message {
781
+ const request_id = r.readVarInt()
782
+ const required_request_id_delta = r.readVarInt()
783
+ const track_namespace = r.readTuple()
784
+ const track_name = r.readString()
785
+ const track_alias = r.readVarInt()
786
+ const parameters = decodeParams(r)
787
+ const track_properties = decodeTrackProperties(r, payloadEnd)
788
+ return {
789
+ type: 'publish',
790
+ request_id,
791
+ required_request_id_delta,
792
+ track_namespace,
793
+ track_name,
794
+ track_alias,
795
+ parameters,
796
+ track_properties,
797
+ }
798
+ }
799
+
800
+ function decodePublishOkPayload(r: BufferReader): Draft17Message {
801
+ const parameters = decodeParams(r)
802
+ return { type: 'publish_ok', parameters }
803
+ }
804
+
805
+ function decodePublishDonePayload(r: BufferReader): Draft17Message {
806
+ const status_code = r.readVarInt()
807
+ const stream_count = r.readVarInt()
808
+ const reason_phrase = r.readString()
809
+ return { type: 'publish_done', status_code, stream_count, reason_phrase }
810
+ }
811
+
812
+ function decodePublishNamespacePayload(r: BufferReader): Draft17Message {
813
+ const request_id = r.readVarInt()
814
+ const required_request_id_delta = r.readVarInt()
815
+ const track_namespace = r.readTuple()
816
+ const parameters = decodeParams(r)
817
+ return {
818
+ type: 'publish_namespace',
819
+ request_id,
820
+ required_request_id_delta,
821
+ track_namespace,
822
+ parameters,
823
+ }
824
+ }
825
+
826
+ function decodeNamespacePayload(r: BufferReader): Draft17Message {
827
+ const namespace_suffix = r.readTuple()
828
+ return { type: 'namespace', namespace_suffix }
829
+ }
830
+
831
+ function decodeNamespaceDonePayload(r: BufferReader): Draft17Message {
832
+ const namespace_suffix = r.readTuple()
833
+ return { type: 'namespace_done', namespace_suffix }
834
+ }
835
+
836
+ function decodeSubscribeNamespacePayload(r: BufferReader): Draft17Message {
837
+ const request_id = r.readVarInt()
838
+ const required_request_id_delta = r.readVarInt()
839
+ const namespace_prefix = r.readTuple()
840
+ const subscribe_options = r.readVarInt()
841
+ const parameters = decodeParams(r)
842
+ return {
843
+ type: 'subscribe_namespace',
844
+ request_id,
845
+ required_request_id_delta,
846
+ namespace_prefix,
847
+ subscribe_options,
848
+ parameters,
849
+ }
850
+ }
851
+
852
+ function decodePublishBlockedPayload(r: BufferReader): Draft17Message {
853
+ const namespace_suffix = r.readTuple()
854
+ const track_name = r.readString()
855
+ return { type: 'publish_blocked', namespace_suffix, track_name }
856
+ }
857
+
858
+ function decodeFetchPayload(r: BufferReader): Draft17Message {
859
+ const request_id = r.readVarInt()
860
+ const required_request_id_delta = r.readVarInt()
861
+ const fetch_type = r.readVarInt()
862
+ const ft = Number(fetch_type)
863
+
864
+ if (ft < 1 || ft > 3) {
865
+ throw new DecodeError('CONSTRAINT_VIOLATION', `Invalid fetch_type: ${ft}`, r.offset)
866
+ }
867
+
868
+ let standalone: StandaloneFetch | undefined
869
+ let joining: JoiningFetch | undefined
870
+
871
+ if (ft === 1) {
872
+ const track_namespace = r.readTuple()
873
+ const track_name = r.readString()
874
+ const start_group = r.readVarInt()
875
+ const start_object = r.readVarInt()
876
+ const end_group = r.readVarInt()
877
+ const end_object = r.readVarInt()
878
+ standalone = {
879
+ track_namespace,
880
+ track_name,
881
+ start_group,
882
+ start_object,
883
+ end_group,
884
+ end_object,
885
+ }
886
+ } else {
887
+ const joining_request_id = r.readVarInt()
888
+ const joining_start = r.readVarInt()
889
+ joining = { joining_request_id, joining_start }
890
+ }
891
+
892
+ const parameters = decodeParams(r)
893
+
894
+ return {
895
+ type: 'fetch',
896
+ request_id,
897
+ required_request_id_delta,
898
+ fetch_type,
899
+ standalone,
900
+ joining,
901
+ parameters,
902
+ } as Draft17Fetch
903
+ }
904
+
905
+ function decodeFetchOkPayload(r: BufferReader, payloadEnd: number): Draft17Message {
906
+ const end_of_track = r.readUint8()
907
+ const end_group = r.readVarInt()
908
+ const end_object = r.readVarInt()
909
+ const parameters = decodeParams(r)
910
+ const track_properties = decodeTrackProperties(r, payloadEnd)
911
+ return {
912
+ type: 'fetch_ok',
913
+ end_of_track,
914
+ end_group,
915
+ end_object,
916
+ parameters,
917
+ track_properties,
918
+ }
919
+ }
920
+
921
+ function decodeTrackStatusPayload(r: BufferReader): Draft17Message {
922
+ const request_id = r.readVarInt()
923
+ const required_request_id_delta = r.readVarInt()
924
+ const track_namespace = r.readTuple()
925
+ const track_name = r.readString()
926
+ const parameters = decodeParams(r)
927
+ return {
928
+ type: 'track_status',
929
+ request_id,
930
+ required_request_id_delta,
931
+ track_namespace,
932
+ track_name,
933
+ parameters,
934
+ }
935
+ }
936
+
937
+ function decodeRequestOkPayload(r: BufferReader): Draft17Message {
938
+ const parameters = decodeParams(r)
939
+ return { type: 'request_ok', parameters }
940
+ }
941
+
942
+ function decodeRequestErrorPayload(r: BufferReader): Draft17Message {
943
+ const error_code = r.readVarInt()
944
+ const retry_interval = r.readVarInt()
945
+ const reason_phrase = r.readString()
946
+ return { type: 'request_error', error_code, retry_interval, reason_phrase }
947
+ }
948
+
949
+ function decodeGoAwayPayload(r: BufferReader): Draft17Message {
950
+ const new_session_uri = r.readString()
951
+ const timeout = r.readVarInt()
952
+ return { type: 'goaway', new_session_uri, timeout }
953
+ }
954
+
955
+ // ─── Public API ────────────────────────────────────────────────────────────────
956
+
957
+ /**
958
+ * Encode a draft-17 control message with type(varint) + length(uint16 BE) + payload.
959
+ */
960
+ export function encodeMessage(message: Draft17Message): Uint8Array {
961
+ const typeId = MESSAGE_ID_MAP.get(message.type)
962
+ if (typeId === undefined) {
963
+ throw new Error(`Unknown message type: ${message.type}`)
964
+ }
965
+
966
+ const payloadWriter = new BufferWriter()
967
+ encodePayload(message, payloadWriter)
968
+ const payload = payloadWriter.finishView()
969
+
970
+ if (payload.byteLength > 0xffff) {
971
+ throw new Error(`Payload too large for 16-bit length: ${payload.byteLength}`)
972
+ }
973
+
974
+ const writer = new BufferWriter(payload.byteLength + 16)
975
+ writer.writeVarInt(typeId)
976
+ writer.writeUint8((payload.byteLength >> 8) & 0xff)
977
+ writer.writeUint8(payload.byteLength & 0xff)
978
+ writer.writeBytes(payload)
979
+
980
+ return writer.finish()
981
+ }
982
+
983
+ function encodePayload(msg: Draft17Message, w: BufferWriter): void {
984
+ switch (msg.type) {
985
+ case 'setup':
986
+ return encodeSetupPayload(msg, w)
987
+ case 'subscribe':
988
+ return encodeSubscribePayload(msg, w)
989
+ case 'subscribe_ok':
990
+ return encodeSubscribeOkPayload(msg, w)
991
+ case 'request_update':
992
+ return encodeRequestUpdatePayload(msg, w)
993
+ case 'publish':
994
+ return encodePublishPayload(msg, w)
995
+ case 'publish_ok':
996
+ return encodePublishOkPayload(msg, w)
997
+ case 'publish_done':
998
+ return encodePublishDonePayload(msg, w)
999
+ case 'publish_namespace':
1000
+ return encodePublishNamespacePayload(msg, w)
1001
+ case 'namespace':
1002
+ return encodeNamespacePayload(msg, w)
1003
+ case 'namespace_done':
1004
+ return encodeNamespaceDonePayload(msg, w)
1005
+ case 'subscribe_namespace':
1006
+ return encodeSubscribeNamespacePayload(msg, w)
1007
+ case 'publish_blocked':
1008
+ return encodePublishBlockedPayload(msg, w)
1009
+ case 'fetch':
1010
+ return encodeFetchPayload(msg, w)
1011
+ case 'fetch_ok':
1012
+ return encodeFetchOkPayload(msg, w)
1013
+ case 'track_status':
1014
+ return encodeTrackStatusPayload(msg, w)
1015
+ case 'request_ok':
1016
+ return encodeRequestOkPayload(msg, w)
1017
+ case 'request_error':
1018
+ return encodeRequestErrorPayload(msg, w)
1019
+ case 'goaway':
1020
+ return encodeGoAwayPayload(msg, w)
1021
+ default: {
1022
+ const _exhaustive: never = msg
1023
+ throw new Error(`Unhandled message type: ${(_exhaustive as Draft17Message).type}`)
1024
+ }
1025
+ }
1026
+ }
1027
+
1028
+ /**
1029
+ * Decode a draft-17 control message from bytes (type + uint16 length + payload).
1030
+ */
1031
+ export function decodeMessage(bytes: Uint8Array): DecodeResult<Draft17Message> {
1032
+ try {
1033
+ const reader = new BufferReader(bytes)
1034
+ const typeId = reader.readVarInt()
1035
+
1036
+ const lenHi = reader.readUint8()
1037
+ const lenLo = reader.readUint8()
1038
+ const payloadLength = (lenHi << 8) | lenLo
1039
+
1040
+ const payloadStart = reader.offset
1041
+ const _payloadEnd = payloadStart + payloadLength
1042
+ const payloadBytes = reader.readBytes(payloadLength)
1043
+ const payloadReader = new BufferReader(payloadBytes)
1044
+
1045
+ let message: Draft17Message
1046
+
1047
+ if (typeId === MSG_SETUP) {
1048
+ message = decodeSetupPayload(payloadReader, payloadLength)
1049
+ } else if (typeId === MSG_SUBSCRIBE) {
1050
+ message = decodeSubscribePayload(payloadReader)
1051
+ } else if (typeId === MSG_SUBSCRIBE_OK) {
1052
+ message = decodeSubscribeOkPayload(payloadReader, payloadLength)
1053
+ } else if (typeId === MSG_REQUEST_UPDATE) {
1054
+ message = decodeRequestUpdatePayload(payloadReader)
1055
+ } else if (typeId === MSG_PUBLISH) {
1056
+ message = decodePublishPayload(payloadReader, payloadLength)
1057
+ } else if (typeId === MSG_PUBLISH_OK) {
1058
+ message = decodePublishOkPayload(payloadReader)
1059
+ } else if (typeId === MSG_PUBLISH_DONE) {
1060
+ message = decodePublishDonePayload(payloadReader)
1061
+ } else if (typeId === MSG_PUBLISH_NAMESPACE) {
1062
+ message = decodePublishNamespacePayload(payloadReader)
1063
+ } else if (typeId === MSG_NAMESPACE) {
1064
+ message = decodeNamespacePayload(payloadReader)
1065
+ } else if (typeId === MSG_NAMESPACE_DONE) {
1066
+ message = decodeNamespaceDonePayload(payloadReader)
1067
+ } else if (typeId === MSG_SUBSCRIBE_NAMESPACE) {
1068
+ message = decodeSubscribeNamespacePayload(payloadReader)
1069
+ } else if (typeId === MSG_PUBLISH_BLOCKED) {
1070
+ message = decodePublishBlockedPayload(payloadReader)
1071
+ } else if (typeId === MSG_FETCH) {
1072
+ message = decodeFetchPayload(payloadReader)
1073
+ } else if (typeId === MSG_FETCH_OK) {
1074
+ message = decodeFetchOkPayload(payloadReader, payloadLength)
1075
+ } else if (typeId === MSG_TRACK_STATUS) {
1076
+ message = decodeTrackStatusPayload(payloadReader)
1077
+ } else if (typeId === MSG_REQUEST_OK) {
1078
+ message = decodeRequestOkPayload(payloadReader)
1079
+ } else if (typeId === MSG_REQUEST_ERROR) {
1080
+ message = decodeRequestErrorPayload(payloadReader)
1081
+ } else if (typeId === MSG_GOAWAY) {
1082
+ message = decodeGoAwayPayload(payloadReader)
1083
+ } else {
1084
+ return {
1085
+ ok: false,
1086
+ error: new DecodeError(
1087
+ 'UNKNOWN_MESSAGE_TYPE',
1088
+ `Unknown message type ID: 0x${typeId.toString(16)}`,
1089
+ 0,
1090
+ ),
1091
+ }
1092
+ }
1093
+
1094
+ return { ok: true, value: message, bytesRead: reader.offset }
1095
+ } catch (e) {
1096
+ if (e instanceof DecodeError) {
1097
+ return { ok: false, error: e }
1098
+ }
1099
+ throw e
1100
+ }
1101
+ }
1102
+
1103
+ // ─── Data Stream Encoding/Decoding (re-exported from data-streams.ts) ───────
1104
+
1105
+ import {
1106
+ createDataStreamDecoder,
1107
+ createFetchStreamDecoder,
1108
+ createSubgroupStreamDecoder,
1109
+ decodeDatagram,
1110
+ decodeDataStream,
1111
+ decodeFetchStream,
1112
+ decodeSubgroupStream,
1113
+ encodeDatagram,
1114
+ encodeFetchStream,
1115
+ encodeSubgroupStream,
1116
+ } from './data-streams.js'
1117
+
1118
+ export {
1119
+ createDataStreamDecoder,
1120
+ createFetchStreamDecoder,
1121
+ createSubgroupStreamDecoder,
1122
+ decodeDatagram,
1123
+ decodeDataStream,
1124
+ decodeFetchStream,
1125
+ decodeSubgroupStream,
1126
+ encodeDatagram,
1127
+ encodeFetchStream,
1128
+ encodeSubgroupStream,
1129
+ }
1130
+
1131
+ // ─── Stream Decoders ───────────────────────────────────────────────────────────
1132
+
1133
+ export function createStreamDecoder(): TransformStream<Uint8Array, Draft17Message> {
1134
+ let buffer = new Uint8Array(0)
1135
+ let offset = 0
1136
+
1137
+ return new TransformStream<Uint8Array, Draft17Message>({
1138
+ transform(chunk, controller) {
1139
+ if (offset > 0) {
1140
+ buffer = buffer.subarray(offset)
1141
+ offset = 0
1142
+ }
1143
+ const newBuffer = new Uint8Array(buffer.length + chunk.length)
1144
+ newBuffer.set(buffer, 0)
1145
+ newBuffer.set(chunk, buffer.length)
1146
+ buffer = newBuffer
1147
+
1148
+ while (offset < buffer.length) {
1149
+ const result = decodeMessage(buffer.subarray(offset))
1150
+ if (!result.ok) {
1151
+ if (result.error.code === 'UNEXPECTED_END') {
1152
+ break
1153
+ }
1154
+ controller.error(result.error)
1155
+ return
1156
+ }
1157
+ controller.enqueue(result.value)
1158
+ offset += result.bytesRead
1159
+ }
1160
+ },
1161
+
1162
+ flush(controller) {
1163
+ if (offset < buffer.length) {
1164
+ controller.error(
1165
+ new DecodeError('UNEXPECTED_END', 'Stream ended with incomplete message data', 0),
1166
+ )
1167
+ }
1168
+ },
1169
+ })
1170
+ }
1171
+
1172
+ // ─── Codec Factory ─────────────────────────────────────────────────────────────
1173
+
1174
+ export interface Draft17Codec extends BaseCodec<Draft17Message> {
1175
+ readonly draft: '17'
1176
+ encodeSubgroupStream(stream: SubgroupStream): Uint8Array
1177
+ encodeDatagram(dg: DatagramObject): Uint8Array
1178
+ encodeFetchStream(stream: FetchStream): Uint8Array
1179
+ decodeSubgroupStream(bytes: Uint8Array): DecodeResult<SubgroupStream>
1180
+ decodeDatagram(bytes: Uint8Array): DecodeResult<DatagramObject>
1181
+ decodeFetchStream(bytes: Uint8Array): DecodeResult<FetchStream>
1182
+ decodeDataStream(
1183
+ streamType: 'subgroup' | 'datagram' | 'fetch',
1184
+ bytes: Uint8Array,
1185
+ ): DecodeResult<Draft17DataStream>
1186
+ createStreamDecoder(): TransformStream<Uint8Array, Draft17Message>
1187
+ createSubgroupStreamDecoder(): TransformStream<Uint8Array, SubgroupStreamHeader | ObjectPayload>
1188
+ createFetchStreamDecoder(): TransformStream<Uint8Array, FetchStreamHeader | ObjectPayload>
1189
+ createDataStreamDecoder(): TransformStream<Uint8Array, DataStreamEvent>
1190
+ }
1191
+
1192
+ export function createDraft17Codec(): Draft17Codec {
1193
+ return {
1194
+ draft: '17',
1195
+ encodeMessage,
1196
+ decodeMessage,
1197
+ encodeSubgroupStream,
1198
+ encodeDatagram,
1199
+ encodeFetchStream,
1200
+ decodeSubgroupStream,
1201
+ decodeDatagram,
1202
+ decodeFetchStream,
1203
+ decodeDataStream,
1204
+ createStreamDecoder,
1205
+ createSubgroupStreamDecoder,
1206
+ createFetchStreamDecoder,
1207
+ createDataStreamDecoder,
1208
+ }
1209
+ }