Regenerate protobuf files
This commit is contained in:
@@ -1,13 +1,13 @@
|
||||
// @generated by protoc-gen-roto — do not edit
|
||||
#![allow(unused_imports)]
|
||||
|
||||
use crate::{ProtoAccessor, ProtoBuilder, Result, RotoError, read_varint, RepeatedFieldIterator};
|
||||
use std::str;
|
||||
|
||||
#[allow(unused_imports)]
|
||||
use roto_runtime::{ProtoAccessor, ProtoBuilder, Result, RotoError, read_varint, RepeatedFieldIterator, RotoMessage};
|
||||
use core::str;
|
||||
#[cfg(feature = "alloc")]
|
||||
use bytes::{Bytes, BytesMut, Buf, BufMut};
|
||||
use crate::google::protobuf::descriptor;
|
||||
|
||||
pub struct Version<'a> {
|
||||
accessor: crate::ProtoAccessor<'a>,
|
||||
accessor: roto_runtime::ProtoAccessor<'a>,
|
||||
major_offset: Option<usize>,
|
||||
minor_offset: Option<usize>,
|
||||
patch_offset: Option<usize>,
|
||||
@@ -15,8 +15,8 @@ pub struct Version<'a> {
|
||||
}
|
||||
|
||||
impl<'a> Version<'a> {
|
||||
pub fn new(data: &'a [u8]) -> crate::Result<Self> {
|
||||
let accessor = crate::ProtoAccessor::new(data)?;
|
||||
pub fn new(data: &'a [u8]) -> roto_runtime::Result<Self> {
|
||||
let accessor = roto_runtime::ProtoAccessor::new(data)?;
|
||||
let mut major_offset = None;
|
||||
let mut minor_offset = None;
|
||||
let mut patch_offset = None;
|
||||
@@ -38,38 +38,62 @@ suffix_offset,
|
||||
})
|
||||
}
|
||||
|
||||
pub fn major(&self) -> crate::Result<i32> {
|
||||
let offset = self.major_offset.ok_or(crate::RotoError::FieldNotFound)?;
|
||||
pub fn major(&self) -> roto_runtime::Result<i32> {
|
||||
let offset = self.major_offset.ok_or(roto_runtime::RotoError::FieldNotFound)?;
|
||||
let (bytes, _) = self.accessor.get_value_at(offset)?;
|
||||
crate::read_varint(bytes).map(|(v, _)| v as i32).map_err(|_| crate::RotoError::WireFormatViolation)
|
||||
roto_runtime::read_varint(bytes).map(|(v, _)| v as i32).map_err(|_| roto_runtime::RotoError::WireFormatViolation)
|
||||
}
|
||||
|
||||
pub fn minor(&self) -> crate::Result<i32> {
|
||||
let offset = self.minor_offset.ok_or(crate::RotoError::FieldNotFound)?;
|
||||
let (bytes, _) = self.accessor.get_value_at(offset)?;
|
||||
crate::read_varint(bytes).map(|(v, _)| v as i32).map_err(|_| crate::RotoError::WireFormatViolation)
|
||||
pub fn major_or_default(&self) -> roto_runtime::Result<i32> {
|
||||
self.major().or(Ok(0))
|
||||
}
|
||||
|
||||
pub fn patch(&self) -> crate::Result<i32> {
|
||||
let offset = self.patch_offset.ok_or(crate::RotoError::FieldNotFound)?;
|
||||
pub fn has_major(&self) -> bool { self.major_offset.is_some() }
|
||||
|
||||
pub fn minor(&self) -> roto_runtime::Result<i32> {
|
||||
let offset = self.minor_offset.ok_or(roto_runtime::RotoError::FieldNotFound)?;
|
||||
let (bytes, _) = self.accessor.get_value_at(offset)?;
|
||||
crate::read_varint(bytes).map(|(v, _)| v as i32).map_err(|_| crate::RotoError::WireFormatViolation)
|
||||
roto_runtime::read_varint(bytes).map(|(v, _)| v as i32).map_err(|_| roto_runtime::RotoError::WireFormatViolation)
|
||||
}
|
||||
|
||||
pub fn suffix(&self) -> crate::Result<&'a str> {
|
||||
let offset = self.suffix_offset.ok_or(crate::RotoError::FieldNotFound)?;
|
||||
let (bytes, _) = self.accessor.get_value_at(offset)?;
|
||||
str::from_utf8(bytes).map_err(|_| crate::RotoError::WireFormatViolation)
|
||||
pub fn minor_or_default(&self) -> roto_runtime::Result<i32> {
|
||||
self.minor().or(Ok(0))
|
||||
}
|
||||
|
||||
pub fn raw_fields(&self) -> crate::RawFieldIterator<'a> {
|
||||
pub fn has_minor(&self) -> bool { self.minor_offset.is_some() }
|
||||
|
||||
pub fn patch(&self) -> roto_runtime::Result<i32> {
|
||||
let offset = self.patch_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)
|
||||
}
|
||||
|
||||
pub fn patch_or_default(&self) -> roto_runtime::Result<i32> {
|
||||
self.patch().or(Ok(0))
|
||||
}
|
||||
|
||||
pub fn has_patch(&self) -> bool { self.patch_offset.is_some() }
|
||||
|
||||
pub fn suffix(&self) -> roto_runtime::Result<&'a str> {
|
||||
let offset = self.suffix_offset.ok_or(roto_runtime::RotoError::FieldNotFound)?;
|
||||
let (bytes, _) = self.accessor.get_value_at(offset)?;
|
||||
core::str::from_utf8(bytes).map_err(|_| roto_runtime::RotoError::WireFormatViolation)
|
||||
}
|
||||
|
||||
pub fn suffix_or_default(&self) -> roto_runtime::Result<&'a str> {
|
||||
self.suffix().or(Ok(""))
|
||||
}
|
||||
|
||||
pub fn has_suffix(&self) -> bool { self.suffix_offset.is_some() }
|
||||
|
||||
pub fn raw_fields(&self) -> roto_runtime::RawFieldIterator<'a> {
|
||||
self.accessor.raw_fields()
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
pub struct VersionBuilder<'b> {
|
||||
builder: crate::ProtoBuilder<'b>,
|
||||
builder: roto_runtime::ProtoBuilder<'b>,
|
||||
major_written: bool,
|
||||
minor_written: bool,
|
||||
patch_written: bool,
|
||||
@@ -79,7 +103,7 @@ pub struct VersionBuilder<'b> {
|
||||
impl<'b> VersionBuilder<'b> {
|
||||
pub fn builder(buf: &mut [u8]) -> VersionBuilder<'_> {
|
||||
VersionBuilder {
|
||||
builder: crate::ProtoBuilder::new(buf),
|
||||
builder: roto_runtime::ProtoBuilder::new(buf),
|
||||
major_written: false,
|
||||
minor_written: false,
|
||||
patch_written: false,
|
||||
@@ -87,32 +111,32 @@ impl<'b> VersionBuilder<'b> {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn major(mut self, value: i32) -> crate::Result<Self> {
|
||||
pub fn major(mut self, value: i32) -> roto_runtime::Result<Self> {
|
||||
self.builder.write_int32(1, value)?;
|
||||
self.major_written = true;
|
||||
Ok(self)
|
||||
}
|
||||
|
||||
pub fn minor(mut self, value: i32) -> crate::Result<Self> {
|
||||
pub fn minor(mut self, value: i32) -> roto_runtime::Result<Self> {
|
||||
self.builder.write_int32(2, value)?;
|
||||
self.minor_written = true;
|
||||
Ok(self)
|
||||
}
|
||||
|
||||
pub fn patch(mut self, value: i32) -> crate::Result<Self> {
|
||||
pub fn patch(mut self, value: i32) -> roto_runtime::Result<Self> {
|
||||
self.builder.write_int32(3, value)?;
|
||||
self.patch_written = true;
|
||||
Ok(self)
|
||||
}
|
||||
|
||||
pub fn suffix(mut self, value: &str) -> crate::Result<Self> {
|
||||
pub fn suffix(mut self, value: &str) -> roto_runtime::Result<Self> {
|
||||
self.builder.write_string(4, value)?;
|
||||
self.suffix_written = true;
|
||||
Ok(self)
|
||||
}
|
||||
|
||||
pub fn with(mut self, msg: &Version<'_>) -> crate::Result<Self> {
|
||||
for item in msg.raw_fields() {
|
||||
pub fn with(mut self, msg: &Version<'_>) -> 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.major_written,
|
||||
@@ -128,13 +152,37 @@ impl<'b> VersionBuilder<'b> {
|
||||
Ok(self)
|
||||
}
|
||||
|
||||
pub fn finish(self) -> crate::Result<&'b mut [u8]> {
|
||||
pub fn finish(self) -> roto_runtime::Result<&'b mut [u8]> {
|
||||
self.builder.finish()
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(feature = "alloc")]
|
||||
pub struct OwnedVersion {
|
||||
pub data: bytes::Bytes,
|
||||
}
|
||||
|
||||
#[cfg(feature = "alloc")]
|
||||
impl roto_runtime::RotoOwned for OwnedVersion {
|
||||
type Reader<'a> = Version<'a>;
|
||||
fn reader(&self) -> Version<'_> {
|
||||
Version::new(&self.data).expect("failed to create reader")
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(feature = "alloc")]
|
||||
impl roto_runtime::RotoMessage for OwnedVersion {
|
||||
fn decode(buf: bytes::Bytes) -> roto_runtime::Result<Self> {
|
||||
Ok(OwnedVersion { data: buf })
|
||||
}
|
||||
|
||||
fn bytes(&self) -> bytes::Bytes {
|
||||
self.data.clone()
|
||||
}
|
||||
}
|
||||
|
||||
pub struct CodeGeneratorRequest<'a> {
|
||||
accessor: crate::ProtoAccessor<'a>,
|
||||
accessor: roto_runtime::ProtoAccessor<'a>,
|
||||
file_to_generate_start: Option<usize>,
|
||||
file_to_generate_end: Option<usize>,
|
||||
parameter_offset: Option<usize>,
|
||||
@@ -146,8 +194,8 @@ pub struct CodeGeneratorRequest<'a> {
|
||||
}
|
||||
|
||||
impl<'a> CodeGeneratorRequest<'a> {
|
||||
pub fn new(data: &'a [u8]) -> crate::Result<Self> {
|
||||
let accessor = crate::ProtoAccessor::new(data)?;
|
||||
pub fn new(data: &'a [u8]) -> roto_runtime::Result<Self> {
|
||||
let accessor = roto_runtime::ProtoAccessor::new(data)?;
|
||||
let mut file_to_generate_start = None;
|
||||
let mut file_to_generate_end = None;
|
||||
let mut parameter_offset = None;
|
||||
@@ -184,47 +232,59 @@ compiler_version_offset,
|
||||
})
|
||||
}
|
||||
|
||||
pub fn file_to_generate(&self) -> crate::RepeatedFieldIterator<'a> {
|
||||
pub fn file_to_generate(&self) -> roto_runtime::RepeatedFieldIterator<'a> {
|
||||
match (self.file_to_generate_start, self.file_to_generate_end) {
|
||||
(Some(start), Some(end)) => self.accessor.iter_repeated_range(1, start, end),
|
||||
_ => self.accessor.iter_repeated(1),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn parameter(&self) -> crate::Result<&'a str> {
|
||||
let offset = self.parameter_offset.ok_or(crate::RotoError::FieldNotFound)?;
|
||||
pub fn parameter(&self) -> roto_runtime::Result<&'a str> {
|
||||
let offset = self.parameter_offset.ok_or(roto_runtime::RotoError::FieldNotFound)?;
|
||||
let (bytes, _) = self.accessor.get_value_at(offset)?;
|
||||
str::from_utf8(bytes).map_err(|_| crate::RotoError::WireFormatViolation)
|
||||
core::str::from_utf8(bytes).map_err(|_| roto_runtime::RotoError::WireFormatViolation)
|
||||
}
|
||||
|
||||
pub fn proto_file(&self) -> crate::RepeatedFieldIterator<'a> {
|
||||
pub fn parameter_or_default(&self) -> roto_runtime::Result<&'a str> {
|
||||
self.parameter().or(Ok(""))
|
||||
}
|
||||
|
||||
pub fn has_parameter(&self) -> bool { self.parameter_offset.is_some() }
|
||||
|
||||
pub fn proto_file(&self) -> roto_runtime::RepeatedFieldIterator<'a> {
|
||||
match (self.proto_file_start, self.proto_file_end) {
|
||||
(Some(start), Some(end)) => self.accessor.iter_repeated_range(15, start, end),
|
||||
_ => self.accessor.iter_repeated(15),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn source_file_descriptors(&self) -> crate::RepeatedFieldIterator<'a> {
|
||||
pub fn source_file_descriptors(&self) -> roto_runtime::RepeatedFieldIterator<'a> {
|
||||
match (self.source_file_descriptors_start, self.source_file_descriptors_end) {
|
||||
(Some(start), Some(end)) => self.accessor.iter_repeated_range(17, start, end),
|
||||
_ => self.accessor.iter_repeated(17),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn compiler_version(&self) -> crate::Result<&'a [u8]> {
|
||||
let offset = self.compiler_version_offset.ok_or(crate::RotoError::FieldNotFound)?;
|
||||
pub fn compiler_version(&self) -> roto_runtime::Result<&'a [u8]> {
|
||||
let offset = self.compiler_version_offset.ok_or(roto_runtime::RotoError::FieldNotFound)?;
|
||||
let (bytes, _) = self.accessor.get_value_at(offset)?;
|
||||
Ok(bytes)
|
||||
}
|
||||
|
||||
pub fn raw_fields(&self) -> crate::RawFieldIterator<'a> {
|
||||
pub fn compiler_version_or_default(&self) -> roto_runtime::Result<&'a [u8]> {
|
||||
self.compiler_version().or(Ok(&[]))
|
||||
}
|
||||
|
||||
pub fn has_compiler_version(&self) -> bool { self.compiler_version_offset.is_some() }
|
||||
|
||||
pub fn raw_fields(&self) -> roto_runtime::RawFieldIterator<'a> {
|
||||
self.accessor.raw_fields()
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
pub struct CodeGeneratorRequestBuilder<'b> {
|
||||
builder: crate::ProtoBuilder<'b>,
|
||||
builder: roto_runtime::ProtoBuilder<'b>,
|
||||
file_to_generate_written: bool,
|
||||
parameter_written: bool,
|
||||
proto_file_written: bool,
|
||||
@@ -235,7 +295,7 @@ pub struct CodeGeneratorRequestBuilder<'b> {
|
||||
impl<'b> CodeGeneratorRequestBuilder<'b> {
|
||||
pub fn builder(buf: &mut [u8]) -> CodeGeneratorRequestBuilder<'_> {
|
||||
CodeGeneratorRequestBuilder {
|
||||
builder: crate::ProtoBuilder::new(buf),
|
||||
builder: roto_runtime::ProtoBuilder::new(buf),
|
||||
file_to_generate_written: false,
|
||||
parameter_written: false,
|
||||
proto_file_written: false,
|
||||
@@ -244,38 +304,38 @@ impl<'b> CodeGeneratorRequestBuilder<'b> {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn file_to_generate(mut self, value: &str) -> crate::Result<Self> {
|
||||
pub fn file_to_generate(mut self, value: &str) -> roto_runtime::Result<Self> {
|
||||
self.builder.write_string(1, value)?;
|
||||
self.file_to_generate_written = true;
|
||||
Ok(self)
|
||||
}
|
||||
|
||||
pub fn parameter(mut self, value: &str) -> crate::Result<Self> {
|
||||
pub fn parameter(mut self, value: &str) -> roto_runtime::Result<Self> {
|
||||
self.builder.write_string(2, value)?;
|
||||
self.parameter_written = true;
|
||||
Ok(self)
|
||||
}
|
||||
|
||||
pub fn proto_file(mut self, value: &[u8]) -> crate::Result<Self> {
|
||||
pub fn proto_file(mut self, value: &[u8]) -> roto_runtime::Result<Self> {
|
||||
self.builder.write_bytes(15, value)?;
|
||||
self.proto_file_written = true;
|
||||
Ok(self)
|
||||
}
|
||||
|
||||
pub fn source_file_descriptors(mut self, value: &[u8]) -> crate::Result<Self> {
|
||||
pub fn source_file_descriptors(mut self, value: &[u8]) -> roto_runtime::Result<Self> {
|
||||
self.builder.write_bytes(17, value)?;
|
||||
self.source_file_descriptors_written = true;
|
||||
Ok(self)
|
||||
}
|
||||
|
||||
pub fn compiler_version(mut self, value: &[u8]) -> crate::Result<Self> {
|
||||
pub fn compiler_version(mut self, value: &[u8]) -> roto_runtime::Result<Self> {
|
||||
self.builder.write_bytes(3, value)?;
|
||||
self.compiler_version_written = true;
|
||||
Ok(self)
|
||||
}
|
||||
|
||||
pub fn with(mut self, msg: &CodeGeneratorRequest<'_>) -> crate::Result<Self> {
|
||||
for item in msg.raw_fields() {
|
||||
pub fn with(mut self, msg: &CodeGeneratorRequest<'_>) -> 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.file_to_generate_written,
|
||||
@@ -292,13 +352,37 @@ impl<'b> CodeGeneratorRequestBuilder<'b> {
|
||||
Ok(self)
|
||||
}
|
||||
|
||||
pub fn finish(self) -> crate::Result<&'b mut [u8]> {
|
||||
pub fn finish(self) -> roto_runtime::Result<&'b mut [u8]> {
|
||||
self.builder.finish()
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(feature = "alloc")]
|
||||
pub struct OwnedCodeGeneratorRequest {
|
||||
pub data: bytes::Bytes,
|
||||
}
|
||||
|
||||
#[cfg(feature = "alloc")]
|
||||
impl roto_runtime::RotoOwned for OwnedCodeGeneratorRequest {
|
||||
type Reader<'a> = CodeGeneratorRequest<'a>;
|
||||
fn reader(&self) -> CodeGeneratorRequest<'_> {
|
||||
CodeGeneratorRequest::new(&self.data).expect("failed to create reader")
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(feature = "alloc")]
|
||||
impl roto_runtime::RotoMessage for OwnedCodeGeneratorRequest {
|
||||
fn decode(buf: bytes::Bytes) -> roto_runtime::Result<Self> {
|
||||
Ok(OwnedCodeGeneratorRequest { data: buf })
|
||||
}
|
||||
|
||||
fn bytes(&self) -> bytes::Bytes {
|
||||
self.data.clone()
|
||||
}
|
||||
}
|
||||
|
||||
pub struct CodeGeneratorResponse<'a> {
|
||||
accessor: crate::ProtoAccessor<'a>,
|
||||
accessor: roto_runtime::ProtoAccessor<'a>,
|
||||
error_offset: Option<usize>,
|
||||
supported_features_offset: Option<usize>,
|
||||
minimum_edition_offset: Option<usize>,
|
||||
@@ -308,8 +392,8 @@ pub struct CodeGeneratorResponse<'a> {
|
||||
}
|
||||
|
||||
impl<'a> CodeGeneratorResponse<'a> {
|
||||
pub fn new(data: &'a [u8]) -> crate::Result<Self> {
|
||||
let accessor = crate::ProtoAccessor::new(data)?;
|
||||
pub fn new(data: &'a [u8]) -> roto_runtime::Result<Self> {
|
||||
let accessor = roto_runtime::ProtoAccessor::new(data)?;
|
||||
let mut error_offset = None;
|
||||
let mut supported_features_offset = None;
|
||||
let mut minimum_edition_offset = None;
|
||||
@@ -338,45 +422,69 @@ file_start, file_end,
|
||||
})
|
||||
}
|
||||
|
||||
pub fn error(&self) -> crate::Result<&'a str> {
|
||||
let offset = self.error_offset.ok_or(crate::RotoError::FieldNotFound)?;
|
||||
pub fn error(&self) -> roto_runtime::Result<&'a str> {
|
||||
let offset = self.error_offset.ok_or(roto_runtime::RotoError::FieldNotFound)?;
|
||||
let (bytes, _) = self.accessor.get_value_at(offset)?;
|
||||
str::from_utf8(bytes).map_err(|_| crate::RotoError::WireFormatViolation)
|
||||
core::str::from_utf8(bytes).map_err(|_| roto_runtime::RotoError::WireFormatViolation)
|
||||
}
|
||||
|
||||
pub fn supported_features(&self) -> crate::Result<u32> {
|
||||
let offset = self.supported_features_offset.ok_or(crate::RotoError::FieldNotFound)?;
|
||||
let (bytes, _) = self.accessor.get_value_at(offset)?;
|
||||
crate::read_varint(bytes).map(|(v, _)| v as u32).map_err(|_| crate::RotoError::WireFormatViolation)
|
||||
pub fn error_or_default(&self) -> roto_runtime::Result<&'a str> {
|
||||
self.error().or(Ok(""))
|
||||
}
|
||||
|
||||
pub fn minimum_edition(&self) -> crate::Result<i32> {
|
||||
let offset = self.minimum_edition_offset.ok_or(crate::RotoError::FieldNotFound)?;
|
||||
pub fn has_error(&self) -> bool { self.error_offset.is_some() }
|
||||
|
||||
pub fn supported_features(&self) -> roto_runtime::Result<u32> {
|
||||
let offset = self.supported_features_offset.ok_or(roto_runtime::RotoError::FieldNotFound)?;
|
||||
let (bytes, _) = self.accessor.get_value_at(offset)?;
|
||||
crate::read_varint(bytes).map(|(v, _)| v as i32).map_err(|_| crate::RotoError::WireFormatViolation)
|
||||
roto_runtime::read_varint(bytes).map(|(v, _)| v as u32).map_err(|_| roto_runtime::RotoError::WireFormatViolation)
|
||||
}
|
||||
|
||||
pub fn maximum_edition(&self) -> crate::Result<i32> {
|
||||
let offset = self.maximum_edition_offset.ok_or(crate::RotoError::FieldNotFound)?;
|
||||
let (bytes, _) = self.accessor.get_value_at(offset)?;
|
||||
crate::read_varint(bytes).map(|(v, _)| v as i32).map_err(|_| crate::RotoError::WireFormatViolation)
|
||||
pub fn supported_features_or_default(&self) -> roto_runtime::Result<u32> {
|
||||
self.supported_features().or(Ok(0))
|
||||
}
|
||||
|
||||
pub fn file(&self) -> crate::RepeatedFieldIterator<'a> {
|
||||
pub fn has_supported_features(&self) -> bool { self.supported_features_offset.is_some() }
|
||||
|
||||
pub fn minimum_edition(&self) -> roto_runtime::Result<i32> {
|
||||
let offset = self.minimum_edition_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)
|
||||
}
|
||||
|
||||
pub fn minimum_edition_or_default(&self) -> roto_runtime::Result<i32> {
|
||||
self.minimum_edition().or(Ok(0))
|
||||
}
|
||||
|
||||
pub fn has_minimum_edition(&self) -> bool { self.minimum_edition_offset.is_some() }
|
||||
|
||||
pub fn maximum_edition(&self) -> roto_runtime::Result<i32> {
|
||||
let offset = self.maximum_edition_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)
|
||||
}
|
||||
|
||||
pub fn maximum_edition_or_default(&self) -> roto_runtime::Result<i32> {
|
||||
self.maximum_edition().or(Ok(0))
|
||||
}
|
||||
|
||||
pub fn has_maximum_edition(&self) -> bool { self.maximum_edition_offset.is_some() }
|
||||
|
||||
pub fn file(&self) -> roto_runtime::RepeatedFieldIterator<'a> {
|
||||
match (self.file_start, self.file_end) {
|
||||
(Some(start), Some(end)) => self.accessor.iter_repeated_range(15, start, end),
|
||||
_ => self.accessor.iter_repeated(15),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn raw_fields(&self) -> crate::RawFieldIterator<'a> {
|
||||
pub fn raw_fields(&self) -> roto_runtime::RawFieldIterator<'a> {
|
||||
self.accessor.raw_fields()
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
pub struct CodeGeneratorResponseBuilder<'b> {
|
||||
builder: crate::ProtoBuilder<'b>,
|
||||
builder: roto_runtime::ProtoBuilder<'b>,
|
||||
error_written: bool,
|
||||
supported_features_written: bool,
|
||||
minimum_edition_written: bool,
|
||||
@@ -387,7 +495,7 @@ pub struct CodeGeneratorResponseBuilder<'b> {
|
||||
impl<'b> CodeGeneratorResponseBuilder<'b> {
|
||||
pub fn builder(buf: &mut [u8]) -> CodeGeneratorResponseBuilder<'_> {
|
||||
CodeGeneratorResponseBuilder {
|
||||
builder: crate::ProtoBuilder::new(buf),
|
||||
builder: roto_runtime::ProtoBuilder::new(buf),
|
||||
error_written: false,
|
||||
supported_features_written: false,
|
||||
minimum_edition_written: false,
|
||||
@@ -396,38 +504,38 @@ impl<'b> CodeGeneratorResponseBuilder<'b> {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn error(mut self, value: &str) -> crate::Result<Self> {
|
||||
pub fn error(mut self, value: &str) -> roto_runtime::Result<Self> {
|
||||
self.builder.write_string(1, value)?;
|
||||
self.error_written = true;
|
||||
Ok(self)
|
||||
}
|
||||
|
||||
pub fn supported_features(mut self, value: u64) -> crate::Result<Self> {
|
||||
pub fn supported_features(mut self, value: u64) -> roto_runtime::Result<Self> {
|
||||
self.builder.write_varint(2, value)?;
|
||||
self.supported_features_written = true;
|
||||
Ok(self)
|
||||
}
|
||||
|
||||
pub fn minimum_edition(mut self, value: i32) -> crate::Result<Self> {
|
||||
pub fn minimum_edition(mut self, value: i32) -> roto_runtime::Result<Self> {
|
||||
self.builder.write_int32(3, value)?;
|
||||
self.minimum_edition_written = true;
|
||||
Ok(self)
|
||||
}
|
||||
|
||||
pub fn maximum_edition(mut self, value: i32) -> crate::Result<Self> {
|
||||
pub fn maximum_edition(mut self, value: i32) -> roto_runtime::Result<Self> {
|
||||
self.builder.write_int32(4, value)?;
|
||||
self.maximum_edition_written = true;
|
||||
Ok(self)
|
||||
}
|
||||
|
||||
pub fn file(mut self, value: &[u8]) -> crate::Result<Self> {
|
||||
pub fn file(mut self, value: &[u8]) -> roto_runtime::Result<Self> {
|
||||
self.builder.write_bytes(15, value)?;
|
||||
self.file_written = true;
|
||||
Ok(self)
|
||||
}
|
||||
|
||||
pub fn with(mut self, msg: &CodeGeneratorResponse<'_>) -> crate::Result<Self> {
|
||||
for item in msg.raw_fields() {
|
||||
pub fn with(mut self, msg: &CodeGeneratorResponse<'_>) -> 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.error_written,
|
||||
@@ -444,11 +552,35 @@ impl<'b> CodeGeneratorResponseBuilder<'b> {
|
||||
Ok(self)
|
||||
}
|
||||
|
||||
pub fn finish(self) -> crate::Result<&'b mut [u8]> {
|
||||
pub fn finish(self) -> roto_runtime::Result<&'b mut [u8]> {
|
||||
self.builder.finish()
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(feature = "alloc")]
|
||||
pub struct OwnedCodeGeneratorResponse {
|
||||
pub data: bytes::Bytes,
|
||||
}
|
||||
|
||||
#[cfg(feature = "alloc")]
|
||||
impl roto_runtime::RotoOwned for OwnedCodeGeneratorResponse {
|
||||
type Reader<'a> = CodeGeneratorResponse<'a>;
|
||||
fn reader(&self) -> CodeGeneratorResponse<'_> {
|
||||
CodeGeneratorResponse::new(&self.data).expect("failed to create reader")
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(feature = "alloc")]
|
||||
impl roto_runtime::RotoMessage for OwnedCodeGeneratorResponse {
|
||||
fn decode(buf: bytes::Bytes) -> roto_runtime::Result<Self> {
|
||||
Ok(OwnedCodeGeneratorResponse { data: buf })
|
||||
}
|
||||
|
||||
fn bytes(&self) -> bytes::Bytes {
|
||||
self.data.clone()
|
||||
}
|
||||
}
|
||||
|
||||
pub mod code_generator_response {
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
|
||||
#[repr(i32)]
|
||||
@@ -470,7 +602,7 @@ impl Feature {
|
||||
}
|
||||
|
||||
pub struct File<'a> {
|
||||
accessor: crate::ProtoAccessor<'a>,
|
||||
accessor: roto_runtime::ProtoAccessor<'a>,
|
||||
name_offset: Option<usize>,
|
||||
insertion_point_offset: Option<usize>,
|
||||
content_offset: Option<usize>,
|
||||
@@ -478,8 +610,8 @@ pub struct File<'a> {
|
||||
}
|
||||
|
||||
impl<'a> File<'a> {
|
||||
pub fn new(data: &'a [u8]) -> crate::Result<Self> {
|
||||
let accessor = crate::ProtoAccessor::new(data)?;
|
||||
pub fn new(data: &'a [u8]) -> roto_runtime::Result<Self> {
|
||||
let accessor = roto_runtime::ProtoAccessor::new(data)?;
|
||||
let mut name_offset = None;
|
||||
let mut insertion_point_offset = None;
|
||||
let mut content_offset = None;
|
||||
@@ -501,38 +633,62 @@ generated_code_info_offset,
|
||||
})
|
||||
}
|
||||
|
||||
pub fn name(&self) -> crate::Result<&'a str> {
|
||||
let offset = self.name_offset.ok_or(crate::RotoError::FieldNotFound)?;
|
||||
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)?;
|
||||
str::from_utf8(bytes).map_err(|_| crate::RotoError::WireFormatViolation)
|
||||
core::str::from_utf8(bytes).map_err(|_| roto_runtime::RotoError::WireFormatViolation)
|
||||
}
|
||||
|
||||
pub fn insertion_point(&self) -> crate::Result<&'a str> {
|
||||
let offset = self.insertion_point_offset.ok_or(crate::RotoError::FieldNotFound)?;
|
||||
let (bytes, _) = self.accessor.get_value_at(offset)?;
|
||||
str::from_utf8(bytes).map_err(|_| crate::RotoError::WireFormatViolation)
|
||||
pub fn name_or_default(&self) -> roto_runtime::Result<&'a str> {
|
||||
self.name().or(Ok(""))
|
||||
}
|
||||
|
||||
pub fn content(&self) -> crate::Result<&'a str> {
|
||||
let offset = self.content_offset.ok_or(crate::RotoError::FieldNotFound)?;
|
||||
pub fn has_name(&self) -> bool { self.name_offset.is_some() }
|
||||
|
||||
pub fn insertion_point(&self) -> roto_runtime::Result<&'a str> {
|
||||
let offset = self.insertion_point_offset.ok_or(roto_runtime::RotoError::FieldNotFound)?;
|
||||
let (bytes, _) = self.accessor.get_value_at(offset)?;
|
||||
str::from_utf8(bytes).map_err(|_| crate::RotoError::WireFormatViolation)
|
||||
core::str::from_utf8(bytes).map_err(|_| roto_runtime::RotoError::WireFormatViolation)
|
||||
}
|
||||
|
||||
pub fn generated_code_info(&self) -> crate::Result<&'a [u8]> {
|
||||
let offset = self.generated_code_info_offset.ok_or(crate::RotoError::FieldNotFound)?;
|
||||
pub fn insertion_point_or_default(&self) -> roto_runtime::Result<&'a str> {
|
||||
self.insertion_point().or(Ok(""))
|
||||
}
|
||||
|
||||
pub fn has_insertion_point(&self) -> bool { self.insertion_point_offset.is_some() }
|
||||
|
||||
pub fn content(&self) -> roto_runtime::Result<&'a str> {
|
||||
let offset = self.content_offset.ok_or(roto_runtime::RotoError::FieldNotFound)?;
|
||||
let (bytes, _) = self.accessor.get_value_at(offset)?;
|
||||
core::str::from_utf8(bytes).map_err(|_| roto_runtime::RotoError::WireFormatViolation)
|
||||
}
|
||||
|
||||
pub fn content_or_default(&self) -> roto_runtime::Result<&'a str> {
|
||||
self.content().or(Ok(""))
|
||||
}
|
||||
|
||||
pub fn has_content(&self) -> bool { self.content_offset.is_some() }
|
||||
|
||||
pub fn generated_code_info(&self) -> roto_runtime::Result<&'a [u8]> {
|
||||
let offset = self.generated_code_info_offset.ok_or(roto_runtime::RotoError::FieldNotFound)?;
|
||||
let (bytes, _) = self.accessor.get_value_at(offset)?;
|
||||
Ok(bytes)
|
||||
}
|
||||
|
||||
pub fn raw_fields(&self) -> crate::RawFieldIterator<'a> {
|
||||
pub fn generated_code_info_or_default(&self) -> roto_runtime::Result<&'a [u8]> {
|
||||
self.generated_code_info().or(Ok(&[]))
|
||||
}
|
||||
|
||||
pub fn has_generated_code_info(&self) -> bool { self.generated_code_info_offset.is_some() }
|
||||
|
||||
pub fn raw_fields(&self) -> roto_runtime::RawFieldIterator<'a> {
|
||||
self.accessor.raw_fields()
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
pub struct FileBuilder<'b> {
|
||||
builder: crate::ProtoBuilder<'b>,
|
||||
builder: roto_runtime::ProtoBuilder<'b>,
|
||||
name_written: bool,
|
||||
insertion_point_written: bool,
|
||||
content_written: bool,
|
||||
@@ -542,7 +698,7 @@ pub struct FileBuilder<'b> {
|
||||
impl<'b> FileBuilder<'b> {
|
||||
pub fn builder(buf: &mut [u8]) -> FileBuilder<'_> {
|
||||
FileBuilder {
|
||||
builder: crate::ProtoBuilder::new(buf),
|
||||
builder: roto_runtime::ProtoBuilder::new(buf),
|
||||
name_written: false,
|
||||
insertion_point_written: false,
|
||||
content_written: false,
|
||||
@@ -550,32 +706,32 @@ impl<'b> FileBuilder<'b> {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn name(mut self, value: &str) -> crate::Result<Self> {
|
||||
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 insertion_point(mut self, value: &str) -> crate::Result<Self> {
|
||||
pub fn insertion_point(mut self, value: &str) -> roto_runtime::Result<Self> {
|
||||
self.builder.write_string(2, value)?;
|
||||
self.insertion_point_written = true;
|
||||
Ok(self)
|
||||
}
|
||||
|
||||
pub fn content(mut self, value: &str) -> crate::Result<Self> {
|
||||
pub fn content(mut self, value: &str) -> roto_runtime::Result<Self> {
|
||||
self.builder.write_string(15, value)?;
|
||||
self.content_written = true;
|
||||
Ok(self)
|
||||
}
|
||||
|
||||
pub fn generated_code_info(mut self, value: &[u8]) -> crate::Result<Self> {
|
||||
pub fn generated_code_info(mut self, value: &[u8]) -> roto_runtime::Result<Self> {
|
||||
self.builder.write_bytes(16, value)?;
|
||||
self.generated_code_info_written = true;
|
||||
Ok(self)
|
||||
}
|
||||
|
||||
pub fn with(mut self, msg: &File<'_>) -> crate::Result<Self> {
|
||||
for item in msg.raw_fields() {
|
||||
pub fn with(mut self, msg: &File<'_>) -> 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,
|
||||
@@ -591,10 +747,37 @@ impl<'b> FileBuilder<'b> {
|
||||
Ok(self)
|
||||
}
|
||||
|
||||
pub fn finish(self) -> crate::Result<&'b mut [u8]> {
|
||||
pub fn finish(self) -> roto_runtime::Result<&'b mut [u8]> {
|
||||
self.builder.finish()
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(feature = "alloc")]
|
||||
pub struct OwnedFile {
|
||||
pub data: bytes::Bytes,
|
||||
}
|
||||
|
||||
#[cfg(feature = "alloc")]
|
||||
impl roto_runtime::RotoOwned for OwnedFile {
|
||||
type Reader<'a> = File<'a>;
|
||||
fn reader(&self) -> File<'_> {
|
||||
File::new(&self.data).expect("failed to create reader")
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(feature = "alloc")]
|
||||
impl roto_runtime::RotoMessage for OwnedFile {
|
||||
fn decode(buf: bytes::Bytes) -> roto_runtime::Result<Self> {
|
||||
Ok(OwnedFile { data: buf })
|
||||
}
|
||||
|
||||
fn bytes(&self) -> bytes::Bytes {
|
||||
self.data.clone()
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
use crate::google::protobuf::descriptor;
|
||||
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
+487
-325
File diff suppressed because it is too large
Load Diff
@@ -1,22 +1,9 @@
|
||||
// @generated by protoc-gen-roto — do not edit
|
||||
#[allow(unused_imports)]
|
||||
|
||||
use roto_runtime::{ProtoAccessor, ProtoBuilder, Result, RotoError, read_varint, RepeatedFieldIterator};
|
||||
use std::str;
|
||||
use roto_runtime::{ProtoAccessor, ProtoBuilder, Result, RotoError, read_varint, RepeatedFieldIterator, RotoMessage};
|
||||
use core::str;
|
||||
#[cfg(feature = "alloc")]
|
||||
use bytes::{Bytes, BytesMut, Buf, BufMut};
|
||||
use tonic::{Request, Response, Status};
|
||||
use tokio_stream::Stream;
|
||||
use std::pin::Pin;
|
||||
use std::sync::Arc;
|
||||
use std::task::{Context, Poll};
|
||||
use std::future::Future;
|
||||
use tonic::body::BoxBody;
|
||||
use tower::Service;
|
||||
use futures_util::StreamExt;
|
||||
use http_body_util::BodyExt;
|
||||
use http_body::Body;
|
||||
use roto_tonic::{BufferPool, StatusBody};
|
||||
|
||||
|
||||
pub struct HelloRequest<'a> {
|
||||
accessor: roto_runtime::ProtoAccessor<'a>,
|
||||
@@ -41,7 +28,7 @@ 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)?;
|
||||
str::from_utf8(bytes).map_err(|_| roto_runtime::RotoError::WireFormatViolation)
|
||||
core::str::from_utf8(bytes).map_err(|_| roto_runtime::RotoError::WireFormatViolation)
|
||||
}
|
||||
|
||||
pub fn name_or_default(&self) -> roto_runtime::Result<&'a str> {
|
||||
@@ -76,7 +63,7 @@ impl<'b> HelloRequestBuilder<'b> {
|
||||
}
|
||||
|
||||
pub fn with(mut self, msg: &HelloRequest<'_>) -> roto_runtime::Result<Self> {
|
||||
for item in msg.raw_fields() {
|
||||
for item in msg.accessor.raw_fields() {
|
||||
let (field_number, raw_bytes) = item?;
|
||||
let is_written = match field_number {
|
||||
1 => self.name_written,
|
||||
@@ -94,10 +81,12 @@ impl<'b> HelloRequestBuilder<'b> {
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(feature = "alloc")]
|
||||
pub struct OwnedHelloRequest {
|
||||
pub data: bytes::Bytes,
|
||||
}
|
||||
|
||||
#[cfg(feature = "alloc")]
|
||||
impl roto_runtime::RotoOwned for OwnedHelloRequest {
|
||||
type Reader<'a> = HelloRequest<'a>;
|
||||
fn reader(&self) -> HelloRequest<'_> {
|
||||
@@ -105,6 +94,7 @@ impl roto_runtime::RotoOwned for OwnedHelloRequest {
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(feature = "alloc")]
|
||||
impl roto_runtime::RotoMessage for OwnedHelloRequest {
|
||||
fn decode(buf: bytes::Bytes) -> roto_runtime::Result<Self> {
|
||||
Ok(OwnedHelloRequest { data: buf })
|
||||
@@ -138,7 +128,7 @@ 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)?;
|
||||
str::from_utf8(bytes).map_err(|_| roto_runtime::RotoError::WireFormatViolation)
|
||||
core::str::from_utf8(bytes).map_err(|_| roto_runtime::RotoError::WireFormatViolation)
|
||||
}
|
||||
|
||||
pub fn message_or_default(&self) -> roto_runtime::Result<&'a str> {
|
||||
@@ -173,7 +163,7 @@ impl<'b> HelloResponseBuilder<'b> {
|
||||
}
|
||||
|
||||
pub fn with(mut self, msg: &HelloResponse<'_>) -> roto_runtime::Result<Self> {
|
||||
for item in msg.raw_fields() {
|
||||
for item in msg.accessor.raw_fields() {
|
||||
let (field_number, raw_bytes) = item?;
|
||||
let is_written = match field_number {
|
||||
1 => self.message_written,
|
||||
@@ -191,10 +181,12 @@ impl<'b> HelloResponseBuilder<'b> {
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(feature = "alloc")]
|
||||
pub struct OwnedHelloResponse {
|
||||
pub data: bytes::Bytes,
|
||||
}
|
||||
|
||||
#[cfg(feature = "alloc")]
|
||||
impl roto_runtime::RotoOwned for OwnedHelloResponse {
|
||||
type Reader<'a> = HelloResponse<'a>;
|
||||
fn reader(&self) -> HelloResponse<'_> {
|
||||
@@ -202,6 +194,7 @@ impl roto_runtime::RotoOwned for OwnedHelloResponse {
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(feature = "alloc")]
|
||||
impl roto_runtime::RotoMessage for OwnedHelloResponse {
|
||||
fn decode(buf: bytes::Bytes) -> roto_runtime::Result<Self> {
|
||||
Ok(OwnedHelloResponse { data: buf })
|
||||
@@ -212,32 +205,65 @@ impl roto_runtime::RotoMessage for OwnedHelloResponse {
|
||||
}
|
||||
}
|
||||
|
||||
#[tonic::async_trait]
|
||||
|
||||
|
||||
#[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]
|
||||
pub trait HelloWorldService: Send + Sync + 'static {
|
||||
async fn hello_world(&self, request: Request<OwnedHelloRequest>) -> std::result::Result<Response<OwnedHelloResponse>, Status>;
|
||||
}
|
||||
|
||||
#[cfg(feature = "alloc")]
|
||||
#[derive(Clone)]
|
||||
pub struct HelloWorldServiceServer {
|
||||
inner: Arc<dyn HelloWorldService>,
|
||||
pool: Arc<BufferPool>,
|
||||
}
|
||||
|
||||
#[cfg(feature = "alloc")]
|
||||
impl HelloWorldServiceServer {
|
||||
pub fn new(inner: Arc<dyn HelloWorldService>, pool: Arc<BufferPool>) -> Self {
|
||||
Self { inner, pool }
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(feature = "alloc")]
|
||||
impl tonic::server::NamedService for HelloWorldServiceServer {
|
||||
const NAME: &'static str = "HelloWorldService";
|
||||
const NAME: &'static str = "hello.HelloWorldService";
|
||||
}
|
||||
|
||||
#[cfg(feature = "alloc")]
|
||||
impl Service<http::Request<BoxBody>> for HelloWorldServiceServer {
|
||||
type Response = http::Response<BoxBody>;
|
||||
type Error = std::convert::Infallible;
|
||||
type Future = Pin<Box<dyn Future<Output = 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<Result<(), Self::Error>> {
|
||||
fn poll_ready(&mut self, _: &mut Context<'_>) -> Poll<std::result::Result<(), Self::Error>> {
|
||||
Poll::Ready(Ok(()))
|
||||
}
|
||||
|
||||
@@ -245,13 +271,12 @@ impl Service<http::Request<BoxBody>> for HelloWorldServiceServer {
|
||||
let inner = self.inner.clone();
|
||||
let pool = self.pool.clone();
|
||||
Box::pin(async move {
|
||||
let path = req.uri().path().to_string();
|
||||
let body = req.into_body();
|
||||
let mut buf = pool.get();
|
||||
let mut stream = body;
|
||||
while let Some(frame_result) = stream.frame().await {
|
||||
let frame = frame_result.map_err(|e| {
|
||||
panic!("Body frame error: {}", e);
|
||||
})?;
|
||||
let frame = frame_result.expect("Body frame error");
|
||||
if let Some(data) = frame.data_ref() {
|
||||
buf.put(data.clone());
|
||||
}
|
||||
@@ -261,30 +286,29 @@ impl Service<http::Request<BoxBody>> for HelloWorldServiceServer {
|
||||
let bytes_vec = buf.split_to(total_len).freeze();
|
||||
pool.put(buf);
|
||||
if bytes_vec.len() < 5 {
|
||||
let res_body = BoxBody::new(StatusBody(Some(Bytes::from_static(&[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());
|
||||
}
|
||||
|
||||
let payload = bytes_vec.slice(5..);
|
||||
let path = req.uri().path();
|
||||
let mut routed = false;
|
||||
|
||||
if path == "/HelloWorldService/hello_world" {
|
||||
if path == "/hello.HelloWorldService/HelloWorld" {
|
||||
let request_msg = match OwnedHelloRequest::decode(payload) {
|
||||
Ok(msg) => msg,
|
||||
Err(e) => {
|
||||
let res_body = BoxBody::new(StatusBody(Some(Bytes::from_static(&[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());
|
||||
}
|
||||
}};
|
||||
};
|
||||
|
||||
let response = match inner.hello_world(Request::new(request_msg)).await {
|
||||
Ok(res) => res,
|
||||
Err(e) => {
|
||||
let res_body = BoxBody::new(StatusBody(Some(Bytes::from_static(&[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());
|
||||
}
|
||||
}};
|
||||
};
|
||||
|
||||
let response_msg = response.into_inner();
|
||||
let response_bytes = response_msg.bytes();
|
||||
@@ -296,15 +320,15 @@ impl Service<http::Request<BoxBody>> for HelloWorldServiceServer {
|
||||
let frame_len = res_buf.len();
|
||||
let frame = res_buf.split_to(frame_len).freeze();
|
||||
pool.put(res_buf);
|
||||
let res_body = BoxBody::new(StatusBody(Some(frame)));
|
||||
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());
|
||||
}
|
||||
if !routed {
|
||||
let res_body = BoxBody::new(StatusBody(Some(Bytes::from_static(&[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());
|
||||
}
|
||||
Ok(http::Response::builder().status(200).body(BoxBody::new(StatusBody(None))).unwrap())
|
||||
Ok(http::Response::builder().status(200).body(BoxBody::new(StatusBody::new(None, 0))).unwrap())
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
// @generated by protoc-gen-roto — do not edit
|
||||
#[allow(unused_imports)]
|
||||
|
||||
use roto_runtime::{ProtoAccessor, ProtoBuilder, Result, RotoError, read_varint, RepeatedFieldIterator, RotoMessage};
|
||||
use core::str;
|
||||
#[cfg(feature = "alloc")]
|
||||
use bytes::{Bytes, BytesMut, Buf, BufMut};
|
||||
|
||||
pub struct Hello<'a> {
|
||||
@@ -675,3 +675,131 @@ impl roto_runtime::RotoMessage for OwnedHelloReply {
|
||||
self.data.clone()
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
#[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]
|
||||
pub trait Greeter: Send + Sync + 'static {
|
||||
async fn say_hello(&self, request: Request<OwnedHelloRequest>) -> std::result::Result<Response<OwnedHelloReply>, Status>;
|
||||
}
|
||||
|
||||
#[cfg(feature = "alloc")]
|
||||
#[derive(Clone)]
|
||||
pub struct GreeterServer {
|
||||
inner: Arc<dyn Greeter>,
|
||||
pool: Arc<BufferPool>,
|
||||
}
|
||||
|
||||
#[cfg(feature = "alloc")]
|
||||
impl GreeterServer {
|
||||
pub fn new(inner: Arc<dyn Greeter>, pool: Arc<BufferPool>) -> Self {
|
||||
Self { inner, pool }
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(feature = "alloc")]
|
||||
impl tonic::server::NamedService for GreeterServer {
|
||||
const NAME: &'static str = "helloworld.Greeter";
|
||||
}
|
||||
|
||||
#[cfg(feature = "alloc")]
|
||||
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>>;
|
||||
|
||||
fn poll_ready(&mut self, _: &mut Context<'_>) -> Poll<std::result::Result<(), Self::Error>> {
|
||||
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 {
|
||||
let path = req.uri().path().to_string();
|
||||
let body = req.into_body();
|
||||
let mut buf = pool.get();
|
||||
let mut stream = body;
|
||||
while let Some(frame_result) = stream.frame().await {
|
||||
let frame = frame_result.expect("Body frame error");
|
||||
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 {
|
||||
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..);
|
||||
let mut routed = false;
|
||||
|
||||
if path == "/helloworld.Greeter/SayHello" {
|
||||
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 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 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);
|
||||
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());
|
||||
}
|
||||
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());
|
||||
}
|
||||
Ok(http::Response::builder().status(200).body(BoxBody::new(StatusBody::new(None, 0))).unwrap())
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,783 @@
|
||||
// @generated by protoc-gen-roto — do not edit
|
||||
#[allow(unused_imports)]
|
||||
use roto_runtime::{ProtoAccessor, ProtoBuilder, Result, RotoError, read_varint, RepeatedFieldIterator, RotoMessage};
|
||||
use core::str;
|
||||
#[cfg(feature = "alloc")]
|
||||
use bytes::{Bytes, BytesMut, Buf, BufMut};
|
||||
use crate::google::protobuf::descriptor;
|
||||
|
||||
pub struct Version<'a> {
|
||||
accessor: roto_runtime::ProtoAccessor<'a>,
|
||||
major_offset: Option<usize>,
|
||||
minor_offset: Option<usize>,
|
||||
patch_offset: Option<usize>,
|
||||
suffix_offset: Option<usize>,
|
||||
}
|
||||
|
||||
impl<'a> Version<'a> {
|
||||
pub fn new(data: &'a [u8]) -> roto_runtime::Result<Self> {
|
||||
let accessor = roto_runtime::ProtoAccessor::new(data)?;
|
||||
let mut major_offset = None;
|
||||
let mut minor_offset = None;
|
||||
let mut patch_offset = None;
|
||||
let mut suffix_offset = None;
|
||||
for item in accessor.fields() {
|
||||
let (offset, tag, _) = item?;
|
||||
if tag.field_number == 1 { major_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 {
|
||||
accessor,
|
||||
major_offset,
|
||||
minor_offset,
|
||||
patch_offset,
|
||||
suffix_offset,
|
||||
})
|
||||
}
|
||||
|
||||
pub fn major(&self) -> roto_runtime::Result<i32> {
|
||||
let offset = self.major_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)
|
||||
}
|
||||
|
||||
pub fn major_or_default(&self) -> roto_runtime::Result<i32> {
|
||||
self.major().or(Ok(0))
|
||||
}
|
||||
|
||||
pub fn has_major(&self) -> bool { self.major_offset.is_some() }
|
||||
|
||||
pub fn minor(&self) -> roto_runtime::Result<i32> {
|
||||
let offset = self.minor_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)
|
||||
}
|
||||
|
||||
pub fn minor_or_default(&self) -> roto_runtime::Result<i32> {
|
||||
self.minor().or(Ok(0))
|
||||
}
|
||||
|
||||
pub fn has_minor(&self) -> bool { self.minor_offset.is_some() }
|
||||
|
||||
pub fn patch(&self) -> roto_runtime::Result<i32> {
|
||||
let offset = self.patch_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)
|
||||
}
|
||||
|
||||
pub fn patch_or_default(&self) -> roto_runtime::Result<i32> {
|
||||
self.patch().or(Ok(0))
|
||||
}
|
||||
|
||||
pub fn has_patch(&self) -> bool { self.patch_offset.is_some() }
|
||||
|
||||
pub fn suffix(&self) -> roto_runtime::Result<&'a str> {
|
||||
let offset = self.suffix_offset.ok_or(roto_runtime::RotoError::FieldNotFound)?;
|
||||
let (bytes, _) = self.accessor.get_value_at(offset)?;
|
||||
core::str::from_utf8(bytes).map_err(|_| roto_runtime::RotoError::WireFormatViolation)
|
||||
}
|
||||
|
||||
pub fn suffix_or_default(&self) -> roto_runtime::Result<&'a str> {
|
||||
self.suffix().or(Ok(""))
|
||||
}
|
||||
|
||||
pub fn has_suffix(&self) -> bool { self.suffix_offset.is_some() }
|
||||
|
||||
pub fn raw_fields(&self) -> roto_runtime::RawFieldIterator<'a> {
|
||||
self.accessor.raw_fields()
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
pub struct VersionBuilder<'b> {
|
||||
builder: roto_runtime::ProtoBuilder<'b>,
|
||||
major_written: bool,
|
||||
minor_written: bool,
|
||||
patch_written: bool,
|
||||
suffix_written: bool,
|
||||
}
|
||||
|
||||
impl<'b> VersionBuilder<'b> {
|
||||
pub fn builder(buf: &mut [u8]) -> VersionBuilder<'_> {
|
||||
VersionBuilder {
|
||||
builder: roto_runtime::ProtoBuilder::new(buf),
|
||||
major_written: false,
|
||||
minor_written: false,
|
||||
patch_written: false,
|
||||
suffix_written: false,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn major(mut self, value: i32) -> roto_runtime::Result<Self> {
|
||||
self.builder.write_int32(1, value)?;
|
||||
self.major_written = true;
|
||||
Ok(self)
|
||||
}
|
||||
|
||||
pub fn minor(mut self, value: i32) -> roto_runtime::Result<Self> {
|
||||
self.builder.write_int32(2, value)?;
|
||||
self.minor_written = true;
|
||||
Ok(self)
|
||||
}
|
||||
|
||||
pub fn patch(mut self, value: i32) -> roto_runtime::Result<Self> {
|
||||
self.builder.write_int32(3, value)?;
|
||||
self.patch_written = true;
|
||||
Ok(self)
|
||||
}
|
||||
|
||||
pub fn suffix(mut self, value: &str) -> roto_runtime::Result<Self> {
|
||||
self.builder.write_string(4, value)?;
|
||||
self.suffix_written = true;
|
||||
Ok(self)
|
||||
}
|
||||
|
||||
pub fn with(mut self, msg: &Version<'_>) -> 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.major_written,
|
||||
2 => self.minor_written,
|
||||
3 => self.patch_written,
|
||||
4 => self.suffix_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()
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(feature = "alloc")]
|
||||
pub struct OwnedVersion {
|
||||
pub data: bytes::Bytes,
|
||||
}
|
||||
|
||||
#[cfg(feature = "alloc")]
|
||||
impl roto_runtime::RotoOwned for OwnedVersion {
|
||||
type Reader<'a> = Version<'a>;
|
||||
fn reader(&self) -> Version<'_> {
|
||||
Version::new(&self.data).expect("failed to create reader")
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(feature = "alloc")]
|
||||
impl roto_runtime::RotoMessage for OwnedVersion {
|
||||
fn decode(buf: bytes::Bytes) -> roto_runtime::Result<Self> {
|
||||
Ok(OwnedVersion { data: buf })
|
||||
}
|
||||
|
||||
fn bytes(&self) -> bytes::Bytes {
|
||||
self.data.clone()
|
||||
}
|
||||
}
|
||||
|
||||
pub struct CodeGeneratorRequest<'a> {
|
||||
accessor: roto_runtime::ProtoAccessor<'a>,
|
||||
file_to_generate_start: Option<usize>,
|
||||
file_to_generate_end: Option<usize>,
|
||||
parameter_offset: Option<usize>,
|
||||
proto_file_start: Option<usize>,
|
||||
proto_file_end: Option<usize>,
|
||||
source_file_descriptors_start: Option<usize>,
|
||||
source_file_descriptors_end: Option<usize>,
|
||||
compiler_version_offset: Option<usize>,
|
||||
}
|
||||
|
||||
impl<'a> CodeGeneratorRequest<'a> {
|
||||
pub fn new(data: &'a [u8]) -> roto_runtime::Result<Self> {
|
||||
let accessor = roto_runtime::ProtoAccessor::new(data)?;
|
||||
let mut file_to_generate_start = None;
|
||||
let mut file_to_generate_end = None;
|
||||
let mut parameter_offset = None;
|
||||
let mut proto_file_start = None;
|
||||
let mut proto_file_end = None;
|
||||
let mut source_file_descriptors_start = None;
|
||||
let mut source_file_descriptors_end = None;
|
||||
let mut compiler_version_offset = None;
|
||||
for item in accessor.fields() {
|
||||
let (offset, tag, _) = item?;
|
||||
if tag.field_number == 1 {
|
||||
if file_to_generate_start.is_none() { file_to_generate_start = Some(offset); }
|
||||
file_to_generate_end = Some(offset);
|
||||
}
|
||||
if tag.field_number == 2 { parameter_offset = Some(offset); }
|
||||
if tag.field_number == 15 {
|
||||
if proto_file_start.is_none() { proto_file_start = Some(offset); }
|
||||
proto_file_end = Some(offset);
|
||||
}
|
||||
if tag.field_number == 17 {
|
||||
if source_file_descriptors_start.is_none() { source_file_descriptors_start = Some(offset); }
|
||||
source_file_descriptors_end = Some(offset);
|
||||
}
|
||||
if tag.field_number == 3 { compiler_version_offset = Some(offset); }
|
||||
}
|
||||
|
||||
Ok(Self {
|
||||
accessor,
|
||||
file_to_generate_start, file_to_generate_end,
|
||||
parameter_offset,
|
||||
proto_file_start, proto_file_end,
|
||||
source_file_descriptors_start, source_file_descriptors_end,
|
||||
compiler_version_offset,
|
||||
})
|
||||
}
|
||||
|
||||
pub fn file_to_generate(&self) -> roto_runtime::RepeatedFieldIterator<'a> {
|
||||
match (self.file_to_generate_start, self.file_to_generate_end) {
|
||||
(Some(start), Some(end)) => self.accessor.iter_repeated_range(1, start, end),
|
||||
_ => self.accessor.iter_repeated(1),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn parameter(&self) -> roto_runtime::Result<&'a str> {
|
||||
let offset = self.parameter_offset.ok_or(roto_runtime::RotoError::FieldNotFound)?;
|
||||
let (bytes, _) = self.accessor.get_value_at(offset)?;
|
||||
core::str::from_utf8(bytes).map_err(|_| roto_runtime::RotoError::WireFormatViolation)
|
||||
}
|
||||
|
||||
pub fn parameter_or_default(&self) -> roto_runtime::Result<&'a str> {
|
||||
self.parameter().or(Ok(""))
|
||||
}
|
||||
|
||||
pub fn has_parameter(&self) -> bool { self.parameter_offset.is_some() }
|
||||
|
||||
pub fn proto_file(&self) -> roto_runtime::RepeatedFieldIterator<'a> {
|
||||
match (self.proto_file_start, self.proto_file_end) {
|
||||
(Some(start), Some(end)) => self.accessor.iter_repeated_range(15, start, end),
|
||||
_ => self.accessor.iter_repeated(15),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn source_file_descriptors(&self) -> roto_runtime::RepeatedFieldIterator<'a> {
|
||||
match (self.source_file_descriptors_start, self.source_file_descriptors_end) {
|
||||
(Some(start), Some(end)) => self.accessor.iter_repeated_range(17, start, end),
|
||||
_ => self.accessor.iter_repeated(17),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn compiler_version(&self) -> roto_runtime::Result<&'a [u8]> {
|
||||
let offset = self.compiler_version_offset.ok_or(roto_runtime::RotoError::FieldNotFound)?;
|
||||
let (bytes, _) = self.accessor.get_value_at(offset)?;
|
||||
Ok(bytes)
|
||||
}
|
||||
|
||||
pub fn compiler_version_or_default(&self) -> roto_runtime::Result<&'a [u8]> {
|
||||
self.compiler_version().or(Ok(&[]))
|
||||
}
|
||||
|
||||
pub fn has_compiler_version(&self) -> bool { self.compiler_version_offset.is_some() }
|
||||
|
||||
pub fn raw_fields(&self) -> roto_runtime::RawFieldIterator<'a> {
|
||||
self.accessor.raw_fields()
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
pub struct CodeGeneratorRequestBuilder<'b> {
|
||||
builder: roto_runtime::ProtoBuilder<'b>,
|
||||
file_to_generate_written: bool,
|
||||
parameter_written: bool,
|
||||
proto_file_written: bool,
|
||||
source_file_descriptors_written: bool,
|
||||
compiler_version_written: bool,
|
||||
}
|
||||
|
||||
impl<'b> CodeGeneratorRequestBuilder<'b> {
|
||||
pub fn builder(buf: &mut [u8]) -> CodeGeneratorRequestBuilder<'_> {
|
||||
CodeGeneratorRequestBuilder {
|
||||
builder: roto_runtime::ProtoBuilder::new(buf),
|
||||
file_to_generate_written: false,
|
||||
parameter_written: false,
|
||||
proto_file_written: false,
|
||||
source_file_descriptors_written: false,
|
||||
compiler_version_written: false,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn file_to_generate(mut self, value: &str) -> roto_runtime::Result<Self> {
|
||||
self.builder.write_string(1, value)?;
|
||||
self.file_to_generate_written = true;
|
||||
Ok(self)
|
||||
}
|
||||
|
||||
pub fn parameter(mut self, value: &str) -> roto_runtime::Result<Self> {
|
||||
self.builder.write_string(2, value)?;
|
||||
self.parameter_written = true;
|
||||
Ok(self)
|
||||
}
|
||||
|
||||
pub fn proto_file(mut self, value: &[u8]) -> roto_runtime::Result<Self> {
|
||||
self.builder.write_bytes(15, value)?;
|
||||
self.proto_file_written = true;
|
||||
Ok(self)
|
||||
}
|
||||
|
||||
pub fn source_file_descriptors(mut self, value: &[u8]) -> roto_runtime::Result<Self> {
|
||||
self.builder.write_bytes(17, value)?;
|
||||
self.source_file_descriptors_written = true;
|
||||
Ok(self)
|
||||
}
|
||||
|
||||
pub fn compiler_version(mut self, value: &[u8]) -> roto_runtime::Result<Self> {
|
||||
self.builder.write_bytes(3, value)?;
|
||||
self.compiler_version_written = true;
|
||||
Ok(self)
|
||||
}
|
||||
|
||||
pub fn with(mut self, msg: &CodeGeneratorRequest<'_>) -> 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.file_to_generate_written,
|
||||
2 => self.parameter_written,
|
||||
15 => self.proto_file_written,
|
||||
17 => self.source_file_descriptors_written,
|
||||
3 => self.compiler_version_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()
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(feature = "alloc")]
|
||||
pub struct OwnedCodeGeneratorRequest {
|
||||
pub data: bytes::Bytes,
|
||||
}
|
||||
|
||||
#[cfg(feature = "alloc")]
|
||||
impl roto_runtime::RotoOwned for OwnedCodeGeneratorRequest {
|
||||
type Reader<'a> = CodeGeneratorRequest<'a>;
|
||||
fn reader(&self) -> CodeGeneratorRequest<'_> {
|
||||
CodeGeneratorRequest::new(&self.data).expect("failed to create reader")
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(feature = "alloc")]
|
||||
impl roto_runtime::RotoMessage for OwnedCodeGeneratorRequest {
|
||||
fn decode(buf: bytes::Bytes) -> roto_runtime::Result<Self> {
|
||||
Ok(OwnedCodeGeneratorRequest { data: buf })
|
||||
}
|
||||
|
||||
fn bytes(&self) -> bytes::Bytes {
|
||||
self.data.clone()
|
||||
}
|
||||
}
|
||||
|
||||
pub struct CodeGeneratorResponse<'a> {
|
||||
accessor: roto_runtime::ProtoAccessor<'a>,
|
||||
error_offset: Option<usize>,
|
||||
supported_features_offset: Option<usize>,
|
||||
minimum_edition_offset: Option<usize>,
|
||||
maximum_edition_offset: Option<usize>,
|
||||
file_start: Option<usize>,
|
||||
file_end: Option<usize>,
|
||||
}
|
||||
|
||||
impl<'a> CodeGeneratorResponse<'a> {
|
||||
pub fn new(data: &'a [u8]) -> roto_runtime::Result<Self> {
|
||||
let accessor = roto_runtime::ProtoAccessor::new(data)?;
|
||||
let mut error_offset = None;
|
||||
let mut supported_features_offset = None;
|
||||
let mut minimum_edition_offset = None;
|
||||
let mut maximum_edition_offset = None;
|
||||
let mut file_start = None;
|
||||
let mut file_end = None;
|
||||
for item in accessor.fields() {
|
||||
let (offset, tag, _) = item?;
|
||||
if tag.field_number == 1 { error_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 file_start.is_none() { file_start = Some(offset); }
|
||||
file_end = Some(offset);
|
||||
}
|
||||
}
|
||||
|
||||
Ok(Self {
|
||||
accessor,
|
||||
error_offset,
|
||||
supported_features_offset,
|
||||
minimum_edition_offset,
|
||||
maximum_edition_offset,
|
||||
file_start, file_end,
|
||||
})
|
||||
}
|
||||
|
||||
pub fn error(&self) -> roto_runtime::Result<&'a str> {
|
||||
let offset = self.error_offset.ok_or(roto_runtime::RotoError::FieldNotFound)?;
|
||||
let (bytes, _) = self.accessor.get_value_at(offset)?;
|
||||
core::str::from_utf8(bytes).map_err(|_| roto_runtime::RotoError::WireFormatViolation)
|
||||
}
|
||||
|
||||
pub fn error_or_default(&self) -> roto_runtime::Result<&'a str> {
|
||||
self.error().or(Ok(""))
|
||||
}
|
||||
|
||||
pub fn has_error(&self) -> bool { self.error_offset.is_some() }
|
||||
|
||||
pub fn supported_features(&self) -> roto_runtime::Result<u32> {
|
||||
let offset = self.supported_features_offset.ok_or(roto_runtime::RotoError::FieldNotFound)?;
|
||||
let (bytes, _) = self.accessor.get_value_at(offset)?;
|
||||
roto_runtime::read_varint(bytes).map(|(v, _)| v as u32).map_err(|_| roto_runtime::RotoError::WireFormatViolation)
|
||||
}
|
||||
|
||||
pub fn supported_features_or_default(&self) -> roto_runtime::Result<u32> {
|
||||
self.supported_features().or(Ok(0))
|
||||
}
|
||||
|
||||
pub fn has_supported_features(&self) -> bool { self.supported_features_offset.is_some() }
|
||||
|
||||
pub fn minimum_edition(&self) -> roto_runtime::Result<i32> {
|
||||
let offset = self.minimum_edition_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)
|
||||
}
|
||||
|
||||
pub fn minimum_edition_or_default(&self) -> roto_runtime::Result<i32> {
|
||||
self.minimum_edition().or(Ok(0))
|
||||
}
|
||||
|
||||
pub fn has_minimum_edition(&self) -> bool { self.minimum_edition_offset.is_some() }
|
||||
|
||||
pub fn maximum_edition(&self) -> roto_runtime::Result<i32> {
|
||||
let offset = self.maximum_edition_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)
|
||||
}
|
||||
|
||||
pub fn maximum_edition_or_default(&self) -> roto_runtime::Result<i32> {
|
||||
self.maximum_edition().or(Ok(0))
|
||||
}
|
||||
|
||||
pub fn has_maximum_edition(&self) -> bool { self.maximum_edition_offset.is_some() }
|
||||
|
||||
pub fn file(&self) -> roto_runtime::RepeatedFieldIterator<'a> {
|
||||
match (self.file_start, self.file_end) {
|
||||
(Some(start), Some(end)) => self.accessor.iter_repeated_range(15, start, end),
|
||||
_ => self.accessor.iter_repeated(15),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn raw_fields(&self) -> roto_runtime::RawFieldIterator<'a> {
|
||||
self.accessor.raw_fields()
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
pub struct CodeGeneratorResponseBuilder<'b> {
|
||||
builder: roto_runtime::ProtoBuilder<'b>,
|
||||
error_written: bool,
|
||||
supported_features_written: bool,
|
||||
minimum_edition_written: bool,
|
||||
maximum_edition_written: bool,
|
||||
file_written: bool,
|
||||
}
|
||||
|
||||
impl<'b> CodeGeneratorResponseBuilder<'b> {
|
||||
pub fn builder(buf: &mut [u8]) -> CodeGeneratorResponseBuilder<'_> {
|
||||
CodeGeneratorResponseBuilder {
|
||||
builder: roto_runtime::ProtoBuilder::new(buf),
|
||||
error_written: false,
|
||||
supported_features_written: false,
|
||||
minimum_edition_written: false,
|
||||
maximum_edition_written: false,
|
||||
file_written: false,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn error(mut self, value: &str) -> roto_runtime::Result<Self> {
|
||||
self.builder.write_string(1, value)?;
|
||||
self.error_written = true;
|
||||
Ok(self)
|
||||
}
|
||||
|
||||
pub fn supported_features(mut self, value: u64) -> roto_runtime::Result<Self> {
|
||||
self.builder.write_varint(2, value)?;
|
||||
self.supported_features_written = true;
|
||||
Ok(self)
|
||||
}
|
||||
|
||||
pub fn minimum_edition(mut self, value: i32) -> roto_runtime::Result<Self> {
|
||||
self.builder.write_int32(3, value)?;
|
||||
self.minimum_edition_written = true;
|
||||
Ok(self)
|
||||
}
|
||||
|
||||
pub fn maximum_edition(mut self, value: i32) -> roto_runtime::Result<Self> {
|
||||
self.builder.write_int32(4, value)?;
|
||||
self.maximum_edition_written = true;
|
||||
Ok(self)
|
||||
}
|
||||
|
||||
pub fn file(mut self, value: &[u8]) -> roto_runtime::Result<Self> {
|
||||
self.builder.write_bytes(15, value)?;
|
||||
self.file_written = true;
|
||||
Ok(self)
|
||||
}
|
||||
|
||||
pub fn with(mut self, msg: &CodeGeneratorResponse<'_>) -> 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.error_written,
|
||||
2 => self.supported_features_written,
|
||||
3 => self.minimum_edition_written,
|
||||
4 => self.maximum_edition_written,
|
||||
15 => self.file_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()
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(feature = "alloc")]
|
||||
pub struct OwnedCodeGeneratorResponse {
|
||||
pub data: bytes::Bytes,
|
||||
}
|
||||
|
||||
#[cfg(feature = "alloc")]
|
||||
impl roto_runtime::RotoOwned for OwnedCodeGeneratorResponse {
|
||||
type Reader<'a> = CodeGeneratorResponse<'a>;
|
||||
fn reader(&self) -> CodeGeneratorResponse<'_> {
|
||||
CodeGeneratorResponse::new(&self.data).expect("failed to create reader")
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(feature = "alloc")]
|
||||
impl roto_runtime::RotoMessage for OwnedCodeGeneratorResponse {
|
||||
fn decode(buf: bytes::Bytes) -> roto_runtime::Result<Self> {
|
||||
Ok(OwnedCodeGeneratorResponse { data: buf })
|
||||
}
|
||||
|
||||
fn bytes(&self) -> bytes::Bytes {
|
||||
self.data.clone()
|
||||
}
|
||||
}
|
||||
|
||||
pub mod code_generator_response {
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
|
||||
#[repr(i32)]
|
||||
pub enum Feature {
|
||||
FEATURENONE = 0,
|
||||
FEATUREPROTO3OPTIONAL = 1,
|
||||
FEATURESUPPORTSEDITIONS = 2,
|
||||
}
|
||||
|
||||
impl Feature {
|
||||
pub fn from_i32(value: i32) -> Self {
|
||||
match value {
|
||||
0 => Feature::FEATURENONE,
|
||||
1 => Feature::FEATUREPROTO3OPTIONAL,
|
||||
2 => Feature::FEATURESUPPORTSEDITIONS,
|
||||
_ => Feature::FEATURENONE,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub struct File<'a> {
|
||||
accessor: roto_runtime::ProtoAccessor<'a>,
|
||||
name_offset: Option<usize>,
|
||||
insertion_point_offset: Option<usize>,
|
||||
content_offset: Option<usize>,
|
||||
generated_code_info_offset: Option<usize>,
|
||||
}
|
||||
|
||||
impl<'a> File<'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 insertion_point_offset = None;
|
||||
let mut content_offset = None;
|
||||
let mut generated_code_info_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 { 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 {
|
||||
accessor,
|
||||
name_offset,
|
||||
insertion_point_offset,
|
||||
content_offset,
|
||||
generated_code_info_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)?;
|
||||
core::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 has_name(&self) -> bool { self.name_offset.is_some() }
|
||||
|
||||
pub fn insertion_point(&self) -> roto_runtime::Result<&'a str> {
|
||||
let offset = self.insertion_point_offset.ok_or(roto_runtime::RotoError::FieldNotFound)?;
|
||||
let (bytes, _) = self.accessor.get_value_at(offset)?;
|
||||
core::str::from_utf8(bytes).map_err(|_| roto_runtime::RotoError::WireFormatViolation)
|
||||
}
|
||||
|
||||
pub fn insertion_point_or_default(&self) -> roto_runtime::Result<&'a str> {
|
||||
self.insertion_point().or(Ok(""))
|
||||
}
|
||||
|
||||
pub fn has_insertion_point(&self) -> bool { self.insertion_point_offset.is_some() }
|
||||
|
||||
pub fn content(&self) -> roto_runtime::Result<&'a str> {
|
||||
let offset = self.content_offset.ok_or(roto_runtime::RotoError::FieldNotFound)?;
|
||||
let (bytes, _) = self.accessor.get_value_at(offset)?;
|
||||
core::str::from_utf8(bytes).map_err(|_| roto_runtime::RotoError::WireFormatViolation)
|
||||
}
|
||||
|
||||
pub fn content_or_default(&self) -> roto_runtime::Result<&'a str> {
|
||||
self.content().or(Ok(""))
|
||||
}
|
||||
|
||||
pub fn has_content(&self) -> bool { self.content_offset.is_some() }
|
||||
|
||||
pub fn generated_code_info(&self) -> roto_runtime::Result<&'a [u8]> {
|
||||
let offset = self.generated_code_info_offset.ok_or(roto_runtime::RotoError::FieldNotFound)?;
|
||||
let (bytes, _) = self.accessor.get_value_at(offset)?;
|
||||
Ok(bytes)
|
||||
}
|
||||
|
||||
pub fn generated_code_info_or_default(&self) -> roto_runtime::Result<&'a [u8]> {
|
||||
self.generated_code_info().or(Ok(&[]))
|
||||
}
|
||||
|
||||
pub fn has_generated_code_info(&self) -> bool { self.generated_code_info_offset.is_some() }
|
||||
|
||||
pub fn raw_fields(&self) -> roto_runtime::RawFieldIterator<'a> {
|
||||
self.accessor.raw_fields()
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
pub struct FileBuilder<'b> {
|
||||
builder: roto_runtime::ProtoBuilder<'b>,
|
||||
name_written: bool,
|
||||
insertion_point_written: bool,
|
||||
content_written: bool,
|
||||
generated_code_info_written: bool,
|
||||
}
|
||||
|
||||
impl<'b> FileBuilder<'b> {
|
||||
pub fn builder(buf: &mut [u8]) -> FileBuilder<'_> {
|
||||
FileBuilder {
|
||||
builder: roto_runtime::ProtoBuilder::new(buf),
|
||||
name_written: false,
|
||||
insertion_point_written: false,
|
||||
content_written: false,
|
||||
generated_code_info_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 insertion_point(mut self, value: &str) -> roto_runtime::Result<Self> {
|
||||
self.builder.write_string(2, value)?;
|
||||
self.insertion_point_written = true;
|
||||
Ok(self)
|
||||
}
|
||||
|
||||
pub fn content(mut self, value: &str) -> roto_runtime::Result<Self> {
|
||||
self.builder.write_string(15, value)?;
|
||||
self.content_written = true;
|
||||
Ok(self)
|
||||
}
|
||||
|
||||
pub fn generated_code_info(mut self, value: &[u8]) -> roto_runtime::Result<Self> {
|
||||
self.builder.write_bytes(16, value)?;
|
||||
self.generated_code_info_written = true;
|
||||
Ok(self)
|
||||
}
|
||||
|
||||
pub fn with(mut self, msg: &File<'_>) -> 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.insertion_point_written,
|
||||
15 => self.content_written,
|
||||
16 => self.generated_code_info_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()
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(feature = "alloc")]
|
||||
pub struct OwnedFile {
|
||||
pub data: bytes::Bytes,
|
||||
}
|
||||
|
||||
#[cfg(feature = "alloc")]
|
||||
impl roto_runtime::RotoOwned for OwnedFile {
|
||||
type Reader<'a> = File<'a>;
|
||||
fn reader(&self) -> File<'_> {
|
||||
File::new(&self.data).expect("failed to create reader")
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(feature = "alloc")]
|
||||
impl roto_runtime::RotoMessage for OwnedFile {
|
||||
fn decode(buf: bytes::Bytes) -> roto_runtime::Result<Self> {
|
||||
Ok(OwnedFile { data: buf })
|
||||
}
|
||||
|
||||
fn bytes(&self) -> bytes::Bytes {
|
||||
self.data.clone()
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
use crate::google::protobuf::descriptor;
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user