msgpackr 1.9.7 → 1.9.9
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-no-eval.cjs +6 -4
- 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 +6 -4
- 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 +26 -23
- package/dist/node.cjs.map +1 -1
- package/dist/test.js +26 -23
- package/dist/test.js.map +1 -1
- package/dist/unpack-no-eval.cjs +2 -2
- package/dist/unpack-no-eval.cjs.map +1 -1
- package/pack.js +4 -2
- package/package.json +1 -1
- package/struct.js +20 -19
- package/unpack.js +2 -2
package/dist/test.js
CHANGED
|
@@ -173,8 +173,8 @@
|
|
|
173
173
|
}
|
|
174
174
|
return this.structures = loadedStructures
|
|
175
175
|
}
|
|
176
|
-
decode(source,
|
|
177
|
-
return this.unpack(source,
|
|
176
|
+
decode(source, options) {
|
|
177
|
+
return this.unpack(source, options)
|
|
178
178
|
}
|
|
179
179
|
};
|
|
180
180
|
function checkedRead(options) {
|
|
@@ -1226,6 +1226,7 @@
|
|
|
1226
1226
|
} else
|
|
1227
1227
|
position = (position + 7) & 0x7ffffff8; // Word align to make any future copying of this buffer faster
|
|
1228
1228
|
start = position;
|
|
1229
|
+
if (encodeOptions & RESERVE_START_SPACE) position += (encodeOptions & 0xff);
|
|
1229
1230
|
referenceMap = packr.structuredClone ? new Map() : null;
|
|
1230
1231
|
if (packr.bundleStrings && typeof value !== 'string') {
|
|
1231
1232
|
bundledStrings = [];
|
|
@@ -1327,7 +1328,7 @@
|
|
|
1327
1328
|
let newSharedData = prepareStructures$1(structures, packr);
|
|
1328
1329
|
if (packr.saveStructures(newSharedData, newSharedData.isCompatible) === false) {
|
|
1329
1330
|
// get updated structures and try again if the update failed
|
|
1330
|
-
return packr.pack(value)
|
|
1331
|
+
return packr.pack(value, encodeOptions)
|
|
1331
1332
|
}
|
|
1332
1333
|
packr.lastNamedStructuresLength = sharedLength;
|
|
1333
1334
|
return returnBuffer
|
|
@@ -1921,7 +1922,7 @@
|
|
|
1921
1922
|
}
|
|
1922
1923
|
};
|
|
1923
1924
|
const writeStruct = (object, safePrototype) => {
|
|
1924
|
-
let newPosition = writeStructSlots(object, target, position, structures, makeRoom, (value, newPosition, notifySharedUpdate) => {
|
|
1925
|
+
let newPosition = writeStructSlots(object, target, start, position, structures, makeRoom, (value, newPosition, notifySharedUpdate) => {
|
|
1925
1926
|
if (notifySharedUpdate)
|
|
1926
1927
|
return hasSharedUpdate = true;
|
|
1927
1928
|
position = newPosition;
|
|
@@ -2191,6 +2192,7 @@
|
|
|
2191
2192
|
defaultPackr.pack;
|
|
2192
2193
|
const REUSE_BUFFER_MODE = 512;
|
|
2193
2194
|
const RESET_BUFFER_MODE = 1024;
|
|
2195
|
+
const RESERVE_START_SPACE = 2048;
|
|
2194
2196
|
|
|
2195
2197
|
const ASCII = 3; // the MIBenum from https://www.iana.org/assignments/character-sets/character-sets.xhtml (and other character encodings could be referenced by MIBenum)
|
|
2196
2198
|
const NUMBER = 0;
|
|
@@ -2221,7 +2223,7 @@
|
|
|
2221
2223
|
return textEncoder.encodeInto(string, target.subarray(position)).written
|
|
2222
2224
|
} : false;
|
|
2223
2225
|
setWriteStructSlots(writeStruct, prepareStructures);
|
|
2224
|
-
function writeStruct(object, target, position, structures, makeRoom, pack, packr) {
|
|
2226
|
+
function writeStruct(object, target, encodingStart, position, structures, makeRoom, pack, packr) {
|
|
2225
2227
|
let typedStructs = packr.typedStructs || (packr.typedStructs = []);
|
|
2226
2228
|
// note that we rely on pack.js to load stored structures before we get to this point
|
|
2227
2229
|
let targetView = target.dataView;
|
|
@@ -2229,12 +2231,12 @@
|
|
|
2229
2231
|
let safeEnd = target.length - 10;
|
|
2230
2232
|
let start = position;
|
|
2231
2233
|
if (position > safeEnd) {
|
|
2232
|
-
let lastStart = start;
|
|
2233
2234
|
target = makeRoom(position);
|
|
2234
2235
|
targetView = target.dataView;
|
|
2235
|
-
position -=
|
|
2236
|
-
|
|
2237
|
-
|
|
2236
|
+
position -= encodingStart;
|
|
2237
|
+
start -= encodingStart;
|
|
2238
|
+
refsStartPosition -= encodingStart;
|
|
2239
|
+
encodingStart = 0;
|
|
2238
2240
|
safeEnd = target.length - 10;
|
|
2239
2241
|
}
|
|
2240
2242
|
|
|
@@ -2272,13 +2274,13 @@
|
|
|
2272
2274
|
};
|
|
2273
2275
|
}
|
|
2274
2276
|
if (position > safeEnd) {
|
|
2275
|
-
let lastStart = start;
|
|
2276
2277
|
target = makeRoom(position);
|
|
2277
2278
|
targetView = target.dataView;
|
|
2278
|
-
position -=
|
|
2279
|
-
|
|
2280
|
-
|
|
2281
|
-
|
|
2279
|
+
position -= encodingStart;
|
|
2280
|
+
start -= encodingStart;
|
|
2281
|
+
refsStartPosition -= encodingStart;
|
|
2282
|
+
refPosition -= encodingStart;
|
|
2283
|
+
encodingStart = 0;
|
|
2282
2284
|
safeEnd = target.length - 10;
|
|
2283
2285
|
}
|
|
2284
2286
|
switch (typeof value) {
|
|
@@ -2317,13 +2319,13 @@
|
|
|
2317
2319
|
let strLength = value.length;
|
|
2318
2320
|
refOffset = refPosition - refsStartPosition;
|
|
2319
2321
|
if ((strLength << 2) + refPosition > safeEnd) {
|
|
2320
|
-
let lastStart = start;
|
|
2321
2322
|
target = makeRoom((strLength << 2) + refPosition);
|
|
2322
2323
|
targetView = target.dataView;
|
|
2323
|
-
position -=
|
|
2324
|
-
|
|
2325
|
-
|
|
2326
|
-
|
|
2324
|
+
position -= encodingStart;
|
|
2325
|
+
start -= encodingStart;
|
|
2326
|
+
refsStartPosition -= encodingStart;
|
|
2327
|
+
refPosition -= encodingStart;
|
|
2328
|
+
encodingStart = 0;
|
|
2327
2329
|
safeEnd = target.length - 10;
|
|
2328
2330
|
}
|
|
2329
2331
|
if (strLength > ((0xff00 + refOffset) >> 2)) {
|
|
@@ -2482,9 +2484,10 @@
|
|
|
2482
2484
|
refPosition = newPosition.position;
|
|
2483
2485
|
targetView = newPosition.targetView;
|
|
2484
2486
|
target = newPosition.target;
|
|
2485
|
-
refsStartPosition -=
|
|
2486
|
-
position -=
|
|
2487
|
-
start
|
|
2487
|
+
refsStartPosition -= encodingStart;
|
|
2488
|
+
position -= encodingStart;
|
|
2489
|
+
start -= encodingStart;
|
|
2490
|
+
encodingStart = 0;
|
|
2488
2491
|
} else
|
|
2489
2492
|
refPosition = newPosition;
|
|
2490
2493
|
if (size === 2) {
|
|
@@ -2558,7 +2561,7 @@
|
|
|
2558
2561
|
if (refsStartPosition === refPosition)
|
|
2559
2562
|
return position; // no refs
|
|
2560
2563
|
typedStructs.lastStringStart = position - start;
|
|
2561
|
-
return writeStruct(object, target, start, structures, makeRoom, pack, packr);
|
|
2564
|
+
return writeStruct(object, target, encodingStart, start, structures, makeRoom, pack, packr);
|
|
2562
2565
|
}
|
|
2563
2566
|
return refPosition;
|
|
2564
2567
|
}
|