msgpackr 1.9.8 → 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/node.cjs CHANGED
@@ -1333,7 +1333,7 @@ class Packr extends Unpackr {
1333
1333
  let newSharedData = prepareStructures$1(structures, packr);
1334
1334
  if (packr.saveStructures(newSharedData, newSharedData.isCompatible) === false) {
1335
1335
  // get updated structures and try again if the update failed
1336
- return packr.pack(value)
1336
+ return packr.pack(value, encodeOptions)
1337
1337
  }
1338
1338
  packr.lastNamedStructuresLength = sharedLength;
1339
1339
  return returnBuffer
@@ -1927,7 +1927,7 @@ class Packr extends Unpackr {
1927
1927
  }
1928
1928
  };
1929
1929
  const writeStruct = (object, safePrototype) => {
1930
- let newPosition = writeStructSlots(object, target, position, structures, makeRoom, (value, newPosition, notifySharedUpdate) => {
1930
+ let newPosition = writeStructSlots(object, target, start, position, structures, makeRoom, (value, newPosition, notifySharedUpdate) => {
1931
1931
  if (notifySharedUpdate)
1932
1932
  return hasSharedUpdate = true;
1933
1933
  position = newPosition;
@@ -2230,7 +2230,7 @@ const encodeUtf8 = hasNodeBuffer ? function(target, string, position) {
2230
2230
  return textEncoder.encodeInto(string, target.subarray(position)).written
2231
2231
  } : false;
2232
2232
  setWriteStructSlots(writeStruct, prepareStructures);
2233
- function writeStruct(object, target, position, structures, makeRoom, pack, packr) {
2233
+ function writeStruct(object, target, encodingStart, position, structures, makeRoom, pack, packr) {
2234
2234
  let typedStructs = packr.typedStructs || (packr.typedStructs = []);
2235
2235
  // note that we rely on pack.js to load stored structures before we get to this point
2236
2236
  let targetView = target.dataView;
@@ -2238,12 +2238,12 @@ function writeStruct(object, target, position, structures, makeRoom, pack, packr
2238
2238
  let safeEnd = target.length - 10;
2239
2239
  let start = position;
2240
2240
  if (position > safeEnd) {
2241
- let lastStart = start;
2242
2241
  target = makeRoom(position);
2243
2242
  targetView = target.dataView;
2244
- position -= lastStart;
2245
- refsStartPosition -= lastStart;
2246
- start = 0;
2243
+ position -= encodingStart;
2244
+ start -= encodingStart;
2245
+ refsStartPosition -= encodingStart;
2246
+ encodingStart = 0;
2247
2247
  safeEnd = target.length - 10;
2248
2248
  }
2249
2249
 
@@ -2281,13 +2281,13 @@ function writeStruct(object, target, position, structures, makeRoom, pack, packr
2281
2281
  };
2282
2282
  }
2283
2283
  if (position > safeEnd) {
2284
- let lastStart = start;
2285
2284
  target = makeRoom(position);
2286
2285
  targetView = target.dataView;
2287
- position -= lastStart;
2288
- refsStartPosition -= lastStart;
2289
- refPosition -= lastStart;
2290
- start = 0;
2286
+ position -= encodingStart;
2287
+ start -= encodingStart;
2288
+ refsStartPosition -= encodingStart;
2289
+ refPosition -= encodingStart;
2290
+ encodingStart = 0;
2291
2291
  safeEnd = target.length - 10;
2292
2292
  }
2293
2293
  switch (typeof value) {
@@ -2326,13 +2326,13 @@ function writeStruct(object, target, position, structures, makeRoom, pack, packr
2326
2326
  let strLength = value.length;
2327
2327
  refOffset = refPosition - refsStartPosition;
2328
2328
  if ((strLength << 2) + refPosition > safeEnd) {
2329
- let lastStart = start;
2330
2329
  target = makeRoom((strLength << 2) + refPosition);
2331
2330
  targetView = target.dataView;
2332
- position -= lastStart;
2333
- refsStartPosition -= lastStart;
2334
- refPosition -= lastStart;
2335
- start = 0;
2331
+ position -= encodingStart;
2332
+ start -= encodingStart;
2333
+ refsStartPosition -= encodingStart;
2334
+ refPosition -= encodingStart;
2335
+ encodingStart = 0;
2336
2336
  safeEnd = target.length - 10;
2337
2337
  }
2338
2338
  if (strLength > ((0xff00 + refOffset) >> 2)) {
@@ -2491,9 +2491,10 @@ function writeStruct(object, target, position, structures, makeRoom, pack, packr
2491
2491
  refPosition = newPosition.position;
2492
2492
  targetView = newPosition.targetView;
2493
2493
  target = newPosition.target;
2494
- refsStartPosition -= start;
2495
- position -= start;
2496
- start = 0;
2494
+ refsStartPosition -= encodingStart;
2495
+ position -= encodingStart;
2496
+ start -= encodingStart;
2497
+ encodingStart = 0;
2497
2498
  } else
2498
2499
  refPosition = newPosition;
2499
2500
  if (size === 2) {
@@ -2567,7 +2568,7 @@ function writeStruct(object, target, position, structures, makeRoom, pack, packr
2567
2568
  if (refsStartPosition === refPosition)
2568
2569
  return position; // no refs
2569
2570
  typedStructs.lastStringStart = position - start;
2570
- return writeStruct(object, target, start, structures, makeRoom, pack, packr);
2571
+ return writeStruct(object, target, encodingStart, start, structures, makeRoom, pack, packr);
2571
2572
  }
2572
2573
  return refPosition;
2573
2574
  }