"use strict";function _createForOfIteratorHelper(r,e){var t="undefined"!=typeof Symbol&&r[Symbol.iterator]||r["@@iterator"];if(!t){if(Array.isArray(r)||(t=_unsupportedIterableToArray(r))||e&&r&&"number"==typeof r.length){t&&(r=t);var a=0,n=function(){};return{s:n,n:function(){return a>=r.length?{done:!0}:{done:!1,value:r[a++]}},e:function(r){throw r},f:n}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}var i,o=!0,f=!1;return{s:function(){t=t.call(r)},n:function(){var r=t.next();return o=r.done,r},e:function(r){f=!0,i=r},f:function(){try{o||null==t.return||t.return()}finally{if(f)throw i}}}}function _unsupportedIterableToArray(r,e){if(r){if("string"==typeof r)return _arrayLikeToArray(r,e);var t=Object.prototype.toString.call(r).slice(8,-1);return"Object"===t&&r.constructor&&(t=r.constructor.name),"Map"===t||"Set"===t?Array.from(r):"Arguments"===t||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t)?_arrayLikeToArray(r,e):void 0}}function _arrayLikeToArray(r,e){(null==e||e>r.length)&&(e=r.length);for(var t=0,a=new Array(e);t0&&void 0!==arguments[0]?arguments[0]:"";return"02"+"".concat(Date.now())+(cachedIP||(cachedIP=IPToIPv6(r)))+Math.random().toString(16).slice(-6)}function genLogID(){return 1e4*Date.now()+Math.floor(1e4*Math.random())}function ocetToBinary(r){return(Array(8).join("0")+parseInt(r,10).toString(2)).slice(-8)}function binaryToHex(r){return(Array(4).join("0")+parseInt(r,2).toString(16)).slice(-4)}function IPv4ToIPv6(r){var e=r.split(/\./).map(function(r){return ocetToBinary(r)}),t=[];return t[0]=binaryToHex(e[0]+e[1]),t[1]=binaryToHex(e[2]+e[3]),["0000","0000","0000","0000","0000","ffff",t[0],t[1]].join("")}function IPToIPv6(r){var e=/(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)(\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)){3}/.test(r),t=/(([0-9a-fA-F]{1,4}:){7,7}[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,7}:|([0-9a-fA-F]{1,4}:){1,6}:[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,5}(:[0-9a-fA-F]{1,4}){1,2}|([0-9a-fA-F]{1,4}:){1,4}(:[0-9a-fA-F]{1,4}){1,3}|([0-9a-fA-F]{1,4}:){1,3}(:[0-9a-fA-F]{1,4}){1,4}|([0-9a-fA-F]{1,4}:){1,2}(:[0-9a-fA-F]{1,4}){1,5}|[0-9a-fA-F]{1,4}:((:[0-9a-fA-F]{1,4}){1,6})|:((:[0-9a-fA-F]{1,4}){1,7}|:)|fe80:(:[0-9a-fA-F]{0,4}){0,4}%[0-9a-zA-Z]{1,}|::(ffff(:0{1,4}){0,1}:){0,1}((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])|([0-9a-fA-F]{1,4}:){1,4}:((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9]))/.test(r);return e?IPv4ToIPv6(r):t?formatIpv6Address(r):"00000000000000000000000000000000"}function formatIpv6Address(r){var e="",t=[],a=0,n=0,i=!0,o="0000";if(r.indexOf("::")>-1){for(var f=r.split("::"),d=0;d0){var s=c.split(":");i&&(a=s.length),n+=s.length;for(var u=0;u>>3){case 0:break r;case 1:e.key=readString(r,readVarint32(r));break;case 2:e.value=readString(r,readVarint32(r));break;default:skipUnknownField(r,7&t)}}if(void 0===e.key)throw new Error("Missing required field: key");if(void 0===e.value)throw new Error("Missing required field: value");return e}function encodeFrame$1(r){var e=popByteBuffer();return _encodeFrame(r,e),toUint8Array(e)}function _encodeFrame(r,e){var t=r.SeqID;void 0!==t&&(writeVarint32(e,8),writeVarint64(e,t));var a=r.LogID;void 0!==a&&(writeVarint32(e,16),writeVarint64(e,a));var n=r.service;void 0!==n&&(writeVarint32(e,24),writeVarint64(e,intToLong(n)));var i=r.method;void 0!==i&&(writeVarint32(e,32),writeVarint64(e,intToLong(i)));var o=r.headers;if(void 0!==o){var f,d=_createForOfIteratorHelper(o);try{for(d.s();!(f=d.n()).done;){var c=f.value;writeVarint32(e,42);var s=popByteBuffer();_encodeHeader(c,s),writeVarint32(e,s.limit),writeByteBuffer(e,s),pushByteBuffer(s)}}catch(r){d.e(r)}finally{d.f()}}var u=r.payloadEncoding;void 0!==u&&(writeVarint32(e,50),writeString(e,u));var v=r.payloadType;void 0!==v&&(writeVarint32(e,58),writeString(e,v));var l=r.payload;void 0!==l&&(writeVarint32(e,66),writeVarint32(e,l.length),writeBytes(e,l));var y=r.LogIDNew;void 0!==y&&(writeVarint32(e,74),writeString(e,y))}function decodeFrame(r){return _decodeFrame(wrapByteBuffer(r))}function _decodeFrame(r){var e={};r:for(;!isAtEnd(r);){var t=readVarint32(r);switch(t>>>3){case 0:break r;case 1:e.SeqID=readVarint64(r,!0);break;case 2:e.LogID=readVarint64(r,!0);break;case 3:e.service=readVarint32(r);break;case 4:e.method=readVarint32(r);break;case 5:var a=pushTemporaryLength(r);(e.headers||(e.headers=[])).push(_decodeHeader(r)),r.limit=a;break;case 6:e.payloadEncoding=readString(r,readVarint32(r));break;case 7:e.payloadType=readString(r,readVarint32(r));break;case 8:e.payload=readBytes(r,readVarint32(r));break;case 9:e.LogIDNew=readString(r,readVarint32(r));break;default:skipUnknownField(r,7&t)}}if(void 0===e.SeqID)throw new Error("Missing required field: SeqID");if(void 0===e.LogID)throw new Error("Missing required field: LogID");if(void 0===e.service)throw new Error("Missing required field: service");if(void 0===e.method)throw new Error("Missing required field: method");return e}function pushTemporaryLength(r){var e=readVarint32(r),t=r.limit;return r.limit=r.offset+e,t}function skipUnknownField(r,e){switch(e){case 0:for(;128&readByte(r););break;case 2:skip(r,readVarint32(r));break;case 5:skip(r,4);break;case 1:skip(r,8);break;default:throw new Error("Unimplemented type: "+e)}}function intToLong(r){return{low:r|=0,high:r>>31,unsigned:r>=0}}var bbStack=[];function popByteBuffer(){var r=bbStack.pop();return r?(r.offset=r.limit=0,r):{bytes:new Uint8Array(64),offset:0,limit:0}}function pushByteBuffer(r){bbStack.push(r)}function wrapByteBuffer(r){return{bytes:r,offset:0,limit:r.length}}function toUint8Array(r){var e=r.bytes,t=r.limit;return e.length===t?e:e.subarray(0,t)}function skip(r,e){if(r.offset+e>r.limit)throw new Error("Skip past limit");r.offset+=e}function isAtEnd(r){return r.offset>=r.limit}function grow(r,e){var t=r.bytes,a=r.offset,n=r.limit,i=a+e;if(i>t.length){var o=new Uint8Array(2*i);o.set(t),r.bytes=o}return r.offset=i,i>n&&(r.limit=i),a}function advance(r,e){var t=r.offset;if(t+e>r.limit)throw new Error("Read past limit");return r.offset+=e,t}function readBytes(r,e){var t=advance(r,e);return r.bytes.subarray(t,t+e)}function writeBytes(r,e){var t=grow(r,e.length);r.bytes.set(e,t)}function readString(r,e){for(var t=advance(r,e),a=String.fromCharCode,n=r.bytes,i="�",o="",f=0;f=e||128!=(192&(c=n[f+t+1]))||(v=(31&d)<<6|63&c)<128?o+=i:(o+=a(v),f++):224==(240&d)?f+2>=e||32896!=(49344&((c=n[f+t+1])|(s=n[f+t+2])<<8))||(v=(15&d)<<12|(63&c)<<6|63&s)<2048||v>=55296&&v<=57343?o+=i:(o+=a(v),f+=2):240==(248&d)?f+3>=e||8421504!=(12632256&((c=n[f+t+1])|(s=n[f+t+2])<<8|(u=n[f+t+3])<<16))||(v=(7&d)<<18|(63&c)<<12|(63&s)<<6|63&u)<65536||v>1114111?o+=i:(o+=a(55296+((v-=65536)>>10),56320+(1023&v)),f+=3):o+=i:o+=a(d)}return o}function writeString(r,e){for(var t=e.length,a=0,n=0;n=55296&&i<=56319&&n+1=55296&&c<=56319&&d+1>6&31|192:(c<65536?f[o++]=c>>12&15|224:(f[o++]=c>>18&7|240,f[o++]=c>>12&63|128),f[o++]=c>>6&63|128),f[o++]=63&c|128)}}function writeByteBuffer(r,e){for(var t=grow(r,e.limit),a=r.bytes,n=e.bytes,i=0,o=e.limit;i>>=0;e>=128;)writeByte(r,127&e|128),e>>>=7;writeByte(r,e)}function readVarint64(r,e){var t,a=0,n=0,i=0;return a=127&(t=readByte(r)),128&t&&(a|=(127&(t=readByte(r)))<<7,128&t&&(a|=(127&(t=readByte(r)))<<14,128&t&&(a|=(127&(t=readByte(r)))<<21,128&t&&(n=127&(t=readByte(r)),128&t&&(n|=(127&(t=readByte(r)))<<7,128&t&&(n|=(127&(t=readByte(r)))<<14,128&t&&(n|=(127&(t=readByte(r)))<<21,128&t&&(i=127&(t=readByte(r)),128&t&&(i|=(127&(t=readByte(r)))<<7))))))))),{low:a|n<<28,high:n>>>4|i<<24,unsigned:e}}function writeVarint64(r,e){var t=e.low>>>0,a=(e.low>>>28|e.high<<4)>>>0,n=e.high>>>24,i=0===n?0===a?t<16384?t<128?1:2:t<1<<21?3:4:a<16384?a<128?5:6:a<1<<21?7:8:n<128?9:10,o=grow(r,i),f=r.bytes;switch(i){case 10:f[o+9]=n>>>7&1;case 9:f[o+8]=9!==i?128|n:127&n;case 8:f[o+7]=8!==i?a>>>21|128:a>>>21&127;case 7:f[o+6]=7!==i?a>>>14|128:a>>>14&127;case 6:f[o+5]=6!==i?a>>>7|128:a>>>7&127;case 5:f[o+4]=5!==i?128|a:127&a;case 4:f[o+3]=4!==i?t>>>21|128:t>>>21&127;case 3:f[o+2]=3!==i?t>>>14|128:t>>>14&127;case 2:f[o+1]=2!==i?t>>>7|128:t>>>7&127;case 1:f[o]=1!==i?128|t:127&t}}function decodedFrame(r){return decodeFrame(r)}function encodeFrame(r){return encodeFrame$1(r)}function readU8a(r){for(var e="",t=0;t>>7==0?(e+=String.fromCharCode(r[t]),t+=1):252&~a?248&~a?240&~a?224&~a?192&~a?(e+=String.fromCharCode(r[t]),t+=1):(n=(63&r[t])<<6,n|=63&r[t+1],e+=String.fromCharCode(n),t+=2):(n=(31&r[t])<<12,n|=(63&r[t+1])<<6,n|=63&r[t+2],e+=String.fromCharCode(n),t+=3):(n=(15&r[t])<<18,n|=(63&r[t+1])<<12,n|=(63&r[t+2])<<6,n|=63&r[t+3],e+=String.fromCharCode(n),t+=4):(n=(7&r[t])<<24,n|=(63&r[t+1])<<18,n|=(63&r[t+2])<<12,n|=(63&r[t+3])<<6,n|=63&r[t+4],e+=String.fromCharCode(n),t+=5):(n=(3&r[t])<<30,n|=(63&r[t+1])<<24,n|=(63&r[t+2])<<18,n|=(63&r[t+3])<<12,n|=(63&r[t+4])<<6,n|=63&r[t+5],e+=String.fromCharCode(n),t+=6)}return e}