def get_protocol_command_for(self, msg: bytes) -> protocol.Command: """Return the Command corresponding to the cmd_id encoded in the given msg.""" cmd_id = get_devp2p_cmd_id(msg) self.logger.trace("Got msg with cmd_id: %s", cmd_id) if cmd_id < self.base_protocol.cmd_length: return self.base_protocol.cmd_by_id[cmd_id] elif cmd_id < self.sub_proto.cmd_id_offset + self.sub_proto.cmd_length: return self.sub_proto.cmd_by_id[cmd_id] else: raise UnknownProtocolCommand(f"No protocol found for cmd_id {cmd_id}")
def get_protocol_command_for(self, msg: bytes) -> protocol.Command: """Return the Command corresponding to the cmd_id encoded in the given msg.""" cmd_id = get_devp2p_cmd_id(msg) self.logger.debug("Got msg with cmd_id: %s", cmd_id) if cmd_id < self.base_protocol.cmd_length: proto = self.base_protocol elif cmd_id < self.sub_proto.cmd_id_offset + self.sub_proto.cmd_length: proto = self.sub_proto # type: ignore else: raise UnknownProtocolCommand("No protocol found for cmd_id {}".format(cmd_id)) return proto.cmd_by_id[cmd_id]
def decode(self, data: bytes) -> _DecodedMsgType: packet_type = get_devp2p_cmd_id(data) if packet_type != self.cmd_id: raise ValueError("Wrong packet type: {}".format(packet_type)) return self.decode_payload(data[1:])
def decode(self, data: bytes) -> PayloadType: packet_type = get_devp2p_cmd_id(data) if packet_type != self.cmd_id: raise MalformedMessage("Wrong packet type: {}".format(packet_type)) return self.decode_payload(data[1:])
def decode(self, data: bytes) -> PayloadType: packet_type = get_devp2p_cmd_id(data) if packet_type != self.cmd_id: raise MalformedMessage(f"Wrong packet type: {packet_type}, expected {self.cmd_id}") return self.decode_payload(data[1:])