Encode struct as binary data and decode binary data into struct with correct endian