def decode(cls, to_decode): """ Create a header from a encoded message. Parameters ---------- to_decode(str): the message to decode """ list_from_decode = _decode(to_decode, HEADER_ROOT_DELIM_INDEX) rv = MessageHeader() rv._restore_from_list(list_from_decode) return rv
def decode(cls, to_decode, payload_type = -1): """ Decode a message and attempt to create an appropriate payload from it. If no payload type is given, a payload type is provided by the calling class. Parameters ---------- to_decode(str): the message to decode payload_type(int): the type of payload to be created a value of -1 will use class information to decode """ if payload_type == -1: payload_type = cls.PAYLOAD_ID rv = cls._new_payload(payload_type) list_from_decode = _decode(to_decode, PAYLOAD_ROOT_DELIM_INDEX) rv._restore_from_list(list_from_decode) if 1 or rv.verify(): return rv else: raise TypeError("Message/Type pairing was not valid.")