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:])
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}")