starpc 0.45.0 → 0.46.1

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.
@@ -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.45.0",
3
+ "version": "0.46.1",
4
4
  "description": "Streaming protobuf RPC service protocol over any two-way channel.",
5
5
  "license": "MIT",
6
6
  "author": {
package/srpc/Cargo.toml CHANGED
@@ -21,6 +21,5 @@ futures = { workspace = true }
21
21
  thiserror = { workspace = true }
22
22
  async-trait = { workspace = true }
23
23
  pin-project-lite = { workspace = true }
24
+ scopeguard = { workspace = true }
24
25
 
25
- [build-dependencies]
26
- prost-build = { workspace = true }
@@ -1,4 +1,4 @@
1
- // go:build deps_only
1
+ //go:build deps_only
2
2
 
3
3
  #include "client-rpc.hpp"
4
4
 
package/srpc/client.cpp CHANGED
@@ -1,4 +1,4 @@
1
- // go:build deps_only
1
+ //go:build deps_only
2
2
 
3
3
  #include "client.hpp"
4
4
 
@@ -1,4 +1,4 @@
1
- // go:build deps_only
1
+ //go:build deps_only
2
2
 
3
3
  #include "common-rpc.hpp"
4
4
 
package/srpc/lib.rs CHANGED
@@ -66,6 +66,8 @@ pub mod mux;
66
66
  pub mod packet;
67
67
  pub mod proto;
68
68
  pub mod rpc;
69
+ #[path = "../rpcstream/mod.rs"]
70
+ pub mod rpcstream;
69
71
  pub mod server;
70
72
  pub mod stream;
71
73
  pub mod testing;
package/srpc/mux.cpp CHANGED
@@ -1,4 +1,4 @@
1
- // go:build deps_only
1
+ //go:build deps_only
2
2
 
3
3
  #include "mux.hpp"
4
4
  #include <mutex>
package/srpc/packet.cpp CHANGED
@@ -1,4 +1,4 @@
1
- // go:build deps_only
1
+ //go:build deps_only
2
2
 
3
3
  #include "packet.hpp"
4
4
 
package/srpc/proto.rs ADDED
@@ -0,0 +1,5 @@
1
+ //! Protocol buffer definitions for starpc.
2
+ //!
3
+ //! This module contains the generated protobuf types from rpcproto.proto.
4
+
5
+ include!("rpcproto.pb.rs");
@@ -1,5 +1,5 @@
1
1
  // Code generated by protoc-gen-go-lite. DO NOT EDIT.
2
- // protoc-gen-go-lite version: v0.12.0
2
+ // protoc-gen-go-lite version: v0.12.1
3
3
  // source: github.com/aperturerobotics/starpc/srpc/rpcproto.proto
4
4
 
5
5
  package srpc
@@ -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)
@@ -1,4 +1,4 @@
1
- // @generated by protoc-gen-es-lite unknown with parameter "ts_nocheck=false,target=ts"
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
 
@@ -1,4 +1,4 @@
1
- // go:build deps_only
1
+ //go:build deps_only
2
2
 
3
3
  #include "server-rpc.hpp"
4
4
 
package/echo/build.rs DELETED
@@ -1,15 +0,0 @@
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
- }
package/srpc/build.rs DELETED
@@ -1,15 +0,0 @@
1
- use std::io::Result;
2
- use std::path::PathBuf;
3
-
4
- fn main() -> Result<()> {
5
- // Get the path to the proto file in the same directory.
6
- let manifest_dir = PathBuf::from(env!("CARGO_MANIFEST_DIR"));
7
- let proto_path = manifest_dir.join("rpcproto.proto");
8
-
9
- println!("cargo:rerun-if-changed={}", proto_path.display());
10
-
11
- prost_build::Config::new()
12
- .compile_protos(&[proto_path], &[&manifest_dir])?;
13
-
14
- Ok(())
15
- }
package/srpc/proto/mod.rs DELETED
@@ -1,10 +0,0 @@
1
- //! Generated protocol buffer types for starpc.
2
- //!
3
- //! This module contains the Packet, CallStart, CallData types generated from
4
- //! rpcproto.proto. These types define the wire protocol for starpc.
5
-
6
- // Include the generated protobuf types.
7
- include!(concat!(env!("OUT_DIR"), "/srpc.rs"));
8
-
9
- // Re-export commonly used items.
10
- pub use self::packet::Body;