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/index.js
CHANGED
|
@@ -943,47 +943,21 @@
|
|
|
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] = data => {
|
|
947
|
-
|
|
948
|
-
let
|
|
949
|
-
|
|
950
|
-
|
|
951
|
-
|
|
946
|
+
currentExtensions[0x42] = (data) => {
|
|
947
|
+
// decode bigint
|
|
948
|
+
let length = data.length;
|
|
949
|
+
let value = BigInt(data[0] & 0x80 ? data[0] - 0x100 : data[0]);
|
|
950
|
+
for (let i = 1; i < length; i++) {
|
|
951
|
+
value <<= BigInt(8);
|
|
952
|
+
value += BigInt(data[i]);
|
|
952
953
|
}
|
|
953
|
-
|
|
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
|
|
954
|
+
return value;
|
|
974
955
|
};
|
|
975
956
|
|
|
976
|
-
let errors = {
|
|
977
|
-
Error, EvalError, RangeError, ReferenceError, SyntaxError, TypeError, URIError, AggregateError: typeof AggregateError === 'function' ? AggregateError : null,
|
|
978
|
-
};
|
|
957
|
+
let errors = { Error, TypeError, ReferenceError };
|
|
979
958
|
currentExtensions[0x65] = () => {
|
|
980
959
|
let data = read();
|
|
981
|
-
|
|
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] })
|
|
960
|
+
return (errors[data[0]] || Error)(data[1], { cause: data[2] })
|
|
987
961
|
};
|
|
988
962
|
|
|
989
963
|
currentExtensions[0x69] = (data) => {
|
|
@@ -1691,46 +1665,22 @@
|
|
|
1691
1665
|
targetView.setFloat64(position, Number(value));
|
|
1692
1666
|
} else if (this.largeBigIntToString) {
|
|
1693
1667
|
return pack(value.toString());
|
|
1694
|
-
} else if (this.useBigIntExtension || this.moreTypes) {
|
|
1695
|
-
|
|
1696
|
-
|
|
1697
|
-
|
|
1698
|
-
|
|
1699
|
-
|
|
1700
|
-
|
|
1701
|
-
|
|
1702
|
-
|
|
1703
|
-
|
|
1704
|
-
|
|
1705
|
-
|
|
1706
|
-
|
|
1707
|
-
|
|
1708
|
-
|
|
1709
|
-
let invert = value < 0;
|
|
1710
|
-
let string = (invert ? ~value : value).toString(16);
|
|
1711
|
-
if (string.length % 2) {
|
|
1712
|
-
string = '0' + string;
|
|
1713
|
-
} else if (parseInt(string.charAt(0), 16) >= 8) {
|
|
1714
|
-
string = '00' + string;
|
|
1715
|
-
}
|
|
1716
|
-
|
|
1717
|
-
if (hasNodeBuffer) {
|
|
1718
|
-
array = Buffer.from(string, 'hex');
|
|
1719
|
-
} else {
|
|
1720
|
-
array = new Uint8Array(string.length / 2);
|
|
1721
|
-
for (let i = 0; i < array.length; i++) {
|
|
1722
|
-
array[i] = parseInt(string.slice(i * 2, i * 2 + 2), 16);
|
|
1723
|
-
}
|
|
1724
|
-
}
|
|
1725
|
-
|
|
1726
|
-
if (invert) {
|
|
1727
|
-
for (let i = 0; i < array.length; i++) array[i] = ~array[i];
|
|
1728
|
-
}
|
|
1668
|
+
} else if ((this.useBigIntExtension || this.moreTypes) && value < BigInt(2)**BigInt(1023) && value > -(BigInt(2)**BigInt(1023))) {
|
|
1669
|
+
target[position++] = 0xc7;
|
|
1670
|
+
position++;
|
|
1671
|
+
target[position++] = 0x42; // "B" for BigInt
|
|
1672
|
+
let bytes = [];
|
|
1673
|
+
let alignedSign;
|
|
1674
|
+
do {
|
|
1675
|
+
let byte = value & BigInt(0xff);
|
|
1676
|
+
alignedSign = (byte & BigInt(0x80)) === (value < BigInt(0) ? BigInt(0x80) : BigInt(0));
|
|
1677
|
+
bytes.push(byte);
|
|
1678
|
+
value >>= BigInt(8);
|
|
1679
|
+
} while (!((value === BigInt(0) || value === BigInt(-1)) && alignedSign));
|
|
1680
|
+
target[position-2] = bytes.length;
|
|
1681
|
+
for (let i = bytes.length; i > 0;) {
|
|
1682
|
+
target[position++] = Number(bytes[--i]);
|
|
1729
1683
|
}
|
|
1730
|
-
|
|
1731
|
-
if (array.length + position > safeEnd)
|
|
1732
|
-
makeRoom(array.length + position);
|
|
1733
|
-
position = writeExtensionData(array, target, position, 0x42);
|
|
1734
1684
|
return
|
|
1735
1685
|
} else {
|
|
1736
1686
|
throw new RangeError(value + ' was too large to fit in MessagePack 64-bit integer format, use' +
|