msgpackr 1.11.11 → 2.0.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
@@ -29,7 +29,6 @@
29
29
  C1.name = 'MessagePack 0xC1';
30
30
  var sequentialMode = false;
31
31
  var inlineObjectReadThreshold = 2;
32
- var readStruct$1, onLoadedStructures$1, onSaveState;
33
32
 
34
33
  let Unpackr$1 = class Unpackr {
35
34
  constructor(options) {
@@ -59,10 +58,10 @@
59
58
  unpack(source, options) {
60
59
  if (src) {
61
60
  // re-entrant execution, save the state and restore it after we do this unpack
62
- return saveState$1(() => {
61
+ return saveState(() => {
63
62
  clearSource();
64
- return this ? this.unpack(source, options) : Unpackr$1.prototype.unpack.call(defaultOptions, source, options)
65
- })
63
+ return this ? this.unpack(source, options) : Unpackr$1.prototype.unpack.call(defaultOptions, source, options);
64
+ });
66
65
  }
67
66
  if (!source.buffer && source.constructor === ArrayBuffer)
68
67
  source = typeof Buffer !== 'undefined' ? Buffer.from(source) : new Uint8Array(source);
@@ -88,14 +87,14 @@
88
87
  // if it doesn't have a buffer, maybe it is the wrong type of object
89
88
  src = null;
90
89
  if (source instanceof Uint8Array)
91
- throw error
92
- throw new Error('Source must be a Uint8Array or Buffer but was a ' + ((source && typeof source == 'object') ? source.constructor.name : typeof source))
90
+ throw error;
91
+ throw new Error('Source must be a Uint8Array or Buffer but was a ' + ((source && typeof source == 'object') ? source.constructor.name : typeof source));
93
92
  }
94
93
  if (this instanceof Unpackr$1) {
95
94
  currentUnpackr = this;
96
95
  if (this.structures) {
97
96
  currentStructures = this.structures;
98
- return checkedRead(options)
97
+ return checkedRead();
99
98
  } else if (!currentStructures || currentStructures.length > 0) {
100
99
  currentStructures = [];
101
100
  }
@@ -104,7 +103,7 @@
104
103
  if (!currentStructures || currentStructures.length > 0)
105
104
  currentStructures = [];
106
105
  }
107
- return checkedRead(options)
106
+ return checkedRead();
108
107
  }
109
108
  unpackMultiple(source, forEach) {
110
109
  let values, lastPosition = 0;
@@ -117,7 +116,7 @@
117
116
  while(position$1 < size) {
118
117
  lastPosition = position$1;
119
118
  if (forEach(checkedRead(), lastPosition, position$1) === false) {
120
- return
119
+ return;
121
120
  }
122
121
  }
123
122
  }
@@ -127,20 +126,18 @@
127
126
  lastPosition = position$1;
128
127
  values.push(checkedRead());
129
128
  }
130
- return values
129
+ return values;
131
130
  }
132
131
  } catch(error) {
133
132
  error.lastPosition = lastPosition;
134
133
  error.values = values;
135
- throw error
134
+ throw error;
136
135
  } finally {
137
136
  sequentialMode = false;
138
137
  clearSource();
139
138
  }
140
139
  }
141
140
  _mergeStructures(loadedStructures, existingStructures) {
142
- if (onLoadedStructures$1)
143
- loadedStructures = onLoadedStructures$1.call(this, loadedStructures);
144
141
  loadedStructures = loadedStructures || [];
145
142
  if (Object.isFrozen(loadedStructures))
146
143
  loadedStructures = loadedStructures.map(structure => structure.slice(0));
@@ -164,10 +161,10 @@
164
161
  }
165
162
  }
166
163
  }
167
- return this.structures = loadedStructures
164
+ return this.structures = loadedStructures;
168
165
  }
169
166
  decode(source, options) {
170
- return this.unpack(source, options)
167
+ return this.unpack(source, options);
171
168
  }
172
169
  };
173
170
  function checkedRead(options) {
@@ -177,15 +174,7 @@
177
174
  if (sharedLength < currentStructures.length)
178
175
  currentStructures.length = sharedLength;
179
176
  }
180
- let result;
181
- if (currentUnpackr.randomAccessStructure && src[position$1] < 0x40 && src[position$1] >= 0x20 && readStruct$1) {
182
- result = readStruct$1(src, position$1, srcEnd, currentUnpackr);
183
- src = null; // dispose of this so that recursive unpack calls don't save state
184
- if (!(options && options.lazy) && result)
185
- result = result.toJSON();
186
- position$1 = srcEnd;
187
- } else
188
- result = read();
177
+ let result = read();
189
178
  if (bundledStrings$1) { // bundled strings to skip past
190
179
  position$1 = bundledStrings$1.postBundlePosition;
191
180
  bundledStrings$1 = null;
@@ -205,7 +194,7 @@
205
194
  referenceMap = null;
206
195
  } else if (position$1 > srcEnd) {
207
196
  // over read
208
- throw new Error('Unexpected end of MessagePack data')
197
+ throw new Error('Unexpected end of MessagePack data');
209
198
  } else if (!sequentialMode) {
210
199
  let jsonView;
211
200
  try {
@@ -213,10 +202,10 @@
213
202
  } catch(error) {
214
203
  jsonView = '(JSON view not available ' + error + ')';
215
204
  }
216
- throw new Error('Data read, but end of buffer not reached ' + jsonView)
205
+ throw new Error('Data read, but end of buffer not reached ' + jsonView);
217
206
  }
218
207
  // else more to read, but we are reading sequentially, so don't clear source yet
219
- return result
208
+ return result;
220
209
  } catch(error) {
221
210
  if (currentStructures && currentStructures.restoreStructures)
222
211
  restoreStructures();
@@ -224,7 +213,7 @@
224
213
  if (error instanceof RangeError || error.message.startsWith('Unexpected end of buffer') || position$1 > srcEnd) {
225
214
  error.incomplete = true;
226
215
  }
227
- throw error
216
+ throw error;
228
217
  }
229
218
  }
230
219
 
@@ -240,7 +229,7 @@
240
229
  if (token < 0xa0) {
241
230
  if (token < 0x80) {
242
231
  if (token < 0x40)
243
- return token
232
+ return token;
244
233
  else {
245
234
  let structure = currentStructures[token & 0x3f] ||
246
235
  currentUnpackr.getStructures && loadStructures()[token & 0x3f];
@@ -248,9 +237,9 @@
248
237
  if (!structure.read) {
249
238
  structure.read = createStructureReader(structure, token & 0x3f);
250
239
  }
251
- return structure.read()
240
+ return structure.read();
252
241
  } else
253
- return token
242
+ return token;
254
243
  }
255
244
  } else if (token < 0x90) {
256
245
  // map
@@ -263,13 +252,13 @@
263
252
  key = '__proto_';
264
253
  object[key] = read();
265
254
  }
266
- return object
255
+ return object;
267
256
  } else {
268
257
  let map = new Map();
269
258
  for (let i = 0; i < token; i++) {
270
259
  map.set(read(), read());
271
260
  }
272
- return map
261
+ return map;
273
262
  }
274
263
  } else {
275
264
  token -= 0x90;
@@ -278,91 +267,91 @@
278
267
  array[i] = read();
279
268
  }
280
269
  if (currentUnpackr.freezeData)
281
- return Object.freeze(array)
282
- return array
270
+ return Object.freeze(array);
271
+ return array;
283
272
  }
284
273
  } else if (token < 0xc0) {
285
274
  // fixstr
286
275
  let length = token - 0xa0;
287
276
  if (srcStringEnd >= position$1) {
288
- return srcString.slice(position$1 - srcStringStart, (position$1 += length) - srcStringStart)
277
+ return srcString.slice(position$1 - srcStringStart, (position$1 += length) - srcStringStart);
289
278
  }
290
279
  if (srcStringEnd == 0 && srcEnd < 140) {
291
280
  // for small blocks, avoiding the overhead of the extract call is helpful
292
281
  let string = length < 16 ? shortStringInJS(length) : longStringInJS(length);
293
282
  if (string != null)
294
- return string
283
+ return string;
295
284
  }
296
- return readFixedString(length)
285
+ return readFixedString(length);
297
286
  } else {
298
287
  let value;
299
288
  switch (token) {
300
- case 0xc0: return null
289
+ case 0xc0: return null;
301
290
  case 0xc1:
302
291
  if (bundledStrings$1) {
303
292
  value = read(); // followed by the length of the string in characters (not bytes!)
304
293
  if (value > 0)
305
- return bundledStrings$1[1].slice(bundledStrings$1.position1, bundledStrings$1.position1 += value)
294
+ return bundledStrings$1[1].slice(bundledStrings$1.position1, bundledStrings$1.position1 += value);
306
295
  else
307
- return bundledStrings$1[0].slice(bundledStrings$1.position0, bundledStrings$1.position0 -= value)
296
+ return bundledStrings$1[0].slice(bundledStrings$1.position0, bundledStrings$1.position0 -= value);
308
297
  }
309
298
  return C1; // "never-used", return special object to denote that
310
- case 0xc2: return false
311
- case 0xc3: return true
299
+ case 0xc2: return false;
300
+ case 0xc3: return true;
312
301
  case 0xc4:
313
302
  // bin 8
314
303
  value = src[position$1++];
315
304
  if (value === undefined)
316
- throw new Error('Unexpected end of buffer')
317
- return readBin(value)
305
+ throw new Error('Unexpected end of buffer');
306
+ return readBin(value);
318
307
  case 0xc5:
319
308
  // bin 16
320
309
  value = dataView.getUint16(position$1);
321
310
  position$1 += 2;
322
- return readBin(value)
311
+ return readBin(value);
323
312
  case 0xc6:
324
313
  // bin 32
325
314
  value = dataView.getUint32(position$1);
326
315
  position$1 += 4;
327
- return readBin(value)
316
+ return readBin(value);
328
317
  case 0xc7:
329
318
  // ext 8
330
- return readExt(src[position$1++])
319
+ return readExt(src[position$1++]);
331
320
  case 0xc8:
332
321
  // ext 16
333
322
  value = dataView.getUint16(position$1);
334
323
  position$1 += 2;
335
- return readExt(value)
324
+ return readExt(value);
336
325
  case 0xc9:
337
326
  // ext 32
338
327
  value = dataView.getUint32(position$1);
339
328
  position$1 += 4;
340
- return readExt(value)
329
+ return readExt(value);
341
330
  case 0xca:
342
331
  value = dataView.getFloat32(position$1);
343
332
  if (currentUnpackr.useFloat32 > 2) {
344
333
  // this does rounding of numbers that were encoded in 32-bit float to nearest significant decimal digit that could be preserved
345
334
  let multiplier = mult10[((src[position$1] & 0x7f) << 1) | (src[position$1 + 1] >> 7)];
346
335
  position$1 += 4;
347
- return ((multiplier * value + (value > 0 ? 0.5 : -0.5)) >> 0) / multiplier
336
+ return ((multiplier * value + (value > 0 ? 0.5 : -0.5)) >> 0) / multiplier;
348
337
  }
349
338
  position$1 += 4;
350
- return value
339
+ return value;
351
340
  case 0xcb:
352
341
  value = dataView.getFloat64(position$1);
353
342
  position$1 += 8;
354
- return value
343
+ return value;
355
344
  // uint handlers
356
345
  case 0xcc:
357
- return src[position$1++]
346
+ return src[position$1++];
358
347
  case 0xcd:
359
348
  value = dataView.getUint16(position$1);
360
349
  position$1 += 2;
361
- return value
350
+ return value;
362
351
  case 0xce:
363
352
  value = dataView.getUint32(position$1);
364
353
  position$1 += 4;
365
- return value
354
+ return value;
366
355
  case 0xcf:
367
356
  if (currentUnpackr.int64AsType === 'number') {
368
357
  value = dataView.getUint32(position$1) * 0x100000000;
@@ -375,19 +364,19 @@
375
364
  } else
376
365
  value = dataView.getBigUint64(position$1);
377
366
  position$1 += 8;
378
- return value
367
+ return value;
379
368
 
380
369
  // int handlers
381
370
  case 0xd0:
382
- return dataView.getInt8(position$1++)
371
+ return dataView.getInt8(position$1++);
383
372
  case 0xd1:
384
373
  value = dataView.getInt16(position$1);
385
374
  position$1 += 2;
386
- return value
375
+ return value;
387
376
  case 0xd2:
388
377
  value = dataView.getInt32(position$1);
389
378
  position$1 += 4;
390
- return value
379
+ return value;
391
380
  case 0xd3:
392
381
  if (currentUnpackr.int64AsType === 'number') {
393
382
  value = dataView.getInt32(position$1) * 0x100000000;
@@ -400,96 +389,96 @@
400
389
  } else
401
390
  value = dataView.getBigInt64(position$1);
402
391
  position$1 += 8;
403
- return value
392
+ return value;
404
393
 
405
394
  case 0xd4:
406
395
  // fixext 1
407
396
  value = src[position$1++];
408
397
  if (value == 0x72) {
409
- return recordDefinition(src[position$1++] & 0x3f)
398
+ return recordDefinition(src[position$1++] & 0x3f);
410
399
  } else {
411
400
  let extension = currentExtensions[value];
412
401
  if (extension) {
413
402
  if (extension.read) {
414
403
  position$1++; // skip filler byte
415
- return extension.read(read())
404
+ return extension.read(read());
416
405
  } else if (extension.noBuffer) {
417
406
  position$1++; // skip filler byte
418
- return extension()
407
+ return extension();
419
408
  } else
420
- return extension(src.subarray(position$1, ++position$1))
409
+ return extension(src.subarray(position$1, ++position$1));
421
410
  } else
422
- throw new Error('Unknown extension ' + value)
411
+ throw new Error('Unknown extension ' + value);
423
412
  }
424
413
  case 0xd5:
425
414
  // fixext 2
426
415
  value = src[position$1];
427
416
  if (value == 0x72) {
428
417
  position$1++;
429
- return recordDefinition(src[position$1++] & 0x3f, src[position$1++])
418
+ return recordDefinition(src[position$1++] & 0x3f, src[position$1++]);
430
419
  } else
431
- return readExt(2)
420
+ return readExt(2);
432
421
  case 0xd6:
433
422
  // fixext 4
434
- return readExt(4)
423
+ return readExt(4);
435
424
  case 0xd7:
436
425
  // fixext 8
437
- return readExt(8)
426
+ return readExt(8);
438
427
  case 0xd8:
439
428
  // fixext 16
440
- return readExt(16)
429
+ return readExt(16);
441
430
  case 0xd9:
442
431
  // str 8
443
432
  value = src[position$1++];
444
433
  if (srcStringEnd >= position$1) {
445
- return srcString.slice(position$1 - srcStringStart, (position$1 += value) - srcStringStart)
434
+ return srcString.slice(position$1 - srcStringStart, (position$1 += value) - srcStringStart);
446
435
  }
447
- return readString8(value)
436
+ return readString8(value);
448
437
  case 0xda:
449
438
  // str 16
450
439
  value = dataView.getUint16(position$1);
451
440
  position$1 += 2;
452
441
  if (srcStringEnd >= position$1) {
453
- return srcString.slice(position$1 - srcStringStart, (position$1 += value) - srcStringStart)
442
+ return srcString.slice(position$1 - srcStringStart, (position$1 += value) - srcStringStart);
454
443
  }
455
- return readString16(value)
444
+ return readString16(value);
456
445
  case 0xdb:
457
446
  // str 32
458
447
  value = dataView.getUint32(position$1);
459
448
  position$1 += 4;
460
449
  if (srcStringEnd >= position$1) {
461
- return srcString.slice(position$1 - srcStringStart, (position$1 += value) - srcStringStart)
450
+ return srcString.slice(position$1 - srcStringStart, (position$1 += value) - srcStringStart);
462
451
  }
463
- return readString32(value)
452
+ return readString32(value);
464
453
  case 0xdc:
465
454
  // array 16
466
455
  value = dataView.getUint16(position$1);
467
456
  position$1 += 2;
468
- return readArray(value)
457
+ return readArray(value);
469
458
  case 0xdd:
470
459
  // array 32
471
460
  value = dataView.getUint32(position$1);
472
461
  position$1 += 4;
473
- return readArray(value)
462
+ return readArray(value);
474
463
  case 0xde:
475
464
  // map 16
476
465
  value = dataView.getUint16(position$1);
477
466
  position$1 += 2;
478
- return readMap(value)
467
+ return readMap(value);
479
468
  case 0xdf:
480
469
  // map 32
481
470
  value = dataView.getUint32(position$1);
482
471
  position$1 += 4;
483
- return readMap(value)
472
+ return readMap(value);
484
473
  default: // negative int
485
474
  if (token >= 0xe0)
486
- return token - 0x100
475
+ return token - 0x100;
487
476
  if (token === undefined) {
488
477
  let error = new Error('Unexpected end of MessagePack data');
489
478
  error.incomplete = true;
490
- throw error
479
+ throw error;
491
480
  }
492
- throw new Error('Unknown MessagePack token ' + token)
481
+ throw new Error('Unknown MessagePack token ' + token);
493
482
 
494
483
  }
495
484
  }
@@ -510,7 +499,7 @@
510
499
  }
511
500
  if (structure.highByte === 0)
512
501
  structure.read = createSecondByteReader(firstId, structure.read);
513
- return optimizedReadObject() // second byte is already read, if there is one so immediately read object
502
+ return optimizedReadObject(); // second byte is already read, if there is one so immediately read object
514
503
  }
515
504
  let object = {};
516
505
  for (let i = 0, l = structure.length; i < l; i++) {
@@ -521,38 +510,38 @@
521
510
  }
522
511
  if (currentUnpackr.freezeData)
523
512
  return Object.freeze(object);
524
- return object
513
+ return object;
525
514
  }
526
515
  readObject.count = 0;
527
516
  if (structure.highByte === 0) {
528
- return createSecondByteReader(firstId, readObject)
517
+ return createSecondByteReader(firstId, readObject);
529
518
  }
530
- return readObject
519
+ return readObject;
531
520
  }
532
521
 
533
522
  const createSecondByteReader = (firstId, read0) => {
534
523
  return function() {
535
524
  let highByte = src[position$1++];
536
525
  if (highByte === 0)
537
- return read0()
526
+ return read0();
538
527
  let id = firstId < 32 ? -(firstId + (highByte << 5)) : firstId + (highByte << 5);
539
528
  let structure = currentStructures[id] || loadStructures()[id];
540
529
  if (!structure) {
541
- throw new Error('Record id is not defined for ' + id)
530
+ throw new Error('Record id is not defined for ' + id);
542
531
  }
543
532
  if (!structure.read)
544
533
  structure.read = createStructureReader(structure, firstId);
545
- return structure.read()
546
- }
534
+ return structure.read();
535
+ };
547
536
  };
548
537
 
549
538
  function loadStructures() {
550
- let loadedStructures = saveState$1(() => {
539
+ let loadedStructures = saveState(() => {
551
540
  // save the state in case getStructures modifies our buffer
552
541
  src = null;
553
- return currentUnpackr.getStructures()
542
+ return currentUnpackr.getStructures();
554
543
  });
555
- return currentStructures = currentUnpackr._mergeStructures(loadedStructures, currentStructures)
544
+ return currentStructures = currentUnpackr._mergeStructures(loadedStructures, currentStructures);
556
545
  }
557
546
 
558
547
  var readFixedString = readStringJS;
@@ -570,7 +559,7 @@
570
559
  let string = strings[stringPosition++];
571
560
  if (string == null) {
572
561
  if (bundledStrings$1)
573
- return readStringJS(length)
562
+ return readStringJS(length);
574
563
  let byteOffset = src.byteOffset;
575
564
  let extraction = extractStrings(position$1 - headerLength + byteOffset, srcEnd + byteOffset, src.buffer);
576
565
  if (typeof extraction == 'string') {
@@ -582,30 +571,30 @@
582
571
  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
583
572
  string = strings[0];
584
573
  if (string === undefined)
585
- throw new Error('Unexpected end of buffer')
574
+ throw new Error('Unexpected end of buffer');
586
575
  }
587
576
  }
588
577
  let srcStringLength = string.length;
589
578
  if (srcStringLength <= length) {
590
579
  position$1 += length;
591
- return string
580
+ return string;
592
581
  }
593
582
  srcString = string;
594
583
  srcStringStart = position$1;
595
584
  srcStringEnd = position$1 + srcStringLength;
596
585
  position$1 += length;
597
- return string.slice(0, length) // we know we just want the beginning
598
- }
586
+ return string.slice(0, length); // we know we just want the beginning
587
+ };
599
588
  }
600
589
  }
601
590
  function readStringJS(length) {
602
591
  let result;
603
592
  if (length < 16) {
604
593
  if (result = shortStringInJS(length))
605
- return result
594
+ return result;
606
595
  }
607
596
  if (length > 64 && decoder)
608
- return decoder.decode(src.subarray(position$1, position$1 += length))
597
+ return decoder.decode(src.subarray(position$1, position$1 += length));
609
598
  const end = position$1 + length;
610
599
  const units = [];
611
600
  result = '';
@@ -668,17 +657,7 @@
668
657
  result += fromCharCode.apply(String, units);
669
658
  }
670
659
 
671
- return result
672
- }
673
- function readString(source, start, length) {
674
- let existingSrc = src;
675
- src = source;
676
- position$1 = start;
677
- try {
678
- return readStringJS(length);
679
- } finally {
680
- src = existingSrc;
681
- }
660
+ return result;
682
661
  }
683
662
 
684
663
  function readArray(length) {
@@ -687,8 +666,8 @@
687
666
  array[i] = read();
688
667
  }
689
668
  if (currentUnpackr.freezeData)
690
- return Object.freeze(array)
691
- return array
669
+ return Object.freeze(array);
670
+ return array;
692
671
  }
693
672
 
694
673
  function readMap(length) {
@@ -700,13 +679,13 @@
700
679
  key = '__proto_';
701
680
  object[key] = read();
702
681
  }
703
- return object
682
+ return object;
704
683
  } else {
705
684
  let map = new Map();
706
685
  for (let i = 0; i < length; i++) {
707
686
  map.set(read(), read());
708
687
  }
709
- return map
688
+ return map;
710
689
  }
711
690
  }
712
691
 
@@ -718,40 +697,40 @@
718
697
  const byte = src[position$1++];
719
698
  if ((byte & 0x80) > 0) {
720
699
  position$1 = start;
721
- return
700
+ return;
722
701
  }
723
702
  bytes[i] = byte;
724
703
  }
725
- return fromCharCode.apply(String, bytes)
704
+ return fromCharCode.apply(String, bytes);
726
705
  }
727
706
  function shortStringInJS(length) {
728
707
  if (length < 4) {
729
708
  if (length < 2) {
730
709
  if (length === 0)
731
- return ''
710
+ return '';
732
711
  else {
733
712
  let a = src[position$1++];
734
713
  if ((a & 0x80) > 1) {
735
714
  position$1 -= 1;
736
- return
715
+ return;
737
716
  }
738
- return fromCharCode(a)
717
+ return fromCharCode(a);
739
718
  }
740
719
  } else {
741
720
  let a = src[position$1++];
742
721
  let b = src[position$1++];
743
722
  if ((a & 0x80) > 0 || (b & 0x80) > 0) {
744
723
  position$1 -= 2;
745
- return
724
+ return;
746
725
  }
747
726
  if (length < 3)
748
- return fromCharCode(a, b)
727
+ return fromCharCode(a, b);
749
728
  let c = src[position$1++];
750
729
  if ((c & 0x80) > 0) {
751
730
  position$1 -= 3;
752
- return
731
+ return;
753
732
  }
754
- return fromCharCode(a, b, c)
733
+ return fromCharCode(a, b, c);
755
734
  }
756
735
  } else {
757
736
  let a = src[position$1++];
@@ -760,34 +739,34 @@
760
739
  let d = src[position$1++];
761
740
  if ((a & 0x80) > 0 || (b & 0x80) > 0 || (c & 0x80) > 0 || (d & 0x80) > 0) {
762
741
  position$1 -= 4;
763
- return
742
+ return;
764
743
  }
765
744
  if (length < 6) {
766
745
  if (length === 4)
767
- return fromCharCode(a, b, c, d)
746
+ return fromCharCode(a, b, c, d);
768
747
  else {
769
748
  let e = src[position$1++];
770
749
  if ((e & 0x80) > 0) {
771
750
  position$1 -= 5;
772
- return
751
+ return;
773
752
  }
774
- return fromCharCode(a, b, c, d, e)
753
+ return fromCharCode(a, b, c, d, e);
775
754
  }
776
755
  } else if (length < 8) {
777
756
  let e = src[position$1++];
778
757
  let f = src[position$1++];
779
758
  if ((e & 0x80) > 0 || (f & 0x80) > 0) {
780
759
  position$1 -= 6;
781
- return
760
+ return;
782
761
  }
783
762
  if (length < 7)
784
- return fromCharCode(a, b, c, d, e, f)
763
+ return fromCharCode(a, b, c, d, e, f);
785
764
  let g = src[position$1++];
786
765
  if ((g & 0x80) > 0) {
787
766
  position$1 -= 7;
788
- return
767
+ return;
789
768
  }
790
- return fromCharCode(a, b, c, d, e, f, g)
769
+ return fromCharCode(a, b, c, d, e, f, g);
791
770
  } else {
792
771
  let e = src[position$1++];
793
772
  let f = src[position$1++];
@@ -795,34 +774,34 @@
795
774
  let h = src[position$1++];
796
775
  if ((e & 0x80) > 0 || (f & 0x80) > 0 || (g & 0x80) > 0 || (h & 0x80) > 0) {
797
776
  position$1 -= 8;
798
- return
777
+ return;
799
778
  }
800
779
  if (length < 10) {
801
780
  if (length === 8)
802
- return fromCharCode(a, b, c, d, e, f, g, h)
781
+ return fromCharCode(a, b, c, d, e, f, g, h);
803
782
  else {
804
783
  let i = src[position$1++];
805
784
  if ((i & 0x80) > 0) {
806
785
  position$1 -= 9;
807
- return
786
+ return;
808
787
  }
809
- return fromCharCode(a, b, c, d, e, f, g, h, i)
788
+ return fromCharCode(a, b, c, d, e, f, g, h, i);
810
789
  }
811
790
  } else if (length < 12) {
812
791
  let i = src[position$1++];
813
792
  let j = src[position$1++];
814
793
  if ((i & 0x80) > 0 || (j & 0x80) > 0) {
815
794
  position$1 -= 10;
816
- return
795
+ return;
817
796
  }
818
797
  if (length < 11)
819
- return fromCharCode(a, b, c, d, e, f, g, h, i, j)
798
+ return fromCharCode(a, b, c, d, e, f, g, h, i, j);
820
799
  let k = src[position$1++];
821
800
  if ((k & 0x80) > 0) {
822
801
  position$1 -= 11;
823
- return
802
+ return;
824
803
  }
825
- return fromCharCode(a, b, c, d, e, f, g, h, i, j, k)
804
+ return fromCharCode(a, b, c, d, e, f, g, h, i, j, k);
826
805
  } else {
827
806
  let i = src[position$1++];
828
807
  let j = src[position$1++];
@@ -830,34 +809,34 @@
830
809
  let l = src[position$1++];
831
810
  if ((i & 0x80) > 0 || (j & 0x80) > 0 || (k & 0x80) > 0 || (l & 0x80) > 0) {
832
811
  position$1 -= 12;
833
- return
812
+ return;
834
813
  }
835
814
  if (length < 14) {
836
815
  if (length === 12)
837
- return fromCharCode(a, b, c, d, e, f, g, h, i, j, k, l)
816
+ return fromCharCode(a, b, c, d, e, f, g, h, i, j, k, l);
838
817
  else {
839
818
  let m = src[position$1++];
840
819
  if ((m & 0x80) > 0) {
841
820
  position$1 -= 13;
842
- return
821
+ return;
843
822
  }
844
- return fromCharCode(a, b, c, d, e, f, g, h, i, j, k, l, m)
823
+ return fromCharCode(a, b, c, d, e, f, g, h, i, j, k, l, m);
845
824
  }
846
825
  } else {
847
826
  let m = src[position$1++];
848
827
  let n = src[position$1++];
849
828
  if ((m & 0x80) > 0 || (n & 0x80) > 0) {
850
829
  position$1 -= 14;
851
- return
830
+ return;
852
831
  }
853
832
  if (length < 15)
854
- return fromCharCode(a, b, c, d, e, f, g, h, i, j, k, l, m, n)
833
+ return fromCharCode(a, b, c, d, e, f, g, h, i, j, k, l, m, n);
855
834
  let o = src[position$1++];
856
835
  if ((o & 0x80) > 0) {
857
836
  position$1 -= 15;
858
- return
837
+ return;
859
838
  }
860
- return fromCharCode(a, b, c, d, e, f, g, h, i, j, k, l, m, n, o)
839
+ return fromCharCode(a, b, c, d, e, f, g, h, i, j, k, l, m, n, o);
861
840
  }
862
841
  }
863
842
  }
@@ -875,22 +854,22 @@
875
854
  case 0xd9:
876
855
  // str 8
877
856
  length = src[position$1++];
878
- break
857
+ break;
879
858
  case 0xda:
880
859
  // str 16
881
860
  length = dataView.getUint16(position$1);
882
861
  position$1 += 2;
883
- break
862
+ break;
884
863
  case 0xdb:
885
864
  // str 32
886
865
  length = dataView.getUint32(position$1);
887
866
  position$1 += 4;
888
- break
867
+ break;
889
868
  default:
890
- throw new Error('Expected string')
869
+ throw new Error('Expected string');
891
870
  }
892
871
  }
893
- return readStringJS(length)
872
+ return readStringJS(length);
894
873
  }
895
874
 
896
875
 
@@ -898,7 +877,7 @@
898
877
  return currentUnpackr.copyBuffers ?
899
878
  // specifically use the copying slice (not the node one)
900
879
  Uint8Array.prototype.slice.call(src, position$1, position$1 += length) :
901
- src.subarray(position$1, position$1 += length)
880
+ src.subarray(position$1, position$1 += length);
902
881
  }
903
882
  function readExt(length) {
904
883
  let type = src[position$1++];
@@ -911,10 +890,10 @@
911
890
  } finally {
912
891
  position$1 = end;
913
892
  }
914
- })
893
+ });
915
894
  }
916
895
  else
917
- throw new Error('Unknown extension type ' + type)
896
+ throw new Error('Unknown extension type ' + type);
918
897
  }
919
898
 
920
899
  var keyCache = new Array(4096);
@@ -924,12 +903,12 @@
924
903
  // fixstr, potentially use key cache
925
904
  length = length - 0xa0;
926
905
  if (srcStringEnd >= position$1) // if it has been extracted, must use it (and faster anyway)
927
- return srcString.slice(position$1 - srcStringStart, (position$1 += length) - srcStringStart)
906
+ return srcString.slice(position$1 - srcStringStart, (position$1 += length) - srcStringStart);
928
907
  else if (!(srcStringEnd == 0 && srcEnd < 180))
929
- return readFixedString(length)
908
+ return readFixedString(length);
930
909
  } else { // not cacheable, go back and do a standard read
931
910
  position$1--;
932
- return asSafeString(read())
911
+ return asSafeString(read());
933
912
  }
934
913
  let key = ((length << 5) ^ (length > 1 ? dataView.getUint16(position$1) : length > 0 ? src[position$1] : 0)) & 0xfff;
935
914
  let entry = keyCache[key];
@@ -942,7 +921,7 @@
942
921
  chunk = dataView.getUint32(checkPosition);
943
922
  if (chunk != entry[i++]) {
944
923
  checkPosition = 0x70000000;
945
- break
924
+ break;
946
925
  }
947
926
  checkPosition += 4;
948
927
  }
@@ -951,12 +930,12 @@
951
930
  chunk = src[checkPosition++];
952
931
  if (chunk != entry[i++]) {
953
932
  checkPosition = 0x70000000;
954
- break
933
+ break;
955
934
  }
956
935
  }
957
936
  if (checkPosition === end) {
958
937
  position$1 = checkPosition;
959
- return entry.string
938
+ return entry.string;
960
939
  }
961
940
  end -= 3;
962
941
  checkPosition = position$1;
@@ -977,8 +956,8 @@
977
956
  // for small blocks, avoiding the overhead of the extract call is helpful
978
957
  let string = length < 16 ? shortStringInJS(length) : longStringInJS(length);
979
958
  if (string != null)
980
- return entry.string = string
981
- return entry.string = readFixedString(length)
959
+ return entry.string = string;
960
+ return entry.string = readFixedString(length);
982
961
  }
983
962
 
984
963
  function asSafeString(property) {
@@ -1009,7 +988,7 @@
1009
988
  }
1010
989
  currentStructures[id] = structure;
1011
990
  structure.read = createStructureReader(structure, firstByte);
1012
- return structure.read()
991
+ return structure.read();
1013
992
  };
1014
993
  currentExtensions[0] = () => {}; // notepack defines extension 0 to mean undefined, so use that as the default here
1015
994
  currentExtensions[0].noBuffer = true;
@@ -1031,17 +1010,17 @@
1031
1010
  out <<= BigInt(64);
1032
1011
  out |= view.getBigUint64(i);
1033
1012
  }
1034
- return out
1013
+ return out;
1035
1014
  }
1036
1015
  // if (length === 8) return view.getBigUint64(start)
1037
1016
  let middle = start + (length >> 4 << 3);
1038
1017
  let left = decode(start, middle);
1039
1018
  let right = decode(middle, end);
1040
- return (left << BigInt((end - middle) * 8)) | right
1019
+ return (left << BigInt((end - middle) * 8)) | right;
1041
1020
  };
1042
1021
  head = (head << BigInt((view.byteLength - headLength) * 8)) | decode(headLength, view.byteLength);
1043
1022
  }
1044
- return head
1023
+ return head;
1045
1024
  };
1046
1025
 
1047
1026
  let errors = {
@@ -1052,14 +1031,14 @@
1052
1031
  if (!errors[data[0]]) {
1053
1032
  let error = Error(data[1], { cause: data[2] });
1054
1033
  error.name = data[0];
1055
- return error
1034
+ return error;
1056
1035
  }
1057
- return errors[data[0]](data[1], { cause: data[2] })
1036
+ return errors[data[0]](data[1], { cause: data[2] });
1058
1037
  };
1059
1038
 
1060
1039
  currentExtensions[0x69] = (data) => {
1061
1040
  // id extension (for structured clones)
1062
- if (currentUnpackr.structuredClone === false) throw new Error('Structured clone extension is disabled')
1041
+ if (currentUnpackr.structuredClone === false) throw new Error('Structured clone extension is disabled');
1063
1042
  let id = dataView.getUint32(position$1 - 4);
1064
1043
  if (!referenceMap)
1065
1044
  referenceMap = new Map();
@@ -1080,7 +1059,7 @@
1080
1059
  let targetProperties = read(); // read the next value as the target object to id
1081
1060
  if (!refEntry.used) {
1082
1061
  // no cycle, can just use the returned read object
1083
- return refEntry.target = targetProperties // replace the placeholder with the real one
1062
+ return refEntry.target = targetProperties; // replace the placeholder with the real one
1084
1063
  } else {
1085
1064
  // there is a cycle, so we have to assign properties to original target
1086
1065
  Object.assign(target, targetProperties);
@@ -1091,16 +1070,16 @@
1091
1070
  for (let [k, v] of targetProperties.entries()) target.set(k, v);
1092
1071
  if (target instanceof Set)
1093
1072
  for (let i of Array.from(targetProperties)) target.add(i);
1094
- return target
1073
+ return target;
1095
1074
  };
1096
1075
 
1097
1076
  currentExtensions[0x70] = (data) => {
1098
1077
  // pointer extension (for structured clones)
1099
- if (currentUnpackr.structuredClone === false) throw new Error('Structured clone extension is disabled')
1078
+ if (currentUnpackr.structuredClone === false) throw new Error('Structured clone extension is disabled');
1100
1079
  let id = dataView.getUint32(position$1 - 4);
1101
1080
  let refEntry = referenceMap.get(id);
1102
1081
  refEntry.used = true;
1103
- return refEntry.target
1082
+ return refEntry.target;
1104
1083
  };
1105
1084
 
1106
1085
  currentExtensions[0x73] = () => new Set(read());
@@ -1115,15 +1094,15 @@
1115
1094
 
1116
1095
  let typedArrayName = typedArrays[typeCode];
1117
1096
  if (!typedArrayName) {
1118
- if (typeCode === 16) return buffer
1119
- if (typeCode === 17) return new DataView(buffer)
1120
- throw new Error('Could not find typed array for code ' + typeCode)
1097
+ if (typeCode === 16) return buffer;
1098
+ if (typeCode === 17) return new DataView(buffer);
1099
+ throw new Error('Could not find typed array for code ' + typeCode);
1121
1100
  }
1122
- return new glbl[typedArrayName](buffer)
1101
+ return new glbl[typedArrayName](buffer);
1123
1102
  };
1124
1103
  currentExtensions[0x78] = () => {
1125
1104
  let data = read();
1126
- return new RegExp(data[0], data[1])
1105
+ return new RegExp(data[0], data[1]);
1127
1106
  };
1128
1107
  const TEMP_BUNDLE = [];
1129
1108
  currentExtensions[0x62] = (data) => {
@@ -1136,30 +1115,28 @@
1136
1115
  bundledStrings$1.position1 = 0;
1137
1116
  bundledStrings$1.postBundlePosition = position$1;
1138
1117
  position$1 = dataPosition;
1139
- return read()
1118
+ return read();
1140
1119
  };
1141
1120
 
1142
1121
  currentExtensions[0xff] = (data) => {
1143
1122
  // 32-bit date extension
1144
1123
  if (data.length == 4)
1145
- return new Date((data[0] * 0x1000000 + (data[1] << 16) + (data[2] << 8) + data[3]) * 1000)
1124
+ return new Date((data[0] * 0x1000000 + (data[1] << 16) + (data[2] << 8) + data[3]) * 1000);
1146
1125
  else if (data.length == 8)
1147
1126
  return new Date(
1148
1127
  ((data[0] << 22) + (data[1] << 14) + (data[2] << 6) + (data[3] >> 2)) / 1000000 +
1149
- ((data[3] & 0x3) * 0x100000000 + data[4] * 0x1000000 + (data[5] << 16) + (data[6] << 8) + data[7]) * 1000)
1128
+ ((data[3] & 0x3) * 0x100000000 + data[4] * 0x1000000 + (data[5] << 16) + (data[6] << 8) + data[7]) * 1000);
1150
1129
  else if (data.length == 12)
1151
1130
  return new Date(
1152
1131
  ((data[0] << 24) + (data[1] << 16) + (data[2] << 8) + data[3]) / 1000000 +
1153
- (((data[4] & 0x80) ? -0x1000000000000 : 0) + data[6] * 0x10000000000 + data[7] * 0x100000000 + data[8] * 0x1000000 + (data[9] << 16) + (data[10] << 8) + data[11]) * 1000)
1132
+ (((data[4] & 0x80) ? -0x1000000000000 : 0) + data[6] * 0x10000000000 + data[7] * 0x100000000 + data[8] * 0x1000000 + (data[9] << 16) + (data[10] << 8) + data[11]) * 1000);
1154
1133
  else
1155
- return new Date('invalid')
1134
+ return new Date('invalid');
1156
1135
  };
1157
1136
  // registration of bulk record definition?
1158
1137
  // currentExtensions[0x52] = () =>
1159
1138
 
1160
- function saveState$1(callback) {
1161
- if (onSaveState)
1162
- onSaveState();
1139
+ function saveState(callback) {
1163
1140
  let savedSrcEnd = srcEnd;
1164
1141
  let savedPosition = position$1;
1165
1142
  let savedStringPosition = stringPosition;
@@ -1192,7 +1169,7 @@
1192
1169
  currentStructures.splice(0, currentStructures.length, ...savedStructuresContents);
1193
1170
  currentUnpackr = savedPackr;
1194
1171
  dataView = new DataView(src.buffer, src.byteOffset, src.byteLength);
1195
- return value
1172
+ return value;
1196
1173
  }
1197
1174
  function clearSource() {
1198
1175
  src = null;
@@ -1226,30 +1203,24 @@
1226
1203
  function roundFloat32$1(float32Number) {
1227
1204
  f32Array[0] = float32Number;
1228
1205
  let multiplier = mult10[((u8Array[3] & 0x7f) << 1) | (u8Array[2] >> 7)];
1229
- return ((multiplier * float32Number + (float32Number > 0 ? 0.5 : -0.5)) >> 0) / multiplier
1230
- }
1231
- function setReadStruct(updatedReadStruct, loadedStructs, saveState) {
1232
- readStruct$1 = updatedReadStruct;
1233
- onLoadedStructures$1 = loadedStructs;
1234
- onSaveState = saveState;
1206
+ return ((multiplier * float32Number + (float32Number > 0 ? 0.5 : -0.5)) >> 0) / multiplier;
1235
1207
  }
1236
1208
 
1237
- let textEncoder$1;
1209
+ let textEncoder;
1238
1210
  try {
1239
- textEncoder$1 = new TextEncoder();
1211
+ textEncoder = new TextEncoder();
1240
1212
  } catch (error) {}
1241
1213
  let extensions, extensionClasses;
1242
- const hasNodeBuffer$1 = typeof Buffer !== 'undefined';
1243
- const ByteArrayAllocate = hasNodeBuffer$1 ?
1244
- function(length) { return Buffer.allocUnsafeSlow(length) } : Uint8Array;
1245
- const ByteArray = hasNodeBuffer$1 ? Buffer : Uint8Array;
1246
- const MAX_BUFFER_SIZE = hasNodeBuffer$1 ? 0x100000000 : 0x7fd00000;
1214
+ const hasNodeBuffer = typeof Buffer !== 'undefined';
1215
+ const ByteArrayAllocate = hasNodeBuffer ?
1216
+ function(length) { return Buffer.allocUnsafeSlow(length); } : Uint8Array;
1217
+ const ByteArray = hasNodeBuffer ? Buffer : Uint8Array;
1218
+ const MAX_BUFFER_SIZE = hasNodeBuffer ? 0x100000000 : 0x7fd00000;
1247
1219
  let target, keysTarget;
1248
1220
  let targetView;
1249
1221
  let position = 0;
1250
1222
  let safeEnd;
1251
1223
  let bundledStrings = null;
1252
- let writeStructSlots;
1253
1224
  const MAX_BUNDLE_SIZE = 0x5500; // maximum characters such that the encoded bytes fits in 16 bits.
1254
1225
  const hasNonLatin = /[\u0080-\uFFFF]/;
1255
1226
  const RECORD_SYMBOL = Symbol('record-id');
@@ -1262,10 +1233,10 @@
1262
1233
  let structures;
1263
1234
  let referenceMap;
1264
1235
  let encodeUtf8 = ByteArray.prototype.utf8Write ? function(string, position) {
1265
- return target.utf8Write(string, position, target.byteLength - position)
1266
- } : (textEncoder$1 && textEncoder$1.encodeInto) ?
1236
+ return target.utf8Write(string, position, target.byteLength - position);
1237
+ } : (textEncoder && textEncoder.encodeInto) ?
1267
1238
  function(string, position) {
1268
- return textEncoder$1.encodeInto(string, target.subarray(position)).written
1239
+ return textEncoder.encodeInto(string, target.subarray(position)).written;
1269
1240
  } : false;
1270
1241
 
1271
1242
  let packr = this;
@@ -1277,7 +1248,7 @@
1277
1248
  if (maxSharedStructures == null)
1278
1249
  maxSharedStructures = hasSharedStructures ? 32 : 0;
1279
1250
  if (maxSharedStructures > 8160)
1280
- throw new Error('Maximum maxSharedStructure is 8160')
1251
+ throw new Error('Maximum maxSharedStructure is 8160');
1281
1252
  if (options.structuredClone && options.moreTypes == undefined) {
1282
1253
  this.moreTypes = true;
1283
1254
  }
@@ -1291,7 +1262,7 @@
1291
1262
  let sharedLimitId = maxSharedStructures + 0x40;
1292
1263
  let maxStructureId = maxSharedStructures + maxOwnStructures + 0x40;
1293
1264
  if (maxStructureId > 8256) {
1294
- throw new Error('Maximum maxSharedStructure + maxOwnStructure is 8192')
1265
+ throw new Error('Maximum maxSharedStructure + maxOwnStructure is 8192');
1295
1266
  }
1296
1267
  let recordIdsToRemove = [];
1297
1268
  let transitionsCount = 0;
@@ -1327,7 +1298,7 @@
1327
1298
  let sharedLength = structures.sharedLength || 0;
1328
1299
  if (sharedLength > maxSharedStructures) {
1329
1300
  //if (maxSharedStructures <= 32 && structures.sharedLength > 32) // TODO: could support this, but would need to update the limit ids
1330
- throw new Error('Shared structures is larger than maximum shared structures, try increasing maxSharedStructures to ' + structures.sharedLength)
1301
+ throw new Error('Shared structures is larger than maximum shared structures, try increasing maxSharedStructures to ' + structures.sharedLength);
1331
1302
  }
1332
1303
  if (!structures.transitions) {
1333
1304
  // rebuild our structure transitions
@@ -1335,7 +1306,7 @@
1335
1306
  for (let i = 0; i < sharedLength; i++) {
1336
1307
  let keys = structures[i];
1337
1308
  if (!keys)
1338
- continue
1309
+ continue;
1339
1310
  let nextTransition, transition = structures.transitions;
1340
1311
  for (let j = 0, l = keys.length; j < l; j++) {
1341
1312
  let key = keys[j];
@@ -1357,14 +1328,7 @@
1357
1328
  hasSharedUpdate = false;
1358
1329
  let encodingError;
1359
1330
  try {
1360
- if (packr.randomAccessStructure && value && typeof value === 'object') {
1361
- if (value.constructor === Object) writeStruct(value); // simple object
1362
- else if (value.constructor !== Map && !Array.isArray(value) && !extensionClasses.some(extClass => value instanceof extClass)) {
1363
- // allow user classes, if they don't need special handling (but do use toJSON if available)
1364
- writeStruct(value.toJSON ? value.toJSON() : value);
1365
- } else pack(value);
1366
- } else
1367
- pack(value);
1331
+ pack(value);
1368
1332
  let lastBundle = bundledStrings;
1369
1333
  if (bundledStrings)
1370
1334
  writeBundles(start, pack, 0);
@@ -1401,15 +1365,15 @@
1401
1365
  packr.offset = position;
1402
1366
  let serialized = insertIds(target.subarray(start, position), idsToInsert);
1403
1367
  referenceMap = null;
1404
- return serialized
1368
+ return serialized;
1405
1369
  }
1406
1370
  packr.offset = position; // update the offset so next serialization doesn't write over our buffer, but can continue writing to same buffer sequentially
1407
1371
  if (encodeOptions & REUSE_BUFFER_MODE) {
1408
1372
  target.start = start;
1409
1373
  target.end = position;
1410
- return target
1374
+ return target;
1411
1375
  }
1412
- return target.subarray(start, position) // position can change if we call pack again in saveStructures, so we get the buffer now
1376
+ return target.subarray(start, position); // position can change if we call pack again in saveStructures, so we get the buffer now
1413
1377
  } catch(error) {
1414
1378
  encodingError = error;
1415
1379
  throw error;
@@ -1420,16 +1384,16 @@
1420
1384
  let sharedLength = structures.sharedLength || 0;
1421
1385
  // we can't rely on start/end with REUSE_BUFFER_MODE since they will (probably) change when we save
1422
1386
  let returnBuffer = target.subarray(start, position);
1423
- let newSharedData = prepareStructures$1(structures, packr);
1387
+ let newSharedData = prepareStructures(structures, packr);
1424
1388
  if (!encodingError) { // TODO: If there is an encoding error, should make the structures as uninitialized so they get rebuilt next time
1425
1389
  if (packr.saveStructures(newSharedData, newSharedData.isCompatible) === false) {
1426
1390
  // get updated structures and try again if the update failed
1427
- return packr.pack(value, encodeOptions)
1391
+ return packr.pack(value, encodeOptions);
1428
1392
  }
1429
1393
  packr.lastNamedStructuresLength = sharedLength;
1430
1394
  // don't keep large buffers around
1431
1395
  if (target.length > 0x40000000) target = null;
1432
- return returnBuffer
1396
+ return returnBuffer;
1433
1397
  }
1434
1398
  }
1435
1399
  }
@@ -1515,7 +1479,7 @@
1515
1479
  bundledStrings[twoByte ? 0 : 1] += value;
1516
1480
  target[position++] = 0xc1;
1517
1481
  pack(twoByte ? -strLength : strLength);
1518
- return
1482
+ return;
1519
1483
  }
1520
1484
  let headerSize;
1521
1485
  // first we estimate the header size, so we can write to the correct location
@@ -1589,7 +1553,7 @@
1589
1553
  } else if (type === 'number') {
1590
1554
  if (value >>> 0 === value) {// positive integer, 32-bit or less
1591
1555
  // positive uint
1592
- if (value < 0x20 || (value < 0x80 && this.useRecords === false) || (value < 0x40 && !this.randomAccessStructure)) {
1556
+ if (value < 0x40 || (value < 0x80 && this.useRecords === false)) {
1593
1557
  target[position++] = value;
1594
1558
  } else if (value < 0x100) {
1595
1559
  target[position++] = 0xcc;
@@ -1628,7 +1592,7 @@
1628
1592
  // this checks for rounding of numbers that were encoded in 32-bit float to nearest significant decimal digit that could be preserved
1629
1593
  ((xShifted = value * mult10[((target[position] & 0x7f) << 1) | (target[position + 1] >> 7)]) >> 0) === xShifted) {
1630
1594
  position += 4;
1631
- return
1595
+ return;
1632
1596
  } else
1633
1597
  position--; // move back into position for writing a double
1634
1598
  }
@@ -1651,7 +1615,7 @@
1651
1615
  target[position++] = 0x70; // "p" for pointer
1652
1616
  targetView.setUint32(position, referee.id);
1653
1617
  position += 4;
1654
- return
1618
+ return;
1655
1619
  } else
1656
1620
  referenceMap.set(value, { offset: position - start });
1657
1621
  }
@@ -1701,7 +1665,7 @@
1701
1665
  } else {
1702
1666
  pack(writeResult);
1703
1667
  }
1704
- return
1668
+ return;
1705
1669
  }
1706
1670
  let currentTarget = target;
1707
1671
  let currentTargetView = targetView;
@@ -1718,7 +1682,7 @@
1718
1682
  makeRoom(position);
1719
1683
  return {
1720
1684
  target, targetView, position: position - size
1721
- }
1685
+ };
1722
1686
  }, pack);
1723
1687
  } finally {
1724
1688
  // restore current target information (unless already restored)
@@ -1734,7 +1698,7 @@
1734
1698
  makeRoom(result.length + position);
1735
1699
  position = writeExtensionData(result, target, position, extension.type);
1736
1700
  }
1737
- return
1701
+ return;
1738
1702
  }
1739
1703
  }
1740
1704
  // check isArray after extensions, because extensions can extend Array
@@ -1746,7 +1710,7 @@
1746
1710
  const json = value.toJSON();
1747
1711
  // if for some reason value.toJSON returns itself it'll loop forever
1748
1712
  if (json !== value)
1749
- return pack(json)
1713
+ return pack(json);
1750
1714
  }
1751
1715
 
1752
1716
  // if there is a writeFunction, use it, otherwise just encode as undefined
@@ -1785,7 +1749,7 @@
1785
1749
  let chunks = [];
1786
1750
  while (true) {
1787
1751
  chunks.push(value & mask);
1788
- if ((value >> BigInt(63)) === empty) break
1752
+ if ((value >> BigInt(63)) === empty) break;
1789
1753
  value >>= BigInt(64);
1790
1754
  }
1791
1755
 
@@ -1800,7 +1764,7 @@
1800
1764
  string = '00' + string;
1801
1765
  }
1802
1766
 
1803
- if (hasNodeBuffer$1) {
1767
+ if (hasNodeBuffer) {
1804
1768
  array = Buffer.from(string, 'hex');
1805
1769
  } else {
1806
1770
  array = new Uint8Array(string.length / 2);
@@ -1817,11 +1781,11 @@
1817
1781
  if (array.length + position > safeEnd)
1818
1782
  makeRoom(array.length + position);
1819
1783
  position = writeExtensionData(array, target, position, 0x42);
1820
- return
1784
+ return;
1821
1785
  } else {
1822
1786
  throw new RangeError(value + ' was too large to fit in MessagePack 64-bit integer format, use' +
1823
1787
  ' useBigIntExtension, or set largeBigIntToFloat to convert to float-64, or set' +
1824
- ' largeBigIntToString to convert to string')
1788
+ ' largeBigIntToString to convert to string');
1825
1789
  }
1826
1790
  }
1827
1791
  position += 8;
@@ -1834,7 +1798,7 @@
1834
1798
  target[position++] = 0;
1835
1799
  }
1836
1800
  } else {
1837
- throw new Error('Unknown type: ' + type)
1801
+ throw new Error('Unknown type: ' + type);
1838
1802
  }
1839
1803
  };
1840
1804
 
@@ -1985,7 +1949,7 @@
1985
1949
  if (end > 0x1000000) {
1986
1950
  // special handling for really large buffers
1987
1951
  if ((end - start) > MAX_BUFFER_SIZE)
1988
- throw new Error('Packed buffer would be larger than maximum buffer size')
1952
+ throw new Error('Packed buffer would be larger than maximum buffer size');
1989
1953
  newSize = Math.min(MAX_BUFFER_SIZE,
1990
1954
  Math.round(Math.max((end - start) * (end > 0x4000000 ? 1.25 : 2), 0x400000) / 0x1000) * 0x1000);
1991
1955
  } else // faster handling for smaller buffers
@@ -2000,7 +1964,7 @@
2000
1964
  position -= start;
2001
1965
  start = 0;
2002
1966
  safeEnd = newBuffer.length - 10;
2003
- return target = newBuffer
1967
+ return target = newBuffer;
2004
1968
  };
2005
1969
  const newRecord = (transition, keys, newTransitions) => {
2006
1970
  let recordId = structures.nextId;
@@ -2082,23 +2046,6 @@
2082
2046
  target[insertionOffset + start] = keysTarget[0];
2083
2047
  }
2084
2048
  };
2085
- const writeStruct = (object) => {
2086
- let newPosition = writeStructSlots(object, target, start, position, structures, makeRoom, (value, newPosition, notifySharedUpdate) => {
2087
- if (notifySharedUpdate)
2088
- return hasSharedUpdate = true;
2089
- position = newPosition;
2090
- let startTarget = target;
2091
- pack(value);
2092
- resetStructures();
2093
- if (startTarget !== target) {
2094
- return { position, targetView, target }; // indicate the buffer was re-allocated
2095
- }
2096
- return position;
2097
- }, this);
2098
- if (newPosition === 0) // bail and go to a msgpack object
2099
- return writeObject(object);
2100
- position = newPosition;
2101
- };
2102
2049
  }
2103
2050
  useBuffer(buffer) {
2104
2051
  // this means we are finished using our own buffer and we can write over it safely
@@ -2116,8 +2063,6 @@
2116
2063
  clearSharedData() {
2117
2064
  if (this.structures)
2118
2065
  this.structures = [];
2119
- if (this.typedStructs)
2120
- this.typedStructs = [];
2121
2066
  }
2122
2067
  };
2123
2068
 
@@ -2141,7 +2086,7 @@
2141
2086
  } else if (isNaN(seconds)) {
2142
2087
  if (this.onInvalidDate) {
2143
2088
  allocateForWrite(0);
2144
- return pack(this.onInvalidDate())
2089
+ return pack(this.onInvalidDate());
2145
2090
  }
2146
2091
  // Intentionally invalid timestamp
2147
2092
  let { target, targetView, position} = allocateForWrite(3);
@@ -2162,7 +2107,7 @@
2162
2107
  pack(set, allocateForWrite, pack) {
2163
2108
  if (this.setAsEmptyObject) {
2164
2109
  allocateForWrite(0);
2165
- return pack({})
2110
+ return pack({});
2166
2111
  }
2167
2112
  let array = Array.from(set);
2168
2113
  let { target, position} = allocateForWrite(this.moreTypes ? 3 : 0);
@@ -2198,7 +2143,7 @@
2198
2143
  if (this.moreTypes)
2199
2144
  writeExtBuffer(arrayBuffer, 0x10, allocateForWrite);
2200
2145
  else
2201
- writeBuffer(hasNodeBuffer$1 ? Buffer.from(arrayBuffer) : new Uint8Array(arrayBuffer), allocateForWrite);
2146
+ writeBuffer(hasNodeBuffer ? Buffer.from(arrayBuffer) : new Uint8Array(arrayBuffer), allocateForWrite);
2202
2147
  }
2203
2148
  }, {
2204
2149
  pack(typedArray, allocateForWrite) {
@@ -2213,7 +2158,7 @@
2213
2158
  if (this.moreTypes)
2214
2159
  writeExtBuffer(arrayBuffer, 0x11, allocateForWrite);
2215
2160
  else
2216
- writeBuffer(hasNodeBuffer$1 ? Buffer.from(arrayBuffer) : new Uint8Array(arrayBuffer), allocateForWrite);
2161
+ writeBuffer(hasNodeBuffer ? Buffer.from(arrayBuffer) : new Uint8Array(arrayBuffer), allocateForWrite);
2217
2162
  }
2218
2163
  }, {
2219
2164
  pack(c1, allocateForWrite) { // specific 0xC1 object
@@ -2270,19 +2215,19 @@
2270
2215
  switch (length) {
2271
2216
  case 1:
2272
2217
  target[position++] = 0xd4;
2273
- break
2218
+ break;
2274
2219
  case 2:
2275
2220
  target[position++] = 0xd5;
2276
- break
2221
+ break;
2277
2222
  case 4:
2278
2223
  target[position++] = 0xd6;
2279
- break
2224
+ break;
2280
2225
  case 8:
2281
2226
  target[position++] = 0xd7;
2282
- break
2227
+ break;
2283
2228
  case 16:
2284
2229
  target[position++] = 0xd8;
2285
- break
2230
+ break;
2286
2231
  default:
2287
2232
  if (length < 0x100) {
2288
2233
  target[position++] = 0xc7;
@@ -2302,7 +2247,7 @@
2302
2247
  target[position++] = type;
2303
2248
  target.set(result, position);
2304
2249
  position += length;
2305
- return position
2250
+ return position;
2306
2251
  }
2307
2252
 
2308
2253
  function insertIds(serialized, idsToInsert) {
@@ -2324,7 +2269,7 @@
2324
2269
  serialized[position++] = id & 0xff;
2325
2270
  lastEnd = offset;
2326
2271
  }
2327
- return serialized
2272
+ return serialized;
2328
2273
  }
2329
2274
 
2330
2275
  function writeBundles(start, pack, incrementPosition) {
@@ -2341,26 +2286,22 @@
2341
2286
  function addExtension$1(extension) {
2342
2287
  if (extension.Class) {
2343
2288
  if (!extension.pack && !extension.write)
2344
- throw new Error('Extension has no pack or write function')
2289
+ throw new Error('Extension has no pack or write function');
2345
2290
  if (extension.pack && !extension.type)
2346
- throw new Error('Extension has no type (numeric code to identify the extension)')
2291
+ throw new Error('Extension has no type (numeric code to identify the extension)');
2347
2292
  extensionClasses.unshift(extension.Class);
2348
2293
  extensions.unshift(extension);
2349
2294
  }
2350
2295
  addExtension$2(extension);
2351
2296
  }
2352
- function prepareStructures$1(structures, packr) {
2297
+ function prepareStructures(structures, packr) {
2353
2298
  structures.isCompatible = (existingStructures) => {
2354
2299
  let compatible = !existingStructures || ((packr.lastNamedStructuresLength || 0) === existingStructures.length);
2355
2300
  if (!compatible) // we want to merge these existing structures immediately since we already have it and we are in the right transaction
2356
2301
  packr._mergeStructures(existingStructures);
2357
2302
  return compatible;
2358
2303
  };
2359
- return structures
2360
- }
2361
- function setWriteStructSlots(writeSlots, makeStructures) {
2362
- writeStructSlots = writeSlots;
2363
- prepareStructures$1 = makeStructures;
2304
+ return structures;
2364
2305
  }
2365
2306
 
2366
2307
  let defaultPackr = new Packr$1({ useRecords: false });
@@ -2370,779 +2311,6 @@
2370
2311
  const RESET_BUFFER_MODE = 1024;
2371
2312
  const RESERVE_START_SPACE = 2048;
2372
2313
 
2373
- const ASCII = 3; // the MIBenum from https://www.iana.org/assignments/character-sets/character-sets.xhtml (and other character encodings could be referenced by MIBenum)
2374
- const NUMBER = 0;
2375
- const UTF8 = 2;
2376
- const OBJECT_DATA = 1;
2377
- const DATE = 16;
2378
- const TYPE_NAMES = ['num', 'object', 'string', 'ascii'];
2379
- TYPE_NAMES[DATE] = 'date';
2380
- const float32Headers = [false, true, true, false, false, true, true, false];
2381
- let evalSupported;
2382
- try {
2383
- new Function('');
2384
- evalSupported = true;
2385
- } catch(error) {
2386
- // if eval variants are not supported, do not create inline object readers ever
2387
- }
2388
-
2389
- let updatedPosition;
2390
- const hasNodeBuffer = typeof Buffer !== 'undefined';
2391
- let textEncoder, currentSource;
2392
- try {
2393
- textEncoder = new TextEncoder();
2394
- } catch (error) {}
2395
- const encodeUtf8 = hasNodeBuffer ? function(target, string, position) {
2396
- return target.utf8Write(string, position, target.byteLength - position)
2397
- } : (textEncoder && textEncoder.encodeInto) ?
2398
- function(target, string, position) {
2399
- return textEncoder.encodeInto(string, target.subarray(position)).written
2400
- } : false;
2401
- setWriteStructSlots(writeStruct, prepareStructures);
2402
- function writeStruct(object, target, encodingStart, position, structures, makeRoom, pack, packr) {
2403
- let typedStructs = packr.typedStructs || (packr.typedStructs = []);
2404
- // note that we rely on pack.js to load stored structures before we get to this point
2405
- let targetView = target.dataView;
2406
- let refsStartPosition = (typedStructs.lastStringStart || 100) + position;
2407
- let safeEnd = target.length - 10;
2408
- let start = position;
2409
- if (position > safeEnd) {
2410
- target = makeRoom(position);
2411
- targetView = target.dataView;
2412
- position -= encodingStart;
2413
- start -= encodingStart;
2414
- refsStartPosition -= encodingStart;
2415
- encodingStart = 0;
2416
- safeEnd = target.length - 10;
2417
- }
2418
-
2419
- let refOffset, refPosition = refsStartPosition;
2420
-
2421
- let transition = typedStructs.transitions || (typedStructs.transitions = Object.create(null));
2422
- let nextId = typedStructs.nextId || typedStructs.length;
2423
- let headerSize =
2424
- nextId < 0xf ? 1 :
2425
- nextId < 0xf0 ? 2 :
2426
- nextId < 0xf000 ? 3 :
2427
- nextId < 0xf00000 ? 4 : 0;
2428
- if (headerSize === 0)
2429
- return 0;
2430
- position += headerSize;
2431
- let queuedReferences = [];
2432
- let usedAscii0;
2433
- let keyIndex = 0;
2434
- for (let key in object) {
2435
- let value = object[key];
2436
- let nextTransition = transition[key];
2437
- if (!nextTransition) {
2438
- transition[key] = nextTransition = {
2439
- key,
2440
- parent: transition,
2441
- enumerationOffset: 0,
2442
- ascii0: null,
2443
- ascii8: null,
2444
- num8: null,
2445
- string16: null,
2446
- object16: null,
2447
- num32: null,
2448
- float64: null,
2449
- date64: null
2450
- };
2451
- }
2452
- if (position > safeEnd) {
2453
- target = makeRoom(position);
2454
- targetView = target.dataView;
2455
- position -= encodingStart;
2456
- start -= encodingStart;
2457
- refsStartPosition -= encodingStart;
2458
- refPosition -= encodingStart;
2459
- encodingStart = 0;
2460
- safeEnd = target.length - 10;
2461
- }
2462
- switch (typeof value) {
2463
- case 'number':
2464
- let number = value;
2465
- // first check to see if we are using a lot of ids and should default to wide/common format
2466
- if (nextId < 200 || !nextTransition.num64) {
2467
- if (number >> 0 === number && number < 0x20000000 && number > -0x1f000000) {
2468
- if (number < 0xf6 && number >= 0 && (nextTransition.num8 && !(nextId > 200 && nextTransition.num32) || number < 0x20 && !nextTransition.num32)) {
2469
- transition = nextTransition.num8 || createTypeTransition(nextTransition, NUMBER, 1);
2470
- target[position++] = number;
2471
- } else {
2472
- transition = nextTransition.num32 || createTypeTransition(nextTransition, NUMBER, 4);
2473
- targetView.setUint32(position, number, true);
2474
- position += 4;
2475
- }
2476
- break;
2477
- } else if (number < 0x100000000 && number >= -0x80000000) {
2478
- targetView.setFloat32(position, number, true);
2479
- if (float32Headers[target[position + 3] >>> 5]) {
2480
- let xShifted;
2481
- // this checks for rounding of numbers that were encoded in 32-bit float to nearest significant decimal digit that could be preserved
2482
- if (((xShifted = number * mult10[((target[position + 3] & 0x7f) << 1) | (target[position + 2] >> 7)]) >> 0) === xShifted) {
2483
- transition = nextTransition.num32 || createTypeTransition(nextTransition, NUMBER, 4);
2484
- position += 4;
2485
- break;
2486
- }
2487
- }
2488
- }
2489
- }
2490
- transition = nextTransition.num64 || createTypeTransition(nextTransition, NUMBER, 8);
2491
- targetView.setFloat64(position, number, true);
2492
- position += 8;
2493
- break;
2494
- case 'string':
2495
- let strLength = value.length;
2496
- refOffset = refPosition - refsStartPosition;
2497
- if ((strLength << 2) + refPosition > safeEnd) {
2498
- target = makeRoom((strLength << 2) + refPosition);
2499
- targetView = target.dataView;
2500
- position -= encodingStart;
2501
- start -= encodingStart;
2502
- refsStartPosition -= encodingStart;
2503
- refPosition -= encodingStart;
2504
- encodingStart = 0;
2505
- safeEnd = target.length - 10;
2506
- }
2507
- if (strLength > ((0xff00 + refOffset) >> 2)) {
2508
- queuedReferences.push(key, value, position - start);
2509
- break;
2510
- }
2511
- let isNotAscii;
2512
- let strStart = refPosition;
2513
- if (strLength < 0x40) {
2514
- let i, c1, c2;
2515
- for (i = 0; i < strLength; i++) {
2516
- c1 = value.charCodeAt(i);
2517
- if (c1 < 0x80) {
2518
- target[refPosition++] = c1;
2519
- } else if (c1 < 0x800) {
2520
- isNotAscii = true;
2521
- target[refPosition++] = c1 >> 6 | 0xc0;
2522
- target[refPosition++] = c1 & 0x3f | 0x80;
2523
- } else if (
2524
- (c1 & 0xfc00) === 0xd800 &&
2525
- ((c2 = value.charCodeAt(i + 1)) & 0xfc00) === 0xdc00
2526
- ) {
2527
- isNotAscii = true;
2528
- c1 = 0x10000 + ((c1 & 0x03ff) << 10) + (c2 & 0x03ff);
2529
- i++;
2530
- target[refPosition++] = c1 >> 18 | 0xf0;
2531
- target[refPosition++] = c1 >> 12 & 0x3f | 0x80;
2532
- target[refPosition++] = c1 >> 6 & 0x3f | 0x80;
2533
- target[refPosition++] = c1 & 0x3f | 0x80;
2534
- } else {
2535
- isNotAscii = true;
2536
- target[refPosition++] = c1 >> 12 | 0xe0;
2537
- target[refPosition++] = c1 >> 6 & 0x3f | 0x80;
2538
- target[refPosition++] = c1 & 0x3f | 0x80;
2539
- }
2540
- }
2541
- } else {
2542
- refPosition += encodeUtf8(target, value, refPosition);
2543
- isNotAscii = refPosition - strStart > strLength;
2544
- }
2545
- if (refOffset < 0xa0 || (refOffset < 0xf6 && (nextTransition.ascii8 || nextTransition.string8))) {
2546
- // short strings
2547
- if (isNotAscii) {
2548
- if (!(transition = nextTransition.string8)) {
2549
- if (typedStructs.length > 10 && (transition = nextTransition.ascii8)) {
2550
- // we can safely change ascii to utf8 in place since they are compatible
2551
- transition.__type = UTF8;
2552
- nextTransition.ascii8 = null;
2553
- nextTransition.string8 = transition;
2554
- pack(null, 0, true); // special call to notify that structures have been updated
2555
- } else {
2556
- transition = createTypeTransition(nextTransition, UTF8, 1);
2557
- }
2558
- }
2559
- } else if (refOffset === 0 && !usedAscii0) {
2560
- usedAscii0 = true;
2561
- transition = nextTransition.ascii0 || createTypeTransition(nextTransition, ASCII, 0);
2562
- break; // don't increment position
2563
- }// else ascii:
2564
- else if (!(transition = nextTransition.ascii8) && !(typedStructs.length > 10 && (transition = nextTransition.string8)))
2565
- transition = createTypeTransition(nextTransition, ASCII, 1);
2566
- target[position++] = refOffset;
2567
- } else {
2568
- // TODO: Enable ascii16 at some point, but get the logic right
2569
- //if (isNotAscii)
2570
- transition = nextTransition.string16 || createTypeTransition(nextTransition, UTF8, 2);
2571
- //else
2572
- //transition = nextTransition.ascii16 || createTypeTransition(nextTransition, ASCII, 2);
2573
- targetView.setUint16(position, refOffset, true);
2574
- position += 2;
2575
- }
2576
- break;
2577
- case 'object':
2578
- if (value) {
2579
- if (value.constructor === Date) {
2580
- transition = nextTransition.date64 || createTypeTransition(nextTransition, DATE, 8);
2581
- targetView.setFloat64(position, value.getTime(), true);
2582
- position += 8;
2583
- } else {
2584
- queuedReferences.push(key, value, keyIndex);
2585
- }
2586
- break;
2587
- } else { // null
2588
- nextTransition = anyType(nextTransition, position, targetView, -10); // match CBOR with this
2589
- if (nextTransition) {
2590
- transition = nextTransition;
2591
- position = updatedPosition;
2592
- } else queuedReferences.push(key, value, keyIndex);
2593
- }
2594
- break;
2595
- case 'boolean':
2596
- transition = nextTransition.num8 || nextTransition.ascii8 || createTypeTransition(nextTransition, NUMBER, 1);
2597
- target[position++] = value ? 0xf9 : 0xf8; // match CBOR with these
2598
- break;
2599
- case 'undefined':
2600
- nextTransition = anyType(nextTransition, position, targetView, -9); // match CBOR with this
2601
- if (nextTransition) {
2602
- transition = nextTransition;
2603
- position = updatedPosition;
2604
- } else queuedReferences.push(key, value, keyIndex);
2605
- break;
2606
- default:
2607
- queuedReferences.push(key, value, keyIndex);
2608
- }
2609
- keyIndex++;
2610
- }
2611
-
2612
- for (let i = 0, l = queuedReferences.length; i < l;) {
2613
- let key = queuedReferences[i++];
2614
- let value = queuedReferences[i++];
2615
- let propertyIndex = queuedReferences[i++];
2616
- let nextTransition = transition[key];
2617
- if (!nextTransition) {
2618
- transition[key] = nextTransition = {
2619
- key,
2620
- parent: transition,
2621
- enumerationOffset: propertyIndex - keyIndex,
2622
- ascii0: null,
2623
- ascii8: null,
2624
- num8: null,
2625
- string16: null,
2626
- object16: null,
2627
- num32: null,
2628
- float64: null
2629
- };
2630
- }
2631
- let newPosition;
2632
- if (value) {
2633
- /*if (typeof value === 'string') { // TODO: we could re-enable long strings
2634
- if (position + value.length * 3 > safeEnd) {
2635
- target = makeRoom(position + value.length * 3);
2636
- position -= start;
2637
- targetView = target.dataView;
2638
- start = 0;
2639
- }
2640
- newPosition = position + target.utf8Write(value, position, 0xffffffff);
2641
- } else { */
2642
- let size;
2643
- refOffset = refPosition - refsStartPosition;
2644
- if (refOffset < 0xff00) {
2645
- transition = nextTransition.object16;
2646
- if (transition)
2647
- size = 2;
2648
- else if ((transition = nextTransition.object32))
2649
- size = 4;
2650
- else {
2651
- transition = createTypeTransition(nextTransition, OBJECT_DATA, 2);
2652
- size = 2;
2653
- }
2654
- } else {
2655
- transition = nextTransition.object32 || createTypeTransition(nextTransition, OBJECT_DATA, 4);
2656
- size = 4;
2657
- }
2658
- newPosition = pack(value, refPosition);
2659
- //}
2660
- if (typeof newPosition === 'object') {
2661
- // re-allocated
2662
- refPosition = newPosition.position;
2663
- targetView = newPosition.targetView;
2664
- target = newPosition.target;
2665
- refsStartPosition -= encodingStart;
2666
- position -= encodingStart;
2667
- start -= encodingStart;
2668
- encodingStart = 0;
2669
- } else
2670
- refPosition = newPosition;
2671
- if (size === 2) {
2672
- targetView.setUint16(position, refOffset, true);
2673
- position += 2;
2674
- } else {
2675
- targetView.setUint32(position, refOffset, true);
2676
- position += 4;
2677
- }
2678
- } else { // null or undefined
2679
- transition = nextTransition.object16 || createTypeTransition(nextTransition, OBJECT_DATA, 2);
2680
- targetView.setInt16(position, value === null ? -10 : -9, true);
2681
- position += 2;
2682
- }
2683
- keyIndex++;
2684
- }
2685
-
2686
-
2687
- let recordId = transition[RECORD_SYMBOL];
2688
- if (recordId == null) {
2689
- recordId = packr.typedStructs.length;
2690
- let structure = [];
2691
- let nextTransition = transition;
2692
- let key, type;
2693
- while ((type = nextTransition.__type) !== undefined) {
2694
- let size = nextTransition.__size;
2695
- nextTransition = nextTransition.__parent;
2696
- key = nextTransition.key;
2697
- let property = [type, size, key];
2698
- if (nextTransition.enumerationOffset)
2699
- property.push(nextTransition.enumerationOffset);
2700
- structure.push(property);
2701
- nextTransition = nextTransition.parent;
2702
- }
2703
- structure.reverse();
2704
- transition[RECORD_SYMBOL] = recordId;
2705
- packr.typedStructs[recordId] = structure;
2706
- pack(null, 0, true); // special call to notify that structures have been updated
2707
- }
2708
-
2709
-
2710
- switch (headerSize) {
2711
- case 1:
2712
- if (recordId >= 0x10) return 0;
2713
- target[start] = recordId + 0x20;
2714
- break;
2715
- case 2:
2716
- if (recordId >= 0x100) return 0;
2717
- target[start] = 0x38;
2718
- target[start + 1] = recordId;
2719
- break;
2720
- case 3:
2721
- if (recordId >= 0x10000) return 0;
2722
- target[start] = 0x39;
2723
- targetView.setUint16(start + 1, recordId, true);
2724
- break;
2725
- case 4:
2726
- if (recordId >= 0x1000000) return 0;
2727
- targetView.setUint32(start, (recordId << 8) + 0x3a, true);
2728
- break;
2729
- }
2730
-
2731
- if (position < refsStartPosition) {
2732
- if (refsStartPosition === refPosition)
2733
- return position; // no refs
2734
- // adjust positioning
2735
- target.copyWithin(position, refsStartPosition, refPosition);
2736
- refPosition += position - refsStartPosition;
2737
- typedStructs.lastStringStart = position - start;
2738
- } else if (position > refsStartPosition) {
2739
- if (refsStartPosition === refPosition)
2740
- return position; // no refs
2741
- typedStructs.lastStringStart = position - start;
2742
- return writeStruct(object, target, encodingStart, start, structures, makeRoom, pack, packr);
2743
- }
2744
- return refPosition;
2745
- }
2746
- function anyType(transition, position, targetView, value) {
2747
- let nextTransition;
2748
- if ((nextTransition = transition.ascii8 || transition.num8)) {
2749
- targetView.setInt8(position, value, true);
2750
- updatedPosition = position + 1;
2751
- return nextTransition;
2752
- }
2753
- if ((nextTransition = transition.string16 || transition.object16)) {
2754
- targetView.setInt16(position, value, true);
2755
- updatedPosition = position + 2;
2756
- return nextTransition;
2757
- }
2758
- if (nextTransition = transition.num32) {
2759
- targetView.setUint32(position, 0xe0000100 + value, true);
2760
- updatedPosition = position + 4;
2761
- return nextTransition;
2762
- }
2763
- // transition.float64
2764
- if (nextTransition = transition.num64) {
2765
- targetView.setFloat64(position, NaN, true);
2766
- targetView.setInt8(position, value);
2767
- updatedPosition = position + 8;
2768
- return nextTransition;
2769
- }
2770
- updatedPosition = position;
2771
- // TODO: can we do an "any" type where we defer the decision?
2772
- return;
2773
- }
2774
- function createTypeTransition(transition, type, size) {
2775
- let typeName = TYPE_NAMES[type] + (size << 3);
2776
- let newTransition = transition[typeName] || (transition[typeName] = Object.create(null));
2777
- newTransition.__type = type;
2778
- newTransition.__size = size;
2779
- newTransition.__parent = transition;
2780
- return newTransition;
2781
- }
2782
- function onLoadedStructures(sharedData) {
2783
- if (!(sharedData instanceof Map))
2784
- return sharedData;
2785
- let typed = sharedData.get('typed') || [];
2786
- if (Object.isFrozen(typed))
2787
- typed = typed.map(structure => structure.slice(0));
2788
- let named = sharedData.get('named');
2789
- let transitions = Object.create(null);
2790
- for (let i = 0, l = typed.length; i < l; i++) {
2791
- let structure = typed[i];
2792
- let transition = transitions;
2793
- for (let [type, size, key] of structure) {
2794
- let nextTransition = transition[key];
2795
- if (!nextTransition) {
2796
- transition[key] = nextTransition = {
2797
- key,
2798
- parent: transition,
2799
- enumerationOffset: 0,
2800
- ascii0: null,
2801
- ascii8: null,
2802
- num8: null,
2803
- string16: null,
2804
- object16: null,
2805
- num32: null,
2806
- float64: null,
2807
- date64: null,
2808
- };
2809
- }
2810
- transition = createTypeTransition(nextTransition, type, size);
2811
- }
2812
- transition[RECORD_SYMBOL] = i;
2813
- }
2814
- typed.transitions = transitions;
2815
- this.typedStructs = typed;
2816
- this.lastTypedStructuresLength = typed.length;
2817
- return named;
2818
- }
2819
- var sourceSymbol = Symbol.for('source');
2820
- function readStruct(src, position, srcEnd, unpackr) {
2821
- let recordId = src[position++] - 0x20;
2822
- if (recordId >= 24) {
2823
- switch(recordId) {
2824
- case 24: recordId = src[position++]; break;
2825
- // little endian:
2826
- case 25: recordId = src[position++] + (src[position++] << 8); break;
2827
- case 26: recordId = src[position++] + (src[position++] << 8) + (src[position++] << 16); break;
2828
- case 27: recordId = src[position++] + (src[position++] << 8) + (src[position++] << 16) + (src[position++] << 24); break;
2829
- }
2830
- }
2831
- let structure = unpackr.typedStructs && unpackr.typedStructs[recordId];
2832
- if (!structure) {
2833
- // copy src buffer because getStructures will override it
2834
- src = Uint8Array.prototype.slice.call(src, position, srcEnd);
2835
- srcEnd -= position;
2836
- position = 0;
2837
- if (!unpackr.getStructures)
2838
- throw new Error(`Reference to shared structure ${recordId} without getStructures method`);
2839
- unpackr._mergeStructures(unpackr.getStructures());
2840
- if (!unpackr.typedStructs)
2841
- throw new Error('Could not find any shared typed structures');
2842
- unpackr.lastTypedStructuresLength = unpackr.typedStructs.length;
2843
- structure = unpackr.typedStructs[recordId];
2844
- if (!structure)
2845
- throw new Error('Could not find typed structure ' + recordId);
2846
- }
2847
- var construct = structure.construct;
2848
- var fullConstruct = structure.fullConstruct;
2849
- if (!construct) {
2850
- construct = structure.construct = function LazyObject() {
2851
- };
2852
- fullConstruct = structure.fullConstruct = function LoadedObject() {
2853
- };
2854
- fullConstruct.prototype = unpackr.structPrototype || {};
2855
- var prototype = construct.prototype = unpackr.structPrototype ? Object.create(unpackr.structPrototype) : {};
2856
- let properties = [];
2857
- let currentOffset = 0;
2858
- let lastRefProperty;
2859
- for (let i = 0, l = structure.length; i < l; i++) {
2860
- let definition = structure[i];
2861
- let [ type, size, key, enumerationOffset ] = definition;
2862
- if (key === '__proto__')
2863
- key = '__proto_';
2864
- let property = {
2865
- key,
2866
- offset: currentOffset,
2867
- };
2868
- if (enumerationOffset)
2869
- properties.splice(i + enumerationOffset, 0, property);
2870
- else
2871
- properties.push(property);
2872
- let getRef;
2873
- switch(size) { // TODO: Move into a separate function
2874
- case 0: getRef = () => 0; break;
2875
- case 1:
2876
- getRef = (source, position) => {
2877
- let ref = source.bytes[position + property.offset];
2878
- return ref >= 0xf6 ? toConstant(ref) : ref;
2879
- };
2880
- break;
2881
- case 2:
2882
- getRef = (source, position) => {
2883
- let src = source.bytes;
2884
- let dataView = src.dataView || (src.dataView = new DataView(src.buffer, src.byteOffset, src.byteLength));
2885
- let ref = dataView.getUint16(position + property.offset, true);
2886
- return ref >= 0xff00 ? toConstant(ref & 0xff) : ref;
2887
- };
2888
- break;
2889
- case 4:
2890
- getRef = (source, position) => {
2891
- let src = source.bytes;
2892
- let dataView = src.dataView || (src.dataView = new DataView(src.buffer, src.byteOffset, src.byteLength));
2893
- let ref = dataView.getUint32(position + property.offset, true);
2894
- return ref >= 0xffffff00 ? toConstant(ref & 0xff) : ref;
2895
- };
2896
- break;
2897
- }
2898
- property.getRef = getRef;
2899
- currentOffset += size;
2900
- let get;
2901
- switch(type) {
2902
- case ASCII:
2903
- if (lastRefProperty && !lastRefProperty.next)
2904
- lastRefProperty.next = property;
2905
- lastRefProperty = property;
2906
- property.multiGetCount = 0;
2907
- get = function(source) {
2908
- let src = source.bytes;
2909
- let position = source.position;
2910
- let refStart = currentOffset + position;
2911
- let ref = getRef(source, position);
2912
- if (typeof ref !== 'number') return ref;
2913
-
2914
- let end, next = property.next;
2915
- while(next) {
2916
- end = next.getRef(source, position);
2917
- if (typeof end === 'number')
2918
- break;
2919
- else
2920
- end = null;
2921
- next = next.next;
2922
- }
2923
- if (end == null)
2924
- end = source.bytesEnd - refStart;
2925
- if (source.srcString) {
2926
- return source.srcString.slice(ref, end);
2927
- }
2928
- /*if (property.multiGetCount > 0) {
2929
- let asciiEnd;
2930
- next = firstRefProperty;
2931
- let dataView = src.dataView || (src.dataView = new DataView(src.buffer, src.byteOffset, src.byteLength));
2932
- do {
2933
- asciiEnd = dataView.getUint16(source.position + next.offset, true);
2934
- if (asciiEnd < 0xff00)
2935
- break;
2936
- else
2937
- asciiEnd = null;
2938
- } while((next = next.next));
2939
- if (asciiEnd == null)
2940
- asciiEnd = source.bytesEnd - refStart
2941
- source.srcString = src.toString('latin1', refStart, refStart + asciiEnd);
2942
- return source.srcString.slice(ref, end);
2943
- }
2944
- if (source.prevStringGet) {
2945
- source.prevStringGet.multiGetCount += 2;
2946
- } else {
2947
- source.prevStringGet = property;
2948
- property.multiGetCount--;
2949
- }*/
2950
- return readString(src, ref + refStart, end - ref);
2951
- //return src.toString('latin1', ref + refStart, end + refStart);
2952
- };
2953
- break;
2954
- case UTF8: case OBJECT_DATA:
2955
- if (lastRefProperty && !lastRefProperty.next)
2956
- lastRefProperty.next = property;
2957
- lastRefProperty = property;
2958
- get = function(source) {
2959
- let position = source.position;
2960
- let refStart = currentOffset + position;
2961
- let ref = getRef(source, position);
2962
- if (typeof ref !== 'number') return ref;
2963
- let src = source.bytes;
2964
- let end, next = property.next;
2965
- while(next) {
2966
- end = next.getRef(source, position);
2967
- if (typeof end === 'number')
2968
- break;
2969
- else
2970
- end = null;
2971
- next = next.next;
2972
- }
2973
- if (end == null)
2974
- end = source.bytesEnd - refStart;
2975
- if (type === UTF8) {
2976
- return src.toString('utf8', ref + refStart, end + refStart);
2977
- } else {
2978
- currentSource = source;
2979
- try {
2980
- return unpackr.unpack(src, { start: ref + refStart, end: end + refStart });
2981
- } finally {
2982
- currentSource = null;
2983
- }
2984
- }
2985
- };
2986
- break;
2987
- case NUMBER:
2988
- switch(size) {
2989
- case 4:
2990
- get = function (source) {
2991
- let src = source.bytes;
2992
- let dataView = src.dataView || (src.dataView = new DataView(src.buffer, src.byteOffset, src.byteLength));
2993
- let position = source.position + property.offset;
2994
- let value = dataView.getInt32(position, true);
2995
- if (value < 0x20000000) {
2996
- if (value > -0x1f000000)
2997
- return value;
2998
- if (value > -0x20000000)
2999
- return toConstant(value & 0xff);
3000
- }
3001
- let fValue = dataView.getFloat32(position, true);
3002
- // this does rounding of numbers that were encoded in 32-bit float to nearest significant decimal digit that could be preserved
3003
- let multiplier = mult10[((src[position + 3] & 0x7f) << 1) | (src[position + 2] >> 7)];
3004
- return ((multiplier * fValue + (fValue > 0 ? 0.5 : -0.5)) >> 0) / multiplier;
3005
- };
3006
- break;
3007
- case 8:
3008
- get = function (source) {
3009
- let src = source.bytes;
3010
- let dataView = src.dataView || (src.dataView = new DataView(src.buffer, src.byteOffset, src.byteLength));
3011
- let value = dataView.getFloat64(source.position + property.offset, true);
3012
- if (isNaN(value)) {
3013
- let byte = src[source.position + property.offset];
3014
- if (byte >= 0xf6)
3015
- return toConstant(byte);
3016
- }
3017
- return value;
3018
- };
3019
- break;
3020
- case 1:
3021
- get = function (source) {
3022
- let src = source.bytes;
3023
- let value = src[source.position + property.offset];
3024
- return value < 0xf6 ? value : toConstant(value);
3025
- };
3026
- break;
3027
- }
3028
- break;
3029
- case DATE:
3030
- get = function (source) {
3031
- let src = source.bytes;
3032
- let dataView = src.dataView || (src.dataView = new DataView(src.buffer, src.byteOffset, src.byteLength));
3033
- return new Date(dataView.getFloat64(source.position + property.offset, true));
3034
- };
3035
- break;
3036
-
3037
- }
3038
- property.get = get;
3039
- }
3040
- // TODO: load the srcString for faster string decoding on toJSON
3041
- if (evalSupported) {
3042
- let objectLiteralProperties = [];
3043
- let args = [];
3044
- let i = 0;
3045
- let hasInheritedProperties;
3046
- for (let property of properties) { // assign in enumeration order
3047
- if (unpackr.alwaysLazyProperty && unpackr.alwaysLazyProperty(property.key)) {
3048
- // these properties are not eagerly evaluated and this can be used for creating properties
3049
- // that are not serialized as JSON
3050
- hasInheritedProperties = true;
3051
- continue;
3052
- }
3053
- Object.defineProperty(prototype, property.key, { get: withSource(property.get), enumerable: true });
3054
- let valueFunction = 'v' + i++;
3055
- args.push(valueFunction);
3056
- objectLiteralProperties.push('o[' + JSON.stringify(property.key) + ']=' + valueFunction + '(s)');
3057
- }
3058
- if (hasInheritedProperties) {
3059
- objectLiteralProperties.push('__proto__:this');
3060
- }
3061
- let toObject = (new Function(...args, 'var c=this;return function(s){var o=new c();' + objectLiteralProperties.join(';') + ';return o;}')).apply(fullConstruct, properties.map(prop => prop.get));
3062
- Object.defineProperty(prototype, 'toJSON', {
3063
- value(omitUnderscoredProperties) {
3064
- return toObject.call(this, this[sourceSymbol]);
3065
- }
3066
- });
3067
- } else {
3068
- Object.defineProperty(prototype, 'toJSON', {
3069
- value(omitUnderscoredProperties) {
3070
- // return an enumerable object with own properties to JSON stringify
3071
- let resolved = {};
3072
- for (let i = 0, l = properties.length; i < l; i++) {
3073
- // TODO: check alwaysLazyProperty
3074
- let key = properties[i].key;
3075
-
3076
- resolved[key] = this[key];
3077
- }
3078
- return resolved;
3079
- },
3080
- // not enumerable or anything
3081
- });
3082
- }
3083
- }
3084
- var instance = new construct();
3085
- instance[sourceSymbol] = {
3086
- bytes: src,
3087
- position,
3088
- srcString: '',
3089
- bytesEnd: srcEnd
3090
- };
3091
- return instance;
3092
- }
3093
- function toConstant(code) {
3094
- switch(code) {
3095
- case 0xf6: return null;
3096
- case 0xf7: return undefined;
3097
- case 0xf8: return false;
3098
- case 0xf9: return true;
3099
- }
3100
- throw new Error('Unknown constant');
3101
- }
3102
- function withSource(get) {
3103
- return function() {
3104
- return get(this[sourceSymbol]);
3105
- }
3106
- }
3107
-
3108
- function saveState() {
3109
- if (currentSource) {
3110
- currentSource.bytes = Uint8Array.prototype.slice.call(currentSource.bytes, currentSource.position, currentSource.bytesEnd);
3111
- currentSource.position = 0;
3112
- currentSource.bytesEnd = currentSource.bytes.length;
3113
- }
3114
- }
3115
- function prepareStructures(structures, packr) {
3116
- if (packr.typedStructs) {
3117
- let structMap = new Map();
3118
- structMap.set('named', structures);
3119
- structMap.set('typed', packr.typedStructs);
3120
- structures = structMap;
3121
- }
3122
- let lastTypedStructuresLength = packr.lastTypedStructuresLength || 0;
3123
- structures.isCompatible = existing => {
3124
- let compatible = true;
3125
- if (existing instanceof Map) {
3126
- let named = existing.get('named') || [];
3127
- if (named.length !== (packr.lastNamedStructuresLength || 0))
3128
- compatible = false;
3129
- let typed = existing.get('typed') || [];
3130
- if (typed.length !== lastTypedStructuresLength)
3131
- compatible = false;
3132
- } else if (existing instanceof Array || Array.isArray(existing)) {
3133
- if (existing.length !== (packr.lastNamedStructuresLength || 0))
3134
- compatible = false;
3135
- }
3136
- if (!compatible)
3137
- packr._mergeStructures(existing);
3138
- return compatible;
3139
- };
3140
- packr.lastTypedStructuresLength = packr.typedStructs && packr.typedStructs.length;
3141
- return structures;
3142
- }
3143
-
3144
- setReadStruct(readStruct, onLoadedStructures, saveState);
3145
-
3146
2314
  const nativeAccelerationDisabled = process.env.MSGPACKR_NATIVE_ACCELERATION_DISABLED !== undefined && process.env.MSGPACKR_NATIVE_ACCELERATION_DISABLED.toLowerCase() === 'true';
3147
2315
 
3148
2316
  if (!nativeAccelerationDisabled) {
@@ -3171,18 +2339,11 @@
3171
2339
  const sampleData = allSampleData[3];
3172
2340
  function tryRequire(module) {
3173
2341
  try {
3174
- return require(module)
2342
+ return require(module);
3175
2343
  } catch(error) {
3176
- return {}
2344
+ return {};
3177
2345
  }
3178
2346
  }
3179
-
3180
- let seed = 0;
3181
- function random() {
3182
- seed++;
3183
- let a = seed * 15485863;
3184
- return (a * a * a % 2038074743) / 2038074743;
3185
- }
3186
2347
  //if (typeof chai === 'undefined') { chai = require('chai') }
3187
2348
  var assert = chai.assert;
3188
2349
  //if (typeof msgpackr === 'undefined') { msgpackr = require('..') }
@@ -3312,39 +2473,6 @@
3312
2473
  var deserialized = unpack(ab);
3313
2474
  assert.deepEqual(deserialized, data);
3314
2475
  });
3315
- test('pack/unpack varying data with random access structures', function () {
3316
- let structures = [];
3317
- let packr = new Packr({
3318
- structures, useRecords: true, randomAccessStructure: true, freezeData: true, saveStructures(structures) {
3319
- }, getStructures() {
3320
- console.log('getStructures');
3321
- }
3322
- });
3323
- for (let i = 0; i < 2000; i++) {
3324
- let data = {};
3325
- let props = ['foo', 'bar', 'a', 'b', 'c', 'name', 'age', 'd'];
3326
-
3327
- function makeString() {
3328
- let str = '';
3329
- while (random() < 0.9) {
3330
- str += random() < 0.8 ? 'hello world' : String.fromCharCode(300);
3331
- }
3332
- return str;
3333
- }
3334
-
3335
- for (let i = 0; i < random() * 20; i++) {
3336
- data[props[Math.floor(random() * 8)]] =
3337
- random() < 0.3 ? Math.floor(random() * 400) / 2 :
3338
- random() < 0.3 ? makeString() : random() < 0.3 ? true : random() < 0.3 ? sampleData : null;
3339
- }
3340
- var serialized = packr.pack(data);
3341
- var deserialized = packr.unpack(serialized);
3342
- for (let key in deserialized) {
3343
- deserialized[key];
3344
- }
3345
- assert.deepEqual(deserialized, data);
3346
- }
3347
- });
3348
2476
 
3349
2477
  for (let sampleData of allSampleData) {
3350
2478
  let snippet = JSON.stringify(sampleData).slice(0, 20) + '...';
@@ -3367,25 +2495,6 @@
3367
2495
  var deserialized = unpack(serialized);
3368
2496
  assert.deepEqual(deserialized, data);
3369
2497
  });
3370
- test('pack/unpack sample data with random access structures ' + snippet, function () {
3371
- var data = sampleData;
3372
- let structures = [];
3373
- let packr = new Packr({
3374
- structures, useRecords: true, randomAccessStructure: true, freezeData: true, saveStructures(structures) {
3375
- }, getStructures() {
3376
- console.log('getStructures');
3377
- }
3378
- });
3379
- for (let i = 0; i < 20; i++) {
3380
- var serialized = packr.pack(data);
3381
- var deserialized = packr.unpack(serialized, {lazy: true});
3382
- var copied = {};
3383
- for (let key in deserialized) {
3384
- copied[key] = deserialized[key];
3385
- }
3386
- assert.deepEqual(copied, data);
3387
- }
3388
- });
3389
2498
  test('pack/unpack sample data with bundled strings ' + snippet, function () {
3390
2499
  var data = sampleData;
3391
2500
  let packr = new Packr({ /*structures,*/ useRecords: false, bundleStrings: true});
@@ -3576,7 +2685,7 @@
3576
2685
 
3577
2686
  }
3578
2687
  Extended.prototype.getDouble = function() {
3579
- return this.value * 2
2688
+ return this.value * 2;
3580
2689
  };
3581
2690
  var instance = new Extended();
3582
2691
  instance.value = 4;
@@ -3596,10 +2705,10 @@
3596
2705
  let data = packr.unpack(buffer);
3597
2706
  e.value = data[0];
3598
2707
  e.string = data[1];
3599
- return e
2708
+ return e;
3600
2709
  },
3601
2710
  pack: function(instance) {
3602
- return packr.pack([instance.value, instance.string])
2711
+ return packr.pack([instance.value, instance.string]);
3603
2712
  }
3604
2713
  });
3605
2714
  var serialized = pack(data);
@@ -3625,10 +2734,10 @@
3625
2734
  type: 12,
3626
2735
  read: function(data) {
3627
2736
  Object.setPrototypeOf(data, ExtendArray.prototype);
3628
- return data
2737
+ return data;
3629
2738
  },
3630
2739
  write: function(instance) {
3631
- return [...instance]
2740
+ return [...instance];
3632
2741
  }
3633
2742
  });
3634
2743
  var serialized = pack(data);
@@ -3681,10 +2790,10 @@
3681
2790
  Class: TestClass,
3682
2791
  type: 0x01,
3683
2792
  pack() {
3684
- return typeof Buffer != 'undefined' ? Buffer.alloc(256) : new Uint8Array(256)
2793
+ return typeof Buffer != 'undefined' ? Buffer.alloc(256) : new Uint8Array(256);
3685
2794
  },
3686
2795
  unpack(data) {
3687
- return data.length
2796
+ return data.length;
3688
2797
  }
3689
2798
  });
3690
2799
  let result = unpack(pack(new TestClass()));
@@ -3696,7 +2805,7 @@
3696
2805
 
3697
2806
  }
3698
2807
  Extended.prototype.getDouble = function() {
3699
- return this.value * 2
2808
+ return this.value * 2;
3700
2809
  };
3701
2810
  var instance = new Extended();
3702
2811
  instance.value = 4;
@@ -3715,10 +2824,10 @@
3715
2824
  let e = new Extended();
3716
2825
  e.value = data[0];
3717
2826
  e.string = data[1];
3718
- return e
2827
+ return e;
3719
2828
  },
3720
2829
  write: function(instance) {
3721
- return [instance.value, instance.string]
2830
+ return [instance.value, instance.string];
3722
2831
  }
3723
2832
  });
3724
2833
  var serialized = pack(data);
@@ -3731,7 +2840,7 @@
3731
2840
 
3732
2841
  }
3733
2842
  Extended.prototype.getDouble = function() {
3734
- return this.value * 2
2843
+ return this.value * 2;
3735
2844
  };
3736
2845
  var instance = new Extended();
3737
2846
  instance.value = 4;
@@ -3748,10 +2857,10 @@
3748
2857
  type: 13,
3749
2858
  read: function(data) {
3750
2859
  Object.setPrototypeOf(data, Extended.prototype);
3751
- return data
2860
+ return data;
3752
2861
  },
3753
2862
  write: function(data) {
3754
- return data
2863
+ return data;
3755
2864
  }
3756
2865
  });
3757
2866
  var serialized = pack(data);
@@ -3776,10 +2885,10 @@
3776
2885
  type: 14,
3777
2886
  read: function(data) {
3778
2887
  Object.setPrototypeOf(data, ExtendArray3.prototype);
3779
- return data
2888
+ return data;
3780
2889
  },
3781
2890
  write: function(data) {
3782
- return data
2891
+ return data;
3783
2892
  }
3784
2893
  });
3785
2894
  var serialized = pack(data);
@@ -3794,10 +2903,10 @@
3794
2903
 
3795
2904
  }
3796
2905
  Extended.prototype.__call__ = function(){
3797
- return this.value * 4
2906
+ return this.value * 4;
3798
2907
  };
3799
2908
  Extended.prototype.getDouble = function() {
3800
- return this.value * 2
2909
+ return this.value * 2;
3801
2910
  };
3802
2911
 
3803
2912
  var instance = function() { instance.__call__();/* callable stuff */ };
@@ -3814,10 +2923,10 @@
3814
2923
  var e = function() { e.__call__(); };
3815
2924
  Object.setPrototypeOf(e,Extended.prototype);
3816
2925
  e.value = packr.unpack(buffer);
3817
- return e
2926
+ return e;
3818
2927
  },
3819
2928
  pack: function(instance) {
3820
- return packr.pack(instance.value)
2929
+ return packr.pack(instance.value);
3821
2930
  }
3822
2931
  });
3823
2932
  var serialized = pack(data);
@@ -3833,7 +2942,7 @@
3833
2942
  addExtension({
3834
2943
  Class: Date,
3835
2944
  write(date) {
3836
- return date.toString()
2945
+ return date.toString();
3837
2946
  }
3838
2947
  });
3839
2948
  var serialized = pack(data);
@@ -4130,7 +3239,7 @@
4130
3239
  const structures2 = [...structures];
4131
3240
  const packr = new Packr({
4132
3241
  getStructures() {
4133
- return structures
3242
+ return structures;
4134
3243
  },
4135
3244
  saveStructures(structures) {
4136
3245
  },
@@ -4138,7 +3247,7 @@
4138
3247
  });
4139
3248
  const packr2 = new Packr({
4140
3249
  getStructures() {
4141
- return structures2
3250
+ return structures2;
4142
3251
  },
4143
3252
  saveStructures(structures) {
4144
3253
  },
@@ -4459,9 +3568,9 @@
4459
3568
 
4460
3569
  test('pack toJSON returning this', () => {
4461
3570
  class Serializable {
4462
- someData = [1, 2, 3, 4]
3571
+ someData = [1, 2, 3, 4];
4463
3572
  toJSON() {
4464
- return this
3573
+ return this;
4465
3574
  }
4466
3575
  }
4467
3576
  const serialized = pack(new Serializable);