msgpackr 1.5.4 → 1.5.5
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 +2 -1
- package/dist/index.js +19 -9
- package/dist/index.min.js +63 -62
- package/dist/node.cjs +19 -9
- package/dist/test.js +2 -0
- package/pack.js +11 -8
- package/package.json +1 -1
- package/unpack.d.ts +2 -0
- package/unpack.js +8 -1
- package/dist/str.cjs +0 -100
package/README.md
CHANGED
|
@@ -159,7 +159,8 @@ The following options properties can be provided to the Packr or Unpackr constru
|
|
|
159
159
|
|
|
160
160
|
* `useRecords` - Setting this to `false` disables the record extension and stores JavaScript objects as MessagePack maps, and unpacks maps as JavaScript `Object`s, which ensures compatibilty with other decoders.
|
|
161
161
|
* `structures` - Provides the array of structures that is to be used for record extension, if you want the structures saved and used again. This array will be modified in place with new record structures that are serialized (if less than 32 structures are in the array).
|
|
162
|
-
* `
|
|
162
|
+
* `moreTypes` - Enable serialization of additional built-in types/classes including typed arrays, `Set`s, `Map`s, and `Error`s.
|
|
163
|
+
* `structuredClone` - This enables the structured cloning extensions that will encode object/cyclic references. `moreTypes` is enabled by default when this is enabled.
|
|
163
164
|
* `mapsAsObjects` - If `true`, this will decode MessagePack maps and JS `Object`s with the map entries decoded to object properties. If `false`, maps are decoded as JavaScript `Map`s. This is disabled by default if `useRecords` is enabled (which allows `Map`s to be preserved), and is enabled by default if `useRecords` is disabled.
|
|
164
165
|
* `useFloat32` - This will enable msgpackr to encode non-integer numbers as `float32`. See next section for possible values.
|
|
165
166
|
* `variableMapSize` - This will use varying map size definition (fixmap, map16, map32) based on the number of keys when encoding objects, which yields slightly more compact encodings (for small objects), but is typically 5-10% slower during encoding. This is necessary if you need to use objects with more than 65535 keys. This is only relevant when record extension is disabled.
|
package/dist/index.js
CHANGED
|
@@ -28,6 +28,13 @@
|
|
|
28
28
|
const C1 = new C1Type();
|
|
29
29
|
C1.name = 'MessagePack 0xC1';
|
|
30
30
|
var sequentialMode = false;
|
|
31
|
+
var inlineObjectReadThreshold = 2;
|
|
32
|
+
try {
|
|
33
|
+
new Function('');
|
|
34
|
+
} catch(error) {
|
|
35
|
+
// if eval variants are not supported, do not create inline object readers ever
|
|
36
|
+
inlineObjectReadThreshold = Infinity;
|
|
37
|
+
}
|
|
31
38
|
|
|
32
39
|
class Unpackr {
|
|
33
40
|
constructor(options) {
|
|
@@ -436,7 +443,7 @@
|
|
|
436
443
|
function createStructureReader(structure, firstId) {
|
|
437
444
|
function readObject() {
|
|
438
445
|
// This initial function is quick to instantiate, but runs slower. After several iterations pay the cost to build the faster function
|
|
439
|
-
if (readObject.count++ >
|
|
446
|
+
if (readObject.count++ > inlineObjectReadThreshold) {
|
|
440
447
|
let readObject = structure.read = (new Function('r', 'return function(){return {' + structure.map(key => validName.test(key) ? key + ':r()' : ('[' + JSON.stringify(key) + ']:r()')).join(',') + '}}'))(read);
|
|
441
448
|
if (structure.highByte === 0)
|
|
442
449
|
structure.read = createSecondByteReader(firstId, structure.read);
|
|
@@ -1041,6 +1048,9 @@
|
|
|
1041
1048
|
maxSharedStructures = hasSharedStructures ? 32 : 0;
|
|
1042
1049
|
if (maxSharedStructures > 8160)
|
|
1043
1050
|
throw new Error('Maximum maxSharedStructure is 8160')
|
|
1051
|
+
if (options.structuredClone && options.moreTypes == undefined) {
|
|
1052
|
+
options.moreTypes = true;
|
|
1053
|
+
}
|
|
1044
1054
|
let maxOwnStructures = options.maxOwnStructures;
|
|
1045
1055
|
if (maxOwnStructures == null)
|
|
1046
1056
|
maxOwnStructures = hasSharedStructures ? 32 : 64;
|
|
@@ -1732,8 +1742,8 @@
|
|
|
1732
1742
|
}, {
|
|
1733
1743
|
pack(set, allocateForWrite, pack) {
|
|
1734
1744
|
let array = Array.from(set);
|
|
1735
|
-
let { target, position} = allocateForWrite(this.
|
|
1736
|
-
if (this.
|
|
1745
|
+
let { target, position} = allocateForWrite(this.moreTypes ? 3 : 0);
|
|
1746
|
+
if (this.moreTypes) {
|
|
1737
1747
|
target[position++] = 0xd4;
|
|
1738
1748
|
target[position++] = 0x73; // 's' for Set
|
|
1739
1749
|
target[position++] = 0;
|
|
@@ -1742,8 +1752,8 @@
|
|
|
1742
1752
|
}
|
|
1743
1753
|
}, {
|
|
1744
1754
|
pack(error, allocateForWrite, pack) {
|
|
1745
|
-
let { target, position} = allocateForWrite(this.
|
|
1746
|
-
if (this.
|
|
1755
|
+
let { target, position} = allocateForWrite(this.moreTypes ? 3 : 0);
|
|
1756
|
+
if (this.moreTypes) {
|
|
1747
1757
|
target[position++] = 0xd4;
|
|
1748
1758
|
target[position++] = 0x65; // 'e' for error
|
|
1749
1759
|
target[position++] = 0;
|
|
@@ -1752,8 +1762,8 @@
|
|
|
1752
1762
|
}
|
|
1753
1763
|
}, {
|
|
1754
1764
|
pack(regex, allocateForWrite, pack) {
|
|
1755
|
-
let { target, position} = allocateForWrite(this.
|
|
1756
|
-
if (this.
|
|
1765
|
+
let { target, position} = allocateForWrite(this.moreTypes ? 3 : 0);
|
|
1766
|
+
if (this.moreTypes) {
|
|
1757
1767
|
target[position++] = 0xd4;
|
|
1758
1768
|
target[position++] = 0x78; // 'x' for regeXp
|
|
1759
1769
|
target[position++] = 0;
|
|
@@ -1762,7 +1772,7 @@
|
|
|
1762
1772
|
}
|
|
1763
1773
|
}, {
|
|
1764
1774
|
pack(arrayBuffer, allocateForWrite) {
|
|
1765
|
-
if (this.
|
|
1775
|
+
if (this.moreTypes)
|
|
1766
1776
|
writeExtBuffer(arrayBuffer, 0x10, allocateForWrite);
|
|
1767
1777
|
else
|
|
1768
1778
|
writeBuffer(hasNodeBuffer ? Buffer.from(arrayBuffer) : new Uint8Array(arrayBuffer), allocateForWrite);
|
|
@@ -1770,7 +1780,7 @@
|
|
|
1770
1780
|
}, {
|
|
1771
1781
|
pack(typedArray, allocateForWrite) {
|
|
1772
1782
|
let constructor = typedArray.constructor;
|
|
1773
|
-
if (constructor !== ByteArray && this.
|
|
1783
|
+
if (constructor !== ByteArray && this.moreTypes)
|
|
1774
1784
|
writeExtBuffer(typedArray, typedArrays.indexOf(constructor.name), allocateForWrite);
|
|
1775
1785
|
else
|
|
1776
1786
|
writeBuffer(typedArray, allocateForWrite);
|
package/dist/index.min.js
CHANGED
|
@@ -1,82 +1,83 @@
|
|
|
1
|
-
(function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports):"function"==typeof define&&define.amd?define(["exports"],t):(e=e||self,t(e.msgpackr={}))})(this,function(e){'use strict';var t=Math.floor;function n(){try{if(!
|
|
2
|
-
|
|
1
|
+
(function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports):"function"==typeof define&&define.amd?define(["exports"],t):(e=e||self,t(e.msgpackr={}))})(this,function(e){'use strict';var t=Math.floor;function n(){try{if(!D.trusted&&!Y){let e=M.sharedLength||0;e<M.length&&(M.length=e)}let e=r();if(B&&(// bundled strings to skip past
|
|
2
|
+
P=B.postBundlePosition),P==E)M.restoreStructures&&s(),M=null,R=null,C&&(C=null);else if(P>E){// over read
|
|
3
3
|
let e=new Error("Unexpected end of MessagePack data");throw e.incomplete=!0,e}else if(!Y)throw new Error("Data read, but end of buffer not reached");// else more to read, but we are reading sequentially, so don't clear source yet
|
|
4
|
-
return e}catch(e){throw
|
|
5
|
-
let t=e-160;if(
|
|
6
|
-
let e=16>t?g(t):c(t);if(null!=e)return e}return
|
|
4
|
+
return e}catch(e){throw M.restoreStructures&&s(),m(),(e instanceof RangeError||e.message.startsWith("Unexpected end of buffer"))&&(e.incomplete=!0),e}}function s(){for(let e in M.restoreStructures)M[e]=M.restoreStructures[e];M.restoreStructures=null}function r(){let e=R[P++];if(160>e){if(!(128>e)){if(!(144>e)){e-=144;let t=Array(e);for(let n=0;n<e;n++)t[n]=r();return t}if(e-=128,D.mapsAsObjects){let t={};for(let n=0;n<e;n++)t[h()]=r();return t}else{let t=new Map;for(let n=0;n<e;n++)t.set(r(),r());return t}}else if(64>e)return e;else{let t=M[63&e]||D.getStructures&&o()[63&e];return t?(t.read||(t.read=i(t,63&e)),t.read()):e}}else if(192>e){// fixstr
|
|
5
|
+
let t=e-160;if(j>=P)return _.slice(P-F,(P+=t)-F);if(0==j&&140>E){// for small blocks, avoiding the overhead of the extract call is helpful
|
|
6
|
+
let e=16>t?g(t):c(t);if(null!=e)return e}return H(t)}else{let t;switch(e){case 192:return null;case 193:return B?(t=r(),0<t?B[1].slice(B.position1,B.position1+=t):B[0].slice(B.position0,B.position0-=t)):W;// "never-used", return special object to denote that
|
|
7
7
|
case 194:return!1;case 195:return!0;case 196:// bin 8
|
|
8
|
-
return
|
|
9
|
-
return f(
|
|
10
|
-
let e=re[(127&
|
|
11
|
-
case 204:return
|
|
12
|
-
case 208:return
|
|
8
|
+
return l(R[P++]);case 197:return t=T.getUint16(P),P+=2,l(t);case 198:return t=T.getUint32(P),P+=4,l(t);case 199:// ext 8
|
|
9
|
+
return f(R[P++]);case 200:return t=T.getUint16(P),P+=2,f(t);case 201:return t=T.getUint32(P),P+=4,f(t);case 202:if(t=T.getFloat32(P),2<D.useFloat32){// this does rounding of numbers that were encoded in 32-bit float to nearest significant decimal digit that could be preserved
|
|
10
|
+
let e=re[(127&R[P])<<1|R[P+1]>>7];return P+=4,(e*t+(0<t?.5:-.5)>>0)/e}return P+=4,t;case 203:return t=T.getFloat64(P),P+=8,t;// uint handlers
|
|
11
|
+
case 204:return R[P++];case 205:return t=T.getUint16(P),P+=2,t;case 206:return t=T.getUint32(P),P+=4,t;case 207:return D.int64AsNumber?(t=4294967296*T.getUint32(P),t+=T.getUint32(P+4)):t=T.getBigUint64(P),P+=8,t;// int handlers
|
|
12
|
+
case 208:return T.getInt8(P++);case 209:return t=T.getInt16(P),P+=2,t;case 210:return t=T.getInt32(P),P+=4,t;case 211:return D.int64AsNumber?(t=4294967296*T.getInt32(P),t+=T.getUint32(P+4)):t=T.getBigInt64(P),P+=8,t;case 212:if(t=R[P++],114==t)return ee(63&R[P++]);else{let e=v[t];if(e)return e.read?(P++,e.read(r())):e.noBuffer?(P++,e()):e(R.subarray(P,++P));throw new Error("Unknown extension "+t)}case 213:return t=R[P],114==t?(P++,ee(63&R[P++],R[P++])):f(2);case 214:// fixext 4
|
|
13
13
|
return f(4);case 215:// fixext 8
|
|
14
14
|
return f(8);case 216:// fixext 16
|
|
15
|
-
return f(16);case 217:return t=
|
|
15
|
+
return f(16);case 217:return t=R[P++],j>=P?_.slice(P-F,(P+=t)-F):J(t);case 218:return t=T.getUint16(P),P+=2,j>=P?_.slice(P-F,(P+=t)-F):K(t);case 219:return t=T.getUint32(P),P+=4,j>=P?_.slice(P-F,(P+=t)-F):Q(t);case 220:return t=T.getUint16(P),P+=2,u(t);case 221:return t=T.getUint32(P),P+=4,u(t);case 222:return t=T.getUint16(P),P+=2,d(t);case 223:return t=T.getUint32(P),P+=4,d(t);default:// negative int
|
|
16
16
|
if(224<=e)return e-256;if(void 0===e){let e=new Error("Unexpected end of MessagePack data");throw e.incomplete=!0,e}throw new Error("Unknown MessagePack token "+e);}}}function i(e,t){function n(){// This initial function is quick to instantiate, but runs slower. After several iterations pay the cost to build the faster function
|
|
17
|
-
if(
|
|
18
|
-
}let
|
|
19
|
-
const t=63&
|
|
20
|
-
const t=63&
|
|
21
|
-
const t=63&
|
|
22
|
-
e=t-160;else switch(t){case 217:e=
|
|
23
|
-
Uint8Array.prototype.slice.call(
|
|
24
|
-
return
|
|
25
|
-
let d=16>e?g(e):c(e);return null==d?
|
|
17
|
+
if(n.count++>z){let n=e.read=new Function("r","return function(){return {"+e.map(e=>q.test(e)?e+":r()":"["+JSON.stringify(e)+"]:r()").join(",")+"}}")(r);return 0===e.highByte&&(e.read=G(t,e.read)),n();// second byte is already read, if there is one so immediately read object
|
|
18
|
+
}let s={};for(let t,n=0,i=e.length;n<i;n++)t=e[n],s[t]=r();return s}return n.count=0,0===e.highByte?G(t,n):n}function o(){let e=y(()=>(R=null,D.getStructures()));return M=D._mergeStructures(e,M)}function a(e){let t;if(16>e&&(t=g(e)))return t;if(64<e&&x)return x.decode(R.subarray(P,P+=e));const n=P+e,s=[];for(t="";P<n;){const e=R[P++];if(0==(128&e))s.push(e);else if(192==(224&e)){// 2 bytes
|
|
19
|
+
const t=63&R[P++];s.push((31&e)<<6|t)}else if(224==(240&e)){// 3 bytes
|
|
20
|
+
const t=63&R[P++],n=63&R[P++];s.push((31&e)<<12|t<<6|n)}else if(240==(248&e)){// 4 bytes
|
|
21
|
+
const t=63&R[P++],n=63&R[P++],r=63&R[P++];let i=(7&e)<<18|t<<12|n<<6|r;65535<i&&(i-=65536,s.push(55296|1023&i>>>10),i=56320|1023&i),s.push(i)}else s.push(e);4096<=s.length&&(t+=X.apply(String,s),s.length=0)}return 0<s.length&&(t+=X.apply(String,s)),t}function u(e){let t=Array(e);for(let n=0;n<e;n++)t[n]=r();return t}function d(e){if(D.mapsAsObjects){let t={};for(let n=0;n<e;n++)t[h()]=r();return t}else{let t=new Map;for(let n=0;n<e;n++)t.set(r(),r());return t}}function c(e){let t=P,n=Array(e);for(let s=0;s<e;s++){const e=R[P++];if(0<(128&e))return void(P=t);n[s]=e}return X.apply(String,n)}function g(t){if(4>t){if(!(2>t)){let e=R[P++],n=R[P++];if(0<(128&e)||0<(128&n))return void(P-=2);if(3>t)return X(e,n);let s=R[P++];return 0<(128&s)?void(P-=3):X(e,n,s)}if(0===t)return"";else{let e=R[P++];return 1<(128&e)?void(P-=1):X(e)}}else{let s=R[P++],r=R[P++],a=R[P++],u=R[P++];if(0<(128&s)||0<(128&r)||0<(128&a)||0<(128&u))return void(P-=4);if(6>t){if(4===t)return X(s,r,a,u);else{let t=R[P++];return 0<(128&t)?void(P-=5):X(s,r,a,u,t)}}else if(8>t){let n=R[P++],e=R[P++];if(0<(128&n)||0<(128&e))return void(P-=6);if(7>t)return X(s,r,a,u,n,e);let i=R[P++];return 0<(128&i)?void(P-=7):X(s,r,a,u,n,e,i)}else{let d=R[P++],e=R[P++],c=R[P++],g=R[P++];if(0<(128&d)||0<(128&e)||0<(128&c)||0<(128&g))return void(P-=8);if(10>t){if(8===t)return X(s,r,a,u,d,e,c,g);else{let t=R[P++];return 0<(128&t)?void(P-=9):X(s,r,a,u,d,e,c,g,t)}}else if(12>t){let n=R[P++],i=R[P++];if(0<(128&n)||0<(128&i))return void(P-=10);if(11>t)return X(s,r,a,u,d,e,c,g,n,i);let o=R[P++];return 0<(128&o)?void(P-=11):X(s,r,a,u,d,e,c,g,n,i,o)}else{let p=R[P++],i=R[P++],f=R[P++],h=R[P++];if(0<(128&p)||0<(128&i)||0<(128&f)||0<(128&h))return void(P-=12);if(!(14>t)){let l=R[P++],y=R[P++];if(0<(128&l)||0<(128&y))return void(P-=14);if(15>t)return X(s,r,a,u,d,e,c,g,p,i,f,h,l,y);let n=R[P++];return 0<(128&n)?void(P-=15):X(s,r,a,u,d,e,c,g,p,i,f,h,l,y,n)}if(12===t)return X(s,r,a,u,d,e,c,g,p,i,f,h);else{let t=R[P++];return 0<(128&t)?void(P-=13):X(s,r,a,u,d,e,c,g,p,i,f,h,t)}}}}}function p(){let e,t=R[P++];if(192>t)// fixstr
|
|
22
|
+
e=t-160;else switch(t){case 217:e=R[P++];break;case 218:e=T.getUint16(P),P+=2;break;case 219:e=T.getUint32(P),P+=4;break;default:throw new Error("Expected string");}return a(e)}function l(e){return D.copyBuffers?// specifically use the copying slice (not the node one)
|
|
23
|
+
Uint8Array.prototype.slice.call(R,P,P+=e):R.subarray(P,P+=e)}function f(e){let t=R[P++];if(v[t])return v[t](R.subarray(P,P+=e));throw new Error("Unknown extension type "+t)}function h(){let e=R[P++];if(160<=e&&192>e){if(e-=160,j>=P)// if it has been extracted, must use it (and faster anyway)
|
|
24
|
+
return _.slice(P-F,(P+=e)-F);if(!(0==j&&180>E))return H(e)}else return P--,r();let t,n=4095&(e<<5^(1<e?T.getUint16(P):0<e?R[P]:0)),s=Z[n],o=P,a=P+e-3,u=0;if(s&&s.bytes==e){for(;o<a;){if(t=T.getUint32(o),t!=s[u++]){o=1879048192;break}o+=4}for(a+=3;o<a;)if(t=R[o++],t!=s[u++]){o=1879048192;break}if(o===a)return P=o,s.string;a-=3,o=P}for(s=[],Z[n]=s,s.bytes=e;o<a;)t=T.getUint32(o),s.push(t),o+=4;for(a+=3;o<a;)t=R[o++],s.push(t);// for small blocks, avoiding the overhead of the extract call is helpful
|
|
25
|
+
let d=16>e?g(e):c(e);return null==d?s.string=H(e):s.string=d}// the registration of the record definition extension (as "r")
|
|
26
26
|
// notepack defines extension 0 to mean undefined, so use that as the default here
|
|
27
27
|
// registration of bulk record definition?
|
|
28
28
|
// currentExtensions[0x52] = () =>
|
|
29
|
-
function y(e){let t=
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
let n,
|
|
33
|
-
e[o++]=214,e[o++]=105,e[o++]=i>>24,e[o++]=255&i>>16,e[o++]=255&i>>8,e[o++]=255&i,
|
|
29
|
+
function y(e){let t=E,n=P,s=F,r=j,i=_,o=C,a=B,u=new Uint8Array(R.slice(0,E)),d=M,c=M.slice(0,M.length),g=D,p=Y,l=e();return E=t,P=n,F=s,j=r,_=i,C=o,B=a,R=u,Y=p,M=d,M.splice(0,M.length,...c),D=g,T=new DataView(R.buffer,R.byteOffset,R.byteLength),l}function m(){R=null,C=null,M=null}function b(e){v[e.type]=e.unpack?e.unpack:e}function k(e,t,n){let s=e.byteLength;if(256>s+1){var{target:r,position:i}=n(4+s);r[i++]=199,r[i++]=s+1}else if(65536>s+1){var{target:r,position:i}=n(5+s);r[i++]=200,r[i++]=s+1>>8,r[i++]=255&s+1}else{var{target:r,position:i,targetView:o}=n(7+s);// plus one for the type byte
|
|
30
|
+
r[i++]=201,o.setUint32(i,s+1),i+=4}// "t" for typed array
|
|
31
|
+
r[i++]=116,r[i++]=t,r.set(new Uint8Array(e.buffer,e.byteOffset,e.byteLength),i)}function U(e,t){let n=e.byteLength;var s,r;if(256>n){var{target:s,position:r}=t(n+2);s[r++]=196,s[r++]=n}else if(65536>n){var{target:s,position:r}=t(n+3);s[r++]=197,s[r++]=n>>8,s[r++]=255&n}else{var{target:s,position:r,targetView:i}=t(n+5);s[r++]=198,i.setUint32(r,n),r+=4}s.set(e,r)}function I(e,t,n,s){let r=e.length;return 1===r?t[n++]=212:2===r?t[n++]=213:4===r?t[n++]=214:8===r?t[n++]=215:16===r?t[n++]=216:256>r?(t[n++]=199,t[n++]=r):65536>r?(t[n++]=200,t[n++]=r>>8,t[n++]=255&r):(t[n++]=201,t[n++]=r>>24,t[n++]=255&r>>16,t[n++]=255&r>>8,t[n++]=255&r),t[n++]=s,t.set(e,n),n+=r,n}function S(e,t){// insert the ids that need to be referenced for structured clones
|
|
32
|
+
let n,s=6*t.length,r=e.length-s;for(t.sort((e,t)=>e.offset>t.offset?1:-1);n=t.pop();){let t=n.offset,i=n.id;e.copyWithin(t+s,t,r),s-=6;let o=t+s;// 'i'
|
|
33
|
+
e[o++]=214,e[o++]=105,e[o++]=i>>24,e[o++]=255&i>>16,e[o++]=255&i>>8,e[o++]=255&i,r=t}return e}function O(e,t){Ie.setUint32(Ae.position+e,Oe-Ae.position-e);let n=Ae;Ae=null,t(n[0]),t(n[1])}function A(e){if(e.Class){if(!e.pack&&!e.write)throw new Error("Extension has no pack or write function");if(e.pack&&!e.type)throw new Error("Extension has no type (numeric code to identify the extension)");fe.unshift(e.Class),le.unshift(e)}b(e)}function*w(e,t){const n=new Le(t);for(const s of e)yield n.pack(s)}async function*L(e,t){const n=new Le(t);for await(const s of e)yield n.pack(s)}/**
|
|
34
34
|
* Given an Iterable/Iterator input which yields buffers, returns an IterableIterator which yields sync decoded objects
|
|
35
35
|
* Or, given an Async Iterable/Iterator which yields promises resolving in buffers, returns an AsyncIterableIterator.
|
|
36
36
|
* @param {Iterable|Iterator|AsyncIterable|AsyncIterableIterator} bufferIterator
|
|
37
37
|
* @param {object} [options] - unpackr options
|
|
38
38
|
* @returns {IterableIterator|Promise.<AsyncIterableIterator}
|
|
39
|
-
*/var
|
|
40
|
-
|
|
39
|
+
*/var x;try{x=new TextDecoder}catch(e){}var R,E,M,_,B,C,T,P=0,D={},F=0,j=0,v=[],N={useRecords:!1,mapsAsObjects:!0};class V{}const W=new V;W.name="MessagePack 0xC1";var Y=!1,z=2;try{new Function("")}catch(e){// if eval variants are not supported, do not create inline object readers ever
|
|
40
|
+
z=1/0}class ${constructor(e){e&&(!1===e.useRecords&&e.mapsAsObjects===void 0&&(e.mapsAsObjects=!0),e.structures?e.structures.sharedLength=e.structures.length:e.getStructures&&((e.structures=[]).uninitialized=!0,e.structures.sharedLength=0)),Object.assign(this,e)}unpack(e,t){if(R)// re-entrant execution, save the state and restore it after we do this unpack
|
|
41
|
+
return y(()=>(m(),this?this.unpack(e,t):$.prototype.unpack.call(N,e,t)));E=-1<t?t:e.length,P=0,j=0,_=null,B=null,R=e;// this provides cached access to the data view for a buffer if it is getting reused, which is a recommend
|
|
41
42
|
// technique for getting data from a database where it can be copied into an existing buffer instead of creating
|
|
42
43
|
// new ones
|
|
43
|
-
try{
|
|
44
|
-
let e=
|
|
45
|
-
|
|
46
|
-
return
|
|
47
|
-
},
|
|
48
|
-
let e=
|
|
49
|
-
return new
|
|
50
|
-
for(let n=0;256>n;n++)re[n]=+("1e"+t(45.15-.30103*n));var
|
|
51
|
-
let
|
|
52
|
-
throw new Error("Shared structures is larger than maximum shared structures, try increasing maxSharedStructures to "+
|
|
53
|
-
if(
|
|
54
|
-
}finally{if(
|
|
55
|
-
let n=
|
|
56
|
-
let i=3*
|
|
57
|
-
(n=e*re[(127&
|
|
58
|
-
|
|
59
|
-
k(e,!e.hasOwnProperty)}}}else if("boolean"===
|
|
60
|
-
if(this.largeBigIntToFloat)
|
|
61
|
-
let t=Object.keys(e),n=t.length;16>n?
|
|
62
|
-
let
|
|
63
|
-
(e,n)=>{let
|
|
64
|
-
let n=Object.keys(e),d=o;o=
|
|
65
|
-
w(o,n,a,c),i=!0,o=d[u]}
|
|
66
|
-
for(let n in o?96<=o&&
|
|
67
|
-
if(e-t>be)throw new Error("Packed buffer would be larger than maximum buffer size");i=n(be,4096*r(
|
|
68
|
-
i=(
|
|
69
|
-
i=
|
|
70
|
-
|
|
71
|
-
let{target:e,targetView:t,position:
|
|
72
|
-
let{target:t,targetView:
|
|
73
|
-
let{target:e,targetView:t,position:
|
|
74
|
-
let{target:
|
|
75
|
-
let{target:n,position:
|
|
76
|
-
|
|
44
|
+
try{T=e.dataView||(e.dataView=new DataView(e.buffer,e.byteOffset,e.byteLength))}catch(t){if(R=null,e instanceof Uint8Array)throw t;throw new Error("Source must be a Uint8Array or Buffer but was a "+(e&&"object"==typeof e?e.constructor.name:typeof e))}if(this instanceof $){if(D=this,this.structures)return M=this.structures,n();(!M||0<M.length)&&(M=[])}else D=N,(!M||0<M.length)&&(M=[]);return n()}unpackMultiple(e,t){let s,r=0;try{Y=!0;let i=e.length,o=this?this.unpack(e,i):ie.unpack(e,i);if(t){for(t(o);P<i;)if(r=P,!1===t(n()))return;}else{for(s=[o];P<i;)r=P,s.push(n());return s}}catch(e){throw e.lastPosition=r,e.values=s,e}finally{Y=!1,m()}}_mergeStructures(e,t){e=e||[];for(let n,s=0,r=e.length;s<r;s++)n=e[s],n&&(n.isShared=!0,32<=s&&(n.highByte=s-32>>5));for(let n in e.sharedLength=e.length,t||[])if(0<=n){let s=e[n],r=t[n];r&&(s&&((e.restoreStructures||(e.restoreStructures=[]))[n]=s),e[n]=r)}return this.structures=e}decode(e,t){return this.unpack(e,t)}}const q=/^[a-zA-Z_$][a-zA-Z\d_$]*$/,G=(e,t)=>function(){let n=R[P++];if(0===n)return t();let s=32>e?-(e+(n<<5)):e+(n<<5),r=M[s]||o()[s];if(!r)throw new Error("Record id is not defined for "+s);return r.read||(r.read=i(r,e)),r.read()};var H=a,J=a,K=a,Q=a;var X=String.fromCharCode,Z=Array(4096);const ee=(e,t)=>{var n=r();let s=e;void 0!==t&&(e=32>e?-((t<<5)+e):(t<<5)+e,n.highByte=t);let o=M[e];return o&&o.isShared&&((M.restoreStructures||(M.restoreStructures=[]))[e]=o),M[e]=n,n.read=i(n,s),n.read()};var te="object"==typeof self?self:global;v[0]=()=>{},v[0].noBuffer=!0,v[101]=()=>{let e=r();return(te[e[0]]||Error)(e[1])},v[105]=()=>{// id extension (for structured clones)
|
|
45
|
+
let e=T.getUint32(P-4);C||(C=new Map);let t,n=R[P];t=144<=n&&160>n||220==n||221==n?[]:{};let s={target:t};// a placeholder object
|
|
46
|
+
C.set(e,s);let i=r();// read the next value as the target object to id
|
|
47
|
+
return s.used?Object.assign(t,i):(s.target=i,i);// no cycle, can just use the returned read object
|
|
48
|
+
},v[112]=()=>{// pointer extension (for structured clones)
|
|
49
|
+
let e=T.getUint32(P-4),t=C.get(e);return t.used=!0,t.target},v[115]=()=>new Set(r());const ne=["Int8","Uint8","Uint8Clamped","Int16","Uint16","Int32","Uint32","Float32","Float64","BigInt64","BigUint64"].map(e=>e+"Array");v[116]=e=>{let t=e[0],n=ne[t];if(!n)throw new Error("Could not find typed array for code "+t);// we have to always slice/copy here to get a new ArrayBuffer that is word/byte aligned
|
|
50
|
+
return new te[n](Uint8Array.prototype.slice.call(e,1).buffer)},v[120]=()=>{let e=r();return new RegExp(e[0],e[1])};const se=[];v[98]=e=>{let t=(e[0]<<24)+(e[1]<<16)+(e[2]<<8)+e[3],n=P;return P+=t-e.length,B=se,B=[p(),p()],B.position0=0,B.position1=0,B.postBundlePosition=P,P=n,r()},v[255]=e=>4==e.length?new Date(1e3*(16777216*e[0]+(e[1]<<16)+(e[2]<<8)+e[3])):8==e.length?new Date(((e[0]<<22)+(e[1]<<14)+(e[2]<<6)+(e[3]>>2))/1e6+1e3*(4294967296*(3&e[3])+16777216*e[4]+(e[5]<<16)+(e[6]<<8)+e[7])):12==e.length?new Date(((e[0]<<24)+(e[1]<<16)+(e[2]<<8)+e[3])/1e6+1e3*((128&e[4]?-281474976710656:0)+1099511627776*e[6]+4294967296*e[7]+16777216*e[8]+(e[9]<<16)+(e[10]<<8)+e[11])):new Date("invalid");const re=Array(147);// this is a table matching binary exponents to the multiplier to determine significant digit rounding
|
|
51
|
+
for(let n=0;256>n;n++)re[n]=+("1e"+t(45.15-.30103*n));var ie=new $({useRecords:!1});const oe=ie.unpack,ae=ie.unpackMultiple,ue=ie.unpack,de={NEVER:0,ALWAYS:1,DECIMAL_ROUND:3,DECIMAL_FIT:4};let ce,ge=new Float32Array(1),pe=new Uint8Array(ge.buffer,0,4);try{ce=new TextEncoder}catch(e){}let le,fe;const he="undefined"!=typeof Buffer,ye=he?Buffer.allocUnsafeSlow:Uint8Array,me=he?Buffer:Uint8Array,be=he?4294967296:2144337920;let ke,Ue,Ie,Se,Oe=0,Ae=null;const we=Symbol("record-id");class Le extends ${constructor(e){super(e),this.offset=0;let t,n,s,r,i=0,o=me.prototype.utf8Write?function(e,t,n){return ke.utf8Write(e,t,n)}:!!(ce&&ce.encodeInto)&&function(e,t){return ce.encodeInto(e,ke.subarray(t)).written},a=this;e||(e={});let u=e&&e.sequential,d=e.structures||e.saveStructures,c=e.maxSharedStructures;if(null==c&&(c=d?32:0),8160<c)throw new Error("Maximum maxSharedStructure is 8160");e.structuredClone&&null==e.moreTypes&&(e.moreTypes=!0);let g=e.maxOwnStructures;null==g&&(g=d?32:64),this.structures||!1==e.useRecords||(this.structures=[]);// two byte record ids for shared structures
|
|
52
|
+
let p=32<c||64<g+c,l=c+64,f=c+g+64;if(8256<f)throw new Error("Maximum maxSharedStructure + maxOwnStructure is 8192");let h=[],y=0,m=0;this.pack=this.encode=function(e,o){if(ke||(ke=new ye(8192),Ie=new DataView(ke.buffer,0,8192),Oe=0),Se=ke.length-10,2048>Se-Oe?(ke=new ye(ke.length),Ie=new DataView(ke.buffer,0,ke.length),Se=ke.length-10,Oe=0):Oe=2147483640&Oe+7,t=Oe,r=a.structuredClone?new Map:null,a.bundleStrings&&"string"!=typeof e?(Ae=[],Ae.size=1/0):Ae=null,s=a.structures,s){s.uninitialized&&(s=a._mergeStructures(a.getStructures()));let e=s.sharedLength||0;if(e>c)//if (maxSharedStructures <= 32 && structures.sharedLength > 32) // TODO: could support this, but would need to update the limit ids
|
|
53
|
+
throw new Error("Shared structures is larger than maximum shared structures, try increasing maxSharedStructures to "+s.sharedLength);if(!s.transitions){s.transitions=Object.create(null);for(let t,n=0;n<e;n++){if(t=s[n],!t)continue;let e,r=s.transitions;for(let n,s=0,i=t.length;s<i;s++)n=t[s],e=r[n],e||(e=r[n]=Object.create(null)),r=e;r[we]=n+64}i=e}u||(s.nextId=e+64)}n&&(n=!1);try{// update the offset so next serialization doesn't write over our buffer, but can continue writing to same buffer sequentially
|
|
54
|
+
if(b(e),Ae&&O(t,b),a.offset=Oe,r&&r.idsToInsert){Oe+=6*r.idsToInsert.length,Oe>Se&&U(Oe),a.offset=Oe;let e=S(ke.subarray(t,Oe),r.idsToInsert);return r=null,e}return o&Te?(ke.start=t,ke.end=Oe,ke):ke.subarray(t,Oe);// position can change if we call pack again in saveStructures, so we get the buffer now
|
|
55
|
+
}finally{if(s){10>m&&m++;let r=s.sharedLength||c;if(s.length>r&&(s.length=r),1e4<y)s.transitions=null,m=0,y=0,0<h.length&&(h=[]);else if(0<h.length&&!u){for(let e=0,t=h.length;e<t;e++)h[e][we]=0;h=[]}if(n&&a.saveStructures){// we can't rely on start/end with REUSE_BUFFER_MODE since they will (probably) change when we save
|
|
56
|
+
let n=ke.subarray(t,Oe);return!1===a.saveStructures(s,i)?(a._mergeStructures(a.getStructures()),a.pack(e)):(i=r,n)}}o&Pe&&(Oe=t)}};const b=e=>{Oe>Se&&(ke=U(Oe));var n,s=typeof e;if("string"==s){let s=e.length;if(Ae&&4<=s&&4096>s){if((Ae.size+=s)>61440){let e,n=(Ae[0]?3*Ae[0].length+Ae[1].length:0)+10;Oe+n>Se&&(ke=U(Oe+n)),Ae.position?(ke[Oe]=200,Oe+=3,ke[Oe++]=98,e=Oe-t,Oe+=4,O(t,b),Ie.setUint16(e+t-3,Oe-t-e)):(ke[Oe++]=214,ke[Oe++]=98,e=Oe-t,Oe+=4),Ae=["",""],Ae.size=0,Ae.position=e}let n=/[\u0080-\uFFFF]/.test(e);return Ae[n?0:1]+=e,ke[Oe++]=193,void b(n?-s:s)}let r=32>s?1:256>s?2:65536>s?3:5;// first we estimate the header size, so we can write to the correct location
|
|
57
|
+
let i=3*s;if(Oe+i>Se&&(ke=U(Oe+i)),64>s||!o){let t,i,o,a=Oe+r;for(t=0;t<s;t++)i=e.charCodeAt(t),128>i?ke[a++]=i:2048>i?(ke[a++]=192|i>>6,ke[a++]=128|63&i):55296==(64512&i)&&56320==(64512&(o=e.charCodeAt(t+1)))?(i=65536+((1023&i)<<10)+(1023&o),t++,ke[a++]=240|i>>18,ke[a++]=128|63&i>>12,ke[a++]=128|63&i>>6,ke[a++]=128|63&i):(ke[a++]=224|i>>12,ke[a++]=128|63&i>>6,ke[a++]=128|63&i);n=a-Oe-r}else n=o(e,Oe+r,i);32>n?ke[Oe++]=160|n:256>n?(2>r&&ke.copyWithin(Oe+2,Oe+1,Oe+1+n),ke[Oe++]=217,ke[Oe++]=n):65536>n?(3>r&&ke.copyWithin(Oe+3,Oe+2,Oe+2+n),ke[Oe++]=218,ke[Oe++]=n>>8,ke[Oe++]=255&n):(5>r&&ke.copyWithin(Oe+5,Oe+3,Oe+3+n),ke[Oe++]=219,Ie.setUint32(Oe,n),Oe+=4),Oe+=n}else if("number"===s){if(e>>>0===e)64>e?ke[Oe++]=e:256>e?(ke[Oe++]=204,ke[Oe++]=e):65536>e?(ke[Oe++]=205,ke[Oe++]=e>>8,ke[Oe++]=255&e):(ke[Oe++]=206,Ie.setUint32(Oe,e),Oe+=4);else if(e>>0===e)-32<=e?ke[Oe++]=256+e:-128<=e?(ke[Oe++]=208,ke[Oe++]=e+256):-32768<=e?(ke[Oe++]=209,Ie.setInt16(Oe,e),Oe+=2):(ke[Oe++]=210,Ie.setInt32(Oe,e),Oe+=4);else{let t;if(0<(t=this.useFloat32)&&4294967296>e&&-2147483648<=e){ke[Oe++]=202,Ie.setFloat32(Oe,e);let n;if(4>t||// this checks for rounding of numbers that were encoded in 32-bit float to nearest significant decimal digit that could be preserved
|
|
58
|
+
(n=e*re[(127&ke[Oe])<<1|ke[Oe+1]>>7])>>0===n)return void(Oe+=4);// move back into position for writing a double
|
|
59
|
+
Oe--}ke[Oe++]=203,Ie.setFloat64(Oe,e),Oe+=8}}else if("object"===s){if(!e)ke[Oe++]=192;else{if(r){let n=r.get(e);if(n){if(!n.id){let e=r.idsToInsert||(r.idsToInsert=[]);n.id=e.push(n)}return ke[Oe++]=214,ke[Oe++]=112,Ie.setUint32(Oe,n.id),void(Oe+=4)}r.set(e,{offset:Oe-t})}let s=e.constructor;if(s===Object)k(e,!0);else if(s===Array){n=e.length,16>n?ke[Oe++]=144|n:65536>n?(ke[Oe++]=220,ke[Oe++]=n>>8,ke[Oe++]=255&n):(ke[Oe++]=221,Ie.setUint32(Oe,n),Oe+=4);for(let t=0;t<n;t++)b(e[t])}else if(s===Map){n=e.size,16>n?ke[Oe++]=128|n:65536>n?(ke[Oe++]=222,ke[Oe++]=n>>8,ke[Oe++]=255&n):(ke[Oe++]=223,Ie.setUint32(Oe,n),Oe+=4);for(let[t,n]of e)b(t),b(n)}else{for(let t,n=0,s=le.length;n<s;n++)if(t=fe[n],e instanceof t){let t=le[n];if(t.write)return t.type&&(ke[Oe++]=212,ke[Oe++]=t.type,ke[Oe++]=0),void b(t.write.call(this,e));let s=ke,r=Ie,i=Oe;ke=null;let o;try{o=t.pack.call(this,e,e=>(ke=s,s=null,Oe+=e,Oe>Se&&U(Oe),{target:ke,targetView:Ie,position:Oe-e}),b)}finally{s&&(ke=s,Ie=r,Oe=i,Se=ke.length-10)}return void(o&&(o.length+Oe>Se&&U(o.length+Oe),Oe=I(o,ke,Oe,t.type)))}// no extension found, write as object
|
|
60
|
+
k(e,!e.hasOwnProperty)}}}else if("boolean"===s)ke[Oe++]=e?195:194;else if("bigint"===s){if(e<BigInt(1)<<BigInt(63)&&e>=-(BigInt(1)<<BigInt(63)))ke[Oe++]=211,Ie.setBigInt64(Oe,e);else if(e<BigInt(1)<<BigInt(64)&&0<e)ke[Oe++]=207,Ie.setBigUint64(Oe,e);else// overflow
|
|
61
|
+
if(this.largeBigIntToFloat)ke[Oe++]=203,Ie.setFloat64(Oe,+e);else throw new RangeError(e+" was too large to fit in MessagePack 64-bit integer format, set largeBigIntToFloat to convert to float-64");Oe+=8}else if("undefined"===s)this.encodeUndefinedAsNil?ke[Oe++]=192:(ke[Oe++]=212,ke[Oe++]=0,ke[Oe++]=0);else if("function"===s)b(this.writeFunction&&this.writeFunction());else throw new Error("Unknown type: "+s)},k=!1===this.useRecords?this.variableMapSize?e=>{// this method is slightly slower, but generates "preferred serialization" (optimally small for smaller objects)
|
|
62
|
+
let t=Object.keys(e),n=t.length;16>n?ke[Oe++]=128|n:65536>n?(ke[Oe++]=222,ke[Oe++]=n>>8,ke[Oe++]=255&n):(ke[Oe++]=223,Ie.setUint32(Oe,n),Oe+=4);let s;for(let r=0;r<n;r++)b(s=t[r]),b(e[s])}:(e,n)=>{ke[Oe++]=222;// always using map 16, so we can preallocate and set the length afterwards
|
|
63
|
+
let s=Oe-t;Oe+=2;let r=0;for(let t in e)(n||e.hasOwnProperty(t))&&(b(t),b(e[t]),r++);ke[s++ +t]=r>>8,ke[s+t]=255&r}:e.progressiveRecords&&!p?// this is about 2% faster for highly stable structures, since it only requires one for-in loop (but much more expensive when new structure needs to be written)
|
|
64
|
+
(e,n)=>{let r,i,o=s.transitions||(s.transitions=Object.create(null)),a=Oe++-t;for(let u in e)if(n||e.hasOwnProperty(u)){if(r=o[u],r)o=r;else{// record doesn't exist, create full new record and insert it
|
|
65
|
+
let n=Object.keys(e),d=o;o=s.transitions;let c=0;for(let e,t=0,s=n.length;t<s;t++)e=n[t],r=o[e],r||(r=o[e]=Object.create(null),c++),o=r;a+t+1==Oe?(Oe--,A(o,n,c)):// otherwise we need to insert the record, moving existing data after the record
|
|
66
|
+
w(o,n,a,c),i=!0,o=d[u]}b(e[u])}if(!i){let n=o[we];n?ke[a+t]=n:w(o,Object.keys(e),a,0)}}:(e,t)=>{let n,r=s.transitions||(s.transitions=Object.create(null)),i=0;for(let s in e)(t||e.hasOwnProperty(s))&&(n=r[s],n||(n=r[s]=Object.create(null),i++),r=n);let o=r[we];// now write the values
|
|
67
|
+
for(let n in o?96<=o&&p?(ke[Oe++]=(31&(o-=96))+96,ke[Oe++]=o>>5):ke[Oe++]=o:A(r,r.__keys__||Object.keys(e),i),e)(t||e.hasOwnProperty(n))&&b(e[n])},U=e=>{var n=Math.min,s=Math.round,r=Math.max;let i;if(16777216<e){// special handling for really large buffers
|
|
68
|
+
if(e-t>be)throw new Error("Packed buffer would be larger than maximum buffer size");i=n(be,4096*s(r((e-t)*(67108864<e?1.25:2),4194304)/4096))}else// faster handling for smaller buffers
|
|
69
|
+
i=(r(e-t<<2,ke.length-1)>>12)+1<<12;let o=new ye(i);return Ie=new DataView(o.buffer,0,i),ke.copy?ke.copy(o,0,t,e):o.set(ke.slice(t,e)),Oe-=t,t=0,Se=o.length-10,ke=o},A=(e,t,r)=>{let i=s.nextId;i||(i=64),i<l&&this.shouldShareStructure&&!this.shouldShareStructure(t)?(i=s.nextOwnId,!(i<f)&&(i=l),s.nextOwnId=i+1):(i>=f&&(// cycle back around
|
|
70
|
+
i=l),s.nextId=i+1);let o=t.highByte=96<=i&&p?i-96>>5:-1;e[we]=i,e.__keys__=t,s[i-64]=t,i<l?(t.isShared=!0,s.sharedLength=i-63,n=!0,0<=o?(ke[Oe++]=(31&i)+96,ke[Oe++]=o):ke[Oe++]=i):(0<=o?(ke[Oe++]=213,ke[Oe++]=114,ke[Oe++]=(31&i)+96,ke[Oe++]=o):(ke[Oe++]=212,ke[Oe++]=114,ke[Oe++]=i),r&&(y+=m*r),h.length>=g&&(h.shift()[we]=0),h.push(e),b(t))},w=(e,n,s,r)=>{let i=ke,o=Oe,a=Se,u=t;ke=Ue,Oe=0,t=0,ke||(Ue=ke=new ye(8192)),Se=ke.length-10,A(e,n,r),Ue=ke;let d=Oe;if(ke=i,Oe=o,Se=a,t=u,1<d){let e=Oe+d-1;e>Se&&U(e);let n=s+t;ke.copyWithin(n+d,n+1,Oe),ke.set(Ue.slice(0,d),n),Oe=e}else ke[s+t]=Ue[0]}}useBuffer(e){// this means we are finished using our own buffer and we can write over it safely
|
|
71
|
+
ke=e,Ie=new DataView(ke.buffer,ke.byteOffset,ke.byteLength),Oe=0}clearSharedData(){this.structures&&(this.structures=[])}}fe=[Date,Set,Error,RegExp,ArrayBuffer,Object.getPrototypeOf(Uint8Array.prototype).constructor/*TypedArray*/,V],le=[{pack(e,n,s){let r=e.getTime()/1e3;if((this.useTimestamp32||0===e.getMilliseconds())&&0<=r&&4294967296>r){// Timestamp 32
|
|
72
|
+
let{target:e,targetView:t,position:s}=n(6);e[s++]=214,e[s++]=255,t.setUint32(s,r)}else if(0<r&&17179869184>r){// Timestamp 64
|
|
73
|
+
let{target:t,targetView:s,position:i}=n(10);t[i++]=215,t[i++]=255,s.setUint32(i,4e6*e.getMilliseconds()+(r/1e3/4294967296>>0)),s.setUint32(i+4,r)}else if(isNaN(r)){if(this.onInvalidDate)return n(0),s(this.onInvalidDate());// Intentionally invalid timestamp
|
|
74
|
+
let{target:e,targetView:t,position:r}=n(3);e[r++]=212,e[r++]=255,e[r++]=255}else{// Timestamp 96
|
|
75
|
+
let{target:s,targetView:i,position:o}=n(15);s[o++]=199,s[o++]=12,s[o++]=255,i.setUint32(o,1e6*e.getMilliseconds()),i.setBigInt64(o+4,BigInt(t(r)))}}},{pack(e,t,n){let s=Array.from(e),{target:r,position:i}=t(this.moreTypes?3:0);this.moreTypes&&(r[i++]=212,r[i++]=115,r[i++]=0),n(s)}},{pack(e,t,n){let{target:s,position:r}=t(this.moreTypes?3:0);this.moreTypes&&(s[r++]=212,s[r++]=101,s[r++]=0),n([e.name,e.message])}},{pack(e,t,n){let{target:s,position:r}=t(this.moreTypes?3:0);this.moreTypes&&(s[r++]=212,s[r++]=120,s[r++]=0),n([e.source,e.flags])}},{pack(e,t){this.moreTypes?k(e,16,t):U(he?Buffer.from(e):new Uint8Array(e),t)}},{pack(e,t){let n=e.constructor;n!==me&&this.moreTypes?k(e,ne.indexOf(n.name),t):U(e,t)}},{pack(e,t){// specific 0xC1 object
|
|
76
|
+
let{target:n,position:s}=t(1);n[s]=193}}];let xe=new Le({useRecords:!1});const Re=xe.pack,Ee=xe.pack,{NEVER:Me,ALWAYS:_e,DECIMAL_ROUND:Be,DECIMAL_FIT:Ce}=de,Te=512,Pe=1024;e.ALWAYS=_e,e.C1=W,e.DECIMAL_FIT=Ce,e.DECIMAL_ROUND=Be,e.Decoder=$,e.Encoder=Le,e.FLOAT32_OPTIONS=de,e.NEVER=Me,e.Packr=Le,e.REUSE_BUFFER_MODE=Te,e.Unpackr=$,e.addExtension=A,e.clearSource=m,e.decode=ue,e.decodeIter=function(e,t={}){if(!e||"object"!=typeof e)throw new Error("first argument must be an Iterable, Async Iterable, Iterator, Async Iterator, or a promise");const n=new $(t);let s;const r=e=>{let t;// if there's incomplete data from previous chunk, concatinate and try again
|
|
77
|
+
s&&(e=Buffer.concat([s,e]),s=void 0);try{t=n.unpackMultiple(e)}catch(n){if(n.incomplete)s=e.slice(n.lastPosition),t=n.values;else throw n}return t};if("function"==typeof e[Symbol.iterator])return function*(){for(const t of e)yield*r(t)}();return"function"==typeof e[Symbol.asyncIterator]?async function*(){for await(const t of e)yield*r(t)}():void 0},e.encode=Ee,e.encodeIter=/**
|
|
77
78
|
* Given an Iterable first argument, returns an Iterable where each value is packed as a Buffer
|
|
78
79
|
* If the argument is only Async Iterable, the return value will be an Async Iterable.
|
|
79
80
|
* @param {Iterable|Iterator|AsyncIterable|AsyncIterator} objectIterator - iterable source, like a Readable object stream, an array, Set, or custom object
|
|
80
81
|
* @param {options} [options] - msgpackr pack options
|
|
81
82
|
* @returns {IterableIterator|Promise.<AsyncIterableIterator>}
|
|
82
|
-
*/function(e,t={}){if(!e||"object"!=typeof e)throw new Error("first argument must be an Iterable, Async Iterable, or a Promise for an Async Iterable");else{if("function"==typeof e[Symbol.iterator])return w(e,t);if("function"==typeof e.then||"function"==typeof e[Symbol.asyncIterator])return
|
|
83
|
+
*/function(e,t={}){if(!e||"object"!=typeof e)throw new Error("first argument must be an Iterable, Async Iterable, or a Promise for an Async Iterable");else{if("function"==typeof e[Symbol.iterator])return w(e,t);if("function"==typeof e.then||"function"==typeof e[Symbol.asyncIterator])return L(e,t);throw new Error("first argument must be an Iterable, Async Iterable, Iterator, Async Iterator, or a Promise")}},e.isNativeAccelerationEnabled=!1,e.mapsAsObjects=!0,e.pack=Re,e.roundFloat32=function(e){ge[0]=e;let t=re[(127&pe[3])<<1|pe[2]>>7];return(t*e+(0<e?.5:-.5)>>0)/t},e.unpack=oe,e.unpackMultiple=ae,e.useRecords=!1,Object.defineProperty(e,"__esModule",{value:!0})});
|
package/dist/node.cjs
CHANGED
|
@@ -32,6 +32,13 @@ class C1Type {}
|
|
|
32
32
|
const C1 = new C1Type();
|
|
33
33
|
C1.name = 'MessagePack 0xC1';
|
|
34
34
|
var sequentialMode = false;
|
|
35
|
+
var inlineObjectReadThreshold = 2;
|
|
36
|
+
try {
|
|
37
|
+
new Function('');
|
|
38
|
+
} catch(error) {
|
|
39
|
+
// if eval variants are not supported, do not create inline object readers ever
|
|
40
|
+
inlineObjectReadThreshold = Infinity;
|
|
41
|
+
}
|
|
35
42
|
|
|
36
43
|
class Unpackr {
|
|
37
44
|
constructor(options) {
|
|
@@ -442,7 +449,7 @@ const validName = /^[a-zA-Z_$][a-zA-Z\d_$]*$/;
|
|
|
442
449
|
function createStructureReader(structure, firstId) {
|
|
443
450
|
function readObject() {
|
|
444
451
|
// This initial function is quick to instantiate, but runs slower. After several iterations pay the cost to build the faster function
|
|
445
|
-
if (readObject.count++ >
|
|
452
|
+
if (readObject.count++ > inlineObjectReadThreshold) {
|
|
446
453
|
let readObject = structure.read = (new Function('r', 'return function(){return {' + structure.map(key => validName.test(key) ? key + ':r()' : ('[' + JSON.stringify(key) + ']:r()')).join(',') + '}}'))(read);
|
|
447
454
|
if (structure.highByte === 0)
|
|
448
455
|
structure.read = createSecondByteReader(firstId, structure.read);
|
|
@@ -1090,6 +1097,9 @@ class Packr extends Unpackr {
|
|
|
1090
1097
|
maxSharedStructures = hasSharedStructures ? 32 : 0;
|
|
1091
1098
|
if (maxSharedStructures > 8160)
|
|
1092
1099
|
throw new Error('Maximum maxSharedStructure is 8160')
|
|
1100
|
+
if (options.structuredClone && options.moreTypes == undefined) {
|
|
1101
|
+
options.moreTypes = true;
|
|
1102
|
+
}
|
|
1093
1103
|
let maxOwnStructures = options.maxOwnStructures;
|
|
1094
1104
|
if (maxOwnStructures == null)
|
|
1095
1105
|
maxOwnStructures = hasSharedStructures ? 32 : 64;
|
|
@@ -1781,8 +1791,8 @@ extensions = [{
|
|
|
1781
1791
|
}, {
|
|
1782
1792
|
pack(set, allocateForWrite, pack) {
|
|
1783
1793
|
let array = Array.from(set);
|
|
1784
|
-
let { target, position} = allocateForWrite(this.
|
|
1785
|
-
if (this.
|
|
1794
|
+
let { target, position} = allocateForWrite(this.moreTypes ? 3 : 0);
|
|
1795
|
+
if (this.moreTypes) {
|
|
1786
1796
|
target[position++] = 0xd4;
|
|
1787
1797
|
target[position++] = 0x73; // 's' for Set
|
|
1788
1798
|
target[position++] = 0;
|
|
@@ -1791,8 +1801,8 @@ extensions = [{
|
|
|
1791
1801
|
}
|
|
1792
1802
|
}, {
|
|
1793
1803
|
pack(error, allocateForWrite, pack) {
|
|
1794
|
-
let { target, position} = allocateForWrite(this.
|
|
1795
|
-
if (this.
|
|
1804
|
+
let { target, position} = allocateForWrite(this.moreTypes ? 3 : 0);
|
|
1805
|
+
if (this.moreTypes) {
|
|
1796
1806
|
target[position++] = 0xd4;
|
|
1797
1807
|
target[position++] = 0x65; // 'e' for error
|
|
1798
1808
|
target[position++] = 0;
|
|
@@ -1801,8 +1811,8 @@ extensions = [{
|
|
|
1801
1811
|
}
|
|
1802
1812
|
}, {
|
|
1803
1813
|
pack(regex, allocateForWrite, pack) {
|
|
1804
|
-
let { target, position} = allocateForWrite(this.
|
|
1805
|
-
if (this.
|
|
1814
|
+
let { target, position} = allocateForWrite(this.moreTypes ? 3 : 0);
|
|
1815
|
+
if (this.moreTypes) {
|
|
1806
1816
|
target[position++] = 0xd4;
|
|
1807
1817
|
target[position++] = 0x78; // 'x' for regeXp
|
|
1808
1818
|
target[position++] = 0;
|
|
@@ -1811,7 +1821,7 @@ extensions = [{
|
|
|
1811
1821
|
}
|
|
1812
1822
|
}, {
|
|
1813
1823
|
pack(arrayBuffer, allocateForWrite) {
|
|
1814
|
-
if (this.
|
|
1824
|
+
if (this.moreTypes)
|
|
1815
1825
|
writeExtBuffer(arrayBuffer, 0x10, allocateForWrite);
|
|
1816
1826
|
else
|
|
1817
1827
|
writeBuffer(hasNodeBuffer ? Buffer.from(arrayBuffer) : new Uint8Array(arrayBuffer), allocateForWrite);
|
|
@@ -1819,7 +1829,7 @@ extensions = [{
|
|
|
1819
1829
|
}, {
|
|
1820
1830
|
pack(typedArray, allocateForWrite) {
|
|
1821
1831
|
let constructor = typedArray.constructor;
|
|
1822
|
-
if (constructor !== ByteArray && this.
|
|
1832
|
+
if (constructor !== ByteArray && this.moreTypes)
|
|
1823
1833
|
writeExtBuffer(typedArray, typedArrays.indexOf(constructor.name), allocateForWrite);
|
|
1824
1834
|
else
|
|
1825
1835
|
writeBuffer(typedArray, allocateForWrite);
|
package/dist/test.js
CHANGED
|
@@ -859,6 +859,7 @@
|
|
|
859
859
|
object.children[2] = object.children[0];
|
|
860
860
|
object.childrenAgain = object.children;
|
|
861
861
|
let packr = new Packr({
|
|
862
|
+
moreTypes: true,
|
|
862
863
|
structuredClone: true,
|
|
863
864
|
});
|
|
864
865
|
var serialized = packr.pack(object);
|
|
@@ -883,6 +884,7 @@
|
|
|
883
884
|
uint16Array: new Uint16Array([3,4])
|
|
884
885
|
};
|
|
885
886
|
let packr = new Packr({
|
|
887
|
+
moreTypes: true,
|
|
886
888
|
structuredClone: true,
|
|
887
889
|
});
|
|
888
890
|
var serialized = packr.pack(object);
|
package/pack.js
CHANGED
|
@@ -44,6 +44,9 @@ export class Packr extends Unpackr {
|
|
|
44
44
|
maxSharedStructures = hasSharedStructures ? 32 : 0
|
|
45
45
|
if (maxSharedStructures > 8160)
|
|
46
46
|
throw new Error('Maximum maxSharedStructure is 8160')
|
|
47
|
+
if (options.structuredClone && options.moreTypes == undefined) {
|
|
48
|
+
options.moreTypes = true
|
|
49
|
+
}
|
|
47
50
|
let maxOwnStructures = options.maxOwnStructures
|
|
48
51
|
if (maxOwnStructures == null)
|
|
49
52
|
maxOwnStructures = hasSharedStructures ? 32 : 64
|
|
@@ -741,8 +744,8 @@ extensions = [{
|
|
|
741
744
|
}, {
|
|
742
745
|
pack(set, allocateForWrite, pack) {
|
|
743
746
|
let array = Array.from(set)
|
|
744
|
-
let { target, position} = allocateForWrite(this.
|
|
745
|
-
if (this.
|
|
747
|
+
let { target, position} = allocateForWrite(this.moreTypes ? 3 : 0)
|
|
748
|
+
if (this.moreTypes) {
|
|
746
749
|
target[position++] = 0xd4
|
|
747
750
|
target[position++] = 0x73 // 's' for Set
|
|
748
751
|
target[position++] = 0
|
|
@@ -751,8 +754,8 @@ extensions = [{
|
|
|
751
754
|
}
|
|
752
755
|
}, {
|
|
753
756
|
pack(error, allocateForWrite, pack) {
|
|
754
|
-
let { target, position} = allocateForWrite(this.
|
|
755
|
-
if (this.
|
|
757
|
+
let { target, position} = allocateForWrite(this.moreTypes ? 3 : 0)
|
|
758
|
+
if (this.moreTypes) {
|
|
756
759
|
target[position++] = 0xd4
|
|
757
760
|
target[position++] = 0x65 // 'e' for error
|
|
758
761
|
target[position++] = 0
|
|
@@ -761,8 +764,8 @@ extensions = [{
|
|
|
761
764
|
}
|
|
762
765
|
}, {
|
|
763
766
|
pack(regex, allocateForWrite, pack) {
|
|
764
|
-
let { target, position} = allocateForWrite(this.
|
|
765
|
-
if (this.
|
|
767
|
+
let { target, position} = allocateForWrite(this.moreTypes ? 3 : 0)
|
|
768
|
+
if (this.moreTypes) {
|
|
766
769
|
target[position++] = 0xd4
|
|
767
770
|
target[position++] = 0x78 // 'x' for regeXp
|
|
768
771
|
target[position++] = 0
|
|
@@ -771,7 +774,7 @@ extensions = [{
|
|
|
771
774
|
}
|
|
772
775
|
}, {
|
|
773
776
|
pack(arrayBuffer, allocateForWrite) {
|
|
774
|
-
if (this.
|
|
777
|
+
if (this.moreTypes)
|
|
775
778
|
writeExtBuffer(arrayBuffer, 0x10, allocateForWrite)
|
|
776
779
|
else
|
|
777
780
|
writeBuffer(hasNodeBuffer ? Buffer.from(arrayBuffer) : new Uint8Array(arrayBuffer), allocateForWrite)
|
|
@@ -779,7 +782,7 @@ extensions = [{
|
|
|
779
782
|
}, {
|
|
780
783
|
pack(typedArray, allocateForWrite) {
|
|
781
784
|
let constructor = typedArray.constructor
|
|
782
|
-
if (constructor !== ByteArray && this.
|
|
785
|
+
if (constructor !== ByteArray && this.moreTypes)
|
|
783
786
|
writeExtBuffer(typedArray, typedArrays.indexOf(constructor.name), allocateForWrite)
|
|
784
787
|
else
|
|
785
788
|
writeBuffer(typedArray, allocateForWrite)
|
package/package.json
CHANGED
package/unpack.d.ts
CHANGED
|
@@ -9,6 +9,7 @@ export interface Options {
|
|
|
9
9
|
useFloat32?: FLOAT32_OPTIONS
|
|
10
10
|
useRecords?: boolean
|
|
11
11
|
structures?: {}[]
|
|
12
|
+
moreTypes?: boolean
|
|
12
13
|
structuredClone?: boolean
|
|
13
14
|
mapsAsObjects?: boolean
|
|
14
15
|
variableMapSize?: boolean
|
|
@@ -19,6 +20,7 @@ export interface Options {
|
|
|
19
20
|
encodeUndefinedAsNil?: boolean
|
|
20
21
|
maxSharedStructures?: number
|
|
21
22
|
maxOwnStructures?: number
|
|
23
|
+
int64AsNumber?: boolean
|
|
22
24
|
shouldShareStructure?: (keys: string[]) => boolean
|
|
23
25
|
getStructures?(): {}[]
|
|
24
26
|
saveStructures?(structures: {}[]): boolean | void
|
package/unpack.js
CHANGED
|
@@ -27,6 +27,13 @@ export class C1Type {}
|
|
|
27
27
|
export const C1 = new C1Type()
|
|
28
28
|
C1.name = 'MessagePack 0xC1'
|
|
29
29
|
var sequentialMode = false
|
|
30
|
+
var inlineObjectReadThreshold = 2
|
|
31
|
+
try {
|
|
32
|
+
new Function('')
|
|
33
|
+
} catch(error) {
|
|
34
|
+
// if eval variants are not supported, do not create inline object readers ever
|
|
35
|
+
inlineObjectReadThreshold = Infinity
|
|
36
|
+
}
|
|
30
37
|
|
|
31
38
|
export class Unpackr {
|
|
32
39
|
constructor(options) {
|
|
@@ -440,7 +447,7 @@ const validName = /^[a-zA-Z_$][a-zA-Z\d_$]*$/
|
|
|
440
447
|
function createStructureReader(structure, firstId) {
|
|
441
448
|
function readObject() {
|
|
442
449
|
// This initial function is quick to instantiate, but runs slower. After several iterations pay the cost to build the faster function
|
|
443
|
-
if (readObject.count++ >
|
|
450
|
+
if (readObject.count++ > inlineObjectReadThreshold) {
|
|
444
451
|
let readObject = structure.read = (new Function('r', 'return function(){return {' + structure.map(key => validName.test(key) ? key + ':r()' : ('[' + JSON.stringify(key) + ']:r()')).join(',') + '}}'))(read)
|
|
445
452
|
if (structure.highByte === 0)
|
|
446
453
|
structure.read = createSecondByteReader(firstId, structure.read)
|
package/dist/str.cjs
DELETED
|
@@ -1,100 +0,0 @@
|
|
|
1
|
-
let utfz = require('../../msgpack-benchmark/node_modules/utfz-lib')
|
|
2
|
-
|
|
3
|
-
var safeEnd = 1000000;
|
|
4
|
-
var b = new Uint8Array(32768)
|
|
5
|
-
function writeString(value, target, position) {
|
|
6
|
-
var length, strLength = value.length;
|
|
7
|
-
let headerSize;
|
|
8
|
-
// first we estimate the header size, so we can write to the correct location
|
|
9
|
-
if (strLength < 0x20) {
|
|
10
|
-
headerSize = 1;
|
|
11
|
-
} else if (strLength < 0x100) {
|
|
12
|
-
headerSize = 2;
|
|
13
|
-
} else if (strLength < 0x10000) {
|
|
14
|
-
headerSize = 3;
|
|
15
|
-
} else {
|
|
16
|
-
headerSize = 5;
|
|
17
|
-
}
|
|
18
|
-
let maxBytes = strLength * 3;
|
|
19
|
-
//if (position + maxBytes > safeEnd)
|
|
20
|
-
// target = makeRoom(position + maxBytes);
|
|
21
|
-
for (let i = 0; i < 100; i++) {
|
|
22
|
-
length = pack(value, strLength, target, position + headerSize);
|
|
23
|
-
}
|
|
24
|
-
if (strLength < 0x40 || !encodeUtf8) {
|
|
25
|
-
var strPosition = position + headerSize;
|
|
26
|
-
var c2 = 0;
|
|
27
|
-
for (let i = 0; i < strLength; i++) {
|
|
28
|
-
const c1 = value.charCodeAt(i);
|
|
29
|
-
if (c1 < 0x80) {
|
|
30
|
-
target[strPosition++] = c1;
|
|
31
|
-
} else if (c1 < 0x800) {
|
|
32
|
-
target[strPosition++] = c1 >> 6 | 0xc0;
|
|
33
|
-
target[strPosition++] = c1 & 0x3f | 0x80;
|
|
34
|
-
} else if (
|
|
35
|
-
(c1 & 0xfc00) === 0xd800 &&
|
|
36
|
-
((c2 = value.charCodeAt(i + 1)) & 0xfc00) === 0xdc00
|
|
37
|
-
) {
|
|
38
|
-
c1 = 0x10000 + ((c1 & 0x03ff) << 10) + (c2 & 0x03ff);
|
|
39
|
-
i++;
|
|
40
|
-
target[strPosition++] = c1 >> 18 | 0xf0;
|
|
41
|
-
target[strPosition++] = c1 >> 12 & 0x3f | 0x80;
|
|
42
|
-
target[strPosition++] = c1 >> 6 & 0x3f | 0x80;
|
|
43
|
-
target[strPosition++] = c1 & 0x3f | 0x80;
|
|
44
|
-
} else {
|
|
45
|
-
target[strPosition++] = c1 >> 12 | 0xe0;
|
|
46
|
-
target[strPosition++] = c1 >> 6 & 0x3f | 0x80;
|
|
47
|
-
target[strPosition++] = c1 & 0x3f | 0x80;
|
|
48
|
-
}
|
|
49
|
-
}
|
|
50
|
-
length = strPosition - position - headerSize;
|
|
51
|
-
} else {
|
|
52
|
-
length = encodeUtf8(value, position + headerSize, maxBytes);
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
if (length < 0x20) {
|
|
57
|
-
target[position++] = 0xa0 | length;
|
|
58
|
-
} else if (length < 0x100) {
|
|
59
|
-
if (headerSize < 2) {
|
|
60
|
-
target.copyWithin(position + 2, position + 1, position + 1 + length);
|
|
61
|
-
}
|
|
62
|
-
target[position++] = 0xd9;
|
|
63
|
-
target[position++] = length;
|
|
64
|
-
} else if (length < 0x10000) {
|
|
65
|
-
if (headerSize < 3) {
|
|
66
|
-
target.copyWithin(position + 3, position + 2, position + 2 + length);
|
|
67
|
-
}
|
|
68
|
-
target[position++] = 0xda;
|
|
69
|
-
target[position++] = length >> 8;
|
|
70
|
-
target[position++] = length & 0xff;
|
|
71
|
-
} else {
|
|
72
|
-
if (headerSize < 5) {
|
|
73
|
-
target.copyWithin(position + 5, position + 3, position + 3 + length);
|
|
74
|
-
}
|
|
75
|
-
target[position++] = 0xdb;
|
|
76
|
-
targetView.setUint32(position, length);
|
|
77
|
-
position += 4;
|
|
78
|
-
}
|
|
79
|
-
return position + length
|
|
80
|
-
};
|
|
81
|
-
const pack = (str, length, buf, offset) => {
|
|
82
|
-
const start = offset;
|
|
83
|
-
let currHigh = 0;
|
|
84
|
-
for (let i = 0; i < length; i++) {
|
|
85
|
-
const code = str.charCodeAt(i);
|
|
86
|
-
const high = code >> 8;
|
|
87
|
-
if (high !== currHigh) {
|
|
88
|
-
buf[i + offset++] = 0;
|
|
89
|
-
buf[i + offset++] = high;
|
|
90
|
-
currHigh = high;
|
|
91
|
-
}
|
|
92
|
-
const low = code & 0xff;
|
|
93
|
-
buf[i + offset] = low;
|
|
94
|
-
if (!low) {
|
|
95
|
-
buf[i + ++offset] = currHigh;
|
|
96
|
-
}
|
|
97
|
-
}
|
|
98
|
-
return length + offset - start;
|
|
99
|
-
};
|
|
100
|
-
module.exports = writeString;
|