Clean up interop server and fmt
This commit is contained in:
@@ -1,85 +1,6 @@
|
||||
use structopt::StructOpt;
|
||||
use tonic::{Code, Request, Response, Status, Server};
|
||||
use std::pin::Pin;
|
||||
use tonic_interop::pb::*;
|
||||
|
||||
#[derive(Default, Clone)]
|
||||
pub struct TestService {
|
||||
data: String,
|
||||
}
|
||||
|
||||
type Result<T> = std::result::Result<Response<T>, Status>;
|
||||
type Streaming<T> = Request<tonic::Streaming<T>>;
|
||||
type Stream<T> = Pin<Box<dyn futures_core::Stream<Item = std::result::Result<T, Status>> + Send + 'static>>;
|
||||
|
||||
#[tonic::async_trait]
|
||||
impl tonic_interop::pb::TestService for TestService {
|
||||
async fn empty_call(&self, _request: Request<Empty>) -> Result<Empty> {
|
||||
println!("empty_call");
|
||||
Ok(Response::new(Empty {}))
|
||||
}
|
||||
|
||||
async fn unary_call(
|
||||
&self,
|
||||
request: Request<SimpleRequest>,
|
||||
) -> Result<SimpleResponse> {
|
||||
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<SimpleRequest>) -> Result<SimpleResponse> {
|
||||
unimplemented!()
|
||||
}
|
||||
|
||||
type StreamingOutputCallStream = Stream<StreamingOutputCallResponse>;
|
||||
|
||||
async fn streaming_output_call(&self, _: Request<StreamingOutputCallRequest>) -> Result<Self::StreamingOutputCallStream> {
|
||||
unimplemented!()
|
||||
}
|
||||
|
||||
async fn streaming_input_call(&self, _: Streaming<StreamingInputCallRequest>) -> Result<StreamingInputCallResponse> {
|
||||
unimplemented!()
|
||||
}
|
||||
|
||||
type FullDuplexCallStream = Stream<StreamingOutputCallResponse>;
|
||||
|
||||
async fn full_duplex_call(&self, _: Streaming<StreamingOutputCallRequest>) -> Result<Self::FullDuplexCallStream> {
|
||||
unimplemented!()
|
||||
}
|
||||
|
||||
type HalfDuplexCallStream = Stream<StreamingOutputCallResponse>;
|
||||
|
||||
async fn half_duplex_call(&self, _: Streaming<StreamingOutputCallRequest>) -> Result<Self::HalfDuplexCallStream> {
|
||||
unimplemented!()
|
||||
}
|
||||
|
||||
async fn unimplemented_call(&self, _: Request<Empty>) -> Result<Empty> {
|
||||
unimplemented!()
|
||||
}
|
||||
}
|
||||
use tonic::Server;
|
||||
use tonic_interop::server;
|
||||
|
||||
#[derive(StructOpt)]
|
||||
struct Opts {
|
||||
@@ -94,7 +15,7 @@ async fn main() -> std::result::Result<(), Box<dyn std::error::Error>> {
|
||||
pretty_env_logger::init();
|
||||
let addr = "127.0.0.1:10000".parse().unwrap();
|
||||
|
||||
let greeter = TestService::default();
|
||||
let test_service = server::create();
|
||||
|
||||
let mut builder = Server::builder();
|
||||
|
||||
@@ -104,7 +25,7 @@ async fn main() -> std::result::Result<(), Box<dyn std::error::Error>> {
|
||||
builder.tls(ca, key);
|
||||
}
|
||||
|
||||
builder.serve(addr, TestServiceServer::new(greeter)).await?;
|
||||
builder.serve(addr, test_service).await?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
pub mod client;
|
||||
pub mod server;
|
||||
|
||||
pub mod pb {
|
||||
#![allow(dead_code)]
|
||||
|
||||
@@ -0,0 +1,97 @@
|
||||
use crate::pb::*;
|
||||
use std::pin::Pin;
|
||||
use tonic::{Code, Request, Response, Status};
|
||||
|
||||
pub fn create() -> TestServiceServer<TestService> {
|
||||
TestServiceServer::new(TestService {
|
||||
data: String::new(),
|
||||
})
|
||||
}
|
||||
|
||||
#[derive(Default, Clone)]
|
||||
pub struct TestService {
|
||||
data: String,
|
||||
}
|
||||
|
||||
type Result<T> = std::result::Result<Response<T>, Status>;
|
||||
type Streaming<T> = Request<tonic::Streaming<T>>;
|
||||
type Stream<T> =
|
||||
Pin<Box<dyn futures_core::Stream<Item = std::result::Result<T, Status>> + Send + 'static>>;
|
||||
|
||||
#[tonic::async_trait]
|
||||
impl crate::pb::TestService for TestService {
|
||||
async fn empty_call(&self, _request: Request<Empty>) -> Result<Empty> {
|
||||
println!("empty_call");
|
||||
Ok(Response::new(Empty {}))
|
||||
}
|
||||
|
||||
async fn unary_call(&self, request: Request<SimpleRequest>) -> Result<SimpleResponse> {
|
||||
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<SimpleRequest>) -> Result<SimpleResponse> {
|
||||
unimplemented!()
|
||||
}
|
||||
|
||||
type StreamingOutputCallStream = Stream<StreamingOutputCallResponse>;
|
||||
|
||||
async fn streaming_output_call(
|
||||
&self,
|
||||
_: Request<StreamingOutputCallRequest>,
|
||||
) -> Result<Self::StreamingOutputCallStream> {
|
||||
unimplemented!()
|
||||
}
|
||||
|
||||
async fn streaming_input_call(
|
||||
&self,
|
||||
_: Streaming<StreamingInputCallRequest>,
|
||||
) -> Result<StreamingInputCallResponse> {
|
||||
unimplemented!()
|
||||
}
|
||||
|
||||
type FullDuplexCallStream = Stream<StreamingOutputCallResponse>;
|
||||
|
||||
async fn full_duplex_call(
|
||||
&self,
|
||||
_: Streaming<StreamingOutputCallRequest>,
|
||||
) -> Result<Self::FullDuplexCallStream> {
|
||||
unimplemented!()
|
||||
}
|
||||
|
||||
type HalfDuplexCallStream = Stream<StreamingOutputCallResponse>;
|
||||
|
||||
async fn half_duplex_call(
|
||||
&self,
|
||||
_: Streaming<StreamingOutputCallRequest>,
|
||||
) -> Result<Self::HalfDuplexCallStream> {
|
||||
unimplemented!()
|
||||
}
|
||||
|
||||
async fn unimplemented_call(&self, _: Request<Empty>) -> Result<Empty> {
|
||||
unimplemented!()
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user