msgpackr 1.11.4 → 1.11.5
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 +77 -25
- 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 +77 -25
- 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 +79 -27
- package/dist/node.cjs.map +1 -1
- package/dist/test.js +115 -37
- package/dist/test.js.map +1 -1
- package/dist/unpack-no-eval.cjs +36 -10
- package/dist/unpack-no-eval.cjs.map +1 -1
- package/pack.js +42 -16
- package/package.json +1 -1
- package/struct.js +1 -1
- package/unpack.js +36 -10
package/dist/index.js
CHANGED
|
@@ -943,21 +943,47 @@
|
|
|
943
943
|
currentExtensions[0] = () => {}; // notepack defines extension 0 to mean undefined, so use that as the default here
|
|
944
944
|
currentExtensions[0].noBuffer = true;
|
|
945
945
|
|
|
946
|
-
currentExtensions[0x42] =
|
|
947
|
-
|
|
948
|
-
let
|
|
949
|
-
let
|
|
950
|
-
|
|
951
|
-
|
|
952
|
-
value += BigInt(data[i]);
|
|
946
|
+
currentExtensions[0x42] = data => {
|
|
947
|
+
let headLength = (data.byteLength % 8) || 8;
|
|
948
|
+
let head = BigInt(data[0] & 0x80 ? data[0] - 0x100 : data[0]);
|
|
949
|
+
for (let i = 1; i < headLength; i++) {
|
|
950
|
+
head <<= BigInt(8);
|
|
951
|
+
head += BigInt(data[i]);
|
|
953
952
|
}
|
|
954
|
-
|
|
953
|
+
if (data.byteLength !== headLength) {
|
|
954
|
+
let view = new DataView(data.buffer, data.byteOffset, data.byteLength);
|
|
955
|
+
let decode = (start, end) => {
|
|
956
|
+
let length = end - start;
|
|
957
|
+
if (length <= 40) {
|
|
958
|
+
let out = view.getBigUint64(start);
|
|
959
|
+
for (let i = start + 8; i < end; i += 8) {
|
|
960
|
+
out <<= BigInt(64n);
|
|
961
|
+
out |= view.getBigUint64(i);
|
|
962
|
+
}
|
|
963
|
+
return out
|
|
964
|
+
}
|
|
965
|
+
// if (length === 8) return view.getBigUint64(start)
|
|
966
|
+
let middle = start + (length >> 4 << 3);
|
|
967
|
+
let left = decode(start, middle);
|
|
968
|
+
let right = decode(middle, end);
|
|
969
|
+
return (left << BigInt((end - middle) * 8)) | right
|
|
970
|
+
};
|
|
971
|
+
head = (head << BigInt((view.byteLength - headLength) * 8)) | decode(headLength, view.byteLength);
|
|
972
|
+
}
|
|
973
|
+
return head
|
|
955
974
|
};
|
|
956
975
|
|
|
957
|
-
let errors = {
|
|
976
|
+
let errors = {
|
|
977
|
+
Error, EvalError, RangeError, ReferenceError, SyntaxError, TypeError, URIError, AggregateError: typeof AggregateError === 'function' ? AggregateError : null,
|
|
978
|
+
};
|
|
958
979
|
currentExtensions[0x65] = () => {
|
|
959
980
|
let data = read();
|
|
960
|
-
|
|
981
|
+
if (!errors[data[0]]) {
|
|
982
|
+
let error = Error(data[1], { cause: data[2] });
|
|
983
|
+
error.name = data[0];
|
|
984
|
+
return error
|
|
985
|
+
}
|
|
986
|
+
return errors[data[0]](data[1], { cause: data[2] })
|
|
961
987
|
};
|
|
962
988
|
|
|
963
989
|
currentExtensions[0x69] = (data) => {
|
|
@@ -1665,22 +1691,47 @@
|
|
|
1665
1691
|
targetView.setFloat64(position, Number(value));
|
|
1666
1692
|
} else if (this.largeBigIntToString) {
|
|
1667
1693
|
return pack(value.toString());
|
|
1668
|
-
} else if (
|
|
1669
|
-
|
|
1670
|
-
|
|
1671
|
-
|
|
1672
|
-
|
|
1673
|
-
|
|
1674
|
-
|
|
1675
|
-
|
|
1676
|
-
|
|
1677
|
-
|
|
1678
|
-
|
|
1679
|
-
|
|
1680
|
-
|
|
1681
|
-
|
|
1682
|
-
|
|
1694
|
+
} else if (this.useBigIntExtension || this.moreTypes) {
|
|
1695
|
+
let empty = value < 0 ? BigInt(-1) : BigInt(0);
|
|
1696
|
+
|
|
1697
|
+
let array;
|
|
1698
|
+
if (value >> BigInt(0x10000) === empty) {
|
|
1699
|
+
let mask = BigInt(0x10000000000000000) - BigInt(1); // literal would overflow
|
|
1700
|
+
let chunks = [];
|
|
1701
|
+
while (true) {
|
|
1702
|
+
chunks.push(value & mask);
|
|
1703
|
+
if ((value >> BigInt(63)) === empty) break
|
|
1704
|
+
value >>= BigInt(64);
|
|
1705
|
+
}
|
|
1706
|
+
|
|
1707
|
+
array = new Uint8Array(new BigUint64Array(chunks).buffer);
|
|
1708
|
+
array.reverse();
|
|
1709
|
+
} else {
|
|
1710
|
+
let invert = value < 0;
|
|
1711
|
+
let string = (invert ? ~value : value).toString(16);
|
|
1712
|
+
if (string.length % 2) {
|
|
1713
|
+
string = '0' + string;
|
|
1714
|
+
} else if (parseInt(string.charAt(0), 16) >= 8) {
|
|
1715
|
+
string = '00' + string;
|
|
1716
|
+
}
|
|
1717
|
+
|
|
1718
|
+
if (hasNodeBuffer) {
|
|
1719
|
+
array = Buffer.from(string, 'hex');
|
|
1720
|
+
} else {
|
|
1721
|
+
array = new Uint8Array(string.length / 2);
|
|
1722
|
+
for (let i = 0; i < array.length; i++) {
|
|
1723
|
+
array[i] = parseInt(string.slice(i * 2, i * 2 + 2), 16);
|
|
1724
|
+
}
|
|
1725
|
+
}
|
|
1726
|
+
|
|
1727
|
+
if (invert) {
|
|
1728
|
+
for (let i = 0; i < array.length; i++) array[i] = ~array[i];
|
|
1729
|
+
}
|
|
1683
1730
|
}
|
|
1731
|
+
|
|
1732
|
+
if (array.length + position > safeEnd)
|
|
1733
|
+
makeRoom(array.length + position);
|
|
1734
|
+
position = writeExtensionData(array, target, position, 0x42);
|
|
1684
1735
|
return
|
|
1685
1736
|
} else {
|
|
1686
1737
|
throw new RangeError(value + ' was too large to fit in MessagePack 64-bit integer format, use' +
|
|
@@ -1968,6 +2019,7 @@
|
|
|
1968
2019
|
// this means we are finished using our own buffer and we can write over it safely
|
|
1969
2020
|
target = buffer;
|
|
1970
2021
|
target.dataView || (target.dataView = new DataView(target.buffer, target.byteOffset, target.byteLength));
|
|
2022
|
+
targetView = target.dataView;
|
|
1971
2023
|
position = 0;
|
|
1972
2024
|
}
|
|
1973
2025
|
set position (value) {
|