msgpackr 1.7.2 → 1.8.0

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 CHANGED
@@ -1,8 +1,8 @@
1
1
  (function (global, factory) {
2
2
  typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports) :
3
3
  typeof define === 'function' && define.amd ? define(['exports'], factory) :
4
- (global = global || self, factory(global.msgpackr = {}));
5
- }(this, (function (exports) { 'use strict';
4
+ (global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global.msgpackr = {}));
5
+ })(this, (function (exports) { 'use strict';
6
6
 
7
7
  var decoder;
8
8
  try {
@@ -10,13 +10,13 @@
10
10
  } catch(error) {}
11
11
  var src;
12
12
  var srcEnd;
13
- var position = 0;
13
+ var position$1 = 0;
14
14
  var currentUnpackr = {};
15
15
  var currentStructures;
16
16
  var srcString;
17
17
  var srcStringStart = 0;
18
18
  var srcStringEnd = 0;
19
- var bundledStrings;
19
+ var bundledStrings$1;
20
20
  var referenceMap;
21
21
  var currentExtensions = [];
22
22
  var dataView;
@@ -30,6 +30,7 @@
30
30
  var sequentialMode = false;
31
31
  var inlineObjectReadThreshold = 2;
32
32
  var readStruct;
33
+ // no-eval build
33
34
  try {
34
35
  new Function('');
35
36
  } catch(error) {
@@ -56,6 +57,9 @@
56
57
  (options.structures = []).uninitialized = true; // this is what we use to denote an uninitialized structures
57
58
  options.structures.sharedLength = 0;
58
59
  }
60
+ if (options.int64AsNumber) {
61
+ options.int64AsType = 'number';
62
+ }
59
63
  }
60
64
  Object.assign(this, options);
61
65
  }
@@ -69,14 +73,14 @@
69
73
  }
70
74
  if (typeof options === 'object') {
71
75
  srcEnd = options.end || source.length;
72
- position = options.start || 0;
76
+ position$1 = options.start || 0;
73
77
  } else {
74
- position = 0;
78
+ position$1 = 0;
75
79
  srcEnd = options > -1 ? options : source.length;
76
80
  }
77
81
  srcStringEnd = 0;
78
82
  srcString = null;
79
- bundledStrings = null;
83
+ bundledStrings$1 = null;
80
84
  src = source;
81
85
  // this provides cached access to the data view for a buffer if it is getting reused, which is a recommend
82
86
  // technique for getting data from a database where it can be copied into an existing buffer instead of creating
@@ -113,8 +117,8 @@
113
117
  let value = this ? this.unpack(source, size) : defaultUnpackr.unpack(source, size);
114
118
  if (forEach) {
115
119
  forEach(value);
116
- while(position < size) {
117
- lastPosition = position;
120
+ while(position$1 < size) {
121
+ lastPosition = position$1;
118
122
  if (forEach(checkedRead()) === false) {
119
123
  return
120
124
  }
@@ -122,8 +126,8 @@
122
126
  }
123
127
  else {
124
128
  values = [ value ];
125
- while(position < size) {
126
- lastPosition = position;
129
+ while(position$1 < size) {
130
+ lastPosition = position$1;
127
131
  values.push(checkedRead());
128
132
  }
129
133
  return values
@@ -175,18 +179,20 @@
175
179
  currentStructures.length = sharedLength;
176
180
  }
177
181
  let result;
178
- if (currentUnpackr.randomAccessStructure && src[position] < 0x40 && src[position] >= 0x20 && readStruct) {
179
- result = readStruct(src, position, srcEnd, currentUnpackr);
182
+ if (currentUnpackr.randomAccessStructure && src[position$1] < 0x40 && src[position$1] >= 0x20 && readStruct) {
183
+ result = readStruct(src, position$1, srcEnd, currentUnpackr);
180
184
  src = null; // dispose of this so that recursive unpack calls don't save state
181
185
  if (!(options && options.lazy) && result)
182
186
  result = result.toJSON();
183
- position = srcEnd;
187
+ position$1 = srcEnd;
184
188
  } else
185
189
  result = read();
186
- if (bundledStrings) // bundled strings to skip past
187
- position = bundledStrings.postBundlePosition;
190
+ if (bundledStrings$1) { // bundled strings to skip past
191
+ position$1 = bundledStrings$1.postBundlePosition;
192
+ bundledStrings$1 = null;
193
+ }
188
194
 
189
- if (position == srcEnd) {
195
+ if (position$1 == srcEnd) {
190
196
  // finished reading this source, cleanup references
191
197
  if (currentStructures && currentStructures.restoreStructures)
192
198
  restoreStructures();
@@ -194,7 +200,7 @@
194
200
  src = null;
195
201
  if (referenceMap)
196
202
  referenceMap = null;
197
- } else if (position > srcEnd) {
203
+ } else if (position$1 > srcEnd) {
198
204
  // over read
199
205
  throw new Error('Unexpected end of MessagePack data')
200
206
  } else if (!sequentialMode) {
@@ -206,7 +212,7 @@
206
212
  if (currentStructures && currentStructures.restoreStructures)
207
213
  restoreStructures();
208
214
  clearSource();
209
- if (error instanceof RangeError || error.message.startsWith('Unexpected end of buffer') || position > srcEnd) {
215
+ if (error instanceof RangeError || error.message.startsWith('Unexpected end of buffer') || position$1 > srcEnd) {
210
216
  error.incomplete = true;
211
217
  }
212
218
  throw error
@@ -221,7 +227,7 @@
221
227
  }
222
228
 
223
229
  function read() {
224
- let token = src[position++];
230
+ let token = src[position$1++];
225
231
  if (token < 0xa0) {
226
232
  if (token < 0x80) {
227
233
  if (token < 0x40)
@@ -269,8 +275,8 @@
269
275
  } else if (token < 0xc0) {
270
276
  // fixstr
271
277
  let length = token - 0xa0;
272
- if (srcStringEnd >= position) {
273
- return srcString.slice(position - srcStringStart, (position += length) - srcStringStart)
278
+ if (srcStringEnd >= position$1) {
279
+ return srcString.slice(position$1 - srcStringStart, (position$1 += length) - srcStringStart)
274
280
  }
275
281
  if (srcStringEnd == 0 && srcEnd < 140) {
276
282
  // for small blocks, avoiding the overhead of the extract call is helpful
@@ -284,124 +290,128 @@
284
290
  switch (token) {
285
291
  case 0xc0: return null
286
292
  case 0xc1:
287
- if (bundledStrings) {
293
+ if (bundledStrings$1) {
288
294
  value = read(); // followed by the length of the string in characters (not bytes!)
289
295
  if (value > 0)
290
- return bundledStrings[1].slice(bundledStrings.position1, bundledStrings.position1 += value)
296
+ return bundledStrings$1[1].slice(bundledStrings$1.position1, bundledStrings$1.position1 += value)
291
297
  else
292
- return bundledStrings[0].slice(bundledStrings.position0, bundledStrings.position0 -= value)
298
+ return bundledStrings$1[0].slice(bundledStrings$1.position0, bundledStrings$1.position0 -= value)
293
299
  }
294
300
  return C1; // "never-used", return special object to denote that
295
301
  case 0xc2: return false
296
302
  case 0xc3: return true
297
303
  case 0xc4:
298
304
  // bin 8
299
- value = src[position++];
305
+ value = src[position$1++];
300
306
  if (value === undefined)
301
307
  throw new Error('Unexpected end of buffer')
302
308
  return readBin(value)
303
309
  case 0xc5:
304
310
  // bin 16
305
- value = dataView.getUint16(position);
306
- position += 2;
311
+ value = dataView.getUint16(position$1);
312
+ position$1 += 2;
307
313
  return readBin(value)
308
314
  case 0xc6:
309
315
  // bin 32
310
- value = dataView.getUint32(position);
311
- position += 4;
316
+ value = dataView.getUint32(position$1);
317
+ position$1 += 4;
312
318
  return readBin(value)
313
319
  case 0xc7:
314
320
  // ext 8
315
- return readExt(src[position++])
321
+ return readExt(src[position$1++])
316
322
  case 0xc8:
317
323
  // ext 16
318
- value = dataView.getUint16(position);
319
- position += 2;
324
+ value = dataView.getUint16(position$1);
325
+ position$1 += 2;
320
326
  return readExt(value)
321
327
  case 0xc9:
322
328
  // ext 32
323
- value = dataView.getUint32(position);
324
- position += 4;
329
+ value = dataView.getUint32(position$1);
330
+ position$1 += 4;
325
331
  return readExt(value)
326
332
  case 0xca:
327
- value = dataView.getFloat32(position);
333
+ value = dataView.getFloat32(position$1);
328
334
  if (currentUnpackr.useFloat32 > 2) {
329
335
  // this does rounding of numbers that were encoded in 32-bit float to nearest significant decimal digit that could be preserved
330
- let multiplier = mult10[((src[position] & 0x7f) << 1) | (src[position + 1] >> 7)];
331
- position += 4;
336
+ let multiplier = mult10[((src[position$1] & 0x7f) << 1) | (src[position$1 + 1] >> 7)];
337
+ position$1 += 4;
332
338
  return ((multiplier * value + (value > 0 ? 0.5 : -0.5)) >> 0) / multiplier
333
339
  }
334
- position += 4;
340
+ position$1 += 4;
335
341
  return value
336
342
  case 0xcb:
337
- value = dataView.getFloat64(position);
338
- position += 8;
343
+ value = dataView.getFloat64(position$1);
344
+ position$1 += 8;
339
345
  return value
340
346
  // uint handlers
341
347
  case 0xcc:
342
- return src[position++]
348
+ return src[position$1++]
343
349
  case 0xcd:
344
- value = dataView.getUint16(position);
345
- position += 2;
350
+ value = dataView.getUint16(position$1);
351
+ position$1 += 2;
346
352
  return value
347
353
  case 0xce:
348
- value = dataView.getUint32(position);
349
- position += 4;
354
+ value = dataView.getUint32(position$1);
355
+ position$1 += 4;
350
356
  return value
351
357
  case 0xcf:
352
- if (currentUnpackr.int64AsNumber) {
353
- value = dataView.getUint32(position) * 0x100000000;
354
- value += dataView.getUint32(position + 4);
358
+ if (currentUnpackr.int64AsType === 'number') {
359
+ value = dataView.getUint32(position$1) * 0x100000000;
360
+ value += dataView.getUint32(position$1 + 4);
361
+ } else if (currentUnpackr.int64AsType === 'string') {
362
+ value = dataView.getBigUint64(position$1).toString();
355
363
  } else
356
- value = dataView.getBigUint64(position);
357
- position += 8;
364
+ value = dataView.getBigUint64(position$1);
365
+ position$1 += 8;
358
366
  return value
359
367
 
360
368
  // int handlers
361
369
  case 0xd0:
362
- return dataView.getInt8(position++)
370
+ return dataView.getInt8(position$1++)
363
371
  case 0xd1:
364
- value = dataView.getInt16(position);
365
- position += 2;
372
+ value = dataView.getInt16(position$1);
373
+ position$1 += 2;
366
374
  return value
367
375
  case 0xd2:
368
- value = dataView.getInt32(position);
369
- position += 4;
376
+ value = dataView.getInt32(position$1);
377
+ position$1 += 4;
370
378
  return value
371
379
  case 0xd3:
372
- if (currentUnpackr.int64AsNumber) {
373
- value = dataView.getInt32(position) * 0x100000000;
374
- value += dataView.getUint32(position + 4);
380
+ if (currentUnpackr.int64AsType === 'number') {
381
+ value = dataView.getInt32(position$1) * 0x100000000;
382
+ value += dataView.getUint32(position$1 + 4);
383
+ } else if (currentUnpackr.int64AsType === 'string') {
384
+ value = dataView.getBigInt64(position$1).toString();
375
385
  } else
376
- value = dataView.getBigInt64(position);
377
- position += 8;
386
+ value = dataView.getBigInt64(position$1);
387
+ position$1 += 8;
378
388
  return value
379
389
 
380
390
  case 0xd4:
381
391
  // fixext 1
382
- value = src[position++];
392
+ value = src[position$1++];
383
393
  if (value == 0x72) {
384
- return recordDefinition(src[position++] & 0x3f)
394
+ return recordDefinition(src[position$1++] & 0x3f)
385
395
  } else {
386
396
  let extension = currentExtensions[value];
387
397
  if (extension) {
388
398
  if (extension.read) {
389
- position++; // skip filler byte
399
+ position$1++; // skip filler byte
390
400
  return extension.read(read())
391
401
  } else if (extension.noBuffer) {
392
- position++; // skip filler byte
402
+ position$1++; // skip filler byte
393
403
  return extension()
394
404
  } else
395
- return extension(src.subarray(position, ++position))
405
+ return extension(src.subarray(position$1, ++position$1))
396
406
  } else
397
407
  throw new Error('Unknown extension ' + value)
398
408
  }
399
409
  case 0xd5:
400
410
  // fixext 2
401
- value = src[position];
411
+ value = src[position$1];
402
412
  if (value == 0x72) {
403
- position++;
404
- return recordDefinition(src[position++] & 0x3f, src[position++])
413
+ position$1++;
414
+ return recordDefinition(src[position$1++] & 0x3f, src[position$1++])
405
415
  } else
406
416
  return readExt(2)
407
417
  case 0xd6:
@@ -415,46 +425,46 @@
415
425
  return readExt(16)
416
426
  case 0xd9:
417
427
  // str 8
418
- value = src[position++];
419
- if (srcStringEnd >= position) {
420
- return srcString.slice(position - srcStringStart, (position += value) - srcStringStart)
428
+ value = src[position$1++];
429
+ if (srcStringEnd >= position$1) {
430
+ return srcString.slice(position$1 - srcStringStart, (position$1 += value) - srcStringStart)
421
431
  }
422
432
  return readString8(value)
423
433
  case 0xda:
424
434
  // str 16
425
- value = dataView.getUint16(position);
426
- position += 2;
427
- if (srcStringEnd >= position) {
428
- return srcString.slice(position - srcStringStart, (position += value) - srcStringStart)
435
+ value = dataView.getUint16(position$1);
436
+ position$1 += 2;
437
+ if (srcStringEnd >= position$1) {
438
+ return srcString.slice(position$1 - srcStringStart, (position$1 += value) - srcStringStart)
429
439
  }
430
440
  return readString16(value)
431
441
  case 0xdb:
432
442
  // str 32
433
- value = dataView.getUint32(position);
434
- position += 4;
435
- if (srcStringEnd >= position) {
436
- return srcString.slice(position - srcStringStart, (position += value) - srcStringStart)
443
+ value = dataView.getUint32(position$1);
444
+ position$1 += 4;
445
+ if (srcStringEnd >= position$1) {
446
+ return srcString.slice(position$1 - srcStringStart, (position$1 += value) - srcStringStart)
437
447
  }
438
448
  return readString32(value)
439
449
  case 0xdc:
440
450
  // array 16
441
- value = dataView.getUint16(position);
442
- position += 2;
451
+ value = dataView.getUint16(position$1);
452
+ position$1 += 2;
443
453
  return readArray(value)
444
454
  case 0xdd:
445
455
  // array 32
446
- value = dataView.getUint32(position);
447
- position += 4;
456
+ value = dataView.getUint32(position$1);
457
+ position$1 += 4;
448
458
  return readArray(value)
449
459
  case 0xde:
450
460
  // map 16
451
- value = dataView.getUint16(position);
452
- position += 2;
461
+ value = dataView.getUint16(position$1);
462
+ position$1 += 2;
453
463
  return readMap(value)
454
464
  case 0xdf:
455
465
  // map 32
456
- value = dataView.getUint32(position);
457
- position += 4;
466
+ value = dataView.getUint32(position$1);
467
+ position$1 += 4;
458
468
  return readMap(value)
459
469
  default: // negative int
460
470
  if (token >= 0xe0)
@@ -500,7 +510,7 @@
500
510
 
501
511
  const createSecondByteReader = (firstId, read0) => {
502
512
  return function() {
503
- let highByte = src[position++];
513
+ let highByte = src[position$1++];
504
514
  if (highByte === 0)
505
515
  return read0()
506
516
  let id = firstId < 32 ? -(firstId + (highByte << 5)) : firstId + (highByte << 5);
@@ -535,29 +545,29 @@
535
545
  return result
536
546
  }
537
547
  if (length > 64 && decoder)
538
- return decoder.decode(src.subarray(position, position += length))
539
- const end = position + length;
548
+ return decoder.decode(src.subarray(position$1, position$1 += length))
549
+ const end = position$1 + length;
540
550
  const units = [];
541
551
  result = '';
542
- while (position < end) {
543
- const byte1 = src[position++];
552
+ while (position$1 < end) {
553
+ const byte1 = src[position$1++];
544
554
  if ((byte1 & 0x80) === 0) {
545
555
  // 1 byte
546
556
  units.push(byte1);
547
557
  } else if ((byte1 & 0xe0) === 0xc0) {
548
558
  // 2 bytes
549
- const byte2 = src[position++] & 0x3f;
559
+ const byte2 = src[position$1++] & 0x3f;
550
560
  units.push(((byte1 & 0x1f) << 6) | byte2);
551
561
  } else if ((byte1 & 0xf0) === 0xe0) {
552
562
  // 3 bytes
553
- const byte2 = src[position++] & 0x3f;
554
- const byte3 = src[position++] & 0x3f;
563
+ const byte2 = src[position$1++] & 0x3f;
564
+ const byte3 = src[position$1++] & 0x3f;
555
565
  units.push(((byte1 & 0x1f) << 12) | (byte2 << 6) | byte3);
556
566
  } else if ((byte1 & 0xf8) === 0xf0) {
557
567
  // 4 bytes
558
- const byte2 = src[position++] & 0x3f;
559
- const byte3 = src[position++] & 0x3f;
560
- const byte4 = src[position++] & 0x3f;
568
+ const byte2 = src[position$1++] & 0x3f;
569
+ const byte3 = src[position$1++] & 0x3f;
570
+ const byte4 = src[position$1++] & 0x3f;
561
571
  let unit = ((byte1 & 0x07) << 0x12) | (byte2 << 0x0c) | (byte3 << 0x06) | byte4;
562
572
  if (unit > 0xffff) {
563
573
  unit -= 0x10000;
@@ -613,12 +623,12 @@
613
623
 
614
624
  var fromCharCode = String.fromCharCode;
615
625
  function longStringInJS(length) {
616
- let start = position;
626
+ let start = position$1;
617
627
  let bytes = new Array(length);
618
628
  for (let i = 0; i < length; i++) {
619
- const byte = src[position++];
629
+ const byte = src[position$1++];
620
630
  if ((byte & 0x80) > 0) {
621
- position = start;
631
+ position$1 = start;
622
632
  return
623
633
  }
624
634
  bytes[i] = byte;
@@ -631,131 +641,131 @@
631
641
  if (length === 0)
632
642
  return ''
633
643
  else {
634
- let a = src[position++];
644
+ let a = src[position$1++];
635
645
  if ((a & 0x80) > 1) {
636
- position -= 1;
646
+ position$1 -= 1;
637
647
  return
638
648
  }
639
649
  return fromCharCode(a)
640
650
  }
641
651
  } else {
642
- let a = src[position++];
643
- let b = src[position++];
652
+ let a = src[position$1++];
653
+ let b = src[position$1++];
644
654
  if ((a & 0x80) > 0 || (b & 0x80) > 0) {
645
- position -= 2;
655
+ position$1 -= 2;
646
656
  return
647
657
  }
648
658
  if (length < 3)
649
659
  return fromCharCode(a, b)
650
- let c = src[position++];
660
+ let c = src[position$1++];
651
661
  if ((c & 0x80) > 0) {
652
- position -= 3;
662
+ position$1 -= 3;
653
663
  return
654
664
  }
655
665
  return fromCharCode(a, b, c)
656
666
  }
657
667
  } else {
658
- let a = src[position++];
659
- let b = src[position++];
660
- let c = src[position++];
661
- let d = src[position++];
668
+ let a = src[position$1++];
669
+ let b = src[position$1++];
670
+ let c = src[position$1++];
671
+ let d = src[position$1++];
662
672
  if ((a & 0x80) > 0 || (b & 0x80) > 0 || (c & 0x80) > 0 || (d & 0x80) > 0) {
663
- position -= 4;
673
+ position$1 -= 4;
664
674
  return
665
675
  }
666
676
  if (length < 6) {
667
677
  if (length === 4)
668
678
  return fromCharCode(a, b, c, d)
669
679
  else {
670
- let e = src[position++];
680
+ let e = src[position$1++];
671
681
  if ((e & 0x80) > 0) {
672
- position -= 5;
682
+ position$1 -= 5;
673
683
  return
674
684
  }
675
685
  return fromCharCode(a, b, c, d, e)
676
686
  }
677
687
  } else if (length < 8) {
678
- let e = src[position++];
679
- let f = src[position++];
688
+ let e = src[position$1++];
689
+ let f = src[position$1++];
680
690
  if ((e & 0x80) > 0 || (f & 0x80) > 0) {
681
- position -= 6;
691
+ position$1 -= 6;
682
692
  return
683
693
  }
684
694
  if (length < 7)
685
695
  return fromCharCode(a, b, c, d, e, f)
686
- let g = src[position++];
696
+ let g = src[position$1++];
687
697
  if ((g & 0x80) > 0) {
688
- position -= 7;
698
+ position$1 -= 7;
689
699
  return
690
700
  }
691
701
  return fromCharCode(a, b, c, d, e, f, g)
692
702
  } else {
693
- let e = src[position++];
694
- let f = src[position++];
695
- let g = src[position++];
696
- let h = src[position++];
703
+ let e = src[position$1++];
704
+ let f = src[position$1++];
705
+ let g = src[position$1++];
706
+ let h = src[position$1++];
697
707
  if ((e & 0x80) > 0 || (f & 0x80) > 0 || (g & 0x80) > 0 || (h & 0x80) > 0) {
698
- position -= 8;
708
+ position$1 -= 8;
699
709
  return
700
710
  }
701
711
  if (length < 10) {
702
712
  if (length === 8)
703
713
  return fromCharCode(a, b, c, d, e, f, g, h)
704
714
  else {
705
- let i = src[position++];
715
+ let i = src[position$1++];
706
716
  if ((i & 0x80) > 0) {
707
- position -= 9;
717
+ position$1 -= 9;
708
718
  return
709
719
  }
710
720
  return fromCharCode(a, b, c, d, e, f, g, h, i)
711
721
  }
712
722
  } else if (length < 12) {
713
- let i = src[position++];
714
- let j = src[position++];
723
+ let i = src[position$1++];
724
+ let j = src[position$1++];
715
725
  if ((i & 0x80) > 0 || (j & 0x80) > 0) {
716
- position -= 10;
726
+ position$1 -= 10;
717
727
  return
718
728
  }
719
729
  if (length < 11)
720
730
  return fromCharCode(a, b, c, d, e, f, g, h, i, j)
721
- let k = src[position++];
731
+ let k = src[position$1++];
722
732
  if ((k & 0x80) > 0) {
723
- position -= 11;
733
+ position$1 -= 11;
724
734
  return
725
735
  }
726
736
  return fromCharCode(a, b, c, d, e, f, g, h, i, j, k)
727
737
  } else {
728
- let i = src[position++];
729
- let j = src[position++];
730
- let k = src[position++];
731
- let l = src[position++];
738
+ let i = src[position$1++];
739
+ let j = src[position$1++];
740
+ let k = src[position$1++];
741
+ let l = src[position$1++];
732
742
  if ((i & 0x80) > 0 || (j & 0x80) > 0 || (k & 0x80) > 0 || (l & 0x80) > 0) {
733
- position -= 12;
743
+ position$1 -= 12;
734
744
  return
735
745
  }
736
746
  if (length < 14) {
737
747
  if (length === 12)
738
748
  return fromCharCode(a, b, c, d, e, f, g, h, i, j, k, l)
739
749
  else {
740
- let m = src[position++];
750
+ let m = src[position$1++];
741
751
  if ((m & 0x80) > 0) {
742
- position -= 13;
752
+ position$1 -= 13;
743
753
  return
744
754
  }
745
755
  return fromCharCode(a, b, c, d, e, f, g, h, i, j, k, l, m)
746
756
  }
747
757
  } else {
748
- let m = src[position++];
749
- let n = src[position++];
758
+ let m = src[position$1++];
759
+ let n = src[position$1++];
750
760
  if ((m & 0x80) > 0 || (n & 0x80) > 0) {
751
- position -= 14;
761
+ position$1 -= 14;
752
762
  return
753
763
  }
754
764
  if (length < 15)
755
765
  return fromCharCode(a, b, c, d, e, f, g, h, i, j, k, l, m, n)
756
- let o = src[position++];
766
+ let o = src[position$1++];
757
767
  if ((o & 0x80) > 0) {
758
- position -= 15;
768
+ position$1 -= 15;
759
769
  return
760
770
  }
761
771
  return fromCharCode(a, b, c, d, e, f, g, h, i, j, k, l, m, n, o)
@@ -766,7 +776,7 @@
766
776
  }
767
777
 
768
778
  function readOnlyJSString() {
769
- let token = src[position++];
779
+ let token = src[position$1++];
770
780
  let length;
771
781
  if (token < 0xc0) {
772
782
  // fixstr
@@ -775,17 +785,17 @@
775
785
  switch(token) {
776
786
  case 0xd9:
777
787
  // str 8
778
- length = src[position++];
788
+ length = src[position$1++];
779
789
  break
780
790
  case 0xda:
781
791
  // str 16
782
- length = dataView.getUint16(position);
783
- position += 2;
792
+ length = dataView.getUint16(position$1);
793
+ position$1 += 2;
784
794
  break
785
795
  case 0xdb:
786
796
  // str 32
787
- length = dataView.getUint32(position);
788
- position += 4;
797
+ length = dataView.getUint32(position$1);
798
+ position$1 += 4;
789
799
  break
790
800
  default:
791
801
  throw new Error('Expected string')
@@ -798,44 +808,44 @@
798
808
  function readBin(length) {
799
809
  return currentUnpackr.copyBuffers ?
800
810
  // specifically use the copying slice (not the node one)
801
- Uint8Array.prototype.slice.call(src, position, position += length) :
802
- src.subarray(position, position += length)
811
+ Uint8Array.prototype.slice.call(src, position$1, position$1 += length) :
812
+ src.subarray(position$1, position$1 += length)
803
813
  }
804
814
  function readExt(length) {
805
- let type = src[position++];
815
+ let type = src[position$1++];
806
816
  if (currentExtensions[type]) {
807
817
  let end;
808
- return currentExtensions[type](src.subarray(position, end = (position += length)), (readPosition) => {
809
- position = readPosition;
818
+ return currentExtensions[type](src.subarray(position$1, end = (position$1 += length)), (readPosition) => {
819
+ position$1 = readPosition;
810
820
  try {
811
821
  return read();
812
822
  } finally {
813
- position = end;
823
+ position$1 = end;
814
824
  }
815
825
  })
816
826
  }
817
827
  else
818
- throw new Error('Unknown extension type ' + type)``
828
+ throw new Error('Unknown extension type ' + type)
819
829
  }
820
830
 
821
831
  var keyCache = new Array(4096);
822
832
  function readKey() {
823
- let length = src[position++];
833
+ let length = src[position$1++];
824
834
  if (length >= 0xa0 && length < 0xc0) {
825
835
  // fixstr, potentially use key cache
826
836
  length = length - 0xa0;
827
- if (srcStringEnd >= position) // if it has been extracted, must use it (and faster anyway)
828
- return srcString.slice(position - srcStringStart, (position += length) - srcStringStart)
837
+ if (srcStringEnd >= position$1) // if it has been extracted, must use it (and faster anyway)
838
+ return srcString.slice(position$1 - srcStringStart, (position$1 += length) - srcStringStart)
829
839
  else if (!(srcStringEnd == 0 && srcEnd < 180))
830
840
  return readFixedString(length)
831
841
  } else { // not cacheable, go back and do a standard read
832
- position--;
842
+ position$1--;
833
843
  return read().toString()
834
844
  }
835
- let key = ((length << 5) ^ (length > 1 ? dataView.getUint16(position) : length > 0 ? src[position] : 0)) & 0xfff;
845
+ let key = ((length << 5) ^ (length > 1 ? dataView.getUint16(position$1) : length > 0 ? src[position$1] : 0)) & 0xfff;
836
846
  let entry = keyCache[key];
837
- let checkPosition = position;
838
- let end = position + length - 3;
847
+ let checkPosition = position$1;
848
+ let end = position$1 + length - 3;
839
849
  let chunk;
840
850
  let i = 0;
841
851
  if (entry && entry.bytes == length) {
@@ -856,11 +866,11 @@
856
866
  }
857
867
  }
858
868
  if (checkPosition === end) {
859
- position = checkPosition;
869
+ position$1 = checkPosition;
860
870
  return entry.string
861
871
  }
862
872
  end -= 3;
863
- checkPosition = position;
873
+ checkPosition = position$1;
864
874
  }
865
875
  entry = [];
866
876
  keyCache[key] = entry;
@@ -908,10 +918,10 @@
908
918
 
909
919
  currentExtensions[0x69] = (data) => {
910
920
  // id extension (for structured clones)
911
- let id = dataView.getUint32(position - 4);
921
+ let id = dataView.getUint32(position$1 - 4);
912
922
  if (!referenceMap)
913
923
  referenceMap = new Map();
914
- let token = src[position];
924
+ let token = src[position$1];
915
925
  let target;
916
926
  // TODO: handle Maps, Sets, and other types that can cycle; this is complicated, because you potentially need to read
917
927
  // ahead past references to record structure definitions
@@ -931,7 +941,7 @@
931
941
 
932
942
  currentExtensions[0x70] = (data) => {
933
943
  // pointer extension (for structured clones)
934
- let id = dataView.getUint32(position - 4);
944
+ let id = dataView.getUint32(position$1 - 4);
935
945
  let refEntry = referenceMap.get(id);
936
946
  refEntry.used = true;
937
947
  return refEntry.target
@@ -956,14 +966,14 @@
956
966
  const TEMP_BUNDLE = [];
957
967
  currentExtensions[0x62] = (data) => {
958
968
  let dataSize = (data[0] << 24) + (data[1] << 16) + (data[2] << 8) + data[3];
959
- let dataPosition = position;
960
- position += dataSize - data.length;
961
- bundledStrings = TEMP_BUNDLE;
962
- bundledStrings = [readOnlyJSString(), readOnlyJSString()];
963
- bundledStrings.position0 = 0;
964
- bundledStrings.position1 = 0;
965
- bundledStrings.postBundlePosition = position;
966
- position = dataPosition;
969
+ let dataPosition = position$1;
970
+ position$1 += dataSize - data.length;
971
+ bundledStrings$1 = TEMP_BUNDLE;
972
+ bundledStrings$1 = [readOnlyJSString(), readOnlyJSString()];
973
+ bundledStrings$1.position0 = 0;
974
+ bundledStrings$1.position1 = 0;
975
+ bundledStrings$1.postBundlePosition = position$1;
976
+ position$1 = dataPosition;
967
977
  return read()
968
978
  };
969
979
 
@@ -987,12 +997,12 @@
987
997
 
988
998
  function saveState(callback) {
989
999
  let savedSrcEnd = srcEnd;
990
- let savedPosition = position;
1000
+ let savedPosition = position$1;
991
1001
  let savedSrcStringStart = srcStringStart;
992
1002
  let savedSrcStringEnd = srcStringEnd;
993
1003
  let savedSrcString = srcString;
994
1004
  let savedReferenceMap = referenceMap;
995
- let savedBundledStrings = bundledStrings;
1005
+ let savedBundledStrings = bundledStrings$1;
996
1006
 
997
1007
  // TODO: We may need to revisit this if we do more external calls to user code (since it could be slow)
998
1008
  let savedSrc = new Uint8Array(src.slice(0, srcEnd)); // we copy the data in case it changes while external data is processed
@@ -1002,12 +1012,12 @@
1002
1012
  let savedSequentialMode = sequentialMode;
1003
1013
  let value = callback();
1004
1014
  srcEnd = savedSrcEnd;
1005
- position = savedPosition;
1015
+ position$1 = savedPosition;
1006
1016
  srcStringStart = savedSrcStringStart;
1007
1017
  srcStringEnd = savedSrcStringEnd;
1008
1018
  srcString = savedSrcString;
1009
1019
  referenceMap = savedReferenceMap;
1010
- bundledStrings = savedBundledStrings;
1020
+ bundledStrings$1 = savedBundledStrings;
1011
1021
  src = savedSrc;
1012
1022
  sequentialMode = savedSequentialMode;
1013
1023
  currentStructures = savedStructures;
@@ -1022,7 +1032,7 @@
1022
1032
  currentStructures = null;
1023
1033
  }
1024
1034
 
1025
- function addExtension(extension) {
1035
+ function addExtension$1(extension) {
1026
1036
  if (extension.unpack)
1027
1037
  currentExtensions[extension.type] = extension.unpack;
1028
1038
  else
@@ -1064,9 +1074,9 @@
1064
1074
  const MAX_BUFFER_SIZE = hasNodeBuffer ? 0x100000000 : 0x7fd00000;
1065
1075
  let target, keysTarget;
1066
1076
  let targetView;
1067
- let position$1 = 0;
1077
+ let position = 0;
1068
1078
  let safeEnd;
1069
- let bundledStrings$1 = null;
1079
+ let bundledStrings = null;
1070
1080
  let writeStructSlots;
1071
1081
  const MAX_BUNDLE_SIZE = 0xf000;
1072
1082
  const hasNonLatin = /[\u0080-\uFFFF]/;
@@ -1118,25 +1128,25 @@
1118
1128
  this.pack = this.encode = function(value, encodeOptions) {
1119
1129
  if (!target) {
1120
1130
  target = new ByteArrayAllocate(8192);
1121
- targetView = target.dataView = new DataView(target.buffer, 0, 8192);
1122
- position$1 = 0;
1131
+ targetView = target.dataView || (target.dataView = new DataView(target.buffer, 0, 8192));
1132
+ position = 0;
1123
1133
  }
1124
1134
  safeEnd = target.length - 10;
1125
- if (safeEnd - position$1 < 0x800) {
1135
+ if (safeEnd - position < 0x800) {
1126
1136
  // don't start too close to the end,
1127
1137
  target = new ByteArrayAllocate(target.length);
1128
- targetView = target.dataView = new DataView(target.buffer, 0, target.length);
1138
+ targetView = target.dataView || (target.dataView = new DataView(target.buffer, 0, target.length));
1129
1139
  safeEnd = target.length - 10;
1130
- position$1 = 0;
1140
+ position = 0;
1131
1141
  } else
1132
- position$1 = (position$1 + 7) & 0x7ffffff8; // Word align to make any future copying of this buffer faster
1133
- start = position$1;
1142
+ position = (position + 7) & 0x7ffffff8; // Word align to make any future copying of this buffer faster
1143
+ start = position;
1134
1144
  referenceMap = packr.structuredClone ? new Map() : null;
1135
1145
  if (packr.bundleStrings && typeof value !== 'string') {
1136
- bundledStrings$1 = [];
1137
- bundledStrings$1.size = Infinity; // force a new bundle start on first string
1146
+ bundledStrings = [];
1147
+ bundledStrings.size = Infinity; // force a new bundle start on first string
1138
1148
  } else
1139
- bundledStrings$1 = null;
1149
+ bundledStrings = null;
1140
1150
  structures = packr.structures;
1141
1151
  if (structures) {
1142
1152
  if (structures.uninitialized)
@@ -1177,8 +1187,8 @@
1177
1187
  writeStruct(value);
1178
1188
  else
1179
1189
  pack(value);
1180
- let lastBundle = bundledStrings$1;
1181
- if (bundledStrings$1)
1190
+ let lastBundle = bundledStrings;
1191
+ if (bundledStrings)
1182
1192
  writeBundles(start, pack, 0);
1183
1193
  if (referenceMap && referenceMap.idsToInsert) {
1184
1194
  let idsToInsert = referenceMap.idsToInsert.sort((a, b) => a.offset > b.offset ? 1 : -1);
@@ -1207,21 +1217,21 @@
1207
1217
  targetView.setUint32(lastBundle.position + start,
1208
1218
  targetView.getUint32(lastBundle.position + start) + incrementPosition);
1209
1219
  }
1210
- position$1 += idsToInsert.length * 6;
1211
- if (position$1 > safeEnd)
1212
- makeRoom(position$1);
1213
- packr.offset = position$1;
1214
- let serialized = insertIds(target.subarray(start, position$1), idsToInsert);
1220
+ position += idsToInsert.length * 6;
1221
+ if (position > safeEnd)
1222
+ makeRoom(position);
1223
+ packr.offset = position;
1224
+ let serialized = insertIds(target.subarray(start, position), idsToInsert);
1215
1225
  referenceMap = null;
1216
1226
  return serialized
1217
1227
  }
1218
- packr.offset = position$1; // update the offset so next serialization doesn't write over our buffer, but can continue writing to same buffer sequentially
1228
+ packr.offset = position; // update the offset so next serialization doesn't write over our buffer, but can continue writing to same buffer sequentially
1219
1229
  if (encodeOptions & REUSE_BUFFER_MODE) {
1220
1230
  target.start = start;
1221
- target.end = position$1;
1231
+ target.end = position;
1222
1232
  return target
1223
1233
  }
1224
- return target.subarray(start, position$1) // position can change if we call pack again in saveStructures, so we get the buffer now
1234
+ return target.subarray(start, position) // position can change if we call pack again in saveStructures, so we get the buffer now
1225
1235
  } finally {
1226
1236
  if (structures) {
1227
1237
  if (serializationsSinceTransitionRebuild < 10)
@@ -1244,7 +1254,7 @@
1244
1254
  }
1245
1255
  if (hasSharedUpdate && packr.saveStructures) {
1246
1256
  // we can't rely on start/end with REUSE_BUFFER_MODE since they will (probably) change when we save
1247
- let returnBuffer = target.subarray(start, position$1);
1257
+ let returnBuffer = target.subarray(start, position);
1248
1258
  let newSharedData = prepareStructures(structures, packr);
1249
1259
  if (packr.saveStructures(newSharedData, newSharedData.isCompatible) === false) {
1250
1260
  // get updated structures and try again if the update failed
@@ -1255,47 +1265,47 @@
1255
1265
  }
1256
1266
  }
1257
1267
  if (encodeOptions & RESET_BUFFER_MODE)
1258
- position$1 = start;
1268
+ position = start;
1259
1269
  }
1260
1270
  };
1261
1271
  const pack = (value) => {
1262
- if (position$1 > safeEnd)
1263
- target = makeRoom(position$1);
1272
+ if (position > safeEnd)
1273
+ target = makeRoom(position);
1264
1274
 
1265
1275
  var type = typeof value;
1266
1276
  var length;
1267
1277
  if (type === 'string') {
1268
1278
  let strLength = value.length;
1269
- if (bundledStrings$1 && strLength >= 4 && strLength < 0x1000) {
1270
- if ((bundledStrings$1.size += strLength) > MAX_BUNDLE_SIZE) {
1279
+ if (bundledStrings && strLength >= 4 && strLength < 0x1000) {
1280
+ if ((bundledStrings.size += strLength) > MAX_BUNDLE_SIZE) {
1271
1281
  let extStart;
1272
- let maxBytes = (bundledStrings$1[0] ? bundledStrings$1[0].length * 3 + bundledStrings$1[1].length : 0) + 10;
1273
- if (position$1 + maxBytes > safeEnd)
1274
- target = makeRoom(position$1 + maxBytes);
1282
+ let maxBytes = (bundledStrings[0] ? bundledStrings[0].length * 3 + bundledStrings[1].length : 0) + 10;
1283
+ if (position + maxBytes > safeEnd)
1284
+ target = makeRoom(position + maxBytes);
1275
1285
  let lastBundle;
1276
- 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
1277
- lastBundle = bundledStrings$1;
1278
- target[position$1] = 0xc8; // ext 16
1279
- position$1 += 3; // reserve for the writing bundle size
1280
- target[position$1++] = 0x62; // 'b'
1281
- extStart = position$1 - start;
1282
- position$1 += 4; // reserve for writing bundle reference
1286
+ if (bundledStrings.position) { // here we use the 0x62 extension to write the last bundle and reserve space for the reference pointer to the next/current bundle
1287
+ lastBundle = bundledStrings;
1288
+ target[position] = 0xc8; // ext 16
1289
+ position += 3; // reserve for the writing bundle size
1290
+ target[position++] = 0x62; // 'b'
1291
+ extStart = position - start;
1292
+ position += 4; // reserve for writing bundle reference
1283
1293
  writeBundles(start, pack, 0); // write the last bundles
1284
- targetView.setUint16(extStart + start - 3, position$1 - start - extStart);
1294
+ targetView.setUint16(extStart + start - 3, position - start - extStart);
1285
1295
  } 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)
1286
- target[position$1++] = 0xd6; // fixext 4
1287
- target[position$1++] = 0x62; // 'b'
1288
- extStart = position$1 - start;
1289
- position$1 += 4; // reserve for writing bundle reference
1296
+ target[position++] = 0xd6; // fixext 4
1297
+ target[position++] = 0x62; // 'b'
1298
+ extStart = position - start;
1299
+ position += 4; // reserve for writing bundle reference
1290
1300
  }
1291
- bundledStrings$1 = ['', '']; // create new ones
1292
- bundledStrings$1.previous = lastBundle;
1293
- bundledStrings$1.size = 0;
1294
- bundledStrings$1.position = extStart;
1301
+ bundledStrings = ['', '']; // create new ones
1302
+ bundledStrings.previous = lastBundle;
1303
+ bundledStrings.size = 0;
1304
+ bundledStrings.position = extStart;
1295
1305
  }
1296
1306
  let twoByte = hasNonLatin.test(value);
1297
- bundledStrings$1[twoByte ? 0 : 1] += value;
1298
- target[position$1++] = 0xc1;
1307
+ bundledStrings[twoByte ? 0 : 1] += value;
1308
+ target[position++] = 0xc1;
1299
1309
  pack(twoByte ? -strLength : strLength);
1300
1310
  return
1301
1311
  }
@@ -1311,11 +1321,11 @@
1311
1321
  headerSize = 5;
1312
1322
  }
1313
1323
  let maxBytes = strLength * 3;
1314
- if (position$1 + maxBytes > safeEnd)
1315
- target = makeRoom(position$1 + maxBytes);
1324
+ if (position + maxBytes > safeEnd)
1325
+ target = makeRoom(position + maxBytes);
1316
1326
 
1317
1327
  if (strLength < 0x40 || !encodeUtf8) {
1318
- let i, c1, c2, strPosition = position$1 + headerSize;
1328
+ let i, c1, c2, strPosition = position + headerSize;
1319
1329
  for (i = 0; i < strLength; i++) {
1320
1330
  c1 = value.charCodeAt(i);
1321
1331
  if (c1 < 0x80) {
@@ -1339,88 +1349,88 @@
1339
1349
  target[strPosition++] = c1 & 0x3f | 0x80;
1340
1350
  }
1341
1351
  }
1342
- length = strPosition - position$1 - headerSize;
1352
+ length = strPosition - position - headerSize;
1343
1353
  } else {
1344
- length = encodeUtf8(value, position$1 + headerSize);
1354
+ length = encodeUtf8(value, position + headerSize);
1345
1355
  }
1346
1356
 
1347
1357
  if (length < 0x20) {
1348
- target[position$1++] = 0xa0 | length;
1358
+ target[position++] = 0xa0 | length;
1349
1359
  } else if (length < 0x100) {
1350
1360
  if (headerSize < 2) {
1351
- target.copyWithin(position$1 + 2, position$1 + 1, position$1 + 1 + length);
1361
+ target.copyWithin(position + 2, position + 1, position + 1 + length);
1352
1362
  }
1353
- target[position$1++] = 0xd9;
1354
- target[position$1++] = length;
1363
+ target[position++] = 0xd9;
1364
+ target[position++] = length;
1355
1365
  } else if (length < 0x10000) {
1356
1366
  if (headerSize < 3) {
1357
- target.copyWithin(position$1 + 3, position$1 + 2, position$1 + 2 + length);
1367
+ target.copyWithin(position + 3, position + 2, position + 2 + length);
1358
1368
  }
1359
- target[position$1++] = 0xda;
1360
- target[position$1++] = length >> 8;
1361
- target[position$1++] = length & 0xff;
1369
+ target[position++] = 0xda;
1370
+ target[position++] = length >> 8;
1371
+ target[position++] = length & 0xff;
1362
1372
  } else {
1363
1373
  if (headerSize < 5) {
1364
- target.copyWithin(position$1 + 5, position$1 + 3, position$1 + 3 + length);
1374
+ target.copyWithin(position + 5, position + 3, position + 3 + length);
1365
1375
  }
1366
- target[position$1++] = 0xdb;
1367
- targetView.setUint32(position$1, length);
1368
- position$1 += 4;
1376
+ target[position++] = 0xdb;
1377
+ targetView.setUint32(position, length);
1378
+ position += 4;
1369
1379
  }
1370
- position$1 += length;
1380
+ position += length;
1371
1381
  } else if (type === 'number') {
1372
1382
  if (value >>> 0 === value) {// positive integer, 32-bit or less
1373
1383
  // positive uint
1374
1384
  if (value < 0x20 || (value < 0x80 && this.useRecords === false) || (value < 0x40 && !this.randomAccessStructure)) {
1375
- target[position$1++] = value;
1385
+ target[position++] = value;
1376
1386
  } else if (value < 0x100) {
1377
- target[position$1++] = 0xcc;
1378
- target[position$1++] = value;
1387
+ target[position++] = 0xcc;
1388
+ target[position++] = value;
1379
1389
  } else if (value < 0x10000) {
1380
- target[position$1++] = 0xcd;
1381
- target[position$1++] = value >> 8;
1382
- target[position$1++] = value & 0xff;
1390
+ target[position++] = 0xcd;
1391
+ target[position++] = value >> 8;
1392
+ target[position++] = value & 0xff;
1383
1393
  } else {
1384
- target[position$1++] = 0xce;
1385
- targetView.setUint32(position$1, value);
1386
- position$1 += 4;
1394
+ target[position++] = 0xce;
1395
+ targetView.setUint32(position, value);
1396
+ position += 4;
1387
1397
  }
1388
1398
  } else if (value >> 0 === value) { // negative integer
1389
1399
  if (value >= -0x20) {
1390
- target[position$1++] = 0x100 + value;
1400
+ target[position++] = 0x100 + value;
1391
1401
  } else if (value >= -0x80) {
1392
- target[position$1++] = 0xd0;
1393
- target[position$1++] = value + 0x100;
1402
+ target[position++] = 0xd0;
1403
+ target[position++] = value + 0x100;
1394
1404
  } else if (value >= -0x8000) {
1395
- target[position$1++] = 0xd1;
1396
- targetView.setInt16(position$1, value);
1397
- position$1 += 2;
1405
+ target[position++] = 0xd1;
1406
+ targetView.setInt16(position, value);
1407
+ position += 2;
1398
1408
  } else {
1399
- target[position$1++] = 0xd2;
1400
- targetView.setInt32(position$1, value);
1401
- position$1 += 4;
1409
+ target[position++] = 0xd2;
1410
+ targetView.setInt32(position, value);
1411
+ position += 4;
1402
1412
  }
1403
1413
  } else {
1404
1414
  let useFloat32;
1405
1415
  if ((useFloat32 = this.useFloat32) > 0 && value < 0x100000000 && value >= -0x80000000) {
1406
- target[position$1++] = 0xca;
1407
- targetView.setFloat32(position$1, value);
1416
+ target[position++] = 0xca;
1417
+ targetView.setFloat32(position, value);
1408
1418
  let xShifted;
1409
1419
  if (useFloat32 < 4 ||
1410
1420
  // this checks for rounding of numbers that were encoded in 32-bit float to nearest significant decimal digit that could be preserved
1411
- ((xShifted = value * mult10[((target[position$1] & 0x7f) << 1) | (target[position$1 + 1] >> 7)]) >> 0) === xShifted) {
1412
- position$1 += 4;
1421
+ ((xShifted = value * mult10[((target[position] & 0x7f) << 1) | (target[position + 1] >> 7)]) >> 0) === xShifted) {
1422
+ position += 4;
1413
1423
  return
1414
1424
  } else
1415
- position$1--; // move back into position for writing a double
1425
+ position--; // move back into position for writing a double
1416
1426
  }
1417
- target[position$1++] = 0xcb;
1418
- targetView.setFloat64(position$1, value);
1419
- position$1 += 8;
1427
+ target[position++] = 0xcb;
1428
+ targetView.setFloat64(position, value);
1429
+ position += 8;
1420
1430
  }
1421
1431
  } else if (type === 'object') {
1422
1432
  if (!value)
1423
- target[position$1++] = 0xc0;
1433
+ target[position++] = 0xc0;
1424
1434
  else {
1425
1435
  if (referenceMap) {
1426
1436
  let referee = referenceMap.get(value);
@@ -1429,29 +1439,29 @@
1429
1439
  let idsToInsert = referenceMap.idsToInsert || (referenceMap.idsToInsert = []);
1430
1440
  referee.id = idsToInsert.push(referee);
1431
1441
  }
1432
- target[position$1++] = 0xd6; // fixext 4
1433
- target[position$1++] = 0x70; // "p" for pointer
1434
- targetView.setUint32(position$1, referee.id);
1435
- position$1 += 4;
1442
+ target[position++] = 0xd6; // fixext 4
1443
+ target[position++] = 0x70; // "p" for pointer
1444
+ targetView.setUint32(position, referee.id);
1445
+ position += 4;
1436
1446
  return
1437
1447
  } else
1438
- referenceMap.set(value, { offset: position$1 - start });
1448
+ referenceMap.set(value, { offset: position - start });
1439
1449
  }
1440
1450
  let constructor = value.constructor;
1441
1451
  if (constructor === Object) {
1442
1452
  writeObject(value, true);
1443
- } else if (constructor === Array) {
1453
+ } else if (constructor === Array || Array.isArray(value)) {
1444
1454
  length = value.length;
1445
1455
  if (length < 0x10) {
1446
- target[position$1++] = 0x90 | length;
1456
+ target[position++] = 0x90 | length;
1447
1457
  } else if (length < 0x10000) {
1448
- target[position$1++] = 0xdc;
1449
- target[position$1++] = length >> 8;
1450
- target[position$1++] = length & 0xff;
1458
+ target[position++] = 0xdc;
1459
+ target[position++] = length >> 8;
1460
+ target[position++] = length & 0xff;
1451
1461
  } else {
1452
- target[position$1++] = 0xdd;
1453
- targetView.setUint32(position$1, length);
1454
- position$1 += 4;
1462
+ target[position++] = 0xdd;
1463
+ targetView.setUint32(position, length);
1464
+ position += 4;
1455
1465
  }
1456
1466
  for (let i = 0; i < length; i++) {
1457
1467
  pack(value[i]);
@@ -1459,15 +1469,15 @@
1459
1469
  } else if (constructor === Map) {
1460
1470
  length = value.size;
1461
1471
  if (length < 0x10) {
1462
- target[position$1++] = 0x80 | length;
1472
+ target[position++] = 0x80 | length;
1463
1473
  } else if (length < 0x10000) {
1464
- target[position$1++] = 0xde;
1465
- target[position$1++] = length >> 8;
1466
- target[position$1++] = length & 0xff;
1474
+ target[position++] = 0xde;
1475
+ target[position++] = length >> 8;
1476
+ target[position++] = length & 0xff;
1467
1477
  } else {
1468
- target[position$1++] = 0xdf;
1469
- targetView.setUint32(position$1, length);
1470
- position$1 += 4;
1478
+ target[position++] = 0xdf;
1479
+ targetView.setUint32(position, length);
1480
+ position += 4;
1471
1481
  }
1472
1482
  for (let [ key, entryValue ] of value) {
1473
1483
  pack(key);
@@ -1480,16 +1490,16 @@
1480
1490
  let extension = extensions[i];
1481
1491
  if (extension.write) {
1482
1492
  if (extension.type) {
1483
- target[position$1++] = 0xd4; // one byte "tag" extension
1484
- target[position$1++] = extension.type;
1485
- target[position$1++] = 0;
1493
+ target[position++] = 0xd4; // one byte "tag" extension
1494
+ target[position++] = extension.type;
1495
+ target[position++] = 0;
1486
1496
  }
1487
1497
  pack(extension.write.call(this, value));
1488
1498
  return
1489
1499
  }
1490
1500
  let currentTarget = target;
1491
1501
  let currentTargetView = targetView;
1492
- let currentPosition = position$1;
1502
+ let currentPosition = position;
1493
1503
  target = null;
1494
1504
  let result;
1495
1505
  try {
@@ -1497,11 +1507,11 @@
1497
1507
  // restore target and use it
1498
1508
  target = currentTarget;
1499
1509
  currentTarget = null;
1500
- position$1 += size;
1501
- if (position$1 > safeEnd)
1502
- makeRoom(position$1);
1510
+ position += size;
1511
+ if (position > safeEnd)
1512
+ makeRoom(position);
1503
1513
  return {
1504
- target, targetView, position: position$1 - size
1514
+ target, targetView, position: position - size
1505
1515
  }
1506
1516
  }, pack);
1507
1517
  } finally {
@@ -1509,14 +1519,14 @@
1509
1519
  if (currentTarget) {
1510
1520
  target = currentTarget;
1511
1521
  targetView = currentTargetView;
1512
- position$1 = currentPosition;
1522
+ position = currentPosition;
1513
1523
  safeEnd = target.length - 10;
1514
1524
  }
1515
1525
  }
1516
1526
  if (result) {
1517
- if (result.length + position$1 > safeEnd)
1518
- makeRoom(result.length + position$1);
1519
- position$1 = writeExtensionData(result, target, position$1, extension.type);
1527
+ if (result.length + position > safeEnd)
1528
+ makeRoom(result.length + position);
1529
+ position = writeExtensionData(result, target, position, extension.type);
1520
1530
  }
1521
1531
  return
1522
1532
  }
@@ -1526,33 +1536,33 @@
1526
1536
  }
1527
1537
  }
1528
1538
  } else if (type === 'boolean') {
1529
- target[position$1++] = value ? 0xc3 : 0xc2;
1539
+ target[position++] = value ? 0xc3 : 0xc2;
1530
1540
  } else if (type === 'bigint') {
1531
1541
  if (value < (BigInt(1)<<BigInt(63)) && value >= -(BigInt(1)<<BigInt(63))) {
1532
1542
  // use a signed int as long as it fits
1533
- target[position$1++] = 0xd3;
1534
- targetView.setBigInt64(position$1, value);
1543
+ target[position++] = 0xd3;
1544
+ targetView.setBigInt64(position, value);
1535
1545
  } else if (value < (BigInt(1)<<BigInt(64)) && value > 0) {
1536
1546
  // if we can fit an unsigned int, use that
1537
- target[position$1++] = 0xcf;
1538
- targetView.setBigUint64(position$1, value);
1547
+ target[position++] = 0xcf;
1548
+ targetView.setBigUint64(position, value);
1539
1549
  } else {
1540
1550
  // overflow
1541
1551
  if (this.largeBigIntToFloat) {
1542
- target[position$1++] = 0xcb;
1543
- targetView.setFloat64(position$1, Number(value));
1552
+ target[position++] = 0xcb;
1553
+ targetView.setFloat64(position, Number(value));
1544
1554
  } else {
1545
1555
  throw new RangeError(value + ' was too large to fit in MessagePack 64-bit integer format, set largeBigIntToFloat to convert to float-64')
1546
1556
  }
1547
1557
  }
1548
- position$1 += 8;
1558
+ position += 8;
1549
1559
  } else if (type === 'undefined') {
1550
1560
  if (this.encodeUndefinedAsNil)
1551
- target[position$1++] = 0xc0;
1561
+ target[position++] = 0xc0;
1552
1562
  else {
1553
- target[position$1++] = 0xd4; // a number of implementations use fixext1 with type 0, data 0 to denote undefined, so we follow suite
1554
- target[position$1++] = 0;
1555
- target[position$1++] = 0;
1563
+ target[position++] = 0xd4; // a number of implementations use fixext1 with type 0, data 0 to denote undefined, so we follow suite
1564
+ target[position++] = 0;
1565
+ target[position++] = 0;
1556
1566
  }
1557
1567
  } else if (type === 'function') {
1558
1568
  pack(this.writeFunction && this.writeFunction()); // if there is a writeFunction, use it, otherwise just encode as undefined
@@ -1566,15 +1576,15 @@
1566
1576
  let keys = Object.keys(object);
1567
1577
  let length = keys.length;
1568
1578
  if (length < 0x10) {
1569
- target[position$1++] = 0x80 | length;
1579
+ target[position++] = 0x80 | length;
1570
1580
  } else if (length < 0x10000) {
1571
- target[position$1++] = 0xde;
1572
- target[position$1++] = length >> 8;
1573
- target[position$1++] = length & 0xff;
1581
+ target[position++] = 0xde;
1582
+ target[position++] = length >> 8;
1583
+ target[position++] = length & 0xff;
1574
1584
  } else {
1575
- target[position$1++] = 0xdf;
1576
- targetView.setUint32(position$1, length);
1577
- position$1 += 4;
1585
+ target[position++] = 0xdf;
1586
+ targetView.setUint32(position, length);
1587
+ position += 4;
1578
1588
  }
1579
1589
  let key;
1580
1590
  for (let i = 0; i < length; i++) {
@@ -1583,9 +1593,9 @@
1583
1593
  }
1584
1594
  } :
1585
1595
  (object, safePrototype) => {
1586
- target[position$1++] = 0xde; // always using map 16, so we can preallocate and set the length afterwards
1587
- let objectOffset = position$1 - start;
1588
- position$1 += 2;
1596
+ target[position++] = 0xde; // always using map 16, so we can preallocate and set the length afterwards
1597
+ let objectOffset = position - start;
1598
+ position += 2;
1589
1599
  let size = 0;
1590
1600
  for (let key in object) {
1591
1601
  if (safePrototype || object.hasOwnProperty(key)) {
@@ -1600,7 +1610,7 @@
1600
1610
  (options.progressiveRecords && !useTwoByteRecords) ? // this is about 2% faster for highly stable structures, since it only requires one for-in loop (but much more expensive when new structure needs to be written)
1601
1611
  (object, safePrototype) => {
1602
1612
  let nextTransition, transition = structures.transitions || (structures.transitions = Object.create(null));
1603
- let objectOffset = position$1++ - start;
1613
+ let objectOffset = position++ - start;
1604
1614
  let wroteKeys;
1605
1615
  for (let key in object) {
1606
1616
  if (safePrototype || object.hasOwnProperty(key)) {
@@ -1622,9 +1632,9 @@
1622
1632
  }
1623
1633
  transition = nextTransition;
1624
1634
  }
1625
- if (objectOffset + start + 1 == position$1) {
1635
+ if (objectOffset + start + 1 == position) {
1626
1636
  // first key, so we don't need to insert, we can just write record directly
1627
- position$1--;
1637
+ position--;
1628
1638
  newRecord(transition, keys, newTransitions);
1629
1639
  } else // otherwise we need to insert the record, moving existing data after the record
1630
1640
  insertNewRecord(transition, keys, objectOffset, newTransitions);
@@ -1656,10 +1666,10 @@
1656
1666
  let recordId = transition[RECORD_SYMBOL];
1657
1667
  if (recordId) {
1658
1668
  if (recordId >= 0x60 && useTwoByteRecords) {
1659
- target[position$1++] = ((recordId -= 0x60) & 0x1f) + 0x60;
1660
- target[position$1++] = recordId >> 5;
1669
+ target[position++] = ((recordId -= 0x60) & 0x1f) + 0x60;
1670
+ target[position++] = recordId >> 5;
1661
1671
  } else
1662
- target[position$1++] = recordId;
1672
+ target[position++] = recordId;
1663
1673
  } else {
1664
1674
  newRecord(transition, transition.__keys__ || Object.keys(object), newTransitions);
1665
1675
  }
@@ -1679,13 +1689,13 @@
1679
1689
  } else // faster handling for smaller buffers
1680
1690
  newSize = ((Math.max((end - start) << 2, target.length - 1) >> 12) + 1) << 12;
1681
1691
  let newBuffer = new ByteArrayAllocate(newSize);
1682
- targetView = newBuffer.dataView = new DataView(newBuffer.buffer, 0, newSize);
1692
+ targetView = newBuffer.dataView || (newBuffer.dataView = new DataView(newBuffer.buffer, 0, newSize));
1683
1693
  end = Math.min(end, target.length);
1684
1694
  if (target.copy)
1685
1695
  target.copy(newBuffer, 0, start, end);
1686
1696
  else
1687
1697
  newBuffer.set(target.slice(start, end));
1688
- position$1 -= start;
1698
+ position -= start;
1689
1699
  start = 0;
1690
1700
  safeEnd = newBuffer.length - 10;
1691
1701
  return target = newBuffer
@@ -1714,21 +1724,21 @@
1714
1724
  structures.sharedLength = recordId - 0x3f;
1715
1725
  hasSharedUpdate = true;
1716
1726
  if (highByte >= 0) {
1717
- target[position$1++] = (recordId & 0x1f) + 0x60;
1718
- target[position$1++] = highByte;
1727
+ target[position++] = (recordId & 0x1f) + 0x60;
1728
+ target[position++] = highByte;
1719
1729
  } else {
1720
- target[position$1++] = recordId;
1730
+ target[position++] = recordId;
1721
1731
  }
1722
1732
  } else {
1723
1733
  if (highByte >= 0) {
1724
- target[position$1++] = 0xd5; // fixext 2
1725
- target[position$1++] = 0x72; // "r" record defintion extension type
1726
- target[position$1++] = (recordId & 0x1f) + 0x60;
1727
- target[position$1++] = highByte;
1734
+ target[position++] = 0xd5; // fixext 2
1735
+ target[position++] = 0x72; // "r" record defintion extension type
1736
+ target[position++] = (recordId & 0x1f) + 0x60;
1737
+ target[position++] = highByte;
1728
1738
  } else {
1729
- target[position$1++] = 0xd4; // fixext 1
1730
- target[position$1++] = 0x72; // "r" record defintion extension type
1731
- target[position$1++] = recordId;
1739
+ target[position++] = 0xd4; // fixext 1
1740
+ target[position++] = 0x72; // "r" record defintion extension type
1741
+ target[position++] = recordId;
1732
1742
  }
1733
1743
 
1734
1744
  if (newTransitions)
@@ -1742,46 +1752,57 @@
1742
1752
  };
1743
1753
  const insertNewRecord = (transition, keys, insertionOffset, newTransitions) => {
1744
1754
  let mainTarget = target;
1745
- let mainPosition = position$1;
1755
+ let mainPosition = position;
1746
1756
  let mainSafeEnd = safeEnd;
1747
1757
  let mainStart = start;
1748
1758
  target = keysTarget;
1749
- position$1 = 0;
1759
+ position = 0;
1750
1760
  start = 0;
1751
1761
  if (!target)
1752
1762
  keysTarget = target = new ByteArrayAllocate(8192);
1753
1763
  safeEnd = target.length - 10;
1754
1764
  newRecord(transition, keys, newTransitions);
1755
1765
  keysTarget = target;
1756
- let keysPosition = position$1;
1766
+ let keysPosition = position;
1757
1767
  target = mainTarget;
1758
- position$1 = mainPosition;
1768
+ position = mainPosition;
1759
1769
  safeEnd = mainSafeEnd;
1760
1770
  start = mainStart;
1761
1771
  if (keysPosition > 1) {
1762
- let newEnd = position$1 + keysPosition - 1;
1772
+ let newEnd = position + keysPosition - 1;
1763
1773
  if (newEnd > safeEnd)
1764
1774
  makeRoom(newEnd);
1765
1775
  let insertionPosition = insertionOffset + start;
1766
- target.copyWithin(insertionPosition + keysPosition, insertionPosition + 1, position$1);
1776
+ target.copyWithin(insertionPosition + keysPosition, insertionPosition + 1, position);
1767
1777
  target.set(keysTarget.slice(0, keysPosition), insertionPosition);
1768
- position$1 = newEnd;
1778
+ position = newEnd;
1769
1779
  } else {
1770
1780
  target[insertionOffset + start] = keysTarget[0];
1771
1781
  }
1772
1782
  };
1773
1783
  const writeStruct = (object, safePrototype) => {
1774
- let newPosition = writeStructSlots();
1784
+ let newPosition = writeStructSlots(object, target, position, structures, makeRoom, (value, newPosition, notifySharedUpdate) => {
1785
+ if (notifySharedUpdate)
1786
+ return hasSharedUpdate = true;
1787
+ position = newPosition;
1788
+ if (start > 0) {
1789
+ pack(value);
1790
+ if (start == 0)
1791
+ return { position, targetView, target }; // indicate the buffer was re-allocated
1792
+ } else
1793
+ pack(value);
1794
+ return position;
1795
+ }, this);
1775
1796
  if (newPosition === 0) // bail and go to a msgpack object
1776
1797
  return writeObject(object, true);
1777
- position$1 = newPosition;
1798
+ position = newPosition;
1778
1799
  };
1779
1800
  }
1780
1801
  useBuffer(buffer) {
1781
1802
  // this means we are finished using our own buffer and we can write over it safely
1782
1803
  target = buffer;
1783
1804
  targetView = new DataView(target.buffer, target.byteOffset, target.byteLength);
1784
- position$1 = 0;
1805
+ position = 0;
1785
1806
  }
1786
1807
  clearSharedData() {
1787
1808
  if (this.structures)
@@ -1986,17 +2007,17 @@
1986
2007
  }
1987
2008
 
1988
2009
  function writeBundles(start, pack, incrementPosition) {
1989
- if (bundledStrings$1.length > 0) {
1990
- targetView.setUint32(bundledStrings$1.position + start, position$1 + incrementPosition - bundledStrings$1.position - start);
1991
- bundledStrings$1.stringsPosition = position$1 - start;
1992
- let writeStrings = bundledStrings$1;
1993
- bundledStrings$1 = null;
2010
+ if (bundledStrings.length > 0) {
2011
+ targetView.setUint32(bundledStrings.position + start, position + incrementPosition - bundledStrings.position - start);
2012
+ bundledStrings.stringsPosition = position - start;
2013
+ let writeStrings = bundledStrings;
2014
+ bundledStrings = null;
1994
2015
  pack(writeStrings[0]);
1995
2016
  pack(writeStrings[1]);
1996
2017
  }
1997
2018
  }
1998
2019
 
1999
- function addExtension$1(extension) {
2020
+ function addExtension(extension) {
2000
2021
  if (extension.Class) {
2001
2022
  if (!extension.pack && !extension.write)
2002
2023
  throw new Error('Extension has no pack or write function')
@@ -2005,7 +2026,7 @@
2005
2026
  extensionClasses.unshift(extension.Class);
2006
2027
  extensions.unshift(extension);
2007
2028
  }
2008
- addExtension(extension);
2029
+ addExtension$1(extension);
2009
2030
  }
2010
2031
  function prepareStructures(structures, packr) {
2011
2032
  structures.isCompatible = (existingStructures) => {
@@ -2124,7 +2145,7 @@
2124
2145
  exports.Packr = Packr;
2125
2146
  exports.REUSE_BUFFER_MODE = REUSE_BUFFER_MODE;
2126
2147
  exports.Unpackr = Unpackr;
2127
- exports.addExtension = addExtension$1;
2148
+ exports.addExtension = addExtension;
2128
2149
  exports.clearSource = clearSource;
2129
2150
  exports.decode = decode;
2130
2151
  exports.decodeIter = decodeIter;
@@ -2138,7 +2159,5 @@
2138
2159
  exports.unpackMultiple = unpackMultiple;
2139
2160
  exports.useRecords = useRecords;
2140
2161
 
2141
- Object.defineProperty(exports, '__esModule', { value: true });
2142
-
2143
- })));
2162
+ }));
2144
2163
  //# sourceMappingURL=index.js.map