I am sending 1.0 and 2.0 as binary from C program to STDOUT:
float array[2] = { 1.0, 2.0 };
fwrite(&array[0], sizeof(array[0]), sizeof(array) / sizeof(array[0]), stdout);
fflush(stdout);
Python program reads STDOUT as:
b'\x00\x00\x80?\x00\x00\x00@'
When I try to convert this back to float, this works:
struct.unpack('<f', array[0:4]) # 1.0
struct.unpack('<f', array[4:8]) # 2.0
However, if I try to decode the whole array at once, it fails:
struct.unpack('<f', array)
with the following message:
error: unpack requires a buffer of 4 bytes
Is it possible to decode the whole array at once, or I should decode in a loop each float separately?