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/index.js
CHANGED
|
@@ -945,7 +945,7 @@
|
|
|
945
945
|
let length = data.length;
|
|
946
946
|
let value = BigInt(data[0] & 0x80 ? data[0] - 0x100 : data[0]);
|
|
947
947
|
for (let i = 1; i < length; i++) {
|
|
948
|
-
value <<=
|
|
948
|
+
value <<= BigInt(8);
|
|
949
949
|
value += BigInt(data[i]);
|
|
950
950
|
}
|
|
951
951
|
return value;
|
|
@@ -1141,7 +1141,7 @@
|
|
|
1141
1141
|
let structures;
|
|
1142
1142
|
let referenceMap;
|
|
1143
1143
|
let encodeUtf8 = ByteArray.prototype.utf8Write ? function(string, position) {
|
|
1144
|
-
return target.utf8Write(string, position,
|
|
1144
|
+
return target.utf8Write(string, position, target.byteLength - position)
|
|
1145
1145
|
} : (textEncoder && textEncoder.encodeInto) ?
|
|
1146
1146
|
function(string, position) {
|
|
1147
1147
|
return textEncoder.encodeInto(string, target.subarray(position)).written
|
|
@@ -1166,7 +1166,7 @@
|
|
|
1166
1166
|
if (!this.structures && options.useRecords != false)
|
|
1167
1167
|
this.structures = [];
|
|
1168
1168
|
// two byte record ids for shared structures
|
|
1169
|
-
let useTwoByteRecords = maxSharedStructures > 32 || (maxOwnStructures + maxSharedStructures > 64);
|
|
1169
|
+
let useTwoByteRecords = maxSharedStructures > 32 || (maxOwnStructures + maxSharedStructures > 64);
|
|
1170
1170
|
let sharedLimitId = maxSharedStructures + 0x40;
|
|
1171
1171
|
let maxStructureId = maxSharedStructures + maxOwnStructures + 0x40;
|
|
1172
1172
|
if (maxStructureId > 8256) {
|
|
@@ -1184,7 +1184,7 @@
|
|
|
1184
1184
|
}
|
|
1185
1185
|
safeEnd = target.length - 10;
|
|
1186
1186
|
if (safeEnd - position < 0x800) {
|
|
1187
|
-
// don't start too close to the end,
|
|
1187
|
+
// don't start too close to the end,
|
|
1188
1188
|
target = new ByteArrayAllocate(target.length);
|
|
1189
1189
|
targetView = target.dataView || (target.dataView = new DataView(target.buffer, 0, target.length));
|
|
1190
1190
|
safeEnd = target.length - 10;
|
|
@@ -1527,7 +1527,7 @@
|
|
|
1527
1527
|
targetView.setUint32(position, referee.id);
|
|
1528
1528
|
position += 4;
|
|
1529
1529
|
return
|
|
1530
|
-
} else
|
|
1530
|
+
} else
|
|
1531
1531
|
referenceMap.set(value, { offset: position - start });
|
|
1532
1532
|
}
|
|
1533
1533
|
let constructor = value.constructor;
|
|
@@ -1555,7 +1555,7 @@
|
|
|
1555
1555
|
pack(entryValue);
|
|
1556
1556
|
}
|
|
1557
1557
|
}
|
|
1558
|
-
} else {
|
|
1558
|
+
} else {
|
|
1559
1559
|
for (let i = 0, l = extensions.length; i < l; i++) {
|
|
1560
1560
|
let extensionClass = extensionClasses[i];
|
|
1561
1561
|
if (value instanceof extensionClass) {
|
|
@@ -1623,11 +1623,11 @@
|
|
|
1623
1623
|
if (json !== value)
|
|
1624
1624
|
return pack(json)
|
|
1625
1625
|
}
|
|
1626
|
-
|
|
1626
|
+
|
|
1627
1627
|
// if there is a writeFunction, use it, otherwise just encode as undefined
|
|
1628
1628
|
if (type === 'function')
|
|
1629
1629
|
return pack(this.writeFunction && this.writeFunction(value));
|
|
1630
|
-
|
|
1630
|
+
|
|
1631
1631
|
// no extension found, write as plain object
|
|
1632
1632
|
writeObject(value);
|
|
1633
1633
|
}
|
|
@@ -1649,18 +1649,20 @@
|
|
|
1649
1649
|
if (this.largeBigIntToFloat) {
|
|
1650
1650
|
target[position++] = 0xcb;
|
|
1651
1651
|
targetView.setFloat64(position, Number(value));
|
|
1652
|
-
} else if (this.
|
|
1652
|
+
} else if (this.largeBigIntToString) {
|
|
1653
|
+
return pack(value.toString());
|
|
1654
|
+
} else if (this.useBigIntExtension && value < BigInt(2)**BigInt(1023) && value > -(BigInt(2)**BigInt(1023))) {
|
|
1653
1655
|
target[position++] = 0xc7;
|
|
1654
1656
|
position++;
|
|
1655
1657
|
target[position++] = 0x42; // "B" for BigInt
|
|
1656
1658
|
let bytes = [];
|
|
1657
1659
|
let alignedSign;
|
|
1658
1660
|
do {
|
|
1659
|
-
let byte = value &
|
|
1660
|
-
alignedSign = (byte &
|
|
1661
|
+
let byte = value & BigInt(0xff);
|
|
1662
|
+
alignedSign = (byte & BigInt(0x80)) === (value < BigInt(0) ? BigInt(0x80) : BigInt(0));
|
|
1661
1663
|
bytes.push(byte);
|
|
1662
|
-
value >>=
|
|
1663
|
-
} while (!((value ===
|
|
1664
|
+
value >>= BigInt(8);
|
|
1665
|
+
} while (!((value === BigInt(0) || value === BigInt(-1)) && alignedSign));
|
|
1664
1666
|
target[position-2] = bytes.length;
|
|
1665
1667
|
for (let i = bytes.length; i > 0;) {
|
|
1666
1668
|
target[position++] = Number(bytes[--i]);
|
|
@@ -1668,7 +1670,8 @@
|
|
|
1668
1670
|
return
|
|
1669
1671
|
} else {
|
|
1670
1672
|
throw new RangeError(value + ' was too large to fit in MessagePack 64-bit integer format, use' +
|
|
1671
|
-
' useBigIntExtension or set largeBigIntToFloat to convert to float-64'
|
|
1673
|
+
' useBigIntExtension, or set largeBigIntToFloat to convert to float-64, or set' +
|
|
1674
|
+
' largeBigIntToString to convert to string')
|
|
1672
1675
|
}
|
|
1673
1676
|
}
|
|
1674
1677
|
position += 8;
|
|
@@ -1685,9 +1688,19 @@
|
|
|
1685
1688
|
}
|
|
1686
1689
|
};
|
|
1687
1690
|
|
|
1688
|
-
const writePlainObject = (this.variableMapSize || this.coercibleKeyAsNumber) ? (object) => {
|
|
1691
|
+
const writePlainObject = (this.variableMapSize || this.coercibleKeyAsNumber || this.skipValues) ? (object) => {
|
|
1689
1692
|
// this method is slightly slower, but generates "preferred serialization" (optimally small for smaller objects)
|
|
1690
|
-
let keys
|
|
1693
|
+
let keys;
|
|
1694
|
+
if (this.skipValues) {
|
|
1695
|
+
keys = [];
|
|
1696
|
+
for (let key in object) {
|
|
1697
|
+
if ((typeof object.hasOwnProperty !== 'function' || object.hasOwnProperty(key)) &&
|
|
1698
|
+
!this.skipValues.includes(object[key]))
|
|
1699
|
+
keys.push(key);
|
|
1700
|
+
}
|
|
1701
|
+
} else {
|
|
1702
|
+
keys = Object.keys(object);
|
|
1703
|
+
}
|
|
1691
1704
|
let length = keys.length;
|
|
1692
1705
|
if (length < 0x10) {
|
|
1693
1706
|
target[position++] = 0x80 | length;
|
|
@@ -1728,6 +1741,10 @@
|
|
|
1728
1741
|
size++;
|
|
1729
1742
|
}
|
|
1730
1743
|
}
|
|
1744
|
+
if (size > 0xffff) {
|
|
1745
|
+
throw new Error('Object is too large to serialize with fast 16-bit map size,' +
|
|
1746
|
+
' use the "variableMapSize" option to serialize this object');
|
|
1747
|
+
}
|
|
1731
1748
|
target[objectOffset++ + start] = size >> 8;
|
|
1732
1749
|
target[objectOffset + start] = size & 0xff;
|
|
1733
1750
|
};
|
|
@@ -1806,9 +1823,9 @@
|
|
|
1806
1823
|
}
|
|
1807
1824
|
};
|
|
1808
1825
|
|
|
1809
|
-
//
|
|
1826
|
+
// create reference to useRecords if useRecords is a function
|
|
1810
1827
|
const checkUseRecords = typeof this.useRecords == 'function' && this.useRecords;
|
|
1811
|
-
|
|
1828
|
+
|
|
1812
1829
|
const writeObject = checkUseRecords ? (object) => {
|
|
1813
1830
|
checkUseRecords(object) ? writeRecord(object) : writePlainObject(object);
|
|
1814
1831
|
} : writeRecord;
|
|
@@ -1936,9 +1953,15 @@
|
|
|
1936
1953
|
useBuffer(buffer) {
|
|
1937
1954
|
// this means we are finished using our own buffer and we can write over it safely
|
|
1938
1955
|
target = buffer;
|
|
1939
|
-
|
|
1956
|
+
target.dataView || (target.dataView = new DataView(target.buffer, target.byteOffset, target.byteLength));
|
|
1940
1957
|
position = 0;
|
|
1941
1958
|
}
|
|
1959
|
+
set position (value) {
|
|
1960
|
+
position = value;
|
|
1961
|
+
}
|
|
1962
|
+
get position() {
|
|
1963
|
+
return position;
|
|
1964
|
+
}
|
|
1942
1965
|
clearSharedData() {
|
|
1943
1966
|
if (this.structures)
|
|
1944
1967
|
this.structures = [];
|
|
@@ -2076,7 +2099,7 @@
|
|
|
2076
2099
|
target[position++] = length >> 8;
|
|
2077
2100
|
target[position++] = length & 0xff;
|
|
2078
2101
|
} else {
|
|
2079
|
-
|
|
2102
|
+
let { target, position, targetView } = allocateForWrite(length + 5);
|
|
2080
2103
|
target[position++] = 0xc6;
|
|
2081
2104
|
targetView.setUint32(position, length);
|
|
2082
2105
|
position += 4;
|
|
@@ -2284,6 +2307,8 @@
|
|
|
2284
2307
|
exports.FLOAT32_OPTIONS = FLOAT32_OPTIONS;
|
|
2285
2308
|
exports.NEVER = NEVER;
|
|
2286
2309
|
exports.Packr = Packr;
|
|
2310
|
+
exports.RESERVE_START_SPACE = RESERVE_START_SPACE;
|
|
2311
|
+
exports.RESET_BUFFER_MODE = RESET_BUFFER_MODE;
|
|
2287
2312
|
exports.REUSE_BUFFER_MODE = REUSE_BUFFER_MODE;
|
|
2288
2313
|
exports.Unpackr = Unpackr;
|
|
2289
2314
|
exports.addExtension = addExtension;
|