Format generated interop.rs

This commit is contained in:
2026-06-18 22:38:37 -07:00
parent 3d0eab01cf
commit 3640af6e57
+125 -44
View File
@@ -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,7 +23,9 @@ 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 {
@@ -25,7 +35,9 @@ 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,7 +125,9 @@ 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 {
@@ -122,7 +137,9 @@ 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,7 +227,9 @@ 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 {
@@ -219,7 +239,9 @@ 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,7 +329,9 @@ 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 {
@@ -316,7 +341,9 @@ 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<OwnedUnaryRequest>) -> std::result::Result<Response<OwnedUnaryResponse>, Status>;
async fn streaming_call(&self, request: Request<OwnedStreamingRequest>) -> std::result::Result<Response<Pin<Box<dyn Stream<Item = std::result::Result<OwnedStreamingResponse, Status>> + Send>>>, Status>;
async fn unary_call(
&self,
request: Request<OwnedUnaryRequest>,
) -> std::result::Result<Response<OwnedUnaryResponse>, Status>;
async fn streaming_call(
&self,
request: Request<OwnedStreamingRequest>,
) -> std::result::Result<
Response<
Pin<Box<dyn Stream<Item = std::result::Result<OwnedStreamingResponse, Status>> + Send>>,
>,
Status,
>;
}
#[derive(Clone)]
@@ -433,7 +476,8 @@ impl tonic::server::NamedService for InteropServiceServer {
impl Service<http::Request<BoxBody>> for InteropServiceServer {
type Response = http::Response<BoxBody>;
type Error = std::convert::Infallible;
type Future = Pin<Box<dyn Future<Output = std::result::Result<Self::Response, Self::Error>> + Send>>;
type Future =
Pin<Box<dyn Future<Output = std::result::Result<Self::Response, Self::Error>> + Send>>;
fn poll_ready(&mut self, _: &mut Context<'_>) -> Poll<std::result::Result<(), Self::Error>> {
Poll::Ready(Ok(()))
@@ -458,8 +502,14 @@ impl Service<http::Request<BoxBody>> 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<http::Request<BoxBody>> 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<http::Request<BoxBody>> 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())
})
}
}