bicycle_plugin_echo/
lib.rs

1/*
2Bicycle is a database database framework.
3
4Copyright (C) 2024 Ordinary Labs
5
6This program is free software: you can redistribute it and/or modify
7it under the terms of the GNU Affero General Public License as
8published by the Free Software Foundation, either version 3 of the
9License, or (at your option) any later version.
10
11This program is distributed in the hope that it will be useful,
12but WITHOUT ANY WARRANTY; without even the implied warranty of
13MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14GNU Affero General Public License for more details.
15
16You should have received a copy of the GNU Affero General Public License
17along with this program.  If not, see <http://www.gnu.org/licenses/>.
18*/
19
20use tonic::{Request, Response, Status};
21
22mod proto {
23    tonic::include_proto!("plugin");
24}
25
26pub const FILE_DESCRIPTOR_SET: &[u8] = tonic::include_file_descriptor_set!("plugin_descriptor");
27
28pub use proto::plugin_server::PluginServer as Server;
29use proto::{plugin_server::Plugin, Echo};
30
31pub struct Service {}
32
33#[tonic::async_trait]
34impl Plugin for Service {
35    async fn plugin_echo(&self, req: Request<Echo>) -> Result<Response<Echo>, Status> {
36        Ok(Response::new(req.into_inner()))
37    }
38
39    async fn plugin_echo_loud(&self, req: Request<Echo>) -> Result<Response<Echo>, Status> {
40        use heck::ToShoutySnekCase;
41
42        let resp = Echo {
43            hiya_buddy: req.into_inner().hiya_buddy.TO_SHOUTY_SNEK_CASE(),
44        };
45
46        Ok(Response::new(resp))
47    }
48}