starpc 0.44.0 → 0.46.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/echo/echo.pb.js +1 -1
- package/dist/mock/mock.pb.js +1 -1
- package/dist/rpcstream/rpcstream.pb.js +1 -1
- package/dist/srpc/rpcproto.pb.js +1 -1
- package/echo/Cargo.toml +0 -4
- package/echo/echo.pb.go +1 -1
- package/echo/echo.pb.rs +9 -0
- package/echo/echo.pb.ts +1 -1
- package/echo/echo_e2e_test.cpp +793 -34
- package/echo/echo_srpc.pb.cpp +1 -1
- package/echo/echo_srpc.pb.go +1 -1
- package/echo/echo_srpc.pb.hpp +3 -1
- package/echo/echo_srpc.pb.rs +312 -0
- package/echo/gen/mod.rs +15 -2
- package/echo/main.rs +9 -0
- package/go.mod +4 -3
- package/go.sum +8 -6
- package/mock/mock.pb.go +1 -1
- package/mock/mock.pb.rs +9 -0
- package/mock/mock.pb.ts +1 -1
- package/mock/mock_srpc.pb.cpp +1 -1
- package/mock/mock_srpc.pb.go +1 -1
- package/mock/mock_srpc.pb.hpp +3 -1
- package/mock/mock_srpc.pb.rs +103 -0
- package/package.json +5 -4
- package/srpc/Cargo.toml +1 -2
- package/srpc/client-rpc.cpp +20 -18
- package/srpc/client-rpc.hpp +14 -11
- package/srpc/client.cpp +11 -15
- package/srpc/client.hpp +17 -25
- package/srpc/common-rpc.cpp +12 -13
- package/srpc/common-rpc.hpp +13 -11
- package/srpc/errors.hpp +33 -20
- package/srpc/handler.hpp +3 -3
- package/srpc/invoker.hpp +26 -29
- package/srpc/lib.rs +1 -0
- package/srpc/message.hpp +4 -6
- package/srpc/msg-stream.hpp +13 -11
- package/srpc/mux.cpp +18 -17
- package/srpc/mux.hpp +15 -14
- package/srpc/packet.cpp +24 -26
- package/srpc/packet.hpp +14 -17
- package/srpc/proto.rs +5 -0
- package/srpc/rpcproto.pb.go +1 -1
- package/srpc/rpcproto.pb.rs +62 -0
- package/srpc/rpcproto.pb.ts +1 -1
- package/srpc/rpcstream/mod.rs +38 -0
- package/srpc/rpcstream/proto.rs +286 -0
- package/srpc/rpcstream/stream.rs +517 -0
- package/srpc/rpcstream/writer.rs +150 -0
- package/srpc/server-rpc.cpp +21 -21
- package/srpc/server-rpc.hpp +15 -13
- package/srpc/starpc.hpp +1 -1
- package/srpc/stream.hpp +18 -16
- package/srpc/writer.hpp +15 -12
- package/echo/build.rs +0 -15
- package/srpc/build.rs +0 -15
- package/srpc/proto/mod.rs +0 -10
package/srpc/message.hpp
CHANGED
|
@@ -13,18 +13,16 @@ using Message = google::protobuf::MessageLite;
|
|
|
13
13
|
|
|
14
14
|
// MarshalVT serializes the message to bytes.
|
|
15
15
|
// (VT suffix matches vtprotobuf convention used in Go)
|
|
16
|
-
inline bool MarshalVT(const Message&
|
|
16
|
+
inline bool MarshalVT(const Message &msg, std::string *out) {
|
|
17
17
|
return msg.SerializeToString(out);
|
|
18
18
|
}
|
|
19
19
|
|
|
20
20
|
// UnmarshalVT deserializes the message from bytes.
|
|
21
|
-
inline bool UnmarshalVT(Message*
|
|
21
|
+
inline bool UnmarshalVT(Message *msg, const std::string &data) {
|
|
22
22
|
return msg->ParseFromString(data);
|
|
23
23
|
}
|
|
24
24
|
|
|
25
25
|
// SizeVT returns the serialized size of the message.
|
|
26
|
-
inline size_t SizeVT(const Message& msg)
|
|
27
|
-
return msg.ByteSizeLong();
|
|
28
|
-
}
|
|
26
|
+
inline size_t SizeVT(const Message &msg) { return msg.ByteSizeLong(); }
|
|
29
27
|
|
|
30
|
-
}
|
|
28
|
+
} // namespace starpc
|
package/srpc/msg-stream.hpp
CHANGED
|
@@ -12,15 +12,16 @@ namespace starpc {
|
|
|
12
12
|
// MsgStreamRw is the read-write interface for MsgStream.
|
|
13
13
|
// Matches Go MsgStreamRw interface in msg-stream.go
|
|
14
14
|
class MsgStreamRw {
|
|
15
|
-
|
|
15
|
+
public:
|
|
16
16
|
virtual ~MsgStreamRw() = default;
|
|
17
17
|
|
|
18
18
|
// ReadOne reads a single message and returns.
|
|
19
19
|
// Returns EOF_ if the stream ended.
|
|
20
|
-
virtual Error ReadOne(std::string*
|
|
20
|
+
virtual Error ReadOne(std::string *out) = 0;
|
|
21
21
|
|
|
22
22
|
// WriteCallData writes a call data packet.
|
|
23
|
-
virtual Error WriteCallData(const std::string&
|
|
23
|
+
virtual Error WriteCallData(const std::string &data, bool data_is_zero,
|
|
24
|
+
bool complete, Error err) = 0;
|
|
24
25
|
|
|
25
26
|
// WriteCallCancel writes a call cancel (close) packet.
|
|
26
27
|
virtual Error WriteCallCancel() = 0;
|
|
@@ -29,13 +30,13 @@ class MsgStreamRw {
|
|
|
29
30
|
// MsgStream implements the stream interface passed to implementations.
|
|
30
31
|
// Matches Go MsgStream struct in msg-stream.go
|
|
31
32
|
class MsgStream : public Stream {
|
|
32
|
-
|
|
33
|
+
public:
|
|
33
34
|
// Constructor matching NewMsgStream in Go
|
|
34
|
-
MsgStream(MsgStreamRw*
|
|
35
|
+
MsgStream(MsgStreamRw *rw, std::function<void()> close_cb)
|
|
35
36
|
: rw_(rw), close_cb_(std::move(close_cb)) {}
|
|
36
37
|
|
|
37
38
|
// MsgSend sends the message to the remote.
|
|
38
|
-
Error MsgSend(const Message&
|
|
39
|
+
Error MsgSend(const Message &msg) override {
|
|
39
40
|
std::string msg_data;
|
|
40
41
|
if (!msg.SerializeToString(&msg_data)) {
|
|
41
42
|
return Error::InvalidMessage;
|
|
@@ -44,7 +45,7 @@ class MsgStream : public Stream {
|
|
|
44
45
|
}
|
|
45
46
|
|
|
46
47
|
// MsgRecv receives an incoming message from the remote.
|
|
47
|
-
Error MsgRecv(Message*
|
|
48
|
+
Error MsgRecv(Message *msg) override {
|
|
48
49
|
std::string data;
|
|
49
50
|
Error err = rw_->ReadOne(&data);
|
|
50
51
|
if (err != Error::OK) {
|
|
@@ -70,15 +71,16 @@ class MsgStream : public Stream {
|
|
|
70
71
|
return err;
|
|
71
72
|
}
|
|
72
73
|
|
|
73
|
-
|
|
74
|
-
MsgStreamRw*
|
|
74
|
+
private:
|
|
75
|
+
MsgStreamRw *rw_;
|
|
75
76
|
std::function<void()> close_cb_;
|
|
76
77
|
};
|
|
77
78
|
|
|
78
79
|
// NewMsgStream constructs a new Stream with a MsgStreamRw.
|
|
79
80
|
// Matches Go NewMsgStream function in msg-stream.go
|
|
80
|
-
inline std::unique_ptr<MsgStream> NewMsgStream(MsgStreamRw*
|
|
81
|
+
inline std::unique_ptr<MsgStream> NewMsgStream(MsgStreamRw *rw,
|
|
82
|
+
std::function<void()> close_cb) {
|
|
81
83
|
return std::make_unique<MsgStream>(rw, std::move(close_cb));
|
|
82
84
|
}
|
|
83
85
|
|
|
84
|
-
}
|
|
86
|
+
} // namespace starpc
|
package/srpc/mux.cpp
CHANGED
|
@@ -1,14 +1,15 @@
|
|
|
1
1
|
//go:build deps_only
|
|
2
2
|
|
|
3
3
|
#include "mux.hpp"
|
|
4
|
+
#include <mutex>
|
|
4
5
|
|
|
5
6
|
namespace starpc {
|
|
6
7
|
|
|
7
|
-
Mux::Mux(std::vector<Invoker*> fallback_invokers)
|
|
8
|
+
Mux::Mux(std::vector<Invoker *> fallback_invokers)
|
|
8
9
|
: fallback_(std::move(fallback_invokers)) {}
|
|
9
10
|
|
|
10
|
-
Error Mux::Register(Handler*
|
|
11
|
-
const std::string&
|
|
11
|
+
Error Mux::Register(Handler *handler) {
|
|
12
|
+
const std::string &service_id = handler->GetServiceID();
|
|
12
13
|
auto method_ids = handler->GetMethodIDs();
|
|
13
14
|
|
|
14
15
|
if (service_id.empty()) {
|
|
@@ -17,8 +18,8 @@ Error Mux::Register(Handler* handler) {
|
|
|
17
18
|
|
|
18
19
|
std::unique_lock<std::shared_mutex> lock(mtx_);
|
|
19
20
|
|
|
20
|
-
auto&
|
|
21
|
-
for (const auto&
|
|
21
|
+
auto &service_methods = services_[service_id];
|
|
22
|
+
for (const auto &method_id : method_ids) {
|
|
22
23
|
if (!method_id.empty()) {
|
|
23
24
|
service_methods[method_id] = handler;
|
|
24
25
|
}
|
|
@@ -27,7 +28,7 @@ Error Mux::Register(Handler* handler) {
|
|
|
27
28
|
return Error::OK;
|
|
28
29
|
}
|
|
29
30
|
|
|
30
|
-
bool Mux::HasService(const std::string&
|
|
31
|
+
bool Mux::HasService(const std::string &service_id) const {
|
|
31
32
|
if (service_id.empty()) {
|
|
32
33
|
return false;
|
|
33
34
|
}
|
|
@@ -37,7 +38,8 @@ bool Mux::HasService(const std::string& service_id) const {
|
|
|
37
38
|
return it != services_.end() && !it->second.empty();
|
|
38
39
|
}
|
|
39
40
|
|
|
40
|
-
bool Mux::HasServiceMethod(const std::string&
|
|
41
|
+
bool Mux::HasServiceMethod(const std::string &service_id,
|
|
42
|
+
const std::string &method_id) const {
|
|
41
43
|
if (service_id.empty() || method_id.empty()) {
|
|
42
44
|
return false;
|
|
43
45
|
}
|
|
@@ -48,8 +50,8 @@ bool Mux::HasServiceMethod(const std::string& service_id, const std::string& met
|
|
|
48
50
|
return false;
|
|
49
51
|
}
|
|
50
52
|
|
|
51
|
-
for (const auto&
|
|
52
|
-
for (const auto&
|
|
53
|
+
for (const auto &[mid, handler] : svc_it->second) {
|
|
54
|
+
for (const auto &handler_method : handler->GetMethodIDs()) {
|
|
53
55
|
if (handler_method == method_id) {
|
|
54
56
|
return true;
|
|
55
57
|
}
|
|
@@ -59,18 +61,17 @@ bool Mux::HasServiceMethod(const std::string& service_id, const std::string& met
|
|
|
59
61
|
return false;
|
|
60
62
|
}
|
|
61
63
|
|
|
62
|
-
std::pair<bool, Error> Mux::InvokeMethod(
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
Handler* handler = nullptr;
|
|
64
|
+
std::pair<bool, Error> Mux::InvokeMethod(const std::string &service_id,
|
|
65
|
+
const std::string &method_id,
|
|
66
|
+
Stream *strm) {
|
|
67
|
+
Handler *handler = nullptr;
|
|
67
68
|
|
|
68
69
|
{
|
|
69
70
|
std::shared_lock<std::shared_mutex> lock(mtx_);
|
|
70
71
|
|
|
71
72
|
if (service_id.empty()) {
|
|
72
73
|
// If service string is empty, search all services
|
|
73
|
-
for (const auto&
|
|
74
|
+
for (const auto &[svc_id, svc_methods] : services_) {
|
|
74
75
|
auto it = svc_methods.find(method_id);
|
|
75
76
|
if (it != svc_methods.end()) {
|
|
76
77
|
handler = it->second;
|
|
@@ -93,7 +94,7 @@ std::pair<bool, Error> Mux::InvokeMethod(
|
|
|
93
94
|
}
|
|
94
95
|
|
|
95
96
|
// Try fallback invokers
|
|
96
|
-
for (auto*
|
|
97
|
+
for (auto *invoker : fallback_) {
|
|
97
98
|
if (invoker != nullptr) {
|
|
98
99
|
auto [handled, err] = invoker->InvokeMethod(service_id, method_id, strm);
|
|
99
100
|
if (err != Error::OK || handled) {
|
|
@@ -105,4 +106,4 @@ std::pair<bool, Error> Mux::InvokeMethod(
|
|
|
105
106
|
return {false, Error::OK};
|
|
106
107
|
}
|
|
107
108
|
|
|
108
|
-
}
|
|
109
|
+
} // namespace starpc
|
package/srpc/mux.hpp
CHANGED
|
@@ -14,38 +14,38 @@ namespace starpc {
|
|
|
14
14
|
// Mux contains a set of <service, method> handlers.
|
|
15
15
|
// Matches Go Mux interface in mux.go
|
|
16
16
|
class Mux : public Invoker, public QueryableInvoker {
|
|
17
|
-
|
|
17
|
+
public:
|
|
18
18
|
// Constructor matching NewMux in Go
|
|
19
|
-
explicit Mux(std::vector<Invoker*> fallback_invokers = {});
|
|
19
|
+
explicit Mux(std::vector<Invoker *> fallback_invokers = {});
|
|
20
20
|
~Mux() override = default;
|
|
21
21
|
|
|
22
22
|
// Register registers a new RPC method handler (service).
|
|
23
23
|
// Matches Go Register in mux.go
|
|
24
|
-
Error Register(Handler*
|
|
24
|
+
Error Register(Handler *handler);
|
|
25
25
|
|
|
26
26
|
// InvokeMethod invokes the method matching the service & method ID.
|
|
27
27
|
// Returns {found, error} - found is false if method not found.
|
|
28
28
|
// If service string is empty, ignore it.
|
|
29
29
|
// Matches Go InvokeMethod in mux.go
|
|
30
|
-
std::pair<bool, Error> InvokeMethod(
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
Stream* strm) override;
|
|
30
|
+
std::pair<bool, Error> InvokeMethod(const std::string &service_id,
|
|
31
|
+
const std::string &method_id,
|
|
32
|
+
Stream *strm) override;
|
|
34
33
|
|
|
35
34
|
// HasService checks if the service ID exists in the handlers.
|
|
36
35
|
// Matches Go HasService in mux.go
|
|
37
|
-
bool HasService(const std::string&
|
|
36
|
+
bool HasService(const std::string &service_id) const override;
|
|
38
37
|
|
|
39
38
|
// HasServiceMethod checks if <service-id, method-id> exists in the handlers.
|
|
40
39
|
// Matches Go HasServiceMethod in mux.go
|
|
41
|
-
bool HasServiceMethod(const std::string&
|
|
40
|
+
bool HasServiceMethod(const std::string &service_id,
|
|
41
|
+
const std::string &method_id) const override;
|
|
42
42
|
|
|
43
|
-
|
|
43
|
+
private:
|
|
44
44
|
// Mapping from method id to handler
|
|
45
|
-
using MuxMethods = std::unordered_map<std::string, Handler*>;
|
|
45
|
+
using MuxMethods = std::unordered_map<std::string, Handler *>;
|
|
46
46
|
|
|
47
47
|
// Fallback invokers
|
|
48
|
-
std::vector<Invoker*> fallback_;
|
|
48
|
+
std::vector<Invoker *> fallback_;
|
|
49
49
|
|
|
50
50
|
// Read-write mutex guards services_
|
|
51
51
|
mutable std::shared_mutex mtx_;
|
|
@@ -56,8 +56,9 @@ class Mux : public Invoker, public QueryableInvoker {
|
|
|
56
56
|
|
|
57
57
|
// NewMux constructs a new Mux.
|
|
58
58
|
// Matches Go NewMux function in mux.go
|
|
59
|
-
inline std::unique_ptr<Mux>
|
|
59
|
+
inline std::unique_ptr<Mux>
|
|
60
|
+
NewMux(std::vector<Invoker *> fallback_invokers = {}) {
|
|
60
61
|
return std::make_unique<Mux>(std::move(fallback_invokers));
|
|
61
62
|
}
|
|
62
63
|
|
|
63
|
-
}
|
|
64
|
+
} // namespace starpc
|
package/srpc/packet.cpp
CHANGED
|
@@ -7,7 +7,7 @@
|
|
|
7
7
|
namespace starpc {
|
|
8
8
|
|
|
9
9
|
PacketDataHandler NewPacketDataHandler(PacketHandler handler) {
|
|
10
|
-
return [handler](const std::string&
|
|
10
|
+
return [handler](const std::string &data) -> Error {
|
|
11
11
|
srpc::Packet pkt;
|
|
12
12
|
if (!pkt.ParseFromString(data)) {
|
|
13
13
|
return Error::InvalidMessage;
|
|
@@ -16,20 +16,20 @@ PacketDataHandler NewPacketDataHandler(PacketHandler handler) {
|
|
|
16
16
|
};
|
|
17
17
|
}
|
|
18
18
|
|
|
19
|
-
Error ValidatePacket(const srpc::Packet&
|
|
19
|
+
Error ValidatePacket(const srpc::Packet &pkt) {
|
|
20
20
|
switch (pkt.body_case()) {
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
21
|
+
case srpc::Packet::kCallStart:
|
|
22
|
+
return ValidateCallStart(pkt.call_start());
|
|
23
|
+
case srpc::Packet::kCallData:
|
|
24
|
+
return ValidateCallData(pkt.call_data());
|
|
25
|
+
case srpc::Packet::kCallCancel:
|
|
26
|
+
return Error::OK;
|
|
27
|
+
default:
|
|
28
|
+
return Error::UnrecognizedPacket;
|
|
29
29
|
}
|
|
30
30
|
}
|
|
31
31
|
|
|
32
|
-
Error ValidateCallStart(const srpc::CallStart&
|
|
32
|
+
Error ValidateCallStart(const srpc::CallStart &pkt) {
|
|
33
33
|
if (pkt.rpc_method().empty()) {
|
|
34
34
|
return Error::EmptyMethodID;
|
|
35
35
|
}
|
|
@@ -39,20 +39,20 @@ Error ValidateCallStart(const srpc::CallStart& pkt) {
|
|
|
39
39
|
return Error::OK;
|
|
40
40
|
}
|
|
41
41
|
|
|
42
|
-
Error ValidateCallData(const srpc::CallData&
|
|
43
|
-
if (pkt.data().empty() && !pkt.complete() && pkt.error().empty() &&
|
|
42
|
+
Error ValidateCallData(const srpc::CallData &pkt) {
|
|
43
|
+
if (pkt.data().empty() && !pkt.complete() && pkt.error().empty() &&
|
|
44
|
+
!pkt.data_is_zero()) {
|
|
44
45
|
return Error::EmptyPacket;
|
|
45
46
|
}
|
|
46
47
|
return Error::OK;
|
|
47
48
|
}
|
|
48
49
|
|
|
49
|
-
std::unique_ptr<srpc::Packet> NewCallStartPacket(
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
bool data_is_zero) {
|
|
50
|
+
std::unique_ptr<srpc::Packet> NewCallStartPacket(const std::string &service,
|
|
51
|
+
const std::string &method,
|
|
52
|
+
const std::string &data,
|
|
53
|
+
bool data_is_zero) {
|
|
54
54
|
auto pkt = std::make_unique<srpc::Packet>();
|
|
55
|
-
auto*
|
|
55
|
+
auto *call_start = pkt->mutable_call_start();
|
|
56
56
|
call_start->set_rpc_service(service);
|
|
57
57
|
call_start->set_rpc_method(method);
|
|
58
58
|
call_start->set_data(data);
|
|
@@ -60,13 +60,11 @@ std::unique_ptr<srpc::Packet> NewCallStartPacket(
|
|
|
60
60
|
return pkt;
|
|
61
61
|
}
|
|
62
62
|
|
|
63
|
-
std::unique_ptr<srpc::Packet> NewCallDataPacket(
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
bool complete,
|
|
67
|
-
Error err) {
|
|
63
|
+
std::unique_ptr<srpc::Packet> NewCallDataPacket(const std::string &data,
|
|
64
|
+
bool data_is_zero,
|
|
65
|
+
bool complete, Error err) {
|
|
68
66
|
auto pkt = std::make_unique<srpc::Packet>();
|
|
69
|
-
auto*
|
|
67
|
+
auto *call_data = pkt->mutable_call_data();
|
|
70
68
|
call_data->set_data(data);
|
|
71
69
|
call_data->set_data_is_zero(data_is_zero);
|
|
72
70
|
call_data->set_complete(err != Error::OK || complete);
|
|
@@ -82,4 +80,4 @@ std::unique_ptr<srpc::Packet> NewCallCancelPacket() {
|
|
|
82
80
|
return pkt;
|
|
83
81
|
}
|
|
84
82
|
|
|
85
|
-
}
|
|
83
|
+
} // namespace starpc
|
package/srpc/packet.hpp
CHANGED
|
@@ -11,7 +11,7 @@ namespace srpc {
|
|
|
11
11
|
class Packet;
|
|
12
12
|
class CallStart;
|
|
13
13
|
class CallData;
|
|
14
|
-
}
|
|
14
|
+
} // namespace srpc
|
|
15
15
|
|
|
16
16
|
namespace starpc {
|
|
17
17
|
|
|
@@ -21,39 +21,36 @@ using CloseHandler = std::function<void(Error close_err)>;
|
|
|
21
21
|
|
|
22
22
|
// PacketHandler handles a packet.
|
|
23
23
|
// Matches Go PacketHandler in packet.go
|
|
24
|
-
using PacketHandler = std::function<Error(const srpc::Packet&
|
|
24
|
+
using PacketHandler = std::function<Error(const srpc::Packet &pkt)>;
|
|
25
25
|
|
|
26
26
|
// PacketDataHandler handles a packet before it is parsed.
|
|
27
27
|
// Matches Go PacketDataHandler in packet.go
|
|
28
|
-
using PacketDataHandler = std::function<Error(const std::string&
|
|
28
|
+
using PacketDataHandler = std::function<Error(const std::string &data)>;
|
|
29
29
|
|
|
30
30
|
// NewPacketDataHandler wraps a PacketHandler with a decoding step.
|
|
31
31
|
PacketDataHandler NewPacketDataHandler(PacketHandler handler);
|
|
32
32
|
|
|
33
33
|
// Validate performs cursory validation of a Packet.
|
|
34
|
-
Error ValidatePacket(const srpc::Packet&
|
|
34
|
+
Error ValidatePacket(const srpc::Packet &pkt);
|
|
35
35
|
|
|
36
36
|
// Validate performs cursory validation of a CallStart.
|
|
37
|
-
Error ValidateCallStart(const srpc::CallStart&
|
|
37
|
+
Error ValidateCallStart(const srpc::CallStart &pkt);
|
|
38
38
|
|
|
39
39
|
// Validate performs cursory validation of a CallData.
|
|
40
|
-
Error ValidateCallData(const srpc::CallData&
|
|
40
|
+
Error ValidateCallData(const srpc::CallData &pkt);
|
|
41
41
|
|
|
42
42
|
// NewCallStartPacket constructs a new CallStart packet.
|
|
43
|
-
std::unique_ptr<srpc::Packet> NewCallStartPacket(
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
bool data_is_zero);
|
|
43
|
+
std::unique_ptr<srpc::Packet> NewCallStartPacket(const std::string &service,
|
|
44
|
+
const std::string &method,
|
|
45
|
+
const std::string &data,
|
|
46
|
+
bool data_is_zero);
|
|
48
47
|
|
|
49
48
|
// NewCallDataPacket constructs a new CallData packet.
|
|
50
|
-
std::unique_ptr<srpc::Packet> NewCallDataPacket(
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
bool complete,
|
|
54
|
-
Error err);
|
|
49
|
+
std::unique_ptr<srpc::Packet> NewCallDataPacket(const std::string &data,
|
|
50
|
+
bool data_is_zero,
|
|
51
|
+
bool complete, Error err);
|
|
55
52
|
|
|
56
53
|
// NewCallCancelPacket constructs a new CallCancel packet with cancel.
|
|
57
54
|
std::unique_ptr<srpc::Packet> NewCallCancelPacket();
|
|
58
55
|
|
|
59
|
-
}
|
|
56
|
+
} // namespace starpc
|
package/srpc/proto.rs
ADDED
package/srpc/rpcproto.pb.go
CHANGED
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
// @generated
|
|
2
|
+
// This file is @generated by prost-build.
|
|
3
|
+
/// Packet is a message sent over a srpc packet connection.
|
|
4
|
+
#[derive(Clone, PartialEq, Eq, Hash, ::prost::Message)]
|
|
5
|
+
pub struct Packet {
|
|
6
|
+
/// Body is the packet body.
|
|
7
|
+
#[prost(oneof="packet::Body", tags="1, 2, 3")]
|
|
8
|
+
pub body: ::core::option::Option<packet::Body>,
|
|
9
|
+
}
|
|
10
|
+
/// Nested message and enum types in `Packet`.
|
|
11
|
+
pub mod packet {
|
|
12
|
+
/// Body is the packet body.
|
|
13
|
+
#[derive(Clone, PartialEq, Eq, Hash, ::prost::Oneof)]
|
|
14
|
+
pub enum Body {
|
|
15
|
+
/// CallStart initiates a new call.
|
|
16
|
+
#[prost(message, tag="1")]
|
|
17
|
+
CallStart(super::CallStart),
|
|
18
|
+
/// CallData is a message in a streaming RPC sequence.
|
|
19
|
+
#[prost(message, tag="2")]
|
|
20
|
+
CallData(super::CallData),
|
|
21
|
+
/// CallCancel cancels the call.
|
|
22
|
+
#[prost(bool, tag="3")]
|
|
23
|
+
CallCancel(bool),
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
/// CallStart requests starting a new RPC call.
|
|
27
|
+
#[derive(Clone, PartialEq, Eq, Hash, ::prost::Message)]
|
|
28
|
+
pub struct CallStart {
|
|
29
|
+
/// RpcService is the service to contact.
|
|
30
|
+
/// Must be set.
|
|
31
|
+
#[prost(string, tag="1")]
|
|
32
|
+
pub rpc_service: ::prost::alloc::string::String,
|
|
33
|
+
/// RpcMethod is the RPC method to call.
|
|
34
|
+
/// Must be set.
|
|
35
|
+
#[prost(string, tag="2")]
|
|
36
|
+
pub rpc_method: ::prost::alloc::string::String,
|
|
37
|
+
/// Data contains the request or the first message in the stream.
|
|
38
|
+
/// Optional if streaming.
|
|
39
|
+
#[prost(bytes="vec", tag="3")]
|
|
40
|
+
pub data: ::prost::alloc::vec::Vec<u8>,
|
|
41
|
+
/// DataIsZero indicates Data is set with an empty message.
|
|
42
|
+
#[prost(bool, tag="4")]
|
|
43
|
+
pub data_is_zero: bool,
|
|
44
|
+
}
|
|
45
|
+
/// CallData contains a message in a streaming RPC sequence.
|
|
46
|
+
#[derive(Clone, PartialEq, Eq, Hash, ::prost::Message)]
|
|
47
|
+
pub struct CallData {
|
|
48
|
+
/// Data contains the packet in the sequence.
|
|
49
|
+
#[prost(bytes="vec", tag="1")]
|
|
50
|
+
pub data: ::prost::alloc::vec::Vec<u8>,
|
|
51
|
+
/// DataIsZero indicates Data is set with an empty message.
|
|
52
|
+
#[prost(bool, tag="2")]
|
|
53
|
+
pub data_is_zero: bool,
|
|
54
|
+
/// Complete indicates the RPC call is completed.
|
|
55
|
+
#[prost(bool, tag="3")]
|
|
56
|
+
pub complete: bool,
|
|
57
|
+
/// Error contains any error that caused the RPC to fail.
|
|
58
|
+
/// If set, implies complete=true.
|
|
59
|
+
#[prost(string, tag="4")]
|
|
60
|
+
pub error: ::prost::alloc::string::String,
|
|
61
|
+
}
|
|
62
|
+
// @@protoc_insertion_point(module)
|
package/srpc/rpcproto.pb.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
// @generated by protoc-gen-es-lite unknown with parameter "ts_nocheck=false
|
|
1
|
+
// @generated by protoc-gen-es-lite unknown with parameter "target=ts,ts_nocheck=false"
|
|
2
2
|
// @generated from file github.com/aperturerobotics/starpc/srpc/rpcproto.proto (package srpc, syntax proto3)
|
|
3
3
|
/* eslint-disable */
|
|
4
4
|
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
//! RpcStream module for nested RPC calls.
|
|
2
|
+
//!
|
|
3
|
+
//! This module enables nesting RPC calls within RPC calls, supporting
|
|
4
|
+
//! component-based architectures where different components expose different
|
|
5
|
+
//! services via sub-streams.
|
|
6
|
+
//!
|
|
7
|
+
//! # Overview
|
|
8
|
+
//!
|
|
9
|
+
//! The rpcstream protocol works as follows:
|
|
10
|
+
//! 1. Client opens a bidirectional stream to the server
|
|
11
|
+
//! 2. Client sends `RpcStreamInit` with the target component ID
|
|
12
|
+
//! 3. Server looks up the component and sends `RpcAck`
|
|
13
|
+
//! 4. Both sides exchange `RpcStreamPacket::Data` containing nested RPC packets
|
|
14
|
+
//!
|
|
15
|
+
//! # Example
|
|
16
|
+
//!
|
|
17
|
+
//! ```rust,ignore
|
|
18
|
+
//! use starpc::rpcstream::{open_rpc_stream, RpcStreamGetter};
|
|
19
|
+
//!
|
|
20
|
+
//! // Client side: open a stream to a component
|
|
21
|
+
//! let stream = my_service.rpc_stream().await?;
|
|
22
|
+
//! let rpc_stream = open_rpc_stream(stream, "my-component", true).await?;
|
|
23
|
+
//!
|
|
24
|
+
//! // Server side: handle incoming rpc stream
|
|
25
|
+
//! let getter: RpcStreamGetter = Arc::new(|ctx, component_id, released| {
|
|
26
|
+
//! // Look up the invoker for this component
|
|
27
|
+
//! Some((invoker, release_fn))
|
|
28
|
+
//! });
|
|
29
|
+
//! handle_rpc_stream(stream, getter).await?;
|
|
30
|
+
//! ```
|
|
31
|
+
|
|
32
|
+
mod proto;
|
|
33
|
+
mod stream;
|
|
34
|
+
mod writer;
|
|
35
|
+
|
|
36
|
+
pub use proto::*;
|
|
37
|
+
pub use stream::*;
|
|
38
|
+
pub use writer::*;
|