def message_from_dict(data: Dict[str, Any]) -> Message: if "_type" not in data: raise InvalidProtocolMessage( "Invalid message data. Can not find the data type") from None if data["_type"] not in VALID_MESSAGE_TYPES: raise InvalidProtocolMessage( 'Invalid message type (data["type"] = {})'.format( data["_type"])) from None return DictSerializer.deserialize(data)
def message_from_dict(data: dict) -> Message: try: klass: Message = CLASSNAME_TO_CLASS[data["type"]] except KeyError: if "type" in data: raise InvalidProtocolMessage( 'Invalid message type (data["type"] = {})'.format(data["type"]) ) from None raise InvalidProtocolMessage("Invalid message data. Can not find the data type") from None return klass.from_dict(data)
def from_dict(data: dict) -> 'Message': try: klass = CLASSNAME_TO_CLASS[data['type']] except KeyError: if 'type' in data: raise InvalidProtocolMessage( 'Invalid message type (data["type"] = {})'.format( data['type']), ) from None else: raise InvalidProtocolMessage( 'Invalid message data. Can not find the data type', ) from None return klass.from_dict(data)
def decode(data): try: klass = CMDID_TO_CLASS[data[0]] except KeyError: raise InvalidProtocolMessage( 'Invalid message type (data[0] = {})'.format(hex(data[0]))) return klass.decode(data)
def __init__(self, data): if len(data) < size: raise InvalidProtocolMessage( 'data buffer has less than the expected size {}'.format(size), ) object.__setattr__(self, 'data', data)
def from_dict(data): try: klass = CLASSNAME_TO_CLASS[data['type']] except KeyError: raise InvalidProtocolMessage( 'Invalid message type (data["type"] = {})'.format(data['type']), ) from None return klass.from_dict(data)