chore(examples): Remove dummy echo implementation (#1178)
This commit is contained in:
@@ -14,6 +14,8 @@ fn main() {
|
|||||||
|
|
||||||
tonic_build::compile_protos("proto/echo/echo.proto").unwrap();
|
tonic_build::compile_protos("proto/echo/echo.proto").unwrap();
|
||||||
|
|
||||||
|
tonic_build::compile_protos("proto/unaryecho/echo.proto").unwrap();
|
||||||
|
|
||||||
tonic_build::configure()
|
tonic_build::configure()
|
||||||
.server_mod_attribute("attrs", "#[cfg(feature = \"server\")]")
|
.server_mod_attribute("attrs", "#[cfg(feature = \"server\")]")
|
||||||
.server_attribute("Echo", "#[derive(PartialEq)]")
|
.server_attribute("Echo", "#[derive(PartialEq)]")
|
||||||
|
|||||||
@@ -0,0 +1,37 @@
|
|||||||
|
/*
|
||||||
|
*
|
||||||
|
* Copyright 2018 gRPC authors.
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
syntax = "proto3";
|
||||||
|
|
||||||
|
package grpc.examples.unaryecho;
|
||||||
|
|
||||||
|
// EchoRequest is the request for echo.
|
||||||
|
message EchoRequest {
|
||||||
|
string message = 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
// EchoResponse is the response for echo.
|
||||||
|
message EchoResponse {
|
||||||
|
string message = 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Echo is the echo service.
|
||||||
|
service Echo {
|
||||||
|
// UnaryEcho is unary echo.
|
||||||
|
rpc UnaryEcho(EchoRequest) returns (EchoResponse) {}
|
||||||
|
}
|
||||||
@@ -1,5 +1,5 @@
|
|||||||
pub mod pb {
|
pub mod pb {
|
||||||
tonic::include_proto!("grpc.examples.echo");
|
tonic::include_proto!("grpc.examples.unaryecho");
|
||||||
}
|
}
|
||||||
|
|
||||||
use pb::{echo_client::EchoClient, EchoRequest};
|
use pb::{echo_client::EchoClient, EchoRequest};
|
||||||
|
|||||||
@@ -1,14 +1,11 @@
|
|||||||
pub mod pb {
|
pub mod pb {
|
||||||
tonic::include_proto!("grpc.examples.echo");
|
tonic::include_proto!("grpc.examples.unaryecho");
|
||||||
}
|
}
|
||||||
|
|
||||||
use futures::Stream;
|
|
||||||
use pb::{EchoRequest, EchoResponse};
|
use pb::{EchoRequest, EchoResponse};
|
||||||
use std::pin::Pin;
|
use tonic::{metadata::MetadataValue, transport::Server, Request, Response, Status};
|
||||||
use tonic::{metadata::MetadataValue, transport::Server, Request, Response, Status, Streaming};
|
|
||||||
|
|
||||||
type EchoResult<T> = Result<Response<T>, Status>;
|
type EchoResult<T> = Result<Response<T>, Status>;
|
||||||
type ResponseStream = Pin<Box<dyn Stream<Item = Result<EchoResponse, Status>> + Send>>;
|
|
||||||
|
|
||||||
#[derive(Default)]
|
#[derive(Default)]
|
||||||
pub struct EchoServer;
|
pub struct EchoServer;
|
||||||
@@ -19,31 +16,6 @@ impl pb::echo_server::Echo for EchoServer {
|
|||||||
let message = request.into_inner().message;
|
let message = request.into_inner().message;
|
||||||
Ok(Response::new(EchoResponse { message }))
|
Ok(Response::new(EchoResponse { message }))
|
||||||
}
|
}
|
||||||
|
|
||||||
type ServerStreamingEchoStream = ResponseStream;
|
|
||||||
|
|
||||||
async fn server_streaming_echo(
|
|
||||||
&self,
|
|
||||||
_: Request<EchoRequest>,
|
|
||||||
) -> EchoResult<Self::ServerStreamingEchoStream> {
|
|
||||||
Err(Status::unimplemented("not implemented"))
|
|
||||||
}
|
|
||||||
|
|
||||||
async fn client_streaming_echo(
|
|
||||||
&self,
|
|
||||||
_: Request<Streaming<EchoRequest>>,
|
|
||||||
) -> EchoResult<EchoResponse> {
|
|
||||||
Err(Status::unimplemented("not implemented"))
|
|
||||||
}
|
|
||||||
|
|
||||||
type BidirectionalStreamingEchoStream = ResponseStream;
|
|
||||||
|
|
||||||
async fn bidirectional_streaming_echo(
|
|
||||||
&self,
|
|
||||||
_: Request<Streaming<EchoRequest>>,
|
|
||||||
) -> EchoResult<Self::BidirectionalStreamingEchoStream> {
|
|
||||||
Err(Status::unimplemented("not implemented"))
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[tokio::main]
|
#[tokio::main]
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
pub mod pb {
|
pub mod pb {
|
||||||
tonic::include_proto!("grpc.examples.echo");
|
tonic::include_proto!("grpc.examples.unaryecho");
|
||||||
}
|
}
|
||||||
|
|
||||||
use pb::{echo_client::EchoClient, EchoRequest};
|
use pb::{echo_client::EchoClient, EchoRequest};
|
||||||
|
|||||||
@@ -1,17 +1,14 @@
|
|||||||
pub mod pb {
|
pub mod pb {
|
||||||
tonic::include_proto!("grpc.examples.echo");
|
tonic::include_proto!("grpc.examples.unaryecho");
|
||||||
}
|
}
|
||||||
|
|
||||||
use futures::Stream;
|
|
||||||
use std::net::SocketAddr;
|
use std::net::SocketAddr;
|
||||||
use std::pin::Pin;
|
|
||||||
use tokio::sync::mpsc;
|
use tokio::sync::mpsc;
|
||||||
use tonic::{transport::Server, Request, Response, Status, Streaming};
|
use tonic::{transport::Server, Request, Response, Status};
|
||||||
|
|
||||||
use pb::{EchoRequest, EchoResponse};
|
use pb::{EchoRequest, EchoResponse};
|
||||||
|
|
||||||
type EchoResult<T> = Result<Response<T>, Status>;
|
type EchoResult<T> = Result<Response<T>, Status>;
|
||||||
type ResponseStream = Pin<Box<dyn Stream<Item = Result<EchoResponse, Status>> + Send>>;
|
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub struct EchoServer {
|
pub struct EchoServer {
|
||||||
@@ -25,31 +22,6 @@ impl pb::echo_server::Echo for EchoServer {
|
|||||||
|
|
||||||
Ok(Response::new(EchoResponse { message }))
|
Ok(Response::new(EchoResponse { message }))
|
||||||
}
|
}
|
||||||
|
|
||||||
type ServerStreamingEchoStream = ResponseStream;
|
|
||||||
|
|
||||||
async fn server_streaming_echo(
|
|
||||||
&self,
|
|
||||||
_: Request<EchoRequest>,
|
|
||||||
) -> EchoResult<Self::ServerStreamingEchoStream> {
|
|
||||||
Err(Status::unimplemented("not implemented"))
|
|
||||||
}
|
|
||||||
|
|
||||||
async fn client_streaming_echo(
|
|
||||||
&self,
|
|
||||||
_: Request<Streaming<EchoRequest>>,
|
|
||||||
) -> EchoResult<EchoResponse> {
|
|
||||||
Err(Status::unimplemented("not implemented"))
|
|
||||||
}
|
|
||||||
|
|
||||||
type BidirectionalStreamingEchoStream = ResponseStream;
|
|
||||||
|
|
||||||
async fn bidirectional_streaming_echo(
|
|
||||||
&self,
|
|
||||||
_: Request<Streaming<EchoRequest>>,
|
|
||||||
) -> EchoResult<Self::BidirectionalStreamingEchoStream> {
|
|
||||||
Err(Status::unimplemented("not implemented"))
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[tokio::main]
|
#[tokio::main]
|
||||||
|
|||||||
@@ -8,7 +8,7 @@ pub mod hello_world {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub mod echo {
|
pub mod echo {
|
||||||
tonic::include_proto!("grpc.examples.echo");
|
tonic::include_proto!("grpc.examples.unaryecho");
|
||||||
}
|
}
|
||||||
|
|
||||||
use echo::{echo_client::EchoClient, EchoRequest};
|
use echo::{echo_client::EchoClient, EchoRequest};
|
||||||
|
|||||||
@@ -4,7 +4,6 @@
|
|||||||
//! `curl localhost:50051/hello`
|
//! `curl localhost:50051/hello`
|
||||||
|
|
||||||
use futures::future::{self, Either, TryFutureExt};
|
use futures::future::{self, Either, TryFutureExt};
|
||||||
use futures::Stream;
|
|
||||||
use http::version::Version;
|
use http::version::Version;
|
||||||
use hyper::{service::make_service_fn, Server};
|
use hyper::{service::make_service_fn, Server};
|
||||||
use std::convert::Infallible;
|
use std::convert::Infallible;
|
||||||
@@ -23,7 +22,7 @@ pub mod hello_world {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub mod echo {
|
pub mod echo {
|
||||||
tonic::include_proto!("grpc.examples.echo");
|
tonic::include_proto!("grpc.examples.unaryecho");
|
||||||
}
|
}
|
||||||
use hello_world::{
|
use hello_world::{
|
||||||
greeter_server::{Greeter, GreeterServer},
|
greeter_server::{Greeter, GreeterServer},
|
||||||
@@ -35,8 +34,6 @@ use echo::{
|
|||||||
EchoRequest, EchoResponse,
|
EchoRequest, EchoResponse,
|
||||||
};
|
};
|
||||||
|
|
||||||
type ResponseStream = Pin<Box<dyn Stream<Item = Result<EchoResponse, Status>> + Send>>;
|
|
||||||
|
|
||||||
#[derive(Default)]
|
#[derive(Default)]
|
||||||
pub struct MyGreeter {}
|
pub struct MyGreeter {}
|
||||||
|
|
||||||
@@ -65,31 +62,6 @@ impl Echo for MyEcho {
|
|||||||
let message = request.into_inner().message;
|
let message = request.into_inner().message;
|
||||||
Ok(Response::new(EchoResponse { message }))
|
Ok(Response::new(EchoResponse { message }))
|
||||||
}
|
}
|
||||||
|
|
||||||
type ServerStreamingEchoStream = ResponseStream;
|
|
||||||
|
|
||||||
async fn server_streaming_echo(
|
|
||||||
&self,
|
|
||||||
_: Request<EchoRequest>,
|
|
||||||
) -> Result<Response<Self::ServerStreamingEchoStream>, Status> {
|
|
||||||
Err(Status::unimplemented("Not yet implemented"))
|
|
||||||
}
|
|
||||||
|
|
||||||
async fn client_streaming_echo(
|
|
||||||
&self,
|
|
||||||
_: Request<tonic::Streaming<EchoRequest>>,
|
|
||||||
) -> Result<Response<EchoResponse>, Status> {
|
|
||||||
Err(Status::unimplemented("Not yet implemented"))
|
|
||||||
}
|
|
||||||
|
|
||||||
type BidirectionalStreamingEchoStream = ResponseStream;
|
|
||||||
|
|
||||||
async fn bidirectional_streaming_echo(
|
|
||||||
&self,
|
|
||||||
_: Request<tonic::Streaming<EchoRequest>>,
|
|
||||||
) -> Result<Response<Self::BidirectionalStreamingEchoStream>, Status> {
|
|
||||||
Err(Status::unimplemented("Not yet implemented"))
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[tokio::main]
|
#[tokio::main]
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
pub mod pb {
|
pub mod pb {
|
||||||
tonic::include_proto!("grpc.examples.echo");
|
tonic::include_proto!("grpc.examples.unaryecho");
|
||||||
}
|
}
|
||||||
|
|
||||||
use pb::{echo_client::EchoClient, EchoRequest};
|
use pb::{echo_client::EchoClient, EchoRequest};
|
||||||
|
|||||||
@@ -1,17 +1,14 @@
|
|||||||
pub mod pb {
|
pub mod pb {
|
||||||
tonic::include_proto!("grpc.examples.echo");
|
tonic::include_proto!("grpc.examples.unaryecho");
|
||||||
}
|
}
|
||||||
|
|
||||||
use futures::Stream;
|
|
||||||
use std::net::SocketAddr;
|
use std::net::SocketAddr;
|
||||||
use std::pin::Pin;
|
|
||||||
use tokio::sync::mpsc;
|
use tokio::sync::mpsc;
|
||||||
use tonic::{transport::Server, Request, Response, Status, Streaming};
|
use tonic::{transport::Server, Request, Response, Status};
|
||||||
|
|
||||||
use pb::{EchoRequest, EchoResponse};
|
use pb::{EchoRequest, EchoResponse};
|
||||||
|
|
||||||
type EchoResult<T> = Result<Response<T>, Status>;
|
type EchoResult<T> = Result<Response<T>, Status>;
|
||||||
type ResponseStream = Pin<Box<dyn Stream<Item = Result<EchoResponse, Status>> + Send>>;
|
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub struct EchoServer {
|
pub struct EchoServer {
|
||||||
@@ -25,31 +22,6 @@ impl pb::echo_server::Echo for EchoServer {
|
|||||||
|
|
||||||
Ok(Response::new(EchoResponse { message }))
|
Ok(Response::new(EchoResponse { message }))
|
||||||
}
|
}
|
||||||
|
|
||||||
type ServerStreamingEchoStream = ResponseStream;
|
|
||||||
|
|
||||||
async fn server_streaming_echo(
|
|
||||||
&self,
|
|
||||||
_: Request<EchoRequest>,
|
|
||||||
) -> EchoResult<Self::ServerStreamingEchoStream> {
|
|
||||||
Err(Status::unimplemented("not implemented"))
|
|
||||||
}
|
|
||||||
|
|
||||||
async fn client_streaming_echo(
|
|
||||||
&self,
|
|
||||||
_: Request<Streaming<EchoRequest>>,
|
|
||||||
) -> EchoResult<EchoResponse> {
|
|
||||||
Err(Status::unimplemented("not implemented"))
|
|
||||||
}
|
|
||||||
|
|
||||||
type BidirectionalStreamingEchoStream = ResponseStream;
|
|
||||||
|
|
||||||
async fn bidirectional_streaming_echo(
|
|
||||||
&self,
|
|
||||||
_: Request<Streaming<EchoRequest>>,
|
|
||||||
) -> EchoResult<Self::BidirectionalStreamingEchoStream> {
|
|
||||||
Err(Status::unimplemented("not implemented"))
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[tokio::main]
|
#[tokio::main]
|
||||||
|
|||||||
@@ -3,7 +3,7 @@ pub mod hello_world {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub mod echo {
|
pub mod echo {
|
||||||
tonic::include_proto!("grpc.examples.echo");
|
tonic::include_proto!("grpc.examples.unaryecho");
|
||||||
}
|
}
|
||||||
|
|
||||||
use echo::{echo_client::EchoClient, EchoRequest};
|
use echo::{echo_client::EchoClient, EchoRequest};
|
||||||
|
|||||||
@@ -1,5 +1,3 @@
|
|||||||
use futures::Stream;
|
|
||||||
use std::pin::Pin;
|
|
||||||
use tonic::{transport::Server, Request, Response, Status};
|
use tonic::{transport::Server, Request, Response, Status};
|
||||||
|
|
||||||
pub mod hello_world {
|
pub mod hello_world {
|
||||||
@@ -7,7 +5,7 @@ pub mod hello_world {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub mod echo {
|
pub mod echo {
|
||||||
tonic::include_proto!("grpc.examples.echo");
|
tonic::include_proto!("grpc.examples.unaryecho");
|
||||||
}
|
}
|
||||||
|
|
||||||
use hello_world::{
|
use hello_world::{
|
||||||
@@ -20,8 +18,6 @@ use echo::{
|
|||||||
EchoRequest, EchoResponse,
|
EchoRequest, EchoResponse,
|
||||||
};
|
};
|
||||||
|
|
||||||
type ResponseStream = Pin<Box<dyn Stream<Item = Result<EchoResponse, Status>> + Send>>;
|
|
||||||
|
|
||||||
#[tokio::main]
|
#[tokio::main]
|
||||||
async fn main() -> Result<(), Box<dyn std::error::Error>> {
|
async fn main() -> Result<(), Box<dyn std::error::Error>> {
|
||||||
let addr = "[::1]:50051".parse().unwrap();
|
let addr = "[::1]:50051".parse().unwrap();
|
||||||
@@ -66,29 +62,4 @@ impl Echo for MyEcho {
|
|||||||
let message = request.into_inner().message;
|
let message = request.into_inner().message;
|
||||||
Ok(Response::new(EchoResponse { message }))
|
Ok(Response::new(EchoResponse { message }))
|
||||||
}
|
}
|
||||||
|
|
||||||
type ServerStreamingEchoStream = ResponseStream;
|
|
||||||
|
|
||||||
async fn server_streaming_echo(
|
|
||||||
&self,
|
|
||||||
_: Request<EchoRequest>,
|
|
||||||
) -> Result<Response<Self::ServerStreamingEchoStream>, Status> {
|
|
||||||
Err(Status::unimplemented("Not yet implemented"))
|
|
||||||
}
|
|
||||||
|
|
||||||
async fn client_streaming_echo(
|
|
||||||
&self,
|
|
||||||
_: Request<tonic::Streaming<EchoRequest>>,
|
|
||||||
) -> Result<Response<EchoResponse>, Status> {
|
|
||||||
Err(Status::unimplemented("Not yet implemented"))
|
|
||||||
}
|
|
||||||
|
|
||||||
type BidirectionalStreamingEchoStream = ResponseStream;
|
|
||||||
|
|
||||||
async fn bidirectional_streaming_echo(
|
|
||||||
&self,
|
|
||||||
_: Request<tonic::Streaming<EchoRequest>>,
|
|
||||||
) -> Result<Response<Self::BidirectionalStreamingEchoStream>, Status> {
|
|
||||||
Err(Status::unimplemented("Not yet implemented"))
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
pub mod pb {
|
pub mod pb {
|
||||||
tonic::include_proto!("/grpc.examples.echo");
|
tonic::include_proto!("/grpc.examples.unaryecho");
|
||||||
}
|
}
|
||||||
|
|
||||||
use pb::{echo_client::EchoClient, EchoRequest};
|
use pb::{echo_client::EchoClient, EchoRequest};
|
||||||
|
|||||||
@@ -2,7 +2,7 @@
|
|||||||
//! provide a custom `ClientConfig` for the tls configuration.
|
//! provide a custom `ClientConfig` for the tls configuration.
|
||||||
|
|
||||||
pub mod pb {
|
pub mod pb {
|
||||||
tonic::include_proto!("/grpc.examples.echo");
|
tonic::include_proto!("/grpc.examples.unaryecho");
|
||||||
}
|
}
|
||||||
|
|
||||||
use hyper::{client::HttpConnector, Uri};
|
use hyper::{client::HttpConnector, Uri};
|
||||||
|
|||||||
@@ -1,20 +1,17 @@
|
|||||||
pub mod pb {
|
pub mod pb {
|
||||||
tonic::include_proto!("/grpc.examples.echo");
|
tonic::include_proto!("/grpc.examples.unaryecho");
|
||||||
}
|
}
|
||||||
|
|
||||||
use futures::Stream;
|
|
||||||
use pb::{EchoRequest, EchoResponse};
|
use pb::{EchoRequest, EchoResponse};
|
||||||
use std::pin::Pin;
|
|
||||||
use tonic::{
|
use tonic::{
|
||||||
transport::{
|
transport::{
|
||||||
server::{TcpConnectInfo, TlsConnectInfo},
|
server::{TcpConnectInfo, TlsConnectInfo},
|
||||||
Identity, Server, ServerTlsConfig,
|
Identity, Server, ServerTlsConfig,
|
||||||
},
|
},
|
||||||
Request, Response, Status, Streaming,
|
Request, Response, Status,
|
||||||
};
|
};
|
||||||
|
|
||||||
type EchoResult<T> = Result<Response<T>, Status>;
|
type EchoResult<T> = Result<Response<T>, Status>;
|
||||||
type ResponseStream = Pin<Box<dyn Stream<Item = Result<EchoResponse, Status>> + Send>>;
|
|
||||||
|
|
||||||
#[derive(Default)]
|
#[derive(Default)]
|
||||||
pub struct EchoServer;
|
pub struct EchoServer;
|
||||||
@@ -35,31 +32,6 @@ impl pb::echo_server::Echo for EchoServer {
|
|||||||
let message = request.into_inner().message;
|
let message = request.into_inner().message;
|
||||||
Ok(Response::new(EchoResponse { message }))
|
Ok(Response::new(EchoResponse { message }))
|
||||||
}
|
}
|
||||||
|
|
||||||
type ServerStreamingEchoStream = ResponseStream;
|
|
||||||
|
|
||||||
async fn server_streaming_echo(
|
|
||||||
&self,
|
|
||||||
_: Request<EchoRequest>,
|
|
||||||
) -> EchoResult<Self::ServerStreamingEchoStream> {
|
|
||||||
Err(Status::unimplemented("not implemented"))
|
|
||||||
}
|
|
||||||
|
|
||||||
async fn client_streaming_echo(
|
|
||||||
&self,
|
|
||||||
_: Request<Streaming<EchoRequest>>,
|
|
||||||
) -> EchoResult<EchoResponse> {
|
|
||||||
Err(Status::unimplemented("not implemented"))
|
|
||||||
}
|
|
||||||
|
|
||||||
type BidirectionalStreamingEchoStream = ResponseStream;
|
|
||||||
|
|
||||||
async fn bidirectional_streaming_echo(
|
|
||||||
&self,
|
|
||||||
_: Request<Streaming<EchoRequest>>,
|
|
||||||
) -> EchoResult<Self::BidirectionalStreamingEchoStream> {
|
|
||||||
Err(Status::unimplemented("not implemented"))
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[tokio::main]
|
#[tokio::main]
|
||||||
|
|||||||
@@ -1,17 +1,16 @@
|
|||||||
pub mod pb {
|
pub mod pb {
|
||||||
tonic::include_proto!("/grpc.examples.echo");
|
tonic::include_proto!("/grpc.examples.unaryecho");
|
||||||
}
|
}
|
||||||
|
|
||||||
use futures::Stream;
|
|
||||||
use hyper::server::conn::Http;
|
use hyper::server::conn::Http;
|
||||||
use pb::{EchoRequest, EchoResponse};
|
use pb::{EchoRequest, EchoResponse};
|
||||||
use std::{pin::Pin, sync::Arc};
|
use std::sync::Arc;
|
||||||
use tokio::net::TcpListener;
|
use tokio::net::TcpListener;
|
||||||
use tokio_rustls::{
|
use tokio_rustls::{
|
||||||
rustls::{Certificate, PrivateKey, ServerConfig},
|
rustls::{Certificate, PrivateKey, ServerConfig},
|
||||||
TlsAcceptor,
|
TlsAcceptor,
|
||||||
};
|
};
|
||||||
use tonic::{transport::Server, Request, Response, Status, Streaming};
|
use tonic::{transport::Server, Request, Response, Status};
|
||||||
use tower_http::ServiceBuilderExt;
|
use tower_http::ServiceBuilderExt;
|
||||||
|
|
||||||
#[tokio::main]
|
#[tokio::main]
|
||||||
@@ -98,7 +97,6 @@ struct ConnInfo {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type EchoResult<T> = Result<Response<T>, Status>;
|
type EchoResult<T> = Result<Response<T>, Status>;
|
||||||
type ResponseStream = Pin<Box<dyn Stream<Item = Result<EchoResponse, Status>> + Send>>;
|
|
||||||
|
|
||||||
#[derive(Default)]
|
#[derive(Default)]
|
||||||
pub struct EchoServer;
|
pub struct EchoServer;
|
||||||
@@ -115,29 +113,4 @@ impl pb::echo_server::Echo for EchoServer {
|
|||||||
let message = request.into_inner().message;
|
let message = request.into_inner().message;
|
||||||
Ok(Response::new(EchoResponse { message }))
|
Ok(Response::new(EchoResponse { message }))
|
||||||
}
|
}
|
||||||
|
|
||||||
type ServerStreamingEchoStream = ResponseStream;
|
|
||||||
|
|
||||||
async fn server_streaming_echo(
|
|
||||||
&self,
|
|
||||||
_: Request<EchoRequest>,
|
|
||||||
) -> EchoResult<Self::ServerStreamingEchoStream> {
|
|
||||||
Err(Status::unimplemented("not implemented"))
|
|
||||||
}
|
|
||||||
|
|
||||||
async fn client_streaming_echo(
|
|
||||||
&self,
|
|
||||||
_: Request<Streaming<EchoRequest>>,
|
|
||||||
) -> EchoResult<EchoResponse> {
|
|
||||||
Err(Status::unimplemented("not implemented"))
|
|
||||||
}
|
|
||||||
|
|
||||||
type BidirectionalStreamingEchoStream = ResponseStream;
|
|
||||||
|
|
||||||
async fn bidirectional_streaming_echo(
|
|
||||||
&self,
|
|
||||||
_: Request<Streaming<EchoRequest>>,
|
|
||||||
) -> EchoResult<Self::BidirectionalStreamingEchoStream> {
|
|
||||||
Err(Status::unimplemented("not implemented"))
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
pub mod pb {
|
pub mod pb {
|
||||||
tonic::include_proto!("grpc.examples.echo");
|
tonic::include_proto!("grpc.examples.unaryecho");
|
||||||
}
|
}
|
||||||
|
|
||||||
use pb::{echo_client::EchoClient, EchoRequest};
|
use pb::{echo_client::EchoClient, EchoRequest};
|
||||||
|
|||||||
@@ -1,15 +1,12 @@
|
|||||||
pub mod pb {
|
pub mod pb {
|
||||||
tonic::include_proto!("grpc.examples.echo");
|
tonic::include_proto!("grpc.examples.unaryecho");
|
||||||
}
|
}
|
||||||
|
|
||||||
use futures::Stream;
|
|
||||||
use pb::{EchoRequest, EchoResponse};
|
use pb::{EchoRequest, EchoResponse};
|
||||||
use std::pin::Pin;
|
|
||||||
use tonic::transport::{Certificate, Identity, Server, ServerTlsConfig};
|
use tonic::transport::{Certificate, Identity, Server, ServerTlsConfig};
|
||||||
use tonic::{Request, Response, Status};
|
use tonic::{Request, Response, Status};
|
||||||
|
|
||||||
type EchoResult<T> = Result<Response<T>, Status>;
|
type EchoResult<T> = Result<Response<T>, Status>;
|
||||||
type ResponseStream = Pin<Box<dyn Stream<Item = Result<EchoResponse, Status>> + Send>>;
|
|
||||||
|
|
||||||
#[derive(Default)]
|
#[derive(Default)]
|
||||||
pub struct EchoServer;
|
pub struct EchoServer;
|
||||||
@@ -26,31 +23,6 @@ impl pb::echo_server::Echo for EchoServer {
|
|||||||
let message = request.into_inner().message;
|
let message = request.into_inner().message;
|
||||||
Ok(Response::new(EchoResponse { message }))
|
Ok(Response::new(EchoResponse { message }))
|
||||||
}
|
}
|
||||||
|
|
||||||
type ServerStreamingEchoStream = ResponseStream;
|
|
||||||
|
|
||||||
async fn server_streaming_echo(
|
|
||||||
&self,
|
|
||||||
_: Request<EchoRequest>,
|
|
||||||
) -> Result<Response<Self::ServerStreamingEchoStream>, Status> {
|
|
||||||
Err(Status::unimplemented("Not yet implemented"))
|
|
||||||
}
|
|
||||||
|
|
||||||
async fn client_streaming_echo(
|
|
||||||
&self,
|
|
||||||
_: Request<tonic::Streaming<EchoRequest>>,
|
|
||||||
) -> Result<Response<EchoResponse>, Status> {
|
|
||||||
Err(Status::unimplemented("Not yet implemented"))
|
|
||||||
}
|
|
||||||
|
|
||||||
type BidirectionalStreamingEchoStream = ResponseStream;
|
|
||||||
|
|
||||||
async fn bidirectional_streaming_echo(
|
|
||||||
&self,
|
|
||||||
_: Request<tonic::Streaming<EchoRequest>>,
|
|
||||||
) -> Result<Response<Self::BidirectionalStreamingEchoStream>, Status> {
|
|
||||||
Err(Status::unimplemented("Not yet implemented"))
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[tokio::main]
|
#[tokio::main]
|
||||||
|
|||||||
Reference in New Issue
Block a user