use crate::pb::*; use std::pin::Pin; use tonic::{Code, Request, Response, Status}; pub fn create() -> TestServiceServer { TestServiceServer::new(TestService { data: String::new(), }) } #[derive(Default, Clone)] pub struct TestService { data: String, } type Result = std::result::Result, Status>; type Streaming = Request>; type Stream = Pin> + Send + 'static>>; #[tonic::async_trait] impl crate::pb::TestService for TestService { async fn empty_call(&self, _request: Request) -> Result { println!("empty_call"); Ok(Response::new(Empty {})) } async fn unary_call(&self, request: Request) -> Result { println!("unary_call"); let req = request.into_inner(); if let Some(echo_status) = req.response_status { let status = Status::new(Code::from_i32(echo_status.code), echo_status.message); return Err(status); } let res_size = if req.response_size >= 0 { req.response_size as usize } else { let status = Status::new(Code::InvalidArgument, "response_size cannot be negative"); return Err(status); }; let res = SimpleResponse { payload: Some(Payload { body: vec![0; res_size], ..Default::default() }), ..Default::default() }; Ok(Response::new(res)) } async fn cacheable_unary_call(&self, _: Request) -> Result { unimplemented!() } type StreamingOutputCallStream = Stream; async fn streaming_output_call( &self, _: Request, ) -> Result { unimplemented!() } async fn streaming_input_call( &self, _: Streaming, ) -> Result { unimplemented!() } type FullDuplexCallStream = Stream; async fn full_duplex_call( &self, _: Streaming, ) -> Result { unimplemented!() } type HalfDuplexCallStream = Stream; async fn half_duplex_call( &self, _: Streaming, ) -> Result { unimplemented!() } async fn unimplemented_call(&self, _: Request) -> Result { unimplemented!() } }