diff --git a/codegen/src/generator/mod.rs b/codegen/src/generator/mod.rs index 4c072c9..f8bb17a 100644 --- a/codegen/src/generator/mod.rs +++ b/codegen/src/generator/mod.rs @@ -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 { diff --git a/codegen/src/google/protobuf/compiler/plugin.rs b/codegen/src/google/protobuf/compiler/plugin.rs index 4ff4a27..abfaee0 100644 --- a/codegen/src/google/protobuf/compiler/plugin.rs +++ b/codegen/src/google/protobuf/compiler/plugin.rs @@ -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 { - 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 { 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 { - 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 { 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 { - 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 { 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 { - 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 { 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 { - 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 { 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 { - 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 { 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, - insertion_point_offset: Option, - content_offset: Option, - generated_code_info_offset: Option, -} - -impl<'a> File<'a> { - pub fn new(data: &'a [u8]) -> crate::runtime::Result { - 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.builder.write_string(1, value)?; - self.name_written = true; - Ok(self) - } - - pub fn insertion_point(mut self, value: &str) -> crate::runtime::Result { - self.builder.write_string(2, value)?; - self.insertion_point_written = true; - Ok(self) - } - - pub fn content(mut self, value: &str) -> crate::runtime::Result { - 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.builder.write_bytes(16, value)?; - self.generated_code_info_written = true; - Ok(self) - } - - pub fn with(mut self, msg: &File<'_>) -> crate::runtime::Result { - 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 { - Ok(OwnedFile { data: buf }) + pub struct File<'a> { + accessor: crate::runtime::ProtoAccessor<'a>, + name_offset: Option, + insertion_point_offset: Option, + content_offset: Option, + generated_code_info_offset: Option, } - fn bytes(&self) -> bytes::Bytes { - self.data.clone() + impl<'a> File<'a> { + pub fn new(data: &'a [u8]) -> crate::runtime::Result { + 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.builder.write_string(1, value)?; + self.name_written = true; + Ok(self) + } + + pub fn insertion_point(mut self, value: &str) -> crate::runtime::Result { + self.builder.write_string(2, value)?; + self.insertion_point_written = true; + Ok(self) + } + + pub fn content(mut self, value: &str) -> crate::runtime::Result { + 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.builder.write_bytes(16, value)?; + self.generated_code_info_written = true; + Ok(self) + } + + pub fn with(mut self, msg: &File<'_>) -> crate::runtime::Result { + 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 { + Ok(OwnedFile { data: buf }) + } + + fn bytes(&self) -> bytes::Bytes { + self.data.clone() + } } } - -} - diff --git a/codegen/src/google/protobuf/descriptor.rs b/codegen/src/google/protobuf/descriptor.rs index f659858..15ad4e6 100644 --- a/codegen/src/google/protobuf/descriptor.rs +++ b/codegen/src/google/protobuf/descriptor.rs @@ -1,22 +1,23 @@ // @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}; - #[derive(Debug, Clone, Copy, PartialEq, Eq)] #[repr(i32)] @@ -92,14 +93,17 @@ impl<'a> FileDescriptorSet<'a> { for item in accessor.fields() { let (offset, tag, _) = item?; if tag.field_number == 1 { - 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, -file_start, file_end, + file_start, + file_end, }) } @@ -113,7 +117,6 @@ file_start, file_end, pub fn raw_fields(&self) -> crate::runtime::RawFieldIterator<'a> { self.accessor.raw_fields() } - } pub struct FileDescriptorSetBuilder<'b> { @@ -228,67 +231,105 @@ impl<'a> FileDescriptorProto<'a> { let mut edition_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 { package_offset = Some(offset); } + if tag.field_number == 1 { + name_offset = Some(offset); + } + if tag.field_number == 2 { + package_offset = Some(offset); + } if tag.field_number == 3 { - if dependency_start.is_none() { dependency_start = Some(offset); } + if dependency_start.is_none() { + dependency_start = Some(offset); + } dependency_end = Some(offset); } if tag.field_number == 10 { - if public_dependency_start.is_none() { public_dependency_start = Some(offset); } + if public_dependency_start.is_none() { + public_dependency_start = Some(offset); + } public_dependency_end = Some(offset); } if tag.field_number == 11 { - if weak_dependency_start.is_none() { weak_dependency_start = Some(offset); } + if weak_dependency_start.is_none() { + weak_dependency_start = Some(offset); + } weak_dependency_end = Some(offset); } if tag.field_number == 15 { - if option_dependency_start.is_none() { option_dependency_start = Some(offset); } + if option_dependency_start.is_none() { + option_dependency_start = Some(offset); + } option_dependency_end = Some(offset); } if tag.field_number == 4 { - if message_type_start.is_none() { message_type_start = Some(offset); } + if message_type_start.is_none() { + message_type_start = Some(offset); + } message_type_end = Some(offset); } if tag.field_number == 5 { - if enum_type_start.is_none() { enum_type_start = Some(offset); } + if enum_type_start.is_none() { + enum_type_start = Some(offset); + } enum_type_end = Some(offset); } if tag.field_number == 6 { - if service_start.is_none() { service_start = Some(offset); } + if service_start.is_none() { + service_start = Some(offset); + } service_end = Some(offset); } if tag.field_number == 7 { - if extension_start.is_none() { extension_start = Some(offset); } + if extension_start.is_none() { + extension_start = Some(offset); + } extension_end = Some(offset); } - if tag.field_number == 8 { options_offset = Some(offset); } - if tag.field_number == 9 { source_code_info_offset = Some(offset); } - if tag.field_number == 12 { syntax_offset = Some(offset); } - if tag.field_number == 14 { edition_offset = Some(offset); } + if tag.field_number == 8 { + options_offset = Some(offset); + } + if tag.field_number == 9 { + source_code_info_offset = Some(offset); + } + if tag.field_number == 12 { + syntax_offset = Some(offset); + } + if tag.field_number == 14 { + edition_offset = Some(offset); + } } Ok(Self { accessor, -name_offset, -package_offset, -dependency_start, dependency_end, -public_dependency_start, public_dependency_end, -weak_dependency_start, weak_dependency_end, -option_dependency_start, option_dependency_end, -message_type_start, message_type_end, -enum_type_start, enum_type_end, -service_start, service_end, -extension_start, extension_end, -options_offset, -source_code_info_offset, -syntax_offset, -edition_offset, + name_offset, + package_offset, + dependency_start, + dependency_end, + public_dependency_start, + public_dependency_end, + weak_dependency_start, + weak_dependency_end, + option_dependency_start, + option_dependency_end, + message_type_start, + message_type_end, + enum_type_start, + enum_type_end, + service_start, + service_end, + extension_start, + extension_end, + options_offset, + source_code_info_offset, + syntax_offset, + edition_offset, }) } pub fn name(&self) -> crate::runtime::Result<&'a str> { - let offset = self.name_offset.ok_or(crate::runtime::RotoError::FieldNotFound)?; + let offset = self + .name_offset + .ok_or(crate::runtime::RotoError::FieldNotFound)?; let (bytes, _) = self.accessor.get_value_at(offset)?; str::from_utf8(bytes).map_err(|_| crate::runtime::RotoError::WireFormatViolation) } @@ -297,10 +338,14 @@ edition_offset, self.name().or(Ok("")) } - pub fn has_name(&self) -> bool { self.name_offset.is_some() } + pub fn has_name(&self) -> bool { + self.name_offset.is_some() + } pub fn package(&self) -> crate::runtime::Result<&'a str> { - let offset = self.package_offset.ok_or(crate::runtime::RotoError::FieldNotFound)?; + let offset = self + .package_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) } @@ -309,7 +354,9 @@ edition_offset, self.package().or(Ok("")) } - pub fn has_package(&self) -> bool { self.package_offset.is_some() } + pub fn has_package(&self) -> bool { + self.package_offset.is_some() + } pub fn dependency(&self) -> crate::runtime::RepeatedFieldIterator<'a> { match (self.dependency_start, self.dependency_end) { @@ -368,7 +415,9 @@ edition_offset, } pub fn options(&self) -> crate::runtime::Result<&'a [u8]> { - let offset = self.options_offset.ok_or(crate::runtime::RotoError::FieldNotFound)?; + let offset = self + .options_offset + .ok_or(crate::runtime::RotoError::FieldNotFound)?; let (bytes, _) = self.accessor.get_value_at(offset)?; Ok(bytes) } @@ -377,10 +426,14 @@ edition_offset, self.options().or(Ok(&[])) } - pub fn has_options(&self) -> bool { self.options_offset.is_some() } + pub fn has_options(&self) -> bool { + self.options_offset.is_some() + } pub fn source_code_info(&self) -> crate::runtime::Result<&'a [u8]> { - let offset = self.source_code_info_offset.ok_or(crate::runtime::RotoError::FieldNotFound)?; + let offset = self + .source_code_info_offset + .ok_or(crate::runtime::RotoError::FieldNotFound)?; let (bytes, _) = self.accessor.get_value_at(offset)?; Ok(bytes) } @@ -389,10 +442,14 @@ edition_offset, self.source_code_info().or(Ok(&[])) } - pub fn has_source_code_info(&self) -> bool { self.source_code_info_offset.is_some() } + pub fn has_source_code_info(&self) -> bool { + self.source_code_info_offset.is_some() + } pub fn syntax(&self) -> crate::runtime::Result<&'a str> { - let offset = self.syntax_offset.ok_or(crate::runtime::RotoError::FieldNotFound)?; + let offset = self + .syntax_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) } @@ -401,24 +458,31 @@ edition_offset, self.syntax().or(Ok("")) } - pub fn has_syntax(&self) -> bool { self.syntax_offset.is_some() } + pub fn has_syntax(&self) -> bool { + self.syntax_offset.is_some() + } pub fn edition(&self) -> crate::runtime::Result { - let offset = self.edition_offset.ok_or(crate::runtime::RotoError::FieldNotFound)?; + let offset = self + .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 u64).map_err(|_| crate::runtime::RotoError::WireFormatViolation) + crate::runtime::read_varint(bytes) + .map(|(v, _)| v as u64) + .map_err(|_| crate::runtime::RotoError::WireFormatViolation) } pub fn edition_or_default(&self) -> crate::runtime::Result { self.edition().or(Ok(0)) } - pub fn has_edition(&self) -> bool { self.edition_offset.is_some() } + pub fn has_edition(&self) -> bool { + self.edition_offset.is_some() + } pub fn raw_fields(&self) -> crate::runtime::RawFieldIterator<'a> { self.accessor.raw_fields() } - } pub struct FileDescriptorProtoBuilder<'b> { @@ -644,61 +708,93 @@ impl<'a> DescriptorProto<'a> { let mut visibility_offset = None; for item in accessor.fields() { let (offset, tag, _) = item?; - if tag.field_number == 1 { name_offset = Some(offset); } + if tag.field_number == 1 { + name_offset = Some(offset); + } if tag.field_number == 2 { - if field_start.is_none() { field_start = Some(offset); } + if field_start.is_none() { + field_start = Some(offset); + } field_end = Some(offset); } if tag.field_number == 6 { - if extension_start.is_none() { extension_start = Some(offset); } + if extension_start.is_none() { + extension_start = Some(offset); + } extension_end = Some(offset); } if tag.field_number == 3 { - if nested_type_start.is_none() { nested_type_start = Some(offset); } + if nested_type_start.is_none() { + nested_type_start = Some(offset); + } nested_type_end = Some(offset); } if tag.field_number == 4 { - if enum_type_start.is_none() { enum_type_start = Some(offset); } + if enum_type_start.is_none() { + enum_type_start = Some(offset); + } enum_type_end = Some(offset); } if tag.field_number == 5 { - if extension_range_start.is_none() { extension_range_start = Some(offset); } + if extension_range_start.is_none() { + extension_range_start = Some(offset); + } extension_range_end = Some(offset); } if tag.field_number == 8 { - if oneof_decl_start.is_none() { oneof_decl_start = Some(offset); } + if oneof_decl_start.is_none() { + oneof_decl_start = Some(offset); + } oneof_decl_end = Some(offset); } - if tag.field_number == 7 { options_offset = Some(offset); } + if tag.field_number == 7 { + options_offset = Some(offset); + } if tag.field_number == 9 { - if reserved_range_start.is_none() { reserved_range_start = Some(offset); } + if reserved_range_start.is_none() { + reserved_range_start = Some(offset); + } reserved_range_end = Some(offset); } if tag.field_number == 10 { - if reserved_name_start.is_none() { reserved_name_start = Some(offset); } + if reserved_name_start.is_none() { + reserved_name_start = Some(offset); + } reserved_name_end = Some(offset); } - if tag.field_number == 11 { visibility_offset = Some(offset); } + if tag.field_number == 11 { + visibility_offset = Some(offset); + } } Ok(Self { accessor, -name_offset, -field_start, field_end, -extension_start, extension_end, -nested_type_start, nested_type_end, -enum_type_start, enum_type_end, -extension_range_start, extension_range_end, -oneof_decl_start, oneof_decl_end, -options_offset, -reserved_range_start, reserved_range_end, -reserved_name_start, reserved_name_end, -visibility_offset, + name_offset, + field_start, + field_end, + extension_start, + extension_end, + nested_type_start, + nested_type_end, + enum_type_start, + enum_type_end, + extension_range_start, + extension_range_end, + oneof_decl_start, + oneof_decl_end, + options_offset, + reserved_range_start, + reserved_range_end, + reserved_name_start, + reserved_name_end, + visibility_offset, }) } pub fn name(&self) -> crate::runtime::Result<&'a str> { - let offset = self.name_offset.ok_or(crate::runtime::RotoError::FieldNotFound)?; + let offset = self + .name_offset + .ok_or(crate::runtime::RotoError::FieldNotFound)?; let (bytes, _) = self.accessor.get_value_at(offset)?; str::from_utf8(bytes).map_err(|_| crate::runtime::RotoError::WireFormatViolation) } @@ -707,7 +803,9 @@ visibility_offset, self.name().or(Ok("")) } - pub fn has_name(&self) -> bool { self.name_offset.is_some() } + pub fn has_name(&self) -> bool { + self.name_offset.is_some() + } pub fn field(&self) -> crate::runtime::RepeatedFieldIterator<'a> { match (self.field_start, self.field_end) { @@ -752,7 +850,9 @@ visibility_offset, } pub fn options(&self) -> crate::runtime::Result<&'a [u8]> { - let offset = self.options_offset.ok_or(crate::runtime::RotoError::FieldNotFound)?; + let offset = self + .options_offset + .ok_or(crate::runtime::RotoError::FieldNotFound)?; let (bytes, _) = self.accessor.get_value_at(offset)?; Ok(bytes) } @@ -761,7 +861,9 @@ visibility_offset, self.options().or(Ok(&[])) } - pub fn has_options(&self) -> bool { self.options_offset.is_some() } + pub fn has_options(&self) -> bool { + self.options_offset.is_some() + } pub fn reserved_range(&self) -> crate::runtime::RepeatedFieldIterator<'a> { match (self.reserved_range_start, self.reserved_range_end) { @@ -778,21 +880,26 @@ visibility_offset, } pub fn visibility(&self) -> crate::runtime::Result { - let offset = self.visibility_offset.ok_or(crate::runtime::RotoError::FieldNotFound)?; + let offset = self + .visibility_offset + .ok_or(crate::runtime::RotoError::FieldNotFound)?; let (bytes, _) = self.accessor.get_value_at(offset)?; - crate::runtime::read_varint(bytes).map(|(v, _)| v as u64).map_err(|_| crate::runtime::RotoError::WireFormatViolation) + crate::runtime::read_varint(bytes) + .map(|(v, _)| v as u64) + .map_err(|_| crate::runtime::RotoError::WireFormatViolation) } pub fn visibility_or_default(&self) -> crate::runtime::Result { self.visibility().or(Ok(0)) } - pub fn has_visibility(&self) -> bool { self.visibility_offset.is_some() } + pub fn has_visibility(&self) -> bool { + self.visibility_offset.is_some() + } pub fn raw_fields(&self) -> crate::runtime::RawFieldIterator<'a> { self.accessor.raw_fields() } - } pub struct DescriptorProtoBuilder<'b> { @@ -945,275 +1052,310 @@ impl crate::runtime::RotoMessage for OwnedDescriptorProto { } pub mod descriptor_proto { -pub struct ExtensionRange<'a> { - accessor: crate::runtime::ProtoAccessor<'a>, - start_offset: Option, - end_offset: Option, - options_offset: Option, -} + pub struct ExtensionRange<'a> { + accessor: crate::runtime::ProtoAccessor<'a>, + start_offset: Option, + end_offset: Option, + options_offset: Option, + } -impl<'a> ExtensionRange<'a> { - pub fn new(data: &'a [u8]) -> crate::runtime::Result { - let accessor = crate::runtime::ProtoAccessor::new(data)?; - let mut start_offset = None; - let mut end_offset = None; - let mut options_offset = None; - for item in accessor.fields() { - let (offset, tag, _) = item?; - if tag.field_number == 1 { start_offset = Some(offset); } - if tag.field_number == 2 { end_offset = Some(offset); } - if tag.field_number == 3 { options_offset = Some(offset); } + impl<'a> ExtensionRange<'a> { + pub fn new(data: &'a [u8]) -> crate::runtime::Result { + let accessor = crate::runtime::ProtoAccessor::new(data)?; + let mut start_offset = None; + let mut end_offset = None; + let mut options_offset = None; + for item in accessor.fields() { + let (offset, tag, _) = item?; + if tag.field_number == 1 { + start_offset = Some(offset); + } + if tag.field_number == 2 { + end_offset = Some(offset); + } + if tag.field_number == 3 { + options_offset = Some(offset); + } + } + + Ok(Self { + accessor, + start_offset, + end_offset, + options_offset, + }) } - Ok(Self { - accessor, -start_offset, -end_offset, -options_offset, - }) - } + pub fn start(&self) -> crate::runtime::Result { + let offset = self + .start_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) + } - pub fn start(&self) -> crate::runtime::Result { - let offset = self.start_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) - } + pub fn start_or_default(&self) -> crate::runtime::Result { + self.start().or(Ok(0)) + } - pub fn start_or_default(&self) -> crate::runtime::Result { - self.start().or(Ok(0)) - } + pub fn has_start(&self) -> bool { + self.start_offset.is_some() + } - pub fn has_start(&self) -> bool { self.start_offset.is_some() } + pub fn end(&self) -> crate::runtime::Result { + let offset = self + .end_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) + } - pub fn end(&self) -> crate::runtime::Result { - let offset = self.end_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) - } + pub fn end_or_default(&self) -> crate::runtime::Result { + self.end().or(Ok(0)) + } - pub fn end_or_default(&self) -> crate::runtime::Result { - self.end().or(Ok(0)) - } + pub fn has_end(&self) -> bool { + self.end_offset.is_some() + } - pub fn has_end(&self) -> bool { self.end_offset.is_some() } + pub fn options(&self) -> crate::runtime::Result<&'a [u8]> { + let offset = self + .options_offset + .ok_or(crate::runtime::RotoError::FieldNotFound)?; + let (bytes, _) = self.accessor.get_value_at(offset)?; + Ok(bytes) + } - pub fn options(&self) -> crate::runtime::Result<&'a [u8]> { - let offset = self.options_offset.ok_or(crate::runtime::RotoError::FieldNotFound)?; - let (bytes, _) = self.accessor.get_value_at(offset)?; - Ok(bytes) - } + pub fn options_or_default(&self) -> crate::runtime::Result<&'a [u8]> { + self.options().or(Ok(&[])) + } - pub fn options_or_default(&self) -> crate::runtime::Result<&'a [u8]> { - self.options().or(Ok(&[])) - } + pub fn has_options(&self) -> bool { + self.options_offset.is_some() + } - pub fn has_options(&self) -> bool { self.options_offset.is_some() } - - pub fn raw_fields(&self) -> crate::runtime::RawFieldIterator<'a> { - self.accessor.raw_fields() - } - -} - -pub struct ExtensionRangeBuilder<'b> { - builder: crate::runtime::ProtoBuilder<'b>, - start_written: bool, - end_written: bool, - options_written: bool, -} - -impl<'b> ExtensionRangeBuilder<'b> { - pub fn builder(buf: &mut [u8]) -> ExtensionRangeBuilder<'_> { - ExtensionRangeBuilder { - builder: crate::runtime::ProtoBuilder::new(buf), - start_written: false, - end_written: false, - options_written: false, + pub fn raw_fields(&self) -> crate::runtime::RawFieldIterator<'a> { + self.accessor.raw_fields() } } - pub fn start(mut self, value: i32) -> crate::runtime::Result { - self.builder.write_int32(1, value)?; - self.start_written = true; - Ok(self) + pub struct ExtensionRangeBuilder<'b> { + builder: crate::runtime::ProtoBuilder<'b>, + start_written: bool, + end_written: bool, + options_written: bool, } - pub fn end(mut self, value: i32) -> crate::runtime::Result { - self.builder.write_int32(2, value)?; - self.end_written = true; - Ok(self) - } - - pub fn options(mut self, value: &[u8]) -> crate::runtime::Result { - self.builder.write_bytes(3, value)?; - self.options_written = true; - Ok(self) - } - - pub fn with(mut self, msg: &ExtensionRange<'_>) -> crate::runtime::Result { - for item in msg.raw_fields() { - let (field_number, raw_bytes) = item?; - let is_written = match field_number { - 1 => self.start_written, - 2 => self.end_written, - 3 => self.options_written, - _ => false, - }; - if !is_written { - self.builder.write_raw(raw_bytes)?; + impl<'b> ExtensionRangeBuilder<'b> { + pub fn builder(buf: &mut [u8]) -> ExtensionRangeBuilder<'_> { + ExtensionRangeBuilder { + builder: crate::runtime::ProtoBuilder::new(buf), + start_written: false, + end_written: false, + options_written: false, } } - Ok(self) - } - pub fn finish(self) -> crate::runtime::Result<&'b mut [u8]> { - self.builder.finish() - } -} - -pub struct OwnedExtensionRange { - pub data: bytes::Bytes, -} - -impl crate::runtime::RotoOwned for OwnedExtensionRange { - type Reader<'a> = ExtensionRange<'a>; - fn reader(&self) -> ExtensionRange<'_> { - ExtensionRange::new(&self.data).expect("failed to create reader") - } -} - -impl crate::runtime::RotoMessage for OwnedExtensionRange { - fn decode(buf: bytes::Bytes) -> crate::runtime::Result { - Ok(OwnedExtensionRange { data: buf }) - } - - fn bytes(&self) -> bytes::Bytes { - self.data.clone() - } -} - -pub struct ReservedRange<'a> { - accessor: crate::runtime::ProtoAccessor<'a>, - start_offset: Option, - end_offset: Option, -} - -impl<'a> ReservedRange<'a> { - pub fn new(data: &'a [u8]) -> crate::runtime::Result { - let accessor = crate::runtime::ProtoAccessor::new(data)?; - let mut start_offset = None; - let mut end_offset = None; - for item in accessor.fields() { - let (offset, tag, _) = item?; - if tag.field_number == 1 { start_offset = Some(offset); } - if tag.field_number == 2 { end_offset = Some(offset); } + pub fn start(mut self, value: i32) -> crate::runtime::Result { + self.builder.write_int32(1, value)?; + self.start_written = true; + Ok(self) } - Ok(Self { - accessor, -start_offset, -end_offset, - }) - } + pub fn end(mut self, value: i32) -> crate::runtime::Result { + self.builder.write_int32(2, value)?; + self.end_written = true; + Ok(self) + } - pub fn start(&self) -> crate::runtime::Result { - let offset = self.start_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) - } + pub fn options(mut self, value: &[u8]) -> crate::runtime::Result { + self.builder.write_bytes(3, value)?; + self.options_written = true; + Ok(self) + } - pub fn start_or_default(&self) -> crate::runtime::Result { - self.start().or(Ok(0)) - } + pub fn with(mut self, msg: &ExtensionRange<'_>) -> crate::runtime::Result { + for item in msg.raw_fields() { + let (field_number, raw_bytes) = item?; + let is_written = match field_number { + 1 => self.start_written, + 2 => self.end_written, + 3 => self.options_written, + _ => false, + }; + if !is_written { + self.builder.write_raw(raw_bytes)?; + } + } + Ok(self) + } - pub fn has_start(&self) -> bool { self.start_offset.is_some() } - - pub fn end(&self) -> crate::runtime::Result { - let offset = self.end_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) - } - - pub fn end_or_default(&self) -> crate::runtime::Result { - self.end().or(Ok(0)) - } - - pub fn has_end(&self) -> bool { self.end_offset.is_some() } - - pub fn raw_fields(&self) -> crate::runtime::RawFieldIterator<'a> { - self.accessor.raw_fields() - } - -} - -pub struct ReservedRangeBuilder<'b> { - builder: crate::runtime::ProtoBuilder<'b>, - start_written: bool, - end_written: bool, -} - -impl<'b> ReservedRangeBuilder<'b> { - pub fn builder(buf: &mut [u8]) -> ReservedRangeBuilder<'_> { - ReservedRangeBuilder { - builder: crate::runtime::ProtoBuilder::new(buf), - start_written: false, - end_written: false, + pub fn finish(self) -> crate::runtime::Result<&'b mut [u8]> { + self.builder.finish() } } - pub fn start(mut self, value: i32) -> crate::runtime::Result { - self.builder.write_int32(1, value)?; - self.start_written = true; - Ok(self) + pub struct OwnedExtensionRange { + pub data: bytes::Bytes, } - pub fn end(mut self, value: i32) -> crate::runtime::Result { - self.builder.write_int32(2, value)?; - self.end_written = true; - Ok(self) + impl crate::runtime::RotoOwned for OwnedExtensionRange { + type Reader<'a> = ExtensionRange<'a>; + fn reader(&self) -> ExtensionRange<'_> { + ExtensionRange::new(&self.data).expect("failed to create reader") + } } - pub fn with(mut self, msg: &ReservedRange<'_>) -> crate::runtime::Result { - for item in msg.raw_fields() { - let (field_number, raw_bytes) = item?; - let is_written = match field_number { - 1 => self.start_written, - 2 => self.end_written, - _ => false, - }; - if !is_written { - self.builder.write_raw(raw_bytes)?; + impl crate::runtime::RotoMessage for OwnedExtensionRange { + fn decode(buf: bytes::Bytes) -> crate::runtime::Result { + Ok(OwnedExtensionRange { data: buf }) + } + + fn bytes(&self) -> bytes::Bytes { + self.data.clone() + } + } + + pub struct ReservedRange<'a> { + accessor: crate::runtime::ProtoAccessor<'a>, + start_offset: Option, + end_offset: Option, + } + + impl<'a> ReservedRange<'a> { + pub fn new(data: &'a [u8]) -> crate::runtime::Result { + let accessor = crate::runtime::ProtoAccessor::new(data)?; + let mut start_offset = None; + let mut end_offset = None; + for item in accessor.fields() { + let (offset, tag, _) = item?; + if tag.field_number == 1 { + start_offset = Some(offset); + } + if tag.field_number == 2 { + end_offset = Some(offset); + } + } + + Ok(Self { + accessor, + start_offset, + end_offset, + }) + } + + pub fn start(&self) -> crate::runtime::Result { + let offset = self + .start_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) + } + + pub fn start_or_default(&self) -> crate::runtime::Result { + self.start().or(Ok(0)) + } + + pub fn has_start(&self) -> bool { + self.start_offset.is_some() + } + + pub fn end(&self) -> crate::runtime::Result { + let offset = self + .end_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) + } + + pub fn end_or_default(&self) -> crate::runtime::Result { + self.end().or(Ok(0)) + } + + pub fn has_end(&self) -> bool { + self.end_offset.is_some() + } + + pub fn raw_fields(&self) -> crate::runtime::RawFieldIterator<'a> { + self.accessor.raw_fields() + } + } + + pub struct ReservedRangeBuilder<'b> { + builder: crate::runtime::ProtoBuilder<'b>, + start_written: bool, + end_written: bool, + } + + impl<'b> ReservedRangeBuilder<'b> { + pub fn builder(buf: &mut [u8]) -> ReservedRangeBuilder<'_> { + ReservedRangeBuilder { + builder: crate::runtime::ProtoBuilder::new(buf), + start_written: false, + end_written: false, } } - Ok(self) + + pub fn start(mut self, value: i32) -> crate::runtime::Result { + self.builder.write_int32(1, value)?; + self.start_written = true; + Ok(self) + } + + pub fn end(mut self, value: i32) -> crate::runtime::Result { + self.builder.write_int32(2, value)?; + self.end_written = true; + Ok(self) + } + + pub fn with(mut self, msg: &ReservedRange<'_>) -> crate::runtime::Result { + for item in msg.raw_fields() { + let (field_number, raw_bytes) = item?; + let is_written = match field_number { + 1 => self.start_written, + 2 => self.end_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 fn finish(self) -> crate::runtime::Result<&'b mut [u8]> { - self.builder.finish() - } -} - -pub struct OwnedReservedRange { - pub data: bytes::Bytes, -} - -impl crate::runtime::RotoOwned for OwnedReservedRange { - type Reader<'a> = ReservedRange<'a>; - fn reader(&self) -> ReservedRange<'_> { - ReservedRange::new(&self.data).expect("failed to create reader") - } -} - -impl crate::runtime::RotoMessage for OwnedReservedRange { - fn decode(buf: bytes::Bytes) -> crate::runtime::Result { - Ok(OwnedReservedRange { data: buf }) + pub struct OwnedReservedRange { + pub data: bytes::Bytes, } - fn bytes(&self) -> bytes::Bytes { - self.data.clone() + impl crate::runtime::RotoOwned for OwnedReservedRange { + type Reader<'a> = ReservedRange<'a>; + fn reader(&self) -> ReservedRange<'_> { + ReservedRange::new(&self.data).expect("failed to create reader") + } } -} + impl crate::runtime::RotoMessage for OwnedReservedRange { + fn decode(buf: bytes::Bytes) -> crate::runtime::Result { + Ok(OwnedReservedRange { data: buf }) + } + + fn bytes(&self) -> bytes::Bytes { + self.data.clone() + } + } } pub struct ExtensionRangeOptions<'a> { @@ -1238,28 +1380,41 @@ impl<'a> ExtensionRangeOptions<'a> { for item in accessor.fields() { let (offset, tag, _) = item?; if tag.field_number == 999 { - if uninterpreted_option_start.is_none() { uninterpreted_option_start = Some(offset); } + if uninterpreted_option_start.is_none() { + uninterpreted_option_start = Some(offset); + } uninterpreted_option_end = Some(offset); } if tag.field_number == 2 { - if declaration_start.is_none() { declaration_start = Some(offset); } + if declaration_start.is_none() { + declaration_start = Some(offset); + } declaration_end = Some(offset); } - if tag.field_number == 50 { features_offset = Some(offset); } - if tag.field_number == 3 { verification_offset = Some(offset); } + if tag.field_number == 50 { + features_offset = Some(offset); + } + if tag.field_number == 3 { + verification_offset = Some(offset); + } } Ok(Self { accessor, -uninterpreted_option_start, uninterpreted_option_end, -declaration_start, declaration_end, -features_offset, -verification_offset, + uninterpreted_option_start, + uninterpreted_option_end, + declaration_start, + declaration_end, + features_offset, + verification_offset, }) } pub fn uninterpreted_option(&self) -> crate::runtime::RepeatedFieldIterator<'a> { - match (self.uninterpreted_option_start, self.uninterpreted_option_end) { + match ( + self.uninterpreted_option_start, + self.uninterpreted_option_end, + ) { (Some(start), Some(end)) => self.accessor.iter_repeated_range(999, start, end), _ => self.accessor.iter_repeated(999), } @@ -1273,7 +1428,9 @@ verification_offset, } pub fn features(&self) -> crate::runtime::Result<&'a [u8]> { - let offset = self.features_offset.ok_or(crate::runtime::RotoError::FieldNotFound)?; + let offset = self + .features_offset + .ok_or(crate::runtime::RotoError::FieldNotFound)?; let (bytes, _) = self.accessor.get_value_at(offset)?; Ok(bytes) } @@ -1282,24 +1439,31 @@ verification_offset, self.features().or(Ok(&[])) } - pub fn has_features(&self) -> bool { self.features_offset.is_some() } + pub fn has_features(&self) -> bool { + self.features_offset.is_some() + } pub fn verification(&self) -> crate::runtime::Result { - let offset = self.verification_offset.ok_or(crate::runtime::RotoError::FieldNotFound)?; + let offset = self + .verification_offset + .ok_or(crate::runtime::RotoError::FieldNotFound)?; let (bytes, _) = self.accessor.get_value_at(offset)?; - crate::runtime::read_varint(bytes).map(|(v, _)| v as u64).map_err(|_| crate::runtime::RotoError::WireFormatViolation) + crate::runtime::read_varint(bytes) + .map(|(v, _)| v as u64) + .map_err(|_| crate::runtime::RotoError::WireFormatViolation) } pub fn verification_or_default(&self) -> crate::runtime::Result { self.verification().or(Ok(0)) } - pub fn has_verification(&self) -> bool { self.verification_offset.is_some() } + pub fn has_verification(&self) -> bool { + self.verification_offset.is_some() + } pub fn raw_fields(&self) -> crate::runtime::RawFieldIterator<'a> { self.accessor.raw_fields() } - } pub struct ExtensionRangeOptionsBuilder<'b> { @@ -1389,220 +1553,254 @@ impl crate::runtime::RotoMessage for OwnedExtensionRangeOptions { } pub mod extension_range_options { -#[derive(Debug, Clone, Copy, PartialEq, Eq)] -#[repr(i32)] -pub enum VerificationState { - DECLARATION = 0, - UNVERIFIED = 1, -} - -impl VerificationState { - pub fn from_i32(value: i32) -> Self { - match value { - 0 => VerificationState::DECLARATION, - 1 => VerificationState::UNVERIFIED, - _ => VerificationState::DECLARATION, - } - } -} - -pub struct Declaration<'a> { - accessor: crate::runtime::ProtoAccessor<'a>, - number_offset: Option, - full_name_offset: Option, - type_offset: Option, - reserved_offset: Option, - repeated_offset: Option, -} - -impl<'a> Declaration<'a> { - pub fn new(data: &'a [u8]) -> crate::runtime::Result { - let accessor = crate::runtime::ProtoAccessor::new(data)?; - let mut number_offset = None; - let mut full_name_offset = None; - let mut type_offset = None; - let mut reserved_offset = None; - let mut repeated_offset = None; - for item in accessor.fields() { - let (offset, tag, _) = item?; - if tag.field_number == 1 { number_offset = Some(offset); } - if tag.field_number == 2 { full_name_offset = Some(offset); } - if tag.field_number == 3 { type_offset = Some(offset); } - if tag.field_number == 5 { reserved_offset = Some(offset); } - if tag.field_number == 6 { repeated_offset = Some(offset); } - } - - Ok(Self { - accessor, -number_offset, -full_name_offset, -type_offset, -reserved_offset, -repeated_offset, - }) + #[derive(Debug, Clone, Copy, PartialEq, Eq)] + #[repr(i32)] + pub enum VerificationState { + DECLARATION = 0, + UNVERIFIED = 1, } - pub fn number(&self) -> crate::runtime::Result { - let offset = self.number_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) - } - - pub fn number_or_default(&self) -> crate::runtime::Result { - self.number().or(Ok(0)) - } - - pub fn has_number(&self) -> bool { self.number_offset.is_some() } - - pub fn full_name(&self) -> crate::runtime::Result<&'a str> { - let offset = self.full_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 full_name_or_default(&self) -> crate::runtime::Result<&'a str> { - self.full_name().or(Ok("")) - } - - pub fn has_full_name(&self) -> bool { self.full_name_offset.is_some() } - - pub fn r#type(&self) -> crate::runtime::Result<&'a str> { - let offset = self.type_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 r#type_or_default(&self) -> crate::runtime::Result<&'a str> { - self.r#type().or(Ok("")) - } - - pub fn has_type(&self) -> bool { self.type_offset.is_some() } - - pub fn reserved(&self) -> crate::runtime::Result { - let offset = self.reserved_offset.ok_or(crate::runtime::RotoError::FieldNotFound)?; - let (bytes, _) = self.accessor.get_value_at(offset)?; - crate::runtime::read_varint(bytes).map(|(v, _)| v != 0).map_err(|_| crate::runtime::RotoError::WireFormatViolation) - } - - pub fn reserved_or_default(&self) -> crate::runtime::Result { - self.reserved().or(Ok(false)) - } - - pub fn has_reserved(&self) -> bool { self.reserved_offset.is_some() } - - pub fn repeated(&self) -> crate::runtime::Result { - let offset = self.repeated_offset.ok_or(crate::runtime::RotoError::FieldNotFound)?; - let (bytes, _) = self.accessor.get_value_at(offset)?; - crate::runtime::read_varint(bytes).map(|(v, _)| v != 0).map_err(|_| crate::runtime::RotoError::WireFormatViolation) - } - - pub fn repeated_or_default(&self) -> crate::runtime::Result { - self.repeated().or(Ok(false)) - } - - pub fn has_repeated(&self) -> bool { self.repeated_offset.is_some() } - - pub fn raw_fields(&self) -> crate::runtime::RawFieldIterator<'a> { - self.accessor.raw_fields() - } - -} - -pub struct DeclarationBuilder<'b> { - builder: crate::runtime::ProtoBuilder<'b>, - number_written: bool, - full_name_written: bool, - type_written: bool, - reserved_written: bool, - repeated_written: bool, -} - -impl<'b> DeclarationBuilder<'b> { - pub fn builder(buf: &mut [u8]) -> DeclarationBuilder<'_> { - DeclarationBuilder { - builder: crate::runtime::ProtoBuilder::new(buf), - number_written: false, - full_name_written: false, - type_written: false, - reserved_written: false, - repeated_written: false, - } - } - - pub fn number(mut self, value: i32) -> crate::runtime::Result { - self.builder.write_int32(1, value)?; - self.number_written = true; - Ok(self) - } - - pub fn full_name(mut self, value: &str) -> crate::runtime::Result { - self.builder.write_string(2, value)?; - self.full_name_written = true; - Ok(self) - } - - pub fn r#type(mut self, value: &str) -> crate::runtime::Result { - self.builder.write_string(3, value)?; - self.type_written = true; - Ok(self) - } - - pub fn reserved(mut self, value: u64) -> crate::runtime::Result { - self.builder.write_varint(5, value)?; - self.reserved_written = true; - Ok(self) - } - - pub fn repeated(mut self, value: u64) -> crate::runtime::Result { - self.builder.write_varint(6, value)?; - self.repeated_written = true; - Ok(self) - } - - pub fn with(mut self, msg: &Declaration<'_>) -> crate::runtime::Result { - for item in msg.raw_fields() { - let (field_number, raw_bytes) = item?; - let is_written = match field_number { - 1 => self.number_written, - 2 => self.full_name_written, - 3 => self.type_written, - 5 => self.reserved_written, - 6 => self.repeated_written, - _ => false, - }; - if !is_written { - self.builder.write_raw(raw_bytes)?; + impl VerificationState { + pub fn from_i32(value: i32) -> Self { + match value { + 0 => VerificationState::DECLARATION, + 1 => VerificationState::UNVERIFIED, + _ => VerificationState::DECLARATION, } } - Ok(self) } - pub fn finish(self) -> crate::runtime::Result<&'b mut [u8]> { - self.builder.finish() - } -} - -pub struct OwnedDeclaration { - pub data: bytes::Bytes, -} - -impl crate::runtime::RotoOwned for OwnedDeclaration { - type Reader<'a> = Declaration<'a>; - fn reader(&self) -> Declaration<'_> { - Declaration::new(&self.data).expect("failed to create reader") - } -} - -impl crate::runtime::RotoMessage for OwnedDeclaration { - fn decode(buf: bytes::Bytes) -> crate::runtime::Result { - Ok(OwnedDeclaration { data: buf }) + pub struct Declaration<'a> { + accessor: crate::runtime::ProtoAccessor<'a>, + number_offset: Option, + full_name_offset: Option, + type_offset: Option, + reserved_offset: Option, + repeated_offset: Option, } - fn bytes(&self) -> bytes::Bytes { - self.data.clone() - } -} + impl<'a> Declaration<'a> { + pub fn new(data: &'a [u8]) -> crate::runtime::Result { + let accessor = crate::runtime::ProtoAccessor::new(data)?; + let mut number_offset = None; + let mut full_name_offset = None; + let mut type_offset = None; + let mut reserved_offset = None; + let mut repeated_offset = None; + for item in accessor.fields() { + let (offset, tag, _) = item?; + if tag.field_number == 1 { + number_offset = Some(offset); + } + if tag.field_number == 2 { + full_name_offset = Some(offset); + } + if tag.field_number == 3 { + type_offset = Some(offset); + } + if tag.field_number == 5 { + reserved_offset = Some(offset); + } + if tag.field_number == 6 { + repeated_offset = Some(offset); + } + } + Ok(Self { + accessor, + number_offset, + full_name_offset, + type_offset, + reserved_offset, + repeated_offset, + }) + } + + pub fn number(&self) -> crate::runtime::Result { + let offset = self + .number_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) + } + + pub fn number_or_default(&self) -> crate::runtime::Result { + self.number().or(Ok(0)) + } + + pub fn has_number(&self) -> bool { + self.number_offset.is_some() + } + + pub fn full_name(&self) -> crate::runtime::Result<&'a str> { + let offset = self + .full_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 full_name_or_default(&self) -> crate::runtime::Result<&'a str> { + self.full_name().or(Ok("")) + } + + pub fn has_full_name(&self) -> bool { + self.full_name_offset.is_some() + } + + pub fn r#type(&self) -> crate::runtime::Result<&'a str> { + let offset = self + .type_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 r#type_or_default(&self) -> crate::runtime::Result<&'a str> { + self.r#type().or(Ok("")) + } + + pub fn has_type(&self) -> bool { + self.type_offset.is_some() + } + + pub fn reserved(&self) -> crate::runtime::Result { + let offset = self + .reserved_offset + .ok_or(crate::runtime::RotoError::FieldNotFound)?; + let (bytes, _) = self.accessor.get_value_at(offset)?; + crate::runtime::read_varint(bytes) + .map(|(v, _)| v != 0) + .map_err(|_| crate::runtime::RotoError::WireFormatViolation) + } + + pub fn reserved_or_default(&self) -> crate::runtime::Result { + self.reserved().or(Ok(false)) + } + + pub fn has_reserved(&self) -> bool { + self.reserved_offset.is_some() + } + + pub fn repeated(&self) -> crate::runtime::Result { + let offset = self + .repeated_offset + .ok_or(crate::runtime::RotoError::FieldNotFound)?; + let (bytes, _) = self.accessor.get_value_at(offset)?; + crate::runtime::read_varint(bytes) + .map(|(v, _)| v != 0) + .map_err(|_| crate::runtime::RotoError::WireFormatViolation) + } + + pub fn repeated_or_default(&self) -> crate::runtime::Result { + self.repeated().or(Ok(false)) + } + + pub fn has_repeated(&self) -> bool { + self.repeated_offset.is_some() + } + + pub fn raw_fields(&self) -> crate::runtime::RawFieldIterator<'a> { + self.accessor.raw_fields() + } + } + + pub struct DeclarationBuilder<'b> { + builder: crate::runtime::ProtoBuilder<'b>, + number_written: bool, + full_name_written: bool, + type_written: bool, + reserved_written: bool, + repeated_written: bool, + } + + impl<'b> DeclarationBuilder<'b> { + pub fn builder(buf: &mut [u8]) -> DeclarationBuilder<'_> { + DeclarationBuilder { + builder: crate::runtime::ProtoBuilder::new(buf), + number_written: false, + full_name_written: false, + type_written: false, + reserved_written: false, + repeated_written: false, + } + } + + pub fn number(mut self, value: i32) -> crate::runtime::Result { + self.builder.write_int32(1, value)?; + self.number_written = true; + Ok(self) + } + + pub fn full_name(mut self, value: &str) -> crate::runtime::Result { + self.builder.write_string(2, value)?; + self.full_name_written = true; + Ok(self) + } + + pub fn r#type(mut self, value: &str) -> crate::runtime::Result { + self.builder.write_string(3, value)?; + self.type_written = true; + Ok(self) + } + + pub fn reserved(mut self, value: u64) -> crate::runtime::Result { + self.builder.write_varint(5, value)?; + self.reserved_written = true; + Ok(self) + } + + pub fn repeated(mut self, value: u64) -> crate::runtime::Result { + self.builder.write_varint(6, value)?; + self.repeated_written = true; + Ok(self) + } + + pub fn with(mut self, msg: &Declaration<'_>) -> crate::runtime::Result { + for item in msg.raw_fields() { + let (field_number, raw_bytes) = item?; + let is_written = match field_number { + 1 => self.number_written, + 2 => self.full_name_written, + 3 => self.type_written, + 5 => self.reserved_written, + 6 => self.repeated_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 OwnedDeclaration { + pub data: bytes::Bytes, + } + + impl crate::runtime::RotoOwned for OwnedDeclaration { + type Reader<'a> = Declaration<'a>; + fn reader(&self) -> Declaration<'_> { + Declaration::new(&self.data).expect("failed to create reader") + } + } + + impl crate::runtime::RotoMessage for OwnedDeclaration { + fn decode(buf: bytes::Bytes) -> crate::runtime::Result { + Ok(OwnedDeclaration { data: buf }) + } + + fn bytes(&self) -> bytes::Bytes { + self.data.clone() + } + } } pub struct FieldDescriptorProto<'a> { @@ -1636,37 +1834,61 @@ impl<'a> FieldDescriptorProto<'a> { let mut proto3_optional_offset = None; for item in accessor.fields() { let (offset, tag, _) = item?; - if tag.field_number == 1 { name_offset = Some(offset); } - if tag.field_number == 3 { number_offset = Some(offset); } - if tag.field_number == 4 { label_offset = Some(offset); } - if tag.field_number == 5 { type_offset = Some(offset); } - if tag.field_number == 6 { type_name_offset = Some(offset); } - if tag.field_number == 2 { extendee_offset = Some(offset); } - if tag.field_number == 7 { default_value_offset = Some(offset); } - if tag.field_number == 9 { oneof_index_offset = Some(offset); } - if tag.field_number == 10 { json_name_offset = Some(offset); } - if tag.field_number == 8 { options_offset = Some(offset); } - if tag.field_number == 17 { proto3_optional_offset = Some(offset); } + if tag.field_number == 1 { + name_offset = Some(offset); + } + if tag.field_number == 3 { + number_offset = Some(offset); + } + if tag.field_number == 4 { + label_offset = Some(offset); + } + if tag.field_number == 5 { + type_offset = Some(offset); + } + if tag.field_number == 6 { + type_name_offset = Some(offset); + } + if tag.field_number == 2 { + extendee_offset = Some(offset); + } + if tag.field_number == 7 { + default_value_offset = Some(offset); + } + if tag.field_number == 9 { + oneof_index_offset = Some(offset); + } + if tag.field_number == 10 { + json_name_offset = Some(offset); + } + if tag.field_number == 8 { + options_offset = Some(offset); + } + if tag.field_number == 17 { + proto3_optional_offset = Some(offset); + } } Ok(Self { accessor, -name_offset, -number_offset, -label_offset, -type_offset, -type_name_offset, -extendee_offset, -default_value_offset, -oneof_index_offset, -json_name_offset, -options_offset, -proto3_optional_offset, + name_offset, + number_offset, + label_offset, + type_offset, + type_name_offset, + extendee_offset, + default_value_offset, + oneof_index_offset, + json_name_offset, + options_offset, + proto3_optional_offset, }) } pub fn name(&self) -> crate::runtime::Result<&'a str> { - let offset = self.name_offset.ok_or(crate::runtime::RotoError::FieldNotFound)?; + let offset = self + .name_offset + .ok_or(crate::runtime::RotoError::FieldNotFound)?; let (bytes, _) = self.accessor.get_value_at(offset)?; str::from_utf8(bytes).map_err(|_| crate::runtime::RotoError::WireFormatViolation) } @@ -1675,46 +1897,68 @@ proto3_optional_offset, self.name().or(Ok("")) } - pub fn has_name(&self) -> bool { self.name_offset.is_some() } + pub fn has_name(&self) -> bool { + self.name_offset.is_some() + } pub fn number(&self) -> crate::runtime::Result { - let offset = self.number_offset.ok_or(crate::runtime::RotoError::FieldNotFound)?; + let offset = self + .number_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 number_or_default(&self) -> crate::runtime::Result { self.number().or(Ok(0)) } - pub fn has_number(&self) -> bool { self.number_offset.is_some() } + pub fn has_number(&self) -> bool { + self.number_offset.is_some() + } pub fn label(&self) -> crate::runtime::Result { - let offset = self.label_offset.ok_or(crate::runtime::RotoError::FieldNotFound)?; + let offset = self + .label_offset + .ok_or(crate::runtime::RotoError::FieldNotFound)?; let (bytes, _) = self.accessor.get_value_at(offset)?; - crate::runtime::read_varint(bytes).map(|(v, _)| v as u64).map_err(|_| crate::runtime::RotoError::WireFormatViolation) + crate::runtime::read_varint(bytes) + .map(|(v, _)| v as u64) + .map_err(|_| crate::runtime::RotoError::WireFormatViolation) } pub fn label_or_default(&self) -> crate::runtime::Result { self.label().or(Ok(0)) } - pub fn has_label(&self) -> bool { self.label_offset.is_some() } + pub fn has_label(&self) -> bool { + self.label_offset.is_some() + } pub fn r#type(&self) -> crate::runtime::Result { - let offset = self.type_offset.ok_or(crate::runtime::RotoError::FieldNotFound)?; + let offset = self + .type_offset + .ok_or(crate::runtime::RotoError::FieldNotFound)?; let (bytes, _) = self.accessor.get_value_at(offset)?; - crate::runtime::read_varint(bytes).map(|(v, _)| v as u64).map_err(|_| crate::runtime::RotoError::WireFormatViolation) + crate::runtime::read_varint(bytes) + .map(|(v, _)| v as u64) + .map_err(|_| crate::runtime::RotoError::WireFormatViolation) } pub fn r#type_or_default(&self) -> crate::runtime::Result { self.r#type().or(Ok(0)) } - pub fn has_type(&self) -> bool { self.type_offset.is_some() } + pub fn has_type(&self) -> bool { + self.type_offset.is_some() + } pub fn type_name(&self) -> crate::runtime::Result<&'a str> { - let offset = self.type_name_offset.ok_or(crate::runtime::RotoError::FieldNotFound)?; + let offset = self + .type_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) } @@ -1723,10 +1967,14 @@ proto3_optional_offset, self.type_name().or(Ok("")) } - pub fn has_type_name(&self) -> bool { self.type_name_offset.is_some() } + pub fn has_type_name(&self) -> bool { + self.type_name_offset.is_some() + } pub fn extendee(&self) -> crate::runtime::Result<&'a str> { - let offset = self.extendee_offset.ok_or(crate::runtime::RotoError::FieldNotFound)?; + let offset = self + .extendee_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) } @@ -1735,10 +1983,14 @@ proto3_optional_offset, self.extendee().or(Ok("")) } - pub fn has_extendee(&self) -> bool { self.extendee_offset.is_some() } + pub fn has_extendee(&self) -> bool { + self.extendee_offset.is_some() + } pub fn default_value(&self) -> crate::runtime::Result<&'a str> { - let offset = self.default_value_offset.ok_or(crate::runtime::RotoError::FieldNotFound)?; + let offset = self + .default_value_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) } @@ -1747,22 +1999,32 @@ proto3_optional_offset, self.default_value().or(Ok("")) } - pub fn has_default_value(&self) -> bool { self.default_value_offset.is_some() } + pub fn has_default_value(&self) -> bool { + self.default_value_offset.is_some() + } pub fn oneof_index(&self) -> crate::runtime::Result { - let offset = self.oneof_index_offset.ok_or(crate::runtime::RotoError::FieldNotFound)?; + let offset = self + .oneof_index_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 oneof_index_or_default(&self) -> crate::runtime::Result { self.oneof_index().or(Ok(0)) } - pub fn has_oneof_index(&self) -> bool { self.oneof_index_offset.is_some() } + pub fn has_oneof_index(&self) -> bool { + self.oneof_index_offset.is_some() + } pub fn json_name(&self) -> crate::runtime::Result<&'a str> { - let offset = self.json_name_offset.ok_or(crate::runtime::RotoError::FieldNotFound)?; + let offset = self + .json_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) } @@ -1771,10 +2033,14 @@ proto3_optional_offset, self.json_name().or(Ok("")) } - pub fn has_json_name(&self) -> bool { self.json_name_offset.is_some() } + pub fn has_json_name(&self) -> bool { + self.json_name_offset.is_some() + } pub fn options(&self) -> crate::runtime::Result<&'a [u8]> { - let offset = self.options_offset.ok_or(crate::runtime::RotoError::FieldNotFound)?; + let offset = self + .options_offset + .ok_or(crate::runtime::RotoError::FieldNotFound)?; let (bytes, _) = self.accessor.get_value_at(offset)?; Ok(bytes) } @@ -1783,24 +2049,31 @@ proto3_optional_offset, self.options().or(Ok(&[])) } - pub fn has_options(&self) -> bool { self.options_offset.is_some() } + pub fn has_options(&self) -> bool { + self.options_offset.is_some() + } pub fn proto3_optional(&self) -> crate::runtime::Result { - let offset = self.proto3_optional_offset.ok_or(crate::runtime::RotoError::FieldNotFound)?; + let offset = self + .proto3_optional_offset + .ok_or(crate::runtime::RotoError::FieldNotFound)?; let (bytes, _) = self.accessor.get_value_at(offset)?; - crate::runtime::read_varint(bytes).map(|(v, _)| v != 0).map_err(|_| crate::runtime::RotoError::WireFormatViolation) + crate::runtime::read_varint(bytes) + .map(|(v, _)| v != 0) + .map_err(|_| crate::runtime::RotoError::WireFormatViolation) } pub fn proto3_optional_or_default(&self) -> crate::runtime::Result { self.proto3_optional().or(Ok(false)) } - pub fn has_proto3_optional(&self) -> bool { self.proto3_optional_offset.is_some() } + pub fn has_proto3_optional(&self) -> bool { + self.proto3_optional_offset.is_some() + } pub fn raw_fields(&self) -> crate::runtime::RawFieldIterator<'a> { self.accessor.raw_fields() } - } pub struct FieldDescriptorProtoBuilder<'b> { @@ -1953,78 +2226,77 @@ impl crate::runtime::RotoMessage for OwnedFieldDescriptorProto { } pub mod field_descriptor_proto { -#[derive(Debug, Clone, Copy, PartialEq, Eq)] -#[repr(i32)] -pub enum Type { - TYPEDOUBLE = 1, - TYPEFLOAT = 2, - TYPEINT64 = 3, - TYPEUINT64 = 4, - TYPEINT32 = 5, - TYPEFIXED64 = 6, - TYPEFIXED32 = 7, - TYPEBOOL = 8, - TYPESTRING = 9, - TYPEGROUP = 10, - TYPEMESSAGE = 11, - TYPEBYTES = 12, - TYPEUINT32 = 13, - TYPEENUM = 14, - TYPESFIXED32 = 15, - TYPESFIXED64 = 16, - TYPESINT32 = 17, - TYPESINT64 = 18, - Unknown = 0, -} + #[derive(Debug, Clone, Copy, PartialEq, Eq)] + #[repr(i32)] + pub enum Type { + TYPEDOUBLE = 1, + TYPEFLOAT = 2, + TYPEINT64 = 3, + TYPEUINT64 = 4, + TYPEINT32 = 5, + TYPEFIXED64 = 6, + TYPEFIXED32 = 7, + TYPEBOOL = 8, + TYPESTRING = 9, + TYPEGROUP = 10, + TYPEMESSAGE = 11, + TYPEBYTES = 12, + TYPEUINT32 = 13, + TYPEENUM = 14, + TYPESFIXED32 = 15, + TYPESFIXED64 = 16, + TYPESINT32 = 17, + TYPESINT64 = 18, + Unknown = 0, + } -impl Type { - pub fn from_i32(value: i32) -> Self { - match value { - 1 => Type::TYPEDOUBLE, - 2 => Type::TYPEFLOAT, - 3 => Type::TYPEINT64, - 4 => Type::TYPEUINT64, - 5 => Type::TYPEINT32, - 6 => Type::TYPEFIXED64, - 7 => Type::TYPEFIXED32, - 8 => Type::TYPEBOOL, - 9 => Type::TYPESTRING, - 10 => Type::TYPEGROUP, - 11 => Type::TYPEMESSAGE, - 12 => Type::TYPEBYTES, - 13 => Type::TYPEUINT32, - 14 => Type::TYPEENUM, - 15 => Type::TYPESFIXED32, - 16 => Type::TYPESFIXED64, - 17 => Type::TYPESINT32, - 18 => Type::TYPESINT64, - _ => Type::Unknown, + impl Type { + pub fn from_i32(value: i32) -> Self { + match value { + 1 => Type::TYPEDOUBLE, + 2 => Type::TYPEFLOAT, + 3 => Type::TYPEINT64, + 4 => Type::TYPEUINT64, + 5 => Type::TYPEINT32, + 6 => Type::TYPEFIXED64, + 7 => Type::TYPEFIXED32, + 8 => Type::TYPEBOOL, + 9 => Type::TYPESTRING, + 10 => Type::TYPEGROUP, + 11 => Type::TYPEMESSAGE, + 12 => Type::TYPEBYTES, + 13 => Type::TYPEUINT32, + 14 => Type::TYPEENUM, + 15 => Type::TYPESFIXED32, + 16 => Type::TYPESFIXED64, + 17 => Type::TYPESINT32, + 18 => Type::TYPESINT64, + _ => Type::Unknown, + } } } -} -#[derive(Debug, Clone, Copy, PartialEq, Eq)] -#[repr(i32)] -pub enum Label { - LABELOPTIONAL = 1, - LABELREPEATED = 3, - LABELREQUIRED = 2, - Unknown = 0, -} + #[derive(Debug, Clone, Copy, PartialEq, Eq)] + #[repr(i32)] + pub enum Label { + LABELOPTIONAL = 1, + LABELREPEATED = 3, + LABELREQUIRED = 2, + Unknown = 0, + } -impl Label { - pub fn from_i32(value: i32) -> Self { - match value { - 1 => Label::LABELOPTIONAL, - 3 => Label::LABELREPEATED, - 2 => Label::LABELREQUIRED, - _ => Label::Unknown, + impl Label { + pub fn from_i32(value: i32) -> Self { + match value { + 1 => Label::LABELOPTIONAL, + 3 => Label::LABELREPEATED, + 2 => Label::LABELREQUIRED, + _ => Label::Unknown, + } } } } -} - pub struct OneofDescriptorProto<'a> { accessor: crate::runtime::ProtoAccessor<'a>, name_offset: Option, @@ -2038,19 +2310,25 @@ impl<'a> OneofDescriptorProto<'a> { let mut options_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 { options_offset = Some(offset); } + if tag.field_number == 1 { + name_offset = Some(offset); + } + if tag.field_number == 2 { + options_offset = Some(offset); + } } Ok(Self { accessor, -name_offset, -options_offset, + name_offset, + options_offset, }) } pub fn name(&self) -> crate::runtime::Result<&'a str> { - let offset = self.name_offset.ok_or(crate::runtime::RotoError::FieldNotFound)?; + let offset = self + .name_offset + .ok_or(crate::runtime::RotoError::FieldNotFound)?; let (bytes, _) = self.accessor.get_value_at(offset)?; str::from_utf8(bytes).map_err(|_| crate::runtime::RotoError::WireFormatViolation) } @@ -2059,10 +2337,14 @@ options_offset, self.name().or(Ok("")) } - pub fn has_name(&self) -> bool { self.name_offset.is_some() } + pub fn has_name(&self) -> bool { + self.name_offset.is_some() + } pub fn options(&self) -> crate::runtime::Result<&'a [u8]> { - let offset = self.options_offset.ok_or(crate::runtime::RotoError::FieldNotFound)?; + let offset = self + .options_offset + .ok_or(crate::runtime::RotoError::FieldNotFound)?; let (bytes, _) = self.accessor.get_value_at(offset)?; Ok(bytes) } @@ -2071,12 +2353,13 @@ options_offset, self.options().or(Ok(&[])) } - pub fn has_options(&self) -> bool { self.options_offset.is_some() } + pub fn has_options(&self) -> bool { + self.options_offset.is_some() + } pub fn raw_fields(&self) -> crate::runtime::RawFieldIterator<'a> { self.accessor.raw_fields() } - } pub struct OneofDescriptorProtoBuilder<'b> { @@ -2174,36 +2457,53 @@ impl<'a> EnumDescriptorProto<'a> { let mut visibility_offset = None; for item in accessor.fields() { let (offset, tag, _) = item?; - if tag.field_number == 1 { name_offset = Some(offset); } + if tag.field_number == 1 { + name_offset = Some(offset); + } if tag.field_number == 2 { - if value_start.is_none() { value_start = Some(offset); } + if value_start.is_none() { + value_start = Some(offset); + } value_end = Some(offset); } - if tag.field_number == 3 { options_offset = Some(offset); } + if tag.field_number == 3 { + options_offset = Some(offset); + } if tag.field_number == 4 { - if reserved_range_start.is_none() { reserved_range_start = Some(offset); } + if reserved_range_start.is_none() { + reserved_range_start = Some(offset); + } reserved_range_end = Some(offset); } if tag.field_number == 5 { - if reserved_name_start.is_none() { reserved_name_start = Some(offset); } + if reserved_name_start.is_none() { + reserved_name_start = Some(offset); + } reserved_name_end = Some(offset); } - if tag.field_number == 6 { visibility_offset = Some(offset); } + if tag.field_number == 6 { + visibility_offset = Some(offset); + } } Ok(Self { accessor, -name_offset, -value_start, value_end, -options_offset, -reserved_range_start, reserved_range_end, -reserved_name_start, reserved_name_end, -visibility_offset, + name_offset, + value_start, + value_end, + options_offset, + reserved_range_start, + reserved_range_end, + reserved_name_start, + reserved_name_end, + visibility_offset, }) } pub fn name(&self) -> crate::runtime::Result<&'a str> { - let offset = self.name_offset.ok_or(crate::runtime::RotoError::FieldNotFound)?; + let offset = self + .name_offset + .ok_or(crate::runtime::RotoError::FieldNotFound)?; let (bytes, _) = self.accessor.get_value_at(offset)?; str::from_utf8(bytes).map_err(|_| crate::runtime::RotoError::WireFormatViolation) } @@ -2212,7 +2512,9 @@ visibility_offset, self.name().or(Ok("")) } - pub fn has_name(&self) -> bool { self.name_offset.is_some() } + pub fn has_name(&self) -> bool { + self.name_offset.is_some() + } pub fn value(&self) -> crate::runtime::RepeatedFieldIterator<'a> { match (self.value_start, self.value_end) { @@ -2222,7 +2524,9 @@ visibility_offset, } pub fn options(&self) -> crate::runtime::Result<&'a [u8]> { - let offset = self.options_offset.ok_or(crate::runtime::RotoError::FieldNotFound)?; + let offset = self + .options_offset + .ok_or(crate::runtime::RotoError::FieldNotFound)?; let (bytes, _) = self.accessor.get_value_at(offset)?; Ok(bytes) } @@ -2231,7 +2535,9 @@ visibility_offset, self.options().or(Ok(&[])) } - pub fn has_options(&self) -> bool { self.options_offset.is_some() } + pub fn has_options(&self) -> bool { + self.options_offset.is_some() + } pub fn reserved_range(&self) -> crate::runtime::RepeatedFieldIterator<'a> { match (self.reserved_range_start, self.reserved_range_end) { @@ -2248,21 +2554,26 @@ visibility_offset, } pub fn visibility(&self) -> crate::runtime::Result { - let offset = self.visibility_offset.ok_or(crate::runtime::RotoError::FieldNotFound)?; + let offset = self + .visibility_offset + .ok_or(crate::runtime::RotoError::FieldNotFound)?; let (bytes, _) = self.accessor.get_value_at(offset)?; - crate::runtime::read_varint(bytes).map(|(v, _)| v as u64).map_err(|_| crate::runtime::RotoError::WireFormatViolation) + crate::runtime::read_varint(bytes) + .map(|(v, _)| v as u64) + .map_err(|_| crate::runtime::RotoError::WireFormatViolation) } pub fn visibility_or_default(&self) -> crate::runtime::Result { self.visibility().or(Ok(0)) } - pub fn has_visibility(&self) -> bool { self.visibility_offset.is_some() } + pub fn has_visibility(&self) -> bool { + self.visibility_offset.is_some() + } pub fn raw_fields(&self) -> crate::runtime::RawFieldIterator<'a> { self.accessor.raw_fields() } - } pub struct EnumDescriptorProtoBuilder<'b> { @@ -2370,128 +2681,142 @@ impl crate::runtime::RotoMessage for OwnedEnumDescriptorProto { } pub mod enum_descriptor_proto { -pub struct EnumReservedRange<'a> { - accessor: crate::runtime::ProtoAccessor<'a>, - start_offset: Option, - end_offset: Option, -} + pub struct EnumReservedRange<'a> { + accessor: crate::runtime::ProtoAccessor<'a>, + start_offset: Option, + end_offset: Option, + } -impl<'a> EnumReservedRange<'a> { - pub fn new(data: &'a [u8]) -> crate::runtime::Result { - let accessor = crate::runtime::ProtoAccessor::new(data)?; - let mut start_offset = None; - let mut end_offset = None; - for item in accessor.fields() { - let (offset, tag, _) = item?; - if tag.field_number == 1 { start_offset = Some(offset); } - if tag.field_number == 2 { end_offset = Some(offset); } + impl<'a> EnumReservedRange<'a> { + pub fn new(data: &'a [u8]) -> crate::runtime::Result { + let accessor = crate::runtime::ProtoAccessor::new(data)?; + let mut start_offset = None; + let mut end_offset = None; + for item in accessor.fields() { + let (offset, tag, _) = item?; + if tag.field_number == 1 { + start_offset = Some(offset); + } + if tag.field_number == 2 { + end_offset = Some(offset); + } + } + + Ok(Self { + accessor, + start_offset, + end_offset, + }) } - Ok(Self { - accessor, -start_offset, -end_offset, - }) - } + pub fn start(&self) -> crate::runtime::Result { + let offset = self + .start_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) + } - pub fn start(&self) -> crate::runtime::Result { - let offset = self.start_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) - } + pub fn start_or_default(&self) -> crate::runtime::Result { + self.start().or(Ok(0)) + } - pub fn start_or_default(&self) -> crate::runtime::Result { - self.start().or(Ok(0)) - } + pub fn has_start(&self) -> bool { + self.start_offset.is_some() + } - pub fn has_start(&self) -> bool { self.start_offset.is_some() } + pub fn end(&self) -> crate::runtime::Result { + let offset = self + .end_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) + } - pub fn end(&self) -> crate::runtime::Result { - let offset = self.end_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) - } + pub fn end_or_default(&self) -> crate::runtime::Result { + self.end().or(Ok(0)) + } - pub fn end_or_default(&self) -> crate::runtime::Result { - self.end().or(Ok(0)) - } + pub fn has_end(&self) -> bool { + self.end_offset.is_some() + } - pub fn has_end(&self) -> bool { self.end_offset.is_some() } - - pub fn raw_fields(&self) -> crate::runtime::RawFieldIterator<'a> { - self.accessor.raw_fields() - } - -} - -pub struct EnumReservedRangeBuilder<'b> { - builder: crate::runtime::ProtoBuilder<'b>, - start_written: bool, - end_written: bool, -} - -impl<'b> EnumReservedRangeBuilder<'b> { - pub fn builder(buf: &mut [u8]) -> EnumReservedRangeBuilder<'_> { - EnumReservedRangeBuilder { - builder: crate::runtime::ProtoBuilder::new(buf), - start_written: false, - end_written: false, + pub fn raw_fields(&self) -> crate::runtime::RawFieldIterator<'a> { + self.accessor.raw_fields() } } - pub fn start(mut self, value: i32) -> crate::runtime::Result { - self.builder.write_int32(1, value)?; - self.start_written = true; - Ok(self) + pub struct EnumReservedRangeBuilder<'b> { + builder: crate::runtime::ProtoBuilder<'b>, + start_written: bool, + end_written: bool, } - pub fn end(mut self, value: i32) -> crate::runtime::Result { - self.builder.write_int32(2, value)?; - self.end_written = true; - Ok(self) - } - - pub fn with(mut self, msg: &EnumReservedRange<'_>) -> crate::runtime::Result { - for item in msg.raw_fields() { - let (field_number, raw_bytes) = item?; - let is_written = match field_number { - 1 => self.start_written, - 2 => self.end_written, - _ => false, - }; - if !is_written { - self.builder.write_raw(raw_bytes)?; + impl<'b> EnumReservedRangeBuilder<'b> { + pub fn builder(buf: &mut [u8]) -> EnumReservedRangeBuilder<'_> { + EnumReservedRangeBuilder { + builder: crate::runtime::ProtoBuilder::new(buf), + start_written: false, + end_written: false, } } - Ok(self) + + pub fn start(mut self, value: i32) -> crate::runtime::Result { + self.builder.write_int32(1, value)?; + self.start_written = true; + Ok(self) + } + + pub fn end(mut self, value: i32) -> crate::runtime::Result { + self.builder.write_int32(2, value)?; + self.end_written = true; + Ok(self) + } + + pub fn with(mut self, msg: &EnumReservedRange<'_>) -> crate::runtime::Result { + for item in msg.raw_fields() { + let (field_number, raw_bytes) = item?; + let is_written = match field_number { + 1 => self.start_written, + 2 => self.end_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 fn finish(self) -> crate::runtime::Result<&'b mut [u8]> { - self.builder.finish() - } -} - -pub struct OwnedEnumReservedRange { - pub data: bytes::Bytes, -} - -impl crate::runtime::RotoOwned for OwnedEnumReservedRange { - type Reader<'a> = EnumReservedRange<'a>; - fn reader(&self) -> EnumReservedRange<'_> { - EnumReservedRange::new(&self.data).expect("failed to create reader") - } -} - -impl crate::runtime::RotoMessage for OwnedEnumReservedRange { - fn decode(buf: bytes::Bytes) -> crate::runtime::Result { - Ok(OwnedEnumReservedRange { data: buf }) + pub struct OwnedEnumReservedRange { + pub data: bytes::Bytes, } - fn bytes(&self) -> bytes::Bytes { - self.data.clone() + impl crate::runtime::RotoOwned for OwnedEnumReservedRange { + type Reader<'a> = EnumReservedRange<'a>; + fn reader(&self) -> EnumReservedRange<'_> { + EnumReservedRange::new(&self.data).expect("failed to create reader") + } } -} + impl crate::runtime::RotoMessage for OwnedEnumReservedRange { + fn decode(buf: bytes::Bytes) -> crate::runtime::Result { + Ok(OwnedEnumReservedRange { data: buf }) + } + + fn bytes(&self) -> bytes::Bytes { + self.data.clone() + } + } } pub struct EnumValueDescriptorProto<'a> { @@ -2509,21 +2834,29 @@ impl<'a> EnumValueDescriptorProto<'a> { let mut options_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 { number_offset = Some(offset); } - if tag.field_number == 3 { options_offset = Some(offset); } + if tag.field_number == 1 { + name_offset = Some(offset); + } + if tag.field_number == 2 { + number_offset = Some(offset); + } + if tag.field_number == 3 { + options_offset = Some(offset); + } } Ok(Self { accessor, -name_offset, -number_offset, -options_offset, + name_offset, + number_offset, + options_offset, }) } pub fn name(&self) -> crate::runtime::Result<&'a str> { - let offset = self.name_offset.ok_or(crate::runtime::RotoError::FieldNotFound)?; + let offset = self + .name_offset + .ok_or(crate::runtime::RotoError::FieldNotFound)?; let (bytes, _) = self.accessor.get_value_at(offset)?; str::from_utf8(bytes).map_err(|_| crate::runtime::RotoError::WireFormatViolation) } @@ -2532,22 +2865,32 @@ options_offset, self.name().or(Ok("")) } - pub fn has_name(&self) -> bool { self.name_offset.is_some() } + pub fn has_name(&self) -> bool { + self.name_offset.is_some() + } pub fn number(&self) -> crate::runtime::Result { - let offset = self.number_offset.ok_or(crate::runtime::RotoError::FieldNotFound)?; + let offset = self + .number_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 number_or_default(&self) -> crate::runtime::Result { self.number().or(Ok(0)) } - pub fn has_number(&self) -> bool { self.number_offset.is_some() } + pub fn has_number(&self) -> bool { + self.number_offset.is_some() + } pub fn options(&self) -> crate::runtime::Result<&'a [u8]> { - let offset = self.options_offset.ok_or(crate::runtime::RotoError::FieldNotFound)?; + let offset = self + .options_offset + .ok_or(crate::runtime::RotoError::FieldNotFound)?; let (bytes, _) = self.accessor.get_value_at(offset)?; Ok(bytes) } @@ -2556,12 +2899,13 @@ options_offset, self.options().or(Ok(&[])) } - pub fn has_options(&self) -> bool { self.options_offset.is_some() } + pub fn has_options(&self) -> bool { + self.options_offset.is_some() + } pub fn raw_fields(&self) -> crate::runtime::RawFieldIterator<'a> { self.accessor.raw_fields() } - } pub struct EnumValueDescriptorProtoBuilder<'b> { @@ -2658,24 +3002,33 @@ impl<'a> ServiceDescriptorProto<'a> { let mut options_offset = None; for item in accessor.fields() { let (offset, tag, _) = item?; - if tag.field_number == 1 { name_offset = Some(offset); } + if tag.field_number == 1 { + name_offset = Some(offset); + } if tag.field_number == 2 { - if method_start.is_none() { method_start = Some(offset); } + if method_start.is_none() { + method_start = Some(offset); + } method_end = Some(offset); } - if tag.field_number == 3 { options_offset = Some(offset); } + if tag.field_number == 3 { + options_offset = Some(offset); + } } Ok(Self { accessor, -name_offset, -method_start, method_end, -options_offset, + name_offset, + method_start, + method_end, + options_offset, }) } pub fn name(&self) -> crate::runtime::Result<&'a str> { - let offset = self.name_offset.ok_or(crate::runtime::RotoError::FieldNotFound)?; + let offset = self + .name_offset + .ok_or(crate::runtime::RotoError::FieldNotFound)?; let (bytes, _) = self.accessor.get_value_at(offset)?; str::from_utf8(bytes).map_err(|_| crate::runtime::RotoError::WireFormatViolation) } @@ -2684,7 +3037,9 @@ options_offset, self.name().or(Ok("")) } - pub fn has_name(&self) -> bool { self.name_offset.is_some() } + pub fn has_name(&self) -> bool { + self.name_offset.is_some() + } pub fn method(&self) -> crate::runtime::RepeatedFieldIterator<'a> { match (self.method_start, self.method_end) { @@ -2694,7 +3049,9 @@ options_offset, } pub fn options(&self) -> crate::runtime::Result<&'a [u8]> { - let offset = self.options_offset.ok_or(crate::runtime::RotoError::FieldNotFound)?; + let offset = self + .options_offset + .ok_or(crate::runtime::RotoError::FieldNotFound)?; let (bytes, _) = self.accessor.get_value_at(offset)?; Ok(bytes) } @@ -2703,12 +3060,13 @@ options_offset, self.options().or(Ok(&[])) } - pub fn has_options(&self) -> bool { self.options_offset.is_some() } + pub fn has_options(&self) -> bool { + self.options_offset.is_some() + } pub fn raw_fields(&self) -> crate::runtime::RawFieldIterator<'a> { self.accessor.raw_fields() } - } pub struct ServiceDescriptorProtoBuilder<'b> { @@ -2809,27 +3167,41 @@ impl<'a> MethodDescriptorProto<'a> { let mut server_streaming_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 { input_type_offset = Some(offset); } - if tag.field_number == 3 { output_type_offset = Some(offset); } - if tag.field_number == 4 { options_offset = Some(offset); } - if tag.field_number == 5 { client_streaming_offset = Some(offset); } - if tag.field_number == 6 { server_streaming_offset = Some(offset); } + if tag.field_number == 1 { + name_offset = Some(offset); + } + if tag.field_number == 2 { + input_type_offset = Some(offset); + } + if tag.field_number == 3 { + output_type_offset = Some(offset); + } + if tag.field_number == 4 { + options_offset = Some(offset); + } + if tag.field_number == 5 { + client_streaming_offset = Some(offset); + } + if tag.field_number == 6 { + server_streaming_offset = Some(offset); + } } Ok(Self { accessor, -name_offset, -input_type_offset, -output_type_offset, -options_offset, -client_streaming_offset, -server_streaming_offset, + name_offset, + input_type_offset, + output_type_offset, + options_offset, + client_streaming_offset, + server_streaming_offset, }) } pub fn name(&self) -> crate::runtime::Result<&'a str> { - let offset = self.name_offset.ok_or(crate::runtime::RotoError::FieldNotFound)?; + let offset = self + .name_offset + .ok_or(crate::runtime::RotoError::FieldNotFound)?; let (bytes, _) = self.accessor.get_value_at(offset)?; str::from_utf8(bytes).map_err(|_| crate::runtime::RotoError::WireFormatViolation) } @@ -2838,10 +3210,14 @@ server_streaming_offset, self.name().or(Ok("")) } - pub fn has_name(&self) -> bool { self.name_offset.is_some() } + pub fn has_name(&self) -> bool { + self.name_offset.is_some() + } pub fn input_type(&self) -> crate::runtime::Result<&'a str> { - let offset = self.input_type_offset.ok_or(crate::runtime::RotoError::FieldNotFound)?; + let offset = self + .input_type_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) } @@ -2850,10 +3226,14 @@ server_streaming_offset, self.input_type().or(Ok("")) } - pub fn has_input_type(&self) -> bool { self.input_type_offset.is_some() } + pub fn has_input_type(&self) -> bool { + self.input_type_offset.is_some() + } pub fn output_type(&self) -> crate::runtime::Result<&'a str> { - let offset = self.output_type_offset.ok_or(crate::runtime::RotoError::FieldNotFound)?; + let offset = self + .output_type_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) } @@ -2862,10 +3242,14 @@ server_streaming_offset, self.output_type().or(Ok("")) } - pub fn has_output_type(&self) -> bool { self.output_type_offset.is_some() } + pub fn has_output_type(&self) -> bool { + self.output_type_offset.is_some() + } pub fn options(&self) -> crate::runtime::Result<&'a [u8]> { - let offset = self.options_offset.ok_or(crate::runtime::RotoError::FieldNotFound)?; + let offset = self + .options_offset + .ok_or(crate::runtime::RotoError::FieldNotFound)?; let (bytes, _) = self.accessor.get_value_at(offset)?; Ok(bytes) } @@ -2874,36 +3258,49 @@ server_streaming_offset, self.options().or(Ok(&[])) } - pub fn has_options(&self) -> bool { self.options_offset.is_some() } + pub fn has_options(&self) -> bool { + self.options_offset.is_some() + } pub fn client_streaming(&self) -> crate::runtime::Result { - let offset = self.client_streaming_offset.ok_or(crate::runtime::RotoError::FieldNotFound)?; + let offset = self + .client_streaming_offset + .ok_or(crate::runtime::RotoError::FieldNotFound)?; let (bytes, _) = self.accessor.get_value_at(offset)?; - crate::runtime::read_varint(bytes).map(|(v, _)| v != 0).map_err(|_| crate::runtime::RotoError::WireFormatViolation) + crate::runtime::read_varint(bytes) + .map(|(v, _)| v != 0) + .map_err(|_| crate::runtime::RotoError::WireFormatViolation) } pub fn client_streaming_or_default(&self) -> crate::runtime::Result { self.client_streaming().or(Ok(false)) } - pub fn has_client_streaming(&self) -> bool { self.client_streaming_offset.is_some() } + pub fn has_client_streaming(&self) -> bool { + self.client_streaming_offset.is_some() + } pub fn server_streaming(&self) -> crate::runtime::Result { - let offset = self.server_streaming_offset.ok_or(crate::runtime::RotoError::FieldNotFound)?; + let offset = self + .server_streaming_offset + .ok_or(crate::runtime::RotoError::FieldNotFound)?; let (bytes, _) = self.accessor.get_value_at(offset)?; - crate::runtime::read_varint(bytes).map(|(v, _)| v != 0).map_err(|_| crate::runtime::RotoError::WireFormatViolation) + crate::runtime::read_varint(bytes) + .map(|(v, _)| v != 0) + .map_err(|_| crate::runtime::RotoError::WireFormatViolation) } pub fn server_streaming_or_default(&self) -> crate::runtime::Result { self.server_streaming().or(Ok(false)) } - pub fn has_server_streaming(&self) -> bool { self.server_streaming_offset.is_some() } + pub fn has_server_streaming(&self) -> bool { + self.server_streaming_offset.is_some() + } pub fn raw_fields(&self) -> crate::runtime::RawFieldIterator<'a> { self.accessor.raw_fields() } - } pub struct MethodDescriptorProtoBuilder<'b> { @@ -3063,60 +3460,105 @@ impl<'a> FileOptions<'a> { let mut uninterpreted_option_end = None; for item in accessor.fields() { let (offset, tag, _) = item?; - if tag.field_number == 1 { java_package_offset = Some(offset); } - if tag.field_number == 8 { java_outer_classname_offset = Some(offset); } - if tag.field_number == 10 { java_multiple_files_offset = Some(offset); } - if tag.field_number == 20 { java_generate_equals_and_hash_offset = Some(offset); } - if tag.field_number == 27 { java_string_check_utf8_offset = Some(offset); } - if tag.field_number == 9 { optimize_for_offset = Some(offset); } - if tag.field_number == 11 { go_package_offset = Some(offset); } - if tag.field_number == 16 { cc_generic_services_offset = Some(offset); } - if tag.field_number == 17 { java_generic_services_offset = Some(offset); } - if tag.field_number == 18 { py_generic_services_offset = Some(offset); } - if tag.field_number == 23 { deprecated_offset = Some(offset); } - if tag.field_number == 31 { cc_enable_arenas_offset = Some(offset); } - if tag.field_number == 36 { objc_class_prefix_offset = Some(offset); } - if tag.field_number == 37 { csharp_namespace_offset = Some(offset); } - if tag.field_number == 39 { swift_prefix_offset = Some(offset); } - if tag.field_number == 40 { php_class_prefix_offset = Some(offset); } - if tag.field_number == 41 { php_namespace_offset = Some(offset); } - if tag.field_number == 44 { php_metadata_namespace_offset = Some(offset); } - if tag.field_number == 45 { ruby_package_offset = Some(offset); } - if tag.field_number == 50 { features_offset = Some(offset); } + if tag.field_number == 1 { + java_package_offset = Some(offset); + } + if tag.field_number == 8 { + java_outer_classname_offset = Some(offset); + } + if tag.field_number == 10 { + java_multiple_files_offset = Some(offset); + } + if tag.field_number == 20 { + java_generate_equals_and_hash_offset = Some(offset); + } + if tag.field_number == 27 { + java_string_check_utf8_offset = Some(offset); + } + if tag.field_number == 9 { + optimize_for_offset = Some(offset); + } + if tag.field_number == 11 { + go_package_offset = Some(offset); + } + if tag.field_number == 16 { + cc_generic_services_offset = Some(offset); + } + if tag.field_number == 17 { + java_generic_services_offset = Some(offset); + } + if tag.field_number == 18 { + py_generic_services_offset = Some(offset); + } + if tag.field_number == 23 { + deprecated_offset = Some(offset); + } + if tag.field_number == 31 { + cc_enable_arenas_offset = Some(offset); + } + if tag.field_number == 36 { + objc_class_prefix_offset = Some(offset); + } + if tag.field_number == 37 { + csharp_namespace_offset = Some(offset); + } + if tag.field_number == 39 { + swift_prefix_offset = Some(offset); + } + if tag.field_number == 40 { + php_class_prefix_offset = Some(offset); + } + if tag.field_number == 41 { + php_namespace_offset = Some(offset); + } + if tag.field_number == 44 { + php_metadata_namespace_offset = Some(offset); + } + if tag.field_number == 45 { + ruby_package_offset = Some(offset); + } + if tag.field_number == 50 { + features_offset = Some(offset); + } if tag.field_number == 999 { - if uninterpreted_option_start.is_none() { uninterpreted_option_start = Some(offset); } + if uninterpreted_option_start.is_none() { + uninterpreted_option_start = Some(offset); + } uninterpreted_option_end = Some(offset); } } Ok(Self { accessor, -java_package_offset, -java_outer_classname_offset, -java_multiple_files_offset, -java_generate_equals_and_hash_offset, -java_string_check_utf8_offset, -optimize_for_offset, -go_package_offset, -cc_generic_services_offset, -java_generic_services_offset, -py_generic_services_offset, -deprecated_offset, -cc_enable_arenas_offset, -objc_class_prefix_offset, -csharp_namespace_offset, -swift_prefix_offset, -php_class_prefix_offset, -php_namespace_offset, -php_metadata_namespace_offset, -ruby_package_offset, -features_offset, -uninterpreted_option_start, uninterpreted_option_end, + java_package_offset, + java_outer_classname_offset, + java_multiple_files_offset, + java_generate_equals_and_hash_offset, + java_string_check_utf8_offset, + optimize_for_offset, + go_package_offset, + cc_generic_services_offset, + java_generic_services_offset, + py_generic_services_offset, + deprecated_offset, + cc_enable_arenas_offset, + objc_class_prefix_offset, + csharp_namespace_offset, + swift_prefix_offset, + php_class_prefix_offset, + php_namespace_offset, + php_metadata_namespace_offset, + ruby_package_offset, + features_offset, + uninterpreted_option_start, + uninterpreted_option_end, }) } pub fn java_package(&self) -> crate::runtime::Result<&'a str> { - let offset = self.java_package_offset.ok_or(crate::runtime::RotoError::FieldNotFound)?; + let offset = self + .java_package_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) } @@ -3125,10 +3567,14 @@ uninterpreted_option_start, uninterpreted_option_end, self.java_package().or(Ok("")) } - pub fn has_java_package(&self) -> bool { self.java_package_offset.is_some() } + pub fn has_java_package(&self) -> bool { + self.java_package_offset.is_some() + } pub fn java_outer_classname(&self) -> crate::runtime::Result<&'a str> { - let offset = self.java_outer_classname_offset.ok_or(crate::runtime::RotoError::FieldNotFound)?; + let offset = self + .java_outer_classname_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) } @@ -3137,58 +3583,86 @@ uninterpreted_option_start, uninterpreted_option_end, self.java_outer_classname().or(Ok("")) } - pub fn has_java_outer_classname(&self) -> bool { self.java_outer_classname_offset.is_some() } + pub fn has_java_outer_classname(&self) -> bool { + self.java_outer_classname_offset.is_some() + } pub fn java_multiple_files(&self) -> crate::runtime::Result { - let offset = self.java_multiple_files_offset.ok_or(crate::runtime::RotoError::FieldNotFound)?; + let offset = self + .java_multiple_files_offset + .ok_or(crate::runtime::RotoError::FieldNotFound)?; let (bytes, _) = self.accessor.get_value_at(offset)?; - crate::runtime::read_varint(bytes).map(|(v, _)| v != 0).map_err(|_| crate::runtime::RotoError::WireFormatViolation) + crate::runtime::read_varint(bytes) + .map(|(v, _)| v != 0) + .map_err(|_| crate::runtime::RotoError::WireFormatViolation) } pub fn java_multiple_files_or_default(&self) -> crate::runtime::Result { self.java_multiple_files().or(Ok(false)) } - pub fn has_java_multiple_files(&self) -> bool { self.java_multiple_files_offset.is_some() } + pub fn has_java_multiple_files(&self) -> bool { + self.java_multiple_files_offset.is_some() + } pub fn java_generate_equals_and_hash(&self) -> crate::runtime::Result { - let offset = self.java_generate_equals_and_hash_offset.ok_or(crate::runtime::RotoError::FieldNotFound)?; + let offset = self + .java_generate_equals_and_hash_offset + .ok_or(crate::runtime::RotoError::FieldNotFound)?; let (bytes, _) = self.accessor.get_value_at(offset)?; - crate::runtime::read_varint(bytes).map(|(v, _)| v != 0).map_err(|_| crate::runtime::RotoError::WireFormatViolation) + crate::runtime::read_varint(bytes) + .map(|(v, _)| v != 0) + .map_err(|_| crate::runtime::RotoError::WireFormatViolation) } pub fn java_generate_equals_and_hash_or_default(&self) -> crate::runtime::Result { self.java_generate_equals_and_hash().or(Ok(false)) } - pub fn has_java_generate_equals_and_hash(&self) -> bool { self.java_generate_equals_and_hash_offset.is_some() } + pub fn has_java_generate_equals_and_hash(&self) -> bool { + self.java_generate_equals_and_hash_offset.is_some() + } pub fn java_string_check_utf8(&self) -> crate::runtime::Result { - let offset = self.java_string_check_utf8_offset.ok_or(crate::runtime::RotoError::FieldNotFound)?; + let offset = self + .java_string_check_utf8_offset + .ok_or(crate::runtime::RotoError::FieldNotFound)?; let (bytes, _) = self.accessor.get_value_at(offset)?; - crate::runtime::read_varint(bytes).map(|(v, _)| v != 0).map_err(|_| crate::runtime::RotoError::WireFormatViolation) + crate::runtime::read_varint(bytes) + .map(|(v, _)| v != 0) + .map_err(|_| crate::runtime::RotoError::WireFormatViolation) } pub fn java_string_check_utf8_or_default(&self) -> crate::runtime::Result { self.java_string_check_utf8().or(Ok(false)) } - pub fn has_java_string_check_utf8(&self) -> bool { self.java_string_check_utf8_offset.is_some() } + pub fn has_java_string_check_utf8(&self) -> bool { + self.java_string_check_utf8_offset.is_some() + } pub fn optimize_for(&self) -> crate::runtime::Result { - let offset = self.optimize_for_offset.ok_or(crate::runtime::RotoError::FieldNotFound)?; + let offset = self + .optimize_for_offset + .ok_or(crate::runtime::RotoError::FieldNotFound)?; let (bytes, _) = self.accessor.get_value_at(offset)?; - crate::runtime::read_varint(bytes).map(|(v, _)| v as u64).map_err(|_| crate::runtime::RotoError::WireFormatViolation) + crate::runtime::read_varint(bytes) + .map(|(v, _)| v as u64) + .map_err(|_| crate::runtime::RotoError::WireFormatViolation) } pub fn optimize_for_or_default(&self) -> crate::runtime::Result { self.optimize_for().or(Ok(0)) } - pub fn has_optimize_for(&self) -> bool { self.optimize_for_offset.is_some() } + pub fn has_optimize_for(&self) -> bool { + self.optimize_for_offset.is_some() + } pub fn go_package(&self) -> crate::runtime::Result<&'a str> { - let offset = self.go_package_offset.ok_or(crate::runtime::RotoError::FieldNotFound)?; + let offset = self + .go_package_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) } @@ -3197,70 +3671,104 @@ uninterpreted_option_start, uninterpreted_option_end, self.go_package().or(Ok("")) } - pub fn has_go_package(&self) -> bool { self.go_package_offset.is_some() } + pub fn has_go_package(&self) -> bool { + self.go_package_offset.is_some() + } pub fn cc_generic_services(&self) -> crate::runtime::Result { - let offset = self.cc_generic_services_offset.ok_or(crate::runtime::RotoError::FieldNotFound)?; + let offset = self + .cc_generic_services_offset + .ok_or(crate::runtime::RotoError::FieldNotFound)?; let (bytes, _) = self.accessor.get_value_at(offset)?; - crate::runtime::read_varint(bytes).map(|(v, _)| v != 0).map_err(|_| crate::runtime::RotoError::WireFormatViolation) + crate::runtime::read_varint(bytes) + .map(|(v, _)| v != 0) + .map_err(|_| crate::runtime::RotoError::WireFormatViolation) } pub fn cc_generic_services_or_default(&self) -> crate::runtime::Result { self.cc_generic_services().or(Ok(false)) } - pub fn has_cc_generic_services(&self) -> bool { self.cc_generic_services_offset.is_some() } + pub fn has_cc_generic_services(&self) -> bool { + self.cc_generic_services_offset.is_some() + } pub fn java_generic_services(&self) -> crate::runtime::Result { - let offset = self.java_generic_services_offset.ok_or(crate::runtime::RotoError::FieldNotFound)?; + let offset = self + .java_generic_services_offset + .ok_or(crate::runtime::RotoError::FieldNotFound)?; let (bytes, _) = self.accessor.get_value_at(offset)?; - crate::runtime::read_varint(bytes).map(|(v, _)| v != 0).map_err(|_| crate::runtime::RotoError::WireFormatViolation) + crate::runtime::read_varint(bytes) + .map(|(v, _)| v != 0) + .map_err(|_| crate::runtime::RotoError::WireFormatViolation) } pub fn java_generic_services_or_default(&self) -> crate::runtime::Result { self.java_generic_services().or(Ok(false)) } - pub fn has_java_generic_services(&self) -> bool { self.java_generic_services_offset.is_some() } + pub fn has_java_generic_services(&self) -> bool { + self.java_generic_services_offset.is_some() + } pub fn py_generic_services(&self) -> crate::runtime::Result { - let offset = self.py_generic_services_offset.ok_or(crate::runtime::RotoError::FieldNotFound)?; + let offset = self + .py_generic_services_offset + .ok_or(crate::runtime::RotoError::FieldNotFound)?; let (bytes, _) = self.accessor.get_value_at(offset)?; - crate::runtime::read_varint(bytes).map(|(v, _)| v != 0).map_err(|_| crate::runtime::RotoError::WireFormatViolation) + crate::runtime::read_varint(bytes) + .map(|(v, _)| v != 0) + .map_err(|_| crate::runtime::RotoError::WireFormatViolation) } pub fn py_generic_services_or_default(&self) -> crate::runtime::Result { self.py_generic_services().or(Ok(false)) } - pub fn has_py_generic_services(&self) -> bool { self.py_generic_services_offset.is_some() } + pub fn has_py_generic_services(&self) -> bool { + self.py_generic_services_offset.is_some() + } pub fn deprecated(&self) -> crate::runtime::Result { - let offset = self.deprecated_offset.ok_or(crate::runtime::RotoError::FieldNotFound)?; + let offset = self + .deprecated_offset + .ok_or(crate::runtime::RotoError::FieldNotFound)?; let (bytes, _) = self.accessor.get_value_at(offset)?; - crate::runtime::read_varint(bytes).map(|(v, _)| v != 0).map_err(|_| crate::runtime::RotoError::WireFormatViolation) + crate::runtime::read_varint(bytes) + .map(|(v, _)| v != 0) + .map_err(|_| crate::runtime::RotoError::WireFormatViolation) } pub fn deprecated_or_default(&self) -> crate::runtime::Result { self.deprecated().or(Ok(false)) } - pub fn has_deprecated(&self) -> bool { self.deprecated_offset.is_some() } + pub fn has_deprecated(&self) -> bool { + self.deprecated_offset.is_some() + } pub fn cc_enable_arenas(&self) -> crate::runtime::Result { - let offset = self.cc_enable_arenas_offset.ok_or(crate::runtime::RotoError::FieldNotFound)?; + let offset = self + .cc_enable_arenas_offset + .ok_or(crate::runtime::RotoError::FieldNotFound)?; let (bytes, _) = self.accessor.get_value_at(offset)?; - crate::runtime::read_varint(bytes).map(|(v, _)| v != 0).map_err(|_| crate::runtime::RotoError::WireFormatViolation) + crate::runtime::read_varint(bytes) + .map(|(v, _)| v != 0) + .map_err(|_| crate::runtime::RotoError::WireFormatViolation) } pub fn cc_enable_arenas_or_default(&self) -> crate::runtime::Result { self.cc_enable_arenas().or(Ok(false)) } - pub fn has_cc_enable_arenas(&self) -> bool { self.cc_enable_arenas_offset.is_some() } + pub fn has_cc_enable_arenas(&self) -> bool { + self.cc_enable_arenas_offset.is_some() + } pub fn objc_class_prefix(&self) -> crate::runtime::Result<&'a str> { - let offset = self.objc_class_prefix_offset.ok_or(crate::runtime::RotoError::FieldNotFound)?; + let offset = self + .objc_class_prefix_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) } @@ -3269,10 +3777,14 @@ uninterpreted_option_start, uninterpreted_option_end, self.objc_class_prefix().or(Ok("")) } - pub fn has_objc_class_prefix(&self) -> bool { self.objc_class_prefix_offset.is_some() } + pub fn has_objc_class_prefix(&self) -> bool { + self.objc_class_prefix_offset.is_some() + } pub fn csharp_namespace(&self) -> crate::runtime::Result<&'a str> { - let offset = self.csharp_namespace_offset.ok_or(crate::runtime::RotoError::FieldNotFound)?; + let offset = self + .csharp_namespace_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) } @@ -3281,10 +3793,14 @@ uninterpreted_option_start, uninterpreted_option_end, self.csharp_namespace().or(Ok("")) } - pub fn has_csharp_namespace(&self) -> bool { self.csharp_namespace_offset.is_some() } + pub fn has_csharp_namespace(&self) -> bool { + self.csharp_namespace_offset.is_some() + } pub fn swift_prefix(&self) -> crate::runtime::Result<&'a str> { - let offset = self.swift_prefix_offset.ok_or(crate::runtime::RotoError::FieldNotFound)?; + let offset = self + .swift_prefix_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) } @@ -3293,10 +3809,14 @@ uninterpreted_option_start, uninterpreted_option_end, self.swift_prefix().or(Ok("")) } - pub fn has_swift_prefix(&self) -> bool { self.swift_prefix_offset.is_some() } + pub fn has_swift_prefix(&self) -> bool { + self.swift_prefix_offset.is_some() + } pub fn php_class_prefix(&self) -> crate::runtime::Result<&'a str> { - let offset = self.php_class_prefix_offset.ok_or(crate::runtime::RotoError::FieldNotFound)?; + let offset = self + .php_class_prefix_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) } @@ -3305,10 +3825,14 @@ uninterpreted_option_start, uninterpreted_option_end, self.php_class_prefix().or(Ok("")) } - pub fn has_php_class_prefix(&self) -> bool { self.php_class_prefix_offset.is_some() } + pub fn has_php_class_prefix(&self) -> bool { + self.php_class_prefix_offset.is_some() + } pub fn php_namespace(&self) -> crate::runtime::Result<&'a str> { - let offset = self.php_namespace_offset.ok_or(crate::runtime::RotoError::FieldNotFound)?; + let offset = self + .php_namespace_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) } @@ -3317,10 +3841,14 @@ uninterpreted_option_start, uninterpreted_option_end, self.php_namespace().or(Ok("")) } - pub fn has_php_namespace(&self) -> bool { self.php_namespace_offset.is_some() } + pub fn has_php_namespace(&self) -> bool { + self.php_namespace_offset.is_some() + } pub fn php_metadata_namespace(&self) -> crate::runtime::Result<&'a str> { - let offset = self.php_metadata_namespace_offset.ok_or(crate::runtime::RotoError::FieldNotFound)?; + let offset = self + .php_metadata_namespace_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) } @@ -3329,10 +3857,14 @@ uninterpreted_option_start, uninterpreted_option_end, self.php_metadata_namespace().or(Ok("")) } - pub fn has_php_metadata_namespace(&self) -> bool { self.php_metadata_namespace_offset.is_some() } + pub fn has_php_metadata_namespace(&self) -> bool { + self.php_metadata_namespace_offset.is_some() + } pub fn ruby_package(&self) -> crate::runtime::Result<&'a str> { - let offset = self.ruby_package_offset.ok_or(crate::runtime::RotoError::FieldNotFound)?; + let offset = self + .ruby_package_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) } @@ -3341,10 +3873,14 @@ uninterpreted_option_start, uninterpreted_option_end, self.ruby_package().or(Ok("")) } - pub fn has_ruby_package(&self) -> bool { self.ruby_package_offset.is_some() } + pub fn has_ruby_package(&self) -> bool { + self.ruby_package_offset.is_some() + } pub fn features(&self) -> crate::runtime::Result<&'a [u8]> { - let offset = self.features_offset.ok_or(crate::runtime::RotoError::FieldNotFound)?; + let offset = self + .features_offset + .ok_or(crate::runtime::RotoError::FieldNotFound)?; let (bytes, _) = self.accessor.get_value_at(offset)?; Ok(bytes) } @@ -3353,10 +3889,15 @@ uninterpreted_option_start, uninterpreted_option_end, self.features().or(Ok(&[])) } - pub fn has_features(&self) -> bool { self.features_offset.is_some() } + pub fn has_features(&self) -> bool { + self.features_offset.is_some() + } pub fn uninterpreted_option(&self) -> crate::runtime::RepeatedFieldIterator<'a> { - match (self.uninterpreted_option_start, self.uninterpreted_option_end) { + match ( + self.uninterpreted_option_start, + self.uninterpreted_option_end, + ) { (Some(start), Some(end)) => self.accessor.iter_repeated_range(999, start, end), _ => self.accessor.iter_repeated(999), } @@ -3365,7 +3906,6 @@ uninterpreted_option_start, uninterpreted_option_end, pub fn raw_fields(&self) -> crate::runtime::RawFieldIterator<'a> { self.accessor.raw_fields() } - } pub struct FileOptionsBuilder<'b> { @@ -3608,28 +4148,27 @@ impl crate::runtime::RotoMessage for OwnedFileOptions { } pub mod file_options { -#[derive(Debug, Clone, Copy, PartialEq, Eq)] -#[repr(i32)] -pub enum OptimizeMode { - SPEED = 1, - CODESIZE = 2, - LITERUNTIME = 3, - Unknown = 0, -} + #[derive(Debug, Clone, Copy, PartialEq, Eq)] + #[repr(i32)] + pub enum OptimizeMode { + SPEED = 1, + CODESIZE = 2, + LITERUNTIME = 3, + Unknown = 0, + } -impl OptimizeMode { - pub fn from_i32(value: i32) -> Self { - match value { - 1 => OptimizeMode::SPEED, - 2 => OptimizeMode::CODESIZE, - 3 => OptimizeMode::LITERUNTIME, - _ => OptimizeMode::Unknown, + impl OptimizeMode { + pub fn from_i32(value: i32) -> Self { + match value { + 1 => OptimizeMode::SPEED, + 2 => OptimizeMode::CODESIZE, + 3 => OptimizeMode::LITERUNTIME, + _ => OptimizeMode::Unknown, + } } } } -} - pub struct MessageOptions<'a> { accessor: crate::runtime::ProtoAccessor<'a>, message_set_wire_format_offset: Option, @@ -3655,92 +4194,141 @@ impl<'a> MessageOptions<'a> { let mut uninterpreted_option_end = None; for item in accessor.fields() { let (offset, tag, _) = item?; - if tag.field_number == 1 { message_set_wire_format_offset = Some(offset); } - if tag.field_number == 2 { no_standard_descriptor_accessor_offset = Some(offset); } - if tag.field_number == 3 { deprecated_offset = Some(offset); } - if tag.field_number == 7 { map_entry_offset = Some(offset); } - if tag.field_number == 11 { deprecated_legacy_json_field_conflicts_offset = Some(offset); } - if tag.field_number == 12 { features_offset = Some(offset); } + if tag.field_number == 1 { + message_set_wire_format_offset = Some(offset); + } + if tag.field_number == 2 { + no_standard_descriptor_accessor_offset = Some(offset); + } + if tag.field_number == 3 { + deprecated_offset = Some(offset); + } + if tag.field_number == 7 { + map_entry_offset = Some(offset); + } + if tag.field_number == 11 { + deprecated_legacy_json_field_conflicts_offset = Some(offset); + } + if tag.field_number == 12 { + features_offset = Some(offset); + } if tag.field_number == 999 { - if uninterpreted_option_start.is_none() { uninterpreted_option_start = Some(offset); } + if uninterpreted_option_start.is_none() { + uninterpreted_option_start = Some(offset); + } uninterpreted_option_end = Some(offset); } } Ok(Self { accessor, -message_set_wire_format_offset, -no_standard_descriptor_accessor_offset, -deprecated_offset, -map_entry_offset, -deprecated_legacy_json_field_conflicts_offset, -features_offset, -uninterpreted_option_start, uninterpreted_option_end, + message_set_wire_format_offset, + no_standard_descriptor_accessor_offset, + deprecated_offset, + map_entry_offset, + deprecated_legacy_json_field_conflicts_offset, + features_offset, + uninterpreted_option_start, + uninterpreted_option_end, }) } pub fn message_set_wire_format(&self) -> crate::runtime::Result { - let offset = self.message_set_wire_format_offset.ok_or(crate::runtime::RotoError::FieldNotFound)?; + let offset = self + .message_set_wire_format_offset + .ok_or(crate::runtime::RotoError::FieldNotFound)?; let (bytes, _) = self.accessor.get_value_at(offset)?; - crate::runtime::read_varint(bytes).map(|(v, _)| v != 0).map_err(|_| crate::runtime::RotoError::WireFormatViolation) + crate::runtime::read_varint(bytes) + .map(|(v, _)| v != 0) + .map_err(|_| crate::runtime::RotoError::WireFormatViolation) } pub fn message_set_wire_format_or_default(&self) -> crate::runtime::Result { self.message_set_wire_format().or(Ok(false)) } - pub fn has_message_set_wire_format(&self) -> bool { self.message_set_wire_format_offset.is_some() } + pub fn has_message_set_wire_format(&self) -> bool { + self.message_set_wire_format_offset.is_some() + } pub fn no_standard_descriptor_accessor(&self) -> crate::runtime::Result { - let offset = self.no_standard_descriptor_accessor_offset.ok_or(crate::runtime::RotoError::FieldNotFound)?; + let offset = self + .no_standard_descriptor_accessor_offset + .ok_or(crate::runtime::RotoError::FieldNotFound)?; let (bytes, _) = self.accessor.get_value_at(offset)?; - crate::runtime::read_varint(bytes).map(|(v, _)| v != 0).map_err(|_| crate::runtime::RotoError::WireFormatViolation) + crate::runtime::read_varint(bytes) + .map(|(v, _)| v != 0) + .map_err(|_| crate::runtime::RotoError::WireFormatViolation) } pub fn no_standard_descriptor_accessor_or_default(&self) -> crate::runtime::Result { self.no_standard_descriptor_accessor().or(Ok(false)) } - pub fn has_no_standard_descriptor_accessor(&self) -> bool { self.no_standard_descriptor_accessor_offset.is_some() } + pub fn has_no_standard_descriptor_accessor(&self) -> bool { + self.no_standard_descriptor_accessor_offset.is_some() + } pub fn deprecated(&self) -> crate::runtime::Result { - let offset = self.deprecated_offset.ok_or(crate::runtime::RotoError::FieldNotFound)?; + let offset = self + .deprecated_offset + .ok_or(crate::runtime::RotoError::FieldNotFound)?; let (bytes, _) = self.accessor.get_value_at(offset)?; - crate::runtime::read_varint(bytes).map(|(v, _)| v != 0).map_err(|_| crate::runtime::RotoError::WireFormatViolation) + crate::runtime::read_varint(bytes) + .map(|(v, _)| v != 0) + .map_err(|_| crate::runtime::RotoError::WireFormatViolation) } pub fn deprecated_or_default(&self) -> crate::runtime::Result { self.deprecated().or(Ok(false)) } - pub fn has_deprecated(&self) -> bool { self.deprecated_offset.is_some() } + pub fn has_deprecated(&self) -> bool { + self.deprecated_offset.is_some() + } pub fn map_entry(&self) -> crate::runtime::Result { - let offset = self.map_entry_offset.ok_or(crate::runtime::RotoError::FieldNotFound)?; + let offset = self + .map_entry_offset + .ok_or(crate::runtime::RotoError::FieldNotFound)?; let (bytes, _) = self.accessor.get_value_at(offset)?; - crate::runtime::read_varint(bytes).map(|(v, _)| v != 0).map_err(|_| crate::runtime::RotoError::WireFormatViolation) + crate::runtime::read_varint(bytes) + .map(|(v, _)| v != 0) + .map_err(|_| crate::runtime::RotoError::WireFormatViolation) } pub fn map_entry_or_default(&self) -> crate::runtime::Result { self.map_entry().or(Ok(false)) } - pub fn has_map_entry(&self) -> bool { self.map_entry_offset.is_some() } - - pub fn deprecated_legacy_json_field_conflicts(&self) -> crate::runtime::Result { - let offset = self.deprecated_legacy_json_field_conflicts_offset.ok_or(crate::runtime::RotoError::FieldNotFound)?; - let (bytes, _) = self.accessor.get_value_at(offset)?; - crate::runtime::read_varint(bytes).map(|(v, _)| v != 0).map_err(|_| crate::runtime::RotoError::WireFormatViolation) + pub fn has_map_entry(&self) -> bool { + self.map_entry_offset.is_some() } - pub fn deprecated_legacy_json_field_conflicts_or_default(&self) -> crate::runtime::Result { + pub fn deprecated_legacy_json_field_conflicts(&self) -> crate::runtime::Result { + let offset = self + .deprecated_legacy_json_field_conflicts_offset + .ok_or(crate::runtime::RotoError::FieldNotFound)?; + let (bytes, _) = self.accessor.get_value_at(offset)?; + crate::runtime::read_varint(bytes) + .map(|(v, _)| v != 0) + .map_err(|_| crate::runtime::RotoError::WireFormatViolation) + } + + pub fn deprecated_legacy_json_field_conflicts_or_default( + &self, + ) -> crate::runtime::Result { self.deprecated_legacy_json_field_conflicts().or(Ok(false)) } - pub fn has_deprecated_legacy_json_field_conflicts(&self) -> bool { self.deprecated_legacy_json_field_conflicts_offset.is_some() } + pub fn has_deprecated_legacy_json_field_conflicts(&self) -> bool { + self.deprecated_legacy_json_field_conflicts_offset.is_some() + } pub fn features(&self) -> crate::runtime::Result<&'a [u8]> { - let offset = self.features_offset.ok_or(crate::runtime::RotoError::FieldNotFound)?; + let offset = self + .features_offset + .ok_or(crate::runtime::RotoError::FieldNotFound)?; let (bytes, _) = self.accessor.get_value_at(offset)?; Ok(bytes) } @@ -3749,10 +4337,15 @@ uninterpreted_option_start, uninterpreted_option_end, self.features().or(Ok(&[])) } - pub fn has_features(&self) -> bool { self.features_offset.is_some() } + pub fn has_features(&self) -> bool { + self.features_offset.is_some() + } pub fn uninterpreted_option(&self) -> crate::runtime::RepeatedFieldIterator<'a> { - match (self.uninterpreted_option_start, self.uninterpreted_option_end) { + match ( + self.uninterpreted_option_start, + self.uninterpreted_option_end, + ) { (Some(start), Some(end)) => self.accessor.iter_repeated_range(999, start, end), _ => self.accessor.iter_repeated(999), } @@ -3761,7 +4354,6 @@ uninterpreted_option_start, uninterpreted_option_end, pub fn raw_fields(&self) -> crate::runtime::RawFieldIterator<'a> { self.accessor.raw_fields() } - } pub struct MessageOptionsBuilder<'b> { @@ -3813,7 +4405,10 @@ impl<'b> MessageOptionsBuilder<'b> { Ok(self) } - pub fn deprecated_legacy_json_field_conflicts(mut self, value: u64) -> crate::runtime::Result { + pub fn deprecated_legacy_json_field_conflicts( + mut self, + value: u64, + ) -> crate::runtime::Result { self.builder.write_varint(11, value)?; self.deprecated_legacy_json_field_conflicts_written = true; Ok(self) @@ -3920,157 +4515,242 @@ impl<'a> FieldOptions<'a> { let mut uninterpreted_option_end = None; for item in accessor.fields() { let (offset, tag, _) = item?; - if tag.field_number == 1 { ctype_offset = Some(offset); } - if tag.field_number == 2 { packed_offset = Some(offset); } - if tag.field_number == 6 { jstype_offset = Some(offset); } - if tag.field_number == 5 { lazy_offset = Some(offset); } - if tag.field_number == 15 { unverified_lazy_offset = Some(offset); } - if tag.field_number == 3 { deprecated_offset = Some(offset); } - if tag.field_number == 10 { weak_offset = Some(offset); } - if tag.field_number == 16 { debug_redact_offset = Some(offset); } - if tag.field_number == 17 { retention_offset = Some(offset); } + if tag.field_number == 1 { + ctype_offset = Some(offset); + } + if tag.field_number == 2 { + packed_offset = Some(offset); + } + if tag.field_number == 6 { + jstype_offset = Some(offset); + } + if tag.field_number == 5 { + lazy_offset = Some(offset); + } + if tag.field_number == 15 { + unverified_lazy_offset = Some(offset); + } + if tag.field_number == 3 { + deprecated_offset = Some(offset); + } + if tag.field_number == 10 { + weak_offset = Some(offset); + } + if tag.field_number == 16 { + debug_redact_offset = Some(offset); + } + if tag.field_number == 17 { + retention_offset = Some(offset); + } if tag.field_number == 19 { - if targets_start.is_none() { targets_start = Some(offset); } + if targets_start.is_none() { + targets_start = Some(offset); + } targets_end = Some(offset); } if tag.field_number == 20 { - if edition_defaults_start.is_none() { edition_defaults_start = Some(offset); } + if edition_defaults_start.is_none() { + edition_defaults_start = Some(offset); + } edition_defaults_end = Some(offset); } - if tag.field_number == 21 { features_offset = Some(offset); } - if tag.field_number == 22 { feature_support_offset = Some(offset); } + if tag.field_number == 21 { + features_offset = Some(offset); + } + if tag.field_number == 22 { + feature_support_offset = Some(offset); + } if tag.field_number == 999 { - if uninterpreted_option_start.is_none() { uninterpreted_option_start = Some(offset); } + if uninterpreted_option_start.is_none() { + uninterpreted_option_start = Some(offset); + } uninterpreted_option_end = Some(offset); } } Ok(Self { accessor, -ctype_offset, -packed_offset, -jstype_offset, -lazy_offset, -unverified_lazy_offset, -deprecated_offset, -weak_offset, -debug_redact_offset, -retention_offset, -targets_start, targets_end, -edition_defaults_start, edition_defaults_end, -features_offset, -feature_support_offset, -uninterpreted_option_start, uninterpreted_option_end, + ctype_offset, + packed_offset, + jstype_offset, + lazy_offset, + unverified_lazy_offset, + deprecated_offset, + weak_offset, + debug_redact_offset, + retention_offset, + targets_start, + targets_end, + edition_defaults_start, + edition_defaults_end, + features_offset, + feature_support_offset, + uninterpreted_option_start, + uninterpreted_option_end, }) } pub fn ctype(&self) -> crate::runtime::Result { - let offset = self.ctype_offset.ok_or(crate::runtime::RotoError::FieldNotFound)?; + let offset = self + .ctype_offset + .ok_or(crate::runtime::RotoError::FieldNotFound)?; let (bytes, _) = self.accessor.get_value_at(offset)?; - crate::runtime::read_varint(bytes).map(|(v, _)| v as u64).map_err(|_| crate::runtime::RotoError::WireFormatViolation) + crate::runtime::read_varint(bytes) + .map(|(v, _)| v as u64) + .map_err(|_| crate::runtime::RotoError::WireFormatViolation) } pub fn ctype_or_default(&self) -> crate::runtime::Result { self.ctype().or(Ok(0)) } - pub fn has_ctype(&self) -> bool { self.ctype_offset.is_some() } + pub fn has_ctype(&self) -> bool { + self.ctype_offset.is_some() + } pub fn packed(&self) -> crate::runtime::Result { - let offset = self.packed_offset.ok_or(crate::runtime::RotoError::FieldNotFound)?; + let offset = self + .packed_offset + .ok_or(crate::runtime::RotoError::FieldNotFound)?; let (bytes, _) = self.accessor.get_value_at(offset)?; - crate::runtime::read_varint(bytes).map(|(v, _)| v != 0).map_err(|_| crate::runtime::RotoError::WireFormatViolation) + crate::runtime::read_varint(bytes) + .map(|(v, _)| v != 0) + .map_err(|_| crate::runtime::RotoError::WireFormatViolation) } pub fn packed_or_default(&self) -> crate::runtime::Result { self.packed().or(Ok(false)) } - pub fn has_packed(&self) -> bool { self.packed_offset.is_some() } + pub fn has_packed(&self) -> bool { + self.packed_offset.is_some() + } pub fn jstype(&self) -> crate::runtime::Result { - let offset = self.jstype_offset.ok_or(crate::runtime::RotoError::FieldNotFound)?; + let offset = self + .jstype_offset + .ok_or(crate::runtime::RotoError::FieldNotFound)?; let (bytes, _) = self.accessor.get_value_at(offset)?; - crate::runtime::read_varint(bytes).map(|(v, _)| v as u64).map_err(|_| crate::runtime::RotoError::WireFormatViolation) + crate::runtime::read_varint(bytes) + .map(|(v, _)| v as u64) + .map_err(|_| crate::runtime::RotoError::WireFormatViolation) } pub fn jstype_or_default(&self) -> crate::runtime::Result { self.jstype().or(Ok(0)) } - pub fn has_jstype(&self) -> bool { self.jstype_offset.is_some() } + pub fn has_jstype(&self) -> bool { + self.jstype_offset.is_some() + } pub fn lazy(&self) -> crate::runtime::Result { - let offset = self.lazy_offset.ok_or(crate::runtime::RotoError::FieldNotFound)?; + let offset = self + .lazy_offset + .ok_or(crate::runtime::RotoError::FieldNotFound)?; let (bytes, _) = self.accessor.get_value_at(offset)?; - crate::runtime::read_varint(bytes).map(|(v, _)| v != 0).map_err(|_| crate::runtime::RotoError::WireFormatViolation) + crate::runtime::read_varint(bytes) + .map(|(v, _)| v != 0) + .map_err(|_| crate::runtime::RotoError::WireFormatViolation) } pub fn lazy_or_default(&self) -> crate::runtime::Result { self.lazy().or(Ok(false)) } - pub fn has_lazy(&self) -> bool { self.lazy_offset.is_some() } + pub fn has_lazy(&self) -> bool { + self.lazy_offset.is_some() + } pub fn unverified_lazy(&self) -> crate::runtime::Result { - let offset = self.unverified_lazy_offset.ok_or(crate::runtime::RotoError::FieldNotFound)?; + let offset = self + .unverified_lazy_offset + .ok_or(crate::runtime::RotoError::FieldNotFound)?; let (bytes, _) = self.accessor.get_value_at(offset)?; - crate::runtime::read_varint(bytes).map(|(v, _)| v != 0).map_err(|_| crate::runtime::RotoError::WireFormatViolation) + crate::runtime::read_varint(bytes) + .map(|(v, _)| v != 0) + .map_err(|_| crate::runtime::RotoError::WireFormatViolation) } pub fn unverified_lazy_or_default(&self) -> crate::runtime::Result { self.unverified_lazy().or(Ok(false)) } - pub fn has_unverified_lazy(&self) -> bool { self.unverified_lazy_offset.is_some() } + pub fn has_unverified_lazy(&self) -> bool { + self.unverified_lazy_offset.is_some() + } pub fn deprecated(&self) -> crate::runtime::Result { - let offset = self.deprecated_offset.ok_or(crate::runtime::RotoError::FieldNotFound)?; + let offset = self + .deprecated_offset + .ok_or(crate::runtime::RotoError::FieldNotFound)?; let (bytes, _) = self.accessor.get_value_at(offset)?; - crate::runtime::read_varint(bytes).map(|(v, _)| v != 0).map_err(|_| crate::runtime::RotoError::WireFormatViolation) + crate::runtime::read_varint(bytes) + .map(|(v, _)| v != 0) + .map_err(|_| crate::runtime::RotoError::WireFormatViolation) } pub fn deprecated_or_default(&self) -> crate::runtime::Result { self.deprecated().or(Ok(false)) } - pub fn has_deprecated(&self) -> bool { self.deprecated_offset.is_some() } + pub fn has_deprecated(&self) -> bool { + self.deprecated_offset.is_some() + } pub fn weak(&self) -> crate::runtime::Result { - let offset = self.weak_offset.ok_or(crate::runtime::RotoError::FieldNotFound)?; + let offset = self + .weak_offset + .ok_or(crate::runtime::RotoError::FieldNotFound)?; let (bytes, _) = self.accessor.get_value_at(offset)?; - crate::runtime::read_varint(bytes).map(|(v, _)| v != 0).map_err(|_| crate::runtime::RotoError::WireFormatViolation) + crate::runtime::read_varint(bytes) + .map(|(v, _)| v != 0) + .map_err(|_| crate::runtime::RotoError::WireFormatViolation) } pub fn weak_or_default(&self) -> crate::runtime::Result { self.weak().or(Ok(false)) } - pub fn has_weak(&self) -> bool { self.weak_offset.is_some() } + pub fn has_weak(&self) -> bool { + self.weak_offset.is_some() + } pub fn debug_redact(&self) -> crate::runtime::Result { - let offset = self.debug_redact_offset.ok_or(crate::runtime::RotoError::FieldNotFound)?; + let offset = self + .debug_redact_offset + .ok_or(crate::runtime::RotoError::FieldNotFound)?; let (bytes, _) = self.accessor.get_value_at(offset)?; - crate::runtime::read_varint(bytes).map(|(v, _)| v != 0).map_err(|_| crate::runtime::RotoError::WireFormatViolation) + crate::runtime::read_varint(bytes) + .map(|(v, _)| v != 0) + .map_err(|_| crate::runtime::RotoError::WireFormatViolation) } pub fn debug_redact_or_default(&self) -> crate::runtime::Result { self.debug_redact().or(Ok(false)) } - pub fn has_debug_redact(&self) -> bool { self.debug_redact_offset.is_some() } + pub fn has_debug_redact(&self) -> bool { + self.debug_redact_offset.is_some() + } pub fn retention(&self) -> crate::runtime::Result { - let offset = self.retention_offset.ok_or(crate::runtime::RotoError::FieldNotFound)?; + let offset = self + .retention_offset + .ok_or(crate::runtime::RotoError::FieldNotFound)?; let (bytes, _) = self.accessor.get_value_at(offset)?; - crate::runtime::read_varint(bytes).map(|(v, _)| v as u64).map_err(|_| crate::runtime::RotoError::WireFormatViolation) + crate::runtime::read_varint(bytes) + .map(|(v, _)| v as u64) + .map_err(|_| crate::runtime::RotoError::WireFormatViolation) } pub fn retention_or_default(&self) -> crate::runtime::Result { self.retention().or(Ok(0)) } - pub fn has_retention(&self) -> bool { self.retention_offset.is_some() } + pub fn has_retention(&self) -> bool { + self.retention_offset.is_some() + } pub fn targets(&self) -> crate::runtime::RepeatedFieldIterator<'a> { match (self.targets_start, self.targets_end) { @@ -4087,7 +4767,9 @@ uninterpreted_option_start, uninterpreted_option_end, } pub fn features(&self) -> crate::runtime::Result<&'a [u8]> { - let offset = self.features_offset.ok_or(crate::runtime::RotoError::FieldNotFound)?; + let offset = self + .features_offset + .ok_or(crate::runtime::RotoError::FieldNotFound)?; let (bytes, _) = self.accessor.get_value_at(offset)?; Ok(bytes) } @@ -4096,10 +4778,14 @@ uninterpreted_option_start, uninterpreted_option_end, self.features().or(Ok(&[])) } - pub fn has_features(&self) -> bool { self.features_offset.is_some() } + pub fn has_features(&self) -> bool { + self.features_offset.is_some() + } pub fn feature_support(&self) -> crate::runtime::Result<&'a [u8]> { - let offset = self.feature_support_offset.ok_or(crate::runtime::RotoError::FieldNotFound)?; + let offset = self + .feature_support_offset + .ok_or(crate::runtime::RotoError::FieldNotFound)?; let (bytes, _) = self.accessor.get_value_at(offset)?; Ok(bytes) } @@ -4108,10 +4794,15 @@ uninterpreted_option_start, uninterpreted_option_end, self.feature_support().or(Ok(&[])) } - pub fn has_feature_support(&self) -> bool { self.feature_support_offset.is_some() } + pub fn has_feature_support(&self) -> bool { + self.feature_support_offset.is_some() + } pub fn uninterpreted_option(&self) -> crate::runtime::RepeatedFieldIterator<'a> { - match (self.uninterpreted_option_start, self.uninterpreted_option_end) { + match ( + self.uninterpreted_option_start, + self.uninterpreted_option_end, + ) { (Some(start), Some(end)) => self.accessor.iter_repeated_range(999, start, end), _ => self.accessor.iter_repeated(999), } @@ -4120,7 +4811,6 @@ uninterpreted_option_start, uninterpreted_option_end, pub fn raw_fields(&self) -> crate::runtime::RawFieldIterator<'a> { self.accessor.raw_fields() } - } pub struct FieldOptionsBuilder<'b> { @@ -4300,415 +4990,462 @@ impl crate::runtime::RotoMessage for OwnedFieldOptions { } pub mod field_options { -#[derive(Debug, Clone, Copy, PartialEq, Eq)] -#[repr(i32)] -pub enum CType { - STRING = 0, - CORD = 1, - STRINGPIECE = 2, -} - -impl CType { - pub fn from_i32(value: i32) -> Self { - match value { - 0 => CType::STRING, - 1 => CType::CORD, - 2 => CType::STRINGPIECE, - _ => CType::STRING, - } - } -} - -#[derive(Debug, Clone, Copy, PartialEq, Eq)] -#[repr(i32)] -pub enum JSType { - JSNORMAL = 0, - JSSTRING = 1, - JSNUMBER = 2, -} - -impl JSType { - pub fn from_i32(value: i32) -> Self { - match value { - 0 => JSType::JSNORMAL, - 1 => JSType::JSSTRING, - 2 => JSType::JSNUMBER, - _ => JSType::JSNORMAL, - } - } -} - -#[derive(Debug, Clone, Copy, PartialEq, Eq)] -#[repr(i32)] -pub enum OptionRetention { - RETENTIONUNKNOWN = 0, - RETENTIONRUNTIME = 1, - RETENTIONSOURCE = 2, -} - -impl OptionRetention { - pub fn from_i32(value: i32) -> Self { - match value { - 0 => OptionRetention::RETENTIONUNKNOWN, - 1 => OptionRetention::RETENTIONRUNTIME, - 2 => OptionRetention::RETENTIONSOURCE, - _ => OptionRetention::RETENTIONUNKNOWN, - } - } -} - -#[derive(Debug, Clone, Copy, PartialEq, Eq)] -#[repr(i32)] -pub enum OptionTargetType { - TARGETTYPEUNKNOWN = 0, - TARGETTYPEFILE = 1, - TARGETTYPEEXTENSIONRANGE = 2, - TARGETTYPEMESSAGE = 3, - TARGETTYPEFIELD = 4, - TARGETTYPEONEOF = 5, - TARGETTYPEENUM = 6, - TARGETTYPEENUMENTRY = 7, - TARGETTYPESERVICE = 8, - TARGETTYPEMETHOD = 9, -} - -impl OptionTargetType { - pub fn from_i32(value: i32) -> Self { - match value { - 0 => OptionTargetType::TARGETTYPEUNKNOWN, - 1 => OptionTargetType::TARGETTYPEFILE, - 2 => OptionTargetType::TARGETTYPEEXTENSIONRANGE, - 3 => OptionTargetType::TARGETTYPEMESSAGE, - 4 => OptionTargetType::TARGETTYPEFIELD, - 5 => OptionTargetType::TARGETTYPEONEOF, - 6 => OptionTargetType::TARGETTYPEENUM, - 7 => OptionTargetType::TARGETTYPEENUMENTRY, - 8 => OptionTargetType::TARGETTYPESERVICE, - 9 => OptionTargetType::TARGETTYPEMETHOD, - _ => OptionTargetType::TARGETTYPEUNKNOWN, - } - } -} - -pub struct EditionDefault<'a> { - accessor: crate::runtime::ProtoAccessor<'a>, - edition_offset: Option, - value_offset: Option, -} - -impl<'a> EditionDefault<'a> { - pub fn new(data: &'a [u8]) -> crate::runtime::Result { - let accessor = crate::runtime::ProtoAccessor::new(data)?; - let mut edition_offset = None; - let mut value_offset = None; - for item in accessor.fields() { - let (offset, tag, _) = item?; - if tag.field_number == 3 { edition_offset = Some(offset); } - if tag.field_number == 2 { value_offset = Some(offset); } - } - - Ok(Self { - accessor, -edition_offset, -value_offset, - }) + #[derive(Debug, Clone, Copy, PartialEq, Eq)] + #[repr(i32)] + pub enum CType { + STRING = 0, + CORD = 1, + STRINGPIECE = 2, } - pub fn edition(&self) -> crate::runtime::Result { - let offset = self.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 u64).map_err(|_| crate::runtime::RotoError::WireFormatViolation) - } - - pub fn edition_or_default(&self) -> crate::runtime::Result { - self.edition().or(Ok(0)) - } - - pub fn has_edition(&self) -> bool { self.edition_offset.is_some() } - - pub fn value(&self) -> crate::runtime::Result<&'a str> { - let offset = self.value_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 value_or_default(&self) -> crate::runtime::Result<&'a str> { - self.value().or(Ok("")) - } - - pub fn has_value(&self) -> bool { self.value_offset.is_some() } - - pub fn raw_fields(&self) -> crate::runtime::RawFieldIterator<'a> { - self.accessor.raw_fields() - } - -} - -pub struct EditionDefaultBuilder<'b> { - builder: crate::runtime::ProtoBuilder<'b>, - edition_written: bool, - value_written: bool, -} - -impl<'b> EditionDefaultBuilder<'b> { - pub fn builder(buf: &mut [u8]) -> EditionDefaultBuilder<'_> { - EditionDefaultBuilder { - builder: crate::runtime::ProtoBuilder::new(buf), - edition_written: false, - value_written: false, - } - } - - pub fn edition(mut self, value: u64) -> crate::runtime::Result { - self.builder.write_varint(3, value)?; - self.edition_written = true; - Ok(self) - } - - pub fn value(mut self, value: &str) -> crate::runtime::Result { - self.builder.write_string(2, value)?; - self.value_written = true; - Ok(self) - } - - pub fn with(mut self, msg: &EditionDefault<'_>) -> crate::runtime::Result { - for item in msg.raw_fields() { - let (field_number, raw_bytes) = item?; - let is_written = match field_number { - 3 => self.edition_written, - 2 => self.value_written, - _ => false, - }; - if !is_written { - self.builder.write_raw(raw_bytes)?; + impl CType { + pub fn from_i32(value: i32) -> Self { + match value { + 0 => CType::STRING, + 1 => CType::CORD, + 2 => CType::STRINGPIECE, + _ => CType::STRING, } } - Ok(self) } - pub fn finish(self) -> crate::runtime::Result<&'b mut [u8]> { - self.builder.finish() - } -} - -pub struct OwnedEditionDefault { - pub data: bytes::Bytes, -} - -impl crate::runtime::RotoOwned for OwnedEditionDefault { - type Reader<'a> = EditionDefault<'a>; - fn reader(&self) -> EditionDefault<'_> { - EditionDefault::new(&self.data).expect("failed to create reader") - } -} - -impl crate::runtime::RotoMessage for OwnedEditionDefault { - fn decode(buf: bytes::Bytes) -> crate::runtime::Result { - Ok(OwnedEditionDefault { data: buf }) + #[derive(Debug, Clone, Copy, PartialEq, Eq)] + #[repr(i32)] + pub enum JSType { + JSNORMAL = 0, + JSSTRING = 1, + JSNUMBER = 2, } - fn bytes(&self) -> bytes::Bytes { - self.data.clone() - } -} - -pub struct FeatureSupport<'a> { - accessor: crate::runtime::ProtoAccessor<'a>, - edition_introduced_offset: Option, - edition_deprecated_offset: Option, - deprecation_warning_offset: Option, - edition_removed_offset: Option, - removal_error_offset: Option, -} - -impl<'a> FeatureSupport<'a> { - pub fn new(data: &'a [u8]) -> crate::runtime::Result { - let accessor = crate::runtime::ProtoAccessor::new(data)?; - let mut edition_introduced_offset = None; - let mut edition_deprecated_offset = None; - let mut deprecation_warning_offset = None; - let mut edition_removed_offset = None; - let mut removal_error_offset = None; - for item in accessor.fields() { - let (offset, tag, _) = item?; - if tag.field_number == 1 { edition_introduced_offset = Some(offset); } - if tag.field_number == 2 { edition_deprecated_offset = Some(offset); } - if tag.field_number == 3 { deprecation_warning_offset = Some(offset); } - if tag.field_number == 4 { edition_removed_offset = Some(offset); } - if tag.field_number == 5 { removal_error_offset = Some(offset); } - } - - Ok(Self { - accessor, -edition_introduced_offset, -edition_deprecated_offset, -deprecation_warning_offset, -edition_removed_offset, -removal_error_offset, - }) - } - - pub fn edition_introduced(&self) -> crate::runtime::Result { - let offset = self.edition_introduced_offset.ok_or(crate::runtime::RotoError::FieldNotFound)?; - let (bytes, _) = self.accessor.get_value_at(offset)?; - crate::runtime::read_varint(bytes).map(|(v, _)| v as u64).map_err(|_| crate::runtime::RotoError::WireFormatViolation) - } - - pub fn edition_introduced_or_default(&self) -> crate::runtime::Result { - self.edition_introduced().or(Ok(0)) - } - - pub fn has_edition_introduced(&self) -> bool { self.edition_introduced_offset.is_some() } - - pub fn edition_deprecated(&self) -> crate::runtime::Result { - let offset = self.edition_deprecated_offset.ok_or(crate::runtime::RotoError::FieldNotFound)?; - let (bytes, _) = self.accessor.get_value_at(offset)?; - crate::runtime::read_varint(bytes).map(|(v, _)| v as u64).map_err(|_| crate::runtime::RotoError::WireFormatViolation) - } - - pub fn edition_deprecated_or_default(&self) -> crate::runtime::Result { - self.edition_deprecated().or(Ok(0)) - } - - pub fn has_edition_deprecated(&self) -> bool { self.edition_deprecated_offset.is_some() } - - pub fn deprecation_warning(&self) -> crate::runtime::Result<&'a str> { - let offset = self.deprecation_warning_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 deprecation_warning_or_default(&self) -> crate::runtime::Result<&'a str> { - self.deprecation_warning().or(Ok("")) - } - - pub fn has_deprecation_warning(&self) -> bool { self.deprecation_warning_offset.is_some() } - - pub fn edition_removed(&self) -> crate::runtime::Result { - let offset = self.edition_removed_offset.ok_or(crate::runtime::RotoError::FieldNotFound)?; - let (bytes, _) = self.accessor.get_value_at(offset)?; - crate::runtime::read_varint(bytes).map(|(v, _)| v as u64).map_err(|_| crate::runtime::RotoError::WireFormatViolation) - } - - pub fn edition_removed_or_default(&self) -> crate::runtime::Result { - self.edition_removed().or(Ok(0)) - } - - pub fn has_edition_removed(&self) -> bool { self.edition_removed_offset.is_some() } - - pub fn removal_error(&self) -> crate::runtime::Result<&'a str> { - let offset = self.removal_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) - } - - pub fn removal_error_or_default(&self) -> crate::runtime::Result<&'a str> { - self.removal_error().or(Ok("")) - } - - pub fn has_removal_error(&self) -> bool { self.removal_error_offset.is_some() } - - pub fn raw_fields(&self) -> crate::runtime::RawFieldIterator<'a> { - self.accessor.raw_fields() - } - -} - -pub struct FeatureSupportBuilder<'b> { - builder: crate::runtime::ProtoBuilder<'b>, - edition_introduced_written: bool, - edition_deprecated_written: bool, - deprecation_warning_written: bool, - edition_removed_written: bool, - removal_error_written: bool, -} - -impl<'b> FeatureSupportBuilder<'b> { - pub fn builder(buf: &mut [u8]) -> FeatureSupportBuilder<'_> { - FeatureSupportBuilder { - builder: crate::runtime::ProtoBuilder::new(buf), - edition_introduced_written: false, - edition_deprecated_written: false, - deprecation_warning_written: false, - edition_removed_written: false, - removal_error_written: false, - } - } - - pub fn edition_introduced(mut self, value: u64) -> crate::runtime::Result { - self.builder.write_varint(1, value)?; - self.edition_introduced_written = true; - Ok(self) - } - - pub fn edition_deprecated(mut self, value: u64) -> crate::runtime::Result { - self.builder.write_varint(2, value)?; - self.edition_deprecated_written = true; - Ok(self) - } - - pub fn deprecation_warning(mut self, value: &str) -> crate::runtime::Result { - self.builder.write_string(3, value)?; - self.deprecation_warning_written = true; - Ok(self) - } - - pub fn edition_removed(mut self, value: u64) -> crate::runtime::Result { - self.builder.write_varint(4, value)?; - self.edition_removed_written = true; - Ok(self) - } - - pub fn removal_error(mut self, value: &str) -> crate::runtime::Result { - self.builder.write_string(5, value)?; - self.removal_error_written = true; - Ok(self) - } - - pub fn with(mut self, msg: &FeatureSupport<'_>) -> crate::runtime::Result { - for item in msg.raw_fields() { - let (field_number, raw_bytes) = item?; - let is_written = match field_number { - 1 => self.edition_introduced_written, - 2 => self.edition_deprecated_written, - 3 => self.deprecation_warning_written, - 4 => self.edition_removed_written, - 5 => self.removal_error_written, - _ => false, - }; - if !is_written { - self.builder.write_raw(raw_bytes)?; + impl JSType { + pub fn from_i32(value: i32) -> Self { + match value { + 0 => JSType::JSNORMAL, + 1 => JSType::JSSTRING, + 2 => JSType::JSNUMBER, + _ => JSType::JSNORMAL, } } - Ok(self) } - pub fn finish(self) -> crate::runtime::Result<&'b mut [u8]> { - self.builder.finish() - } -} - -pub struct OwnedFeatureSupport { - pub data: bytes::Bytes, -} - -impl crate::runtime::RotoOwned for OwnedFeatureSupport { - type Reader<'a> = FeatureSupport<'a>; - fn reader(&self) -> FeatureSupport<'_> { - FeatureSupport::new(&self.data).expect("failed to create reader") - } -} - -impl crate::runtime::RotoMessage for OwnedFeatureSupport { - fn decode(buf: bytes::Bytes) -> crate::runtime::Result { - Ok(OwnedFeatureSupport { data: buf }) + #[derive(Debug, Clone, Copy, PartialEq, Eq)] + #[repr(i32)] + pub enum OptionRetention { + RETENTIONUNKNOWN = 0, + RETENTIONRUNTIME = 1, + RETENTIONSOURCE = 2, } - fn bytes(&self) -> bytes::Bytes { - self.data.clone() + impl OptionRetention { + pub fn from_i32(value: i32) -> Self { + match value { + 0 => OptionRetention::RETENTIONUNKNOWN, + 1 => OptionRetention::RETENTIONRUNTIME, + 2 => OptionRetention::RETENTIONSOURCE, + _ => OptionRetention::RETENTIONUNKNOWN, + } + } } -} + #[derive(Debug, Clone, Copy, PartialEq, Eq)] + #[repr(i32)] + pub enum OptionTargetType { + TARGETTYPEUNKNOWN = 0, + TARGETTYPEFILE = 1, + TARGETTYPEEXTENSIONRANGE = 2, + TARGETTYPEMESSAGE = 3, + TARGETTYPEFIELD = 4, + TARGETTYPEONEOF = 5, + TARGETTYPEENUM = 6, + TARGETTYPEENUMENTRY = 7, + TARGETTYPESERVICE = 8, + TARGETTYPEMETHOD = 9, + } + + impl OptionTargetType { + pub fn from_i32(value: i32) -> Self { + match value { + 0 => OptionTargetType::TARGETTYPEUNKNOWN, + 1 => OptionTargetType::TARGETTYPEFILE, + 2 => OptionTargetType::TARGETTYPEEXTENSIONRANGE, + 3 => OptionTargetType::TARGETTYPEMESSAGE, + 4 => OptionTargetType::TARGETTYPEFIELD, + 5 => OptionTargetType::TARGETTYPEONEOF, + 6 => OptionTargetType::TARGETTYPEENUM, + 7 => OptionTargetType::TARGETTYPEENUMENTRY, + 8 => OptionTargetType::TARGETTYPESERVICE, + 9 => OptionTargetType::TARGETTYPEMETHOD, + _ => OptionTargetType::TARGETTYPEUNKNOWN, + } + } + } + + pub struct EditionDefault<'a> { + accessor: crate::runtime::ProtoAccessor<'a>, + edition_offset: Option, + value_offset: Option, + } + + impl<'a> EditionDefault<'a> { + pub fn new(data: &'a [u8]) -> crate::runtime::Result { + let accessor = crate::runtime::ProtoAccessor::new(data)?; + let mut edition_offset = None; + let mut value_offset = None; + for item in accessor.fields() { + let (offset, tag, _) = item?; + if tag.field_number == 3 { + edition_offset = Some(offset); + } + if tag.field_number == 2 { + value_offset = Some(offset); + } + } + + Ok(Self { + accessor, + edition_offset, + value_offset, + }) + } + + pub fn edition(&self) -> crate::runtime::Result { + let offset = self + .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 u64) + .map_err(|_| crate::runtime::RotoError::WireFormatViolation) + } + + pub fn edition_or_default(&self) -> crate::runtime::Result { + self.edition().or(Ok(0)) + } + + pub fn has_edition(&self) -> bool { + self.edition_offset.is_some() + } + + pub fn value(&self) -> crate::runtime::Result<&'a str> { + let offset = self + .value_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 value_or_default(&self) -> crate::runtime::Result<&'a str> { + self.value().or(Ok("")) + } + + pub fn has_value(&self) -> bool { + self.value_offset.is_some() + } + + pub fn raw_fields(&self) -> crate::runtime::RawFieldIterator<'a> { + self.accessor.raw_fields() + } + } + + pub struct EditionDefaultBuilder<'b> { + builder: crate::runtime::ProtoBuilder<'b>, + edition_written: bool, + value_written: bool, + } + + impl<'b> EditionDefaultBuilder<'b> { + pub fn builder(buf: &mut [u8]) -> EditionDefaultBuilder<'_> { + EditionDefaultBuilder { + builder: crate::runtime::ProtoBuilder::new(buf), + edition_written: false, + value_written: false, + } + } + + pub fn edition(mut self, value: u64) -> crate::runtime::Result { + self.builder.write_varint(3, value)?; + self.edition_written = true; + Ok(self) + } + + pub fn value(mut self, value: &str) -> crate::runtime::Result { + self.builder.write_string(2, value)?; + self.value_written = true; + Ok(self) + } + + pub fn with(mut self, msg: &EditionDefault<'_>) -> crate::runtime::Result { + for item in msg.raw_fields() { + let (field_number, raw_bytes) = item?; + let is_written = match field_number { + 3 => self.edition_written, + 2 => self.value_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 OwnedEditionDefault { + pub data: bytes::Bytes, + } + + impl crate::runtime::RotoOwned for OwnedEditionDefault { + type Reader<'a> = EditionDefault<'a>; + fn reader(&self) -> EditionDefault<'_> { + EditionDefault::new(&self.data).expect("failed to create reader") + } + } + + impl crate::runtime::RotoMessage for OwnedEditionDefault { + fn decode(buf: bytes::Bytes) -> crate::runtime::Result { + Ok(OwnedEditionDefault { data: buf }) + } + + fn bytes(&self) -> bytes::Bytes { + self.data.clone() + } + } + + pub struct FeatureSupport<'a> { + accessor: crate::runtime::ProtoAccessor<'a>, + edition_introduced_offset: Option, + edition_deprecated_offset: Option, + deprecation_warning_offset: Option, + edition_removed_offset: Option, + removal_error_offset: Option, + } + + impl<'a> FeatureSupport<'a> { + pub fn new(data: &'a [u8]) -> crate::runtime::Result { + let accessor = crate::runtime::ProtoAccessor::new(data)?; + let mut edition_introduced_offset = None; + let mut edition_deprecated_offset = None; + let mut deprecation_warning_offset = None; + let mut edition_removed_offset = None; + let mut removal_error_offset = None; + for item in accessor.fields() { + let (offset, tag, _) = item?; + if tag.field_number == 1 { + edition_introduced_offset = Some(offset); + } + if tag.field_number == 2 { + edition_deprecated_offset = Some(offset); + } + if tag.field_number == 3 { + deprecation_warning_offset = Some(offset); + } + if tag.field_number == 4 { + edition_removed_offset = Some(offset); + } + if tag.field_number == 5 { + removal_error_offset = Some(offset); + } + } + + Ok(Self { + accessor, + edition_introduced_offset, + edition_deprecated_offset, + deprecation_warning_offset, + edition_removed_offset, + removal_error_offset, + }) + } + + pub fn edition_introduced(&self) -> crate::runtime::Result { + let offset = self + .edition_introduced_offset + .ok_or(crate::runtime::RotoError::FieldNotFound)?; + let (bytes, _) = self.accessor.get_value_at(offset)?; + crate::runtime::read_varint(bytes) + .map(|(v, _)| v as u64) + .map_err(|_| crate::runtime::RotoError::WireFormatViolation) + } + + pub fn edition_introduced_or_default(&self) -> crate::runtime::Result { + self.edition_introduced().or(Ok(0)) + } + + pub fn has_edition_introduced(&self) -> bool { + self.edition_introduced_offset.is_some() + } + + pub fn edition_deprecated(&self) -> crate::runtime::Result { + let offset = self + .edition_deprecated_offset + .ok_or(crate::runtime::RotoError::FieldNotFound)?; + let (bytes, _) = self.accessor.get_value_at(offset)?; + crate::runtime::read_varint(bytes) + .map(|(v, _)| v as u64) + .map_err(|_| crate::runtime::RotoError::WireFormatViolation) + } + + pub fn edition_deprecated_or_default(&self) -> crate::runtime::Result { + self.edition_deprecated().or(Ok(0)) + } + + pub fn has_edition_deprecated(&self) -> bool { + self.edition_deprecated_offset.is_some() + } + + pub fn deprecation_warning(&self) -> crate::runtime::Result<&'a str> { + let offset = self + .deprecation_warning_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 deprecation_warning_or_default(&self) -> crate::runtime::Result<&'a str> { + self.deprecation_warning().or(Ok("")) + } + + pub fn has_deprecation_warning(&self) -> bool { + self.deprecation_warning_offset.is_some() + } + + pub fn edition_removed(&self) -> crate::runtime::Result { + let offset = self + .edition_removed_offset + .ok_or(crate::runtime::RotoError::FieldNotFound)?; + let (bytes, _) = self.accessor.get_value_at(offset)?; + crate::runtime::read_varint(bytes) + .map(|(v, _)| v as u64) + .map_err(|_| crate::runtime::RotoError::WireFormatViolation) + } + + pub fn edition_removed_or_default(&self) -> crate::runtime::Result { + self.edition_removed().or(Ok(0)) + } + + pub fn has_edition_removed(&self) -> bool { + self.edition_removed_offset.is_some() + } + + pub fn removal_error(&self) -> crate::runtime::Result<&'a str> { + let offset = self + .removal_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) + } + + pub fn removal_error_or_default(&self) -> crate::runtime::Result<&'a str> { + self.removal_error().or(Ok("")) + } + + pub fn has_removal_error(&self) -> bool { + self.removal_error_offset.is_some() + } + + pub fn raw_fields(&self) -> crate::runtime::RawFieldIterator<'a> { + self.accessor.raw_fields() + } + } + + pub struct FeatureSupportBuilder<'b> { + builder: crate::runtime::ProtoBuilder<'b>, + edition_introduced_written: bool, + edition_deprecated_written: bool, + deprecation_warning_written: bool, + edition_removed_written: bool, + removal_error_written: bool, + } + + impl<'b> FeatureSupportBuilder<'b> { + pub fn builder(buf: &mut [u8]) -> FeatureSupportBuilder<'_> { + FeatureSupportBuilder { + builder: crate::runtime::ProtoBuilder::new(buf), + edition_introduced_written: false, + edition_deprecated_written: false, + deprecation_warning_written: false, + edition_removed_written: false, + removal_error_written: false, + } + } + + pub fn edition_introduced(mut self, value: u64) -> crate::runtime::Result { + self.builder.write_varint(1, value)?; + self.edition_introduced_written = true; + Ok(self) + } + + pub fn edition_deprecated(mut self, value: u64) -> crate::runtime::Result { + self.builder.write_varint(2, value)?; + self.edition_deprecated_written = true; + Ok(self) + } + + pub fn deprecation_warning(mut self, value: &str) -> crate::runtime::Result { + self.builder.write_string(3, value)?; + self.deprecation_warning_written = true; + Ok(self) + } + + pub fn edition_removed(mut self, value: u64) -> crate::runtime::Result { + self.builder.write_varint(4, value)?; + self.edition_removed_written = true; + Ok(self) + } + + pub fn removal_error(mut self, value: &str) -> crate::runtime::Result { + self.builder.write_string(5, value)?; + self.removal_error_written = true; + Ok(self) + } + + pub fn with(mut self, msg: &FeatureSupport<'_>) -> crate::runtime::Result { + for item in msg.raw_fields() { + let (field_number, raw_bytes) = item?; + let is_written = match field_number { + 1 => self.edition_introduced_written, + 2 => self.edition_deprecated_written, + 3 => self.deprecation_warning_written, + 4 => self.edition_removed_written, + 5 => self.removal_error_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 OwnedFeatureSupport { + pub data: bytes::Bytes, + } + + impl crate::runtime::RotoOwned for OwnedFeatureSupport { + type Reader<'a> = FeatureSupport<'a>; + fn reader(&self) -> FeatureSupport<'_> { + FeatureSupport::new(&self.data).expect("failed to create reader") + } + } + + impl crate::runtime::RotoMessage for OwnedFeatureSupport { + fn decode(buf: bytes::Bytes) -> crate::runtime::Result { + Ok(OwnedFeatureSupport { data: buf }) + } + + fn bytes(&self) -> bytes::Bytes { + self.data.clone() + } + } } pub struct OneofOptions<'a> { @@ -4726,22 +5463,29 @@ impl<'a> OneofOptions<'a> { let mut uninterpreted_option_end = None; for item in accessor.fields() { let (offset, tag, _) = item?; - if tag.field_number == 1 { features_offset = Some(offset); } + if tag.field_number == 1 { + features_offset = Some(offset); + } if tag.field_number == 999 { - if uninterpreted_option_start.is_none() { uninterpreted_option_start = Some(offset); } + if uninterpreted_option_start.is_none() { + uninterpreted_option_start = Some(offset); + } uninterpreted_option_end = Some(offset); } } Ok(Self { accessor, -features_offset, -uninterpreted_option_start, uninterpreted_option_end, + features_offset, + uninterpreted_option_start, + uninterpreted_option_end, }) } pub fn features(&self) -> crate::runtime::Result<&'a [u8]> { - let offset = self.features_offset.ok_or(crate::runtime::RotoError::FieldNotFound)?; + let offset = self + .features_offset + .ok_or(crate::runtime::RotoError::FieldNotFound)?; let (bytes, _) = self.accessor.get_value_at(offset)?; Ok(bytes) } @@ -4750,10 +5494,15 @@ uninterpreted_option_start, uninterpreted_option_end, self.features().or(Ok(&[])) } - pub fn has_features(&self) -> bool { self.features_offset.is_some() } + pub fn has_features(&self) -> bool { + self.features_offset.is_some() + } pub fn uninterpreted_option(&self) -> crate::runtime::RepeatedFieldIterator<'a> { - match (self.uninterpreted_option_start, self.uninterpreted_option_end) { + match ( + self.uninterpreted_option_start, + self.uninterpreted_option_end, + ) { (Some(start), Some(end)) => self.accessor.iter_repeated_range(999, start, end), _ => self.accessor.iter_repeated(999), } @@ -4762,7 +5511,6 @@ uninterpreted_option_start, uninterpreted_option_end, pub fn raw_fields(&self) -> crate::runtime::RawFieldIterator<'a> { self.accessor.raw_fields() } - } pub struct OneofOptionsBuilder<'b> { @@ -4854,64 +5602,97 @@ impl<'a> EnumOptions<'a> { let mut uninterpreted_option_end = None; for item in accessor.fields() { let (offset, tag, _) = item?; - if tag.field_number == 2 { allow_alias_offset = Some(offset); } - if tag.field_number == 3 { deprecated_offset = Some(offset); } - if tag.field_number == 6 { deprecated_legacy_json_field_conflicts_offset = Some(offset); } - if tag.field_number == 7 { features_offset = Some(offset); } + if tag.field_number == 2 { + allow_alias_offset = Some(offset); + } + if tag.field_number == 3 { + deprecated_offset = Some(offset); + } + if tag.field_number == 6 { + deprecated_legacy_json_field_conflicts_offset = Some(offset); + } + if tag.field_number == 7 { + features_offset = Some(offset); + } if tag.field_number == 999 { - if uninterpreted_option_start.is_none() { uninterpreted_option_start = Some(offset); } + if uninterpreted_option_start.is_none() { + uninterpreted_option_start = Some(offset); + } uninterpreted_option_end = Some(offset); } } Ok(Self { accessor, -allow_alias_offset, -deprecated_offset, -deprecated_legacy_json_field_conflicts_offset, -features_offset, -uninterpreted_option_start, uninterpreted_option_end, + allow_alias_offset, + deprecated_offset, + deprecated_legacy_json_field_conflicts_offset, + features_offset, + uninterpreted_option_start, + uninterpreted_option_end, }) } pub fn allow_alias(&self) -> crate::runtime::Result { - let offset = self.allow_alias_offset.ok_or(crate::runtime::RotoError::FieldNotFound)?; + let offset = self + .allow_alias_offset + .ok_or(crate::runtime::RotoError::FieldNotFound)?; let (bytes, _) = self.accessor.get_value_at(offset)?; - crate::runtime::read_varint(bytes).map(|(v, _)| v != 0).map_err(|_| crate::runtime::RotoError::WireFormatViolation) + crate::runtime::read_varint(bytes) + .map(|(v, _)| v != 0) + .map_err(|_| crate::runtime::RotoError::WireFormatViolation) } pub fn allow_alias_or_default(&self) -> crate::runtime::Result { self.allow_alias().or(Ok(false)) } - pub fn has_allow_alias(&self) -> bool { self.allow_alias_offset.is_some() } + pub fn has_allow_alias(&self) -> bool { + self.allow_alias_offset.is_some() + } pub fn deprecated(&self) -> crate::runtime::Result { - let offset = self.deprecated_offset.ok_or(crate::runtime::RotoError::FieldNotFound)?; + let offset = self + .deprecated_offset + .ok_or(crate::runtime::RotoError::FieldNotFound)?; let (bytes, _) = self.accessor.get_value_at(offset)?; - crate::runtime::read_varint(bytes).map(|(v, _)| v != 0).map_err(|_| crate::runtime::RotoError::WireFormatViolation) + crate::runtime::read_varint(bytes) + .map(|(v, _)| v != 0) + .map_err(|_| crate::runtime::RotoError::WireFormatViolation) } pub fn deprecated_or_default(&self) -> crate::runtime::Result { self.deprecated().or(Ok(false)) } - pub fn has_deprecated(&self) -> bool { self.deprecated_offset.is_some() } - - pub fn deprecated_legacy_json_field_conflicts(&self) -> crate::runtime::Result { - let offset = self.deprecated_legacy_json_field_conflicts_offset.ok_or(crate::runtime::RotoError::FieldNotFound)?; - let (bytes, _) = self.accessor.get_value_at(offset)?; - crate::runtime::read_varint(bytes).map(|(v, _)| v != 0).map_err(|_| crate::runtime::RotoError::WireFormatViolation) + pub fn has_deprecated(&self) -> bool { + self.deprecated_offset.is_some() } - pub fn deprecated_legacy_json_field_conflicts_or_default(&self) -> crate::runtime::Result { + pub fn deprecated_legacy_json_field_conflicts(&self) -> crate::runtime::Result { + let offset = self + .deprecated_legacy_json_field_conflicts_offset + .ok_or(crate::runtime::RotoError::FieldNotFound)?; + let (bytes, _) = self.accessor.get_value_at(offset)?; + crate::runtime::read_varint(bytes) + .map(|(v, _)| v != 0) + .map_err(|_| crate::runtime::RotoError::WireFormatViolation) + } + + pub fn deprecated_legacy_json_field_conflicts_or_default( + &self, + ) -> crate::runtime::Result { self.deprecated_legacy_json_field_conflicts().or(Ok(false)) } - pub fn has_deprecated_legacy_json_field_conflicts(&self) -> bool { self.deprecated_legacy_json_field_conflicts_offset.is_some() } + pub fn has_deprecated_legacy_json_field_conflicts(&self) -> bool { + self.deprecated_legacy_json_field_conflicts_offset.is_some() + } pub fn features(&self) -> crate::runtime::Result<&'a [u8]> { - let offset = self.features_offset.ok_or(crate::runtime::RotoError::FieldNotFound)?; + let offset = self + .features_offset + .ok_or(crate::runtime::RotoError::FieldNotFound)?; let (bytes, _) = self.accessor.get_value_at(offset)?; Ok(bytes) } @@ -4920,10 +5701,15 @@ uninterpreted_option_start, uninterpreted_option_end, self.features().or(Ok(&[])) } - pub fn has_features(&self) -> bool { self.features_offset.is_some() } + pub fn has_features(&self) -> bool { + self.features_offset.is_some() + } pub fn uninterpreted_option(&self) -> crate::runtime::RepeatedFieldIterator<'a> { - match (self.uninterpreted_option_start, self.uninterpreted_option_end) { + match ( + self.uninterpreted_option_start, + self.uninterpreted_option_end, + ) { (Some(start), Some(end)) => self.accessor.iter_repeated_range(999, start, end), _ => self.accessor.iter_repeated(999), } @@ -4932,7 +5718,6 @@ uninterpreted_option_start, uninterpreted_option_end, pub fn raw_fields(&self) -> crate::runtime::RawFieldIterator<'a> { self.accessor.raw_fields() } - } pub struct EnumOptionsBuilder<'b> { @@ -4968,7 +5753,10 @@ impl<'b> EnumOptionsBuilder<'b> { Ok(self) } - pub fn deprecated_legacy_json_field_conflicts(mut self, value: u64) -> crate::runtime::Result { + pub fn deprecated_legacy_json_field_conflicts( + mut self, + value: u64, + ) -> crate::runtime::Result { self.builder.write_varint(6, value)?; self.deprecated_legacy_json_field_conflicts_written = true; Ok(self) @@ -5051,40 +5839,59 @@ impl<'a> EnumValueOptions<'a> { let mut uninterpreted_option_end = None; for item in accessor.fields() { let (offset, tag, _) = item?; - if tag.field_number == 1 { deprecated_offset = Some(offset); } - if tag.field_number == 2 { features_offset = Some(offset); } - if tag.field_number == 3 { debug_redact_offset = Some(offset); } - if tag.field_number == 4 { feature_support_offset = Some(offset); } + if tag.field_number == 1 { + deprecated_offset = Some(offset); + } + if tag.field_number == 2 { + features_offset = Some(offset); + } + if tag.field_number == 3 { + debug_redact_offset = Some(offset); + } + if tag.field_number == 4 { + feature_support_offset = Some(offset); + } if tag.field_number == 999 { - if uninterpreted_option_start.is_none() { uninterpreted_option_start = Some(offset); } + if uninterpreted_option_start.is_none() { + uninterpreted_option_start = Some(offset); + } uninterpreted_option_end = Some(offset); } } Ok(Self { accessor, -deprecated_offset, -features_offset, -debug_redact_offset, -feature_support_offset, -uninterpreted_option_start, uninterpreted_option_end, + deprecated_offset, + features_offset, + debug_redact_offset, + feature_support_offset, + uninterpreted_option_start, + uninterpreted_option_end, }) } pub fn deprecated(&self) -> crate::runtime::Result { - let offset = self.deprecated_offset.ok_or(crate::runtime::RotoError::FieldNotFound)?; + let offset = self + .deprecated_offset + .ok_or(crate::runtime::RotoError::FieldNotFound)?; let (bytes, _) = self.accessor.get_value_at(offset)?; - crate::runtime::read_varint(bytes).map(|(v, _)| v != 0).map_err(|_| crate::runtime::RotoError::WireFormatViolation) + crate::runtime::read_varint(bytes) + .map(|(v, _)| v != 0) + .map_err(|_| crate::runtime::RotoError::WireFormatViolation) } pub fn deprecated_or_default(&self) -> crate::runtime::Result { self.deprecated().or(Ok(false)) } - pub fn has_deprecated(&self) -> bool { self.deprecated_offset.is_some() } + pub fn has_deprecated(&self) -> bool { + self.deprecated_offset.is_some() + } pub fn features(&self) -> crate::runtime::Result<&'a [u8]> { - let offset = self.features_offset.ok_or(crate::runtime::RotoError::FieldNotFound)?; + let offset = self + .features_offset + .ok_or(crate::runtime::RotoError::FieldNotFound)?; let (bytes, _) = self.accessor.get_value_at(offset)?; Ok(bytes) } @@ -5093,22 +5900,32 @@ uninterpreted_option_start, uninterpreted_option_end, self.features().or(Ok(&[])) } - pub fn has_features(&self) -> bool { self.features_offset.is_some() } + pub fn has_features(&self) -> bool { + self.features_offset.is_some() + } pub fn debug_redact(&self) -> crate::runtime::Result { - let offset = self.debug_redact_offset.ok_or(crate::runtime::RotoError::FieldNotFound)?; + let offset = self + .debug_redact_offset + .ok_or(crate::runtime::RotoError::FieldNotFound)?; let (bytes, _) = self.accessor.get_value_at(offset)?; - crate::runtime::read_varint(bytes).map(|(v, _)| v != 0).map_err(|_| crate::runtime::RotoError::WireFormatViolation) + crate::runtime::read_varint(bytes) + .map(|(v, _)| v != 0) + .map_err(|_| crate::runtime::RotoError::WireFormatViolation) } pub fn debug_redact_or_default(&self) -> crate::runtime::Result { self.debug_redact().or(Ok(false)) } - pub fn has_debug_redact(&self) -> bool { self.debug_redact_offset.is_some() } + pub fn has_debug_redact(&self) -> bool { + self.debug_redact_offset.is_some() + } pub fn feature_support(&self) -> crate::runtime::Result<&'a [u8]> { - let offset = self.feature_support_offset.ok_or(crate::runtime::RotoError::FieldNotFound)?; + let offset = self + .feature_support_offset + .ok_or(crate::runtime::RotoError::FieldNotFound)?; let (bytes, _) = self.accessor.get_value_at(offset)?; Ok(bytes) } @@ -5117,10 +5934,15 @@ uninterpreted_option_start, uninterpreted_option_end, self.feature_support().or(Ok(&[])) } - pub fn has_feature_support(&self) -> bool { self.feature_support_offset.is_some() } + pub fn has_feature_support(&self) -> bool { + self.feature_support_offset.is_some() + } pub fn uninterpreted_option(&self) -> crate::runtime::RepeatedFieldIterator<'a> { - match (self.uninterpreted_option_start, self.uninterpreted_option_end) { + match ( + self.uninterpreted_option_start, + self.uninterpreted_option_end, + ) { (Some(start), Some(end)) => self.accessor.iter_repeated_range(999, start, end), _ => self.accessor.iter_repeated(999), } @@ -5129,7 +5951,6 @@ uninterpreted_option_start, uninterpreted_option_end, pub fn raw_fields(&self) -> crate::runtime::RawFieldIterator<'a> { self.accessor.raw_fields() } - } pub struct EnumValueOptionsBuilder<'b> { @@ -5244,24 +6065,33 @@ impl<'a> ServiceOptions<'a> { let mut uninterpreted_option_end = None; for item in accessor.fields() { let (offset, tag, _) = item?; - if tag.field_number == 34 { features_offset = Some(offset); } - if tag.field_number == 33 { deprecated_offset = Some(offset); } + if tag.field_number == 34 { + features_offset = Some(offset); + } + if tag.field_number == 33 { + deprecated_offset = Some(offset); + } if tag.field_number == 999 { - if uninterpreted_option_start.is_none() { uninterpreted_option_start = Some(offset); } + if uninterpreted_option_start.is_none() { + uninterpreted_option_start = Some(offset); + } uninterpreted_option_end = Some(offset); } } Ok(Self { accessor, -features_offset, -deprecated_offset, -uninterpreted_option_start, uninterpreted_option_end, + features_offset, + deprecated_offset, + uninterpreted_option_start, + uninterpreted_option_end, }) } pub fn features(&self) -> crate::runtime::Result<&'a [u8]> { - let offset = self.features_offset.ok_or(crate::runtime::RotoError::FieldNotFound)?; + let offset = self + .features_offset + .ok_or(crate::runtime::RotoError::FieldNotFound)?; let (bytes, _) = self.accessor.get_value_at(offset)?; Ok(bytes) } @@ -5270,22 +6100,33 @@ uninterpreted_option_start, uninterpreted_option_end, self.features().or(Ok(&[])) } - pub fn has_features(&self) -> bool { self.features_offset.is_some() } + pub fn has_features(&self) -> bool { + self.features_offset.is_some() + } pub fn deprecated(&self) -> crate::runtime::Result { - let offset = self.deprecated_offset.ok_or(crate::runtime::RotoError::FieldNotFound)?; + let offset = self + .deprecated_offset + .ok_or(crate::runtime::RotoError::FieldNotFound)?; let (bytes, _) = self.accessor.get_value_at(offset)?; - crate::runtime::read_varint(bytes).map(|(v, _)| v != 0).map_err(|_| crate::runtime::RotoError::WireFormatViolation) + crate::runtime::read_varint(bytes) + .map(|(v, _)| v != 0) + .map_err(|_| crate::runtime::RotoError::WireFormatViolation) } pub fn deprecated_or_default(&self) -> crate::runtime::Result { self.deprecated().or(Ok(false)) } - pub fn has_deprecated(&self) -> bool { self.deprecated_offset.is_some() } + pub fn has_deprecated(&self) -> bool { + self.deprecated_offset.is_some() + } pub fn uninterpreted_option(&self) -> crate::runtime::RepeatedFieldIterator<'a> { - match (self.uninterpreted_option_start, self.uninterpreted_option_end) { + match ( + self.uninterpreted_option_start, + self.uninterpreted_option_end, + ) { (Some(start), Some(end)) => self.accessor.iter_repeated_range(999, start, end), _ => self.accessor.iter_repeated(999), } @@ -5294,7 +6135,6 @@ uninterpreted_option_start, uninterpreted_option_end, pub fn raw_fields(&self) -> crate::runtime::RawFieldIterator<'a> { self.accessor.raw_fields() } - } pub struct ServiceOptionsBuilder<'b> { @@ -5393,50 +6233,73 @@ impl<'a> MethodOptions<'a> { let mut uninterpreted_option_end = None; for item in accessor.fields() { let (offset, tag, _) = item?; - if tag.field_number == 33 { deprecated_offset = Some(offset); } - if tag.field_number == 34 { idempotency_level_offset = Some(offset); } - if tag.field_number == 35 { features_offset = Some(offset); } + if tag.field_number == 33 { + deprecated_offset = Some(offset); + } + if tag.field_number == 34 { + idempotency_level_offset = Some(offset); + } + if tag.field_number == 35 { + features_offset = Some(offset); + } if tag.field_number == 999 { - if uninterpreted_option_start.is_none() { uninterpreted_option_start = Some(offset); } + if uninterpreted_option_start.is_none() { + uninterpreted_option_start = Some(offset); + } uninterpreted_option_end = Some(offset); } } Ok(Self { accessor, -deprecated_offset, -idempotency_level_offset, -features_offset, -uninterpreted_option_start, uninterpreted_option_end, + deprecated_offset, + idempotency_level_offset, + features_offset, + uninterpreted_option_start, + uninterpreted_option_end, }) } pub fn deprecated(&self) -> crate::runtime::Result { - let offset = self.deprecated_offset.ok_or(crate::runtime::RotoError::FieldNotFound)?; + let offset = self + .deprecated_offset + .ok_or(crate::runtime::RotoError::FieldNotFound)?; let (bytes, _) = self.accessor.get_value_at(offset)?; - crate::runtime::read_varint(bytes).map(|(v, _)| v != 0).map_err(|_| crate::runtime::RotoError::WireFormatViolation) + crate::runtime::read_varint(bytes) + .map(|(v, _)| v != 0) + .map_err(|_| crate::runtime::RotoError::WireFormatViolation) } pub fn deprecated_or_default(&self) -> crate::runtime::Result { self.deprecated().or(Ok(false)) } - pub fn has_deprecated(&self) -> bool { self.deprecated_offset.is_some() } + pub fn has_deprecated(&self) -> bool { + self.deprecated_offset.is_some() + } pub fn idempotency_level(&self) -> crate::runtime::Result { - let offset = self.idempotency_level_offset.ok_or(crate::runtime::RotoError::FieldNotFound)?; + let offset = self + .idempotency_level_offset + .ok_or(crate::runtime::RotoError::FieldNotFound)?; let (bytes, _) = self.accessor.get_value_at(offset)?; - crate::runtime::read_varint(bytes).map(|(v, _)| v as u64).map_err(|_| crate::runtime::RotoError::WireFormatViolation) + crate::runtime::read_varint(bytes) + .map(|(v, _)| v as u64) + .map_err(|_| crate::runtime::RotoError::WireFormatViolation) } pub fn idempotency_level_or_default(&self) -> crate::runtime::Result { self.idempotency_level().or(Ok(0)) } - pub fn has_idempotency_level(&self) -> bool { self.idempotency_level_offset.is_some() } + pub fn has_idempotency_level(&self) -> bool { + self.idempotency_level_offset.is_some() + } pub fn features(&self) -> crate::runtime::Result<&'a [u8]> { - let offset = self.features_offset.ok_or(crate::runtime::RotoError::FieldNotFound)?; + let offset = self + .features_offset + .ok_or(crate::runtime::RotoError::FieldNotFound)?; let (bytes, _) = self.accessor.get_value_at(offset)?; Ok(bytes) } @@ -5445,10 +6308,15 @@ uninterpreted_option_start, uninterpreted_option_end, self.features().or(Ok(&[])) } - pub fn has_features(&self) -> bool { self.features_offset.is_some() } + pub fn has_features(&self) -> bool { + self.features_offset.is_some() + } pub fn uninterpreted_option(&self) -> crate::runtime::RepeatedFieldIterator<'a> { - match (self.uninterpreted_option_start, self.uninterpreted_option_end) { + match ( + self.uninterpreted_option_start, + self.uninterpreted_option_end, + ) { (Some(start), Some(end)) => self.accessor.iter_repeated_range(999, start, end), _ => self.accessor.iter_repeated(999), } @@ -5457,7 +6325,6 @@ uninterpreted_option_start, uninterpreted_option_end, pub fn raw_fields(&self) -> crate::runtime::RawFieldIterator<'a> { self.accessor.raw_fields() } - } pub struct MethodOptionsBuilder<'b> { @@ -5547,27 +6414,26 @@ impl crate::runtime::RotoMessage for OwnedMethodOptions { } pub mod method_options { -#[derive(Debug, Clone, Copy, PartialEq, Eq)] -#[repr(i32)] -pub enum IdempotencyLevel { - IDEMPOTENCYUNKNOWN = 0, - NOSIDEEFFECTS = 1, - IDEMPOTENT = 2, -} + #[derive(Debug, Clone, Copy, PartialEq, Eq)] + #[repr(i32)] + pub enum IdempotencyLevel { + IDEMPOTENCYUNKNOWN = 0, + NOSIDEEFFECTS = 1, + IDEMPOTENT = 2, + } -impl IdempotencyLevel { - pub fn from_i32(value: i32) -> Self { - match value { - 0 => IdempotencyLevel::IDEMPOTENCYUNKNOWN, - 1 => IdempotencyLevel::NOSIDEEFFECTS, - 2 => IdempotencyLevel::IDEMPOTENT, - _ => IdempotencyLevel::IDEMPOTENCYUNKNOWN, + impl IdempotencyLevel { + pub fn from_i32(value: i32) -> Self { + match value { + 0 => IdempotencyLevel::IDEMPOTENCYUNKNOWN, + 1 => IdempotencyLevel::NOSIDEEFFECTS, + 2 => IdempotencyLevel::IDEMPOTENT, + _ => IdempotencyLevel::IDEMPOTENCYUNKNOWN, + } } } } -} - pub struct UninterpretedOption<'a> { accessor: crate::runtime::ProtoAccessor<'a>, name_start: Option, @@ -5594,26 +6460,41 @@ impl<'a> UninterpretedOption<'a> { for item in accessor.fields() { let (offset, tag, _) = item?; if tag.field_number == 2 { - if name_start.is_none() { name_start = Some(offset); } + if name_start.is_none() { + name_start = Some(offset); + } name_end = Some(offset); } - if tag.field_number == 3 { identifier_value_offset = Some(offset); } - if tag.field_number == 4 { positive_int_value_offset = Some(offset); } - if tag.field_number == 5 { negative_int_value_offset = Some(offset); } - if tag.field_number == 6 { double_value_offset = Some(offset); } - if tag.field_number == 7 { string_value_offset = Some(offset); } - if tag.field_number == 8 { aggregate_value_offset = Some(offset); } + if tag.field_number == 3 { + identifier_value_offset = Some(offset); + } + if tag.field_number == 4 { + positive_int_value_offset = Some(offset); + } + if tag.field_number == 5 { + negative_int_value_offset = Some(offset); + } + if tag.field_number == 6 { + double_value_offset = Some(offset); + } + if tag.field_number == 7 { + string_value_offset = Some(offset); + } + if tag.field_number == 8 { + aggregate_value_offset = Some(offset); + } } Ok(Self { accessor, -name_start, name_end, -identifier_value_offset, -positive_int_value_offset, -negative_int_value_offset, -double_value_offset, -string_value_offset, -aggregate_value_offset, + name_start, + name_end, + identifier_value_offset, + positive_int_value_offset, + negative_int_value_offset, + double_value_offset, + string_value_offset, + aggregate_value_offset, }) } @@ -5625,7 +6506,9 @@ aggregate_value_offset, } pub fn identifier_value(&self) -> crate::runtime::Result<&'a str> { - let offset = self.identifier_value_offset.ok_or(crate::runtime::RotoError::FieldNotFound)?; + let offset = self + .identifier_value_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) } @@ -5634,46 +6517,68 @@ aggregate_value_offset, self.identifier_value().or(Ok("")) } - pub fn has_identifier_value(&self) -> bool { self.identifier_value_offset.is_some() } + pub fn has_identifier_value(&self) -> bool { + self.identifier_value_offset.is_some() + } pub fn positive_int_value(&self) -> crate::runtime::Result { - let offset = self.positive_int_value_offset.ok_or(crate::runtime::RotoError::FieldNotFound)?; + let offset = self + .positive_int_value_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 positive_int_value_or_default(&self) -> crate::runtime::Result { self.positive_int_value().or(Ok(0)) } - pub fn has_positive_int_value(&self) -> bool { self.positive_int_value_offset.is_some() } + pub fn has_positive_int_value(&self) -> bool { + self.positive_int_value_offset.is_some() + } pub fn negative_int_value(&self) -> crate::runtime::Result { - let offset = self.negative_int_value_offset.ok_or(crate::runtime::RotoError::FieldNotFound)?; + let offset = self + .negative_int_value_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 negative_int_value_or_default(&self) -> crate::runtime::Result { self.negative_int_value().or(Ok(0)) } - pub fn has_negative_int_value(&self) -> bool { self.negative_int_value_offset.is_some() } + pub fn has_negative_int_value(&self) -> bool { + self.negative_int_value_offset.is_some() + } pub fn double_value(&self) -> crate::runtime::Result { - let offset = self.double_value_offset.ok_or(crate::runtime::RotoError::FieldNotFound)?; + let offset = self + .double_value_offset + .ok_or(crate::runtime::RotoError::FieldNotFound)?; let (bytes, _) = self.accessor.get_value_at(offset)?; - Ok(f64::from_le_bytes(bytes.try_into().map_err(|_| crate::runtime::RotoError::WireFormatViolation)?)) + Ok(f64::from_le_bytes(bytes.try_into().map_err(|_| { + crate::runtime::RotoError::WireFormatViolation + })?)) } pub fn double_value_or_default(&self) -> crate::runtime::Result { self.double_value().or(Ok(0.0)) } - pub fn has_double_value(&self) -> bool { self.double_value_offset.is_some() } + pub fn has_double_value(&self) -> bool { + self.double_value_offset.is_some() + } pub fn string_value(&self) -> crate::runtime::Result<&'a [u8]> { - let offset = self.string_value_offset.ok_or(crate::runtime::RotoError::FieldNotFound)?; + let offset = self + .string_value_offset + .ok_or(crate::runtime::RotoError::FieldNotFound)?; let (bytes, _) = self.accessor.get_value_at(offset)?; Ok(bytes) } @@ -5682,10 +6587,14 @@ aggregate_value_offset, self.string_value().or(Ok(&[])) } - pub fn has_string_value(&self) -> bool { self.string_value_offset.is_some() } + pub fn has_string_value(&self) -> bool { + self.string_value_offset.is_some() + } pub fn aggregate_value(&self) -> crate::runtime::Result<&'a str> { - let offset = self.aggregate_value_offset.ok_or(crate::runtime::RotoError::FieldNotFound)?; + let offset = self + .aggregate_value_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) } @@ -5694,12 +6603,13 @@ aggregate_value_offset, self.aggregate_value().or(Ok("")) } - pub fn has_aggregate_value(&self) -> bool { self.aggregate_value_offset.is_some() } + pub fn has_aggregate_value(&self) -> bool { + self.aggregate_value_offset.is_some() + } pub fn raw_fields(&self) -> crate::runtime::RawFieldIterator<'a> { self.accessor.raw_fields() } - } pub struct UninterpretedOptionBuilder<'b> { @@ -5816,128 +6726,140 @@ impl crate::runtime::RotoMessage for OwnedUninterpretedOption { } pub mod uninterpreted_option { -pub struct NamePart<'a> { - accessor: crate::runtime::ProtoAccessor<'a>, - name_part_offset: Option, - is_extension_offset: Option, -} + pub struct NamePart<'a> { + accessor: crate::runtime::ProtoAccessor<'a>, + name_part_offset: Option, + is_extension_offset: Option, + } -impl<'a> NamePart<'a> { - pub fn new(data: &'a [u8]) -> crate::runtime::Result { - let accessor = crate::runtime::ProtoAccessor::new(data)?; - let mut name_part_offset = None; - let mut is_extension_offset = None; - for item in accessor.fields() { - let (offset, tag, _) = item?; - if tag.field_number == 1 { name_part_offset = Some(offset); } - if tag.field_number == 2 { is_extension_offset = Some(offset); } + impl<'a> NamePart<'a> { + pub fn new(data: &'a [u8]) -> crate::runtime::Result { + let accessor = crate::runtime::ProtoAccessor::new(data)?; + let mut name_part_offset = None; + let mut is_extension_offset = None; + for item in accessor.fields() { + let (offset, tag, _) = item?; + if tag.field_number == 1 { + name_part_offset = Some(offset); + } + if tag.field_number == 2 { + is_extension_offset = Some(offset); + } + } + + Ok(Self { + accessor, + name_part_offset, + is_extension_offset, + }) } - Ok(Self { - accessor, -name_part_offset, -is_extension_offset, - }) - } + pub fn name_part(&self) -> crate::runtime::Result<&'a str> { + let offset = self + .name_part_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_part(&self) -> crate::runtime::Result<&'a str> { - let offset = self.name_part_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_part_or_default(&self) -> crate::runtime::Result<&'a str> { + self.name_part().or(Ok("")) + } - pub fn name_part_or_default(&self) -> crate::runtime::Result<&'a str> { - self.name_part().or(Ok("")) - } + pub fn has_name_part(&self) -> bool { + self.name_part_offset.is_some() + } - pub fn has_name_part(&self) -> bool { self.name_part_offset.is_some() } + pub fn is_extension(&self) -> crate::runtime::Result { + let offset = self + .is_extension_offset + .ok_or(crate::runtime::RotoError::FieldNotFound)?; + let (bytes, _) = self.accessor.get_value_at(offset)?; + crate::runtime::read_varint(bytes) + .map(|(v, _)| v != 0) + .map_err(|_| crate::runtime::RotoError::WireFormatViolation) + } - pub fn is_extension(&self) -> crate::runtime::Result { - let offset = self.is_extension_offset.ok_or(crate::runtime::RotoError::FieldNotFound)?; - let (bytes, _) = self.accessor.get_value_at(offset)?; - crate::runtime::read_varint(bytes).map(|(v, _)| v != 0).map_err(|_| crate::runtime::RotoError::WireFormatViolation) - } + pub fn is_extension_or_default(&self) -> crate::runtime::Result { + self.is_extension().or(Ok(false)) + } - pub fn is_extension_or_default(&self) -> crate::runtime::Result { - self.is_extension().or(Ok(false)) - } + pub fn has_is_extension(&self) -> bool { + self.is_extension_offset.is_some() + } - pub fn has_is_extension(&self) -> bool { self.is_extension_offset.is_some() } - - pub fn raw_fields(&self) -> crate::runtime::RawFieldIterator<'a> { - self.accessor.raw_fields() - } - -} - -pub struct NamePartBuilder<'b> { - builder: crate::runtime::ProtoBuilder<'b>, - name_part_written: bool, - is_extension_written: bool, -} - -impl<'b> NamePartBuilder<'b> { - pub fn builder(buf: &mut [u8]) -> NamePartBuilder<'_> { - NamePartBuilder { - builder: crate::runtime::ProtoBuilder::new(buf), - name_part_written: false, - is_extension_written: false, + pub fn raw_fields(&self) -> crate::runtime::RawFieldIterator<'a> { + self.accessor.raw_fields() } } - pub fn name_part(mut self, value: &str) -> crate::runtime::Result { - self.builder.write_string(1, value)?; - self.name_part_written = true; - Ok(self) + pub struct NamePartBuilder<'b> { + builder: crate::runtime::ProtoBuilder<'b>, + name_part_written: bool, + is_extension_written: bool, } - pub fn is_extension(mut self, value: u64) -> crate::runtime::Result { - self.builder.write_varint(2, value)?; - self.is_extension_written = true; - Ok(self) - } - - pub fn with(mut self, msg: &NamePart<'_>) -> crate::runtime::Result { - for item in msg.raw_fields() { - let (field_number, raw_bytes) = item?; - let is_written = match field_number { - 1 => self.name_part_written, - 2 => self.is_extension_written, - _ => false, - }; - if !is_written { - self.builder.write_raw(raw_bytes)?; + impl<'b> NamePartBuilder<'b> { + pub fn builder(buf: &mut [u8]) -> NamePartBuilder<'_> { + NamePartBuilder { + builder: crate::runtime::ProtoBuilder::new(buf), + name_part_written: false, + is_extension_written: false, } } - Ok(self) + + pub fn name_part(mut self, value: &str) -> crate::runtime::Result { + self.builder.write_string(1, value)?; + self.name_part_written = true; + Ok(self) + } + + pub fn is_extension(mut self, value: u64) -> crate::runtime::Result { + self.builder.write_varint(2, value)?; + self.is_extension_written = true; + Ok(self) + } + + pub fn with(mut self, msg: &NamePart<'_>) -> crate::runtime::Result { + for item in msg.raw_fields() { + let (field_number, raw_bytes) = item?; + let is_written = match field_number { + 1 => self.name_part_written, + 2 => self.is_extension_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 fn finish(self) -> crate::runtime::Result<&'b mut [u8]> { - self.builder.finish() - } -} - -pub struct OwnedNamePart { - pub data: bytes::Bytes, -} - -impl crate::runtime::RotoOwned for OwnedNamePart { - type Reader<'a> = NamePart<'a>; - fn reader(&self) -> NamePart<'_> { - NamePart::new(&self.data).expect("failed to create reader") - } -} - -impl crate::runtime::RotoMessage for OwnedNamePart { - fn decode(buf: bytes::Bytes) -> crate::runtime::Result { - Ok(OwnedNamePart { data: buf }) + pub struct OwnedNamePart { + pub data: bytes::Bytes, } - fn bytes(&self) -> bytes::Bytes { - self.data.clone() + impl crate::runtime::RotoOwned for OwnedNamePart { + type Reader<'a> = NamePart<'a>; + fn reader(&self) -> NamePart<'_> { + NamePart::new(&self.data).expect("failed to create reader") + } } -} + impl crate::runtime::RotoMessage for OwnedNamePart { + fn decode(buf: bytes::Bytes) -> crate::runtime::Result { + Ok(OwnedNamePart { data: buf }) + } + + fn bytes(&self) -> bytes::Bytes { + self.data.clone() + } + } } pub struct FeatureSet<'a> { @@ -5967,143 +6889,214 @@ impl<'a> FeatureSet<'a> { let mut enforce_proto_limits_offset = None; for item in accessor.fields() { let (offset, tag, _) = item?; - if tag.field_number == 1 { field_presence_offset = Some(offset); } - if tag.field_number == 2 { enum_type_offset = Some(offset); } - if tag.field_number == 3 { repeated_field_encoding_offset = Some(offset); } - if tag.field_number == 4 { utf8_validation_offset = Some(offset); } - if tag.field_number == 5 { message_encoding_offset = Some(offset); } - if tag.field_number == 6 { json_format_offset = Some(offset); } - if tag.field_number == 7 { enforce_naming_style_offset = Some(offset); } - if tag.field_number == 8 { default_symbol_visibility_offset = Some(offset); } - if tag.field_number == 9 { enforce_proto_limits_offset = Some(offset); } + if tag.field_number == 1 { + field_presence_offset = Some(offset); + } + if tag.field_number == 2 { + enum_type_offset = Some(offset); + } + if tag.field_number == 3 { + repeated_field_encoding_offset = Some(offset); + } + if tag.field_number == 4 { + utf8_validation_offset = Some(offset); + } + if tag.field_number == 5 { + message_encoding_offset = Some(offset); + } + if tag.field_number == 6 { + json_format_offset = Some(offset); + } + if tag.field_number == 7 { + enforce_naming_style_offset = Some(offset); + } + if tag.field_number == 8 { + default_symbol_visibility_offset = Some(offset); + } + if tag.field_number == 9 { + enforce_proto_limits_offset = Some(offset); + } } Ok(Self { accessor, -field_presence_offset, -enum_type_offset, -repeated_field_encoding_offset, -utf8_validation_offset, -message_encoding_offset, -json_format_offset, -enforce_naming_style_offset, -default_symbol_visibility_offset, -enforce_proto_limits_offset, + field_presence_offset, + enum_type_offset, + repeated_field_encoding_offset, + utf8_validation_offset, + message_encoding_offset, + json_format_offset, + enforce_naming_style_offset, + default_symbol_visibility_offset, + enforce_proto_limits_offset, }) } pub fn field_presence(&self) -> crate::runtime::Result { - let offset = self.field_presence_offset.ok_or(crate::runtime::RotoError::FieldNotFound)?; + let offset = self + .field_presence_offset + .ok_or(crate::runtime::RotoError::FieldNotFound)?; let (bytes, _) = self.accessor.get_value_at(offset)?; - crate::runtime::read_varint(bytes).map(|(v, _)| v as u64).map_err(|_| crate::runtime::RotoError::WireFormatViolation) + crate::runtime::read_varint(bytes) + .map(|(v, _)| v as u64) + .map_err(|_| crate::runtime::RotoError::WireFormatViolation) } pub fn field_presence_or_default(&self) -> crate::runtime::Result { self.field_presence().or(Ok(0)) } - pub fn has_field_presence(&self) -> bool { self.field_presence_offset.is_some() } + pub fn has_field_presence(&self) -> bool { + self.field_presence_offset.is_some() + } pub fn enum_type(&self) -> crate::runtime::Result { - let offset = self.enum_type_offset.ok_or(crate::runtime::RotoError::FieldNotFound)?; + let offset = self + .enum_type_offset + .ok_or(crate::runtime::RotoError::FieldNotFound)?; let (bytes, _) = self.accessor.get_value_at(offset)?; - crate::runtime::read_varint(bytes).map(|(v, _)| v as u64).map_err(|_| crate::runtime::RotoError::WireFormatViolation) + crate::runtime::read_varint(bytes) + .map(|(v, _)| v as u64) + .map_err(|_| crate::runtime::RotoError::WireFormatViolation) } pub fn enum_type_or_default(&self) -> crate::runtime::Result { self.enum_type().or(Ok(0)) } - pub fn has_enum_type(&self) -> bool { self.enum_type_offset.is_some() } + pub fn has_enum_type(&self) -> bool { + self.enum_type_offset.is_some() + } pub fn repeated_field_encoding(&self) -> crate::runtime::Result { - let offset = self.repeated_field_encoding_offset.ok_or(crate::runtime::RotoError::FieldNotFound)?; + let offset = self + .repeated_field_encoding_offset + .ok_or(crate::runtime::RotoError::FieldNotFound)?; let (bytes, _) = self.accessor.get_value_at(offset)?; - crate::runtime::read_varint(bytes).map(|(v, _)| v as u64).map_err(|_| crate::runtime::RotoError::WireFormatViolation) + crate::runtime::read_varint(bytes) + .map(|(v, _)| v as u64) + .map_err(|_| crate::runtime::RotoError::WireFormatViolation) } pub fn repeated_field_encoding_or_default(&self) -> crate::runtime::Result { self.repeated_field_encoding().or(Ok(0)) } - pub fn has_repeated_field_encoding(&self) -> bool { self.repeated_field_encoding_offset.is_some() } + pub fn has_repeated_field_encoding(&self) -> bool { + self.repeated_field_encoding_offset.is_some() + } pub fn utf8_validation(&self) -> crate::runtime::Result { - let offset = self.utf8_validation_offset.ok_or(crate::runtime::RotoError::FieldNotFound)?; + let offset = self + .utf8_validation_offset + .ok_or(crate::runtime::RotoError::FieldNotFound)?; let (bytes, _) = self.accessor.get_value_at(offset)?; - crate::runtime::read_varint(bytes).map(|(v, _)| v as u64).map_err(|_| crate::runtime::RotoError::WireFormatViolation) + crate::runtime::read_varint(bytes) + .map(|(v, _)| v as u64) + .map_err(|_| crate::runtime::RotoError::WireFormatViolation) } pub fn utf8_validation_or_default(&self) -> crate::runtime::Result { self.utf8_validation().or(Ok(0)) } - pub fn has_utf8_validation(&self) -> bool { self.utf8_validation_offset.is_some() } + pub fn has_utf8_validation(&self) -> bool { + self.utf8_validation_offset.is_some() + } pub fn message_encoding(&self) -> crate::runtime::Result { - let offset = self.message_encoding_offset.ok_or(crate::runtime::RotoError::FieldNotFound)?; + let offset = self + .message_encoding_offset + .ok_or(crate::runtime::RotoError::FieldNotFound)?; let (bytes, _) = self.accessor.get_value_at(offset)?; - crate::runtime::read_varint(bytes).map(|(v, _)| v as u64).map_err(|_| crate::runtime::RotoError::WireFormatViolation) + crate::runtime::read_varint(bytes) + .map(|(v, _)| v as u64) + .map_err(|_| crate::runtime::RotoError::WireFormatViolation) } pub fn message_encoding_or_default(&self) -> crate::runtime::Result { self.message_encoding().or(Ok(0)) } - pub fn has_message_encoding(&self) -> bool { self.message_encoding_offset.is_some() } + pub fn has_message_encoding(&self) -> bool { + self.message_encoding_offset.is_some() + } pub fn json_format(&self) -> crate::runtime::Result { - let offset = self.json_format_offset.ok_or(crate::runtime::RotoError::FieldNotFound)?; + let offset = self + .json_format_offset + .ok_or(crate::runtime::RotoError::FieldNotFound)?; let (bytes, _) = self.accessor.get_value_at(offset)?; - crate::runtime::read_varint(bytes).map(|(v, _)| v as u64).map_err(|_| crate::runtime::RotoError::WireFormatViolation) + crate::runtime::read_varint(bytes) + .map(|(v, _)| v as u64) + .map_err(|_| crate::runtime::RotoError::WireFormatViolation) } pub fn json_format_or_default(&self) -> crate::runtime::Result { self.json_format().or(Ok(0)) } - pub fn has_json_format(&self) -> bool { self.json_format_offset.is_some() } + pub fn has_json_format(&self) -> bool { + self.json_format_offset.is_some() + } pub fn enforce_naming_style(&self) -> crate::runtime::Result { - let offset = self.enforce_naming_style_offset.ok_or(crate::runtime::RotoError::FieldNotFound)?; + let offset = self + .enforce_naming_style_offset + .ok_or(crate::runtime::RotoError::FieldNotFound)?; let (bytes, _) = self.accessor.get_value_at(offset)?; - crate::runtime::read_varint(bytes).map(|(v, _)| v as u64).map_err(|_| crate::runtime::RotoError::WireFormatViolation) + crate::runtime::read_varint(bytes) + .map(|(v, _)| v as u64) + .map_err(|_| crate::runtime::RotoError::WireFormatViolation) } pub fn enforce_naming_style_or_default(&self) -> crate::runtime::Result { self.enforce_naming_style().or(Ok(0)) } - pub fn has_enforce_naming_style(&self) -> bool { self.enforce_naming_style_offset.is_some() } + pub fn has_enforce_naming_style(&self) -> bool { + self.enforce_naming_style_offset.is_some() + } pub fn default_symbol_visibility(&self) -> crate::runtime::Result { - let offset = self.default_symbol_visibility_offset.ok_or(crate::runtime::RotoError::FieldNotFound)?; + let offset = self + .default_symbol_visibility_offset + .ok_or(crate::runtime::RotoError::FieldNotFound)?; let (bytes, _) = self.accessor.get_value_at(offset)?; - crate::runtime::read_varint(bytes).map(|(v, _)| v as u64).map_err(|_| crate::runtime::RotoError::WireFormatViolation) + crate::runtime::read_varint(bytes) + .map(|(v, _)| v as u64) + .map_err(|_| crate::runtime::RotoError::WireFormatViolation) } pub fn default_symbol_visibility_or_default(&self) -> crate::runtime::Result { self.default_symbol_visibility().or(Ok(0)) } - pub fn has_default_symbol_visibility(&self) -> bool { self.default_symbol_visibility_offset.is_some() } + pub fn has_default_symbol_visibility(&self) -> bool { + self.default_symbol_visibility_offset.is_some() + } pub fn enforce_proto_limits(&self) -> crate::runtime::Result { - let offset = self.enforce_proto_limits_offset.ok_or(crate::runtime::RotoError::FieldNotFound)?; + let offset = self + .enforce_proto_limits_offset + .ok_or(crate::runtime::RotoError::FieldNotFound)?; let (bytes, _) = self.accessor.get_value_at(offset)?; - crate::runtime::read_varint(bytes).map(|(v, _)| v as u64).map_err(|_| crate::runtime::RotoError::WireFormatViolation) + crate::runtime::read_varint(bytes) + .map(|(v, _)| v as u64) + .map_err(|_| crate::runtime::RotoError::WireFormatViolation) } pub fn enforce_proto_limits_or_default(&self) -> crate::runtime::Result { self.enforce_proto_limits().or(Ok(0)) } - pub fn has_enforce_proto_limits(&self) -> bool { self.enforce_proto_limits_offset.is_some() } + pub fn has_enforce_proto_limits(&self) -> bool { + self.enforce_proto_limits_offset.is_some() + } pub fn raw_fields(&self) -> crate::runtime::RawFieldIterator<'a> { self.accessor.raw_fields() } - } pub struct FeatureSetBuilder<'b> { @@ -6238,335 +7231,326 @@ impl crate::runtime::RotoMessage for OwnedFeatureSet { } pub mod feature_set { -#[derive(Debug, Clone, Copy, PartialEq, Eq)] -#[repr(i32)] -pub enum FieldPresence { - FIELDPRESENCEUNKNOWN = 0, - EXPLICIT = 1, - IMPLICIT = 2, - LEGACYREQUIRED = 3, -} - -impl FieldPresence { - pub fn from_i32(value: i32) -> Self { - match value { - 0 => FieldPresence::FIELDPRESENCEUNKNOWN, - 1 => FieldPresence::EXPLICIT, - 2 => FieldPresence::IMPLICIT, - 3 => FieldPresence::LEGACYREQUIRED, - _ => FieldPresence::FIELDPRESENCEUNKNOWN, - } - } -} - -#[derive(Debug, Clone, Copy, PartialEq, Eq)] -#[repr(i32)] -pub enum EnumType { - ENUMTYPEUNKNOWN = 0, - OPEN = 1, - CLOSED = 2, -} - -impl EnumType { - pub fn from_i32(value: i32) -> Self { - match value { - 0 => EnumType::ENUMTYPEUNKNOWN, - 1 => EnumType::OPEN, - 2 => EnumType::CLOSED, - _ => EnumType::ENUMTYPEUNKNOWN, - } - } -} - -#[derive(Debug, Clone, Copy, PartialEq, Eq)] -#[repr(i32)] -pub enum RepeatedFieldEncoding { - REPEATEDFIELDENCODINGUNKNOWN = 0, - PACKED = 1, - EXPANDED = 2, -} - -impl RepeatedFieldEncoding { - pub fn from_i32(value: i32) -> Self { - match value { - 0 => RepeatedFieldEncoding::REPEATEDFIELDENCODINGUNKNOWN, - 1 => RepeatedFieldEncoding::PACKED, - 2 => RepeatedFieldEncoding::EXPANDED, - _ => RepeatedFieldEncoding::REPEATEDFIELDENCODINGUNKNOWN, - } - } -} - -#[derive(Debug, Clone, Copy, PartialEq, Eq)] -#[repr(i32)] -pub enum Utf8Validation { - UTF8VALIDATIONUNKNOWN = 0, - VERIFY = 2, - NONE = 3, -} - -impl Utf8Validation { - pub fn from_i32(value: i32) -> Self { - match value { - 0 => Utf8Validation::UTF8VALIDATIONUNKNOWN, - 2 => Utf8Validation::VERIFY, - 3 => Utf8Validation::NONE, - _ => Utf8Validation::UTF8VALIDATIONUNKNOWN, - } - } -} - -#[derive(Debug, Clone, Copy, PartialEq, Eq)] -#[repr(i32)] -pub enum MessageEncoding { - MESSAGEENCODINGUNKNOWN = 0, - LENGTHPREFIXED = 1, - DELIMITED = 2, -} - -impl MessageEncoding { - pub fn from_i32(value: i32) -> Self { - match value { - 0 => MessageEncoding::MESSAGEENCODINGUNKNOWN, - 1 => MessageEncoding::LENGTHPREFIXED, - 2 => MessageEncoding::DELIMITED, - _ => MessageEncoding::MESSAGEENCODINGUNKNOWN, - } - } -} - -#[derive(Debug, Clone, Copy, PartialEq, Eq)] -#[repr(i32)] -pub enum JsonFormat { - JSONFORMATUNKNOWN = 0, - ALLOW = 1, - LEGACYBESTEFFORT = 2, -} - -impl JsonFormat { - pub fn from_i32(value: i32) -> Self { - match value { - 0 => JsonFormat::JSONFORMATUNKNOWN, - 1 => JsonFormat::ALLOW, - 2 => JsonFormat::LEGACYBESTEFFORT, - _ => JsonFormat::JSONFORMATUNKNOWN, - } - } -} - -#[derive(Debug, Clone, Copy, PartialEq, Eq)] -#[repr(i32)] -pub enum EnforceNamingStyle { - ENFORCENAMINGSTYLEUNKNOWN = 0, - STYLE2024 = 1, - STYLELEGACY = 2, - STYLE2026 = 3, -} - -impl EnforceNamingStyle { - pub fn from_i32(value: i32) -> Self { - match value { - 0 => EnforceNamingStyle::ENFORCENAMINGSTYLEUNKNOWN, - 1 => EnforceNamingStyle::STYLE2024, - 2 => EnforceNamingStyle::STYLELEGACY, - 3 => EnforceNamingStyle::STYLE2026, - _ => EnforceNamingStyle::ENFORCENAMINGSTYLEUNKNOWN, - } - } -} - -pub struct VisibilityFeature<'a> { - accessor: crate::runtime::ProtoAccessor<'a>, -} - -impl<'a> VisibilityFeature<'a> { - pub fn new(data: &'a [u8]) -> crate::runtime::Result { - let accessor = crate::runtime::ProtoAccessor::new(data)?; - for item in accessor.fields() { - let (offset, tag, _) = item?; - } - - Ok(Self { - accessor, - }) + #[derive(Debug, Clone, Copy, PartialEq, Eq)] + #[repr(i32)] + pub enum FieldPresence { + FIELDPRESENCEUNKNOWN = 0, + EXPLICIT = 1, + IMPLICIT = 2, + LEGACYREQUIRED = 3, } - pub fn raw_fields(&self) -> crate::runtime::RawFieldIterator<'a> { - self.accessor.raw_fields() - } - -} - -pub struct VisibilityFeatureBuilder<'b> { - builder: crate::runtime::ProtoBuilder<'b>, -} - -impl<'b> VisibilityFeatureBuilder<'b> { - pub fn builder(buf: &mut [u8]) -> VisibilityFeatureBuilder<'_> { - VisibilityFeatureBuilder { - builder: crate::runtime::ProtoBuilder::new(buf), - } - } - - pub fn with(mut self, msg: &VisibilityFeature<'_>) -> crate::runtime::Result { - for item in msg.raw_fields() { - let (field_number, raw_bytes) = item?; - let is_written = match field_number { - _ => false, - }; - if !is_written { - self.builder.write_raw(raw_bytes)?; + impl FieldPresence { + pub fn from_i32(value: i32) -> Self { + match value { + 0 => FieldPresence::FIELDPRESENCEUNKNOWN, + 1 => FieldPresence::EXPLICIT, + 2 => FieldPresence::IMPLICIT, + 3 => FieldPresence::LEGACYREQUIRED, + _ => FieldPresence::FIELDPRESENCEUNKNOWN, } } - Ok(self) } - pub fn finish(self) -> crate::runtime::Result<&'b mut [u8]> { - self.builder.finish() - } -} - -pub struct OwnedVisibilityFeature { - pub data: bytes::Bytes, -} - -impl crate::runtime::RotoOwned for OwnedVisibilityFeature { - type Reader<'a> = VisibilityFeature<'a>; - fn reader(&self) -> VisibilityFeature<'_> { - VisibilityFeature::new(&self.data).expect("failed to create reader") - } -} - -impl crate::runtime::RotoMessage for OwnedVisibilityFeature { - fn decode(buf: bytes::Bytes) -> crate::runtime::Result { - Ok(OwnedVisibilityFeature { data: buf }) + #[derive(Debug, Clone, Copy, PartialEq, Eq)] + #[repr(i32)] + pub enum EnumType { + ENUMTYPEUNKNOWN = 0, + OPEN = 1, + CLOSED = 2, } - fn bytes(&self) -> bytes::Bytes { - self.data.clone() - } -} - -pub mod visibility_feature { -#[derive(Debug, Clone, Copy, PartialEq, Eq)] -#[repr(i32)] -pub enum DefaultSymbolVisibility { - DEFAULTSYMBOLVISIBILITYUNKNOWN = 0, - EXPORTALL = 1, - EXPORTTOPLEVEL = 2, - LOCALALL = 3, - STRICT = 4, -} - -impl DefaultSymbolVisibility { - pub fn from_i32(value: i32) -> Self { - match value { - 0 => DefaultSymbolVisibility::DEFAULTSYMBOLVISIBILITYUNKNOWN, - 1 => DefaultSymbolVisibility::EXPORTALL, - 2 => DefaultSymbolVisibility::EXPORTTOPLEVEL, - 3 => DefaultSymbolVisibility::LOCALALL, - 4 => DefaultSymbolVisibility::STRICT, - _ => DefaultSymbolVisibility::DEFAULTSYMBOLVISIBILITYUNKNOWN, - } - } -} - -} - -pub struct ProtoLimitsFeature<'a> { - accessor: crate::runtime::ProtoAccessor<'a>, -} - -impl<'a> ProtoLimitsFeature<'a> { - pub fn new(data: &'a [u8]) -> crate::runtime::Result { - let accessor = crate::runtime::ProtoAccessor::new(data)?; - for item in accessor.fields() { - let (offset, tag, _) = item?; - } - - Ok(Self { - accessor, - }) - } - - pub fn raw_fields(&self) -> crate::runtime::RawFieldIterator<'a> { - self.accessor.raw_fields() - } - -} - -pub struct ProtoLimitsFeatureBuilder<'b> { - builder: crate::runtime::ProtoBuilder<'b>, -} - -impl<'b> ProtoLimitsFeatureBuilder<'b> { - pub fn builder(buf: &mut [u8]) -> ProtoLimitsFeatureBuilder<'_> { - ProtoLimitsFeatureBuilder { - builder: crate::runtime::ProtoBuilder::new(buf), - } - } - - pub fn with(mut self, msg: &ProtoLimitsFeature<'_>) -> crate::runtime::Result { - for item in msg.raw_fields() { - let (field_number, raw_bytes) = item?; - let is_written = match field_number { - _ => false, - }; - if !is_written { - self.builder.write_raw(raw_bytes)?; + impl EnumType { + pub fn from_i32(value: i32) -> Self { + match value { + 0 => EnumType::ENUMTYPEUNKNOWN, + 1 => EnumType::OPEN, + 2 => EnumType::CLOSED, + _ => EnumType::ENUMTYPEUNKNOWN, } } - Ok(self) } - pub fn finish(self) -> crate::runtime::Result<&'b mut [u8]> { - self.builder.finish() - } -} - -pub struct OwnedProtoLimitsFeature { - pub data: bytes::Bytes, -} - -impl crate::runtime::RotoOwned for OwnedProtoLimitsFeature { - type Reader<'a> = ProtoLimitsFeature<'a>; - fn reader(&self) -> ProtoLimitsFeature<'_> { - ProtoLimitsFeature::new(&self.data).expect("failed to create reader") - } -} - -impl crate::runtime::RotoMessage for OwnedProtoLimitsFeature { - fn decode(buf: bytes::Bytes) -> crate::runtime::Result { - Ok(OwnedProtoLimitsFeature { data: buf }) + #[derive(Debug, Clone, Copy, PartialEq, Eq)] + #[repr(i32)] + pub enum RepeatedFieldEncoding { + REPEATEDFIELDENCODINGUNKNOWN = 0, + PACKED = 1, + EXPANDED = 2, } - fn bytes(&self) -> bytes::Bytes { - self.data.clone() - } -} - -pub mod proto_limits_feature { -#[derive(Debug, Clone, Copy, PartialEq, Eq)] -#[repr(i32)] -pub enum EnforceProtoLimits { - PROTOLIMITSUNKNOWN = 0, - LEGACYNOEXPLICITLIMITS = 1, - PROTOLIMITS2026 = 2, -} - -impl EnforceProtoLimits { - pub fn from_i32(value: i32) -> Self { - match value { - 0 => EnforceProtoLimits::PROTOLIMITSUNKNOWN, - 1 => EnforceProtoLimits::LEGACYNOEXPLICITLIMITS, - 2 => EnforceProtoLimits::PROTOLIMITS2026, - _ => EnforceProtoLimits::PROTOLIMITSUNKNOWN, + impl RepeatedFieldEncoding { + pub fn from_i32(value: i32) -> Self { + match value { + 0 => RepeatedFieldEncoding::REPEATEDFIELDENCODINGUNKNOWN, + 1 => RepeatedFieldEncoding::PACKED, + 2 => RepeatedFieldEncoding::EXPANDED, + _ => RepeatedFieldEncoding::REPEATEDFIELDENCODINGUNKNOWN, + } } } -} -} + #[derive(Debug, Clone, Copy, PartialEq, Eq)] + #[repr(i32)] + pub enum Utf8Validation { + UTF8VALIDATIONUNKNOWN = 0, + VERIFY = 2, + NONE = 3, + } + impl Utf8Validation { + pub fn from_i32(value: i32) -> Self { + match value { + 0 => Utf8Validation::UTF8VALIDATIONUNKNOWN, + 2 => Utf8Validation::VERIFY, + 3 => Utf8Validation::NONE, + _ => Utf8Validation::UTF8VALIDATIONUNKNOWN, + } + } + } + + #[derive(Debug, Clone, Copy, PartialEq, Eq)] + #[repr(i32)] + pub enum MessageEncoding { + MESSAGEENCODINGUNKNOWN = 0, + LENGTHPREFIXED = 1, + DELIMITED = 2, + } + + impl MessageEncoding { + pub fn from_i32(value: i32) -> Self { + match value { + 0 => MessageEncoding::MESSAGEENCODINGUNKNOWN, + 1 => MessageEncoding::LENGTHPREFIXED, + 2 => MessageEncoding::DELIMITED, + _ => MessageEncoding::MESSAGEENCODINGUNKNOWN, + } + } + } + + #[derive(Debug, Clone, Copy, PartialEq, Eq)] + #[repr(i32)] + pub enum JsonFormat { + JSONFORMATUNKNOWN = 0, + ALLOW = 1, + LEGACYBESTEFFORT = 2, + } + + impl JsonFormat { + pub fn from_i32(value: i32) -> Self { + match value { + 0 => JsonFormat::JSONFORMATUNKNOWN, + 1 => JsonFormat::ALLOW, + 2 => JsonFormat::LEGACYBESTEFFORT, + _ => JsonFormat::JSONFORMATUNKNOWN, + } + } + } + + #[derive(Debug, Clone, Copy, PartialEq, Eq)] + #[repr(i32)] + pub enum EnforceNamingStyle { + ENFORCENAMINGSTYLEUNKNOWN = 0, + STYLE2024 = 1, + STYLELEGACY = 2, + STYLE2026 = 3, + } + + impl EnforceNamingStyle { + pub fn from_i32(value: i32) -> Self { + match value { + 0 => EnforceNamingStyle::ENFORCENAMINGSTYLEUNKNOWN, + 1 => EnforceNamingStyle::STYLE2024, + 2 => EnforceNamingStyle::STYLELEGACY, + 3 => EnforceNamingStyle::STYLE2026, + _ => EnforceNamingStyle::ENFORCENAMINGSTYLEUNKNOWN, + } + } + } + + pub struct VisibilityFeature<'a> { + accessor: crate::runtime::ProtoAccessor<'a>, + } + + impl<'a> VisibilityFeature<'a> { + pub fn new(data: &'a [u8]) -> crate::runtime::Result { + let accessor = crate::runtime::ProtoAccessor::new(data)?; + for item in accessor.fields() { + let (offset, tag, _) = item?; + } + + Ok(Self { accessor }) + } + + pub fn raw_fields(&self) -> crate::runtime::RawFieldIterator<'a> { + self.accessor.raw_fields() + } + } + + pub struct VisibilityFeatureBuilder<'b> { + builder: crate::runtime::ProtoBuilder<'b>, + } + + impl<'b> VisibilityFeatureBuilder<'b> { + pub fn builder(buf: &mut [u8]) -> VisibilityFeatureBuilder<'_> { + VisibilityFeatureBuilder { + builder: crate::runtime::ProtoBuilder::new(buf), + } + } + + pub fn with(mut self, msg: &VisibilityFeature<'_>) -> crate::runtime::Result { + for item in msg.raw_fields() { + let (field_number, raw_bytes) = item?; + let is_written = match field_number { + _ => 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 OwnedVisibilityFeature { + pub data: bytes::Bytes, + } + + impl crate::runtime::RotoOwned for OwnedVisibilityFeature { + type Reader<'a> = VisibilityFeature<'a>; + fn reader(&self) -> VisibilityFeature<'_> { + VisibilityFeature::new(&self.data).expect("failed to create reader") + } + } + + impl crate::runtime::RotoMessage for OwnedVisibilityFeature { + fn decode(buf: bytes::Bytes) -> crate::runtime::Result { + Ok(OwnedVisibilityFeature { data: buf }) + } + + fn bytes(&self) -> bytes::Bytes { + self.data.clone() + } + } + + pub mod visibility_feature { + #[derive(Debug, Clone, Copy, PartialEq, Eq)] + #[repr(i32)] + pub enum DefaultSymbolVisibility { + DEFAULTSYMBOLVISIBILITYUNKNOWN = 0, + EXPORTALL = 1, + EXPORTTOPLEVEL = 2, + LOCALALL = 3, + STRICT = 4, + } + + impl DefaultSymbolVisibility { + pub fn from_i32(value: i32) -> Self { + match value { + 0 => DefaultSymbolVisibility::DEFAULTSYMBOLVISIBILITYUNKNOWN, + 1 => DefaultSymbolVisibility::EXPORTALL, + 2 => DefaultSymbolVisibility::EXPORTTOPLEVEL, + 3 => DefaultSymbolVisibility::LOCALALL, + 4 => DefaultSymbolVisibility::STRICT, + _ => DefaultSymbolVisibility::DEFAULTSYMBOLVISIBILITYUNKNOWN, + } + } + } + } + + pub struct ProtoLimitsFeature<'a> { + accessor: crate::runtime::ProtoAccessor<'a>, + } + + impl<'a> ProtoLimitsFeature<'a> { + pub fn new(data: &'a [u8]) -> crate::runtime::Result { + let accessor = crate::runtime::ProtoAccessor::new(data)?; + for item in accessor.fields() { + let (offset, tag, _) = item?; + } + + Ok(Self { accessor }) + } + + pub fn raw_fields(&self) -> crate::runtime::RawFieldIterator<'a> { + self.accessor.raw_fields() + } + } + + pub struct ProtoLimitsFeatureBuilder<'b> { + builder: crate::runtime::ProtoBuilder<'b>, + } + + impl<'b> ProtoLimitsFeatureBuilder<'b> { + pub fn builder(buf: &mut [u8]) -> ProtoLimitsFeatureBuilder<'_> { + ProtoLimitsFeatureBuilder { + builder: crate::runtime::ProtoBuilder::new(buf), + } + } + + pub fn with(mut self, msg: &ProtoLimitsFeature<'_>) -> crate::runtime::Result { + for item in msg.raw_fields() { + let (field_number, raw_bytes) = item?; + let is_written = match field_number { + _ => 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 OwnedProtoLimitsFeature { + pub data: bytes::Bytes, + } + + impl crate::runtime::RotoOwned for OwnedProtoLimitsFeature { + type Reader<'a> = ProtoLimitsFeature<'a>; + fn reader(&self) -> ProtoLimitsFeature<'_> { + ProtoLimitsFeature::new(&self.data).expect("failed to create reader") + } + } + + impl crate::runtime::RotoMessage for OwnedProtoLimitsFeature { + fn decode(buf: bytes::Bytes) -> crate::runtime::Result { + Ok(OwnedProtoLimitsFeature { data: buf }) + } + + fn bytes(&self) -> bytes::Bytes { + self.data.clone() + } + } + + pub mod proto_limits_feature { + #[derive(Debug, Clone, Copy, PartialEq, Eq)] + #[repr(i32)] + pub enum EnforceProtoLimits { + PROTOLIMITSUNKNOWN = 0, + LEGACYNOEXPLICITLIMITS = 1, + PROTOLIMITS2026 = 2, + } + + impl EnforceProtoLimits { + pub fn from_i32(value: i32) -> Self { + match value { + 0 => EnforceProtoLimits::PROTOLIMITSUNKNOWN, + 1 => EnforceProtoLimits::LEGACYNOEXPLICITLIMITS, + 2 => EnforceProtoLimits::PROTOLIMITS2026, + _ => EnforceProtoLimits::PROTOLIMITSUNKNOWN, + } + } + } + } } pub struct FeatureSetDefaults<'a> { @@ -6587,18 +7571,25 @@ impl<'a> FeatureSetDefaults<'a> { for item in accessor.fields() { let (offset, tag, _) = item?; if tag.field_number == 1 { - if defaults_start.is_none() { defaults_start = Some(offset); } + if defaults_start.is_none() { + defaults_start = Some(offset); + } defaults_end = Some(offset); } - if tag.field_number == 4 { minimum_edition_offset = Some(offset); } - if tag.field_number == 5 { maximum_edition_offset = Some(offset); } + if tag.field_number == 4 { + minimum_edition_offset = Some(offset); + } + if tag.field_number == 5 { + maximum_edition_offset = Some(offset); + } } Ok(Self { accessor, -defaults_start, defaults_end, -minimum_edition_offset, -maximum_edition_offset, + defaults_start, + defaults_end, + minimum_edition_offset, + maximum_edition_offset, }) } @@ -6610,33 +7601,44 @@ maximum_edition_offset, } pub fn minimum_edition(&self) -> crate::runtime::Result { - 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 u64).map_err(|_| crate::runtime::RotoError::WireFormatViolation) + crate::runtime::read_varint(bytes) + .map(|(v, _)| v as u64) + .map_err(|_| crate::runtime::RotoError::WireFormatViolation) } pub fn minimum_edition_or_default(&self) -> crate::runtime::Result { 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 { - 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 u64).map_err(|_| crate::runtime::RotoError::WireFormatViolation) + crate::runtime::read_varint(bytes) + .map(|(v, _)| v as u64) + .map_err(|_| crate::runtime::RotoError::WireFormatViolation) } pub fn maximum_edition_or_default(&self) -> crate::runtime::Result { 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 raw_fields(&self) -> crate::runtime::RawFieldIterator<'a> { self.accessor.raw_fields() } - } pub struct FeatureSetDefaultsBuilder<'b> { @@ -6717,153 +7719,171 @@ impl crate::runtime::RotoMessage for OwnedFeatureSetDefaults { } pub mod feature_set_defaults { -pub struct FeatureSetEditionDefault<'a> { - accessor: crate::runtime::ProtoAccessor<'a>, - edition_offset: Option, - overridable_features_offset: Option, - fixed_features_offset: Option, -} + pub struct FeatureSetEditionDefault<'a> { + accessor: crate::runtime::ProtoAccessor<'a>, + edition_offset: Option, + overridable_features_offset: Option, + fixed_features_offset: Option, + } -impl<'a> FeatureSetEditionDefault<'a> { - pub fn new(data: &'a [u8]) -> crate::runtime::Result { - let accessor = crate::runtime::ProtoAccessor::new(data)?; - let mut edition_offset = None; - let mut overridable_features_offset = None; - let mut fixed_features_offset = None; - for item in accessor.fields() { - let (offset, tag, _) = item?; - if tag.field_number == 3 { edition_offset = Some(offset); } - if tag.field_number == 4 { overridable_features_offset = Some(offset); } - if tag.field_number == 5 { fixed_features_offset = Some(offset); } + impl<'a> FeatureSetEditionDefault<'a> { + pub fn new(data: &'a [u8]) -> crate::runtime::Result { + let accessor = crate::runtime::ProtoAccessor::new(data)?; + let mut edition_offset = None; + let mut overridable_features_offset = None; + let mut fixed_features_offset = None; + for item in accessor.fields() { + let (offset, tag, _) = item?; + if tag.field_number == 3 { + edition_offset = Some(offset); + } + if tag.field_number == 4 { + overridable_features_offset = Some(offset); + } + if tag.field_number == 5 { + fixed_features_offset = Some(offset); + } + } + + Ok(Self { + accessor, + edition_offset, + overridable_features_offset, + fixed_features_offset, + }) } - Ok(Self { - accessor, -edition_offset, -overridable_features_offset, -fixed_features_offset, - }) - } + pub fn edition(&self) -> crate::runtime::Result { + let offset = self + .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 u64) + .map_err(|_| crate::runtime::RotoError::WireFormatViolation) + } - pub fn edition(&self) -> crate::runtime::Result { - let offset = self.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 u64).map_err(|_| crate::runtime::RotoError::WireFormatViolation) - } + pub fn edition_or_default(&self) -> crate::runtime::Result { + self.edition().or(Ok(0)) + } - pub fn edition_or_default(&self) -> crate::runtime::Result { - self.edition().or(Ok(0)) - } + pub fn has_edition(&self) -> bool { + self.edition_offset.is_some() + } - pub fn has_edition(&self) -> bool { self.edition_offset.is_some() } + pub fn overridable_features(&self) -> crate::runtime::Result<&'a [u8]> { + let offset = self + .overridable_features_offset + .ok_or(crate::runtime::RotoError::FieldNotFound)?; + let (bytes, _) = self.accessor.get_value_at(offset)?; + Ok(bytes) + } - pub fn overridable_features(&self) -> crate::runtime::Result<&'a [u8]> { - let offset = self.overridable_features_offset.ok_or(crate::runtime::RotoError::FieldNotFound)?; - let (bytes, _) = self.accessor.get_value_at(offset)?; - Ok(bytes) - } + pub fn overridable_features_or_default(&self) -> crate::runtime::Result<&'a [u8]> { + self.overridable_features().or(Ok(&[])) + } - pub fn overridable_features_or_default(&self) -> crate::runtime::Result<&'a [u8]> { - self.overridable_features().or(Ok(&[])) - } + pub fn has_overridable_features(&self) -> bool { + self.overridable_features_offset.is_some() + } - pub fn has_overridable_features(&self) -> bool { self.overridable_features_offset.is_some() } + pub fn fixed_features(&self) -> crate::runtime::Result<&'a [u8]> { + let offset = self + .fixed_features_offset + .ok_or(crate::runtime::RotoError::FieldNotFound)?; + let (bytes, _) = self.accessor.get_value_at(offset)?; + Ok(bytes) + } - pub fn fixed_features(&self) -> crate::runtime::Result<&'a [u8]> { - let offset = self.fixed_features_offset.ok_or(crate::runtime::RotoError::FieldNotFound)?; - let (bytes, _) = self.accessor.get_value_at(offset)?; - Ok(bytes) - } + pub fn fixed_features_or_default(&self) -> crate::runtime::Result<&'a [u8]> { + self.fixed_features().or(Ok(&[])) + } - pub fn fixed_features_or_default(&self) -> crate::runtime::Result<&'a [u8]> { - self.fixed_features().or(Ok(&[])) - } + pub fn has_fixed_features(&self) -> bool { + self.fixed_features_offset.is_some() + } - pub fn has_fixed_features(&self) -> bool { self.fixed_features_offset.is_some() } - - pub fn raw_fields(&self) -> crate::runtime::RawFieldIterator<'a> { - self.accessor.raw_fields() - } - -} - -pub struct FeatureSetEditionDefaultBuilder<'b> { - builder: crate::runtime::ProtoBuilder<'b>, - edition_written: bool, - overridable_features_written: bool, - fixed_features_written: bool, -} - -impl<'b> FeatureSetEditionDefaultBuilder<'b> { - pub fn builder(buf: &mut [u8]) -> FeatureSetEditionDefaultBuilder<'_> { - FeatureSetEditionDefaultBuilder { - builder: crate::runtime::ProtoBuilder::new(buf), - edition_written: false, - overridable_features_written: false, - fixed_features_written: false, + pub fn raw_fields(&self) -> crate::runtime::RawFieldIterator<'a> { + self.accessor.raw_fields() } } - pub fn edition(mut self, value: u64) -> crate::runtime::Result { - self.builder.write_varint(3, value)?; - self.edition_written = true; - Ok(self) + pub struct FeatureSetEditionDefaultBuilder<'b> { + builder: crate::runtime::ProtoBuilder<'b>, + edition_written: bool, + overridable_features_written: bool, + fixed_features_written: bool, } - pub fn overridable_features(mut self, value: &[u8]) -> crate::runtime::Result { - self.builder.write_bytes(4, value)?; - self.overridable_features_written = true; - Ok(self) - } - - pub fn fixed_features(mut self, value: &[u8]) -> crate::runtime::Result { - self.builder.write_bytes(5, value)?; - self.fixed_features_written = true; - Ok(self) - } - - pub fn with(mut self, msg: &FeatureSetEditionDefault<'_>) -> crate::runtime::Result { - for item in msg.raw_fields() { - let (field_number, raw_bytes) = item?; - let is_written = match field_number { - 3 => self.edition_written, - 4 => self.overridable_features_written, - 5 => self.fixed_features_written, - _ => false, - }; - if !is_written { - self.builder.write_raw(raw_bytes)?; + impl<'b> FeatureSetEditionDefaultBuilder<'b> { + pub fn builder(buf: &mut [u8]) -> FeatureSetEditionDefaultBuilder<'_> { + FeatureSetEditionDefaultBuilder { + builder: crate::runtime::ProtoBuilder::new(buf), + edition_written: false, + overridable_features_written: false, + fixed_features_written: false, } } - Ok(self) + + pub fn edition(mut self, value: u64) -> crate::runtime::Result { + self.builder.write_varint(3, value)?; + self.edition_written = true; + Ok(self) + } + + pub fn overridable_features(mut self, value: &[u8]) -> crate::runtime::Result { + self.builder.write_bytes(4, value)?; + self.overridable_features_written = true; + Ok(self) + } + + pub fn fixed_features(mut self, value: &[u8]) -> crate::runtime::Result { + self.builder.write_bytes(5, value)?; + self.fixed_features_written = true; + Ok(self) + } + + pub fn with(mut self, msg: &FeatureSetEditionDefault<'_>) -> crate::runtime::Result { + for item in msg.raw_fields() { + let (field_number, raw_bytes) = item?; + let is_written = match field_number { + 3 => self.edition_written, + 4 => self.overridable_features_written, + 5 => self.fixed_features_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 fn finish(self) -> crate::runtime::Result<&'b mut [u8]> { - self.builder.finish() - } -} - -pub struct OwnedFeatureSetEditionDefault { - pub data: bytes::Bytes, -} - -impl crate::runtime::RotoOwned for OwnedFeatureSetEditionDefault { - type Reader<'a> = FeatureSetEditionDefault<'a>; - fn reader(&self) -> FeatureSetEditionDefault<'_> { - FeatureSetEditionDefault::new(&self.data).expect("failed to create reader") - } -} - -impl crate::runtime::RotoMessage for OwnedFeatureSetEditionDefault { - fn decode(buf: bytes::Bytes) -> crate::runtime::Result { - Ok(OwnedFeatureSetEditionDefault { data: buf }) + pub struct OwnedFeatureSetEditionDefault { + pub data: bytes::Bytes, } - fn bytes(&self) -> bytes::Bytes { - self.data.clone() + impl crate::runtime::RotoOwned for OwnedFeatureSetEditionDefault { + type Reader<'a> = FeatureSetEditionDefault<'a>; + fn reader(&self) -> FeatureSetEditionDefault<'_> { + FeatureSetEditionDefault::new(&self.data).expect("failed to create reader") + } } -} + impl crate::runtime::RotoMessage for OwnedFeatureSetEditionDefault { + fn decode(buf: bytes::Bytes) -> crate::runtime::Result { + Ok(OwnedFeatureSetEditionDefault { data: buf }) + } + + fn bytes(&self) -> bytes::Bytes { + self.data.clone() + } + } } pub struct SourceCodeInfo<'a> { @@ -6880,14 +7900,17 @@ impl<'a> SourceCodeInfo<'a> { for item in accessor.fields() { let (offset, tag, _) = item?; if tag.field_number == 1 { - if location_start.is_none() { location_start = Some(offset); } + if location_start.is_none() { + location_start = Some(offset); + } location_end = Some(offset); } } Ok(Self { accessor, -location_start, location_end, + location_start, + location_end, }) } @@ -6901,7 +7924,6 @@ location_start, location_end, pub fn raw_fields(&self) -> crate::runtime::RawFieldIterator<'a> { self.accessor.raw_fields() } - } pub struct SourceCodeInfoBuilder<'b> { @@ -6964,203 +7986,225 @@ impl crate::runtime::RotoMessage for OwnedSourceCodeInfo { } pub mod source_code_info { -pub struct Location<'a> { - accessor: crate::runtime::ProtoAccessor<'a>, - path_start: Option, - path_end: Option, - span_start: Option, - span_end: Option, - leading_comments_offset: Option, - trailing_comments_offset: Option, - leading_detached_comments_start: Option, - leading_detached_comments_end: Option, -} + pub struct Location<'a> { + accessor: crate::runtime::ProtoAccessor<'a>, + path_start: Option, + path_end: Option, + span_start: Option, + span_end: Option, + leading_comments_offset: Option, + trailing_comments_offset: Option, + leading_detached_comments_start: Option, + leading_detached_comments_end: Option, + } -impl<'a> Location<'a> { - pub fn new(data: &'a [u8]) -> crate::runtime::Result { - let accessor = crate::runtime::ProtoAccessor::new(data)?; - let mut path_start = None; - let mut path_end = None; - let mut span_start = None; - let mut span_end = None; - let mut leading_comments_offset = None; - let mut trailing_comments_offset = None; - let mut leading_detached_comments_start = None; - let mut leading_detached_comments_end = None; - for item in accessor.fields() { - let (offset, tag, _) = item?; - if tag.field_number == 1 { - if path_start.is_none() { path_start = Some(offset); } - path_end = Some(offset); + impl<'a> Location<'a> { + pub fn new(data: &'a [u8]) -> crate::runtime::Result { + let accessor = crate::runtime::ProtoAccessor::new(data)?; + let mut path_start = None; + let mut path_end = None; + let mut span_start = None; + let mut span_end = None; + let mut leading_comments_offset = None; + let mut trailing_comments_offset = None; + let mut leading_detached_comments_start = None; + let mut leading_detached_comments_end = None; + for item in accessor.fields() { + let (offset, tag, _) = item?; + if tag.field_number == 1 { + if path_start.is_none() { + path_start = Some(offset); + } + path_end = Some(offset); + } + if tag.field_number == 2 { + if span_start.is_none() { + span_start = Some(offset); + } + span_end = Some(offset); + } + if tag.field_number == 3 { + leading_comments_offset = Some(offset); + } + if tag.field_number == 4 { + trailing_comments_offset = Some(offset); + } + if tag.field_number == 6 { + if leading_detached_comments_start.is_none() { + leading_detached_comments_start = Some(offset); + } + leading_detached_comments_end = Some(offset); + } } - if tag.field_number == 2 { - if span_start.is_none() { span_start = Some(offset); } - span_end = Some(offset); - } - if tag.field_number == 3 { leading_comments_offset = Some(offset); } - if tag.field_number == 4 { trailing_comments_offset = Some(offset); } - if tag.field_number == 6 { - if leading_detached_comments_start.is_none() { leading_detached_comments_start = Some(offset); } - leading_detached_comments_end = Some(offset); + + Ok(Self { + accessor, + path_start, + path_end, + span_start, + span_end, + leading_comments_offset, + trailing_comments_offset, + leading_detached_comments_start, + leading_detached_comments_end, + }) + } + + pub fn path(&self) -> crate::runtime::RepeatedFieldIterator<'a> { + match (self.path_start, self.path_end) { + (Some(start), Some(end)) => self.accessor.iter_repeated_range(1, start, end), + _ => self.accessor.iter_repeated(1), } } - Ok(Self { - accessor, -path_start, path_end, -span_start, span_end, -leading_comments_offset, -trailing_comments_offset, -leading_detached_comments_start, leading_detached_comments_end, - }) - } - - pub fn path(&self) -> crate::runtime::RepeatedFieldIterator<'a> { - match (self.path_start, self.path_end) { - (Some(start), Some(end)) => self.accessor.iter_repeated_range(1, start, end), - _ => self.accessor.iter_repeated(1), - } - } - - pub fn span(&self) -> crate::runtime::RepeatedFieldIterator<'a> { - match (self.span_start, self.span_end) { - (Some(start), Some(end)) => self.accessor.iter_repeated_range(2, start, end), - _ => self.accessor.iter_repeated(2), - } - } - - pub fn leading_comments(&self) -> crate::runtime::Result<&'a str> { - let offset = self.leading_comments_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 leading_comments_or_default(&self) -> crate::runtime::Result<&'a str> { - self.leading_comments().or(Ok("")) - } - - pub fn has_leading_comments(&self) -> bool { self.leading_comments_offset.is_some() } - - pub fn trailing_comments(&self) -> crate::runtime::Result<&'a str> { - let offset = self.trailing_comments_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 trailing_comments_or_default(&self) -> crate::runtime::Result<&'a str> { - self.trailing_comments().or(Ok("")) - } - - pub fn has_trailing_comments(&self) -> bool { self.trailing_comments_offset.is_some() } - - pub fn leading_detached_comments(&self) -> crate::runtime::RepeatedFieldIterator<'a> { - match (self.leading_detached_comments_start, self.leading_detached_comments_end) { - (Some(start), Some(end)) => self.accessor.iter_repeated_range(6, start, end), - _ => self.accessor.iter_repeated(6), - } - } - - pub fn raw_fields(&self) -> crate::runtime::RawFieldIterator<'a> { - self.accessor.raw_fields() - } - -} - -pub struct LocationBuilder<'b> { - builder: crate::runtime::ProtoBuilder<'b>, - path_written: bool, - span_written: bool, - leading_comments_written: bool, - trailing_comments_written: bool, - leading_detached_comments_written: bool, -} - -impl<'b> LocationBuilder<'b> { - pub fn builder(buf: &mut [u8]) -> LocationBuilder<'_> { - LocationBuilder { - builder: crate::runtime::ProtoBuilder::new(buf), - path_written: false, - span_written: false, - leading_comments_written: false, - trailing_comments_written: false, - leading_detached_comments_written: false, - } - } - - pub fn path(mut self, value: i32) -> crate::runtime::Result { - self.builder.write_int32(1, value)?; - self.path_written = true; - Ok(self) - } - - pub fn span(mut self, value: i32) -> crate::runtime::Result { - self.builder.write_int32(2, value)?; - self.span_written = true; - Ok(self) - } - - pub fn leading_comments(mut self, value: &str) -> crate::runtime::Result { - self.builder.write_string(3, value)?; - self.leading_comments_written = true; - Ok(self) - } - - pub fn trailing_comments(mut self, value: &str) -> crate::runtime::Result { - self.builder.write_string(4, value)?; - self.trailing_comments_written = true; - Ok(self) - } - - pub fn leading_detached_comments(mut self, value: &str) -> crate::runtime::Result { - self.builder.write_string(6, value)?; - self.leading_detached_comments_written = true; - Ok(self) - } - - pub fn with(mut self, msg: &Location<'_>) -> crate::runtime::Result { - for item in msg.raw_fields() { - let (field_number, raw_bytes) = item?; - let is_written = match field_number { - 1 => self.path_written, - 2 => self.span_written, - 3 => self.leading_comments_written, - 4 => self.trailing_comments_written, - 6 => self.leading_detached_comments_written, - _ => false, - }; - if !is_written { - self.builder.write_raw(raw_bytes)?; + pub fn span(&self) -> crate::runtime::RepeatedFieldIterator<'a> { + match (self.span_start, self.span_end) { + (Some(start), Some(end)) => self.accessor.iter_repeated_range(2, start, end), + _ => self.accessor.iter_repeated(2), } } - Ok(self) + + pub fn leading_comments(&self) -> crate::runtime::Result<&'a str> { + let offset = self + .leading_comments_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 leading_comments_or_default(&self) -> crate::runtime::Result<&'a str> { + self.leading_comments().or(Ok("")) + } + + pub fn has_leading_comments(&self) -> bool { + self.leading_comments_offset.is_some() + } + + pub fn trailing_comments(&self) -> crate::runtime::Result<&'a str> { + let offset = self + .trailing_comments_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 trailing_comments_or_default(&self) -> crate::runtime::Result<&'a str> { + self.trailing_comments().or(Ok("")) + } + + pub fn has_trailing_comments(&self) -> bool { + self.trailing_comments_offset.is_some() + } + + pub fn leading_detached_comments(&self) -> crate::runtime::RepeatedFieldIterator<'a> { + match ( + self.leading_detached_comments_start, + self.leading_detached_comments_end, + ) { + (Some(start), Some(end)) => self.accessor.iter_repeated_range(6, start, end), + _ => self.accessor.iter_repeated(6), + } + } + + pub fn raw_fields(&self) -> crate::runtime::RawFieldIterator<'a> { + self.accessor.raw_fields() + } } - pub fn finish(self) -> crate::runtime::Result<&'b mut [u8]> { - self.builder.finish() - } -} - -pub struct OwnedLocation { - pub data: bytes::Bytes, -} - -impl crate::runtime::RotoOwned for OwnedLocation { - type Reader<'a> = Location<'a>; - fn reader(&self) -> Location<'_> { - Location::new(&self.data).expect("failed to create reader") - } -} - -impl crate::runtime::RotoMessage for OwnedLocation { - fn decode(buf: bytes::Bytes) -> crate::runtime::Result { - Ok(OwnedLocation { data: buf }) + pub struct LocationBuilder<'b> { + builder: crate::runtime::ProtoBuilder<'b>, + path_written: bool, + span_written: bool, + leading_comments_written: bool, + trailing_comments_written: bool, + leading_detached_comments_written: bool, } - fn bytes(&self) -> bytes::Bytes { - self.data.clone() - } -} + impl<'b> LocationBuilder<'b> { + pub fn builder(buf: &mut [u8]) -> LocationBuilder<'_> { + LocationBuilder { + builder: crate::runtime::ProtoBuilder::new(buf), + path_written: false, + span_written: false, + leading_comments_written: false, + trailing_comments_written: false, + leading_detached_comments_written: false, + } + } + pub fn path(mut self, value: i32) -> crate::runtime::Result { + self.builder.write_int32(1, value)?; + self.path_written = true; + Ok(self) + } + + pub fn span(mut self, value: i32) -> crate::runtime::Result { + self.builder.write_int32(2, value)?; + self.span_written = true; + Ok(self) + } + + pub fn leading_comments(mut self, value: &str) -> crate::runtime::Result { + self.builder.write_string(3, value)?; + self.leading_comments_written = true; + Ok(self) + } + + pub fn trailing_comments(mut self, value: &str) -> crate::runtime::Result { + self.builder.write_string(4, value)?; + self.trailing_comments_written = true; + Ok(self) + } + + pub fn leading_detached_comments(mut self, value: &str) -> crate::runtime::Result { + self.builder.write_string(6, value)?; + self.leading_detached_comments_written = true; + Ok(self) + } + + pub fn with(mut self, msg: &Location<'_>) -> crate::runtime::Result { + for item in msg.raw_fields() { + let (field_number, raw_bytes) = item?; + let is_written = match field_number { + 1 => self.path_written, + 2 => self.span_written, + 3 => self.leading_comments_written, + 4 => self.trailing_comments_written, + 6 => self.leading_detached_comments_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 OwnedLocation { + pub data: bytes::Bytes, + } + + impl crate::runtime::RotoOwned for OwnedLocation { + type Reader<'a> = Location<'a>; + fn reader(&self) -> Location<'_> { + Location::new(&self.data).expect("failed to create reader") + } + } + + impl crate::runtime::RotoMessage for OwnedLocation { + fn decode(buf: bytes::Bytes) -> crate::runtime::Result { + Ok(OwnedLocation { data: buf }) + } + + fn bytes(&self) -> bytes::Bytes { + self.data.clone() + } + } } pub struct GeneratedCodeInfo<'a> { @@ -7177,14 +8221,17 @@ impl<'a> GeneratedCodeInfo<'a> { for item in accessor.fields() { let (offset, tag, _) = item?; if tag.field_number == 1 { - if annotation_start.is_none() { annotation_start = Some(offset); } + if annotation_start.is_none() { + annotation_start = Some(offset); + } annotation_end = Some(offset); } } Ok(Self { accessor, -annotation_start, annotation_end, + annotation_start, + annotation_end, }) } @@ -7198,7 +8245,6 @@ annotation_start, annotation_end, pub fn raw_fields(&self) -> crate::runtime::RawFieldIterator<'a> { self.accessor.raw_fields() } - } pub struct GeneratedCodeInfoBuilder<'b> { @@ -7261,224 +8307,253 @@ impl crate::runtime::RotoMessage for OwnedGeneratedCodeInfo { } pub mod generated_code_info { -pub struct Annotation<'a> { - accessor: crate::runtime::ProtoAccessor<'a>, - path_start: Option, - path_end: Option, - source_file_offset: Option, - begin_offset: Option, - end_offset: Option, - semantic_offset: Option, -} + pub struct Annotation<'a> { + accessor: crate::runtime::ProtoAccessor<'a>, + path_start: Option, + path_end: Option, + source_file_offset: Option, + begin_offset: Option, + end_offset: Option, + semantic_offset: Option, + } -impl<'a> Annotation<'a> { - pub fn new(data: &'a [u8]) -> crate::runtime::Result { - let accessor = crate::runtime::ProtoAccessor::new(data)?; - let mut path_start = None; - let mut path_end = None; - let mut source_file_offset = None; - let mut begin_offset = None; - let mut end_offset = None; - let mut semantic_offset = None; - for item in accessor.fields() { - let (offset, tag, _) = item?; - if tag.field_number == 1 { - if path_start.is_none() { path_start = Some(offset); } - path_end = Some(offset); + impl<'a> Annotation<'a> { + pub fn new(data: &'a [u8]) -> crate::runtime::Result { + let accessor = crate::runtime::ProtoAccessor::new(data)?; + let mut path_start = None; + let mut path_end = None; + let mut source_file_offset = None; + let mut begin_offset = None; + let mut end_offset = None; + let mut semantic_offset = None; + for item in accessor.fields() { + let (offset, tag, _) = item?; + if tag.field_number == 1 { + if path_start.is_none() { + path_start = Some(offset); + } + path_end = Some(offset); + } + if tag.field_number == 2 { + source_file_offset = Some(offset); + } + if tag.field_number == 3 { + begin_offset = Some(offset); + } + if tag.field_number == 4 { + end_offset = Some(offset); + } + if tag.field_number == 5 { + semantic_offset = Some(offset); + } } - if tag.field_number == 2 { source_file_offset = Some(offset); } - if tag.field_number == 3 { begin_offset = Some(offset); } - if tag.field_number == 4 { end_offset = Some(offset); } - if tag.field_number == 5 { semantic_offset = Some(offset); } + + Ok(Self { + accessor, + path_start, + path_end, + source_file_offset, + begin_offset, + end_offset, + semantic_offset, + }) } - Ok(Self { - accessor, -path_start, path_end, -source_file_offset, -begin_offset, -end_offset, -semantic_offset, - }) - } - - pub fn path(&self) -> crate::runtime::RepeatedFieldIterator<'a> { - match (self.path_start, self.path_end) { - (Some(start), Some(end)) => self.accessor.iter_repeated_range(1, start, end), - _ => self.accessor.iter_repeated(1), - } - } - - pub fn source_file(&self) -> crate::runtime::Result<&'a str> { - let offset = self.source_file_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 source_file_or_default(&self) -> crate::runtime::Result<&'a str> { - self.source_file().or(Ok("")) - } - - pub fn has_source_file(&self) -> bool { self.source_file_offset.is_some() } - - pub fn begin(&self) -> crate::runtime::Result { - let offset = self.begin_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) - } - - pub fn begin_or_default(&self) -> crate::runtime::Result { - self.begin().or(Ok(0)) - } - - pub fn has_begin(&self) -> bool { self.begin_offset.is_some() } - - pub fn end(&self) -> crate::runtime::Result { - let offset = self.end_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) - } - - pub fn end_or_default(&self) -> crate::runtime::Result { - self.end().or(Ok(0)) - } - - pub fn has_end(&self) -> bool { self.end_offset.is_some() } - - pub fn semantic(&self) -> crate::runtime::Result { - let offset = self.semantic_offset.ok_or(crate::runtime::RotoError::FieldNotFound)?; - let (bytes, _) = self.accessor.get_value_at(offset)?; - crate::runtime::read_varint(bytes).map(|(v, _)| v as u64).map_err(|_| crate::runtime::RotoError::WireFormatViolation) - } - - pub fn semantic_or_default(&self) -> crate::runtime::Result { - self.semantic().or(Ok(0)) - } - - pub fn has_semantic(&self) -> bool { self.semantic_offset.is_some() } - - pub fn raw_fields(&self) -> crate::runtime::RawFieldIterator<'a> { - self.accessor.raw_fields() - } - -} - -pub struct AnnotationBuilder<'b> { - builder: crate::runtime::ProtoBuilder<'b>, - path_written: bool, - source_file_written: bool, - begin_written: bool, - end_written: bool, - semantic_written: bool, -} - -impl<'b> AnnotationBuilder<'b> { - pub fn builder(buf: &mut [u8]) -> AnnotationBuilder<'_> { - AnnotationBuilder { - builder: crate::runtime::ProtoBuilder::new(buf), - path_written: false, - source_file_written: false, - begin_written: false, - end_written: false, - semantic_written: false, - } - } - - pub fn path(mut self, value: i32) -> crate::runtime::Result { - self.builder.write_int32(1, value)?; - self.path_written = true; - Ok(self) - } - - pub fn source_file(mut self, value: &str) -> crate::runtime::Result { - self.builder.write_string(2, value)?; - self.source_file_written = true; - Ok(self) - } - - pub fn begin(mut self, value: i32) -> crate::runtime::Result { - self.builder.write_int32(3, value)?; - self.begin_written = true; - Ok(self) - } - - pub fn end(mut self, value: i32) -> crate::runtime::Result { - self.builder.write_int32(4, value)?; - self.end_written = true; - Ok(self) - } - - pub fn semantic(mut self, value: u64) -> crate::runtime::Result { - self.builder.write_varint(5, value)?; - self.semantic_written = true; - Ok(self) - } - - pub fn with(mut self, msg: &Annotation<'_>) -> crate::runtime::Result { - for item in msg.raw_fields() { - let (field_number, raw_bytes) = item?; - let is_written = match field_number { - 1 => self.path_written, - 2 => self.source_file_written, - 3 => self.begin_written, - 4 => self.end_written, - 5 => self.semantic_written, - _ => false, - }; - if !is_written { - self.builder.write_raw(raw_bytes)?; + pub fn path(&self) -> crate::runtime::RepeatedFieldIterator<'a> { + match (self.path_start, self.path_end) { + (Some(start), Some(end)) => self.accessor.iter_repeated_range(1, start, end), + _ => self.accessor.iter_repeated(1), } } - Ok(self) + + pub fn source_file(&self) -> crate::runtime::Result<&'a str> { + let offset = self + .source_file_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 source_file_or_default(&self) -> crate::runtime::Result<&'a str> { + self.source_file().or(Ok("")) + } + + pub fn has_source_file(&self) -> bool { + self.source_file_offset.is_some() + } + + pub fn begin(&self) -> crate::runtime::Result { + let offset = self + .begin_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) + } + + pub fn begin_or_default(&self) -> crate::runtime::Result { + self.begin().or(Ok(0)) + } + + pub fn has_begin(&self) -> bool { + self.begin_offset.is_some() + } + + pub fn end(&self) -> crate::runtime::Result { + let offset = self + .end_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) + } + + pub fn end_or_default(&self) -> crate::runtime::Result { + self.end().or(Ok(0)) + } + + pub fn has_end(&self) -> bool { + self.end_offset.is_some() + } + + pub fn semantic(&self) -> crate::runtime::Result { + let offset = self + .semantic_offset + .ok_or(crate::runtime::RotoError::FieldNotFound)?; + let (bytes, _) = self.accessor.get_value_at(offset)?; + crate::runtime::read_varint(bytes) + .map(|(v, _)| v as u64) + .map_err(|_| crate::runtime::RotoError::WireFormatViolation) + } + + pub fn semantic_or_default(&self) -> crate::runtime::Result { + self.semantic().or(Ok(0)) + } + + pub fn has_semantic(&self) -> bool { + self.semantic_offset.is_some() + } + + pub fn raw_fields(&self) -> crate::runtime::RawFieldIterator<'a> { + self.accessor.raw_fields() + } } - pub fn finish(self) -> crate::runtime::Result<&'b mut [u8]> { - self.builder.finish() - } -} - -pub struct OwnedAnnotation { - pub data: bytes::Bytes, -} - -impl crate::runtime::RotoOwned for OwnedAnnotation { - type Reader<'a> = Annotation<'a>; - fn reader(&self) -> Annotation<'_> { - Annotation::new(&self.data).expect("failed to create reader") - } -} - -impl crate::runtime::RotoMessage for OwnedAnnotation { - fn decode(buf: bytes::Bytes) -> crate::runtime::Result { - Ok(OwnedAnnotation { data: buf }) + pub struct AnnotationBuilder<'b> { + builder: crate::runtime::ProtoBuilder<'b>, + path_written: bool, + source_file_written: bool, + begin_written: bool, + end_written: bool, + semantic_written: bool, } - fn bytes(&self) -> bytes::Bytes { - self.data.clone() + impl<'b> AnnotationBuilder<'b> { + pub fn builder(buf: &mut [u8]) -> AnnotationBuilder<'_> { + AnnotationBuilder { + builder: crate::runtime::ProtoBuilder::new(buf), + path_written: false, + source_file_written: false, + begin_written: false, + end_written: false, + semantic_written: false, + } + } + + pub fn path(mut self, value: i32) -> crate::runtime::Result { + self.builder.write_int32(1, value)?; + self.path_written = true; + Ok(self) + } + + pub fn source_file(mut self, value: &str) -> crate::runtime::Result { + self.builder.write_string(2, value)?; + self.source_file_written = true; + Ok(self) + } + + pub fn begin(mut self, value: i32) -> crate::runtime::Result { + self.builder.write_int32(3, value)?; + self.begin_written = true; + Ok(self) + } + + pub fn end(mut self, value: i32) -> crate::runtime::Result { + self.builder.write_int32(4, value)?; + self.end_written = true; + Ok(self) + } + + pub fn semantic(mut self, value: u64) -> crate::runtime::Result { + self.builder.write_varint(5, value)?; + self.semantic_written = true; + Ok(self) + } + + pub fn with(mut self, msg: &Annotation<'_>) -> crate::runtime::Result { + for item in msg.raw_fields() { + let (field_number, raw_bytes) = item?; + let is_written = match field_number { + 1 => self.path_written, + 2 => self.source_file_written, + 3 => self.begin_written, + 4 => self.end_written, + 5 => self.semantic_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 mod annotation { -#[derive(Debug, Clone, Copy, PartialEq, Eq)] -#[repr(i32)] -pub enum Semantic { - NONE = 0, - SET = 1, - ALIAS = 2, -} + pub struct OwnedAnnotation { + pub data: bytes::Bytes, + } -impl Semantic { - pub fn from_i32(value: i32) -> Self { - match value { - 0 => Semantic::NONE, - 1 => Semantic::SET, - 2 => Semantic::ALIAS, - _ => Semantic::NONE, + impl crate::runtime::RotoOwned for OwnedAnnotation { + type Reader<'a> = Annotation<'a>; + fn reader(&self) -> Annotation<'_> { + Annotation::new(&self.data).expect("failed to create reader") + } + } + + impl crate::runtime::RotoMessage for OwnedAnnotation { + fn decode(buf: bytes::Bytes) -> crate::runtime::Result { + Ok(OwnedAnnotation { data: buf }) + } + + fn bytes(&self) -> bytes::Bytes { + self.data.clone() + } + } + + pub mod annotation { + #[derive(Debug, Clone, Copy, PartialEq, Eq)] + #[repr(i32)] + pub enum Semantic { + NONE = 0, + SET = 1, + ALIAS = 2, + } + + impl Semantic { + pub fn from_i32(value: i32) -> Self { + match value { + 0 => Semantic::NONE, + 1 => Semantic::SET, + 2 => Semantic::ALIAS, + _ => Semantic::NONE, + } + } } } } - -} - -} - diff --git a/examples/hello_world/src/bin/client.rs b/examples/hello_world/src/bin/client.rs index 49103b8..c08206a 100644 --- a/examples/hello_world/src/bin/client.rs +++ b/examples/hello_world/src/bin/client.rs @@ -1,12 +1,19 @@ -use tonic::Request; -use roto_tonic::RotoCodec; -use hello::{HelloWorldService, OwnedHelloRequest, OwnedHelloResponse}; +use hello::{OwnedHelloRequest, OwnedHelloResponse}; use roto_runtime::RotoOwned; +use roto_tonic::RotoCodec; use std::task::{Context, Poll}; +use tonic::Request; use tower::Service; pub use roto_tonic::{BufferPool, StatusBody}; +#[allow( + unused, + unused_imports, + unused_assignments, + unused_variables, + non_camel_case_types +)] pub mod hello { include!(concat!(env!("OUT_DIR"), "/hello.rs")); } @@ -45,8 +52,10 @@ async fn main() -> Result<(), Box> { // We need to specify the method path. For HelloWorldService/HelloWorld, it is "/hello.HelloWorldService/HelloWorld" let mut buf = vec![0u8; 1024]; let slice = hello::HelloRequestBuilder::builder(&mut buf) - .name("Roto").unwrap() - .finish().unwrap(); + .name("Roto") + .unwrap() + .finish() + .unwrap(); let request = OwnedHelloRequest { data: bytes::Bytes::copy_from_slice(slice), @@ -63,7 +72,10 @@ async fn main() -> Result<(), Box> { let response_msg: OwnedHelloResponse = response.into_inner(); let reader = response_msg.reader(); - println!("Server responded: {}", reader.message().unwrap_or("No message")); + println!( + "Server responded: {}", + reader.message().unwrap_or("No message") + ); Ok(()) } diff --git a/examples/hello_world/src/bin/server.rs b/examples/hello_world/src/bin/server.rs index 77c1396..141c105 100644 --- a/examples/hello_world/src/bin/server.rs +++ b/examples/hello_world/src/bin/server.rs @@ -1,20 +1,24 @@ -use std::pin::Pin; -use std::future::Future; -use std::task::{Context, Poll}; -use std::sync::{Arc, Mutex}; -use tonic::{transport::Server, Request, Response, Status}; -use roto_tonic::RotoCodec; +use bytes::{BufMut, Bytes}; use hello::{HelloWorldService, OwnedHelloRequest, OwnedHelloResponse}; -use tower::Service; -use bytes::{Bytes, BytesMut, Buf, BufMut}; -use tonic::body::BoxBody; -use futures_util::StreamExt; -use roto_runtime::{RotoOwned, RotoMessage}; use http_body_util::BodyExt; -use http_body::Body; +use roto_runtime::{RotoMessage, RotoOwned}; +use std::future::Future; +use std::pin::Pin; +use std::sync::Arc; +use std::task::{Context, Poll}; +use tonic::body::BoxBody; +use tonic::{Request, Response, Status, transport::Server}; +use tower::Service; pub use roto_tonic::{BufferPool, StatusBody}; +#[allow( + unused, + unused_imports, + unused_assignments, + unused_variables, + non_camel_case_types +)] pub mod hello { include!(concat!(env!("OUT_DIR"), "/hello.rs")); } @@ -43,8 +47,10 @@ impl HelloWorldService for MyHelloWorld { let mut buf = self.pool.get(); buf.resize(1024, 0); let slice = hello::HelloResponseBuilder::builder(&mut buf[..]) - .message(&format!("Hello {}!", name)).unwrap() - .finish().unwrap(); + .message(&format!("Hello {}!", name)) + .unwrap() + .finish() + .unwrap(); let res_len = slice.len(); let response_bytes = buf.split_to(res_len).freeze(); @@ -68,7 +74,10 @@ pub struct HelloWorldServer { impl HelloWorldServer { pub fn new(inner: MyHelloWorld, pool: Arc) -> Self { - Self { inner: Arc::new(inner), pool } + Self { + inner: Arc::new(inner), + pool, + } } } @@ -111,7 +120,10 @@ impl Service> for HelloWorldServer { if bytes_vec.len() < 5 { println!("Body too short: {} bytes", bytes_vec.len()); - let res_body = BoxBody::new(StatusBody::new(Some(Bytes::from_static(&[0, 0, 0, 0, 0])), 0)); + let res_body = BoxBody::new(StatusBody::new( + Some(Bytes::from_static(&[0, 0, 0, 0, 0])), + 0, + )); return Ok(http::Response::builder() .status(200) .body(res_body) @@ -123,8 +135,14 @@ impl Service> for HelloWorldServer { Ok(msg) => msg, Err(e) => { println!("Decode error: {}", e); - let res_body = BoxBody::new(StatusBody::new(Some(Bytes::from_static(&[0, 0, 0, 0, 0])), 0)); - return Ok(http::Response::builder().status(200).body(res_body).unwrap()); + let res_body = BoxBody::new(StatusBody::new( + Some(Bytes::from_static(&[0, 0, 0, 0, 0])), + 0, + )); + return Ok(http::Response::builder() + .status(200) + .body(res_body) + .unwrap()); } }; @@ -133,8 +151,14 @@ impl Service> for HelloWorldServer { Ok(res) => res, Err(e) => { println!("Service error: {}", e); - let res_body = BoxBody::new(StatusBody::new(Some(Bytes::from_static(&[0, 0, 0, 0, 0])), 0)); - return Ok(http::Response::builder().status(200).body(res_body).unwrap()); + let res_body = BoxBody::new(StatusBody::new( + Some(Bytes::from_static(&[0, 0, 0, 0, 0])), + 0, + )); + return Ok(http::Response::builder() + .status(200) + .body(res_body) + .unwrap()); } }; diff --git a/roto-tonic/src/generated/helloworld.rs b/roto-tonic/src/generated/helloworld.rs index 94af62a..6b6dcdb 100644 --- a/roto-tonic/src/generated/helloworld.rs +++ b/roto-tonic/src/generated/helloworld.rs @@ -1,22 +1,29 @@ // @generated by protoc-gen-roto — do not edit -#[allow(unused)] +#![allow( + unused, + unused_imports, + unused_assignments, + unused_variables, + non_camel_case_types +)] -use roto_runtime::{ProtoAccessor, ProtoBuilder, Result, RotoError, read_varint, RepeatedFieldIterator, RotoMessage}; -use std::str; -use bytes::{Bytes, BytesMut, Buf, BufMut}; -use tonic::{Request, Response, Status}; -use tokio_stream::Stream; +use crate::{BufferPool, StatusBody}; +use bytes::{Buf, BufMut, Bytes, BytesMut}; +use futures_util::StreamExt; +use http_body::Body; +use http_body_util::BodyExt; +use roto_runtime::{ + ProtoAccessor, ProtoBuilder, RepeatedFieldIterator, Result, RotoError, RotoMessage, read_varint, +}; +use std::future::Future; use std::pin::Pin; +use std::str; use std::sync::Arc; use std::task::{Context, Poll}; -use std::future::Future; +use tokio_stream::Stream; use tonic::body::BoxBody; +use tonic::{Request, Response, Status}; use tower::Service; -use futures_util::StreamExt; -use http_body_util::BodyExt; -use http_body::Body; -use crate::{BufferPool, StatusBody}; - pub struct Hello<'a> { accessor: roto_runtime::ProtoAccessor<'a>, @@ -47,36 +54,57 @@ impl<'a> Hello<'a> { let mut pets_end = None; for item in accessor.fields() { let (offset, tag, _) = item?; - if tag.field_number == 1 { name_offset = Some(offset); } - if tag.field_number == 2 { d_offset = Some(offset); } - if tag.field_number == 3 { f_offset = Some(offset); } - if tag.field_number == 4 { b_offset = Some(offset); } - if tag.field_number == 5 { n_offset = Some(offset); } - if tag.field_number == 6 { l_offset = Some(offset); } - if tag.field_number == 7 { c1_offset = Some(offset); } - if tag.field_number == 8 { c2_offset = Some(offset); } + if tag.field_number == 1 { + name_offset = Some(offset); + } + if tag.field_number == 2 { + d_offset = Some(offset); + } + if tag.field_number == 3 { + f_offset = Some(offset); + } + if tag.field_number == 4 { + b_offset = Some(offset); + } + if tag.field_number == 5 { + n_offset = Some(offset); + } + if tag.field_number == 6 { + l_offset = Some(offset); + } + if tag.field_number == 7 { + c1_offset = Some(offset); + } + if tag.field_number == 8 { + c2_offset = Some(offset); + } if tag.field_number == 9 { - if pets_start.is_none() { pets_start = Some(offset); } + if pets_start.is_none() { + pets_start = Some(offset); + } pets_end = Some(offset); } } Ok(Self { accessor, -name_offset, -d_offset, -f_offset, -b_offset, -n_offset, -l_offset, -c1_offset, -c2_offset, -pets_start, pets_end, + name_offset, + d_offset, + f_offset, + b_offset, + n_offset, + l_offset, + c1_offset, + c2_offset, + pets_start, + pets_end, }) } pub fn name(&self) -> roto_runtime::Result<&'a str> { - let offset = self.name_offset.ok_or(roto_runtime::RotoError::FieldNotFound)?; + let offset = self + .name_offset + .ok_or(roto_runtime::RotoError::FieldNotFound)?; let (bytes, _) = self.accessor.get_value_at(offset)?; std::str::from_utf8(bytes).map_err(|_| roto_runtime::RotoError::WireFormatViolation) } @@ -85,70 +113,104 @@ pets_start, pets_end, self.name().or(Ok("")) } - pub fn has_name(&self) -> bool { self.name_offset.is_some() } + pub fn has_name(&self) -> bool { + self.name_offset.is_some() + } pub fn d(&self) -> roto_runtime::Result { - let offset = self.d_offset.ok_or(roto_runtime::RotoError::FieldNotFound)?; + let offset = self + .d_offset + .ok_or(roto_runtime::RotoError::FieldNotFound)?; let (bytes, _) = self.accessor.get_value_at(offset)?; - Ok(f64::from_le_bytes(bytes.try_into().map_err(|_| roto_runtime::RotoError::WireFormatViolation)?)) + Ok(f64::from_le_bytes(bytes.try_into().map_err(|_| { + roto_runtime::RotoError::WireFormatViolation + })?)) } pub fn d_or_default(&self) -> roto_runtime::Result { self.d().or(Ok(0.0)) } - pub fn has_d(&self) -> bool { self.d_offset.is_some() } + pub fn has_d(&self) -> bool { + self.d_offset.is_some() + } pub fn f(&self) -> roto_runtime::Result { - let offset = self.f_offset.ok_or(roto_runtime::RotoError::FieldNotFound)?; + let offset = self + .f_offset + .ok_or(roto_runtime::RotoError::FieldNotFound)?; let (bytes, _) = self.accessor.get_value_at(offset)?; - Ok(f32::from_le_bytes(bytes.try_into().map_err(|_| roto_runtime::RotoError::WireFormatViolation)?)) + Ok(f32::from_le_bytes(bytes.try_into().map_err(|_| { + roto_runtime::RotoError::WireFormatViolation + })?)) } pub fn f_or_default(&self) -> roto_runtime::Result { self.f().or(Ok(0.0)) } - pub fn has_f(&self) -> bool { self.f_offset.is_some() } + pub fn has_f(&self) -> bool { + self.f_offset.is_some() + } pub fn b(&self) -> roto_runtime::Result { - let offset = self.b_offset.ok_or(roto_runtime::RotoError::FieldNotFound)?; + let offset = self + .b_offset + .ok_or(roto_runtime::RotoError::FieldNotFound)?; let (bytes, _) = self.accessor.get_value_at(offset)?; - roto_runtime::read_varint(bytes).map(|(v, _)| v != 0).map_err(|_| roto_runtime::RotoError::WireFormatViolation) + roto_runtime::read_varint(bytes) + .map(|(v, _)| v != 0) + .map_err(|_| roto_runtime::RotoError::WireFormatViolation) } pub fn b_or_default(&self) -> roto_runtime::Result { self.b().or(Ok(false)) } - pub fn has_b(&self) -> bool { self.b_offset.is_some() } + pub fn has_b(&self) -> bool { + self.b_offset.is_some() + } pub fn n(&self) -> roto_runtime::Result { - let offset = self.n_offset.ok_or(roto_runtime::RotoError::FieldNotFound)?; + let offset = self + .n_offset + .ok_or(roto_runtime::RotoError::FieldNotFound)?; let (bytes, _) = self.accessor.get_value_at(offset)?; - roto_runtime::read_varint(bytes).map(|(v, _)| v as i32).map_err(|_| roto_runtime::RotoError::WireFormatViolation) + roto_runtime::read_varint(bytes) + .map(|(v, _)| v as i32) + .map_err(|_| roto_runtime::RotoError::WireFormatViolation) } pub fn n_or_default(&self) -> roto_runtime::Result { self.n().or(Ok(0)) } - pub fn has_n(&self) -> bool { self.n_offset.is_some() } + pub fn has_n(&self) -> bool { + self.n_offset.is_some() + } pub fn l(&self) -> roto_runtime::Result { - let offset = self.l_offset.ok_or(roto_runtime::RotoError::FieldNotFound)?; + let offset = self + .l_offset + .ok_or(roto_runtime::RotoError::FieldNotFound)?; let (bytes, _) = self.accessor.get_value_at(offset)?; - roto_runtime::read_varint(bytes).map(|(v, _)| v as i32).map_err(|_| roto_runtime::RotoError::WireFormatViolation) + roto_runtime::read_varint(bytes) + .map(|(v, _)| v as i32) + .map_err(|_| roto_runtime::RotoError::WireFormatViolation) } pub fn l_or_default(&self) -> roto_runtime::Result { self.l().or(Ok(0)) } - pub fn has_l(&self) -> bool { self.l_offset.is_some() } + pub fn has_l(&self) -> bool { + self.l_offset.is_some() + } pub fn c1(&self) -> roto_runtime::Result<&'a str> { - let offset = self.c1_offset.ok_or(roto_runtime::RotoError::FieldNotFound)?; + let offset = self + .c1_offset + .ok_or(roto_runtime::RotoError::FieldNotFound)?; let (bytes, _) = self.accessor.get_value_at(offset)?; std::str::from_utf8(bytes).map_err(|_| roto_runtime::RotoError::WireFormatViolation) } @@ -157,19 +219,27 @@ pets_start, pets_end, self.c1().or(Ok("")) } - pub fn has_c1(&self) -> bool { self.c1_offset.is_some() } + pub fn has_c1(&self) -> bool { + self.c1_offset.is_some() + } pub fn c2(&self) -> roto_runtime::Result { - let offset = self.c2_offset.ok_or(roto_runtime::RotoError::FieldNotFound)?; + let offset = self + .c2_offset + .ok_or(roto_runtime::RotoError::FieldNotFound)?; let (bytes, _) = self.accessor.get_value_at(offset)?; - roto_runtime::read_varint(bytes).map(|(v, _)| v != 0).map_err(|_| roto_runtime::RotoError::WireFormatViolation) + roto_runtime::read_varint(bytes) + .map(|(v, _)| v != 0) + .map_err(|_| roto_runtime::RotoError::WireFormatViolation) } pub fn c2_or_default(&self) -> roto_runtime::Result { self.c2().or(Ok(false)) } - pub fn has_c2(&self) -> bool { self.c2_offset.is_some() } + pub fn has_c2(&self) -> bool { + self.c2_offset.is_some() + } pub fn pets(&self) -> roto_runtime::RepeatedFieldIterator<'a> { match (self.pets_start, self.pets_end) { @@ -178,12 +248,12 @@ pets_start, pets_end, } } - pub fn which_choice(&self) -> roto_runtime::Result> > { + pub fn which_choice(&self) -> roto_runtime::Result>> { if self.c1_offset.is_some() { - return Ok(Some(hello::Choice::c1 (self.c1()?))); + return Ok(Some(hello::Choice::c1(self.c1()?))); } if self.c2_offset.is_some() { - return Ok(Some(hello::Choice::c2 (self.c2()?))); + return Ok(Some(hello::Choice::c2(self.c2()?))); } Ok(None) } @@ -191,7 +261,6 @@ pets_start, pets_end, pub fn raw_fields(&self) -> roto_runtime::RawFieldIterator<'a> { self.accessor.raw_fields() } - } pub struct HelloBuilder<'b> { @@ -326,161 +395,172 @@ impl roto_runtime::RotoMessage for OwnedHello { } pub mod hello { -pub struct Pet<'a> { - accessor: roto_runtime::ProtoAccessor<'a>, - name_offset: Option, - color_offset: Option, -} + pub struct Pet<'a> { + accessor: roto_runtime::ProtoAccessor<'a>, + name_offset: Option, + color_offset: Option, + } -impl<'a> Pet<'a> { - pub fn new(data: &'a [u8]) -> roto_runtime::Result { - let accessor = roto_runtime::ProtoAccessor::new(data)?; - let mut name_offset = None; - let mut color_offset = None; - for item in accessor.fields() { - let (offset, tag, _) = item?; - if tag.field_number == 1 { name_offset = Some(offset); } - if tag.field_number == 2 { color_offset = Some(offset); } + impl<'a> Pet<'a> { + pub fn new(data: &'a [u8]) -> roto_runtime::Result { + let accessor = roto_runtime::ProtoAccessor::new(data)?; + let mut name_offset = None; + let mut color_offset = None; + for item in accessor.fields() { + let (offset, tag, _) = item?; + if tag.field_number == 1 { + name_offset = Some(offset); + } + if tag.field_number == 2 { + color_offset = Some(offset); + } + } + + Ok(Self { + accessor, + name_offset, + color_offset, + }) } - Ok(Self { - accessor, -name_offset, -color_offset, - }) - } + pub fn name(&self) -> roto_runtime::Result<&'a str> { + let offset = self + .name_offset + .ok_or(roto_runtime::RotoError::FieldNotFound)?; + let (bytes, _) = self.accessor.get_value_at(offset)?; + std::str::from_utf8(bytes).map_err(|_| roto_runtime::RotoError::WireFormatViolation) + } - pub fn name(&self) -> roto_runtime::Result<&'a str> { - let offset = self.name_offset.ok_or(roto_runtime::RotoError::FieldNotFound)?; - let (bytes, _) = self.accessor.get_value_at(offset)?; - std::str::from_utf8(bytes).map_err(|_| roto_runtime::RotoError::WireFormatViolation) - } + pub fn name_or_default(&self) -> roto_runtime::Result<&'a str> { + self.name().or(Ok("")) + } - pub fn name_or_default(&self) -> roto_runtime::Result<&'a str> { - self.name().or(Ok("")) - } + pub fn has_name(&self) -> bool { + self.name_offset.is_some() + } - pub fn has_name(&self) -> bool { self.name_offset.is_some() } + pub fn color(&self) -> roto_runtime::Result { + let offset = self + .color_offset + .ok_or(roto_runtime::RotoError::FieldNotFound)?; + let (bytes, _) = self.accessor.get_value_at(offset)?; + roto_runtime::read_varint(bytes) + .map(|(v, _)| v as u64) + .map_err(|_| roto_runtime::RotoError::WireFormatViolation) + } - pub fn color(&self) -> roto_runtime::Result { - let offset = self.color_offset.ok_or(roto_runtime::RotoError::FieldNotFound)?; - let (bytes, _) = self.accessor.get_value_at(offset)?; - roto_runtime::read_varint(bytes).map(|(v, _)| v as u64).map_err(|_| roto_runtime::RotoError::WireFormatViolation) - } + pub fn color_or_default(&self) -> roto_runtime::Result { + self.color().or(Ok(0)) + } - pub fn color_or_default(&self) -> roto_runtime::Result { - self.color().or(Ok(0)) - } + pub fn has_color(&self) -> bool { + self.color_offset.is_some() + } - pub fn has_color(&self) -> bool { self.color_offset.is_some() } - - pub fn raw_fields(&self) -> roto_runtime::RawFieldIterator<'a> { - self.accessor.raw_fields() - } - -} - -pub struct PetBuilder<'b> { - builder: roto_runtime::ProtoBuilder<'b>, - name_written: bool, - color_written: bool, -} - -impl<'b> PetBuilder<'b> { - pub fn builder(buf: &mut [u8]) -> PetBuilder<'_> { - PetBuilder { - builder: roto_runtime::ProtoBuilder::new(buf), - name_written: false, - color_written: false, + pub fn raw_fields(&self) -> roto_runtime::RawFieldIterator<'a> { + self.accessor.raw_fields() } } - pub fn name(mut self, value: &str) -> roto_runtime::Result { - self.builder.write_string(1, value)?; - self.name_written = true; - Ok(self) + pub struct PetBuilder<'b> { + builder: roto_runtime::ProtoBuilder<'b>, + name_written: bool, + color_written: bool, } - pub fn color(mut self, value: u64) -> roto_runtime::Result { - self.builder.write_varint(2, value)?; - self.color_written = true; - Ok(self) - } - - pub fn with(mut self, msg: &Pet<'_>) -> roto_runtime::Result { - for item in msg.accessor.raw_fields() { - let (field_number, raw_bytes) = item?; - let is_written = match field_number { - 1 => self.name_written, - 2 => self.color_written, - _ => false, - }; - if !is_written { - self.builder.write_raw(raw_bytes)?; + impl<'b> PetBuilder<'b> { + pub fn builder(buf: &mut [u8]) -> PetBuilder<'_> { + PetBuilder { + builder: roto_runtime::ProtoBuilder::new(buf), + name_written: false, + color_written: false, } } - Ok(self) - } - pub fn finish(self) -> roto_runtime::Result<&'b mut [u8]> { - self.builder.finish() - } -} + pub fn name(mut self, value: &str) -> roto_runtime::Result { + self.builder.write_string(1, value)?; + self.name_written = true; + Ok(self) + } -pub struct OwnedPet { - pub data: bytes::Bytes, -} + pub fn color(mut self, value: u64) -> roto_runtime::Result { + self.builder.write_varint(2, value)?; + self.color_written = true; + Ok(self) + } -impl roto_runtime::RotoOwned for OwnedPet { - type Reader<'a> = Pet<'a>; - fn reader(&self) -> Pet<'_> { - Pet::new(&self.data).expect("failed to create reader") - } -} + pub fn with(mut self, msg: &Pet<'_>) -> roto_runtime::Result { + for item in msg.accessor.raw_fields() { + let (field_number, raw_bytes) = item?; + let is_written = match field_number { + 1 => self.name_written, + 2 => self.color_written, + _ => false, + }; + if !is_written { + self.builder.write_raw(raw_bytes)?; + } + } + Ok(self) + } -impl roto_runtime::RotoMessage for OwnedPet { - fn decode(buf: bytes::Bytes) -> roto_runtime::Result { - Ok(OwnedPet { data: buf }) - } - - fn bytes(&self) -> bytes::Bytes { - self.data.clone() - } -} - -pub mod pet { -#[derive(Debug, Clone, Copy, PartialEq, Eq)] -#[repr(i32)] -pub enum Color { - BLACK = 0, - WHITE = 1, - BLUE = 2, - RED = 3, - YELLOW = 4, - GREEN = 5, -} - -impl Color { - pub fn from_i32(value: i32) -> Self { - match value { - 0 => Color::BLACK, - 1 => Color::WHITE, - 2 => Color::BLUE, - 3 => Color::RED, - 4 => Color::YELLOW, - 5 => Color::GREEN, - _ => Color::BLACK, + pub fn finish(self) -> roto_runtime::Result<&'b mut [u8]> { + self.builder.finish() } } -} -} + pub struct OwnedPet { + pub data: bytes::Bytes, + } -pub enum Choice<'a> { - c1(&'a str), - c2(bool), -} + impl roto_runtime::RotoOwned for OwnedPet { + type Reader<'a> = Pet<'a>; + fn reader(&self) -> Pet<'_> { + Pet::new(&self.data).expect("failed to create reader") + } + } + impl roto_runtime::RotoMessage for OwnedPet { + fn decode(buf: bytes::Bytes) -> roto_runtime::Result { + Ok(OwnedPet { data: buf }) + } + + fn bytes(&self) -> bytes::Bytes { + self.data.clone() + } + } + + pub mod pet { + #[derive(Debug, Clone, Copy, PartialEq, Eq)] + #[repr(i32)] + pub enum Color { + BLACK = 0, + WHITE = 1, + BLUE = 2, + RED = 3, + YELLOW = 4, + GREEN = 5, + } + + impl Color { + pub fn from_i32(value: i32) -> Self { + match value { + 0 => Color::BLACK, + 1 => Color::WHITE, + 2 => Color::BLUE, + 3 => Color::RED, + 4 => Color::YELLOW, + 5 => Color::GREEN, + _ => Color::BLACK, + } + } + } + } + + pub enum Choice<'a> { + c1(&'a str), + c2(bool), + } } pub struct HelloRequest<'a> { @@ -494,17 +574,21 @@ impl<'a> HelloRequest<'a> { let mut request_offset = None; for item in accessor.fields() { let (offset, tag, _) = item?; - if tag.field_number == 1 { request_offset = Some(offset); } + if tag.field_number == 1 { + request_offset = Some(offset); + } } Ok(Self { accessor, -request_offset, + request_offset, }) } pub fn request(&self) -> roto_runtime::Result<&'a [u8]> { - let offset = self.request_offset.ok_or(roto_runtime::RotoError::FieldNotFound)?; + let offset = self + .request_offset + .ok_or(roto_runtime::RotoError::FieldNotFound)?; let (bytes, _) = self.accessor.get_value_at(offset)?; Ok(bytes) } @@ -513,12 +597,13 @@ request_offset, self.request().or(Ok(&[])) } - pub fn has_request(&self) -> bool { self.request_offset.is_some() } + pub fn has_request(&self) -> bool { + self.request_offset.is_some() + } pub fn raw_fields(&self) -> roto_runtime::RawFieldIterator<'a> { self.accessor.raw_fields() } - } pub struct HelloRequestBuilder<'b> { @@ -591,17 +676,21 @@ impl<'a> HelloReply<'a> { let mut response_offset = None; for item in accessor.fields() { let (offset, tag, _) = item?; - if tag.field_number == 1 { response_offset = Some(offset); } + if tag.field_number == 1 { + response_offset = Some(offset); + } } Ok(Self { accessor, -response_offset, + response_offset, }) } pub fn response(&self) -> roto_runtime::Result<&'a [u8]> { - let offset = self.response_offset.ok_or(roto_runtime::RotoError::FieldNotFound)?; + let offset = self + .response_offset + .ok_or(roto_runtime::RotoError::FieldNotFound)?; let (bytes, _) = self.accessor.get_value_at(offset)?; Ok(bytes) } @@ -610,12 +699,13 @@ response_offset, self.response().or(Ok(&[])) } - pub fn has_response(&self) -> bool { self.response_offset.is_some() } + pub fn has_response(&self) -> bool { + self.response_offset.is_some() + } pub fn raw_fields(&self) -> roto_runtime::RawFieldIterator<'a> { self.accessor.raw_fields() } - } pub struct HelloReplyBuilder<'b> { @@ -679,7 +769,10 @@ impl roto_runtime::RotoMessage for OwnedHelloReply { #[tonic::async_trait] pub trait Greeter: Send + Sync + 'static { - async fn say_hello(&self, request: Request) -> std::result::Result, Status>; + async fn say_hello( + &self, + request: Request, + ) -> std::result::Result, Status>; } #[derive(Clone)] @@ -701,7 +794,8 @@ impl tonic::server::NamedService for GreeterServer { impl Service> for GreeterServer { type Response = http::Response; type Error = std::convert::Infallible; - type Future = Pin> + Send>>; + type Future = + Pin> + Send>>; fn poll_ready(&mut self, _: &mut Context<'_>) -> Poll> { Poll::Ready(Ok(())) @@ -726,8 +820,14 @@ impl Service> for GreeterServer { let bytes_vec = buf.split_to(total_len).freeze(); pool.put(buf); if bytes_vec.len() < 5 { - let res_body = BoxBody::new(StatusBody::new(Some(Bytes::from_static(&[0, 0, 0, 0, 0])), 0)); - return Ok(http::Response::builder().status(200).body(res_body).unwrap()); + let res_body = BoxBody::new(StatusBody::new( + Some(Bytes::from_static(&[0, 0, 0, 0, 0])), + 0, + )); + return Ok(http::Response::builder() + .status(200) + .body(res_body) + .unwrap()); } let payload = bytes_vec.slice(5..); @@ -737,16 +837,28 @@ impl Service> for GreeterServer { let request_msg = match OwnedHelloRequest::decode(payload) { Ok(msg) => msg, Err(e) => { - let res_body = BoxBody::new(StatusBody::new(Some(Bytes::from_static(&[0, 0, 0, 0, 0])), 0)); - return Ok(http::Response::builder().status(200).body(res_body).unwrap()); + let res_body = BoxBody::new(StatusBody::new( + Some(Bytes::from_static(&[0, 0, 0, 0, 0])), + 0, + )); + return Ok(http::Response::builder() + .status(200) + .body(res_body) + .unwrap()); } }; let response = match inner.say_hello(Request::new(request_msg)).await { Ok(res) => res, Err(e) => { - let res_body = BoxBody::new(StatusBody::new(Some(Bytes::from_static(&[0, 0, 0, 0, 0])), 0)); - return Ok(http::Response::builder().status(200).body(res_body).unwrap()); + let res_body = BoxBody::new(StatusBody::new( + Some(Bytes::from_static(&[0, 0, 0, 0, 0])), + 0, + )); + return Ok(http::Response::builder() + .status(200) + .body(res_body) + .unwrap()); } }; @@ -762,13 +874,26 @@ impl Service> for GreeterServer { pool.put(res_buf); let res_body = BoxBody::new(StatusBody::new(Some(frame), 0)); routed = true; - return Ok(http::Response::builder().status(200).header("content-type", "application/grpc").body(res_body).unwrap()); + return Ok(http::Response::builder() + .status(200) + .header("content-type", "application/grpc") + .body(res_body) + .unwrap()); } if !routed { - let res_body = BoxBody::new(StatusBody::new(Some(Bytes::from_static(&[0, 0, 0, 0, 0])), 0)); - return Ok(http::Response::builder().status(200).body(res_body).unwrap()); + let res_body = BoxBody::new(StatusBody::new( + Some(Bytes::from_static(&[0, 0, 0, 0, 0])), + 0, + )); + return Ok(http::Response::builder() + .status(200) + .body(res_body) + .unwrap()); } - Ok(http::Response::builder().status(200).body(BoxBody::new(StatusBody::new(None, 0))).unwrap()) + Ok(http::Response::builder() + .status(200) + .body(BoxBody::new(StatusBody::new(None, 0))) + .unwrap()) }) } } diff --git a/roto-tonic/src/generated/interop.rs b/roto-tonic/src/generated/interop.rs index fe94017..04ef6f4 100644 --- a/roto-tonic/src/generated/interop.rs +++ b/roto-tonic/src/generated/interop.rs @@ -1,5 +1,5 @@ // @generated by protoc-gen-roto — do not edit -#![allow(unused)] +#[allow(unused, unused_imports, unused_assignments, unused_variables, non_camel_case_types)] use roto_runtime::{ProtoAccessor, ProtoBuilder, Result, RotoError, read_varint, RepeatedFieldIterator, RotoMessage}; use core::str; use bytes::{Bytes, BytesMut, Buf, BufMut}; @@ -394,6 +394,7 @@ impl roto_runtime::RotoMessage for OwnedStreamingResponse { +#[allow(unused, unused_imports, unused_assignments, unused_variables, non_camel_case_types)] use tonic::{Request, Response, Status}; use tokio_stream::Stream; use std::pin::Pin; @@ -462,12 +463,12 @@ impl Service> for InteropServiceServer { } let payload = bytes_vec.slice(5..); + #[allow(unused_assignments)] let mut routed = false; - if path == "/interop.InteropService/UnaryCall" { let request_msg = match OwnedUnaryRequest::decode(payload) { Ok(msg) => msg, - Err(e) => { + Err(_e) => { let res_body = BoxBody::new(StatusBody::new(Some(Bytes::from_static(&[0, 0, 0, 0, 0])), 0)); return Ok(http::Response::builder().status(200).body(res_body).unwrap()); } @@ -475,7 +476,7 @@ impl Service> for InteropServiceServer { let response = match inner.unary_call(Request::new(request_msg)).await { Ok(res) => res, - Err(e) => { + Err(_e) => { let res_body = BoxBody::new(StatusBody::new(Some(Bytes::from_static(&[0, 0, 0, 0, 0])), 0)); return Ok(http::Response::builder().status(200).body(res_body).unwrap()); }