sonic-ws 1.3.1 → 1.3.2
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/index.js +14 -4
- package/dist/version.js +1 -10
- package/dist/ws/Connection.d.ts +64 -1
- package/dist/ws/Connection.js +1 -111
- package/dist/ws/PacketProcessor.js +1 -37
- package/dist/ws/client/core/ClientCore.js +1 -219
- package/dist/ws/client/node/ClientNode.js +1 -17
- package/dist/ws/debug/DebugServer.js +1 -197
- package/dist/ws/packets/PacketProcessors.d.ts +1 -1
- package/dist/ws/packets/PacketProcessors.js +1 -302
- package/dist/ws/packets/PacketType.js +1 -46
- package/dist/ws/packets/Packets.d.ts +8 -9
- package/dist/ws/packets/Packets.js +1 -295
- package/dist/ws/server/SonicWSConnection.js +1 -250
- package/dist/ws/server/SonicWSServer.js +1 -231
- package/dist/ws/util/BufferUtil.d.ts +3 -1
- package/dist/ws/util/BufferUtil.js +1 -25
- package/dist/ws/util/StringUtil.d.ts +0 -1
- package/dist/ws/util/StringUtil.js +1 -38
- package/dist/ws/util/enums/EnumHandler.js +1 -35
- package/dist/ws/util/enums/EnumType.js +1 -53
- package/dist/ws/util/packets/BatchHelper.js +1 -70
- package/dist/ws/util/packets/CompressionUtil.d.ts +6 -13
- package/dist/ws/util/packets/CompressionUtil.js +1 -325
- package/dist/ws/util/packets/HashUtil.js +1 -107
- package/dist/ws/util/packets/JSONUtil.js +1 -164
- package/dist/ws/util/packets/PacketHolder.js +1 -87
- package/dist/ws/util/packets/PacketUtils.js +1 -224
- package/dist/ws/util/packets/RateHandler.js +1 -51
- package/package.json +3 -2
- package/dist/ws/debug/DebugClient.d.ts +0 -11
- package/dist/ws/debug/DebugClient.js +0 -448
|
@@ -2,329 +2,5 @@
|
|
|
2
2
|
* Copyright 2026 Lily (liwybloc)
|
|
3
3
|
* Licensed under the Apache License, Version 2.0.
|
|
4
4
|
*/
|
|
5
|
-
"use strict";
|
|
6
5
|
|
|
7
|
-
Object.defineProperty(exports,
|
|
8
|
-
exports.decompressBools = exports.compressBools = exports.varIntOverflowPow = exports.EMPTY_UINT8 = exports.ONE_FOURTH = exports.ONE_EIGHT = exports.MAX_VARINT = exports.MAX_UVARINT = exports.MAX_VSECT_SIZE = exports.VARINT_OVERFLOW = exports.NEGATIVE_VARINT = exports.VARINT_CHAIN_FLAG = exports.UVARINT_OVERFLOW = exports.MAX_INT_D = exports.SHORT_OVERFLOW = exports.SHORT_CC_OVERFLOW = exports.NEGATIVE_SHORT = exports.MAX_SHORT = exports.BYTE_OVERFLOW = exports.NEGATIVE_BYTE = exports.MAX_BYTE = void 0;
|
|
9
|
-
exports.fromShort = fromShort;
|
|
10
|
-
exports.toShort = toShort;
|
|
11
|
-
exports.toByte = toByte;
|
|
12
|
-
exports.sectorSize = sectorSize;
|
|
13
|
-
exports.convertBase = convertBase;
|
|
14
|
-
exports.convertFloat = convertFloat;
|
|
15
|
-
exports.deconvertFloat = deconvertFloat;
|
|
16
|
-
exports.convertDouble = convertDouble;
|
|
17
|
-
exports.deconvertDouble = deconvertDouble;
|
|
18
|
-
exports.mapZigZag = mapZigZag;
|
|
19
|
-
exports.demapZigZag = demapZigZag;
|
|
20
|
-
exports.demapShort_ZZ = demapShort_ZZ;
|
|
21
|
-
exports.mapShort_ZZ = mapShort_ZZ;
|
|
22
|
-
exports.convertVarInt = convertVarInt;
|
|
23
|
-
exports.readVarInt = readVarInt;
|
|
24
|
-
exports.deconvertVarInts = deconvertVarInts;
|
|
25
|
-
exports.bytesToBits = bytesToBits;
|
|
26
|
-
exports.bitsToBytes = bitsToBytes;
|
|
27
|
-
exports.compressGzip = compressGzip;
|
|
28
|
-
exports.decompressGzip = decompressGzip;
|
|
29
|
-
exports.bytesToHex = bytesToHex;
|
|
30
|
-
exports.hexToBytes = hexToBytes;
|
|
31
|
-
const BufferUtil_1 = require("../BufferUtil");
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
exports.MAX_BYTE = 0xFF;
|
|
35
|
-
|
|
36
|
-
exports.NEGATIVE_BYTE = Math.floor(exports.MAX_BYTE / 2);
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
exports.BYTE_OVERFLOW = exports.NEGATIVE_BYTE + 1;
|
|
40
|
-
|
|
41
|
-
exports.MAX_SHORT = 0xFFFF;
|
|
42
|
-
|
|
43
|
-
exports.NEGATIVE_SHORT = Math.floor(exports.MAX_SHORT / 2);
|
|
44
|
-
|
|
45
|
-
exports.SHORT_CC_OVERFLOW = exports.MAX_BYTE + 1;
|
|
46
|
-
|
|
47
|
-
exports.SHORT_OVERFLOW = exports.MAX_SHORT + 1;
|
|
48
|
-
|
|
49
|
-
exports.MAX_INT_D = Number.MAX_SAFE_INTEGER;
|
|
50
|
-
|
|
51
|
-
exports.UVARINT_OVERFLOW = exports.NEGATIVE_BYTE + 1, exports.VARINT_CHAIN_FLAG = 0x80, exports.NEGATIVE_VARINT = Math.floor(exports.NEGATIVE_BYTE / 2), exports.VARINT_OVERFLOW = exports.NEGATIVE_VARINT + 1, exports.MAX_VSECT_SIZE = 7, exports.MAX_UVARINT = (exports.UVARINT_OVERFLOW ** exports.MAX_VSECT_SIZE) - 1, exports.MAX_VARINT = Math.floor(exports.MAX_UVARINT / 2);
|
|
52
|
-
|
|
53
|
-
exports.ONE_EIGHT = 1 / 8, exports.ONE_FOURTH = 1 / 4;
|
|
54
|
-
exports.EMPTY_UINT8 = new Uint8Array([]);
|
|
55
|
-
|
|
56
|
-
const VARINT_OVERFLOW_POWS = [];
|
|
57
|
-
const varIntOverflowPow = (num) => VARINT_OVERFLOW_POWS[num] ??= exports.UVARINT_OVERFLOW ** num;
|
|
58
|
-
exports.varIntOverflowPow = varIntOverflowPow;
|
|
59
|
-
const TWO_POWS = [];
|
|
60
|
-
const twoPow = (num) => TWO_POWS[num] ??= Math.pow(2, num);
|
|
61
|
-
for (let i = 0; i <= 3; i++) {
|
|
62
|
-
(0, exports.varIntOverflowPow)(i);
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
function fromShort(short) {
|
|
66
|
-
|
|
67
|
-
return short[0] * exports.SHORT_CC_OVERFLOW + short[1];
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
function toShort(n) {
|
|
71
|
-
|
|
72
|
-
if (!isFinite(n))
|
|
73
|
-
throw new Error("Can only use real numbers in shorts: " + n);
|
|
74
|
-
|
|
75
|
-
if (n > exports.MAX_SHORT || n < 0)
|
|
76
|
-
throw new Error(`Short Numbers must be within range 0 and ${exports.MAX_SHORT}`);
|
|
77
|
-
|
|
78
|
-
return [Math.floor(n / exports.SHORT_CC_OVERFLOW), n % exports.SHORT_CC_OVERFLOW];
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
function toByte(n) {
|
|
82
|
-
|
|
83
|
-
if (!isFinite(n))
|
|
84
|
-
throw new Error("Can only use real numbers in bytes: " + n);
|
|
85
|
-
;
|
|
86
|
-
|
|
87
|
-
if (n > exports.MAX_BYTE || n < -exports.MAX_BYTE - 1)
|
|
88
|
-
throw new Error(`Byte Numbers must be within range -${exports.MAX_BYTE + 1} and ${exports.MAX_BYTE}: ${n}`);
|
|
89
|
-
return n;
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
function sectorSize(number, pow) {
|
|
93
|
-
number = Math.abs(number);
|
|
94
|
-
|
|
95
|
-
let count = 1;
|
|
96
|
-
|
|
97
|
-
for (let num = pow(1); number >= num; num = pow(++count))
|
|
98
|
-
;
|
|
99
|
-
return count;
|
|
100
|
-
}
|
|
101
|
-
|
|
102
|
-
function convertBase(number, chars, neg, overflow, overflowFunc) {
|
|
103
|
-
|
|
104
|
-
if (!isFinite(number))
|
|
105
|
-
throw new Error("Cannot use a non-finite number: " + number);
|
|
106
|
-
|
|
107
|
-
if (number == 0)
|
|
108
|
-
return Array.from({ length: chars }).map(() => 0);
|
|
109
|
-
if (chars == 1)
|
|
110
|
-
return [number];
|
|
111
|
-
|
|
112
|
-
const negative = number < 0;
|
|
113
|
-
number = Math.abs(number);
|
|
114
|
-
|
|
115
|
-
if (number > exports.MAX_INT_D)
|
|
116
|
-
throw new Error(`Non-float numbers must be within range -${exports.MAX_INT_D.toLocaleString()} and ${exports.MAX_INT_D.toLocaleString()}: ${number}`);
|
|
117
|
-
let result = [];
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
const posPowerAmt = chars - 1;
|
|
121
|
-
for (let i = 0; i < posPowerAmt; i++) {
|
|
122
|
-
const power = overflowFunc(posPowerAmt - i);
|
|
123
|
-
const based = Math.floor(number / power);
|
|
124
|
-
result.push(based);
|
|
125
|
-
|
|
126
|
-
number -= based * power;
|
|
127
|
-
}
|
|
128
|
-
|
|
129
|
-
result.push(number % overflow);
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
const bits = negative ? result.map(part => part > 0 ? part + neg : part)
|
|
133
|
-
: result;
|
|
134
|
-
return bits;
|
|
135
|
-
}
|
|
136
|
-
|
|
137
|
-
const compressBools = (array) => array.reduce((byte, val, i) => byte | (val << (7 - i)), 0);
|
|
138
|
-
exports.compressBools = compressBools;
|
|
139
|
-
const decompressBools = (byte) => [...Array(8)].map((_, i) => (byte & (1 << (7 - i))) !== 0);
|
|
140
|
-
exports.decompressBools = decompressBools;
|
|
141
|
-
|
|
142
|
-
const MAN_BITS = 23;
|
|
143
|
-
function parseBin(str) {
|
|
144
|
-
return parseInt(str, 2);
|
|
145
|
-
}
|
|
146
|
-
function parseMan(bin, isNormal) {
|
|
147
|
-
const mantissaInt = parseBin(bin);
|
|
148
|
-
let fraction = 0;
|
|
149
|
-
for (let i = 0; i < MAN_BITS; i++) {
|
|
150
|
-
if (mantissaInt & (1 << (MAN_BITS - i - 1))) {
|
|
151
|
-
fraction += twoPow(-(i + 1));
|
|
152
|
-
}
|
|
153
|
-
}
|
|
154
|
-
return (isNormal ? 1 : 0) + fraction;
|
|
155
|
-
}
|
|
156
|
-
|
|
157
|
-
const FLOAT_EXPSIZE = 8, FLOAT_FRACTSIZE = 23;
|
|
158
|
-
const DOUBLE_EXPSIZE = 11, DOUBLE_FRACTSIZE = 52;
|
|
159
|
-
const FLOAT_SPECIAL = 0xFF, DOUBLE_SPECIAL = 0x7FF;
|
|
160
|
-
|
|
161
|
-
function assembleFloatingPoint(expSize, fractSize, sign, exponent, mantissa) {
|
|
162
|
-
const bin = sign.toString(2) + exponent.toString(2).padStart(expSize, "0") + mantissa.toString(2).padStart(fractSize, "0");
|
|
163
|
-
return (0, BufferUtil_1.splitArray)(bin, 8).map((x) => parseBin(x));
|
|
164
|
-
}
|
|
165
|
-
function assembleSingleFloat(sign, exponent, mantissa) {
|
|
166
|
-
return assembleFloatingPoint(FLOAT_EXPSIZE, FLOAT_FRACTSIZE, sign, exponent, mantissa);
|
|
167
|
-
}
|
|
168
|
-
function assembleDoubleFloat(sign, exponent, mantissa) {
|
|
169
|
-
return assembleFloatingPoint(DOUBLE_EXPSIZE, DOUBLE_FRACTSIZE, sign, exponent, mantissa);
|
|
170
|
-
}
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
function convertFloat(flt) {
|
|
174
|
-
if (isNaN(flt))
|
|
175
|
-
return assembleSingleFloat(0, FLOAT_SPECIAL, 1);
|
|
176
|
-
const sign = (flt < 0) ? 1 : 0;
|
|
177
|
-
flt = Math.abs(flt);
|
|
178
|
-
if (flt == 0.0)
|
|
179
|
-
return assembleSingleFloat(sign, 0, 0);
|
|
180
|
-
const exponent = Math.floor(Math.log(flt) / Math.LN2);
|
|
181
|
-
if (exponent > 127 || exponent < -126)
|
|
182
|
-
return assembleSingleFloat(sign, 0xFF, 0);
|
|
183
|
-
const mantissa = flt / twoPow(exponent);
|
|
184
|
-
const roundMan = Math.round((mantissa - 1) * twoPow(23));
|
|
185
|
-
return assembleSingleFloat(sign, exponent + 127, roundMan & 0x7FFFFF);
|
|
186
|
-
}
|
|
187
|
-
function deconvertFloat(bytes) {
|
|
188
|
-
const bin = bytes.map(x => x.toString(2).padStart(8, "0")).join("");
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
const sign = parseBin(bin[0]);
|
|
193
|
-
const rawExp = parseBin(bin.slice(1, 9));
|
|
194
|
-
const exp = rawExp == 0 ? -126 : rawExp - 127;
|
|
195
|
-
const man = parseMan(bin.slice(9, 32), rawExp != 0);
|
|
196
|
-
let result;
|
|
197
|
-
if (rawExp == FLOAT_SPECIAL) {
|
|
198
|
-
result = man == 0 ? Infinity : NaN;
|
|
199
|
-
}
|
|
200
|
-
else {
|
|
201
|
-
result = man * twoPow(exp);
|
|
202
|
-
}
|
|
203
|
-
return sign == 1 ? -result : result;
|
|
204
|
-
}
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
function convertDouble(double) {
|
|
208
|
-
if (isNaN(double))
|
|
209
|
-
return assembleDoubleFloat(0, DOUBLE_SPECIAL, 1);
|
|
210
|
-
const sign = double < 0 ? 1 : 0;
|
|
211
|
-
if (!isFinite(double))
|
|
212
|
-
return assembleDoubleFloat(sign, DOUBLE_SPECIAL, 0);
|
|
213
|
-
double = Math.abs(double);
|
|
214
|
-
let exponent, significand;
|
|
215
|
-
if (double == 0) {
|
|
216
|
-
exponent = 0;
|
|
217
|
-
significand = 0;
|
|
218
|
-
}
|
|
219
|
-
else {
|
|
220
|
-
exponent = Math.floor(Math.log2(double)) - 51;
|
|
221
|
-
significand = Math.floor(double / twoPow(exponent));
|
|
222
|
-
}
|
|
223
|
-
return assembleDoubleFloat(sign, exponent + 1023, significand);
|
|
224
|
-
}
|
|
225
|
-
function deconvertDouble(bytes) {
|
|
226
|
-
const bin = bytes.map(x => x.toString(2).padStart(8, "0")).join("");
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
const sign = parseBin(bin[0]);
|
|
231
|
-
const rawExp = parseBin(bin.slice(1, 12));
|
|
232
|
-
const exp = rawExp == 0 ? -1022 : rawExp - 1023;
|
|
233
|
-
const man = parseBin(bin.slice(12, 64));
|
|
234
|
-
let result;
|
|
235
|
-
if (rawExp == DOUBLE_SPECIAL) {
|
|
236
|
-
result = man == 0 ? Infinity : NaN;
|
|
237
|
-
}
|
|
238
|
-
else {
|
|
239
|
-
result = man * twoPow(exp);
|
|
240
|
-
}
|
|
241
|
-
return sign == 1 ? -result : result;
|
|
242
|
-
}
|
|
243
|
-
|
|
244
|
-
function mapZigZag(n) {
|
|
245
|
-
return ((n << 1) ^ (n >> 31));
|
|
246
|
-
}
|
|
247
|
-
function demapZigZag(n) {
|
|
248
|
-
return (n >>> 1) ^ -((n & 1));
|
|
249
|
-
}
|
|
250
|
-
function demapShort_ZZ(short) {
|
|
251
|
-
return demapZigZag(fromShort(short));
|
|
252
|
-
}
|
|
253
|
-
function mapShort_ZZ(short) {
|
|
254
|
-
return toShort(mapZigZag(short));
|
|
255
|
-
}
|
|
256
|
-
|
|
257
|
-
function convertVarInt(num) {
|
|
258
|
-
if (num > exports.MAX_UVARINT || num < 0)
|
|
259
|
-
throw new Error(`Variable Ints must be within range 0 and ${exports.MAX_VARINT}: ${num}`);
|
|
260
|
-
const chars = sectorSize(num, exports.varIntOverflowPow);
|
|
261
|
-
return convertBase(num, chars, exports.VARINT_OVERFLOW, exports.UVARINT_OVERFLOW, exports.varIntOverflowPow).map((x, i) => i == 0 ? x : x | exports.VARINT_CHAIN_FLAG).reverse();
|
|
262
|
-
}
|
|
263
|
-
function readVarInt(arr, off) {
|
|
264
|
-
let num = [];
|
|
265
|
-
let cont;
|
|
266
|
-
do {
|
|
267
|
-
const part = arr[off++];
|
|
268
|
-
cont = (part & exports.VARINT_CHAIN_FLAG) != 0;
|
|
269
|
-
num.push(cont ? part ^ exports.VARINT_CHAIN_FLAG : part);
|
|
270
|
-
} while (cont);
|
|
271
|
-
const number = num.reduce((p, c, i) => p + c * (0, exports.varIntOverflowPow)(i), 0);
|
|
272
|
-
return [off, number];
|
|
273
|
-
}
|
|
274
|
-
function deconvertVarInts(arr) {
|
|
275
|
-
let res = [];
|
|
276
|
-
let i = 0;
|
|
277
|
-
while (i < arr.length) {
|
|
278
|
-
const [off, varint] = readVarInt(arr, i);
|
|
279
|
-
res.push(varint);
|
|
280
|
-
i = off;
|
|
281
|
-
}
|
|
282
|
-
return res;
|
|
283
|
-
}
|
|
284
|
-
function bytesToBits(bytes) {
|
|
285
|
-
return Array.from(bytes).map(b => b.toString(2).padStart(8, '0')).join('');
|
|
286
|
-
}
|
|
287
|
-
function bitsToBytes(bitString) {
|
|
288
|
-
const bytes = [];
|
|
289
|
-
for (let i = 0; i < bitString.length; i += 8) {
|
|
290
|
-
const byte = bitString.slice(i, i + 8).padEnd(8, '0');
|
|
291
|
-
bytes.push(parseInt(byte, 2));
|
|
292
|
-
}
|
|
293
|
-
return new Uint8Array(bytes);
|
|
294
|
-
}
|
|
295
|
-
const gzipError = "Your browser is too old to support compression. Please update!";
|
|
296
|
-
async function compressGzip(data, ident = "") {
|
|
297
|
-
if (typeof CompressionStream === "undefined") {
|
|
298
|
-
if (typeof window !== "undefined")
|
|
299
|
-
window.alert(gzipError);
|
|
300
|
-
throw new Error(gzipError);
|
|
301
|
-
}
|
|
302
|
-
const stream = new Blob([data]).stream().pipeThrough(new CompressionStream("deflate-raw"));
|
|
303
|
-
const buffer = await new Response(stream).arrayBuffer();
|
|
304
|
-
if (data.length <= buffer.byteLength && ident != "") {
|
|
305
|
-
console.warn("WARN: Packet '" + ident + "' is small, and compressing it makes the size bigger!");
|
|
306
|
-
}
|
|
307
|
-
return new Uint8Array(buffer);
|
|
308
|
-
}
|
|
309
|
-
async function decompressGzip(data) {
|
|
310
|
-
if (typeof DecompressionStream === "undefined") {
|
|
311
|
-
if (typeof window !== "undefined")
|
|
312
|
-
window.alert(gzipError);
|
|
313
|
-
throw new Error(gzipError);
|
|
314
|
-
}
|
|
315
|
-
const stream = new Blob([data]).stream().pipeThrough(new DecompressionStream("deflate-raw"));
|
|
316
|
-
const buffer = await new Response(stream).arrayBuffer();
|
|
317
|
-
return new Uint8Array(buffer);
|
|
318
|
-
}
|
|
319
|
-
function bytesToHex(bytes) {
|
|
320
|
-
return Array.from(bytes, b => b.toString(16).padStart(2, '0')).join('');
|
|
321
|
-
}
|
|
322
|
-
;
|
|
323
|
-
function hexToBytes(hex) {
|
|
324
|
-
const bytes = new Uint8Array(hex.length / 2);
|
|
325
|
-
for (let i = 0; i < hex.length; i += 2) {
|
|
326
|
-
bytes[i / 2] = parseInt(hex.substring(i, i + 2), 16);
|
|
327
|
-
}
|
|
328
|
-
return bytes;
|
|
329
|
-
}
|
|
330
|
-
;
|
|
6
|
+
Object.defineProperty(exports,"__esModule",{value:!0}),exports.bitsToBytes=exports.bytesToBits=exports.decompressBools=exports.compressBools=exports.EMPTY_UINT8=exports.ONE_FOURTH=exports.ONE_EIGHT=exports.MAX_VARINT=exports.MAX_UVARINT=exports.MAX_VSECT_SIZE=exports.VARINT_OVERFLOW=exports.NEGATIVE_VARINT=exports.VARINT_CHAIN_FLAG=exports.UVARINT_OVERFLOW=exports.SHORT_CC_OVERFLOW=exports.MAX_SHORT=exports.NEGATIVE_BYTE=exports.MAX_BYTE=void 0,exports.fromShort=o,exports.toShort=n,exports.toByte=function(t){if(!isFinite(t))throw new Error("Can only use real numbers in bytes: "+t);if(t>exports.MAX_BYTE||t<-exports.MAX_BYTE-1)throw new Error(`Byte Numbers must be within range -${exports.MAX_BYTE+1} and ${exports.MAX_BYTE}: ${t}`);return t},exports.convertFloat=function(t){if(isNaN(t))return T(0,A,1);const r=t<0?1:0;if(0==(t=Math.abs(t)))return T(r,0,0);const o=Math.floor(Math.log(t)/Math.LN2);if(o>127||o<-126)return T(r,255,0);const n=t/e(o),s=Math.round((n-1)*e(23));return T(r,o+127,8388607&s)},exports.deconvertFloat=function(t){const r=t.map(t=>t.toString(2).padStart(8,"0")).join(""),o=p(r[0]),n=p(r.slice(1,9)),i=0==n?-126:n-127,a=function(t,r){const o=p(t);let n=0;for(let t=0;t<s;t++)o&1<<s-t-1&&(n+=e(-(t+1)));return(r?1:0)+n}(r.slice(9,32),0!=n);let u;u=n==A?0==a?1/0:NaN:a*e(i);return 1==o?-u:u},exports.convertDouble=function(t){if(isNaN(t))return _(0,c,1);const r=t<0?1:0;if(!isFinite(t))return _(r,c,0);let o,n;0==(t=Math.abs(t))?(o=0,n=0):(o=Math.floor(Math.log2(t))-51,n=Math.floor(t/e(o)));return _(r,o+1023,n)},exports.deconvertDouble=function(t){const r=t.map(t=>t.toString(2).padStart(8,"0")).join(""),o=p(r[0]),n=p(r.slice(1,12)),s=0==n?-1022:n-1023,i=p(r.slice(12,64));let a;a=n==c?0==i?1/0:NaN:i*e(s);return 1==o?-a:a},exports.mapZigZag=E,exports.demapZigZag=l,exports.demapShort_ZZ=function(t){return l(o(t))},exports.mapShort_ZZ=function(t){return n(E(t))},exports.convertVarInt=function(t){if(t>exports.MAX_UVARINT||t<0)throw new Error(`Variable Ints must be within range 0 and ${exports.MAX_VARINT}: ${t}`);if(0===t)return[0];const r=[];for(;t>0;){let e=127&t;(t>>>=7)>0&&(e|=exports.VARINT_CHAIN_FLAG),r.push(e)}return r},exports.readVarInt=N,exports.deconvertVarInts=function(t){let r=[],e=0;for(;e<t.length;){const[o,n]=N(t,e);r.push(n),e=o}return r},exports.compressGzip=async function(t,r=""){if("undefined"==typeof CompressionStream)throw"undefined"!=typeof window&&window.alert(I),new Error(I);const e=new Blob([t]).stream().pipeThrough(new CompressionStream("deflate-raw")),o=await new Response(e).arrayBuffer();t.length<=o.byteLength&&""!=r&&console.warn("WARN: Packet '"+r+"' is small, and compressing it makes the size bigger!");return new Uint8Array(o)},exports.decompressGzip=async function(t){if("undefined"==typeof DecompressionStream)throw"undefined"!=typeof window&&window.alert(I),new Error(I);const r=new Blob([t]).stream().pipeThrough(new DecompressionStream("deflate-raw")),e=await new Response(r).arrayBuffer();return new Uint8Array(e)},exports.bytesToHex=function(t){return Array.from(t,t=>t.toString(16).padStart(2,"0")).join("")},exports.hexToBytes=function(t){const r=new Uint8Array(t.length/2);for(let e=0;e<t.length;e+=2)r[e/2]=parseInt(t.substring(e,e+2),16);return r};const t=require("../BufferUtil");exports.MAX_BYTE=255,exports.NEGATIVE_BYTE=127,exports.MAX_SHORT=65535,exports.SHORT_CC_OVERFLOW=exports.MAX_BYTE+1,exports.UVARINT_OVERFLOW=exports.NEGATIVE_BYTE+1,exports.VARINT_CHAIN_FLAG=128,exports.NEGATIVE_VARINT=Math.floor(exports.NEGATIVE_BYTE/2),exports.VARINT_OVERFLOW=exports.NEGATIVE_VARINT+1,exports.MAX_VSECT_SIZE=7,exports.MAX_UVARINT=exports.UVARINT_OVERFLOW**exports.MAX_VSECT_SIZE-1,exports.MAX_VARINT=Math.floor(exports.MAX_UVARINT/2),exports.ONE_EIGHT=1/8,exports.ONE_FOURTH=1/4,exports.EMPTY_UINT8=new Uint8Array([]);const r=[],e=t=>r[t]??=Math.pow(2,t);function o(t){return t[0]*exports.SHORT_CC_OVERFLOW+t[1]}function n(t){if(!isFinite(t))throw new Error("Can only use real numbers in shorts: "+t);if(t>exports.MAX_SHORT||t<0)throw new Error(`Short Numbers must be within range 0 and ${exports.MAX_SHORT}`);return[Math.floor(t/exports.SHORT_CC_OVERFLOW),t%exports.SHORT_CC_OVERFLOW]}exports.compressBools=t=>t.reduce((t,r,e)=>t|r<<7-e,0);exports.decompressBools=t=>[...Array(8)].map((r,e)=>!!(t&1<<7-e));const s=23;function p(t){return parseInt(t,2)}const i=8,a=23,u=11,x=52,A=255,c=2047;function f(r,e,o,n,s){const i=o.toString(2)+n.toString(2).padStart(r,"0")+s.toString(2).padStart(e,"0");return(0,t.splitArray)(Array.from(i),8).map(t=>p(t.join("")))}function T(t,r,e){return f(i,a,t,r,e)}function _(t,r,e){return f(u,x,t,r,e)}function E(t){return t<<1^t>>31}function l(t){return t>>>1^-(1&t)}function N(t,r){let e,o=0,n=0;do{e=t[r++],o+=(e&~exports.VARINT_CHAIN_FLAG)<<n,n+=7}while(0!==(e&exports.VARINT_CHAIN_FLAG));return[r,o]}exports.bytesToBits=t=>Array.from(t).map(t=>t.toString(2).padStart(8,"0")).join("");exports.bitsToBytes=t=>new Uint8Array(t.match(/.{1,8}/g)?.map(t=>parseInt(t.padEnd(8,"0"),2))??[]);const I="Your browser is too old to support compression. Please update!";
|
|
@@ -2,111 +2,5 @@
|
|
|
2
2
|
* Copyright 2026 Lily (liwybloc)
|
|
3
3
|
* Licensed under the Apache License, Version 2.0.
|
|
4
4
|
*/
|
|
5
|
-
"use strict";
|
|
6
5
|
|
|
7
|
-
Object.defineProperty(exports,
|
|
8
|
-
exports.setHashFunc = setHashFunc;
|
|
9
|
-
exports.hashValue = hashValue;
|
|
10
|
-
const HASH_INIT_64 = 14695981039346656037n;
|
|
11
|
-
const HASH_PRIME_64 = 1099511628211n;
|
|
12
|
-
const MASK_64 = (1n << 64n) - 1n;
|
|
13
|
-
const hashValue64 = (value) => {
|
|
14
|
-
let hash = HASH_INIT_64;
|
|
15
|
-
const walk = (v) => {
|
|
16
|
-
if (v === null) {
|
|
17
|
-
hash ^= 0n;
|
|
18
|
-
hash = (hash * HASH_PRIME_64) & MASK_64;
|
|
19
|
-
return;
|
|
20
|
-
}
|
|
21
|
-
const t = typeof v;
|
|
22
|
-
if (t === "number") {
|
|
23
|
-
hash ^= BigInt(Math.trunc(v));
|
|
24
|
-
hash = (hash * HASH_PRIME_64) & MASK_64;
|
|
25
|
-
return;
|
|
26
|
-
}
|
|
27
|
-
if (t === "string") {
|
|
28
|
-
for (let i = 0; i < v.length; i++) {
|
|
29
|
-
hash ^= BigInt(v.charCodeAt(i));
|
|
30
|
-
hash = (hash * HASH_PRIME_64) & MASK_64;
|
|
31
|
-
}
|
|
32
|
-
return;
|
|
33
|
-
}
|
|
34
|
-
if (t === "boolean") {
|
|
35
|
-
hash ^= v ? 1n : 0n;
|
|
36
|
-
hash = (hash * HASH_PRIME_64) & MASK_64;
|
|
37
|
-
return;
|
|
38
|
-
}
|
|
39
|
-
if (Array.isArray(v)) {
|
|
40
|
-
for (let i = 0; i < v.length; i++) {
|
|
41
|
-
walk(v[i]);
|
|
42
|
-
}
|
|
43
|
-
return;
|
|
44
|
-
}
|
|
45
|
-
if (t === "object") {
|
|
46
|
-
const keys = Object.keys(v).sort();
|
|
47
|
-
for (let i = 0; i < keys.length; i++) {
|
|
48
|
-
const k = keys[i];
|
|
49
|
-
for (let j = 0; j < k.length; j++) {
|
|
50
|
-
hash ^= BigInt(k.charCodeAt(j));
|
|
51
|
-
hash = (hash * HASH_PRIME_64) & MASK_64;
|
|
52
|
-
}
|
|
53
|
-
walk(v[k]);
|
|
54
|
-
}
|
|
55
|
-
}
|
|
56
|
-
};
|
|
57
|
-
walk(value);
|
|
58
|
-
return hash;
|
|
59
|
-
};
|
|
60
|
-
const HASH_INIT = 2166136261;
|
|
61
|
-
const hashValue32 = (value) => {
|
|
62
|
-
let hash = HASH_INIT;
|
|
63
|
-
const walk = (v) => {
|
|
64
|
-
if (v === null) {
|
|
65
|
-
hash ^= 0;
|
|
66
|
-
return;
|
|
67
|
-
}
|
|
68
|
-
const t = typeof v;
|
|
69
|
-
if (t === "number") {
|
|
70
|
-
hash ^= v | 0;
|
|
71
|
-
hash += (hash << 1) + (hash << 4) + (hash << 7) + (hash << 8) + (hash << 24);
|
|
72
|
-
return;
|
|
73
|
-
}
|
|
74
|
-
if (t === "string") {
|
|
75
|
-
for (let i = 0; i < v.length; i++) {
|
|
76
|
-
hash ^= v.charCodeAt(i);
|
|
77
|
-
hash += (hash << 1) + (hash << 4) + (hash << 7) + (hash << 8) + (hash << 24);
|
|
78
|
-
}
|
|
79
|
-
return;
|
|
80
|
-
}
|
|
81
|
-
if (t === "boolean") {
|
|
82
|
-
hash ^= v ? 1 : 0;
|
|
83
|
-
return;
|
|
84
|
-
}
|
|
85
|
-
if (Array.isArray(v)) {
|
|
86
|
-
for (let i = 0; i < v.length; i++) {
|
|
87
|
-
walk(v[i]);
|
|
88
|
-
}
|
|
89
|
-
return;
|
|
90
|
-
}
|
|
91
|
-
if (t === "object") {
|
|
92
|
-
const keys = Object.keys(v).sort();
|
|
93
|
-
for (let i = 0; i < keys.length; i++) {
|
|
94
|
-
const k = keys[i];
|
|
95
|
-
for (let j = 0; j < k.length; j++) {
|
|
96
|
-
hash ^= k.charCodeAt(j);
|
|
97
|
-
hash += (hash << 1) + (hash << 4) + (hash << 7) + (hash << 8) + (hash << 24);
|
|
98
|
-
}
|
|
99
|
-
walk(v[k]);
|
|
100
|
-
}
|
|
101
|
-
}
|
|
102
|
-
};
|
|
103
|
-
walk(value);
|
|
104
|
-
return hash >>> 0;
|
|
105
|
-
};
|
|
106
|
-
let hashFunc = hashValue64;
|
|
107
|
-
function setHashFunc(use64Bit) {
|
|
108
|
-
hashFunc = use64Bit ? hashValue64 : hashValue32;
|
|
109
|
-
}
|
|
110
|
-
function hashValue(value) {
|
|
111
|
-
return hashFunc(value);
|
|
112
|
-
}
|
|
6
|
+
Object.defineProperty(exports,"__esModule",{value:!0}),exports.setHashFunc=function(e){o=e?n:r},exports.hashValue=function(e){return o(e)};const e=1099511628211n,t=(1n<<64n)-1n,n=n=>{let r=14695981039346656037n;const o=n=>{if(null===n)return r^=0n,void(r=r*e&t);const l=typeof n;if("number"===l)return r^=BigInt(Math.trunc(n)),void(r=r*e&t);if("string"!==l){if("boolean"===l)return r^=n?1n:0n,void(r=r*e&t);if(Array.isArray(n))for(let e=0;e<n.length;e++)o(n[e]);else if("object"===l){const l=Object.keys(n).sort();for(let s=0;s<l.length;s++){const i=l[s];for(let n=0;n<i.length;n++)r^=BigInt(i.charCodeAt(n)),r=r*e&t;o(n[i])}}}else for(let o=0;o<n.length;o++)r^=BigInt(n.charCodeAt(o)),r=r*e&t};return o(n),r},r=e=>{let t=2166136261;const n=e=>{if(null===e)return void(t^=0);const r=typeof e;if("number"===r)return t^=0|e,void(t+=(t<<1)+(t<<4)+(t<<7)+(t<<8)+(t<<24));if("string"!==r)if("boolean"!==r){if(Array.isArray(e))for(let t=0;t<e.length;t++)n(e[t]);else if("object"===r){const r=Object.keys(e).sort();for(let o=0;o<r.length;o++){const l=r[o];for(let e=0;e<l.length;e++)t^=l.charCodeAt(e),t+=(t<<1)+(t<<4)+(t<<7)+(t<<8)+(t<<24);n(e[l])}}}else t^=e?1:0;else for(let n=0;n<e.length;n++)t^=e.charCodeAt(n),t+=(t<<1)+(t<<4)+(t<<7)+(t<<8)+(t<<24)};return n(e),t>>>0};let o=n;
|
|
@@ -2,168 +2,5 @@
|
|
|
2
2
|
* Copyright 2026 Lily (liwybloc)
|
|
3
3
|
* Licensed under the Apache License, Version 2.0.
|
|
4
4
|
*/
|
|
5
|
-
"use strict";
|
|
6
5
|
|
|
7
|
-
Object.defineProperty(exports,
|
|
8
|
-
exports.decompressJSON = exports.compressJSON = void 0;
|
|
9
|
-
const BufferUtil_1 = require("../BufferUtil");
|
|
10
|
-
const CompressionUtil_1 = require("./CompressionUtil");
|
|
11
|
-
var JSONType;
|
|
12
|
-
(function (JSONType) {
|
|
13
|
-
JSONType[JSONType["NULL"] = 0] = "NULL";
|
|
14
|
-
JSONType[JSONType["BOOL"] = 1] = "BOOL";
|
|
15
|
-
JSONType[JSONType["INT"] = 2] = "INT";
|
|
16
|
-
JSONType[JSONType["FLOAT"] = 3] = "FLOAT";
|
|
17
|
-
JSONType[JSONType["STRING"] = 4] = "STRING";
|
|
18
|
-
JSONType[JSONType["ARRAY"] = 5] = "ARRAY";
|
|
19
|
-
JSONType[JSONType["OBJECT"] = 6] = "OBJECT";
|
|
20
|
-
})(JSONType || (JSONType = {}));
|
|
21
|
-
const encodeString = (str) => {
|
|
22
|
-
const encoder = new TextEncoder();
|
|
23
|
-
const data = encoder.encode(str);
|
|
24
|
-
return [...(0, CompressionUtil_1.convertVarInt)(data.length), ...data];
|
|
25
|
-
};
|
|
26
|
-
const decodeString = (bytes, offset) => {
|
|
27
|
-
const [off, len] = (0, CompressionUtil_1.readVarInt)(bytes, offset);
|
|
28
|
-
const decoder = new TextDecoder();
|
|
29
|
-
return { value: decoder.decode(bytes.subarray(off, off + len)), length: off + len - offset };
|
|
30
|
-
};
|
|
31
|
-
|
|
32
|
-
const packTypeBits = (types) => {
|
|
33
|
-
let bits = '';
|
|
34
|
-
for (const t of types)
|
|
35
|
-
bits += t.toString(2).padStart(3, '0');
|
|
36
|
-
return (0, CompressionUtil_1.bitsToBytes)(bits);
|
|
37
|
-
};
|
|
38
|
-
|
|
39
|
-
const unpackTypeBits = (bytes, totalValues) => {
|
|
40
|
-
const bitStr = (0, CompressionUtil_1.bytesToBits)(bytes);
|
|
41
|
-
const types = [];
|
|
42
|
-
for (let i = 0; i < totalValues; i++) {
|
|
43
|
-
types.push(parseInt(bitStr.slice(i * 3, i * 3 + 3), 2));
|
|
44
|
-
}
|
|
45
|
-
return types;
|
|
46
|
-
};
|
|
47
|
-
|
|
48
|
-
const compressJSON = (value) => {
|
|
49
|
-
const bools = [];
|
|
50
|
-
const payload = [];
|
|
51
|
-
const typeList = [];
|
|
52
|
-
const encodeValue = (val) => {
|
|
53
|
-
if (val === null) {
|
|
54
|
-
typeList.push(JSONType.NULL);
|
|
55
|
-
}
|
|
56
|
-
else if (typeof val === 'boolean') {
|
|
57
|
-
typeList.push(JSONType.BOOL);
|
|
58
|
-
bools.push(val);
|
|
59
|
-
}
|
|
60
|
-
else if (Number.isInteger(val)) {
|
|
61
|
-
typeList.push(JSONType.INT);
|
|
62
|
-
payload.push(...(0, CompressionUtil_1.convertVarInt)((0, CompressionUtil_1.mapZigZag)(val)));
|
|
63
|
-
}
|
|
64
|
-
else if (typeof val === 'number') {
|
|
65
|
-
typeList.push(JSONType.FLOAT);
|
|
66
|
-
payload.push(...(0, CompressionUtil_1.convertFloat)(val));
|
|
67
|
-
}
|
|
68
|
-
else if (typeof val === 'string') {
|
|
69
|
-
typeList.push(JSONType.STRING);
|
|
70
|
-
payload.push(...encodeString(val));
|
|
71
|
-
}
|
|
72
|
-
else if (Array.isArray(val)) {
|
|
73
|
-
typeList.push(JSONType.ARRAY);
|
|
74
|
-
payload.push(...(0, CompressionUtil_1.convertVarInt)(val.length));
|
|
75
|
-
for (const item of val)
|
|
76
|
-
encodeValue(item);
|
|
77
|
-
}
|
|
78
|
-
else if (typeof val === 'object') {
|
|
79
|
-
typeList.push(JSONType.OBJECT);
|
|
80
|
-
const keys = Object.keys(val);
|
|
81
|
-
payload.push(...(0, CompressionUtil_1.convertVarInt)(keys.length));
|
|
82
|
-
for (const key of keys) {
|
|
83
|
-
payload.push(...encodeString(key));
|
|
84
|
-
encodeValue(val[key]);
|
|
85
|
-
}
|
|
86
|
-
}
|
|
87
|
-
else {
|
|
88
|
-
throw new Error('Unsupported type');
|
|
89
|
-
}
|
|
90
|
-
};
|
|
91
|
-
encodeValue(value);
|
|
92
|
-
|
|
93
|
-
const boolBytes = bools.length
|
|
94
|
-
? (0, BufferUtil_1.splitArray)(bools, 8).map((slice) => (0, CompressionUtil_1.compressBools)(slice))
|
|
95
|
-
: [];
|
|
96
|
-
|
|
97
|
-
const typeBytes = packTypeBits(typeList);
|
|
98
|
-
|
|
99
|
-
const header = [...(0, CompressionUtil_1.convertVarInt)(boolBytes.length), ...(0, CompressionUtil_1.convertVarInt)(typeBytes.length)];
|
|
100
|
-
return Uint8Array.from([...header, ...boolBytes.flat(), ...typeBytes, ...payload]);
|
|
101
|
-
};
|
|
102
|
-
exports.compressJSON = compressJSON;
|
|
103
|
-
|
|
104
|
-
const decompressJSON = (bytes) => {
|
|
105
|
-
let offset = 0;
|
|
106
|
-
|
|
107
|
-
const [off1, boolByteLen] = (0, CompressionUtil_1.readVarInt)(bytes, offset);
|
|
108
|
-
offset = off1;
|
|
109
|
-
const [off2, typeByteLen] = (0, CompressionUtil_1.readVarInt)(bytes, offset);
|
|
110
|
-
offset = off2;
|
|
111
|
-
|
|
112
|
-
const boolStream = [];
|
|
113
|
-
for (let i = 0; i < boolByteLen; i++) {
|
|
114
|
-
boolStream.push(...(0, CompressionUtil_1.decompressBools)(bytes[offset++]));
|
|
115
|
-
}
|
|
116
|
-
let boolIndex = 0;
|
|
117
|
-
|
|
118
|
-
const typeBytes = bytes.subarray(offset, offset + typeByteLen);
|
|
119
|
-
offset += typeByteLen;
|
|
120
|
-
const typeList = unpackTypeBits(typeBytes, typeBytes.length * 8 / 3);
|
|
121
|
-
let typeIndex = 0;
|
|
122
|
-
const decodeValue = (depth) => {
|
|
123
|
-
if (depth > 500)
|
|
124
|
-
throw new Error("JSON array too deep.");
|
|
125
|
-
const type = typeList[typeIndex++];
|
|
126
|
-
switch (type) {
|
|
127
|
-
case JSONType.NULL: return null;
|
|
128
|
-
case JSONType.BOOL: return boolStream[boolIndex++];
|
|
129
|
-
case JSONType.INT: {
|
|
130
|
-
const [off, n] = (0, CompressionUtil_1.readVarInt)(bytes, offset);
|
|
131
|
-
offset = off;
|
|
132
|
-
return (0, CompressionUtil_1.demapZigZag)(n);
|
|
133
|
-
}
|
|
134
|
-
case JSONType.FLOAT: {
|
|
135
|
-
const val = (0, CompressionUtil_1.deconvertFloat)(Array.from(bytes.subarray(offset, offset + 4)));
|
|
136
|
-
offset += 4;
|
|
137
|
-
return val;
|
|
138
|
-
}
|
|
139
|
-
case JSONType.STRING: {
|
|
140
|
-
const { value, length } = decodeString(bytes, offset);
|
|
141
|
-
offset += length;
|
|
142
|
-
return value;
|
|
143
|
-
}
|
|
144
|
-
case JSONType.ARRAY: {
|
|
145
|
-
const [off, len] = (0, CompressionUtil_1.readVarInt)(bytes, offset);
|
|
146
|
-
offset = off;
|
|
147
|
-
const arr = [];
|
|
148
|
-
for (let i = 0; i < len; i++)
|
|
149
|
-
arr.push(decodeValue(depth + 1));
|
|
150
|
-
return arr;
|
|
151
|
-
}
|
|
152
|
-
case JSONType.OBJECT: {
|
|
153
|
-
const [off, numKeys] = (0, CompressionUtil_1.readVarInt)(bytes, offset);
|
|
154
|
-
offset = off;
|
|
155
|
-
const obj = {};
|
|
156
|
-
for (let i = 0; i < numKeys; i++) {
|
|
157
|
-
const { value: key, length: keyLen } = decodeString(bytes, offset);
|
|
158
|
-
offset += keyLen;
|
|
159
|
-
obj[key] = decodeValue(depth + 1);
|
|
160
|
-
}
|
|
161
|
-
return obj;
|
|
162
|
-
}
|
|
163
|
-
default:
|
|
164
|
-
throw new Error(`Unknown type ${type}`);
|
|
165
|
-
}
|
|
166
|
-
};
|
|
167
|
-
return decodeValue(0);
|
|
168
|
-
};
|
|
169
|
-
exports.decompressJSON = decompressJSON;
|
|
6
|
+
Object.defineProperty(exports,"__esModule",{value:!0}),exports.decompressJSON=exports.compressJSON=void 0;const e=require("../BufferUtil"),r=require("./CompressionUtil");var t;!function(e){e[e.NULL=0]="NULL",e[e.BOOL=1]="BOOL",e[e.INT=2]="INT",e[e.FLOAT=3]="FLOAT",e[e.STRING=4]="STRING",e[e.ARRAY=5]="ARRAY",e[e.OBJECT=6]="OBJECT"}(t||(t={}));const s=e=>{const t=(new TextEncoder).encode(e);return[...(0,r.convertVarInt)(t.length),...t]},n=(e,t)=>{const[s,n]=(0,r.readVarInt)(e,t);return{value:(new TextDecoder).decode(e.subarray(s,s+n)),length:s+n-t}};exports.compressJSON=n=>{const o=[],c=[],a=[],u=e=>{if(null===e)a.push(t.NULL);else if("boolean"==typeof e)a.push(t.BOOL),o.push(e);else if(Number.isInteger(e))a.push(t.INT),c.push(...(0,r.convertVarInt)((0,r.mapZigZag)(e)));else if("number"==typeof e)a.push(t.FLOAT),c.push(...(0,r.convertFloat)(e));else if("string"==typeof e)a.push(t.STRING),c.push(...s(e));else if(Array.isArray(e)){a.push(t.ARRAY),c.push(...(0,r.convertVarInt)(e.length));for(const r of e)u(r)}else{if("object"!=typeof e)throw new Error("Unsupported type");{a.push(t.OBJECT);const n=Object.keys(e);c.push(...(0,r.convertVarInt)(n.length));for(const r of n)c.push(...s(r)),u(e[r])}}};u(n);const p=o.length?(0,e.splitArray)(o,8).map(e=>(0,r.compressBools)(e)):[],l=(e=>{let t="";for(const r of e)t+=r.toString(2).padStart(3,"0");return(0,r.bitsToBytes)(t)})(a),h=[...(0,r.convertVarInt)(p.length),...(0,r.convertVarInt)(l.length)];return Uint8Array.from([...h,...p.flat(),...l,...c])};exports.decompressJSON=e=>{let s=0;const[o,c]=(0,r.readVarInt)(e,s);s=o;const[a,u]=(0,r.readVarInt)(e,s);s=a;const p=[];for(let t=0;t<c;t++)p.push(...(0,r.decompressBools)(e[s++]));let l=0;const h=e.subarray(s,s+u);s+=u;const f=((e,t)=>{const s=(0,r.bytesToBits)(e),n=[];for(let e=0;e<t;e++)n.push(parseInt(s.slice(3*e,3*e+3),2));return n})(h,8*h.length/3);let i=0;const d=o=>{if(o>500)throw new Error("JSON array too deep.");const c=f[i++];switch(c){case t.NULL:return null;case t.BOOL:return p[l++];case t.INT:{const[t,n]=(0,r.readVarInt)(e,s);return s=t,(0,r.demapZigZag)(n)}case t.FLOAT:{const t=(0,r.deconvertFloat)(Array.from(e.subarray(s,s+4)));return s+=4,t}case t.STRING:{const{value:r,length:t}=n(e,s);return s+=t,r}case t.ARRAY:{const[t,n]=(0,r.readVarInt)(e,s);s=t;const c=[];for(let e=0;e<n;e++)c.push(d(o+1));return c}case t.OBJECT:{const[t,c]=(0,r.readVarInt)(e,s);s=t;const a={};for(let r=0;r<c;r++){const{value:r,length:t}=n(e,s);s+=t,a[r]=d(o+1)}return a}default:throw new Error(`Unknown type ${c}`)}};return d(0)};
|