msgpackr 1.7.1 → 1.7.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/dist/index.js +40 -22
- package/dist/index.js.map +1 -1
- package/dist/index.min.js +49 -48
- package/dist/index.min.js.map +1 -1
- package/dist/node.cjs +40 -22
- package/dist/node.cjs.map +1 -1
- package/dist/test.js +66 -24
- package/dist/test.js.map +1 -1
- package/pack.js +37 -10
- package/package.json +1 -1
- package/unpack.js +3 -12
package/dist/node.cjs
CHANGED
|
@@ -872,7 +872,7 @@ function readExt(length) {
|
|
|
872
872
|
})
|
|
873
873
|
}
|
|
874
874
|
else
|
|
875
|
-
throw new Error('Unknown extension type ' + type)
|
|
875
|
+
throw new Error('Unknown extension type ' + type)``
|
|
876
876
|
}
|
|
877
877
|
|
|
878
878
|
var keyCache = new Array(4096);
|
|
@@ -887,7 +887,7 @@ function readKey() {
|
|
|
887
887
|
return readFixedString(length)
|
|
888
888
|
} else { // not cacheable, go back and do a standard read
|
|
889
889
|
position--;
|
|
890
|
-
return read()
|
|
890
|
+
return read().toString()
|
|
891
891
|
}
|
|
892
892
|
let key = ((length << 5) ^ (length > 1 ? dataView.getUint16(position) : length > 0 ? src[position] : 0)) & 0xfff;
|
|
893
893
|
let entry = keyCache[key];
|
|
@@ -941,16 +941,7 @@ function readKey() {
|
|
|
941
941
|
|
|
942
942
|
// the registration of the record definition extension (as "r")
|
|
943
943
|
const recordDefinition = (id, highByte) => {
|
|
944
|
-
let structure;
|
|
945
|
-
if (currentUnpackr.freezeData) {
|
|
946
|
-
currentUnpackr.freezeData = false;
|
|
947
|
-
try {
|
|
948
|
-
structure = read();
|
|
949
|
-
} finally {
|
|
950
|
-
currentUnpackr.freezeData = true;
|
|
951
|
-
}
|
|
952
|
-
} else
|
|
953
|
-
structure = read();
|
|
944
|
+
let structure = read().map(property => property.toString()); // ensure that all keys are strings and that the array is mutable
|
|
954
945
|
let firstByte = id;
|
|
955
946
|
if (highByte !== undefined) {
|
|
956
947
|
id = id < 32 ? -((highByte << 5) + id) : ((highByte << 5) + id);
|
|
@@ -1254,20 +1245,44 @@ class Packr extends Unpackr {
|
|
|
1254
1245
|
writeStruct(value);
|
|
1255
1246
|
else
|
|
1256
1247
|
pack(value);
|
|
1248
|
+
let lastBundle = bundledStrings$1;
|
|
1249
|
+
if (bundledStrings$1)
|
|
1250
|
+
writeBundles(start, pack, 0);
|
|
1257
1251
|
if (referenceMap && referenceMap.idsToInsert) {
|
|
1258
|
-
let
|
|
1259
|
-
|
|
1260
|
-
|
|
1261
|
-
|
|
1252
|
+
let idsToInsert = referenceMap.idsToInsert.sort((a, b) => a.offset > b.offset ? 1 : -1);
|
|
1253
|
+
let i = idsToInsert.length;
|
|
1254
|
+
let incrementPosition = -1;
|
|
1255
|
+
while (lastBundle && i > 0) {
|
|
1256
|
+
let insertionPoint = idsToInsert[--i].offset + start;
|
|
1257
|
+
if (insertionPoint < (lastBundle.stringsPosition + start) && incrementPosition === -1)
|
|
1258
|
+
incrementPosition = 0;
|
|
1259
|
+
if (insertionPoint > (lastBundle.position + start)) {
|
|
1260
|
+
if (incrementPosition >= 0)
|
|
1261
|
+
incrementPosition += 6;
|
|
1262
|
+
} else {
|
|
1263
|
+
if (incrementPosition >= 0) {
|
|
1264
|
+
// update the bundle reference now
|
|
1265
|
+
targetView.setUint32(lastBundle.position + start,
|
|
1266
|
+
targetView.getUint32(lastBundle.position + start) + incrementPosition);
|
|
1267
|
+
incrementPosition = -1; // reset
|
|
1268
|
+
}
|
|
1269
|
+
lastBundle = lastBundle.previous;
|
|
1270
|
+
i++;
|
|
1271
|
+
}
|
|
1272
|
+
}
|
|
1273
|
+
if (incrementPosition >= 0 && lastBundle) {
|
|
1274
|
+
// update the bundle reference now
|
|
1275
|
+
targetView.setUint32(lastBundle.position + start,
|
|
1276
|
+
targetView.getUint32(lastBundle.position + start) + incrementPosition);
|
|
1277
|
+
}
|
|
1278
|
+
position$1 += idsToInsert.length * 6;
|
|
1262
1279
|
if (position$1 > safeEnd)
|
|
1263
1280
|
makeRoom(position$1);
|
|
1264
1281
|
packr.offset = position$1;
|
|
1265
|
-
let serialized = insertIds(target.subarray(start, position$1),
|
|
1282
|
+
let serialized = insertIds(target.subarray(start, position$1), idsToInsert);
|
|
1266
1283
|
referenceMap = null;
|
|
1267
1284
|
return serialized
|
|
1268
1285
|
}
|
|
1269
|
-
if (bundledStrings$1)
|
|
1270
|
-
writeBundles(start, pack, 0);
|
|
1271
1286
|
packr.offset = position$1; // update the offset so next serialization doesn't write over our buffer, but can continue writing to same buffer sequentially
|
|
1272
1287
|
if (encodeOptions & REUSE_BUFFER_MODE) {
|
|
1273
1288
|
target.start = start;
|
|
@@ -1325,13 +1340,15 @@ class Packr extends Unpackr {
|
|
|
1325
1340
|
let maxBytes = (bundledStrings$1[0] ? bundledStrings$1[0].length * 3 + bundledStrings$1[1].length : 0) + 10;
|
|
1326
1341
|
if (position$1 + maxBytes > safeEnd)
|
|
1327
1342
|
target = makeRoom(position$1 + maxBytes);
|
|
1328
|
-
|
|
1343
|
+
let lastBundle;
|
|
1344
|
+
if (bundledStrings$1.position) { // here we use the 0x62 extension to write the last bundle and reserve space for the reference pointer to the next/current bundle
|
|
1345
|
+
lastBundle = bundledStrings$1;
|
|
1329
1346
|
target[position$1] = 0xc8; // ext 16
|
|
1330
1347
|
position$1 += 3; // reserve for the writing bundle size
|
|
1331
1348
|
target[position$1++] = 0x62; // 'b'
|
|
1332
1349
|
extStart = position$1 - start;
|
|
1333
1350
|
position$1 += 4; // reserve for writing bundle reference
|
|
1334
|
-
writeBundles(start, pack); // write the last bundles
|
|
1351
|
+
writeBundles(start, pack, 0); // write the last bundles
|
|
1335
1352
|
targetView.setUint16(extStart + start - 3, position$1 - start - extStart);
|
|
1336
1353
|
} else { // here we use the 0x62 extension just to reserve the space for the reference pointer to the bundle (will be updated once the bundle is written)
|
|
1337
1354
|
target[position$1++] = 0xd6; // fixext 4
|
|
@@ -1340,6 +1357,7 @@ class Packr extends Unpackr {
|
|
|
1340
1357
|
position$1 += 4; // reserve for writing bundle reference
|
|
1341
1358
|
}
|
|
1342
1359
|
bundledStrings$1 = ['', '']; // create new ones
|
|
1360
|
+
bundledStrings$1.previous = lastBundle;
|
|
1343
1361
|
bundledStrings$1.size = 0;
|
|
1344
1362
|
bundledStrings$1.position = extStart;
|
|
1345
1363
|
}
|
|
@@ -2029,7 +2047,6 @@ function insertIds(serialized, idsToInsert) {
|
|
|
2029
2047
|
let nextId;
|
|
2030
2048
|
let distanceToMove = idsToInsert.length * 6;
|
|
2031
2049
|
let lastEnd = serialized.length - distanceToMove;
|
|
2032
|
-
idsToInsert.sort((a, b) => a.offset > b.offset ? 1 : -1);
|
|
2033
2050
|
while (nextId = idsToInsert.pop()) {
|
|
2034
2051
|
let offset = nextId.offset;
|
|
2035
2052
|
let id = nextId.id;
|
|
@@ -2050,6 +2067,7 @@ function insertIds(serialized, idsToInsert) {
|
|
|
2050
2067
|
function writeBundles(start, pack, incrementPosition) {
|
|
2051
2068
|
if (bundledStrings$1.length > 0) {
|
|
2052
2069
|
targetView.setUint32(bundledStrings$1.position + start, position$1 + incrementPosition - bundledStrings$1.position - start);
|
|
2070
|
+
bundledStrings$1.stringsPosition = position$1 - start;
|
|
2053
2071
|
let writeStrings = bundledStrings$1;
|
|
2054
2072
|
bundledStrings$1 = null;
|
|
2055
2073
|
pack(writeStrings[0]);
|