Cracker0dks
Cracker0dks

Reputation: 2490

How can i get the dataType when Array is castet into an ArrayBuffer?

I have an Array:

var dataArray = new Uint16Array(256);

then my array goes over nodeJs to an other pc. (nodejs binaryType = "arraybuffer")

How do I know on the other client that i have to cast to Uint16Array and not Uint8Array?

Note: the bit depth and array length is a dynamic value and can change while programm is running.

Thanks :)

Upvotes: 0

Views: 110

Answers (1)

LJᛃ
LJᛃ

Reputation: 8123

When transferring data as ArrayBuffer its just binary buffer data, you need to know with what view you want to access the data with. TypedArrays are just a view on a binary ArrayBuffer.

There are several ways to handle this:

  • Use different routes to submit your data
  • Add a prefix byte to your data
  • And possibly the best solution, do not change your data type mid application. imho a clean interface should only handle one type of data.

Upvotes: 1

Related Questions