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/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "msgpackr",
3
3
  "author": "Kris Zyp",
4
- "version": "1.7.0-alpha7",
4
+ "version": "1.7.0-beta1",
5
5
  "description": "Ultra-fast MessagePack implementation with extensions for records and structured cloning",
6
6
  "license": "MIT",
7
7
  "types": "./index.d.ts",
package/struct.js CHANGED
@@ -472,9 +472,8 @@ function onLoadedStructures(sharedData) {
472
472
  this.lastTypedStructuresLength = typed.length;
473
473
  return named;
474
474
  }
475
- var sourceSymbol = Symbol('source')
475
+ var sourceSymbol = Symbol.for('source')
476
476
  function readStruct(src, position, srcEnd, unpackr) {
477
- // var stringLength = (src[position++] << 8) | src[position++];
478
477
  let recordId = src[position++] - 0x20;
479
478
  if (recordId >= 24) {
480
479
  switch(recordId) {
@@ -535,13 +534,13 @@ function readStruct(src, position, srcEnd, unpackr) {
535
534
  case 0: getRef = () => 0; break;
536
535
  case 1:
537
536
  getRef = (source, position) => {
538
- let ref = source.src[position + property.offset];
537
+ let ref = source.bytes[position + property.offset];
539
538
  return ref >= 0xf6 ? toConstant(ref) : ref;
540
539
  };
541
540
  break;
542
541
  case 2:
543
542
  getRef = (source, position) => {
544
- let src = source.src;
543
+ let src = source.bytes;
545
544
  let dataView = src.dataView || (src.dataView = new DataView(src.buffer, src.byteOffset, src.byteLength));
546
545
  let ref = dataView.getUint16(position + property.offset, true);
547
546
  return ref >= 0xff00 ? toConstant(ref & 0xff) : ref;
@@ -549,7 +548,7 @@ function readStruct(src, position, srcEnd, unpackr) {
549
548
  break;
550
549
  case 4:
551
550
  getRef = (source, position) => {
552
- let src = source.src;
551
+ let src = source.bytes;
553
552
  let dataView = src.dataView || (src.dataView = new DataView(src.buffer, src.byteOffset, src.byteLength));
554
553
  let ref = dataView.getUint32(position + property.offset, true);
555
554
  return ref >= 0xffffff00 ? toConstant(ref & 0xff) : ref;
@@ -567,7 +566,7 @@ function readStruct(src, position, srcEnd, unpackr) {
567
566
  property.multiGetCount = 0;
568
567
  get = function() {
569
568
  let source = this[sourceSymbol];
570
- let src = source.src;
569
+ let src = source.bytes;
571
570
  let position = source.position;
572
571
  let refStart = currentOffset + position;
573
572
  let ref = getRef(source, position);
@@ -583,7 +582,7 @@ function readStruct(src, position, srcEnd, unpackr) {
583
582
  next = next.next;
584
583
  }
585
584
  if (end == null)
586
- end = source.srcEnd - refStart;
585
+ end = source.bytesEnd - refStart;
587
586
  if (source.srcString) {
588
587
  return source.srcString.slice(ref, end);
589
588
  }
@@ -599,7 +598,7 @@ function readStruct(src, position, srcEnd, unpackr) {
599
598
  asciiEnd = null;
600
599
  } while((next = next.next));
601
600
  if (asciiEnd == null)
602
- asciiEnd = source.srcEnd - refStart
601
+ asciiEnd = source.bytesEnd - refStart
603
602
  source.srcString = src.toString('latin1', refStart, refStart + asciiEnd);
604
603
  return source.srcString.slice(ref, end);
605
604
  }
@@ -623,7 +622,7 @@ function readStruct(src, position, srcEnd, unpackr) {
623
622
  let refStart = currentOffset + position;
624
623
  let ref = getRef(source, position);
625
624
  if (typeof ref !== 'number') return ref;
626
- let src = source.src;
625
+ let src = source.bytes;
627
626
  let end, next = property.next;
628
627
  while(next) {
629
628
  end = next.getRef(source, position);
@@ -634,7 +633,7 @@ function readStruct(src, position, srcEnd, unpackr) {
634
633
  next = next.next;
635
634
  }
636
635
  if (end == null)
637
- end = source.srcEnd - refStart;
636
+ end = source.bytesEnd - refStart;
638
637
  if (type === UTF8) {
639
638
  return src.toString('utf8', ref + refStart, end + refStart);
640
639
  } else {
@@ -652,7 +651,7 @@ function readStruct(src, position, srcEnd, unpackr) {
652
651
  case 4:
653
652
  get = function () {
654
653
  let source = this[sourceSymbol];
655
- let src = source.src;
654
+ let src = source.bytes;
656
655
  let dataView = src.dataView || (src.dataView = new DataView(src.buffer, src.byteOffset, src.byteLength));
657
656
  let position = source.position + property.offset;
658
657
  let value = dataView.getInt32(position, true)
@@ -671,7 +670,7 @@ function readStruct(src, position, srcEnd, unpackr) {
671
670
  case 8:
672
671
  get = function () {
673
672
  let source = this[sourceSymbol];
674
- let src = source.src;
673
+ let src = source.bytes;
675
674
  let dataView = src.dataView || (src.dataView = new DataView(src.buffer, src.byteOffset, src.byteLength));
676
675
  let value = dataView.getFloat64(source.position + property.offset, true);
677
676
  if (isNaN(value)) {
@@ -685,7 +684,7 @@ function readStruct(src, position, srcEnd, unpackr) {
685
684
  case 1:
686
685
  get = function () {
687
686
  let source = this[sourceSymbol];
688
- let src = source.src;
687
+ let src = source.bytes;
689
688
  let value = src[source.position + property.offset];
690
689
  return value < 0xf6 ? value : toConstant(value);
691
690
  };
@@ -695,7 +694,7 @@ function readStruct(src, position, srcEnd, unpackr) {
695
694
  case DATE:
696
695
  get = function () {
697
696
  let source = this[sourceSymbol];
698
- let src = source.src;
697
+ let src = source.bytes;
699
698
  let dataView = src.dataView || (src.dataView = new DataView(src.buffer, src.byteOffset, src.byteLength));
700
699
  return new Date(dataView.getFloat64(source.position + property.offset, true));
701
700
  };
@@ -709,10 +708,10 @@ function readStruct(src, position, srcEnd, unpackr) {
709
708
  }
710
709
  var instance = new construct();
711
710
  instance[sourceSymbol] = {
712
- src,
711
+ bytes: src,
713
712
  position,
714
713
  srcString: '',
715
- srcEnd
714
+ bytesEnd: srcEnd
716
715
  }
717
716
  return instance;
718
717
  }
@@ -728,9 +727,9 @@ function toConstant(code) {
728
727
 
729
728
  function saveState() {
730
729
  if (currentSource) {
731
- currentSource.src = Uint8Array.prototype.slice.call(currentSource.src, currentSource.position, currentSource.srcEnd);
730
+ currentSource.bytes = Uint8Array.prototype.slice.call(currentSource.bytes, currentSource.position, currentSource.bytesEnd);
732
731
  currentSource.position = 0;
733
- currentSource.srcEnd = currentSource.src.length;
732
+ currentSource.bytesEnd = currentSource.bytes.length;
734
733
  }
735
734
  }
736
735
  function prepareStructures(structures, packr) {
package/unpack.js CHANGED
@@ -930,7 +930,16 @@ function readKey() {
930
930
 
931
931
  // the registration of the record definition extension (as "r")
932
932
  const recordDefinition = (id, highByte) => {
933
- var structure = read()
933
+ let structure
934
+ if (currentUnpackr.freezeData) {
935
+ currentUnpackr.freezeData = false;
936
+ try {
937
+ structure = read()
938
+ } finally {
939
+ currentUnpackr.freezeData = true;
940
+ }
941
+ } else
942
+ structure = read()
934
943
  let firstByte = id
935
944
  if (highByte !== undefined) {
936
945
  id = id < 32 ? -((highByte << 5) + id) : ((highByte << 5) + id)