Skip to content
Snippets Groups Projects
Commit 6bb1a104 authored by Samuel GAIST's avatar Samuel GAIST
Browse files

[baseformat] Fix handling of string when packing

The size used for packing the string was wrong because it used the
original string lenght rather than the encoded.
parent c1fd1a4b
Branches
Tags
1 merge request!36Fix handling of string when packing
Pipeline #25574 passed
......@@ -267,8 +267,10 @@ def pack_array(dtype, value, fd):
fd.write(value.tostring())
elif issubclass(dtype, str): # it is a string
for o in value.flat:
fd.write(struct.pack(STRING % len(o), len(o), o.encode('utf-8')))
for item in value.flat:
encoded = item.encode('utf-8')
length = len(encoded)
fd.write(struct.pack(STRING % length, length, encoded))
else: # it is a dataformat
for o in value.flat:
......@@ -298,8 +300,9 @@ def pack_scalar(dtype, value, fd):
fd.write(struct.pack(ENDIANNESS + BINCODE[dtype], value))
elif issubclass(dtype, str): # it is a string
fd.write(struct.pack(STRING % len(value), len(value),
value.encode('utf8')))
encoded = value.encode('utf-8')
length = len(encoded)
fd.write(struct.pack(STRING % length, length, encoded))
else: # it is a dataformat
value.pack_into(fd)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment