Context
I know that in python you can create an a string representing the packed bytes of an array doing something like such:
import numpy as np
np.array([1, 2], dtype=np.int32).tobytes()
# returns '\x01\x00\x00\x00\x02\x00\x00\x00'
np.array([1, 2], dtype=np.float32).tobytes()
# returns '\x00\x00\x80?\x00\x00\x00@'
And they can be decoded using np.fromstring
Question
Currently, my Javascript is receiving a string of packed bytes that encodes an array of floats (i.e. '\x00\x00\x80?\x00\x00\x00@'
) and I need to decode the array -- what is the best way to do this?
(if it were an array of ints I imagine I could use text-encoding to pull the bytes and then just multiply and add appropriately...)
Thanks,