@msgpack/msgpack
Advanced tools
Comparing version
@@ -1,2 +0,2 @@ | ||
!function(t,e){"object"==typeof exports&&"object"==typeof module?module.exports=e():"function"==typeof define&&define.amd?define([],e):"object"==typeof exports?exports.MessagePack=e():t.MessagePack=e()}(this,(function(){return function(){"use strict";var t={d:function(e,n){for(var r in n)t.o(n,r)&&!t.o(e,r)&&Object.defineProperty(e,r,{enumerable:!0,get:n[r]})},o:function(t,e){return Object.prototype.hasOwnProperty.call(t,e)},r:function(t){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"__esModule",{value:!0})}},e={};t.r(e),t.d(e,{DataViewIndexOutOfBoundsError:function(){return _},DecodeError:function(){return h},Decoder:function(){return H},EXT_TIMESTAMP:function(){return d},Encoder:function(){return E},ExtData:function(){return c},ExtensionCodec:function(){return S},decode:function(){return V},decodeArrayStream:function(){return Z},decodeAsync:function(){return Y},decodeMulti:function(){return K},decodeMultiStream:function(){return $},decodeTimestampExtension:function(){return m},decodeTimestampToTimeSpec:function(){return U},encode:function(){return A},encodeDateToTimeSpec:function(){return g},encodeTimeSpecToTimestamp:function(){return v},encodeTimestampExtension:function(){return b}});var n=function(t,e){var n="function"==typeof Symbol&&t[Symbol.iterator];if(!n)return t;var r,i,o=n.call(t),s=[];try{for(;(void 0===e||e-- >0)&&!(r=o.next()).done;)s.push(r.value)}catch(t){i={error:t}}finally{try{r&&!r.done&&(n=o.return)&&n.call(o)}finally{if(i)throw i.error}}return s},r=function(t,e,n){if(n||2===arguments.length)for(var r,i=0,o=e.length;i<o;i++)!r&&i in e||(r||(r=Array.prototype.slice.call(e,0,i)),r[i]=e[i]);return t.concat(r||Array.prototype.slice.call(e))},i=new TextEncoder;function o(t,e,i){for(var o=e,s=o+i,a=[],c="";o<s;){var u=t[o++];if(128&u)if(192==(224&u)){var h=63&t[o++];a.push((31&u)<<6|h)}else if(224==(240&u)){h=63&t[o++];var f=63&t[o++];a.push((31&u)<<12|h<<6|f)}else if(240==(248&u)){var l=(7&u)<<18|(h=63&t[o++])<<12|(f=63&t[o++])<<6|63&t[o++];l>65535&&(l-=65536,a.push(l>>>10&1023|55296),l=56320|1023&l),a.push(l)}else a.push(u);else a.push(u);a.length>=4096&&(c+=String.fromCharCode.apply(String,r([],n(a),!1)),a.length=0)}return a.length>0&&(c+=String.fromCharCode.apply(String,r([],n(a),!1))),c}var s=new TextDecoder;var a,c=function(t,e){this.type=t,this.data=e},u=(a=function(t,e){return a=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var n in e)Object.prototype.hasOwnProperty.call(e,n)&&(t[n]=e[n])},a(t,e)},function(t,e){if("function"!=typeof e&&null!==e)throw new TypeError("Class extends value "+String(e)+" is not a constructor or null");function n(){this.constructor=t}a(t,e),t.prototype=null===e?Object.create(e):(n.prototype=e.prototype,new n)}),h=function(t){function e(n){var r=t.call(this,n)||this,i=Object.create(e.prototype);return Object.setPrototypeOf(r,i),Object.defineProperty(r,"name",{configurable:!0,enumerable:!1,value:e.name}),r}return u(e,t),e}(Error),f=4294967295;function l(t,e,n){var r=Math.floor(n/4294967296),i=n;t.setUint32(e,r),t.setUint32(e+4,i)}function p(t,e){return 4294967296*t.getInt32(e)+t.getUint32(e+4)}var d=-1,y=4294967295,w=17179869183;function v(t){var e,n=t.sec,r=t.nsec;if(n>=0&&r>=0&&n<=w){if(0===r&&n<=y){var i=new Uint8Array(4);return(e=new DataView(i.buffer)).setUint32(0,n),i}var o=n/4294967296,s=4294967295&n;return i=new Uint8Array(8),(e=new DataView(i.buffer)).setUint32(0,r<<2|3&o),e.setUint32(4,s),i}return i=new Uint8Array(12),(e=new DataView(i.buffer)).setUint32(0,r),l(e,4,n),i}function g(t){var e=t.getTime(),n=Math.floor(e/1e3),r=1e6*(e-1e3*n),i=Math.floor(r/1e9);return{sec:n+i,nsec:r-1e9*i}}function b(t){return t instanceof Date?v(g(t)):null}function U(t){var e=new DataView(t.buffer,t.byteOffset,t.byteLength);switch(t.byteLength){case 4:return{sec:e.getUint32(0),nsec:0};case 8:var n=e.getUint32(0);return{sec:4294967296*(3&n)+e.getUint32(4),nsec:n>>>2};case 12:return{sec:p(e,4),nsec:e.getUint32(0)};default:throw new h("Unrecognized data size for timestamp (expected 4, 8, or 12): ".concat(t.length))}}function m(t){var e=U(t);return new Date(1e3*e.sec+e.nsec/1e6)}var x={type:d,encode:b,decode:m},S=function(){function t(){this.builtInEncoders=[],this.builtInDecoders=[],this.encoders=[],this.decoders=[],this.register(x)}return t.prototype.register=function(t){var e=t.type,n=t.encode,r=t.decode;if(e>=0)this.encoders[e]=n,this.decoders[e]=r;else{var i=1+e;this.builtInEncoders[i]=n,this.builtInDecoders[i]=r}},t.prototype.tryToEncode=function(t,e){for(var n=0;n<this.builtInEncoders.length;n++)if(null!=(r=this.builtInEncoders[n])&&null!=(i=r(t,e)))return new c(-1-n,i);for(n=0;n<this.encoders.length;n++){var r,i;if(null!=(r=this.encoders[n])&&null!=(i=r(t,e)))return new c(n,i)}return t instanceof c?t:null},t.prototype.decode=function(t,e,n){var r=e<0?this.builtInDecoders[-1-e]:this.decoders[e];return r?r(t,e,n):new c(e,t)},t.defaultCodec=new t,t}();function B(t){return t instanceof Uint8Array?t:ArrayBuffer.isView(t)?new Uint8Array(t.buffer,t.byteOffset,t.byteLength):function(t){return t instanceof ArrayBuffer||"undefined"!=typeof SharedArrayBuffer&&t instanceof SharedArrayBuffer}(t)?new Uint8Array(t):Uint8Array.from(t)}var I=function(t){var e="function"==typeof Symbol&&Symbol.iterator,n=e&&t[e],r=0;if(n)return n.call(t);if(t&&"number"==typeof t.length)return{next:function(){return t&&r>=t.length&&(t=void 0),{value:t&&t[r++],done:!t}}};throw new TypeError(e?"Object is not iterable.":"Symbol.iterator is not defined.")},E=function(){function t(t){var e,n,r,i,o,s,a,c;this.extensionCodec=null!==(e=null==t?void 0:t.extensionCodec)&&void 0!==e?e:S.defaultCodec,this.context=null==t?void 0:t.context,this.useBigInt64=null!==(n=null==t?void 0:t.useBigInt64)&&void 0!==n&&n,this.maxDepth=null!==(r=null==t?void 0:t.maxDepth)&&void 0!==r?r:100,this.initialBufferSize=null!==(i=null==t?void 0:t.initialBufferSize)&&void 0!==i?i:2048,this.sortKeys=null!==(o=null==t?void 0:t.sortKeys)&&void 0!==o&&o,this.forceFloat32=null!==(s=null==t?void 0:t.forceFloat32)&&void 0!==s&&s,this.ignoreUndefined=null!==(a=null==t?void 0:t.ignoreUndefined)&&void 0!==a&&a,this.forceIntegerToFloat=null!==(c=null==t?void 0:t.forceIntegerToFloat)&&void 0!==c&&c,this.pos=0,this.view=new DataView(new ArrayBuffer(this.initialBufferSize)),this.bytes=new Uint8Array(this.view.buffer)}return t.prototype.reinitializeState=function(){this.pos=0},t.prototype.encodeSharedRef=function(t){return this.reinitializeState(),this.doEncode(t,1),this.bytes.subarray(0,this.pos)},t.prototype.encode=function(t){return this.reinitializeState(),this.doEncode(t,1),this.bytes.slice(0,this.pos)},t.prototype.doEncode=function(t,e){if(e>this.maxDepth)throw new Error("Too deep objects in depth ".concat(e));null==t?this.encodeNil():"boolean"==typeof t?this.encodeBoolean(t):"number"==typeof t?this.forceIntegerToFloat?this.encodeNumberAsFloat(t):this.encodeNumber(t):"string"==typeof t?this.encodeString(t):this.useBigInt64&&"bigint"==typeof t?this.encodeBigInt64(t):this.encodeObject(t,e)},t.prototype.ensureBufferSizeToWrite=function(t){var e=this.pos+t;this.view.byteLength<e&&this.resizeBuffer(2*e)},t.prototype.resizeBuffer=function(t){var e=new ArrayBuffer(t),n=new Uint8Array(e),r=new DataView(e);n.set(this.bytes),this.view=r,this.bytes=n},t.prototype.encodeNil=function(){this.writeU8(192)},t.prototype.encodeBoolean=function(t){!1===t?this.writeU8(194):this.writeU8(195)},t.prototype.encodeNumber=function(t){!this.forceIntegerToFloat&&Number.isSafeInteger(t)?t>=0?t<128?this.writeU8(t):t<256?(this.writeU8(204),this.writeU8(t)):t<65536?(this.writeU8(205),this.writeU16(t)):t<4294967296?(this.writeU8(206),this.writeU32(t)):this.useBigInt64?this.encodeNumberAsFloat(t):(this.writeU8(207),this.writeU64(t)):t>=-32?this.writeU8(224|t+32):t>=-128?(this.writeU8(208),this.writeI8(t)):t>=-32768?(this.writeU8(209),this.writeI16(t)):t>=-2147483648?(this.writeU8(210),this.writeI32(t)):this.useBigInt64?this.encodeNumberAsFloat(t):(this.writeU8(211),this.writeI64(t)):this.encodeNumberAsFloat(t)},t.prototype.encodeNumberAsFloat=function(t){this.forceFloat32?(this.writeU8(202),this.writeF32(t)):(this.writeU8(203),this.writeF64(t))},t.prototype.encodeBigInt64=function(t){t>=BigInt(0)?(this.writeU8(207),this.writeBigUint64(t)):(this.writeU8(211),this.writeBigInt64(t))},t.prototype.writeStringHeader=function(t){if(t<32)this.writeU8(160+t);else if(t<256)this.writeU8(217),this.writeU8(t);else if(t<65536)this.writeU8(218),this.writeU16(t);else{if(!(t<4294967296))throw new Error("Too long string: ".concat(t," bytes in UTF-8"));this.writeU8(219),this.writeU32(t)}},t.prototype.encodeString=function(t){var e,n,r,o=function(t){for(var e=t.length,n=0,r=0;r<e;){var i=t.charCodeAt(r++);if(4294967168&i)if(4294965248&i){if(i>=55296&&i<=56319&&r<e){var o=t.charCodeAt(r);56320==(64512&o)&&(++r,i=((1023&i)<<10)+(1023&o)+65536)}n+=4294901760&i?4:3}else n+=2;else n++}return n}(t);this.ensureBufferSizeToWrite(5+o),this.writeStringHeader(o),e=t,n=this.bytes,r=this.pos,e.length>50?function(t,e,n){i.encodeInto(t,e.subarray(n))}(e,n,r):function(t,e,n){for(var r=t.length,i=n,o=0;o<r;){var s=t.charCodeAt(o++);if(4294967168&s){if(4294965248&s){if(s>=55296&&s<=56319&&o<r){var a=t.charCodeAt(o);56320==(64512&a)&&(++o,s=((1023&s)<<10)+(1023&a)+65536)}4294901760&s?(e[i++]=s>>18&7|240,e[i++]=s>>12&63|128,e[i++]=s>>6&63|128):(e[i++]=s>>12&15|224,e[i++]=s>>6&63|128)}else e[i++]=s>>6&31|192;e[i++]=63&s|128}else e[i++]=s}}(e,n,r),this.pos+=o},t.prototype.encodeObject=function(t,e){var n=this.extensionCodec.tryToEncode(t,this.context);if(null!=n)this.encodeExtension(n);else if(Array.isArray(t))this.encodeArray(t,e);else if(ArrayBuffer.isView(t))this.encodeBinary(t);else{if("object"!=typeof t)throw new Error("Unrecognized object: ".concat(Object.prototype.toString.apply(t)));this.encodeMap(t,e)}},t.prototype.encodeBinary=function(t){var e=t.byteLength;if(e<256)this.writeU8(196),this.writeU8(e);else if(e<65536)this.writeU8(197),this.writeU16(e);else{if(!(e<4294967296))throw new Error("Too large binary: ".concat(e));this.writeU8(198),this.writeU32(e)}var n=B(t);this.writeU8a(n)},t.prototype.encodeArray=function(t,e){var n,r,i=t.length;if(i<16)this.writeU8(144+i);else if(i<65536)this.writeU8(220),this.writeU16(i);else{if(!(i<4294967296))throw new Error("Too large array: ".concat(i));this.writeU8(221),this.writeU32(i)}try{for(var o=I(t),s=o.next();!s.done;s=o.next()){var a=s.value;this.doEncode(a,e+1)}}catch(t){n={error:t}}finally{try{s&&!s.done&&(r=o.return)&&r.call(o)}finally{if(n)throw n.error}}},t.prototype.countWithoutUndefined=function(t,e){var n,r,i=0;try{for(var o=I(e),s=o.next();!s.done;s=o.next())void 0!==t[s.value]&&i++}catch(t){n={error:t}}finally{try{s&&!s.done&&(r=o.return)&&r.call(o)}finally{if(n)throw n.error}}return i},t.prototype.encodeMap=function(t,e){var n,r,i=Object.keys(t);this.sortKeys&&i.sort();var o=this.ignoreUndefined?this.countWithoutUndefined(t,i):i.length;if(o<16)this.writeU8(128+o);else if(o<65536)this.writeU8(222),this.writeU16(o);else{if(!(o<4294967296))throw new Error("Too large map object: ".concat(o));this.writeU8(223),this.writeU32(o)}try{for(var s=I(i),a=s.next();!a.done;a=s.next()){var c=a.value,u=t[c];this.ignoreUndefined&&void 0===u||(this.encodeString(c),this.doEncode(u,e+1))}}catch(t){n={error:t}}finally{try{a&&!a.done&&(r=s.return)&&r.call(s)}finally{if(n)throw n.error}}},t.prototype.encodeExtension=function(t){if("function"==typeof t.data){var e=t.data(this.pos+6),n=e.length;if(n>=4294967296)throw new Error("Too large extension object: ".concat(n));return this.writeU8(201),this.writeU32(n),this.writeI8(t.type),void this.writeU8a(e)}var r=t.data.length;if(1===r)this.writeU8(212);else if(2===r)this.writeU8(213);else if(4===r)this.writeU8(214);else if(8===r)this.writeU8(215);else if(16===r)this.writeU8(216);else if(r<256)this.writeU8(199),this.writeU8(r);else if(r<65536)this.writeU8(200),this.writeU16(r);else{if(!(r<4294967296))throw new Error("Too large extension object: ".concat(r));this.writeU8(201),this.writeU32(r)}this.writeI8(t.type),this.writeU8a(t.data)},t.prototype.writeU8=function(t){this.ensureBufferSizeToWrite(1),this.view.setUint8(this.pos,t),this.pos++},t.prototype.writeU8a=function(t){var e=t.length;this.ensureBufferSizeToWrite(e),this.bytes.set(t,this.pos),this.pos+=e},t.prototype.writeI8=function(t){this.ensureBufferSizeToWrite(1),this.view.setInt8(this.pos,t),this.pos++},t.prototype.writeU16=function(t){this.ensureBufferSizeToWrite(2),this.view.setUint16(this.pos,t),this.pos+=2},t.prototype.writeI16=function(t){this.ensureBufferSizeToWrite(2),this.view.setInt16(this.pos,t),this.pos+=2},t.prototype.writeU32=function(t){this.ensureBufferSizeToWrite(4),this.view.setUint32(this.pos,t),this.pos+=4},t.prototype.writeI32=function(t){this.ensureBufferSizeToWrite(4),this.view.setInt32(this.pos,t),this.pos+=4},t.prototype.writeF32=function(t){this.ensureBufferSizeToWrite(4),this.view.setFloat32(this.pos,t),this.pos+=4},t.prototype.writeF64=function(t){this.ensureBufferSizeToWrite(8),this.view.setFloat64(this.pos,t),this.pos+=8},t.prototype.writeU64=function(t){this.ensureBufferSizeToWrite(8),function(t,e,n){var r=n/4294967296,i=n;t.setUint32(e,r),t.setUint32(e+4,i)}(this.view,this.pos,t),this.pos+=8},t.prototype.writeI64=function(t){this.ensureBufferSizeToWrite(8),l(this.view,this.pos,t),this.pos+=8},t.prototype.writeBigUint64=function(t){this.ensureBufferSizeToWrite(8),this.view.setBigUint64(this.pos,t),this.pos+=8},t.prototype.writeBigInt64=function(t){this.ensureBufferSizeToWrite(8),this.view.setBigInt64(this.pos,t),this.pos+=8},t}();function A(t,e){return new E(e).encodeSharedRef(t)}function k(t){return"".concat(t<0?"-":"","0x").concat(Math.abs(t).toString(16).padStart(2,"0"))}var T=function(){function t(t,e){void 0===t&&(t=16),void 0===e&&(e=16),this.hit=0,this.miss=0,this.maxKeyLength=t,this.maxLengthPerKey=e,this.caches=[];for(var n=0;n<this.maxKeyLength;n++)this.caches.push([])}return t.prototype.canBeCached=function(t){return t>0&&t<=this.maxKeyLength},t.prototype.find=function(t,e,n){var r,i,o=this.caches[n-1];try{t:for(var s=function(t){var e="function"==typeof Symbol&&Symbol.iterator,n=e&&t[e],r=0;if(n)return n.call(t);if(t&&"number"==typeof t.length)return{next:function(){return t&&r>=t.length&&(t=void 0),{value:t&&t[r++],done:!t}}};throw new TypeError(e?"Object is not iterable.":"Symbol.iterator is not defined.")}(o),a=s.next();!a.done;a=s.next()){for(var c=a.value,u=c.bytes,h=0;h<n;h++)if(u[h]!==t[e+h])continue t;return c.str}}catch(t){r={error:t}}finally{try{a&&!a.done&&(i=s.return)&&i.call(s)}finally{if(r)throw r.error}}return null},t.prototype.store=function(t,e){var n=this.caches[t.length-1],r={bytes:t,str:e};n.length>=this.maxLengthPerKey?n[Math.random()*n.length|0]=r:n.push(r)},t.prototype.decode=function(t,e,n){var r=this.find(t,e,n);if(null!=r)return this.hit++,r;this.miss++;var i=o(t,e,n),s=Uint8Array.prototype.slice.call(t,e,e+n);return this.store(s,i),i},t}(),P=function(t,e){var n,r,i,o={label:0,sent:function(){if(1&i[0])throw i[1];return i[1]},trys:[],ops:[]},s=Object.create(("function"==typeof Iterator?Iterator:Object).prototype);return s.next=a(0),s.throw=a(1),s.return=a(2),"function"==typeof Symbol&&(s[Symbol.iterator]=function(){return this}),s;function a(a){return function(c){return function(a){if(n)throw new TypeError("Generator is already executing.");for(;s&&(s=0,a[0]&&(o=0)),o;)try{if(n=1,r&&(i=2&a[0]?r.return:a[0]?r.throw||((i=r.return)&&i.call(r),0):r.next)&&!(i=i.call(r,a[1])).done)return i;switch(r=0,i&&(a=[2&a[0],i.value]),a[0]){case 0:case 1:i=a;break;case 4:return o.label++,{value:a[1],done:!1};case 5:o.label++,r=a[1],a=[0];continue;case 7:a=o.ops.pop(),o.trys.pop();continue;default:if(!((i=(i=o.trys).length>0&&i[i.length-1])||6!==a[0]&&2!==a[0])){o=0;continue}if(3===a[0]&&(!i||a[1]>i[0]&&a[1]<i[3])){o.label=a[1];break}if(6===a[0]&&o.label<i[1]){o.label=i[1],i=a;break}if(i&&o.label<i[2]){o.label=i[2],o.ops.push(a);break}i[2]&&o.ops.pop(),o.trys.pop();continue}a=e.call(t,o)}catch(t){a=[6,t],r=0}finally{n=i=0}if(5&a[0])throw a[1];return{value:a[0]?a[1]:void 0,done:!0}}([a,c])}}},z=function(t){if(!Symbol.asyncIterator)throw new TypeError("Symbol.asyncIterator is not defined.");var e,n=t[Symbol.asyncIterator];return n?n.call(t):(t="function"==typeof __values?__values(t):t[Symbol.iterator](),e={},r("next"),r("throw"),r("return"),e[Symbol.asyncIterator]=function(){return this},e);function r(n){e[n]=t[n]&&function(e){return new Promise((function(r,i){!function(t,e,n,r){Promise.resolve(r).then((function(e){t({value:e,done:n})}),e)}(r,i,(e=t[n](e)).done,e.value)}))}}},L=function(t){return this instanceof L?(this.v=t,this):new L(t)},M="array",j="map_key",O="map_value",D=function(){function t(){this.stack=[],this.stackHeadPosition=-1}return Object.defineProperty(t.prototype,"length",{get:function(){return this.stackHeadPosition+1},enumerable:!1,configurable:!0}),t.prototype.top=function(){return this.stack[this.stackHeadPosition]},t.prototype.pushArrayState=function(t){var e=this.getUninitializedStateFromPool();e.type=M,e.position=0,e.size=t,e.array=new Array(t)},t.prototype.pushMapState=function(t){var e=this.getUninitializedStateFromPool();e.type=j,e.readCount=0,e.size=t,e.map={}},t.prototype.getUninitializedStateFromPool=function(){if(this.stackHeadPosition++,this.stackHeadPosition===this.stack.length){this.stack.push({type:void 0,size:0,array:void 0,position:0,readCount:0,map:void 0,key:null})}return this.stack[this.stackHeadPosition]},t.prototype.release=function(t){var e;if(this.stack[this.stackHeadPosition]!==t)throw new Error("Invalid stack state. Released state is not on top of the stack.");t.type===M&&((e=t).size=0,e.array=void 0,e.position=0,e.type=void 0),t.type!==j&&t.type!==O||((e=t).size=0,e.map=void 0,e.readCount=0,e.type=void 0),this.stackHeadPosition--},t.prototype.reset=function(){this.stack.length=0,this.stackHeadPosition=-1},t}(),F=new DataView(new ArrayBuffer(0)),C=new Uint8Array(F.buffer);try{F.getInt8(0)}catch(t){if(!(t instanceof RangeError))throw new Error("This module is not supported in the current JavaScript engine because DataView does not throw RangeError on out-of-bounds access")}var _=RangeError,W=new _("Insufficient data"),R=new T,H=function(){function t(t){var e,n,r,i,o,s,a,c;this.totalPos=0,this.pos=0,this.view=F,this.bytes=C,this.headByte=-1,this.stack=new D,this.extensionCodec=null!==(e=null==t?void 0:t.extensionCodec)&&void 0!==e?e:S.defaultCodec,this.context=null==t?void 0:t.context,this.useBigInt64=null!==(n=null==t?void 0:t.useBigInt64)&&void 0!==n&&n,this.rawStrings=null!==(r=null==t?void 0:t.rawStrings)&&void 0!==r&&r,this.maxStrLength=null!==(i=null==t?void 0:t.maxStrLength)&&void 0!==i?i:f,this.maxBinLength=null!==(o=null==t?void 0:t.maxBinLength)&&void 0!==o?o:f,this.maxArrayLength=null!==(s=null==t?void 0:t.maxArrayLength)&&void 0!==s?s:f,this.maxMapLength=null!==(a=null==t?void 0:t.maxMapLength)&&void 0!==a?a:f,this.maxExtLength=null!==(c=null==t?void 0:t.maxExtLength)&&void 0!==c?c:f,this.keyDecoder=void 0!==(null==t?void 0:t.keyDecoder)?t.keyDecoder:R}return t.prototype.reinitializeState=function(){this.totalPos=0,this.headByte=-1,this.stack.reset()},t.prototype.setBuffer=function(t){this.bytes=B(t),this.view=function(t){if(t instanceof ArrayBuffer)return new DataView(t);var e=B(t);return new DataView(e.buffer,e.byteOffset,e.byteLength)}(this.bytes),this.pos=0},t.prototype.appendBuffer=function(t){if(-1!==this.headByte||this.hasRemaining(1)){var e=this.bytes.subarray(this.pos),n=B(t),r=new Uint8Array(e.length+n.length);r.set(e),r.set(n,e.length),this.setBuffer(r)}else this.setBuffer(t)},t.prototype.hasRemaining=function(t){return this.view.byteLength-this.pos>=t},t.prototype.createExtraByteError=function(t){var e=this.view,n=this.pos;return new RangeError("Extra ".concat(e.byteLength-n," of ").concat(e.byteLength," byte(s) found at buffer[").concat(t,"]"))},t.prototype.decode=function(t){this.reinitializeState(),this.setBuffer(t);var e=this.doDecodeSync();if(this.hasRemaining(1))throw this.createExtraByteError(this.pos);return e},t.prototype.decodeMulti=function(t){return P(this,(function(e){switch(e.label){case 0:this.reinitializeState(),this.setBuffer(t),e.label=1;case 1:return this.hasRemaining(1)?[4,this.doDecodeSync()]:[3,3];case 2:return e.sent(),[3,1];case 3:return[2]}}))},t.prototype.decodeAsync=function(t){return e=this,n=void 0,i=function(){var e,n,r,i,o,s,a,c,u,h,f,l,p,d,y;return P(this,(function(w){switch(w.label){case 0:e=!1,w.label=1;case 1:w.trys.push([1,6,7,12]),u=!0,h=z(t),w.label=2;case 2:return[4,h.next()];case 3:if(f=w.sent(),l=f.done)return[3,5];if(y=f.value,u=!1,r=y,e)throw this.createExtraByteError(this.totalPos);this.appendBuffer(r);try{n=this.doDecodeSync(),e=!0}catch(t){if(!(t instanceof _))throw t}this.totalPos+=this.pos,w.label=4;case 4:return u=!0,[3,2];case 5:return[3,12];case 6:return i=w.sent(),p={error:i},[3,12];case 7:return w.trys.push([7,,10,11]),u||l||!(d=h.return)?[3,9]:[4,d.call(h)];case 8:w.sent(),w.label=9;case 9:return[3,11];case 10:if(p)throw p.error;return[7];case 11:return[7];case 12:if(e){if(this.hasRemaining(1))throw this.createExtraByteError(this.totalPos);return[2,n]}throw s=(o=this).headByte,a=o.pos,c=o.totalPos,new RangeError("Insufficient data in parsing ".concat(k(s)," at ").concat(c," (").concat(a," in the current buffer)"))}}))},new((r=void 0)||(r=Promise))((function(t,o){function s(t){try{c(i.next(t))}catch(t){o(t)}}function a(t){try{c(i.throw(t))}catch(t){o(t)}}function c(e){var n;e.done?t(e.value):(n=e.value,n instanceof r?n:new r((function(t){t(n)}))).then(s,a)}c((i=i.apply(e,n||[])).next())}));var e,n,r,i},t.prototype.decodeArrayStream=function(t){return this.decodeMultiAsync(t,!0)},t.prototype.decodeStream=function(t){return this.decodeMultiAsync(t,!1)},t.prototype.decodeMultiAsync=function(t,e){return function(t,e,n){if(!Symbol.asyncIterator)throw new TypeError("Symbol.asyncIterator is not defined.");var r,i=n.apply(t,e||[]),o=[];return r=Object.create(("function"==typeof AsyncIterator?AsyncIterator:Object).prototype),s("next"),s("throw"),s("return",(function(t){return function(e){return Promise.resolve(e).then(t,u)}})),r[Symbol.asyncIterator]=function(){return this},r;function s(t,e){i[t]&&(r[t]=function(e){return new Promise((function(n,r){o.push([t,e,n,r])>1||a(t,e)}))},e&&(r[t]=e(r[t])))}function a(t,e){try{(n=i[t](e)).value instanceof L?Promise.resolve(n.value.v).then(c,u):h(o[0][2],n)}catch(t){h(o[0][3],t)}var n}function c(t){a("next",t)}function u(t){a("throw",t)}function h(t,e){t(e),o.shift(),o.length&&a(o[0][0],o[0][1])}}(this,arguments,(function(){var n,r,i,o,s,a,c,u,h,f,l,p;return P(this,(function(d){switch(d.label){case 0:n=e,r=-1,d.label=1;case 1:d.trys.push([1,13,14,19]),i=!0,o=z(t),d.label=2;case 2:return[4,L(o.next())];case 3:if(s=d.sent(),h=s.done)return[3,12];if(p=s.value,i=!1,a=p,e&&0===r)throw this.createExtraByteError(this.totalPos);this.appendBuffer(a),n&&(r=this.readArraySize(),n=!1,this.complete()),d.label=4;case 4:d.trys.push([4,9,,10]),d.label=5;case 5:return[4,L(this.doDecodeSync())];case 6:return[4,d.sent()];case 7:return d.sent(),0==--r?[3,8]:[3,5];case 8:return[3,10];case 9:if(!((c=d.sent())instanceof _))throw c;return[3,10];case 10:this.totalPos+=this.pos,d.label=11;case 11:return i=!0,[3,2];case 12:return[3,19];case 13:return u=d.sent(),f={error:u},[3,19];case 14:return d.trys.push([14,,17,18]),i||h||!(l=o.return)?[3,16]:[4,L(l.call(o))];case 15:d.sent(),d.label=16;case 16:return[3,18];case 17:if(f)throw f.error;return[7];case 18:return[7];case 19:return[2]}}))}))},t.prototype.doDecodeSync=function(){t:for(;;){var t=this.readHeadByte(),e=void 0;if(t>=224)e=t-256;else if(t<192)if(t<128)e=t;else if(t<144){if(0!=(r=t-128)){this.pushMapState(r),this.complete();continue t}e={}}else if(t<160){if(0!=(r=t-144)){this.pushArrayState(r),this.complete();continue t}e=[]}else{var n=t-160;e=this.decodeString(n,0)}else if(192===t)e=null;else if(194===t)e=!1;else if(195===t)e=!0;else if(202===t)e=this.readF32();else if(203===t)e=this.readF64();else if(204===t)e=this.readU8();else if(205===t)e=this.readU16();else if(206===t)e=this.readU32();else if(207===t)e=this.useBigInt64?this.readU64AsBigInt():this.readU64();else if(208===t)e=this.readI8();else if(209===t)e=this.readI16();else if(210===t)e=this.readI32();else if(211===t)e=this.useBigInt64?this.readI64AsBigInt():this.readI64();else if(217===t)n=this.lookU8(),e=this.decodeString(n,1);else if(218===t)n=this.lookU16(),e=this.decodeString(n,2);else if(219===t)n=this.lookU32(),e=this.decodeString(n,4);else if(220===t){if(0!==(r=this.readU16())){this.pushArrayState(r),this.complete();continue t}e=[]}else if(221===t){if(0!==(r=this.readU32())){this.pushArrayState(r),this.complete();continue t}e=[]}else if(222===t){if(0!==(r=this.readU16())){this.pushMapState(r),this.complete();continue t}e={}}else if(223===t){if(0!==(r=this.readU32())){this.pushMapState(r),this.complete();continue t}e={}}else if(196===t){var r=this.lookU8();e=this.decodeBinary(r,1)}else if(197===t)r=this.lookU16(),e=this.decodeBinary(r,2);else if(198===t)r=this.lookU32(),e=this.decodeBinary(r,4);else if(212===t)e=this.decodeExtension(1,0);else if(213===t)e=this.decodeExtension(2,0);else if(214===t)e=this.decodeExtension(4,0);else if(215===t)e=this.decodeExtension(8,0);else if(216===t)e=this.decodeExtension(16,0);else if(199===t)r=this.lookU8(),e=this.decodeExtension(r,1);else if(200===t)r=this.lookU16(),e=this.decodeExtension(r,2);else{if(201!==t)throw new h("Unrecognized type byte: ".concat(k(t)));r=this.lookU32(),e=this.decodeExtension(r,4)}this.complete();for(var i=this.stack;i.length>0;){var o=i.top();if(o.type===M){if(o.array[o.position]=e,o.position++,o.position!==o.size)continue t;e=o.array,i.release(o)}else{if(o.type===j){if("string"!=typeof(s=e)&&"number"!=typeof s)throw new h("The type of key must be string or number but "+typeof e);if("__proto__"===e)throw new h("The key __proto__ is not allowed");o.key=e,o.type=O;continue t}if(o.map[o.key]=e,o.readCount++,o.readCount!==o.size){o.key=null,o.type=j;continue t}e=o.map,i.release(o)}}return e}var s},t.prototype.readHeadByte=function(){return-1===this.headByte&&(this.headByte=this.readU8()),this.headByte},t.prototype.complete=function(){this.headByte=-1},t.prototype.readArraySize=function(){var t=this.readHeadByte();switch(t){case 220:return this.readU16();case 221:return this.readU32();default:if(t<160)return t-144;throw new h("Unrecognized array type byte: ".concat(k(t)))}},t.prototype.pushMapState=function(t){if(t>this.maxMapLength)throw new h("Max length exceeded: map length (".concat(t,") > maxMapLengthLength (").concat(this.maxMapLength,")"));this.stack.pushMapState(t)},t.prototype.pushArrayState=function(t){if(t>this.maxArrayLength)throw new h("Max length exceeded: array length (".concat(t,") > maxArrayLength (").concat(this.maxArrayLength,")"));this.stack.pushArrayState(t)},t.prototype.decodeString=function(t,e){return!this.rawStrings||this.stateIsMapKey()?this.decodeUtf8String(t,e):this.decodeBinary(t,e)},t.prototype.decodeUtf8String=function(t,e){var n;if(t>this.maxStrLength)throw new h("Max length exceeded: UTF-8 byte length (".concat(t,") > maxStrLength (").concat(this.maxStrLength,")"));if(this.bytes.byteLength<this.pos+e+t)throw W;var r,i=this.pos+e;return r=this.stateIsMapKey()&&(null===(n=this.keyDecoder)||void 0===n?void 0:n.canBeCached(t))?this.keyDecoder.decode(this.bytes,i,t):function(t,e,n){return n>200?function(t,e,n){var r=t.subarray(e,e+n);return s.decode(r)}(t,e,n):o(t,e,n)}(this.bytes,i,t),this.pos+=e+t,r},t.prototype.stateIsMapKey=function(){return this.stack.length>0&&this.stack.top().type===j},t.prototype.decodeBinary=function(t,e){if(t>this.maxBinLength)throw new h("Max length exceeded: bin length (".concat(t,") > maxBinLength (").concat(this.maxBinLength,")"));if(!this.hasRemaining(t+e))throw W;var n=this.pos+e,r=this.bytes.subarray(n,n+t);return this.pos+=e+t,r},t.prototype.decodeExtension=function(t,e){if(t>this.maxExtLength)throw new h("Max length exceeded: ext length (".concat(t,") > maxExtLength (").concat(this.maxExtLength,")"));var n=this.view.getInt8(this.pos+e),r=this.decodeBinary(t,e+1);return this.extensionCodec.decode(r,n,this.context)},t.prototype.lookU8=function(){return this.view.getUint8(this.pos)},t.prototype.lookU16=function(){return this.view.getUint16(this.pos)},t.prototype.lookU32=function(){return this.view.getUint32(this.pos)},t.prototype.readU8=function(){var t=this.view.getUint8(this.pos);return this.pos++,t},t.prototype.readI8=function(){var t=this.view.getInt8(this.pos);return this.pos++,t},t.prototype.readU16=function(){var t=this.view.getUint16(this.pos);return this.pos+=2,t},t.prototype.readI16=function(){var t=this.view.getInt16(this.pos);return this.pos+=2,t},t.prototype.readU32=function(){var t=this.view.getUint32(this.pos);return this.pos+=4,t},t.prototype.readI32=function(){var t=this.view.getInt32(this.pos);return this.pos+=4,t},t.prototype.readU64=function(){var t,e,n=(t=this.view,e=this.pos,4294967296*t.getUint32(e)+t.getUint32(e+4));return this.pos+=8,n},t.prototype.readI64=function(){var t=p(this.view,this.pos);return this.pos+=8,t},t.prototype.readU64AsBigInt=function(){var t=this.view.getBigUint64(this.pos);return this.pos+=8,t},t.prototype.readI64AsBigInt=function(){var t=this.view.getBigInt64(this.pos);return this.pos+=8,t},t.prototype.readF32=function(){var t=this.view.getFloat32(this.pos);return this.pos+=4,t},t.prototype.readF64=function(){var t=this.view.getFloat64(this.pos);return this.pos+=8,t},t}();function V(t,e){return new H(e).decode(t)}function K(t,e){return new H(e).decodeMulti(t)}var N=function(t,e){var n,r,i,o={label:0,sent:function(){if(1&i[0])throw i[1];return i[1]},trys:[],ops:[]},s=Object.create(("function"==typeof Iterator?Iterator:Object).prototype);return s.next=a(0),s.throw=a(1),s.return=a(2),"function"==typeof Symbol&&(s[Symbol.iterator]=function(){return this}),s;function a(a){return function(c){return function(a){if(n)throw new TypeError("Generator is already executing.");for(;s&&(s=0,a[0]&&(o=0)),o;)try{if(n=1,r&&(i=2&a[0]?r.return:a[0]?r.throw||((i=r.return)&&i.call(r),0):r.next)&&!(i=i.call(r,a[1])).done)return i;switch(r=0,i&&(a=[2&a[0],i.value]),a[0]){case 0:case 1:i=a;break;case 4:return o.label++,{value:a[1],done:!1};case 5:o.label++,r=a[1],a=[0];continue;case 7:a=o.ops.pop(),o.trys.pop();continue;default:if(!((i=(i=o.trys).length>0&&i[i.length-1])||6!==a[0]&&2!==a[0])){o=0;continue}if(3===a[0]&&(!i||a[1]>i[0]&&a[1]<i[3])){o.label=a[1];break}if(6===a[0]&&o.label<i[1]){o.label=i[1],i=a;break}if(i&&o.label<i[2]){o.label=i[2],o.ops.push(a);break}i[2]&&o.ops.pop(),o.trys.pop();continue}a=e.call(t,o)}catch(t){a=[6,t],r=0}finally{n=i=0}if(5&a[0])throw a[1];return{value:a[0]?a[1]:void 0,done:!0}}([a,c])}}},G=function(t){return this instanceof G?(this.v=t,this):new G(t)},J=function(t,e,n){if(!Symbol.asyncIterator)throw new TypeError("Symbol.asyncIterator is not defined.");var r,i=n.apply(t,e||[]),o=[];return r=Object.create(("function"==typeof AsyncIterator?AsyncIterator:Object).prototype),s("next"),s("throw"),s("return",(function(t){return function(e){return Promise.resolve(e).then(t,u)}})),r[Symbol.asyncIterator]=function(){return this},r;function s(t,e){i[t]&&(r[t]=function(e){return new Promise((function(n,r){o.push([t,e,n,r])>1||a(t,e)}))},e&&(r[t]=e(r[t])))}function a(t,e){try{(n=i[t](e)).value instanceof G?Promise.resolve(n.value.v).then(c,u):h(o[0][2],n)}catch(t){h(o[0][3],t)}var n}function c(t){a("next",t)}function u(t){a("throw",t)}function h(t,e){t(e),o.shift(),o.length&&a(o[0][0],o[0][1])}};function X(t){return null!=t[Symbol.asyncIterator]?t:function(t){return J(this,arguments,(function(){var e,n,r,i;return N(this,(function(o){switch(o.label){case 0:e=t.getReader(),o.label=1;case 1:o.trys.push([1,,9,10]),o.label=2;case 2:return[4,G(e.read())];case 3:return n=o.sent(),r=n.done,i=n.value,r?[4,G(void 0)]:[3,5];case 4:return[2,o.sent()];case 5:return function(t){if(null==t)throw new Error("Assertion Failure: value must not be null nor undefined")}(i),[4,G(i)];case 6:return[4,o.sent()];case 7:return o.sent(),[3,2];case 8:return[3,10];case 9:return e.releaseLock(),[7];case 10:return[2]}}))}))}(t)}var q=function(t,e,n,r){return new(n||(n=Promise))((function(i,o){function s(t){try{c(r.next(t))}catch(t){o(t)}}function a(t){try{c(r.throw(t))}catch(t){o(t)}}function c(t){var e;t.done?i(t.value):(e=t.value,e instanceof n?e:new n((function(t){t(e)}))).then(s,a)}c((r=r.apply(t,e||[])).next())}))},Q=function(t,e){var n,r,i,o={label:0,sent:function(){if(1&i[0])throw i[1];return i[1]},trys:[],ops:[]},s=Object.create(("function"==typeof Iterator?Iterator:Object).prototype);return s.next=a(0),s.throw=a(1),s.return=a(2),"function"==typeof Symbol&&(s[Symbol.iterator]=function(){return this}),s;function a(a){return function(c){return function(a){if(n)throw new TypeError("Generator is already executing.");for(;s&&(s=0,a[0]&&(o=0)),o;)try{if(n=1,r&&(i=2&a[0]?r.return:a[0]?r.throw||((i=r.return)&&i.call(r),0):r.next)&&!(i=i.call(r,a[1])).done)return i;switch(r=0,i&&(a=[2&a[0],i.value]),a[0]){case 0:case 1:i=a;break;case 4:return o.label++,{value:a[1],done:!1};case 5:o.label++,r=a[1],a=[0];continue;case 7:a=o.ops.pop(),o.trys.pop();continue;default:if(!((i=(i=o.trys).length>0&&i[i.length-1])||6!==a[0]&&2!==a[0])){o=0;continue}if(3===a[0]&&(!i||a[1]>i[0]&&a[1]<i[3])){o.label=a[1];break}if(6===a[0]&&o.label<i[1]){o.label=i[1],i=a;break}if(i&&o.label<i[2]){o.label=i[2],o.ops.push(a);break}i[2]&&o.ops.pop(),o.trys.pop();continue}a=e.call(t,o)}catch(t){a=[6,t],r=0}finally{n=i=0}if(5&a[0])throw a[1];return{value:a[0]?a[1]:void 0,done:!0}}([a,c])}}};function Y(t,e){return q(this,void 0,void 0,(function(){var n;return Q(this,(function(r){return n=X(t),[2,new H(e).decodeAsync(n)]}))}))}function Z(t,e){var n=X(t);return new H(e).decodeArrayStream(n)}function $(t,e){var n=X(t);return new H(e).decodeStream(n)}return e}()})); | ||
!function(t,e){"object"==typeof exports&&"object"==typeof module?module.exports=e():"function"==typeof define&&define.amd?define([],e):"object"==typeof exports?exports.MessagePack=e():t.MessagePack=e()}(this,(function(){return function(){"use strict";var t={d:function(e,r){for(var n in r)t.o(r,n)&&!t.o(e,n)&&Object.defineProperty(e,n,{enumerable:!0,get:r[n]})},o:function(t,e){return Object.prototype.hasOwnProperty.call(t,e)},r:function(t){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"__esModule",{value:!0})}},e={};t.r(e),t.d(e,{DecodeError:function(){return h},Decoder:function(){return J},EXT_TIMESTAMP:function(){return d},Encoder:function(){return A},ExtData:function(){return c},ExtensionCodec:function(){return x},decode:function(){return X},decodeArrayStream:function(){return nt},decodeAsync:function(){return rt},decodeMulti:function(){return q},decodeMultiStream:function(){return it},decodeTimestampExtension:function(){return U},decodeTimestampToTimeSpec:function(){return m},encode:function(){return T},encodeDateToTimeSpec:function(){return g},encodeTimeSpecToTimestamp:function(){return v},encodeTimestampExtension:function(){return b}});var r=function(t,e){var r="function"==typeof Symbol&&t[Symbol.iterator];if(!r)return t;var n,i,o=r.call(t),s=[];try{for(;(void 0===e||e-- >0)&&!(n=o.next()).done;)s.push(n.value)}catch(t){i={error:t}}finally{try{n&&!n.done&&(r=o.return)&&r.call(o)}finally{if(i)throw i.error}}return s},n=function(t,e,r){if(r||2===arguments.length)for(var n,i=0,o=e.length;i<o;i++)!n&&i in e||(n||(n=Array.prototype.slice.call(e,0,i)),n[i]=e[i]);return t.concat(n||Array.prototype.slice.call(e))},i=new TextEncoder;function o(t,e,i){for(var o=e,s=o+i,a=[],c="";o<s;){var u=t[o++];if(128&u)if(192==(224&u)){var h=63&t[o++];a.push((31&u)<<6|h)}else if(224==(240&u)){h=63&t[o++];var f=63&t[o++];a.push((31&u)<<12|h<<6|f)}else if(240==(248&u)){var l=(7&u)<<18|(h=63&t[o++])<<12|(f=63&t[o++])<<6|63&t[o++];l>65535&&(l-=65536,a.push(l>>>10&1023|55296),l=56320|1023&l),a.push(l)}else a.push(u);else a.push(u);a.length>=4096&&(c+=String.fromCharCode.apply(String,n([],r(a),!1)),a.length=0)}return a.length>0&&(c+=String.fromCharCode.apply(String,n([],r(a),!1))),c}var s=new TextDecoder;var a,c=function(t,e){this.type=t,this.data=e},u=(a=function(t,e){return a=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var r in e)Object.prototype.hasOwnProperty.call(e,r)&&(t[r]=e[r])},a(t,e)},function(t,e){if("function"!=typeof e&&null!==e)throw new TypeError("Class extends value "+String(e)+" is not a constructor or null");function r(){this.constructor=t}a(t,e),t.prototype=null===e?Object.create(e):(r.prototype=e.prototype,new r)}),h=function(t){function e(r){var n=t.call(this,r)||this,i=Object.create(e.prototype);return Object.setPrototypeOf(n,i),Object.defineProperty(n,"name",{configurable:!0,enumerable:!1,value:e.name}),n}return u(e,t),e}(Error),f=4294967295;function l(t,e,r){var n=Math.floor(r/4294967296),i=r;t.setUint32(e,n),t.setUint32(e+4,i)}function p(t,e){return 4294967296*t.getInt32(e)+t.getUint32(e+4)}var d=-1,y=4294967295,w=17179869183;function v(t){var e,r=t.sec,n=t.nsec;if(r>=0&&n>=0&&r<=w){if(0===n&&r<=y){var i=new Uint8Array(4);return(e=new DataView(i.buffer)).setUint32(0,r),i}var o=r/4294967296,s=4294967295&r;return i=new Uint8Array(8),(e=new DataView(i.buffer)).setUint32(0,n<<2|3&o),e.setUint32(4,s),i}return i=new Uint8Array(12),(e=new DataView(i.buffer)).setUint32(0,n),l(e,4,r),i}function g(t){var e=t.getTime(),r=Math.floor(e/1e3),n=1e6*(e-1e3*r),i=Math.floor(n/1e9);return{sec:r+i,nsec:n-1e9*i}}function b(t){return t instanceof Date?v(g(t)):null}function m(t){var e=new DataView(t.buffer,t.byteOffset,t.byteLength);switch(t.byteLength){case 4:return{sec:e.getUint32(0),nsec:0};case 8:var r=e.getUint32(0);return{sec:4294967296*(3&r)+e.getUint32(4),nsec:r>>>2};case 12:return{sec:p(e,4),nsec:e.getUint32(0)};default:throw new h("Unrecognized data size for timestamp (expected 4, 8, or 12): ".concat(t.length))}}function U(t){var e=m(t);return new Date(1e3*e.sec+e.nsec/1e6)}var S={type:d,encode:b,decode:U},x=function(){function t(){this.builtInEncoders=[],this.builtInDecoders=[],this.encoders=[],this.decoders=[],this.register(S)}return t.prototype.register=function(t){var e=t.type,r=t.encode,n=t.decode;if(e>=0)this.encoders[e]=r,this.decoders[e]=n;else{var i=-1-e;this.builtInEncoders[i]=r,this.builtInDecoders[i]=n}},t.prototype.tryToEncode=function(t,e){for(var r=0;r<this.builtInEncoders.length;r++)if(null!=(n=this.builtInEncoders[r])&&null!=(i=n(t,e)))return new c(-1-r,i);for(r=0;r<this.encoders.length;r++){var n,i;if(null!=(n=this.encoders[r])&&null!=(i=n(t,e)))return new c(r,i)}return t instanceof c?t:null},t.prototype.decode=function(t,e,r){var n=e<0?this.builtInDecoders[-1-e]:this.decoders[e];return n?n(t,e,r):new c(e,t)},t.defaultCodec=new t,t}();function E(t){return t instanceof Uint8Array?t:ArrayBuffer.isView(t)?new Uint8Array(t.buffer,t.byteOffset,t.byteLength):function(t){return t instanceof ArrayBuffer||"undefined"!=typeof SharedArrayBuffer&&t instanceof SharedArrayBuffer}(t)?new Uint8Array(t):Uint8Array.from(t)}var B=function(t,e,r){if(null!=e){if("object"!=typeof e&&"function"!=typeof e)throw new TypeError("Object expected.");var n,i;if(r){if(!Symbol.asyncDispose)throw new TypeError("Symbol.asyncDispose is not defined.");n=e[Symbol.asyncDispose]}if(void 0===n){if(!Symbol.dispose)throw new TypeError("Symbol.dispose is not defined.");n=e[Symbol.dispose],r&&(i=n)}if("function"!=typeof n)throw new TypeError("Object not disposable.");i&&(n=function(){try{i.call(this)}catch(t){return Promise.reject(t)}}),t.stack.push({value:e,dispose:n,async:r})}else r&&t.stack.push({async:!0});return e},I=function(t){return function(e){function r(r){e.error=e.hasError?new t(r,e.error,"An error was suppressed during disposal."):r,e.hasError=!0}var n,i=0;return function t(){for(;n=e.stack.pop();)try{if(!n.async&&1===i)return i=0,e.stack.push(n),Promise.resolve().then(t);if(n.dispose){var o=n.dispose.call(n.value);if(n.async)return i|=2,Promise.resolve(o).then(t,(function(e){return r(e),t()}))}else i|=1}catch(t){r(t)}if(1===i)return e.hasError?Promise.reject(e.error):Promise.resolve();if(e.hasError)throw e.error}()}}("function"==typeof SuppressedError?SuppressedError:function(t,e,r){var n=new Error(r);return n.name="SuppressedError",n.error=t,n.suppressed=e,n}),k=function(t){var e="function"==typeof Symbol&&Symbol.iterator,r=e&&t[e],n=0;if(r)return r.call(t);if(t&&"number"==typeof t.length)return{next:function(){return t&&n>=t.length&&(t=void 0),{value:t&&t[n++],done:!t}}};throw new TypeError(e?"Object is not iterable.":"Symbol.iterator is not defined.")},A=function(){function t(t){var e,r,n,i,o,s,a,c;this.entered=!1,this.extensionCodec=null!==(e=null==t?void 0:t.extensionCodec)&&void 0!==e?e:x.defaultCodec,this.context=null==t?void 0:t.context,this.useBigInt64=null!==(r=null==t?void 0:t.useBigInt64)&&void 0!==r&&r,this.maxDepth=null!==(n=null==t?void 0:t.maxDepth)&&void 0!==n?n:100,this.initialBufferSize=null!==(i=null==t?void 0:t.initialBufferSize)&&void 0!==i?i:2048,this.sortKeys=null!==(o=null==t?void 0:t.sortKeys)&&void 0!==o&&o,this.forceFloat32=null!==(s=null==t?void 0:t.forceFloat32)&&void 0!==s&&s,this.ignoreUndefined=null!==(a=null==t?void 0:t.ignoreUndefined)&&void 0!==a&&a,this.forceIntegerToFloat=null!==(c=null==t?void 0:t.forceIntegerToFloat)&&void 0!==c&&c,this.pos=0,this.view=new DataView(new ArrayBuffer(this.initialBufferSize)),this.bytes=new Uint8Array(this.view.buffer)}return t.prototype.clone=function(){return new t({extensionCodec:this.extensionCodec,context:this.context,useBigInt64:this.useBigInt64,maxDepth:this.maxDepth,initialBufferSize:this.initialBufferSize,sortKeys:this.sortKeys,forceFloat32:this.forceFloat32,ignoreUndefined:this.ignoreUndefined,forceIntegerToFloat:this.forceIntegerToFloat})},t.prototype.reinitializeState=function(){this.pos=0},t.prototype.enteringGuard=function(){var t,e=this;return this.entered=!0,(t={})[Symbol.dispose]=function(){e.entered=!1},t},t.prototype.encodeSharedRef=function(t){var e={stack:[],error:void 0,hasError:!1};try{return this.entered?this.clone().encodeSharedRef(t):(B(e,this.enteringGuard(),!1),this.reinitializeState(),this.doEncode(t,1),this.bytes.subarray(0,this.pos))}catch(t){e.error=t,e.hasError=!0}finally{I(e)}},t.prototype.encode=function(t){var e={stack:[],error:void 0,hasError:!1};try{return this.entered?this.clone().encode(t):(B(e,this.enteringGuard(),!1),this.reinitializeState(),this.doEncode(t,1),this.bytes.slice(0,this.pos))}catch(t){e.error=t,e.hasError=!0}finally{I(e)}},t.prototype.doEncode=function(t,e){if(e>this.maxDepth)throw new Error("Too deep objects in depth ".concat(e));null==t?this.encodeNil():"boolean"==typeof t?this.encodeBoolean(t):"number"==typeof t?this.forceIntegerToFloat?this.encodeNumberAsFloat(t):this.encodeNumber(t):"string"==typeof t?this.encodeString(t):this.useBigInt64&&"bigint"==typeof t?this.encodeBigInt64(t):this.encodeObject(t,e)},t.prototype.ensureBufferSizeToWrite=function(t){var e=this.pos+t;this.view.byteLength<e&&this.resizeBuffer(2*e)},t.prototype.resizeBuffer=function(t){var e=new ArrayBuffer(t),r=new Uint8Array(e),n=new DataView(e);r.set(this.bytes),this.view=n,this.bytes=r},t.prototype.encodeNil=function(){this.writeU8(192)},t.prototype.encodeBoolean=function(t){!1===t?this.writeU8(194):this.writeU8(195)},t.prototype.encodeNumber=function(t){!this.forceIntegerToFloat&&Number.isSafeInteger(t)?t>=0?t<128?this.writeU8(t):t<256?(this.writeU8(204),this.writeU8(t)):t<65536?(this.writeU8(205),this.writeU16(t)):t<4294967296?(this.writeU8(206),this.writeU32(t)):this.useBigInt64?this.encodeNumberAsFloat(t):(this.writeU8(207),this.writeU64(t)):t>=-32?this.writeU8(224|t+32):t>=-128?(this.writeU8(208),this.writeI8(t)):t>=-32768?(this.writeU8(209),this.writeI16(t)):t>=-2147483648?(this.writeU8(210),this.writeI32(t)):this.useBigInt64?this.encodeNumberAsFloat(t):(this.writeU8(211),this.writeI64(t)):this.encodeNumberAsFloat(t)},t.prototype.encodeNumberAsFloat=function(t){this.forceFloat32?(this.writeU8(202),this.writeF32(t)):(this.writeU8(203),this.writeF64(t))},t.prototype.encodeBigInt64=function(t){t>=BigInt(0)?(this.writeU8(207),this.writeBigUint64(t)):(this.writeU8(211),this.writeBigInt64(t))},t.prototype.writeStringHeader=function(t){if(t<32)this.writeU8(160+t);else if(t<256)this.writeU8(217),this.writeU8(t);else if(t<65536)this.writeU8(218),this.writeU16(t);else{if(!(t<4294967296))throw new Error("Too long string: ".concat(t," bytes in UTF-8"));this.writeU8(219),this.writeU32(t)}},t.prototype.encodeString=function(t){var e,r,n,o=function(t){for(var e=t.length,r=0,n=0;n<e;){var i=t.charCodeAt(n++);if(4294967168&i)if(4294965248&i){if(i>=55296&&i<=56319&&n<e){var o=t.charCodeAt(n);56320==(64512&o)&&(++n,i=((1023&i)<<10)+(1023&o)+65536)}r+=4294901760&i?4:3}else r+=2;else r++}return r}(t);this.ensureBufferSizeToWrite(5+o),this.writeStringHeader(o),e=t,r=this.bytes,n=this.pos,e.length>50?function(t,e,r){i.encodeInto(t,e.subarray(r))}(e,r,n):function(t,e,r){for(var n=t.length,i=r,o=0;o<n;){var s=t.charCodeAt(o++);if(4294967168&s){if(4294965248&s){if(s>=55296&&s<=56319&&o<n){var a=t.charCodeAt(o);56320==(64512&a)&&(++o,s=((1023&s)<<10)+(1023&a)+65536)}4294901760&s?(e[i++]=s>>18&7|240,e[i++]=s>>12&63|128,e[i++]=s>>6&63|128):(e[i++]=s>>12&15|224,e[i++]=s>>6&63|128)}else e[i++]=s>>6&31|192;e[i++]=63&s|128}else e[i++]=s}}(e,r,n),this.pos+=o},t.prototype.encodeObject=function(t,e){var r=this.extensionCodec.tryToEncode(t,this.context);if(null!=r)this.encodeExtension(r);else if(Array.isArray(t))this.encodeArray(t,e);else if(ArrayBuffer.isView(t))this.encodeBinary(t);else{if("object"!=typeof t)throw new Error("Unrecognized object: ".concat(Object.prototype.toString.apply(t)));this.encodeMap(t,e)}},t.prototype.encodeBinary=function(t){var e=t.byteLength;if(e<256)this.writeU8(196),this.writeU8(e);else if(e<65536)this.writeU8(197),this.writeU16(e);else{if(!(e<4294967296))throw new Error("Too large binary: ".concat(e));this.writeU8(198),this.writeU32(e)}var r=E(t);this.writeU8a(r)},t.prototype.encodeArray=function(t,e){var r,n,i=t.length;if(i<16)this.writeU8(144+i);else if(i<65536)this.writeU8(220),this.writeU16(i);else{if(!(i<4294967296))throw new Error("Too large array: ".concat(i));this.writeU8(221),this.writeU32(i)}try{for(var o=k(t),s=o.next();!s.done;s=o.next()){var a=s.value;this.doEncode(a,e+1)}}catch(t){r={error:t}}finally{try{s&&!s.done&&(n=o.return)&&n.call(o)}finally{if(r)throw r.error}}},t.prototype.countWithoutUndefined=function(t,e){var r,n,i=0;try{for(var o=k(e),s=o.next();!s.done;s=o.next())void 0!==t[s.value]&&i++}catch(t){r={error:t}}finally{try{s&&!s.done&&(n=o.return)&&n.call(o)}finally{if(r)throw r.error}}return i},t.prototype.encodeMap=function(t,e){var r,n,i=Object.keys(t);this.sortKeys&&i.sort();var o=this.ignoreUndefined?this.countWithoutUndefined(t,i):i.length;if(o<16)this.writeU8(128+o);else if(o<65536)this.writeU8(222),this.writeU16(o);else{if(!(o<4294967296))throw new Error("Too large map object: ".concat(o));this.writeU8(223),this.writeU32(o)}try{for(var s=k(i),a=s.next();!a.done;a=s.next()){var c=a.value,u=t[c];this.ignoreUndefined&&void 0===u||(this.encodeString(c),this.doEncode(u,e+1))}}catch(t){r={error:t}}finally{try{a&&!a.done&&(n=s.return)&&n.call(s)}finally{if(r)throw r.error}}},t.prototype.encodeExtension=function(t){if("function"==typeof t.data){var e=t.data(this.pos+6),r=e.length;if(r>=4294967296)throw new Error("Too large extension object: ".concat(r));return this.writeU8(201),this.writeU32(r),this.writeI8(t.type),void this.writeU8a(e)}var n=t.data.length;if(1===n)this.writeU8(212);else if(2===n)this.writeU8(213);else if(4===n)this.writeU8(214);else if(8===n)this.writeU8(215);else if(16===n)this.writeU8(216);else if(n<256)this.writeU8(199),this.writeU8(n);else if(n<65536)this.writeU8(200),this.writeU16(n);else{if(!(n<4294967296))throw new Error("Too large extension object: ".concat(n));this.writeU8(201),this.writeU32(n)}this.writeI8(t.type),this.writeU8a(t.data)},t.prototype.writeU8=function(t){this.ensureBufferSizeToWrite(1),this.view.setUint8(this.pos,t),this.pos++},t.prototype.writeU8a=function(t){var e=t.length;this.ensureBufferSizeToWrite(e),this.bytes.set(t,this.pos),this.pos+=e},t.prototype.writeI8=function(t){this.ensureBufferSizeToWrite(1),this.view.setInt8(this.pos,t),this.pos++},t.prototype.writeU16=function(t){this.ensureBufferSizeToWrite(2),this.view.setUint16(this.pos,t),this.pos+=2},t.prototype.writeI16=function(t){this.ensureBufferSizeToWrite(2),this.view.setInt16(this.pos,t),this.pos+=2},t.prototype.writeU32=function(t){this.ensureBufferSizeToWrite(4),this.view.setUint32(this.pos,t),this.pos+=4},t.prototype.writeI32=function(t){this.ensureBufferSizeToWrite(4),this.view.setInt32(this.pos,t),this.pos+=4},t.prototype.writeF32=function(t){this.ensureBufferSizeToWrite(4),this.view.setFloat32(this.pos,t),this.pos+=4},t.prototype.writeF64=function(t){this.ensureBufferSizeToWrite(8),this.view.setFloat64(this.pos,t),this.pos+=8},t.prototype.writeU64=function(t){this.ensureBufferSizeToWrite(8),function(t,e,r){var n=r/4294967296,i=r;t.setUint32(e,n),t.setUint32(e+4,i)}(this.view,this.pos,t),this.pos+=8},t.prototype.writeI64=function(t){this.ensureBufferSizeToWrite(8),l(this.view,this.pos,t),this.pos+=8},t.prototype.writeBigUint64=function(t){this.ensureBufferSizeToWrite(8),this.view.setBigUint64(this.pos,t),this.pos+=8},t.prototype.writeBigInt64=function(t){this.ensureBufferSizeToWrite(8),this.view.setBigInt64(this.pos,t),this.pos+=8},t}();function T(t,e){return new A(e).encodeSharedRef(t)}function P(t){return"".concat(t<0?"-":"","0x").concat(Math.abs(t).toString(16).padStart(2,"0"))}var L=function(){function t(t,e){void 0===t&&(t=16),void 0===e&&(e=16),this.hit=0,this.miss=0,this.maxKeyLength=t,this.maxLengthPerKey=e,this.caches=[];for(var r=0;r<this.maxKeyLength;r++)this.caches.push([])}return t.prototype.canBeCached=function(t){return t>0&&t<=this.maxKeyLength},t.prototype.find=function(t,e,r){var n,i,o=this.caches[r-1];try{t:for(var s=function(t){var e="function"==typeof Symbol&&Symbol.iterator,r=e&&t[e],n=0;if(r)return r.call(t);if(t&&"number"==typeof t.length)return{next:function(){return t&&n>=t.length&&(t=void 0),{value:t&&t[n++],done:!t}}};throw new TypeError(e?"Object is not iterable.":"Symbol.iterator is not defined.")}(o),a=s.next();!a.done;a=s.next()){for(var c=a.value,u=c.bytes,h=0;h<r;h++)if(u[h]!==t[e+h])continue t;return c.str}}catch(t){n={error:t}}finally{try{a&&!a.done&&(i=s.return)&&i.call(s)}finally{if(n)throw n.error}}return null},t.prototype.store=function(t,e){var r=this.caches[t.length-1],n={bytes:t,str:e};r.length>=this.maxLengthPerKey?r[Math.random()*r.length|0]=n:r.push(n)},t.prototype.decode=function(t,e,r){var n=this.find(t,e,r);if(null!=n)return this.hit++,n;this.miss++;var i=o(t,e,r),s=Uint8Array.prototype.slice.call(t,e,e+r);return this.store(s,i),i},t}(),j=function(t,e){var r,n,i,o={label:0,sent:function(){if(1&i[0])throw i[1];return i[1]},trys:[],ops:[]},s=Object.create(("function"==typeof Iterator?Iterator:Object).prototype);return s.next=a(0),s.throw=a(1),s.return=a(2),"function"==typeof Symbol&&(s[Symbol.iterator]=function(){return this}),s;function a(a){return function(c){return function(a){if(r)throw new TypeError("Generator is already executing.");for(;s&&(s=0,a[0]&&(o=0)),o;)try{if(r=1,n&&(i=2&a[0]?n.return:a[0]?n.throw||((i=n.return)&&i.call(n),0):n.next)&&!(i=i.call(n,a[1])).done)return i;switch(n=0,i&&(a=[2&a[0],i.value]),a[0]){case 0:case 1:i=a;break;case 4:return o.label++,{value:a[1],done:!1};case 5:o.label++,n=a[1],a=[0];continue;case 7:a=o.ops.pop(),o.trys.pop();continue;default:if(!((i=(i=o.trys).length>0&&i[i.length-1])||6!==a[0]&&2!==a[0])){o=0;continue}if(3===a[0]&&(!i||a[1]>i[0]&&a[1]<i[3])){o.label=a[1];break}if(6===a[0]&&o.label<i[1]){o.label=i[1],i=a;break}if(i&&o.label<i[2]){o.label=i[2],o.ops.push(a);break}i[2]&&o.ops.pop(),o.trys.pop();continue}a=e.call(t,o)}catch(t){a=[6,t],n=0}finally{r=i=0}if(5&a[0])throw a[1];return{value:a[0]?a[1]:void 0,done:!0}}([a,c])}}},z=function(t,e,r){if(null!=e){if("object"!=typeof e&&"function"!=typeof e)throw new TypeError("Object expected.");var n,i;if(r){if(!Symbol.asyncDispose)throw new TypeError("Symbol.asyncDispose is not defined.");n=e[Symbol.asyncDispose]}if(void 0===n){if(!Symbol.dispose)throw new TypeError("Symbol.dispose is not defined.");n=e[Symbol.dispose],r&&(i=n)}if("function"!=typeof n)throw new TypeError("Object not disposable.");i&&(n=function(){try{i.call(this)}catch(t){return Promise.reject(t)}}),t.stack.push({value:e,dispose:n,async:r})}else r&&t.stack.push({async:!0});return e},M=function(t){return function(e){function r(r){e.error=e.hasError?new t(r,e.error,"An error was suppressed during disposal."):r,e.hasError=!0}var n,i=0;return function t(){for(;n=e.stack.pop();)try{if(!n.async&&1===i)return i=0,e.stack.push(n),Promise.resolve().then(t);if(n.dispose){var o=n.dispose.call(n.value);if(n.async)return i|=2,Promise.resolve(o).then(t,(function(e){return r(e),t()}))}else i|=1}catch(t){r(t)}if(1===i)return e.hasError?Promise.reject(e.error):Promise.resolve();if(e.hasError)throw e.error}()}}("function"==typeof SuppressedError?SuppressedError:function(t,e,r){var n=new Error(r);return n.name="SuppressedError",n.error=t,n.suppressed=e,n}),D=function(t){if(!Symbol.asyncIterator)throw new TypeError("Symbol.asyncIterator is not defined.");var e,r=t[Symbol.asyncIterator];return r?r.call(t):(t="function"==typeof C?C(t):t[Symbol.iterator](),e={},n("next"),n("throw"),n("return"),e[Symbol.asyncIterator]=function(){return this},e);function n(r){e[r]=t[r]&&function(e){return new Promise((function(n,i){!function(t,e,r,n){Promise.resolve(n).then((function(e){t({value:e,done:r})}),e)}(n,i,(e=t[r](e)).done,e.value)}))}}},O=function(t){return this instanceof O?(this.v=t,this):new O(t)},F=function(t){var e,r;return e={},n("next"),n("throw",(function(t){throw t})),n("return"),e[Symbol.iterator]=function(){return this},e;function n(n,i){e[n]=t[n]?function(e){return(r=!r)?{value:O(t[n](e)),done:!1}:i?i(e):e}:i}},C=function(t){var e="function"==typeof Symbol&&Symbol.iterator,r=e&&t[e],n=0;if(r)return r.call(t);if(t&&"number"==typeof t.length)return{next:function(){return t&&n>=t.length&&(t=void 0),{value:t&&t[n++],done:!t}}};throw new TypeError(e?"Object is not iterable.":"Symbol.iterator is not defined.")},_="array",R="map_key",W="map_value",H=function(){function t(){this.stack=[],this.stackHeadPosition=-1}return Object.defineProperty(t.prototype,"length",{get:function(){return this.stackHeadPosition+1},enumerable:!1,configurable:!0}),t.prototype.top=function(){return this.stack[this.stackHeadPosition]},t.prototype.pushArrayState=function(t){var e=this.getUninitializedStateFromPool();e.type=_,e.position=0,e.size=t,e.array=new Array(t)},t.prototype.pushMapState=function(t){var e=this.getUninitializedStateFromPool();e.type=R,e.readCount=0,e.size=t,e.map={}},t.prototype.getUninitializedStateFromPool=function(){if(this.stackHeadPosition++,this.stackHeadPosition===this.stack.length){this.stack.push({type:void 0,size:0,array:void 0,position:0,readCount:0,map:void 0,key:null})}return this.stack[this.stackHeadPosition]},t.prototype.release=function(t){var e;if(this.stack[this.stackHeadPosition]!==t)throw new Error("Invalid stack state. Released state is not on top of the stack.");t.type===_&&((e=t).size=0,e.array=void 0,e.position=0,e.type=void 0),t.type!==R&&t.type!==W||((e=t).size=0,e.map=void 0,e.readCount=0,e.type=void 0),this.stackHeadPosition--},t.prototype.reset=function(){this.stack.length=0,this.stackHeadPosition=-1},t}(),K=new DataView(new ArrayBuffer(0)),G=new Uint8Array(K.buffer);try{K.getInt8(0)}catch(t){if(!(t instanceof RangeError))throw new Error("This module is not supported in the current JavaScript engine because DataView does not throw RangeError on out-of-bounds access")}var V=new RangeError("Insufficient data"),N=new L,J=function(){function t(t){var e,r,n,i,o,s,a,c;this.totalPos=0,this.pos=0,this.view=K,this.bytes=G,this.headByte=-1,this.stack=new H,this.entered=!1,this.extensionCodec=null!==(e=null==t?void 0:t.extensionCodec)&&void 0!==e?e:x.defaultCodec,this.context=null==t?void 0:t.context,this.useBigInt64=null!==(r=null==t?void 0:t.useBigInt64)&&void 0!==r&&r,this.rawStrings=null!==(n=null==t?void 0:t.rawStrings)&&void 0!==n&&n,this.maxStrLength=null!==(i=null==t?void 0:t.maxStrLength)&&void 0!==i?i:f,this.maxBinLength=null!==(o=null==t?void 0:t.maxBinLength)&&void 0!==o?o:f,this.maxArrayLength=null!==(s=null==t?void 0:t.maxArrayLength)&&void 0!==s?s:f,this.maxMapLength=null!==(a=null==t?void 0:t.maxMapLength)&&void 0!==a?a:f,this.maxExtLength=null!==(c=null==t?void 0:t.maxExtLength)&&void 0!==c?c:f,this.keyDecoder=void 0!==(null==t?void 0:t.keyDecoder)?t.keyDecoder:N}return t.prototype.clone=function(){return new t({extensionCodec:this.extensionCodec,context:this.context,useBigInt64:this.useBigInt64,rawStrings:this.rawStrings,maxStrLength:this.maxStrLength,maxBinLength:this.maxBinLength,maxArrayLength:this.maxArrayLength,maxMapLength:this.maxMapLength,maxExtLength:this.maxExtLength,keyDecoder:this.keyDecoder})},t.prototype.reinitializeState=function(){this.totalPos=0,this.headByte=-1,this.stack.reset()},t.prototype.setBuffer=function(t){var e=E(t);this.bytes=e,this.view=new DataView(e.buffer,e.byteOffset,e.byteLength),this.pos=0},t.prototype.appendBuffer=function(t){if(-1!==this.headByte||this.hasRemaining(1)){var e=this.bytes.subarray(this.pos),r=E(t),n=new Uint8Array(e.length+r.length);n.set(e),n.set(r,e.length),this.setBuffer(n)}else this.setBuffer(t)},t.prototype.hasRemaining=function(t){return this.view.byteLength-this.pos>=t},t.prototype.createExtraByteError=function(t){var e=this.view,r=this.pos;return new RangeError("Extra ".concat(e.byteLength-r," of ").concat(e.byteLength," byte(s) found at buffer[").concat(t,"]"))},t.prototype.enteringGuard=function(){var t,e=this;return this.entered=!0,(t={})[Symbol.dispose]=function(){e.entered=!1},t},t.prototype.decode=function(t){var e={stack:[],error:void 0,hasError:!1};try{if(this.entered)return this.clone().decode(t);z(e,this.enteringGuard(),!1),this.reinitializeState(),this.setBuffer(t);var r=this.doDecodeSync();if(this.hasRemaining(1))throw this.createExtraByteError(this.pos);return r}catch(t){e.error=t,e.hasError=!0}finally{M(e)}},t.prototype.decodeMulti=function(t){var e,r,n;return j(this,(function(i){switch(i.label){case 0:e={stack:[],error:void 0,hasError:!1},i.label=1;case 1:return i.trys.push([1,7,8,9]),this.entered?(r=this.clone(),[5,C(r.decodeMulti(t))]):[3,3];case 2:return i.sent(),[2];case 3:z(e,this.enteringGuard(),!1),this.reinitializeState(),this.setBuffer(t),i.label=4;case 4:return this.hasRemaining(1)?[4,this.doDecodeSync()]:[3,6];case 5:return i.sent(),[3,4];case 6:return[3,9];case 7:return n=i.sent(),e.error=n,e.hasError=!0,[3,9];case 8:return M(e),[7];case 9:return[2]}}))},t.prototype.decodeAsync=function(t){return e=this,r=void 0,i=function(){var e,r,n,i,o,s,a,c,u,h,f,l,p,d,y,w,v;return j(this,(function(g){switch(g.label){case 0:e={stack:[],error:void 0,hasError:!1},g.label=1;case 1:if(g.trys.push([1,14,15,16]),this.entered)return[2,this.clone().decodeAsync(t)];z(e,this.enteringGuard(),!1),r=!1,n=void 0,g.label=2;case 2:g.trys.push([2,7,8,13]),f=!0,l=D(t),g.label=3;case 3:return[4,l.next()];case 4:if(p=g.sent(),d=p.done)return[3,6];if(v=p.value,f=!1,i=v,r)throw this.entered=!1,this.createExtraByteError(this.totalPos);this.appendBuffer(i);try{n=this.doDecodeSync(),r=!0}catch(t){if(!(t instanceof RangeError))throw t}this.totalPos+=this.pos,g.label=5;case 5:return f=!0,[3,3];case 6:return[3,13];case 7:return o=g.sent(),y={error:o},[3,13];case 8:return g.trys.push([8,,11,12]),f||d||!(w=l.return)?[3,10]:[4,w.call(l)];case 9:g.sent(),g.label=10;case 10:return[3,12];case 11:if(y)throw y.error;return[7];case 12:return[7];case 13:if(r){if(this.hasRemaining(1))throw this.createExtraByteError(this.totalPos);return[2,n]}throw a=(s=this).headByte,c=s.pos,u=s.totalPos,new RangeError("Insufficient data in parsing ".concat(P(a)," at ").concat(u," (").concat(c," in the current buffer)"));case 14:return h=g.sent(),e.error=h,e.hasError=!0,[3,16];case 15:return M(e),[7];case 16:return[2]}}))},new((n=void 0)||(n=Promise))((function(t,o){function s(t){try{c(i.next(t))}catch(t){o(t)}}function a(t){try{c(i.throw(t))}catch(t){o(t)}}function c(e){var r;e.done?t(e.value):(r=e.value,r instanceof n?r:new n((function(t){t(r)}))).then(s,a)}c((i=i.apply(e,r||[])).next())}));var e,r,n,i},t.prototype.decodeArrayStream=function(t){return this.decodeMultiAsync(t,!0)},t.prototype.decodeStream=function(t){return this.decodeMultiAsync(t,!1)},t.prototype.decodeMultiAsync=function(t,e){return function(t,e,r){if(!Symbol.asyncIterator)throw new TypeError("Symbol.asyncIterator is not defined.");var n,i=r.apply(t,e||[]),o=[];return n=Object.create(("function"==typeof AsyncIterator?AsyncIterator:Object).prototype),s("next"),s("throw"),s("return",(function(t){return function(e){return Promise.resolve(e).then(t,u)}})),n[Symbol.asyncIterator]=function(){return this},n;function s(t,e){i[t]&&(n[t]=function(e){return new Promise((function(r,n){o.push([t,e,r,n])>1||a(t,e)}))},e&&(n[t]=e(n[t])))}function a(t,e){try{(r=i[t](e)).value instanceof O?Promise.resolve(r.value.v).then(c,u):h(o[0][2],r)}catch(t){h(o[0][3],t)}var r}function c(t){a("next",t)}function u(t){a("throw",t)}function h(t,e){t(e),o.shift(),o.length&&a(o[0][0],o[0][1])}}(this,arguments,(function(){var r,n,i,o,s,a,c,u,h,f,l,p,d,y,w;return j(this,(function(v){switch(v.label){case 0:r={stack:[],error:void 0,hasError:!1},v.label=1;case 1:return v.trys.push([1,25,26,27]),this.entered?(n=this.clone(),[5,C(F(D(n.decodeMultiAsync(t,e))))]):[3,5];case 2:return[4,O.apply(void 0,[v.sent()])];case 3:return v.sent(),[4,O(void 0)];case 4:return[2,v.sent()];case 5:z(r,this.enteringGuard(),!1),i=e,o=-1,v.label=6;case 6:v.trys.push([6,18,19,24]),s=!0,a=D(t),v.label=7;case 7:return[4,O(a.next())];case 8:if(c=v.sent(),p=c.done)return[3,17];if(w=c.value,s=!1,u=w,e&&0===o)throw this.createExtraByteError(this.totalPos);this.appendBuffer(u),i&&(o=this.readArraySize(),i=!1,this.complete()),v.label=9;case 9:v.trys.push([9,14,,15]),v.label=10;case 10:return[4,O(this.doDecodeSync())];case 11:return[4,v.sent()];case 12:return v.sent(),0==--o?[3,13]:[3,10];case 13:return[3,15];case 14:if(!((h=v.sent())instanceof RangeError))throw h;return[3,15];case 15:this.totalPos+=this.pos,v.label=16;case 16:return s=!0,[3,7];case 17:return[3,24];case 18:return f=v.sent(),d={error:f},[3,24];case 19:return v.trys.push([19,,22,23]),s||p||!(y=a.return)?[3,21]:[4,O(y.call(a))];case 20:v.sent(),v.label=21;case 21:return[3,23];case 22:if(d)throw d.error;return[7];case 23:return[7];case 24:return[3,27];case 25:return l=v.sent(),r.error=l,r.hasError=!0,[3,27];case 26:return M(r),[7];case 27:return[2]}}))}))},t.prototype.doDecodeSync=function(){t:for(;;){var t=this.readHeadByte(),e=void 0;if(t>=224)e=t-256;else if(t<192)if(t<128)e=t;else if(t<144){if(0!=(n=t-128)){this.pushMapState(n),this.complete();continue t}e={}}else if(t<160){if(0!=(n=t-144)){this.pushArrayState(n),this.complete();continue t}e=[]}else{var r=t-160;e=this.decodeString(r,0)}else if(192===t)e=null;else if(194===t)e=!1;else if(195===t)e=!0;else if(202===t)e=this.readF32();else if(203===t)e=this.readF64();else if(204===t)e=this.readU8();else if(205===t)e=this.readU16();else if(206===t)e=this.readU32();else if(207===t)e=this.useBigInt64?this.readU64AsBigInt():this.readU64();else if(208===t)e=this.readI8();else if(209===t)e=this.readI16();else if(210===t)e=this.readI32();else if(211===t)e=this.useBigInt64?this.readI64AsBigInt():this.readI64();else if(217===t)r=this.lookU8(),e=this.decodeString(r,1);else if(218===t)r=this.lookU16(),e=this.decodeString(r,2);else if(219===t)r=this.lookU32(),e=this.decodeString(r,4);else if(220===t){if(0!==(n=this.readU16())){this.pushArrayState(n),this.complete();continue t}e=[]}else if(221===t){if(0!==(n=this.readU32())){this.pushArrayState(n),this.complete();continue t}e=[]}else if(222===t){if(0!==(n=this.readU16())){this.pushMapState(n),this.complete();continue t}e={}}else if(223===t){if(0!==(n=this.readU32())){this.pushMapState(n),this.complete();continue t}e={}}else if(196===t){var n=this.lookU8();e=this.decodeBinary(n,1)}else if(197===t)n=this.lookU16(),e=this.decodeBinary(n,2);else if(198===t)n=this.lookU32(),e=this.decodeBinary(n,4);else if(212===t)e=this.decodeExtension(1,0);else if(213===t)e=this.decodeExtension(2,0);else if(214===t)e=this.decodeExtension(4,0);else if(215===t)e=this.decodeExtension(8,0);else if(216===t)e=this.decodeExtension(16,0);else if(199===t)n=this.lookU8(),e=this.decodeExtension(n,1);else if(200===t)n=this.lookU16(),e=this.decodeExtension(n,2);else{if(201!==t)throw new h("Unrecognized type byte: ".concat(P(t)));n=this.lookU32(),e=this.decodeExtension(n,4)}this.complete();for(var i=this.stack;i.length>0;){var o=i.top();if(o.type===_){if(o.array[o.position]=e,o.position++,o.position!==o.size)continue t;e=o.array,i.release(o)}else{if(o.type===R){if("string"!=typeof(s=e)&&"number"!=typeof s)throw new h("The type of key must be string or number but "+typeof e);if("__proto__"===e)throw new h("The key __proto__ is not allowed");o.key=e,o.type=W;continue t}if(o.map[o.key]=e,o.readCount++,o.readCount!==o.size){o.key=null,o.type=R;continue t}e=o.map,i.release(o)}}return e}var s},t.prototype.readHeadByte=function(){return-1===this.headByte&&(this.headByte=this.readU8()),this.headByte},t.prototype.complete=function(){this.headByte=-1},t.prototype.readArraySize=function(){var t=this.readHeadByte();switch(t){case 220:return this.readU16();case 221:return this.readU32();default:if(t<160)return t-144;throw new h("Unrecognized array type byte: ".concat(P(t)))}},t.prototype.pushMapState=function(t){if(t>this.maxMapLength)throw new h("Max length exceeded: map length (".concat(t,") > maxMapLengthLength (").concat(this.maxMapLength,")"));this.stack.pushMapState(t)},t.prototype.pushArrayState=function(t){if(t>this.maxArrayLength)throw new h("Max length exceeded: array length (".concat(t,") > maxArrayLength (").concat(this.maxArrayLength,")"));this.stack.pushArrayState(t)},t.prototype.decodeString=function(t,e){return!this.rawStrings||this.stateIsMapKey()?this.decodeUtf8String(t,e):this.decodeBinary(t,e)},t.prototype.decodeUtf8String=function(t,e){var r;if(t>this.maxStrLength)throw new h("Max length exceeded: UTF-8 byte length (".concat(t,") > maxStrLength (").concat(this.maxStrLength,")"));if(this.bytes.byteLength<this.pos+e+t)throw V;var n,i=this.pos+e;return n=this.stateIsMapKey()&&(null===(r=this.keyDecoder)||void 0===r?void 0:r.canBeCached(t))?this.keyDecoder.decode(this.bytes,i,t):function(t,e,r){return r>200?function(t,e,r){var n=t.subarray(e,e+r);return s.decode(n)}(t,e,r):o(t,e,r)}(this.bytes,i,t),this.pos+=e+t,n},t.prototype.stateIsMapKey=function(){return this.stack.length>0&&this.stack.top().type===R},t.prototype.decodeBinary=function(t,e){if(t>this.maxBinLength)throw new h("Max length exceeded: bin length (".concat(t,") > maxBinLength (").concat(this.maxBinLength,")"));if(!this.hasRemaining(t+e))throw V;var r=this.pos+e,n=this.bytes.subarray(r,r+t);return this.pos+=e+t,n},t.prototype.decodeExtension=function(t,e){if(t>this.maxExtLength)throw new h("Max length exceeded: ext length (".concat(t,") > maxExtLength (").concat(this.maxExtLength,")"));var r=this.view.getInt8(this.pos+e),n=this.decodeBinary(t,e+1);return this.extensionCodec.decode(n,r,this.context)},t.prototype.lookU8=function(){return this.view.getUint8(this.pos)},t.prototype.lookU16=function(){return this.view.getUint16(this.pos)},t.prototype.lookU32=function(){return this.view.getUint32(this.pos)},t.prototype.readU8=function(){var t=this.view.getUint8(this.pos);return this.pos++,t},t.prototype.readI8=function(){var t=this.view.getInt8(this.pos);return this.pos++,t},t.prototype.readU16=function(){var t=this.view.getUint16(this.pos);return this.pos+=2,t},t.prototype.readI16=function(){var t=this.view.getInt16(this.pos);return this.pos+=2,t},t.prototype.readU32=function(){var t=this.view.getUint32(this.pos);return this.pos+=4,t},t.prototype.readI32=function(){var t=this.view.getInt32(this.pos);return this.pos+=4,t},t.prototype.readU64=function(){var t,e,r=(t=this.view,e=this.pos,4294967296*t.getUint32(e)+t.getUint32(e+4));return this.pos+=8,r},t.prototype.readI64=function(){var t=p(this.view,this.pos);return this.pos+=8,t},t.prototype.readU64AsBigInt=function(){var t=this.view.getBigUint64(this.pos);return this.pos+=8,t},t.prototype.readI64AsBigInt=function(){var t=this.view.getBigInt64(this.pos);return this.pos+=8,t},t.prototype.readF32=function(){var t=this.view.getFloat32(this.pos);return this.pos+=4,t},t.prototype.readF64=function(){var t=this.view.getFloat64(this.pos);return this.pos+=8,t},t}();function X(t,e){return new J(e).decode(t)}function q(t,e){return new J(e).decodeMulti(t)}var Q=function(t,e){var r,n,i,o={label:0,sent:function(){if(1&i[0])throw i[1];return i[1]},trys:[],ops:[]},s=Object.create(("function"==typeof Iterator?Iterator:Object).prototype);return s.next=a(0),s.throw=a(1),s.return=a(2),"function"==typeof Symbol&&(s[Symbol.iterator]=function(){return this}),s;function a(a){return function(c){return function(a){if(r)throw new TypeError("Generator is already executing.");for(;s&&(s=0,a[0]&&(o=0)),o;)try{if(r=1,n&&(i=2&a[0]?n.return:a[0]?n.throw||((i=n.return)&&i.call(n),0):n.next)&&!(i=i.call(n,a[1])).done)return i;switch(n=0,i&&(a=[2&a[0],i.value]),a[0]){case 0:case 1:i=a;break;case 4:return o.label++,{value:a[1],done:!1};case 5:o.label++,n=a[1],a=[0];continue;case 7:a=o.ops.pop(),o.trys.pop();continue;default:if(!((i=(i=o.trys).length>0&&i[i.length-1])||6!==a[0]&&2!==a[0])){o=0;continue}if(3===a[0]&&(!i||a[1]>i[0]&&a[1]<i[3])){o.label=a[1];break}if(6===a[0]&&o.label<i[1]){o.label=i[1],i=a;break}if(i&&o.label<i[2]){o.label=i[2],o.ops.push(a);break}i[2]&&o.ops.pop(),o.trys.pop();continue}a=e.call(t,o)}catch(t){a=[6,t],n=0}finally{r=i=0}if(5&a[0])throw a[1];return{value:a[0]?a[1]:void 0,done:!0}}([a,c])}}},Y=function(t){return this instanceof Y?(this.v=t,this):new Y(t)},Z=function(t,e,r){if(!Symbol.asyncIterator)throw new TypeError("Symbol.asyncIterator is not defined.");var n,i=r.apply(t,e||[]),o=[];return n=Object.create(("function"==typeof AsyncIterator?AsyncIterator:Object).prototype),s("next"),s("throw"),s("return",(function(t){return function(e){return Promise.resolve(e).then(t,u)}})),n[Symbol.asyncIterator]=function(){return this},n;function s(t,e){i[t]&&(n[t]=function(e){return new Promise((function(r,n){o.push([t,e,r,n])>1||a(t,e)}))},e&&(n[t]=e(n[t])))}function a(t,e){try{(r=i[t](e)).value instanceof Y?Promise.resolve(r.value.v).then(c,u):h(o[0][2],r)}catch(t){h(o[0][3],t)}var r}function c(t){a("next",t)}function u(t){a("throw",t)}function h(t,e){t(e),o.shift(),o.length&&a(o[0][0],o[0][1])}};function $(t){return null!=t[Symbol.asyncIterator]?t:function(t){return Z(this,arguments,(function(){var e,r,n,i;return Q(this,(function(o){switch(o.label){case 0:e=t.getReader(),o.label=1;case 1:o.trys.push([1,,9,10]),o.label=2;case 2:return[4,Y(e.read())];case 3:return r=o.sent(),n=r.done,i=r.value,n?[4,Y(void 0)]:[3,5];case 4:return[2,o.sent()];case 5:return function(t){if(null==t)throw new Error("Assertion Failure: value must not be null nor undefined")}(i),[4,Y(i)];case 6:return[4,o.sent()];case 7:return o.sent(),[3,2];case 8:return[3,10];case 9:return e.releaseLock(),[7];case 10:return[2]}}))}))}(t)}var tt=function(t,e,r,n){return new(r||(r=Promise))((function(i,o){function s(t){try{c(n.next(t))}catch(t){o(t)}}function a(t){try{c(n.throw(t))}catch(t){o(t)}}function c(t){var e;t.done?i(t.value):(e=t.value,e instanceof r?e:new r((function(t){t(e)}))).then(s,a)}c((n=n.apply(t,e||[])).next())}))},et=function(t,e){var r,n,i,o={label:0,sent:function(){if(1&i[0])throw i[1];return i[1]},trys:[],ops:[]},s=Object.create(("function"==typeof Iterator?Iterator:Object).prototype);return s.next=a(0),s.throw=a(1),s.return=a(2),"function"==typeof Symbol&&(s[Symbol.iterator]=function(){return this}),s;function a(a){return function(c){return function(a){if(r)throw new TypeError("Generator is already executing.");for(;s&&(s=0,a[0]&&(o=0)),o;)try{if(r=1,n&&(i=2&a[0]?n.return:a[0]?n.throw||((i=n.return)&&i.call(n),0):n.next)&&!(i=i.call(n,a[1])).done)return i;switch(n=0,i&&(a=[2&a[0],i.value]),a[0]){case 0:case 1:i=a;break;case 4:return o.label++,{value:a[1],done:!1};case 5:o.label++,n=a[1],a=[0];continue;case 7:a=o.ops.pop(),o.trys.pop();continue;default:if(!((i=(i=o.trys).length>0&&i[i.length-1])||6!==a[0]&&2!==a[0])){o=0;continue}if(3===a[0]&&(!i||a[1]>i[0]&&a[1]<i[3])){o.label=a[1];break}if(6===a[0]&&o.label<i[1]){o.label=i[1],i=a;break}if(i&&o.label<i[2]){o.label=i[2],o.ops.push(a);break}i[2]&&o.ops.pop(),o.trys.pop();continue}a=e.call(t,o)}catch(t){a=[6,t],n=0}finally{r=i=0}if(5&a[0])throw a[1];return{value:a[0]?a[1]:void 0,done:!0}}([a,c])}}};function rt(t,e){return tt(this,void 0,void 0,(function(){var r;return et(this,(function(n){return r=$(t),[2,new J(e).decodeAsync(r)]}))}))}function nt(t,e){var r=$(t);return new J(e).decodeArrayStream(r)}function it(t,e){var r=$(t);return new J(e).decodeStream(r)}return e}()})); | ||
//# sourceMappingURL=msgpack.min.js.map |
@@ -60,3 +60,2 @@ import { ExtensionCodecType } from "./ExtensionCodec"; | ||
}>> & ContextOf<ContextType>; | ||
export declare const DataViewIndexOutOfBoundsError: RangeErrorConstructor; | ||
export declare class Decoder<ContextType = undefined> { | ||
@@ -79,3 +78,5 @@ private readonly extensionCodec; | ||
private readonly stack; | ||
private entered; | ||
constructor(options?: DecoderOptions<ContextType>); | ||
private clone; | ||
private reinitializeState; | ||
@@ -86,2 +87,3 @@ private setBuffer; | ||
private createExtraByteError; | ||
private enteringGuard; | ||
/** | ||
@@ -92,6 +94,6 @@ * @throws {@link DecodeError} | ||
decode(buffer: ArrayLike<number> | ArrayBufferView | ArrayBufferLike): unknown; | ||
decodeMulti(buffer: ArrayLike<number> | BufferSource): Generator<unknown, void, unknown>; | ||
decodeAsync(stream: AsyncIterable<ArrayLike<number> | BufferSource>): Promise<unknown>; | ||
decodeArrayStream(stream: AsyncIterable<ArrayLike<number> | BufferSource>): AsyncGenerator<unknown, void, unknown>; | ||
decodeStream(stream: AsyncIterable<ArrayLike<number> | BufferSource>): AsyncGenerator<unknown, void, unknown>; | ||
decodeMulti(buffer: ArrayLike<number> | ArrayBufferView | ArrayBufferLike): Generator<unknown, void, unknown>; | ||
decodeAsync(stream: AsyncIterable<ArrayLike<number> | ArrayBufferView | ArrayBufferLike>): Promise<unknown>; | ||
decodeArrayStream(stream: AsyncIterable<ArrayLike<number> | ArrayBufferView | ArrayBufferLike>): AsyncGenerator<unknown, void, unknown>; | ||
decodeStream(stream: AsyncIterable<ArrayLike<number> | ArrayBufferView | ArrayBufferLike>): AsyncGenerator<unknown, void, unknown>; | ||
private decodeMultiAsync; | ||
@@ -105,4 +107,10 @@ private doDecodeSync; | ||
private decodeString; | ||
/** | ||
* @throws {@link RangeError} | ||
*/ | ||
private decodeUtf8String; | ||
private stateIsMapKey; | ||
/** | ||
* @throws {@link RangeError} | ||
*/ | ||
private decodeBinary; | ||
@@ -109,0 +117,0 @@ private decodeExtension; |
"use strict"; | ||
var __addDisposableResource = (this && this.__addDisposableResource) || function (env, value, async) { | ||
if (value !== null && value !== void 0) { | ||
if (typeof value !== "object" && typeof value !== "function") throw new TypeError("Object expected."); | ||
var dispose, inner; | ||
if (async) { | ||
if (!Symbol.asyncDispose) throw new TypeError("Symbol.asyncDispose is not defined."); | ||
dispose = value[Symbol.asyncDispose]; | ||
} | ||
if (dispose === void 0) { | ||
if (!Symbol.dispose) throw new TypeError("Symbol.dispose is not defined."); | ||
dispose = value[Symbol.dispose]; | ||
if (async) inner = dispose; | ||
} | ||
if (typeof dispose !== "function") throw new TypeError("Object not disposable."); | ||
if (inner) dispose = function() { try { inner.call(this); } catch (e) { return Promise.reject(e); } }; | ||
env.stack.push({ value: value, dispose: dispose, async: async }); | ||
} | ||
else if (async) { | ||
env.stack.push({ async: true }); | ||
} | ||
return value; | ||
}; | ||
var __disposeResources = (this && this.__disposeResources) || (function (SuppressedError) { | ||
return function (env) { | ||
function fail(e) { | ||
env.error = env.hasError ? new SuppressedError(e, env.error, "An error was suppressed during disposal.") : e; | ||
env.hasError = true; | ||
} | ||
var r, s = 0; | ||
function next() { | ||
while (r = env.stack.pop()) { | ||
try { | ||
if (!r.async && s === 1) return s = 0, env.stack.push(r), Promise.resolve().then(next); | ||
if (r.dispose) { | ||
var result = r.dispose.call(r.value); | ||
if (r.async) return s |= 2, Promise.resolve(result).then(next, function(e) { fail(e); return next(); }); | ||
} | ||
else s |= 1; | ||
} | ||
catch (e) { | ||
fail(e); | ||
} | ||
} | ||
if (s === 1) return env.hasError ? Promise.reject(env.error) : Promise.resolve(); | ||
if (env.hasError) throw env.error; | ||
} | ||
return next(); | ||
}; | ||
})(typeof SuppressedError === "function" ? SuppressedError : function (error, suppressed, message) { | ||
var e = new Error(message); | ||
return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e; | ||
}); | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.Decoder = exports.DataViewIndexOutOfBoundsError = void 0; | ||
exports.Decoder = void 0; | ||
const prettyByte_1 = require("./utils/prettyByte"); | ||
@@ -97,4 +149,3 @@ const ExtensionCodec_1 = require("./ExtensionCodec"); | ||
} | ||
exports.DataViewIndexOutOfBoundsError = RangeError; | ||
const MORE_DATA = new exports.DataViewIndexOutOfBoundsError("Insufficient data"); | ||
const MORE_DATA = new RangeError("Insufficient data"); | ||
const sharedCachedKeyDecoder = new CachedKeyDecoder_1.CachedKeyDecoder(); | ||
@@ -110,2 +161,3 @@ class Decoder { | ||
this.stack = new StackPool(); | ||
this.entered = false; | ||
this.extensionCodec = (_a = options === null || options === void 0 ? void 0 : options.extensionCodec) !== null && _a !== void 0 ? _a : ExtensionCodec_1.ExtensionCodec.defaultCodec; | ||
@@ -122,2 +174,17 @@ this.context = options === null || options === void 0 ? void 0 : options.context; // needs a type assertion because EncoderOptions has no context property when ContextType is undefined | ||
} | ||
clone() { | ||
// eslint-disable-next-line @typescript-eslint/no-unsafe-argument | ||
return new Decoder({ | ||
extensionCodec: this.extensionCodec, | ||
context: this.context, | ||
useBigInt64: this.useBigInt64, | ||
rawStrings: this.rawStrings, | ||
maxStrLength: this.maxStrLength, | ||
maxBinLength: this.maxBinLength, | ||
maxArrayLength: this.maxArrayLength, | ||
maxMapLength: this.maxMapLength, | ||
maxExtLength: this.maxExtLength, | ||
keyDecoder: this.keyDecoder, | ||
}); | ||
} | ||
reinitializeState() { | ||
@@ -130,4 +197,5 @@ this.totalPos = 0; | ||
setBuffer(buffer) { | ||
this.bytes = (0, typedArrays_1.ensureUint8Array)(buffer); | ||
this.view = (0, typedArrays_1.createDataView)(this.bytes); | ||
const bytes = (0, typedArrays_1.ensureUint8Array)(buffer); | ||
this.bytes = bytes; | ||
this.view = new DataView(bytes.buffer, bytes.byteOffset, bytes.byteLength); | ||
this.pos = 0; | ||
@@ -156,2 +224,10 @@ } | ||
} | ||
enteringGuard() { | ||
this.entered = true; | ||
return { | ||
[Symbol.dispose]: () => { | ||
this.entered = false; | ||
}, | ||
}; | ||
} | ||
/** | ||
@@ -162,45 +238,95 @@ * @throws {@link DecodeError} | ||
decode(buffer) { | ||
this.reinitializeState(); | ||
this.setBuffer(buffer); | ||
const object = this.doDecodeSync(); | ||
if (this.hasRemaining(1)) { | ||
throw this.createExtraByteError(this.pos); | ||
const env_1 = { stack: [], error: void 0, hasError: false }; | ||
try { | ||
if (this.entered) { | ||
const instance = this.clone(); | ||
return instance.decode(buffer); | ||
} | ||
// eslint-disable-next-line @typescript-eslint/no-unused-vars | ||
const _guard = __addDisposableResource(env_1, this.enteringGuard(), false); | ||
this.reinitializeState(); | ||
this.setBuffer(buffer); | ||
const object = this.doDecodeSync(); | ||
if (this.hasRemaining(1)) { | ||
throw this.createExtraByteError(this.pos); | ||
} | ||
return object; | ||
} | ||
return object; | ||
catch (e_1) { | ||
env_1.error = e_1; | ||
env_1.hasError = true; | ||
} | ||
finally { | ||
__disposeResources(env_1); | ||
} | ||
} | ||
*decodeMulti(buffer) { | ||
this.reinitializeState(); | ||
this.setBuffer(buffer); | ||
while (this.hasRemaining(1)) { | ||
yield this.doDecodeSync(); | ||
const env_2 = { stack: [], error: void 0, hasError: false }; | ||
try { | ||
if (this.entered) { | ||
const instance = this.clone(); | ||
yield* instance.decodeMulti(buffer); | ||
return; | ||
} | ||
// eslint-disable-next-line @typescript-eslint/no-unused-vars | ||
const _guard = __addDisposableResource(env_2, this.enteringGuard(), false); | ||
this.reinitializeState(); | ||
this.setBuffer(buffer); | ||
while (this.hasRemaining(1)) { | ||
yield this.doDecodeSync(); | ||
} | ||
} | ||
catch (e_2) { | ||
env_2.error = e_2; | ||
env_2.hasError = true; | ||
} | ||
finally { | ||
__disposeResources(env_2); | ||
} | ||
} | ||
async decodeAsync(stream) { | ||
let decoded = false; | ||
let object; | ||
for await (const buffer of stream) { | ||
if (decoded) { | ||
throw this.createExtraByteError(this.totalPos); | ||
const env_3 = { stack: [], error: void 0, hasError: false }; | ||
try { | ||
if (this.entered) { | ||
const instance = this.clone(); | ||
return instance.decodeAsync(stream); | ||
} | ||
this.appendBuffer(buffer); | ||
try { | ||
object = this.doDecodeSync(); | ||
decoded = true; | ||
// eslint-disable-next-line @typescript-eslint/no-unused-vars | ||
const _guard = __addDisposableResource(env_3, this.enteringGuard(), false); | ||
let decoded = false; | ||
let object; | ||
for await (const buffer of stream) { | ||
if (decoded) { | ||
this.entered = false; | ||
throw this.createExtraByteError(this.totalPos); | ||
} | ||
this.appendBuffer(buffer); | ||
try { | ||
object = this.doDecodeSync(); | ||
decoded = true; | ||
} | ||
catch (e) { | ||
if (!(e instanceof RangeError)) { | ||
throw e; // rethrow | ||
} | ||
// fallthrough | ||
} | ||
this.totalPos += this.pos; | ||
} | ||
catch (e) { | ||
if (!(e instanceof exports.DataViewIndexOutOfBoundsError)) { | ||
throw e; // rethrow | ||
if (decoded) { | ||
if (this.hasRemaining(1)) { | ||
throw this.createExtraByteError(this.totalPos); | ||
} | ||
// fallthrough | ||
return object; | ||
} | ||
this.totalPos += this.pos; | ||
const { headByte, pos, totalPos } = this; | ||
throw new RangeError(`Insufficient data in parsing ${(0, prettyByte_1.prettyByte)(headByte)} at ${totalPos} (${pos} in the current buffer)`); | ||
} | ||
if (decoded) { | ||
if (this.hasRemaining(1)) { | ||
throw this.createExtraByteError(this.totalPos); | ||
} | ||
return object; | ||
catch (e_3) { | ||
env_3.error = e_3; | ||
env_3.hasError = true; | ||
} | ||
const { headByte, pos, totalPos } = this; | ||
throw new RangeError(`Insufficient data in parsing ${(0, prettyByte_1.prettyByte)(headByte)} at ${totalPos} (${pos} in the current buffer)`); | ||
finally { | ||
__disposeResources(env_3); | ||
} | ||
} | ||
@@ -214,30 +340,47 @@ decodeArrayStream(stream) { | ||
async *decodeMultiAsync(stream, isArray) { | ||
let isArrayHeaderRequired = isArray; | ||
let arrayItemsLeft = -1; | ||
for await (const buffer of stream) { | ||
if (isArray && arrayItemsLeft === 0) { | ||
throw this.createExtraByteError(this.totalPos); | ||
const env_4 = { stack: [], error: void 0, hasError: false }; | ||
try { | ||
if (this.entered) { | ||
const instance = this.clone(); | ||
yield* instance.decodeMultiAsync(stream, isArray); | ||
return; | ||
} | ||
this.appendBuffer(buffer); | ||
if (isArrayHeaderRequired) { | ||
arrayItemsLeft = this.readArraySize(); | ||
isArrayHeaderRequired = false; | ||
this.complete(); | ||
} | ||
try { | ||
while (true) { | ||
yield this.doDecodeSync(); | ||
if (--arrayItemsLeft === 0) { | ||
break; | ||
// eslint-disable-next-line @typescript-eslint/no-unused-vars | ||
const _guard = __addDisposableResource(env_4, this.enteringGuard(), false); | ||
let isArrayHeaderRequired = isArray; | ||
let arrayItemsLeft = -1; | ||
for await (const buffer of stream) { | ||
if (isArray && arrayItemsLeft === 0) { | ||
throw this.createExtraByteError(this.totalPos); | ||
} | ||
this.appendBuffer(buffer); | ||
if (isArrayHeaderRequired) { | ||
arrayItemsLeft = this.readArraySize(); | ||
isArrayHeaderRequired = false; | ||
this.complete(); | ||
} | ||
try { | ||
while (true) { | ||
yield this.doDecodeSync(); | ||
if (--arrayItemsLeft === 0) { | ||
break; | ||
} | ||
} | ||
} | ||
} | ||
catch (e) { | ||
if (!(e instanceof exports.DataViewIndexOutOfBoundsError)) { | ||
throw e; // rethrow | ||
catch (e) { | ||
if (!(e instanceof RangeError)) { | ||
throw e; // rethrow | ||
} | ||
// fallthrough | ||
} | ||
// fallthrough | ||
this.totalPos += this.pos; | ||
} | ||
this.totalPos += this.pos; | ||
} | ||
catch (e_4) { | ||
env_4.error = e_4; | ||
env_4.hasError = true; | ||
} | ||
finally { | ||
__disposeResources(env_4); | ||
} | ||
} | ||
@@ -555,2 +698,5 @@ doDecodeSync() { | ||
} | ||
/** | ||
* @throws {@link RangeError} | ||
*/ | ||
decodeUtf8String(byteLength, headerOffset) { | ||
@@ -582,2 +728,5 @@ var _a; | ||
} | ||
/** | ||
* @throws {@link RangeError} | ||
*/ | ||
decodeBinary(byteLength, headOffset) { | ||
@@ -584,0 +733,0 @@ if (byteLength > this.maxBinLength) { |
@@ -71,4 +71,7 @@ import { ExtensionCodecType } from "./ExtensionCodec"; | ||
private bytes; | ||
private entered; | ||
constructor(options?: EncoderOptions<ContextType>); | ||
private clone; | ||
private reinitializeState; | ||
private enteringGuard; | ||
/** | ||
@@ -75,0 +78,0 @@ * This is almost equivalent to {@link Encoder#encode}, but it returns an reference of the encoder's internal buffer and thus much faster than {@link Encoder#encode}. |
"use strict"; | ||
var __addDisposableResource = (this && this.__addDisposableResource) || function (env, value, async) { | ||
if (value !== null && value !== void 0) { | ||
if (typeof value !== "object" && typeof value !== "function") throw new TypeError("Object expected."); | ||
var dispose, inner; | ||
if (async) { | ||
if (!Symbol.asyncDispose) throw new TypeError("Symbol.asyncDispose is not defined."); | ||
dispose = value[Symbol.asyncDispose]; | ||
} | ||
if (dispose === void 0) { | ||
if (!Symbol.dispose) throw new TypeError("Symbol.dispose is not defined."); | ||
dispose = value[Symbol.dispose]; | ||
if (async) inner = dispose; | ||
} | ||
if (typeof dispose !== "function") throw new TypeError("Object not disposable."); | ||
if (inner) dispose = function() { try { inner.call(this); } catch (e) { return Promise.reject(e); } }; | ||
env.stack.push({ value: value, dispose: dispose, async: async }); | ||
} | ||
else if (async) { | ||
env.stack.push({ async: true }); | ||
} | ||
return value; | ||
}; | ||
var __disposeResources = (this && this.__disposeResources) || (function (SuppressedError) { | ||
return function (env) { | ||
function fail(e) { | ||
env.error = env.hasError ? new SuppressedError(e, env.error, "An error was suppressed during disposal.") : e; | ||
env.hasError = true; | ||
} | ||
var r, s = 0; | ||
function next() { | ||
while (r = env.stack.pop()) { | ||
try { | ||
if (!r.async && s === 1) return s = 0, env.stack.push(r), Promise.resolve().then(next); | ||
if (r.dispose) { | ||
var result = r.dispose.call(r.value); | ||
if (r.async) return s |= 2, Promise.resolve(result).then(next, function(e) { fail(e); return next(); }); | ||
} | ||
else s |= 1; | ||
} | ||
catch (e) { | ||
fail(e); | ||
} | ||
} | ||
if (s === 1) return env.hasError ? Promise.reject(env.error) : Promise.resolve(); | ||
if (env.hasError) throw env.error; | ||
} | ||
return next(); | ||
}; | ||
})(typeof SuppressedError === "function" ? SuppressedError : function (error, suppressed, message) { | ||
var e = new Error(message); | ||
return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e; | ||
}); | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
@@ -13,2 +65,3 @@ exports.Encoder = exports.DEFAULT_INITIAL_BUFFER_SIZE = exports.DEFAULT_MAX_DEPTH = void 0; | ||
var _a, _b, _c, _d, _e, _f, _g, _h; | ||
this.entered = false; | ||
this.extensionCodec = (_a = options === null || options === void 0 ? void 0 : options.extensionCodec) !== null && _a !== void 0 ? _a : ExtensionCodec_1.ExtensionCodec.defaultCodec; | ||
@@ -27,5 +80,29 @@ this.context = options === null || options === void 0 ? void 0 : options.context; // needs a type assertion because EncoderOptions has no context property when ContextType is undefined | ||
} | ||
clone() { | ||
// Because of slightly special argument `context`, | ||
// type assertion is needed. | ||
// eslint-disable-next-line @typescript-eslint/no-unsafe-argument | ||
return new Encoder({ | ||
extensionCodec: this.extensionCodec, | ||
context: this.context, | ||
useBigInt64: this.useBigInt64, | ||
maxDepth: this.maxDepth, | ||
initialBufferSize: this.initialBufferSize, | ||
sortKeys: this.sortKeys, | ||
forceFloat32: this.forceFloat32, | ||
ignoreUndefined: this.ignoreUndefined, | ||
forceIntegerToFloat: this.forceIntegerToFloat, | ||
}); | ||
} | ||
reinitializeState() { | ||
this.pos = 0; | ||
} | ||
enteringGuard() { | ||
this.entered = true; | ||
return { | ||
[Symbol.dispose]: () => { | ||
this.entered = false; | ||
}, | ||
}; | ||
} | ||
/** | ||
@@ -37,5 +114,21 @@ * This is almost equivalent to {@link Encoder#encode}, but it returns an reference of the encoder's internal buffer and thus much faster than {@link Encoder#encode}. | ||
encodeSharedRef(object) { | ||
this.reinitializeState(); | ||
this.doEncode(object, 1); | ||
return this.bytes.subarray(0, this.pos); | ||
const env_1 = { stack: [], error: void 0, hasError: false }; | ||
try { | ||
if (this.entered) { | ||
const instance = this.clone(); | ||
return instance.encodeSharedRef(object); | ||
} | ||
// eslint-disable-next-line @typescript-eslint/no-unused-vars | ||
const _guard = __addDisposableResource(env_1, this.enteringGuard(), false); | ||
this.reinitializeState(); | ||
this.doEncode(object, 1); | ||
return this.bytes.subarray(0, this.pos); | ||
} | ||
catch (e_1) { | ||
env_1.error = e_1; | ||
env_1.hasError = true; | ||
} | ||
finally { | ||
__disposeResources(env_1); | ||
} | ||
} | ||
@@ -46,5 +139,21 @@ /** | ||
encode(object) { | ||
this.reinitializeState(); | ||
this.doEncode(object, 1); | ||
return this.bytes.slice(0, this.pos); | ||
const env_2 = { stack: [], error: void 0, hasError: false }; | ||
try { | ||
if (this.entered) { | ||
const instance = this.clone(); | ||
return instance.encode(object); | ||
} | ||
// eslint-disable-next-line @typescript-eslint/no-unused-vars | ||
const _guard = __addDisposableResource(env_2, this.enteringGuard(), false); | ||
this.reinitializeState(); | ||
this.doEncode(object, 1); | ||
return this.bytes.slice(0, this.pos); | ||
} | ||
catch (e_2) { | ||
env_2.error = e_2; | ||
env_2.hasError = true; | ||
} | ||
finally { | ||
__disposeResources(env_2); | ||
} | ||
} | ||
@@ -51,0 +160,0 @@ doEncode(object, depth) { |
@@ -25,3 +25,3 @@ "use strict"; | ||
// built-in extensions | ||
const index = 1 + type; | ||
const index = -1 - type; | ||
this.builtInEncoders[index] = encode; | ||
@@ -28,0 +28,0 @@ this.builtInDecoders[index] = decode; |
@@ -7,4 +7,4 @@ import { encode } from "./encode"; | ||
export { decodeAsync, decodeArrayStream, decodeMultiStream }; | ||
import { Decoder, DataViewIndexOutOfBoundsError } from "./Decoder"; | ||
export { Decoder, DataViewIndexOutOfBoundsError }; | ||
import { Decoder } from "./Decoder"; | ||
export { Decoder }; | ||
import type { DecoderOptions } from "./Decoder"; | ||
@@ -11,0 +11,0 @@ export type { DecoderOptions }; |
"use strict"; | ||
// Main Functions: | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.decodeTimestampExtension = exports.encodeTimestampExtension = exports.decodeTimestampToTimeSpec = exports.encodeTimeSpecToTimestamp = exports.encodeDateToTimeSpec = exports.EXT_TIMESTAMP = exports.ExtData = exports.ExtensionCodec = exports.Encoder = exports.DecodeError = exports.DataViewIndexOutOfBoundsError = exports.Decoder = exports.decodeMultiStream = exports.decodeArrayStream = exports.decodeAsync = exports.decodeMulti = exports.decode = exports.encode = void 0; | ||
exports.decodeTimestampExtension = exports.encodeTimestampExtension = exports.decodeTimestampToTimeSpec = exports.encodeTimeSpecToTimestamp = exports.encodeDateToTimeSpec = exports.EXT_TIMESTAMP = exports.ExtData = exports.ExtensionCodec = exports.Encoder = exports.DecodeError = exports.Decoder = exports.decodeMultiStream = exports.decodeArrayStream = exports.decodeAsync = exports.decodeMulti = exports.decode = exports.encode = void 0; | ||
const encode_1 = require("./encode"); | ||
@@ -16,3 +16,2 @@ Object.defineProperty(exports, "encode", { enumerable: true, get: function () { return encode_1.encode; } }); | ||
Object.defineProperty(exports, "Decoder", { enumerable: true, get: function () { return Decoder_1.Decoder; } }); | ||
Object.defineProperty(exports, "DataViewIndexOutOfBoundsError", { enumerable: true, get: function () { return Decoder_1.DataViewIndexOutOfBoundsError; } }); | ||
const DecodeError_1 = require("./DecodeError"); | ||
@@ -19,0 +18,0 @@ Object.defineProperty(exports, "DecodeError", { enumerable: true, get: function () { return DecodeError_1.DecodeError; } }); |
export declare function ensureUint8Array(buffer: ArrayLike<number> | Uint8Array<ArrayBufferLike> | ArrayBufferView | ArrayBufferLike): Uint8Array<ArrayBufferLike>; | ||
export declare function createDataView(buffer: ArrayLike<number> | ArrayBufferView | ArrayBuffer): DataView<ArrayBufferLike>; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.ensureUint8Array = ensureUint8Array; | ||
exports.createDataView = createDataView; | ||
function isArrayBuffer(buffer) { | ||
function isArrayBufferLike(buffer) { | ||
return (buffer instanceof ArrayBuffer || (typeof SharedArrayBuffer !== "undefined" && buffer instanceof SharedArrayBuffer)); | ||
@@ -15,3 +14,3 @@ } | ||
} | ||
else if (isArrayBuffer(buffer)) { | ||
else if (isArrayBufferLike(buffer)) { | ||
return new Uint8Array(buffer); | ||
@@ -24,9 +23,2 @@ } | ||
} | ||
function createDataView(buffer) { | ||
if (buffer instanceof ArrayBuffer) { | ||
return new DataView(buffer); | ||
} | ||
const bufferView = ensureUint8Array(buffer); | ||
return new DataView(bufferView.buffer, bufferView.byteOffset, bufferView.byteLength); | ||
} | ||
//# sourceMappingURL=typedArrays.js.map |
{ | ||
"name": "@msgpack/msgpack", | ||
"version": "3.0.0-beta4", | ||
"version": "3.0.0-beta5", | ||
"description": "MessagePack for ECMA-262/JavaScript/TypeScript", | ||
@@ -5,0 +5,0 @@ "author": "The MessagePack community", |
@@ -22,6 +22,3 @@ import { utf8DecodeJs } from "./utils/utf8"; | ||
constructor( | ||
maxKeyLength = DEFAULT_MAX_KEY_LENGTH, | ||
maxLengthPerKey = DEFAULT_MAX_LENGTH_PER_KEY, | ||
) { | ||
constructor(maxKeyLength = DEFAULT_MAX_KEY_LENGTH, maxLengthPerKey = DEFAULT_MAX_LENGTH_PER_KEY) { | ||
this.maxKeyLength = maxKeyLength; | ||
@@ -28,0 +25,0 @@ this.maxLengthPerKey = maxLengthPerKey; |
@@ -5,3 +5,3 @@ import { prettyByte } from "./utils/prettyByte"; | ||
import { utf8Decode } from "./utils/utf8"; | ||
import { createDataView, ensureUint8Array } from "./utils/typedArrays"; | ||
import { ensureUint8Array } from "./utils/typedArrays"; | ||
import { CachedKeyDecoder, KeyDecoder } from "./CachedKeyDecoder"; | ||
@@ -27,5 +27,5 @@ import { DecodeError } from "./DecodeError"; | ||
* string values will be returned as Uint8Arrays without additional decoding. | ||
* | ||
* | ||
* This is useful if the strings may contain invalid UTF-8 sequences. | ||
* | ||
* | ||
* Note that this option only applies to string values, not map keys. Additionally, when | ||
@@ -201,5 +201,4 @@ * enabled, raw string length is limited by the maxBinLength option. | ||
} | ||
export const DataViewIndexOutOfBoundsError = RangeError; | ||
const MORE_DATA = new DataViewIndexOutOfBoundsError("Insufficient data"); | ||
const MORE_DATA = new RangeError("Insufficient data"); | ||
@@ -228,2 +227,4 @@ const sharedCachedKeyDecoder = new CachedKeyDecoder(); | ||
private entered = false; | ||
public constructor(options?: DecoderOptions<ContextType>) { | ||
@@ -243,2 +244,18 @@ this.extensionCodec = options?.extensionCodec ?? (ExtensionCodec.defaultCodec as ExtensionCodecType<ContextType>); | ||
private clone(): Decoder<ContextType> { | ||
// eslint-disable-next-line @typescript-eslint/no-unsafe-argument | ||
return new Decoder({ | ||
extensionCodec: this.extensionCodec, | ||
context: this.context, | ||
useBigInt64: this.useBigInt64, | ||
rawStrings: this.rawStrings, | ||
maxStrLength: this.maxStrLength, | ||
maxBinLength: this.maxBinLength, | ||
maxArrayLength: this.maxArrayLength, | ||
maxMapLength: this.maxMapLength, | ||
maxExtLength: this.maxExtLength, | ||
keyDecoder: this.keyDecoder, | ||
} as any); | ||
} | ||
private reinitializeState() { | ||
@@ -253,4 +270,5 @@ this.totalPos = 0; | ||
private setBuffer(buffer: ArrayLike<number> | ArrayBufferView | ArrayBufferLike): void { | ||
this.bytes = ensureUint8Array(buffer); | ||
this.view = createDataView(this.bytes); | ||
const bytes = ensureUint8Array(buffer); | ||
this.bytes = bytes; | ||
this.view = new DataView(bytes.buffer, bytes.byteOffset, bytes.byteLength); | ||
this.pos = 0; | ||
@@ -283,2 +301,11 @@ } | ||
private enteringGuard(): Disposable { | ||
this.entered = true; | ||
return { | ||
[Symbol.dispose]: () => { | ||
this.entered = false; | ||
}, | ||
}; | ||
} | ||
/** | ||
@@ -289,2 +316,9 @@ * @throws {@link DecodeError} | ||
public decode(buffer: ArrayLike<number> | ArrayBufferView | ArrayBufferLike): unknown { | ||
if (this.entered) { | ||
const instance = this.clone(); | ||
return instance.decode(buffer); | ||
} | ||
// eslint-disable-next-line @typescript-eslint/no-unused-vars | ||
using _guard = this.enteringGuard(); | ||
this.reinitializeState(); | ||
@@ -300,3 +334,11 @@ this.setBuffer(buffer); | ||
public *decodeMulti(buffer: ArrayLike<number> | BufferSource): Generator<unknown, void, unknown> { | ||
public *decodeMulti(buffer: ArrayLike<number> | ArrayBufferView | ArrayBufferLike): Generator<unknown, void, unknown> { | ||
if (this.entered) { | ||
const instance = this.clone(); | ||
yield* instance.decodeMulti(buffer); | ||
return; | ||
} | ||
// eslint-disable-next-line @typescript-eslint/no-unused-vars | ||
using _guard = this.enteringGuard(); | ||
this.reinitializeState(); | ||
@@ -310,3 +352,10 @@ this.setBuffer(buffer); | ||
public async decodeAsync(stream: AsyncIterable<ArrayLike<number> | BufferSource>): Promise<unknown> { | ||
public async decodeAsync(stream: AsyncIterable<ArrayLike<number> | ArrayBufferView | ArrayBufferLike>): Promise<unknown> { | ||
if (this.entered) { | ||
const instance = this.clone(); | ||
return instance.decodeAsync(stream); | ||
} | ||
// eslint-disable-next-line @typescript-eslint/no-unused-vars | ||
using _guard = this.enteringGuard(); | ||
let decoded = false; | ||
@@ -316,2 +365,3 @@ let object: unknown; | ||
if (decoded) { | ||
this.entered = false; | ||
throw this.createExtraByteError(this.totalPos); | ||
@@ -326,3 +376,3 @@ } | ||
} catch (e) { | ||
if (!(e instanceof DataViewIndexOutOfBoundsError)) { | ||
if (!(e instanceof RangeError)) { | ||
throw e; // rethrow | ||
@@ -349,3 +399,3 @@ } | ||
public decodeArrayStream( | ||
stream: AsyncIterable<ArrayLike<number> | BufferSource>, | ||
stream: AsyncIterable<ArrayLike<number> | ArrayBufferView | ArrayBufferLike>, | ||
): AsyncGenerator<unknown, void, unknown> { | ||
@@ -355,7 +405,15 @@ return this.decodeMultiAsync(stream, true); | ||
public decodeStream(stream: AsyncIterable<ArrayLike<number> | BufferSource>): AsyncGenerator<unknown, void, unknown> { | ||
public decodeStream(stream: AsyncIterable<ArrayLike<number> | ArrayBufferView | ArrayBufferLike>): AsyncGenerator<unknown, void, unknown> { | ||
return this.decodeMultiAsync(stream, false); | ||
} | ||
private async *decodeMultiAsync(stream: AsyncIterable<ArrayLike<number> | BufferSource>, isArray: boolean) { | ||
private async *decodeMultiAsync(stream: AsyncIterable<ArrayLike<number> | ArrayBufferView | ArrayBufferLike>, isArray: boolean): AsyncGenerator<unknown, void, unknown> { | ||
if (this.entered) { | ||
const instance = this.clone(); | ||
yield* instance.decodeMultiAsync(stream, isArray); | ||
return; | ||
} | ||
// eslint-disable-next-line @typescript-eslint/no-unused-vars | ||
using _guard = this.enteringGuard(); | ||
let isArrayHeaderRequired = isArray; | ||
@@ -385,3 +443,3 @@ let arrayItemsLeft = -1; | ||
} catch (e) { | ||
if (!(e instanceof DataViewIndexOutOfBoundsError)) { | ||
if (!(e instanceof RangeError)) { | ||
throw e; // rethrow | ||
@@ -675,2 +733,5 @@ } | ||
/** | ||
* @throws {@link RangeError} | ||
*/ | ||
private decodeUtf8String(byteLength: number, headerOffset: number): string { | ||
@@ -706,2 +767,5 @@ if (byteLength > this.maxStrLength) { | ||
/** | ||
* @throws {@link RangeError} | ||
*/ | ||
private decodeBinary(byteLength: number, headOffset: number): Uint8Array { | ||
@@ -708,0 +772,0 @@ if (byteLength > this.maxBinLength) { |
@@ -89,2 +89,4 @@ import { utf8Count, utf8Encode } from "./utils/utf8"; | ||
private entered = false; | ||
public constructor(options?: EncoderOptions<ContextType>) { | ||
@@ -107,2 +109,19 @@ this.extensionCodec = options?.extensionCodec ?? (ExtensionCodec.defaultCodec as ExtensionCodecType<ContextType>); | ||
private clone() { | ||
// Because of slightly special argument `context`, | ||
// type assertion is needed. | ||
// eslint-disable-next-line @typescript-eslint/no-unsafe-argument | ||
return new Encoder<ContextType>({ | ||
extensionCodec: this.extensionCodec, | ||
context: this.context, | ||
useBigInt64: this.useBigInt64, | ||
maxDepth: this.maxDepth, | ||
initialBufferSize: this.initialBufferSize, | ||
sortKeys: this.sortKeys, | ||
forceFloat32: this.forceFloat32, | ||
ignoreUndefined: this.ignoreUndefined, | ||
forceIntegerToFloat: this.forceIntegerToFloat, | ||
} as any); | ||
} | ||
private reinitializeState() { | ||
@@ -112,2 +131,11 @@ this.pos = 0; | ||
private enteringGuard(): Disposable { | ||
this.entered = true; | ||
return { | ||
[Symbol.dispose]: () => { | ||
this.entered = false; | ||
}, | ||
}; | ||
} | ||
/** | ||
@@ -119,2 +147,9 @@ * This is almost equivalent to {@link Encoder#encode}, but it returns an reference of the encoder's internal buffer and thus much faster than {@link Encoder#encode}. | ||
public encodeSharedRef(object: unknown): Uint8Array { | ||
if (this.entered) { | ||
const instance = this.clone(); | ||
return instance.encodeSharedRef(object); | ||
} | ||
// eslint-disable-next-line @typescript-eslint/no-unused-vars | ||
using _guard = this.enteringGuard(); | ||
this.reinitializeState(); | ||
@@ -129,2 +164,9 @@ this.doEncode(object, 1); | ||
public encode(object: unknown): Uint8Array { | ||
if (this.entered) { | ||
const instance = this.clone(); | ||
return instance.encode(object); | ||
} | ||
// eslint-disable-next-line @typescript-eslint/no-unused-vars | ||
using _guard = this.enteringGuard(); | ||
this.reinitializeState(); | ||
@@ -131,0 +173,0 @@ this.doEncode(object, 1); |
@@ -60,3 +60,3 @@ // ExtensionCodec to handle MessagePack extensions | ||
// built-in extensions | ||
const index = 1 + type; | ||
const index = -1 - type; | ||
this.builtInEncoders[index] = encode; | ||
@@ -63,0 +63,0 @@ this.builtInDecoders[index] = decode; |
@@ -12,4 +12,4 @@ // Main Functions: | ||
import { Decoder, DataViewIndexOutOfBoundsError } from "./Decoder"; | ||
export { Decoder, DataViewIndexOutOfBoundsError }; | ||
import { Decoder } from "./Decoder"; | ||
export { Decoder }; | ||
import type { DecoderOptions } from "./Decoder"; | ||
@@ -16,0 +16,0 @@ export type { DecoderOptions }; |
@@ -1,2 +0,2 @@ | ||
function isArrayBuffer(buffer: unknown): buffer is ArrayBuffer | SharedArrayBuffer { | ||
function isArrayBufferLike(buffer: unknown): buffer is ArrayBufferLike { | ||
return ( | ||
@@ -14,3 +14,3 @@ buffer instanceof ArrayBuffer || (typeof SharedArrayBuffer !== "undefined" && buffer instanceof SharedArrayBuffer) | ||
return new Uint8Array(buffer.buffer, buffer.byteOffset, buffer.byteLength); | ||
} else if (isArrayBuffer(buffer)) { | ||
} else if (isArrayBufferLike(buffer)) { | ||
return new Uint8Array(buffer); | ||
@@ -22,10 +22,1 @@ } else { | ||
} | ||
export function createDataView(buffer: ArrayLike<number> | ArrayBufferView | ArrayBuffer): DataView<ArrayBufferLike> { | ||
if (buffer instanceof ArrayBuffer) { | ||
return new DataView(buffer); | ||
} | ||
const bufferView = ensureUint8Array(buffer); | ||
return new DataView(bufferView.buffer, bufferView.byteOffset, bufferView.byteLength); | ||
} |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
761711
8.5%9249
12.38%