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/test.js CHANGED
@@ -1,22 +1,22 @@
1
- (function (msgpackr, chai, inspector, fs) {
1
+ (function (chai, stream, module, fs) {
2
2
  'use strict';
3
3
 
4
- chai = chai && Object.prototype.hasOwnProperty.call(chai, 'default') ? chai['default'] : chai;
5
- inspector = inspector && Object.prototype.hasOwnProperty.call(inspector, 'default') ? inspector['default'] : inspector;
6
-
7
4
  var decoder;
8
5
  try {
9
6
  decoder = new TextDecoder();
10
7
  } catch(error) {}
11
8
  var src;
12
9
  var srcEnd;
13
- var position = 0;
10
+ var position$1 = 0;
11
+ const EMPTY_ARRAY = [];
12
+ var strings = EMPTY_ARRAY;
13
+ var stringPosition = 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;
@@ -29,7 +29,8 @@
29
29
  C1.name = 'MessagePack 0xC1';
30
30
  var sequentialMode = false;
31
31
  var inlineObjectReadThreshold = 2;
32
- var readStruct, onLoadedStructures, onSaveState;
32
+ var readStruct$1, onLoadedStructures$1, onSaveState;
33
+ // no-eval build
33
34
  try {
34
35
  new Function('');
35
36
  } catch(error) {
@@ -37,7 +38,7 @@
37
38
  inlineObjectReadThreshold = Infinity;
38
39
  }
39
40
 
40
- class Unpackr {
41
+ let Unpackr$1 = class Unpackr {
41
42
  constructor(options) {
42
43
  if (options) {
43
44
  if (options.useRecords === false && options.mapsAsObjects === undefined)
@@ -56,27 +57,32 @@
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
  }
62
66
  unpack(source, options) {
63
67
  if (src) {
64
68
  // re-entrant execution, save the state and restore it after we do this unpack
65
- return saveState(() => {
69
+ return saveState$1(() => {
66
70
  clearSource();
67
- return this ? this.unpack(source, options) : Unpackr.prototype.unpack.call(defaultOptions, source, options)
71
+ return this ? this.unpack(source, options) : Unpackr$1.prototype.unpack.call(defaultOptions, source, options)
68
72
  })
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
  }
81
+ stringPosition = 0;
77
82
  srcStringEnd = 0;
78
83
  srcString = null;
79
- bundledStrings = null;
84
+ strings = EMPTY_ARRAY;
85
+ bundledStrings$1 = null;
80
86
  src = source;
81
87
  // this provides cached access to the data view for a buffer if it is getting reused, which is a recommend
82
88
  // technique for getting data from a database where it can be copied into an existing buffer instead of creating
@@ -90,7 +96,7 @@
90
96
  throw error
91
97
  throw new Error('Source must be a Uint8Array or Buffer but was a ' + ((source && typeof source == 'object') ? source.constructor.name : typeof source))
92
98
  }
93
- if (this instanceof Unpackr) {
99
+ if (this instanceof Unpackr$1) {
94
100
  currentUnpackr = this;
95
101
  if (this.structures) {
96
102
  currentStructures = this.structures;
@@ -113,8 +119,8 @@
113
119
  let value = this ? this.unpack(source, size) : defaultUnpackr.unpack(source, size);
114
120
  if (forEach) {
115
121
  forEach(value);
116
- while(position < size) {
117
- lastPosition = position;
122
+ while(position$1 < size) {
123
+ lastPosition = position$1;
118
124
  if (forEach(checkedRead()) === false) {
119
125
  return
120
126
  }
@@ -122,8 +128,8 @@
122
128
  }
123
129
  else {
124
130
  values = [ value ];
125
- while(position < size) {
126
- lastPosition = position;
131
+ while(position$1 < size) {
132
+ lastPosition = position$1;
127
133
  values.push(checkedRead());
128
134
  }
129
135
  return values
@@ -138,8 +144,8 @@
138
144
  }
139
145
  }
140
146
  _mergeStructures(loadedStructures, existingStructures) {
141
- if (onLoadedStructures)
142
- loadedStructures = onLoadedStructures.call(this, loadedStructures);
147
+ if (onLoadedStructures$1)
148
+ loadedStructures = onLoadedStructures$1.call(this, loadedStructures);
143
149
  loadedStructures = loadedStructures || [];
144
150
  if (Object.isFrozen(loadedStructures))
145
151
  loadedStructures = loadedStructures.map(structure => structure.slice(0));
@@ -168,7 +174,7 @@
168
174
  decode(source, end) {
169
175
  return this.unpack(source, end)
170
176
  }
171
- }
177
+ };
172
178
  function checkedRead(options) {
173
179
  try {
174
180
  if (!currentUnpackr.trusted && !sequentialMode) {
@@ -177,18 +183,20 @@
177
183
  currentStructures.length = sharedLength;
178
184
  }
179
185
  let result;
180
- if (currentUnpackr.randomAccessStructure && src[position] < 0x40 && src[position] >= 0x20 && readStruct) {
181
- result = readStruct(src, position, srcEnd, currentUnpackr);
186
+ if (currentUnpackr.randomAccessStructure && src[position$1] < 0x40 && src[position$1] >= 0x20 && readStruct$1) {
187
+ result = readStruct$1(src, position$1, srcEnd, currentUnpackr);
182
188
  src = null; // dispose of this so that recursive unpack calls don't save state
183
189
  if (!(options && options.lazy) && result)
184
190
  result = result.toJSON();
185
- position = srcEnd;
191
+ position$1 = srcEnd;
186
192
  } else
187
193
  result = read();
188
- if (bundledStrings) // bundled strings to skip past
189
- position = bundledStrings.postBundlePosition;
194
+ if (bundledStrings$1) { // bundled strings to skip past
195
+ position$1 = bundledStrings$1.postBundlePosition;
196
+ bundledStrings$1 = null;
197
+ }
190
198
 
191
- if (position == srcEnd) {
199
+ if (position$1 == srcEnd) {
192
200
  // finished reading this source, cleanup references
193
201
  if (currentStructures && currentStructures.restoreStructures)
194
202
  restoreStructures();
@@ -196,7 +204,7 @@
196
204
  src = null;
197
205
  if (referenceMap)
198
206
  referenceMap = null;
199
- } else if (position > srcEnd) {
207
+ } else if (position$1 > srcEnd) {
200
208
  // over read
201
209
  throw new Error('Unexpected end of MessagePack data')
202
210
  } else if (!sequentialMode) {
@@ -208,7 +216,7 @@
208
216
  if (currentStructures && currentStructures.restoreStructures)
209
217
  restoreStructures();
210
218
  clearSource();
211
- if (error instanceof RangeError || error.message.startsWith('Unexpected end of buffer') || position > srcEnd) {
219
+ if (error instanceof RangeError || error.message.startsWith('Unexpected end of buffer') || position$1 > srcEnd) {
212
220
  error.incomplete = true;
213
221
  }
214
222
  throw error
@@ -223,7 +231,7 @@
223
231
  }
224
232
 
225
233
  function read() {
226
- let token = src[position++];
234
+ let token = src[position$1++];
227
235
  if (token < 0xa0) {
228
236
  if (token < 0x80) {
229
237
  if (token < 0x40)
@@ -271,8 +279,8 @@
271
279
  } else if (token < 0xc0) {
272
280
  // fixstr
273
281
  let length = token - 0xa0;
274
- if (srcStringEnd >= position) {
275
- return srcString.slice(position - srcStringStart, (position += length) - srcStringStart)
282
+ if (srcStringEnd >= position$1) {
283
+ return srcString.slice(position$1 - srcStringStart, (position$1 += length) - srcStringStart)
276
284
  }
277
285
  if (srcStringEnd == 0 && srcEnd < 140) {
278
286
  // for small blocks, avoiding the overhead of the extract call is helpful
@@ -286,124 +294,128 @@
286
294
  switch (token) {
287
295
  case 0xc0: return null
288
296
  case 0xc1:
289
- if (bundledStrings) {
297
+ if (bundledStrings$1) {
290
298
  value = read(); // followed by the length of the string in characters (not bytes!)
291
299
  if (value > 0)
292
- return bundledStrings[1].slice(bundledStrings.position1, bundledStrings.position1 += value)
300
+ return bundledStrings$1[1].slice(bundledStrings$1.position1, bundledStrings$1.position1 += value)
293
301
  else
294
- return bundledStrings[0].slice(bundledStrings.position0, bundledStrings.position0 -= value)
302
+ return bundledStrings$1[0].slice(bundledStrings$1.position0, bundledStrings$1.position0 -= value)
295
303
  }
296
304
  return C1; // "never-used", return special object to denote that
297
305
  case 0xc2: return false
298
306
  case 0xc3: return true
299
307
  case 0xc4:
300
308
  // bin 8
301
- value = src[position++];
309
+ value = src[position$1++];
302
310
  if (value === undefined)
303
311
  throw new Error('Unexpected end of buffer')
304
312
  return readBin(value)
305
313
  case 0xc5:
306
314
  // bin 16
307
- value = dataView.getUint16(position);
308
- position += 2;
315
+ value = dataView.getUint16(position$1);
316
+ position$1 += 2;
309
317
  return readBin(value)
310
318
  case 0xc6:
311
319
  // bin 32
312
- value = dataView.getUint32(position);
313
- position += 4;
320
+ value = dataView.getUint32(position$1);
321
+ position$1 += 4;
314
322
  return readBin(value)
315
323
  case 0xc7:
316
324
  // ext 8
317
- return readExt(src[position++])
325
+ return readExt(src[position$1++])
318
326
  case 0xc8:
319
327
  // ext 16
320
- value = dataView.getUint16(position);
321
- position += 2;
328
+ value = dataView.getUint16(position$1);
329
+ position$1 += 2;
322
330
  return readExt(value)
323
331
  case 0xc9:
324
332
  // ext 32
325
- value = dataView.getUint32(position);
326
- position += 4;
333
+ value = dataView.getUint32(position$1);
334
+ position$1 += 4;
327
335
  return readExt(value)
328
336
  case 0xca:
329
- value = dataView.getFloat32(position);
337
+ value = dataView.getFloat32(position$1);
330
338
  if (currentUnpackr.useFloat32 > 2) {
331
339
  // this does rounding of numbers that were encoded in 32-bit float to nearest significant decimal digit that could be preserved
332
- let multiplier = mult10[((src[position] & 0x7f) << 1) | (src[position + 1] >> 7)];
333
- position += 4;
340
+ let multiplier = mult10[((src[position$1] & 0x7f) << 1) | (src[position$1 + 1] >> 7)];
341
+ position$1 += 4;
334
342
  return ((multiplier * value + (value > 0 ? 0.5 : -0.5)) >> 0) / multiplier
335
343
  }
336
- position += 4;
344
+ position$1 += 4;
337
345
  return value
338
346
  case 0xcb:
339
- value = dataView.getFloat64(position);
340
- position += 8;
347
+ value = dataView.getFloat64(position$1);
348
+ position$1 += 8;
341
349
  return value
342
350
  // uint handlers
343
351
  case 0xcc:
344
- return src[position++]
352
+ return src[position$1++]
345
353
  case 0xcd:
346
- value = dataView.getUint16(position);
347
- position += 2;
354
+ value = dataView.getUint16(position$1);
355
+ position$1 += 2;
348
356
  return value
349
357
  case 0xce:
350
- value = dataView.getUint32(position);
351
- position += 4;
358
+ value = dataView.getUint32(position$1);
359
+ position$1 += 4;
352
360
  return value
353
361
  case 0xcf:
354
- if (currentUnpackr.int64AsNumber) {
355
- value = dataView.getUint32(position) * 0x100000000;
356
- value += dataView.getUint32(position + 4);
362
+ if (currentUnpackr.int64AsType === 'number') {
363
+ value = dataView.getUint32(position$1) * 0x100000000;
364
+ value += dataView.getUint32(position$1 + 4);
365
+ } else if (currentUnpackr.int64AsType === 'string') {
366
+ value = dataView.getBigUint64(position$1).toString();
357
367
  } else
358
- value = dataView.getBigUint64(position);
359
- position += 8;
368
+ value = dataView.getBigUint64(position$1);
369
+ position$1 += 8;
360
370
  return value
361
371
 
362
372
  // int handlers
363
373
  case 0xd0:
364
- return dataView.getInt8(position++)
374
+ return dataView.getInt8(position$1++)
365
375
  case 0xd1:
366
- value = dataView.getInt16(position);
367
- position += 2;
376
+ value = dataView.getInt16(position$1);
377
+ position$1 += 2;
368
378
  return value
369
379
  case 0xd2:
370
- value = dataView.getInt32(position);
371
- position += 4;
380
+ value = dataView.getInt32(position$1);
381
+ position$1 += 4;
372
382
  return value
373
383
  case 0xd3:
374
- if (currentUnpackr.int64AsNumber) {
375
- value = dataView.getInt32(position) * 0x100000000;
376
- value += dataView.getUint32(position + 4);
384
+ if (currentUnpackr.int64AsType === 'number') {
385
+ value = dataView.getInt32(position$1) * 0x100000000;
386
+ value += dataView.getUint32(position$1 + 4);
387
+ } else if (currentUnpackr.int64AsType === 'string') {
388
+ value = dataView.getBigInt64(position$1).toString();
377
389
  } else
378
- value = dataView.getBigInt64(position);
379
- position += 8;
390
+ value = dataView.getBigInt64(position$1);
391
+ position$1 += 8;
380
392
  return value
381
393
 
382
394
  case 0xd4:
383
395
  // fixext 1
384
- value = src[position++];
396
+ value = src[position$1++];
385
397
  if (value == 0x72) {
386
- return recordDefinition(src[position++] & 0x3f)
398
+ return recordDefinition(src[position$1++] & 0x3f)
387
399
  } else {
388
400
  let extension = currentExtensions[value];
389
401
  if (extension) {
390
402
  if (extension.read) {
391
- position++; // skip filler byte
403
+ position$1++; // skip filler byte
392
404
  return extension.read(read())
393
405
  } else if (extension.noBuffer) {
394
- position++; // skip filler byte
406
+ position$1++; // skip filler byte
395
407
  return extension()
396
408
  } else
397
- return extension(src.subarray(position, ++position))
409
+ return extension(src.subarray(position$1, ++position$1))
398
410
  } else
399
411
  throw new Error('Unknown extension ' + value)
400
412
  }
401
413
  case 0xd5:
402
414
  // fixext 2
403
- value = src[position];
415
+ value = src[position$1];
404
416
  if (value == 0x72) {
405
- position++;
406
- return recordDefinition(src[position++] & 0x3f, src[position++])
417
+ position$1++;
418
+ return recordDefinition(src[position$1++] & 0x3f, src[position$1++])
407
419
  } else
408
420
  return readExt(2)
409
421
  case 0xd6:
@@ -417,46 +429,46 @@
417
429
  return readExt(16)
418
430
  case 0xd9:
419
431
  // str 8
420
- value = src[position++];
421
- if (srcStringEnd >= position) {
422
- return srcString.slice(position - srcStringStart, (position += value) - srcStringStart)
432
+ value = src[position$1++];
433
+ if (srcStringEnd >= position$1) {
434
+ return srcString.slice(position$1 - srcStringStart, (position$1 += value) - srcStringStart)
423
435
  }
424
436
  return readString8(value)
425
437
  case 0xda:
426
438
  // str 16
427
- value = dataView.getUint16(position);
428
- position += 2;
429
- if (srcStringEnd >= position) {
430
- return srcString.slice(position - srcStringStart, (position += value) - srcStringStart)
439
+ value = dataView.getUint16(position$1);
440
+ position$1 += 2;
441
+ if (srcStringEnd >= position$1) {
442
+ return srcString.slice(position$1 - srcStringStart, (position$1 += value) - srcStringStart)
431
443
  }
432
444
  return readString16(value)
433
445
  case 0xdb:
434
446
  // str 32
435
- value = dataView.getUint32(position);
436
- position += 4;
437
- if (srcStringEnd >= position) {
438
- return srcString.slice(position - srcStringStart, (position += value) - srcStringStart)
447
+ value = dataView.getUint32(position$1);
448
+ position$1 += 4;
449
+ if (srcStringEnd >= position$1) {
450
+ return srcString.slice(position$1 - srcStringStart, (position$1 += value) - srcStringStart)
439
451
  }
440
452
  return readString32(value)
441
453
  case 0xdc:
442
454
  // array 16
443
- value = dataView.getUint16(position);
444
- position += 2;
455
+ value = dataView.getUint16(position$1);
456
+ position$1 += 2;
445
457
  return readArray(value)
446
458
  case 0xdd:
447
459
  // array 32
448
- value = dataView.getUint32(position);
449
- position += 4;
460
+ value = dataView.getUint32(position$1);
461
+ position$1 += 4;
450
462
  return readArray(value)
451
463
  case 0xde:
452
464
  // map 16
453
- value = dataView.getUint16(position);
454
- position += 2;
465
+ value = dataView.getUint16(position$1);
466
+ position$1 += 2;
455
467
  return readMap(value)
456
468
  case 0xdf:
457
469
  // map 32
458
- value = dataView.getUint32(position);
459
- position += 4;
470
+ value = dataView.getUint32(position$1);
471
+ position$1 += 4;
460
472
  return readMap(value)
461
473
  default: // negative int
462
474
  if (token >= 0xe0)
@@ -502,7 +514,7 @@
502
514
 
503
515
  const createSecondByteReader = (firstId, read0) => {
504
516
  return function() {
505
- let highByte = src[position++];
517
+ let highByte = src[position$1++];
506
518
  if (highByte === 0)
507
519
  return read0()
508
520
  let id = firstId < 32 ? -(firstId + (highByte << 5)) : firstId + (highByte << 5);
@@ -517,7 +529,7 @@
517
529
  };
518
530
 
519
531
  function loadStructures() {
520
- let loadedStructures = saveState(() => {
532
+ let loadedStructures = saveState$1(() => {
521
533
  // save the state in case getStructures modifies our buffer
522
534
  src = null;
523
535
  return currentUnpackr.getStructures()
@@ -529,6 +541,44 @@
529
541
  var readString8 = readStringJS;
530
542
  var readString16 = readStringJS;
531
543
  var readString32 = readStringJS;
544
+
545
+ function setExtractor(extractStrings) {
546
+ readFixedString = readString(1);
547
+ readString8 = readString(2);
548
+ readString16 = readString(3);
549
+ readString32 = readString(5);
550
+ function readString(headerLength) {
551
+ return function readString(length) {
552
+ let string = strings[stringPosition++];
553
+ if (string == null) {
554
+ if (bundledStrings$1)
555
+ return readStringJS(length)
556
+ let extraction = extractStrings(position$1 - headerLength, srcEnd, src);
557
+ if (typeof extraction == 'string') {
558
+ string = extraction;
559
+ strings = EMPTY_ARRAY;
560
+ } else {
561
+ strings = extraction;
562
+ stringPosition = 1;
563
+ srcStringEnd = 1; // even if a utf-8 string was decoded, must indicate we are in the midst of extracted strings and can't skip strings
564
+ string = strings[0];
565
+ if (string === undefined)
566
+ throw new Error('Unexpected end of buffer')
567
+ }
568
+ }
569
+ let srcStringLength = string.length;
570
+ if (srcStringLength <= length) {
571
+ position$1 += length;
572
+ return string
573
+ }
574
+ srcString = string;
575
+ srcStringStart = position$1;
576
+ srcStringEnd = position$1 + srcStringLength;
577
+ position$1 += length;
578
+ return string.slice(0, length) // we know we just want the beginning
579
+ }
580
+ }
581
+ }
532
582
  function readStringJS(length) {
533
583
  let result;
534
584
  if (length < 16) {
@@ -536,29 +586,29 @@
536
586
  return result
537
587
  }
538
588
  if (length > 64 && decoder)
539
- return decoder.decode(src.subarray(position, position += length))
540
- const end = position + length;
589
+ return decoder.decode(src.subarray(position$1, position$1 += length))
590
+ const end = position$1 + length;
541
591
  const units = [];
542
592
  result = '';
543
- while (position < end) {
544
- const byte1 = src[position++];
593
+ while (position$1 < end) {
594
+ const byte1 = src[position$1++];
545
595
  if ((byte1 & 0x80) === 0) {
546
596
  // 1 byte
547
597
  units.push(byte1);
548
598
  } else if ((byte1 & 0xe0) === 0xc0) {
549
599
  // 2 bytes
550
- const byte2 = src[position++] & 0x3f;
600
+ const byte2 = src[position$1++] & 0x3f;
551
601
  units.push(((byte1 & 0x1f) << 6) | byte2);
552
602
  } else if ((byte1 & 0xf0) === 0xe0) {
553
603
  // 3 bytes
554
- const byte2 = src[position++] & 0x3f;
555
- const byte3 = src[position++] & 0x3f;
604
+ const byte2 = src[position$1++] & 0x3f;
605
+ const byte3 = src[position$1++] & 0x3f;
556
606
  units.push(((byte1 & 0x1f) << 12) | (byte2 << 6) | byte3);
557
607
  } else if ((byte1 & 0xf8) === 0xf0) {
558
608
  // 4 bytes
559
- const byte2 = src[position++] & 0x3f;
560
- const byte3 = src[position++] & 0x3f;
561
- const byte4 = src[position++] & 0x3f;
609
+ const byte2 = src[position$1++] & 0x3f;
610
+ const byte3 = src[position$1++] & 0x3f;
611
+ const byte4 = src[position$1++] & 0x3f;
562
612
  let unit = ((byte1 & 0x07) << 0x12) | (byte2 << 0x0c) | (byte3 << 0x06) | byte4;
563
613
  if (unit > 0xffff) {
564
614
  unit -= 0x10000;
@@ -585,7 +635,7 @@
585
635
  function readString(source, start, length) {
586
636
  let existingSrc = src;
587
637
  src = source;
588
- position = start;
638
+ position$1 = start;
589
639
  try {
590
640
  return readStringJS(length);
591
641
  } finally {
@@ -624,12 +674,12 @@
624
674
 
625
675
  var fromCharCode = String.fromCharCode;
626
676
  function longStringInJS(length) {
627
- let start = position;
677
+ let start = position$1;
628
678
  let bytes = new Array(length);
629
679
  for (let i = 0; i < length; i++) {
630
- const byte = src[position++];
680
+ const byte = src[position$1++];
631
681
  if ((byte & 0x80) > 0) {
632
- position = start;
682
+ position$1 = start;
633
683
  return
634
684
  }
635
685
  bytes[i] = byte;
@@ -642,131 +692,131 @@
642
692
  if (length === 0)
643
693
  return ''
644
694
  else {
645
- let a = src[position++];
695
+ let a = src[position$1++];
646
696
  if ((a & 0x80) > 1) {
647
- position -= 1;
697
+ position$1 -= 1;
648
698
  return
649
699
  }
650
700
  return fromCharCode(a)
651
701
  }
652
702
  } else {
653
- let a = src[position++];
654
- let b = src[position++];
703
+ let a = src[position$1++];
704
+ let b = src[position$1++];
655
705
  if ((a & 0x80) > 0 || (b & 0x80) > 0) {
656
- position -= 2;
706
+ position$1 -= 2;
657
707
  return
658
708
  }
659
709
  if (length < 3)
660
710
  return fromCharCode(a, b)
661
- let c = src[position++];
711
+ let c = src[position$1++];
662
712
  if ((c & 0x80) > 0) {
663
- position -= 3;
713
+ position$1 -= 3;
664
714
  return
665
715
  }
666
716
  return fromCharCode(a, b, c)
667
717
  }
668
718
  } else {
669
- let a = src[position++];
670
- let b = src[position++];
671
- let c = src[position++];
672
- let d = src[position++];
719
+ let a = src[position$1++];
720
+ let b = src[position$1++];
721
+ let c = src[position$1++];
722
+ let d = src[position$1++];
673
723
  if ((a & 0x80) > 0 || (b & 0x80) > 0 || (c & 0x80) > 0 || (d & 0x80) > 0) {
674
- position -= 4;
724
+ position$1 -= 4;
675
725
  return
676
726
  }
677
727
  if (length < 6) {
678
728
  if (length === 4)
679
729
  return fromCharCode(a, b, c, d)
680
730
  else {
681
- let e = src[position++];
731
+ let e = src[position$1++];
682
732
  if ((e & 0x80) > 0) {
683
- position -= 5;
733
+ position$1 -= 5;
684
734
  return
685
735
  }
686
736
  return fromCharCode(a, b, c, d, e)
687
737
  }
688
738
  } else if (length < 8) {
689
- let e = src[position++];
690
- let f = src[position++];
739
+ let e = src[position$1++];
740
+ let f = src[position$1++];
691
741
  if ((e & 0x80) > 0 || (f & 0x80) > 0) {
692
- position -= 6;
742
+ position$1 -= 6;
693
743
  return
694
744
  }
695
745
  if (length < 7)
696
746
  return fromCharCode(a, b, c, d, e, f)
697
- let g = src[position++];
747
+ let g = src[position$1++];
698
748
  if ((g & 0x80) > 0) {
699
- position -= 7;
749
+ position$1 -= 7;
700
750
  return
701
751
  }
702
752
  return fromCharCode(a, b, c, d, e, f, g)
703
753
  } else {
704
- let e = src[position++];
705
- let f = src[position++];
706
- let g = src[position++];
707
- let h = src[position++];
754
+ let e = src[position$1++];
755
+ let f = src[position$1++];
756
+ let g = src[position$1++];
757
+ let h = src[position$1++];
708
758
  if ((e & 0x80) > 0 || (f & 0x80) > 0 || (g & 0x80) > 0 || (h & 0x80) > 0) {
709
- position -= 8;
759
+ position$1 -= 8;
710
760
  return
711
761
  }
712
762
  if (length < 10) {
713
763
  if (length === 8)
714
764
  return fromCharCode(a, b, c, d, e, f, g, h)
715
765
  else {
716
- let i = src[position++];
766
+ let i = src[position$1++];
717
767
  if ((i & 0x80) > 0) {
718
- position -= 9;
768
+ position$1 -= 9;
719
769
  return
720
770
  }
721
771
  return fromCharCode(a, b, c, d, e, f, g, h, i)
722
772
  }
723
773
  } else if (length < 12) {
724
- let i = src[position++];
725
- let j = src[position++];
774
+ let i = src[position$1++];
775
+ let j = src[position$1++];
726
776
  if ((i & 0x80) > 0 || (j & 0x80) > 0) {
727
- position -= 10;
777
+ position$1 -= 10;
728
778
  return
729
779
  }
730
780
  if (length < 11)
731
781
  return fromCharCode(a, b, c, d, e, f, g, h, i, j)
732
- let k = src[position++];
782
+ let k = src[position$1++];
733
783
  if ((k & 0x80) > 0) {
734
- position -= 11;
784
+ position$1 -= 11;
735
785
  return
736
786
  }
737
787
  return fromCharCode(a, b, c, d, e, f, g, h, i, j, k)
738
788
  } else {
739
- let i = src[position++];
740
- let j = src[position++];
741
- let k = src[position++];
742
- let l = src[position++];
789
+ let i = src[position$1++];
790
+ let j = src[position$1++];
791
+ let k = src[position$1++];
792
+ let l = src[position$1++];
743
793
  if ((i & 0x80) > 0 || (j & 0x80) > 0 || (k & 0x80) > 0 || (l & 0x80) > 0) {
744
- position -= 12;
794
+ position$1 -= 12;
745
795
  return
746
796
  }
747
797
  if (length < 14) {
748
798
  if (length === 12)
749
799
  return fromCharCode(a, b, c, d, e, f, g, h, i, j, k, l)
750
800
  else {
751
- let m = src[position++];
801
+ let m = src[position$1++];
752
802
  if ((m & 0x80) > 0) {
753
- position -= 13;
803
+ position$1 -= 13;
754
804
  return
755
805
  }
756
806
  return fromCharCode(a, b, c, d, e, f, g, h, i, j, k, l, m)
757
807
  }
758
808
  } else {
759
- let m = src[position++];
760
- let n = src[position++];
809
+ let m = src[position$1++];
810
+ let n = src[position$1++];
761
811
  if ((m & 0x80) > 0 || (n & 0x80) > 0) {
762
- position -= 14;
812
+ position$1 -= 14;
763
813
  return
764
814
  }
765
815
  if (length < 15)
766
816
  return fromCharCode(a, b, c, d, e, f, g, h, i, j, k, l, m, n)
767
- let o = src[position++];
817
+ let o = src[position$1++];
768
818
  if ((o & 0x80) > 0) {
769
- position -= 15;
819
+ position$1 -= 15;
770
820
  return
771
821
  }
772
822
  return fromCharCode(a, b, c, d, e, f, g, h, i, j, k, l, m, n, o)
@@ -777,7 +827,7 @@
777
827
  }
778
828
 
779
829
  function readOnlyJSString() {
780
- let token = src[position++];
830
+ let token = src[position$1++];
781
831
  let length;
782
832
  if (token < 0xc0) {
783
833
  // fixstr
@@ -786,17 +836,17 @@
786
836
  switch(token) {
787
837
  case 0xd9:
788
838
  // str 8
789
- length = src[position++];
839
+ length = src[position$1++];
790
840
  break
791
841
  case 0xda:
792
842
  // str 16
793
- length = dataView.getUint16(position);
794
- position += 2;
843
+ length = dataView.getUint16(position$1);
844
+ position$1 += 2;
795
845
  break
796
846
  case 0xdb:
797
847
  // str 32
798
- length = dataView.getUint32(position);
799
- position += 4;
848
+ length = dataView.getUint32(position$1);
849
+ position$1 += 4;
800
850
  break
801
851
  default:
802
852
  throw new Error('Expected string')
@@ -809,44 +859,44 @@
809
859
  function readBin(length) {
810
860
  return currentUnpackr.copyBuffers ?
811
861
  // specifically use the copying slice (not the node one)
812
- Uint8Array.prototype.slice.call(src, position, position += length) :
813
- src.subarray(position, position += length)
862
+ Uint8Array.prototype.slice.call(src, position$1, position$1 += length) :
863
+ src.subarray(position$1, position$1 += length)
814
864
  }
815
865
  function readExt(length) {
816
- let type = src[position++];
866
+ let type = src[position$1++];
817
867
  if (currentExtensions[type]) {
818
868
  let end;
819
- return currentExtensions[type](src.subarray(position, end = (position += length)), (readPosition) => {
820
- position = readPosition;
869
+ return currentExtensions[type](src.subarray(position$1, end = (position$1 += length)), (readPosition) => {
870
+ position$1 = readPosition;
821
871
  try {
822
872
  return read();
823
873
  } finally {
824
- position = end;
874
+ position$1 = end;
825
875
  }
826
876
  })
827
877
  }
828
878
  else
829
- throw new Error('Unknown extension type ' + type)``
879
+ throw new Error('Unknown extension type ' + type)
830
880
  }
831
881
 
832
882
  var keyCache = new Array(4096);
833
883
  function readKey() {
834
- let length = src[position++];
884
+ let length = src[position$1++];
835
885
  if (length >= 0xa0 && length < 0xc0) {
836
886
  // fixstr, potentially use key cache
837
887
  length = length - 0xa0;
838
- if (srcStringEnd >= position) // if it has been extracted, must use it (and faster anyway)
839
- return srcString.slice(position - srcStringStart, (position += length) - srcStringStart)
888
+ if (srcStringEnd >= position$1) // if it has been extracted, must use it (and faster anyway)
889
+ return srcString.slice(position$1 - srcStringStart, (position$1 += length) - srcStringStart)
840
890
  else if (!(srcStringEnd == 0 && srcEnd < 180))
841
891
  return readFixedString(length)
842
892
  } else { // not cacheable, go back and do a standard read
843
- position--;
893
+ position$1--;
844
894
  return read().toString()
845
895
  }
846
- let key = ((length << 5) ^ (length > 1 ? dataView.getUint16(position) : length > 0 ? src[position] : 0)) & 0xfff;
896
+ let key = ((length << 5) ^ (length > 1 ? dataView.getUint16(position$1) : length > 0 ? src[position$1] : 0)) & 0xfff;
847
897
  let entry = keyCache[key];
848
- let checkPosition = position;
849
- let end = position + length - 3;
898
+ let checkPosition = position$1;
899
+ let end = position$1 + length - 3;
850
900
  let chunk;
851
901
  let i = 0;
852
902
  if (entry && entry.bytes == length) {
@@ -867,11 +917,11 @@
867
917
  }
868
918
  }
869
919
  if (checkPosition === end) {
870
- position = checkPosition;
920
+ position$1 = checkPosition;
871
921
  return entry.string
872
922
  }
873
923
  end -= 3;
874
- checkPosition = position;
924
+ checkPosition = position$1;
875
925
  }
876
926
  entry = [];
877
927
  keyCache[key] = entry;
@@ -919,10 +969,10 @@
919
969
 
920
970
  currentExtensions[0x69] = (data) => {
921
971
  // id extension (for structured clones)
922
- let id = dataView.getUint32(position - 4);
972
+ let id = dataView.getUint32(position$1 - 4);
923
973
  if (!referenceMap)
924
974
  referenceMap = new Map();
925
- let token = src[position];
975
+ let token = src[position$1];
926
976
  let target;
927
977
  // TODO: handle Maps, Sets, and other types that can cycle; this is complicated, because you potentially need to read
928
978
  // ahead past references to record structure definitions
@@ -942,7 +992,7 @@
942
992
 
943
993
  currentExtensions[0x70] = (data) => {
944
994
  // pointer extension (for structured clones)
945
- let id = dataView.getUint32(position - 4);
995
+ let id = dataView.getUint32(position$1 - 4);
946
996
  let refEntry = referenceMap.get(id);
947
997
  refEntry.used = true;
948
998
  return refEntry.target
@@ -967,14 +1017,14 @@
967
1017
  const TEMP_BUNDLE = [];
968
1018
  currentExtensions[0x62] = (data) => {
969
1019
  let dataSize = (data[0] << 24) + (data[1] << 16) + (data[2] << 8) + data[3];
970
- let dataPosition = position;
971
- position += dataSize - data.length;
972
- bundledStrings = TEMP_BUNDLE;
973
- bundledStrings = [readOnlyJSString(), readOnlyJSString()];
974
- bundledStrings.position0 = 0;
975
- bundledStrings.position1 = 0;
976
- bundledStrings.postBundlePosition = position;
977
- position = dataPosition;
1020
+ let dataPosition = position$1;
1021
+ position$1 += dataSize - data.length;
1022
+ bundledStrings$1 = TEMP_BUNDLE;
1023
+ bundledStrings$1 = [readOnlyJSString(), readOnlyJSString()];
1024
+ bundledStrings$1.position0 = 0;
1025
+ bundledStrings$1.position1 = 0;
1026
+ bundledStrings$1.postBundlePosition = position$1;
1027
+ position$1 = dataPosition;
978
1028
  return read()
979
1029
  };
980
1030
 
@@ -996,16 +1046,18 @@
996
1046
  // registration of bulk record definition?
997
1047
  // currentExtensions[0x52] = () =>
998
1048
 
999
- function saveState(callback) {
1049
+ function saveState$1(callback) {
1000
1050
  if (onSaveState)
1001
1051
  onSaveState();
1002
1052
  let savedSrcEnd = srcEnd;
1003
- let savedPosition = position;
1053
+ let savedPosition = position$1;
1054
+ let savedStringPosition = stringPosition;
1004
1055
  let savedSrcStringStart = srcStringStart;
1005
1056
  let savedSrcStringEnd = srcStringEnd;
1006
1057
  let savedSrcString = srcString;
1058
+ let savedStrings = strings;
1007
1059
  let savedReferenceMap = referenceMap;
1008
- let savedBundledStrings = bundledStrings;
1060
+ let savedBundledStrings = bundledStrings$1;
1009
1061
 
1010
1062
  // TODO: We may need to revisit this if we do more external calls to user code (since it could be slow)
1011
1063
  let savedSrc = new Uint8Array(src.slice(0, srcEnd)); // we copy the data in case it changes while external data is processed
@@ -1015,12 +1067,14 @@
1015
1067
  let savedSequentialMode = sequentialMode;
1016
1068
  let value = callback();
1017
1069
  srcEnd = savedSrcEnd;
1018
- position = savedPosition;
1070
+ position$1 = savedPosition;
1071
+ stringPosition = savedStringPosition;
1019
1072
  srcStringStart = savedSrcStringStart;
1020
1073
  srcStringEnd = savedSrcStringEnd;
1021
1074
  srcString = savedSrcString;
1075
+ strings = savedStrings;
1022
1076
  referenceMap = savedReferenceMap;
1023
- bundledStrings = savedBundledStrings;
1077
+ bundledStrings$1 = savedBundledStrings;
1024
1078
  src = savedSrc;
1025
1079
  sequentialMode = savedSequentialMode;
1026
1080
  currentStructures = savedStructures;
@@ -1035,37 +1089,60 @@
1035
1089
  currentStructures = null;
1036
1090
  }
1037
1091
 
1092
+ function addExtension$2(extension) {
1093
+ if (extension.unpack)
1094
+ currentExtensions[extension.type] = extension.unpack;
1095
+ else
1096
+ currentExtensions[extension.type] = extension;
1097
+ }
1098
+
1038
1099
  const mult10 = new Array(147); // this is a table matching binary exponents to the multiplier to determine significant digit rounding
1039
1100
  for (let i = 0; i < 256; i++) {
1040
1101
  mult10[i] = +('1e' + Math.floor(45.15 - i * 0.30103));
1041
1102
  }
1042
- var defaultUnpackr = new Unpackr({ useRecords: false });
1103
+ var defaultUnpackr = new Unpackr$1({ useRecords: false });
1104
+ const unpack$1 = defaultUnpackr.unpack;
1105
+ const unpackMultiple$1 = defaultUnpackr.unpackMultiple;
1106
+ defaultUnpackr.unpack;
1107
+ const FLOAT32_OPTIONS = {
1108
+ NEVER: 0,
1109
+ ALWAYS: 1,
1110
+ DECIMAL_ROUND: 3,
1111
+ DECIMAL_FIT: 4
1112
+ };
1113
+ let f32Array = new Float32Array(1);
1114
+ let u8Array = new Uint8Array(f32Array.buffer, 0, 4);
1115
+ function roundFloat32$1(float32Number) {
1116
+ f32Array[0] = float32Number;
1117
+ let multiplier = mult10[((u8Array[3] & 0x7f) << 1) | (u8Array[2] >> 7)];
1118
+ return ((multiplier * float32Number + (float32Number > 0 ? 0.5 : -0.5)) >> 0) / multiplier
1119
+ }
1043
1120
  function setReadStruct(updatedReadStruct, loadedStructs, saveState) {
1044
- readStruct = updatedReadStruct;
1045
- onLoadedStructures = loadedStructs;
1121
+ readStruct$1 = updatedReadStruct;
1122
+ onLoadedStructures$1 = loadedStructs;
1046
1123
  onSaveState = saveState;
1047
1124
  }
1048
1125
 
1049
- let textEncoder;
1126
+ let textEncoder$1;
1050
1127
  try {
1051
- textEncoder = new TextEncoder();
1128
+ textEncoder$1 = new TextEncoder();
1052
1129
  } catch (error) {}
1053
1130
  let extensions, extensionClasses;
1054
- const hasNodeBuffer = typeof Buffer !== 'undefined';
1055
- const ByteArrayAllocate = hasNodeBuffer ?
1131
+ const hasNodeBuffer$1 = typeof Buffer !== 'undefined';
1132
+ const ByteArrayAllocate = hasNodeBuffer$1 ?
1056
1133
  function(length) { return Buffer.allocUnsafeSlow(length) } : Uint8Array;
1057
- const ByteArray = hasNodeBuffer ? Buffer : Uint8Array;
1058
- const MAX_BUFFER_SIZE = hasNodeBuffer ? 0x100000000 : 0x7fd00000;
1134
+ const ByteArray = hasNodeBuffer$1 ? Buffer : Uint8Array;
1135
+ const MAX_BUFFER_SIZE = hasNodeBuffer$1 ? 0x100000000 : 0x7fd00000;
1059
1136
  let target, keysTarget;
1060
1137
  let targetView;
1061
- let position$1 = 0;
1138
+ let position = 0;
1062
1139
  let safeEnd;
1063
- let bundledStrings$1 = null;
1140
+ let bundledStrings = null;
1064
1141
  let writeStructSlots;
1065
1142
  const MAX_BUNDLE_SIZE = 0xf000;
1066
1143
  const hasNonLatin = /[\u0080-\uFFFF]/;
1067
1144
  const RECORD_SYMBOL = Symbol('record-id');
1068
- class Packr extends Unpackr {
1145
+ let Packr$1 = class Packr extends Unpackr$1 {
1069
1146
  constructor(options) {
1070
1147
  super(options);
1071
1148
  this.offset = 0;
@@ -1075,9 +1152,9 @@
1075
1152
  let referenceMap;
1076
1153
  let encodeUtf8 = ByteArray.prototype.utf8Write ? function(string, position) {
1077
1154
  return target.utf8Write(string, position, 0xffffffff)
1078
- } : (textEncoder && textEncoder.encodeInto) ?
1155
+ } : (textEncoder$1 && textEncoder$1.encodeInto) ?
1079
1156
  function(string, position) {
1080
- return textEncoder.encodeInto(string, target.subarray(position)).written
1157
+ return textEncoder$1.encodeInto(string, target.subarray(position)).written
1081
1158
  } : false;
1082
1159
 
1083
1160
  let packr = this;
@@ -1112,25 +1189,25 @@
1112
1189
  this.pack = this.encode = function(value, encodeOptions) {
1113
1190
  if (!target) {
1114
1191
  target = new ByteArrayAllocate(8192);
1115
- targetView = target.dataView = new DataView(target.buffer, 0, 8192);
1116
- position$1 = 0;
1192
+ targetView = target.dataView || (target.dataView = new DataView(target.buffer, 0, 8192));
1193
+ position = 0;
1117
1194
  }
1118
1195
  safeEnd = target.length - 10;
1119
- if (safeEnd - position$1 < 0x800) {
1196
+ if (safeEnd - position < 0x800) {
1120
1197
  // don't start too close to the end,
1121
1198
  target = new ByteArrayAllocate(target.length);
1122
- targetView = target.dataView = new DataView(target.buffer, 0, target.length);
1199
+ targetView = target.dataView || (target.dataView = new DataView(target.buffer, 0, target.length));
1123
1200
  safeEnd = target.length - 10;
1124
- position$1 = 0;
1201
+ position = 0;
1125
1202
  } else
1126
- position$1 = (position$1 + 7) & 0x7ffffff8; // Word align to make any future copying of this buffer faster
1127
- start = position$1;
1203
+ position = (position + 7) & 0x7ffffff8; // Word align to make any future copying of this buffer faster
1204
+ start = position;
1128
1205
  referenceMap = packr.structuredClone ? new Map() : null;
1129
1206
  if (packr.bundleStrings && typeof value !== 'string') {
1130
- bundledStrings$1 = [];
1131
- bundledStrings$1.size = Infinity; // force a new bundle start on first string
1207
+ bundledStrings = [];
1208
+ bundledStrings.size = Infinity; // force a new bundle start on first string
1132
1209
  } else
1133
- bundledStrings$1 = null;
1210
+ bundledStrings = null;
1134
1211
  structures = packr.structures;
1135
1212
  if (structures) {
1136
1213
  if (structures.uninitialized)
@@ -1171,8 +1248,8 @@
1171
1248
  writeStruct(value);
1172
1249
  else
1173
1250
  pack(value);
1174
- let lastBundle = bundledStrings$1;
1175
- if (bundledStrings$1)
1251
+ let lastBundle = bundledStrings;
1252
+ if (bundledStrings)
1176
1253
  writeBundles(start, pack, 0);
1177
1254
  if (referenceMap && referenceMap.idsToInsert) {
1178
1255
  let idsToInsert = referenceMap.idsToInsert.sort((a, b) => a.offset > b.offset ? 1 : -1);
@@ -1201,21 +1278,21 @@
1201
1278
  targetView.setUint32(lastBundle.position + start,
1202
1279
  targetView.getUint32(lastBundle.position + start) + incrementPosition);
1203
1280
  }
1204
- position$1 += idsToInsert.length * 6;
1205
- if (position$1 > safeEnd)
1206
- makeRoom(position$1);
1207
- packr.offset = position$1;
1208
- let serialized = insertIds(target.subarray(start, position$1), idsToInsert);
1281
+ position += idsToInsert.length * 6;
1282
+ if (position > safeEnd)
1283
+ makeRoom(position);
1284
+ packr.offset = position;
1285
+ let serialized = insertIds(target.subarray(start, position), idsToInsert);
1209
1286
  referenceMap = null;
1210
1287
  return serialized
1211
1288
  }
1212
- packr.offset = position$1; // update the offset so next serialization doesn't write over our buffer, but can continue writing to same buffer sequentially
1289
+ packr.offset = position; // update the offset so next serialization doesn't write over our buffer, but can continue writing to same buffer sequentially
1213
1290
  if (encodeOptions & REUSE_BUFFER_MODE) {
1214
1291
  target.start = start;
1215
- target.end = position$1;
1292
+ target.end = position;
1216
1293
  return target
1217
1294
  }
1218
- return target.subarray(start, position$1) // position can change if we call pack again in saveStructures, so we get the buffer now
1295
+ return target.subarray(start, position) // position can change if we call pack again in saveStructures, so we get the buffer now
1219
1296
  } finally {
1220
1297
  if (structures) {
1221
1298
  if (serializationsSinceTransitionRebuild < 10)
@@ -1238,8 +1315,8 @@
1238
1315
  }
1239
1316
  if (hasSharedUpdate && packr.saveStructures) {
1240
1317
  // we can't rely on start/end with REUSE_BUFFER_MODE since they will (probably) change when we save
1241
- let returnBuffer = target.subarray(start, position$1);
1242
- let newSharedData = prepareStructures(structures, packr);
1318
+ let returnBuffer = target.subarray(start, position);
1319
+ let newSharedData = prepareStructures$1(structures, packr);
1243
1320
  if (packr.saveStructures(newSharedData, newSharedData.isCompatible) === false) {
1244
1321
  // get updated structures and try again if the update failed
1245
1322
  return packr.pack(value)
@@ -1249,47 +1326,47 @@
1249
1326
  }
1250
1327
  }
1251
1328
  if (encodeOptions & RESET_BUFFER_MODE)
1252
- position$1 = start;
1329
+ position = start;
1253
1330
  }
1254
1331
  };
1255
1332
  const pack = (value) => {
1256
- if (position$1 > safeEnd)
1257
- target = makeRoom(position$1);
1333
+ if (position > safeEnd)
1334
+ target = makeRoom(position);
1258
1335
 
1259
1336
  var type = typeof value;
1260
1337
  var length;
1261
1338
  if (type === 'string') {
1262
1339
  let strLength = value.length;
1263
- if (bundledStrings$1 && strLength >= 4 && strLength < 0x1000) {
1264
- if ((bundledStrings$1.size += strLength) > MAX_BUNDLE_SIZE) {
1340
+ if (bundledStrings && strLength >= 4 && strLength < 0x1000) {
1341
+ if ((bundledStrings.size += strLength) > MAX_BUNDLE_SIZE) {
1265
1342
  let extStart;
1266
- let maxBytes = (bundledStrings$1[0] ? bundledStrings$1[0].length * 3 + bundledStrings$1[1].length : 0) + 10;
1267
- if (position$1 + maxBytes > safeEnd)
1268
- target = makeRoom(position$1 + maxBytes);
1343
+ let maxBytes = (bundledStrings[0] ? bundledStrings[0].length * 3 + bundledStrings[1].length : 0) + 10;
1344
+ if (position + maxBytes > safeEnd)
1345
+ target = makeRoom(position + maxBytes);
1269
1346
  let lastBundle;
1270
- 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
1271
- lastBundle = bundledStrings$1;
1272
- target[position$1] = 0xc8; // ext 16
1273
- position$1 += 3; // reserve for the writing bundle size
1274
- target[position$1++] = 0x62; // 'b'
1275
- extStart = position$1 - start;
1276
- position$1 += 4; // reserve for writing bundle reference
1347
+ 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
1348
+ lastBundle = bundledStrings;
1349
+ target[position] = 0xc8; // ext 16
1350
+ position += 3; // reserve for the writing bundle size
1351
+ target[position++] = 0x62; // 'b'
1352
+ extStart = position - start;
1353
+ position += 4; // reserve for writing bundle reference
1277
1354
  writeBundles(start, pack, 0); // write the last bundles
1278
- targetView.setUint16(extStart + start - 3, position$1 - start - extStart);
1355
+ targetView.setUint16(extStart + start - 3, position - start - extStart);
1279
1356
  } 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)
1280
- target[position$1++] = 0xd6; // fixext 4
1281
- target[position$1++] = 0x62; // 'b'
1282
- extStart = position$1 - start;
1283
- position$1 += 4; // reserve for writing bundle reference
1357
+ target[position++] = 0xd6; // fixext 4
1358
+ target[position++] = 0x62; // 'b'
1359
+ extStart = position - start;
1360
+ position += 4; // reserve for writing bundle reference
1284
1361
  }
1285
- bundledStrings$1 = ['', '']; // create new ones
1286
- bundledStrings$1.previous = lastBundle;
1287
- bundledStrings$1.size = 0;
1288
- bundledStrings$1.position = extStart;
1362
+ bundledStrings = ['', '']; // create new ones
1363
+ bundledStrings.previous = lastBundle;
1364
+ bundledStrings.size = 0;
1365
+ bundledStrings.position = extStart;
1289
1366
  }
1290
1367
  let twoByte = hasNonLatin.test(value);
1291
- bundledStrings$1[twoByte ? 0 : 1] += value;
1292
- target[position$1++] = 0xc1;
1368
+ bundledStrings[twoByte ? 0 : 1] += value;
1369
+ target[position++] = 0xc1;
1293
1370
  pack(twoByte ? -strLength : strLength);
1294
1371
  return
1295
1372
  }
@@ -1305,11 +1382,11 @@
1305
1382
  headerSize = 5;
1306
1383
  }
1307
1384
  let maxBytes = strLength * 3;
1308
- if (position$1 + maxBytes > safeEnd)
1309
- target = makeRoom(position$1 + maxBytes);
1385
+ if (position + maxBytes > safeEnd)
1386
+ target = makeRoom(position + maxBytes);
1310
1387
 
1311
1388
  if (strLength < 0x40 || !encodeUtf8) {
1312
- let i, c1, c2, strPosition = position$1 + headerSize;
1389
+ let i, c1, c2, strPosition = position + headerSize;
1313
1390
  for (i = 0; i < strLength; i++) {
1314
1391
  c1 = value.charCodeAt(i);
1315
1392
  if (c1 < 0x80) {
@@ -1333,88 +1410,88 @@
1333
1410
  target[strPosition++] = c1 & 0x3f | 0x80;
1334
1411
  }
1335
1412
  }
1336
- length = strPosition - position$1 - headerSize;
1413
+ length = strPosition - position - headerSize;
1337
1414
  } else {
1338
- length = encodeUtf8(value, position$1 + headerSize);
1415
+ length = encodeUtf8(value, position + headerSize);
1339
1416
  }
1340
1417
 
1341
1418
  if (length < 0x20) {
1342
- target[position$1++] = 0xa0 | length;
1419
+ target[position++] = 0xa0 | length;
1343
1420
  } else if (length < 0x100) {
1344
1421
  if (headerSize < 2) {
1345
- target.copyWithin(position$1 + 2, position$1 + 1, position$1 + 1 + length);
1422
+ target.copyWithin(position + 2, position + 1, position + 1 + length);
1346
1423
  }
1347
- target[position$1++] = 0xd9;
1348
- target[position$1++] = length;
1424
+ target[position++] = 0xd9;
1425
+ target[position++] = length;
1349
1426
  } else if (length < 0x10000) {
1350
1427
  if (headerSize < 3) {
1351
- target.copyWithin(position$1 + 3, position$1 + 2, position$1 + 2 + length);
1428
+ target.copyWithin(position + 3, position + 2, position + 2 + length);
1352
1429
  }
1353
- target[position$1++] = 0xda;
1354
- target[position$1++] = length >> 8;
1355
- target[position$1++] = length & 0xff;
1430
+ target[position++] = 0xda;
1431
+ target[position++] = length >> 8;
1432
+ target[position++] = length & 0xff;
1356
1433
  } else {
1357
1434
  if (headerSize < 5) {
1358
- target.copyWithin(position$1 + 5, position$1 + 3, position$1 + 3 + length);
1435
+ target.copyWithin(position + 5, position + 3, position + 3 + length);
1359
1436
  }
1360
- target[position$1++] = 0xdb;
1361
- targetView.setUint32(position$1, length);
1362
- position$1 += 4;
1437
+ target[position++] = 0xdb;
1438
+ targetView.setUint32(position, length);
1439
+ position += 4;
1363
1440
  }
1364
- position$1 += length;
1441
+ position += length;
1365
1442
  } else if (type === 'number') {
1366
1443
  if (value >>> 0 === value) {// positive integer, 32-bit or less
1367
1444
  // positive uint
1368
1445
  if (value < 0x20 || (value < 0x80 && this.useRecords === false) || (value < 0x40 && !this.randomAccessStructure)) {
1369
- target[position$1++] = value;
1446
+ target[position++] = value;
1370
1447
  } else if (value < 0x100) {
1371
- target[position$1++] = 0xcc;
1372
- target[position$1++] = value;
1448
+ target[position++] = 0xcc;
1449
+ target[position++] = value;
1373
1450
  } else if (value < 0x10000) {
1374
- target[position$1++] = 0xcd;
1375
- target[position$1++] = value >> 8;
1376
- target[position$1++] = value & 0xff;
1451
+ target[position++] = 0xcd;
1452
+ target[position++] = value >> 8;
1453
+ target[position++] = value & 0xff;
1377
1454
  } else {
1378
- target[position$1++] = 0xce;
1379
- targetView.setUint32(position$1, value);
1380
- position$1 += 4;
1455
+ target[position++] = 0xce;
1456
+ targetView.setUint32(position, value);
1457
+ position += 4;
1381
1458
  }
1382
1459
  } else if (value >> 0 === value) { // negative integer
1383
1460
  if (value >= -0x20) {
1384
- target[position$1++] = 0x100 + value;
1461
+ target[position++] = 0x100 + value;
1385
1462
  } else if (value >= -0x80) {
1386
- target[position$1++] = 0xd0;
1387
- target[position$1++] = value + 0x100;
1463
+ target[position++] = 0xd0;
1464
+ target[position++] = value + 0x100;
1388
1465
  } else if (value >= -0x8000) {
1389
- target[position$1++] = 0xd1;
1390
- targetView.setInt16(position$1, value);
1391
- position$1 += 2;
1466
+ target[position++] = 0xd1;
1467
+ targetView.setInt16(position, value);
1468
+ position += 2;
1392
1469
  } else {
1393
- target[position$1++] = 0xd2;
1394
- targetView.setInt32(position$1, value);
1395
- position$1 += 4;
1470
+ target[position++] = 0xd2;
1471
+ targetView.setInt32(position, value);
1472
+ position += 4;
1396
1473
  }
1397
1474
  } else {
1398
1475
  let useFloat32;
1399
1476
  if ((useFloat32 = this.useFloat32) > 0 && value < 0x100000000 && value >= -0x80000000) {
1400
- target[position$1++] = 0xca;
1401
- targetView.setFloat32(position$1, value);
1477
+ target[position++] = 0xca;
1478
+ targetView.setFloat32(position, value);
1402
1479
  let xShifted;
1403
1480
  if (useFloat32 < 4 ||
1404
1481
  // this checks for rounding of numbers that were encoded in 32-bit float to nearest significant decimal digit that could be preserved
1405
- ((xShifted = value * mult10[((target[position$1] & 0x7f) << 1) | (target[position$1 + 1] >> 7)]) >> 0) === xShifted) {
1406
- position$1 += 4;
1482
+ ((xShifted = value * mult10[((target[position] & 0x7f) << 1) | (target[position + 1] >> 7)]) >> 0) === xShifted) {
1483
+ position += 4;
1407
1484
  return
1408
1485
  } else
1409
- position$1--; // move back into position for writing a double
1486
+ position--; // move back into position for writing a double
1410
1487
  }
1411
- target[position$1++] = 0xcb;
1412
- targetView.setFloat64(position$1, value);
1413
- position$1 += 8;
1488
+ target[position++] = 0xcb;
1489
+ targetView.setFloat64(position, value);
1490
+ position += 8;
1414
1491
  }
1415
1492
  } else if (type === 'object') {
1416
1493
  if (!value)
1417
- target[position$1++] = 0xc0;
1494
+ target[position++] = 0xc0;
1418
1495
  else {
1419
1496
  if (referenceMap) {
1420
1497
  let referee = referenceMap.get(value);
@@ -1423,29 +1500,29 @@
1423
1500
  let idsToInsert = referenceMap.idsToInsert || (referenceMap.idsToInsert = []);
1424
1501
  referee.id = idsToInsert.push(referee);
1425
1502
  }
1426
- target[position$1++] = 0xd6; // fixext 4
1427
- target[position$1++] = 0x70; // "p" for pointer
1428
- targetView.setUint32(position$1, referee.id);
1429
- position$1 += 4;
1503
+ target[position++] = 0xd6; // fixext 4
1504
+ target[position++] = 0x70; // "p" for pointer
1505
+ targetView.setUint32(position, referee.id);
1506
+ position += 4;
1430
1507
  return
1431
1508
  } else
1432
- referenceMap.set(value, { offset: position$1 - start });
1509
+ referenceMap.set(value, { offset: position - start });
1433
1510
  }
1434
1511
  let constructor = value.constructor;
1435
1512
  if (constructor === Object) {
1436
1513
  writeObject(value, true);
1437
- } else if (constructor === Array) {
1514
+ } else if (constructor === Array || Array.isArray(value)) {
1438
1515
  length = value.length;
1439
1516
  if (length < 0x10) {
1440
- target[position$1++] = 0x90 | length;
1517
+ target[position++] = 0x90 | length;
1441
1518
  } else if (length < 0x10000) {
1442
- target[position$1++] = 0xdc;
1443
- target[position$1++] = length >> 8;
1444
- target[position$1++] = length & 0xff;
1519
+ target[position++] = 0xdc;
1520
+ target[position++] = length >> 8;
1521
+ target[position++] = length & 0xff;
1445
1522
  } else {
1446
- target[position$1++] = 0xdd;
1447
- targetView.setUint32(position$1, length);
1448
- position$1 += 4;
1523
+ target[position++] = 0xdd;
1524
+ targetView.setUint32(position, length);
1525
+ position += 4;
1449
1526
  }
1450
1527
  for (let i = 0; i < length; i++) {
1451
1528
  pack(value[i]);
@@ -1453,15 +1530,15 @@
1453
1530
  } else if (constructor === Map) {
1454
1531
  length = value.size;
1455
1532
  if (length < 0x10) {
1456
- target[position$1++] = 0x80 | length;
1533
+ target[position++] = 0x80 | length;
1457
1534
  } else if (length < 0x10000) {
1458
- target[position$1++] = 0xde;
1459
- target[position$1++] = length >> 8;
1460
- target[position$1++] = length & 0xff;
1535
+ target[position++] = 0xde;
1536
+ target[position++] = length >> 8;
1537
+ target[position++] = length & 0xff;
1461
1538
  } else {
1462
- target[position$1++] = 0xdf;
1463
- targetView.setUint32(position$1, length);
1464
- position$1 += 4;
1539
+ target[position++] = 0xdf;
1540
+ targetView.setUint32(position, length);
1541
+ position += 4;
1465
1542
  }
1466
1543
  for (let [ key, entryValue ] of value) {
1467
1544
  pack(key);
@@ -1474,16 +1551,16 @@
1474
1551
  let extension = extensions[i];
1475
1552
  if (extension.write) {
1476
1553
  if (extension.type) {
1477
- target[position$1++] = 0xd4; // one byte "tag" extension
1478
- target[position$1++] = extension.type;
1479
- target[position$1++] = 0;
1554
+ target[position++] = 0xd4; // one byte "tag" extension
1555
+ target[position++] = extension.type;
1556
+ target[position++] = 0;
1480
1557
  }
1481
1558
  pack(extension.write.call(this, value));
1482
1559
  return
1483
1560
  }
1484
1561
  let currentTarget = target;
1485
1562
  let currentTargetView = targetView;
1486
- let currentPosition = position$1;
1563
+ let currentPosition = position;
1487
1564
  target = null;
1488
1565
  let result;
1489
1566
  try {
@@ -1491,11 +1568,11 @@
1491
1568
  // restore target and use it
1492
1569
  target = currentTarget;
1493
1570
  currentTarget = null;
1494
- position$1 += size;
1495
- if (position$1 > safeEnd)
1496
- makeRoom(position$1);
1571
+ position += size;
1572
+ if (position > safeEnd)
1573
+ makeRoom(position);
1497
1574
  return {
1498
- target, targetView, position: position$1 - size
1575
+ target, targetView, position: position - size
1499
1576
  }
1500
1577
  }, pack);
1501
1578
  } finally {
@@ -1503,14 +1580,14 @@
1503
1580
  if (currentTarget) {
1504
1581
  target = currentTarget;
1505
1582
  targetView = currentTargetView;
1506
- position$1 = currentPosition;
1583
+ position = currentPosition;
1507
1584
  safeEnd = target.length - 10;
1508
1585
  }
1509
1586
  }
1510
1587
  if (result) {
1511
- if (result.length + position$1 > safeEnd)
1512
- makeRoom(result.length + position$1);
1513
- position$1 = writeExtensionData(result, target, position$1, extension.type);
1588
+ if (result.length + position > safeEnd)
1589
+ makeRoom(result.length + position);
1590
+ position = writeExtensionData(result, target, position, extension.type);
1514
1591
  }
1515
1592
  return
1516
1593
  }
@@ -1520,33 +1597,33 @@
1520
1597
  }
1521
1598
  }
1522
1599
  } else if (type === 'boolean') {
1523
- target[position$1++] = value ? 0xc3 : 0xc2;
1600
+ target[position++] = value ? 0xc3 : 0xc2;
1524
1601
  } else if (type === 'bigint') {
1525
1602
  if (value < (BigInt(1)<<BigInt(63)) && value >= -(BigInt(1)<<BigInt(63))) {
1526
1603
  // use a signed int as long as it fits
1527
- target[position$1++] = 0xd3;
1528
- targetView.setBigInt64(position$1, value);
1604
+ target[position++] = 0xd3;
1605
+ targetView.setBigInt64(position, value);
1529
1606
  } else if (value < (BigInt(1)<<BigInt(64)) && value > 0) {
1530
1607
  // if we can fit an unsigned int, use that
1531
- target[position$1++] = 0xcf;
1532
- targetView.setBigUint64(position$1, value);
1608
+ target[position++] = 0xcf;
1609
+ targetView.setBigUint64(position, value);
1533
1610
  } else {
1534
1611
  // overflow
1535
1612
  if (this.largeBigIntToFloat) {
1536
- target[position$1++] = 0xcb;
1537
- targetView.setFloat64(position$1, Number(value));
1613
+ target[position++] = 0xcb;
1614
+ targetView.setFloat64(position, Number(value));
1538
1615
  } else {
1539
1616
  throw new RangeError(value + ' was too large to fit in MessagePack 64-bit integer format, set largeBigIntToFloat to convert to float-64')
1540
1617
  }
1541
1618
  }
1542
- position$1 += 8;
1619
+ position += 8;
1543
1620
  } else if (type === 'undefined') {
1544
1621
  if (this.encodeUndefinedAsNil)
1545
- target[position$1++] = 0xc0;
1622
+ target[position++] = 0xc0;
1546
1623
  else {
1547
- target[position$1++] = 0xd4; // a number of implementations use fixext1 with type 0, data 0 to denote undefined, so we follow suite
1548
- target[position$1++] = 0;
1549
- target[position$1++] = 0;
1624
+ target[position++] = 0xd4; // a number of implementations use fixext1 with type 0, data 0 to denote undefined, so we follow suite
1625
+ target[position++] = 0;
1626
+ target[position++] = 0;
1550
1627
  }
1551
1628
  } else if (type === 'function') {
1552
1629
  pack(this.writeFunction && this.writeFunction()); // if there is a writeFunction, use it, otherwise just encode as undefined
@@ -1560,15 +1637,15 @@
1560
1637
  let keys = Object.keys(object);
1561
1638
  let length = keys.length;
1562
1639
  if (length < 0x10) {
1563
- target[position$1++] = 0x80 | length;
1640
+ target[position++] = 0x80 | length;
1564
1641
  } else if (length < 0x10000) {
1565
- target[position$1++] = 0xde;
1566
- target[position$1++] = length >> 8;
1567
- target[position$1++] = length & 0xff;
1642
+ target[position++] = 0xde;
1643
+ target[position++] = length >> 8;
1644
+ target[position++] = length & 0xff;
1568
1645
  } else {
1569
- target[position$1++] = 0xdf;
1570
- targetView.setUint32(position$1, length);
1571
- position$1 += 4;
1646
+ target[position++] = 0xdf;
1647
+ targetView.setUint32(position, length);
1648
+ position += 4;
1572
1649
  }
1573
1650
  let key;
1574
1651
  for (let i = 0; i < length; i++) {
@@ -1577,9 +1654,9 @@
1577
1654
  }
1578
1655
  } :
1579
1656
  (object, safePrototype) => {
1580
- target[position$1++] = 0xde; // always using map 16, so we can preallocate and set the length afterwards
1581
- let objectOffset = position$1 - start;
1582
- position$1 += 2;
1657
+ target[position++] = 0xde; // always using map 16, so we can preallocate and set the length afterwards
1658
+ let objectOffset = position - start;
1659
+ position += 2;
1583
1660
  let size = 0;
1584
1661
  for (let key in object) {
1585
1662
  if (safePrototype || object.hasOwnProperty(key)) {
@@ -1594,7 +1671,7 @@
1594
1671
  (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)
1595
1672
  (object, safePrototype) => {
1596
1673
  let nextTransition, transition = structures.transitions || (structures.transitions = Object.create(null));
1597
- let objectOffset = position$1++ - start;
1674
+ let objectOffset = position++ - start;
1598
1675
  let wroteKeys;
1599
1676
  for (let key in object) {
1600
1677
  if (safePrototype || object.hasOwnProperty(key)) {
@@ -1616,9 +1693,9 @@
1616
1693
  }
1617
1694
  transition = nextTransition;
1618
1695
  }
1619
- if (objectOffset + start + 1 == position$1) {
1696
+ if (objectOffset + start + 1 == position) {
1620
1697
  // first key, so we don't need to insert, we can just write record directly
1621
- position$1--;
1698
+ position--;
1622
1699
  newRecord(transition, keys, newTransitions);
1623
1700
  } else // otherwise we need to insert the record, moving existing data after the record
1624
1701
  insertNewRecord(transition, keys, objectOffset, newTransitions);
@@ -1650,10 +1727,10 @@
1650
1727
  let recordId = transition[RECORD_SYMBOL];
1651
1728
  if (recordId) {
1652
1729
  if (recordId >= 0x60 && useTwoByteRecords) {
1653
- target[position$1++] = ((recordId -= 0x60) & 0x1f) + 0x60;
1654
- target[position$1++] = recordId >> 5;
1730
+ target[position++] = ((recordId -= 0x60) & 0x1f) + 0x60;
1731
+ target[position++] = recordId >> 5;
1655
1732
  } else
1656
- target[position$1++] = recordId;
1733
+ target[position++] = recordId;
1657
1734
  } else {
1658
1735
  newRecord(transition, transition.__keys__ || Object.keys(object), newTransitions);
1659
1736
  }
@@ -1673,13 +1750,13 @@
1673
1750
  } else // faster handling for smaller buffers
1674
1751
  newSize = ((Math.max((end - start) << 2, target.length - 1) >> 12) + 1) << 12;
1675
1752
  let newBuffer = new ByteArrayAllocate(newSize);
1676
- targetView = newBuffer.dataView = new DataView(newBuffer.buffer, 0, newSize);
1753
+ targetView = newBuffer.dataView || (newBuffer.dataView = new DataView(newBuffer.buffer, 0, newSize));
1677
1754
  end = Math.min(end, target.length);
1678
1755
  if (target.copy)
1679
1756
  target.copy(newBuffer, 0, start, end);
1680
1757
  else
1681
1758
  newBuffer.set(target.slice(start, end));
1682
- position$1 -= start;
1759
+ position -= start;
1683
1760
  start = 0;
1684
1761
  safeEnd = newBuffer.length - 10;
1685
1762
  return target = newBuffer
@@ -1708,21 +1785,21 @@
1708
1785
  structures.sharedLength = recordId - 0x3f;
1709
1786
  hasSharedUpdate = true;
1710
1787
  if (highByte >= 0) {
1711
- target[position$1++] = (recordId & 0x1f) + 0x60;
1712
- target[position$1++] = highByte;
1788
+ target[position++] = (recordId & 0x1f) + 0x60;
1789
+ target[position++] = highByte;
1713
1790
  } else {
1714
- target[position$1++] = recordId;
1791
+ target[position++] = recordId;
1715
1792
  }
1716
1793
  } else {
1717
1794
  if (highByte >= 0) {
1718
- target[position$1++] = 0xd5; // fixext 2
1719
- target[position$1++] = 0x72; // "r" record defintion extension type
1720
- target[position$1++] = (recordId & 0x1f) + 0x60;
1721
- target[position$1++] = highByte;
1795
+ target[position++] = 0xd5; // fixext 2
1796
+ target[position++] = 0x72; // "r" record defintion extension type
1797
+ target[position++] = (recordId & 0x1f) + 0x60;
1798
+ target[position++] = highByte;
1722
1799
  } else {
1723
- target[position$1++] = 0xd4; // fixext 1
1724
- target[position$1++] = 0x72; // "r" record defintion extension type
1725
- target[position$1++] = recordId;
1800
+ target[position++] = 0xd4; // fixext 1
1801
+ target[position++] = 0x72; // "r" record defintion extension type
1802
+ target[position++] = recordId;
1726
1803
  }
1727
1804
 
1728
1805
  if (newTransitions)
@@ -1736,57 +1813,57 @@
1736
1813
  };
1737
1814
  const insertNewRecord = (transition, keys, insertionOffset, newTransitions) => {
1738
1815
  let mainTarget = target;
1739
- let mainPosition = position$1;
1816
+ let mainPosition = position;
1740
1817
  let mainSafeEnd = safeEnd;
1741
1818
  let mainStart = start;
1742
1819
  target = keysTarget;
1743
- position$1 = 0;
1820
+ position = 0;
1744
1821
  start = 0;
1745
1822
  if (!target)
1746
1823
  keysTarget = target = new ByteArrayAllocate(8192);
1747
1824
  safeEnd = target.length - 10;
1748
1825
  newRecord(transition, keys, newTransitions);
1749
1826
  keysTarget = target;
1750
- let keysPosition = position$1;
1827
+ let keysPosition = position;
1751
1828
  target = mainTarget;
1752
- position$1 = mainPosition;
1829
+ position = mainPosition;
1753
1830
  safeEnd = mainSafeEnd;
1754
1831
  start = mainStart;
1755
1832
  if (keysPosition > 1) {
1756
- let newEnd = position$1 + keysPosition - 1;
1833
+ let newEnd = position + keysPosition - 1;
1757
1834
  if (newEnd > safeEnd)
1758
1835
  makeRoom(newEnd);
1759
1836
  let insertionPosition = insertionOffset + start;
1760
- target.copyWithin(insertionPosition + keysPosition, insertionPosition + 1, position$1);
1837
+ target.copyWithin(insertionPosition + keysPosition, insertionPosition + 1, position);
1761
1838
  target.set(keysTarget.slice(0, keysPosition), insertionPosition);
1762
- position$1 = newEnd;
1839
+ position = newEnd;
1763
1840
  } else {
1764
1841
  target[insertionOffset + start] = keysTarget[0];
1765
1842
  }
1766
1843
  };
1767
1844
  const writeStruct = (object, safePrototype) => {
1768
- let newPosition = writeStructSlots(object, target, position$1, structures, makeRoom, (value, newPosition, notifySharedUpdate) => {
1845
+ let newPosition = writeStructSlots(object, target, position, structures, makeRoom, (value, newPosition, notifySharedUpdate) => {
1769
1846
  if (notifySharedUpdate)
1770
1847
  return hasSharedUpdate = true;
1771
- position$1 = newPosition;
1848
+ position = newPosition;
1772
1849
  if (start > 0) {
1773
1850
  pack(value);
1774
1851
  if (start == 0)
1775
- return { position: position$1, targetView, target }; // indicate the buffer was re-allocated
1852
+ return { position, targetView, target }; // indicate the buffer was re-allocated
1776
1853
  } else
1777
1854
  pack(value);
1778
- return position$1;
1855
+ return position;
1779
1856
  }, this);
1780
1857
  if (newPosition === 0) // bail and go to a msgpack object
1781
1858
  return writeObject(object, true);
1782
- position$1 = newPosition;
1859
+ position = newPosition;
1783
1860
  };
1784
1861
  }
1785
1862
  useBuffer(buffer) {
1786
1863
  // this means we are finished using our own buffer and we can write over it safely
1787
1864
  target = buffer;
1788
1865
  targetView = new DataView(target.buffer, target.byteOffset, target.byteLength);
1789
- position$1 = 0;
1866
+ position = 0;
1790
1867
  }
1791
1868
  clearSharedData() {
1792
1869
  if (this.structures)
@@ -1794,7 +1871,7 @@
1794
1871
  if (this.typedStructs)
1795
1872
  this.typedStructs = [];
1796
1873
  }
1797
- }
1874
+ };
1798
1875
 
1799
1876
  extensionClasses = [ Date, Set, Error, RegExp, ArrayBuffer, Object.getPrototypeOf(Uint8Array.prototype).constructor /*TypedArray*/, C1Type ];
1800
1877
  extensions = [{
@@ -1869,7 +1946,7 @@
1869
1946
  if (this.moreTypes)
1870
1947
  writeExtBuffer(arrayBuffer, 0x10, allocateForWrite);
1871
1948
  else
1872
- writeBuffer(hasNodeBuffer ? Buffer.from(arrayBuffer) : new Uint8Array(arrayBuffer), allocateForWrite);
1949
+ writeBuffer(hasNodeBuffer$1 ? Buffer.from(arrayBuffer) : new Uint8Array(arrayBuffer), allocateForWrite);
1873
1950
  }
1874
1951
  }, {
1875
1952
  pack(typedArray, allocateForWrite) {
@@ -1991,16 +2068,28 @@
1991
2068
  }
1992
2069
 
1993
2070
  function writeBundles(start, pack, incrementPosition) {
1994
- if (bundledStrings$1.length > 0) {
1995
- targetView.setUint32(bundledStrings$1.position + start, position$1 + incrementPosition - bundledStrings$1.position - start);
1996
- bundledStrings$1.stringsPosition = position$1 - start;
1997
- let writeStrings = bundledStrings$1;
1998
- bundledStrings$1 = null;
2071
+ if (bundledStrings.length > 0) {
2072
+ targetView.setUint32(bundledStrings.position + start, position + incrementPosition - bundledStrings.position - start);
2073
+ bundledStrings.stringsPosition = position - start;
2074
+ let writeStrings = bundledStrings;
2075
+ bundledStrings = null;
1999
2076
  pack(writeStrings[0]);
2000
2077
  pack(writeStrings[1]);
2001
2078
  }
2002
2079
  }
2003
- function prepareStructures(structures, packr) {
2080
+
2081
+ function addExtension$1(extension) {
2082
+ if (extension.Class) {
2083
+ if (!extension.pack && !extension.write)
2084
+ throw new Error('Extension has no pack or write function')
2085
+ if (extension.pack && !extension.type)
2086
+ throw new Error('Extension has no type (numeric code to identify the extension)')
2087
+ extensionClasses.unshift(extension.Class);
2088
+ extensions.unshift(extension);
2089
+ }
2090
+ addExtension$2(extension);
2091
+ }
2092
+ function prepareStructures$1(structures, packr) {
2004
2093
  structures.isCompatible = (existingStructures) => {
2005
2094
  let compatible = !existingStructures || ((packr.lastNamedStructuresLength || 0) === existingStructures.length);
2006
2095
  if (!compatible) // we want to merge these existing structures immediately since we already have it and we are in the right transaction
@@ -2011,10 +2100,12 @@
2011
2100
  }
2012
2101
  function setWriteStructSlots(writeSlots, makeStructures) {
2013
2102
  writeStructSlots = writeSlots;
2014
- prepareStructures = makeStructures;
2103
+ prepareStructures$1 = makeStructures;
2015
2104
  }
2016
2105
 
2017
- let defaultPackr = new Packr({ useRecords: false });
2106
+ let defaultPackr = new Packr$1({ useRecords: false });
2107
+ const pack$1 = defaultPackr.pack;
2108
+ defaultPackr.pack;
2018
2109
  const REUSE_BUFFER_MODE = 512;
2019
2110
  const RESET_BUFFER_MODE = 1024;
2020
2111
 
@@ -2035,18 +2126,18 @@
2035
2126
  }
2036
2127
 
2037
2128
  let updatedPosition;
2038
- const hasNodeBuffer$1 = typeof Buffer !== 'undefined';
2039
- let textEncoder$1, currentSource;
2129
+ const hasNodeBuffer = typeof Buffer !== 'undefined';
2130
+ let textEncoder, currentSource;
2040
2131
  try {
2041
- textEncoder$1 = new TextEncoder();
2132
+ textEncoder = new TextEncoder();
2042
2133
  } catch (error) {}
2043
- const encodeUtf8 = hasNodeBuffer$1 ? function(target, string, position) {
2134
+ const encodeUtf8 = hasNodeBuffer ? function(target, string, position) {
2044
2135
  return target.utf8Write(string, position, 0xffffffff)
2045
- } : (textEncoder$1 && textEncoder$1.encodeInto) ?
2136
+ } : (textEncoder && textEncoder.encodeInto) ?
2046
2137
  function(target, string, position) {
2047
- return textEncoder$1.encodeInto(string, target.subarray(position)).written
2138
+ return textEncoder.encodeInto(string, target.subarray(position)).written
2048
2139
  } : false;
2049
- setWriteStructSlots(writeStruct, prepareStructures$1);
2140
+ setWriteStructSlots(writeStruct, prepareStructures);
2050
2141
  function writeStruct(object, target, position, structures, makeRoom, pack, packr) {
2051
2142
  let typedStructs = packr.typedStructs || (packr.typedStructs = []);
2052
2143
  // note that we rely on pack.js to load stored structures before we get to this point
@@ -2139,9 +2230,9 @@
2139
2230
  case 'string':
2140
2231
  let strLength = value.length;
2141
2232
  refOffset = refPosition - refsStartPosition;
2142
- if ((strLength << 2) + position > safeEnd) {
2233
+ if ((strLength << 2) + refPosition > safeEnd) {
2143
2234
  let lastStart = start;
2144
- target = makeRoom(refPosition);
2235
+ target = makeRoom((strLength << 2) + refPosition);
2145
2236
  targetView = target.dataView;
2146
2237
  position -= lastStart;
2147
2238
  refsStartPosition -= lastStart;
@@ -2421,7 +2512,7 @@
2421
2512
  newTransition.__parent = transition;
2422
2513
  return newTransition;
2423
2514
  }
2424
- function onLoadedStructures$1(sharedData) {
2515
+ function onLoadedStructures(sharedData) {
2425
2516
  if (!(sharedData instanceof Map))
2426
2517
  return sharedData;
2427
2518
  let typed = sharedData.get('typed') || [];
@@ -2459,7 +2550,7 @@
2459
2550
  return named;
2460
2551
  }
2461
2552
  var sourceSymbol = Symbol.for('source');
2462
- function readStruct$1(src, position, srcEnd, unpackr) {
2553
+ function readStruct(src, position, srcEnd, unpackr) {
2463
2554
  let recordId = src[position++] - 0x20;
2464
2555
  if (recordId >= 24) {
2465
2556
  switch(recordId) {
@@ -2730,14 +2821,14 @@
2730
2821
  }
2731
2822
  }
2732
2823
 
2733
- function saveState$1() {
2824
+ function saveState() {
2734
2825
  if (currentSource) {
2735
2826
  currentSource.bytes = Uint8Array.prototype.slice.call(currentSource.bytes, currentSource.position, currentSource.bytesEnd);
2736
2827
  currentSource.position = 0;
2737
2828
  currentSource.bytesEnd = currentSource.bytes.length;
2738
2829
  }
2739
2830
  }
2740
- function prepareStructures$1(structures, packr) {
2831
+ function prepareStructures(structures, packr) {
2741
2832
  if (packr.typedStructs) {
2742
2833
  let structMap = new Map();
2743
2834
  structMap.set('named', structures);
@@ -2754,7 +2845,7 @@
2754
2845
  let typed = existing.get('typed') || [];
2755
2846
  if (typed.length !== lastTypedStructuresLength)
2756
2847
  compatible = false;
2757
- } else if (existing instanceof Array) {
2848
+ } else if (existing instanceof Array || Array.isArray(existing)) {
2758
2849
  if (existing.length !== (packr.lastNamedStructuresLength || 0))
2759
2850
  compatible = false;
2760
2851
  }
@@ -2766,7 +2857,23 @@
2766
2857
  return structures;
2767
2858
  }
2768
2859
 
2769
- setReadStruct(readStruct$1, onLoadedStructures$1, saveState$1);
2860
+ setReadStruct(readStruct, onLoadedStructures, saveState);
2861
+
2862
+ const nativeAccelerationDisabled = process.env.MSGPACKR_NATIVE_ACCELERATION_DISABLED !== undefined && process.env.MSGPACKR_NATIVE_ACCELERATION_DISABLED.toLowerCase() === 'true';
2863
+
2864
+ if (!nativeAccelerationDisabled) {
2865
+ let extractor;
2866
+ try {
2867
+ if (typeof require == 'function')
2868
+ extractor = require('msgpackr-extract');
2869
+ else
2870
+ extractor = module.createRequire((document.currentScript && document.currentScript.src || new URL('test.js', document.baseURI).href))('msgpackr-extract');
2871
+ if (extractor)
2872
+ setExtractor(extractor.extractStrings);
2873
+ } catch (error) {
2874
+ // native module is optional
2875
+ }
2876
+ }
2770
2877
 
2771
2878
  let allSampleData = [];
2772
2879
  for (let i = 1; i < 6; i++) {
@@ -2795,49 +2902,49 @@
2795
2902
  //if (typeof chai === 'undefined') { chai = require('chai') }
2796
2903
  var assert = chai.assert;
2797
2904
  //if (typeof msgpackr === 'undefined') { msgpackr = require('..') }
2798
- var Packr$1 = msgpackr.Packr;
2799
- var Unpackr$1 = msgpackr.Unpackr;
2800
- var unpack = msgpackr.unpack;
2801
- var unpackMultiple = msgpackr.unpackMultiple;
2802
- var roundFloat32 = msgpackr.roundFloat32;
2803
- var pack = msgpackr.pack;
2804
- var DECIMAL_FIT = msgpackr.FLOAT32_OPTIONS.DECIMAL_FIT;
2805
-
2806
- var addExtension = msgpackr.addExtension;
2905
+ var Packr = Packr$1;
2906
+ var Unpackr = Unpackr$1;
2907
+ var unpack = unpack$1;
2908
+ var unpackMultiple = unpackMultiple$1;
2909
+ var roundFloat32 = roundFloat32$1;
2910
+ var pack = pack$1;
2911
+ var DECIMAL_FIT = FLOAT32_OPTIONS.DECIMAL_FIT;
2912
+
2913
+ var addExtension = addExtension$1;
2807
2914
  var zlib = tryRequire('zlib');
2808
- var deflateSync = zlib.deflateSync;
2809
- var inflateSync = zlib.inflateSync;
2810
- var deflateSync = zlib.brotliCompressSync;
2811
- var inflateSync = zlib.brotliDecompressSync;
2812
- var constants = zlib.constants;
2915
+ zlib.deflateSync;
2916
+ zlib.inflateSync;
2917
+ zlib.brotliCompressSync;
2918
+ zlib.brotliDecompressSync;
2919
+ zlib.constants;
2813
2920
 
2814
2921
  var ITERATIONS = 4000;
2815
2922
 
2816
- suite('msgpackr basic tests', function(){
2817
- test('pack/unpack data', function(){
2923
+ suite('msgpackr basic tests', function() {
2924
+ test('pack/unpack data', function () {
2818
2925
  var data = {
2819
2926
  data: [
2820
- { a: 1, name: 'one', type: 'odd', isOdd: true },
2821
- { a: 2, name: 'two', type: 'even'},
2822
- { a: 3, name: 'three', type: 'odd', isOdd: true },
2823
- { a: 4, name: 'four', type: 'even'},
2824
- { a: 5, name: 'five', type: 'odd', isOdd: true },
2825
- { a: 6, name: 'six', type: 'even', isOdd: null }
2927
+ {a: 1, name: 'one', type: 'odd', isOdd: true},
2928
+ {a: 2, name: 'two', type: 'even'},
2929
+ {a: 3, name: 'three', type: 'odd', isOdd: true},
2930
+ {a: 4, name: 'four', type: 'even'},
2931
+ {a: 5, name: 'five', type: 'odd', isOdd: true},
2932
+ {a: 6, name: 'six', type: 'even', isOdd: null}
2826
2933
  ],
2827
2934
  description: 'some names',
2828
2935
  types: ['odd', 'even'],
2829
2936
  convertEnumToNum: [
2830
- { prop: 'test' },
2831
- { prop: 'test' },
2832
- { prop: 'test' },
2833
- { prop: 1 },
2834
- { prop: 2 },
2835
- { prop: [undefined] },
2836
- { prop: null }
2937
+ {prop: 'test'},
2938
+ {prop: 'test'},
2939
+ {prop: 'test'},
2940
+ {prop: 1},
2941
+ {prop: 2},
2942
+ {prop: [undefined]},
2943
+ {prop: null}
2837
2944
  ]
2838
2945
  };
2839
2946
  let structures = [];
2840
- let packr = new Packr$1({ structures });
2947
+ let packr = new Packr({structures});
2841
2948
  var serialized = packr.pack(data);
2842
2949
  serialized = packr.pack(data);
2843
2950
  serialized = packr.pack(data);
@@ -2845,12 +2952,12 @@
2845
2952
  assert.deepEqual(deserialized, data);
2846
2953
  });
2847
2954
 
2848
- test('mixed structures', function(){
2849
- let data1 = { a: 1, b: 2, c: 3 };
2850
- let data2 = { a: 1, b: 2, d: 4 };
2851
- let data3 = { a: 1, b: 2, e: 5 };
2955
+ test('mixed structures', function () {
2956
+ let data1 = {a: 1, b: 2, c: 3};
2957
+ let data2 = {a: 1, b: 2, d: 4};
2958
+ let data3 = {a: 1, b: 2, e: 5};
2852
2959
  let structures = [];
2853
- let packr = new Packr$1({ structures });
2960
+ let packr = new Packr({structures});
2854
2961
  var serialized = packr.pack(data1);
2855
2962
  var deserialized = packr.unpack(serialized);
2856
2963
  assert.deepEqual(deserialized, data1);
@@ -2862,7 +2969,7 @@
2862
2969
  assert.deepEqual(deserialized, data3);
2863
2970
  });
2864
2971
 
2865
- test('mixed array', function(){
2972
+ test('mixed array', function () {
2866
2973
  var data = [
2867
2974
  'one',
2868
2975
  'two',
@@ -2874,31 +2981,34 @@
2874
2981
  'three',
2875
2982
  'three',
2876
2983
  'one', [
2877
- 3, -5, -50, -400,1.3, -5.3, true
2984
+ 3, -5, -50, -400, 1.3, -5.3, true
2878
2985
  ]
2879
2986
  ];
2880
2987
  let structures = [];
2881
- let packr = new Packr$1({ structures });
2988
+ let packr = new Packr({structures});
2882
2989
  var serialized = packr.pack(data);
2883
2990
  var deserialized = packr.unpack(serialized);
2884
2991
  assert.deepEqual(deserialized, data);
2885
2992
  });
2886
2993
 
2887
- test('255 chars', function() {
2994
+ test('255 chars', function () {
2888
2995
  const data = 'RRZG9A6I7xupPeOZhxcOcioFsuhszGOdyDUcbRf4Zef2kdPIfC9RaLO4jTM5JhuZvTsF09fbRHMGtqk7YAgu3vespeTe9l61ziZ6VrMnYu2CamK96wCkmz0VUXyqaiUoTPgzk414LS9yYrd5uh7w18ksJF5SlC2e91rukWvNqAZJjYN3jpkqHNOFchCwFrhbxq2Lrv1kSJPYCx9blRg2hGmYqTbElLTZHv20iNqwZeQbRMgSBPT6vnbCBPnOh1W';
2889
2996
  var serialized = pack(data);
2890
2997
  var deserialized = unpack(serialized);
2891
2998
  assert.equal(deserialized, data);
2892
2999
  });
2893
- test('pack/unpack varying data with random access structures', function() {
3000
+ test('pack/unpack varying data with random access structures', function () {
2894
3001
  let structures = [];
2895
- let packr = new Packr$1({ structures, useRecords: true, randomAccessStructure: true, freezeData: true, saveStructures(structures) {
3002
+ let packr = new Packr({
3003
+ structures, useRecords: true, randomAccessStructure: true, freezeData: true, saveStructures(structures) {
2896
3004
  }, getStructures() {
2897
3005
  console.log('getStructures');
2898
- } });
3006
+ }
3007
+ });
2899
3008
  for (let i = 0; i < 20; i++) {
2900
3009
  let data = {};
2901
- let props = ['foo', 'bar', 'a', 'b', 'c','name', 'age', 'd'];
3010
+ let props = ['foo', 'bar', 'a', 'b', 'c', 'name', 'age', 'd'];
3011
+
2902
3012
  function makeString() {
2903
3013
  let str = '';
2904
3014
  while (random() < 0.9) {
@@ -2906,6 +3016,7 @@
2906
3016
  }
2907
3017
  return str;
2908
3018
  }
3019
+
2909
3020
  for (let i = 0; i < random() * 20; i++) {
2910
3021
  data[props[Math.floor(random() * 8)]] =
2911
3022
  random() < 0.3 ? Math.floor(random() * 400) / 2 :
@@ -2914,7 +3025,7 @@
2914
3025
  var serialized = packr.pack(data);
2915
3026
  var deserialized = packr.unpack(serialized);
2916
3027
  for (let key in deserialized) {
2917
- let a = deserialized[key];
3028
+ deserialized[key];
2918
3029
  }
2919
3030
  assert.deepEqual(deserialized, data);
2920
3031
  }
@@ -2922,7 +3033,7 @@
2922
3033
 
2923
3034
  for (let sampleData of allSampleData) {
2924
3035
  let snippet = JSON.stringify(sampleData).slice(0, 20) + '...';
2925
- test('pack/unpack sample data ' + snippet, function(){
3036
+ test('pack/unpack sample data ' + snippet, function () {
2926
3037
  var data = sampleData;
2927
3038
  var serialized = pack(data);
2928
3039
  var deserialized = unpack(serialized);
@@ -2931,16 +3042,28 @@
2931
3042
  var deserialized = unpack(serialized);
2932
3043
  assert.deepEqual(deserialized, data);
2933
3044
  });
2934
- test('pack/unpack sample data with random access structures ' + snippet, function() {
3045
+ test('pack/unpack sample data with Uint8Array encoding' + snippet, function () {
3046
+ var data = sampleData;
3047
+ var serialized = pack(data);
3048
+ serialized = new Uint8Array(serialized);
3049
+ var deserialized = unpack(serialized);
3050
+ assert.deepEqual(deserialized, data);
3051
+ var serialized = pack(data);
3052
+ var deserialized = unpack(serialized);
3053
+ assert.deepEqual(deserialized, data);
3054
+ });
3055
+ test('pack/unpack sample data with random access structures ' + snippet, function () {
2935
3056
  var data = sampleData;
2936
3057
  let structures = [];
2937
- let packr = new Packr$1({ structures, useRecords: true, randomAccessStructure: true, freezeData: true, saveStructures(structures) {
2938
- }, getStructures() {
2939
- console.log('getStructures');
2940
- } });
3058
+ let packr = new Packr({
3059
+ structures, useRecords: true, randomAccessStructure: true, freezeData: true, saveStructures(structures) {
3060
+ }, getStructures() {
3061
+ console.log('getStructures');
3062
+ }
3063
+ });
2941
3064
  for (let i = 0; i < 20; i++) {
2942
3065
  var serialized = packr.pack(data);
2943
- var deserialized = packr.unpack(serialized, { lazy: true });
3066
+ var deserialized = packr.unpack(serialized, {lazy: true});
2944
3067
  var copied = {};
2945
3068
  for (let key in deserialized) {
2946
3069
  copied[key] = deserialized[key];
@@ -2948,26 +3071,26 @@
2948
3071
  assert.deepEqual(copied, data);
2949
3072
  }
2950
3073
  });
2951
- test('pack/unpack sample data with bundled strings ' + snippet, function(){
3074
+ test('pack/unpack sample data with bundled strings ' + snippet, function () {
2952
3075
  var data = sampleData;
2953
- let packr = new Packr$1({ /*structures,*/ useRecords: false, bundleStrings: true });
3076
+ let packr = new Packr({ /*structures,*/ useRecords: false, bundleStrings: true});
2954
3077
  var serialized = packr.pack(data);
2955
3078
  var deserialized = packr.unpack(serialized);
2956
3079
  assert.deepEqual(deserialized, data);
2957
3080
  });
2958
3081
  }
2959
3082
 
2960
- test('pack/unpack empty data with bundled strings', function(){
3083
+ test('pack/unpack empty data with bundled strings', function () {
2961
3084
  var data = {};
2962
- let packr = new Packr$1({ bundleStrings: true });
3085
+ let packr = new Packr({bundleStrings: true});
2963
3086
  var serialized = packr.pack(data);
2964
3087
  var deserialized = packr.unpack(serialized);
2965
3088
  assert.deepEqual(deserialized, data);
2966
3089
  });
2967
- test('pack/unpack sequential data', function(){
2968
- var data = { foo:1, bar: 2 };
2969
- let packr = new Packr$1({ sequential: true });
2970
- let unpackr = new Unpackr$1({ sequential: true });
3090
+ test('pack/unpack sequential data', function () {
3091
+ var data = {foo: 1, bar: 2};
3092
+ let packr = new Packr({sequential: true});
3093
+ let unpackr = new Unpackr({sequential: true});
2971
3094
  var serialized = packr.pack(data);
2972
3095
  var deserialized = unpackr.unpack(serialized);
2973
3096
  assert.deepEqual(deserialized, data);
@@ -2975,6 +3098,22 @@
2975
3098
  var deserialized = unpackr.unpack(serialized);
2976
3099
  assert.deepEqual(deserialized, data);
2977
3100
  });
3101
+ test('pack/unpack with bundled strings and sequential', function () {
3102
+ const options = {
3103
+ bundleStrings: true,
3104
+ sequential: true,
3105
+ };
3106
+
3107
+ const packer = new Packr(options);
3108
+ const unpacker = new Packr(options);
3109
+
3110
+ const data = {data: 42}; // key length >= 4
3111
+
3112
+ unpacker.unpackMultiple(Buffer.concat([
3113
+ packer.pack(data),
3114
+ packer.pack(data)
3115
+ ]));
3116
+ });
2978
3117
  if (typeof Buffer != 'undefined')
2979
3118
  test('replace data', function(){
2980
3119
  var data1 = {
@@ -3028,7 +3167,7 @@
3028
3167
  prop2: 'more string',
3029
3168
  num: 3,
3030
3169
  };
3031
- let packr = new Packr$1();
3170
+ let packr = new Packr();
3032
3171
  addExtension({
3033
3172
  Class: Extended,
3034
3173
  type: 11,
@@ -3082,7 +3221,7 @@
3082
3221
  prop2: 'more string',
3083
3222
  num: 3,
3084
3223
  };
3085
- let packr = new Packr$1();
3224
+ new Packr();
3086
3225
  addExtension({
3087
3226
  Class: Extended,
3088
3227
  type: 12,
@@ -3106,7 +3245,7 @@
3106
3245
  var decoded = unpack(pack(objectWithProto));
3107
3246
  assert(!decoded.foo);
3108
3247
  var objectsWithProto = [objectWithProto, objectWithProto, objectWithProto, objectWithProto, objectWithProto, objectWithProto];
3109
- let packr = new Packr$1();
3248
+ let packr = new Packr();
3110
3249
  var decoded = packr.unpack(packr.pack(objectsWithProto));
3111
3250
  for (let object of decoded) {
3112
3251
  assert(!decoded.foo);
@@ -3138,7 +3277,7 @@
3138
3277
  object.children[1] = object;
3139
3278
  object.children[2] = object.children[0];
3140
3279
  object.childrenAgain = object.children;
3141
- let packr = new Packr$1({
3280
+ let packr = new Packr({
3142
3281
  moreTypes: true,
3143
3282
  structuredClone: true,
3144
3283
  });
@@ -3163,7 +3302,7 @@
3163
3302
  float32Array: fa,
3164
3303
  uint16Array: new Uint16Array([3,4])
3165
3304
  };
3166
- let packr = new Packr$1({
3305
+ let packr = new Packr({
3167
3306
  moreTypes: true,
3168
3307
  structuredClone: true,
3169
3308
  });
@@ -3181,8 +3320,8 @@
3181
3320
  });
3182
3321
  test('big bundledStrings', function() {
3183
3322
  const MSGPACK_OPTIONS = {bundleStrings: true};
3184
- const packer = new Packr$1(MSGPACK_OPTIONS);
3185
- const unpacker = new Unpackr$1(MSGPACK_OPTIONS);
3323
+ const packer = new Packr(MSGPACK_OPTIONS);
3324
+ const unpacker = new Unpackr(MSGPACK_OPTIONS);
3186
3325
 
3187
3326
  const payload = {
3188
3327
  output: [
@@ -3199,7 +3338,7 @@
3199
3338
  assert.equal(deserialized.output[0].url, payload.output[0].url);
3200
3339
  });
3201
3340
  test('structured clone with bundled strings', function() {
3202
- const packer = new Packr$1({
3341
+ const packer = new Packr({
3203
3342
  structuredClone: true, // both options must be enabled
3204
3343
  bundleStrings: true,
3205
3344
  });
@@ -3230,10 +3369,10 @@
3230
3369
  });
3231
3370
 
3232
3371
  test('separate instances', function() {
3233
- const packr = new Packr$1({
3372
+ const packr = new Packr({
3234
3373
  structures: [['m', 'e'], ['action', 'share']]
3235
3374
  });
3236
- const packr2 = new Packr$1({
3375
+ const packr2 = new Packr({
3237
3376
  structures: [['m', 'e'], ['action', 'share']]
3238
3377
  });
3239
3378
  let packed = packr.pack([{m: 1, e: 2}, {action: 3, share: 4}]);
@@ -3248,7 +3387,7 @@
3248
3387
  }
3249
3388
  let structures = [];
3250
3389
  let savedStructures;
3251
- let packr = new Packr$1({
3390
+ let packr = new Packr({
3252
3391
  structures,
3253
3392
  saveStructures(structures) {
3254
3393
  savedStructures = structures;
@@ -3259,7 +3398,7 @@
3259
3398
  var deserialized = packr.unpack(serializedWith32);
3260
3399
  assert.deepEqual(deserialized, data);
3261
3400
  structures = structures.slice(0, 32);
3262
- packr = new Packr$1({
3401
+ packr = new Packr({
3263
3402
  structures,
3264
3403
  maxSharedStructures: 100,
3265
3404
  saveStructures(structures) {
@@ -3269,7 +3408,7 @@
3269
3408
  deserialized = packr.unpack(serializedWith32);
3270
3409
  assert.deepEqual(deserialized, data);
3271
3410
  structures = structures.slice(0, 32);
3272
- packr = new Packr$1({
3411
+ packr = new Packr({
3273
3412
  structures,
3274
3413
  maxSharedStructures: 100,
3275
3414
  saveStructures(structures) {
@@ -3295,7 +3434,7 @@
3295
3434
  structures.push(['a' + i]);
3296
3435
  }
3297
3436
  const structures2 = [...structures];
3298
- const packr = new Packr$1({
3437
+ const packr = new Packr({
3299
3438
  getStructures() {
3300
3439
  return structures
3301
3440
  },
@@ -3303,7 +3442,7 @@
3303
3442
  },
3304
3443
  maxSharedStructures: 100
3305
3444
  });
3306
- const packr2 = new Packr$1({
3445
+ const packr2 = new Packr({
3307
3446
  getStructures() {
3308
3447
  return structures2
3309
3448
  },
@@ -3353,7 +3492,7 @@
3353
3492
  ancient: new Date(-3532219539133),
3354
3493
  invalidDate: new Date('invalid')
3355
3494
  };
3356
- let packr = new Packr$1();
3495
+ let packr = new Packr();
3357
3496
  var serialized = packr.pack(data);
3358
3497
  var deserialized = packr.unpack(serialized);
3359
3498
  assert.equal(deserialized.map.get(4), 'four');
@@ -3375,7 +3514,7 @@
3375
3514
  date: new Date(1532219539011),
3376
3515
  invalidDate: new Date('invalid')
3377
3516
  };
3378
- let packr = new Packr$1({
3517
+ let packr = new Packr({
3379
3518
  mapsAsObjects: true,
3380
3519
  useTimestamp32: true,
3381
3520
  onInvalidDate: () => 'Custom invalid date'
@@ -3431,7 +3570,7 @@
3431
3570
  c: 0.00000000000352501,
3432
3571
  d: 3252.77,
3433
3572
  };
3434
- let packr = new Packr$1({
3573
+ let packr = new Packr({
3435
3574
  useFloat32: DECIMAL_FIT
3436
3575
  });
3437
3576
  var serialized = packr.pack(data);
@@ -3439,17 +3578,50 @@
3439
3578
  var deserialized = packr.unpack(serialized);
3440
3579
  assert.deepEqual(deserialized, data);
3441
3580
  });
3581
+ test('int64/uint64 should be bigints by default', function() {
3582
+ var data = {
3583
+ a: 325283295382932843n
3584
+ };
3585
+
3586
+ let packr = new Packr();
3587
+ var serialized = packr.pack(data);
3588
+ var deserialized = packr.unpack(serialized);
3589
+ assert.deepEqual(deserialized.a, 325283295382932843n);
3590
+ });
3442
3591
  test('bigint to float', function() {
3443
3592
  var data = {
3444
3593
  a: 325283295382932843n
3445
3594
  };
3446
- let packr = new Packr$1({
3595
+ let packr = new Packr({
3596
+ int64AsType: 'number'
3597
+ });
3598
+ var serialized = packr.pack(data);
3599
+ var deserialized = packr.unpack(serialized);
3600
+ assert.deepEqual(deserialized.a, 325283295382932843);
3601
+ });
3602
+ test('int64AsNumber compatibility', function() {
3603
+ // https://github.com/kriszyp/msgpackr/pull/85
3604
+ var data = {
3605
+ a: 325283295382932843n
3606
+ };
3607
+ let packr = new Packr({
3447
3608
  int64AsNumber: true
3448
3609
  });
3449
3610
  var serialized = packr.pack(data);
3450
3611
  var deserialized = packr.unpack(serialized);
3451
3612
  assert.deepEqual(deserialized.a, 325283295382932843);
3452
3613
  });
3614
+ test('bigint to string', function() {
3615
+ var data = {
3616
+ a: 325283295382932843n,
3617
+ };
3618
+ let packr = new Packr({
3619
+ int64AsType: 'string'
3620
+ });
3621
+ var serialized = packr.pack(data);
3622
+ var deserialized = packr.unpack(serialized);
3623
+ assert.deepEqual(deserialized.a, '325283295382932843');
3624
+ });
3453
3625
  test('numbers', function(){
3454
3626
  var data = {
3455
3627
  bigEncodable: 48978578104322,
@@ -3482,7 +3654,7 @@
3482
3654
  tooBig: 2n**66n
3483
3655
  };
3484
3656
  assert.throws(function(){ serialized = pack(tooBigInt); });
3485
- let packr = new Packr$1({
3657
+ let packr = new Packr({
3486
3658
  largeBigIntToFloat: true
3487
3659
  });
3488
3660
  serialized = packr.pack(tooBigInt);
@@ -3549,14 +3721,14 @@
3549
3721
  var serialized = JSON.stringify(data);
3550
3722
  console.log('JSON size', serialized.length);
3551
3723
  for (var i = 0; i < ITERATIONS; i++) {
3552
- var deserialized = JSON.parse(serialized);
3724
+ JSON.parse(serialized);
3553
3725
  }
3554
3726
  });
3555
3727
  test('performance JSON.stringify', function() {
3556
3728
  var data = sampleData;
3557
3729
  this.timeout(10000);
3558
3730
  for (var i = 0; i < ITERATIONS; i++) {
3559
- var serialized = JSON.stringify(data);
3731
+ JSON.stringify(data);
3560
3732
  }
3561
3733
  });
3562
3734
  test('performance unpack', function() {
@@ -3565,29 +3737,29 @@
3565
3737
  let structures = [];
3566
3738
  var serialized = pack(data);
3567
3739
  console.log('MessagePack size', serialized.length);
3568
- let packr = new Packr$1({ structures, bundleStrings: false });
3740
+ let packr = new Packr({ structures, bundleStrings: false });
3569
3741
  var serialized = packr.pack(data);
3570
3742
  console.log('msgpackr w/ record ext size', serialized.length);
3571
3743
  for (var i = 0; i < ITERATIONS; i++) {
3572
- var deserialized = packr.unpack(serialized);
3744
+ packr.unpack(serialized);
3573
3745
  }
3574
3746
  });
3575
3747
  test('performance pack', function() {
3576
3748
  var data = sampleData;
3577
3749
  this.timeout(10000);
3578
3750
  let structures = [];
3579
- let packr = new Packr$1({ structures, bundleStrings: false });
3751
+ let packr = new Packr({ structures, bundleStrings: false });
3580
3752
  let buffer = typeof Buffer != 'undefined' ? Buffer.alloc(0x10000) : new Uint8Array(0x10000);
3581
3753
 
3582
3754
  for (var i = 0; i < ITERATIONS; i++) {
3583
3755
  //serialized = pack(data, { shared: sharedStructure })
3584
3756
  packr.useBuffer(buffer);
3585
- var serialized = packr.pack(data);
3757
+ packr.pack(data);
3586
3758
  //var serializedGzip = deflateSync(serialized)
3587
3759
  }
3588
3760
  //console.log('serialized', serialized.length, global.propertyComparisons)
3589
3761
  });
3590
3762
  });
3591
3763
 
3592
- }(msgpackr, chai, inspector, fs));
3764
+ })(chai, null, module, fs);
3593
3765
  //# sourceMappingURL=test.js.map