mirror of
https://github.com/google/flatbuffers.git
synced 2026-06-02 12:05:50 +00:00
Fix Python host-endianness dependencies (#7773)
* In Python tests, use host-endian-independent dtypes * Fix host endianness dependence in Python flexbuffers Co-authored-by: Derek Bailey <derekbailey@google.com>
This commit is contained in:
@@ -75,7 +75,7 @@ class BitWidth(enum.IntEnum):
|
||||
@staticmethod
|
||||
def F(value):
|
||||
"""Returns the `BitWidth` to encode floating point value."""
|
||||
if struct.unpack('f', struct.pack('f', value))[0] == value:
|
||||
if struct.unpack('<f', struct.pack('<f', value))[0] == value:
|
||||
return BitWidth.W32
|
||||
return BitWidth.W64
|
||||
|
||||
@@ -95,20 +95,20 @@ F = {4: 'f', 8: 'd'} # Floating point formats
|
||||
|
||||
|
||||
def _Unpack(fmt, buf):
|
||||
return struct.unpack(fmt[len(buf)], buf)[0]
|
||||
return struct.unpack('<%s' % fmt[len(buf)], buf)[0]
|
||||
|
||||
|
||||
def _UnpackVector(fmt, buf, length):
|
||||
byte_width = len(buf) // length
|
||||
return struct.unpack('%d%s' % (length, fmt[byte_width]), buf)
|
||||
return struct.unpack('<%d%s' % (length, fmt[byte_width]), buf)
|
||||
|
||||
|
||||
def _Pack(fmt, value, byte_width):
|
||||
return struct.pack(fmt[byte_width], value)
|
||||
return struct.pack('<%s' % fmt[byte_width], value)
|
||||
|
||||
|
||||
def _PackVector(fmt, values, byte_width):
|
||||
return struct.pack('%d%s' % (len(values), fmt[byte_width]), *values)
|
||||
return struct.pack('<%d%s' % (len(values), fmt[byte_width]), *values)
|
||||
|
||||
|
||||
def _Mutate(fmt, buf, value, byte_width, value_bit_width):
|
||||
|
||||
Reference in New Issue
Block a user