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