msgpackr 1.6.0 → 1.6.1

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 CHANGED
@@ -172,11 +172,9 @@
172
172
  referenceMap = null;
173
173
  } else if (position > srcEnd) {
174
174
  // over read
175
- let error = new Error('Unexpected end of MessagePack data');
176
- error.incomplete = true;
177
- throw error
175
+ throw new Error('Unexpected end of MessagePack data')
178
176
  } else if (!sequentialMode) {
179
- throw new Error('Data read, but end of buffer not reached')
177
+ throw new Error('Data read, but end of buffer not reached ' + JSON.stringify(result).slice(0, 100))
180
178
  }
181
179
  // else more to read, but we are reading sequentially, so don't clear source yet
182
180
  return result
@@ -184,7 +182,7 @@
184
182
  if (currentStructures.restoreStructures)
185
183
  restoreStructures();
186
184
  clearSource();
187
- if (error instanceof RangeError || error.message.startsWith('Unexpected end of buffer')) {
185
+ if (error instanceof RangeError || error.message.startsWith('Unexpected end of buffer') || position > srcEnd) {
188
186
  error.incomplete = true;
189
187
  }
190
188
  throw error
@@ -269,7 +267,10 @@
269
267
  case 0xc3: return true
270
268
  case 0xc4:
271
269
  // bin 8
272
- return readBin(src[position++])
270
+ value = src[position++];
271
+ if (value === undefined)
272
+ throw new Error('Unexpected end of buffer')
273
+ return readBin(value)
273
274
  case 0xc5:
274
275
  // bin 16
275
276
  value = dataView.getUint16(position);
@@ -578,12 +579,12 @@
578
579
  for (let i = 0; i < length; i++) {
579
580
  const byte = src[position++];
580
581
  if ((byte & 0x80) > 0) {
581
- position = start;
582
- return
583
- }
584
- bytes[i] = byte;
585
- }
586
- return fromCharCode.apply(String, bytes)
582
+ position = start;
583
+ return
584
+ }
585
+ bytes[i] = byte;
586
+ }
587
+ return fromCharCode.apply(String, bytes)
587
588
  }
588
589
  function shortStringInJS(length) {
589
590
  if (length < 4) {
package/dist/index.min.js CHANGED
@@ -1,11 +1,10 @@
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
- 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 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
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
+ throw new Error("Unexpected end of MessagePack data");else if(!Y)throw new Error("Data read, but end of buffer not reached "+JSON.stringify(e).slice(0,100));// else more to read, but we are reading sequentially, so don't clear source yet
4
+ return e}catch(e){throw M.restoreStructures&&s(),m(),(e instanceof RangeError||e.message.startsWith("Unexpected end of buffer")||P>E)&&(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
5
  let t=e-160;if(v>=P)return _.slice(P-F,(P+=t)-F);if(0==v&&140>E){// for small blocks, avoiding the overhead of the extract call is helpful
6
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
- case 194:return!1;case 195:return!0;case 196:// bin 8
8
- return p(R[P++]);case 197:return t=T.getUint16(P),P+=2,p(t);case 198:return t=T.getUint32(P),P+=4,p(t);case 199:// ext 8
7
+ case 194:return!1;case 195:return!0;case 196:if(t=R[P++],void 0===t)throw new Error("Unexpected end of buffer");return p(t);case 197:return t=T.getUint16(P),P+=2,p(t);case 198:return t=T.getUint32(P),P+=4,p(t);case 199:// ext 8
9
8
  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
9
  let e=se[(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
10
  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
@@ -15,7 +14,7 @@ return f(8);case 216:// fixext 16
15
14
  return f(16);case 217:return t=R[P++],v>=P?_.slice(P-F,(P+=t)-F):J(t);case 218:return t=T.getUint16(P),P+=2,v>=P?_.slice(P-F,(P+=t)-F):K(t);case 219:return t=T.getUint32(P),P+=4,v>=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
15
  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
16
  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
17
+ }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&&L)return L.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
18
  const t=63&R[P++];s.push((31&e)<<6|t)}else if(224==(240&e)){// 3 bytes
20
19
  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
20
  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 l(){let e,t=R[P++];if(192>t)// fixstr
@@ -26,17 +25,17 @@ let d=16>e?g(e):c(e);return null==d?s.string=H(e):s.string=d}// the registration
26
25
  // notepack defines extension 0 to mean undefined, so use that as the default here
27
26
  // registration of bulk record definition?
28
27
  // currentExtensions[0x52] = () =>
29
- function y(e){let t=E,n=P,s=F,r=v,i=_,o=C,a=B,u=new Uint8Array(R.slice(0,E)),d=M,c=M.slice(0,M.length),g=D,l=Y,p=e();return E=t,P=n,F=s,v=r,_=i,C=o,B=a,R=u,Y=l,M=d,M.splice(0,M.length,...c),D=g,T=new DataView(R.buffer,R.byteOffset,R.byteLength),p}function m(){R=null,C=null,M=null}function b(e){j[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
28
+ function y(e){let t=E,n=P,s=F,r=v,i=_,o=C,a=B,u=new Uint8Array(R.slice(0,E)),d=M,c=M.slice(0,M.length),g=D,l=Y,p=e();return E=t,P=n,F=s,v=r,_=i,C=o,B=a,R=u,Y=l,M=d,M.splice(0,M.length,...c),D=g,T=new DataView(R.buffer,R.byteOffset,R.byteLength),p}function m(){R=null,C=null,M=null}function b(e){j[e.type]=e.unpack?e.unpack:e}function U(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
29
  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
30
+ r[i++]=116,r[i++]=t,r.set(new Uint8Array(e.buffer,e.byteOffset,e.byteLength),i)}function k(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
31
  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){Ue.setUint32(Oe.position+e,Se-Oe.position-e);let n=Oe;Oe=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)");pe.unshift(e.Class),le.unshift(e)}b(e)}function*w(e,t){const n=new we(t);for(const s of e)yield n.pack(s)}async function*L(e,t){const n=new we(t);for await(const s of e)yield n.pack(s)}/**
32
+ 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){ke.setUint32(Oe.position+e,Se-Oe.position-e);let n=Oe;Oe=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)");pe.unshift(e.Class),le.unshift(e)}b(e)}function*w(e,t){const n=new we(t);for(const s of e)yield n.pack(s)}async function*x(e,t){const n=new we(t);for await(const s of e)yield n.pack(s)}/**
34
33
  * Given an Iterable/Iterator input which yields buffers, returns an IterableIterator which yields sync decoded objects
35
34
  * Or, given an Async Iterable/Iterator which yields promises resolving in buffers, returns an AsyncIterableIterator.
36
35
  * @param {Iterable|Iterator|AsyncIterable|AsyncIterableIterator} bufferIterator
37
36
  * @param {object} [options] - unpackr options
38
37
  * @returns {IterableIterator|Promise.<AsyncIterableIterator}
39
- */var x;try{x=new TextDecoder}catch(e){}var R,E,M,_,B,C,T,P=0,D={},F=0,v=0,j=[],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
38
+ */var L;try{L=new TextDecoder}catch(e){}var R,E,M,_,B,C,T,P=0,D={},F=0,v=0,j=[],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
39
  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
40
  return y(()=>(m(),this?this.unpack(e,t):$.prototype.unpack.call(N,e,t)));E=-1<t?t:e.length,P=0,v=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
42
41
  // technique for getting data from a database where it can be copied into an existing buffer instead of creating
@@ -48,36 +47,36 @@ return s.used?Object.assign(t,i):(s.target=i,i);// no cycle, can just use the re
48
47
  },j[112]=()=>{// pointer extension (for structured clones)
49
48
  let e=T.getUint32(P-4),t=C.get(e);return t.used=!0,t.target},j[115]=()=>new Set(r());const te=["Int8","Uint8","Uint8Clamped","Int16","Uint16","Int32","Uint32","Float32","Float64","BigInt64","BigUint64"].map(e=>e+"Array");j[116]=e=>{let t=e[0],n=te[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
49
  return new globalThis[n](Uint8Array.prototype.slice.call(e,1).buffer)},j[120]=()=>{let e=r();return new RegExp(e[0],e[1])};const ne=[];j[98]=e=>{let t=(e[0]<<24)+(e[1]<<16)+(e[2]<<8)+e[3],n=P;return P+=t-e.length,B=ne,B=[l(),l()],B.position0=0,B.position1=0,B.postBundlePosition=P,P=n,r()},j[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 se=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++)se[n]=+("1e"+t(45.15-.30103*n));var re=new $({useRecords:!1});const ie=re.unpack,oe=re.unpackMultiple,ae=re.unpack,ue={NEVER:0,ALWAYS:1,DECIMAL_ROUND:3,DECIMAL_FIT:4};let de,ce=new Float32Array(1),ge=new Uint8Array(ce.buffer,0,4);try{de=new TextEncoder}catch(e){}let le,pe;const fe="undefined"!=typeof Buffer,he=fe?function(e){return Buffer.allocUnsafeSlow(e)}:Uint8Array,ye=fe?Buffer:Uint8Array,me=fe?4294967296:2144337920;let be,ke,Ue,Ie,Se=0,Oe=null;const Ae=Symbol("record-id");class we extends ${constructor(e){super(e),this.offset=0;let t,n,s,r,i=0,o=ye.prototype.utf8Write?function(e,t){return be.utf8Write(e,t,4294967295)}:!!(de&&de.encodeInto)&&function(e,t){return de.encodeInto(e,be.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 l=32<c||64<g+c,p=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(be||(be=new he(8192),Ue=new DataView(be.buffer,0,8192),Se=0),Ie=be.length-10,2048>Ie-Se?(be=new he(be.length),Ue=new DataView(be.buffer,0,be.length),Ie=be.length-10,Se=0):Se=2147483640&Se+7,t=Se,r=a.structuredClone?new Map:null,a.bundleStrings&&"string"!=typeof e?(Oe=[],Oe.size=1/0):Oe=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
50
+ for(let n=0;256>n;n++)se[n]=+("1e"+t(45.15-.30103*n));var re=new $({useRecords:!1});const ie=re.unpack,oe=re.unpackMultiple,ae=re.unpack,ue={NEVER:0,ALWAYS:1,DECIMAL_ROUND:3,DECIMAL_FIT:4};let de,ce=new Float32Array(1),ge=new Uint8Array(ce.buffer,0,4);try{de=new TextEncoder}catch(e){}let le,pe;const fe="undefined"!=typeof Buffer,he=fe?function(e){return Buffer.allocUnsafeSlow(e)}:Uint8Array,ye=fe?Buffer:Uint8Array,me=fe?4294967296:2144337920;let be,Ue,ke,Ie,Se=0,Oe=null;const Ae=Symbol("record-id");class we extends ${constructor(e){super(e),this.offset=0;let t,n,s,r,i=0,o=ye.prototype.utf8Write?function(e,t){return be.utf8Write(e,t,4294967295)}:!!(de&&de.encodeInto)&&function(e,t){return de.encodeInto(e,be.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
51
+ let l=32<c||64<g+c,p=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(be||(be=new he(8192),ke=new DataView(be.buffer,0,8192),Se=0),Ie=be.length-10,2048>Ie-Se?(be=new he(be.length),ke=new DataView(be.buffer,0,be.length),Ie=be.length-10,Se=0):Se=2147483640&Se+7,t=Se,r=a.structuredClone?new Map:null,a.bundleStrings&&"string"!=typeof e?(Oe=[],Oe.size=1/0):Oe=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
52
  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[Ae]=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),Oe&&O(t,b),a.offset=Se,r&&r.idsToInsert){Se+=6*r.idsToInsert.length,Se>Ie&&U(Se),a.offset=Se;let e=S(be.subarray(t,Se),r.idsToInsert);return r=null,e}return o&Ce?(be.start=t,be.end=Se,be):be.subarray(t,Se);// position can change if we call pack again in saveStructures, so we get the buffer now
53
+ if(b(e),Oe&&O(t,b),a.offset=Se,r&&r.idsToInsert){Se+=6*r.idsToInsert.length,Se>Ie&&k(Se),a.offset=Se;let e=S(be.subarray(t,Se),r.idsToInsert);return r=null,e}return o&Ce?(be.start=t,be.end=Se,be):be.subarray(t,Se);// position can change if we call pack again in saveStructures, so we get the buffer now
55
54
  }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][Ae]=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=be.subarray(t,Se);return!1===a.saveStructures(s,i)?(a._mergeStructures(a.getStructures()),a.pack(e)):(i=r,n)}}o&Te&&(Se=t)}};const b=e=>{Se>Ie&&(be=U(Se));var n,s=typeof e;if("string"==s){let s=e.length;if(Oe&&4<=s&&4096>s){if((Oe.size+=s)>61440){let e,n=(Oe[0]?3*Oe[0].length+Oe[1].length:0)+10;Se+n>Ie&&(be=U(Se+n)),Oe.position?(be[Se]=200,Se+=3,be[Se++]=98,e=Se-t,Se+=4,O(t,b),Ue.setUint16(e+t-3,Se-t-e)):(be[Se++]=214,be[Se++]=98,e=Se-t,Se+=4),Oe=["",""],Oe.size=0,Oe.position=e}let n=/[\u0080-\uFFFF]/.test(e);return Oe[n?0:1]+=e,be[Se++]=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(Se+i>Ie&&(be=U(Se+i)),64>s||!o){let t,i,o,a=Se+r;for(t=0;t<s;t++)i=e.charCodeAt(t),128>i?be[a++]=i:2048>i?(be[a++]=192|i>>6,be[a++]=128|63&i):55296==(64512&i)&&56320==(64512&(o=e.charCodeAt(t+1)))?(i=65536+((1023&i)<<10)+(1023&o),t++,be[a++]=240|i>>18,be[a++]=128|63&i>>12,be[a++]=128|63&i>>6,be[a++]=128|63&i):(be[a++]=224|i>>12,be[a++]=128|63&i>>6,be[a++]=128|63&i);n=a-Se-r}else n=o(e,Se+r);32>n?be[Se++]=160|n:256>n?(2>r&&be.copyWithin(Se+2,Se+1,Se+1+n),be[Se++]=217,be[Se++]=n):65536>n?(3>r&&be.copyWithin(Se+3,Se+2,Se+2+n),be[Se++]=218,be[Se++]=n>>8,be[Se++]=255&n):(5>r&&be.copyWithin(Se+5,Se+3,Se+3+n),be[Se++]=219,Ue.setUint32(Se,n),Se+=4),Se+=n}else if("number"===s){if(e>>>0===e)64>e?be[Se++]=e:256>e?(be[Se++]=204,be[Se++]=e):65536>e?(be[Se++]=205,be[Se++]=e>>8,be[Se++]=255&e):(be[Se++]=206,Ue.setUint32(Se,e),Se+=4);else if(e>>0===e)-32<=e?be[Se++]=256+e:-128<=e?(be[Se++]=208,be[Se++]=e+256):-32768<=e?(be[Se++]=209,Ue.setInt16(Se,e),Se+=2):(be[Se++]=210,Ue.setInt32(Se,e),Se+=4);else{let t;if(0<(t=this.useFloat32)&&4294967296>e&&-2147483648<=e){be[Se++]=202,Ue.setFloat32(Se,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
55
+ let n=be.subarray(t,Se);return!1===a.saveStructures(s,i)?(a._mergeStructures(a.getStructures()),a.pack(e)):(i=r,n)}}o&Te&&(Se=t)}};const b=e=>{Se>Ie&&(be=k(Se));var n,s=typeof e;if("string"==s){let s=e.length;if(Oe&&4<=s&&4096>s){if((Oe.size+=s)>61440){let e,n=(Oe[0]?3*Oe[0].length+Oe[1].length:0)+10;Se+n>Ie&&(be=k(Se+n)),Oe.position?(be[Se]=200,Se+=3,be[Se++]=98,e=Se-t,Se+=4,O(t,b),ke.setUint16(e+t-3,Se-t-e)):(be[Se++]=214,be[Se++]=98,e=Se-t,Se+=4),Oe=["",""],Oe.size=0,Oe.position=e}let n=/[\u0080-\uFFFF]/.test(e);return Oe[n?0:1]+=e,be[Se++]=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
56
+ let i=3*s;if(Se+i>Ie&&(be=k(Se+i)),64>s||!o){let t,i,o,a=Se+r;for(t=0;t<s;t++)i=e.charCodeAt(t),128>i?be[a++]=i:2048>i?(be[a++]=192|i>>6,be[a++]=128|63&i):55296==(64512&i)&&56320==(64512&(o=e.charCodeAt(t+1)))?(i=65536+((1023&i)<<10)+(1023&o),t++,be[a++]=240|i>>18,be[a++]=128|63&i>>12,be[a++]=128|63&i>>6,be[a++]=128|63&i):(be[a++]=224|i>>12,be[a++]=128|63&i>>6,be[a++]=128|63&i);n=a-Se-r}else n=o(e,Se+r);32>n?be[Se++]=160|n:256>n?(2>r&&be.copyWithin(Se+2,Se+1,Se+1+n),be[Se++]=217,be[Se++]=n):65536>n?(3>r&&be.copyWithin(Se+3,Se+2,Se+2+n),be[Se++]=218,be[Se++]=n>>8,be[Se++]=255&n):(5>r&&be.copyWithin(Se+5,Se+3,Se+3+n),be[Se++]=219,ke.setUint32(Se,n),Se+=4),Se+=n}else if("number"===s){if(e>>>0===e)64>e?be[Se++]=e:256>e?(be[Se++]=204,be[Se++]=e):65536>e?(be[Se++]=205,be[Se++]=e>>8,be[Se++]=255&e):(be[Se++]=206,ke.setUint32(Se,e),Se+=4);else if(e>>0===e)-32<=e?be[Se++]=256+e:-128<=e?(be[Se++]=208,be[Se++]=e+256):-32768<=e?(be[Se++]=209,ke.setInt16(Se,e),Se+=2):(be[Se++]=210,ke.setInt32(Se,e),Se+=4);else{let t;if(0<(t=this.useFloat32)&&4294967296>e&&-2147483648<=e){be[Se++]=202,ke.setFloat32(Se,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
57
  (n=e*se[(127&be[Se])<<1|be[Se+1]>>7])>>0===n)return void(Se+=4);// move back into position for writing a double
59
- Se--}be[Se++]=203,Ue.setFloat64(Se,e),Se+=8}}else if("object"===s){if(!e)be[Se++]=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 be[Se++]=214,be[Se++]=112,Ue.setUint32(Se,n.id),void(Se+=4)}r.set(e,{offset:Se-t})}let s=e.constructor;if(s===Object)k(e,!0);else if(s===Array){n=e.length,16>n?be[Se++]=144|n:65536>n?(be[Se++]=220,be[Se++]=n>>8,be[Se++]=255&n):(be[Se++]=221,Ue.setUint32(Se,n),Se+=4);for(let t=0;t<n;t++)b(e[t])}else if(s===Map){n=e.size,16>n?be[Se++]=128|n:65536>n?(be[Se++]=222,be[Se++]=n>>8,be[Se++]=255&n):(be[Se++]=223,Ue.setUint32(Se,n),Se+=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=pe[n],e instanceof t){let t=le[n];if(t.write)return t.type&&(be[Se++]=212,be[Se++]=t.type,be[Se++]=0),void b(t.write.call(this,e));let s=be,r=Ue,i=Se;be=null;let o;try{o=t.pack.call(this,e,e=>(be=s,s=null,Se+=e,Se>Ie&&U(Se),{target:be,targetView:Ue,position:Se-e}),b)}finally{s&&(be=s,Ue=r,Se=i,Ie=be.length-10)}return void(o&&(o.length+Se>Ie&&U(o.length+Se),Se=I(o,be,Se,t.type)))}// no extension found, write as object
60
- k(e,!e.hasOwnProperty)}}}else if("boolean"===s)be[Se++]=e?195:194;else if("bigint"===s){if(e<BigInt(1)<<BigInt(63)&&e>=-(BigInt(1)<<BigInt(63)))be[Se++]=211,Ue.setBigInt64(Se,e);else if(e<BigInt(1)<<BigInt(64)&&0<e)be[Se++]=207,Ue.setBigUint64(Se,e);else// overflow
61
- if(this.largeBigIntToFloat)be[Se++]=203,Ue.setFloat64(Se,+e);else throw new RangeError(e+" was too large to fit in MessagePack 64-bit integer format, set largeBigIntToFloat to convert to float-64");Se+=8}else if("undefined"===s)this.encodeUndefinedAsNil?be[Se++]=192:(be[Se++]=212,be[Se++]=0,be[Se++]=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?be[Se++]=128|n:65536>n?(be[Se++]=222,be[Se++]=n>>8,be[Se++]=255&n):(be[Se++]=223,Ue.setUint32(Se,n),Se+=4);let s;for(let r=0;r<n;r++)b(s=t[r]),b(e[s])}:(e,n)=>{be[Se++]=222;// always using map 16, so we can preallocate and set the length afterwards
58
+ Se--}be[Se++]=203,ke.setFloat64(Se,e),Se+=8}}else if("object"===s){if(!e)be[Se++]=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 be[Se++]=214,be[Se++]=112,ke.setUint32(Se,n.id),void(Se+=4)}r.set(e,{offset:Se-t})}let s=e.constructor;if(s===Object)U(e,!0);else if(s===Array){n=e.length,16>n?be[Se++]=144|n:65536>n?(be[Se++]=220,be[Se++]=n>>8,be[Se++]=255&n):(be[Se++]=221,ke.setUint32(Se,n),Se+=4);for(let t=0;t<n;t++)b(e[t])}else if(s===Map){n=e.size,16>n?be[Se++]=128|n:65536>n?(be[Se++]=222,be[Se++]=n>>8,be[Se++]=255&n):(be[Se++]=223,ke.setUint32(Se,n),Se+=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=pe[n],e instanceof t){let t=le[n];if(t.write)return t.type&&(be[Se++]=212,be[Se++]=t.type,be[Se++]=0),void b(t.write.call(this,e));let s=be,r=ke,i=Se;be=null;let o;try{o=t.pack.call(this,e,e=>(be=s,s=null,Se+=e,Se>Ie&&k(Se),{target:be,targetView:ke,position:Se-e}),b)}finally{s&&(be=s,ke=r,Se=i,Ie=be.length-10)}return void(o&&(o.length+Se>Ie&&k(o.length+Se),Se=I(o,be,Se,t.type)))}// no extension found, write as object
59
+ U(e,!e.hasOwnProperty)}}}else if("boolean"===s)be[Se++]=e?195:194;else if("bigint"===s){if(e<BigInt(1)<<BigInt(63)&&e>=-(BigInt(1)<<BigInt(63)))be[Se++]=211,ke.setBigInt64(Se,e);else if(e<BigInt(1)<<BigInt(64)&&0<e)be[Se++]=207,ke.setBigUint64(Se,e);else// overflow
60
+ if(this.largeBigIntToFloat)be[Se++]=203,ke.setFloat64(Se,+e);else throw new RangeError(e+" was too large to fit in MessagePack 64-bit integer format, set largeBigIntToFloat to convert to float-64");Se+=8}else if("undefined"===s)this.encodeUndefinedAsNil?be[Se++]=192:(be[Se++]=212,be[Se++]=0,be[Se++]=0);else if("function"===s)b(this.writeFunction&&this.writeFunction());else throw new Error("Unknown type: "+s)},U=!1===this.useRecords?this.variableMapSize?e=>{// this method is slightly slower, but generates "preferred serialization" (optimally small for smaller objects)
61
+ let t=Object.keys(e),n=t.length;16>n?be[Se++]=128|n:65536>n?(be[Se++]=222,be[Se++]=n>>8,be[Se++]=255&n):(be[Se++]=223,ke.setUint32(Se,n),Se+=4);let s;for(let r=0;r<n;r++)b(s=t[r]),b(e[s])}:(e,n)=>{be[Se++]=222;// always using map 16, so we can preallocate and set the length afterwards
63
62
  let s=Se-t;Se+=2;let r=0;for(let t in e)(n||e.hasOwnProperty(t))&&(b(t),b(e[t]),r++);be[s++ +t]=r>>8,be[s+t]=255&r}:e.progressiveRecords&&!l?// 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
63
  (e,n)=>{let r,i,o=s.transitions||(s.transitions=Object.create(null)),a=Se++-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
64
  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==Se?(Se--,A(o,n,c)):// otherwise we need to insert the record, moving existing data after the record
66
65
  w(o,n,a,c),i=!0,o=d[u]}b(e[u])}if(!i){let n=o[Ae];n?be[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[Ae];// now write the values
67
- for(let n in o?96<=o&&l?(be[Se++]=(31&(o-=96))+96,be[Se++]=o>>5):be[Se++]=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
66
+ for(let n in o?96<=o&&l?(be[Se++]=(31&(o-=96))+96,be[Se++]=o>>5):be[Se++]=o:A(r,r.__keys__||Object.keys(e),i),e)(t||e.hasOwnProperty(n))&&b(e[n])},k=e=>{var n=Math.min,s=Math.round,r=Math.max;let i;if(16777216<e){// special handling for really large buffers
68
67
  if(e-t>me)throw new Error("Packed buffer would be larger than maximum buffer size");i=n(me,4096*s(r((e-t)*(67108864<e?1.25:2),4194304)/4096))}else// faster handling for smaller buffers
69
- i=(r(e-t<<2,be.length-1)>>12)+1<<12;let o=new he(i);return Ue=new DataView(o.buffer,0,i),e=n(e,be.length),be.copy?be.copy(o,0,t,e):o.set(be.slice(t,e)),Se-=t,t=0,Ie=o.length-10,be=o},A=(e,t,r)=>{let i=s.nextId;i||(i=64),i<p&&this.shouldShareStructure&&!this.shouldShareStructure(t)?(i=s.nextOwnId,!(i<f)&&(i=p),s.nextOwnId=i+1):(i>=f&&(// cycle back around
70
- i=p),s.nextId=i+1);let o=t.highByte=96<=i&&l?i-96>>5:-1;e[Ae]=i,e.__keys__=t,s[i-64]=t,i<p?(t.isShared=!0,s.sharedLength=i-63,n=!0,0<=o?(be[Se++]=(31&i)+96,be[Se++]=o):be[Se++]=i):(0<=o?(be[Se++]=213,be[Se++]=114,be[Se++]=(31&i)+96,be[Se++]=o):(be[Se++]=212,be[Se++]=114,be[Se++]=i),r&&(y+=m*r),h.length>=g&&(h.shift()[Ae]=0),h.push(e),b(t))},w=(e,n,s,r)=>{let i=be,o=Se,a=Ie,u=t;be=ke,Se=0,t=0,be||(ke=be=new he(8192)),Ie=be.length-10,A(e,n,r),ke=be;let d=Se;if(be=i,Se=o,Ie=a,t=u,1<d){let e=Se+d-1;e>Ie&&U(e);let n=s+t;be.copyWithin(n+d,n+1,Se),be.set(ke.slice(0,d),n),Se=e}else be[s+t]=ke[0]}}useBuffer(e){// this means we are finished using our own buffer and we can write over it safely
71
- be=e,Ue=new DataView(be.buffer,be.byteOffset,be.byteLength),Se=0}clearSharedData(){this.structures&&(this.structures=[])}}pe=[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
68
+ i=(r(e-t<<2,be.length-1)>>12)+1<<12;let o=new he(i);return ke=new DataView(o.buffer,0,i),e=n(e,be.length),be.copy?be.copy(o,0,t,e):o.set(be.slice(t,e)),Se-=t,t=0,Ie=o.length-10,be=o},A=(e,t,r)=>{let i=s.nextId;i||(i=64),i<p&&this.shouldShareStructure&&!this.shouldShareStructure(t)?(i=s.nextOwnId,!(i<f)&&(i=p),s.nextOwnId=i+1):(i>=f&&(// cycle back around
69
+ i=p),s.nextId=i+1);let o=t.highByte=96<=i&&l?i-96>>5:-1;e[Ae]=i,e.__keys__=t,s[i-64]=t,i<p?(t.isShared=!0,s.sharedLength=i-63,n=!0,0<=o?(be[Se++]=(31&i)+96,be[Se++]=o):be[Se++]=i):(0<=o?(be[Se++]=213,be[Se++]=114,be[Se++]=(31&i)+96,be[Se++]=o):(be[Se++]=212,be[Se++]=114,be[Se++]=i),r&&(y+=m*r),h.length>=g&&(h.shift()[Ae]=0),h.push(e),b(t))},w=(e,n,s,r)=>{let i=be,o=Se,a=Ie,u=t;be=Ue,Se=0,t=0,be||(Ue=be=new he(8192)),Ie=be.length-10,A(e,n,r),Ue=be;let d=Se;if(be=i,Se=o,Ie=a,t=u,1<d){let e=Se+d-1;e>Ie&&k(e);let n=s+t;be.copyWithin(n+d,n+1,Se),be.set(Ue.slice(0,d),n),Se=e}else be[s+t]=Ue[0]}}useBuffer(e){// this means we are finished using our own buffer and we can write over it safely
70
+ be=e,ke=new DataView(be.buffer,be.byteOffset,be.byteLength),Se=0}clearSharedData(){this.structures&&(this.structures=[])}}pe=[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
71
  let{target:e,targetView:t,position:s}=n(6);e[s++]=214,e[s++]=255,t.setUint32(s,r)}else if(0<r&&4294967296>r){// Timestamp 64
73
72
  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
73
  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(fe?Buffer.from(e):new Uint8Array(e),t)}},{pack(e,t){let n=e.constructor;n!==ye&&this.moreTypes?k(e,te.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 Le=new we({useRecords:!1});const xe=Le.pack,Re=Le.pack,{NEVER:Ee,ALWAYS:Me,DECIMAL_ROUND:_e,DECIMAL_FIT:Be}=ue,Ce=512,Te=1024;e.ALWAYS=Me,e.C1=W,e.DECIMAL_FIT=Be,e.DECIMAL_ROUND=_e,e.Decoder=$,e.Encoder=we,e.FLOAT32_OPTIONS=ue,e.NEVER=Ee,e.Packr=we,e.REUSE_BUFFER_MODE=Ce,e.Unpackr=$,e.addExtension=A,e.clearSource=m,e.decode=ae,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
74
+ 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?U(e,16,t):k(fe?Buffer.from(e):new Uint8Array(e),t)}},{pack(e,t){let n=e.constructor;n!==ye&&this.moreTypes?U(e,te.indexOf(n.name),t):k(e,t)}},{pack(e,t){// specific 0xC1 object
75
+ let{target:n,position:s}=t(1);n[s]=193}}];let xe=new we({useRecords:!1});const Le=xe.pack,Re=xe.pack,{NEVER:Ee,ALWAYS:Me,DECIMAL_ROUND:_e,DECIMAL_FIT:Be}=ue,Ce=512,Te=1024;e.ALWAYS=Me,e.C1=W,e.DECIMAL_FIT=Be,e.DECIMAL_ROUND=_e,e.Decoder=$,e.Encoder=we,e.FLOAT32_OPTIONS=ue,e.NEVER=Ee,e.Packr=we,e.REUSE_BUFFER_MODE=Ce,e.Unpackr=$,e.addExtension=A,e.clearSource=m,e.decode=ae,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
76
  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=Re,e.encodeIter=/**
78
77
  * Given an Iterable first argument, returns an Iterable where each value is packed as a Buffer
79
78
  * If the argument is only Async Iterable, the return value will be an Async Iterable.
80
79
  * @param {Iterable|Iterator|AsyncIterable|AsyncIterator} objectIterator - iterable source, like a Readable object stream, an array, Set, or custom object
81
80
  * @param {options} [options] - msgpackr pack options
82
81
  * @returns {IterableIterator|Promise.<AsyncIterableIterator>}
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=xe,e.roundFloat32=function(e){ce[0]=e;let t=se[(127&ge[3])<<1|ge[2]>>7];return(t*e+(0<e?.5:-.5)>>0)/t},e.unpack=ie,e.unpackMultiple=oe,e.useRecords=!1,Object.defineProperty(e,"__esModule",{value:!0})});
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 x(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=Le,e.roundFloat32=function(e){ce[0]=e;let t=se[(127&ge[3])<<1|ge[2]>>7];return(t*e+(0<e?.5:-.5)>>0)/t},e.unpack=ie,e.unpackMultiple=oe,e.useRecords=!1,Object.defineProperty(e,"__esModule",{value:!0})});
package/dist/node.cjs CHANGED
@@ -178,11 +178,9 @@ function checkedRead() {
178
178
  referenceMap = null;
179
179
  } else if (position > srcEnd) {
180
180
  // over read
181
- let error = new Error('Unexpected end of MessagePack data');
182
- error.incomplete = true;
183
- throw error
181
+ throw new Error('Unexpected end of MessagePack data')
184
182
  } else if (!sequentialMode) {
185
- throw new Error('Data read, but end of buffer not reached')
183
+ throw new Error('Data read, but end of buffer not reached ' + JSON.stringify(result).slice(0, 100))
186
184
  }
187
185
  // else more to read, but we are reading sequentially, so don't clear source yet
188
186
  return result
@@ -190,7 +188,7 @@ function checkedRead() {
190
188
  if (currentStructures.restoreStructures)
191
189
  restoreStructures();
192
190
  clearSource();
193
- if (error instanceof RangeError || error.message.startsWith('Unexpected end of buffer')) {
191
+ if (error instanceof RangeError || error.message.startsWith('Unexpected end of buffer') || position > srcEnd) {
194
192
  error.incomplete = true;
195
193
  }
196
194
  throw error
@@ -275,7 +273,10 @@ function read() {
275
273
  case 0xc3: return true
276
274
  case 0xc4:
277
275
  // bin 8
278
- return readBin(src[position++])
276
+ value = src[position++];
277
+ if (value === undefined)
278
+ throw new Error('Unexpected end of buffer')
279
+ return readBin(value)
279
280
  case 0xc5:
280
281
  // bin 16
281
282
  value = dataView.getUint16(position);
@@ -623,12 +624,12 @@ function longStringInJS(length) {
623
624
  for (let i = 0; i < length; i++) {
624
625
  const byte = src[position++];
625
626
  if ((byte & 0x80) > 0) {
626
- position = start;
627
- return
628
- }
629
- bytes[i] = byte;
630
- }
631
- return fromCharCode.apply(String, bytes)
627
+ position = start;
628
+ return
629
+ }
630
+ bytes[i] = byte;
631
+ }
632
+ return fromCharCode.apply(String, bytes)
632
633
  }
633
634
  function shortStringInJS(length) {
634
635
  if (length < 4) {
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "msgpackr",
3
3
  "author": "Kris Zyp",
4
- "version": "1.6.0",
4
+ "version": "1.6.1",
5
5
  "description": "Ultra-fast MessagePack implementation with extensions for records and structured cloning",
6
6
  "license": "MIT",
7
7
  "types": "./index.d.ts",
package/unpack.js CHANGED
@@ -176,11 +176,9 @@ export function checkedRead() {
176
176
  referenceMap = null
177
177
  } else if (position > srcEnd) {
178
178
  // over read
179
- let error = new Error('Unexpected end of MessagePack data')
180
- error.incomplete = true
181
- throw error
179
+ throw new Error('Unexpected end of MessagePack data')
182
180
  } else if (!sequentialMode) {
183
- throw new Error('Data read, but end of buffer not reached')
181
+ throw new Error('Data read, but end of buffer not reached ' + JSON.stringify(result).slice(0, 100))
184
182
  }
185
183
  // else more to read, but we are reading sequentially, so don't clear source yet
186
184
  return result
@@ -188,7 +186,7 @@ export function checkedRead() {
188
186
  if (currentStructures.restoreStructures)
189
187
  restoreStructures()
190
188
  clearSource()
191
- if (error instanceof RangeError || error.message.startsWith('Unexpected end of buffer')) {
189
+ if (error instanceof RangeError || error.message.startsWith('Unexpected end of buffer') || position > srcEnd) {
192
190
  error.incomplete = true
193
191
  }
194
192
  throw error
@@ -273,7 +271,10 @@ export function read() {
273
271
  case 0xc3: return true
274
272
  case 0xc4:
275
273
  // bin 8
276
- return readBin(src[position++])
274
+ value = src[position++]
275
+ if (value === undefined)
276
+ throw new Error('Unexpected end of buffer')
277
+ return readBin(value)
277
278
  case 0xc5:
278
279
  // bin 16
279
280
  value = dataView.getUint16(position)
@@ -621,12 +622,12 @@ function longStringInJS(length) {
621
622
  for (let i = 0; i < length; i++) {
622
623
  const byte = src[position++];
623
624
  if ((byte & 0x80) > 0) {
624
- position = start
625
- return
626
- }
627
- bytes[i] = byte
628
- }
629
- return fromCharCode.apply(String, bytes)
625
+ position = start
626
+ return
627
+ }
628
+ bytes[i] = byte
629
+ }
630
+ return fromCharCode.apply(String, bytes)
630
631
  }
631
632
  function shortStringInJS(length) {
632
633
  if (length < 4) {
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;