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/dist/test.js
CHANGED
|
@@ -94,7 +94,7 @@
|
|
|
94
94
|
currentUnpackr = this;
|
|
95
95
|
if (this.structures) {
|
|
96
96
|
currentStructures = this.structures;
|
|
97
|
-
return checkedRead()
|
|
97
|
+
return checkedRead(options)
|
|
98
98
|
} else if (!currentStructures || currentStructures.length > 0) {
|
|
99
99
|
currentStructures = [];
|
|
100
100
|
}
|
|
@@ -103,7 +103,7 @@
|
|
|
103
103
|
if (!currentStructures || currentStructures.length > 0)
|
|
104
104
|
currentStructures = [];
|
|
105
105
|
}
|
|
106
|
-
return checkedRead()
|
|
106
|
+
return checkedRead(options)
|
|
107
107
|
}
|
|
108
108
|
unpackMultiple(source, forEach) {
|
|
109
109
|
let values, lastPosition = 0;
|
|
@@ -169,7 +169,7 @@
|
|
|
169
169
|
return this.unpack(source, end)
|
|
170
170
|
}
|
|
171
171
|
}
|
|
172
|
-
function checkedRead() {
|
|
172
|
+
function checkedRead(options) {
|
|
173
173
|
try {
|
|
174
174
|
if (!currentUnpackr.trusted && !sequentialMode) {
|
|
175
175
|
let sharedLength = currentStructures.sharedLength || 0;
|
|
@@ -179,6 +179,8 @@
|
|
|
179
179
|
let result;
|
|
180
180
|
if (currentUnpackr.randomAccessStructure && src[position] < 0x40 && src[position] >= 0x20 && readStruct) {
|
|
181
181
|
result = readStruct(src, position, srcEnd, currentUnpackr);
|
|
182
|
+
if (!(options && options.lazy) && result)
|
|
183
|
+
result = result.toJSON();
|
|
182
184
|
position = srcEnd;
|
|
183
185
|
} else
|
|
184
186
|
result = read();
|
|
@@ -2412,12 +2414,13 @@
|
|
|
2412
2414
|
construct = structure.construct = function LazyObject() {
|
|
2413
2415
|
};
|
|
2414
2416
|
var prototype = construct.prototype;
|
|
2417
|
+
let properties = [];
|
|
2415
2418
|
Object.defineProperty(prototype, 'toJSON', {
|
|
2416
|
-
|
|
2419
|
+
value() {
|
|
2417
2420
|
// return an enumerable object with own properties to JSON stringify
|
|
2418
2421
|
let resolved = {};
|
|
2419
|
-
for (let i = 0, l =
|
|
2420
|
-
let key =
|
|
2422
|
+
for (let i = 0, l = properties.length; i < l; i++) {
|
|
2423
|
+
let key = properties[i].key;
|
|
2421
2424
|
resolved[key] = this[key];
|
|
2422
2425
|
}
|
|
2423
2426
|
return resolved;
|
|
@@ -2426,7 +2429,6 @@
|
|
|
2426
2429
|
});
|
|
2427
2430
|
let currentOffset = 0;
|
|
2428
2431
|
let lastRefProperty;
|
|
2429
|
-
let properties = [];
|
|
2430
2432
|
for (let i = 0, l = structure.length; i < l; i++) {
|
|
2431
2433
|
let definition = structure[i];
|
|
2432
2434
|
let [ type, size, key, enumerationOffset ] = definition;
|
|
@@ -2619,13 +2621,14 @@
|
|
|
2619
2621
|
throw new Error('Unknown constant');
|
|
2620
2622
|
}
|
|
2621
2623
|
function prepareStructures$1(structures, packr) {
|
|
2622
|
-
if (
|
|
2623
|
-
|
|
2624
|
-
|
|
2625
|
-
|
|
2626
|
-
|
|
2624
|
+
if (packr.typedStructs) {
|
|
2625
|
+
let structMap = new Map();
|
|
2626
|
+
structMap.set('named', structures);
|
|
2627
|
+
structMap.set('typed', packr.typedStructs);
|
|
2628
|
+
structures = structMap;
|
|
2629
|
+
}
|
|
2627
2630
|
let lastTypedStructuresLength = packr.lastTypedStructuresLength || 0;
|
|
2628
|
-
|
|
2631
|
+
structures.isCompatible = existing => {
|
|
2629
2632
|
let compatible = true;
|
|
2630
2633
|
if (existing instanceof Map) {
|
|
2631
2634
|
let named = existing.get('named') || [];
|
|
@@ -2643,7 +2646,7 @@
|
|
|
2643
2646
|
return compatible;
|
|
2644
2647
|
};
|
|
2645
2648
|
packr.lastTypedStructuresLength = packr.typedStructs?.length;
|
|
2646
|
-
return
|
|
2649
|
+
return structures;
|
|
2647
2650
|
}
|
|
2648
2651
|
|
|
2649
2652
|
setReadStruct(readStruct$1, onLoadedStructures$1);
|
|
@@ -2815,7 +2818,7 @@
|
|
|
2815
2818
|
} });
|
|
2816
2819
|
for (let i = 0; i < 20; i++) {
|
|
2817
2820
|
var serialized = packr.pack(data);
|
|
2818
|
-
var deserialized = packr.unpack(serialized);
|
|
2821
|
+
var deserialized = packr.unpack(serialized, { lazy: true });
|
|
2819
2822
|
var copied = {};
|
|
2820
2823
|
for (let key in deserialized) {
|
|
2821
2824
|
copied[key] = deserialized[key];
|