From d6ac0c4aa2e64d59ed11c8964c83b580d9257489 Mon Sep 17 00:00:00 2001 From: Casey Clements Date: Tue, 1 Oct 2024 09:19:26 -0400 Subject: [PATCH 1/2] Fix for ZSeries --- bson/binary.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/bson/binary.py b/bson/binary.py index 47c52d4892..4fab4dd71e 100644 --- a/bson/binary.py +++ b/bson/binary.py @@ -432,7 +432,7 @@ def from_vector( raise NotImplementedError("%s not yet supported" % dtype) metadata = struct.pack(" BinaryVector: @@ -454,7 +454,7 @@ def as_vector(self) -> BinaryVector: if dtype == BinaryVectorDtype.INT8: dtype_format = "b" - format_string = f"{n_values}{dtype_format}" + format_string = f"<{n_values}{dtype_format}" vector = list(struct.unpack_from(format_string, self, position)) return BinaryVector(vector, dtype, padding) From 70d7a4146dbc1df1c65026164818144f2047edbc Mon Sep 17 00:00:00 2001 From: Casey Clements Date: Tue, 1 Oct 2024 10:12:44 -0400 Subject: [PATCH 2/2] Endianness take II --- bson/binary.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/bson/binary.py b/bson/binary.py index 4fab4dd71e..96b61b6dab 100644 --- a/bson/binary.py +++ b/bson/binary.py @@ -465,13 +465,16 @@ def as_vector(self) -> BinaryVector: raise ValueError( "Corrupt data. N bytes for a float32 vector must be a multiple of 4." ) - vector = list(struct.unpack_from(f"{n_values}f", self, position)) + dtype_format = "f" + format_string = f"<{n_values}{dtype_format}" + vector = list(struct.unpack_from(format_string, self, position)) return BinaryVector(vector, dtype, padding) elif dtype == BinaryVectorDtype.PACKED_BIT: # data packed as uint8 dtype_format = "B" - unpacked_uint8s = list(struct.unpack_from(f"{n_values}{dtype_format}", self, position)) + format_string = f"<{n_values}{dtype_format}" + unpacked_uint8s = list(struct.unpack_from(format_string, self, position)) return BinaryVector(unpacked_uint8s, dtype, padding) else: