Passing C enum to function and read in TypeScript

First of all I am not a trained software developper, so please forgive me if I am missing some basics. I am trying to build a wrapper around a dynamic library to IEC 61850 communication.
On the the exposed functions of that library is IedConnection_connect(..., IedClientError error, ...) , where IedClientError is a enum with 23 entries. To be able to use the library I need to 1. create the enumeration in TypeScript and change it to a type array? to be able to pass it down 2. but then I also need to read the changed error again in TypeScript I am not sure how enumerations are coded and how to decode those in TypeScript again and I was hoping one of you can help me out 🙂 BR, Jakob
marvinh.
marvinh.•18d ago
There is a good page about enums in the TS documentation https://www.typescriptlang.org/docs/handbook/enums.html
Leokuma
Leokuma•18d ago
They are just numbers You need to find the enum declaration in the header file (something like IedClientError.h) and see what value is assigned to each enum option. If they are not assigned anything, by default they are assigned a number starting from 0. So if you want to use the first enum option, you pass 0
Jakob
Jakob•18d ago
How would+ This means that I could do something like this? let error = 0; lib.symbols.IedConnection_connect(... , error, ...); console.log(error) This gives me a Segmentation fault (core dumped) error. I think the enum has to be instantiated as an ArrayBuffer, but do not know how to read that buffer correctly.
Leokuma
Leokuma•18d ago
That should work, without an ArrayBuffer Are you declaring the enum as i32? IedConnection_connect: {parameters: [..., "i32", ...]} ooh sorry I just reread OP the function will change the value of the error you pass?
Jakob
Jakob•18d ago
Yes exactly that
Leokuma
Leokuma•18d ago
I'm stupid
Jakob
Jakob•18d ago
It does work like so for me. But I am not sure if this is the propper way of doing it: const error = new Uint8Array(1); lib.symbols.IedConnection_connect(conn, error, host, port); The result is then error[0] And I declare the variable as buffer in the symbols object
Leokuma
Leokuma•18d ago
That's correct
Jakob
Jakob•18d ago
Thank you for the fast response 😄
Leokuma
Leokuma•18d ago
BTW, to make sure the function is actually writing to the buffer, I suggest you fill up the buffer with something before calling it, just to see if it goes back to zero If it doesn't change, I think we'll have to create a pointer to a buffer or something
More Posts
intergrating Flowbite with freshI want to intergrate Flowbite with Fresh. Any idea on the best way to go about this? And will I be lget file path from FsFilegiven a `Deno.FsFile`, is there a way to get its path (or at least a filename)? i can't really see bulr to rtransparent gradientI am working on reactjs project in the project it should have blur to transperant bg take a look at Streaming video from browser to deno serverTrying to stream video from Chrome to my local Deno server but having trouble understanding how to pMigrating from Deno.run to Deno.command, how to readLines?At the moment I have this: ```ts const command = new Deno.command('...'); for await (const line of rHow to abstract tests to allow running different functions against the same test suite?I've set up two suites of tests like this: https://github.com/gustwindjs/gustwind/tree/develop/htmliFresh tabler icon classHello I want to use the fresh tabler icon lib without using the npm version like this: ```ts { "iRedirection in Testing is Always Valued FalseThis is my first test in full stack framework, especially for Fresh. I'm not sure why the `redirecteNeovim setup with LSP formatting & lintinghello, I am trying to set up the fmt & linting using nvim-lspconfig with neovim Anyone know how i sblock js with #[op2] fn without blocking rust threadI'm using deno_core and I'm looking for a way to block the js main thread without using a sync functConnect to managed databases from "INSIDE" of Deno DeployHi I am trying to connect to a managed database from INSIDE another application in deno Deploy. But something wrong with deno i thinkidk but sh1t wont work?Buffer.from equivalent in deno?on node.js ```js const signerPvtKey = Buffer.from( // process.env.PVT_KEY PVT_KEY, "he'Deno.exit' is not allowed in this context.Locally I can do in a nest project npm run build deno run -A .enviroment/deploy.ts and it works coWASM version of SWC.RC errors only in debug modeNOTE: This is a bare bones example just to illustrate the problem: we aren't transpiling anything juWith Deno.serveHttp marked as deprecated is there a way to run an HTTP server off of a Deno.Conn?I have a bit of weird use-case where I want to start a listener, accept the first TCP connection (anIs this correct for Javascript?https://github.com/tc39/proposal-change-array-by-copy This is my opinion about it: This kind of proDenoLS interfering with TsServer in neovimAny way i could fix this?Finalization not workingI can't get the gc to run a destructor.. At first I thought that I'm making some kind of mistake herdeno inside of a docker containerDespite installing it and confirming it inside I can't run deno in this container. Any idea why?