msgpackr 1.7.0-alpha7 → 1.7.0
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 +23 -5
- package/dist/index.js.map +1 -1
- package/dist/index.min.js +53 -53
- package/dist/index.min.js.map +1 -1
- package/dist/node.cjs +93 -49
- package/dist/node.cjs.map +1 -1
- package/dist/test.js +104 -49
- package/dist/test.js.map +1 -1
- package/index.d.ts +62 -14
- package/pack.d.ts +1 -9
- package/pack.js +0 -1
- package/package.json +8 -3
- package/struct.js +70 -44
- package/unpack.d.ts +2 -53
- package/unpack.js +23 -6
package/README.md
CHANGED
|
@@ -40,7 +40,7 @@ stream.write(myData);
|
|
|
40
40
|
```
|
|
41
41
|
Or for a full example of sending and receiving data on a stream:
|
|
42
42
|
```js
|
|
43
|
-
import { PackrStream } from 'msgpackr';
|
|
43
|
+
import { PackrStream, UnpackrStream } from 'msgpackr';
|
|
44
44
|
let sendingStream = new PackrStream();
|
|
45
45
|
let receivingStream = new UnpackrStream();
|
|
46
46
|
// we are just piping to our own stream, but normally you would send and
|
package/dist/index.js
CHANGED
|
@@ -177,6 +177,7 @@
|
|
|
177
177
|
let result;
|
|
178
178
|
if (currentUnpackr.randomAccessStructure && src[position] < 0x40 && src[position] >= 0x20 && readStruct) {
|
|
179
179
|
result = readStruct(src, position, srcEnd, currentUnpackr);
|
|
180
|
+
src = null; // dispose of this so that recursive unpack calls don't save state
|
|
180
181
|
if (!(options && options.lazy) && result)
|
|
181
182
|
result = result.toJSON();
|
|
182
183
|
position = srcEnd;
|
|
@@ -187,7 +188,7 @@
|
|
|
187
188
|
|
|
188
189
|
if (position == srcEnd) {
|
|
189
190
|
// finished reading this source, cleanup references
|
|
190
|
-
if (currentStructures
|
|
191
|
+
if (currentStructures?.restoreStructures)
|
|
191
192
|
restoreStructures();
|
|
192
193
|
currentStructures = null;
|
|
193
194
|
src = null;
|
|
@@ -242,7 +243,10 @@
|
|
|
242
243
|
if (currentUnpackr.mapsAsObjects) {
|
|
243
244
|
let object = {};
|
|
244
245
|
for (let i = 0; i < token; i++) {
|
|
245
|
-
|
|
246
|
+
let key = readKey();
|
|
247
|
+
if (key === '__proto__')
|
|
248
|
+
key = '__proto_';
|
|
249
|
+
object[key] = read();
|
|
246
250
|
}
|
|
247
251
|
return object
|
|
248
252
|
} else {
|
|
@@ -471,7 +475,7 @@
|
|
|
471
475
|
// This initial function is quick to instantiate, but runs slower. After several iterations pay the cost to build the faster function
|
|
472
476
|
if (readObject.count++ > inlineObjectReadThreshold) {
|
|
473
477
|
let readObject = structure.read = (new Function('r', 'return function(){return ' + (currentUnpackr.freezeData ? 'Object.freeze' : '') +
|
|
474
|
-
'({' + structure.map(key => validName.test(key) ? key + ':r()' : ('[' + JSON.stringify(key) + ']:r()')).join(',') + '})}'))(read);
|
|
478
|
+
'({' + structure.map(key => key === '__proto__' ? '__proto_:r()' : validName.test(key) ? key + ':r()' : ('[' + JSON.stringify(key) + ']:r()')).join(',') + '})}'))(read);
|
|
475
479
|
if (structure.highByte === 0)
|
|
476
480
|
structure.read = createSecondByteReader(firstId, structure.read);
|
|
477
481
|
return readObject() // second byte is already read, if there is one so immediately read object
|
|
@@ -479,6 +483,8 @@
|
|
|
479
483
|
let object = {};
|
|
480
484
|
for (let i = 0, l = structure.length; i < l; i++) {
|
|
481
485
|
let key = structure[i];
|
|
486
|
+
if (key === '__proto__')
|
|
487
|
+
key = '__proto_';
|
|
482
488
|
object[key] = read();
|
|
483
489
|
}
|
|
484
490
|
if (currentUnpackr.freezeData)
|
|
@@ -590,7 +596,10 @@
|
|
|
590
596
|
if (currentUnpackr.mapsAsObjects) {
|
|
591
597
|
let object = {};
|
|
592
598
|
for (let i = 0; i < length; i++) {
|
|
593
|
-
|
|
599
|
+
let key = readKey();
|
|
600
|
+
if (key === '__proto__')
|
|
601
|
+
key = '__proto_';
|
|
602
|
+
object[key] = read();
|
|
594
603
|
}
|
|
595
604
|
return object
|
|
596
605
|
} else {
|
|
@@ -875,7 +884,16 @@
|
|
|
875
884
|
|
|
876
885
|
// the registration of the record definition extension (as "r")
|
|
877
886
|
const recordDefinition = (id, highByte) => {
|
|
878
|
-
|
|
887
|
+
let structure;
|
|
888
|
+
if (currentUnpackr.freezeData) {
|
|
889
|
+
currentUnpackr.freezeData = false;
|
|
890
|
+
try {
|
|
891
|
+
structure = read();
|
|
892
|
+
} finally {
|
|
893
|
+
currentUnpackr.freezeData = true;
|
|
894
|
+
}
|
|
895
|
+
} else
|
|
896
|
+
structure = read();
|
|
879
897
|
let firstByte = id;
|
|
880
898
|
if (highByte !== undefined) {
|
|
881
899
|
id = id < 32 ? -((highByte << 5) + id) : ((highByte << 5) + id);
|