This question already has an answer here:
I am reading and unpacking bytes from a hardware device in Python doing something like this:
data = list(struct.unpack('{}f'.format(total_bytes), self.stdout.read(read_bytes)))
That is, I'm reading bytes from the device (via an external command's stdout), and unpacking them into a list of floats.
I'd like to do the same thing in Go. This is my first Go project and I'm very new to the language. This approach did not work:
buf := make([]float32, numbytes)
io.ReadFull(stdout, pwrsBuf)
but fails with the error cannot use buf (type []float32) as type []byte in argument to io.ReadFull
I know that I can read the bytes directly (into a byte slice), but I don't know how to unpack / convert them to floats, as I'm able to do in Python with the above one-liner. How can I do this in Go?
</div>