I have C code which returns a void* and size_t length to Javascript running in a web worker. In Javascript i have the following
let start = getStartAddress();
let len = getLength();
I know for Strings i can do
let mystring = UTF8ToString(start);
This is documented https://emscripten.org/docs/api_reference/preamble.js.html#conversion-functions-strings-pointers-and-arrays
I am at a total loss as to how i get an Uint8Array that i can send through postMessage.
Where would i find documentation that tells me how to do that?
In the absence of documentation an answer to my question would suffice.
Uint8Arraythat i can send throughpostMessage." - hang on, what's going on here? Why do you need to useUint8Arrayin JS? Do you want the JS to allocate first, or the C code to allocate firsty? What is the technical problem exactly?ArrayBuffer? It can representUInt8Arrayarrays and it's a transferrable object which can safely be used withpostMessageand other browser APIs without issue.buffer, and make a copy of its contents. I can't tell if there's no simpler way now, but see my experiment with wasm from 4 years ago here: stackoverflow.com/questions/51666736/… - I simply accesse.memory.buffer, wheree=instance.exports, comes from the instantiated wasm module.bufferof the module, but make a copy of what you need. And remember while you are making the copy you will likely use a typed array (like most probably aUint8Array), but what you can transfer is the underlyingArrayBuffer.