starpc 0.52.0 → 0.52.2
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/README.md +37 -8
- package/dist/echo/client-test.d.ts +1 -1
- package/dist/echo/client-test.js +110 -2
- package/dist/integration/cross-language/tcp-packet-stream.d.ts +3 -0
- package/dist/integration/cross-language/tcp-packet-stream.js +112 -0
- package/dist/integration/cross-language/tcp-packet-stream.test.d.ts +1 -0
- package/dist/integration/cross-language/tcp-packet-stream.test.js +121 -0
- package/dist/integration/cross-language/ts-client.js +50 -37
- package/dist/integration/cross-language/ts-server.js +1 -36
- package/dist/rpcstream/rpcstream.d.ts +5 -1
- package/dist/rpcstream/rpcstream.js +75 -28
- package/dist/rpcstream/rpcstream.test.d.ts +1 -0
- package/dist/rpcstream/rpcstream.test.js +92 -0
- package/dist/srpc/client-rpc.d.ts +1 -0
- package/dist/srpc/client-rpc.js +9 -0
- package/dist/srpc/client-rpc.test.d.ts +1 -0
- package/dist/srpc/client-rpc.test.js +50 -0
- package/dist/srpc/client.js +18 -4
- package/dist/srpc/common-rpc.d.ts +5 -0
- package/dist/srpc/common-rpc.js +37 -8
- package/dist/srpc/common-rpc.test.js +2 -0
- package/dist/srpc/errors.d.ts +2 -0
- package/dist/srpc/errors.js +14 -0
- package/dist/srpc/index.d.ts +1 -1
- package/dist/srpc/index.js +1 -1
- package/dist/srpc/packet-codec.test.d.ts +1 -0
- package/dist/srpc/packet-codec.test.js +75 -0
- package/dist/srpc/packet.d.ts +1 -1
- package/dist/srpc/packet.js +11 -1
- package/dist/srpc/server.js +19 -6
- package/dist/srpc/server.test.js +43 -0
- package/dist/srpc/stream.d.ts +4 -1
- package/dist/srpc/stream.js +62 -3
- package/dist/srpc/stream.test.js +110 -1
- package/dist/srpc/termination.d.ts +27 -0
- package/dist/srpc/termination.js +56 -0
- package/dist/srpc/termination.test.d.ts +1 -0
- package/dist/srpc/termination.test.js +24 -0
- package/dist/testdata/packet-codec-vectors.json +64 -0
- package/echo/Cargo.toml +8 -0
- package/echo/client-test.ts +124 -2
- package/echo/echo_e2e_test.cpp +542 -985
- package/echo/echo_pb2.py +40 -0
- package/echo/echo_pb2.pyi +13 -0
- package/echo/echo_srpc.pb.cpp +3 -5
- package/echo/echo_srpc.pb.go +6 -9
- package/echo/echo_srpc.pb.hpp +23 -3
- package/echo/echo_srpc.pb.rs +61 -26
- package/echo/echo_srpc.py +309 -0
- package/echo/echo_srpc.pyi +85 -0
- package/echo/half_close_test.rs +178 -0
- package/echo/integration_server.rs +14 -21
- package/echo/main.rs +28 -48
- package/go.mod +3 -3
- package/go.sum +6 -8
- package/integration/cross-language/cpp-client.cpp +446 -402
- package/integration/cross-language/cpp-pipe-server.cpp +139 -0
- package/integration/cross-language/cpp-pipe_test.go +114 -0
- package/integration/cross-language/cpp-server.cpp +222 -186
- package/integration/cross-language/go-client/main.go +79 -3
- package/integration/cross-language/python-client.py +146 -0
- package/integration/cross-language/python-server.py +140 -0
- package/integration/cross-language/run.bash +190 -65
- package/integration/cross-language/tcp-packet-stream.test.ts +154 -0
- package/integration/cross-language/tcp-packet-stream.ts +121 -0
- package/integration/cross-language/ts-client.ts +62 -40
- package/integration/cross-language/ts-server.ts +1 -45
- package/mock/mock_pb2.py +38 -0
- package/mock/mock_pb2.pyi +11 -0
- package/mock/mock_srpc.pb.cpp +1 -1
- package/mock/mock_srpc.pb.hpp +1 -1
- package/mock/mock_srpc.pb.rs +10 -9
- package/mock/mock_srpc.py +71 -0
- package/mock/mock_srpc.pyi +27 -0
- package/package.json +19 -5
- package/srpc/CMakeLists.txt +3 -58
- package/srpc/README-cpp.md +69 -0
- package/srpc/__init__.py +0 -0
- package/srpc/accept.go +10 -4
- package/srpc/accept_test.go +25 -0
- package/srpc/build.rs +129 -34
- package/srpc/client-half-close_test.go +152 -0
- package/srpc/client-invoker.go +32 -42
- package/srpc/client-invoker_test.go +53 -0
- package/srpc/client-rpc.cpp +65 -80
- package/srpc/client-rpc.go +32 -33
- package/srpc/client-rpc.hpp +52 -38
- package/srpc/client-rpc.test.ts +67 -0
- package/srpc/client-rpc.ts +10 -0
- package/srpc/client-rpc_test.go +76 -0
- package/srpc/client.cpp +99 -87
- package/srpc/client.hpp +46 -35
- package/srpc/client.rs +78 -38
- package/srpc/client.ts +20 -4
- package/srpc/client_half_close_test.cc +331 -0
- package/srpc/client_invoker.rs +75 -0
- package/srpc/codec.rs +6 -0
- package/srpc/common-rpc.cpp +186 -146
- package/srpc/common-rpc.go +5 -4
- package/srpc/common-rpc.hpp +119 -89
- package/srpc/common-rpc.test.ts +2 -0
- package/srpc/common-rpc.ts +43 -8
- package/srpc/common-rpc_test.go +23 -0
- package/srpc/error.rs +19 -2
- package/srpc/errors.hpp +80 -50
- package/srpc/errors.ts +16 -0
- package/srpc/handler.hpp +9 -7
- package/srpc/handler.rs +7 -45
- package/srpc/index.ts +2 -0
- package/srpc/invoker.hpp +82 -55
- package/srpc/invoker.rs +14 -52
- package/srpc/lib.rs +2 -0
- package/srpc/message.hpp +17 -12
- package/srpc/msg-stream.go +1 -0
- package/srpc/msg-stream.hpp +108 -61
- package/srpc/mux.cpp +84 -84
- package/srpc/mux.hpp +48 -38
- package/srpc/mux.rs +4 -4
- package/srpc/net.go +12 -3
- package/srpc/packet-codec-vectors_test.go +195 -0
- package/srpc/packet-codec.test.ts +139 -0
- package/srpc/packet-rw.go +9 -2
- package/srpc/packet.cpp +60 -58
- package/srpc/packet.hpp +35 -20
- package/srpc/packet.rs +8 -27
- package/srpc/packet.ts +15 -2
- package/srpc/py.typed +0 -0
- package/srpc/rpc.rs +332 -115
- package/srpc/rpc_lifecycle_test.cc +333 -0
- package/srpc/rpcproto_pb2.py +40 -0
- package/srpc/rpcproto_pb2.pyi +40 -0
- package/srpc/server-cancel_test.go +39 -0
- package/srpc/server-rpc.cpp +83 -73
- package/srpc/server-rpc.go +21 -19
- package/srpc/server-rpc.hpp +56 -37
- package/srpc/server.rs +76 -131
- package/srpc/server.test.ts +50 -0
- package/srpc/server.ts +22 -6
- package/srpc/starpc.hpp +4 -2
- package/srpc/stream.go +4 -0
- package/srpc/stream.hpp +95 -34
- package/srpc/stream.rs +7 -2
- package/srpc/stream.test.ts +132 -1
- package/srpc/stream.ts +65 -9
- package/srpc/termination.test.ts +30 -0
- package/srpc/termination.ts +70 -0
- package/srpc/testing.rs +11 -66
- package/srpc/transport.rs +21 -71
- package/srpc/websocket.rs +106 -57
- package/srpc/writer.hpp +46 -32
- package/srpc/yamux.rs +82 -26
- package/srpc/tests/integration_test.rs +0 -495
package/echo/echo_pb2.py
ADDED
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
# -*- coding: utf-8 -*-
|
|
2
|
+
# Generated by the protocol buffer compiler. DO NOT EDIT!
|
|
3
|
+
# NO CHECKED-IN PROTOBUF GENCODE
|
|
4
|
+
# source: github.com/aperturerobotics/starpc/echo/echo.proto
|
|
5
|
+
# Protobuf Python Version: 6.33.4
|
|
6
|
+
"""Generated protocol buffer code."""
|
|
7
|
+
from google.protobuf import descriptor as _descriptor
|
|
8
|
+
from google.protobuf import descriptor_pool as _descriptor_pool
|
|
9
|
+
from google.protobuf import runtime_version as _runtime_version
|
|
10
|
+
from google.protobuf import symbol_database as _symbol_database
|
|
11
|
+
from google.protobuf.internal import builder as _builder
|
|
12
|
+
_runtime_version.ValidateProtobufRuntimeVersion(
|
|
13
|
+
_runtime_version.Domain.PUBLIC,
|
|
14
|
+
6,
|
|
15
|
+
33,
|
|
16
|
+
4,
|
|
17
|
+
'',
|
|
18
|
+
'github.com/aperturerobotics/starpc/echo/echo.proto'
|
|
19
|
+
)
|
|
20
|
+
# @@protoc_insertion_point(imports)
|
|
21
|
+
|
|
22
|
+
_sym_db = _symbol_database.Default()
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
from rpcstream import rpcstream_pb2 as github_dot_com_dot_aperturerobotics_dot_starpc_dot_rpcstream_dot_rpcstream__pb2
|
|
26
|
+
from google.protobuf import empty_pb2 as google_dot_protobuf_dot_empty__pb2
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
DESCRIPTOR = _descriptor_pool.Default().AddSerializedFile(b'\n2github.com/aperturerobotics/starpc/echo/echo.proto\x12\x04\x65\x63ho\x1a<github.com/aperturerobotics/starpc/rpcstream/rpcstream.proto\x1a\x1bgoogle/protobuf/empty.proto\"\x17\n\x07\x45\x63hoMsg\x12\x0c\n\x04\x62ody\x18\x01 \x01(\t2\xd0\x02\n\x06\x45\x63hoer\x12$\n\x04\x45\x63ho\x12\r.echo.EchoMsg\x1a\r.echo.EchoMsg\x12\x32\n\x10\x45\x63hoServerStream\x12\r.echo.EchoMsg\x1a\r.echo.EchoMsg0\x01\x12\x32\n\x10\x45\x63hoClientStream\x12\r.echo.EchoMsg\x1a\r.echo.EchoMsg(\x01\x12\x32\n\x0e\x45\x63hoBidiStream\x12\r.echo.EchoMsg\x1a\r.echo.EchoMsg(\x01\x30\x01\x12G\n\tRpcStream\x12\x1a.rpcstream.RpcStreamPacket\x1a\x1a.rpcstream.RpcStreamPacket(\x01\x30\x01\x12;\n\tDoNothing\x12\x16.google.protobuf.Empty\x1a\x16.google.protobuf.Emptyb\x06proto3')
|
|
30
|
+
|
|
31
|
+
_globals = globals()
|
|
32
|
+
_builder.BuildMessageAndEnumDescriptors(DESCRIPTOR, _globals)
|
|
33
|
+
_builder.BuildTopDescriptorsAndMessages(DESCRIPTOR, 'github.com.aperturerobotics.starpc.echo.echo_pb2', _globals)
|
|
34
|
+
if not _descriptor._USE_C_DESCRIPTORS:
|
|
35
|
+
DESCRIPTOR._loaded_options = None
|
|
36
|
+
_globals['_ECHOMSG']._serialized_start=151
|
|
37
|
+
_globals['_ECHOMSG']._serialized_end=174
|
|
38
|
+
_globals['_ECHOER']._serialized_start=177
|
|
39
|
+
_globals['_ECHOER']._serialized_end=513
|
|
40
|
+
# @@protoc_insertion_point(module_scope)
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
from rpcstream import rpcstream_pb2 as _rpcstream_pb2
|
|
2
|
+
from google.protobuf import empty_pb2 as _empty_pb2
|
|
3
|
+
from google.protobuf import descriptor as _descriptor
|
|
4
|
+
from google.protobuf import message as _message
|
|
5
|
+
from typing import ClassVar as _ClassVar, Optional as _Optional
|
|
6
|
+
|
|
7
|
+
DESCRIPTOR: _descriptor.FileDescriptor
|
|
8
|
+
|
|
9
|
+
class EchoMsg(_message.Message):
|
|
10
|
+
__slots__ = ("body",)
|
|
11
|
+
BODY_FIELD_NUMBER: _ClassVar[int]
|
|
12
|
+
body: str
|
|
13
|
+
def __init__(self, body: _Optional[str] = ...) -> None: ...
|
package/echo/echo_srpc.pb.cpp
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
//go:build deps_only
|
|
2
2
|
|
|
3
3
|
// Code generated by protoc-gen-starpc-cpp. DO NOT EDIT.
|
|
4
|
-
// protoc-gen-starpc-cpp version: v0.
|
|
4
|
+
// protoc-gen-starpc-cpp version: v0.52.2-0.20260927183858-4d0f9be5aa9d+dirty
|
|
5
5
|
// source: github.com/aperturerobotics/starpc/echo/echo.proto
|
|
6
6
|
|
|
7
7
|
#include "echo_srpc.pb.hpp"
|
|
@@ -17,10 +17,8 @@ std::pair<std::unique_ptr<SRPCEchoer_EchoServerStreamClient>, starpc::Error> SRP
|
|
|
17
17
|
if (err != starpc::Error::OK) {
|
|
18
18
|
return {nullptr, err};
|
|
19
19
|
}
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
return {nullptr, err};
|
|
23
|
-
}
|
|
20
|
+
// A failed half-close means the call ended; MsgRecv reports its outcome.
|
|
21
|
+
(void)strm->CloseSend();
|
|
24
22
|
return {std::make_unique<SRPCEchoer_EchoServerStreamClient>(std::move(strm)), starpc::Error::OK};
|
|
25
23
|
}
|
|
26
24
|
|
package/echo/echo_srpc.pb.go
CHANGED
|
@@ -63,9 +63,8 @@ func (c *srpcEchoerClient) EchoServerStream(ctx context.Context, in *EchoMsg) (S
|
|
|
63
63
|
return nil, err
|
|
64
64
|
}
|
|
65
65
|
strm := &srpcEchoer_EchoServerStreamClient{stream}
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
}
|
|
66
|
+
// A failed half-close means the call ended; MsgRecv reports its outcome.
|
|
67
|
+
_ = strm.CloseSend()
|
|
69
68
|
return strm, nil
|
|
70
69
|
}
|
|
71
70
|
|
|
@@ -118,9 +117,8 @@ func (x *srpcEchoer_EchoClientStreamClient) Send(m *EchoMsg) error {
|
|
|
118
117
|
}
|
|
119
118
|
|
|
120
119
|
func (x *srpcEchoer_EchoClientStreamClient) CloseAndRecv() (*EchoMsg, error) {
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
}
|
|
120
|
+
// A failed half-close means the call ended; MsgRecv reports its outcome.
|
|
121
|
+
_ = x.CloseSend()
|
|
124
122
|
m := new(EchoMsg)
|
|
125
123
|
if err := x.MsgRecv(m); err != nil {
|
|
126
124
|
return nil, err
|
|
@@ -129,9 +127,8 @@ func (x *srpcEchoer_EchoClientStreamClient) CloseAndRecv() (*EchoMsg, error) {
|
|
|
129
127
|
}
|
|
130
128
|
|
|
131
129
|
func (x *srpcEchoer_EchoClientStreamClient) CloseAndMsgRecv(m *EchoMsg) error {
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
}
|
|
130
|
+
// A failed half-close means the call ended; MsgRecv reports its outcome.
|
|
131
|
+
_ = x.CloseSend()
|
|
135
132
|
return x.MsgRecv(m)
|
|
136
133
|
}
|
|
137
134
|
|
package/echo/echo_srpc.pb.hpp
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
//go:build deps_only && cgo
|
|
2
2
|
|
|
3
3
|
// Code generated by protoc-gen-starpc-cpp. DO NOT EDIT.
|
|
4
|
-
// protoc-gen-starpc-cpp version: v0.
|
|
4
|
+
// protoc-gen-starpc-cpp version: v0.52.2-0.20260927183858-4d0f9be5aa9d+dirty
|
|
5
5
|
// source: github.com/aperturerobotics/starpc/echo/echo.proto
|
|
6
6
|
|
|
7
7
|
#pragma once
|
|
@@ -146,6 +146,8 @@ class SRPCEchoer_EchoServerStreamClient {
|
|
|
146
146
|
|
|
147
147
|
starpc::Error CloseSend() { return strm_->CloseSend(); }
|
|
148
148
|
starpc::Error Close() { return strm_->Close(); }
|
|
149
|
+
std::stop_token StopToken() const { return strm_->StopToken(); }
|
|
150
|
+
std::string RemoteErrorMessage() const { return strm_->RemoteErrorMessage(); }
|
|
149
151
|
|
|
150
152
|
private:
|
|
151
153
|
std::unique_ptr<starpc::Stream> strm_;
|
|
@@ -155,6 +157,9 @@ class SRPCEchoer_EchoServerStreamClient {
|
|
|
155
157
|
class SRPCEchoer_EchoServerStreamStream {
|
|
156
158
|
public:
|
|
157
159
|
explicit SRPCEchoer_EchoServerStreamStream(starpc::Stream* strm) : strm_(strm) {}
|
|
160
|
+
std::stop_token StopToken() const { return strm_->StopToken(); }
|
|
161
|
+
starpc::Error Close() { return strm_->Close(); }
|
|
162
|
+
starpc::Error CloseSend() { return strm_->CloseSend(); }
|
|
158
163
|
|
|
159
164
|
starpc::Error Send(const echo::EchoMsg& msg) {
|
|
160
165
|
return strm_->MsgSend(msg);
|
|
@@ -180,13 +185,15 @@ class SRPCEchoer_EchoClientStreamClient {
|
|
|
180
185
|
}
|
|
181
186
|
|
|
182
187
|
starpc::Error CloseAndRecv(echo::EchoMsg* msg) {
|
|
183
|
-
|
|
184
|
-
|
|
188
|
+
// A failed half-close means the call ended; MsgRecv reports its outcome.
|
|
189
|
+
(void)strm_->CloseSend();
|
|
185
190
|
return strm_->MsgRecv(msg);
|
|
186
191
|
}
|
|
187
192
|
|
|
188
193
|
starpc::Error CloseSend() { return strm_->CloseSend(); }
|
|
189
194
|
starpc::Error Close() { return strm_->Close(); }
|
|
195
|
+
std::stop_token StopToken() const { return strm_->StopToken(); }
|
|
196
|
+
std::string RemoteErrorMessage() const { return strm_->RemoteErrorMessage(); }
|
|
190
197
|
|
|
191
198
|
private:
|
|
192
199
|
std::unique_ptr<starpc::Stream> strm_;
|
|
@@ -196,6 +203,9 @@ class SRPCEchoer_EchoClientStreamClient {
|
|
|
196
203
|
class SRPCEchoer_EchoClientStreamStream {
|
|
197
204
|
public:
|
|
198
205
|
explicit SRPCEchoer_EchoClientStreamStream(starpc::Stream* strm) : strm_(strm) {}
|
|
206
|
+
std::stop_token StopToken() const { return strm_->StopToken(); }
|
|
207
|
+
starpc::Error Close() { return strm_->Close(); }
|
|
208
|
+
starpc::Error CloseSend() { return strm_->CloseSend(); }
|
|
199
209
|
|
|
200
210
|
starpc::Error Recv(echo::EchoMsg* msg) {
|
|
201
211
|
return strm_->MsgRecv(msg);
|
|
@@ -220,6 +230,8 @@ class SRPCEchoer_EchoBidiStreamClient {
|
|
|
220
230
|
|
|
221
231
|
starpc::Error CloseSend() { return strm_->CloseSend(); }
|
|
222
232
|
starpc::Error Close() { return strm_->Close(); }
|
|
233
|
+
std::stop_token StopToken() const { return strm_->StopToken(); }
|
|
234
|
+
std::string RemoteErrorMessage() const { return strm_->RemoteErrorMessage(); }
|
|
223
235
|
|
|
224
236
|
private:
|
|
225
237
|
std::unique_ptr<starpc::Stream> strm_;
|
|
@@ -229,6 +241,9 @@ class SRPCEchoer_EchoBidiStreamClient {
|
|
|
229
241
|
class SRPCEchoer_EchoBidiStreamStream {
|
|
230
242
|
public:
|
|
231
243
|
explicit SRPCEchoer_EchoBidiStreamStream(starpc::Stream* strm) : strm_(strm) {}
|
|
244
|
+
std::stop_token StopToken() const { return strm_->StopToken(); }
|
|
245
|
+
starpc::Error Close() { return strm_->Close(); }
|
|
246
|
+
starpc::Error CloseSend() { return strm_->CloseSend(); }
|
|
232
247
|
|
|
233
248
|
starpc::Error Send(const echo::EchoMsg& msg) {
|
|
234
249
|
return strm_->MsgSend(msg);
|
|
@@ -263,6 +278,8 @@ class SRPCEchoer_RpcStreamClient {
|
|
|
263
278
|
|
|
264
279
|
starpc::Error CloseSend() { return strm_->CloseSend(); }
|
|
265
280
|
starpc::Error Close() { return strm_->Close(); }
|
|
281
|
+
std::stop_token StopToken() const { return strm_->StopToken(); }
|
|
282
|
+
std::string RemoteErrorMessage() const { return strm_->RemoteErrorMessage(); }
|
|
266
283
|
|
|
267
284
|
private:
|
|
268
285
|
std::unique_ptr<starpc::Stream> strm_;
|
|
@@ -272,6 +289,9 @@ class SRPCEchoer_RpcStreamClient {
|
|
|
272
289
|
class SRPCEchoer_RpcStreamStream {
|
|
273
290
|
public:
|
|
274
291
|
explicit SRPCEchoer_RpcStreamStream(starpc::Stream* strm) : strm_(strm) {}
|
|
292
|
+
std::stop_token StopToken() const { return strm_->StopToken(); }
|
|
293
|
+
starpc::Error Close() { return strm_->Close(); }
|
|
294
|
+
starpc::Error CloseSend() { return strm_->CloseSend(); }
|
|
275
295
|
|
|
276
296
|
starpc::Error Send(const rpcstream::RpcStreamPacket& msg) {
|
|
277
297
|
return strm_->MsgSend(msg);
|
package/echo/echo_srpc.pb.rs
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
// Code generated by protoc-gen-starpc-rust. DO NOT EDIT.
|
|
2
|
-
// protoc-gen-starpc-rust version:
|
|
2
|
+
// protoc-gen-starpc-rust version: (devel)
|
|
3
3
|
// source: github.com/aperturerobotics/starpc/echo/echo.proto
|
|
4
4
|
|
|
5
5
|
#[allow(unused_imports)]
|
|
6
|
-
use starpc::StreamExt;
|
|
6
|
+
use starpc::StreamExt as _;
|
|
7
7
|
|
|
8
8
|
/// Service ID for Echoer.
|
|
9
9
|
pub const ECHOER_SERVICE_ID: &str = "echo.Echoer";
|
|
@@ -62,7 +62,10 @@ pub trait EchoerClient: Send + Sync {
|
|
|
62
62
|
/// Echo.
|
|
63
63
|
async fn echo(&self, request: &EchoMsg) -> starpc::Result<EchoMsg>;
|
|
64
64
|
/// EchoServerStream.
|
|
65
|
-
async fn echo_server_stream(
|
|
65
|
+
async fn echo_server_stream(
|
|
66
|
+
&self,
|
|
67
|
+
request: &EchoMsg,
|
|
68
|
+
) -> starpc::Result<Box<dyn EchoerEchoServerStreamStream>>;
|
|
66
69
|
/// EchoClientStream.
|
|
67
70
|
async fn echo_client_stream(&self) -> starpc::Result<Box<dyn EchoerEchoClientStreamStream>>;
|
|
68
71
|
/// EchoBidiStream.
|
|
@@ -90,27 +93,45 @@ impl<C: starpc::Client + 'static> EchoerClient for EchoerClientImpl<C> {
|
|
|
90
93
|
async fn echo(&self, request: &EchoMsg) -> starpc::Result<EchoMsg> {
|
|
91
94
|
self.client.exec_call("echo.Echoer", "Echo", request).await
|
|
92
95
|
}
|
|
93
|
-
async fn echo_server_stream(
|
|
96
|
+
async fn echo_server_stream(
|
|
97
|
+
&self,
|
|
98
|
+
request: &EchoMsg,
|
|
99
|
+
) -> starpc::Result<Box<dyn EchoerEchoServerStreamStream>> {
|
|
94
100
|
use starpc::ProstMessage;
|
|
95
101
|
let data = request.encode_to_vec();
|
|
96
|
-
let stream = self
|
|
97
|
-
|
|
102
|
+
let stream = self
|
|
103
|
+
.client
|
|
104
|
+
.new_stream("echo.Echoer", "EchoServerStream", Some(&data))
|
|
105
|
+
.await?;
|
|
106
|
+
// A failed half-close means the call ended; msg_recv reports its outcome.
|
|
107
|
+
let _ = stream.close_send().await;
|
|
98
108
|
Ok(Box::new(EchoerEchoServerStreamStreamImpl { stream }))
|
|
99
109
|
}
|
|
100
110
|
async fn echo_client_stream(&self) -> starpc::Result<Box<dyn EchoerEchoClientStreamStream>> {
|
|
101
|
-
let stream = self
|
|
111
|
+
let stream = self
|
|
112
|
+
.client
|
|
113
|
+
.new_stream("echo.Echoer", "EchoClientStream", None)
|
|
114
|
+
.await?;
|
|
102
115
|
Ok(Box::new(EchoerEchoClientStreamStreamImpl { stream }))
|
|
103
116
|
}
|
|
104
117
|
async fn echo_bidi_stream(&self) -> starpc::Result<Box<dyn EchoerEchoBidiStreamStream>> {
|
|
105
|
-
let stream = self
|
|
118
|
+
let stream = self
|
|
119
|
+
.client
|
|
120
|
+
.new_stream("echo.Echoer", "EchoBidiStream", None)
|
|
121
|
+
.await?;
|
|
106
122
|
Ok(Box::new(EchoerEchoBidiStreamStreamImpl { stream }))
|
|
107
123
|
}
|
|
108
124
|
async fn rpc_stream(&self) -> starpc::Result<Box<dyn EchoerRpcStreamStream>> {
|
|
109
|
-
let stream = self
|
|
125
|
+
let stream = self
|
|
126
|
+
.client
|
|
127
|
+
.new_stream("echo.Echoer", "RpcStream", None)
|
|
128
|
+
.await?;
|
|
110
129
|
Ok(Box::new(EchoerRpcStreamStreamImpl { stream }))
|
|
111
130
|
}
|
|
112
131
|
async fn do_nothing(&self, request: &Empty) -> starpc::Result<Empty> {
|
|
113
|
-
self.client
|
|
132
|
+
self.client
|
|
133
|
+
.exec_call("echo.Echoer", "DoNothing", request)
|
|
134
|
+
.await
|
|
114
135
|
}
|
|
115
136
|
}
|
|
116
137
|
|
|
@@ -144,7 +165,8 @@ impl EchoerEchoClientStreamStream for EchoerEchoClientStreamStreamImpl {
|
|
|
144
165
|
self.stream.msg_send(msg).await
|
|
145
166
|
}
|
|
146
167
|
async fn close_and_recv(&self) -> starpc::Result<EchoMsg> {
|
|
147
|
-
|
|
168
|
+
// A failed half-close means the call ended; msg_recv reports its outcome.
|
|
169
|
+
let _ = self.stream.close_send().await;
|
|
148
170
|
self.stream.msg_recv().await
|
|
149
171
|
}
|
|
150
172
|
}
|
|
@@ -193,9 +215,13 @@ impl EchoerRpcStreamStream for EchoerRpcStreamStreamImpl {
|
|
|
193
215
|
#[starpc::async_trait]
|
|
194
216
|
pub trait EchoerServer: Send + Sync {
|
|
195
217
|
/// Echo.
|
|
196
|
-
async fn echo(&self, request: EchoMsg) -> starpc::Result<EchoMsg>;
|
|
218
|
+
async fn echo(&self, context: &starpc::Context, request: EchoMsg) -> starpc::Result<EchoMsg>;
|
|
197
219
|
/// EchoServerStream.
|
|
198
|
-
async fn echo_server_stream(
|
|
220
|
+
async fn echo_server_stream(
|
|
221
|
+
&self,
|
|
222
|
+
request: EchoMsg,
|
|
223
|
+
stream: Box<dyn starpc::Stream>,
|
|
224
|
+
) -> starpc::Result<()>;
|
|
199
225
|
/// EchoClientStream.
|
|
200
226
|
async fn echo_client_stream(&self, stream: &dyn starpc::Stream) -> starpc::Result<EchoMsg>;
|
|
201
227
|
/// EchoBidiStream.
|
|
@@ -203,7 +229,7 @@ pub trait EchoerServer: Send + Sync {
|
|
|
203
229
|
/// RpcStream.
|
|
204
230
|
async fn rpc_stream(&self, stream: Box<dyn starpc::Stream>) -> starpc::Result<()>;
|
|
205
231
|
/// DoNothing.
|
|
206
|
-
async fn do_nothing(&self, request: Empty) -> starpc::Result<Empty>;
|
|
232
|
+
async fn do_nothing(&self, context: &starpc::Context, request: Empty) -> starpc::Result<Empty>;
|
|
207
233
|
}
|
|
208
234
|
|
|
209
235
|
const ECHOER_METHOD_IDS: &[&str] = &[
|
|
@@ -223,7 +249,9 @@ pub struct EchoerHandler<S: EchoerServer> {
|
|
|
223
249
|
impl<S: EchoerServer + 'static> EchoerHandler<S> {
|
|
224
250
|
/// Creates a new handler wrapping the server implementation.
|
|
225
251
|
pub fn new(server: S) -> Self {
|
|
226
|
-
Self {
|
|
252
|
+
Self {
|
|
253
|
+
server: std::sync::Arc::new(server),
|
|
254
|
+
}
|
|
227
255
|
}
|
|
228
256
|
|
|
229
257
|
/// Creates a new handler with a shared server.
|
|
@@ -246,7 +274,7 @@ impl<S: EchoerServer + 'static> starpc::Invoker for EchoerHandler<S> {
|
|
|
246
274
|
Ok(r) => r,
|
|
247
275
|
Err(e) => return (true, Err(e)),
|
|
248
276
|
};
|
|
249
|
-
match self.server.
|
|
277
|
+
match <S as EchoerServer>::echo(self.server.as_ref(), stream.context(), request).await {
|
|
250
278
|
Ok(response) => {
|
|
251
279
|
if let Err(e) = stream.msg_send(&response).await {
|
|
252
280
|
return (true, Err(e));
|
|
@@ -261,10 +289,16 @@ impl<S: EchoerServer + 'static> starpc::Invoker for EchoerHandler<S> {
|
|
|
261
289
|
Ok(r) => r,
|
|
262
290
|
Err(e) => return (true, Err(e)),
|
|
263
291
|
};
|
|
264
|
-
(
|
|
292
|
+
(
|
|
293
|
+
true,
|
|
294
|
+
<S as EchoerServer>::echo_server_stream(self.server.as_ref(), request, stream)
|
|
295
|
+
.await,
|
|
296
|
+
)
|
|
265
297
|
}
|
|
266
298
|
"EchoClientStream" => {
|
|
267
|
-
match self.server.
|
|
299
|
+
match <S as EchoerServer>::echo_client_stream(self.server.as_ref(), stream.as_ref())
|
|
300
|
+
.await
|
|
301
|
+
{
|
|
268
302
|
Ok(response) => {
|
|
269
303
|
if let Err(e) = stream.msg_send(&response).await {
|
|
270
304
|
return (true, Err(e));
|
|
@@ -274,18 +308,20 @@ impl<S: EchoerServer + 'static> starpc::Invoker for EchoerHandler<S> {
|
|
|
274
308
|
Err(e) => (true, Err(e)),
|
|
275
309
|
}
|
|
276
310
|
}
|
|
277
|
-
"EchoBidiStream" =>
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
311
|
+
"EchoBidiStream" => (
|
|
312
|
+
true,
|
|
313
|
+
<S as EchoerServer>::echo_bidi_stream(self.server.as_ref(), stream).await,
|
|
314
|
+
),
|
|
315
|
+
"RpcStream" => (
|
|
316
|
+
true,
|
|
317
|
+
<S as EchoerServer>::rpc_stream(self.server.as_ref(), stream).await,
|
|
318
|
+
),
|
|
283
319
|
"DoNothing" => {
|
|
284
320
|
let request: Empty = match stream.msg_recv().await {
|
|
285
321
|
Ok(r) => r,
|
|
286
322
|
Err(e) => return (true, Err(e)),
|
|
287
323
|
};
|
|
288
|
-
match self.server.
|
|
324
|
+
match <S as EchoerServer>::do_nothing(self.server.as_ref(), stream.context(), request).await {
|
|
289
325
|
Ok(response) => {
|
|
290
326
|
if let Err(e) = stream.msg_send(&response).await {
|
|
291
327
|
return (true, Err(e));
|
|
@@ -309,4 +345,3 @@ impl<S: EchoerServer + 'static> starpc::Handler for EchoerHandler<S> {
|
|
|
309
345
|
ECHOER_METHOD_IDS
|
|
310
346
|
}
|
|
311
347
|
}
|
|
312
|
-
|