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/node.cjs CHANGED
@@ -932,7 +932,16 @@ function readKey() {
932
932
 
933
933
  // the registration of the record definition extension (as "r")
934
934
  const recordDefinition = (id, highByte) => {
935
- var structure = read();
935
+ let structure;
936
+ if (currentUnpackr.freezeData) {
937
+ currentUnpackr.freezeData = false;
938
+ try {
939
+ structure = read();
940
+ } finally {
941
+ currentUnpackr.freezeData = true;
942
+ }
943
+ } else
944
+ structure = read();
936
945
  let firstByte = id;
937
946
  if (highByte !== undefined) {
938
947
  id = id < 32 ? -((highByte << 5) + id) : ((highByte << 5) + id);
@@ -2502,9 +2511,8 @@ function onLoadedStructures$1(sharedData) {
2502
2511
  this.lastTypedStructuresLength = typed.length;
2503
2512
  return named;
2504
2513
  }
2505
- var sourceSymbol = Symbol('source');
2514
+ var sourceSymbol = Symbol.for('source');
2506
2515
  function readStruct$1(src, position, srcEnd, unpackr) {
2507
- // var stringLength = (src[position++] << 8) | src[position++];
2508
2516
  let recordId = src[position++] - 0x20;
2509
2517
  if (recordId >= 24) {
2510
2518
  switch(recordId) {
@@ -2565,13 +2573,13 @@ function readStruct$1(src, position, srcEnd, unpackr) {
2565
2573
  case 0: getRef = () => 0; break;
2566
2574
  case 1:
2567
2575
  getRef = (source, position) => {
2568
- let ref = source.src[position + property.offset];
2576
+ let ref = source.bytes[position + property.offset];
2569
2577
  return ref >= 0xf6 ? toConstant(ref) : ref;
2570
2578
  };
2571
2579
  break;
2572
2580
  case 2:
2573
2581
  getRef = (source, position) => {
2574
- let src = source.src;
2582
+ let src = source.bytes;
2575
2583
  let dataView = src.dataView || (src.dataView = new DataView(src.buffer, src.byteOffset, src.byteLength));
2576
2584
  let ref = dataView.getUint16(position + property.offset, true);
2577
2585
  return ref >= 0xff00 ? toConstant(ref & 0xff) : ref;
@@ -2579,7 +2587,7 @@ function readStruct$1(src, position, srcEnd, unpackr) {
2579
2587
  break;
2580
2588
  case 4:
2581
2589
  getRef = (source, position) => {
2582
- let src = source.src;
2590
+ let src = source.bytes;
2583
2591
  let dataView = src.dataView || (src.dataView = new DataView(src.buffer, src.byteOffset, src.byteLength));
2584
2592
  let ref = dataView.getUint32(position + property.offset, true);
2585
2593
  return ref >= 0xffffff00 ? toConstant(ref & 0xff) : ref;
@@ -2597,7 +2605,7 @@ function readStruct$1(src, position, srcEnd, unpackr) {
2597
2605
  property.multiGetCount = 0;
2598
2606
  get = function() {
2599
2607
  let source = this[sourceSymbol];
2600
- let src = source.src;
2608
+ let src = source.bytes;
2601
2609
  let position = source.position;
2602
2610
  let refStart = currentOffset + position;
2603
2611
  let ref = getRef(source, position);
@@ -2613,7 +2621,7 @@ function readStruct$1(src, position, srcEnd, unpackr) {
2613
2621
  next = next.next;
2614
2622
  }
2615
2623
  if (end == null)
2616
- end = source.srcEnd - refStart;
2624
+ end = source.bytesEnd - refStart;
2617
2625
  if (source.srcString) {
2618
2626
  return source.srcString.slice(ref, end);
2619
2627
  }
@@ -2629,7 +2637,7 @@ function readStruct$1(src, position, srcEnd, unpackr) {
2629
2637
  asciiEnd = null;
2630
2638
  } while((next = next.next));
2631
2639
  if (asciiEnd == null)
2632
- asciiEnd = source.srcEnd - refStart
2640
+ asciiEnd = source.bytesEnd - refStart
2633
2641
  source.srcString = src.toString('latin1', refStart, refStart + asciiEnd);
2634
2642
  return source.srcString.slice(ref, end);
2635
2643
  }
@@ -2653,7 +2661,7 @@ function readStruct$1(src, position, srcEnd, unpackr) {
2653
2661
  let refStart = currentOffset + position;
2654
2662
  let ref = getRef(source, position);
2655
2663
  if (typeof ref !== 'number') return ref;
2656
- let src = source.src;
2664
+ let src = source.bytes;
2657
2665
  let end, next = property.next;
2658
2666
  while(next) {
2659
2667
  end = next.getRef(source, position);
@@ -2664,7 +2672,7 @@ function readStruct$1(src, position, srcEnd, unpackr) {
2664
2672
  next = next.next;
2665
2673
  }
2666
2674
  if (end == null)
2667
- end = source.srcEnd - refStart;
2675
+ end = source.bytesEnd - refStart;
2668
2676
  if (type === UTF8) {
2669
2677
  return src.toString('utf8', ref + refStart, end + refStart);
2670
2678
  } else {
@@ -2682,7 +2690,7 @@ function readStruct$1(src, position, srcEnd, unpackr) {
2682
2690
  case 4:
2683
2691
  get = function () {
2684
2692
  let source = this[sourceSymbol];
2685
- let src = source.src;
2693
+ let src = source.bytes;
2686
2694
  let dataView = src.dataView || (src.dataView = new DataView(src.buffer, src.byteOffset, src.byteLength));
2687
2695
  let position = source.position + property.offset;
2688
2696
  let value = dataView.getInt32(position, true);
@@ -2701,7 +2709,7 @@ function readStruct$1(src, position, srcEnd, unpackr) {
2701
2709
  case 8:
2702
2710
  get = function () {
2703
2711
  let source = this[sourceSymbol];
2704
- let src = source.src;
2712
+ let src = source.bytes;
2705
2713
  let dataView = src.dataView || (src.dataView = new DataView(src.buffer, src.byteOffset, src.byteLength));
2706
2714
  let value = dataView.getFloat64(source.position + property.offset, true);
2707
2715
  if (isNaN(value)) {
@@ -2715,7 +2723,7 @@ function readStruct$1(src, position, srcEnd, unpackr) {
2715
2723
  case 1:
2716
2724
  get = function () {
2717
2725
  let source = this[sourceSymbol];
2718
- let src = source.src;
2726
+ let src = source.bytes;
2719
2727
  let value = src[source.position + property.offset];
2720
2728
  return value < 0xf6 ? value : toConstant(value);
2721
2729
  };
@@ -2725,7 +2733,7 @@ function readStruct$1(src, position, srcEnd, unpackr) {
2725
2733
  case DATE:
2726
2734
  get = function () {
2727
2735
  let source = this[sourceSymbol];
2728
- let src = source.src;
2736
+ let src = source.bytes;
2729
2737
  let dataView = src.dataView || (src.dataView = new DataView(src.buffer, src.byteOffset, src.byteLength));
2730
2738
  return new Date(dataView.getFloat64(source.position + property.offset, true));
2731
2739
  };
@@ -2739,10 +2747,10 @@ function readStruct$1(src, position, srcEnd, unpackr) {
2739
2747
  }
2740
2748
  var instance = new construct();
2741
2749
  instance[sourceSymbol] = {
2742
- src,
2750
+ bytes: src,
2743
2751
  position,
2744
2752
  srcString: '',
2745
- srcEnd
2753
+ bytesEnd: srcEnd
2746
2754
  };
2747
2755
  return instance;
2748
2756
  }
@@ -2758,9 +2766,9 @@ function toConstant(code) {
2758
2766
 
2759
2767
  function saveState$1() {
2760
2768
  if (currentSource) {
2761
- currentSource.src = Uint8Array.prototype.slice.call(currentSource.src, currentSource.position, currentSource.srcEnd);
2769
+ currentSource.bytes = Uint8Array.prototype.slice.call(currentSource.bytes, currentSource.position, currentSource.bytesEnd);
2762
2770
  currentSource.position = 0;
2763
- currentSource.srcEnd = currentSource.src.length;
2771
+ currentSource.bytesEnd = currentSource.bytes.length;
2764
2772
  }
2765
2773
  }
2766
2774
  function prepareStructures$1(structures, packr) {