简体   繁体   中英

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 :)

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM