Skip to content
Snippets Groups Projects
Commit 58c36dfd authored by André Anjos's avatar André Anjos :speech_balloon:
Browse files

Merge branch 'fix_baseformat_string_packing' into 'master'

Fix handling of string when packing

See merge request !36
parents c1fd1a4b 6bb1a104
No related branches found
No related tags found
1 merge request!36Fix handling of string when packing
Pipeline #25575 passed
...@@ -267,8 +267,10 @@ def pack_array(dtype, value, fd): ...@@ -267,8 +267,10 @@ def pack_array(dtype, value, fd):
fd.write(value.tostring()) fd.write(value.tostring())
elif issubclass(dtype, str): # it is a string elif issubclass(dtype, str): # it is a string
for o in value.flat: for item in value.flat:
fd.write(struct.pack(STRING % len(o), len(o), o.encode('utf-8'))) encoded = item.encode('utf-8')
length = len(encoded)
fd.write(struct.pack(STRING % length, length, encoded))
else: # it is a dataformat else: # it is a dataformat
for o in value.flat: for o in value.flat:
...@@ -298,8 +300,9 @@ def pack_scalar(dtype, value, fd): ...@@ -298,8 +300,9 @@ def pack_scalar(dtype, value, fd):
fd.write(struct.pack(ENDIANNESS + BINCODE[dtype], value)) fd.write(struct.pack(ENDIANNESS + BINCODE[dtype], value))
elif issubclass(dtype, str): # it is a string elif issubclass(dtype, str): # it is a string
fd.write(struct.pack(STRING % len(value), len(value), encoded = value.encode('utf-8')
value.encode('utf8'))) length = len(encoded)
fd.write(struct.pack(STRING % length, length, encoded))
else: # it is a dataformat else: # it is a dataformat
value.pack_into(fd) 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