Update codegen to suppress more compiler warnings
This commit is contained in:
@@ -1,12 +1,19 @@
|
||||
use tonic::Request;
|
||||
use roto_tonic::RotoCodec;
|
||||
use hello::{HelloWorldService, OwnedHelloRequest, OwnedHelloResponse};
|
||||
use hello::{OwnedHelloRequest, OwnedHelloResponse};
|
||||
use roto_runtime::RotoOwned;
|
||||
use roto_tonic::RotoCodec;
|
||||
use std::task::{Context, Poll};
|
||||
use tonic::Request;
|
||||
use tower::Service;
|
||||
|
||||
pub use roto_tonic::{BufferPool, StatusBody};
|
||||
|
||||
#[allow(
|
||||
unused,
|
||||
unused_imports,
|
||||
unused_assignments,
|
||||
unused_variables,
|
||||
non_camel_case_types
|
||||
)]
|
||||
pub mod hello {
|
||||
include!(concat!(env!("OUT_DIR"), "/hello.rs"));
|
||||
}
|
||||
@@ -45,8 +52,10 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
|
||||
// We need to specify the method path. For HelloWorldService/HelloWorld, it is "/hello.HelloWorldService/HelloWorld"
|
||||
let mut buf = vec![0u8; 1024];
|
||||
let slice = hello::HelloRequestBuilder::builder(&mut buf)
|
||||
.name("Roto").unwrap()
|
||||
.finish().unwrap();
|
||||
.name("Roto")
|
||||
.unwrap()
|
||||
.finish()
|
||||
.unwrap();
|
||||
|
||||
let request = OwnedHelloRequest {
|
||||
data: bytes::Bytes::copy_from_slice(slice),
|
||||
@@ -63,7 +72,10 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
|
||||
|
||||
let response_msg: OwnedHelloResponse = response.into_inner();
|
||||
let reader = response_msg.reader();
|
||||
println!("Server responded: {}", reader.message().unwrap_or("No message"));
|
||||
println!(
|
||||
"Server responded: {}",
|
||||
reader.message().unwrap_or("No message")
|
||||
);
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
@@ -1,20 +1,24 @@
|
||||
use std::pin::Pin;
|
||||
use std::future::Future;
|
||||
use std::task::{Context, Poll};
|
||||
use std::sync::{Arc, Mutex};
|
||||
use tonic::{transport::Server, Request, Response, Status};
|
||||
use roto_tonic::RotoCodec;
|
||||
use bytes::{BufMut, Bytes};
|
||||
use hello::{HelloWorldService, OwnedHelloRequest, OwnedHelloResponse};
|
||||
use tower::Service;
|
||||
use bytes::{Bytes, BytesMut, Buf, BufMut};
|
||||
use tonic::body::BoxBody;
|
||||
use futures_util::StreamExt;
|
||||
use roto_runtime::{RotoOwned, RotoMessage};
|
||||
use http_body_util::BodyExt;
|
||||
use http_body::Body;
|
||||
use roto_runtime::{RotoMessage, RotoOwned};
|
||||
use std::future::Future;
|
||||
use std::pin::Pin;
|
||||
use std::sync::Arc;
|
||||
use std::task::{Context, Poll};
|
||||
use tonic::body::BoxBody;
|
||||
use tonic::{Request, Response, Status, transport::Server};
|
||||
use tower::Service;
|
||||
|
||||
pub use roto_tonic::{BufferPool, StatusBody};
|
||||
|
||||
#[allow(
|
||||
unused,
|
||||
unused_imports,
|
||||
unused_assignments,
|
||||
unused_variables,
|
||||
non_camel_case_types
|
||||
)]
|
||||
pub mod hello {
|
||||
include!(concat!(env!("OUT_DIR"), "/hello.rs"));
|
||||
}
|
||||
@@ -43,8 +47,10 @@ impl HelloWorldService for MyHelloWorld {
|
||||
let mut buf = self.pool.get();
|
||||
buf.resize(1024, 0);
|
||||
let slice = hello::HelloResponseBuilder::builder(&mut buf[..])
|
||||
.message(&format!("Hello {}!", name)).unwrap()
|
||||
.finish().unwrap();
|
||||
.message(&format!("Hello {}!", name))
|
||||
.unwrap()
|
||||
.finish()
|
||||
.unwrap();
|
||||
|
||||
let res_len = slice.len();
|
||||
let response_bytes = buf.split_to(res_len).freeze();
|
||||
@@ -68,7 +74,10 @@ pub struct HelloWorldServer {
|
||||
|
||||
impl HelloWorldServer {
|
||||
pub fn new(inner: MyHelloWorld, pool: Arc<BufferPool>) -> Self {
|
||||
Self { inner: Arc::new(inner), pool }
|
||||
Self {
|
||||
inner: Arc::new(inner),
|
||||
pool,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -111,7 +120,10 @@ impl Service<http::Request<BoxBody>> for HelloWorldServer {
|
||||
|
||||
if bytes_vec.len() < 5 {
|
||||
println!("Body too short: {} bytes", bytes_vec.len());
|
||||
let res_body = BoxBody::new(StatusBody::new(Some(Bytes::from_static(&[0, 0, 0, 0, 0])), 0));
|
||||
let res_body = BoxBody::new(StatusBody::new(
|
||||
Some(Bytes::from_static(&[0, 0, 0, 0, 0])),
|
||||
0,
|
||||
));
|
||||
return Ok(http::Response::builder()
|
||||
.status(200)
|
||||
.body(res_body)
|
||||
@@ -123,8 +135,14 @@ impl Service<http::Request<BoxBody>> for HelloWorldServer {
|
||||
Ok(msg) => msg,
|
||||
Err(e) => {
|
||||
println!("Decode error: {}", e);
|
||||
let res_body = BoxBody::new(StatusBody::new(Some(Bytes::from_static(&[0, 0, 0, 0, 0])), 0));
|
||||
return Ok(http::Response::builder().status(200).body(res_body).unwrap());
|
||||
let res_body = BoxBody::new(StatusBody::new(
|
||||
Some(Bytes::from_static(&[0, 0, 0, 0, 0])),
|
||||
0,
|
||||
));
|
||||
return Ok(http::Response::builder()
|
||||
.status(200)
|
||||
.body(res_body)
|
||||
.unwrap());
|
||||
}
|
||||
};
|
||||
|
||||
@@ -133,8 +151,14 @@ impl Service<http::Request<BoxBody>> for HelloWorldServer {
|
||||
Ok(res) => res,
|
||||
Err(e) => {
|
||||
println!("Service error: {}", e);
|
||||
let res_body = BoxBody::new(StatusBody::new(Some(Bytes::from_static(&[0, 0, 0, 0, 0])), 0));
|
||||
return Ok(http::Response::builder().status(200).body(res_body).unwrap());
|
||||
let res_body = BoxBody::new(StatusBody::new(
|
||||
Some(Bytes::from_static(&[0, 0, 0, 0, 0])),
|
||||
0,
|
||||
));
|
||||
return Ok(http::Response::builder()
|
||||
.status(200)
|
||||
.body(res_body)
|
||||
.unwrap());
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user