2026-05-15 10:29:54 -07:00
|
|
|
// @generated by protoc-gen-roto — do not edit
|
|
|
|
|
#[allow(unused_imports)]
|
2026-05-20 08:09:11 -07:00
|
|
|
use roto_runtime::{ProtoAccessor, ProtoBuilder, Result, RotoError, read_varint, RepeatedFieldIterator, RotoMessage};
|
|
|
|
|
use core::str;
|
|
|
|
|
#[cfg(feature = "alloc")]
|
2026-05-15 10:29:54 -07:00
|
|
|
use bytes::{Bytes, BytesMut, Buf, BufMut};
|
|
|
|
|
|
|
|
|
|
pub struct HelloRequest<'a> {
|
|
|
|
|
accessor: roto_runtime::ProtoAccessor<'a>,
|
|
|
|
|
name_offset: Option<usize>,
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
impl<'a> HelloRequest<'a> {
|
|
|
|
|
pub fn new(data: &'a [u8]) -> roto_runtime::Result<Self> {
|
|
|
|
|
let accessor = roto_runtime::ProtoAccessor::new(data)?;
|
|
|
|
|
let mut name_offset = None;
|
|
|
|
|
for item in accessor.fields() {
|
|
|
|
|
let (offset, tag, _) = item?;
|
|
|
|
|
if tag.field_number == 1 { name_offset = Some(offset); }
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Ok(Self {
|
|
|
|
|
accessor,
|
|
|
|
|
name_offset,
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
pub fn name(&self) -> roto_runtime::Result<&'a str> {
|
|
|
|
|
let offset = self.name_offset.ok_or(roto_runtime::RotoError::FieldNotFound)?;
|
|
|
|
|
let (bytes, _) = self.accessor.get_value_at(offset)?;
|
2026-05-20 08:09:11 -07:00
|
|
|
core::str::from_utf8(bytes).map_err(|_| roto_runtime::RotoError::WireFormatViolation)
|
2026-05-15 10:29:54 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
pub fn name_or_default(&self) -> roto_runtime::Result<&'a str> {
|
|
|
|
|
self.name().or(Ok(""))
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
pub fn has_name(&self) -> bool { self.name_offset.is_some() }
|
|
|
|
|
|
|
|
|
|
pub fn raw_fields(&self) -> roto_runtime::RawFieldIterator<'a> {
|
|
|
|
|
self.accessor.raw_fields()
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
pub struct HelloRequestBuilder<'b> {
|
|
|
|
|
builder: roto_runtime::ProtoBuilder<'b>,
|
|
|
|
|
name_written: bool,
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
impl<'b> HelloRequestBuilder<'b> {
|
|
|
|
|
pub fn builder(buf: &mut [u8]) -> HelloRequestBuilder<'_> {
|
|
|
|
|
HelloRequestBuilder {
|
|
|
|
|
builder: roto_runtime::ProtoBuilder::new(buf),
|
|
|
|
|
name_written: false,
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
pub fn name(mut self, value: &str) -> roto_runtime::Result<Self> {
|
|
|
|
|
self.builder.write_string(1, value)?;
|
|
|
|
|
self.name_written = true;
|
|
|
|
|
Ok(self)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
pub fn with(mut self, msg: &HelloRequest<'_>) -> roto_runtime::Result<Self> {
|
2026-05-20 08:09:11 -07:00
|
|
|
for item in msg.accessor.raw_fields() {
|
2026-05-15 10:29:54 -07:00
|
|
|
let (field_number, raw_bytes) = item?;
|
|
|
|
|
let is_written = match field_number {
|
|
|
|
|
1 => self.name_written,
|
|
|
|
|
_ => false,
|
|
|
|
|
};
|
|
|
|
|
if !is_written {
|
|
|
|
|
self.builder.write_raw(raw_bytes)?;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
Ok(self)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
pub fn finish(self) -> roto_runtime::Result<&'b mut [u8]> {
|
|
|
|
|
self.builder.finish()
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2026-05-20 08:09:11 -07:00
|
|
|
#[cfg(feature = "alloc")]
|
2026-05-15 10:29:54 -07:00
|
|
|
pub struct OwnedHelloRequest {
|
|
|
|
|
pub data: bytes::Bytes,
|
|
|
|
|
}
|
|
|
|
|
|
2026-05-20 08:09:11 -07:00
|
|
|
#[cfg(feature = "alloc")]
|
2026-05-15 10:29:54 -07:00
|
|
|
impl roto_runtime::RotoOwned for OwnedHelloRequest {
|
|
|
|
|
type Reader<'a> = HelloRequest<'a>;
|
|
|
|
|
fn reader(&self) -> HelloRequest<'_> {
|
|
|
|
|
HelloRequest::new(&self.data).expect("failed to create reader")
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2026-05-20 08:09:11 -07:00
|
|
|
#[cfg(feature = "alloc")]
|
2026-05-15 10:29:54 -07:00
|
|
|
impl roto_runtime::RotoMessage for OwnedHelloRequest {
|
|
|
|
|
fn decode(buf: bytes::Bytes) -> roto_runtime::Result<Self> {
|
|
|
|
|
Ok(OwnedHelloRequest { data: buf })
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fn bytes(&self) -> bytes::Bytes {
|
|
|
|
|
self.data.clone()
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
pub struct HelloResponse<'a> {
|
|
|
|
|
accessor: roto_runtime::ProtoAccessor<'a>,
|
|
|
|
|
message_offset: Option<usize>,
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
impl<'a> HelloResponse<'a> {
|
|
|
|
|
pub fn new(data: &'a [u8]) -> roto_runtime::Result<Self> {
|
|
|
|
|
let accessor = roto_runtime::ProtoAccessor::new(data)?;
|
|
|
|
|
let mut message_offset = None;
|
|
|
|
|
for item in accessor.fields() {
|
|
|
|
|
let (offset, tag, _) = item?;
|
|
|
|
|
if tag.field_number == 1 { message_offset = Some(offset); }
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Ok(Self {
|
|
|
|
|
accessor,
|
|
|
|
|
message_offset,
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
pub fn message(&self) -> roto_runtime::Result<&'a str> {
|
|
|
|
|
let offset = self.message_offset.ok_or(roto_runtime::RotoError::FieldNotFound)?;
|
|
|
|
|
let (bytes, _) = self.accessor.get_value_at(offset)?;
|
2026-05-20 08:09:11 -07:00
|
|
|
core::str::from_utf8(bytes).map_err(|_| roto_runtime::RotoError::WireFormatViolation)
|
2026-05-15 10:29:54 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
pub fn message_or_default(&self) -> roto_runtime::Result<&'a str> {
|
|
|
|
|
self.message().or(Ok(""))
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
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 HelloResponseBuilder<'b> {
|
|
|
|
|
builder: roto_runtime::ProtoBuilder<'b>,
|
|
|
|
|
message_written: bool,
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
impl<'b> HelloResponseBuilder<'b> {
|
|
|
|
|
pub fn builder(buf: &mut [u8]) -> HelloResponseBuilder<'_> {
|
|
|
|
|
HelloResponseBuilder {
|
|
|
|
|
builder: roto_runtime::ProtoBuilder::new(buf),
|
|
|
|
|
message_written: false,
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
pub fn message(mut self, value: &str) -> roto_runtime::Result<Self> {
|
|
|
|
|
self.builder.write_string(1, value)?;
|
|
|
|
|
self.message_written = true;
|
|
|
|
|
Ok(self)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
pub fn with(mut self, msg: &HelloResponse<'_>) -> roto_runtime::Result<Self> {
|
2026-05-20 08:09:11 -07:00
|
|
|
for item in msg.accessor.raw_fields() {
|
2026-05-15 10:29:54 -07:00
|
|
|
let (field_number, raw_bytes) = item?;
|
|
|
|
|
let is_written = match field_number {
|
|
|
|
|
1 => self.message_written,
|
|
|
|
|
_ => false,
|
|
|
|
|
};
|
|
|
|
|
if !is_written {
|
|
|
|
|
self.builder.write_raw(raw_bytes)?;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
Ok(self)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
pub fn finish(self) -> roto_runtime::Result<&'b mut [u8]> {
|
|
|
|
|
self.builder.finish()
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2026-05-20 08:09:11 -07:00
|
|
|
#[cfg(feature = "alloc")]
|
2026-05-15 10:29:54 -07:00
|
|
|
pub struct OwnedHelloResponse {
|
|
|
|
|
pub data: bytes::Bytes,
|
|
|
|
|
}
|
|
|
|
|
|
2026-05-20 08:09:11 -07:00
|
|
|
#[cfg(feature = "alloc")]
|
2026-05-15 10:29:54 -07:00
|
|
|
impl roto_runtime::RotoOwned for OwnedHelloResponse {
|
|
|
|
|
type Reader<'a> = HelloResponse<'a>;
|
|
|
|
|
fn reader(&self) -> HelloResponse<'_> {
|
|
|
|
|
HelloResponse::new(&self.data).expect("failed to create reader")
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2026-05-20 08:09:11 -07:00
|
|
|
#[cfg(feature = "alloc")]
|
2026-05-15 10:29:54 -07:00
|
|
|
impl roto_runtime::RotoMessage for OwnedHelloResponse {
|
|
|
|
|
fn decode(buf: bytes::Bytes) -> roto_runtime::Result<Self> {
|
|
|
|
|
Ok(OwnedHelloResponse { data: buf })
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fn bytes(&self) -> bytes::Bytes {
|
|
|
|
|
self.data.clone()
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2026-05-20 08:09:11 -07:00
|
|
|
|
|
|
|
|
|
|
|
|
|
#[cfg(feature = "alloc")]
|
|
|
|
|
use tonic::{Request, Response, Status};
|
|
|
|
|
#[cfg(feature = "alloc")]
|
|
|
|
|
use tokio_stream::Stream;
|
|
|
|
|
#[cfg(feature = "alloc")]
|
|
|
|
|
use std::pin::Pin;
|
|
|
|
|
#[cfg(feature = "alloc")]
|
|
|
|
|
use std::sync::Arc;
|
|
|
|
|
#[cfg(feature = "alloc")]
|
|
|
|
|
use std::task::{Context, Poll};
|
|
|
|
|
#[cfg(feature = "alloc")]
|
|
|
|
|
use std::future::Future;
|
|
|
|
|
#[cfg(feature = "alloc")]
|
|
|
|
|
use tonic::body::BoxBody;
|
|
|
|
|
#[cfg(feature = "alloc")]
|
|
|
|
|
use tower::Service;
|
|
|
|
|
#[cfg(feature = "alloc")]
|
|
|
|
|
use futures_util::StreamExt;
|
|
|
|
|
#[cfg(feature = "alloc")]
|
|
|
|
|
use http_body_util::BodyExt;
|
|
|
|
|
#[cfg(feature = "alloc")]
|
|
|
|
|
use http_body::Body;
|
|
|
|
|
#[cfg(feature = "alloc")]
|
|
|
|
|
use crate::{BufferPool, StatusBody};
|
|
|
|
|
|
|
|
|
|
#[cfg(feature = "alloc")]
|
|
|
|
|
#[async_trait::async_trait]
|
2026-05-15 10:29:54 -07:00
|
|
|
pub trait HelloWorldService: Send + Sync + 'static {
|
|
|
|
|
async fn hello_world(&self, request: Request<OwnedHelloRequest>) -> std::result::Result<Response<OwnedHelloResponse>, Status>;
|
|
|
|
|
}
|
|
|
|
|
|
2026-05-20 08:09:11 -07:00
|
|
|
#[cfg(feature = "alloc")]
|
|
|
|
|
#[derive(Clone)]
|
2026-05-15 10:29:54 -07:00
|
|
|
pub struct HelloWorldServiceServer {
|
|
|
|
|
inner: Arc<dyn HelloWorldService>,
|
|
|
|
|
pool: Arc<BufferPool>,
|
|
|
|
|
}
|
|
|
|
|
|
2026-05-20 08:09:11 -07:00
|
|
|
#[cfg(feature = "alloc")]
|
2026-05-15 10:29:54 -07:00
|
|
|
impl HelloWorldServiceServer {
|
|
|
|
|
pub fn new(inner: Arc<dyn HelloWorldService>, pool: Arc<BufferPool>) -> Self {
|
|
|
|
|
Self { inner, pool }
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2026-05-20 08:09:11 -07:00
|
|
|
#[cfg(feature = "alloc")]
|
2026-05-15 10:29:54 -07:00
|
|
|
impl tonic::server::NamedService for HelloWorldServiceServer {
|
2026-05-20 08:09:11 -07:00
|
|
|
const NAME: &'static str = "hello.HelloWorldService";
|
2026-05-15 10:29:54 -07:00
|
|
|
}
|
|
|
|
|
|
2026-05-20 08:09:11 -07:00
|
|
|
#[cfg(feature = "alloc")]
|
2026-05-15 10:29:54 -07:00
|
|
|
impl Service<http::Request<BoxBody>> for HelloWorldServiceServer {
|
|
|
|
|
type Response = http::Response<BoxBody>;
|
|
|
|
|
type Error = std::convert::Infallible;
|
2026-05-20 08:09:11 -07:00
|
|
|
type Future = Pin<Box<dyn Future<Output = std::result::Result<Self::Response, Self::Error>> + Send>>;
|
2026-05-15 10:29:54 -07:00
|
|
|
|
2026-05-20 08:09:11 -07:00
|
|
|
fn poll_ready(&mut self, _: &mut Context<'_>) -> Poll<std::result::Result<(), Self::Error>> {
|
2026-05-15 10:29:54 -07:00
|
|
|
Poll::Ready(Ok(()))
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fn call(&mut self, req: http::Request<BoxBody>) -> Self::Future {
|
|
|
|
|
let inner = self.inner.clone();
|
|
|
|
|
let pool = self.pool.clone();
|
|
|
|
|
Box::pin(async move {
|
2026-05-20 08:09:11 -07:00
|
|
|
let path = req.uri().path().to_string();
|
2026-05-15 10:29:54 -07:00
|
|
|
let body = req.into_body();
|
|
|
|
|
let mut buf = pool.get();
|
|
|
|
|
let mut stream = body;
|
|
|
|
|
while let Some(frame_result) = stream.frame().await {
|
2026-05-20 08:09:11 -07:00
|
|
|
let frame = frame_result.expect("Body frame error");
|
2026-05-15 10:29:54 -07:00
|
|
|
if let Some(data) = frame.data_ref() {
|
|
|
|
|
buf.put(data.clone());
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
let total_len = buf.len();
|
|
|
|
|
let bytes_vec = buf.split_to(total_len).freeze();
|
|
|
|
|
pool.put(buf);
|
|
|
|
|
if bytes_vec.len() < 5 {
|
2026-05-20 08:09:11 -07:00
|
|
|
let res_body = BoxBody::new(StatusBody::new(Some(Bytes::from_static(&[0, 0, 0, 0, 0])), 0));
|
2026-05-15 10:29:54 -07:00
|
|
|
return Ok(http::Response::builder().status(200).body(res_body).unwrap());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
let payload = bytes_vec.slice(5..);
|
|
|
|
|
let mut routed = false;
|
|
|
|
|
|
2026-05-20 08:09:11 -07:00
|
|
|
if path == "/hello.HelloWorldService/HelloWorld" {
|
2026-05-15 10:29:54 -07:00
|
|
|
let request_msg = match OwnedHelloRequest::decode(payload) {
|
|
|
|
|
Ok(msg) => msg,
|
|
|
|
|
Err(e) => {
|
2026-05-20 08:09:11 -07:00
|
|
|
let res_body = BoxBody::new(StatusBody::new(Some(Bytes::from_static(&[0, 0, 0, 0, 0])), 0));
|
2026-05-15 10:29:54 -07:00
|
|
|
return Ok(http::Response::builder().status(200).body(res_body).unwrap());
|
|
|
|
|
}
|
2026-05-20 08:09:11 -07:00
|
|
|
};
|
2026-05-15 10:29:54 -07:00
|
|
|
|
|
|
|
|
let response = match inner.hello_world(Request::new(request_msg)).await {
|
|
|
|
|
Ok(res) => res,
|
|
|
|
|
Err(e) => {
|
2026-05-20 08:09:11 -07:00
|
|
|
let res_body = BoxBody::new(StatusBody::new(Some(Bytes::from_static(&[0, 0, 0, 0, 0])), 0));
|
2026-05-15 10:29:54 -07:00
|
|
|
return Ok(http::Response::builder().status(200).body(res_body).unwrap());
|
|
|
|
|
}
|
2026-05-20 08:09:11 -07:00
|
|
|
};
|
2026-05-15 10:29:54 -07:00
|
|
|
|
|
|
|
|
let response_msg = response.into_inner();
|
|
|
|
|
let response_bytes = response_msg.bytes();
|
|
|
|
|
let mut res_buf = pool.get();
|
|
|
|
|
res_buf.put_u8(0);
|
|
|
|
|
let len = response_bytes.len() as u32;
|
|
|
|
|
res_buf.put_slice(&len.to_be_bytes());
|
|
|
|
|
res_buf.put_slice(&response_bytes);
|
|
|
|
|
let frame_len = res_buf.len();
|
|
|
|
|
let frame = res_buf.split_to(frame_len).freeze();
|
|
|
|
|
pool.put(res_buf);
|
2026-05-20 08:09:11 -07:00
|
|
|
let res_body = BoxBody::new(StatusBody::new(Some(frame), 0));
|
2026-05-15 10:29:54 -07:00
|
|
|
routed = true;
|
|
|
|
|
return Ok(http::Response::builder().status(200).header("content-type", "application/grpc").body(res_body).unwrap());
|
|
|
|
|
}
|
|
|
|
|
if !routed {
|
2026-05-20 08:09:11 -07:00
|
|
|
let res_body = BoxBody::new(StatusBody::new(Some(Bytes::from_static(&[0, 0, 0, 0, 0])), 0));
|
2026-05-15 10:29:54 -07:00
|
|
|
return Ok(http::Response::builder().status(200).body(res_body).unwrap());
|
|
|
|
|
}
|
2026-05-20 08:09:11 -07:00
|
|
|
Ok(http::Response::builder().status(200).body(BoxBody::new(StatusBody::new(None, 0))).unwrap())
|
2026-05-15 10:29:54 -07:00
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
}
|