|
| 1 | +let wasm; |
| 2 | + |
| 3 | +const cachedTextDecoder = (typeof TextDecoder !== 'undefined' ? new TextDecoder('utf-8', { ignoreBOM: true, fatal: true }) : { decode: () => { throw Error('TextDecoder not available') } } ); |
| 4 | + |
| 5 | +if (typeof TextDecoder !== 'undefined') { cachedTextDecoder.decode(); }; |
| 6 | + |
| 7 | +let cachedUint8ArrayMemory0 = null; |
| 8 | + |
| 9 | +function getUint8ArrayMemory0() { |
| 10 | + if (cachedUint8ArrayMemory0 === null || cachedUint8ArrayMemory0.byteLength === 0) { |
| 11 | + cachedUint8ArrayMemory0 = new Uint8Array(wasm.memory.buffer); |
| 12 | + } |
| 13 | + return cachedUint8ArrayMemory0; |
| 14 | +} |
| 15 | + |
| 16 | +function getStringFromWasm0(ptr, len) { |
| 17 | + ptr = ptr >>> 0; |
| 18 | + return cachedTextDecoder.decode(getUint8ArrayMemory0().subarray(ptr, ptr + len)); |
| 19 | +} |
| 20 | + |
| 21 | +const heap = new Array(128).fill(undefined); |
| 22 | + |
| 23 | +heap.push(undefined, null, true, false); |
| 24 | + |
| 25 | +let heap_next = heap.length; |
| 26 | + |
| 27 | +function addHeapObject(obj) { |
| 28 | + if (heap_next === heap.length) heap.push(heap.length + 1); |
| 29 | + const idx = heap_next; |
| 30 | + heap_next = heap[idx]; |
| 31 | + |
| 32 | + heap[idx] = obj; |
| 33 | + return idx; |
| 34 | +} |
| 35 | + |
| 36 | +let WASM_VECTOR_LEN = 0; |
| 37 | + |
| 38 | +const cachedTextEncoder = (typeof TextEncoder !== 'undefined' ? new TextEncoder('utf-8') : { encode: () => { throw Error('TextEncoder not available') } } ); |
| 39 | + |
| 40 | +const encodeString = (typeof cachedTextEncoder.encodeInto === 'function' |
| 41 | + ? function (arg, view) { |
| 42 | + return cachedTextEncoder.encodeInto(arg, view); |
| 43 | +} |
| 44 | + : function (arg, view) { |
| 45 | + const buf = cachedTextEncoder.encode(arg); |
| 46 | + view.set(buf); |
| 47 | + return { |
| 48 | + read: arg.length, |
| 49 | + written: buf.length |
| 50 | + }; |
| 51 | +}); |
| 52 | + |
| 53 | +function passStringToWasm0(arg, malloc, realloc) { |
| 54 | + |
| 55 | + if (realloc === undefined) { |
| 56 | + const buf = cachedTextEncoder.encode(arg); |
| 57 | + const ptr = malloc(buf.length, 1) >>> 0; |
| 58 | + getUint8ArrayMemory0().subarray(ptr, ptr + buf.length).set(buf); |
| 59 | + WASM_VECTOR_LEN = buf.length; |
| 60 | + return ptr; |
| 61 | + } |
| 62 | + |
| 63 | + let len = arg.length; |
| 64 | + let ptr = malloc(len, 1) >>> 0; |
| 65 | + |
| 66 | + const mem = getUint8ArrayMemory0(); |
| 67 | + |
| 68 | + let offset = 0; |
| 69 | + |
| 70 | + for (; offset < len; offset++) { |
| 71 | + const code = arg.charCodeAt(offset); |
| 72 | + if (code > 0x7F) break; |
| 73 | + mem[ptr + offset] = code; |
| 74 | + } |
| 75 | + |
| 76 | + if (offset !== len) { |
| 77 | + if (offset !== 0) { |
| 78 | + arg = arg.slice(offset); |
| 79 | + } |
| 80 | + ptr = realloc(ptr, len, len = offset + arg.length * 3, 1) >>> 0; |
| 81 | + const view = getUint8ArrayMemory0().subarray(ptr + offset, ptr + len); |
| 82 | + const ret = encodeString(arg, view); |
| 83 | + |
| 84 | + offset += ret.written; |
| 85 | + ptr = realloc(ptr, len, offset, 1) >>> 0; |
| 86 | + } |
| 87 | + |
| 88 | + WASM_VECTOR_LEN = offset; |
| 89 | + return ptr; |
| 90 | +} |
| 91 | + |
| 92 | +function getObject(idx) { return heap[idx]; } |
| 93 | + |
| 94 | +function dropObject(idx) { |
| 95 | + if (idx < 132) return; |
| 96 | + heap[idx] = heap_next; |
| 97 | + heap_next = idx; |
| 98 | +} |
| 99 | + |
| 100 | +function takeObject(idx) { |
| 101 | + const ret = getObject(idx); |
| 102 | + dropObject(idx); |
| 103 | + return ret; |
| 104 | +} |
| 105 | +/** |
| 106 | +* @param {string} cidrs |
| 107 | +* @param {boolean} reverse |
| 108 | +* @param {boolean} exclude_reserved |
| 109 | +* @returns {any} |
| 110 | +*/ |
| 111 | +export function aggregate(cidrs, reverse, exclude_reserved) { |
| 112 | + const ptr0 = passStringToWasm0(cidrs, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc); |
| 113 | + const len0 = WASM_VECTOR_LEN; |
| 114 | + const ret = wasm.aggregate(ptr0, len0, reverse, exclude_reserved); |
| 115 | + return takeObject(ret); |
| 116 | +} |
| 117 | + |
| 118 | +async function __wbg_load(module, imports) { |
| 119 | + if (typeof Response === 'function' && module instanceof Response) { |
| 120 | + if (typeof WebAssembly.instantiateStreaming === 'function') { |
| 121 | + try { |
| 122 | + return await WebAssembly.instantiateStreaming(module, imports); |
| 123 | + |
| 124 | + } catch (e) { |
| 125 | + if (module.headers.get('Content-Type') != 'application/wasm') { |
| 126 | + console.warn("`WebAssembly.instantiateStreaming` failed because your server does not serve wasm with `application/wasm` MIME type. Falling back to `WebAssembly.instantiate` which is slower. Original error:\n", e); |
| 127 | + |
| 128 | + } else { |
| 129 | + throw e; |
| 130 | + } |
| 131 | + } |
| 132 | + } |
| 133 | + |
| 134 | + const bytes = await module.arrayBuffer(); |
| 135 | + return await WebAssembly.instantiate(bytes, imports); |
| 136 | + |
| 137 | + } else { |
| 138 | + const instance = await WebAssembly.instantiate(module, imports); |
| 139 | + |
| 140 | + if (instance instanceof WebAssembly.Instance) { |
| 141 | + return { instance, module }; |
| 142 | + |
| 143 | + } else { |
| 144 | + return instance; |
| 145 | + } |
| 146 | + } |
| 147 | +} |
| 148 | + |
| 149 | +function __wbg_get_imports() { |
| 150 | + const imports = {}; |
| 151 | + imports.wbg = {}; |
| 152 | + imports.wbg.__wbindgen_json_parse = function(arg0, arg1) { |
| 153 | + const ret = JSON.parse(getStringFromWasm0(arg0, arg1)); |
| 154 | + return addHeapObject(ret); |
| 155 | + }; |
| 156 | + |
| 157 | + return imports; |
| 158 | +} |
| 159 | + |
| 160 | +function __wbg_init_memory(imports, memory) { |
| 161 | + |
| 162 | +} |
| 163 | + |
| 164 | +function __wbg_finalize_init(instance, module) { |
| 165 | + wasm = instance.exports; |
| 166 | + __wbg_init.__wbindgen_wasm_module = module; |
| 167 | + cachedUint8ArrayMemory0 = null; |
| 168 | + |
| 169 | + |
| 170 | + |
| 171 | + return wasm; |
| 172 | +} |
| 173 | + |
| 174 | +function initSync(module) { |
| 175 | + if (wasm !== undefined) return wasm; |
| 176 | + |
| 177 | + |
| 178 | + if (typeof module !== 'undefined' && Object.getPrototypeOf(module) === Object.prototype) |
| 179 | + ({module} = module) |
| 180 | + else |
| 181 | + console.warn('using deprecated parameters for `initSync()`; pass a single object instead') |
| 182 | + |
| 183 | + const imports = __wbg_get_imports(); |
| 184 | + |
| 185 | + __wbg_init_memory(imports); |
| 186 | + |
| 187 | + if (!(module instanceof WebAssembly.Module)) { |
| 188 | + module = new WebAssembly.Module(module); |
| 189 | + } |
| 190 | + |
| 191 | + const instance = new WebAssembly.Instance(module, imports); |
| 192 | + |
| 193 | + return __wbg_finalize_init(instance, module); |
| 194 | +} |
| 195 | + |
| 196 | +async function __wbg_init(module_or_path) { |
| 197 | + if (wasm !== undefined) return wasm; |
| 198 | + |
| 199 | + |
| 200 | + if (typeof module_or_path !== 'undefined' && Object.getPrototypeOf(module_or_path) === Object.prototype) |
| 201 | + ({module_or_path} = module_or_path) |
| 202 | + else |
| 203 | + console.warn('using deprecated parameters for the initialization function; pass a single object instead') |
| 204 | + |
| 205 | + if (typeof module_or_path === 'undefined') { |
| 206 | + module_or_path = new URL('cidr_aggregator_bg.wasm', import.meta.url); |
| 207 | + } |
| 208 | + const imports = __wbg_get_imports(); |
| 209 | + |
| 210 | + if (typeof module_or_path === 'string' || (typeof Request === 'function' && module_or_path instanceof Request) || (typeof URL === 'function' && module_or_path instanceof URL)) { |
| 211 | + module_or_path = fetch(module_or_path); |
| 212 | + } |
| 213 | + |
| 214 | + __wbg_init_memory(imports); |
| 215 | + |
| 216 | + const { instance, module } = await __wbg_load(await module_or_path, imports); |
| 217 | + |
| 218 | + return __wbg_finalize_init(instance, module); |
| 219 | +} |
| 220 | + |
| 221 | +export { initSync }; |
| 222 | +export default __wbg_init; |
0 commit comments