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/README.md
CHANGED
|
@@ -184,6 +184,7 @@ The following options properties can be provided to the Packr or Unpackr constru
|
|
|
184
184
|
* `useTimestamp32` - Encode JS `Date`s in 32-bit format when possible by dropping the milliseconds. This is a more efficient encoding of dates. You can also cause dates to use 32-bit format by manually setting the milliseconds to zero (`date.setMilliseconds(0)`).
|
|
185
185
|
* `sequential` - Encode structures in serialized data, and reference previously encoded structures with expectation that decoder will read the encoded structures in the same order as encoded, with `unpackMultiple`.
|
|
186
186
|
* `largeBigIntToFloat` - If a bigint needs to be encoded that is larger than will fit in 64-bit integers, it will be encoded as a float-64 (otherwise will throw a RangeError).
|
|
187
|
+
* `largeBigIntToString` - If a bigint needs to be encoded that is larger than will fit in 64-bit integers, it will be encoded as a string (otherwise will throw a RangeError).
|
|
187
188
|
* `useBigIntExtension` - If a bigint needs to be encoded that is larger than will fit in 64-bit integers, it will be encoded using a custom extension that supports up to about 1000-bits of integer precision.
|
|
188
189
|
* `encodeUndefinedAsNil` - Encodes a value of `undefined` as a MessagePack `nil`, the same as a `null`.
|
|
189
190
|
* `int64AsType` - This will decode uint64 and int64 numbers as the specified type. The type can be `bigint` (default), `number`, `string`, or `auto` (where range [-2^53...2^53] is represented by number and everything else by a bigint).
|
|
@@ -272,7 +273,7 @@ addExtension({
|
|
|
272
273
|
pack(instance) {
|
|
273
274
|
// define how your custom class should be encoded
|
|
274
275
|
return Buffer.from([instance.myData]); // return a buffer
|
|
275
|
-
}
|
|
276
|
+
},
|
|
276
277
|
unpack(buffer) {
|
|
277
278
|
// define how your custom class should be decoded
|
|
278
279
|
let instance = new MyCustomClass();
|
package/dist/index-no-eval.cjs
CHANGED
|
@@ -946,7 +946,7 @@
|
|
|
946
946
|
let length = data.length;
|
|
947
947
|
let value = BigInt(data[0] & 0x80 ? data[0] - 0x100 : data[0]);
|
|
948
948
|
for (let i = 1; i < length; i++) {
|
|
949
|
-
value <<=
|
|
949
|
+
value <<= BigInt(8);
|
|
950
950
|
value += BigInt(data[i]);
|
|
951
951
|
}
|
|
952
952
|
return value;
|
|
@@ -1142,7 +1142,7 @@
|
|
|
1142
1142
|
let structures;
|
|
1143
1143
|
let referenceMap;
|
|
1144
1144
|
let encodeUtf8 = ByteArray.prototype.utf8Write ? function(string, position) {
|
|
1145
|
-
return target.utf8Write(string, position,
|
|
1145
|
+
return target.utf8Write(string, position, target.byteLength - position)
|
|
1146
1146
|
} : (textEncoder && textEncoder.encodeInto) ?
|
|
1147
1147
|
function(string, position) {
|
|
1148
1148
|
return textEncoder.encodeInto(string, target.subarray(position)).written
|
|
@@ -1650,18 +1650,20 @@
|
|
|
1650
1650
|
if (this.largeBigIntToFloat) {
|
|
1651
1651
|
target[position++] = 0xcb;
|
|
1652
1652
|
targetView.setFloat64(position, Number(value));
|
|
1653
|
-
} else if (this.
|
|
1653
|
+
} else if (this.largeBigIntToString) {
|
|
1654
|
+
return pack(value.toString());
|
|
1655
|
+
} else if (this.useBigIntExtension && value < BigInt(2)**BigInt(1023) && value > -(BigInt(2)**BigInt(1023))) {
|
|
1654
1656
|
target[position++] = 0xc7;
|
|
1655
1657
|
position++;
|
|
1656
1658
|
target[position++] = 0x42; // "B" for BigInt
|
|
1657
1659
|
let bytes = [];
|
|
1658
1660
|
let alignedSign;
|
|
1659
1661
|
do {
|
|
1660
|
-
let byte = value &
|
|
1661
|
-
alignedSign = (byte &
|
|
1662
|
+
let byte = value & BigInt(0xff);
|
|
1663
|
+
alignedSign = (byte & BigInt(0x80)) === (value < BigInt(0) ? BigInt(0x80) : BigInt(0));
|
|
1662
1664
|
bytes.push(byte);
|
|
1663
|
-
value >>=
|
|
1664
|
-
} while (!((value ===
|
|
1665
|
+
value >>= BigInt(8);
|
|
1666
|
+
} while (!((value === BigInt(0) || value === BigInt(-1)) && alignedSign));
|
|
1665
1667
|
target[position-2] = bytes.length;
|
|
1666
1668
|
for (let i = bytes.length; i > 0;) {
|
|
1667
1669
|
target[position++] = Number(bytes[--i]);
|
|
@@ -1669,7 +1671,8 @@
|
|
|
1669
1671
|
return
|
|
1670
1672
|
} else {
|
|
1671
1673
|
throw new RangeError(value + ' was too large to fit in MessagePack 64-bit integer format, use' +
|
|
1672
|
-
' useBigIntExtension or set largeBigIntToFloat to convert to float-64'
|
|
1674
|
+
' useBigIntExtension, or set largeBigIntToFloat to convert to float-64, or set' +
|
|
1675
|
+
' largeBigIntToString to convert to string')
|
|
1673
1676
|
}
|
|
1674
1677
|
}
|
|
1675
1678
|
position += 8;
|
|
@@ -1739,6 +1742,10 @@
|
|
|
1739
1742
|
size++;
|
|
1740
1743
|
}
|
|
1741
1744
|
}
|
|
1745
|
+
if (size > 0xffff) {
|
|
1746
|
+
throw new Error('Object is too large to serialize with fast 16-bit map size,' +
|
|
1747
|
+
' use the "variableMapSize" option to serialize this object');
|
|
1748
|
+
}
|
|
1742
1749
|
target[objectOffset++ + start] = size >> 8;
|
|
1743
1750
|
target[objectOffset + start] = size & 0xff;
|
|
1744
1751
|
};
|