Respect binary coded payload data
This commit is contained in:
parent
3c7b11c149
commit
36fb9f243a
2 changed files with 14 additions and 10 deletions
|
@ -42,7 +42,7 @@ class Option(object):
|
||||||
:return: the option value in the correct format depending on the option
|
:return: the option value in the correct format depending on the option
|
||||||
"""
|
"""
|
||||||
if type(self._value) is None:
|
if type(self._value) is None:
|
||||||
self._value = bytearray()
|
self._value = bytes()
|
||||||
opt_type = defines.OptionRegistry.LIST[self._number].value_type
|
opt_type = defines.OptionRegistry.LIST[self._number].value_type
|
||||||
if opt_type == defines.INTEGER:
|
if opt_type == defines.INTEGER:
|
||||||
if byte_len(self._value) > 0:
|
if byte_len(self._value) > 0:
|
||||||
|
|
|
@ -113,13 +113,17 @@ class Serializer(object):
|
||||||
raise AttributeError("Packet length %s, pos %s" % (length_packet, pos))
|
raise AttributeError("Packet length %s, pos %s" % (length_packet, pos))
|
||||||
message.payload = ""
|
message.payload = ""
|
||||||
payload = values[pos:]
|
payload = values[pos:]
|
||||||
try:
|
if hasattr(message, 'payload_type') and message.payload_type in [
|
||||||
if message.payload_type == defines.Content_types["application/octet-stream"]:
|
defines.Content_types["application/octet-stream"],
|
||||||
message.payload = payload
|
defines.Content_types["application/exi"],
|
||||||
else:
|
defines.Content_types["application/cbor"]
|
||||||
|
]:
|
||||||
|
message.payload = payload
|
||||||
|
else:
|
||||||
|
try:
|
||||||
message.payload = payload.decode("utf-8")
|
message.payload = payload.decode("utf-8")
|
||||||
except AttributeError:
|
except AttributeError:
|
||||||
message.payload = payload.decode("utf-8")
|
message.payload = payload
|
||||||
pos += len(payload)
|
pos += len(payload)
|
||||||
|
|
||||||
return message
|
return message
|
||||||
|
@ -323,7 +327,7 @@ class Serializer(object):
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def convert_to_raw(number, value, length):
|
def convert_to_raw(number, value, length):
|
||||||
"""
|
"""
|
||||||
Get the value of an option as a ByteArray.
|
Get the value of an option as bytes.
|
||||||
|
|
||||||
:param number: the option number
|
:param number: the option number
|
||||||
:param value: the option value
|
:param value: the option value
|
||||||
|
@ -350,11 +354,11 @@ class Serializer(object):
|
||||||
if isinstance(value, str):
|
if isinstance(value, str):
|
||||||
value = str(value)
|
value = str(value)
|
||||||
if isinstance(value, str):
|
if isinstance(value, str):
|
||||||
return bytearray(value, "utf-8")
|
return bytes(value, "utf-8")
|
||||||
elif isinstance(value, int):
|
elif isinstance(value, int):
|
||||||
return value
|
return value
|
||||||
else:
|
else:
|
||||||
return bytearray(value)
|
return bytes(value)
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def as_sorted_list(options):
|
def as_sorted_list(options):
|
||||||
|
|
Loading…
Reference in a new issue