update: 更新bobj demo版本
This commit is contained in:
1 parent
01fb8bb7c2
commit
0267fac3a1
8 files changed
+6
-24
No files matched your search
@@ -0,0 +1 @@
|
||||
(function(){"use strict";var w=r=>{throw TypeError(r)},g=(r,e,t)=>e.has(r)||w("Cannot "+t),l=(r,e,t)=>(g(r,e,"read from private field"),e.get(r)),f=(r,e,t)=>e.has(r)?w("Cannot add the same private member more than once"):e instanceof WeakSet?e.add(r):e.set(r,t);function z(r){const e=new ArrayBuffer(8),t=new Uint8Array(e);for(let a=0;a<8;a++)t[a]=r[a]||0;return new DataView(e).getFloat64(0,!0)}const p=[{filter:new Uint8Array([0]),deserialize:r=>r.deserializer.deserialize(r.targetArray)},{filter:new Uint8Array([1]),deserialize:async r=>{const e=await r.deserializer.deserialize(r.targetArray),t=new Array(e.l).fill(0);for(let a=0;a<e.l;a++)t[a]=e[a];return t}},{filter:new Uint8Array([2]),deserialize:r=>new Uint8Array(r.targetArray)},{filter:new Uint8Array([3]),deserialize:r=>new TextDecoder().decode(r.targetArray)},{filter:new Uint8Array([4]),deserialize:r=>z(r.targetArray)},{filter:new Uint8Array([5]),deserialize:r=>r.targetArray[0]===1},{filter:new Uint8Array([6]),deserialize:r=>{}},{filter:new Uint8Array([7]),deserialize:r=>null}];function v(r){let e=0;for(let t=0;t<r.length;t++)e=(e<<8)+r[t];return e}function U(r){const{targetArray:e,textDecoder:t=new TextDecoder}=r,a=e[0],n=e[1],i=e[2],s=t.decode(e.subarray(3,3+a)),y=e.subarray(3+a,3+a+n),b=e.subarray(3+a+n,3+a+n+i),A=v(b),k=e.subarray(3+a+n+i,3+a+n+i+A);return{key:s,valueType:y,value:k,totalLength:3+a+n+i+A}}const h=["0","1","2","3","4","5","6","7","8","9","a","b","c","d","e","f"],d=r=>r.reduce((e,t)=>e+h[t>>8]+h[t&255],"");var o,c,u;class m{constructor(){f(this,o,new Map),f(this,c,[]),f(this,u,new TextDecoder),p.forEach(e=>{this.registerPlugin(e)})}async deserialize(e){const t={};let a=0;for(;a<e.length;){const n=e.subarray(a),i=U({targetArray:n,textDecoder:l(this,u)});if(l(this,o).has(d(i.valueType))){const s=l(this,o).get(d(i.valueType)).deserialize({targetArray:i.value,deserializer:this});t[i.key]=s instanceof Promise?await s:s}else for(const s of l(this,c))if(s.filter(i.valueType)){const y=s.deserialize({targetArray:i.value,deserializer:this});t[i.key]=y instanceof Promise?await y:y}a+=i.totalLength}return t}registerPlugin(e){if(e.filter instanceof Uint8Array){l(this,o).set(d(e.filter),e);return}l(this,c).unshift(e)}}o=new WeakMap,c=new WeakMap,u=new WeakMap;const T=new m;self.onmessage=async r=>{const e=new Uint8Array(r.data),t=await T.deserialize(e);self.postMessage(t)}})();
|
||||
Reference in new issue
Block a user