def _run_command(self, input: pb.BackendInput) -> pb.BackendOutput: input_bytes = input.SerializeToString() output_bytes = self._backend.command(input_bytes) output = pb.BackendOutput() output.ParseFromString(output_bytes) kind = output.WhichOneof("value") if kind == "error": raise BackendException(output.error) else: return output
def _run_command(self, input: pb.BackendInput, release_gil: bool = False) -> pb.BackendOutput: input_bytes = input.SerializeToString() output_bytes = self._backend.command(input_bytes, release_gil) output = pb.BackendOutput() output.ParseFromString(output_bytes) kind = output.WhichOneof("value") if kind == "error": raise proto_exception_to_native(output.error) else: return output
def run_command(self, input: pb.BackendInput) -> pb.BackendOutput: kind = input.WhichOneof("value") handler = getattr(self, kind, None) # run the equivalent of the following, based on available method names # if kind == "deck_tree": # return pb.BackendOutput(deck_tree=self.deck_tree(input.deck_tree)) if handler is not None: input_variant = getattr(input, kind) output_variant = handler(input_variant) output_args: Dict[str, Any] = {kind: output_variant} output = pb.BackendOutput(**output_args) return output else: # forward any unknown commands onto the Rust backend return self.col.backend._run_command(input)