starpc 0.42.0 → 0.44.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/README.md +95 -19
- package/dist/echo/echo.pb.js +1 -1
- package/dist/mock/mock.pb.d.ts +1 -1
- package/dist/mock/mock.pb.js +5 -6
- package/dist/mock/mock_srpc.pb.d.ts +3 -3
- package/dist/mock/mock_srpc.pb.js +5 -5
- package/dist/rpcstream/rpcstream.pb.js +1 -1
- package/dist/srpc/rpcproto.pb.js +1 -1
- package/echo/Cargo.toml +21 -0
- package/echo/build.rs +15 -0
- package/echo/echo.pb.cc +405 -0
- package/echo/echo.pb.go +9 -27
- package/echo/echo.pb.h +364 -0
- package/echo/echo.pb.ts +1 -1
- package/echo/echo_e2e_test.cpp +289 -0
- package/echo/echo_srpc.pb.cpp +113 -0
- package/echo/echo_srpc.pb.go +1 -1
- package/echo/echo_srpc.pb.hpp +292 -0
- package/echo/gen/mod.rs +3 -0
- package/echo/main.rs +162 -0
- package/go.mod +18 -8
- package/go.sum +32 -22
- package/mock/mock.pb.cc +394 -0
- package/mock/mock.pb.go +9 -27
- package/mock/mock.pb.h +366 -0
- package/mock/mock.pb.ts +12 -14
- package/mock/mock_srpc.pb.cpp +42 -0
- package/mock/mock_srpc.pb.go +1 -1
- package/mock/mock_srpc.pb.hpp +98 -0
- package/mock/mock_srpc.pb.ts +12 -9
- package/package.json +15 -14
- package/srpc/CMakeLists.txt +59 -0
- package/srpc/Cargo.toml +26 -0
- package/srpc/build.rs +15 -0
- package/srpc/client-rpc.cpp +104 -0
- package/srpc/client-rpc.hpp +65 -0
- package/srpc/client.cpp +105 -0
- package/srpc/client.hpp +74 -0
- package/srpc/client.rs +356 -0
- package/srpc/codec.rs +225 -0
- package/srpc/common-rpc.cpp +183 -0
- package/srpc/common-rpc.hpp +107 -0
- package/srpc/error.rs +177 -0
- package/srpc/errors.hpp +58 -0
- package/srpc/handler.hpp +23 -0
- package/srpc/handler.rs +163 -0
- package/srpc/invoker.hpp +94 -0
- package/srpc/invoker.rs +192 -0
- package/srpc/lib.rs +107 -0
- package/srpc/message.hpp +30 -0
- package/srpc/message.rs +9 -0
- package/srpc/msg-stream.hpp +84 -0
- package/srpc/mux.cpp +108 -0
- package/srpc/mux.hpp +63 -0
- package/srpc/mux.rs +353 -0
- package/srpc/packet.cpp +85 -0
- package/srpc/packet.hpp +59 -0
- package/srpc/packet.rs +334 -0
- package/srpc/proto/mod.rs +10 -0
- package/srpc/rpc.rs +777 -0
- package/srpc/rpcproto.pb.cc +1381 -0
- package/srpc/rpcproto.pb.go +75 -183
- package/srpc/rpcproto.pb.h +1451 -0
- package/srpc/rpcproto.pb.ts +1 -1
- package/srpc/server-rpc.cpp +97 -0
- package/srpc/server-rpc.hpp +61 -0
- package/srpc/server.rs +337 -0
- package/srpc/starpc.hpp +18 -0
- package/srpc/stream.hpp +59 -0
- package/srpc/stream.rs +304 -0
- package/srpc/testing.rs +290 -0
- package/srpc/tests/integration_test.rs +495 -0
- package/srpc/transport.rs +218 -0
- package/srpc/writer.hpp +57 -0
- package/Makefile +0 -154
package/README.md
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
# starpc
|
|
2
2
|
|
|
3
3
|
[](https://www.npmjs.com/package/starpc)
|
|
4
|
+
[](https://crates.io/crates/starpc)
|
|
4
5
|
[](https://github.com/aperturerobotics/starpc/actions)
|
|
5
6
|
[![GoDoc Widget]][GoDoc] [![Go Report Card Widget]][Go Report Card]
|
|
6
7
|
|
|
@@ -14,32 +15,43 @@
|
|
|
14
15
|
## Table of Contents
|
|
15
16
|
|
|
16
17
|
- [Features](#features)
|
|
18
|
+
- [Documentation](#documentation)
|
|
17
19
|
- [Installation](#installation)
|
|
18
20
|
- [Quick Start](#quick-start)
|
|
19
21
|
- [Examples](#examples)
|
|
20
22
|
- [Protobuf Definition](#protobuf)
|
|
21
23
|
- [Go Implementation](#go)
|
|
22
24
|
- [TypeScript Implementation](#typescript)
|
|
25
|
+
- [Rust Implementation](#rust)
|
|
23
26
|
- [Debugging](#debugging)
|
|
24
27
|
- [Development Setup](#development-setup)
|
|
25
28
|
- [Support](#support)
|
|
26
29
|
|
|
27
30
|
## Features
|
|
28
31
|
|
|
29
|
-
- Full [Proto3 services] support for TypeScript and
|
|
32
|
+
- Full [Proto3 services] support for TypeScript, Go, and Rust
|
|
30
33
|
- Bidirectional streaming in browsers via WebSocket or WebRTC
|
|
31
34
|
- Built on libp2p streams with [@chainsafe/libp2p-yamux]
|
|
32
35
|
- Efficient multiplexing of RPCs over single connections
|
|
33
36
|
- Zero-reflection Go via [protobuf-go-lite]
|
|
34
37
|
- Lightweight TypeScript via [protobuf-es-lite]
|
|
38
|
+
- Async Rust via [prost] and [tokio]
|
|
35
39
|
- Sub-stream support via [rpcstream]
|
|
36
40
|
|
|
37
41
|
[Proto3 services]: https://developers.google.com/protocol-buffers/docs/proto3#services
|
|
38
42
|
[@chainsafe/libp2p-yamux]: https://github.com/ChainSafe/js-libp2p-yamux
|
|
39
43
|
[protobuf-go-lite]: https://github.com/aperturerobotics/protobuf-go-lite
|
|
40
44
|
[protobuf-es-lite]: https://github.com/aperturerobotics/protobuf-es-lite
|
|
45
|
+
[prost]: https://github.com/tokio-rs/prost
|
|
46
|
+
[tokio]: https://github.com/tokio-rs/tokio
|
|
41
47
|
[rpcstream]: ./rpcstream
|
|
42
48
|
|
|
49
|
+
## Documentation
|
|
50
|
+
|
|
51
|
+
- [Getting Started with TypeScript](./GET_STARTED_TYPESCRIPT.md)
|
|
52
|
+
- [Getting Started with Go](./GET_STARTED_GO.md)
|
|
53
|
+
- [Getting Started with Rust](./GET_STARTED_RUST.md)
|
|
54
|
+
|
|
43
55
|
## Installation
|
|
44
56
|
|
|
45
57
|
```bash
|
|
@@ -47,11 +59,10 @@
|
|
|
47
59
|
git clone -b starpc https://github.com/aperturerobotics/protobuf-project
|
|
48
60
|
cd protobuf-project
|
|
49
61
|
|
|
50
|
-
# Install dependencies
|
|
62
|
+
# Install dependencies (any of these work)
|
|
63
|
+
bun install
|
|
51
64
|
npm install
|
|
52
|
-
yarn install
|
|
53
65
|
pnpm install
|
|
54
|
-
bun install
|
|
55
66
|
|
|
56
67
|
# Generate TypeScript and Go code
|
|
57
68
|
bun run gen
|
|
@@ -134,6 +145,84 @@ For TypeScript <-> TypeScript, see the [e2e] test.
|
|
|
134
145
|
[e2e]: ./e2e/e2e.ts
|
|
135
146
|
[integration]: ./integration/integration.ts
|
|
136
147
|
|
|
148
|
+
### Rust
|
|
149
|
+
|
|
150
|
+
Add the dependencies to your `Cargo.toml`:
|
|
151
|
+
|
|
152
|
+
```toml
|
|
153
|
+
[dependencies]
|
|
154
|
+
starpc = "0.1"
|
|
155
|
+
prost = "0.13"
|
|
156
|
+
tokio = { version = "1", features = ["rt", "macros"] }
|
|
157
|
+
|
|
158
|
+
[build-dependencies]
|
|
159
|
+
starpc-build = "0.1"
|
|
160
|
+
prost-build = "0.13"
|
|
161
|
+
```
|
|
162
|
+
|
|
163
|
+
Create a `build.rs` to generate code from your proto files:
|
|
164
|
+
|
|
165
|
+
```rust
|
|
166
|
+
fn main() -> Result<(), Box<dyn std::error::Error>> {
|
|
167
|
+
starpc_build::configure()
|
|
168
|
+
.compile_protos(&["proto/echo.proto"], &["proto"])?;
|
|
169
|
+
Ok(())
|
|
170
|
+
}
|
|
171
|
+
```
|
|
172
|
+
|
|
173
|
+
Implement and use your service:
|
|
174
|
+
|
|
175
|
+
```rust
|
|
176
|
+
use starpc::{Client, Mux, Server, SrpcClient};
|
|
177
|
+
use std::sync::Arc;
|
|
178
|
+
|
|
179
|
+
// Include generated code
|
|
180
|
+
mod proto {
|
|
181
|
+
include!(concat!(env!("OUT_DIR"), "/echo.rs"));
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
use proto::*;
|
|
185
|
+
|
|
186
|
+
// Implement the server trait
|
|
187
|
+
struct EchoServer;
|
|
188
|
+
|
|
189
|
+
#[starpc::async_trait]
|
|
190
|
+
impl EchoerServer for EchoServer {
|
|
191
|
+
async fn echo(&self, request: EchoMsg) -> starpc::Result<EchoMsg> {
|
|
192
|
+
Ok(request) // Echo back the message
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
#[tokio::main]
|
|
197
|
+
async fn main() -> Result<(), Box<dyn std::error::Error>> {
|
|
198
|
+
// Create server
|
|
199
|
+
let mux = Arc::new(Mux::new());
|
|
200
|
+
mux.register(Arc::new(EchoerHandler::new(EchoServer)))?;
|
|
201
|
+
let server = Server::with_arc(mux);
|
|
202
|
+
|
|
203
|
+
// Create an in-memory connection for demonstration
|
|
204
|
+
let (client_stream, server_stream) = tokio::io::duplex(64 * 1024);
|
|
205
|
+
|
|
206
|
+
// Spawn server handler
|
|
207
|
+
tokio::spawn(async move {
|
|
208
|
+
let _ = server.handle_stream(server_stream).await;
|
|
209
|
+
});
|
|
210
|
+
|
|
211
|
+
// Create client
|
|
212
|
+
let opener = starpc::client::transport::SingleStreamOpener::new(client_stream);
|
|
213
|
+
let client = SrpcClient::new(opener);
|
|
214
|
+
let echoer = EchoerClientImpl::new(client);
|
|
215
|
+
|
|
216
|
+
// Make RPC call
|
|
217
|
+
let response = echoer.echo(&EchoMsg { body: "Hello!".into() }).await?;
|
|
218
|
+
println!("Response: {}", response.body);
|
|
219
|
+
|
|
220
|
+
Ok(())
|
|
221
|
+
}
|
|
222
|
+
```
|
|
223
|
+
|
|
224
|
+
See the [echo example](./echo/main.rs) for a complete working example.
|
|
225
|
+
|
|
137
226
|
#### WebSocket Example
|
|
138
227
|
|
|
139
228
|
Connect to a WebSocket server:
|
|
@@ -226,21 +315,8 @@ Uses [protobuf-es-lite] (fork of [protobuf-es]) for TypeScript.
|
|
|
226
315
|
|
|
227
316
|
### MacOS
|
|
228
317
|
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
```bash
|
|
232
|
-
brew install bash make coreutils gnu-sed findutils protobuf
|
|
233
|
-
brew link --overwrite protobuf
|
|
234
|
-
```
|
|
235
|
-
|
|
236
|
-
Add to your shell rc file (.bashrc, .zshrc):
|
|
237
|
-
|
|
238
|
-
```bash
|
|
239
|
-
export PATH="/opt/homebrew/opt/coreutils/libexec/gnubin:$PATH"
|
|
240
|
-
export PATH="/opt/homebrew/opt/gnu-sed/libexec/gnubin:$PATH"
|
|
241
|
-
export PATH="/opt/homebrew/opt/findutils/libexec/gnubin:$PATH"
|
|
242
|
-
export PATH="/opt/homebrew/opt/make/libexec/gnubin:$PATH"
|
|
243
|
-
```
|
|
318
|
+
The `aptre` CLI handles all protobuf generation without requiring additional
|
|
319
|
+
homebrew packages. Just run `bun run gen` after installing bun.
|
|
244
320
|
|
|
245
321
|
## Support
|
|
246
322
|
|
package/dist/echo/echo.pb.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
// @generated by protoc-gen-es-lite unknown with parameter "target=ts
|
|
1
|
+
// @generated by protoc-gen-es-lite unknown with parameter "ts_nocheck=false,target=ts"
|
|
2
2
|
// @generated from file github.com/aperturerobotics/starpc/echo/echo.proto (package echo, syntax proto3)
|
|
3
3
|
/* eslint-disable */
|
|
4
4
|
import { createMessageType, ScalarType } from '@aptre/protobuf-es-lite';
|
package/dist/mock/mock.pb.d.ts
CHANGED
package/dist/mock/mock.pb.js
CHANGED
|
@@ -1,14 +1,13 @@
|
|
|
1
|
-
// @generated by protoc-gen-es-lite unknown with parameter "target=ts
|
|
1
|
+
// @generated by protoc-gen-es-lite unknown with parameter "ts_nocheck=false,target=ts"
|
|
2
2
|
// @generated from file github.com/aperturerobotics/starpc/mock/mock.proto (package e2e.mock, syntax proto3)
|
|
3
3
|
/* eslint-disable */
|
|
4
|
-
import { createMessageType, ScalarType } from
|
|
5
|
-
export const protobufPackage =
|
|
6
|
-
;
|
|
4
|
+
import { createMessageType, ScalarType } from '@aptre/protobuf-es-lite';
|
|
5
|
+
export const protobufPackage = 'e2e.mock';
|
|
7
6
|
// MockMsg contains the message type declaration for MockMsg.
|
|
8
7
|
export const MockMsg = createMessageType({
|
|
9
|
-
typeName:
|
|
8
|
+
typeName: 'e2e.mock.MockMsg',
|
|
10
9
|
fields: [
|
|
11
|
-
{ no: 1, name:
|
|
10
|
+
{ no: 1, name: 'body', kind: 'scalar', T: ScalarType.STRING },
|
|
12
11
|
],
|
|
13
12
|
packedByDefault: true,
|
|
14
13
|
});
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { MockMsg } from
|
|
2
|
-
import { MethodKind } from
|
|
3
|
-
import { ProtoRpc } from
|
|
1
|
+
import { MockMsg } from './mock.pb.js';
|
|
2
|
+
import { MethodKind } from '@aptre/protobuf-es-lite';
|
|
3
|
+
import { ProtoRpc } from 'starpc';
|
|
4
4
|
/**
|
|
5
5
|
* Mock service mocks some RPCs for the e2e tests.
|
|
6
6
|
*
|
|
@@ -1,15 +1,15 @@
|
|
|
1
1
|
// @generated by protoc-gen-es-starpc none 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
|
-
import { MockMsg } from
|
|
5
|
-
import { MethodKind } from
|
|
4
|
+
import { MockMsg } from './mock.pb.js';
|
|
5
|
+
import { MethodKind } from '@aptre/protobuf-es-lite';
|
|
6
6
|
/**
|
|
7
7
|
* Mock service mocks some RPCs for the e2e tests.
|
|
8
8
|
*
|
|
9
9
|
* @generated from service e2e.mock.Mock
|
|
10
10
|
*/
|
|
11
11
|
export const MockDefinition = {
|
|
12
|
-
typeName:
|
|
12
|
+
typeName: 'e2e.mock.Mock',
|
|
13
13
|
methods: {
|
|
14
14
|
/**
|
|
15
15
|
* MockRequest runs a mock unary request.
|
|
@@ -17,12 +17,12 @@ export const MockDefinition = {
|
|
|
17
17
|
* @generated from rpc e2e.mock.Mock.MockRequest
|
|
18
18
|
*/
|
|
19
19
|
MockRequest: {
|
|
20
|
-
name:
|
|
20
|
+
name: 'MockRequest',
|
|
21
21
|
I: MockMsg,
|
|
22
22
|
O: MockMsg,
|
|
23
23
|
kind: MethodKind.Unary,
|
|
24
24
|
},
|
|
25
|
-
}
|
|
25
|
+
},
|
|
26
26
|
};
|
|
27
27
|
export const MockServiceName = MockDefinition.typeName;
|
|
28
28
|
export class MockClient {
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
// @generated by protoc-gen-es-lite unknown with parameter "target=ts
|
|
1
|
+
// @generated by protoc-gen-es-lite unknown with parameter "ts_nocheck=false,target=ts"
|
|
2
2
|
// @generated from file github.com/aperturerobotics/starpc/rpcstream/rpcstream.proto (package rpcstream, syntax proto3)
|
|
3
3
|
/* eslint-disable */
|
|
4
4
|
import { createMessageType, ScalarType } from '@aptre/protobuf-es-lite';
|
package/dist/srpc/rpcproto.pb.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
// @generated by protoc-gen-es-lite unknown with parameter "target=ts
|
|
1
|
+
// @generated by protoc-gen-es-lite unknown with parameter "ts_nocheck=false,target=ts"
|
|
2
2
|
// @generated from file github.com/aperturerobotics/starpc/srpc/rpcproto.proto (package srpc, syntax proto3)
|
|
3
3
|
/* eslint-disable */
|
|
4
4
|
import { createMessageType, ScalarType } from '@aptre/protobuf-es-lite';
|
package/echo/Cargo.toml
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
[package]
|
|
2
|
+
name = "echo-example"
|
|
3
|
+
version.workspace = true
|
|
4
|
+
edition.workspace = true
|
|
5
|
+
rust-version.workspace = true
|
|
6
|
+
license.workspace = true
|
|
7
|
+
publish = false
|
|
8
|
+
|
|
9
|
+
[[bin]]
|
|
10
|
+
name = "echo-example"
|
|
11
|
+
path = "main.rs"
|
|
12
|
+
|
|
13
|
+
[dependencies]
|
|
14
|
+
starpc = { workspace = true }
|
|
15
|
+
prost = { workspace = true }
|
|
16
|
+
tokio = { version = "1", features = ["full"] }
|
|
17
|
+
async-trait = { workspace = true }
|
|
18
|
+
|
|
19
|
+
[build-dependencies]
|
|
20
|
+
starpc-build = { workspace = true }
|
|
21
|
+
prost-build = { workspace = true }
|
package/echo/build.rs
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
use std::io::Result;
|
|
2
|
+
use std::path::PathBuf;
|
|
3
|
+
|
|
4
|
+
fn main() -> Result<()> {
|
|
5
|
+
let manifest_dir = PathBuf::from(env!("CARGO_MANIFEST_DIR"));
|
|
6
|
+
// Use simplified proto without rpcstream dependency
|
|
7
|
+
let proto_path = manifest_dir.join("echo_rust.proto");
|
|
8
|
+
|
|
9
|
+
println!("cargo:rerun-if-changed={}", proto_path.display());
|
|
10
|
+
|
|
11
|
+
starpc_build::configure()
|
|
12
|
+
.compile_protos(&[proto_path], &[&manifest_dir])?;
|
|
13
|
+
|
|
14
|
+
Ok(())
|
|
15
|
+
}
|