mol_vary 0.0.27 → 0.0.28
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 +2 -2
- package/node.d.ts +15 -6
- package/node.d.ts.map +1 -1
- package/node.deps.json +1 -1
- package/node.js +130 -64
- package/node.js.map +1 -1
- package/node.mjs +130 -64
- package/node.test.js +332 -160
- package/node.test.js.map +1 -1
- package/package.json +4 -1
- package/web.d.ts +15 -6
- package/web.d.ts.map +1 -1
- package/web.deps.json +1 -1
- package/web.js +130 -64
- package/web.js.map +1 -1
- package/web.mjs +130 -64
- package/web.test.js +202 -96
- package/web.test.js.map +1 -1
package/node.mjs
CHANGED
|
@@ -28,6 +28,28 @@ var __decorate = (this && this.__decorate) || function (decorators, target, key,
|
|
|
28
28
|
var $ = ( typeof module === 'object' ) ? ( module['export'+'s'] = globalThis ) : globalThis
|
|
29
29
|
$.$$ = $
|
|
30
30
|
|
|
31
|
+
;
|
|
32
|
+
"use strict";
|
|
33
|
+
var $;
|
|
34
|
+
(function ($) {
|
|
35
|
+
function $mol_bigint_encode(num) {
|
|
36
|
+
const minus = num < 0n ? 255 : 0;
|
|
37
|
+
num = minus ? -num - 1n : num;
|
|
38
|
+
const bytes = [];
|
|
39
|
+
do {
|
|
40
|
+
let byte = minus ^ Number(num % 256n);
|
|
41
|
+
bytes.push(byte);
|
|
42
|
+
if (num >>= 8n)
|
|
43
|
+
continue;
|
|
44
|
+
if ((minus & 128) !== (byte & 128))
|
|
45
|
+
bytes.push(minus);
|
|
46
|
+
break;
|
|
47
|
+
} while (num);
|
|
48
|
+
return new Uint8Array(bytes);
|
|
49
|
+
}
|
|
50
|
+
$.$mol_bigint_encode = $mol_bigint_encode;
|
|
51
|
+
})($ || ($ = {}));
|
|
52
|
+
|
|
31
53
|
;
|
|
32
54
|
"use strict";
|
|
33
55
|
var $;
|
|
@@ -95,6 +117,32 @@ var $;
|
|
|
95
117
|
$.$mol_charset_encode_size = $mol_charset_encode_size;
|
|
96
118
|
})($ || ($ = {}));
|
|
97
119
|
|
|
120
|
+
;
|
|
121
|
+
"use strict";
|
|
122
|
+
var $;
|
|
123
|
+
(function ($) {
|
|
124
|
+
function $mol_bigint_decode(buf) {
|
|
125
|
+
if (buf.length === 8)
|
|
126
|
+
return new BigInt64Array(buf.buffer, buf.byteOffset, 1)[0];
|
|
127
|
+
if (buf.length === 4)
|
|
128
|
+
return BigInt(new Int32Array(buf.buffer, buf.byteOffset, 1)[0]);
|
|
129
|
+
if (buf.length === 2)
|
|
130
|
+
return BigInt(new Int16Array(buf.buffer, buf.byteOffset, 1)[0]);
|
|
131
|
+
if (buf.length === 1)
|
|
132
|
+
return BigInt(new Int8Array(buf.buffer, buf.byteOffset, 1)[0]);
|
|
133
|
+
const minus = (buf.at(-1) & 128) ? 255 : 0;
|
|
134
|
+
let result = 0n;
|
|
135
|
+
let offset = 0n;
|
|
136
|
+
for (let i = 0; i < buf.length; i++, offset += 8n) {
|
|
137
|
+
result |= BigInt(buf[i] ^ minus) << offset;
|
|
138
|
+
}
|
|
139
|
+
if (minus)
|
|
140
|
+
result = (result + 1n) * -1n;
|
|
141
|
+
return result;
|
|
142
|
+
}
|
|
143
|
+
$.$mol_bigint_decode = $mol_bigint_decode;
|
|
144
|
+
})($ || ($ = {}));
|
|
145
|
+
|
|
98
146
|
;
|
|
99
147
|
"use strict";
|
|
100
148
|
|
|
@@ -2274,12 +2322,14 @@ var $;
|
|
|
2274
2322
|
$mol_vary_tip[$mol_vary_tip["tupl"] = 192] = "tupl";
|
|
2275
2323
|
$mol_vary_tip[$mol_vary_tip["sint"] = 224] = "sint";
|
|
2276
2324
|
})($mol_vary_tip = $.$mol_vary_tip || ($.$mol_vary_tip = {}));
|
|
2277
|
-
|
|
2278
|
-
|
|
2279
|
-
|
|
2280
|
-
|
|
2281
|
-
|
|
2282
|
-
|
|
2325
|
+
let $mol_vary_len;
|
|
2326
|
+
(function ($mol_vary_len) {
|
|
2327
|
+
$mol_vary_len[$mol_vary_len["L1"] = 28] = "L1";
|
|
2328
|
+
$mol_vary_len[$mol_vary_len["L2"] = 29] = "L2";
|
|
2329
|
+
$mol_vary_len[$mol_vary_len["L4"] = 30] = "L4";
|
|
2330
|
+
$mol_vary_len[$mol_vary_len["L8"] = 31] = "L8";
|
|
2331
|
+
$mol_vary_len[$mol_vary_len["LA"] = 32] = "LA";
|
|
2332
|
+
})($mol_vary_len = $.$mol_vary_len || ($.$mol_vary_len = {}));
|
|
2283
2333
|
let $mol_vary_spec;
|
|
2284
2334
|
(function ($mol_vary_spec) {
|
|
2285
2335
|
$mol_vary_spec[$mol_vary_spec["none"] = 'N'.charCodeAt(0)] = "none";
|
|
@@ -2311,66 +2361,76 @@ var $;
|
|
|
2311
2361
|
const release = (size) => {
|
|
2312
2362
|
capacity -= size;
|
|
2313
2363
|
};
|
|
2314
|
-
const
|
|
2315
|
-
|
|
2316
|
-
|
|
2364
|
+
const dump_bint = (val) => {
|
|
2365
|
+
const buf = $mol_bigint_encode(val);
|
|
2366
|
+
acquire(buf.byteLength - 7);
|
|
2367
|
+
if (buf.byteLength > 264)
|
|
2368
|
+
$mol_fail(new Error('Number too high', { cause: { val } }));
|
|
2369
|
+
buffer[pos++] = -$mol_vary_len.LA;
|
|
2370
|
+
buffer[pos++] = buf.byteLength - 9;
|
|
2371
|
+
buffer.set(buf, pos);
|
|
2372
|
+
pos += buf.byteLength;
|
|
2373
|
+
};
|
|
2374
|
+
const dump_unum = (tip, val) => {
|
|
2375
|
+
if (val < $mol_vary_len.L1) {
|
|
2376
|
+
buffer[pos++] = tip | Number(val);
|
|
2317
2377
|
release(8);
|
|
2318
2378
|
}
|
|
2319
|
-
else if (val
|
|
2320
|
-
buffer[pos++] =
|
|
2379
|
+
else if (val < 2 ** 8) {
|
|
2380
|
+
buffer[pos++] = tip | $mol_vary_len.L1;
|
|
2321
2381
|
buffer[pos++] = Number(val);
|
|
2322
2382
|
release(7);
|
|
2323
2383
|
}
|
|
2324
|
-
else if (val
|
|
2325
|
-
buffer[pos++] =
|
|
2326
|
-
pack.
|
|
2384
|
+
else if (val < 2 ** 16) {
|
|
2385
|
+
buffer[pos++] = tip | $mol_vary_len.L2;
|
|
2386
|
+
pack.setUint16(pos, Number(val), true);
|
|
2327
2387
|
pos += 2;
|
|
2328
2388
|
release(6);
|
|
2329
2389
|
}
|
|
2330
|
-
else if (val
|
|
2331
|
-
buffer[pos++] =
|
|
2332
|
-
pack.
|
|
2390
|
+
else if (val < 2 ** 32) {
|
|
2391
|
+
buffer[pos++] = tip | $mol_vary_len.L4;
|
|
2392
|
+
pack.setUint32(pos, Number(val), true);
|
|
2333
2393
|
pos += 4;
|
|
2334
2394
|
release(4);
|
|
2335
2395
|
}
|
|
2336
|
-
else if (val
|
|
2337
|
-
buffer[pos++] =
|
|
2338
|
-
pack.
|
|
2396
|
+
else if (val < 2n ** 64n) {
|
|
2397
|
+
buffer[pos++] = tip | $mol_vary_len.L8;
|
|
2398
|
+
pack.setBigUint64(pos, BigInt(val), true);
|
|
2339
2399
|
pos += 8;
|
|
2340
2400
|
}
|
|
2341
2401
|
else {
|
|
2342
|
-
|
|
2402
|
+
dump_bint(val);
|
|
2343
2403
|
}
|
|
2344
2404
|
};
|
|
2345
|
-
const
|
|
2346
|
-
if (val
|
|
2347
|
-
buffer[pos++] =
|
|
2405
|
+
const dump_snum = (val) => {
|
|
2406
|
+
if (val > -$mol_vary_len.L1) {
|
|
2407
|
+
buffer[pos++] = Number(val);
|
|
2348
2408
|
release(8);
|
|
2349
2409
|
}
|
|
2350
|
-
else if (val
|
|
2351
|
-
buffer[pos++] =
|
|
2410
|
+
else if (val >= -(2 ** 7)) {
|
|
2411
|
+
buffer[pos++] = -$mol_vary_len.L1;
|
|
2352
2412
|
buffer[pos++] = Number(val);
|
|
2353
2413
|
release(7);
|
|
2354
2414
|
}
|
|
2355
|
-
else if (val
|
|
2356
|
-
buffer[pos++] =
|
|
2357
|
-
pack.
|
|
2415
|
+
else if (val >= -(2 ** 15)) {
|
|
2416
|
+
buffer[pos++] = -$mol_vary_len.L2;
|
|
2417
|
+
pack.setInt16(pos, Number(val), true);
|
|
2358
2418
|
pos += 2;
|
|
2359
2419
|
release(6);
|
|
2360
2420
|
}
|
|
2361
|
-
else if (val
|
|
2362
|
-
buffer[pos++] =
|
|
2363
|
-
pack.
|
|
2421
|
+
else if (val >= -(2 ** 31)) {
|
|
2422
|
+
buffer[pos++] = -$mol_vary_len.L4;
|
|
2423
|
+
pack.setInt32(pos, Number(val), true);
|
|
2364
2424
|
pos += 4;
|
|
2365
2425
|
release(4);
|
|
2366
2426
|
}
|
|
2367
|
-
else if (val
|
|
2368
|
-
buffer[pos++] =
|
|
2369
|
-
pack.
|
|
2427
|
+
else if (val >= -(2n ** 63n)) {
|
|
2428
|
+
buffer[pos++] = -$mol_vary_len.L8;
|
|
2429
|
+
pack.setBigInt64(pos, BigInt(val), true);
|
|
2370
2430
|
pos += 8;
|
|
2371
2431
|
}
|
|
2372
2432
|
else {
|
|
2373
|
-
|
|
2433
|
+
dump_bint(val);
|
|
2374
2434
|
}
|
|
2375
2435
|
};
|
|
2376
2436
|
const dump_string = (val) => {
|
|
@@ -2396,21 +2456,23 @@ var $;
|
|
|
2396
2456
|
}
|
|
2397
2457
|
dump_unum($mol_vary_tip.blob, val.byteLength);
|
|
2398
2458
|
if (val instanceof Uint8Array)
|
|
2399
|
-
buffer[pos++] = $mol_vary_tip.uint |
|
|
2459
|
+
buffer[pos++] = $mol_vary_tip.uint | $mol_vary_len.L1;
|
|
2400
2460
|
else if (val instanceof Uint16Array)
|
|
2401
|
-
buffer[pos++] = $mol_vary_tip.uint |
|
|
2461
|
+
buffer[pos++] = $mol_vary_tip.uint | $mol_vary_len.L2;
|
|
2402
2462
|
else if (val instanceof Uint32Array)
|
|
2403
|
-
buffer[pos++] = $mol_vary_tip.uint |
|
|
2463
|
+
buffer[pos++] = $mol_vary_tip.uint | $mol_vary_len.L4;
|
|
2404
2464
|
else if (val instanceof BigUint64Array)
|
|
2405
|
-
buffer[pos++] = $mol_vary_tip.uint |
|
|
2465
|
+
buffer[pos++] = $mol_vary_tip.uint | $mol_vary_len.L8;
|
|
2406
2466
|
else if (val instanceof Int8Array)
|
|
2407
|
-
buffer[pos++] = $mol_vary_tip.sint |
|
|
2467
|
+
buffer[pos++] = $mol_vary_tip.sint | ~$mol_vary_len.L1;
|
|
2408
2468
|
else if (val instanceof Int16Array)
|
|
2409
|
-
buffer[pos++] = $mol_vary_tip.sint |
|
|
2469
|
+
buffer[pos++] = $mol_vary_tip.sint | ~$mol_vary_len.L2;
|
|
2410
2470
|
else if (val instanceof Int32Array)
|
|
2411
|
-
buffer[pos++] = $mol_vary_tip.sint |
|
|
2471
|
+
buffer[pos++] = $mol_vary_tip.sint | ~$mol_vary_len.L4;
|
|
2412
2472
|
else if (val instanceof BigInt64Array)
|
|
2413
|
-
buffer[pos++] = $mol_vary_tip.sint |
|
|
2473
|
+
buffer[pos++] = $mol_vary_tip.sint | ~$mol_vary_len.L8;
|
|
2474
|
+
else if (typeof Float16Array === 'function' && val instanceof Float16Array)
|
|
2475
|
+
buffer[pos++] = $mol_vary_spec.fp16;
|
|
2414
2476
|
else if (val instanceof Float32Array)
|
|
2415
2477
|
buffer[pos++] = $mol_vary_spec.fp32;
|
|
2416
2478
|
else if (val instanceof Float64Array)
|
|
@@ -2506,21 +2568,21 @@ var $;
|
|
|
2506
2568
|
const read_unum = (kind) => {
|
|
2507
2569
|
++pos;
|
|
2508
2570
|
const num = kind & 0b11111;
|
|
2509
|
-
if (num <
|
|
2571
|
+
if (num < $mol_vary_len.L1)
|
|
2510
2572
|
return num;
|
|
2511
2573
|
let res = 0;
|
|
2512
|
-
if (num ===
|
|
2574
|
+
if (num === $mol_vary_len.L1) {
|
|
2513
2575
|
res = pack.getUint8(pos++);
|
|
2514
2576
|
}
|
|
2515
|
-
else if (num ===
|
|
2577
|
+
else if (num === $mol_vary_len.L2) {
|
|
2516
2578
|
res = pack.getUint16(pos, true);
|
|
2517
2579
|
pos += 2;
|
|
2518
2580
|
}
|
|
2519
|
-
else if (num ===
|
|
2581
|
+
else if (num === $mol_vary_len.L4) {
|
|
2520
2582
|
res = pack.getUint32(pos, true);
|
|
2521
2583
|
pos += 4;
|
|
2522
2584
|
}
|
|
2523
|
-
else if (num ===
|
|
2585
|
+
else if (num === $mol_vary_len.L8) {
|
|
2524
2586
|
res = pack.getBigUint64(pos, true);
|
|
2525
2587
|
if (res <= Number.MAX_SAFE_INTEGER)
|
|
2526
2588
|
res = Number(res);
|
|
@@ -2533,27 +2595,31 @@ var $;
|
|
|
2533
2595
|
};
|
|
2534
2596
|
const read_snum = (kind) => {
|
|
2535
2597
|
const num = pack.getInt8(pos++);
|
|
2536
|
-
if (num
|
|
2598
|
+
if (num > -$mol_vary_len.L1)
|
|
2537
2599
|
return num;
|
|
2538
2600
|
let res = 0;
|
|
2539
|
-
if (num ===
|
|
2540
|
-
res = pack.getInt8(pos);
|
|
2541
|
-
pos += 1;
|
|
2601
|
+
if (num === -$mol_vary_len.L1) {
|
|
2602
|
+
res = pack.getInt8(pos++);
|
|
2542
2603
|
}
|
|
2543
|
-
else if (num ===
|
|
2604
|
+
else if (num === -$mol_vary_len.L2) {
|
|
2544
2605
|
res = pack.getInt16(pos, true);
|
|
2545
2606
|
pos += 2;
|
|
2546
2607
|
}
|
|
2547
|
-
else if (num ===
|
|
2608
|
+
else if (num === -$mol_vary_len.L4) {
|
|
2548
2609
|
res = pack.getInt32(pos, true);
|
|
2549
2610
|
pos += 4;
|
|
2550
2611
|
}
|
|
2551
|
-
else if (num ===
|
|
2612
|
+
else if (num === -$mol_vary_len.L8) {
|
|
2552
2613
|
res = pack.getBigInt64(pos, true);
|
|
2553
2614
|
if (res >= Number.MIN_SAFE_INTEGER && res <= Number.MAX_SAFE_INTEGER)
|
|
2554
2615
|
res = Number(res);
|
|
2555
2616
|
pos += 8;
|
|
2556
2617
|
}
|
|
2618
|
+
else if (num === -$mol_vary_len.LA) {
|
|
2619
|
+
const len = pack.getUint8(pos++) + 9;
|
|
2620
|
+
res = $mol_bigint_decode(new Uint8Array(pack.buffer, pack.byteOffset + pos, len));
|
|
2621
|
+
pos += len;
|
|
2622
|
+
}
|
|
2557
2623
|
else {
|
|
2558
2624
|
$mol_fail(new Error('Unsupported snum', { cause: { num } }));
|
|
2559
2625
|
}
|
|
@@ -2578,14 +2644,14 @@ var $;
|
|
|
2578
2644
|
const len = read_unum(kind);
|
|
2579
2645
|
const kind_item = pack.getUint8(pos++);
|
|
2580
2646
|
switch (kind_item) {
|
|
2581
|
-
case
|
|
2582
|
-
case
|
|
2583
|
-
case
|
|
2584
|
-
case
|
|
2585
|
-
case
|
|
2586
|
-
case
|
|
2587
|
-
case
|
|
2588
|
-
case
|
|
2647
|
+
case $mol_vary_len.L1: return read_buffer(len, Uint8Array);
|
|
2648
|
+
case $mol_vary_len.L2: return read_buffer(len, Uint16Array);
|
|
2649
|
+
case $mol_vary_len.L4: return read_buffer(len, Uint32Array);
|
|
2650
|
+
case $mol_vary_len.L8: return read_buffer(len, BigUint64Array);
|
|
2651
|
+
case ~$mol_vary_len.L1 + 256: return read_buffer(len, Int8Array);
|
|
2652
|
+
case ~$mol_vary_len.L2 + 256: return read_buffer(len, Int16Array);
|
|
2653
|
+
case ~$mol_vary_len.L4 + 256: return read_buffer(len, Int32Array);
|
|
2654
|
+
case ~$mol_vary_len.L8 + 256: return read_buffer(len, BigInt64Array);
|
|
2589
2655
|
case $mol_vary_tip.spec | $mol_vary_spec.fp16: return read_buffer(len, Float16Array);
|
|
2590
2656
|
case $mol_vary_tip.spec | $mol_vary_spec.fp32: return read_buffer(len, Float32Array);
|
|
2591
2657
|
case $mol_vary_tip.spec | $mol_vary_spec.fp64: return read_buffer(len, Float64Array);
|