-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathapi_srpc.pb.rs
More file actions
150 lines (132 loc) · 5.24 KB
/
Copy pathapi_srpc.pb.rs
File metadata and controls
150 lines (132 loc) · 5.24 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
// Code generated by protoc-gen-starpc-rust. DO NOT EDIT.
// protoc-gen-starpc-rust version: v0.49.16
// source: github.com/aperturerobotics/controllerbus/bus/api/api.proto
#[allow(unused_imports)]
use starpc::StreamExt;
/// Service ID for ControllerBusService.
pub const CONTROLLER_BUS_SERVICE_SERVICE_ID: &str = "bus.api.ControllerBusService";
/// Stream trait for ControllerBusService.ExecController.
#[starpc::async_trait]
pub trait ControllerBusServiceExecControllerStream: Send + Sync {
/// Returns the context for this stream.
fn context(&self) -> &starpc::Context;
/// Receives a message from the stream.
async fn recv(&self) -> starpc::Result<ExecControllerResponse>;
/// Closes the stream.
async fn close(&self) -> starpc::Result<()>;
}
/// Client trait for ControllerBusService.
#[starpc::async_trait]
pub trait ControllerBusServiceClient: Send + Sync {
/// GetBusInfo.
async fn get_bus_info(&self, request: &GetBusInfoRequest) -> starpc::Result<GetBusInfoResponse>;
/// ExecController.
async fn exec_controller(&self, request: &ExecControllerRequest) -> starpc::Result<Box<dyn ControllerBusServiceExecControllerStream>>;
}
/// Client implementation for ControllerBusService.
pub struct ControllerBusServiceClientImpl<C> {
client: C,
}
impl<C: starpc::Client> ControllerBusServiceClientImpl<C> {
/// Creates a new client.
pub fn new(client: C) -> Self {
Self { client }
}
}
#[starpc::async_trait]
impl<C: starpc::Client + 'static> ControllerBusServiceClient for ControllerBusServiceClientImpl<C> {
async fn get_bus_info(&self, request: &GetBusInfoRequest) -> starpc::Result<GetBusInfoResponse> {
self.client.exec_call("bus.api.ControllerBusService", "GetBusInfo", request).await
}
async fn exec_controller(&self, request: &ExecControllerRequest) -> starpc::Result<Box<dyn ControllerBusServiceExecControllerStream>> {
use starpc::ProstMessage;
let data = request.encode_to_vec();
let stream = self.client.new_stream("bus.api.ControllerBusService", "ExecController", Some(&data)).await?;
stream.close_send().await?;
Ok(Box::new(ControllerBusServiceExecControllerStreamImpl { stream }))
}
}
struct ControllerBusServiceExecControllerStreamImpl {
stream: Box<dyn starpc::Stream>,
}
#[starpc::async_trait]
impl ControllerBusServiceExecControllerStream for ControllerBusServiceExecControllerStreamImpl {
fn context(&self) -> &starpc::Context {
self.stream.context()
}
async fn recv(&self) -> starpc::Result<ExecControllerResponse> {
self.stream.msg_recv().await
}
async fn close(&self) -> starpc::Result<()> {
self.stream.close().await
}
}
/// Server trait for ControllerBusService.
#[starpc::async_trait]
pub trait ControllerBusServiceServer: Send + Sync {
/// GetBusInfo.
async fn get_bus_info(&self, request: GetBusInfoRequest) -> starpc::Result<GetBusInfoResponse>;
/// ExecController.
async fn exec_controller(&self, request: ExecControllerRequest, stream: Box<dyn starpc::Stream>) -> starpc::Result<()>;
}
const CONTROLLER_BUS_SERVICE_METHOD_IDS: &[&str] = &[
"GetBusInfo",
"ExecController",
];
/// Handler for ControllerBusService.
pub struct ControllerBusServiceHandler<S: ControllerBusServiceServer> {
server: std::sync::Arc<S>,
}
impl<S: ControllerBusServiceServer + 'static> ControllerBusServiceHandler<S> {
/// Creates a new handler wrapping the server implementation.
pub fn new(server: S) -> Self {
Self { server: std::sync::Arc::new(server) }
}
/// Creates a new handler with a shared server.
pub fn with_arc(server: std::sync::Arc<S>) -> Self {
Self { server }
}
}
#[starpc::async_trait]
impl<S: ControllerBusServiceServer + 'static> starpc::Invoker for ControllerBusServiceHandler<S> {
async fn invoke_method(
&self,
_service_id: &str,
method_id: &str,
stream: Box<dyn starpc::Stream>,
) -> (bool, starpc::Result<()>) {
match method_id {
"GetBusInfo" => {
let request: GetBusInfoRequest = match stream.msg_recv().await {
Ok(r) => r,
Err(e) => return (true, Err(e)),
};
match self.server.get_bus_info(request).await {
Ok(response) => {
if let Err(e) = stream.msg_send(&response).await {
return (true, Err(e));
}
(true, Ok(()))
}
Err(e) => (true, Err(e)),
}
}
"ExecController" => {
let request: ExecControllerRequest = match stream.msg_recv().await {
Ok(r) => r,
Err(e) => return (true, Err(e)),
};
(true, self.server.exec_controller(request, stream).await)
}
_ => (false, Err(starpc::Error::Unimplemented)),
}
}
}
impl<S: ControllerBusServiceServer + 'static> starpc::Handler for ControllerBusServiceHandler<S> {
fn service_id(&self) -> &'static str {
"bus.api.ControllerBusService"
}
fn method_ids(&self) -> &'static [&'static str] {
CONTROLLER_BUS_SERVICE_METHOD_IDS
}
}