Update codegen to suppress more compiler warnings
This commit is contained in:
@@ -7,11 +7,11 @@ use crate::runtime::ProtoAccessor;
|
||||
use std::collections::{HashMap, HashSet};
|
||||
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 core::str;\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 tokio_stream::Stream;\n\
|
||||
use std::pin::Pin;\n\
|
||||
@@ -591,7 +591,6 @@ where
|
||||
|
||||
let mut output = String::new();
|
||||
output.push_str("// @generated by protoc-gen-roto — do not edit\n");
|
||||
output.push_str("#[allow(unused_imports)]\n");
|
||||
output.push_str(imports);
|
||||
|
||||
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\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 {
|
||||
|
||||
@@ -1,21 +1,29 @@
|
||||
// @generated by protoc-gen-roto — do not edit
|
||||
#[allow(unused)]
|
||||
#![allow(
|
||||
unused,
|
||||
unused_imports,
|
||||
unused_assignments,
|
||||
unused_variables,
|
||||
non_camel_case_types
|
||||
)]
|
||||
|
||||
use crate::runtime::{ProtoAccessor, ProtoBuilder, Result, RotoError, read_varint, RepeatedFieldIterator};
|
||||
use std::str;
|
||||
use bytes::{Bytes, BytesMut, Buf, BufMut};
|
||||
use tonic::{Request, Response, Status};
|
||||
use tokio_stream::Stream;
|
||||
use crate::runtime::{
|
||||
ProtoAccessor, ProtoBuilder, RepeatedFieldIterator, Result, RotoError, read_varint,
|
||||
};
|
||||
use bytes::{Buf, BufMut, Bytes, BytesMut};
|
||||
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::str;
|
||||
use std::sync::Arc;
|
||||
use std::task::{Context, Poll};
|
||||
use std::future::Future;
|
||||
use tokio_stream::Stream;
|
||||
use tonic::body::BoxBody;
|
||||
use tonic::{Request, Response, Status};
|
||||
use tower::Service;
|
||||
use futures_util::StreamExt;
|
||||
use http_body_util::BodyExt;
|
||||
use http_body::Body;
|
||||
use roto_tonic::{BufferPool, StatusBody};
|
||||
|
||||
use crate::google::protobuf::descriptor;
|
||||
|
||||
@@ -36,59 +44,87 @@ impl<'a> Version<'a> {
|
||||
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); }
|
||||
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,
|
||||
major_offset,
|
||||
minor_offset,
|
||||
patch_offset,
|
||||
suffix_offset,
|
||||
})
|
||||
}
|
||||
|
||||
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)?;
|
||||
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> {
|
||||
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> {
|
||||
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)?;
|
||||
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> {
|
||||
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> {
|
||||
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)?;
|
||||
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> {
|
||||
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> {
|
||||
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)?;
|
||||
str::from_utf8(bytes).map_err(|_| crate::runtime::RotoError::WireFormatViolation)
|
||||
}
|
||||
@@ -97,12 +133,13 @@ suffix_offset,
|
||||
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> {
|
||||
self.accessor.raw_fields()
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
pub struct VersionBuilder<'b> {
|
||||
@@ -217,28 +254,41 @@ impl<'a> CodeGeneratorRequest<'a> {
|
||||
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); }
|
||||
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 == 2 {
|
||||
parameter_offset = Some(offset);
|
||||
}
|
||||
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);
|
||||
}
|
||||
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);
|
||||
}
|
||||
if tag.field_number == 3 { compiler_version_offset = 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,
|
||||
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,
|
||||
})
|
||||
}
|
||||
|
||||
@@ -250,7 +300,9 @@ compiler_version_offset,
|
||||
}
|
||||
|
||||
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)?;
|
||||
str::from_utf8(bytes).map_err(|_| crate::runtime::RotoError::WireFormatViolation)
|
||||
}
|
||||
@@ -259,7 +311,9 @@ compiler_version_offset,
|
||||
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> {
|
||||
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> {
|
||||
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),
|
||||
_ => self.accessor.iter_repeated(17),
|
||||
}
|
||||
}
|
||||
|
||||
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)?;
|
||||
Ok(bytes)
|
||||
}
|
||||
@@ -285,12 +344,13 @@ compiler_version_offset,
|
||||
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> {
|
||||
self.accessor.raw_fields()
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
pub struct CodeGeneratorRequestBuilder<'b> {
|
||||
@@ -409,28 +469,41 @@ impl<'a> CodeGeneratorResponse<'a> {
|
||||
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 == 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); }
|
||||
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,
|
||||
error_offset,
|
||||
supported_features_offset,
|
||||
minimum_edition_offset,
|
||||
maximum_edition_offset,
|
||||
file_start,
|
||||
file_end,
|
||||
})
|
||||
}
|
||||
|
||||
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)?;
|
||||
str::from_utf8(bytes).map_err(|_| crate::runtime::RotoError::WireFormatViolation)
|
||||
}
|
||||
@@ -439,43 +512,63 @@ file_start, file_end,
|
||||
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> {
|
||||
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)?;
|
||||
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> {
|
||||
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> {
|
||||
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)?;
|
||||
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> {
|
||||
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> {
|
||||
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)?;
|
||||
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> {
|
||||
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> {
|
||||
match (self.file_start, self.file_end) {
|
||||
@@ -487,7 +580,6 @@ file_start, file_end,
|
||||
pub fn raw_fields(&self) -> crate::runtime::RawFieldIterator<'a> {
|
||||
self.accessor.raw_fields()
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
pub struct CodeGeneratorResponseBuilder<'b> {
|
||||
@@ -586,196 +678,217 @@ impl crate::runtime::RotoMessage for OwnedCodeGeneratorResponse {
|
||||
}
|
||||
|
||||
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: crate::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]) -> crate::runtime::Result<Self> {
|
||||
let accessor = crate::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,
|
||||
})
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
|
||||
#[repr(i32)]
|
||||
pub enum Feature {
|
||||
FEATURENONE = 0,
|
||||
FEATUREPROTO3OPTIONAL = 1,
|
||||
FEATURESUPPORTSEDITIONS = 2,
|
||||
}
|
||||
|
||||
pub fn name(&self) -> crate::runtime::Result<&'a str> {
|
||||
let offset = self.name_offset.ok_or(crate::runtime::RotoError::FieldNotFound)?;
|
||||
let (bytes, _) = self.accessor.get_value_at(offset)?;
|
||||
str::from_utf8(bytes).map_err(|_| crate::runtime::RotoError::WireFormatViolation)
|
||||
}
|
||||
|
||||
pub fn name_or_default(&self) -> crate::runtime::Result<&'a str> {
|
||||
self.name().or(Ok(""))
|
||||
}
|
||||
|
||||
pub fn has_name(&self) -> bool { self.name_offset.is_some() }
|
||||
|
||||
pub fn insertion_point(&self) -> crate::runtime::Result<&'a str> {
|
||||
let offset = self.insertion_point_offset.ok_or(crate::runtime::RotoError::FieldNotFound)?;
|
||||
let (bytes, _) = self.accessor.get_value_at(offset)?;
|
||||
str::from_utf8(bytes).map_err(|_| crate::runtime::RotoError::WireFormatViolation)
|
||||
}
|
||||
|
||||
pub fn insertion_point_or_default(&self) -> crate::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) -> crate::runtime::Result<&'a str> {
|
||||
let offset = self.content_offset.ok_or(crate::runtime::RotoError::FieldNotFound)?;
|
||||
let (bytes, _) = self.accessor.get_value_at(offset)?;
|
||||
str::from_utf8(bytes).map_err(|_| crate::runtime::RotoError::WireFormatViolation)
|
||||
}
|
||||
|
||||
pub fn content_or_default(&self) -> crate::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) -> crate::runtime::Result<&'a [u8]> {
|
||||
let offset = self.generated_code_info_offset.ok_or(crate::runtime::RotoError::FieldNotFound)?;
|
||||
let (bytes, _) = self.accessor.get_value_at(offset)?;
|
||||
Ok(bytes)
|
||||
}
|
||||
|
||||
pub fn generated_code_info_or_default(&self) -> crate::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) -> crate::runtime::RawFieldIterator<'a> {
|
||||
self.accessor.raw_fields()
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
pub struct FileBuilder<'b> {
|
||||
builder: crate::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: crate::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) -> crate::runtime::Result<Self> {
|
||||
self.builder.write_string(1, value)?;
|
||||
self.name_written = true;
|
||||
Ok(self)
|
||||
}
|
||||
|
||||
pub fn insertion_point(mut self, value: &str) -> crate::runtime::Result<Self> {
|
||||
self.builder.write_string(2, value)?;
|
||||
self.insertion_point_written = true;
|
||||
Ok(self)
|
||||
}
|
||||
|
||||
pub fn content(mut self, value: &str) -> crate::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::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::runtime::Result<Self> {
|
||||
for item in msg.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)?;
|
||||
impl Feature {
|
||||
pub fn from_i32(value: i32) -> Self {
|
||||
match value {
|
||||
0 => Feature::FEATURENONE,
|
||||
1 => Feature::FEATUREPROTO3OPTIONAL,
|
||||
2 => Feature::FEATURESUPPORTSEDITIONS,
|
||||
_ => Feature::FEATURENONE,
|
||||
}
|
||||
}
|
||||
Ok(self)
|
||||
}
|
||||
|
||||
pub fn finish(self) -> crate::runtime::Result<&'b mut [u8]> {
|
||||
self.builder.finish()
|
||||
}
|
||||
}
|
||||
|
||||
pub struct OwnedFile {
|
||||
pub data: bytes::Bytes,
|
||||
}
|
||||
|
||||
impl crate::runtime::RotoOwned for OwnedFile {
|
||||
type Reader<'a> = File<'a>;
|
||||
fn reader(&self) -> File<'_> {
|
||||
File::new(&self.data).expect("failed to create reader")
|
||||
}
|
||||
}
|
||||
|
||||
impl crate::runtime::RotoMessage for OwnedFile {
|
||||
fn decode(buf: bytes::Bytes) -> crate::runtime::Result<Self> {
|
||||
Ok(OwnedFile { data: buf })
|
||||
pub struct File<'a> {
|
||||
accessor: crate::runtime::ProtoAccessor<'a>,
|
||||
name_offset: Option<usize>,
|
||||
insertion_point_offset: Option<usize>,
|
||||
content_offset: Option<usize>,
|
||||
generated_code_info_offset: Option<usize>,
|
||||
}
|
||||
|
||||
fn bytes(&self) -> bytes::Bytes {
|
||||
self.data.clone()
|
||||
impl<'a> File<'a> {
|
||||
pub fn new(data: &'a [u8]) -> crate::runtime::Result<Self> {
|
||||
let accessor = crate::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) -> crate::runtime::Result<&'a str> {
|
||||
let offset = self
|
||||
.name_offset
|
||||
.ok_or(crate::runtime::RotoError::FieldNotFound)?;
|
||||
let (bytes, _) = self.accessor.get_value_at(offset)?;
|
||||
str::from_utf8(bytes).map_err(|_| crate::runtime::RotoError::WireFormatViolation)
|
||||
}
|
||||
|
||||
pub fn name_or_default(&self) -> crate::runtime::Result<&'a str> {
|
||||
self.name().or(Ok(""))
|
||||
}
|
||||
|
||||
pub fn has_name(&self) -> bool {
|
||||
self.name_offset.is_some()
|
||||
}
|
||||
|
||||
pub fn insertion_point(&self) -> crate::runtime::Result<&'a str> {
|
||||
let offset = self
|
||||
.insertion_point_offset
|
||||
.ok_or(crate::runtime::RotoError::FieldNotFound)?;
|
||||
let (bytes, _) = self.accessor.get_value_at(offset)?;
|
||||
str::from_utf8(bytes).map_err(|_| crate::runtime::RotoError::WireFormatViolation)
|
||||
}
|
||||
|
||||
pub fn insertion_point_or_default(&self) -> crate::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) -> crate::runtime::Result<&'a str> {
|
||||
let offset = self
|
||||
.content_offset
|
||||
.ok_or(crate::runtime::RotoError::FieldNotFound)?;
|
||||
let (bytes, _) = self.accessor.get_value_at(offset)?;
|
||||
str::from_utf8(bytes).map_err(|_| crate::runtime::RotoError::WireFormatViolation)
|
||||
}
|
||||
|
||||
pub fn content_or_default(&self) -> crate::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) -> crate::runtime::Result<&'a [u8]> {
|
||||
let offset = self
|
||||
.generated_code_info_offset
|
||||
.ok_or(crate::runtime::RotoError::FieldNotFound)?;
|
||||
let (bytes, _) = self.accessor.get_value_at(offset)?;
|
||||
Ok(bytes)
|
||||
}
|
||||
|
||||
pub fn generated_code_info_or_default(&self) -> crate::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) -> crate::runtime::RawFieldIterator<'a> {
|
||||
self.accessor.raw_fields()
|
||||
}
|
||||
}
|
||||
|
||||
pub struct FileBuilder<'b> {
|
||||
builder: crate::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: crate::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) -> crate::runtime::Result<Self> {
|
||||
self.builder.write_string(1, value)?;
|
||||
self.name_written = true;
|
||||
Ok(self)
|
||||
}
|
||||
|
||||
pub fn insertion_point(mut self, value: &str) -> crate::runtime::Result<Self> {
|
||||
self.builder.write_string(2, value)?;
|
||||
self.insertion_point_written = true;
|
||||
Ok(self)
|
||||
}
|
||||
|
||||
pub fn content(mut self, value: &str) -> crate::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::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::runtime::Result<Self> {
|
||||
for item in msg.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) -> crate::runtime::Result<&'b mut [u8]> {
|
||||
self.builder.finish()
|
||||
}
|
||||
}
|
||||
|
||||
pub struct OwnedFile {
|
||||
pub data: bytes::Bytes,
|
||||
}
|
||||
|
||||
impl crate::runtime::RotoOwned for OwnedFile {
|
||||
type Reader<'a> = File<'a>;
|
||||
fn reader(&self) -> File<'_> {
|
||||
File::new(&self.data).expect("failed to create reader")
|
||||
}
|
||||
}
|
||||
|
||||
impl crate::runtime::RotoMessage for OwnedFile {
|
||||
fn decode(buf: bytes::Bytes) -> crate::runtime::Result<Self> {
|
||||
Ok(OwnedFile { data: buf })
|
||||
}
|
||||
|
||||
fn bytes(&self) -> bytes::Bytes {
|
||||
self.data.clone()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
+3630
-2555
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user