@moqtap/codec 0.1.0 → 0.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/{chunk-YBSEOSSP.js → chunk-A27S7HW7.js} +5 -1
- package/dist/{chunk-5WFXFLL4.cjs → chunk-FUFTMAQD.cjs} +96 -63
- package/dist/{chunk-2NARXGVA.cjs → chunk-FWISIR26.cjs} +5 -1
- package/dist/{chunk-23YG7F46.js → chunk-IXHOBNXA.js} +117 -17
- package/dist/{chunk-3BSZ55L3.cjs → chunk-NLYTRGXA.cjs} +153 -19
- package/dist/{chunk-GDRGWFEK.cjs → chunk-NPWHHWXT.cjs} +249 -37
- package/dist/{chunk-IQPDRQVC.js → chunk-U2B3B42P.js} +62 -29
- package/dist/{chunk-WNTXF3DE.cjs → chunk-YBZD3DU5.cjs} +127 -27
- package/dist/{chunk-DC4L6ZIT.js → chunk-YTXLWKOR.js} +153 -19
- package/dist/{chunk-YPXLV5YK.js → chunk-Z66WDWHI.js} +249 -37
- package/dist/{codec-qPzfmLNu.d.ts → codec-B2mc2g3i.d.ts} +5 -5
- package/dist/{codec-CTvFtQQI.d.cts → codec-Bvr7rFtj.d.cts} +5 -5
- package/dist/draft14-session.cjs +2 -2
- package/dist/draft14-session.d.cts +4 -4
- package/dist/draft14-session.d.ts +4 -4
- package/dist/draft14-session.js +1 -1
- package/dist/draft14.cjs +4 -4
- package/dist/draft14.d.cts +15 -15
- package/dist/draft14.d.ts +15 -15
- package/dist/draft14.js +3 -3
- package/dist/draft7-session.cjs +2 -2
- package/dist/draft7-session.d.cts +3 -3
- package/dist/draft7-session.d.ts +3 -3
- package/dist/draft7-session.js +1 -1
- package/dist/draft7.cjs +5 -5
- package/dist/draft7.d.cts +10 -10
- package/dist/draft7.d.ts +10 -10
- package/dist/draft7.js +2 -2
- package/dist/index.cjs +6 -6
- package/dist/index.d.cts +6 -6
- package/dist/index.d.ts +6 -6
- package/dist/index.js +3 -3
- package/dist/{session-types-B9NIf7_F.d.ts → session-types-DFjMk4HH.d.ts} +20 -20
- package/dist/{session-types-CCo-oA-d.d.cts → session-types-DW1RSZX_.d.cts} +20 -20
- package/dist/session.cjs +4 -4
- package/dist/session.d.cts +3 -3
- package/dist/session.d.ts +3 -3
- package/dist/session.js +2 -2
- package/dist/{types-CIk5W10V.d.ts → types-BTFeKYCb.d.cts} +37 -37
- package/dist/{types-CIk5W10V.d.cts → types-BTFeKYCb.d.ts} +37 -37
- package/dist/{types-ClXELFGN.d.cts → types-DPYE49t0.d.cts} +36 -36
- package/dist/{types-ClXELFGN.d.ts → types-DPYE49t0.d.ts} +36 -36
- package/package.json +7 -7
- package/src/core/buffer-reader.ts +16 -9
- package/src/core/buffer-writer.ts +2 -2
- package/src/core/errors.ts +1 -1
- package/src/core/session-types.ts +28 -41
- package/src/core/types.ts +70 -70
- package/src/drafts/draft07/announce-fsm.ts +1 -1
- package/src/drafts/draft07/codec.ts +195 -86
- package/src/drafts/draft07/index.ts +43 -44
- package/src/drafts/draft07/messages.ts +1 -1
- package/src/drafts/draft07/parameters.ts +2 -2
- package/src/drafts/draft07/rules.ts +68 -37
- package/src/drafts/draft07/session-fsm.ts +330 -117
- package/src/drafts/draft07/session.ts +10 -10
- package/src/drafts/draft07/subscription-fsm.ts +1 -1
- package/src/drafts/draft07/varint.ts +4 -4
- package/src/drafts/draft14/codec.ts +339 -189
- package/src/drafts/draft14/index.ts +103 -108
- package/src/drafts/draft14/messages.ts +61 -61
- package/src/drafts/draft14/rules.ts +77 -34
- package/src/drafts/draft14/session-fsm.ts +458 -146
- package/src/drafts/draft14/session.ts +13 -13
- package/src/drafts/draft14/types.ts +68 -68
- package/src/index.ts +66 -31
- package/src/session.ts +20 -20
|
@@ -35,7 +35,11 @@ var BufferReader = class {
|
|
|
35
35
|
}
|
|
36
36
|
readBytes(length) {
|
|
37
37
|
if (this.remaining < length) {
|
|
38
|
-
throw new DecodeError(
|
|
38
|
+
throw new DecodeError(
|
|
39
|
+
"UNEXPECTED_END",
|
|
40
|
+
`Not enough bytes: need ${length}, have ${this.remaining}`,
|
|
41
|
+
this.pos
|
|
42
|
+
);
|
|
39
43
|
}
|
|
40
44
|
const slice = this.buffer.slice(this.pos, this.pos + length);
|
|
41
45
|
this.pos += length;
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
|
|
4
4
|
|
|
5
|
-
var
|
|
5
|
+
var _chunkFWISIR26cjs = require('./chunk-FWISIR26.cjs');
|
|
6
6
|
|
|
7
7
|
// src/drafts/draft14/messages.ts
|
|
8
8
|
var MSG_SUBSCRIBE_UPDATE = 0x02n;
|
|
@@ -13,12 +13,12 @@ var MSG_PUBLISH_NAMESPACE = 0x06n;
|
|
|
13
13
|
var MSG_PUBLISH_NAMESPACE_OK = 0x07n;
|
|
14
14
|
var MSG_PUBLISH_NAMESPACE_ERROR = 0x08n;
|
|
15
15
|
var MSG_PUBLISH_NAMESPACE_DONE = 0x09n;
|
|
16
|
-
var MSG_UNSUBSCRIBE =
|
|
17
|
-
var MSG_PUBLISH_DONE =
|
|
18
|
-
var MSG_PUBLISH_NAMESPACE_CANCEL =
|
|
19
|
-
var MSG_TRACK_STATUS =
|
|
20
|
-
var MSG_TRACK_STATUS_OK =
|
|
21
|
-
var MSG_TRACK_STATUS_ERROR =
|
|
16
|
+
var MSG_UNSUBSCRIBE = 0x0an;
|
|
17
|
+
var MSG_PUBLISH_DONE = 0x0bn;
|
|
18
|
+
var MSG_PUBLISH_NAMESPACE_CANCEL = 0x0cn;
|
|
19
|
+
var MSG_TRACK_STATUS = 0x0dn;
|
|
20
|
+
var MSG_TRACK_STATUS_OK = 0x0en;
|
|
21
|
+
var MSG_TRACK_STATUS_ERROR = 0x0fn;
|
|
22
22
|
var MSG_GOAWAY = 0x10n;
|
|
23
23
|
var MSG_SUBSCRIBE_NAMESPACE = 0x11n;
|
|
24
24
|
var MSG_SUBSCRIBE_NAMESPACE_OK = 0x12n;
|
|
@@ -29,10 +29,10 @@ var MSG_FETCH = 0x16n;
|
|
|
29
29
|
var MSG_FETCH_CANCEL = 0x17n;
|
|
30
30
|
var MSG_FETCH_OK = 0x18n;
|
|
31
31
|
var MSG_FETCH_ERROR = 0x19n;
|
|
32
|
-
var MSG_REQUESTS_BLOCKED =
|
|
33
|
-
var MSG_PUBLISH =
|
|
34
|
-
var MSG_PUBLISH_OK =
|
|
35
|
-
var MSG_PUBLISH_ERROR =
|
|
32
|
+
var MSG_REQUESTS_BLOCKED = 0x1an;
|
|
33
|
+
var MSG_PUBLISH = 0x1dn;
|
|
34
|
+
var MSG_PUBLISH_OK = 0x1en;
|
|
35
|
+
var MSG_PUBLISH_ERROR = 0x1fn;
|
|
36
36
|
var MSG_CLIENT_SETUP = 0x20n;
|
|
37
37
|
var MSG_SERVER_SETUP = 0x21n;
|
|
38
38
|
var PARAM_ROLE = 0x00n;
|
|
@@ -133,11 +133,11 @@ function decodeParams(reader) {
|
|
|
133
133
|
} else if (paramType === PARAM_MAX_REQUEST_ID) {
|
|
134
134
|
result.max_request_id = value;
|
|
135
135
|
} else {
|
|
136
|
-
const tmpWriter = new (0,
|
|
136
|
+
const tmpWriter = new (0, _chunkFWISIR26cjs.BufferWriter)(16);
|
|
137
137
|
tmpWriter.writeVarInt(value);
|
|
138
138
|
const raw = tmpWriter.finish();
|
|
139
139
|
unknown.push({
|
|
140
|
-
id:
|
|
140
|
+
id: `0x${paramType.toString(16)}`,
|
|
141
141
|
length: raw.byteLength,
|
|
142
142
|
raw_hex: bytesToHex(raw)
|
|
143
143
|
});
|
|
@@ -149,7 +149,7 @@ function decodeParams(reader) {
|
|
|
149
149
|
result.path = new TextDecoder().decode(bytes);
|
|
150
150
|
} else {
|
|
151
151
|
unknown.push({
|
|
152
|
-
id:
|
|
152
|
+
id: `0x${paramType.toString(16)}`,
|
|
153
153
|
length,
|
|
154
154
|
raw_hex: bytesToHex(bytes)
|
|
155
155
|
});
|
|
@@ -337,7 +337,11 @@ function encodeRequestsBlockedPayload(msg, w) {
|
|
|
337
337
|
function decodeClientSetupPayload(r) {
|
|
338
338
|
const numVersions = Number(r.readVarInt());
|
|
339
339
|
if (numVersions === 0) {
|
|
340
|
-
throw new (0,
|
|
340
|
+
throw new (0, _chunkFWISIR26cjs.DecodeError)(
|
|
341
|
+
"CONSTRAINT_VIOLATION",
|
|
342
|
+
"CLIENT_SETUP must offer at least one version",
|
|
343
|
+
r.offset
|
|
344
|
+
);
|
|
341
345
|
}
|
|
342
346
|
const supported_versions = [];
|
|
343
347
|
for (let i = 0; i < numVersions; i++) {
|
|
@@ -361,7 +365,7 @@ function decodeSubscribePayload(r) {
|
|
|
361
365
|
const filter_type = r.readVarInt();
|
|
362
366
|
const ft = Number(filter_type);
|
|
363
367
|
if (ft < 1 || ft > 4) {
|
|
364
|
-
throw new (0,
|
|
368
|
+
throw new (0, _chunkFWISIR26cjs.DecodeError)("CONSTRAINT_VIOLATION", `Invalid filter_type: ${ft}`, r.offset);
|
|
365
369
|
}
|
|
366
370
|
let start_group;
|
|
367
371
|
let start_object;
|
|
@@ -527,7 +531,16 @@ function decodeFetchPayload(r) {
|
|
|
527
531
|
const start_object = r.readVarInt();
|
|
528
532
|
const end_group = r.readVarInt();
|
|
529
533
|
const parameters = decodeParams(r);
|
|
530
|
-
return {
|
|
534
|
+
return {
|
|
535
|
+
type: "fetch",
|
|
536
|
+
request_id,
|
|
537
|
+
track_namespace,
|
|
538
|
+
track_name,
|
|
539
|
+
start_group,
|
|
540
|
+
start_object,
|
|
541
|
+
end_group,
|
|
542
|
+
parameters
|
|
543
|
+
};
|
|
531
544
|
}
|
|
532
545
|
function decodeFetchOkPayload(r) {
|
|
533
546
|
const request_id = r.readVarInt();
|
|
@@ -627,13 +640,13 @@ function encodeMessage(message) {
|
|
|
627
640
|
if (typeId === void 0) {
|
|
628
641
|
throw new Error(`Unknown message type: ${message.type}`);
|
|
629
642
|
}
|
|
630
|
-
const payloadWriter = new (0,
|
|
643
|
+
const payloadWriter = new (0, _chunkFWISIR26cjs.BufferWriter)();
|
|
631
644
|
encodePayload(message, payloadWriter);
|
|
632
645
|
const payload = payloadWriter.finish();
|
|
633
646
|
if (payload.byteLength > 65535) {
|
|
634
647
|
throw new Error(`Payload too large for 16-bit length: ${payload.byteLength}`);
|
|
635
648
|
}
|
|
636
|
-
const writer = new (0,
|
|
649
|
+
const writer = new (0, _chunkFWISIR26cjs.BufferWriter)();
|
|
637
650
|
writer.writeVarInt(typeId);
|
|
638
651
|
writer.writeUint8(payload.byteLength >> 8 & 255);
|
|
639
652
|
writer.writeUint8(payload.byteLength & 255);
|
|
@@ -710,31 +723,35 @@ function encodePayload(msg, w) {
|
|
|
710
723
|
}
|
|
711
724
|
function decodeMessage(bytes) {
|
|
712
725
|
try {
|
|
713
|
-
const reader = new (0,
|
|
726
|
+
const reader = new (0, _chunkFWISIR26cjs.BufferReader)(bytes);
|
|
714
727
|
const typeId = reader.readVarInt();
|
|
715
728
|
const lenHi = reader.readUint8();
|
|
716
729
|
const lenLo = reader.readUint8();
|
|
717
730
|
const payloadLength = lenHi << 8 | lenLo;
|
|
718
731
|
const payloadBytes = reader.readBytes(payloadLength);
|
|
719
|
-
const payloadReader = new (0,
|
|
732
|
+
const payloadReader = new (0, _chunkFWISIR26cjs.BufferReader)(payloadBytes);
|
|
720
733
|
const decoder = payloadDecoders.get(typeId);
|
|
721
734
|
if (!decoder) {
|
|
722
735
|
return {
|
|
723
736
|
ok: false,
|
|
724
|
-
error: new (0,
|
|
737
|
+
error: new (0, _chunkFWISIR26cjs.DecodeError)(
|
|
738
|
+
"UNKNOWN_MESSAGE_TYPE",
|
|
739
|
+
`Unknown message type ID: 0x${typeId.toString(16)}`,
|
|
740
|
+
0
|
|
741
|
+
)
|
|
725
742
|
};
|
|
726
743
|
}
|
|
727
744
|
const message = decoder(payloadReader);
|
|
728
745
|
return { ok: true, value: message, bytesRead: reader.offset };
|
|
729
746
|
} catch (e) {
|
|
730
|
-
if (e instanceof
|
|
747
|
+
if (e instanceof _chunkFWISIR26cjs.DecodeError) {
|
|
731
748
|
return { ok: false, error: e };
|
|
732
749
|
}
|
|
733
750
|
throw e;
|
|
734
751
|
}
|
|
735
752
|
}
|
|
736
753
|
function encodeSubgroupStream(stream) {
|
|
737
|
-
const w = new (0,
|
|
754
|
+
const w = new (0, _chunkFWISIR26cjs.BufferWriter)();
|
|
738
755
|
w.writeVarInt(0n);
|
|
739
756
|
w.writeVarInt(stream.trackAlias);
|
|
740
757
|
w.writeVarInt(stream.groupId);
|
|
@@ -748,7 +765,7 @@ function encodeSubgroupStream(stream) {
|
|
|
748
765
|
return w.finish();
|
|
749
766
|
}
|
|
750
767
|
function encodeDatagram(dg) {
|
|
751
|
-
const w = new (0,
|
|
768
|
+
const w = new (0, _chunkFWISIR26cjs.BufferWriter)();
|
|
752
769
|
w.writeVarInt(dg.trackAlias);
|
|
753
770
|
w.writeVarInt(dg.groupId);
|
|
754
771
|
w.writeVarInt(dg.objectId);
|
|
@@ -757,7 +774,7 @@ function encodeDatagram(dg) {
|
|
|
757
774
|
return w.finish();
|
|
758
775
|
}
|
|
759
776
|
function encodeFetchStream(stream) {
|
|
760
|
-
const w = new (0,
|
|
777
|
+
const w = new (0, _chunkFWISIR26cjs.BufferWriter)();
|
|
761
778
|
w.writeVarInt(2n);
|
|
762
779
|
w.writeVarInt(stream.subscribeRequestId);
|
|
763
780
|
for (const obj of stream.objects) {
|
|
@@ -769,10 +786,17 @@ function encodeFetchStream(stream) {
|
|
|
769
786
|
}
|
|
770
787
|
function decodeSubgroupStream(bytes) {
|
|
771
788
|
try {
|
|
772
|
-
const r = new (0,
|
|
789
|
+
const r = new (0, _chunkFWISIR26cjs.BufferReader)(bytes);
|
|
773
790
|
const streamType = r.readVarInt();
|
|
774
791
|
if (streamType !== 0n) {
|
|
775
|
-
return {
|
|
792
|
+
return {
|
|
793
|
+
ok: false,
|
|
794
|
+
error: new (0, _chunkFWISIR26cjs.DecodeError)(
|
|
795
|
+
"CONSTRAINT_VIOLATION",
|
|
796
|
+
`Expected subgroup stream type 0, got ${streamType}`,
|
|
797
|
+
0
|
|
798
|
+
)
|
|
799
|
+
};
|
|
776
800
|
}
|
|
777
801
|
const trackAlias = r.readVarInt();
|
|
778
802
|
const groupId = r.readVarInt();
|
|
@@ -791,13 +815,13 @@ function decodeSubgroupStream(bytes) {
|
|
|
791
815
|
bytesRead: r.offset
|
|
792
816
|
};
|
|
793
817
|
} catch (e) {
|
|
794
|
-
if (e instanceof
|
|
818
|
+
if (e instanceof _chunkFWISIR26cjs.DecodeError) return { ok: false, error: e };
|
|
795
819
|
throw e;
|
|
796
820
|
}
|
|
797
821
|
}
|
|
798
822
|
function decodeDatagram(bytes) {
|
|
799
823
|
try {
|
|
800
|
-
const r = new (0,
|
|
824
|
+
const r = new (0, _chunkFWISIR26cjs.BufferReader)(bytes);
|
|
801
825
|
const trackAlias = r.readVarInt();
|
|
802
826
|
const groupId = r.readVarInt();
|
|
803
827
|
const objectId = r.readVarInt();
|
|
@@ -809,16 +833,23 @@ function decodeDatagram(bytes) {
|
|
|
809
833
|
bytesRead: r.offset
|
|
810
834
|
};
|
|
811
835
|
} catch (e) {
|
|
812
|
-
if (e instanceof
|
|
836
|
+
if (e instanceof _chunkFWISIR26cjs.DecodeError) return { ok: false, error: e };
|
|
813
837
|
throw e;
|
|
814
838
|
}
|
|
815
839
|
}
|
|
816
840
|
function decodeFetchStream(bytes) {
|
|
817
841
|
try {
|
|
818
|
-
const r = new (0,
|
|
842
|
+
const r = new (0, _chunkFWISIR26cjs.BufferReader)(bytes);
|
|
819
843
|
const streamType = r.readVarInt();
|
|
820
844
|
if (streamType !== 2n) {
|
|
821
|
-
return {
|
|
845
|
+
return {
|
|
846
|
+
ok: false,
|
|
847
|
+
error: new (0, _chunkFWISIR26cjs.DecodeError)(
|
|
848
|
+
"CONSTRAINT_VIOLATION",
|
|
849
|
+
`Expected fetch stream type 2, got ${streamType}`,
|
|
850
|
+
0
|
|
851
|
+
)
|
|
852
|
+
};
|
|
822
853
|
}
|
|
823
854
|
const subscribeRequestId = r.readVarInt();
|
|
824
855
|
const objects = [];
|
|
@@ -834,7 +865,7 @@ function decodeFetchStream(bytes) {
|
|
|
834
865
|
bytesRead: r.offset
|
|
835
866
|
};
|
|
836
867
|
} catch (e) {
|
|
837
|
-
if (e instanceof
|
|
868
|
+
if (e instanceof _chunkFWISIR26cjs.DecodeError) return { ok: false, error: e };
|
|
838
869
|
throw e;
|
|
839
870
|
}
|
|
840
871
|
}
|
|
@@ -876,7 +907,7 @@ function createStreamDecoder() {
|
|
|
876
907
|
flush(controller) {
|
|
877
908
|
if (buffer.length > 0) {
|
|
878
909
|
controller.error(
|
|
879
|
-
new (0,
|
|
910
|
+
new (0, _chunkFWISIR26cjs.DecodeError)("UNEXPECTED_END", "Stream ended with incomplete message data", 0)
|
|
880
911
|
);
|
|
881
912
|
}
|
|
882
913
|
}
|
|
@@ -893,11 +924,15 @@ function createSubgroupStreamDecoder() {
|
|
|
893
924
|
buffer = newBuffer;
|
|
894
925
|
if (!headerEmitted) {
|
|
895
926
|
try {
|
|
896
|
-
const r = new (0,
|
|
927
|
+
const r = new (0, _chunkFWISIR26cjs.BufferReader)(buffer);
|
|
897
928
|
const streamType = r.readVarInt();
|
|
898
929
|
if (streamType !== 0n) {
|
|
899
930
|
controller.error(
|
|
900
|
-
new (0,
|
|
931
|
+
new (0, _chunkFWISIR26cjs.DecodeError)(
|
|
932
|
+
"CONSTRAINT_VIOLATION",
|
|
933
|
+
`Expected subgroup stream type 0, got ${streamType}`,
|
|
934
|
+
0
|
|
935
|
+
)
|
|
901
936
|
);
|
|
902
937
|
return;
|
|
903
938
|
}
|
|
@@ -915,7 +950,7 @@ function createSubgroupStreamDecoder() {
|
|
|
915
950
|
headerEmitted = true;
|
|
916
951
|
buffer = buffer.slice(r.offset);
|
|
917
952
|
} catch (e) {
|
|
918
|
-
if (e instanceof
|
|
953
|
+
if (e instanceof _chunkFWISIR26cjs.DecodeError && e.code === "UNEXPECTED_END") {
|
|
919
954
|
return;
|
|
920
955
|
}
|
|
921
956
|
controller.error(e);
|
|
@@ -924,14 +959,14 @@ function createSubgroupStreamDecoder() {
|
|
|
924
959
|
}
|
|
925
960
|
while (buffer.length > 0) {
|
|
926
961
|
try {
|
|
927
|
-
const r = new (0,
|
|
962
|
+
const r = new (0, _chunkFWISIR26cjs.BufferReader)(buffer);
|
|
928
963
|
const objectId = r.readVarInt();
|
|
929
964
|
const payloadLength = Number(r.readVarInt());
|
|
930
965
|
const payload = r.readBytes(payloadLength);
|
|
931
966
|
controller.enqueue({ type: "object", objectId, payloadLength, payload });
|
|
932
967
|
buffer = buffer.slice(r.offset);
|
|
933
968
|
} catch (e) {
|
|
934
|
-
if (e instanceof
|
|
969
|
+
if (e instanceof _chunkFWISIR26cjs.DecodeError && e.code === "UNEXPECTED_END") {
|
|
935
970
|
break;
|
|
936
971
|
}
|
|
937
972
|
controller.error(e);
|
|
@@ -941,9 +976,7 @@ function createSubgroupStreamDecoder() {
|
|
|
941
976
|
},
|
|
942
977
|
flush(controller) {
|
|
943
978
|
if (buffer.length > 0) {
|
|
944
|
-
controller.error(
|
|
945
|
-
new (0, _chunk2NARXGVAcjs.DecodeError)("UNEXPECTED_END", "Stream ended with incomplete data", 0)
|
|
946
|
-
);
|
|
979
|
+
controller.error(new (0, _chunkFWISIR26cjs.DecodeError)("UNEXPECTED_END", "Stream ended with incomplete data", 0));
|
|
947
980
|
}
|
|
948
981
|
}
|
|
949
982
|
});
|
|
@@ -959,11 +992,15 @@ function createFetchStreamDecoder() {
|
|
|
959
992
|
buffer = newBuffer;
|
|
960
993
|
if (!headerEmitted) {
|
|
961
994
|
try {
|
|
962
|
-
const r = new (0,
|
|
995
|
+
const r = new (0, _chunkFWISIR26cjs.BufferReader)(buffer);
|
|
963
996
|
const streamType = r.readVarInt();
|
|
964
997
|
if (streamType !== 2n) {
|
|
965
998
|
controller.error(
|
|
966
|
-
new (0,
|
|
999
|
+
new (0, _chunkFWISIR26cjs.DecodeError)(
|
|
1000
|
+
"CONSTRAINT_VIOLATION",
|
|
1001
|
+
`Expected fetch stream type 2, got ${streamType}`,
|
|
1002
|
+
0
|
|
1003
|
+
)
|
|
967
1004
|
);
|
|
968
1005
|
return;
|
|
969
1006
|
}
|
|
@@ -975,7 +1012,7 @@ function createFetchStreamDecoder() {
|
|
|
975
1012
|
headerEmitted = true;
|
|
976
1013
|
buffer = buffer.slice(r.offset);
|
|
977
1014
|
} catch (e) {
|
|
978
|
-
if (e instanceof
|
|
1015
|
+
if (e instanceof _chunkFWISIR26cjs.DecodeError && e.code === "UNEXPECTED_END") {
|
|
979
1016
|
return;
|
|
980
1017
|
}
|
|
981
1018
|
controller.error(e);
|
|
@@ -984,14 +1021,14 @@ function createFetchStreamDecoder() {
|
|
|
984
1021
|
}
|
|
985
1022
|
while (buffer.length > 0) {
|
|
986
1023
|
try {
|
|
987
|
-
const r = new (0,
|
|
1024
|
+
const r = new (0, _chunkFWISIR26cjs.BufferReader)(buffer);
|
|
988
1025
|
const objectId = r.readVarInt();
|
|
989
1026
|
const payloadLength = Number(r.readVarInt());
|
|
990
1027
|
const payload = r.readBytes(payloadLength);
|
|
991
1028
|
controller.enqueue({ type: "object", objectId, payloadLength, payload });
|
|
992
1029
|
buffer = buffer.slice(r.offset);
|
|
993
1030
|
} catch (e) {
|
|
994
|
-
if (e instanceof
|
|
1031
|
+
if (e instanceof _chunkFWISIR26cjs.DecodeError && e.code === "UNEXPECTED_END") {
|
|
995
1032
|
break;
|
|
996
1033
|
}
|
|
997
1034
|
controller.error(e);
|
|
@@ -1001,9 +1038,7 @@ function createFetchStreamDecoder() {
|
|
|
1001
1038
|
},
|
|
1002
1039
|
flush(controller) {
|
|
1003
1040
|
if (buffer.length > 0) {
|
|
1004
|
-
controller.error(
|
|
1005
|
-
new (0, _chunk2NARXGVAcjs.DecodeError)("UNEXPECTED_END", "Stream ended with incomplete data", 0)
|
|
1006
|
-
);
|
|
1041
|
+
controller.error(new (0, _chunkFWISIR26cjs.DecodeError)("UNEXPECTED_END", "Stream ended with incomplete data", 0));
|
|
1007
1042
|
}
|
|
1008
1043
|
}
|
|
1009
1044
|
});
|
|
@@ -1020,7 +1055,7 @@ function createDataStreamDecoder() {
|
|
|
1020
1055
|
buffer = newBuffer;
|
|
1021
1056
|
if (detectedType === null) {
|
|
1022
1057
|
try {
|
|
1023
|
-
const r = new (0,
|
|
1058
|
+
const r = new (0, _chunkFWISIR26cjs.BufferReader)(buffer);
|
|
1024
1059
|
const streamType = r.readVarInt();
|
|
1025
1060
|
if (streamType === 0n) {
|
|
1026
1061
|
detectedType = "subgroup";
|
|
@@ -1028,12 +1063,12 @@ function createDataStreamDecoder() {
|
|
|
1028
1063
|
detectedType = "fetch";
|
|
1029
1064
|
} else {
|
|
1030
1065
|
controller.error(
|
|
1031
|
-
new (0,
|
|
1066
|
+
new (0, _chunkFWISIR26cjs.DecodeError)("CONSTRAINT_VIOLATION", `Unknown data stream type: ${streamType}`, 0)
|
|
1032
1067
|
);
|
|
1033
1068
|
return;
|
|
1034
1069
|
}
|
|
1035
1070
|
} catch (e) {
|
|
1036
|
-
if (e instanceof
|
|
1071
|
+
if (e instanceof _chunkFWISIR26cjs.DecodeError && e.code === "UNEXPECTED_END") {
|
|
1037
1072
|
return;
|
|
1038
1073
|
}
|
|
1039
1074
|
controller.error(e);
|
|
@@ -1043,7 +1078,7 @@ function createDataStreamDecoder() {
|
|
|
1043
1078
|
if (detectedType === "subgroup") {
|
|
1044
1079
|
if (!headerEmitted) {
|
|
1045
1080
|
try {
|
|
1046
|
-
const r = new (0,
|
|
1081
|
+
const r = new (0, _chunkFWISIR26cjs.BufferReader)(buffer);
|
|
1047
1082
|
r.readVarInt();
|
|
1048
1083
|
const trackAlias = r.readVarInt();
|
|
1049
1084
|
const groupId = r.readVarInt();
|
|
@@ -1059,7 +1094,7 @@ function createDataStreamDecoder() {
|
|
|
1059
1094
|
headerEmitted = true;
|
|
1060
1095
|
buffer = buffer.slice(r.offset);
|
|
1061
1096
|
} catch (e) {
|
|
1062
|
-
if (e instanceof
|
|
1097
|
+
if (e instanceof _chunkFWISIR26cjs.DecodeError && e.code === "UNEXPECTED_END") {
|
|
1063
1098
|
return;
|
|
1064
1099
|
}
|
|
1065
1100
|
controller.error(e);
|
|
@@ -1069,7 +1104,7 @@ function createDataStreamDecoder() {
|
|
|
1069
1104
|
} else {
|
|
1070
1105
|
if (!headerEmitted) {
|
|
1071
1106
|
try {
|
|
1072
|
-
const r = new (0,
|
|
1107
|
+
const r = new (0, _chunkFWISIR26cjs.BufferReader)(buffer);
|
|
1073
1108
|
r.readVarInt();
|
|
1074
1109
|
const subscribeRequestId = r.readVarInt();
|
|
1075
1110
|
controller.enqueue({
|
|
@@ -1079,7 +1114,7 @@ function createDataStreamDecoder() {
|
|
|
1079
1114
|
headerEmitted = true;
|
|
1080
1115
|
buffer = buffer.slice(r.offset);
|
|
1081
1116
|
} catch (e) {
|
|
1082
|
-
if (e instanceof
|
|
1117
|
+
if (e instanceof _chunkFWISIR26cjs.DecodeError && e.code === "UNEXPECTED_END") {
|
|
1083
1118
|
return;
|
|
1084
1119
|
}
|
|
1085
1120
|
controller.error(e);
|
|
@@ -1089,14 +1124,14 @@ function createDataStreamDecoder() {
|
|
|
1089
1124
|
}
|
|
1090
1125
|
while (buffer.length > 0) {
|
|
1091
1126
|
try {
|
|
1092
|
-
const r = new (0,
|
|
1127
|
+
const r = new (0, _chunkFWISIR26cjs.BufferReader)(buffer);
|
|
1093
1128
|
const objectId = r.readVarInt();
|
|
1094
1129
|
const payloadLength = Number(r.readVarInt());
|
|
1095
1130
|
const payload = r.readBytes(payloadLength);
|
|
1096
1131
|
controller.enqueue({ type: "object", objectId, payloadLength, payload });
|
|
1097
1132
|
buffer = buffer.slice(r.offset);
|
|
1098
1133
|
} catch (e) {
|
|
1099
|
-
if (e instanceof
|
|
1134
|
+
if (e instanceof _chunkFWISIR26cjs.DecodeError && e.code === "UNEXPECTED_END") {
|
|
1100
1135
|
break;
|
|
1101
1136
|
}
|
|
1102
1137
|
controller.error(e);
|
|
@@ -1106,9 +1141,7 @@ function createDataStreamDecoder() {
|
|
|
1106
1141
|
},
|
|
1107
1142
|
flush(controller) {
|
|
1108
1143
|
if (buffer.length > 0) {
|
|
1109
|
-
controller.error(
|
|
1110
|
-
new (0, _chunk2NARXGVAcjs.DecodeError)("UNEXPECTED_END", "Stream ended with incomplete data", 0)
|
|
1111
|
-
);
|
|
1144
|
+
controller.error(new (0, _chunkFWISIR26cjs.DecodeError)("UNEXPECTED_END", "Stream ended with incomplete data", 0));
|
|
1112
1145
|
}
|
|
1113
1146
|
}
|
|
1114
1147
|
});
|
|
@@ -35,7 +35,11 @@ var BufferReader = class {
|
|
|
35
35
|
}
|
|
36
36
|
readBytes(length) {
|
|
37
37
|
if (this.remaining < length) {
|
|
38
|
-
throw new DecodeError(
|
|
38
|
+
throw new DecodeError(
|
|
39
|
+
"UNEXPECTED_END",
|
|
40
|
+
`Not enough bytes: need ${length}, have ${this.remaining}`,
|
|
41
|
+
this.pos
|
|
42
|
+
);
|
|
39
43
|
}
|
|
40
44
|
const slice = this.buffer.slice(this.pos, this.pos + length);
|
|
41
45
|
this.pos += length;
|