deno_bindgen
deno_bindgen copied to clipboard
Accessing structs from C to Deno
Hello, I know this is a rust based codegen but I hope it's ok to ask this. What could be the best way to access structs that contains strings in Deno from C? Is it advisable just to stringify the object in C so that I can do new Deno.UnsafePointerView(ptr).getCString()
in Deno?
Example
typedef struct { char name; int age; } SampleObject;
Consider using https://deno.land/x/byte_type for that.
import { Struct, u8, isize } from "https://deno.land/x/byte_type/ffi.ts";
const SampleObject = new Struct({
name: u8,
age: isize,
});
const ptr = lib.symbols.asd();
const view = new Deno.UnsafePointerView(ptr);
const object = SampleObject.read(view);
Closing this. Using byte_type works .