1 #include <torch/csrc/distributed/rpc/python_resp.h> 2 3 namespace torch::distributed::rpc { 4 PythonResp(SerializedPyObj && serializedPyObj)5PythonResp::PythonResp(SerializedPyObj&& serializedPyObj) 6 : serializedPyObj_(std::move(serializedPyObj)) {} 7 toMessageImpl()8c10::intrusive_ptr<Message> PythonResp::toMessageImpl() && { 9 auto payload = std::vector<char>( 10 serializedPyObj_.payload_.begin(), serializedPyObj_.payload_.end()); 11 return c10::make_intrusive<Message>( 12 std::move(payload), 13 std::move(serializedPyObj_.tensors_), 14 MessageType::PYTHON_RET); 15 } 16 fromMessage(const Message & message)17std::unique_ptr<PythonResp> PythonResp::fromMessage(const Message& message) { 18 std::string payload(message.payload().begin(), message.payload().end()); 19 std::vector<Tensor> tensors = message.tensors(); 20 SerializedPyObj serializedPyObj(std::move(payload), std::move(tensors)); 21 return std::make_unique<PythonResp>(std::move(serializedPyObj)); 22 } 23 serializedPyObj() const24const SerializedPyObj& PythonResp::serializedPyObj() const { 25 return serializedPyObj_; 26 } 27 28 } // namespace torch::distributed::rpc 29