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/pack.js CHANGED
@@ -181,7 +181,7 @@ export class Packr extends Unpackr {
181
181
  let newSharedData = prepareStructures(structures, packr);
182
182
  if (packr.saveStructures(newSharedData, newSharedData.isCompatible) === false) {
183
183
  // get updated structures and try again if the update failed
184
- return packr.pack(value)
184
+ return packr.pack(value, encodeOptions)
185
185
  }
186
186
  packr.lastNamedStructuresLength = sharedLength
187
187
  return returnBuffer
@@ -775,7 +775,7 @@ export class Packr extends Unpackr {
775
775
  }
776
776
  }
777
777
  const writeStruct = (object, safePrototype) => {
778
- let newPosition = writeStructSlots(object, target, position, structures, makeRoom, (value, newPosition, notifySharedUpdate) => {
778
+ let newPosition = writeStructSlots(object, target, start, position, structures, makeRoom, (value, newPosition, notifySharedUpdate) => {
779
779
  if (notifySharedUpdate)
780
780
  return hasSharedUpdate = true;
781
781
  position = newPosition;
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "msgpackr",
3
3
  "author": "Kris Zyp",
4
- "version": "1.9.8",
4
+ "version": "1.9.9",
5
5
  "description": "Ultra-fast MessagePack implementation with extensions for records and structured cloning",
6
6
  "license": "MIT",
7
7
  "types": "./index.d.ts",
package/struct.js CHANGED
@@ -69,7 +69,7 @@ const encodeUtf8 = hasNodeBuffer ? function(target, string, position) {
69
69
  const TYPE = Symbol('type');
70
70
  const PARENT = Symbol('parent');
71
71
  setWriteStructSlots(writeStruct, prepareStructures);
72
- function writeStruct(object, target, position, structures, makeRoom, pack, packr) {
72
+ function writeStruct(object, target, encodingStart, position, structures, makeRoom, pack, packr) {
73
73
  let typedStructs = packr.typedStructs || (packr.typedStructs = []);
74
74
  // note that we rely on pack.js to load stored structures before we get to this point
75
75
  let targetView = target.dataView;
@@ -77,12 +77,12 @@ function writeStruct(object, target, position, structures, makeRoom, pack, packr
77
77
  let safeEnd = target.length - 10;
78
78
  let start = position;
79
79
  if (position > safeEnd) {
80
- let lastStart = start;
81
80
  target = makeRoom(position);
82
81
  targetView = target.dataView;
83
- position -= lastStart;
84
- refsStartPosition -= lastStart;
85
- start = 0;
82
+ position -= encodingStart;
83
+ start -= encodingStart;
84
+ refsStartPosition -= encodingStart;
85
+ encodingStart = 0;
86
86
  safeEnd = target.length - 10;
87
87
  }
88
88
 
@@ -120,13 +120,13 @@ function writeStruct(object, target, position, structures, makeRoom, pack, packr
120
120
  };
121
121
  }
122
122
  if (position > safeEnd) {
123
- let lastStart = start;
124
123
  target = makeRoom(position);
125
124
  targetView = target.dataView;
126
- position -= lastStart;
127
- refsStartPosition -= lastStart;
128
- refPosition -= lastStart;
129
- start = 0;
125
+ position -= encodingStart;
126
+ start -= encodingStart;
127
+ refsStartPosition -= encodingStart;
128
+ refPosition -= encodingStart;
129
+ encodingStart = 0;
130
130
  safeEnd = target.length - 10
131
131
  }
132
132
  switch (typeof value) {
@@ -165,13 +165,13 @@ function writeStruct(object, target, position, structures, makeRoom, pack, packr
165
165
  let strLength = value.length;
166
166
  refOffset = refPosition - refsStartPosition;
167
167
  if ((strLength << 2) + refPosition > safeEnd) {
168
- let lastStart = start;
169
168
  target = makeRoom((strLength << 2) + refPosition);
170
169
  targetView = target.dataView;
171
- position -= lastStart;
172
- refsStartPosition -= lastStart;
173
- refPosition -= lastStart;
174
- start = 0;
170
+ position -= encodingStart;
171
+ start -= encodingStart;
172
+ refsStartPosition -= encodingStart;
173
+ refPosition -= encodingStart;
174
+ encodingStart = 0;
175
175
  safeEnd = target.length - 10
176
176
  }
177
177
  if (strLength > ((0xff00 + refOffset) >> 2)) {
@@ -330,9 +330,10 @@ function writeStruct(object, target, position, structures, makeRoom, pack, packr
330
330
  refPosition = newPosition.position;
331
331
  targetView = newPosition.targetView;
332
332
  target = newPosition.target;
333
- refsStartPosition -= start;
334
- position -= start;
335
- start = 0;
333
+ refsStartPosition -= encodingStart;
334
+ position -= encodingStart;
335
+ start -= encodingStart;
336
+ encodingStart = 0;
336
337
  } else
337
338
  refPosition = newPosition;
338
339
  if (size === 2) {
@@ -406,7 +407,7 @@ function writeStruct(object, target, position, structures, makeRoom, pack, packr
406
407
  if (refsStartPosition === refPosition)
407
408
  return position; // no refs
408
409
  typedStructs.lastStringStart = position - start;
409
- return writeStruct(object, target, start, structures, makeRoom, pack, packr);
410
+ return writeStruct(object, target, encodingStart, start, structures, makeRoom, pack, packr);
410
411
  }
411
412
  return refPosition;
412
413
  }