msgpackr 1.7.0 → 1.7.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/pack.js CHANGED
@@ -125,12 +125,11 @@ export class Packr extends Unpackr {
125
125
  writeStruct(value);
126
126
  else
127
127
  pack(value)
128
- if (bundledStrings) {
129
- writeBundles(start, pack)
130
- }
131
- packr.offset = position // update the offset so next serialization doesn't write over our buffer, but can continue writing to same buffer sequentially
132
128
  if (referenceMap && referenceMap.idsToInsert) {
133
- position += referenceMap.idsToInsert.length * 6
129
+ let incrementPosition = referenceMap.idsToInsert.length * 6;
130
+ if (bundledStrings)
131
+ writeBundles(start, pack, incrementPosition)
132
+ position += incrementPosition
134
133
  if (position > safeEnd)
135
134
  makeRoom(position)
136
135
  packr.offset = position
@@ -138,6 +137,9 @@ export class Packr extends Unpackr {
138
137
  referenceMap = null
139
138
  return serialized
140
139
  }
140
+ if (bundledStrings)
141
+ writeBundles(start, pack, 0)
142
+ packr.offset = position // update the offset so next serialization doesn't write over our buffer, but can continue writing to same buffer sequentially
141
143
  if (encodeOptions & REUSE_BUFFER_MODE) {
142
144
  target.start = start
143
145
  target.end = position
@@ -922,12 +924,11 @@ function insertIds(serialized, idsToInsert) {
922
924
  return serialized
923
925
  }
924
926
 
925
- function writeBundles(start, pack) {
927
+ function writeBundles(start, pack, incrementPosition) {
926
928
  if (bundledStrings.length > 0) {
927
- targetView.setUint32(bundledStrings.position + start, position - bundledStrings.position - start)
929
+ targetView.setUint32(bundledStrings.position + start, position + incrementPosition - bundledStrings.position - start)
928
930
  let writeStrings = bundledStrings
929
931
  bundledStrings = null
930
- let startPosition = position
931
932
  pack(writeStrings[0])
932
933
  pack(writeStrings[1])
933
934
  }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "msgpackr",
3
3
  "author": "Kris Zyp",
4
- "version": "1.7.0",
4
+ "version": "1.7.1",
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
@@ -492,7 +492,7 @@ function readStruct(src, position, srcEnd, unpackr) {
492
492
  case 27: recordId = src[position++] + (src[position++] << 8) + (src[position++] << 16) + (src[position++] << 24); break;
493
493
  }
494
494
  }
495
- let structure = unpackr.typedStructs?.[recordId];
495
+ let structure = unpackr.typedStructs && unpackr.typedStructs[recordId];
496
496
  if (!structure) {
497
497
  // copy src buffer because getStructures will override it
498
498
  src = Uint8Array.prototype.slice.call(src, position, srcEnd);
@@ -784,7 +784,7 @@ function prepareStructures(structures, packr) {
784
784
  packr._mergeStructures(existing);
785
785
  return compatible;
786
786
  };
787
- packr.lastTypedStructuresLength = packr.typedStructs?.length;
787
+ packr.lastTypedStructuresLength = packr.typedStructs && packr.typedStructs.length;
788
788
  return structures;
789
789
  }
790
790
 
package/unpack.js CHANGED
@@ -193,7 +193,7 @@ export function checkedRead(options) {
193
193
 
194
194
  if (position == srcEnd) {
195
195
  // finished reading this source, cleanup references
196
- if (currentStructures?.restoreStructures)
196
+ if (currentStructures && currentStructures.restoreStructures)
197
197
  restoreStructures()
198
198
  currentStructures = null
199
199
  src = null
@@ -208,7 +208,7 @@ export function checkedRead(options) {
208
208
  // else more to read, but we are reading sequentially, so don't clear source yet
209
209
  return result
210
210
  } catch(error) {
211
- if (currentStructures?.restoreStructures)
211
+ if (currentStructures && currentStructures.restoreStructures)
212
212
  restoreStructures()
213
213
  clearSource()
214
214
  if (error instanceof RangeError || error.message.startsWith('Unexpected end of buffer') || position > srcEnd) {