msgpackr 1.11.3 → 1.11.4
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-no-eval.cjs +25 -75
- package/dist/index-no-eval.cjs.map +1 -1
- package/dist/index-no-eval.min.js +1 -1
- package/dist/index-no-eval.min.js.map +1 -1
- package/dist/index.js +25 -75
- package/dist/index.js.map +1 -1
- package/dist/index.min.js +1 -1
- package/dist/index.min.js.map +1 -1
- package/dist/node.cjs +26 -76
- package/dist/node.cjs.map +1 -1
- package/dist/test.js +35 -104
- package/dist/test.js.map +1 -1
- package/dist/unpack-no-eval.cjs +10 -36
- package/dist/unpack-no-eval.cjs.map +1 -1
- package/pack.js +16 -40
- package/package.json +1 -1
- package/unpack.js +10 -36
package/dist/test.js
CHANGED
|
@@ -995,47 +995,21 @@
|
|
|
995
995
|
currentExtensions[0] = () => {}; // notepack defines extension 0 to mean undefined, so use that as the default here
|
|
996
996
|
currentExtensions[0].noBuffer = true;
|
|
997
997
|
|
|
998
|
-
currentExtensions[0x42] = data => {
|
|
999
|
-
|
|
1000
|
-
let
|
|
1001
|
-
|
|
1002
|
-
|
|
1003
|
-
|
|
998
|
+
currentExtensions[0x42] = (data) => {
|
|
999
|
+
// decode bigint
|
|
1000
|
+
let length = data.length;
|
|
1001
|
+
let value = BigInt(data[0] & 0x80 ? data[0] - 0x100 : data[0]);
|
|
1002
|
+
for (let i = 1; i < length; i++) {
|
|
1003
|
+
value <<= BigInt(8);
|
|
1004
|
+
value += BigInt(data[i]);
|
|
1004
1005
|
}
|
|
1005
|
-
|
|
1006
|
-
let view = new DataView(data.buffer, data.byteOffset, data.byteLength);
|
|
1007
|
-
let decode = (start, end) => {
|
|
1008
|
-
let length = end - start;
|
|
1009
|
-
if (length <= 40) {
|
|
1010
|
-
let out = view.getBigUint64(start);
|
|
1011
|
-
for (let i = start + 8; i < end; i += 8) {
|
|
1012
|
-
out <<= BigInt(64n);
|
|
1013
|
-
out |= view.getBigUint64(i);
|
|
1014
|
-
}
|
|
1015
|
-
return out
|
|
1016
|
-
}
|
|
1017
|
-
// if (length === 8) return view.getBigUint64(start)
|
|
1018
|
-
let middle = start + (length >> 4 << 3);
|
|
1019
|
-
let left = decode(start, middle);
|
|
1020
|
-
let right = decode(middle, end);
|
|
1021
|
-
return (left << BigInt((end - middle) * 8)) | right
|
|
1022
|
-
};
|
|
1023
|
-
head = (head << BigInt((view.byteLength - headLength) * 8)) | decode(headLength, view.byteLength);
|
|
1024
|
-
}
|
|
1025
|
-
return head
|
|
1006
|
+
return value;
|
|
1026
1007
|
};
|
|
1027
1008
|
|
|
1028
|
-
let errors = {
|
|
1029
|
-
Error, EvalError, RangeError, ReferenceError, SyntaxError, TypeError, URIError, AggregateError: typeof AggregateError === 'function' ? AggregateError : null,
|
|
1030
|
-
};
|
|
1009
|
+
let errors = { Error, TypeError, ReferenceError };
|
|
1031
1010
|
currentExtensions[0x65] = () => {
|
|
1032
1011
|
let data = read();
|
|
1033
|
-
|
|
1034
|
-
let error = Error(data[1], { cause: data[2] });
|
|
1035
|
-
error.name = data[0];
|
|
1036
|
-
return error
|
|
1037
|
-
}
|
|
1038
|
-
return errors[data[0]](data[1], { cause: data[2] })
|
|
1012
|
+
return (errors[data[0]] || Error)(data[1], { cause: data[2] })
|
|
1039
1013
|
};
|
|
1040
1014
|
|
|
1041
1015
|
currentExtensions[0x69] = (data) => {
|
|
@@ -1753,46 +1727,22 @@
|
|
|
1753
1727
|
targetView.setFloat64(position, Number(value));
|
|
1754
1728
|
} else if (this.largeBigIntToString) {
|
|
1755
1729
|
return pack(value.toString());
|
|
1756
|
-
} else if (this.useBigIntExtension || this.moreTypes) {
|
|
1757
|
-
|
|
1758
|
-
|
|
1759
|
-
|
|
1760
|
-
|
|
1761
|
-
|
|
1762
|
-
|
|
1763
|
-
|
|
1764
|
-
|
|
1765
|
-
|
|
1766
|
-
|
|
1767
|
-
|
|
1768
|
-
|
|
1769
|
-
|
|
1770
|
-
|
|
1771
|
-
let invert = value < 0;
|
|
1772
|
-
let string = (invert ? ~value : value).toString(16);
|
|
1773
|
-
if (string.length % 2) {
|
|
1774
|
-
string = '0' + string;
|
|
1775
|
-
} else if (parseInt(string.charAt(0), 16) >= 8) {
|
|
1776
|
-
string = '00' + string;
|
|
1777
|
-
}
|
|
1778
|
-
|
|
1779
|
-
if (hasNodeBuffer$1) {
|
|
1780
|
-
array = Buffer.from(string, 'hex');
|
|
1781
|
-
} else {
|
|
1782
|
-
array = new Uint8Array(string.length / 2);
|
|
1783
|
-
for (let i = 0; i < array.length; i++) {
|
|
1784
|
-
array[i] = parseInt(string.slice(i * 2, i * 2 + 2), 16);
|
|
1785
|
-
}
|
|
1786
|
-
}
|
|
1787
|
-
|
|
1788
|
-
if (invert) {
|
|
1789
|
-
for (let i = 0; i < array.length; i++) array[i] = ~array[i];
|
|
1790
|
-
}
|
|
1730
|
+
} else if ((this.useBigIntExtension || this.moreTypes) && value < BigInt(2)**BigInt(1023) && value > -(BigInt(2)**BigInt(1023))) {
|
|
1731
|
+
target[position++] = 0xc7;
|
|
1732
|
+
position++;
|
|
1733
|
+
target[position++] = 0x42; // "B" for BigInt
|
|
1734
|
+
let bytes = [];
|
|
1735
|
+
let alignedSign;
|
|
1736
|
+
do {
|
|
1737
|
+
let byte = value & BigInt(0xff);
|
|
1738
|
+
alignedSign = (byte & BigInt(0x80)) === (value < BigInt(0) ? BigInt(0x80) : BigInt(0));
|
|
1739
|
+
bytes.push(byte);
|
|
1740
|
+
value >>= BigInt(8);
|
|
1741
|
+
} while (!((value === BigInt(0) || value === BigInt(-1)) && alignedSign));
|
|
1742
|
+
target[position-2] = bytes.length;
|
|
1743
|
+
for (let i = bytes.length; i > 0;) {
|
|
1744
|
+
target[position++] = Number(bytes[--i]);
|
|
1791
1745
|
}
|
|
1792
|
-
|
|
1793
|
-
if (array.length + position > safeEnd)
|
|
1794
|
-
makeRoom(array.length + position);
|
|
1795
|
-
position = writeExtensionData(array, target, position, 0x42);
|
|
1796
1746
|
return
|
|
1797
1747
|
} else {
|
|
1798
1748
|
throw new RangeError(value + ' was too large to fit in MessagePack 64-bit integer format, use' +
|
|
@@ -3367,7 +3317,7 @@
|
|
|
3367
3317
|
{id: 2, type: 1, labels: {b: 1, c: 2}},
|
|
3368
3318
|
{id: 3, type: 1, labels: {d: 1, e: 2}}
|
|
3369
3319
|
];
|
|
3370
|
-
|
|
3320
|
+
|
|
3371
3321
|
var alternatives = [
|
|
3372
3322
|
{useRecords: false}, // 88 bytes
|
|
3373
3323
|
{useRecords: true}, // 58 bytes
|
|
@@ -3379,7 +3329,7 @@
|
|
|
3379
3329
|
let packr = new Packr(o);
|
|
3380
3330
|
var serialized = packr.pack(data);
|
|
3381
3331
|
var deserialized = packr.unpack(serialized);
|
|
3382
|
-
assert.deepEqual(deserialized, data);
|
|
3332
|
+
assert.deepEqual(deserialized, data);
|
|
3383
3333
|
}
|
|
3384
3334
|
});
|
|
3385
3335
|
|
|
@@ -3501,7 +3451,7 @@
|
|
|
3501
3451
|
});
|
|
3502
3452
|
|
|
3503
3453
|
test('BigInt', function() {
|
|
3504
|
-
let packr = new Packr({
|
|
3454
|
+
let packr = new Packr({useBigIntExtension: true});
|
|
3505
3455
|
let data = {
|
|
3506
3456
|
a: 3333333333333333333333333333n,
|
|
3507
3457
|
b: 1234567890123456789012345678901234567890n,
|
|
@@ -3509,21 +3459,10 @@
|
|
|
3509
3459
|
d: -352523523642364364364264264264264264262642642n,
|
|
3510
3460
|
e: 0xffffffffffffffffffffffffffn,
|
|
3511
3461
|
f: -0xffffffffffffffffffffffffffn,
|
|
3512
|
-
|
|
3513
|
-
h: (-1234n << 123n) ^ (5678n << 56n) ^ 890n,
|
|
3514
|
-
i: (1234n << 1234n) ^ (5678n << 567n) ^ 890n,
|
|
3515
|
-
j: (-1234n << 1234n) ^ (5678n << 567n) ^ 890n,
|
|
3516
|
-
k: 0xdeadn << 0xbeefn,
|
|
3517
|
-
l: -0xdeadn << 0xbeefn,
|
|
3518
|
-
m: 11n << 0x11111n ^ 111n,
|
|
3519
|
-
n: -11n << 0x11111n ^ 111n,
|
|
3462
|
+
o: -12345678901234567890n,
|
|
3520
3463
|
array: [],
|
|
3521
3464
|
};
|
|
3522
|
-
|
|
3523
|
-
for (let n = 7n; n.toString(16).length * 4 < 150000; n *= n) {
|
|
3524
|
-
data.array.push(n, -n);
|
|
3525
|
-
}
|
|
3526
|
-
|
|
3465
|
+
|
|
3527
3466
|
let serialized = packr.pack(data);
|
|
3528
3467
|
let deserialized = packr.unpack(serialized);
|
|
3529
3468
|
assert.deepEqual(data, deserialized);
|
|
@@ -3750,7 +3689,7 @@
|
|
|
3750
3689
|
|
|
3751
3690
|
test('extended class pack/unpack proxied', function(){
|
|
3752
3691
|
function Extended() {
|
|
3753
|
-
|
|
3692
|
+
|
|
3754
3693
|
}
|
|
3755
3694
|
Extended.prototype.__call__ = function(){
|
|
3756
3695
|
return this.value * 4
|
|
@@ -3761,7 +3700,7 @@
|
|
|
3761
3700
|
|
|
3762
3701
|
var instance = function() { instance.__call__();/* callable stuff */ };
|
|
3763
3702
|
Object.setPrototypeOf(instance,Extended.prototype);
|
|
3764
|
-
|
|
3703
|
+
|
|
3765
3704
|
instance.value = 4;
|
|
3766
3705
|
var data = instance;
|
|
3767
3706
|
|
|
@@ -3842,9 +3781,7 @@
|
|
|
3842
3781
|
test('moreTypes: Error with causes', function() {
|
|
3843
3782
|
const object = {
|
|
3844
3783
|
error: new Error('test'),
|
|
3845
|
-
errorWithCause: new Error('test-1', { cause: new Error('test-2')
|
|
3846
|
-
type: new TypeError(),
|
|
3847
|
-
range: new RangeError('test', { cause: [1, 2] }),
|
|
3784
|
+
errorWithCause: new Error('test-1', { cause: new Error('test-2')}),
|
|
3848
3785
|
};
|
|
3849
3786
|
const packr = new Packr({
|
|
3850
3787
|
moreTypes: true,
|
|
@@ -3857,12 +3794,6 @@
|
|
|
3857
3794
|
assert.equal(deserialized.errorWithCause.message, object.errorWithCause.message);
|
|
3858
3795
|
assert.equal(deserialized.errorWithCause.cause.message, object.errorWithCause.cause.message);
|
|
3859
3796
|
assert.equal(deserialized.errorWithCause.cause.cause, object.errorWithCause.cause.cause);
|
|
3860
|
-
assert.equal(deserialized.type.message, object.type.message);
|
|
3861
|
-
assert.equal(deserialized.range.message, object.range.message);
|
|
3862
|
-
assert.deepEqual(deserialized.range.cause, object.range.cause);
|
|
3863
|
-
assert(deserialized.error instanceof Error);
|
|
3864
|
-
assert(deserialized.type instanceof TypeError);
|
|
3865
|
-
assert(deserialized.range instanceof RangeError);
|
|
3866
3797
|
});
|
|
3867
3798
|
|
|
3868
3799
|
test('structured cloning: self reference', function() {
|
|
@@ -4091,7 +4022,7 @@
|
|
|
4091
4022
|
getStructures() {
|
|
4092
4023
|
return structures
|
|
4093
4024
|
},
|
|
4094
|
-
saveStructures(structures) {
|
|
4025
|
+
saveStructures(structures) {
|
|
4095
4026
|
},
|
|
4096
4027
|
maxSharedStructures: 100
|
|
4097
4028
|
});
|
|
@@ -4099,7 +4030,7 @@
|
|
|
4099
4030
|
getStructures() {
|
|
4100
4031
|
return structures2
|
|
4101
4032
|
},
|
|
4102
|
-
saveStructures(structures) {
|
|
4033
|
+
saveStructures(structures) {
|
|
4103
4034
|
},
|
|
4104
4035
|
maxSharedStructures: 100
|
|
4105
4036
|
});
|