function Flick(){}function ErlObject(){}ErlObject.prototype.type="erl",ErlObject.prototype.toString=function(){return this.type},ErlObject.prototype.extend=function(e,n){const t=function(){};t.prototype=ErlObject.prototype,e.prototype=new t,e.prototype.constructor=e,e.prototype.type=n};function ErlAtom(e){this.value=e}ErlObject.prototype.extend(ErlAtom,"atom"),ErlAtom.prototype.equals=function(e){return e instanceof ErlAtom&&this.value===e.value},ErlAtom.prototype.encodeSize=function(e){return 3+Math.min(255,(e||this.value).length)},ErlAtom.prototype.toString=function(){return!this.value.length||this.value[0]<"a"||this.value[0]>"z"?"'"+this.value+"'":this.value};function ErlBinary(e){if(typeof e=="string")this.value=Array.from(e);else if(e instanceof Array)this.value=e;else throw new Error("Unsupported binary data type: "+Flick.getClassName(e))}ErlObject.prototype.extend(ErlBinary,"binary"),ErlBinary.prototype.equals=function(e){return e instanceof ErlBinary&&this.value.equals(e.value)},ErlBinary.prototype.encodeSize=function(e){return 5+(e||this.value).length},ErlBinary.prototype.toString=function(e={}){const n=this.value,t=n.length>0&&n.every(o=>o>30&&o<127),r=t?n.map(o=>String.fromCharCode(o)).join(""):n.join(","),i=e.compact===!0;return`${i?"`":`<<${t?'"':""}`}${r}${i?"`":`${t?'"':""}>>`}`};function ErlTuple(e){this.value=e,this.length=e===void 0?0:e.length}ErlObject.prototype.extend(ErlTuple,"tuple"),ErlTuple.prototype.equals=function(e){return e instanceof ErlTuple&&this.value.equals(e.value)},ErlTuple.prototype.encodeSize=function(){return Flick.encode_tuple_size(this.value)},ErlTuple.prototype.toString=function(){return"{"+this.value.map(e=>Flick.toString(e)).join(",")+"}"},ErlTuple.prototype.toDate=function(){return new Date(this.toTimestamp())},ErlTuple.prototype.toTimestamp=function(){if(length!==3)return-1;const e=value[0]*1e9+value[1]*1e3+value[2]/1e3;return isNaN(e)?-1:e};function ErlMap(e){if(e instanceof ErlMap)this.value=Flick.objectDeepClone(e.value);else if(e instanceof Object)this.value=e;else throw new Error("ErlMap must be given an object!")}ErlObject.prototype.extend(ErlMap,"map"),ErlMap.prototype.equals=function(e){return e instanceof ErlMap&&Flick.objectsEqual(this.value,e.value)},ErlMap.prototype.encodeSize=function(e={}){return Flick.encode_map_size(this.value,e)},ErlMap.prototype.toString=function(){return"#{"+Object.keys(this.value).map(e=>`${e} => ${Flick.toString(this.value[e])}`).join(",")+"}"};function ErlPid(e,n,t,r){if(typeof e=="string")e=new ErlAtom(e);else if(!(e instanceof ErlAtom))throw new Error("Node argument must be an atom!");this.node=e,this.id=n>>>0,this.serial=t>>>0,this.creation=r>>>0}ErlObject.prototype.extend(ErlPid,"pid"),ErlPid.prototype.equals=function(e){return e instanceof ErlPid&&this.node.equals(e.node)&&this.id===e.id&&this.serial===e.serial&&this.creation===e.creation},ErlPid.prototype.encodeSize=function(){return 1+this.node.encodeSize()+12},ErlPid.prototype.toString=function(){return"#pid{"+this.node+","+this.id+","+this.serial+"}"};function ErlRef(e,n,t){if(typeof e=="string")e=new ErlAtom(e);else if(!(e instanceof ErlAtom))throw new Error("Node argument must be an atom!");if(!(t instanceof Array)||t.length>3)throw new Error("Reference IDs must be an array of length <= 3!");this.node=e,this.creation=n>>>0,this.ids=t}ErlObject.prototype.extend(ErlRef,"ref"),ErlRef.prototype.equals=function(e){return e instanceof ErlRef&&this.node.equals(e.node)&&this.creation===e.creation&&this.ids.equals(e.ids)},ErlRef.prototype.encodeSize=function(){return 3+this.node.encodeSize()+4+4*this.ids.length},ErlRef.prototype.toString=function(){return`#ref{${this.node.toString()+(this.ids.length?this.ids.map(e=>`,${e}`).join(""):"")}}`};function ErlVar(e,n){this.valueType=n,this.name=e}ErlObject.prototype.extend(ErlVar,"binary"),ErlVar.prototype.equals=function(e){return!1},ErlVar.prototype.encodeSize=function(){throw new Error("Cannot encode variables!")},ErlVar.prototype.toString=function(){let e;switch(this.valueType){case Flick.Enum.ATOM:e="::atom()";break;case Flick.Enum.BINARY:e="::binary()";break;case Flick.Enum.ErlBoolean:e="::bool()";break;case Flick.Enum.ErlByte:e="::byte()";break;case Flick.Enum.ErlDouble:e="::double()";break;case Flick.Enum.ErlLong:e="::int()";break;case Flick.Enum.ErlList:e="::list()";break;case Flick.Enum.ErlMap:e="::map()";break;case Flick.Enum.ErlPid:e="::pid()";break;case Flick.Enum.ErlPort:e="::port()";break;case Flick.Enum.ErlRef:e="::ref()";break;case Flick.Enum.ErlString:e="::string()";break;case Flick.Enum.ErlTuple:e="::tuple()";break;case Flick.Enum.ErlVar:e="::var()";break;default:e="";break}return this.name+e},Flick.prototype.encode=function(e,n={}){var t=1+this.encode_size(e,n),r=new ArrayBuffer(t),i=new DataView(r);i.setUint8(0,this.Enum.VERSION);var a=this.encode_inner(e,i,1,n);if(a.offset!==t)throw new Error("Invalid size of encoded buffer: "+a.offset+" expected: "+t);return r},Flick.prototype.decode=function(e){var n=new DataView(e,0);if(n.getUint8(0)!==this.Enum.VERSION)throw new Error("Not a valid Erlang term.");var t=this.decode_inner({data:n,offset:1});if(t.offset!==e.byteLength)throw new Error("Erlang term buffer has unused "+e.byteLength-t.offset+" bytes");return t.value},Flick.prototype.equals=function(){var e=arguments[0],n=arguments.length>1?arguments[1]:this;if(e===n)return!0;if(ErlObject.prototype.isPrototypeOf(e))return e.equals(n)||e instanceof ErlTuple&&n instanceof Date&&e.toTimestamp()===n.getTime();if(e instanceof Date&&n instanceof ErlTuple)return n.toTimestamp()===e.getTime();if(e instanceof Array)return n instanceof Array&&e.equals(n);if(e instanceof Object!=n instanceof Object)return!1;for(let i in e)if(!(i in n))return!1;for(let i in n)if(!(i in e))return!1;for(let i in e){var t=e[i],r=n[i];if(!Flick.equals(t,r))return!1}return!0},Flick.prototype.toString=function(e,n={}){if(e===void 0)return"undefined";if(e===null)return"null";switch(typeof e){case"number":return e.toString();case"boolean":return e.toString();case"string":return`"${e.toString()}"`}return ErlObject.prototype.isPrototypeOf(e)?e.toString(n):e instanceof Array?`[${e.map(r=>Flick.toString(r,n)).join(",")}]`:`[${Object.keys(e).map(r=>`{${r},${Flick.toString(e[r],n)}}`).join(",")}]`},Flick.prototype.atom=function(e){return new ErlAtom(e)},Flick.prototype.binary=function(e){return new ErlBinary(e)},Flick.prototype.tuple=function(){var e=new Array(arguments.length);for(let n=0,t=arguments.length;n<t;++n)e[n]=arguments[n];return new ErlTuple(e)},Flick.prototype.pid=function(e,n,t,r){return new ErlPid(e,n,t,r)},Flick.prototype.ref=function(e,n,t){return new ErlRef(e,n,t)},Flick.prototype.map=function(e){return new ErlMap(e)},Flick.prototype.toArrayBuffer=function(e){var n=new ArrayBuffer(e.length),t=new DataView(n);for(let r=0,i=e.length;r<i;++r)t.setUint8(r,e[r]);return n},Flick.prototype.bufferToArray=function(e){var n=new DataView(e),t=new Array(n.byteLength);for(let r=0,i=n.byteLength;r<i;++r)t[r]=n.getUint8(r);return t},Flick.prototype.Enum={VERSION:131,SMALL_ATOM:115,ATOM:100,ATOM_UTF8:118,SMALL_ATOM_UTF8:119,BINARY:109,BIT_BINARY:77,SMALL_INTEGER:97,INTEGER:98,SMALL_BIG:110,LARGE_BIG:111,FLOAT:99,NEW_FLOAT:70,STRING:107,PORT:102,V4_PORT:120,NEW_PORT:89,PID:103,NEW_PID:88,SMALL_TUPLE:104,LARGE_TUPLE:105,LIST:108,MAP:116,REFERENCE:101,NEW_REFERENCE:114,NEWER_REFERENCE:90,NIL:106,TUPLE:104,DOUBLE:70,BYTE:97,BOOLEAN:254,VAR:255,ZERO:0},Flick.prototype.Encoding={ASCII:1,LATIN1:2,UTF8:4},Flick.prototype.encode_size=function(e,n={}){if(e===null)return this.atom("nil").encodeSize();if(e===void 0)return this.atom(String(e)).encodeSize();switch(typeof e){case"number":return this.encode_number_size(e);case"string":return this.encode_string_size(e);case"boolean":return e?7:8}switch(e.type){case"atom":return e.encodeSize();case"tuple":return e.encodeSize();case"binary":return e.encodeSize();case"pid":return e.encodeSize();case"ref":return e.encodeSize();case"map":return e.encodeSize()}if(e instanceof Array)return this.is_assoc_array(e)?this.encode_assoc_array_size(e):this.encode_array_size(e);if(e instanceof Object)return Flick.encode_map_size(e,n);throw new Error(`Cannot determine type of object: ${JSON.stringify(e)}`)},Flick.prototype.encode_inner=function(e,n,t,r={}){var a="encode_"+(e instanceof Array?this.is_assoc_array(e)?"assoc_array":"array":typeof e);return this[a](e,n,t,r)},Flick.prototype.encode_object=function(e,n,t,r={}){if(e===null)return this.encode_atom("nil",n,t);if(e===void 0)return this.encode_atom(String(e),n,t);switch(e.type){case"atom":return this.encode_atom(e.value,n,t);case"binary":return this.encode_binary(e.value,n,t);case"tuple":return this.encode_tuple(e,n,t);case"ref":return this.encode_ref(e,n,t);case"pid":return this.encode_pid(e,n,t);case"map":return this.encode_map(e,n,t,r)}return Flick.is_assoc_array(e)?this.encode_assoc_array(e,n,t):e instanceof Array?this.encode_array(e,n,t):this.encode_tuple_or_map(e,n,t,r)},Flick.prototype.encode_undefined=function(e,n,t){if(e!=null)throw new Error("Object value must by undefined or null. Found: "+String(e));return this.encode_atom(String(e),n,t)},Flick.prototype.encode_string_size=function(e){return 3+e.length},Flick.prototype.encode_string=function(e,n,t){n.setUint8(t++,this.Enum.STRING),n.setUint16(t,e.length),t+=2;for(let r=0,i=e.length;r<i;++r)n.setUint8(t++,e.charCodeAt(r));return{data:n,offset:t}},Flick.prototype.encode_boolean=function(e,n,t){return this.encode_atom(e?"true":"false",n,t)},Flick.prototype.encode_number_size=function(e){var n,t=this.isInt(e);if(!t)return 9;if(e>=0&&e<256)return 2;if(e>=-2147483648&&e<=2147483647)return 5;var r=0;for(e<0&&(e=-e);e;++r,e=Math.floor(e/256));return 3+r},Flick.prototype.encode_number=function(e,n,t){if(!this.isInt(e))return this.encode_float(e,n,t);if(e>=0&&e<256)return n.setUint8(t++,this.Enum.SMALL_INTEGER),n.setUint8(t++,e),{data:n,offset:t};if(e>=-2147483648&&e<=2147483647)return n.setUint8(t++,this.Enum.INTEGER),n.setUint32(t,e),{data:n,offset:t+4};var r=t;t+=2,n.setUint8(t++,e<0?1:0),e<0&&(e=-e);for(var i=0;e;++i,e=Math.floor(e/256)){var a=e%256;n.setUint8(t++,a)}var s=i<256?this.Enum.SMALL_BIG:this.Enum.LARGE_BIG;return n.setUint8(r++,s),n.setUint8(r,i),{data:n,offset:t}},Flick.prototype.encode_float=function(e,n,t){if(!Number.isFinite(e))throw new Error(`Cannot encode non-finite float: ${e}`);return n.setUint8(t++,this.Enum.NEW_FLOAT),n.setFloat64(t,e),{data:n,offset:t+8}},Flick.prototype.encode_atom=function(e,n,t){n.setUint8(t++,this.Enum.ATOM),n.setUint16(t,e.length),t+=2;for(let r=0,i=e.length;r<i;++r)n.setUint8(t++,e.charCodeAt(r));return{data:n,offset:t}},Flick.prototype.encode_binary=function(e,n,t){if(n.setUint8(t++,this.Enum.BINARY),n.setUint32(t,e.length),t+=4,e instanceof Array)for(let r=0,i=e.length;r<i;++r)n.setUint8(t++,e[r]);else if(typeof e=="string")for(let r=0,i=e.length;r<i;++r)n.setUint8(t++,e.charCodeAt(r));else throw new Error(`Invalid ErlBinary data type: ${typeof e}`);return{data:n,offset:t}},Flick.prototype.encode_tuple_size=function(e,n,t){if(e instanceof Array)return e.reduce((r,i)=>r+Flick.encode_size(i),1+(e.length<256?1:4));if(e instanceof Object){let r=0,i=0;for(const a in e)if(e.hasOwnProperty(a)&&(i+=Flick.encode_size(a)+Flick.encode_size(e[a]),++r>1))throw new Error(`Invalid size of a tuple that is likely part of a proplist: ${JSON.stringify(e)}`);return 1+(r<256?1:4)+i}else throw new Error(`Invalid type of tuple data: ${typeof e}`)},Flick.prototype.encode_tuple_or_map=function(e,n,t,r={}){if(!(e instanceof ErlTuple)&&e instanceof Object){let i=0,a=[];for(const s in e)if(e.hasOwnProperty(s)&&(a.push(s),a.push(e[s]),++i>1))return this.encode_map(e,n,t,r);e=new ErlTuple(a)}return this.encode_tuple(e,n,t)},Flick.prototype.encode_tuple=function(e,n,t){if(e instanceof ErlTuple){var r=e.length;return r<256?(n.setUint8(t++,this.Enum.SMALL_TUPLE),n.setUint8(t++,r)):(n.setUint8(t++,this.Enum.LARGE_TUPLE),n.setUint32(t,r),t+=4),e.value.reduce((i,a)=>Flick.encode_inner(a,i.data,i.offset),{data:n,offset:t})}else throw new Error(`Invalid type of tuple object: ${JSON.stringify(e)}`)},Flick.prototype.encode_pid=function(e,n,t){n.setUint8(t++,this.Enum.NEW_PID);var r=this.encode_atom(e.node.value,n,t);return t=r.offset,n.setUint32(t,e.id),t+=4,n.setUint32(t,e.serial),t+=4,n.setUint32(t,e.creation),t+=4,{data:n,offset:t}},Flick.prototype.encode_ref=function(e,n,t){n.setUint8(t++,this.Enum.NEWER_REFERENCE),n.setUint16(t,e.ids.length),t+=2;var r=this.encode_atom(e.node.value,n,t);return t=r.offset,n.setUint32(t,e.creation),t+=4,t=e.ids.reduce((i,a)=>(n.setUint32(i,a),i+4),t),{data:n,offset:t}},Flick.prototype.encode_map_size=function(e,n){if(!(e instanceof Object))throw new Error(`Invalid data type for encoding map size: ${typeof e}`);const t=n.mapKeyType||"binary",r=t=="atom",i=t=="binary";return Object.entries(e).reduce((s,o)=>{const u=typeof o[0]=="string"?i?ErlBinary.prototype.encodeSize(o[0]):r?ErlAtom.prototype.encodeSize(o[0]):this.encode_string_size(o[0]):Flick.encode_size(o[0]);return s+=u+Flick.encode_size(o[1])},5)},Flick.prototype.encode_map=function(e,n,t,r={}){n.setUint8(t++,this.Enum.MAP);let i=0;if(e instanceof ErlMap)e=e.value;else if(!1=="object")throw new Error(`ErlMap encoding expects an object, got: ${typeof e}`);for(let u in e)e.hasOwnProperty(u)&&++i;n.setUint32(t,i),t+=4;const a=r.mapKeyType||"binary",s=a=="atom",o=a=="binary";return Object.entries(e).reduce((u,c)=>(u=typeof c[0]=="string"?o?this.encode_binary(c[0],u.data,u.offset):s?this.encode_atom(c[0],u.data,u.offset):this.encode_string(c[0],u.data,u.offset):Flick.encode_inner(c[0],u.data,u.offset),this.encode_inner(c[1],u.data,u.offset)),{data:n,offset:t})},Flick.prototype.encode_array_size=function(e){return e.reduce((n,t)=>n+Flick.encode_size(t),e.length?6:1)},Flick.prototype.encode_array_size=function(e){return e.reduce((n,t)=>n+Flick.encode_size(t),e.length?6:1)},Flick.prototype.encode_array=function(e,n,t){return e.length>0&&(n.setUint8(t++,this.Enum.LIST),n.setUint32(t,e.length),t+=4,t=e.reduce((r,i)=>{var a=Flick.encode_inner(i,n,r);return a.offset},t)),n.setUint8(t++,this.Enum.NIL),{data:n,offset:t}},Flick.prototype.is_assoc_array=function(e){return e instanceof Array&&e.length>0&&e.every(n=>{if(n instanceof ErlTuple&&n.length===2&&n.value[0]instanceof ErlAtom)return!0;if(!(n instanceof Object))return!1;const t=Object.keys(n);return t.length!==1?!1:t[0]instanceof ErlAtom||typeof t[0]=="string"})},Flick.prototype.encode_assoc_array_size=function(e){if(!e instanceof Array)throw new Error(`Invalid type of data in assoc array: ${typeof e} (expected array)`);return e.reduce((t,r)=>{let i=0,a;for(const s in r)if(r.hasOwnProperty(s)){if(++i>1){a=r;break}t+=2+this.atom(s).encodeSize()+this.encode_size(r[s])}if(i!=1)throw new Error(`Invalid size of tuple inside a proplist: ${JSON.stringify(a)}`);return t},6)},Flick.prototype.encode_assoc_array=function(e,n,t){if(!e instanceof Array)throw new Error(`Invalid type of data in assoc array: ${typeof e} (expected array)`);for(let r=0;r<e.length;++r){let i=e[r],a,s,o=0;for(const u in i)if(i.hasOwnProperty(u)){if(++o>1)break;a=u,s=i[u]}if(o!=1)throw new Error(`Invalid size of tuple inside a proplist: ${JSON.stringify(i)}`);e[r]=this.tuple(this.atom(a),s)}return this.encode_array(e,n,t)},Flick.prototype.decode_inner=function(e){const t=e.data.getUint8(e.offset);switch(t){case this.Enum.SMALL_ATOM:return this.decode_atom(e);case this.Enum.ATOM:return this.decode_atom(e);case this.Enum.ATOM_UTF8:return this.decode_atom(e);case this.Enum.SMALL_ATOM_UTF8:return this.decode_atom(e);case this.Enum.STRING:return this.decode_string(e);case this.Enum.SMALL_INTEGER:return this.decode_integer(e);case this.Enum.INTEGER:case this.Enum.SMALL_BIG:case this.Enum.LARGE_BIG:return this.decode_integer(e);case this.Enum.FLOAT:case this.Enum.NEW_FLOAT:return this.decode_float(e);case this.Enum.LIST:return this.decode_list(e);case this.Enum.MAP:return this.decode_map(e);case this.Enum.NIL:return{value:[],offset:e.offset+1};case this.Enum.SMALL_TUPLE:case this.Enum.LARGE_TUPLE:return this.decode_tuple(e);case this.Enum.BINARY:return this.decode_binary(e);case this.Enum.PID:case this.Enum.NEW_PID:return this.decode_pid(e);case this.Enum.NEW_REFERENCE:case this.Enum.NEWER_REFERENCE:return this.decode_ref(e);default:throw new Error("Unexpected Erlang type: "+t+" at offset "+e.offset)}},Flick.prototype.decode_atom=function(e){var n=e.data,t=e.offset,r,i=n.getUint8(t++);switch(i){case this.Enum.ATOM:case this.Enum.ATOM_UTF8:r=n.getUint16(t),t+=2;break;case this.Enum.SMALL_ATOM:case this.Enum.SMALL_ATOM_UTF8:r=n.getUint8(t++);break;default:throw new Error("Invalid Erlang atom: "+i+" at offset "+t)}var a=new Uint8Array(n.buffer,t,r);t+=r;var s=String.fromCharCode.apply(String,a),o;switch(s){case"true":o=!0;break;case"false":o=!1;break;case"undefined":o=void 0;break;case"null":case"nil":o=null;break;default:o=this.atom(s)}return{value:o,offset:t}},Flick.prototype.decode_binary=function(e){var n=e.data,t=e.offset,r=n.getUint8(t++);if(r!==this.Enum.BINARY)throw new Error("Invalid Erlang binary: "+r+" at offset "+t);var i=n.getUint32(t);t+=4;var a=new Array(i);for(let s=t,o=0,u=t+i;s<u;++s,++o)a[o]=n.getUint8(s);return{value:this.binary(a),offset:t+i}},Flick.prototype.decode_integer=function(e){var n=e.data,t=e.offset,r=n.getUint8(t++),i,a,s;switch(r){case this.Enum.SMALL_INTEGER:i=n.getUint8(t++);break;case this.Enum.INTEGER:i=n.getInt32(t),t+=4;break;case this.Enum.SMALL_BIG:a=n.getUint8(t++);case this.Enum.LARGE_BIG:if(r!=this.Enum.SMALL_BIG&&(a=n.getUint32(t),t+=4),a>8)throw new Error("Integer value too large for type: "+r+" arity "+a);s=n.getUint8(t++),i=0;for(let o=0,u=1;o<a;++o,u*=256)i+=n.getUint8(t++)*u;s&&(i=-i);break;default:throw new Error("Invalid Erlang integer type: "+r+" at offset "+t)}return{value:i,offset:t}},Flick.prototype.decode_float=function(e){var n=e.data,t=e.offset,r=n.getUint8(t++),i,a;switch(r){case this.Enum.FLOAT:a=31;var s=new Uint8Array(n.buffer,t,a);t+=a;var o=String.fromCharCode.apply(String,s);i=parseFloat(o);break;case this.Enum.NEW_FLOAT:i=n.getFloat64(t),t+=8;break;default:throw new Error("Invalid Erlang float type: "+r+" at offset "+t)}return{value:i,offset:t}},Flick.prototype.decode_string=function(e){var n=e.data,t=e.offset,r,i,a=n.getUint8(t++);switch(a){case this.Enum.STRING:r=n.getUint16(t),t+=2;var s=new Uint8Array(n.buffer,t,r);t+=r,i=String.fromCharCode.apply(String,s);break;case this.Enum.LIST:r=n.getUint32(t),t+=4;var o=[];for(let c=0;c<r;c++){if(n.getUint8(t++)!==this.SMALL_INTEGER)throw new Error("Error decoding string.");var u=n.getUint8(t++);o.push(u)}i=String.fromCharCode.apply(String,o);break;case this.Enum.NIL:i="";break;default:throw new Error("Invalid Erlang string type: "+a+" at offset "+t)}return{value:i,offset:t}},Flick.prototype.decode_list=function(e){var n=e.data,t=e.offset,r,i,a=n.getUint8(t++);switch(a){case this.Enum.STRING:r=n.getUint16(t),t+=2;var s=new Uint8Array(n.buffer,t,r);t+=r,i=String.fromCharCode.apply(String,s);break;case this.Enum.LIST:r=n.getUint32(t),e.offset=t+4,i=new Array(r);for(let u=0;u<r;++u){var o=Flick.decode_inner(e);i[u]=o.value,e.offset=o.offset}t=e.offset,n.byteLength>t&&n.getUint8(t)===this.Enum.NIL&&t++;break;case this.Enum.NIL:i=[];break;default:throw new Error("Invalid Erlang list type: "+a+" at offset "+t)}return{value:i,offset:t}},Flick.prototype.decode_map=function(e){const n=e.data;let t=e.offset;const r=n.getUint8(t++);if(r!==this.Enum.MAP)throw new Error("Invalid map type: "+r);const i=n.getUint32(t);e.offset=t+4;let a={};for(let s=0;s<i;++s){const o=Flick.decode_inner(e);e.offset=o.offset;const u=Flick.decode_inner(e);e.offset=u.offset;const c=o.value,f=c instanceof ErlAtom?c.value:c instanceof ErlBinary?String.fromCharCode.apply(String,c.value):typeof c=="string"?c:c.hasOwnProperty("value")?c.value:c;a[f]=u.value}return{value:a,offset:e.offset}},Flick.prototype.decode_tuple=function(e){var n=e.data,t=e.offset,r,i=n.getUint8(t++);switch(i){case this.Enum.SMALL_TUPLE:r=n.getUint8(t),e.offset=t+1;break;case this.Enum.LARGE_TUPLE:r=n.getUint32(t),e.offset+=4;break;default:throw new Error("Invalid Erlang tuple type: "+i+" at offset "+t)}var a=new Array(r);for(let o=0;o<r;o++){var s=Flick.decode_inner(e);a[o]=s.value,e.offset=s.offset}return{value:this.tuple.apply(this,a),offset:e.offset}},Flick.prototype.decode_pid=function(e){var n=e.data,t=e.offset,r=n.getUint8(t++);if(r!==this.Enum.PID&&r!==this.Enum.NEW_PID)throw new Error("Invalid pid type: "+r);e.offset=t;var i=this.decode_atom(e);t=i.offset;var a=n.getUint32(t);t+=4;var s=n.getUint32(t);t+=4;var o;return r===this.Enum.NEW_PID?(o=n.getUint32(t),t+=4):o=n.getUint8(t++),{value:this.pid(i.value,a,s,o),offset:t}},Flick.prototype.decode_ref=function(e){var n=e.data,t=e.offset,r=n.getUint8(t++);if(r!==this.Enum.NEW_REFERENCE&&r!==this.Enum.NEWER_REFERENCE)throw new Error("Invalid ref type: "+r);var i=n.getUint16(t);t+=2;var a=new Array(i);e.offset=t;var s=this.decode_atom(e);t=s.offset;var o;r===this.Enum.NEWER_REFERENCE?(o=n.getUint32(t),t+=4):o=n.getUint8(t++);for(let u=0;u<i;++u,t+=4)a[u]=n.getUint32(t);return{value:this.ref(s.value,o,a),offset:t}},Flick.prototype.getClassName=function(e){const t=/(.{1,}) => \(/.exec(e.constructor.toString());return t&&t.length>1?t[1]:""},Flick.prototype.isInt=function(e){return parseFloat(e)==parseInt(e)&&!isNaN(e)},Flick.prototype.timestampToTuple=function(e){var n=Math.floor(e/1e9);e-=n*1e9;var t=Math.floor(e/1e3);e-=t*1e3;var r=e;return new ErlTuple([n,t,r])},Flick.prototype.dateToTuple=function(e){var n=e.getTime(),t=Math.floor(n/1e9);n-=t*1e9;var r=Math.floor(n/1e3);n-=r*1e3;var i=n;return new ErlTuple([t,r,i])};var Flick=new Flick;Array.prototype.equals=function(e){if(!e||this.length!=e.length)return!1;for(let n=0,t=this.length;n<t;n++)if(this[n]instanceof Array&&e[n]instanceof Array||this[n]instanceof ErlTuple&&e[n]instanceof ErlTuple||this[n].equals!==void 0){if(!this[n].equals(e[n]))return!1}else if(this[n]!==e[n])return!1;return!0},ArrayBuffer.prototype.equals=function(e){if(!e)return!1;const n=new Uint8Array(this),t=e instanceof ArrayBuffer?new Uint8Array(e):e;if(n.length!=t.length)return!1;for(let r=0,i=n.length;r<i;++r)if(n[r]!==t[r])return!1;return!0},Flick.objectEquals=function(e,n){"use strict";return e==null||n===null||n===void 0?e===n:e.constructor!==n.constructor?!1:e instanceof Function||e instanceof RegExp?e===n:e===n||e.valueOf()===n.valueOf()?!0:Array.isArray(e)?e.equals(n):e instanceof Date||!(e instanceof Object)||!(n instanceof Object)?!1:Object.keys(n).every(t=>e[t]!==void 0)&&Object.keys(e).every(t=>objectEquals(e[t],n[t]))},Flick.objectDeepClone=function(e,n=void 0,t=()=>!0){let r={};function i(a,s,o){for(const[u,c]of Object.entries(s)){if(!t(o,u))continue;if(Array.isArray(c)){a[u]=c.slice();continue}else if(c===null||typeof c!="object"){a[u]=c;continue}a[u]===void 0&&(a[u]=new c.__proto__.constructor);const f=[...o,u];i(a[u],c,f)}}return i(r,e,[]),n!==void 0&&i(r,n,[]),r};