diff --git a/coapthon/messages/message.py b/coapthon/messages/message.py index 6364bf8..d8159f9 100644 --- a/coapthon/messages/message.py +++ b/coapthon/messages/message.py @@ -119,17 +119,16 @@ class Message(object): """ Set the Token of the message. - :type value: String + :type value: Bytes :param value: the Token :raise AttributeError: if value is longer than 256 """ if value is None: self._token = value return - if isinstance(value, int): - value = bytes([value]) if not isinstance(value, bytes): - value = bytes(value, "utf-8") + value = bytes(value) + if len(value) > 256: raise AttributeError self._token = value diff --git a/coapthon/serializer.py b/coapthon/serializer.py index 3b5e914..2f4683f 100644 --- a/coapthon/serializer.py +++ b/coapthon/serializer.py @@ -157,10 +157,8 @@ class Serializer(object): values = [tmp, message.code, message.mid] if message.token is not None and tkl > 0: - - for b in message.token: - fmt += "B" - values.append(b) + fmt += "%ss" % tkl + values.append(message.token) options = Serializer.as_sorted_list(message.options) # already sorted lastoptionnumber = 0