msgpackr 1.7.0-alpha7 → 1.7.0-beta1

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
@@ -886,7 +886,16 @@
886
886
 
887
887
  // the registration of the record definition extension (as "r")
888
888
  const recordDefinition = (id, highByte) => {
889
- var structure = read();
889
+ let structure;
890
+ if (currentUnpackr.freezeData) {
891
+ currentUnpackr.freezeData = false;
892
+ try {
893
+ structure = read();
894
+ } finally {
895
+ currentUnpackr.freezeData = true;
896
+ }
897
+ } else
898
+ structure = read();
890
899
  let firstByte = id;
891
900
  if (highByte !== undefined) {
892
901
  id = id < 32 ? -((highByte << 5) + id) : ((highByte << 5) + id);
@@ -2412,9 +2421,8 @@
2412
2421
  this.lastTypedStructuresLength = typed.length;
2413
2422
  return named;
2414
2423
  }
2415
- var sourceSymbol = Symbol('source');
2424
+ var sourceSymbol = Symbol.for('source');
2416
2425
  function readStruct$1(src, position, srcEnd, unpackr) {
2417
- // var stringLength = (src[position++] << 8) | src[position++];
2418
2426
  let recordId = src[position++] - 0x20;
2419
2427
  if (recordId >= 24) {
2420
2428
  switch(recordId) {
@@ -2475,13 +2483,13 @@
2475
2483
  case 0: getRef = () => 0; break;
2476
2484
  case 1:
2477
2485
  getRef = (source, position) => {
2478
- let ref = source.src[position + property.offset];
2486
+ let ref = source.bytes[position + property.offset];
2479
2487
  return ref >= 0xf6 ? toConstant(ref) : ref;
2480
2488
  };
2481
2489
  break;
2482
2490
  case 2:
2483
2491
  getRef = (source, position) => {
2484
- let src = source.src;
2492
+ let src = source.bytes;
2485
2493
  let dataView = src.dataView || (src.dataView = new DataView(src.buffer, src.byteOffset, src.byteLength));
2486
2494
  let ref = dataView.getUint16(position + property.offset, true);
2487
2495
  return ref >= 0xff00 ? toConstant(ref & 0xff) : ref;
@@ -2489,7 +2497,7 @@
2489
2497
  break;
2490
2498
  case 4:
2491
2499
  getRef = (source, position) => {
2492
- let src = source.src;
2500
+ let src = source.bytes;
2493
2501
  let dataView = src.dataView || (src.dataView = new DataView(src.buffer, src.byteOffset, src.byteLength));
2494
2502
  let ref = dataView.getUint32(position + property.offset, true);
2495
2503
  return ref >= 0xffffff00 ? toConstant(ref & 0xff) : ref;
@@ -2507,7 +2515,7 @@
2507
2515
  property.multiGetCount = 0;
2508
2516
  get = function() {
2509
2517
  let source = this[sourceSymbol];
2510
- let src = source.src;
2518
+ let src = source.bytes;
2511
2519
  let position = source.position;
2512
2520
  let refStart = currentOffset + position;
2513
2521
  let ref = getRef(source, position);
@@ -2523,7 +2531,7 @@
2523
2531
  next = next.next;
2524
2532
  }
2525
2533
  if (end == null)
2526
- end = source.srcEnd - refStart;
2534
+ end = source.bytesEnd - refStart;
2527
2535
  if (source.srcString) {
2528
2536
  return source.srcString.slice(ref, end);
2529
2537
  }
@@ -2539,7 +2547,7 @@
2539
2547
  asciiEnd = null;
2540
2548
  } while((next = next.next));
2541
2549
  if (asciiEnd == null)
2542
- asciiEnd = source.srcEnd - refStart
2550
+ asciiEnd = source.bytesEnd - refStart
2543
2551
  source.srcString = src.toString('latin1', refStart, refStart + asciiEnd);
2544
2552
  return source.srcString.slice(ref, end);
2545
2553
  }
@@ -2563,7 +2571,7 @@
2563
2571
  let refStart = currentOffset + position;
2564
2572
  let ref = getRef(source, position);
2565
2573
  if (typeof ref !== 'number') return ref;
2566
- let src = source.src;
2574
+ let src = source.bytes;
2567
2575
  let end, next = property.next;
2568
2576
  while(next) {
2569
2577
  end = next.getRef(source, position);
@@ -2574,7 +2582,7 @@
2574
2582
  next = next.next;
2575
2583
  }
2576
2584
  if (end == null)
2577
- end = source.srcEnd - refStart;
2585
+ end = source.bytesEnd - refStart;
2578
2586
  if (type === UTF8) {
2579
2587
  return src.toString('utf8', ref + refStart, end + refStart);
2580
2588
  } else {
@@ -2592,7 +2600,7 @@
2592
2600
  case 4:
2593
2601
  get = function () {
2594
2602
  let source = this[sourceSymbol];
2595
- let src = source.src;
2603
+ let src = source.bytes;
2596
2604
  let dataView = src.dataView || (src.dataView = new DataView(src.buffer, src.byteOffset, src.byteLength));
2597
2605
  let position = source.position + property.offset;
2598
2606
  let value = dataView.getInt32(position, true);
@@ -2611,7 +2619,7 @@
2611
2619
  case 8:
2612
2620
  get = function () {
2613
2621
  let source = this[sourceSymbol];
2614
- let src = source.src;
2622
+ let src = source.bytes;
2615
2623
  let dataView = src.dataView || (src.dataView = new DataView(src.buffer, src.byteOffset, src.byteLength));
2616
2624
  let value = dataView.getFloat64(source.position + property.offset, true);
2617
2625
  if (isNaN(value)) {
@@ -2625,7 +2633,7 @@
2625
2633
  case 1:
2626
2634
  get = function () {
2627
2635
  let source = this[sourceSymbol];
2628
- let src = source.src;
2636
+ let src = source.bytes;
2629
2637
  let value = src[source.position + property.offset];
2630
2638
  return value < 0xf6 ? value : toConstant(value);
2631
2639
  };
@@ -2635,7 +2643,7 @@
2635
2643
  case DATE:
2636
2644
  get = function () {
2637
2645
  let source = this[sourceSymbol];
2638
- let src = source.src;
2646
+ let src = source.bytes;
2639
2647
  let dataView = src.dataView || (src.dataView = new DataView(src.buffer, src.byteOffset, src.byteLength));
2640
2648
  return new Date(dataView.getFloat64(source.position + property.offset, true));
2641
2649
  };
@@ -2649,10 +2657,10 @@
2649
2657
  }
2650
2658
  var instance = new construct();
2651
2659
  instance[sourceSymbol] = {
2652
- src,
2660
+ bytes: src,
2653
2661
  position,
2654
2662
  srcString: '',
2655
- srcEnd
2663
+ bytesEnd: srcEnd
2656
2664
  };
2657
2665
  return instance;
2658
2666
  }
@@ -2668,9 +2676,9 @@
2668
2676
 
2669
2677
  function saveState$1() {
2670
2678
  if (currentSource) {
2671
- currentSource.src = Uint8Array.prototype.slice.call(currentSource.src, currentSource.position, currentSource.srcEnd);
2679
+ currentSource.bytes = Uint8Array.prototype.slice.call(currentSource.bytes, currentSource.position, currentSource.bytesEnd);
2672
2680
  currentSource.position = 0;
2673
- currentSource.srcEnd = currentSource.src.length;
2681
+ currentSource.bytesEnd = currentSource.bytes.length;
2674
2682
  }
2675
2683
  }
2676
2684
  function prepareStructures$1(structures, packr) {