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/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.45.1-0.20260203090429-3e915608d4e8
|
|
5
5
|
// source: github.com/aperturerobotics/starpc/echo/echo.proto
|
|
6
6
|
|
|
7
7
|
#include "echo_srpc.pb.hpp"
|
package/echo/echo_srpc.pb.go
CHANGED
package/echo/echo_srpc.pb.hpp
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
|
+
//go:build deps_only && cgo
|
|
2
|
+
|
|
1
3
|
// Code generated by protoc-gen-starpc-cpp. DO NOT EDIT.
|
|
2
|
-
// protoc-gen-starpc-cpp version: v0.
|
|
4
|
+
// protoc-gen-starpc-cpp version: v0.45.1-0.20260203090429-3e915608d4e8
|
|
3
5
|
// source: github.com/aperturerobotics/starpc/echo/echo.proto
|
|
4
6
|
|
|
5
7
|
#pragma once
|
|
@@ -0,0 +1,312 @@
|
|
|
1
|
+
// Code generated by protoc-gen-starpc-rust. DO NOT EDIT.
|
|
2
|
+
// protoc-gen-starpc-rust version: v0.45.1-0.20260203090429-3e915608d4e8
|
|
3
|
+
// source: github.com/aperturerobotics/starpc/echo/echo.proto
|
|
4
|
+
|
|
5
|
+
#[allow(unused_imports)]
|
|
6
|
+
use starpc::StreamExt;
|
|
7
|
+
|
|
8
|
+
/// Service ID for Echoer.
|
|
9
|
+
pub const ECHOER_SERVICE_ID: &str = "echo.Echoer";
|
|
10
|
+
|
|
11
|
+
/// Stream trait for Echoer.EchoServerStream.
|
|
12
|
+
#[starpc::async_trait]
|
|
13
|
+
pub trait EchoerEchoServerStreamStream: Send + Sync {
|
|
14
|
+
/// Returns the context for this stream.
|
|
15
|
+
fn context(&self) -> &starpc::Context;
|
|
16
|
+
/// Receives a message from the stream.
|
|
17
|
+
async fn recv(&self) -> starpc::Result<EchoMsg>;
|
|
18
|
+
/// Closes the stream.
|
|
19
|
+
async fn close(&self) -> starpc::Result<()>;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
/// Stream trait for Echoer.EchoClientStream.
|
|
23
|
+
#[starpc::async_trait]
|
|
24
|
+
pub trait EchoerEchoClientStreamStream: Send + Sync {
|
|
25
|
+
/// Returns the context for this stream.
|
|
26
|
+
fn context(&self) -> &starpc::Context;
|
|
27
|
+
/// Sends a message on the stream.
|
|
28
|
+
async fn send(&self, msg: &EchoMsg) -> starpc::Result<()>;
|
|
29
|
+
/// Closes the send side and receives the response.
|
|
30
|
+
async fn close_and_recv(&self) -> starpc::Result<EchoMsg>;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
/// Stream trait for Echoer.EchoBidiStream.
|
|
34
|
+
#[starpc::async_trait]
|
|
35
|
+
pub trait EchoerEchoBidiStreamStream: Send + Sync {
|
|
36
|
+
/// Returns the context for this stream.
|
|
37
|
+
fn context(&self) -> &starpc::Context;
|
|
38
|
+
/// Sends a message on the stream.
|
|
39
|
+
async fn send(&self, msg: &EchoMsg) -> starpc::Result<()>;
|
|
40
|
+
/// Receives a message from the stream.
|
|
41
|
+
async fn recv(&self) -> starpc::Result<EchoMsg>;
|
|
42
|
+
/// Closes the stream.
|
|
43
|
+
async fn close(&self) -> starpc::Result<()>;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
/// Stream trait for Echoer.RpcStream.
|
|
47
|
+
#[starpc::async_trait]
|
|
48
|
+
pub trait EchoerRpcStreamStream: Send + Sync {
|
|
49
|
+
/// Returns the context for this stream.
|
|
50
|
+
fn context(&self) -> &starpc::Context;
|
|
51
|
+
/// Sends a message on the stream.
|
|
52
|
+
async fn send(&self, msg: &RpcStreamPacket) -> starpc::Result<()>;
|
|
53
|
+
/// Receives a message from the stream.
|
|
54
|
+
async fn recv(&self) -> starpc::Result<RpcStreamPacket>;
|
|
55
|
+
/// Closes the stream.
|
|
56
|
+
async fn close(&self) -> starpc::Result<()>;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
/// Client trait for Echoer.
|
|
60
|
+
#[starpc::async_trait]
|
|
61
|
+
pub trait EchoerClient: Send + Sync {
|
|
62
|
+
/// Echo.
|
|
63
|
+
async fn echo(&self, request: &EchoMsg) -> starpc::Result<EchoMsg>;
|
|
64
|
+
/// EchoServerStream.
|
|
65
|
+
async fn echo_server_stream(&self, request: &EchoMsg) -> starpc::Result<Box<dyn EchoerEchoServerStreamStream>>;
|
|
66
|
+
/// EchoClientStream.
|
|
67
|
+
async fn echo_client_stream(&self) -> starpc::Result<Box<dyn EchoerEchoClientStreamStream>>;
|
|
68
|
+
/// EchoBidiStream.
|
|
69
|
+
async fn echo_bidi_stream(&self) -> starpc::Result<Box<dyn EchoerEchoBidiStreamStream>>;
|
|
70
|
+
/// RpcStream.
|
|
71
|
+
async fn rpc_stream(&self) -> starpc::Result<Box<dyn EchoerRpcStreamStream>>;
|
|
72
|
+
/// DoNothing.
|
|
73
|
+
async fn do_nothing(&self, request: &Empty) -> starpc::Result<Empty>;
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
/// Client implementation for Echoer.
|
|
77
|
+
pub struct EchoerClientImpl<C> {
|
|
78
|
+
client: C,
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
impl<C: starpc::Client> EchoerClientImpl<C> {
|
|
82
|
+
/// Creates a new client.
|
|
83
|
+
pub fn new(client: C) -> Self {
|
|
84
|
+
Self { client }
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
#[starpc::async_trait]
|
|
89
|
+
impl<C: starpc::Client + 'static> EchoerClient for EchoerClientImpl<C> {
|
|
90
|
+
async fn echo(&self, request: &EchoMsg) -> starpc::Result<EchoMsg> {
|
|
91
|
+
self.client.exec_call("echo.Echoer", "Echo", request).await
|
|
92
|
+
}
|
|
93
|
+
async fn echo_server_stream(&self, request: &EchoMsg) -> starpc::Result<Box<dyn EchoerEchoServerStreamStream>> {
|
|
94
|
+
use starpc::ProstMessage;
|
|
95
|
+
let data = request.encode_to_vec();
|
|
96
|
+
let stream = self.client.new_stream("echo.Echoer", "EchoServerStream", Some(&data)).await?;
|
|
97
|
+
stream.close_send().await?;
|
|
98
|
+
Ok(Box::new(EchoerEchoServerStreamStreamImpl { stream }))
|
|
99
|
+
}
|
|
100
|
+
async fn echo_client_stream(&self) -> starpc::Result<Box<dyn EchoerEchoClientStreamStream>> {
|
|
101
|
+
let stream = self.client.new_stream("echo.Echoer", "EchoClientStream", None).await?;
|
|
102
|
+
Ok(Box::new(EchoerEchoClientStreamStreamImpl { stream }))
|
|
103
|
+
}
|
|
104
|
+
async fn echo_bidi_stream(&self) -> starpc::Result<Box<dyn EchoerEchoBidiStreamStream>> {
|
|
105
|
+
let stream = self.client.new_stream("echo.Echoer", "EchoBidiStream", None).await?;
|
|
106
|
+
Ok(Box::new(EchoerEchoBidiStreamStreamImpl { stream }))
|
|
107
|
+
}
|
|
108
|
+
async fn rpc_stream(&self) -> starpc::Result<Box<dyn EchoerRpcStreamStream>> {
|
|
109
|
+
let stream = self.client.new_stream("echo.Echoer", "RpcStream", None).await?;
|
|
110
|
+
Ok(Box::new(EchoerRpcStreamStreamImpl { stream }))
|
|
111
|
+
}
|
|
112
|
+
async fn do_nothing(&self, request: &Empty) -> starpc::Result<Empty> {
|
|
113
|
+
self.client.exec_call("echo.Echoer", "DoNothing", request).await
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
struct EchoerEchoServerStreamStreamImpl {
|
|
118
|
+
stream: Box<dyn starpc::Stream>,
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
#[starpc::async_trait]
|
|
122
|
+
impl EchoerEchoServerStreamStream for EchoerEchoServerStreamStreamImpl {
|
|
123
|
+
fn context(&self) -> &starpc::Context {
|
|
124
|
+
self.stream.context()
|
|
125
|
+
}
|
|
126
|
+
async fn recv(&self) -> starpc::Result<EchoMsg> {
|
|
127
|
+
self.stream.msg_recv().await
|
|
128
|
+
}
|
|
129
|
+
async fn close(&self) -> starpc::Result<()> {
|
|
130
|
+
self.stream.close().await
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
struct EchoerEchoClientStreamStreamImpl {
|
|
135
|
+
stream: Box<dyn starpc::Stream>,
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
#[starpc::async_trait]
|
|
139
|
+
impl EchoerEchoClientStreamStream for EchoerEchoClientStreamStreamImpl {
|
|
140
|
+
fn context(&self) -> &starpc::Context {
|
|
141
|
+
self.stream.context()
|
|
142
|
+
}
|
|
143
|
+
async fn send(&self, msg: &EchoMsg) -> starpc::Result<()> {
|
|
144
|
+
self.stream.msg_send(msg).await
|
|
145
|
+
}
|
|
146
|
+
async fn close_and_recv(&self) -> starpc::Result<EchoMsg> {
|
|
147
|
+
self.stream.close_send().await?;
|
|
148
|
+
self.stream.msg_recv().await
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
struct EchoerEchoBidiStreamStreamImpl {
|
|
153
|
+
stream: Box<dyn starpc::Stream>,
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
#[starpc::async_trait]
|
|
157
|
+
impl EchoerEchoBidiStreamStream for EchoerEchoBidiStreamStreamImpl {
|
|
158
|
+
fn context(&self) -> &starpc::Context {
|
|
159
|
+
self.stream.context()
|
|
160
|
+
}
|
|
161
|
+
async fn send(&self, msg: &EchoMsg) -> starpc::Result<()> {
|
|
162
|
+
self.stream.msg_send(msg).await
|
|
163
|
+
}
|
|
164
|
+
async fn recv(&self) -> starpc::Result<EchoMsg> {
|
|
165
|
+
self.stream.msg_recv().await
|
|
166
|
+
}
|
|
167
|
+
async fn close(&self) -> starpc::Result<()> {
|
|
168
|
+
self.stream.close().await
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
struct EchoerRpcStreamStreamImpl {
|
|
173
|
+
stream: Box<dyn starpc::Stream>,
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
#[starpc::async_trait]
|
|
177
|
+
impl EchoerRpcStreamStream for EchoerRpcStreamStreamImpl {
|
|
178
|
+
fn context(&self) -> &starpc::Context {
|
|
179
|
+
self.stream.context()
|
|
180
|
+
}
|
|
181
|
+
async fn send(&self, msg: &RpcStreamPacket) -> starpc::Result<()> {
|
|
182
|
+
self.stream.msg_send(msg).await
|
|
183
|
+
}
|
|
184
|
+
async fn recv(&self) -> starpc::Result<RpcStreamPacket> {
|
|
185
|
+
self.stream.msg_recv().await
|
|
186
|
+
}
|
|
187
|
+
async fn close(&self) -> starpc::Result<()> {
|
|
188
|
+
self.stream.close().await
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
/// Server trait for Echoer.
|
|
193
|
+
#[starpc::async_trait]
|
|
194
|
+
pub trait EchoerServer: Send + Sync {
|
|
195
|
+
/// Echo.
|
|
196
|
+
async fn echo(&self, request: EchoMsg) -> starpc::Result<EchoMsg>;
|
|
197
|
+
/// EchoServerStream.
|
|
198
|
+
async fn echo_server_stream(&self, request: EchoMsg, stream: Box<dyn starpc::Stream>) -> starpc::Result<()>;
|
|
199
|
+
/// EchoClientStream.
|
|
200
|
+
async fn echo_client_stream(&self, stream: &dyn starpc::Stream) -> starpc::Result<EchoMsg>;
|
|
201
|
+
/// EchoBidiStream.
|
|
202
|
+
async fn echo_bidi_stream(&self, stream: Box<dyn starpc::Stream>) -> starpc::Result<()>;
|
|
203
|
+
/// RpcStream.
|
|
204
|
+
async fn rpc_stream(&self, stream: Box<dyn starpc::Stream>) -> starpc::Result<()>;
|
|
205
|
+
/// DoNothing.
|
|
206
|
+
async fn do_nothing(&self, request: Empty) -> starpc::Result<Empty>;
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
const ECHOER_METHOD_IDS: &[&str] = &[
|
|
210
|
+
"Echo",
|
|
211
|
+
"EchoServerStream",
|
|
212
|
+
"EchoClientStream",
|
|
213
|
+
"EchoBidiStream",
|
|
214
|
+
"RpcStream",
|
|
215
|
+
"DoNothing",
|
|
216
|
+
];
|
|
217
|
+
|
|
218
|
+
/// Handler for Echoer.
|
|
219
|
+
pub struct EchoerHandler<S: EchoerServer> {
|
|
220
|
+
server: std::sync::Arc<S>,
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
impl<S: EchoerServer + 'static> EchoerHandler<S> {
|
|
224
|
+
/// Creates a new handler wrapping the server implementation.
|
|
225
|
+
pub fn new(server: S) -> Self {
|
|
226
|
+
Self { server: std::sync::Arc::new(server) }
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
/// Creates a new handler with a shared server.
|
|
230
|
+
pub fn with_arc(server: std::sync::Arc<S>) -> Self {
|
|
231
|
+
Self { server }
|
|
232
|
+
}
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
#[starpc::async_trait]
|
|
236
|
+
impl<S: EchoerServer + 'static> starpc::Invoker for EchoerHandler<S> {
|
|
237
|
+
async fn invoke_method(
|
|
238
|
+
&self,
|
|
239
|
+
_service_id: &str,
|
|
240
|
+
method_id: &str,
|
|
241
|
+
stream: Box<dyn starpc::Stream>,
|
|
242
|
+
) -> (bool, starpc::Result<()>) {
|
|
243
|
+
match method_id {
|
|
244
|
+
"Echo" => {
|
|
245
|
+
let request: EchoMsg = match stream.msg_recv().await {
|
|
246
|
+
Ok(r) => r,
|
|
247
|
+
Err(e) => return (true, Err(e)),
|
|
248
|
+
};
|
|
249
|
+
match self.server.echo(request).await {
|
|
250
|
+
Ok(response) => {
|
|
251
|
+
if let Err(e) = stream.msg_send(&response).await {
|
|
252
|
+
return (true, Err(e));
|
|
253
|
+
}
|
|
254
|
+
(true, Ok(()))
|
|
255
|
+
}
|
|
256
|
+
Err(e) => (true, Err(e)),
|
|
257
|
+
}
|
|
258
|
+
}
|
|
259
|
+
"EchoServerStream" => {
|
|
260
|
+
let request: EchoMsg = match stream.msg_recv().await {
|
|
261
|
+
Ok(r) => r,
|
|
262
|
+
Err(e) => return (true, Err(e)),
|
|
263
|
+
};
|
|
264
|
+
(true, self.server.echo_server_stream(request, stream).await)
|
|
265
|
+
}
|
|
266
|
+
"EchoClientStream" => {
|
|
267
|
+
match self.server.echo_client_stream(stream.as_ref()).await {
|
|
268
|
+
Ok(response) => {
|
|
269
|
+
if let Err(e) = stream.msg_send(&response).await {
|
|
270
|
+
return (true, Err(e));
|
|
271
|
+
}
|
|
272
|
+
(true, Ok(()))
|
|
273
|
+
}
|
|
274
|
+
Err(e) => (true, Err(e)),
|
|
275
|
+
}
|
|
276
|
+
}
|
|
277
|
+
"EchoBidiStream" => {
|
|
278
|
+
(true, self.server.echo_bidi_stream(stream).await)
|
|
279
|
+
}
|
|
280
|
+
"RpcStream" => {
|
|
281
|
+
(true, self.server.rpc_stream(stream).await)
|
|
282
|
+
}
|
|
283
|
+
"DoNothing" => {
|
|
284
|
+
let request: Empty = match stream.msg_recv().await {
|
|
285
|
+
Ok(r) => r,
|
|
286
|
+
Err(e) => return (true, Err(e)),
|
|
287
|
+
};
|
|
288
|
+
match self.server.do_nothing(request).await {
|
|
289
|
+
Ok(response) => {
|
|
290
|
+
if let Err(e) = stream.msg_send(&response).await {
|
|
291
|
+
return (true, Err(e));
|
|
292
|
+
}
|
|
293
|
+
(true, Ok(()))
|
|
294
|
+
}
|
|
295
|
+
Err(e) => (true, Err(e)),
|
|
296
|
+
}
|
|
297
|
+
}
|
|
298
|
+
_ => (false, Err(starpc::Error::Unimplemented)),
|
|
299
|
+
}
|
|
300
|
+
}
|
|
301
|
+
}
|
|
302
|
+
|
|
303
|
+
impl<S: EchoerServer + 'static> starpc::Handler for EchoerHandler<S> {
|
|
304
|
+
fn service_id(&self) -> &'static str {
|
|
305
|
+
"echo.Echoer"
|
|
306
|
+
}
|
|
307
|
+
|
|
308
|
+
fn method_ids(&self) -> &'static [&'static str] {
|
|
309
|
+
ECHOER_METHOD_IDS
|
|
310
|
+
}
|
|
311
|
+
}
|
|
312
|
+
|
package/echo/gen/mod.rs
CHANGED
|
@@ -1,3 +1,16 @@
|
|
|
1
|
-
//! Generated code
|
|
1
|
+
//! Generated code for the echo service.
|
|
2
|
+
//!
|
|
3
|
+
//! This module includes pre-generated protobuf types and service stubs.
|
|
2
4
|
|
|
3
|
-
|
|
5
|
+
// Re-export starpc's RpcStreamPacket types for use by the service stubs.
|
|
6
|
+
pub use starpc::rpcstream::RpcStreamPacket;
|
|
7
|
+
|
|
8
|
+
// Empty type for google.protobuf.Empty
|
|
9
|
+
#[derive(Clone, PartialEq, Eq, Hash, ::prost::Message)]
|
|
10
|
+
pub struct Empty {}
|
|
11
|
+
|
|
12
|
+
// Include the generated message types.
|
|
13
|
+
include!("../echo.pb.rs");
|
|
14
|
+
|
|
15
|
+
// Include the generated service stubs.
|
|
16
|
+
include!("../echo_srpc.pb.rs");
|
package/echo/main.rs
CHANGED
|
@@ -89,6 +89,15 @@ impl EchoerServer for EchoServerImpl {
|
|
|
89
89
|
|
|
90
90
|
Ok(())
|
|
91
91
|
}
|
|
92
|
+
|
|
93
|
+
async fn rpc_stream(&self, _stream: Box<dyn Stream>) -> Result<()> {
|
|
94
|
+
// RPC stream is not implemented in this example.
|
|
95
|
+
Err(Error::Unimplemented)
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
async fn do_nothing(&self, _request: gen::Empty) -> Result<gen::Empty> {
|
|
99
|
+
Ok(gen::Empty {})
|
|
100
|
+
}
|
|
92
101
|
}
|
|
93
102
|
|
|
94
103
|
#[tokio::main]
|
package/go.mod
CHANGED
|
@@ -11,8 +11,8 @@ replace (
|
|
|
11
11
|
)
|
|
12
12
|
|
|
13
13
|
require (
|
|
14
|
-
github.com/aperturerobotics/common v0.
|
|
15
|
-
github.com/aperturerobotics/protobuf-go-lite v0.12.
|
|
14
|
+
github.com/aperturerobotics/common v0.30.1-0.20260203095300-e0754eb22a37 // latest
|
|
15
|
+
github.com/aperturerobotics/protobuf-go-lite v0.12.1 // latest
|
|
16
16
|
github.com/aperturerobotics/util v1.32.3 // latest
|
|
17
17
|
)
|
|
18
18
|
|
|
@@ -30,10 +30,11 @@ require (
|
|
|
30
30
|
github.com/aperturerobotics/cli v1.1.0 // indirect
|
|
31
31
|
github.com/aperturerobotics/go-protoc-wasi v0.0.0-20260131050911-b5f94b044584 // indirect
|
|
32
32
|
github.com/aperturerobotics/json-iterator-lite v1.0.1-0.20251104042408-0c9eb8a3f726 // indirect
|
|
33
|
-
github.com/aperturerobotics/protobuf v0.0.0-
|
|
33
|
+
github.com/aperturerobotics/protobuf v0.0.0-20260203024654-8201686529c4 // wasi
|
|
34
34
|
)
|
|
35
35
|
|
|
36
36
|
require (
|
|
37
|
+
github.com/aperturerobotics/go-protoc-gen-prost v0.0.0-20260203094828-3faf47d2c868 // indirect
|
|
37
38
|
github.com/ipfs/go-cid v0.4.1 // indirect
|
|
38
39
|
github.com/klauspost/cpuid/v2 v2.2.8 // indirect
|
|
39
40
|
github.com/libp2p/go-buffer-pool v0.1.0 // indirect
|
package/go.sum
CHANGED
|
@@ -2,18 +2,20 @@ github.com/aperturerobotics/abseil-cpp v0.0.0-20260131110040-4bb56e2f9017 h1:3U7
|
|
|
2
2
|
github.com/aperturerobotics/abseil-cpp v0.0.0-20260131110040-4bb56e2f9017/go.mod h1:lNSJTKECIUFAnfeSqy01kXYTYe1BHubW7198jNX3nEw=
|
|
3
3
|
github.com/aperturerobotics/cli v1.1.0 h1:7a+YRC+EY3npAnTzhHV5gLCiw91KS0Ts3XwLILGOsT8=
|
|
4
4
|
github.com/aperturerobotics/cli v1.1.0/go.mod h1:M7BFP9wow5ytTzMyJQOOO991fGfsUqdTI7gGEsHfTQ8=
|
|
5
|
-
github.com/aperturerobotics/common v0.
|
|
6
|
-
github.com/aperturerobotics/common v0.
|
|
5
|
+
github.com/aperturerobotics/common v0.30.1-0.20260203095300-e0754eb22a37 h1:ia/PiOkGovJUA2Evo3Qjn6mARVbpeACO5ENs5EKH3aQ=
|
|
6
|
+
github.com/aperturerobotics/common v0.30.1-0.20260203095300-e0754eb22a37/go.mod h1:o3LkfVkdyNtWz31nGkCKuMP7H2dxarmYCYgXmy1zjtg=
|
|
7
7
|
github.com/aperturerobotics/go-libp2p v0.37.1-0.20241111002741-5cfbb50b74e0 h1:tGwbeDoEeQCrUQL+ClUywldqvz9eRmhcVrGwGxz2xJg=
|
|
8
8
|
github.com/aperturerobotics/go-libp2p v0.37.1-0.20241111002741-5cfbb50b74e0/go.mod h1:FJkAtQcP9XxqG1NNLNHKm+wLVIGSCQX2s6CEoD+w97g=
|
|
9
|
+
github.com/aperturerobotics/go-protoc-gen-prost v0.0.0-20260203094828-3faf47d2c868 h1:r2j7F1tGHkchPBLL55e44g/DfYqK2JV0Ed8suMAxmlU=
|
|
10
|
+
github.com/aperturerobotics/go-protoc-gen-prost v0.0.0-20260203094828-3faf47d2c868/go.mod h1:OBb/beWmr/pDIZAUfi86j/4tBh2v5ctTxKMqSnh9c/4=
|
|
9
11
|
github.com/aperturerobotics/go-protoc-wasi v0.0.0-20260131050911-b5f94b044584 h1:ER8DYYL71cTg39uZ+Gi699tL/hZoscUWDOw4DbizqhI=
|
|
10
12
|
github.com/aperturerobotics/go-protoc-wasi v0.0.0-20260131050911-b5f94b044584/go.mod h1:vEq8i7EKb32+KXGtIEZjjhNns+BdsL2dUMw4uhy3578=
|
|
11
13
|
github.com/aperturerobotics/json-iterator-lite v1.0.1-0.20251104042408-0c9eb8a3f726 h1:4B1F0DzuqPzb6WqgCjWaqDD7JU9RDsevQG5OP0DFBgs=
|
|
12
14
|
github.com/aperturerobotics/json-iterator-lite v1.0.1-0.20251104042408-0c9eb8a3f726/go.mod h1:SvGGBv3OVxUyqO0ZxA/nvs6z3cg7NIbZ64TnbV2OISo=
|
|
13
|
-
github.com/aperturerobotics/protobuf v0.0.0-
|
|
14
|
-
github.com/aperturerobotics/protobuf v0.0.0-
|
|
15
|
-
github.com/aperturerobotics/protobuf-go-lite v0.12.
|
|
16
|
-
github.com/aperturerobotics/protobuf-go-lite v0.12.
|
|
15
|
+
github.com/aperturerobotics/protobuf v0.0.0-20260203024654-8201686529c4 h1:4Dy3BAHh2kgVdHAqtlwcFsgY0kAwUe2m3rfFcaGwGQg=
|
|
16
|
+
github.com/aperturerobotics/protobuf v0.0.0-20260203024654-8201686529c4/go.mod h1:tMgO7y6SJo/d9ZcvrpNqIQtdYT9de+QmYaHOZ4KnhOg=
|
|
17
|
+
github.com/aperturerobotics/protobuf-go-lite v0.12.1 h1:o9of87F/LFS2p5xfq32CrU99dvfqIAalTP7ZzoZK6Kg=
|
|
18
|
+
github.com/aperturerobotics/protobuf-go-lite v0.12.1/go.mod h1:lGH3s5ArCTXKI4wJdlNpaybUtwSjfAG0vdWjxOfMcF8=
|
|
17
19
|
github.com/aperturerobotics/util v1.32.3 h1:wBc6L2guYMgLEzFwORH3CLMoMpfEqbV6pDqYervo3S0=
|
|
18
20
|
github.com/aperturerobotics/util v1.32.3/go.mod h1:qfRZZUDn0sEfc43JRA6rKP8bwFxliqGqJZX+p1jeOnQ=
|
|
19
21
|
github.com/coder/websocket v1.8.14 h1:9L0p0iKiNOibykf283eHkKUHHrpG7f65OE3BhhO7v9g=
|
package/mock/mock.pb.go
CHANGED
package/mock/mock.pb.rs
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
// @generated
|
|
2
|
+
// This file is @generated by prost-build.
|
|
3
|
+
/// MockMsg is the mock message body.
|
|
4
|
+
#[derive(Clone, PartialEq, Eq, Hash, ::prost::Message)]
|
|
5
|
+
pub struct MockMsg {
|
|
6
|
+
#[prost(string, tag="1")]
|
|
7
|
+
pub body: ::prost::alloc::string::String,
|
|
8
|
+
}
|
|
9
|
+
// @@protoc_insertion_point(module)
|
package/mock/mock.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/mock/mock.proto (package e2e.mock, syntax proto3)
|
|
3
3
|
/* eslint-disable */
|
|
4
4
|
|
package/mock/mock_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.45.1-0.20260203090429-3e915608d4e8
|
|
5
5
|
// source: github.com/aperturerobotics/starpc/mock/mock.proto
|
|
6
6
|
|
|
7
7
|
#include "mock_srpc.pb.hpp"
|
package/mock/mock_srpc.pb.go
CHANGED
package/mock/mock_srpc.pb.hpp
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
|
+
//go:build deps_only && cgo
|
|
2
|
+
|
|
1
3
|
// Code generated by protoc-gen-starpc-cpp. DO NOT EDIT.
|
|
2
|
-
// protoc-gen-starpc-cpp version: v0.
|
|
4
|
+
// protoc-gen-starpc-cpp version: v0.45.1-0.20260203090429-3e915608d4e8
|
|
3
5
|
// source: github.com/aperturerobotics/starpc/mock/mock.proto
|
|
4
6
|
|
|
5
7
|
#pragma once
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
// Code generated by protoc-gen-starpc-rust. DO NOT EDIT.
|
|
2
|
+
// protoc-gen-starpc-rust version: v0.45.1-0.20260203090429-3e915608d4e8
|
|
3
|
+
// source: github.com/aperturerobotics/starpc/mock/mock.proto
|
|
4
|
+
|
|
5
|
+
#[allow(unused_imports)]
|
|
6
|
+
use starpc::StreamExt;
|
|
7
|
+
|
|
8
|
+
/// Service ID for Mock.
|
|
9
|
+
pub const MOCK_SERVICE_ID: &str = "e2e.mock.Mock";
|
|
10
|
+
|
|
11
|
+
/// Client trait for Mock.
|
|
12
|
+
#[starpc::async_trait]
|
|
13
|
+
pub trait MockClient: Send + Sync {
|
|
14
|
+
/// MockRequest.
|
|
15
|
+
async fn mock_request(&self, request: &MockMsg) -> starpc::Result<MockMsg>;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
/// Client implementation for Mock.
|
|
19
|
+
pub struct MockClientImpl<C> {
|
|
20
|
+
client: C,
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
impl<C: starpc::Client> MockClientImpl<C> {
|
|
24
|
+
/// Creates a new client.
|
|
25
|
+
pub fn new(client: C) -> Self {
|
|
26
|
+
Self { client }
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
#[starpc::async_trait]
|
|
31
|
+
impl<C: starpc::Client + 'static> MockClient for MockClientImpl<C> {
|
|
32
|
+
async fn mock_request(&self, request: &MockMsg) -> starpc::Result<MockMsg> {
|
|
33
|
+
self.client.exec_call("e2e.mock.Mock", "MockRequest", request).await
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
/// Server trait for Mock.
|
|
38
|
+
#[starpc::async_trait]
|
|
39
|
+
pub trait MockServer: Send + Sync {
|
|
40
|
+
/// MockRequest.
|
|
41
|
+
async fn mock_request(&self, request: MockMsg) -> starpc::Result<MockMsg>;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
const MOCK_METHOD_IDS: &[&str] = &[
|
|
45
|
+
"MockRequest",
|
|
46
|
+
];
|
|
47
|
+
|
|
48
|
+
/// Handler for Mock.
|
|
49
|
+
pub struct MockHandler<S: MockServer> {
|
|
50
|
+
server: std::sync::Arc<S>,
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
impl<S: MockServer + 'static> MockHandler<S> {
|
|
54
|
+
/// Creates a new handler wrapping the server implementation.
|
|
55
|
+
pub fn new(server: S) -> Self {
|
|
56
|
+
Self { server: std::sync::Arc::new(server) }
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
/// Creates a new handler with a shared server.
|
|
60
|
+
pub fn with_arc(server: std::sync::Arc<S>) -> Self {
|
|
61
|
+
Self { server }
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
#[starpc::async_trait]
|
|
66
|
+
impl<S: MockServer + 'static> starpc::Invoker for MockHandler<S> {
|
|
67
|
+
async fn invoke_method(
|
|
68
|
+
&self,
|
|
69
|
+
_service_id: &str,
|
|
70
|
+
method_id: &str,
|
|
71
|
+
stream: Box<dyn starpc::Stream>,
|
|
72
|
+
) -> (bool, starpc::Result<()>) {
|
|
73
|
+
match method_id {
|
|
74
|
+
"MockRequest" => {
|
|
75
|
+
let request: MockMsg = match stream.msg_recv().await {
|
|
76
|
+
Ok(r) => r,
|
|
77
|
+
Err(e) => return (true, Err(e)),
|
|
78
|
+
};
|
|
79
|
+
match self.server.mock_request(request).await {
|
|
80
|
+
Ok(response) => {
|
|
81
|
+
if let Err(e) = stream.msg_send(&response).await {
|
|
82
|
+
return (true, Err(e));
|
|
83
|
+
}
|
|
84
|
+
(true, Ok(()))
|
|
85
|
+
}
|
|
86
|
+
Err(e) => (true, Err(e)),
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
_ => (false, Err(starpc::Error::Unimplemented)),
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
impl<S: MockServer + 'static> starpc::Handler for MockHandler<S> {
|
|
95
|
+
fn service_id(&self) -> &'static str {
|
|
96
|
+
"e2e.mock.Mock"
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
fn method_ids(&self) -> &'static [&'static str] {
|
|
100
|
+
MOCK_METHOD_IDS
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "starpc",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.46.0",
|
|
4
4
|
"description": "Streaming protobuf RPC service protocol over any two-way channel.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"author": {
|
|
@@ -76,6 +76,7 @@
|
|
|
76
76
|
"gen:force": "bun run go:aptre -- generate --force && bun run format",
|
|
77
77
|
"test": "bun run test:js && bun run test:go",
|
|
78
78
|
"test:go": "bun run go:aptre -- test",
|
|
79
|
+
"test:cpp": "mkdir -p build && cd build && cmake .. -DCMAKE_BUILD_TYPE=Release && cmake --build . --parallel && ctest --output-on-failure",
|
|
79
80
|
"build:e2e": "bun run build && cd e2e && esbuild e2e.ts --sourcemap --outfile=e2e.cjs --bundle --platform=node",
|
|
80
81
|
"test:js": "vitest run",
|
|
81
82
|
"test:js:watch": "vitest",
|
|
@@ -107,14 +108,14 @@
|
|
|
107
108
|
"esbuild": "^0.27.0",
|
|
108
109
|
"eslint": "^9.39.1",
|
|
109
110
|
"eslint-config-prettier": "^10.0.2",
|
|
110
|
-
"happy-dom": "^20.
|
|
111
|
+
"happy-dom": "^20.5.0",
|
|
111
112
|
"husky": "^9.1.7",
|
|
112
113
|
"lint-staged": "^16.2.7",
|
|
113
114
|
"prettier": "^3.8.1",
|
|
114
115
|
"rimraf": "^6.1.2",
|
|
115
116
|
"tsx": "^4.20.4",
|
|
116
117
|
"typescript": "^5.8.2",
|
|
117
|
-
"@typescript/native-preview": "^7.0.0-dev.
|
|
118
|
+
"@typescript/native-preview": "^7.0.0-dev.20260202.1",
|
|
118
119
|
"vitest": "^4.0.18"
|
|
119
120
|
},
|
|
120
121
|
"dependencies": {
|
|
@@ -132,6 +133,6 @@
|
|
|
132
133
|
"ws": "^8.18.1"
|
|
133
134
|
},
|
|
134
135
|
"resolutions": {
|
|
135
|
-
"@aptre/protobuf-es-lite": "0.5.
|
|
136
|
+
"@aptre/protobuf-es-lite": "0.5.3"
|
|
136
137
|
}
|
|
137
138
|
}
|
package/srpc/Cargo.toml
CHANGED