diff --git a/roto-tonic/src/generated/interop.rs b/roto-tonic/src/generated/interop.rs index 04ef6f4..f71f4a5 100644 --- a/roto-tonic/src/generated/interop.rs +++ b/roto-tonic/src/generated/interop.rs @@ -1,8 +1,16 @@ // @generated by protoc-gen-roto — do not edit -#[allow(unused, unused_imports, unused_assignments, unused_variables, non_camel_case_types)] -use roto_runtime::{ProtoAccessor, ProtoBuilder, Result, RotoError, read_varint, RepeatedFieldIterator, RotoMessage}; +#![allow( + unused, + unused_imports, + unused_assignments, + unused_variables, + non_camel_case_types +)] +use bytes::{Buf, BufMut, Bytes, BytesMut}; use core::str; -use bytes::{Bytes, BytesMut, Buf, BufMut}; +use roto_runtime::{ + ProtoAccessor, ProtoBuilder, RepeatedFieldIterator, Result, RotoError, RotoMessage, read_varint, +}; pub struct UnaryRequest<'a> { accessor: roto_runtime::ProtoAccessor<'a>, @@ -15,17 +23,21 @@ impl<'a> UnaryRequest<'a> { let mut message_offset = None; for item in accessor.fields() { let (offset, tag, _) = item?; - if tag.field_number == 1 { message_offset = Some(offset); } + if tag.field_number == 1 { + message_offset = Some(offset); + } } Ok(Self { accessor, -message_offset, + message_offset, }) } pub fn message(&self) -> roto_runtime::Result<&'a str> { - let offset = self.message_offset.ok_or(roto_runtime::RotoError::FieldNotFound)?; + let offset = self + .message_offset + .ok_or(roto_runtime::RotoError::FieldNotFound)?; let (bytes, _) = self.accessor.get_value_at(offset)?; core::str::from_utf8(bytes).map_err(|_| roto_runtime::RotoError::WireFormatViolation) } @@ -34,12 +46,13 @@ message_offset, self.message().or(Ok("")) } - pub fn has_message(&self) -> bool { self.message_offset.is_some() } + pub fn has_message(&self) -> bool { + self.message_offset.is_some() + } pub fn raw_fields(&self) -> roto_runtime::RawFieldIterator<'a> { self.accessor.raw_fields() } - } pub struct UnaryRequestBuilder<'b> { @@ -112,17 +125,21 @@ impl<'a> UnaryResponse<'a> { let mut reply_offset = None; for item in accessor.fields() { let (offset, tag, _) = item?; - if tag.field_number == 1 { reply_offset = Some(offset); } + if tag.field_number == 1 { + reply_offset = Some(offset); + } } Ok(Self { accessor, -reply_offset, + reply_offset, }) } pub fn reply(&self) -> roto_runtime::Result<&'a str> { - let offset = self.reply_offset.ok_or(roto_runtime::RotoError::FieldNotFound)?; + let offset = self + .reply_offset + .ok_or(roto_runtime::RotoError::FieldNotFound)?; let (bytes, _) = self.accessor.get_value_at(offset)?; core::str::from_utf8(bytes).map_err(|_| roto_runtime::RotoError::WireFormatViolation) } @@ -131,12 +148,13 @@ reply_offset, self.reply().or(Ok("")) } - pub fn has_reply(&self) -> bool { self.reply_offset.is_some() } + pub fn has_reply(&self) -> bool { + self.reply_offset.is_some() + } pub fn raw_fields(&self) -> roto_runtime::RawFieldIterator<'a> { self.accessor.raw_fields() } - } pub struct UnaryResponseBuilder<'b> { @@ -209,17 +227,21 @@ impl<'a> StreamingRequest<'a> { let mut query_offset = None; for item in accessor.fields() { let (offset, tag, _) = item?; - if tag.field_number == 1 { query_offset = Some(offset); } + if tag.field_number == 1 { + query_offset = Some(offset); + } } Ok(Self { accessor, -query_offset, + query_offset, }) } pub fn query(&self) -> roto_runtime::Result<&'a str> { - let offset = self.query_offset.ok_or(roto_runtime::RotoError::FieldNotFound)?; + let offset = self + .query_offset + .ok_or(roto_runtime::RotoError::FieldNotFound)?; let (bytes, _) = self.accessor.get_value_at(offset)?; core::str::from_utf8(bytes).map_err(|_| roto_runtime::RotoError::WireFormatViolation) } @@ -228,12 +250,13 @@ query_offset, self.query().or(Ok("")) } - pub fn has_query(&self) -> bool { self.query_offset.is_some() } + pub fn has_query(&self) -> bool { + self.query_offset.is_some() + } pub fn raw_fields(&self) -> roto_runtime::RawFieldIterator<'a> { self.accessor.raw_fields() } - } pub struct StreamingRequestBuilder<'b> { @@ -306,17 +329,21 @@ impl<'a> StreamingResponse<'a> { let mut item_offset = None; for item in accessor.fields() { let (offset, tag, _) = item?; - if tag.field_number == 1 { item_offset = Some(offset); } + if tag.field_number == 1 { + item_offset = Some(offset); + } } Ok(Self { accessor, -item_offset, + item_offset, }) } pub fn item(&self) -> roto_runtime::Result<&'a str> { - let offset = self.item_offset.ok_or(roto_runtime::RotoError::FieldNotFound)?; + let offset = self + .item_offset + .ok_or(roto_runtime::RotoError::FieldNotFound)?; let (bytes, _) = self.accessor.get_value_at(offset)?; core::str::from_utf8(bytes).map_err(|_| roto_runtime::RotoError::WireFormatViolation) } @@ -325,12 +352,13 @@ item_offset, self.item().or(Ok("")) } - pub fn has_item(&self) -> bool { self.item_offset.is_some() } + pub fn has_item(&self) -> bool { + self.item_offset.is_some() + } pub fn raw_fields(&self) -> roto_runtime::RawFieldIterator<'a> { self.accessor.raw_fields() } - } pub struct StreamingResponseBuilder<'b> { @@ -392,26 +420,41 @@ impl roto_runtime::RotoMessage for OwnedStreamingResponse { } } - - -#[allow(unused, unused_imports, unused_assignments, unused_variables, non_camel_case_types)] -use tonic::{Request, Response, Status}; -use tokio_stream::Stream; +use crate::{BufferPool, StatusBody}; +use futures_util::StreamExt; +use http_body::Body; +use http_body_util::BodyExt; +use std::future::Future; use std::pin::Pin; use std::sync::Arc; use std::task::{Context, Poll}; -use std::future::Future; +use tokio_stream::Stream; use tonic::body::BoxBody; +#[allow( + unused, + unused_imports, + unused_assignments, + unused_variables, + non_camel_case_types +)] +use tonic::{Request, Response, Status}; use tower::Service; -use futures_util::StreamExt; -use http_body_util::BodyExt; -use http_body::Body; -use crate::{BufferPool, StatusBody}; #[async_trait::async_trait] pub trait InteropService: Send + Sync + 'static { - async fn unary_call(&self, request: Request) -> std::result::Result, Status>; - async fn streaming_call(&self, request: Request) -> std::result::Result> + Send>>>, Status>; + async fn unary_call( + &self, + request: Request, + ) -> std::result::Result, Status>; + async fn streaming_call( + &self, + request: Request, + ) -> std::result::Result< + Response< + Pin> + Send>>, + >, + Status, + >; } #[derive(Clone)] @@ -433,7 +476,8 @@ impl tonic::server::NamedService for InteropServiceServer { impl Service> for InteropServiceServer { type Response = http::Response; type Error = std::convert::Infallible; - type Future = Pin> + Send>>; + type Future = + Pin> + Send>>; fn poll_ready(&mut self, _: &mut Context<'_>) -> Poll> { Poll::Ready(Ok(())) @@ -458,8 +502,14 @@ impl Service> for InteropServiceServer { let bytes_vec = buf.split_to(total_len).freeze(); pool.put(buf); if bytes_vec.len() < 5 { - 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()); } let payload = bytes_vec.slice(5..); @@ -469,16 +519,28 @@ impl Service> for InteropServiceServer { let request_msg = match OwnedUnaryRequest::decode(payload) { Ok(msg) => msg, Err(_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()); } }; let response = match inner.unary_call(Request::new(request_msg)).await { Ok(res) => res, Err(_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()); } }; @@ -494,17 +556,36 @@ impl Service> for InteropServiceServer { pool.put(res_buf); let res_body = BoxBody::new(StatusBody::new(Some(frame), 0)); routed = true; - return Ok(http::Response::builder().status(200).header("content-type", "application/grpc").body(res_body).unwrap()); + return Ok(http::Response::builder() + .status(200) + .header("content-type", "application/grpc") + .body(res_body) + .unwrap()); } if path == "/interop.InteropService/StreamingCall" { - 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()); } if !routed { - 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()); } - Ok(http::Response::builder().status(200).body(BoxBody::new(StatusBody::new(None, 0))).unwrap()) + Ok(http::Response::builder() + .status(200) + .body(BoxBody::new(StatusBody::new(None, 0))) + .unwrap()) }) } }