diff options
author | Ben Beasley <code@musicinmybrain.net> | 2023-01-10 13:20:08 -0500 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-01-10 10:20:08 -0800 |
commit | b23493a7d2e58bdc62a35be256e55c32185fe223 (patch) | |
tree | 2b3074867194a9efd76cfeabe0f49db23aa772f3 /python | |
parent | b50b6be60a3647b5a320498b9534b6f74450c2b1 (diff) | |
download | flatbuffers-b23493a7d2e58bdc62a35be256e55c32185fe223.tar.gz flatbuffers-b23493a7d2e58bdc62a35be256e55c32185fe223.tar.bz2 flatbuffers-b23493a7d2e58bdc62a35be256e55c32185fe223.zip |
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>
Diffstat (limited to 'python')
-rw-r--r-- | python/flatbuffers/flexbuffers.py | 10 |
1 files changed, 5 insertions, 5 deletions
diff --git a/python/flatbuffers/flexbuffers.py b/python/flatbuffers/flexbuffers.py index aaa02fda..34d42a69 100644 --- a/python/flatbuffers/flexbuffers.py +++ b/python/flatbuffers/flexbuffers.py @@ -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): |