mol_vary 0.0.24 → 0.0.26
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 +7 -0
- package/node.d.ts +2 -2
- package/node.deps.json +1 -1
- package/node.js +12 -9
- package/node.js.map +1 -1
- package/node.mjs +12 -9
- package/node.test.js +16 -9
- package/node.test.js.map +1 -1
- package/package.json +1 -1
- package/web.d.ts +2 -2
- package/web.deps.json +1 -1
- package/web.js +12 -9
- package/web.js.map +1 -1
- package/web.mjs +12 -9
- package/web.test.js +4 -0
- package/web.test.js.map +1 -1
package/node.mjs
CHANGED
|
@@ -2292,7 +2292,7 @@ var $;
|
|
|
2292
2292
|
})($mol_vary_spec = $.$mol_vary_spec || ($.$mol_vary_spec = {}));
|
|
2293
2293
|
let buffer = new Uint8Array(256);
|
|
2294
2294
|
let pack = new DataView(buffer.buffer);
|
|
2295
|
-
class $mol_vary extends
|
|
2295
|
+
class $mol_vary extends Object {
|
|
2296
2296
|
static pack(data) {
|
|
2297
2297
|
let pos = 0;
|
|
2298
2298
|
let capacity = 0;
|
|
@@ -2499,8 +2499,8 @@ var $;
|
|
|
2499
2499
|
dump(data);
|
|
2500
2500
|
return buffer.slice(0, pos);
|
|
2501
2501
|
}
|
|
2502
|
-
static take(
|
|
2503
|
-
const pack = new
|
|
2502
|
+
static take(buffer) {
|
|
2503
|
+
const pack = new DataView(buffer.buffer, buffer.byteOffset, buffer.byteLength);
|
|
2504
2504
|
const stream = [];
|
|
2505
2505
|
let pos = 0;
|
|
2506
2506
|
const read_unum = (kind) => {
|
|
@@ -2510,7 +2510,7 @@ var $;
|
|
|
2510
2510
|
return num;
|
|
2511
2511
|
let res = 0;
|
|
2512
2512
|
if (num === 28) {
|
|
2513
|
-
res =
|
|
2513
|
+
res = pack.getUint8(pos++);
|
|
2514
2514
|
}
|
|
2515
2515
|
else if (num === 29) {
|
|
2516
2516
|
res = pack.getUint16(pos, true);
|
|
@@ -2561,14 +2561,14 @@ var $;
|
|
|
2561
2561
|
};
|
|
2562
2562
|
const read_text = (kind) => {
|
|
2563
2563
|
const len = read_unum(kind);
|
|
2564
|
-
const [text, bytes] = $mol_charset_decode_from(
|
|
2564
|
+
const [text, bytes] = $mol_charset_decode_from(buffer, pack.byteOffset + pos, len);
|
|
2565
2565
|
pos += bytes;
|
|
2566
2566
|
if (text.length)
|
|
2567
2567
|
stream.push(text);
|
|
2568
2568
|
return text;
|
|
2569
2569
|
};
|
|
2570
2570
|
const read_buffer = (len, TypedArray) => {
|
|
2571
|
-
const bin = new TypedArray(
|
|
2571
|
+
const bin = new TypedArray(buffer.slice(pos, pos + len).buffer);
|
|
2572
2572
|
pos += len;
|
|
2573
2573
|
if (len)
|
|
2574
2574
|
stream.push(bin);
|
|
@@ -2576,7 +2576,7 @@ var $;
|
|
|
2576
2576
|
};
|
|
2577
2577
|
const read_blob = (kind) => {
|
|
2578
2578
|
const len = read_unum(kind);
|
|
2579
|
-
const kind_item =
|
|
2579
|
+
const kind_item = pack.getUint8(pos++);
|
|
2580
2580
|
switch (kind_item) {
|
|
2581
2581
|
case $.$mol_vary_len[1]: return read_buffer(len, Uint8Array);
|
|
2582
2582
|
case $.$mol_vary_len[2]: return read_buffer(len, Uint16Array);
|
|
@@ -2665,7 +2665,7 @@ var $;
|
|
|
2665
2665
|
}
|
|
2666
2666
|
};
|
|
2667
2667
|
const read_vary = () => {
|
|
2668
|
-
const kind =
|
|
2668
|
+
const kind = pack.getUint8(pos);
|
|
2669
2669
|
const tip = kind & 0b111_00000;
|
|
2670
2670
|
switch (tip) {
|
|
2671
2671
|
case $mol_vary_tip.uint: return read_unum(kind);
|
|
@@ -2679,7 +2679,10 @@ var $;
|
|
|
2679
2679
|
default: $mol_fail(new Error('Unsupported tip', { cause: { tip } }));
|
|
2680
2680
|
}
|
|
2681
2681
|
};
|
|
2682
|
-
|
|
2682
|
+
const result = read_vary();
|
|
2683
|
+
if (pos !== buffer.byteLength)
|
|
2684
|
+
$mol_fail(new Error('Buffer too large', { cause: { size: buffer.byteLength, taken: pos, result } }));
|
|
2685
|
+
return result;
|
|
2683
2686
|
}
|
|
2684
2687
|
static riches = new Map();
|
|
2685
2688
|
static type(Class, keys, lean, rich) {
|
package/node.test.js
CHANGED
|
@@ -2283,7 +2283,7 @@ var $;
|
|
|
2283
2283
|
})($mol_vary_spec = $.$mol_vary_spec || ($.$mol_vary_spec = {}));
|
|
2284
2284
|
let buffer = new Uint8Array(256);
|
|
2285
2285
|
let pack = new DataView(buffer.buffer);
|
|
2286
|
-
class $mol_vary extends
|
|
2286
|
+
class $mol_vary extends Object {
|
|
2287
2287
|
static pack(data) {
|
|
2288
2288
|
let pos = 0;
|
|
2289
2289
|
let capacity = 0;
|
|
@@ -2490,8 +2490,8 @@ var $;
|
|
|
2490
2490
|
dump(data);
|
|
2491
2491
|
return buffer.slice(0, pos);
|
|
2492
2492
|
}
|
|
2493
|
-
static take(
|
|
2494
|
-
const pack = new
|
|
2493
|
+
static take(buffer) {
|
|
2494
|
+
const pack = new DataView(buffer.buffer, buffer.byteOffset, buffer.byteLength);
|
|
2495
2495
|
const stream = [];
|
|
2496
2496
|
let pos = 0;
|
|
2497
2497
|
const read_unum = (kind) => {
|
|
@@ -2501,7 +2501,7 @@ var $;
|
|
|
2501
2501
|
return num;
|
|
2502
2502
|
let res = 0;
|
|
2503
2503
|
if (num === 28) {
|
|
2504
|
-
res =
|
|
2504
|
+
res = pack.getUint8(pos++);
|
|
2505
2505
|
}
|
|
2506
2506
|
else if (num === 29) {
|
|
2507
2507
|
res = pack.getUint16(pos, true);
|
|
@@ -2552,14 +2552,14 @@ var $;
|
|
|
2552
2552
|
};
|
|
2553
2553
|
const read_text = (kind) => {
|
|
2554
2554
|
const len = read_unum(kind);
|
|
2555
|
-
const [text, bytes] = $mol_charset_decode_from(
|
|
2555
|
+
const [text, bytes] = $mol_charset_decode_from(buffer, pack.byteOffset + pos, len);
|
|
2556
2556
|
pos += bytes;
|
|
2557
2557
|
if (text.length)
|
|
2558
2558
|
stream.push(text);
|
|
2559
2559
|
return text;
|
|
2560
2560
|
};
|
|
2561
2561
|
const read_buffer = (len, TypedArray) => {
|
|
2562
|
-
const bin = new TypedArray(
|
|
2562
|
+
const bin = new TypedArray(buffer.slice(pos, pos + len).buffer);
|
|
2563
2563
|
pos += len;
|
|
2564
2564
|
if (len)
|
|
2565
2565
|
stream.push(bin);
|
|
@@ -2567,7 +2567,7 @@ var $;
|
|
|
2567
2567
|
};
|
|
2568
2568
|
const read_blob = (kind) => {
|
|
2569
2569
|
const len = read_unum(kind);
|
|
2570
|
-
const kind_item =
|
|
2570
|
+
const kind_item = pack.getUint8(pos++);
|
|
2571
2571
|
switch (kind_item) {
|
|
2572
2572
|
case $.$mol_vary_len[1]: return read_buffer(len, Uint8Array);
|
|
2573
2573
|
case $.$mol_vary_len[2]: return read_buffer(len, Uint16Array);
|
|
@@ -2656,7 +2656,7 @@ var $;
|
|
|
2656
2656
|
}
|
|
2657
2657
|
};
|
|
2658
2658
|
const read_vary = () => {
|
|
2659
|
-
const kind =
|
|
2659
|
+
const kind = pack.getUint8(pos);
|
|
2660
2660
|
const tip = kind & 0b111_00000;
|
|
2661
2661
|
switch (tip) {
|
|
2662
2662
|
case $mol_vary_tip.uint: return read_unum(kind);
|
|
@@ -2670,7 +2670,10 @@ var $;
|
|
|
2670
2670
|
default: $mol_fail(new Error('Unsupported tip', { cause: { tip } }));
|
|
2671
2671
|
}
|
|
2672
2672
|
};
|
|
2673
|
-
|
|
2673
|
+
const result = read_vary();
|
|
2674
|
+
if (pos !== buffer.byteLength)
|
|
2675
|
+
$mol_fail(new Error('Buffer too large', { cause: { size: buffer.byteLength, taken: pos, result } }));
|
|
2676
|
+
return result;
|
|
2674
2677
|
}
|
|
2675
2678
|
static riches = new Map();
|
|
2676
2679
|
static type(Class, keys, lean, rich) {
|
|
@@ -4707,6 +4710,10 @@ var $;
|
|
|
4707
4710
|
check(Number.MAX_SAFE_INTEGER, [uint | l8, 255, 255, 255, 255, 255, 255, 31, 0]);
|
|
4708
4711
|
check(256n ** 8n - 1n, [uint | l8, 255, 255, 255, 255, 255, 255, 255, 255]);
|
|
4709
4712
|
},
|
|
4713
|
+
"vary pack with wrong size"($) {
|
|
4714
|
+
$mol_assert_fail(() => $mol_vary.take(new Uint8Array([uint | l1])), Error);
|
|
4715
|
+
$mol_assert_fail(() => $mol_vary.take(new Uint8Array([uint | l1, 200, 300])), 'Buffer too large');
|
|
4716
|
+
},
|
|
4710
4717
|
"vary pack sint0"($) {
|
|
4711
4718
|
check(-1, [-1]);
|
|
4712
4719
|
check(-28, [-28]);
|