コード例 #1
0
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)
コード例 #2
0
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)
コード例 #3
0
ファイル: messages.py プロジェクト: loredanacirstea/raiden
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)
コード例 #4
0
ファイル: messages.py プロジェクト: nguyenquangminh/raiden
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)
コード例 #5
0
ファイル: format.py プロジェクト: zhengyunly/raiden
    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)
コード例 #6
0
ファイル: messages.py プロジェクト: nhatchimai111/raiden
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)