msgpackr 1.11.0 → 1.11.1

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/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 <<= 8n;
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, 0xffffffff)
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.useBigIntExtension && value < 2n**(1023n) && value > -(2n**(1023n))) {
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 & 0xffn;
1722
- alignedSign = (byte & 0x80n) === (value < 0n ? 0x80n : 0n);
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 >>= 8n;
1725
- } while (!((value === 0n || value === -1n) && alignedSign));
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
  };
@@ -2154,7 +2161,7 @@
2154
2161
  target[position++] = length >> 8;
2155
2162
  target[position++] = length & 0xff;
2156
2163
  } else {
2157
- var { target, position, targetView } = allocateForWrite(length + 5);
2164
+ let { target, position, targetView } = allocateForWrite(length + 5);
2158
2165
  target[position++] = 0xc6;
2159
2166
  targetView.setUint32(position, length);
2160
2167
  position += 4;
@@ -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, 0xffffffff)
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() {