msgpackr 1.11.0 → 1.11.2
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 -1
- package/dist/index-no-eval.cjs +15 -8
- 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 +15 -8
- 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 +16 -9
- package/dist/node.cjs.map +1 -1
- package/dist/test.js +23 -9
- package/dist/test.js.map +1 -1
- package/dist/unpack-no-eval.cjs +1 -1
- package/dist/unpack-no-eval.cjs.map +1 -1
- package/index.d.cts +1 -0
- package/index.d.ts +1 -0
- package/pack.js +14 -7
- package/package.json +1 -1
- package/struct.js +1 -1
- package/unpack.js +1 -1
package/dist/test.js
CHANGED
|
@@ -997,7 +997,7 @@
|
|
|
997
997
|
let length = data.length;
|
|
998
998
|
let value = BigInt(data[0] & 0x80 ? data[0] - 0x100 : data[0]);
|
|
999
999
|
for (let i = 1; i < length; i++) {
|
|
1000
|
-
value <<=
|
|
1000
|
+
value <<= BigInt(8);
|
|
1001
1001
|
value += BigInt(data[i]);
|
|
1002
1002
|
}
|
|
1003
1003
|
return value;
|
|
@@ -1203,7 +1203,7 @@
|
|
|
1203
1203
|
let structures;
|
|
1204
1204
|
let referenceMap;
|
|
1205
1205
|
let encodeUtf8 = ByteArray.prototype.utf8Write ? function(string, position) {
|
|
1206
|
-
return target.utf8Write(string, position,
|
|
1206
|
+
return target.utf8Write(string, position, target.byteLength - position)
|
|
1207
1207
|
} : (textEncoder$1 && textEncoder$1.encodeInto) ?
|
|
1208
1208
|
function(string, position) {
|
|
1209
1209
|
return textEncoder$1.encodeInto(string, target.subarray(position)).written
|
|
@@ -1711,18 +1711,20 @@
|
|
|
1711
1711
|
if (this.largeBigIntToFloat) {
|
|
1712
1712
|
target[position++] = 0xcb;
|
|
1713
1713
|
targetView.setFloat64(position, Number(value));
|
|
1714
|
-
} else if (this.
|
|
1714
|
+
} else if (this.largeBigIntToString) {
|
|
1715
|
+
return pack(value.toString());
|
|
1716
|
+
} else if (this.useBigIntExtension && value < BigInt(2)**BigInt(1023) && value > -(BigInt(2)**BigInt(1023))) {
|
|
1715
1717
|
target[position++] = 0xc7;
|
|
1716
1718
|
position++;
|
|
1717
1719
|
target[position++] = 0x42; // "B" for BigInt
|
|
1718
1720
|
let bytes = [];
|
|
1719
1721
|
let alignedSign;
|
|
1720
1722
|
do {
|
|
1721
|
-
let byte = value &
|
|
1722
|
-
alignedSign = (byte &
|
|
1723
|
+
let byte = value & BigInt(0xff);
|
|
1724
|
+
alignedSign = (byte & BigInt(0x80)) === (value < BigInt(0) ? BigInt(0x80) : BigInt(0));
|
|
1723
1725
|
bytes.push(byte);
|
|
1724
|
-
value >>=
|
|
1725
|
-
} while (!((value ===
|
|
1726
|
+
value >>= BigInt(8);
|
|
1727
|
+
} while (!((value === BigInt(0) || value === BigInt(-1)) && alignedSign));
|
|
1726
1728
|
target[position-2] = bytes.length;
|
|
1727
1729
|
for (let i = bytes.length; i > 0;) {
|
|
1728
1730
|
target[position++] = Number(bytes[--i]);
|
|
@@ -1730,7 +1732,8 @@
|
|
|
1730
1732
|
return
|
|
1731
1733
|
} else {
|
|
1732
1734
|
throw new RangeError(value + ' was too large to fit in MessagePack 64-bit integer format, use' +
|
|
1733
|
-
' useBigIntExtension or set largeBigIntToFloat to convert to float-64'
|
|
1735
|
+
' useBigIntExtension, or set largeBigIntToFloat to convert to float-64, or set' +
|
|
1736
|
+
' largeBigIntToString to convert to string')
|
|
1734
1737
|
}
|
|
1735
1738
|
}
|
|
1736
1739
|
position += 8;
|
|
@@ -1800,6 +1803,10 @@
|
|
|
1800
1803
|
size++;
|
|
1801
1804
|
}
|
|
1802
1805
|
}
|
|
1806
|
+
if (size > 0xffff) {
|
|
1807
|
+
throw new Error('Object is too large to serialize with fast 16-bit map size,' +
|
|
1808
|
+
' use the "variableMapSize" option to serialize this object');
|
|
1809
|
+
}
|
|
1803
1810
|
target[objectOffset++ + start] = size >> 8;
|
|
1804
1811
|
target[objectOffset + start] = size & 0xff;
|
|
1805
1812
|
};
|
|
@@ -2290,7 +2297,7 @@
|
|
|
2290
2297
|
textEncoder = new TextEncoder();
|
|
2291
2298
|
} catch (error) {}
|
|
2292
2299
|
const encodeUtf8 = hasNodeBuffer ? function(target, string, position) {
|
|
2293
|
-
return target.utf8Write(string, position,
|
|
2300
|
+
return target.utf8Write(string, position, target.byteLength - position)
|
|
2294
2301
|
} : (textEncoder && textEncoder.encodeInto) ?
|
|
2295
2302
|
function(target, string, position) {
|
|
2296
2303
|
return textEncoder.encodeInto(string, target.subarray(position)).written
|
|
@@ -4193,6 +4200,13 @@
|
|
|
4193
4200
|
serialized = packr.pack(tooBigInt);
|
|
4194
4201
|
deserialized = unpack(serialized);
|
|
4195
4202
|
assert.isTrue(deserialized.tooBig > 2n**65n);
|
|
4203
|
+
|
|
4204
|
+
packr = new Packr({
|
|
4205
|
+
largeBigIntToString: true
|
|
4206
|
+
});
|
|
4207
|
+
serialized = packr.pack(tooBigInt);
|
|
4208
|
+
deserialized = unpack(serialized);
|
|
4209
|
+
assert.equal(deserialized.tooBig, (2n**66n).toString());
|
|
4196
4210
|
});
|
|
4197
4211
|
|
|
4198
4212
|
test('roundFloat32', function() {
|