Utilizing Plain JavaScript for Data Transfer in Web Workers
In my current project, I am avoiding the use of Node and sticking to plain JavaScript within the browser. One challenge I encountered is efficiently sending data to web workers. After some experimentation, I successfully created buffers from arrays as shown below:
// assume it contains integers
var numbers = new Int8Array(10);
// works
const data = {buffer: numbers.buffer};
worker.postMessage(data, [data.buffer]);
Now, let's consider a scenario where I have an object structured like this:
var myObject = {'in': [0.123,-0,521], 'out' : [1.409]};
The question that arises is how can I convert this object into a buffer without relying on Node.js? I came across similar inquiries online, but most solutions involved using Node which is not part of my current setup.