Update codegen to suppress more compiler warnings

This commit is contained in:
2026-06-18 22:36:11 -07:00
parent bbe2083965
commit 3d0eab01cf
7 changed files with 4400 additions and 3048 deletions
+5 -3
View File
@@ -7,11 +7,11 @@ use crate::runtime::ProtoAccessor;
use std::collections::{HashMap, HashSet}; use std::collections::{HashMap, HashSet};
use std::str; use std::str;
const DATA_IMPORTS: &str = "#[allow(unused)]\n\ const DATA_IMPORTS: &str = "#[allow(unused, unused_imports, unused_assignments, unused_variables, non_camel_case_types)]\n\
use roto_runtime::{ProtoAccessor, ProtoBuilder, Result, RotoError, read_varint, RepeatedFieldIterator, RotoMessage};\n\ use roto_runtime::{ProtoAccessor, ProtoBuilder, Result, RotoError, read_varint, RepeatedFieldIterator, RotoMessage};\n\
use core::str;\n\ use core::str;\n\
use bytes::{Bytes, BytesMut, Buf, BufMut};\n"; use bytes::{Bytes, BytesMut, Buf, BufMut};\n";
const SERVICE_IMPORTS: &str = "#[allow(unused)]\n\ const SERVICE_IMPORTS: &str = "#[allow(unused, unused_imports, unused_assignments, unused_variables, non_camel_case_types)]\n\
use tonic::{Request, Response, Status};\n\ use tonic::{Request, Response, Status};\n\
use tokio_stream::Stream;\n\ use tokio_stream::Stream;\n\
use std::pin::Pin;\n\ use std::pin::Pin;\n\
@@ -591,7 +591,6 @@ where
let mut output = String::new(); let mut output = String::new();
output.push_str("// @generated by protoc-gen-roto — do not edit\n"); output.push_str("// @generated by protoc-gen-roto — do not edit\n");
output.push_str("#[allow(unused_imports)]\n");
output.push_str(imports); output.push_str(imports);
for dep_res in file_proto.dependency() { for dep_res in file_proto.dependency() {
@@ -773,6 +772,9 @@ fn strip_boilerplate(content: &str) -> String {
"#[allow(unused_imports)]\n", "#[allow(unused_imports)]\n",
"#![allow(unused_imports)]\n\n", "#![allow(unused_imports)]\n\n",
"#![allow(unused_imports)]\n", "#![allow(unused_imports)]\n",
"#[allow(unused, unused_imports, unused_assignments, unused_variables, non_camel_case_types)]\n",
"#![allow(unused, unused_imports, unused_assignments, unused_variables, non_camel_case_types)]\n",
"#![allow(unused, unused_imports, unused_assignments, unused_variables)]\n",
]; ];
for pattern in patterns { for pattern in patterns {
+221 -108
View File
@@ -1,21 +1,29 @@
// @generated by protoc-gen-roto — do not edit // @generated by protoc-gen-roto — do not edit
#[allow(unused)] #![allow(
unused,
unused_imports,
unused_assignments,
unused_variables,
non_camel_case_types
)]
use crate::runtime::{ProtoAccessor, ProtoBuilder, Result, RotoError, read_varint, RepeatedFieldIterator}; use crate::runtime::{
use std::str; ProtoAccessor, ProtoBuilder, RepeatedFieldIterator, Result, RotoError, read_varint,
use bytes::{Bytes, BytesMut, Buf, BufMut}; };
use tonic::{Request, Response, Status}; use bytes::{Buf, BufMut, Bytes, BytesMut};
use tokio_stream::Stream; use futures_util::StreamExt;
use http_body::Body;
use http_body_util::BodyExt;
use roto_tonic::{BufferPool, StatusBody};
use std::future::Future;
use std::pin::Pin; use std::pin::Pin;
use std::str;
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;
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 roto_tonic::{BufferPool, StatusBody};
use crate::google::protobuf::descriptor; use crate::google::protobuf::descriptor;
@@ -36,59 +44,87 @@ impl<'a> Version<'a> {
let mut suffix_offset = None; let mut suffix_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 { major_offset = Some(offset); } if tag.field_number == 1 {
if tag.field_number == 2 { minor_offset = Some(offset); } major_offset = Some(offset);
if tag.field_number == 3 { patch_offset = Some(offset); } }
if tag.field_number == 4 { suffix_offset = Some(offset); } if tag.field_number == 2 {
minor_offset = Some(offset);
}
if tag.field_number == 3 {
patch_offset = Some(offset);
}
if tag.field_number == 4 {
suffix_offset = Some(offset);
}
} }
Ok(Self { Ok(Self {
accessor, accessor,
major_offset, major_offset,
minor_offset, minor_offset,
patch_offset, patch_offset,
suffix_offset, suffix_offset,
}) })
} }
pub fn major(&self) -> crate::runtime::Result<i32> { pub fn major(&self) -> crate::runtime::Result<i32> {
let offset = self.major_offset.ok_or(crate::runtime::RotoError::FieldNotFound)?; let offset = self
.major_offset
.ok_or(crate::runtime::RotoError::FieldNotFound)?;
let (bytes, _) = self.accessor.get_value_at(offset)?; let (bytes, _) = self.accessor.get_value_at(offset)?;
crate::runtime::read_varint(bytes).map(|(v, _)| v as i32).map_err(|_| crate::runtime::RotoError::WireFormatViolation) crate::runtime::read_varint(bytes)
.map(|(v, _)| v as i32)
.map_err(|_| crate::runtime::RotoError::WireFormatViolation)
} }
pub fn major_or_default(&self) -> crate::runtime::Result<i32> { pub fn major_or_default(&self) -> crate::runtime::Result<i32> {
self.major().or(Ok(0)) self.major().or(Ok(0))
} }
pub fn has_major(&self) -> bool { self.major_offset.is_some() } pub fn has_major(&self) -> bool {
self.major_offset.is_some()
}
pub fn minor(&self) -> crate::runtime::Result<i32> { pub fn minor(&self) -> crate::runtime::Result<i32> {
let offset = self.minor_offset.ok_or(crate::runtime::RotoError::FieldNotFound)?; let offset = self
.minor_offset
.ok_or(crate::runtime::RotoError::FieldNotFound)?;
let (bytes, _) = self.accessor.get_value_at(offset)?; let (bytes, _) = self.accessor.get_value_at(offset)?;
crate::runtime::read_varint(bytes).map(|(v, _)| v as i32).map_err(|_| crate::runtime::RotoError::WireFormatViolation) crate::runtime::read_varint(bytes)
.map(|(v, _)| v as i32)
.map_err(|_| crate::runtime::RotoError::WireFormatViolation)
} }
pub fn minor_or_default(&self) -> crate::runtime::Result<i32> { pub fn minor_or_default(&self) -> crate::runtime::Result<i32> {
self.minor().or(Ok(0)) self.minor().or(Ok(0))
} }
pub fn has_minor(&self) -> bool { self.minor_offset.is_some() } pub fn has_minor(&self) -> bool {
self.minor_offset.is_some()
}
pub fn patch(&self) -> crate::runtime::Result<i32> { pub fn patch(&self) -> crate::runtime::Result<i32> {
let offset = self.patch_offset.ok_or(crate::runtime::RotoError::FieldNotFound)?; let offset = self
.patch_offset
.ok_or(crate::runtime::RotoError::FieldNotFound)?;
let (bytes, _) = self.accessor.get_value_at(offset)?; let (bytes, _) = self.accessor.get_value_at(offset)?;
crate::runtime::read_varint(bytes).map(|(v, _)| v as i32).map_err(|_| crate::runtime::RotoError::WireFormatViolation) crate::runtime::read_varint(bytes)
.map(|(v, _)| v as i32)
.map_err(|_| crate::runtime::RotoError::WireFormatViolation)
} }
pub fn patch_or_default(&self) -> crate::runtime::Result<i32> { pub fn patch_or_default(&self) -> crate::runtime::Result<i32> {
self.patch().or(Ok(0)) self.patch().or(Ok(0))
} }
pub fn has_patch(&self) -> bool { self.patch_offset.is_some() } pub fn has_patch(&self) -> bool {
self.patch_offset.is_some()
}
pub fn suffix(&self) -> crate::runtime::Result<&'a str> { pub fn suffix(&self) -> crate::runtime::Result<&'a str> {
let offset = self.suffix_offset.ok_or(crate::runtime::RotoError::FieldNotFound)?; let offset = self
.suffix_offset
.ok_or(crate::runtime::RotoError::FieldNotFound)?;
let (bytes, _) = self.accessor.get_value_at(offset)?; let (bytes, _) = self.accessor.get_value_at(offset)?;
str::from_utf8(bytes).map_err(|_| crate::runtime::RotoError::WireFormatViolation) str::from_utf8(bytes).map_err(|_| crate::runtime::RotoError::WireFormatViolation)
} }
@@ -97,12 +133,13 @@ suffix_offset,
self.suffix().or(Ok("")) self.suffix().or(Ok(""))
} }
pub fn has_suffix(&self) -> bool { self.suffix_offset.is_some() } pub fn has_suffix(&self) -> bool {
self.suffix_offset.is_some()
}
pub fn raw_fields(&self) -> crate::runtime::RawFieldIterator<'a> { pub fn raw_fields(&self) -> crate::runtime::RawFieldIterator<'a> {
self.accessor.raw_fields() self.accessor.raw_fields()
} }
} }
pub struct VersionBuilder<'b> { pub struct VersionBuilder<'b> {
@@ -217,28 +254,41 @@ impl<'a> CodeGeneratorRequest<'a> {
for item in accessor.fields() { for item in accessor.fields() {
let (offset, tag, _) = item?; let (offset, tag, _) = item?;
if tag.field_number == 1 { if tag.field_number == 1 {
if file_to_generate_start.is_none() { file_to_generate_start = Some(offset); } if file_to_generate_start.is_none() {
file_to_generate_start = Some(offset);
}
file_to_generate_end = Some(offset); file_to_generate_end = Some(offset);
} }
if tag.field_number == 2 { parameter_offset = Some(offset); } if tag.field_number == 2 {
parameter_offset = Some(offset);
}
if tag.field_number == 15 { if tag.field_number == 15 {
if proto_file_start.is_none() { proto_file_start = Some(offset); } if proto_file_start.is_none() {
proto_file_start = Some(offset);
}
proto_file_end = Some(offset); proto_file_end = Some(offset);
} }
if tag.field_number == 17 { if tag.field_number == 17 {
if source_file_descriptors_start.is_none() { source_file_descriptors_start = Some(offset); } if source_file_descriptors_start.is_none() {
source_file_descriptors_start = Some(offset);
}
source_file_descriptors_end = Some(offset); source_file_descriptors_end = Some(offset);
} }
if tag.field_number == 3 { compiler_version_offset = Some(offset); } if tag.field_number == 3 {
compiler_version_offset = Some(offset);
}
} }
Ok(Self { Ok(Self {
accessor, accessor,
file_to_generate_start, file_to_generate_end, file_to_generate_start,
parameter_offset, file_to_generate_end,
proto_file_start, proto_file_end, parameter_offset,
source_file_descriptors_start, source_file_descriptors_end, proto_file_start,
compiler_version_offset, proto_file_end,
source_file_descriptors_start,
source_file_descriptors_end,
compiler_version_offset,
}) })
} }
@@ -250,7 +300,9 @@ compiler_version_offset,
} }
pub fn parameter(&self) -> crate::runtime::Result<&'a str> { pub fn parameter(&self) -> crate::runtime::Result<&'a str> {
let offset = self.parameter_offset.ok_or(crate::runtime::RotoError::FieldNotFound)?; let offset = self
.parameter_offset
.ok_or(crate::runtime::RotoError::FieldNotFound)?;
let (bytes, _) = self.accessor.get_value_at(offset)?; let (bytes, _) = self.accessor.get_value_at(offset)?;
str::from_utf8(bytes).map_err(|_| crate::runtime::RotoError::WireFormatViolation) str::from_utf8(bytes).map_err(|_| crate::runtime::RotoError::WireFormatViolation)
} }
@@ -259,7 +311,9 @@ compiler_version_offset,
self.parameter().or(Ok("")) self.parameter().or(Ok(""))
} }
pub fn has_parameter(&self) -> bool { self.parameter_offset.is_some() } pub fn has_parameter(&self) -> bool {
self.parameter_offset.is_some()
}
pub fn proto_file(&self) -> crate::runtime::RepeatedFieldIterator<'a> { pub fn proto_file(&self) -> crate::runtime::RepeatedFieldIterator<'a> {
match (self.proto_file_start, self.proto_file_end) { match (self.proto_file_start, self.proto_file_end) {
@@ -269,14 +323,19 @@ compiler_version_offset,
} }
pub fn source_file_descriptors(&self) -> crate::runtime::RepeatedFieldIterator<'a> { pub fn source_file_descriptors(&self) -> crate::runtime::RepeatedFieldIterator<'a> {
match (self.source_file_descriptors_start, self.source_file_descriptors_end) { match (
self.source_file_descriptors_start,
self.source_file_descriptors_end,
) {
(Some(start), Some(end)) => self.accessor.iter_repeated_range(17, start, end), (Some(start), Some(end)) => self.accessor.iter_repeated_range(17, start, end),
_ => self.accessor.iter_repeated(17), _ => self.accessor.iter_repeated(17),
} }
} }
pub fn compiler_version(&self) -> crate::runtime::Result<&'a [u8]> { pub fn compiler_version(&self) -> crate::runtime::Result<&'a [u8]> {
let offset = self.compiler_version_offset.ok_or(crate::runtime::RotoError::FieldNotFound)?; let offset = self
.compiler_version_offset
.ok_or(crate::runtime::RotoError::FieldNotFound)?;
let (bytes, _) = self.accessor.get_value_at(offset)?; let (bytes, _) = self.accessor.get_value_at(offset)?;
Ok(bytes) Ok(bytes)
} }
@@ -285,12 +344,13 @@ compiler_version_offset,
self.compiler_version().or(Ok(&[])) self.compiler_version().or(Ok(&[]))
} }
pub fn has_compiler_version(&self) -> bool { self.compiler_version_offset.is_some() } pub fn has_compiler_version(&self) -> bool {
self.compiler_version_offset.is_some()
}
pub fn raw_fields(&self) -> crate::runtime::RawFieldIterator<'a> { pub fn raw_fields(&self) -> crate::runtime::RawFieldIterator<'a> {
self.accessor.raw_fields() self.accessor.raw_fields()
} }
} }
pub struct CodeGeneratorRequestBuilder<'b> { pub struct CodeGeneratorRequestBuilder<'b> {
@@ -409,28 +469,41 @@ impl<'a> CodeGeneratorResponse<'a> {
let mut file_end = None; let mut file_end = None;
for item in accessor.fields() { for item in accessor.fields() {
let (offset, tag, _) = item?; let (offset, tag, _) = item?;
if tag.field_number == 1 { error_offset = Some(offset); } if tag.field_number == 1 {
if tag.field_number == 2 { supported_features_offset = Some(offset); } error_offset = Some(offset);
if tag.field_number == 3 { minimum_edition_offset = Some(offset); } }
if tag.field_number == 4 { maximum_edition_offset = Some(offset); } if tag.field_number == 2 {
supported_features_offset = Some(offset);
}
if tag.field_number == 3 {
minimum_edition_offset = Some(offset);
}
if tag.field_number == 4 {
maximum_edition_offset = Some(offset);
}
if tag.field_number == 15 { if tag.field_number == 15 {
if file_start.is_none() { file_start = Some(offset); } if file_start.is_none() {
file_start = Some(offset);
}
file_end = Some(offset); file_end = Some(offset);
} }
} }
Ok(Self { Ok(Self {
accessor, accessor,
error_offset, error_offset,
supported_features_offset, supported_features_offset,
minimum_edition_offset, minimum_edition_offset,
maximum_edition_offset, maximum_edition_offset,
file_start, file_end, file_start,
file_end,
}) })
} }
pub fn error(&self) -> crate::runtime::Result<&'a str> { pub fn error(&self) -> crate::runtime::Result<&'a str> {
let offset = self.error_offset.ok_or(crate::runtime::RotoError::FieldNotFound)?; let offset = self
.error_offset
.ok_or(crate::runtime::RotoError::FieldNotFound)?;
let (bytes, _) = self.accessor.get_value_at(offset)?; let (bytes, _) = self.accessor.get_value_at(offset)?;
str::from_utf8(bytes).map_err(|_| crate::runtime::RotoError::WireFormatViolation) str::from_utf8(bytes).map_err(|_| crate::runtime::RotoError::WireFormatViolation)
} }
@@ -439,43 +512,63 @@ file_start, file_end,
self.error().or(Ok("")) self.error().or(Ok(""))
} }
pub fn has_error(&self) -> bool { self.error_offset.is_some() } pub fn has_error(&self) -> bool {
self.error_offset.is_some()
}
pub fn supported_features(&self) -> crate::runtime::Result<u32> { pub fn supported_features(&self) -> crate::runtime::Result<u32> {
let offset = self.supported_features_offset.ok_or(crate::runtime::RotoError::FieldNotFound)?; let offset = self
.supported_features_offset
.ok_or(crate::runtime::RotoError::FieldNotFound)?;
let (bytes, _) = self.accessor.get_value_at(offset)?; let (bytes, _) = self.accessor.get_value_at(offset)?;
crate::runtime::read_varint(bytes).map(|(v, _)| v as u32).map_err(|_| crate::runtime::RotoError::WireFormatViolation) crate::runtime::read_varint(bytes)
.map(|(v, _)| v as u32)
.map_err(|_| crate::runtime::RotoError::WireFormatViolation)
} }
pub fn supported_features_or_default(&self) -> crate::runtime::Result<u32> { pub fn supported_features_or_default(&self) -> crate::runtime::Result<u32> {
self.supported_features().or(Ok(0)) self.supported_features().or(Ok(0))
} }
pub fn has_supported_features(&self) -> bool { self.supported_features_offset.is_some() } pub fn has_supported_features(&self) -> bool {
self.supported_features_offset.is_some()
}
pub fn minimum_edition(&self) -> crate::runtime::Result<i32> { pub fn minimum_edition(&self) -> crate::runtime::Result<i32> {
let offset = self.minimum_edition_offset.ok_or(crate::runtime::RotoError::FieldNotFound)?; let offset = self
.minimum_edition_offset
.ok_or(crate::runtime::RotoError::FieldNotFound)?;
let (bytes, _) = self.accessor.get_value_at(offset)?; let (bytes, _) = self.accessor.get_value_at(offset)?;
crate::runtime::read_varint(bytes).map(|(v, _)| v as i32).map_err(|_| crate::runtime::RotoError::WireFormatViolation) crate::runtime::read_varint(bytes)
.map(|(v, _)| v as i32)
.map_err(|_| crate::runtime::RotoError::WireFormatViolation)
} }
pub fn minimum_edition_or_default(&self) -> crate::runtime::Result<i32> { pub fn minimum_edition_or_default(&self) -> crate::runtime::Result<i32> {
self.minimum_edition().or(Ok(0)) self.minimum_edition().or(Ok(0))
} }
pub fn has_minimum_edition(&self) -> bool { self.minimum_edition_offset.is_some() } pub fn has_minimum_edition(&self) -> bool {
self.minimum_edition_offset.is_some()
}
pub fn maximum_edition(&self) -> crate::runtime::Result<i32> { pub fn maximum_edition(&self) -> crate::runtime::Result<i32> {
let offset = self.maximum_edition_offset.ok_or(crate::runtime::RotoError::FieldNotFound)?; let offset = self
.maximum_edition_offset
.ok_or(crate::runtime::RotoError::FieldNotFound)?;
let (bytes, _) = self.accessor.get_value_at(offset)?; let (bytes, _) = self.accessor.get_value_at(offset)?;
crate::runtime::read_varint(bytes).map(|(v, _)| v as i32).map_err(|_| crate::runtime::RotoError::WireFormatViolation) crate::runtime::read_varint(bytes)
.map(|(v, _)| v as i32)
.map_err(|_| crate::runtime::RotoError::WireFormatViolation)
} }
pub fn maximum_edition_or_default(&self) -> crate::runtime::Result<i32> { pub fn maximum_edition_or_default(&self) -> crate::runtime::Result<i32> {
self.maximum_edition().or(Ok(0)) self.maximum_edition().or(Ok(0))
} }
pub fn has_maximum_edition(&self) -> bool { self.maximum_edition_offset.is_some() } pub fn has_maximum_edition(&self) -> bool {
self.maximum_edition_offset.is_some()
}
pub fn file(&self) -> crate::runtime::RepeatedFieldIterator<'a> { pub fn file(&self) -> crate::runtime::RepeatedFieldIterator<'a> {
match (self.file_start, self.file_end) { match (self.file_start, self.file_end) {
@@ -487,7 +580,6 @@ file_start, file_end,
pub fn raw_fields(&self) -> crate::runtime::RawFieldIterator<'a> { pub fn raw_fields(&self) -> crate::runtime::RawFieldIterator<'a> {
self.accessor.raw_fields() self.accessor.raw_fields()
} }
} }
pub struct CodeGeneratorResponseBuilder<'b> { pub struct CodeGeneratorResponseBuilder<'b> {
@@ -586,15 +678,15 @@ impl crate::runtime::RotoMessage for OwnedCodeGeneratorResponse {
} }
pub mod code_generator_response { pub mod code_generator_response {
#[derive(Debug, Clone, Copy, PartialEq, Eq)] #[derive(Debug, Clone, Copy, PartialEq, Eq)]
#[repr(i32)] #[repr(i32)]
pub enum Feature { pub enum Feature {
FEATURENONE = 0, FEATURENONE = 0,
FEATUREPROTO3OPTIONAL = 1, FEATUREPROTO3OPTIONAL = 1,
FEATURESUPPORTSEDITIONS = 2, FEATURESUPPORTSEDITIONS = 2,
} }
impl Feature { impl Feature {
pub fn from_i32(value: i32) -> Self { pub fn from_i32(value: i32) -> Self {
match value { match value {
0 => Feature::FEATURENONE, 0 => Feature::FEATURENONE,
@@ -603,17 +695,17 @@ impl Feature {
_ => Feature::FEATURENONE, _ => Feature::FEATURENONE,
} }
} }
} }
pub struct File<'a> { pub struct File<'a> {
accessor: crate::runtime::ProtoAccessor<'a>, accessor: crate::runtime::ProtoAccessor<'a>,
name_offset: Option<usize>, name_offset: Option<usize>,
insertion_point_offset: Option<usize>, insertion_point_offset: Option<usize>,
content_offset: Option<usize>, content_offset: Option<usize>,
generated_code_info_offset: Option<usize>, generated_code_info_offset: Option<usize>,
} }
impl<'a> File<'a> { impl<'a> File<'a> {
pub fn new(data: &'a [u8]) -> crate::runtime::Result<Self> { pub fn new(data: &'a [u8]) -> crate::runtime::Result<Self> {
let accessor = crate::runtime::ProtoAccessor::new(data)?; let accessor = crate::runtime::ProtoAccessor::new(data)?;
let mut name_offset = None; let mut name_offset = None;
@@ -622,23 +714,33 @@ impl<'a> File<'a> {
let mut generated_code_info_offset = None; let mut generated_code_info_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 { name_offset = Some(offset); } if tag.field_number == 1 {
if tag.field_number == 2 { insertion_point_offset = Some(offset); } name_offset = Some(offset);
if tag.field_number == 15 { content_offset = Some(offset); } }
if tag.field_number == 16 { generated_code_info_offset = Some(offset); } if tag.field_number == 2 {
insertion_point_offset = Some(offset);
}
if tag.field_number == 15 {
content_offset = Some(offset);
}
if tag.field_number == 16 {
generated_code_info_offset = Some(offset);
}
} }
Ok(Self { Ok(Self {
accessor, accessor,
name_offset, name_offset,
insertion_point_offset, insertion_point_offset,
content_offset, content_offset,
generated_code_info_offset, generated_code_info_offset,
}) })
} }
pub fn name(&self) -> crate::runtime::Result<&'a str> { pub fn name(&self) -> crate::runtime::Result<&'a str> {
let offset = self.name_offset.ok_or(crate::runtime::RotoError::FieldNotFound)?; let offset = self
.name_offset
.ok_or(crate::runtime::RotoError::FieldNotFound)?;
let (bytes, _) = self.accessor.get_value_at(offset)?; let (bytes, _) = self.accessor.get_value_at(offset)?;
str::from_utf8(bytes).map_err(|_| crate::runtime::RotoError::WireFormatViolation) str::from_utf8(bytes).map_err(|_| crate::runtime::RotoError::WireFormatViolation)
} }
@@ -647,10 +749,14 @@ generated_code_info_offset,
self.name().or(Ok("")) 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 insertion_point(&self) -> crate::runtime::Result<&'a str> { pub fn insertion_point(&self) -> crate::runtime::Result<&'a str> {
let offset = self.insertion_point_offset.ok_or(crate::runtime::RotoError::FieldNotFound)?; let offset = self
.insertion_point_offset
.ok_or(crate::runtime::RotoError::FieldNotFound)?;
let (bytes, _) = self.accessor.get_value_at(offset)?; let (bytes, _) = self.accessor.get_value_at(offset)?;
str::from_utf8(bytes).map_err(|_| crate::runtime::RotoError::WireFormatViolation) str::from_utf8(bytes).map_err(|_| crate::runtime::RotoError::WireFormatViolation)
} }
@@ -659,10 +765,14 @@ generated_code_info_offset,
self.insertion_point().or(Ok("")) self.insertion_point().or(Ok(""))
} }
pub fn has_insertion_point(&self) -> bool { self.insertion_point_offset.is_some() } pub fn has_insertion_point(&self) -> bool {
self.insertion_point_offset.is_some()
}
pub fn content(&self) -> crate::runtime::Result<&'a str> { pub fn content(&self) -> crate::runtime::Result<&'a str> {
let offset = self.content_offset.ok_or(crate::runtime::RotoError::FieldNotFound)?; let offset = self
.content_offset
.ok_or(crate::runtime::RotoError::FieldNotFound)?;
let (bytes, _) = self.accessor.get_value_at(offset)?; let (bytes, _) = self.accessor.get_value_at(offset)?;
str::from_utf8(bytes).map_err(|_| crate::runtime::RotoError::WireFormatViolation) str::from_utf8(bytes).map_err(|_| crate::runtime::RotoError::WireFormatViolation)
} }
@@ -671,10 +781,14 @@ generated_code_info_offset,
self.content().or(Ok("")) self.content().or(Ok(""))
} }
pub fn has_content(&self) -> bool { self.content_offset.is_some() } pub fn has_content(&self) -> bool {
self.content_offset.is_some()
}
pub fn generated_code_info(&self) -> crate::runtime::Result<&'a [u8]> { pub fn generated_code_info(&self) -> crate::runtime::Result<&'a [u8]> {
let offset = self.generated_code_info_offset.ok_or(crate::runtime::RotoError::FieldNotFound)?; let offset = self
.generated_code_info_offset
.ok_or(crate::runtime::RotoError::FieldNotFound)?;
let (bytes, _) = self.accessor.get_value_at(offset)?; let (bytes, _) = self.accessor.get_value_at(offset)?;
Ok(bytes) Ok(bytes)
} }
@@ -683,23 +797,24 @@ generated_code_info_offset,
self.generated_code_info().or(Ok(&[])) self.generated_code_info().or(Ok(&[]))
} }
pub fn has_generated_code_info(&self) -> bool { self.generated_code_info_offset.is_some() } pub fn has_generated_code_info(&self) -> bool {
self.generated_code_info_offset.is_some()
}
pub fn raw_fields(&self) -> crate::runtime::RawFieldIterator<'a> { pub fn raw_fields(&self) -> crate::runtime::RawFieldIterator<'a> {
self.accessor.raw_fields() self.accessor.raw_fields()
} }
}
} pub struct FileBuilder<'b> {
pub struct FileBuilder<'b> {
builder: crate::runtime::ProtoBuilder<'b>, builder: crate::runtime::ProtoBuilder<'b>,
name_written: bool, name_written: bool,
insertion_point_written: bool, insertion_point_written: bool,
content_written: bool, content_written: bool,
generated_code_info_written: bool, generated_code_info_written: bool,
} }
impl<'b> FileBuilder<'b> { impl<'b> FileBuilder<'b> {
pub fn builder(buf: &mut [u8]) -> FileBuilder<'_> { pub fn builder(buf: &mut [u8]) -> FileBuilder<'_> {
FileBuilder { FileBuilder {
builder: crate::runtime::ProtoBuilder::new(buf), builder: crate::runtime::ProtoBuilder::new(buf),
@@ -754,20 +869,20 @@ impl<'b> FileBuilder<'b> {
pub fn finish(self) -> crate::runtime::Result<&'b mut [u8]> { pub fn finish(self) -> crate::runtime::Result<&'b mut [u8]> {
self.builder.finish() self.builder.finish()
} }
} }
pub struct OwnedFile { pub struct OwnedFile {
pub data: bytes::Bytes, pub data: bytes::Bytes,
} }
impl crate::runtime::RotoOwned for OwnedFile { impl crate::runtime::RotoOwned for OwnedFile {
type Reader<'a> = File<'a>; type Reader<'a> = File<'a>;
fn reader(&self) -> File<'_> { fn reader(&self) -> File<'_> {
File::new(&self.data).expect("failed to create reader") File::new(&self.data).expect("failed to create reader")
} }
} }
impl crate::runtime::RotoMessage for OwnedFile { impl crate::runtime::RotoMessage for OwnedFile {
fn decode(buf: bytes::Bytes) -> crate::runtime::Result<Self> { fn decode(buf: bytes::Bytes) -> crate::runtime::Result<Self> {
Ok(OwnedFile { data: buf }) Ok(OwnedFile { data: buf })
} }
@@ -775,7 +890,5 @@ impl crate::runtime::RotoMessage for OwnedFile {
fn bytes(&self) -> bytes::Bytes { fn bytes(&self) -> bytes::Bytes {
self.data.clone() self.data.clone()
} }
}
} }
}
File diff suppressed because it is too large Load Diff
+18 -6
View File
@@ -1,12 +1,19 @@
use tonic::Request; use hello::{OwnedHelloRequest, OwnedHelloResponse};
use roto_tonic::RotoCodec;
use hello::{HelloWorldService, OwnedHelloRequest, OwnedHelloResponse};
use roto_runtime::RotoOwned; use roto_runtime::RotoOwned;
use roto_tonic::RotoCodec;
use std::task::{Context, Poll}; use std::task::{Context, Poll};
use tonic::Request;
use tower::Service; use tower::Service;
pub use roto_tonic::{BufferPool, StatusBody}; pub use roto_tonic::{BufferPool, StatusBody};
#[allow(
unused,
unused_imports,
unused_assignments,
unused_variables,
non_camel_case_types
)]
pub mod hello { pub mod hello {
include!(concat!(env!("OUT_DIR"), "/hello.rs")); include!(concat!(env!("OUT_DIR"), "/hello.rs"));
} }
@@ -45,8 +52,10 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
// We need to specify the method path. For HelloWorldService/HelloWorld, it is "/hello.HelloWorldService/HelloWorld" // We need to specify the method path. For HelloWorldService/HelloWorld, it is "/hello.HelloWorldService/HelloWorld"
let mut buf = vec![0u8; 1024]; let mut buf = vec![0u8; 1024];
let slice = hello::HelloRequestBuilder::builder(&mut buf) let slice = hello::HelloRequestBuilder::builder(&mut buf)
.name("Roto").unwrap() .name("Roto")
.finish().unwrap(); .unwrap()
.finish()
.unwrap();
let request = OwnedHelloRequest { let request = OwnedHelloRequest {
data: bytes::Bytes::copy_from_slice(slice), data: bytes::Bytes::copy_from_slice(slice),
@@ -63,7 +72,10 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
let response_msg: OwnedHelloResponse = response.into_inner(); let response_msg: OwnedHelloResponse = response.into_inner();
let reader = response_msg.reader(); let reader = response_msg.reader();
println!("Server responded: {}", reader.message().unwrap_or("No message")); println!(
"Server responded: {}",
reader.message().unwrap_or("No message")
);
Ok(()) Ok(())
} }
+44 -20
View File
@@ -1,20 +1,24 @@
use std::pin::Pin; use bytes::{BufMut, Bytes};
use std::future::Future;
use std::task::{Context, Poll};
use std::sync::{Arc, Mutex};
use tonic::{transport::Server, Request, Response, Status};
use roto_tonic::RotoCodec;
use hello::{HelloWorldService, OwnedHelloRequest, OwnedHelloResponse}; use hello::{HelloWorldService, OwnedHelloRequest, OwnedHelloResponse};
use tower::Service;
use bytes::{Bytes, BytesMut, Buf, BufMut};
use tonic::body::BoxBody;
use futures_util::StreamExt;
use roto_runtime::{RotoOwned, RotoMessage};
use http_body_util::BodyExt; use http_body_util::BodyExt;
use http_body::Body; use roto_runtime::{RotoMessage, RotoOwned};
use std::future::Future;
use std::pin::Pin;
use std::sync::Arc;
use std::task::{Context, Poll};
use tonic::body::BoxBody;
use tonic::{Request, Response, Status, transport::Server};
use tower::Service;
pub use roto_tonic::{BufferPool, StatusBody}; pub use roto_tonic::{BufferPool, StatusBody};
#[allow(
unused,
unused_imports,
unused_assignments,
unused_variables,
non_camel_case_types
)]
pub mod hello { pub mod hello {
include!(concat!(env!("OUT_DIR"), "/hello.rs")); include!(concat!(env!("OUT_DIR"), "/hello.rs"));
} }
@@ -43,8 +47,10 @@ impl HelloWorldService for MyHelloWorld {
let mut buf = self.pool.get(); let mut buf = self.pool.get();
buf.resize(1024, 0); buf.resize(1024, 0);
let slice = hello::HelloResponseBuilder::builder(&mut buf[..]) let slice = hello::HelloResponseBuilder::builder(&mut buf[..])
.message(&format!("Hello {}!", name)).unwrap() .message(&format!("Hello {}!", name))
.finish().unwrap(); .unwrap()
.finish()
.unwrap();
let res_len = slice.len(); let res_len = slice.len();
let response_bytes = buf.split_to(res_len).freeze(); let response_bytes = buf.split_to(res_len).freeze();
@@ -68,7 +74,10 @@ pub struct HelloWorldServer {
impl HelloWorldServer { impl HelloWorldServer {
pub fn new(inner: MyHelloWorld, pool: Arc<BufferPool>) -> Self { pub fn new(inner: MyHelloWorld, pool: Arc<BufferPool>) -> Self {
Self { inner: Arc::new(inner), pool } Self {
inner: Arc::new(inner),
pool,
}
} }
} }
@@ -111,7 +120,10 @@ impl Service<http::Request<BoxBody>> for HelloWorldServer {
if bytes_vec.len() < 5 { if bytes_vec.len() < 5 {
println!("Body too short: {} bytes", bytes_vec.len()); println!("Body too short: {} bytes", bytes_vec.len());
let res_body = BoxBody::new(StatusBody::new(Some(Bytes::from_static(&[0, 0, 0, 0, 0])), 0)); let res_body = BoxBody::new(StatusBody::new(
Some(Bytes::from_static(&[0, 0, 0, 0, 0])),
0,
));
return Ok(http::Response::builder() return Ok(http::Response::builder()
.status(200) .status(200)
.body(res_body) .body(res_body)
@@ -123,8 +135,14 @@ impl Service<http::Request<BoxBody>> for HelloWorldServer {
Ok(msg) => msg, Ok(msg) => msg,
Err(e) => { Err(e) => {
println!("Decode error: {}", e); println!("Decode error: {}", 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());
} }
}; };
@@ -133,8 +151,14 @@ impl Service<http::Request<BoxBody>> for HelloWorldServer {
Ok(res) => res, Ok(res) => res,
Err(e) => { Err(e) => {
println!("Service error: {}", e); println!("Service error: {}", 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());
} }
}; };
+239 -114
View File
@@ -1,22 +1,29 @@
// @generated by protoc-gen-roto — do not edit // @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 crate::{BufferPool, StatusBody};
use std::str; use bytes::{Buf, BufMut, Bytes, BytesMut};
use bytes::{Bytes, BytesMut, Buf, BufMut}; use futures_util::StreamExt;
use tonic::{Request, Response, Status}; use http_body::Body;
use tokio_stream::Stream; 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::pin::Pin;
use std::str;
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;
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};
pub struct Hello<'a> { pub struct Hello<'a> {
accessor: roto_runtime::ProtoAccessor<'a>, accessor: roto_runtime::ProtoAccessor<'a>,
@@ -47,36 +54,57 @@ impl<'a> Hello<'a> {
let mut pets_end = None; let mut pets_end = None;
for item in accessor.fields() { for item in accessor.fields() {
let (offset, tag, _) = item?; let (offset, tag, _) = item?;
if tag.field_number == 1 { name_offset = Some(offset); } if tag.field_number == 1 {
if tag.field_number == 2 { d_offset = Some(offset); } name_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 == 2 {
if tag.field_number == 5 { n_offset = Some(offset); } d_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 == 3 {
if tag.field_number == 8 { c2_offset = Some(offset); } 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 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); pets_end = Some(offset);
} }
} }
Ok(Self { Ok(Self {
accessor, accessor,
name_offset, name_offset,
d_offset, d_offset,
f_offset, f_offset,
b_offset, b_offset,
n_offset, n_offset,
l_offset, l_offset,
c1_offset, c1_offset,
c2_offset, c2_offset,
pets_start, pets_end, pets_start,
pets_end,
}) })
} }
pub fn name(&self) -> roto_runtime::Result<&'a str> { 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)?; let (bytes, _) = self.accessor.get_value_at(offset)?;
std::str::from_utf8(bytes).map_err(|_| roto_runtime::RotoError::WireFormatViolation) std::str::from_utf8(bytes).map_err(|_| roto_runtime::RotoError::WireFormatViolation)
} }
@@ -85,70 +113,104 @@ pets_start, pets_end,
self.name().or(Ok("")) 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> { 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)?; 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> { pub fn d_or_default(&self) -> roto_runtime::Result<f64> {
self.d().or(Ok(0.0)) 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> { 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)?; 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> { pub fn f_or_default(&self) -> roto_runtime::Result<f32> {
self.f().or(Ok(0.0)) 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> { 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)?; 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> { pub fn b_or_default(&self) -> roto_runtime::Result<bool> {
self.b().or(Ok(false)) 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> { 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)?; 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> { pub fn n_or_default(&self) -> roto_runtime::Result<i32> {
self.n().or(Ok(0)) 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> { 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)?; 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> { pub fn l_or_default(&self) -> roto_runtime::Result<i32> {
self.l().or(Ok(0)) 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> { 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)?; let (bytes, _) = self.accessor.get_value_at(offset)?;
std::str::from_utf8(bytes).map_err(|_| roto_runtime::RotoError::WireFormatViolation) std::str::from_utf8(bytes).map_err(|_| roto_runtime::RotoError::WireFormatViolation)
} }
@@ -157,19 +219,27 @@ pets_start, pets_end,
self.c1().or(Ok("")) 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> { 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)?; 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> { pub fn c2_or_default(&self) -> roto_runtime::Result<bool> {
self.c2().or(Ok(false)) 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> { pub fn pets(&self) -> roto_runtime::RepeatedFieldIterator<'a> {
match (self.pets_start, self.pets_end) { 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() { 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() { if self.c2_offset.is_some() {
return Ok(Some(hello::Choice::c2 (self.c2()?))); return Ok(Some(hello::Choice::c2(self.c2()?)));
} }
Ok(None) Ok(None)
} }
@@ -191,7 +261,6 @@ pets_start, pets_end,
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 HelloBuilder<'b> { pub struct HelloBuilder<'b> {
@@ -326,32 +395,38 @@ impl roto_runtime::RotoMessage for OwnedHello {
} }
pub mod hello { pub mod hello {
pub struct Pet<'a> { pub struct Pet<'a> {
accessor: roto_runtime::ProtoAccessor<'a>, accessor: roto_runtime::ProtoAccessor<'a>,
name_offset: Option<usize>, name_offset: Option<usize>,
color_offset: Option<usize>, color_offset: Option<usize>,
} }
impl<'a> Pet<'a> { impl<'a> Pet<'a> {
pub fn new(data: &'a [u8]) -> roto_runtime::Result<Self> { pub fn new(data: &'a [u8]) -> roto_runtime::Result<Self> {
let accessor = roto_runtime::ProtoAccessor::new(data)?; let accessor = roto_runtime::ProtoAccessor::new(data)?;
let mut name_offset = None; let mut name_offset = None;
let mut color_offset = None; let mut color_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 { name_offset = Some(offset); } if tag.field_number == 1 {
if tag.field_number == 2 { color_offset = Some(offset); } name_offset = Some(offset);
}
if tag.field_number == 2 {
color_offset = Some(offset);
}
} }
Ok(Self { Ok(Self {
accessor, accessor,
name_offset, name_offset,
color_offset, color_offset,
}) })
} }
pub fn name(&self) -> roto_runtime::Result<&'a str> { 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)?; let (bytes, _) = self.accessor.get_value_at(offset)?;
std::str::from_utf8(bytes).map_err(|_| roto_runtime::RotoError::WireFormatViolation) std::str::from_utf8(bytes).map_err(|_| roto_runtime::RotoError::WireFormatViolation)
} }
@@ -360,33 +435,40 @@ color_offset,
self.name().or(Ok("")) 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> { pub fn color(&self) -> roto_runtime::Result<u64> {
let offset = self.color_offset.ok_or(roto_runtime::RotoError::FieldNotFound)?; let offset = self
.color_offset
.ok_or(roto_runtime::RotoError::FieldNotFound)?;
let (bytes, _) = self.accessor.get_value_at(offset)?; let (bytes, _) = self.accessor.get_value_at(offset)?;
roto_runtime::read_varint(bytes).map(|(v, _)| v as u64).map_err(|_| roto_runtime::RotoError::WireFormatViolation) 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> { pub fn color_or_default(&self) -> roto_runtime::Result<u64> {
self.color().or(Ok(0)) 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> { pub fn raw_fields(&self) -> roto_runtime::RawFieldIterator<'a> {
self.accessor.raw_fields() self.accessor.raw_fields()
} }
}
} pub struct PetBuilder<'b> {
pub struct PetBuilder<'b> {
builder: roto_runtime::ProtoBuilder<'b>, builder: roto_runtime::ProtoBuilder<'b>,
name_written: bool, name_written: bool,
color_written: bool, color_written: bool,
} }
impl<'b> PetBuilder<'b> { impl<'b> PetBuilder<'b> {
pub fn builder(buf: &mut [u8]) -> PetBuilder<'_> { pub fn builder(buf: &mut [u8]) -> PetBuilder<'_> {
PetBuilder { PetBuilder {
builder: roto_runtime::ProtoBuilder::new(buf), builder: roto_runtime::ProtoBuilder::new(buf),
@@ -425,20 +507,20 @@ impl<'b> PetBuilder<'b> {
pub fn finish(self) -> roto_runtime::Result<&'b mut [u8]> { pub fn finish(self) -> roto_runtime::Result<&'b mut [u8]> {
self.builder.finish() self.builder.finish()
} }
} }
pub struct OwnedPet { pub struct OwnedPet {
pub data: bytes::Bytes, pub data: bytes::Bytes,
} }
impl roto_runtime::RotoOwned for OwnedPet { impl roto_runtime::RotoOwned for OwnedPet {
type Reader<'a> = Pet<'a>; type Reader<'a> = Pet<'a>;
fn reader(&self) -> Pet<'_> { fn reader(&self) -> Pet<'_> {
Pet::new(&self.data).expect("failed to create reader") Pet::new(&self.data).expect("failed to create reader")
} }
} }
impl roto_runtime::RotoMessage for OwnedPet { impl roto_runtime::RotoMessage for OwnedPet {
fn decode(buf: bytes::Bytes) -> roto_runtime::Result<Self> { fn decode(buf: bytes::Bytes) -> roto_runtime::Result<Self> {
Ok(OwnedPet { data: buf }) Ok(OwnedPet { data: buf })
} }
@@ -446,21 +528,21 @@ impl roto_runtime::RotoMessage for OwnedPet {
fn bytes(&self) -> bytes::Bytes { fn bytes(&self) -> bytes::Bytes {
self.data.clone() self.data.clone()
} }
} }
pub mod pet { pub mod pet {
#[derive(Debug, Clone, Copy, PartialEq, Eq)] #[derive(Debug, Clone, Copy, PartialEq, Eq)]
#[repr(i32)] #[repr(i32)]
pub enum Color { pub enum Color {
BLACK = 0, BLACK = 0,
WHITE = 1, WHITE = 1,
BLUE = 2, BLUE = 2,
RED = 3, RED = 3,
YELLOW = 4, YELLOW = 4,
GREEN = 5, GREEN = 5,
} }
impl Color { impl Color {
pub fn from_i32(value: i32) -> Self { pub fn from_i32(value: i32) -> Self {
match value { match value {
0 => Color::BLACK, 0 => Color::BLACK,
@@ -472,15 +554,13 @@ impl Color {
_ => Color::BLACK, _ => Color::BLACK,
} }
} }
} }
}
} pub enum Choice<'a> {
pub enum Choice<'a> {
c1(&'a str), c1(&'a str),
c2(bool), c2(bool),
} }
} }
pub struct HelloRequest<'a> { pub struct HelloRequest<'a> {
@@ -494,17 +574,21 @@ impl<'a> HelloRequest<'a> {
let mut request_offset = None; let mut request_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 { request_offset = Some(offset); } if tag.field_number == 1 {
request_offset = Some(offset);
}
} }
Ok(Self { Ok(Self {
accessor, accessor,
request_offset, request_offset,
}) })
} }
pub fn request(&self) -> roto_runtime::Result<&'a [u8]> { 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)?; let (bytes, _) = self.accessor.get_value_at(offset)?;
Ok(bytes) Ok(bytes)
} }
@@ -513,12 +597,13 @@ request_offset,
self.request().or(Ok(&[])) 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> { pub fn raw_fields(&self) -> roto_runtime::RawFieldIterator<'a> {
self.accessor.raw_fields() self.accessor.raw_fields()
} }
} }
pub struct HelloRequestBuilder<'b> { pub struct HelloRequestBuilder<'b> {
@@ -591,17 +676,21 @@ impl<'a> HelloReply<'a> {
let mut response_offset = None; let mut response_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 { response_offset = Some(offset); } if tag.field_number == 1 {
response_offset = Some(offset);
}
} }
Ok(Self { Ok(Self {
accessor, accessor,
response_offset, response_offset,
}) })
} }
pub fn response(&self) -> roto_runtime::Result<&'a [u8]> { 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)?; let (bytes, _) = self.accessor.get_value_at(offset)?;
Ok(bytes) Ok(bytes)
} }
@@ -610,12 +699,13 @@ response_offset,
self.response().or(Ok(&[])) 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> { pub fn raw_fields(&self) -> roto_runtime::RawFieldIterator<'a> {
self.accessor.raw_fields() self.accessor.raw_fields()
} }
} }
pub struct HelloReplyBuilder<'b> { pub struct HelloReplyBuilder<'b> {
@@ -679,7 +769,10 @@ impl roto_runtime::RotoMessage for OwnedHelloReply {
#[tonic::async_trait] #[tonic::async_trait]
pub trait Greeter: Send + Sync + 'static { 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)] #[derive(Clone)]
@@ -701,7 +794,8 @@ impl tonic::server::NamedService for GreeterServer {
impl Service<http::Request<BoxBody>> for GreeterServer { impl Service<http::Request<BoxBody>> for GreeterServer {
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(()))
@@ -726,8 +820,14 @@ impl Service<http::Request<BoxBody>> for GreeterServer {
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..);
@@ -737,16 +837,28 @@ impl Service<http::Request<BoxBody>> for GreeterServer {
let request_msg = match OwnedHelloRequest::decode(payload) { let request_msg = match OwnedHelloRequest::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.say_hello(Request::new(request_msg)).await { let response = match inner.say_hello(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());
} }
}; };
@@ -762,13 +874,26 @@ impl Service<http::Request<BoxBody>> for GreeterServer {
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 !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())
}) })
} }
} }
+5 -4
View File
@@ -1,5 +1,5 @@
// @generated by protoc-gen-roto — do not edit // @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 roto_runtime::{ProtoAccessor, ProtoBuilder, Result, RotoError, read_varint, RepeatedFieldIterator, RotoMessage};
use core::str; use core::str;
use bytes::{Bytes, BytesMut, Buf, BufMut}; 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 tonic::{Request, Response, Status};
use tokio_stream::Stream; use tokio_stream::Stream;
use std::pin::Pin; use std::pin::Pin;
@@ -462,12 +463,12 @@ impl Service<http::Request<BoxBody>> for InteropServiceServer {
} }
let payload = bytes_vec.slice(5..); let payload = bytes_vec.slice(5..);
#[allow(unused_assignments)]
let mut routed = false; let mut routed = false;
if path == "/interop.InteropService/UnaryCall" { if path == "/interop.InteropService/UnaryCall" {
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(Some(Bytes::from_static(&[0, 0, 0, 0, 0])), 0));
return Ok(http::Response::builder().status(200).body(res_body).unwrap()); 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 { 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(Some(Bytes::from_static(&[0, 0, 0, 0, 0])), 0));
return Ok(http::Response::builder().status(200).body(res_body).unwrap()); return Ok(http::Response::builder().status(200).body(res_body).unwrap());
} }