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/README.md +1 -1
- package/dist/index.js +10 -1
- package/dist/index.js.map +1 -1
- package/dist/index.min.js +45 -45
- package/dist/index.min.js.map +1 -1
- package/dist/node.cjs +27 -19
- package/dist/node.cjs.map +1 -1
- package/dist/test.js +27 -19
- package/dist/test.js.map +1 -1
- package/package.json +1 -1
- package/struct.js +17 -18
- package/unpack.js +10 -1
package/package.json
CHANGED
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.
|
|
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.
|
|
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.
|
|
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.
|
|
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.
|
|
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.
|
|
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.
|
|
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.
|
|
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.
|
|
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.
|
|
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.
|
|
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.
|
|
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.
|
|
730
|
+
currentSource.bytes = Uint8Array.prototype.slice.call(currentSource.bytes, currentSource.position, currentSource.bytesEnd);
|
|
732
731
|
currentSource.position = 0;
|
|
733
|
-
currentSource.
|
|
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
|
-
|
|
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)
|