Format generated interop.rs

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