-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmsgpack.min.js
2 lines (2 loc) · 13.9 KB
/
msgpack.min.js
1
2
/// micro msgpack library | version 1.3.7 | by Codesmith32 | license: MIT / https://mit-license.org | https://github.com/CodeSmith32/msgpack-js-micro
!function(r){var e="function"==typeof r.Uint8Array&&"function"==typeof r.ArrayBuffer,n="function"==typeof r.Buffer,t="function"==typeof r.BigInt,i=r.Uint8Array||function(){},o=r.ArrayBuffer||function(){},u=r.DataView||function(){},f=r.Buffer||function(){},a=r.BigInt||function(){},c=r.BigInt?{bits:r.BigInt(32),mask:r.BigInt(4294967295)}:{},s=e&&new r.Uint8Array(4),d=e&&new r.Float32Array(s.buffer),g=e&&new r.Uint8Array(8),l=e&&new r.Float64Array(g.buffer),b=e&&1===new Uint32Array(new i([1,0,0,0]).buffer)[0],h=Object.prototype.hasOwnProperty,y=function(r,e){return h.call(e,r)},p=function(){try{return Object.defineProperty.bind(Object)}catch(r){return function(r,e,n){r[e]=n.value}}}(),w=Object.create?function(){return Object.create(null)}:function(){return{}};try{"name"in Function.prototype||Object.defineProperty(Function.prototype,"name",{get:function(){return this.toString().match(/function\s*([^\s(]*)/)[1]}})}catch(r){Function.prototype.name=""}function E(r){if("string"==typeof r)return r;if(n&&r instanceof f)return r.toString("latin1");if(r&&r.constructor&&!(r instanceof i)&&r.constructor.name.match(/^(Big)?(Uint|Int|Float)(8|16|32|64)(Clamped)?Array$/)&&(r=new i(r.buffer,r.byteOffset,r.byteLength)),r instanceof o&&(r=new i(r)),r instanceof u&&(r=new i(r.buffer)),r instanceof i){for(var e="",t=0;t<r.length;t+=128)e+=String.fromCharCode.apply(null,r.subarray(t,t+128));return e}throw new Error("MsgPack Error: Cannot normalize to string for value of type "+typeof r+(r?" "+r.constructor.name:""))}function v(r,t){switch(t){case"buffer":if(n)return f.from(r,"latin1");case"arraybuffer":return function(r){if(!e)throw new Error("MsgPack Error: Requesting ArrayBuffer return in environment that doesn't support TypedArrays or ArrayBuffers");for(var n=new i(r.length),t=0;t<r.length;t++)n[t]=r.charCodeAt(t);return n.buffer}(r)}return r}Array.isArray||(Array.isArray=function(r){return"[object Array]"===Object.prototype.toString.call(r)}),[].indexOf||(Array.prototype.indexOf=function(r,e){var n=this.length>>>0;for((e=0|+e||0)<0&&(e+=n);e<n;e++)if(e in this&&this[e]===r)return e;return-1});var m=Math.log,k=m(2),x=m(10),C=(Math.log10,Math.log2||function(r){return m(r)/k}),A=Math.abs,M=Math.floor,P=Math.round,T=Math.pow,j=T(2,149),I=T(2,1022),B=T(2,52);function F(r){var n=this;if(!(n instanceof F))throw new Error("Bad instantiation of object msgpack::BinReader");var t=0;function i(e){if(t+e>r.length)throw new Error("MsgPack Error: Unexpected end of data")}function o(e){return 255&r.charCodeAt(t++)}r=E(r),n.ui8=function(){return i(1),o()},n.i8=function(){i(1);var r=o();return 128&r&&(r|=-256),r},n.ui16=function(){return i(2),256*o()+o()},n.i16=function(){i(2);var r=256*o()+o();return 32768&r&&(r|=-65536),r},n.ui32=function(){return i(4),16777216*o()+65536*o()+256*o()+o()>>>0},n.i32=function(){return i(4),16777216*o()+65536*o()+256*o()+o()>>0},n.ui64=function(r){return r?(a(n.ui32())<<c.bits)+a(n.ui32()):4294967296*n.ui32()+n.ui32()},n.i64=function(r){return(r?a(n.i32())<<c.bits:4294967296*n.i32())+(r?a(n.ui32()):n.ui32())},e?(n.f32=function(){if(i(4),b)for(var r=3;r>=0;r--)s[r]=o();else for(r=0;r<4;r++)s[r]=o();return d[0]},n.f64=function(){if(i(8),b)for(var r=7;r>=0;r--)g[r]=o();else for(r=0;r<8;r++)g[r]=o();return l[0]}):(n.f32=function(){i(4);var r=16777216*o()+65536*o()+256*o()+o(),e=!!(2147483648&r),n=r>>23&255,t=8388607&r;return 255===n?0===t?e?-1/0:1/0:NaN:0===n?t/j:(t+=8388608)*(e?-1:1)*T(2,n-127-23)},n.f64=function(){i(8);var r=16777216*o()+65536*o()+256*o()+o(),e=!!(2147483648&r),n=r>>20&2047,t=4294967296*(1048575&r)+(16777216*o()+65536*o()+256*o()+o());return 2047===n?0===t?e?-1/0:1/0:NaN:0===n?t/I/B:(t/B+1)*(e?-1:1)*T(2,n-1023)}),n.buf=function(e){i(e);var n=r.slice(t,t+e);return t+=e,n},n.eof=function(){return t>=r.length}}function N(){var r=this;if(!(r instanceof N))throw new Error("Bad instantiation of object msgpack::BinWriter");var n="";function t(r){n+=String.fromCharCode(255&r)}r.i8=function(e){return t(e),r},r.i16=function(e){return t(e>>8),t(e),r},r.i32=function(e){return t(e>>24),t(e>>16),t(e>>8),t(e),r},r.i64=function(e){return r.i32(M(e/4294967296)).i32(e),r},e?(r.f32=function(r){if(d[0]=r,b)for(var e=3;e>=0;e--)t(s[e]);else for(e=0;e<4;e++)t(s[e])},r.f64=function(r){if(l[0]=r,b)for(var e=7;e>=0;e--)t(g[e]);else for(e=0;e<8;e++)t(g[e])}):(r.f32=function(e){if(isNaN(e))return n+="À\0\0",r;if(e===1/0)return n+="\0\0",r;if(e===-1/0)return n+="ÿ\0\0",r;if(0===e)return n+="\0\0\0\0",r;var i=e<0,o=i?-e:e,u=M(C(o)),f=P(o*T(2,23-u))-8388608;return u+=127,f>8388607&&(u++,f&=8388607),u>254?(n+=i?"ÿ\0\0":"\0\0",r):(u<=0&&(u=0,f=P(o*j)),t(i<<7|u>>1&127),t(u<<7|f>>16&127),t(f>>8),t(f),r)},r.f64=function(e){if(isNaN(e))return n+="ø\0\0\0\0\0\0",r;if(e===1/0)return n+="ð\0\0\0\0\0\0",r;if(e===-1/0)return n+="ÿð\0\0\0\0\0\0",r;if(0===e)return n+="\0\0\0\0\0\0\0\0",r;var i=e<0,o=i?-e:e,u=M(C(o)),f=P(u>0?o*T(2,52-u):o*T(2,52)*T(2,-u))-4503599627370496;return u+=1023,f>0x80000000000000&&(u++,f-=0x80000000000000),u>2046?(n+=i?"ÿð\0\0\0\0\0\0":"ð\0\0\0\0\0\0",r):(u<=0&&(u=0,f=P(o*I*B)),t(i<<7|u>>4&127),t(u<<4|f/281474976710656&15),t(f/1099511627776),t(f/4294967296),t(f/16777216),t(f/65536),t(f/256),t(f),r)}),r.buf=function(e){return n+=e,r},r.data=function(){return n}}function D(r,e){var n=this;if(!(n instanceof D))throw new Error("Bad instantiation of object msgpack");var i=w(),o=w();n.extend=function(r){var e=r.type,n=r.varType||"object",t=r.encode,u=r.decode,f={enc:t,dec:u,ty:e};if("number"!=typeof e||e<0||e>127)throw new Error("MsgPack Error: Failed to add extension with type code: "+typeof e+" "+ +e);if("function"!=typeof t)throw new Error("MsgPack Error: Failed to add extension; missing 'encode' function");if("function"!=typeof u)throw new Error("MsgPack Error: Failed to add extension; missing 'decode' function");if(y(e,o))throw new Error("MsgPack Error: Failed to register extension with code "+e+"; extension code already in use");(i[n]=i[n]||[]).push(f),o[e]=f};var u={string:0,buffer:0,arraybuffer:0},f={utf8:0,latin1:0},a={returnType:"string",stringEncoding:"utf8",useDoubles:!0};n.encode=function(r,e){var n=y("returnType",e=e||{})?e.returnType.toLowerCase():a.returnType,t=y("stringEncoding",e)?e.stringEncoding.toLowerCase():a.stringEncoding,o=y("useDoubles",e)?!!e.useDoubles:a.useDoubles,u=new N,f=[];return function r(e){var n=typeof e;if(y(n,i))for(var a,s,d=0;d<i[n].length;d++)if(!1!==(s=(a=i[n][d]).enc(e))){if(null==s)throw new Error("MsgPack Error: Extension code "+a.ty+" failed to return a valid buffer");return 1===(s=E(s)).length?u.i8(212):2===s.length?u.i8(213):4===s.length?u.i8(214):8===s.length?u.i8(215):16===s.length?u.i8(216):s.length<256?u.i8(199).i8(s.length):s.length<65536?u.i8(200).i16(s.length):u.i8(201).i32(s.length),void u.i8(a.ty).buf(s)}if("bigint"===n&&e<=4294967295&&(e=Number(e),n="number"),e&&"function"==typeof e.constructor&&e.constructor.name.match(/^(Big)?(Uint|Int|Float)(8|16|32|64)(Clamped)?Array$|^(ArrayBuffer|Buffer|DataView)$/))(e=E(e)).length<256?u.i8(196).i8(e.length).buf(e):e.length<65536?u.i8(197).i16(e.length).buf(e):u.i8(198).i32(e.length).buf(e);else if(null==e)u.i8(192);else if("boolean"===n)u.i8(194+e);else if("number"===n)e===-1/0||e===1/0||isNaN(e)||M(e)!==e?o&&function(r){if(r===-1/0||r===1/0||isNaN(r))return!1;r=A(r);var e=C(r);return e<-120||e>120||(r/=T(2,M(e)-23))!==M(r)}(e)?u.i8(203).f64(e):u.i8(202).f32(e):e<0?e>=-32?u.i8(e):e>=-128?u.i8(208).i8(e):e>=-32768?u.i8(209).i16(e):e>=-2147483648?u.i8(210).i32(e):u.i8(211).i64(e):e<128?u.i8(e):e<256?u.i8(204).i8(e):e<65536?u.i8(205).i16(e):e<=4294967295?u.i8(206).i32(e):u.i8(207).i64(e);else if("bigint"===n)u.i8(e<0?211:207),u.i32(Number(e>>c.bits)).i32(Number(e&c.mask));else if("string"===n)"utf8"===t?e=e.replace(/[\x80-\uffff]/g,(function(r){return(r=r.charCodeAt())<2048?String.fromCharCode(192|r>>6,128|63&r):String.fromCharCode(224|r>>12&15,128|r>>6&63,128|63&r)})):e=function(r){return r.replace(/[\u0100-\uffff]/g,(function(r){return String.fromCharCode(255&r.charCodeAt(0))}))}(e),e.length<32?u.i8(160|e.length).buf(e):e.length<256?u.i8(217).i8(e.length).buf(e):e.length<65536?u.i8(218).i16(e.length).buf(e):u.i8(219).i32(e.length).buf(e);else{if("object"!==n)throw new Error("MsgPack Error: Failed to encode element of type "+n);if(f.indexOf(e)>-1)throw new Error("MsgPack Error: Failed to encode object with recursive properties");if(f.push(e),Array.isArray(e)){e.length<16?u.i8(144|e.length):e.length<65536?u.i8(220).i16(e.length):u.i8(221).i32(e.length);for(d=0;d<e.length;d++)r(e[d])}else{var g=0;for(var d in e)y(d,e)&&void 0!==e[d]&&g++;for(var d in g<16?u.i8(128|g):g<65536?u.i8(222).i16(g):u.i8(223).i32(g),e)if(y(d,e)&&void 0!==e[d]&&(r(d),r(e[d]),--g<0))throw new Error("MsgPack Error: Failed to encode malformed Proxy object");if(g)throw new Error("MsgPack Error: Failed to encode malformed Proxy object")}f.pop()}}(r),v(u.data(),n)},n.encode.defaults=function(r){if("string"==typeof r){if(y(r,a))return a[r];throw new Error("Unknown encode setting name: "+r)}if("object"!=typeof r)throw new Error("Could not set encode defaults with non-object setting input");if(y("returnType",r)){if("string"!=typeof r.returnType||!y(r.returnType,u))throw new Error("MsgPack Error: Invalid encode default value for returnType");a.returnType=r.returnType}if(y("stringEncoding",r)){if("string"!=typeof r.stringEncoding||!y(r.stringEncoding,f))throw new Error("MsgPack Error: Invalid encode default value for stringEncoding");a.stringEncoding=r.stringEncoding}if(y("useDoubles",r)){if("boolean"!=typeof r.useDoubles)throw new Error("MsgPack Error: Invalid encode default value for useDoubles");a.useDoubles=r.useDoubles}};var s={binaryType:"string",stringEncoding:"utf8",bigInts:!1};n.decode=function(r,e){var n=y("binaryType",e=e||{})?e.binaryType.toLowerCase():s.binaryType,i=y("stringEncoding",e)?e.stringEncoding.toLowerCase():s.stringEncoding,u=t&&(y("bigInts",e)?!!e.bigInts:s.bigInts),f=new F(r);function a(r){for(var e={},n=0;n<r;n++){var t=b(),i=b();"__proto__"===t?p(e,t,{enumerable:!0,configurable:!0,writable:!0,value:i}):e[t]=i}return e}function c(r){for(var e=[],n=0;n<r;n++)e.push(b());return e}function d(r){return v(r,n)}function g(r){return"utf8"===i?function(r){return r.replace(/([\xc0-\xdf][\x80-\xbf])|([\xe0-\xef][\x80-\xbf]{2})|([\xf0-\xf7][\x80-\xbf]{3})/g,(function(r,e,n,t){var i=r.charCodeAt(0),o=r.charCodeAt(1),u=r.length>2&&r.charCodeAt(2),f=r.length>3&&r.charCodeAt(3);return e?String.fromCharCode((31&i)<<6|63&o):n?String.fromCharCode((15&i)<<12|(63&o)<<6|63&u):t?String.fromCharCode((7&i)<<18|(63&o)<<12|(63&u)<<6|63&f):void 0}))}(r):r}function l(r,e){return y(r,o)?o[r].dec(e):(console.warn("MsgPack Warning: Failed to decode unregistered extension type "+r),null)}function b(){var r,e=f.ui8();if(0==(128&e))return e;if(224==(224&e))return-256|e;if(128==(240&e))return a(15&e);if(144==(240&e))return c(15&e);if(160==(224&e))return g(f.buf(31&e));switch(e){case 193:throw new Error("MsgPack Error: Encountered reserved type 0xc1");case 192:return null;case 194:return!1;case 195:return!0;case 196:return d(f.buf(f.ui8()));case 197:return d(f.buf(f.ui16()));case 198:return d(f.buf(f.ui32()));case 199:return r=f.ui8(),l(f.i8(),f.buf(r));case 200:return r=f.ui16(),l(f.i8(),f.buf(r));case 201:return r=f.ui32(),l(f.i8(),f.buf(r));case 202:return f.f32();case 203:return f.f64();case 204:return f.ui8();case 205:return f.ui16();case 206:return f.ui32();case 207:return f.ui64(u);case 208:return f.i8();case 209:return f.i16();case 210:return f.i32();case 211:return f.i64(u);case 212:return l(f.i8(),f.buf(1));case 213:return l(f.i8(),f.buf(2));case 214:return l(f.i8(),f.buf(4));case 215:return l(f.i8(),f.buf(8));case 216:return l(f.i8(),f.buf(16));case 217:return g(f.buf(f.ui8()));case 218:return g(f.buf(f.ui16()));case 219:return g(f.buf(f.ui32()));case 220:return c(f.ui16());case 221:return c(f.ui32());case 222:return a(f.ui16());case 223:return a(f.ui32())}throw new Error("MsgPack Error: Somehow encountered unknown byte code: "+e)}var h=b();if(!f.eof())throw new Error("MsgPack Error: Trying to decode more data than expected");return h},n.decode.defaults=function(r){if("string"==typeof r){if(y(r,s))return s[r];throw new Error("Unknown decode setting name: "+r)}if("object"!=typeof r)throw new Error("Could not set decode defaults with non-object setting input");if(y("binaryType",r)){if("string"!=typeof r.binaryType||!y(r.binaryType,u))throw new Error("MsgPack Error: Invalid decode default value for binaryType");s.binaryType=r.binaryType}if(y("stringEncoding",r)){if("string"!=typeof r.stringEncoding||!y(r.stringEncoding,f))throw new Error("MsgPack Error: Invalid decode default value for stringEncoding");s.stringEncoding=r.stringEncoding}if(y("bigInts",r)){if("boolean"!=typeof r.bigInts)throw new Error("MsgPack Error: Non-boolean decode default value for bigInts");s.bigInts=r.bigInts}},function(r){var e=r.type,n=r.varType||"object",t={enc:r.encode,dec:r.decode,ty:e};if(e>=0)throw new Error("MsgPack Error: Failed to add core extension; type code must be negative: "+ +e);(i[n]=i[n]||[]).push(t),o[e]=t}({type:-1,encode:function(r){if("[object Date]"!==Object.prototype.toString.call(r)||"function"!=typeof r.getTime)return!1;var e=r.getTime();if("number"!=typeof e)return!1;var n=e/1e3|0,t=1e6*(e-1e3*n),i=new N;return n<0||n>17179869183?i.i32(t).i64(n):t||n>4294967295?i.i32(4*t+(n/4294967296&3)).i32(n):i.i32(n),i.data()},decode:function(r){var e=new Date,n=new F(r),t=0,i=0;switch(r.length){case 4:t=n.ui32();break;case 8:i=n.ui32(),t=n.ui32()+4294967296*(3&i),i=M(i/4);break;case 12:i=n.ui32(),t=n.i64();break;default:throw new Error("MsgPack Error: Failed to decode Timestamp: Unknown timestamp encoding version with length "+r.length)}return e.setTime(1e3*t+i/1e6),e}}),r&&"object"==typeof r&&n.encode.defaults(r),e&&"object"==typeof e&&n.decode.defaults(e)}var O=new D;D.extend=O.extend,D.encode=O.encode,D.decode=O.decode,"object"==typeof module&&"object"==typeof module.exports?module.exports=D:r.msgpack=D}("undefined"!=typeof window?window:"undefined"!=typeof global?global:this);