msgpackr 1.7.0-alpha4 → 1.7.0-alpha5
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/index.js +5 -3
- package/dist/index.js.map +1 -1
- package/dist/index.min.js +17 -17
- package/dist/index.min.js.map +1 -1
- package/dist/node.cjs +17 -14
- package/dist/node.cjs.map +1 -1
- package/dist/test.js +18 -15
- package/dist/test.js.map +1 -1
- package/package.json +1 -1
- package/struct.js +12 -11
- package/unpack.js +5 -3
package/package.json
CHANGED
package/struct.js
CHANGED
|
@@ -478,12 +478,13 @@ function readStruct(src, position, srcEnd, unpackr) {
|
|
|
478
478
|
construct = structure.construct = function LazyObject() {
|
|
479
479
|
}
|
|
480
480
|
var prototype = construct.prototype;
|
|
481
|
+
let properties = [];
|
|
481
482
|
Object.defineProperty(prototype, 'toJSON', {
|
|
482
|
-
|
|
483
|
+
value() {
|
|
483
484
|
// return an enumerable object with own properties to JSON stringify
|
|
484
485
|
let resolved = {};
|
|
485
|
-
for (let i = 0, l =
|
|
486
|
-
let key =
|
|
486
|
+
for (let i = 0, l = properties.length; i < l; i++) {
|
|
487
|
+
let key = properties[i].key;
|
|
487
488
|
resolved[key] = this[key];
|
|
488
489
|
}
|
|
489
490
|
return resolved;
|
|
@@ -492,7 +493,6 @@ function readStruct(src, position, srcEnd, unpackr) {
|
|
|
492
493
|
});
|
|
493
494
|
let currentOffset = 0;
|
|
494
495
|
let lastRefProperty;
|
|
495
|
-
let properties = [];
|
|
496
496
|
for (let i = 0, l = structure.length; i < l; i++) {
|
|
497
497
|
let definition = structure[i];
|
|
498
498
|
let [ type, size, key, enumerationOffset ] = definition;
|
|
@@ -685,13 +685,14 @@ function toConstant(code) {
|
|
|
685
685
|
throw new Error('Unknown constant');
|
|
686
686
|
}
|
|
687
687
|
function prepareStructures(structures, packr) {
|
|
688
|
-
if (
|
|
689
|
-
|
|
690
|
-
|
|
691
|
-
|
|
692
|
-
|
|
688
|
+
if (packr.typedStructs) {
|
|
689
|
+
let structMap = new Map();
|
|
690
|
+
structMap.set('named', structures);
|
|
691
|
+
structMap.set('typed', packr.typedStructs);
|
|
692
|
+
structures = structMap;
|
|
693
|
+
}
|
|
693
694
|
let lastTypedStructuresLength = packr.lastTypedStructuresLength || 0;
|
|
694
|
-
|
|
695
|
+
structures.isCompatible = existing => {
|
|
695
696
|
let compatible = true;
|
|
696
697
|
if (existing instanceof Map) {
|
|
697
698
|
let named = existing.get('named') || [];
|
|
@@ -709,7 +710,7 @@ function prepareStructures(structures, packr) {
|
|
|
709
710
|
return compatible;
|
|
710
711
|
};
|
|
711
712
|
packr.lastTypedStructuresLength = packr.typedStructs?.length;
|
|
712
|
-
return
|
|
713
|
+
return structures;
|
|
713
714
|
}
|
|
714
715
|
|
|
715
716
|
setReadStruct(readStruct, onLoadedStructures);
|
package/unpack.js
CHANGED
|
@@ -95,7 +95,7 @@ export class Unpackr {
|
|
|
95
95
|
currentUnpackr = this
|
|
96
96
|
if (this.structures) {
|
|
97
97
|
currentStructures = this.structures
|
|
98
|
-
return checkedRead()
|
|
98
|
+
return checkedRead(options)
|
|
99
99
|
} else if (!currentStructures || currentStructures.length > 0) {
|
|
100
100
|
currentStructures = []
|
|
101
101
|
}
|
|
@@ -104,7 +104,7 @@ export class Unpackr {
|
|
|
104
104
|
if (!currentStructures || currentStructures.length > 0)
|
|
105
105
|
currentStructures = []
|
|
106
106
|
}
|
|
107
|
-
return checkedRead()
|
|
107
|
+
return checkedRead(options)
|
|
108
108
|
}
|
|
109
109
|
unpackMultiple(source, forEach) {
|
|
110
110
|
let values, lastPosition = 0
|
|
@@ -173,7 +173,7 @@ export class Unpackr {
|
|
|
173
173
|
export function getPosition() {
|
|
174
174
|
return position
|
|
175
175
|
}
|
|
176
|
-
export function checkedRead() {
|
|
176
|
+
export function checkedRead(options) {
|
|
177
177
|
try {
|
|
178
178
|
if (!currentUnpackr.trusted && !sequentialMode) {
|
|
179
179
|
let sharedLength = currentStructures.sharedLength || 0
|
|
@@ -183,6 +183,8 @@ export function checkedRead() {
|
|
|
183
183
|
let result
|
|
184
184
|
if (currentUnpackr.randomAccessStructure && src[position] < 0x40 && src[position] >= 0x20 && readStruct) {
|
|
185
185
|
result = readStruct(src, position, srcEnd, currentUnpackr)
|
|
186
|
+
if (!(options && options.lazy) && result)
|
|
187
|
+
result = result.toJSON()
|
|
186
188
|
position = srcEnd
|
|
187
189
|
} else
|
|
188
190
|
result = read()
|