github.com/primecitizens/pcz/std@v0.2.1/plat/js/webext/system/network/bindings/ffi_bindings.ts (about)

     1  import { importModule, Application, heap, Pointer } from "@ffi";
     2  
     3  importModule("plat/js/webext/system/network", (A: Application) => {
     4    const WEBEXT = typeof globalThis.browser === "undefined" ? globalThis.chrome : globalThis.browser;
     5  
     6    return {
     7      "store_NetworkInterface": (ptr: Pointer, ref: heap.Ref<any>) => {
     8        const x = A.H.get<any>(ref);
     9  
    10        if (typeof x === "undefined") {
    11          A.store.Bool(ptr + 13, false);
    12          A.store.Ref(ptr + 0, undefined);
    13          A.store.Ref(ptr + 4, undefined);
    14          A.store.Bool(ptr + 12, false);
    15          A.store.Int32(ptr + 8, 0);
    16        } else {
    17          A.store.Bool(ptr + 13, true);
    18          A.store.Ref(ptr + 0, x["name"]);
    19          A.store.Ref(ptr + 4, x["address"]);
    20          A.store.Bool(ptr + 12, "prefixLength" in x ? true : false);
    21          A.store.Int32(ptr + 8, x["prefixLength"] === undefined ? 0 : (x["prefixLength"] as number));
    22        }
    23      },
    24      "load_NetworkInterface": (ptr: Pointer, create: heap.Ref<boolean>, ref: heap.Ref<any>): heap.Ref<any> => {
    25        const x = create === A.H.TRUE ? {} : A.H.get<any>(ref);
    26  
    27        x["name"] = A.load.Ref(ptr + 0, undefined);
    28        x["address"] = A.load.Ref(ptr + 4, undefined);
    29        if (A.load.Bool(ptr + 12)) {
    30          x["prefixLength"] = A.load.Int32(ptr + 8);
    31        } else {
    32          delete x["prefixLength"];
    33        }
    34        return create === A.H.TRUE ? A.H.push(x) : ref;
    35      },
    36      "has_GetNetworkInterfaces": (): heap.Ref<boolean> => {
    37        if (WEBEXT?.system?.network && "getNetworkInterfaces" in WEBEXT?.system?.network) {
    38          return A.H.TRUE;
    39        }
    40        return A.H.FALSE;
    41      },
    42      "func_GetNetworkInterfaces": (fn: Pointer): void => {
    43        A.store.Ref(fn, WEBEXT.system.network.getNetworkInterfaces);
    44      },
    45      "call_GetNetworkInterfaces": (retPtr: Pointer): void => {
    46        const _ret = WEBEXT.system.network.getNetworkInterfaces();
    47        A.store.Ref(retPtr, _ret);
    48      },
    49      "try_GetNetworkInterfaces": (retPtr: Pointer, errPtr: Pointer): heap.Ref<boolean> => {
    50        try {
    51          const _ret = WEBEXT.system.network.getNetworkInterfaces();
    52          A.store.Ref(retPtr, _ret);
    53          return A.H.TRUE;
    54        } catch (err: any) {
    55          A.store.Ref(errPtr, err);
    56          return A.H.FALSE;
    57        }
    58      },
    59    };
    60  });