Allow parsing messages from byteslike

Byteslike objects (like memoryview) do not have a decode function defined.
Instead, a string may be created from them by passing them to the str
constructor along with an encoding.
This commit is contained in:
Robin Lambertz 2021-08-25 12:53:02 +02:00 committed by GitHub
parent ad8b91766a
commit fb2793e0b6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -866,7 +866,7 @@ class Message(ABC):
value = struct.unpack(fmt, value)[0]
elif wire_type == WIRE_LEN_DELIM:
if meta.proto_type == TYPE_STRING:
value = value.decode("utf-8")
value = str(value, "utf-8")
elif meta.proto_type == TYPE_MESSAGE:
cls = self._betterproto.cls_by_field[field_name]