msgpackr 1.10.2 → 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/README.md +4 -2
- package/dist/index-no-eval.cjs +45 -20
- 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 +45 -20
- 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 +46 -21
- package/dist/node.cjs.map +1 -1
- package/dist/test.js +101 -21
- 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 +19 -9
- package/index.d.ts +19 -9
- package/index.js +1 -1
- package/pack.js +43 -26
- package/package.json +1 -1
- package/struct.js +3 -1
- package/unpack.js +1 -1
package/dist/node.cjs
CHANGED
|
@@ -1001,7 +1001,7 @@ currentExtensions[0x42] = (data) => {
|
|
|
1001
1001
|
let length = data.length;
|
|
1002
1002
|
let value = BigInt(data[0] & 0x80 ? data[0] - 0x100 : data[0]);
|
|
1003
1003
|
for (let i = 1; i < length; i++) {
|
|
1004
|
-
value <<=
|
|
1004
|
+
value <<= BigInt(8);
|
|
1005
1005
|
value += BigInt(data[i]);
|
|
1006
1006
|
}
|
|
1007
1007
|
return value;
|
|
@@ -1208,7 +1208,7 @@ class Packr extends Unpackr {
|
|
|
1208
1208
|
let structures;
|
|
1209
1209
|
let referenceMap;
|
|
1210
1210
|
let encodeUtf8 = ByteArray.prototype.utf8Write ? function(string, position) {
|
|
1211
|
-
return target.utf8Write(string, position,
|
|
1211
|
+
return target.utf8Write(string, position, target.byteLength - position)
|
|
1212
1212
|
} : (textEncoder$1 && textEncoder$1.encodeInto) ?
|
|
1213
1213
|
function(string, position) {
|
|
1214
1214
|
return textEncoder$1.encodeInto(string, target.subarray(position)).written
|
|
@@ -1233,7 +1233,7 @@ class Packr extends Unpackr {
|
|
|
1233
1233
|
if (!this.structures && options.useRecords != false)
|
|
1234
1234
|
this.structures = [];
|
|
1235
1235
|
// two byte record ids for shared structures
|
|
1236
|
-
let useTwoByteRecords = maxSharedStructures > 32 || (maxOwnStructures + maxSharedStructures > 64);
|
|
1236
|
+
let useTwoByteRecords = maxSharedStructures > 32 || (maxOwnStructures + maxSharedStructures > 64);
|
|
1237
1237
|
let sharedLimitId = maxSharedStructures + 0x40;
|
|
1238
1238
|
let maxStructureId = maxSharedStructures + maxOwnStructures + 0x40;
|
|
1239
1239
|
if (maxStructureId > 8256) {
|
|
@@ -1251,7 +1251,7 @@ class Packr extends Unpackr {
|
|
|
1251
1251
|
}
|
|
1252
1252
|
safeEnd = target.length - 10;
|
|
1253
1253
|
if (safeEnd - position < 0x800) {
|
|
1254
|
-
// don't start too close to the end,
|
|
1254
|
+
// don't start too close to the end,
|
|
1255
1255
|
target = new ByteArrayAllocate(target.length);
|
|
1256
1256
|
targetView = target.dataView || (target.dataView = new DataView(target.buffer, 0, target.length));
|
|
1257
1257
|
safeEnd = target.length - 10;
|
|
@@ -1594,7 +1594,7 @@ class Packr extends Unpackr {
|
|
|
1594
1594
|
targetView.setUint32(position, referee.id);
|
|
1595
1595
|
position += 4;
|
|
1596
1596
|
return
|
|
1597
|
-
} else
|
|
1597
|
+
} else
|
|
1598
1598
|
referenceMap.set(value, { offset: position - start });
|
|
1599
1599
|
}
|
|
1600
1600
|
let constructor = value.constructor;
|
|
@@ -1622,7 +1622,7 @@ class Packr extends Unpackr {
|
|
|
1622
1622
|
pack(entryValue);
|
|
1623
1623
|
}
|
|
1624
1624
|
}
|
|
1625
|
-
} else {
|
|
1625
|
+
} else {
|
|
1626
1626
|
for (let i = 0, l = extensions.length; i < l; i++) {
|
|
1627
1627
|
let extensionClass = extensionClasses[i];
|
|
1628
1628
|
if (value instanceof extensionClass) {
|
|
@@ -1690,11 +1690,11 @@ class Packr extends Unpackr {
|
|
|
1690
1690
|
if (json !== value)
|
|
1691
1691
|
return pack(json)
|
|
1692
1692
|
}
|
|
1693
|
-
|
|
1693
|
+
|
|
1694
1694
|
// if there is a writeFunction, use it, otherwise just encode as undefined
|
|
1695
1695
|
if (type === 'function')
|
|
1696
1696
|
return pack(this.writeFunction && this.writeFunction(value));
|
|
1697
|
-
|
|
1697
|
+
|
|
1698
1698
|
// no extension found, write as plain object
|
|
1699
1699
|
writeObject(value);
|
|
1700
1700
|
}
|
|
@@ -1716,18 +1716,20 @@ class Packr extends Unpackr {
|
|
|
1716
1716
|
if (this.largeBigIntToFloat) {
|
|
1717
1717
|
target[position++] = 0xcb;
|
|
1718
1718
|
targetView.setFloat64(position, Number(value));
|
|
1719
|
-
} else if (this.
|
|
1719
|
+
} else if (this.largeBigIntToString) {
|
|
1720
|
+
return pack(value.toString());
|
|
1721
|
+
} else if (this.useBigIntExtension && value < BigInt(2)**BigInt(1023) && value > -(BigInt(2)**BigInt(1023))) {
|
|
1720
1722
|
target[position++] = 0xc7;
|
|
1721
1723
|
position++;
|
|
1722
1724
|
target[position++] = 0x42; // "B" for BigInt
|
|
1723
1725
|
let bytes = [];
|
|
1724
1726
|
let alignedSign;
|
|
1725
1727
|
do {
|
|
1726
|
-
let byte = value &
|
|
1727
|
-
alignedSign = (byte &
|
|
1728
|
+
let byte = value & BigInt(0xff);
|
|
1729
|
+
alignedSign = (byte & BigInt(0x80)) === (value < BigInt(0) ? BigInt(0x80) : BigInt(0));
|
|
1728
1730
|
bytes.push(byte);
|
|
1729
|
-
value >>=
|
|
1730
|
-
} while (!((value ===
|
|
1731
|
+
value >>= BigInt(8);
|
|
1732
|
+
} while (!((value === BigInt(0) || value === BigInt(-1)) && alignedSign));
|
|
1731
1733
|
target[position-2] = bytes.length;
|
|
1732
1734
|
for (let i = bytes.length; i > 0;) {
|
|
1733
1735
|
target[position++] = Number(bytes[--i]);
|
|
@@ -1735,7 +1737,8 @@ class Packr extends Unpackr {
|
|
|
1735
1737
|
return
|
|
1736
1738
|
} else {
|
|
1737
1739
|
throw new RangeError(value + ' was too large to fit in MessagePack 64-bit integer format, use' +
|
|
1738
|
-
' useBigIntExtension or set largeBigIntToFloat to convert to float-64'
|
|
1740
|
+
' useBigIntExtension, or set largeBigIntToFloat to convert to float-64, or set' +
|
|
1741
|
+
' largeBigIntToString to convert to string')
|
|
1739
1742
|
}
|
|
1740
1743
|
}
|
|
1741
1744
|
position += 8;
|
|
@@ -1752,9 +1755,19 @@ class Packr extends Unpackr {
|
|
|
1752
1755
|
}
|
|
1753
1756
|
};
|
|
1754
1757
|
|
|
1755
|
-
const writePlainObject = (this.variableMapSize || this.coercibleKeyAsNumber) ? (object) => {
|
|
1758
|
+
const writePlainObject = (this.variableMapSize || this.coercibleKeyAsNumber || this.skipValues) ? (object) => {
|
|
1756
1759
|
// this method is slightly slower, but generates "preferred serialization" (optimally small for smaller objects)
|
|
1757
|
-
let keys
|
|
1760
|
+
let keys;
|
|
1761
|
+
if (this.skipValues) {
|
|
1762
|
+
keys = [];
|
|
1763
|
+
for (let key in object) {
|
|
1764
|
+
if ((typeof object.hasOwnProperty !== 'function' || object.hasOwnProperty(key)) &&
|
|
1765
|
+
!this.skipValues.includes(object[key]))
|
|
1766
|
+
keys.push(key);
|
|
1767
|
+
}
|
|
1768
|
+
} else {
|
|
1769
|
+
keys = Object.keys(object);
|
|
1770
|
+
}
|
|
1758
1771
|
let length = keys.length;
|
|
1759
1772
|
if (length < 0x10) {
|
|
1760
1773
|
target[position++] = 0x80 | length;
|
|
@@ -1795,6 +1808,10 @@ class Packr extends Unpackr {
|
|
|
1795
1808
|
size++;
|
|
1796
1809
|
}
|
|
1797
1810
|
}
|
|
1811
|
+
if (size > 0xffff) {
|
|
1812
|
+
throw new Error('Object is too large to serialize with fast 16-bit map size,' +
|
|
1813
|
+
' use the "variableMapSize" option to serialize this object');
|
|
1814
|
+
}
|
|
1798
1815
|
target[objectOffset++ + start] = size >> 8;
|
|
1799
1816
|
target[objectOffset + start] = size & 0xff;
|
|
1800
1817
|
};
|
|
@@ -1873,9 +1890,9 @@ class Packr extends Unpackr {
|
|
|
1873
1890
|
}
|
|
1874
1891
|
};
|
|
1875
1892
|
|
|
1876
|
-
//
|
|
1893
|
+
// create reference to useRecords if useRecords is a function
|
|
1877
1894
|
const checkUseRecords = typeof this.useRecords == 'function' && this.useRecords;
|
|
1878
|
-
|
|
1895
|
+
|
|
1879
1896
|
const writeObject = checkUseRecords ? (object) => {
|
|
1880
1897
|
checkUseRecords(object) ? writeRecord(object) : writePlainObject(object);
|
|
1881
1898
|
} : writeRecord;
|
|
@@ -2003,9 +2020,15 @@ class Packr extends Unpackr {
|
|
|
2003
2020
|
useBuffer(buffer) {
|
|
2004
2021
|
// this means we are finished using our own buffer and we can write over it safely
|
|
2005
2022
|
target = buffer;
|
|
2006
|
-
|
|
2023
|
+
target.dataView || (target.dataView = new DataView(target.buffer, target.byteOffset, target.byteLength));
|
|
2007
2024
|
position = 0;
|
|
2008
2025
|
}
|
|
2026
|
+
set position (value) {
|
|
2027
|
+
position = value;
|
|
2028
|
+
}
|
|
2029
|
+
get position() {
|
|
2030
|
+
return position;
|
|
2031
|
+
}
|
|
2009
2032
|
clearSharedData() {
|
|
2010
2033
|
if (this.structures)
|
|
2011
2034
|
this.structures = [];
|
|
@@ -2143,7 +2166,7 @@ function writeBuffer(buffer, allocateForWrite) {
|
|
|
2143
2166
|
target[position++] = length >> 8;
|
|
2144
2167
|
target[position++] = length & 0xff;
|
|
2145
2168
|
} else {
|
|
2146
|
-
|
|
2169
|
+
let { target, position, targetView } = allocateForWrite(length + 5);
|
|
2147
2170
|
target[position++] = 0xc6;
|
|
2148
2171
|
targetView.setUint32(position, length);
|
|
2149
2172
|
position += 4;
|
|
@@ -2281,7 +2304,7 @@ try {
|
|
|
2281
2304
|
textEncoder = new TextEncoder();
|
|
2282
2305
|
} catch (error) {}
|
|
2283
2306
|
const encodeUtf8 = hasNodeBuffer ? function(target, string, position) {
|
|
2284
|
-
return target.utf8Write(string, position,
|
|
2307
|
+
return target.utf8Write(string, position, target.byteLength - position)
|
|
2285
2308
|
} : (textEncoder && textEncoder.encodeInto) ?
|
|
2286
2309
|
function(target, string, position) {
|
|
2287
2310
|
return textEncoder.encodeInto(string, target.subarray(position)).written
|
|
@@ -2722,6 +2745,8 @@ function readStruct(src, position, srcEnd, unpackr) {
|
|
|
2722
2745
|
src = Uint8Array.prototype.slice.call(src, position, srcEnd);
|
|
2723
2746
|
srcEnd -= position;
|
|
2724
2747
|
position = 0;
|
|
2748
|
+
if (!unpackr.getStructures)
|
|
2749
|
+
throw new Error(`Reference to shared structure ${recordId} without getStructures method`);
|
|
2725
2750
|
unpackr._mergeStructures(unpackr.getStructures());
|
|
2726
2751
|
if (!unpackr.typedStructs)
|
|
2727
2752
|
throw new Error('Could not find any shared typed structures');
|