Update codegen to suppress more compiler warnings
This commit is contained in:
@@ -1,22 +1,29 @@
|
||||
// @generated by protoc-gen-roto — do not edit
|
||||
#[allow(unused)]
|
||||
#![allow(
|
||||
unused,
|
||||
unused_imports,
|
||||
unused_assignments,
|
||||
unused_variables,
|
||||
non_camel_case_types
|
||||
)]
|
||||
|
||||
use roto_runtime::{ProtoAccessor, ProtoBuilder, Result, RotoError, read_varint, RepeatedFieldIterator, RotoMessage};
|
||||
use std::str;
|
||||
use bytes::{Bytes, BytesMut, Buf, BufMut};
|
||||
use tonic::{Request, Response, Status};
|
||||
use tokio_stream::Stream;
|
||||
use crate::{BufferPool, StatusBody};
|
||||
use bytes::{Buf, BufMut, Bytes, BytesMut};
|
||||
use futures_util::StreamExt;
|
||||
use http_body::Body;
|
||||
use http_body_util::BodyExt;
|
||||
use roto_runtime::{
|
||||
ProtoAccessor, ProtoBuilder, RepeatedFieldIterator, Result, RotoError, RotoMessage, read_varint,
|
||||
};
|
||||
use std::future::Future;
|
||||
use std::pin::Pin;
|
||||
use std::str;
|
||||
use std::sync::Arc;
|
||||
use std::task::{Context, Poll};
|
||||
use std::future::Future;
|
||||
use tokio_stream::Stream;
|
||||
use tonic::body::BoxBody;
|
||||
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};
|
||||
|
||||
|
||||
pub struct Hello<'a> {
|
||||
accessor: roto_runtime::ProtoAccessor<'a>,
|
||||
@@ -47,36 +54,57 @@ impl<'a> Hello<'a> {
|
||||
let mut pets_end = None;
|
||||
for item in accessor.fields() {
|
||||
let (offset, tag, _) = item?;
|
||||
if tag.field_number == 1 { name_offset = Some(offset); }
|
||||
if tag.field_number == 2 { d_offset = Some(offset); }
|
||||
if tag.field_number == 3 { f_offset = Some(offset); }
|
||||
if tag.field_number == 4 { b_offset = Some(offset); }
|
||||
if tag.field_number == 5 { n_offset = Some(offset); }
|
||||
if tag.field_number == 6 { l_offset = Some(offset); }
|
||||
if tag.field_number == 7 { c1_offset = Some(offset); }
|
||||
if tag.field_number == 8 { c2_offset = Some(offset); }
|
||||
if tag.field_number == 1 {
|
||||
name_offset = Some(offset);
|
||||
}
|
||||
if tag.field_number == 2 {
|
||||
d_offset = Some(offset);
|
||||
}
|
||||
if tag.field_number == 3 {
|
||||
f_offset = Some(offset);
|
||||
}
|
||||
if tag.field_number == 4 {
|
||||
b_offset = Some(offset);
|
||||
}
|
||||
if tag.field_number == 5 {
|
||||
n_offset = Some(offset);
|
||||
}
|
||||
if tag.field_number == 6 {
|
||||
l_offset = Some(offset);
|
||||
}
|
||||
if tag.field_number == 7 {
|
||||
c1_offset = Some(offset);
|
||||
}
|
||||
if tag.field_number == 8 {
|
||||
c2_offset = Some(offset);
|
||||
}
|
||||
if tag.field_number == 9 {
|
||||
if pets_start.is_none() { pets_start = Some(offset); }
|
||||
if pets_start.is_none() {
|
||||
pets_start = Some(offset);
|
||||
}
|
||||
pets_end = Some(offset);
|
||||
}
|
||||
}
|
||||
|
||||
Ok(Self {
|
||||
accessor,
|
||||
name_offset,
|
||||
d_offset,
|
||||
f_offset,
|
||||
b_offset,
|
||||
n_offset,
|
||||
l_offset,
|
||||
c1_offset,
|
||||
c2_offset,
|
||||
pets_start, pets_end,
|
||||
name_offset,
|
||||
d_offset,
|
||||
f_offset,
|
||||
b_offset,
|
||||
n_offset,
|
||||
l_offset,
|
||||
c1_offset,
|
||||
c2_offset,
|
||||
pets_start,
|
||||
pets_end,
|
||||
})
|
||||
}
|
||||
|
||||
pub fn name(&self) -> roto_runtime::Result<&'a str> {
|
||||
let offset = self.name_offset.ok_or(roto_runtime::RotoError::FieldNotFound)?;
|
||||
let offset = self
|
||||
.name_offset
|
||||
.ok_or(roto_runtime::RotoError::FieldNotFound)?;
|
||||
let (bytes, _) = self.accessor.get_value_at(offset)?;
|
||||
std::str::from_utf8(bytes).map_err(|_| roto_runtime::RotoError::WireFormatViolation)
|
||||
}
|
||||
@@ -85,70 +113,104 @@ pets_start, pets_end,
|
||||
self.name().or(Ok(""))
|
||||
}
|
||||
|
||||
pub fn has_name(&self) -> bool { self.name_offset.is_some() }
|
||||
pub fn has_name(&self) -> bool {
|
||||
self.name_offset.is_some()
|
||||
}
|
||||
|
||||
pub fn d(&self) -> roto_runtime::Result<f64> {
|
||||
let offset = self.d_offset.ok_or(roto_runtime::RotoError::FieldNotFound)?;
|
||||
let offset = self
|
||||
.d_offset
|
||||
.ok_or(roto_runtime::RotoError::FieldNotFound)?;
|
||||
let (bytes, _) = self.accessor.get_value_at(offset)?;
|
||||
Ok(f64::from_le_bytes(bytes.try_into().map_err(|_| roto_runtime::RotoError::WireFormatViolation)?))
|
||||
Ok(f64::from_le_bytes(bytes.try_into().map_err(|_| {
|
||||
roto_runtime::RotoError::WireFormatViolation
|
||||
})?))
|
||||
}
|
||||
|
||||
pub fn d_or_default(&self) -> roto_runtime::Result<f64> {
|
||||
self.d().or(Ok(0.0))
|
||||
}
|
||||
|
||||
pub fn has_d(&self) -> bool { self.d_offset.is_some() }
|
||||
pub fn has_d(&self) -> bool {
|
||||
self.d_offset.is_some()
|
||||
}
|
||||
|
||||
pub fn f(&self) -> roto_runtime::Result<f32> {
|
||||
let offset = self.f_offset.ok_or(roto_runtime::RotoError::FieldNotFound)?;
|
||||
let offset = self
|
||||
.f_offset
|
||||
.ok_or(roto_runtime::RotoError::FieldNotFound)?;
|
||||
let (bytes, _) = self.accessor.get_value_at(offset)?;
|
||||
Ok(f32::from_le_bytes(bytes.try_into().map_err(|_| roto_runtime::RotoError::WireFormatViolation)?))
|
||||
Ok(f32::from_le_bytes(bytes.try_into().map_err(|_| {
|
||||
roto_runtime::RotoError::WireFormatViolation
|
||||
})?))
|
||||
}
|
||||
|
||||
pub fn f_or_default(&self) -> roto_runtime::Result<f32> {
|
||||
self.f().or(Ok(0.0))
|
||||
}
|
||||
|
||||
pub fn has_f(&self) -> bool { self.f_offset.is_some() }
|
||||
pub fn has_f(&self) -> bool {
|
||||
self.f_offset.is_some()
|
||||
}
|
||||
|
||||
pub fn b(&self) -> roto_runtime::Result<bool> {
|
||||
let offset = self.b_offset.ok_or(roto_runtime::RotoError::FieldNotFound)?;
|
||||
let offset = self
|
||||
.b_offset
|
||||
.ok_or(roto_runtime::RotoError::FieldNotFound)?;
|
||||
let (bytes, _) = self.accessor.get_value_at(offset)?;
|
||||
roto_runtime::read_varint(bytes).map(|(v, _)| v != 0).map_err(|_| roto_runtime::RotoError::WireFormatViolation)
|
||||
roto_runtime::read_varint(bytes)
|
||||
.map(|(v, _)| v != 0)
|
||||
.map_err(|_| roto_runtime::RotoError::WireFormatViolation)
|
||||
}
|
||||
|
||||
pub fn b_or_default(&self) -> roto_runtime::Result<bool> {
|
||||
self.b().or(Ok(false))
|
||||
}
|
||||
|
||||
pub fn has_b(&self) -> bool { self.b_offset.is_some() }
|
||||
pub fn has_b(&self) -> bool {
|
||||
self.b_offset.is_some()
|
||||
}
|
||||
|
||||
pub fn n(&self) -> roto_runtime::Result<i32> {
|
||||
let offset = self.n_offset.ok_or(roto_runtime::RotoError::FieldNotFound)?;
|
||||
let offset = self
|
||||
.n_offset
|
||||
.ok_or(roto_runtime::RotoError::FieldNotFound)?;
|
||||
let (bytes, _) = self.accessor.get_value_at(offset)?;
|
||||
roto_runtime::read_varint(bytes).map(|(v, _)| v as i32).map_err(|_| roto_runtime::RotoError::WireFormatViolation)
|
||||
roto_runtime::read_varint(bytes)
|
||||
.map(|(v, _)| v as i32)
|
||||
.map_err(|_| roto_runtime::RotoError::WireFormatViolation)
|
||||
}
|
||||
|
||||
pub fn n_or_default(&self) -> roto_runtime::Result<i32> {
|
||||
self.n().or(Ok(0))
|
||||
}
|
||||
|
||||
pub fn has_n(&self) -> bool { self.n_offset.is_some() }
|
||||
pub fn has_n(&self) -> bool {
|
||||
self.n_offset.is_some()
|
||||
}
|
||||
|
||||
pub fn l(&self) -> roto_runtime::Result<i32> {
|
||||
let offset = self.l_offset.ok_or(roto_runtime::RotoError::FieldNotFound)?;
|
||||
let offset = self
|
||||
.l_offset
|
||||
.ok_or(roto_runtime::RotoError::FieldNotFound)?;
|
||||
let (bytes, _) = self.accessor.get_value_at(offset)?;
|
||||
roto_runtime::read_varint(bytes).map(|(v, _)| v as i32).map_err(|_| roto_runtime::RotoError::WireFormatViolation)
|
||||
roto_runtime::read_varint(bytes)
|
||||
.map(|(v, _)| v as i32)
|
||||
.map_err(|_| roto_runtime::RotoError::WireFormatViolation)
|
||||
}
|
||||
|
||||
pub fn l_or_default(&self) -> roto_runtime::Result<i32> {
|
||||
self.l().or(Ok(0))
|
||||
}
|
||||
|
||||
pub fn has_l(&self) -> bool { self.l_offset.is_some() }
|
||||
pub fn has_l(&self) -> bool {
|
||||
self.l_offset.is_some()
|
||||
}
|
||||
|
||||
pub fn c1(&self) -> roto_runtime::Result<&'a str> {
|
||||
let offset = self.c1_offset.ok_or(roto_runtime::RotoError::FieldNotFound)?;
|
||||
let offset = self
|
||||
.c1_offset
|
||||
.ok_or(roto_runtime::RotoError::FieldNotFound)?;
|
||||
let (bytes, _) = self.accessor.get_value_at(offset)?;
|
||||
std::str::from_utf8(bytes).map_err(|_| roto_runtime::RotoError::WireFormatViolation)
|
||||
}
|
||||
@@ -157,19 +219,27 @@ pets_start, pets_end,
|
||||
self.c1().or(Ok(""))
|
||||
}
|
||||
|
||||
pub fn has_c1(&self) -> bool { self.c1_offset.is_some() }
|
||||
pub fn has_c1(&self) -> bool {
|
||||
self.c1_offset.is_some()
|
||||
}
|
||||
|
||||
pub fn c2(&self) -> roto_runtime::Result<bool> {
|
||||
let offset = self.c2_offset.ok_or(roto_runtime::RotoError::FieldNotFound)?;
|
||||
let offset = self
|
||||
.c2_offset
|
||||
.ok_or(roto_runtime::RotoError::FieldNotFound)?;
|
||||
let (bytes, _) = self.accessor.get_value_at(offset)?;
|
||||
roto_runtime::read_varint(bytes).map(|(v, _)| v != 0).map_err(|_| roto_runtime::RotoError::WireFormatViolation)
|
||||
roto_runtime::read_varint(bytes)
|
||||
.map(|(v, _)| v != 0)
|
||||
.map_err(|_| roto_runtime::RotoError::WireFormatViolation)
|
||||
}
|
||||
|
||||
pub fn c2_or_default(&self) -> roto_runtime::Result<bool> {
|
||||
self.c2().or(Ok(false))
|
||||
}
|
||||
|
||||
pub fn has_c2(&self) -> bool { self.c2_offset.is_some() }
|
||||
pub fn has_c2(&self) -> bool {
|
||||
self.c2_offset.is_some()
|
||||
}
|
||||
|
||||
pub fn pets(&self) -> roto_runtime::RepeatedFieldIterator<'a> {
|
||||
match (self.pets_start, self.pets_end) {
|
||||
@@ -178,12 +248,12 @@ pets_start, pets_end,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn which_choice(&self) -> roto_runtime::Result<Option<hello::Choice<'a>> > {
|
||||
pub fn which_choice(&self) -> roto_runtime::Result<Option<hello::Choice<'a>>> {
|
||||
if self.c1_offset.is_some() {
|
||||
return Ok(Some(hello::Choice::c1 (self.c1()?)));
|
||||
return Ok(Some(hello::Choice::c1(self.c1()?)));
|
||||
}
|
||||
if self.c2_offset.is_some() {
|
||||
return Ok(Some(hello::Choice::c2 (self.c2()?)));
|
||||
return Ok(Some(hello::Choice::c2(self.c2()?)));
|
||||
}
|
||||
Ok(None)
|
||||
}
|
||||
@@ -191,7 +261,6 @@ pets_start, pets_end,
|
||||
pub fn raw_fields(&self) -> roto_runtime::RawFieldIterator<'a> {
|
||||
self.accessor.raw_fields()
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
pub struct HelloBuilder<'b> {
|
||||
@@ -326,161 +395,172 @@ impl roto_runtime::RotoMessage for OwnedHello {
|
||||
}
|
||||
|
||||
pub mod hello {
|
||||
pub struct Pet<'a> {
|
||||
accessor: roto_runtime::ProtoAccessor<'a>,
|
||||
name_offset: Option<usize>,
|
||||
color_offset: Option<usize>,
|
||||
}
|
||||
pub struct Pet<'a> {
|
||||
accessor: roto_runtime::ProtoAccessor<'a>,
|
||||
name_offset: Option<usize>,
|
||||
color_offset: Option<usize>,
|
||||
}
|
||||
|
||||
impl<'a> Pet<'a> {
|
||||
pub fn new(data: &'a [u8]) -> roto_runtime::Result<Self> {
|
||||
let accessor = roto_runtime::ProtoAccessor::new(data)?;
|
||||
let mut name_offset = None;
|
||||
let mut color_offset = None;
|
||||
for item in accessor.fields() {
|
||||
let (offset, tag, _) = item?;
|
||||
if tag.field_number == 1 { name_offset = Some(offset); }
|
||||
if tag.field_number == 2 { color_offset = Some(offset); }
|
||||
impl<'a> Pet<'a> {
|
||||
pub fn new(data: &'a [u8]) -> roto_runtime::Result<Self> {
|
||||
let accessor = roto_runtime::ProtoAccessor::new(data)?;
|
||||
let mut name_offset = None;
|
||||
let mut color_offset = None;
|
||||
for item in accessor.fields() {
|
||||
let (offset, tag, _) = item?;
|
||||
if tag.field_number == 1 {
|
||||
name_offset = Some(offset);
|
||||
}
|
||||
if tag.field_number == 2 {
|
||||
color_offset = Some(offset);
|
||||
}
|
||||
}
|
||||
|
||||
Ok(Self {
|
||||
accessor,
|
||||
name_offset,
|
||||
color_offset,
|
||||
})
|
||||
}
|
||||
|
||||
Ok(Self {
|
||||
accessor,
|
||||
name_offset,
|
||||
color_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)?;
|
||||
std::str::from_utf8(bytes).map_err(|_| roto_runtime::RotoError::WireFormatViolation)
|
||||
}
|
||||
|
||||
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)?;
|
||||
std::str::from_utf8(bytes).map_err(|_| roto_runtime::RotoError::WireFormatViolation)
|
||||
}
|
||||
pub fn name_or_default(&self) -> roto_runtime::Result<&'a str> {
|
||||
self.name().or(Ok(""))
|
||||
}
|
||||
|
||||
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 has_name(&self) -> bool { self.name_offset.is_some() }
|
||||
pub fn color(&self) -> roto_runtime::Result<u64> {
|
||||
let offset = self
|
||||
.color_offset
|
||||
.ok_or(roto_runtime::RotoError::FieldNotFound)?;
|
||||
let (bytes, _) = self.accessor.get_value_at(offset)?;
|
||||
roto_runtime::read_varint(bytes)
|
||||
.map(|(v, _)| v as u64)
|
||||
.map_err(|_| roto_runtime::RotoError::WireFormatViolation)
|
||||
}
|
||||
|
||||
pub fn color(&self) -> roto_runtime::Result<u64> {
|
||||
let offset = self.color_offset.ok_or(roto_runtime::RotoError::FieldNotFound)?;
|
||||
let (bytes, _) = self.accessor.get_value_at(offset)?;
|
||||
roto_runtime::read_varint(bytes).map(|(v, _)| v as u64).map_err(|_| roto_runtime::RotoError::WireFormatViolation)
|
||||
}
|
||||
pub fn color_or_default(&self) -> roto_runtime::Result<u64> {
|
||||
self.color().or(Ok(0))
|
||||
}
|
||||
|
||||
pub fn color_or_default(&self) -> roto_runtime::Result<u64> {
|
||||
self.color().or(Ok(0))
|
||||
}
|
||||
pub fn has_color(&self) -> bool {
|
||||
self.color_offset.is_some()
|
||||
}
|
||||
|
||||
pub fn has_color(&self) -> bool { self.color_offset.is_some() }
|
||||
|
||||
pub fn raw_fields(&self) -> roto_runtime::RawFieldIterator<'a> {
|
||||
self.accessor.raw_fields()
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
pub struct PetBuilder<'b> {
|
||||
builder: roto_runtime::ProtoBuilder<'b>,
|
||||
name_written: bool,
|
||||
color_written: bool,
|
||||
}
|
||||
|
||||
impl<'b> PetBuilder<'b> {
|
||||
pub fn builder(buf: &mut [u8]) -> PetBuilder<'_> {
|
||||
PetBuilder {
|
||||
builder: roto_runtime::ProtoBuilder::new(buf),
|
||||
name_written: false,
|
||||
color_written: false,
|
||||
pub fn raw_fields(&self) -> roto_runtime::RawFieldIterator<'a> {
|
||||
self.accessor.raw_fields()
|
||||
}
|
||||
}
|
||||
|
||||
pub fn name(mut self, value: &str) -> roto_runtime::Result<Self> {
|
||||
self.builder.write_string(1, value)?;
|
||||
self.name_written = true;
|
||||
Ok(self)
|
||||
pub struct PetBuilder<'b> {
|
||||
builder: roto_runtime::ProtoBuilder<'b>,
|
||||
name_written: bool,
|
||||
color_written: bool,
|
||||
}
|
||||
|
||||
pub fn color(mut self, value: u64) -> roto_runtime::Result<Self> {
|
||||
self.builder.write_varint(2, value)?;
|
||||
self.color_written = true;
|
||||
Ok(self)
|
||||
}
|
||||
|
||||
pub fn with(mut self, msg: &Pet<'_>) -> roto_runtime::Result<Self> {
|
||||
for item in msg.accessor.raw_fields() {
|
||||
let (field_number, raw_bytes) = item?;
|
||||
let is_written = match field_number {
|
||||
1 => self.name_written,
|
||||
2 => self.color_written,
|
||||
_ => false,
|
||||
};
|
||||
if !is_written {
|
||||
self.builder.write_raw(raw_bytes)?;
|
||||
impl<'b> PetBuilder<'b> {
|
||||
pub fn builder(buf: &mut [u8]) -> PetBuilder<'_> {
|
||||
PetBuilder {
|
||||
builder: roto_runtime::ProtoBuilder::new(buf),
|
||||
name_written: false,
|
||||
color_written: false,
|
||||
}
|
||||
}
|
||||
Ok(self)
|
||||
}
|
||||
|
||||
pub fn finish(self) -> roto_runtime::Result<&'b mut [u8]> {
|
||||
self.builder.finish()
|
||||
}
|
||||
}
|
||||
pub fn name(mut self, value: &str) -> roto_runtime::Result<Self> {
|
||||
self.builder.write_string(1, value)?;
|
||||
self.name_written = true;
|
||||
Ok(self)
|
||||
}
|
||||
|
||||
pub struct OwnedPet {
|
||||
pub data: bytes::Bytes,
|
||||
}
|
||||
pub fn color(mut self, value: u64) -> roto_runtime::Result<Self> {
|
||||
self.builder.write_varint(2, value)?;
|
||||
self.color_written = true;
|
||||
Ok(self)
|
||||
}
|
||||
|
||||
impl roto_runtime::RotoOwned for OwnedPet {
|
||||
type Reader<'a> = Pet<'a>;
|
||||
fn reader(&self) -> Pet<'_> {
|
||||
Pet::new(&self.data).expect("failed to create reader")
|
||||
}
|
||||
}
|
||||
pub fn with(mut self, msg: &Pet<'_>) -> roto_runtime::Result<Self> {
|
||||
for item in msg.accessor.raw_fields() {
|
||||
let (field_number, raw_bytes) = item?;
|
||||
let is_written = match field_number {
|
||||
1 => self.name_written,
|
||||
2 => self.color_written,
|
||||
_ => false,
|
||||
};
|
||||
if !is_written {
|
||||
self.builder.write_raw(raw_bytes)?;
|
||||
}
|
||||
}
|
||||
Ok(self)
|
||||
}
|
||||
|
||||
impl roto_runtime::RotoMessage for OwnedPet {
|
||||
fn decode(buf: bytes::Bytes) -> roto_runtime::Result<Self> {
|
||||
Ok(OwnedPet { data: buf })
|
||||
}
|
||||
|
||||
fn bytes(&self) -> bytes::Bytes {
|
||||
self.data.clone()
|
||||
}
|
||||
}
|
||||
|
||||
pub mod pet {
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
|
||||
#[repr(i32)]
|
||||
pub enum Color {
|
||||
BLACK = 0,
|
||||
WHITE = 1,
|
||||
BLUE = 2,
|
||||
RED = 3,
|
||||
YELLOW = 4,
|
||||
GREEN = 5,
|
||||
}
|
||||
|
||||
impl Color {
|
||||
pub fn from_i32(value: i32) -> Self {
|
||||
match value {
|
||||
0 => Color::BLACK,
|
||||
1 => Color::WHITE,
|
||||
2 => Color::BLUE,
|
||||
3 => Color::RED,
|
||||
4 => Color::YELLOW,
|
||||
5 => Color::GREEN,
|
||||
_ => Color::BLACK,
|
||||
pub fn finish(self) -> roto_runtime::Result<&'b mut [u8]> {
|
||||
self.builder.finish()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
pub struct OwnedPet {
|
||||
pub data: bytes::Bytes,
|
||||
}
|
||||
|
||||
pub enum Choice<'a> {
|
||||
c1(&'a str),
|
||||
c2(bool),
|
||||
}
|
||||
impl roto_runtime::RotoOwned for OwnedPet {
|
||||
type Reader<'a> = Pet<'a>;
|
||||
fn reader(&self) -> Pet<'_> {
|
||||
Pet::new(&self.data).expect("failed to create reader")
|
||||
}
|
||||
}
|
||||
|
||||
impl roto_runtime::RotoMessage for OwnedPet {
|
||||
fn decode(buf: bytes::Bytes) -> roto_runtime::Result<Self> {
|
||||
Ok(OwnedPet { data: buf })
|
||||
}
|
||||
|
||||
fn bytes(&self) -> bytes::Bytes {
|
||||
self.data.clone()
|
||||
}
|
||||
}
|
||||
|
||||
pub mod pet {
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
|
||||
#[repr(i32)]
|
||||
pub enum Color {
|
||||
BLACK = 0,
|
||||
WHITE = 1,
|
||||
BLUE = 2,
|
||||
RED = 3,
|
||||
YELLOW = 4,
|
||||
GREEN = 5,
|
||||
}
|
||||
|
||||
impl Color {
|
||||
pub fn from_i32(value: i32) -> Self {
|
||||
match value {
|
||||
0 => Color::BLACK,
|
||||
1 => Color::WHITE,
|
||||
2 => Color::BLUE,
|
||||
3 => Color::RED,
|
||||
4 => Color::YELLOW,
|
||||
5 => Color::GREEN,
|
||||
_ => Color::BLACK,
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub enum Choice<'a> {
|
||||
c1(&'a str),
|
||||
c2(bool),
|
||||
}
|
||||
}
|
||||
|
||||
pub struct HelloRequest<'a> {
|
||||
@@ -494,17 +574,21 @@ impl<'a> HelloRequest<'a> {
|
||||
let mut request_offset = None;
|
||||
for item in accessor.fields() {
|
||||
let (offset, tag, _) = item?;
|
||||
if tag.field_number == 1 { request_offset = Some(offset); }
|
||||
if tag.field_number == 1 {
|
||||
request_offset = Some(offset);
|
||||
}
|
||||
}
|
||||
|
||||
Ok(Self {
|
||||
accessor,
|
||||
request_offset,
|
||||
request_offset,
|
||||
})
|
||||
}
|
||||
|
||||
pub fn request(&self) -> roto_runtime::Result<&'a [u8]> {
|
||||
let offset = self.request_offset.ok_or(roto_runtime::RotoError::FieldNotFound)?;
|
||||
let offset = self
|
||||
.request_offset
|
||||
.ok_or(roto_runtime::RotoError::FieldNotFound)?;
|
||||
let (bytes, _) = self.accessor.get_value_at(offset)?;
|
||||
Ok(bytes)
|
||||
}
|
||||
@@ -513,12 +597,13 @@ request_offset,
|
||||
self.request().or(Ok(&[]))
|
||||
}
|
||||
|
||||
pub fn has_request(&self) -> bool { self.request_offset.is_some() }
|
||||
pub fn has_request(&self) -> bool {
|
||||
self.request_offset.is_some()
|
||||
}
|
||||
|
||||
pub fn raw_fields(&self) -> roto_runtime::RawFieldIterator<'a> {
|
||||
self.accessor.raw_fields()
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
pub struct HelloRequestBuilder<'b> {
|
||||
@@ -591,17 +676,21 @@ impl<'a> HelloReply<'a> {
|
||||
let mut response_offset = None;
|
||||
for item in accessor.fields() {
|
||||
let (offset, tag, _) = item?;
|
||||
if tag.field_number == 1 { response_offset = Some(offset); }
|
||||
if tag.field_number == 1 {
|
||||
response_offset = Some(offset);
|
||||
}
|
||||
}
|
||||
|
||||
Ok(Self {
|
||||
accessor,
|
||||
response_offset,
|
||||
response_offset,
|
||||
})
|
||||
}
|
||||
|
||||
pub fn response(&self) -> roto_runtime::Result<&'a [u8]> {
|
||||
let offset = self.response_offset.ok_or(roto_runtime::RotoError::FieldNotFound)?;
|
||||
let offset = self
|
||||
.response_offset
|
||||
.ok_or(roto_runtime::RotoError::FieldNotFound)?;
|
||||
let (bytes, _) = self.accessor.get_value_at(offset)?;
|
||||
Ok(bytes)
|
||||
}
|
||||
@@ -610,12 +699,13 @@ response_offset,
|
||||
self.response().or(Ok(&[]))
|
||||
}
|
||||
|
||||
pub fn has_response(&self) -> bool { self.response_offset.is_some() }
|
||||
pub fn has_response(&self) -> bool {
|
||||
self.response_offset.is_some()
|
||||
}
|
||||
|
||||
pub fn raw_fields(&self) -> roto_runtime::RawFieldIterator<'a> {
|
||||
self.accessor.raw_fields()
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
pub struct HelloReplyBuilder<'b> {
|
||||
@@ -679,7 +769,10 @@ impl roto_runtime::RotoMessage for OwnedHelloReply {
|
||||
|
||||
#[tonic::async_trait]
|
||||
pub trait Greeter: Send + Sync + 'static {
|
||||
async fn say_hello(&self, request: Request<OwnedHelloRequest>) -> std::result::Result<Response<OwnedHelloReply>, Status>;
|
||||
async fn say_hello(
|
||||
&self,
|
||||
request: Request<OwnedHelloRequest>,
|
||||
) -> std::result::Result<Response<OwnedHelloReply>, Status>;
|
||||
}
|
||||
|
||||
#[derive(Clone)]
|
||||
@@ -701,7 +794,8 @@ impl tonic::server::NamedService for GreeterServer {
|
||||
impl Service<http::Request<BoxBody>> for GreeterServer {
|
||||
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(()))
|
||||
@@ -726,8 +820,14 @@ impl Service<http::Request<BoxBody>> for GreeterServer {
|
||||
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..);
|
||||
@@ -737,16 +837,28 @@ impl Service<http::Request<BoxBody>> for GreeterServer {
|
||||
let request_msg = match OwnedHelloRequest::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.say_hello(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());
|
||||
}
|
||||
};
|
||||
|
||||
@@ -762,13 +874,26 @@ impl Service<http::Request<BoxBody>> for GreeterServer {
|
||||
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 !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())
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
// @generated by protoc-gen-roto — do not edit
|
||||
#![allow(unused)]
|
||||
#[allow(unused, unused_imports, unused_assignments, unused_variables, non_camel_case_types)]
|
||||
use roto_runtime::{ProtoAccessor, ProtoBuilder, Result, RotoError, read_varint, RepeatedFieldIterator, RotoMessage};
|
||||
use core::str;
|
||||
use bytes::{Bytes, BytesMut, Buf, BufMut};
|
||||
@@ -394,6 +394,7 @@ 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 std::pin::Pin;
|
||||
@@ -462,12 +463,12 @@ impl Service<http::Request<BoxBody>> for InteropServiceServer {
|
||||
}
|
||||
|
||||
let payload = bytes_vec.slice(5..);
|
||||
#[allow(unused_assignments)]
|
||||
let mut routed = false;
|
||||
|
||||
if path == "/interop.InteropService/UnaryCall" {
|
||||
let request_msg = match OwnedUnaryRequest::decode(payload) {
|
||||
Ok(msg) => msg,
|
||||
Err(e) => {
|
||||
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());
|
||||
}
|
||||
@@ -475,7 +476,7 @@ impl Service<http::Request<BoxBody>> for InteropServiceServer {
|
||||
|
||||
let response = match inner.unary_call(Request::new(request_msg)).await {
|
||||
Ok(res) => res,
|
||||
Err(e) => {
|
||||
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());
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user