update: 添加bobj相关内容
This commit is contained in:
1 parent
d20dc84d9d
commit
01fb8bb7c2
8 files changed
+72
-2
No files matched your search
@@ -0,0 +1 @@
|
||||
(function(){"use strict";var y=e=>{throw TypeError(e)},c=(e,r,t)=>r.has(e)||y("Cannot "+t),l=(e,r,t)=>(c(e,r,"read from private field"),t?t.call(e):r.get(e)),f=(e,r,t)=>r.has(e)?y("Cannot add the same private member more than once"):r instanceof WeakSet?r.add(e):r.set(e,t);const u=(e,r)=>{r=r||1;const t=[];for(;e>0||r>0;)t.unshift(e&255),e=e>>8,r--;return new Uint8Array(t)},w=e=>{const{key:r,valueType:t,value:n,textEncoder:a=new TextEncoder}=e,s=a.encode(r),o=u(n.length);return new Uint8Array([s.length,t.length,o.length,...s,...t,...o,...n])};function g(e){const r=new ArrayBuffer(8);return new DataView(r).setFloat64(0,e,!0),new Uint8Array(Array.from(new Uint8Array(r)))}const A=[{filter:e=>!0,targetType:new Uint8Array([0]),async serialize(e){const r=new TextEncoder;let t=new Uint8Array(0);for(const n in e.target){const a=e.target[n],s=await e.serializer.filter(a);if(!s)throw new Error("Unknown value type");const o=await e.serializer.serialize(a)??new Uint8Array(0);t=new Uint8Array([...t,...w({key:n,valueType:s,value:o,textEncoder:r})])}return t}},{filter:e=>e instanceof Array,targetType:new Uint8Array([1]),async serialize(e){const r={...e.target,l:e.target.length};return await e.serializer.serialize(r)}},{filter:e=>e instanceof Uint8Array,targetType:new Uint8Array([2]),serialize(e){return e.target}},{filter(e){return typeof e=="string"},targetType:new Uint8Array([3]),serialize(e){return(e.textEncoder||new TextEncoder).encode(e.target)}},{filter(e){return typeof e=="number"},targetType:new Uint8Array([4]),serialize(e){return g(e.target)}},{filter(e){return typeof e=="boolean"},targetType:new Uint8Array([5]),serialize(e){return new Uint8Array([e.target?1:0])}},{filter(e){return typeof e>"u"},targetType:new Uint8Array([6]),serialize(){return new Uint8Array(0)}},{filter(e){return e===null},targetType:new Uint8Array([7]),serialize(){return new Uint8Array(0)}}];var i;class p{constructor(){f(this,i,[]),A.forEach(r=>{this.registerPlugin(r)})}async serialize(r){for(const t of l(this,i))if(t.filter(r)){const n=t.serialize({target:r,serializer:this});let a;return n instanceof Promise?a=await n:a=n,a}}async filter(r){for(const t of l(this,i))if(t.filter(r))return t.targetType}registerPlugin(r){l(this,i).unshift(r)}}i=new WeakMap;const h=new p;self.onmessage=async e=>{const r=e.data,t=await h.serialize(r);self.postMessage(t)}})();
|
||||
Reference in new issue
Block a user