@moqtap/codec 0.6.0 → 0.8.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +28 -2
- package/dist/{chunk-CXFAQKL3.js → chunk-23KRITJ6.js} +1 -1
- package/dist/{chunk-JL3NEW3O.cjs → chunk-4XLYCT5Q.cjs} +90 -1
- package/dist/{chunk-DLSGOZ6P.js → chunk-5XZKO2U5.js} +34 -34
- package/dist/{chunk-62LYLROG.js → chunk-APTV6F72.js} +35 -35
- package/dist/{chunk-JB5VDJ2V.cjs → chunk-B56AG5HU.cjs} +37 -37
- package/dist/{chunk-JTRU76JN.cjs → chunk-BQHLUT37.cjs} +109 -111
- package/dist/{chunk-4HBKHNU2.cjs → chunk-CZNW3R5E.cjs} +37 -37
- package/dist/{chunk-OGZTQA24.cjs → chunk-EQAYMCXO.cjs} +64 -64
- package/dist/{chunk-HYI6LFMD.js → chunk-HEO2JG6C.js} +1 -1
- package/dist/{chunk-UP4XPH4J.js → chunk-I55J3KXD.js} +31 -31
- package/dist/{chunk-HZHSO7EW.cjs → chunk-IDV2JYJ6.cjs} +39 -39
- package/dist/{chunk-BAG6YWCP.cjs → chunk-IEJULBKB.cjs} +63 -63
- package/dist/{chunk-Y6KCSM3V.js → chunk-IJAF6PAY.js} +1 -1
- package/dist/{chunk-WMJVSBBE.cjs → chunk-J3ASFPCX.cjs} +57 -57
- package/dist/{chunk-Q5D6OW6Q.js → chunk-JJEN2VG5.js} +51 -53
- package/dist/{chunk-COWGGUL4.js → chunk-JKMYAUGY.js} +1 -1
- package/dist/{chunk-SIYYMFCC.cjs → chunk-KCH4BQXK.cjs} +37 -37
- package/dist/{chunk-VOU7PNHI.js → chunk-KLPWJU6W.js} +89 -0
- package/dist/{chunk-NZ7GYEMT.js → chunk-KNLPX3YA.js} +1 -1
- package/dist/{chunk-A33U4WVS.cjs → chunk-KTVN4P6J.cjs} +67 -67
- package/dist/{chunk-7KBAWOBA.js → chunk-KYVTM5VI.js} +1 -1
- package/dist/{chunk-RZ3UML47.js → chunk-MD2OA7SE.js} +1 -1
- package/dist/{chunk-MSG2FXJ2.cjs → chunk-MH7537FB.cjs} +68 -68
- package/dist/{chunk-SHMA4PBY.js → chunk-N2V7Z37J.js} +1 -1
- package/dist/{chunk-HO44OANK.cjs → chunk-QGIHC6BA.cjs} +36 -36
- package/dist/{chunk-PKEOQSSZ.cjs → chunk-RIIA4ALQ.cjs} +37 -37
- package/dist/{chunk-XZE5R57R.cjs → chunk-VZHL2U2N.cjs} +37 -37
- package/dist/{chunk-RW4UG7CN.js → chunk-XHAP2YST.js} +1 -1
- package/dist/{codec-B1snaM9L.d.cts → codec-BnamSx7L.d.cts} +1 -1
- package/dist/{codec-D49OofBr.d.ts → codec-CFhUGTu2.d.ts} +1 -1
- package/dist/draft07.cjs +4 -4
- package/dist/draft07.js +2 -2
- package/dist/draft08.cjs +3 -3
- package/dist/draft08.js +2 -2
- package/dist/draft09.cjs +3 -3
- package/dist/draft09.js +2 -2
- package/dist/draft10.cjs +3 -3
- package/dist/draft10.js +2 -2
- package/dist/draft11.cjs +3 -3
- package/dist/draft11.js +2 -2
- package/dist/draft12.cjs +3 -3
- package/dist/draft12.js +2 -2
- package/dist/draft13.cjs +3 -3
- package/dist/draft13.js +2 -2
- package/dist/draft14-session.d.cts +1 -1
- package/dist/draft14-session.d.ts +1 -1
- package/dist/draft14.cjs +3 -3
- package/dist/draft14.d.cts +3 -3
- package/dist/draft14.d.ts +3 -3
- package/dist/draft14.js +2 -2
- package/dist/draft15.cjs +3 -3
- package/dist/draft15.js +2 -2
- package/dist/draft16.cjs +3 -3
- package/dist/draft16.js +2 -2
- package/dist/draft17.cjs +3 -3
- package/dist/draft17.js +2 -2
- package/dist/draft18.cjs +3 -3
- package/dist/draft18.js +2 -2
- package/dist/draft19.cjs +3 -3
- package/dist/draft19.js +2 -2
- package/dist/index.cjs +81 -29
- package/dist/index.d.cts +73 -3
- package/dist/index.d.ts +73 -3
- package/dist/index.js +67 -15
- package/dist/session.d.cts +1 -1
- package/dist/session.d.ts +1 -1
- package/dist/{types-DjmrHp_s.d.cts → types-CVeKIk7A.d.cts} +29 -21
- package/dist/{types-DjmrHp_s.d.ts → types-CVeKIk7A.d.ts} +29 -21
- package/package.json +2 -2
- package/src/core/accessors.ts +120 -0
- package/src/core/buffer-reader.ts +74 -2
- package/src/core/buffer-writer.ts +56 -4
- package/src/drafts/draft14/codec.ts +50 -52
- package/src/drafts/draft14/types.ts +31 -23
- package/src/drafts/draft17/codec.ts +2 -2
- package/src/drafts/draft17/data-streams.ts +2 -2
- package/src/drafts/draft18/codec.ts +2 -2
- package/src/drafts/draft18/data-streams.ts +2 -2
- package/src/drafts/draft19/codec.ts +2 -2
- package/src/drafts/draft19/data-streams.ts +2 -2
- package/src/index.ts +8 -0
|
@@ -4,7 +4,7 @@ import {
|
|
|
4
4
|
DecodeError,
|
|
5
5
|
bytesToHex,
|
|
6
6
|
hexToBytes
|
|
7
|
-
} from "./chunk-
|
|
7
|
+
} from "./chunk-KLPWJU6W.js";
|
|
8
8
|
|
|
9
9
|
// src/drafts/draft14/messages.ts
|
|
10
10
|
var MSG_SUBSCRIBE_UPDATE = 0x02n;
|
|
@@ -1029,8 +1029,8 @@ function encodeSubscribePayload(msg, w) {
|
|
|
1029
1029
|
w.writeVarInt(msg.request_id);
|
|
1030
1030
|
w.writeTuple(msg.track_namespace);
|
|
1031
1031
|
w.writeString(msg.track_name);
|
|
1032
|
-
w.writeUint8(
|
|
1033
|
-
w.writeUint8(
|
|
1032
|
+
w.writeUint8(msg.subscriber_priority);
|
|
1033
|
+
w.writeUint8(msg.group_order);
|
|
1034
1034
|
w.writeVarInt(msg.forward);
|
|
1035
1035
|
w.writeVarInt(msg.filter_type);
|
|
1036
1036
|
const ft = msg.filter_type;
|
|
@@ -1047,7 +1047,7 @@ function encodeSubscribeOkPayload(msg, w) {
|
|
|
1047
1047
|
w.writeVarInt(msg.request_id);
|
|
1048
1048
|
w.writeVarInt(msg.track_alias);
|
|
1049
1049
|
w.writeVarInt(msg.expires);
|
|
1050
|
-
w.writeUint8(
|
|
1050
|
+
w.writeUint8(msg.group_order);
|
|
1051
1051
|
w.writeVarInt(msg.content_exists);
|
|
1052
1052
|
if (msg.content_exists === 1n) {
|
|
1053
1053
|
w.writeVarInt(msg.largest_location.group);
|
|
@@ -1061,7 +1061,7 @@ function encodeSubscribeUpdatePayload(msg, w) {
|
|
|
1061
1061
|
w.writeVarInt(msg.start_group);
|
|
1062
1062
|
w.writeVarInt(msg.start_object);
|
|
1063
1063
|
w.writeVarInt(msg.end_group);
|
|
1064
|
-
w.writeUint8(
|
|
1064
|
+
w.writeUint8(msg.subscriber_priority);
|
|
1065
1065
|
w.writeVarInt(msg.forward);
|
|
1066
1066
|
encodeMessageParams(msg.parameters, w);
|
|
1067
1067
|
}
|
|
@@ -1078,7 +1078,7 @@ function encodePublishPayload(msg, w) {
|
|
|
1078
1078
|
w.writeTuple(msg.track_namespace);
|
|
1079
1079
|
w.writeString(msg.track_name);
|
|
1080
1080
|
w.writeVarInt(msg.track_alias);
|
|
1081
|
-
w.writeUint8(
|
|
1081
|
+
w.writeUint8(msg.group_order);
|
|
1082
1082
|
w.writeVarInt(msg.content_exists);
|
|
1083
1083
|
if (msg.content_exists === 1n) {
|
|
1084
1084
|
w.writeVarInt(msg.largest_location.group);
|
|
@@ -1090,8 +1090,8 @@ function encodePublishPayload(msg, w) {
|
|
|
1090
1090
|
function encodePublishOkPayload(msg, w) {
|
|
1091
1091
|
w.writeVarInt(msg.request_id);
|
|
1092
1092
|
w.writeVarInt(msg.forward);
|
|
1093
|
-
w.writeUint8(
|
|
1094
|
-
w.writeUint8(
|
|
1093
|
+
w.writeUint8(msg.subscriber_priority);
|
|
1094
|
+
w.writeUint8(msg.group_order);
|
|
1095
1095
|
w.writeVarInt(msg.filter_type);
|
|
1096
1096
|
const ft = msg.filter_type;
|
|
1097
1097
|
if (ft >= FilterType.AbsoluteStart) {
|
|
@@ -1155,26 +1155,26 @@ function encodeUnsubscribeNamespacePayload(msg, w) {
|
|
|
1155
1155
|
}
|
|
1156
1156
|
function encodeFetchPayload(msg, w) {
|
|
1157
1157
|
w.writeVarInt(msg.request_id);
|
|
1158
|
-
w.writeUint8(
|
|
1159
|
-
w.writeUint8(
|
|
1158
|
+
w.writeUint8(msg.subscriber_priority);
|
|
1159
|
+
w.writeUint8(msg.group_order);
|
|
1160
1160
|
w.writeVarInt(msg.fetch_type);
|
|
1161
1161
|
const ft = msg.fetch_type;
|
|
1162
|
-
if (ft === FetchType.Standalone) {
|
|
1163
|
-
w.writeTuple(msg.track_namespace);
|
|
1164
|
-
w.writeString(msg.track_name);
|
|
1165
|
-
w.writeVarInt(msg.start_group);
|
|
1166
|
-
w.writeVarInt(msg.start_object);
|
|
1167
|
-
w.writeVarInt(msg.end_group);
|
|
1168
|
-
w.writeVarInt(msg.end_object);
|
|
1169
|
-
} else {
|
|
1170
|
-
w.writeVarInt(msg.joining_request_id);
|
|
1171
|
-
w.writeVarInt(msg.joining_start);
|
|
1162
|
+
if (ft === FetchType.Standalone && msg.standalone) {
|
|
1163
|
+
w.writeTuple(msg.standalone.track_namespace);
|
|
1164
|
+
w.writeString(msg.standalone.track_name);
|
|
1165
|
+
w.writeVarInt(msg.standalone.start_group);
|
|
1166
|
+
w.writeVarInt(msg.standalone.start_object);
|
|
1167
|
+
w.writeVarInt(msg.standalone.end_group);
|
|
1168
|
+
w.writeVarInt(msg.standalone.end_object);
|
|
1169
|
+
} else if (msg.joining) {
|
|
1170
|
+
w.writeVarInt(msg.joining.joining_request_id);
|
|
1171
|
+
w.writeVarInt(msg.joining.joining_start);
|
|
1172
1172
|
}
|
|
1173
1173
|
encodeMessageParams(msg.parameters, w);
|
|
1174
1174
|
}
|
|
1175
1175
|
function encodeFetchOkPayload(msg, w) {
|
|
1176
1176
|
w.writeVarInt(msg.request_id);
|
|
1177
|
-
w.writeUint8(
|
|
1177
|
+
w.writeUint8(msg.group_order);
|
|
1178
1178
|
w.writeVarInt(msg.end_of_track);
|
|
1179
1179
|
w.writeVarInt(msg.end_location.group);
|
|
1180
1180
|
w.writeVarInt(msg.end_location.object);
|
|
@@ -1192,8 +1192,8 @@ function encodeTrackStatusPayload(msg, w) {
|
|
|
1192
1192
|
w.writeVarInt(msg.request_id);
|
|
1193
1193
|
w.writeTuple(msg.track_namespace);
|
|
1194
1194
|
w.writeString(msg.track_name);
|
|
1195
|
-
w.writeUint8(
|
|
1196
|
-
w.writeUint8(
|
|
1195
|
+
w.writeUint8(msg.subscriber_priority);
|
|
1196
|
+
w.writeUint8(msg.group_order);
|
|
1197
1197
|
w.writeVarInt(msg.forward);
|
|
1198
1198
|
w.writeVarInt(msg.filter_type);
|
|
1199
1199
|
const ft = msg.filter_type;
|
|
@@ -1207,7 +1207,7 @@ function encodeTrackStatusOkPayload(msg, w) {
|
|
|
1207
1207
|
w.writeVarInt(msg.request_id);
|
|
1208
1208
|
w.writeVarInt(msg.track_alias);
|
|
1209
1209
|
w.writeVarInt(msg.expires);
|
|
1210
|
-
w.writeUint8(
|
|
1210
|
+
w.writeUint8(msg.group_order);
|
|
1211
1211
|
w.writeVarInt(msg.content_exists);
|
|
1212
1212
|
if (msg.content_exists === 1n) {
|
|
1213
1213
|
w.writeVarInt(msg.largest_location.group);
|
|
@@ -1254,8 +1254,8 @@ function decodeSubscribePayload(r) {
|
|
|
1254
1254
|
const request_id = r.readVarInt();
|
|
1255
1255
|
const track_namespace = r.readTuple();
|
|
1256
1256
|
const track_name = r.readString();
|
|
1257
|
-
const subscriber_priority =
|
|
1258
|
-
const group_order =
|
|
1257
|
+
const subscriber_priority = r.readUint8();
|
|
1258
|
+
const group_order = r.readUint8();
|
|
1259
1259
|
const forward = r.readVarInt();
|
|
1260
1260
|
const filter_type = r.readVarInt();
|
|
1261
1261
|
if (filter_type < FilterType.NextGroupStart || filter_type > FilterType.AbsoluteRange) {
|
|
@@ -1292,7 +1292,7 @@ function decodeSubscribeOkPayload(r) {
|
|
|
1292
1292
|
const request_id = r.readVarInt();
|
|
1293
1293
|
const track_alias = r.readVarInt();
|
|
1294
1294
|
const expires = r.readVarInt();
|
|
1295
|
-
const group_order =
|
|
1295
|
+
const group_order = r.readUint8();
|
|
1296
1296
|
const content_exists = r.readVarInt();
|
|
1297
1297
|
let largest_location;
|
|
1298
1298
|
if (content_exists === 1n) {
|
|
@@ -1319,7 +1319,7 @@ function decodeSubscribeUpdatePayload(r) {
|
|
|
1319
1319
|
const start_group = r.readVarInt();
|
|
1320
1320
|
const start_object = r.readVarInt();
|
|
1321
1321
|
const end_group = r.readVarInt();
|
|
1322
|
-
const subscriber_priority =
|
|
1322
|
+
const subscriber_priority = r.readUint8();
|
|
1323
1323
|
const forward = r.readVarInt();
|
|
1324
1324
|
const parameters = decodeMessageParams(r);
|
|
1325
1325
|
return {
|
|
@@ -1349,7 +1349,7 @@ function decodePublishPayload(r) {
|
|
|
1349
1349
|
const track_namespace = r.readTuple();
|
|
1350
1350
|
const track_name = r.readString();
|
|
1351
1351
|
const track_alias = r.readVarInt();
|
|
1352
|
-
const group_order =
|
|
1352
|
+
const group_order = r.readUint8();
|
|
1353
1353
|
const content_exists = r.readVarInt();
|
|
1354
1354
|
let largest_location;
|
|
1355
1355
|
if (content_exists === 1n) {
|
|
@@ -1376,8 +1376,8 @@ function decodePublishPayload(r) {
|
|
|
1376
1376
|
function decodePublishOkPayload(r) {
|
|
1377
1377
|
const request_id = r.readVarInt();
|
|
1378
1378
|
const forward = r.readVarInt();
|
|
1379
|
-
const subscriber_priority =
|
|
1380
|
-
const group_order =
|
|
1379
|
+
const subscriber_priority = r.readUint8();
|
|
1380
|
+
const group_order = r.readUint8();
|
|
1381
1381
|
const filter_type = r.readVarInt();
|
|
1382
1382
|
let start_group;
|
|
1383
1383
|
let start_object;
|
|
@@ -1493,19 +1493,21 @@ function decodeUnsubscribeNamespacePayload(r) {
|
|
|
1493
1493
|
}
|
|
1494
1494
|
function decodeFetchPayload(r) {
|
|
1495
1495
|
const request_id = r.readVarInt();
|
|
1496
|
-
const subscriber_priority =
|
|
1497
|
-
const group_order =
|
|
1496
|
+
const subscriber_priority = r.readUint8();
|
|
1497
|
+
const group_order = r.readUint8();
|
|
1498
1498
|
const fetch_type = r.readVarInt();
|
|
1499
1499
|
if (fetch_type < FetchType.Standalone || fetch_type > FetchType.AbsoluteJoining) {
|
|
1500
1500
|
throw new DecodeError("CONSTRAINT_VIOLATION", `Invalid fetch_type: ${fetch_type}`, r.offset);
|
|
1501
1501
|
}
|
|
1502
1502
|
if (fetch_type === FetchType.Standalone) {
|
|
1503
|
-
const
|
|
1504
|
-
|
|
1505
|
-
|
|
1506
|
-
|
|
1507
|
-
|
|
1508
|
-
|
|
1503
|
+
const standalone = {
|
|
1504
|
+
track_namespace: r.readTuple(),
|
|
1505
|
+
track_name: r.readString(),
|
|
1506
|
+
start_group: r.readVarInt(),
|
|
1507
|
+
start_object: r.readVarInt(),
|
|
1508
|
+
end_group: r.readVarInt(),
|
|
1509
|
+
end_object: r.readVarInt()
|
|
1510
|
+
};
|
|
1509
1511
|
const parameters = decodeMessageParams(r);
|
|
1510
1512
|
return {
|
|
1511
1513
|
type: "fetch",
|
|
@@ -1513,17 +1515,14 @@ function decodeFetchPayload(r) {
|
|
|
1513
1515
|
subscriber_priority,
|
|
1514
1516
|
group_order,
|
|
1515
1517
|
fetch_type,
|
|
1516
|
-
|
|
1517
|
-
track_name,
|
|
1518
|
-
start_group,
|
|
1519
|
-
start_object,
|
|
1520
|
-
end_group,
|
|
1521
|
-
end_object,
|
|
1518
|
+
standalone,
|
|
1522
1519
|
parameters
|
|
1523
1520
|
};
|
|
1524
1521
|
} else {
|
|
1525
|
-
const
|
|
1526
|
-
|
|
1522
|
+
const joining = {
|
|
1523
|
+
joining_request_id: r.readVarInt(),
|
|
1524
|
+
joining_start: r.readVarInt()
|
|
1525
|
+
};
|
|
1527
1526
|
const parameters = decodeMessageParams(r);
|
|
1528
1527
|
return {
|
|
1529
1528
|
type: "fetch",
|
|
@@ -1531,15 +1530,14 @@ function decodeFetchPayload(r) {
|
|
|
1531
1530
|
subscriber_priority,
|
|
1532
1531
|
group_order,
|
|
1533
1532
|
fetch_type,
|
|
1534
|
-
|
|
1535
|
-
joining_start,
|
|
1533
|
+
joining,
|
|
1536
1534
|
parameters
|
|
1537
1535
|
};
|
|
1538
1536
|
}
|
|
1539
1537
|
}
|
|
1540
1538
|
function decodeFetchOkPayload(r) {
|
|
1541
1539
|
const request_id = r.readVarInt();
|
|
1542
|
-
const group_order =
|
|
1540
|
+
const group_order = r.readUint8();
|
|
1543
1541
|
const end_of_track = r.readVarInt();
|
|
1544
1542
|
const end_location = {
|
|
1545
1543
|
group: r.readVarInt(),
|
|
@@ -1569,8 +1567,8 @@ function decodeTrackStatusPayload(r) {
|
|
|
1569
1567
|
const request_id = r.readVarInt();
|
|
1570
1568
|
const track_namespace = r.readTuple();
|
|
1571
1569
|
const track_name = r.readString();
|
|
1572
|
-
const subscriber_priority =
|
|
1573
|
-
const group_order =
|
|
1570
|
+
const subscriber_priority = r.readUint8();
|
|
1571
|
+
const group_order = r.readUint8();
|
|
1574
1572
|
const forward = r.readVarInt();
|
|
1575
1573
|
const filter_type = r.readVarInt();
|
|
1576
1574
|
let start_group;
|
|
@@ -1599,7 +1597,7 @@ function decodeTrackStatusOkPayload(r) {
|
|
|
1599
1597
|
const request_id = r.readVarInt();
|
|
1600
1598
|
const track_alias = r.readVarInt();
|
|
1601
1599
|
const expires = r.readVarInt();
|
|
1602
|
-
const group_order =
|
|
1600
|
+
const group_order = r.readUint8();
|
|
1603
1601
|
const content_exists = r.readVarInt();
|
|
1604
1602
|
let largest_location;
|
|
1605
1603
|
if (content_exists === 1n) {
|
|
@@ -4,12 +4,12 @@
|
|
|
4
4
|
|
|
5
5
|
|
|
6
6
|
|
|
7
|
-
var
|
|
7
|
+
var _chunk4XLYCT5Qcjs = require('./chunk-4XLYCT5Q.cjs');
|
|
8
8
|
|
|
9
9
|
// src/drafts/draft13/data-streams.ts
|
|
10
10
|
var FETCH_STREAM_TYPE = 0x05n;
|
|
11
11
|
function encodeSubgroupStream(stream) {
|
|
12
|
-
const w = new (0,
|
|
12
|
+
const w = new (0, _chunk4XLYCT5Qcjs.BufferWriter)();
|
|
13
13
|
const typeId = stream.streamTypeId;
|
|
14
14
|
w.writeVarInt(BigInt(typeId));
|
|
15
15
|
const extensionsPresent = (typeId & 1) !== 0;
|
|
@@ -34,7 +34,7 @@ function encodeSubgroupStream(stream) {
|
|
|
34
34
|
return w.finish();
|
|
35
35
|
}
|
|
36
36
|
function encodeDatagram(dg) {
|
|
37
|
-
const w = new (0,
|
|
37
|
+
const w = new (0, _chunk4XLYCT5Qcjs.BufferWriter)();
|
|
38
38
|
w.writeVarInt(BigInt(dg.streamTypeId));
|
|
39
39
|
w.writeVarInt(dg.trackAlias);
|
|
40
40
|
w.writeVarInt(dg.groupId);
|
|
@@ -55,7 +55,7 @@ function encodeDatagram(dg) {
|
|
|
55
55
|
return w.finish();
|
|
56
56
|
}
|
|
57
57
|
function encodeFetchStream(stream) {
|
|
58
|
-
const w = new (0,
|
|
58
|
+
const w = new (0, _chunk4XLYCT5Qcjs.BufferWriter)();
|
|
59
59
|
w.writeVarInt(FETCH_STREAM_TYPE);
|
|
60
60
|
w.writeVarInt(stream.requestId);
|
|
61
61
|
for (const obj of stream.objects) {
|
|
@@ -77,14 +77,14 @@ function encodeFetchStream(stream) {
|
|
|
77
77
|
}
|
|
78
78
|
function decodeSubgroupStream(bytes) {
|
|
79
79
|
try {
|
|
80
|
-
const r = new (0,
|
|
80
|
+
const r = new (0, _chunk4XLYCT5Qcjs.BufferReader)(bytes);
|
|
81
81
|
const streamTypeId = Number(r.readVarInt());
|
|
82
82
|
const validRange1 = streamTypeId >= 16 && streamTypeId <= 21;
|
|
83
83
|
const validRange2 = streamTypeId >= 24 && streamTypeId <= 29;
|
|
84
84
|
if (!validRange1 && !validRange2) {
|
|
85
85
|
return {
|
|
86
86
|
ok: false,
|
|
87
|
-
error: new (0,
|
|
87
|
+
error: new (0, _chunk4XLYCT5Qcjs.DecodeError)(
|
|
88
88
|
"CONSTRAINT_VIOLATION",
|
|
89
89
|
`Expected subgroup type 0x10-0x15 or 0x18-0x1D, got 0x${streamTypeId.toString(16)}`,
|
|
90
90
|
0
|
|
@@ -154,18 +154,18 @@ function decodeSubgroupStream(bytes) {
|
|
|
154
154
|
bytesRead: r.offset
|
|
155
155
|
};
|
|
156
156
|
} catch (e) {
|
|
157
|
-
if (e instanceof
|
|
157
|
+
if (e instanceof _chunk4XLYCT5Qcjs.DecodeError) return { ok: false, error: e };
|
|
158
158
|
throw e;
|
|
159
159
|
}
|
|
160
160
|
}
|
|
161
161
|
function decodeDatagram(bytes) {
|
|
162
162
|
try {
|
|
163
|
-
const r = new (0,
|
|
163
|
+
const r = new (0, _chunk4XLYCT5Qcjs.BufferReader)(bytes);
|
|
164
164
|
const streamTypeId = Number(r.readVarInt());
|
|
165
165
|
if (streamTypeId < 0 || streamTypeId > 5) {
|
|
166
166
|
return {
|
|
167
167
|
ok: false,
|
|
168
|
-
error: new (0,
|
|
168
|
+
error: new (0, _chunk4XLYCT5Qcjs.DecodeError)(
|
|
169
169
|
"CONSTRAINT_VIOLATION",
|
|
170
170
|
`Expected datagram type 0x00-0x05, got 0x${streamTypeId.toString(16)}`,
|
|
171
171
|
0
|
|
@@ -212,18 +212,18 @@ function decodeDatagram(bytes) {
|
|
|
212
212
|
result.objectStatus = objectStatus;
|
|
213
213
|
return { ok: true, value: result, bytesRead: r.offset };
|
|
214
214
|
} catch (e) {
|
|
215
|
-
if (e instanceof
|
|
215
|
+
if (e instanceof _chunk4XLYCT5Qcjs.DecodeError) return { ok: false, error: e };
|
|
216
216
|
throw e;
|
|
217
217
|
}
|
|
218
218
|
}
|
|
219
219
|
function decodeFetchStream(bytes) {
|
|
220
220
|
try {
|
|
221
|
-
const r = new (0,
|
|
221
|
+
const r = new (0, _chunk4XLYCT5Qcjs.BufferReader)(bytes);
|
|
222
222
|
const streamType = r.readVarInt();
|
|
223
223
|
if (streamType !== FETCH_STREAM_TYPE) {
|
|
224
224
|
return {
|
|
225
225
|
ok: false,
|
|
226
|
-
error: new (0,
|
|
226
|
+
error: new (0, _chunk4XLYCT5Qcjs.DecodeError)(
|
|
227
227
|
"CONSTRAINT_VIOLATION",
|
|
228
228
|
`Expected fetch type 0x05, got 0x${streamType.toString(16)}`,
|
|
229
229
|
0
|
|
@@ -275,7 +275,7 @@ function decodeFetchStream(bytes) {
|
|
|
275
275
|
bytesRead: r.offset
|
|
276
276
|
};
|
|
277
277
|
} catch (e) {
|
|
278
|
-
if (e instanceof
|
|
278
|
+
if (e instanceof _chunk4XLYCT5Qcjs.DecodeError) return { ok: false, error: e };
|
|
279
279
|
throw e;
|
|
280
280
|
}
|
|
281
281
|
}
|
|
@@ -377,7 +377,7 @@ var MESSAGE_ID_MAP = new Map(
|
|
|
377
377
|
var textEncoder = /* @__PURE__ */ new TextEncoder();
|
|
378
378
|
var textDecoder = /* @__PURE__ */ new TextDecoder();
|
|
379
379
|
function encodeAuthorizationToken(at, w) {
|
|
380
|
-
const tmpW = new (0,
|
|
380
|
+
const tmpW = new (0, _chunk4XLYCT5Qcjs.BufferWriter)(64);
|
|
381
381
|
tmpW.writeVarInt(at.alias_type);
|
|
382
382
|
const aliasType = Number(at.alias_type);
|
|
383
383
|
if (aliasType === 0 || aliasType === 1 || aliasType === 2) {
|
|
@@ -438,11 +438,11 @@ function encodeSetupParams(params, w) {
|
|
|
438
438
|
const id = BigInt(u.id);
|
|
439
439
|
w.writeVarInt(id);
|
|
440
440
|
if (id % 2n === 0n) {
|
|
441
|
-
const raw =
|
|
442
|
-
const tmpReader = new (0,
|
|
441
|
+
const raw = _chunk4XLYCT5Qcjs.hexToBytes.call(void 0, u.raw_hex);
|
|
442
|
+
const tmpReader = new (0, _chunk4XLYCT5Qcjs.BufferReader)(raw);
|
|
443
443
|
w.writeVarInt(tmpReader.readVarInt());
|
|
444
444
|
} else {
|
|
445
|
-
const raw =
|
|
445
|
+
const raw = _chunk4XLYCT5Qcjs.hexToBytes.call(void 0, u.raw_hex);
|
|
446
446
|
w.writeVarInt(raw.byteLength);
|
|
447
447
|
w.writeBytes(raw);
|
|
448
448
|
}
|
|
@@ -462,13 +462,13 @@ function decodeSetupParams(r) {
|
|
|
462
462
|
} else if (paramType === SETUP_PARAM_MAX_AUTH_TOKEN_CACHE_SIZE) {
|
|
463
463
|
result.max_auth_token_cache_size = value;
|
|
464
464
|
} else {
|
|
465
|
-
const tmpW = new (0,
|
|
465
|
+
const tmpW = new (0, _chunk4XLYCT5Qcjs.BufferWriter)(16);
|
|
466
466
|
tmpW.writeVarInt(value);
|
|
467
467
|
const raw = tmpW.finish();
|
|
468
468
|
unknown.push({
|
|
469
469
|
id: `0x${paramType.toString(16)}`,
|
|
470
470
|
length: raw.byteLength,
|
|
471
|
-
raw_hex:
|
|
471
|
+
raw_hex: _chunk4XLYCT5Qcjs.bytesToHex.call(void 0, raw)
|
|
472
472
|
});
|
|
473
473
|
}
|
|
474
474
|
} else {
|
|
@@ -483,7 +483,7 @@ function decodeSetupParams(r) {
|
|
|
483
483
|
unknown.push({
|
|
484
484
|
id: `0x${paramType.toString(16)}`,
|
|
485
485
|
length,
|
|
486
|
-
raw_hex:
|
|
486
|
+
raw_hex: _chunk4XLYCT5Qcjs.bytesToHex.call(void 0, bytes)
|
|
487
487
|
});
|
|
488
488
|
}
|
|
489
489
|
}
|
|
@@ -514,11 +514,11 @@ function encodeParams(params, w) {
|
|
|
514
514
|
const id = BigInt(u.id);
|
|
515
515
|
w.writeVarInt(id);
|
|
516
516
|
if (id % 2n === 0n) {
|
|
517
|
-
const raw =
|
|
518
|
-
const tmpReader = new (0,
|
|
517
|
+
const raw = _chunk4XLYCT5Qcjs.hexToBytes.call(void 0, u.raw_hex);
|
|
518
|
+
const tmpReader = new (0, _chunk4XLYCT5Qcjs.BufferReader)(raw);
|
|
519
519
|
w.writeVarInt(tmpReader.readVarInt());
|
|
520
520
|
} else {
|
|
521
|
-
const raw =
|
|
521
|
+
const raw = _chunk4XLYCT5Qcjs.hexToBytes.call(void 0, u.raw_hex);
|
|
522
522
|
w.writeVarInt(raw.byteLength);
|
|
523
523
|
w.writeBytes(raw);
|
|
524
524
|
}
|
|
@@ -538,13 +538,13 @@ function decodeParams(r) {
|
|
|
538
538
|
} else if (paramType === PARAM_MAX_CACHE_DURATION) {
|
|
539
539
|
result.max_cache_duration = value;
|
|
540
540
|
} else {
|
|
541
|
-
const tmpW = new (0,
|
|
541
|
+
const tmpW = new (0, _chunk4XLYCT5Qcjs.BufferWriter)(16);
|
|
542
542
|
tmpW.writeVarInt(value);
|
|
543
543
|
const raw = tmpW.finish();
|
|
544
544
|
unknown.push({
|
|
545
545
|
id: `0x${paramType.toString(16)}`,
|
|
546
546
|
length: raw.byteLength,
|
|
547
|
-
raw_hex:
|
|
547
|
+
raw_hex: _chunk4XLYCT5Qcjs.bytesToHex.call(void 0, raw)
|
|
548
548
|
});
|
|
549
549
|
}
|
|
550
550
|
} else {
|
|
@@ -556,7 +556,7 @@ function decodeParams(r) {
|
|
|
556
556
|
unknown.push({
|
|
557
557
|
id: `0x${paramType.toString(16)}`,
|
|
558
558
|
length,
|
|
559
|
-
raw_hex:
|
|
559
|
+
raw_hex: _chunk4XLYCT5Qcjs.bytesToHex.call(void 0, bytes)
|
|
560
560
|
});
|
|
561
561
|
}
|
|
562
562
|
}
|
|
@@ -780,7 +780,7 @@ function encodeRequestsBlockedPayload(msg, w) {
|
|
|
780
780
|
function decodeClientSetupPayload(r) {
|
|
781
781
|
const numVersions = Number(r.readVarInt());
|
|
782
782
|
if (numVersions === 0) {
|
|
783
|
-
throw new (0,
|
|
783
|
+
throw new (0, _chunk4XLYCT5Qcjs.DecodeError)("CONSTRAINT_VIOLATION", "supported_versions must not be empty", r.offset);
|
|
784
784
|
}
|
|
785
785
|
const supported_versions = [];
|
|
786
786
|
for (let i = 0; i < numVersions; i++) supported_versions.push(r.readVarInt());
|
|
@@ -802,7 +802,7 @@ function decodeSubscribePayload(r) {
|
|
|
802
802
|
const filter_type = r.readVarInt();
|
|
803
803
|
const ft = Number(filter_type);
|
|
804
804
|
if (ft < 1 || ft > 4) {
|
|
805
|
-
throw new (0,
|
|
805
|
+
throw new (0, _chunk4XLYCT5Qcjs.DecodeError)("CONSTRAINT_VIOLATION", `Invalid filter_type: ${ft}`, r.offset);
|
|
806
806
|
}
|
|
807
807
|
let start_group;
|
|
808
808
|
let start_object;
|
|
@@ -1028,7 +1028,7 @@ function decodeFetchPayload(r) {
|
|
|
1028
1028
|
const fetch_type = r.readVarInt();
|
|
1029
1029
|
const ft = Number(fetch_type);
|
|
1030
1030
|
if (ft < 1 || ft > 3) {
|
|
1031
|
-
throw new (0,
|
|
1031
|
+
throw new (0, _chunk4XLYCT5Qcjs.DecodeError)("CONSTRAINT_VIOLATION", `Invalid fetch_type: ${ft}`, r.offset);
|
|
1032
1032
|
}
|
|
1033
1033
|
let standalone;
|
|
1034
1034
|
let joining;
|
|
@@ -1100,7 +1100,7 @@ function decodeTrackStatusPayload(r) {
|
|
|
1100
1100
|
const filter_type = r.readVarInt();
|
|
1101
1101
|
const ft = Number(filter_type);
|
|
1102
1102
|
if (ft < 1 || ft > 4) {
|
|
1103
|
-
throw new (0,
|
|
1103
|
+
throw new (0, _chunk4XLYCT5Qcjs.DecodeError)("CONSTRAINT_VIOLATION", `Invalid filter_type: ${ft}`, r.offset);
|
|
1104
1104
|
}
|
|
1105
1105
|
let start_group;
|
|
1106
1106
|
let start_object;
|
|
@@ -1207,10 +1207,10 @@ var payloadDecoders = /* @__PURE__ */ new Map([
|
|
|
1207
1207
|
function encodeMessage(message) {
|
|
1208
1208
|
const typeId = MESSAGE_ID_MAP.get(message.type);
|
|
1209
1209
|
if (typeId === void 0) throw new Error(`Unknown message type: ${message.type}`);
|
|
1210
|
-
const payloadWriter = new (0,
|
|
1210
|
+
const payloadWriter = new (0, _chunk4XLYCT5Qcjs.BufferWriter)();
|
|
1211
1211
|
encodePayload(message, payloadWriter);
|
|
1212
1212
|
const payload = payloadWriter.finishView();
|
|
1213
|
-
const writer = new (0,
|
|
1213
|
+
const writer = new (0, _chunk4XLYCT5Qcjs.BufferWriter)(payload.byteLength + 16);
|
|
1214
1214
|
writer.writeVarInt(typeId);
|
|
1215
1215
|
if (payload.byteLength > 65535) {
|
|
1216
1216
|
throw new Error(`Payload too large for 16-bit length: ${payload.byteLength}`);
|
|
@@ -1290,18 +1290,18 @@ function encodePayload(msg, w) {
|
|
|
1290
1290
|
}
|
|
1291
1291
|
function decodeMessage(bytes) {
|
|
1292
1292
|
try {
|
|
1293
|
-
const reader = new (0,
|
|
1293
|
+
const reader = new (0, _chunk4XLYCT5Qcjs.BufferReader)(bytes);
|
|
1294
1294
|
const typeId = reader.readVarInt();
|
|
1295
1295
|
const lenHi = reader.readUint8();
|
|
1296
1296
|
const lenLo = reader.readUint8();
|
|
1297
1297
|
const payloadLength = lenHi << 8 | lenLo;
|
|
1298
1298
|
const payloadBytes = reader.readBytes(payloadLength);
|
|
1299
|
-
const payloadReader = new (0,
|
|
1299
|
+
const payloadReader = new (0, _chunk4XLYCT5Qcjs.BufferReader)(payloadBytes);
|
|
1300
1300
|
const decoder = payloadDecoders.get(typeId);
|
|
1301
1301
|
if (!decoder) {
|
|
1302
1302
|
return {
|
|
1303
1303
|
ok: false,
|
|
1304
|
-
error: new (0,
|
|
1304
|
+
error: new (0, _chunk4XLYCT5Qcjs.DecodeError)(
|
|
1305
1305
|
"UNKNOWN_MESSAGE_TYPE",
|
|
1306
1306
|
`Unknown message type ID: 0x${typeId.toString(16)}`,
|
|
1307
1307
|
0
|
|
@@ -1311,7 +1311,7 @@ function decodeMessage(bytes) {
|
|
|
1311
1311
|
const message = decoder(payloadReader);
|
|
1312
1312
|
return { ok: true, value: message, bytesRead: reader.offset };
|
|
1313
1313
|
} catch (e) {
|
|
1314
|
-
if (e instanceof
|
|
1314
|
+
if (e instanceof _chunk4XLYCT5Qcjs.DecodeError) return { ok: false, error: e };
|
|
1315
1315
|
throw e;
|
|
1316
1316
|
}
|
|
1317
1317
|
}
|
|
@@ -1341,7 +1341,7 @@ function createStreamDecoder() {
|
|
|
1341
1341
|
},
|
|
1342
1342
|
flush(controller) {
|
|
1343
1343
|
if (offset < buffer.length)
|
|
1344
|
-
controller.error(new (0,
|
|
1344
|
+
controller.error(new (0, _chunk4XLYCT5Qcjs.DecodeError)("UNEXPECTED_END", "Stream ended with incomplete data", 0));
|
|
1345
1345
|
}
|
|
1346
1346
|
});
|
|
1347
1347
|
}
|
|
@@ -124,6 +124,54 @@ var BufferReader = class {
|
|
|
124
124
|
return params;
|
|
125
125
|
}
|
|
126
126
|
};
|
|
127
|
+
var MoqtBufferReader = class extends BufferReader {
|
|
128
|
+
/** Draft-17 omits the 7-byte length; draft-18 restored it. */
|
|
129
|
+
get allowSevenByte() {
|
|
130
|
+
return true;
|
|
131
|
+
}
|
|
132
|
+
readVarInt() {
|
|
133
|
+
if (this.remaining < 1) {
|
|
134
|
+
throw new DecodeError("UNEXPECTED_END", "Not enough bytes for varint", this.pos);
|
|
135
|
+
}
|
|
136
|
+
const first = this.view.getUint8(this.pos);
|
|
137
|
+
if (first === 255) {
|
|
138
|
+
if (this.remaining < 9) {
|
|
139
|
+
throw new DecodeError("UNEXPECTED_END", "Not enough bytes for 9-byte varint", this.pos);
|
|
140
|
+
}
|
|
141
|
+
const value2 = this.view.getBigUint64(this.pos + 1);
|
|
142
|
+
this.pos += 9;
|
|
143
|
+
return value2;
|
|
144
|
+
}
|
|
145
|
+
let leadingOnes = 0;
|
|
146
|
+
while (leadingOnes < 8 && (first & 128 >> leadingOnes) !== 0) leadingOnes++;
|
|
147
|
+
const length = leadingOnes + 1;
|
|
148
|
+
if (length === 7 && !this.allowSevenByte) {
|
|
149
|
+
throw new DecodeError(
|
|
150
|
+
"INVALID_VARINT",
|
|
151
|
+
"The 7-byte varint is not defined in draft-17",
|
|
152
|
+
this.pos
|
|
153
|
+
);
|
|
154
|
+
}
|
|
155
|
+
if (this.remaining < length) {
|
|
156
|
+
throw new DecodeError(
|
|
157
|
+
"UNEXPECTED_END",
|
|
158
|
+
`Not enough bytes for ${length}-byte varint`,
|
|
159
|
+
this.pos
|
|
160
|
+
);
|
|
161
|
+
}
|
|
162
|
+
let value = BigInt(first & (1 << 8 - length) - 1);
|
|
163
|
+
for (let i = 1; i < length; i++) {
|
|
164
|
+
value = value << 8n | BigInt(this.view.getUint8(this.pos + i));
|
|
165
|
+
}
|
|
166
|
+
this.pos += length;
|
|
167
|
+
return value;
|
|
168
|
+
}
|
|
169
|
+
};
|
|
170
|
+
var Draft17BufferReader = class extends MoqtBufferReader {
|
|
171
|
+
get allowSevenByte() {
|
|
172
|
+
return false;
|
|
173
|
+
}
|
|
174
|
+
};
|
|
127
175
|
|
|
128
176
|
// src/core/buffer-writer.ts
|
|
129
177
|
var textEncoder = /* @__PURE__ */ new TextEncoder();
|
|
@@ -211,6 +259,43 @@ var BufferWriter = class {
|
|
|
211
259
|
return this.buffer.subarray(0, this.pos);
|
|
212
260
|
}
|
|
213
261
|
};
|
|
262
|
+
var MoqtBufferWriter = class extends BufferWriter {
|
|
263
|
+
/** Draft-17 omits the 7-byte length; draft-18 restored it. */
|
|
264
|
+
get allowSevenByte() {
|
|
265
|
+
return true;
|
|
266
|
+
}
|
|
267
|
+
writeVarInt(value) {
|
|
268
|
+
const v = BigInt(value);
|
|
269
|
+
if (v < 0n) throw new Error("VarInt value must be non-negative");
|
|
270
|
+
if (v > 0xffffffffffffffffn) throw new Error("VarInt value exceeds 64-bit range");
|
|
271
|
+
let length = 9;
|
|
272
|
+
for (let n = 1; n <= 8; n++) {
|
|
273
|
+
if (n === 7 && !this.allowSevenByte) continue;
|
|
274
|
+
if (v < 1n << BigInt(7 * n)) {
|
|
275
|
+
length = n;
|
|
276
|
+
break;
|
|
277
|
+
}
|
|
278
|
+
}
|
|
279
|
+
this.ensureCapacity(length);
|
|
280
|
+
if (length === 9) {
|
|
281
|
+
this.view.setUint8(this.pos, 255);
|
|
282
|
+
this.view.setBigUint64(this.pos + 1, v);
|
|
283
|
+
this.pos += 9;
|
|
284
|
+
return;
|
|
285
|
+
}
|
|
286
|
+
const prefix = BigInt((1 << length - 1) - 1 << 9 - length) & 0xffn;
|
|
287
|
+
const combined = prefix << BigInt(8 * (length - 1)) | v;
|
|
288
|
+
for (let i = 0; i < length; i++) {
|
|
289
|
+
this.view.setUint8(this.pos + i, Number(combined >> BigInt(8 * (length - 1 - i)) & 0xffn));
|
|
290
|
+
}
|
|
291
|
+
this.pos += length;
|
|
292
|
+
}
|
|
293
|
+
};
|
|
294
|
+
var Draft17BufferWriter = class extends MoqtBufferWriter {
|
|
295
|
+
get allowSevenByte() {
|
|
296
|
+
return false;
|
|
297
|
+
}
|
|
298
|
+
};
|
|
214
299
|
|
|
215
300
|
// src/core/hex.ts
|
|
216
301
|
var HEX_TABLE = /* @__PURE__ */ Array.from(
|
|
@@ -235,7 +320,11 @@ function hexToBytes(hex) {
|
|
|
235
320
|
export {
|
|
236
321
|
DecodeError,
|
|
237
322
|
BufferReader,
|
|
323
|
+
MoqtBufferReader,
|
|
324
|
+
Draft17BufferReader,
|
|
238
325
|
BufferWriter,
|
|
326
|
+
MoqtBufferWriter,
|
|
327
|
+
Draft17BufferWriter,
|
|
239
328
|
bytesToHex,
|
|
240
329
|
hexToBytes
|
|
241
330
|
};
|