diff --git a/src/google/mod.rs b/src/google/mod.rs new file mode 100644 index 0000000..91e4166 --- /dev/null +++ b/src/google/mod.rs @@ -0,0 +1 @@ +pub mod protobuf; diff --git a/src/google/protobuf/compiler/mod.rs b/src/google/protobuf/compiler/mod.rs new file mode 100644 index 0000000..962cb1b --- /dev/null +++ b/src/google/protobuf/compiler/mod.rs @@ -0,0 +1 @@ +pub mod plugin; diff --git a/src/google/protobuf/compiler/plugin.rs b/src/google/protobuf/compiler/plugin.rs new file mode 100644 index 0000000..d18f794 --- /dev/null +++ b/src/google/protobuf/compiler/plugin.rs @@ -0,0 +1,457 @@ +use crate::{ProtoAccessor, ProtoBuilder, Result, RotoError, read_varint, RepeatedFieldIterator}; +use std::str; + +use crate::google::protobuf::descriptor; + +pub struct Version<'a> { + accessor: crate::ProtoAccessor<'a>, + major_offset: Option, + minor_offset: Option, + patch_offset: Option, + suffix_offset: Option, +} + +impl<'a> Version<'a> { + pub fn new(data: &'a [u8]) -> crate::Result { + let accessor = crate::ProtoAccessor::new(data)?; + let mut major_offset = None; + let mut minor_offset = None; + let mut patch_offset = None; + let mut suffix_offset = None; + for item in accessor.fields() { + let (offset, tag, _) = item?; + if tag.field_number == 1 { major_offset = Some(offset); } + if tag.field_number == 2 { minor_offset = Some(offset); } + if tag.field_number == 3 { patch_offset = Some(offset); } + if tag.field_number == 4 { suffix_offset = Some(offset); } + } + + Ok(Self { + accessor, +major_offset, +minor_offset, +patch_offset, +suffix_offset, + }) + } + + pub fn major(&self) -> crate::Result { + let offset = self.major_offset.ok_or(crate::RotoError::FieldNotFound)?; + let (bytes, _) = self.accessor.get_value_at(offset)?; + crate::read_varint(bytes).map(|(v, _)| v as i32).map_err(|_| crate::RotoError::WireFormatViolation) + } + + pub fn minor(&self) -> crate::Result { + let offset = self.minor_offset.ok_or(crate::RotoError::FieldNotFound)?; + let (bytes, _) = self.accessor.get_value_at(offset)?; + crate::read_varint(bytes).map(|(v, _)| v as i32).map_err(|_| crate::RotoError::WireFormatViolation) + } + + pub fn patch(&self) -> crate::Result { + let offset = self.patch_offset.ok_or(crate::RotoError::FieldNotFound)?; + let (bytes, _) = self.accessor.get_value_at(offset)?; + crate::read_varint(bytes).map(|(v, _)| v as i32).map_err(|_| crate::RotoError::WireFormatViolation) + } + + pub fn suffix(&self) -> crate::Result<&'a str> { + let offset = self.suffix_offset.ok_or(crate::RotoError::FieldNotFound)?; + let (bytes, _) = self.accessor.get_value_at(offset)?; + str::from_utf8(bytes).map_err(|_| crate::RotoError::WireFormatViolation) + } + +} + +pub struct VersionBuilder<'b> { + builder: crate::ProtoBuilder<'b>, +} + +impl<'b> VersionBuilder<'b> { + pub fn builder(buf: &mut [u8]) -> VersionBuilder<'_> { + VersionBuilder { + builder: crate::ProtoBuilder::new(buf), + } + } + + pub fn major(mut self, value: i32) -> crate::Result { + self.builder.write_int32(1, value)?; + Ok(self) + } + + pub fn minor(mut self, value: i32) -> crate::Result { + self.builder.write_int32(2, value)?; + Ok(self) + } + + pub fn patch(mut self, value: i32) -> crate::Result { + self.builder.write_int32(3, value)?; + Ok(self) + } + + pub fn suffix(mut self, value: &str) -> crate::Result { + self.builder.write_string(4, value)?; + Ok(self) + } + + pub fn finish(self) -> crate::Result<&'b mut [u8]> { + self.builder.finish() + } +} + +pub struct CodeGeneratorRequest<'a> { + accessor: crate::ProtoAccessor<'a>, + file_to_generate_start: Option, + file_to_generate_end: Option, + parameter_offset: Option, + proto_file_start: Option, + proto_file_end: Option, + source_file_descriptors_start: Option, + source_file_descriptors_end: Option, + compiler_version_offset: Option, +} + +impl<'a> CodeGeneratorRequest<'a> { + pub fn new(data: &'a [u8]) -> crate::Result { + let accessor = crate::ProtoAccessor::new(data)?; + let mut file_to_generate_start = None; + let mut file_to_generate_end = None; + let mut parameter_offset = None; + let mut proto_file_start = None; + let mut proto_file_end = None; + let mut source_file_descriptors_start = None; + let mut source_file_descriptors_end = None; + let mut compiler_version_offset = None; + for item in accessor.fields() { + let (offset, tag, _) = item?; + if tag.field_number == 1 { + if file_to_generate_start.is_none() { file_to_generate_start = Some(offset); } + file_to_generate_end = Some(offset); + } + if tag.field_number == 2 { parameter_offset = Some(offset); } + if tag.field_number == 15 { + if proto_file_start.is_none() { proto_file_start = Some(offset); } + proto_file_end = Some(offset); + } + if tag.field_number == 17 { + if source_file_descriptors_start.is_none() { source_file_descriptors_start = Some(offset); } + source_file_descriptors_end = Some(offset); + } + if tag.field_number == 3 { compiler_version_offset = Some(offset); } + } + + Ok(Self { + accessor, +file_to_generate_start, file_to_generate_end, +parameter_offset, +proto_file_start, proto_file_end, +source_file_descriptors_start, source_file_descriptors_end, +compiler_version_offset, + }) + } + + pub fn file_to_generate(&self) -> crate::RepeatedFieldIterator<'a> { + match (self.file_to_generate_start, self.file_to_generate_end) { + (Some(start), Some(end)) => self.accessor.iter_repeated_range(1, start, end), + _ => self.accessor.iter_repeated(1), + } + } + + pub fn parameter(&self) -> crate::Result<&'a str> { + let offset = self.parameter_offset.ok_or(crate::RotoError::FieldNotFound)?; + let (bytes, _) = self.accessor.get_value_at(offset)?; + str::from_utf8(bytes).map_err(|_| crate::RotoError::WireFormatViolation) + } + + pub fn proto_file(&self) -> crate::RepeatedFieldIterator<'a> { + match (self.proto_file_start, self.proto_file_end) { + (Some(start), Some(end)) => self.accessor.iter_repeated_range(15, start, end), + _ => self.accessor.iter_repeated(15), + } + } + + pub fn source_file_descriptors(&self) -> crate::RepeatedFieldIterator<'a> { + match (self.source_file_descriptors_start, self.source_file_descriptors_end) { + (Some(start), Some(end)) => self.accessor.iter_repeated_range(17, start, end), + _ => self.accessor.iter_repeated(17), + } + } + + pub fn compiler_version(&self) -> crate::Result<&'a [u8]> { + let offset = self.compiler_version_offset.ok_or(crate::RotoError::FieldNotFound)?; + let (bytes, _) = self.accessor.get_value_at(offset)?; + Ok(bytes) + } + +} + +pub struct CodeGeneratorRequestBuilder<'b> { + builder: crate::ProtoBuilder<'b>, +} + +impl<'b> CodeGeneratorRequestBuilder<'b> { + pub fn builder(buf: &mut [u8]) -> CodeGeneratorRequestBuilder<'_> { + CodeGeneratorRequestBuilder { + builder: crate::ProtoBuilder::new(buf), + } + } + + pub fn file_to_generate(mut self, value: &str) -> crate::Result { + self.builder.write_string(1, value)?; + Ok(self) + } + + pub fn parameter(mut self, value: &str) -> crate::Result { + self.builder.write_string(2, value)?; + Ok(self) + } + + pub fn proto_file(mut self, value: &[u8]) -> crate::Result { + self.builder.write_bytes(15, value)?; + Ok(self) + } + + pub fn source_file_descriptors(mut self, value: &[u8]) -> crate::Result { + self.builder.write_bytes(17, value)?; + Ok(self) + } + + pub fn compiler_version(mut self, value: &[u8]) -> crate::Result { + self.builder.write_bytes(3, value)?; + Ok(self) + } + + pub fn finish(self) -> crate::Result<&'b mut [u8]> { + self.builder.finish() + } +} + +pub struct CodeGeneratorResponse<'a> { + accessor: crate::ProtoAccessor<'a>, + error_offset: Option, + supported_features_offset: Option, + minimum_edition_offset: Option, + maximum_edition_offset: Option, + file_start: Option, + file_end: Option, +} + +impl<'a> CodeGeneratorResponse<'a> { + pub fn new(data: &'a [u8]) -> crate::Result { + let accessor = crate::ProtoAccessor::new(data)?; + let mut error_offset = None; + let mut supported_features_offset = None; + let mut minimum_edition_offset = None; + let mut maximum_edition_offset = None; + let mut file_start = None; + let mut file_end = None; + for item in accessor.fields() { + let (offset, tag, _) = item?; + if tag.field_number == 1 { error_offset = Some(offset); } + if tag.field_number == 2 { supported_features_offset = Some(offset); } + if tag.field_number == 3 { minimum_edition_offset = Some(offset); } + if tag.field_number == 4 { maximum_edition_offset = Some(offset); } + if tag.field_number == 15 { + if file_start.is_none() { file_start = Some(offset); } + file_end = Some(offset); + } + } + + Ok(Self { + accessor, +error_offset, +supported_features_offset, +minimum_edition_offset, +maximum_edition_offset, +file_start, file_end, + }) + } + + pub fn error(&self) -> crate::Result<&'a str> { + let offset = self.error_offset.ok_or(crate::RotoError::FieldNotFound)?; + let (bytes, _) = self.accessor.get_value_at(offset)?; + str::from_utf8(bytes).map_err(|_| crate::RotoError::WireFormatViolation) + } + + pub fn supported_features(&self) -> crate::Result { + let offset = self.supported_features_offset.ok_or(crate::RotoError::FieldNotFound)?; + let (bytes, _) = self.accessor.get_value_at(offset)?; + crate::read_varint(bytes).map(|(v, _)| v as u32).map_err(|_| crate::RotoError::WireFormatViolation) + } + + pub fn minimum_edition(&self) -> crate::Result { + let offset = self.minimum_edition_offset.ok_or(crate::RotoError::FieldNotFound)?; + let (bytes, _) = self.accessor.get_value_at(offset)?; + crate::read_varint(bytes).map(|(v, _)| v as i32).map_err(|_| crate::RotoError::WireFormatViolation) + } + + pub fn maximum_edition(&self) -> crate::Result { + let offset = self.maximum_edition_offset.ok_or(crate::RotoError::FieldNotFound)?; + let (bytes, _) = self.accessor.get_value_at(offset)?; + crate::read_varint(bytes).map(|(v, _)| v as i32).map_err(|_| crate::RotoError::WireFormatViolation) + } + + pub fn file(&self) -> crate::RepeatedFieldIterator<'a> { + match (self.file_start, self.file_end) { + (Some(start), Some(end)) => self.accessor.iter_repeated_range(15, start, end), + _ => self.accessor.iter_repeated(15), + } + } + +} + +pub struct CodeGeneratorResponseBuilder<'b> { + builder: crate::ProtoBuilder<'b>, +} + +impl<'b> CodeGeneratorResponseBuilder<'b> { + pub fn builder(buf: &mut [u8]) -> CodeGeneratorResponseBuilder<'_> { + CodeGeneratorResponseBuilder { + builder: crate::ProtoBuilder::new(buf), + } + } + + pub fn error(mut self, value: &str) -> crate::Result { + self.builder.write_string(1, value)?; + Ok(self) + } + + pub fn supported_features(mut self, value: u64) -> crate::Result { + self.builder.write_varint(2, value)?; + Ok(self) + } + + pub fn minimum_edition(mut self, value: i32) -> crate::Result { + self.builder.write_int32(3, value)?; + Ok(self) + } + + pub fn maximum_edition(mut self, value: i32) -> crate::Result { + self.builder.write_int32(4, value)?; + Ok(self) + } + + pub fn file(mut self, value: &[u8]) -> crate::Result { + self.builder.write_bytes(15, value)?; + Ok(self) + } + + pub fn finish(self) -> crate::Result<&'b mut [u8]> { + self.builder.finish() + } +} + +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::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::Result { + let accessor = crate::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::Result<&'a str> { + let offset = self.name_offset.ok_or(crate::RotoError::FieldNotFound)?; + let (bytes, _) = self.accessor.get_value_at(offset)?; + str::from_utf8(bytes).map_err(|_| crate::RotoError::WireFormatViolation) + } + + pub fn insertion_point(&self) -> crate::Result<&'a str> { + let offset = self.insertion_point_offset.ok_or(crate::RotoError::FieldNotFound)?; + let (bytes, _) = self.accessor.get_value_at(offset)?; + str::from_utf8(bytes).map_err(|_| crate::RotoError::WireFormatViolation) + } + + pub fn content(&self) -> crate::Result<&'a str> { + let offset = self.content_offset.ok_or(crate::RotoError::FieldNotFound)?; + let (bytes, _) = self.accessor.get_value_at(offset)?; + str::from_utf8(bytes).map_err(|_| crate::RotoError::WireFormatViolation) + } + + pub fn generated_code_info(&self) -> crate::Result<&'a [u8]> { + let offset = self.generated_code_info_offset.ok_or(crate::RotoError::FieldNotFound)?; + let (bytes, _) = self.accessor.get_value_at(offset)?; + Ok(bytes) + } + +} + +pub struct FileBuilder<'b> { + builder: crate::ProtoBuilder<'b>, +} + +impl<'b> FileBuilder<'b> { + pub fn builder(buf: &mut [u8]) -> FileBuilder<'_> { + FileBuilder { + builder: crate::ProtoBuilder::new(buf), + } + } + + pub fn name(mut self, value: &str) -> crate::Result { + self.builder.write_string(1, value)?; + Ok(self) + } + + pub fn insertion_point(mut self, value: &str) -> crate::Result { + self.builder.write_string(2, value)?; + Ok(self) + } + + pub fn content(mut self, value: &str) -> crate::Result { + self.builder.write_string(15, value)?; + Ok(self) + } + + pub fn generated_code_info(mut self, value: &[u8]) -> crate::Result { + self.builder.write_bytes(16, value)?; + Ok(self) + } + + pub fn finish(self) -> crate::Result<&'b mut [u8]> { + self.builder.finish() + } +} + +} + diff --git a/src/google/protobuf/descriptor.rs b/src/google/protobuf/descriptor.rs new file mode 100644 index 0000000..e194965 --- /dev/null +++ b/src/google/protobuf/descriptor.rs @@ -0,0 +1,4614 @@ +use crate::{ProtoAccessor, ProtoBuilder, Result, RotoError, read_varint, RepeatedFieldIterator}; +use std::str; + + +#[derive(Debug, Clone, Copy, PartialEq, Eq)] +#[repr(i32)] +pub enum Edition { + EDITIONUNKNOWN = 0, + EDITIONLEGACY = 900, + EDITIONPROTO2 = 998, + EDITIONPROTO3 = 999, + EDITION2023 = 1000, + EDITION2024 = 1001, + EDITION2026 = 1002, + EDITIONUNSTABLE = 9999, + EDITION1TESTONLY = 1, + EDITION2TESTONLY = 2, + EDITION99997TESTONLY = 99997, + EDITION99998TESTONLY = 99998, + EDITION99999TESTONLY = 99999, + EDITIONMAX = 2147483647, +} + +impl Edition { + pub fn from_i32(value: i32) -> Self { + match value { + 0 => Edition::EDITIONUNKNOWN, + 900 => Edition::EDITIONLEGACY, + 998 => Edition::EDITIONPROTO2, + 999 => Edition::EDITIONPROTO3, + 1000 => Edition::EDITION2023, + 1001 => Edition::EDITION2024, + 1002 => Edition::EDITION2026, + 9999 => Edition::EDITIONUNSTABLE, + 1 => Edition::EDITION1TESTONLY, + 2 => Edition::EDITION2TESTONLY, + 99997 => Edition::EDITION99997TESTONLY, + 99998 => Edition::EDITION99998TESTONLY, + 99999 => Edition::EDITION99999TESTONLY, + 2147483647 => Edition::EDITIONMAX, + _ => Edition::EDITIONUNKNOWN, + } + } +} + +#[derive(Debug, Clone, Copy, PartialEq, Eq)] +#[repr(i32)] +pub enum SymbolVisibility { + VISIBILITYUNSET = 0, + VISIBILITYLOCAL = 1, + VISIBILITYEXPORT = 2, +} + +impl SymbolVisibility { + pub fn from_i32(value: i32) -> Self { + match value { + 0 => SymbolVisibility::VISIBILITYUNSET, + 1 => SymbolVisibility::VISIBILITYLOCAL, + 2 => SymbolVisibility::VISIBILITYEXPORT, + _ => SymbolVisibility::VISIBILITYUNSET, + } + } +} + +pub struct FileDescriptorSet<'a> { + accessor: crate::ProtoAccessor<'a>, + file_start: Option, + file_end: Option, +} + +impl<'a> FileDescriptorSet<'a> { + pub fn new(data: &'a [u8]) -> crate::Result { + let accessor = crate::ProtoAccessor::new(data)?; + let mut file_start = None; + let mut file_end = None; + for item in accessor.fields() { + let (offset, tag, _) = item?; + if tag.field_number == 1 { + if file_start.is_none() { file_start = Some(offset); } + file_end = Some(offset); + } + } + + Ok(Self { + accessor, +file_start, file_end, + }) + } + + pub fn file(&self) -> crate::RepeatedFieldIterator<'a> { + match (self.file_start, self.file_end) { + (Some(start), Some(end)) => self.accessor.iter_repeated_range(1, start, end), + _ => self.accessor.iter_repeated(1), + } + } + +} + +pub struct FileDescriptorSetBuilder<'b> { + builder: crate::ProtoBuilder<'b>, +} + +impl<'b> FileDescriptorSetBuilder<'b> { + pub fn builder(buf: &mut [u8]) -> FileDescriptorSetBuilder<'_> { + FileDescriptorSetBuilder { + builder: crate::ProtoBuilder::new(buf), + } + } + + pub fn file(mut self, value: &[u8]) -> crate::Result { + self.builder.write_bytes(1, value)?; + Ok(self) + } + + pub fn finish(self) -> crate::Result<&'b mut [u8]> { + self.builder.finish() + } +} + +pub struct FileDescriptorProto<'a> { + accessor: crate::ProtoAccessor<'a>, + name_offset: Option, + package_offset: Option, + dependency_start: Option, + dependency_end: Option, + public_dependency_start: Option, + public_dependency_end: Option, + weak_dependency_start: Option, + weak_dependency_end: Option, + option_dependency_start: Option, + option_dependency_end: Option, + message_type_start: Option, + message_type_end: Option, + enum_type_start: Option, + enum_type_end: Option, + service_start: Option, + service_end: Option, + extension_start: Option, + extension_end: Option, + options_offset: Option, + source_code_info_offset: Option, + syntax_offset: Option, + edition_offset: Option, +} + +impl<'a> FileDescriptorProto<'a> { + pub fn new(data: &'a [u8]) -> crate::Result { + let accessor = crate::ProtoAccessor::new(data)?; + let mut name_offset = None; + let mut package_offset = None; + let mut dependency_start = None; + let mut dependency_end = None; + let mut public_dependency_start = None; + let mut public_dependency_end = None; + let mut weak_dependency_start = None; + let mut weak_dependency_end = None; + let mut option_dependency_start = None; + let mut option_dependency_end = None; + let mut message_type_start = None; + let mut message_type_end = None; + let mut enum_type_start = None; + let mut enum_type_end = None; + let mut service_start = None; + let mut service_end = None; + let mut extension_start = None; + let mut extension_end = None; + let mut options_offset = None; + let mut source_code_info_offset = None; + let mut syntax_offset = None; + 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 == 3 { + 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); } + public_dependency_end = Some(offset); + } + if tag.field_number == 11 { + 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); } + option_dependency_end = Some(offset); + } + if tag.field_number == 4 { + 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); } + enum_type_end = Some(offset); + } + if tag.field_number == 6 { + 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); } + 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); } + } + + 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, + }) + } + + pub fn name(&self) -> crate::Result<&'a str> { + let offset = self.name_offset.ok_or(crate::RotoError::FieldNotFound)?; + let (bytes, _) = self.accessor.get_value_at(offset)?; + str::from_utf8(bytes).map_err(|_| crate::RotoError::WireFormatViolation) + } + + pub fn package(&self) -> crate::Result<&'a str> { + let offset = self.package_offset.ok_or(crate::RotoError::FieldNotFound)?; + let (bytes, _) = self.accessor.get_value_at(offset)?; + str::from_utf8(bytes).map_err(|_| crate::RotoError::WireFormatViolation) + } + + pub fn dependency(&self) -> crate::RepeatedFieldIterator<'a> { + match (self.dependency_start, self.dependency_end) { + (Some(start), Some(end)) => self.accessor.iter_repeated_range(3, start, end), + _ => self.accessor.iter_repeated(3), + } + } + + pub fn public_dependency(&self) -> crate::RepeatedFieldIterator<'a> { + match (self.public_dependency_start, self.public_dependency_end) { + (Some(start), Some(end)) => self.accessor.iter_repeated_range(10, start, end), + _ => self.accessor.iter_repeated(10), + } + } + + pub fn weak_dependency(&self) -> crate::RepeatedFieldIterator<'a> { + match (self.weak_dependency_start, self.weak_dependency_end) { + (Some(start), Some(end)) => self.accessor.iter_repeated_range(11, start, end), + _ => self.accessor.iter_repeated(11), + } + } + + pub fn option_dependency(&self) -> crate::RepeatedFieldIterator<'a> { + match (self.option_dependency_start, self.option_dependency_end) { + (Some(start), Some(end)) => self.accessor.iter_repeated_range(15, start, end), + _ => self.accessor.iter_repeated(15), + } + } + + pub fn message_type(&self) -> crate::RepeatedFieldIterator<'a> { + match (self.message_type_start, self.message_type_end) { + (Some(start), Some(end)) => self.accessor.iter_repeated_range(4, start, end), + _ => self.accessor.iter_repeated(4), + } + } + + pub fn enum_type(&self) -> crate::RepeatedFieldIterator<'a> { + match (self.enum_type_start, self.enum_type_end) { + (Some(start), Some(end)) => self.accessor.iter_repeated_range(5, start, end), + _ => self.accessor.iter_repeated(5), + } + } + + pub fn service(&self) -> crate::RepeatedFieldIterator<'a> { + match (self.service_start, self.service_end) { + (Some(start), Some(end)) => self.accessor.iter_repeated_range(6, start, end), + _ => self.accessor.iter_repeated(6), + } + } + + pub fn extension(&self) -> crate::RepeatedFieldIterator<'a> { + match (self.extension_start, self.extension_end) { + (Some(start), Some(end)) => self.accessor.iter_repeated_range(7, start, end), + _ => self.accessor.iter_repeated(7), + } + } + + pub fn options(&self) -> crate::Result<&'a [u8]> { + let offset = self.options_offset.ok_or(crate::RotoError::FieldNotFound)?; + let (bytes, _) = self.accessor.get_value_at(offset)?; + Ok(bytes) + } + + pub fn source_code_info(&self) -> crate::Result<&'a [u8]> { + let offset = self.source_code_info_offset.ok_or(crate::RotoError::FieldNotFound)?; + let (bytes, _) = self.accessor.get_value_at(offset)?; + Ok(bytes) + } + + pub fn syntax(&self) -> crate::Result<&'a str> { + let offset = self.syntax_offset.ok_or(crate::RotoError::FieldNotFound)?; + let (bytes, _) = self.accessor.get_value_at(offset)?; + str::from_utf8(bytes).map_err(|_| crate::RotoError::WireFormatViolation) + } + + pub fn edition(&self) -> crate::Result { + let offset = self.edition_offset.ok_or(crate::RotoError::FieldNotFound)?; + let (bytes, _) = self.accessor.get_value_at(offset)?; + crate::read_varint(bytes).map(|(v, _)| v as u64).map_err(|_| crate::RotoError::WireFormatViolation) + } + +} + +pub struct FileDescriptorProtoBuilder<'b> { + builder: crate::ProtoBuilder<'b>, +} + +impl<'b> FileDescriptorProtoBuilder<'b> { + pub fn builder(buf: &mut [u8]) -> FileDescriptorProtoBuilder<'_> { + FileDescriptorProtoBuilder { + builder: crate::ProtoBuilder::new(buf), + } + } + + pub fn name(mut self, value: &str) -> crate::Result { + self.builder.write_string(1, value)?; + Ok(self) + } + + pub fn package(mut self, value: &str) -> crate::Result { + self.builder.write_string(2, value)?; + Ok(self) + } + + pub fn dependency(mut self, value: &str) -> crate::Result { + self.builder.write_string(3, value)?; + Ok(self) + } + + pub fn public_dependency(mut self, value: i32) -> crate::Result { + self.builder.write_int32(10, value)?; + Ok(self) + } + + pub fn weak_dependency(mut self, value: i32) -> crate::Result { + self.builder.write_int32(11, value)?; + Ok(self) + } + + pub fn option_dependency(mut self, value: &str) -> crate::Result { + self.builder.write_string(15, value)?; + Ok(self) + } + + pub fn message_type(mut self, value: &[u8]) -> crate::Result { + self.builder.write_bytes(4, value)?; + Ok(self) + } + + pub fn enum_type(mut self, value: &[u8]) -> crate::Result { + self.builder.write_bytes(5, value)?; + Ok(self) + } + + pub fn service(mut self, value: &[u8]) -> crate::Result { + self.builder.write_bytes(6, value)?; + Ok(self) + } + + pub fn extension(mut self, value: &[u8]) -> crate::Result { + self.builder.write_bytes(7, value)?; + Ok(self) + } + + pub fn options(mut self, value: &[u8]) -> crate::Result { + self.builder.write_bytes(8, value)?; + Ok(self) + } + + pub fn source_code_info(mut self, value: &[u8]) -> crate::Result { + self.builder.write_bytes(9, value)?; + Ok(self) + } + + pub fn syntax(mut self, value: &str) -> crate::Result { + self.builder.write_string(12, value)?; + Ok(self) + } + + pub fn edition(mut self, value: u64) -> crate::Result { + self.builder.write_varint(14, value)?; + Ok(self) + } + + pub fn finish(self) -> crate::Result<&'b mut [u8]> { + self.builder.finish() + } +} + +pub struct DescriptorProto<'a> { + accessor: crate::ProtoAccessor<'a>, + name_offset: Option, + field_start: Option, + field_end: Option, + extension_start: Option, + extension_end: Option, + nested_type_start: Option, + nested_type_end: Option, + enum_type_start: Option, + enum_type_end: Option, + extension_range_start: Option, + extension_range_end: Option, + oneof_decl_start: Option, + oneof_decl_end: Option, + options_offset: Option, + reserved_range_start: Option, + reserved_range_end: Option, + reserved_name_start: Option, + reserved_name_end: Option, + visibility_offset: Option, +} + +impl<'a> DescriptorProto<'a> { + pub fn new(data: &'a [u8]) -> crate::Result { + let accessor = crate::ProtoAccessor::new(data)?; + let mut name_offset = None; + let mut field_start = None; + let mut field_end = None; + let mut extension_start = None; + let mut extension_end = None; + let mut nested_type_start = None; + let mut nested_type_end = None; + let mut enum_type_start = None; + let mut enum_type_end = None; + let mut extension_range_start = None; + let mut extension_range_end = None; + let mut oneof_decl_start = None; + let mut oneof_decl_end = None; + let mut options_offset = None; + let mut reserved_range_start = None; + let mut reserved_range_end = None; + let mut reserved_name_start = None; + let mut reserved_name_end = None; + 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 == 2 { + 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); } + extension_end = Some(offset); + } + if tag.field_number == 3 { + 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); } + enum_type_end = Some(offset); + } + if tag.field_number == 5 { + 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); } + oneof_decl_end = 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); } + reserved_range_end = Some(offset); + } + if tag.field_number == 10 { + 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); } + } + + 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, + }) + } + + pub fn name(&self) -> crate::Result<&'a str> { + let offset = self.name_offset.ok_or(crate::RotoError::FieldNotFound)?; + let (bytes, _) = self.accessor.get_value_at(offset)?; + str::from_utf8(bytes).map_err(|_| crate::RotoError::WireFormatViolation) + } + + pub fn field(&self) -> crate::RepeatedFieldIterator<'a> { + match (self.field_start, self.field_end) { + (Some(start), Some(end)) => self.accessor.iter_repeated_range(2, start, end), + _ => self.accessor.iter_repeated(2), + } + } + + pub fn extension(&self) -> crate::RepeatedFieldIterator<'a> { + match (self.extension_start, self.extension_end) { + (Some(start), Some(end)) => self.accessor.iter_repeated_range(6, start, end), + _ => self.accessor.iter_repeated(6), + } + } + + pub fn nested_type(&self) -> crate::RepeatedFieldIterator<'a> { + match (self.nested_type_start, self.nested_type_end) { + (Some(start), Some(end)) => self.accessor.iter_repeated_range(3, start, end), + _ => self.accessor.iter_repeated(3), + } + } + + pub fn enum_type(&self) -> crate::RepeatedFieldIterator<'a> { + match (self.enum_type_start, self.enum_type_end) { + (Some(start), Some(end)) => self.accessor.iter_repeated_range(4, start, end), + _ => self.accessor.iter_repeated(4), + } + } + + pub fn extension_range(&self) -> crate::RepeatedFieldIterator<'a> { + match (self.extension_range_start, self.extension_range_end) { + (Some(start), Some(end)) => self.accessor.iter_repeated_range(5, start, end), + _ => self.accessor.iter_repeated(5), + } + } + + pub fn oneof_decl(&self) -> crate::RepeatedFieldIterator<'a> { + match (self.oneof_decl_start, self.oneof_decl_end) { + (Some(start), Some(end)) => self.accessor.iter_repeated_range(8, start, end), + _ => self.accessor.iter_repeated(8), + } + } + + pub fn options(&self) -> crate::Result<&'a [u8]> { + let offset = self.options_offset.ok_or(crate::RotoError::FieldNotFound)?; + let (bytes, _) = self.accessor.get_value_at(offset)?; + Ok(bytes) + } + + pub fn reserved_range(&self) -> crate::RepeatedFieldIterator<'a> { + match (self.reserved_range_start, self.reserved_range_end) { + (Some(start), Some(end)) => self.accessor.iter_repeated_range(9, start, end), + _ => self.accessor.iter_repeated(9), + } + } + + pub fn reserved_name(&self) -> crate::RepeatedFieldIterator<'a> { + match (self.reserved_name_start, self.reserved_name_end) { + (Some(start), Some(end)) => self.accessor.iter_repeated_range(10, start, end), + _ => self.accessor.iter_repeated(10), + } + } + + pub fn visibility(&self) -> crate::Result { + let offset = self.visibility_offset.ok_or(crate::RotoError::FieldNotFound)?; + let (bytes, _) = self.accessor.get_value_at(offset)?; + crate::read_varint(bytes).map(|(v, _)| v as u64).map_err(|_| crate::RotoError::WireFormatViolation) + } + +} + +pub struct DescriptorProtoBuilder<'b> { + builder: crate::ProtoBuilder<'b>, +} + +impl<'b> DescriptorProtoBuilder<'b> { + pub fn builder(buf: &mut [u8]) -> DescriptorProtoBuilder<'_> { + DescriptorProtoBuilder { + builder: crate::ProtoBuilder::new(buf), + } + } + + pub fn name(mut self, value: &str) -> crate::Result { + self.builder.write_string(1, value)?; + Ok(self) + } + + pub fn field(mut self, value: &[u8]) -> crate::Result { + self.builder.write_bytes(2, value)?; + Ok(self) + } + + pub fn extension(mut self, value: &[u8]) -> crate::Result { + self.builder.write_bytes(6, value)?; + Ok(self) + } + + pub fn nested_type(mut self, value: &[u8]) -> crate::Result { + self.builder.write_bytes(3, value)?; + Ok(self) + } + + pub fn enum_type(mut self, value: &[u8]) -> crate::Result { + self.builder.write_bytes(4, value)?; + Ok(self) + } + + pub fn extension_range(mut self, value: &[u8]) -> crate::Result { + self.builder.write_bytes(5, value)?; + Ok(self) + } + + pub fn oneof_decl(mut self, value: &[u8]) -> crate::Result { + self.builder.write_bytes(8, value)?; + Ok(self) + } + + pub fn options(mut self, value: &[u8]) -> crate::Result { + self.builder.write_bytes(7, value)?; + Ok(self) + } + + pub fn reserved_range(mut self, value: &[u8]) -> crate::Result { + self.builder.write_bytes(9, value)?; + Ok(self) + } + + pub fn reserved_name(mut self, value: &str) -> crate::Result { + self.builder.write_string(10, value)?; + Ok(self) + } + + pub fn visibility(mut self, value: u64) -> crate::Result { + self.builder.write_varint(11, value)?; + Ok(self) + } + + pub fn finish(self) -> crate::Result<&'b mut [u8]> { + self.builder.finish() + } +} + +pub mod descriptor_proto { +pub struct ExtensionRange<'a> { + accessor: crate::ProtoAccessor<'a>, + start_offset: Option, + end_offset: Option, + options_offset: Option, +} + +impl<'a> ExtensionRange<'a> { + pub fn new(data: &'a [u8]) -> crate::Result { + let accessor = crate::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, + }) + } + + pub fn start(&self) -> crate::Result { + let offset = self.start_offset.ok_or(crate::RotoError::FieldNotFound)?; + let (bytes, _) = self.accessor.get_value_at(offset)?; + crate::read_varint(bytes).map(|(v, _)| v as i32).map_err(|_| crate::RotoError::WireFormatViolation) + } + + pub fn end(&self) -> crate::Result { + let offset = self.end_offset.ok_or(crate::RotoError::FieldNotFound)?; + let (bytes, _) = self.accessor.get_value_at(offset)?; + crate::read_varint(bytes).map(|(v, _)| v as i32).map_err(|_| crate::RotoError::WireFormatViolation) + } + + pub fn options(&self) -> crate::Result<&'a [u8]> { + let offset = self.options_offset.ok_or(crate::RotoError::FieldNotFound)?; + let (bytes, _) = self.accessor.get_value_at(offset)?; + Ok(bytes) + } + +} + +pub struct ExtensionRangeBuilder<'b> { + builder: crate::ProtoBuilder<'b>, +} + +impl<'b> ExtensionRangeBuilder<'b> { + pub fn builder(buf: &mut [u8]) -> ExtensionRangeBuilder<'_> { + ExtensionRangeBuilder { + builder: crate::ProtoBuilder::new(buf), + } + } + + pub fn start(mut self, value: i32) -> crate::Result { + self.builder.write_int32(1, value)?; + Ok(self) + } + + pub fn end(mut self, value: i32) -> crate::Result { + self.builder.write_int32(2, value)?; + Ok(self) + } + + pub fn options(mut self, value: &[u8]) -> crate::Result { + self.builder.write_bytes(3, value)?; + Ok(self) + } + + pub fn finish(self) -> crate::Result<&'b mut [u8]> { + self.builder.finish() + } +} + +pub struct ReservedRange<'a> { + accessor: crate::ProtoAccessor<'a>, + start_offset: Option, + end_offset: Option, +} + +impl<'a> ReservedRange<'a> { + pub fn new(data: &'a [u8]) -> crate::Result { + let accessor = crate::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::Result { + let offset = self.start_offset.ok_or(crate::RotoError::FieldNotFound)?; + let (bytes, _) = self.accessor.get_value_at(offset)?; + crate::read_varint(bytes).map(|(v, _)| v as i32).map_err(|_| crate::RotoError::WireFormatViolation) + } + + pub fn end(&self) -> crate::Result { + let offset = self.end_offset.ok_or(crate::RotoError::FieldNotFound)?; + let (bytes, _) = self.accessor.get_value_at(offset)?; + crate::read_varint(bytes).map(|(v, _)| v as i32).map_err(|_| crate::RotoError::WireFormatViolation) + } + +} + +pub struct ReservedRangeBuilder<'b> { + builder: crate::ProtoBuilder<'b>, +} + +impl<'b> ReservedRangeBuilder<'b> { + pub fn builder(buf: &mut [u8]) -> ReservedRangeBuilder<'_> { + ReservedRangeBuilder { + builder: crate::ProtoBuilder::new(buf), + } + } + + pub fn start(mut self, value: i32) -> crate::Result { + self.builder.write_int32(1, value)?; + Ok(self) + } + + pub fn end(mut self, value: i32) -> crate::Result { + self.builder.write_int32(2, value)?; + Ok(self) + } + + pub fn finish(self) -> crate::Result<&'b mut [u8]> { + self.builder.finish() + } +} + +} + +pub struct ExtensionRangeOptions<'a> { + accessor: crate::ProtoAccessor<'a>, + uninterpreted_option_start: Option, + uninterpreted_option_end: Option, + declaration_start: Option, + declaration_end: Option, + features_offset: Option, + verification_offset: Option, +} + +impl<'a> ExtensionRangeOptions<'a> { + pub fn new(data: &'a [u8]) -> crate::Result { + let accessor = crate::ProtoAccessor::new(data)?; + let mut uninterpreted_option_start = None; + let mut uninterpreted_option_end = None; + let mut declaration_start = None; + let mut declaration_end = None; + let mut features_offset = None; + let mut verification_offset = None; + 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); } + uninterpreted_option_end = Some(offset); + } + if tag.field_number == 2 { + 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); } + } + + Ok(Self { + accessor, +uninterpreted_option_start, uninterpreted_option_end, +declaration_start, declaration_end, +features_offset, +verification_offset, + }) + } + + pub fn uninterpreted_option(&self) -> crate::RepeatedFieldIterator<'a> { + 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), + } + } + + pub fn declaration(&self) -> crate::RepeatedFieldIterator<'a> { + match (self.declaration_start, self.declaration_end) { + (Some(start), Some(end)) => self.accessor.iter_repeated_range(2, start, end), + _ => self.accessor.iter_repeated(2), + } + } + + pub fn features(&self) -> crate::Result<&'a [u8]> { + let offset = self.features_offset.ok_or(crate::RotoError::FieldNotFound)?; + let (bytes, _) = self.accessor.get_value_at(offset)?; + Ok(bytes) + } + + pub fn verification(&self) -> crate::Result { + let offset = self.verification_offset.ok_or(crate::RotoError::FieldNotFound)?; + let (bytes, _) = self.accessor.get_value_at(offset)?; + crate::read_varint(bytes).map(|(v, _)| v as u64).map_err(|_| crate::RotoError::WireFormatViolation) + } + +} + +pub struct ExtensionRangeOptionsBuilder<'b> { + builder: crate::ProtoBuilder<'b>, +} + +impl<'b> ExtensionRangeOptionsBuilder<'b> { + pub fn builder(buf: &mut [u8]) -> ExtensionRangeOptionsBuilder<'_> { + ExtensionRangeOptionsBuilder { + builder: crate::ProtoBuilder::new(buf), + } + } + + pub fn uninterpreted_option(mut self, value: &[u8]) -> crate::Result { + self.builder.write_bytes(999, value)?; + Ok(self) + } + + pub fn declaration(mut self, value: &[u8]) -> crate::Result { + self.builder.write_bytes(2, value)?; + Ok(self) + } + + pub fn features(mut self, value: &[u8]) -> crate::Result { + self.builder.write_bytes(50, value)?; + Ok(self) + } + + pub fn verification(mut self, value: u64) -> crate::Result { + self.builder.write_varint(3, value)?; + Ok(self) + } + + pub fn finish(self) -> crate::Result<&'b mut [u8]> { + self.builder.finish() + } +} + +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::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::Result { + let accessor = crate::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::Result { + let offset = self.number_offset.ok_or(crate::RotoError::FieldNotFound)?; + let (bytes, _) = self.accessor.get_value_at(offset)?; + crate::read_varint(bytes).map(|(v, _)| v as i32).map_err(|_| crate::RotoError::WireFormatViolation) + } + + pub fn full_name(&self) -> crate::Result<&'a str> { + let offset = self.full_name_offset.ok_or(crate::RotoError::FieldNotFound)?; + let (bytes, _) = self.accessor.get_value_at(offset)?; + str::from_utf8(bytes).map_err(|_| crate::RotoError::WireFormatViolation) + } + + pub fn r#type(&self) -> crate::Result<&'a str> { + let offset = self.type_offset.ok_or(crate::RotoError::FieldNotFound)?; + let (bytes, _) = self.accessor.get_value_at(offset)?; + str::from_utf8(bytes).map_err(|_| crate::RotoError::WireFormatViolation) + } + + pub fn reserved(&self) -> crate::Result { + let offset = self.reserved_offset.ok_or(crate::RotoError::FieldNotFound)?; + let (bytes, _) = self.accessor.get_value_at(offset)?; + crate::read_varint(bytes).map(|(v, _)| v != 0).map_err(|_| crate::RotoError::WireFormatViolation) + } + + pub fn repeated(&self) -> crate::Result { + let offset = self.repeated_offset.ok_or(crate::RotoError::FieldNotFound)?; + let (bytes, _) = self.accessor.get_value_at(offset)?; + crate::read_varint(bytes).map(|(v, _)| v != 0).map_err(|_| crate::RotoError::WireFormatViolation) + } + +} + +pub struct DeclarationBuilder<'b> { + builder: crate::ProtoBuilder<'b>, +} + +impl<'b> DeclarationBuilder<'b> { + pub fn builder(buf: &mut [u8]) -> DeclarationBuilder<'_> { + DeclarationBuilder { + builder: crate::ProtoBuilder::new(buf), + } + } + + pub fn number(mut self, value: i32) -> crate::Result { + self.builder.write_int32(1, value)?; + Ok(self) + } + + pub fn full_name(mut self, value: &str) -> crate::Result { + self.builder.write_string(2, value)?; + Ok(self) + } + + pub fn r#type(mut self, value: &str) -> crate::Result { + self.builder.write_string(3, value)?; + Ok(self) + } + + pub fn reserved(mut self, value: u64) -> crate::Result { + self.builder.write_varint(5, value)?; + Ok(self) + } + + pub fn repeated(mut self, value: u64) -> crate::Result { + self.builder.write_varint(6, value)?; + Ok(self) + } + + pub fn finish(self) -> crate::Result<&'b mut [u8]> { + self.builder.finish() + } +} + +} + +pub struct FieldDescriptorProto<'a> { + accessor: crate::ProtoAccessor<'a>, + name_offset: Option, + number_offset: Option, + label_offset: Option, + type_offset: Option, + type_name_offset: Option, + extendee_offset: Option, + default_value_offset: Option, + oneof_index_offset: Option, + json_name_offset: Option, + options_offset: Option, + proto3_optional_offset: Option, +} + +impl<'a> FieldDescriptorProto<'a> { + pub fn new(data: &'a [u8]) -> crate::Result { + let accessor = crate::ProtoAccessor::new(data)?; + let mut name_offset = None; + let mut number_offset = None; + let mut label_offset = None; + let mut type_offset = None; + let mut type_name_offset = None; + let mut extendee_offset = None; + let mut default_value_offset = None; + let mut oneof_index_offset = None; + let mut json_name_offset = None; + let mut options_offset = None; + 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); } + } + + 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, + }) + } + + pub fn name(&self) -> crate::Result<&'a str> { + let offset = self.name_offset.ok_or(crate::RotoError::FieldNotFound)?; + let (bytes, _) = self.accessor.get_value_at(offset)?; + str::from_utf8(bytes).map_err(|_| crate::RotoError::WireFormatViolation) + } + + pub fn number(&self) -> crate::Result { + let offset = self.number_offset.ok_or(crate::RotoError::FieldNotFound)?; + let (bytes, _) = self.accessor.get_value_at(offset)?; + crate::read_varint(bytes).map(|(v, _)| v as i32).map_err(|_| crate::RotoError::WireFormatViolation) + } + + pub fn label(&self) -> crate::Result { + let offset = self.label_offset.ok_or(crate::RotoError::FieldNotFound)?; + let (bytes, _) = self.accessor.get_value_at(offset)?; + crate::read_varint(bytes).map(|(v, _)| v as u64).map_err(|_| crate::RotoError::WireFormatViolation) + } + + pub fn r#type(&self) -> crate::Result { + let offset = self.type_offset.ok_or(crate::RotoError::FieldNotFound)?; + let (bytes, _) = self.accessor.get_value_at(offset)?; + crate::read_varint(bytes).map(|(v, _)| v as u64).map_err(|_| crate::RotoError::WireFormatViolation) + } + + pub fn type_name(&self) -> crate::Result<&'a str> { + let offset = self.type_name_offset.ok_or(crate::RotoError::FieldNotFound)?; + let (bytes, _) = self.accessor.get_value_at(offset)?; + str::from_utf8(bytes).map_err(|_| crate::RotoError::WireFormatViolation) + } + + pub fn extendee(&self) -> crate::Result<&'a str> { + let offset = self.extendee_offset.ok_or(crate::RotoError::FieldNotFound)?; + let (bytes, _) = self.accessor.get_value_at(offset)?; + str::from_utf8(bytes).map_err(|_| crate::RotoError::WireFormatViolation) + } + + pub fn default_value(&self) -> crate::Result<&'a str> { + let offset = self.default_value_offset.ok_or(crate::RotoError::FieldNotFound)?; + let (bytes, _) = self.accessor.get_value_at(offset)?; + str::from_utf8(bytes).map_err(|_| crate::RotoError::WireFormatViolation) + } + + pub fn oneof_index(&self) -> crate::Result { + let offset = self.oneof_index_offset.ok_or(crate::RotoError::FieldNotFound)?; + let (bytes, _) = self.accessor.get_value_at(offset)?; + crate::read_varint(bytes).map(|(v, _)| v as i32).map_err(|_| crate::RotoError::WireFormatViolation) + } + + pub fn json_name(&self) -> crate::Result<&'a str> { + let offset = self.json_name_offset.ok_or(crate::RotoError::FieldNotFound)?; + let (bytes, _) = self.accessor.get_value_at(offset)?; + str::from_utf8(bytes).map_err(|_| crate::RotoError::WireFormatViolation) + } + + pub fn options(&self) -> crate::Result<&'a [u8]> { + let offset = self.options_offset.ok_or(crate::RotoError::FieldNotFound)?; + let (bytes, _) = self.accessor.get_value_at(offset)?; + Ok(bytes) + } + + pub fn proto3_optional(&self) -> crate::Result { + let offset = self.proto3_optional_offset.ok_or(crate::RotoError::FieldNotFound)?; + let (bytes, _) = self.accessor.get_value_at(offset)?; + crate::read_varint(bytes).map(|(v, _)| v != 0).map_err(|_| crate::RotoError::WireFormatViolation) + } + +} + +pub struct FieldDescriptorProtoBuilder<'b> { + builder: crate::ProtoBuilder<'b>, +} + +impl<'b> FieldDescriptorProtoBuilder<'b> { + pub fn builder(buf: &mut [u8]) -> FieldDescriptorProtoBuilder<'_> { + FieldDescriptorProtoBuilder { + builder: crate::ProtoBuilder::new(buf), + } + } + + pub fn name(mut self, value: &str) -> crate::Result { + self.builder.write_string(1, value)?; + Ok(self) + } + + pub fn number(mut self, value: i32) -> crate::Result { + self.builder.write_int32(3, value)?; + Ok(self) + } + + pub fn label(mut self, value: u64) -> crate::Result { + self.builder.write_varint(4, value)?; + Ok(self) + } + + pub fn r#type(mut self, value: u64) -> crate::Result { + self.builder.write_varint(5, value)?; + Ok(self) + } + + pub fn type_name(mut self, value: &str) -> crate::Result { + self.builder.write_string(6, value)?; + Ok(self) + } + + pub fn extendee(mut self, value: &str) -> crate::Result { + self.builder.write_string(2, value)?; + Ok(self) + } + + pub fn default_value(mut self, value: &str) -> crate::Result { + self.builder.write_string(7, value)?; + Ok(self) + } + + pub fn oneof_index(mut self, value: i32) -> crate::Result { + self.builder.write_int32(9, value)?; + Ok(self) + } + + pub fn json_name(mut self, value: &str) -> crate::Result { + self.builder.write_string(10, value)?; + Ok(self) + } + + pub fn options(mut self, value: &[u8]) -> crate::Result { + self.builder.write_bytes(8, value)?; + Ok(self) + } + + pub fn proto3_optional(mut self, value: u64) -> crate::Result { + self.builder.write_varint(17, value)?; + Ok(self) + } + + pub fn finish(self) -> crate::Result<&'b mut [u8]> { + self.builder.finish() + } +} + +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, +} + +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, +} + +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::ProtoAccessor<'a>, + name_offset: Option, + options_offset: Option, +} + +impl<'a> OneofDescriptorProto<'a> { + pub fn new(data: &'a [u8]) -> crate::Result { + let accessor = crate::ProtoAccessor::new(data)?; + let mut name_offset = None; + 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); } + } + + Ok(Self { + accessor, +name_offset, +options_offset, + }) + } + + pub fn name(&self) -> crate::Result<&'a str> { + let offset = self.name_offset.ok_or(crate::RotoError::FieldNotFound)?; + let (bytes, _) = self.accessor.get_value_at(offset)?; + str::from_utf8(bytes).map_err(|_| crate::RotoError::WireFormatViolation) + } + + pub fn options(&self) -> crate::Result<&'a [u8]> { + let offset = self.options_offset.ok_or(crate::RotoError::FieldNotFound)?; + let (bytes, _) = self.accessor.get_value_at(offset)?; + Ok(bytes) + } + +} + +pub struct OneofDescriptorProtoBuilder<'b> { + builder: crate::ProtoBuilder<'b>, +} + +impl<'b> OneofDescriptorProtoBuilder<'b> { + pub fn builder(buf: &mut [u8]) -> OneofDescriptorProtoBuilder<'_> { + OneofDescriptorProtoBuilder { + builder: crate::ProtoBuilder::new(buf), + } + } + + pub fn name(mut self, value: &str) -> crate::Result { + self.builder.write_string(1, value)?; + Ok(self) + } + + pub fn options(mut self, value: &[u8]) -> crate::Result { + self.builder.write_bytes(2, value)?; + Ok(self) + } + + pub fn finish(self) -> crate::Result<&'b mut [u8]> { + self.builder.finish() + } +} + +pub struct EnumDescriptorProto<'a> { + accessor: crate::ProtoAccessor<'a>, + name_offset: Option, + value_start: Option, + value_end: Option, + options_offset: Option, + reserved_range_start: Option, + reserved_range_end: Option, + reserved_name_start: Option, + reserved_name_end: Option, + visibility_offset: Option, +} + +impl<'a> EnumDescriptorProto<'a> { + pub fn new(data: &'a [u8]) -> crate::Result { + let accessor = crate::ProtoAccessor::new(data)?; + let mut name_offset = None; + let mut value_start = None; + let mut value_end = None; + let mut options_offset = None; + let mut reserved_range_start = None; + let mut reserved_range_end = None; + let mut reserved_name_start = None; + let mut reserved_name_end = None; + 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 == 2 { + 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 == 4 { + 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); } + reserved_name_end = 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, + }) + } + + pub fn name(&self) -> crate::Result<&'a str> { + let offset = self.name_offset.ok_or(crate::RotoError::FieldNotFound)?; + let (bytes, _) = self.accessor.get_value_at(offset)?; + str::from_utf8(bytes).map_err(|_| crate::RotoError::WireFormatViolation) + } + + pub fn value(&self) -> crate::RepeatedFieldIterator<'a> { + match (self.value_start, self.value_end) { + (Some(start), Some(end)) => self.accessor.iter_repeated_range(2, start, end), + _ => self.accessor.iter_repeated(2), + } + } + + pub fn options(&self) -> crate::Result<&'a [u8]> { + let offset = self.options_offset.ok_or(crate::RotoError::FieldNotFound)?; + let (bytes, _) = self.accessor.get_value_at(offset)?; + Ok(bytes) + } + + pub fn reserved_range(&self) -> crate::RepeatedFieldIterator<'a> { + match (self.reserved_range_start, self.reserved_range_end) { + (Some(start), Some(end)) => self.accessor.iter_repeated_range(4, start, end), + _ => self.accessor.iter_repeated(4), + } + } + + pub fn reserved_name(&self) -> crate::RepeatedFieldIterator<'a> { + match (self.reserved_name_start, self.reserved_name_end) { + (Some(start), Some(end)) => self.accessor.iter_repeated_range(5, start, end), + _ => self.accessor.iter_repeated(5), + } + } + + pub fn visibility(&self) -> crate::Result { + let offset = self.visibility_offset.ok_or(crate::RotoError::FieldNotFound)?; + let (bytes, _) = self.accessor.get_value_at(offset)?; + crate::read_varint(bytes).map(|(v, _)| v as u64).map_err(|_| crate::RotoError::WireFormatViolation) + } + +} + +pub struct EnumDescriptorProtoBuilder<'b> { + builder: crate::ProtoBuilder<'b>, +} + +impl<'b> EnumDescriptorProtoBuilder<'b> { + pub fn builder(buf: &mut [u8]) -> EnumDescriptorProtoBuilder<'_> { + EnumDescriptorProtoBuilder { + builder: crate::ProtoBuilder::new(buf), + } + } + + pub fn name(mut self, value: &str) -> crate::Result { + self.builder.write_string(1, value)?; + Ok(self) + } + + pub fn value(mut self, value: &[u8]) -> crate::Result { + self.builder.write_bytes(2, value)?; + Ok(self) + } + + pub fn options(mut self, value: &[u8]) -> crate::Result { + self.builder.write_bytes(3, value)?; + Ok(self) + } + + pub fn reserved_range(mut self, value: &[u8]) -> crate::Result { + self.builder.write_bytes(4, value)?; + Ok(self) + } + + pub fn reserved_name(mut self, value: &str) -> crate::Result { + self.builder.write_string(5, value)?; + Ok(self) + } + + pub fn visibility(mut self, value: u64) -> crate::Result { + self.builder.write_varint(6, value)?; + Ok(self) + } + + pub fn finish(self) -> crate::Result<&'b mut [u8]> { + self.builder.finish() + } +} + +pub mod enum_descriptor_proto { +pub struct EnumReservedRange<'a> { + accessor: crate::ProtoAccessor<'a>, + start_offset: Option, + end_offset: Option, +} + +impl<'a> EnumReservedRange<'a> { + pub fn new(data: &'a [u8]) -> crate::Result { + let accessor = crate::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::Result { + let offset = self.start_offset.ok_or(crate::RotoError::FieldNotFound)?; + let (bytes, _) = self.accessor.get_value_at(offset)?; + crate::read_varint(bytes).map(|(v, _)| v as i32).map_err(|_| crate::RotoError::WireFormatViolation) + } + + pub fn end(&self) -> crate::Result { + let offset = self.end_offset.ok_or(crate::RotoError::FieldNotFound)?; + let (bytes, _) = self.accessor.get_value_at(offset)?; + crate::read_varint(bytes).map(|(v, _)| v as i32).map_err(|_| crate::RotoError::WireFormatViolation) + } + +} + +pub struct EnumReservedRangeBuilder<'b> { + builder: crate::ProtoBuilder<'b>, +} + +impl<'b> EnumReservedRangeBuilder<'b> { + pub fn builder(buf: &mut [u8]) -> EnumReservedRangeBuilder<'_> { + EnumReservedRangeBuilder { + builder: crate::ProtoBuilder::new(buf), + } + } + + pub fn start(mut self, value: i32) -> crate::Result { + self.builder.write_int32(1, value)?; + Ok(self) + } + + pub fn end(mut self, value: i32) -> crate::Result { + self.builder.write_int32(2, value)?; + Ok(self) + } + + pub fn finish(self) -> crate::Result<&'b mut [u8]> { + self.builder.finish() + } +} + +} + +pub struct EnumValueDescriptorProto<'a> { + accessor: crate::ProtoAccessor<'a>, + name_offset: Option, + number_offset: Option, + options_offset: Option, +} + +impl<'a> EnumValueDescriptorProto<'a> { + pub fn new(data: &'a [u8]) -> crate::Result { + let accessor = crate::ProtoAccessor::new(data)?; + let mut name_offset = None; + let mut number_offset = None; + 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); } + } + + Ok(Self { + accessor, +name_offset, +number_offset, +options_offset, + }) + } + + pub fn name(&self) -> crate::Result<&'a str> { + let offset = self.name_offset.ok_or(crate::RotoError::FieldNotFound)?; + let (bytes, _) = self.accessor.get_value_at(offset)?; + str::from_utf8(bytes).map_err(|_| crate::RotoError::WireFormatViolation) + } + + pub fn number(&self) -> crate::Result { + let offset = self.number_offset.ok_or(crate::RotoError::FieldNotFound)?; + let (bytes, _) = self.accessor.get_value_at(offset)?; + crate::read_varint(bytes).map(|(v, _)| v as i32).map_err(|_| crate::RotoError::WireFormatViolation) + } + + pub fn options(&self) -> crate::Result<&'a [u8]> { + let offset = self.options_offset.ok_or(crate::RotoError::FieldNotFound)?; + let (bytes, _) = self.accessor.get_value_at(offset)?; + Ok(bytes) + } + +} + +pub struct EnumValueDescriptorProtoBuilder<'b> { + builder: crate::ProtoBuilder<'b>, +} + +impl<'b> EnumValueDescriptorProtoBuilder<'b> { + pub fn builder(buf: &mut [u8]) -> EnumValueDescriptorProtoBuilder<'_> { + EnumValueDescriptorProtoBuilder { + builder: crate::ProtoBuilder::new(buf), + } + } + + pub fn name(mut self, value: &str) -> crate::Result { + self.builder.write_string(1, value)?; + Ok(self) + } + + pub fn number(mut self, value: i32) -> crate::Result { + self.builder.write_int32(2, value)?; + Ok(self) + } + + pub fn options(mut self, value: &[u8]) -> crate::Result { + self.builder.write_bytes(3, value)?; + Ok(self) + } + + pub fn finish(self) -> crate::Result<&'b mut [u8]> { + self.builder.finish() + } +} + +pub struct ServiceDescriptorProto<'a> { + accessor: crate::ProtoAccessor<'a>, + name_offset: Option, + method_start: Option, + method_end: Option, + options_offset: Option, +} + +impl<'a> ServiceDescriptorProto<'a> { + pub fn new(data: &'a [u8]) -> crate::Result { + let accessor = crate::ProtoAccessor::new(data)?; + let mut name_offset = None; + let mut method_start = None; + let mut method_end = None; + 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 { + if method_start.is_none() { method_start = Some(offset); } + method_end = Some(offset); + } + if tag.field_number == 3 { options_offset = Some(offset); } + } + + Ok(Self { + accessor, +name_offset, +method_start, method_end, +options_offset, + }) + } + + pub fn name(&self) -> crate::Result<&'a str> { + let offset = self.name_offset.ok_or(crate::RotoError::FieldNotFound)?; + let (bytes, _) = self.accessor.get_value_at(offset)?; + str::from_utf8(bytes).map_err(|_| crate::RotoError::WireFormatViolation) + } + + pub fn method(&self) -> crate::RepeatedFieldIterator<'a> { + match (self.method_start, self.method_end) { + (Some(start), Some(end)) => self.accessor.iter_repeated_range(2, start, end), + _ => self.accessor.iter_repeated(2), + } + } + + pub fn options(&self) -> crate::Result<&'a [u8]> { + let offset = self.options_offset.ok_or(crate::RotoError::FieldNotFound)?; + let (bytes, _) = self.accessor.get_value_at(offset)?; + Ok(bytes) + } + +} + +pub struct ServiceDescriptorProtoBuilder<'b> { + builder: crate::ProtoBuilder<'b>, +} + +impl<'b> ServiceDescriptorProtoBuilder<'b> { + pub fn builder(buf: &mut [u8]) -> ServiceDescriptorProtoBuilder<'_> { + ServiceDescriptorProtoBuilder { + builder: crate::ProtoBuilder::new(buf), + } + } + + pub fn name(mut self, value: &str) -> crate::Result { + self.builder.write_string(1, value)?; + Ok(self) + } + + pub fn method(mut self, value: &[u8]) -> crate::Result { + self.builder.write_bytes(2, value)?; + Ok(self) + } + + pub fn options(mut self, value: &[u8]) -> crate::Result { + self.builder.write_bytes(3, value)?; + Ok(self) + } + + pub fn finish(self) -> crate::Result<&'b mut [u8]> { + self.builder.finish() + } +} + +pub struct MethodDescriptorProto<'a> { + accessor: crate::ProtoAccessor<'a>, + name_offset: Option, + input_type_offset: Option, + output_type_offset: Option, + options_offset: Option, + client_streaming_offset: Option, + server_streaming_offset: Option, +} + +impl<'a> MethodDescriptorProto<'a> { + pub fn new(data: &'a [u8]) -> crate::Result { + let accessor = crate::ProtoAccessor::new(data)?; + let mut name_offset = None; + let mut input_type_offset = None; + let mut output_type_offset = None; + let mut options_offset = None; + let mut client_streaming_offset = None; + 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); } + } + + Ok(Self { + accessor, +name_offset, +input_type_offset, +output_type_offset, +options_offset, +client_streaming_offset, +server_streaming_offset, + }) + } + + pub fn name(&self) -> crate::Result<&'a str> { + let offset = self.name_offset.ok_or(crate::RotoError::FieldNotFound)?; + let (bytes, _) = self.accessor.get_value_at(offset)?; + str::from_utf8(bytes).map_err(|_| crate::RotoError::WireFormatViolation) + } + + pub fn input_type(&self) -> crate::Result<&'a str> { + let offset = self.input_type_offset.ok_or(crate::RotoError::FieldNotFound)?; + let (bytes, _) = self.accessor.get_value_at(offset)?; + str::from_utf8(bytes).map_err(|_| crate::RotoError::WireFormatViolation) + } + + pub fn output_type(&self) -> crate::Result<&'a str> { + let offset = self.output_type_offset.ok_or(crate::RotoError::FieldNotFound)?; + let (bytes, _) = self.accessor.get_value_at(offset)?; + str::from_utf8(bytes).map_err(|_| crate::RotoError::WireFormatViolation) + } + + pub fn options(&self) -> crate::Result<&'a [u8]> { + let offset = self.options_offset.ok_or(crate::RotoError::FieldNotFound)?; + let (bytes, _) = self.accessor.get_value_at(offset)?; + Ok(bytes) + } + + pub fn client_streaming(&self) -> crate::Result { + let offset = self.client_streaming_offset.ok_or(crate::RotoError::FieldNotFound)?; + let (bytes, _) = self.accessor.get_value_at(offset)?; + crate::read_varint(bytes).map(|(v, _)| v != 0).map_err(|_| crate::RotoError::WireFormatViolation) + } + + pub fn server_streaming(&self) -> crate::Result { + let offset = self.server_streaming_offset.ok_or(crate::RotoError::FieldNotFound)?; + let (bytes, _) = self.accessor.get_value_at(offset)?; + crate::read_varint(bytes).map(|(v, _)| v != 0).map_err(|_| crate::RotoError::WireFormatViolation) + } + +} + +pub struct MethodDescriptorProtoBuilder<'b> { + builder: crate::ProtoBuilder<'b>, +} + +impl<'b> MethodDescriptorProtoBuilder<'b> { + pub fn builder(buf: &mut [u8]) -> MethodDescriptorProtoBuilder<'_> { + MethodDescriptorProtoBuilder { + builder: crate::ProtoBuilder::new(buf), + } + } + + pub fn name(mut self, value: &str) -> crate::Result { + self.builder.write_string(1, value)?; + Ok(self) + } + + pub fn input_type(mut self, value: &str) -> crate::Result { + self.builder.write_string(2, value)?; + Ok(self) + } + + pub fn output_type(mut self, value: &str) -> crate::Result { + self.builder.write_string(3, value)?; + Ok(self) + } + + pub fn options(mut self, value: &[u8]) -> crate::Result { + self.builder.write_bytes(4, value)?; + Ok(self) + } + + pub fn client_streaming(mut self, value: u64) -> crate::Result { + self.builder.write_varint(5, value)?; + Ok(self) + } + + pub fn server_streaming(mut self, value: u64) -> crate::Result { + self.builder.write_varint(6, value)?; + Ok(self) + } + + pub fn finish(self) -> crate::Result<&'b mut [u8]> { + self.builder.finish() + } +} + +pub struct FileOptions<'a> { + accessor: crate::ProtoAccessor<'a>, + java_package_offset: Option, + java_outer_classname_offset: Option, + java_multiple_files_offset: Option, + java_generate_equals_and_hash_offset: Option, + java_string_check_utf8_offset: Option, + optimize_for_offset: Option, + go_package_offset: Option, + cc_generic_services_offset: Option, + java_generic_services_offset: Option, + py_generic_services_offset: Option, + deprecated_offset: Option, + cc_enable_arenas_offset: Option, + objc_class_prefix_offset: Option, + csharp_namespace_offset: Option, + swift_prefix_offset: Option, + php_class_prefix_offset: Option, + php_namespace_offset: Option, + php_metadata_namespace_offset: Option, + ruby_package_offset: Option, + features_offset: Option, + uninterpreted_option_start: Option, + uninterpreted_option_end: Option, +} + +impl<'a> FileOptions<'a> { + pub fn new(data: &'a [u8]) -> crate::Result { + let accessor = crate::ProtoAccessor::new(data)?; + let mut java_package_offset = None; + let mut java_outer_classname_offset = None; + let mut java_multiple_files_offset = None; + let mut java_generate_equals_and_hash_offset = None; + let mut java_string_check_utf8_offset = None; + let mut optimize_for_offset = None; + let mut go_package_offset = None; + let mut cc_generic_services_offset = None; + let mut java_generic_services_offset = None; + let mut py_generic_services_offset = None; + let mut deprecated_offset = None; + let mut cc_enable_arenas_offset = None; + let mut objc_class_prefix_offset = None; + let mut csharp_namespace_offset = None; + let mut swift_prefix_offset = None; + let mut php_class_prefix_offset = None; + let mut php_namespace_offset = None; + let mut php_metadata_namespace_offset = None; + let mut ruby_package_offset = None; + let mut features_offset = None; + let mut uninterpreted_option_start = None; + 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 == 999 { + 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, + }) + } + + pub fn java_package(&self) -> crate::Result<&'a str> { + let offset = self.java_package_offset.ok_or(crate::RotoError::FieldNotFound)?; + let (bytes, _) = self.accessor.get_value_at(offset)?; + str::from_utf8(bytes).map_err(|_| crate::RotoError::WireFormatViolation) + } + + pub fn java_outer_classname(&self) -> crate::Result<&'a str> { + let offset = self.java_outer_classname_offset.ok_or(crate::RotoError::FieldNotFound)?; + let (bytes, _) = self.accessor.get_value_at(offset)?; + str::from_utf8(bytes).map_err(|_| crate::RotoError::WireFormatViolation) + } + + pub fn java_multiple_files(&self) -> crate::Result { + let offset = self.java_multiple_files_offset.ok_or(crate::RotoError::FieldNotFound)?; + let (bytes, _) = self.accessor.get_value_at(offset)?; + crate::read_varint(bytes).map(|(v, _)| v != 0).map_err(|_| crate::RotoError::WireFormatViolation) + } + + pub fn java_generate_equals_and_hash(&self) -> crate::Result { + let offset = self.java_generate_equals_and_hash_offset.ok_or(crate::RotoError::FieldNotFound)?; + let (bytes, _) = self.accessor.get_value_at(offset)?; + crate::read_varint(bytes).map(|(v, _)| v != 0).map_err(|_| crate::RotoError::WireFormatViolation) + } + + pub fn java_string_check_utf8(&self) -> crate::Result { + let offset = self.java_string_check_utf8_offset.ok_or(crate::RotoError::FieldNotFound)?; + let (bytes, _) = self.accessor.get_value_at(offset)?; + crate::read_varint(bytes).map(|(v, _)| v != 0).map_err(|_| crate::RotoError::WireFormatViolation) + } + + pub fn optimize_for(&self) -> crate::Result { + let offset = self.optimize_for_offset.ok_or(crate::RotoError::FieldNotFound)?; + let (bytes, _) = self.accessor.get_value_at(offset)?; + crate::read_varint(bytes).map(|(v, _)| v as u64).map_err(|_| crate::RotoError::WireFormatViolation) + } + + pub fn go_package(&self) -> crate::Result<&'a str> { + let offset = self.go_package_offset.ok_or(crate::RotoError::FieldNotFound)?; + let (bytes, _) = self.accessor.get_value_at(offset)?; + str::from_utf8(bytes).map_err(|_| crate::RotoError::WireFormatViolation) + } + + pub fn cc_generic_services(&self) -> crate::Result { + let offset = self.cc_generic_services_offset.ok_or(crate::RotoError::FieldNotFound)?; + let (bytes, _) = self.accessor.get_value_at(offset)?; + crate::read_varint(bytes).map(|(v, _)| v != 0).map_err(|_| crate::RotoError::WireFormatViolation) + } + + pub fn java_generic_services(&self) -> crate::Result { + let offset = self.java_generic_services_offset.ok_or(crate::RotoError::FieldNotFound)?; + let (bytes, _) = self.accessor.get_value_at(offset)?; + crate::read_varint(bytes).map(|(v, _)| v != 0).map_err(|_| crate::RotoError::WireFormatViolation) + } + + pub fn py_generic_services(&self) -> crate::Result { + let offset = self.py_generic_services_offset.ok_or(crate::RotoError::FieldNotFound)?; + let (bytes, _) = self.accessor.get_value_at(offset)?; + crate::read_varint(bytes).map(|(v, _)| v != 0).map_err(|_| crate::RotoError::WireFormatViolation) + } + + pub fn deprecated(&self) -> crate::Result { + let offset = self.deprecated_offset.ok_or(crate::RotoError::FieldNotFound)?; + let (bytes, _) = self.accessor.get_value_at(offset)?; + crate::read_varint(bytes).map(|(v, _)| v != 0).map_err(|_| crate::RotoError::WireFormatViolation) + } + + pub fn cc_enable_arenas(&self) -> crate::Result { + let offset = self.cc_enable_arenas_offset.ok_or(crate::RotoError::FieldNotFound)?; + let (bytes, _) = self.accessor.get_value_at(offset)?; + crate::read_varint(bytes).map(|(v, _)| v != 0).map_err(|_| crate::RotoError::WireFormatViolation) + } + + pub fn objc_class_prefix(&self) -> crate::Result<&'a str> { + let offset = self.objc_class_prefix_offset.ok_or(crate::RotoError::FieldNotFound)?; + let (bytes, _) = self.accessor.get_value_at(offset)?; + str::from_utf8(bytes).map_err(|_| crate::RotoError::WireFormatViolation) + } + + pub fn csharp_namespace(&self) -> crate::Result<&'a str> { + let offset = self.csharp_namespace_offset.ok_or(crate::RotoError::FieldNotFound)?; + let (bytes, _) = self.accessor.get_value_at(offset)?; + str::from_utf8(bytes).map_err(|_| crate::RotoError::WireFormatViolation) + } + + pub fn swift_prefix(&self) -> crate::Result<&'a str> { + let offset = self.swift_prefix_offset.ok_or(crate::RotoError::FieldNotFound)?; + let (bytes, _) = self.accessor.get_value_at(offset)?; + str::from_utf8(bytes).map_err(|_| crate::RotoError::WireFormatViolation) + } + + pub fn php_class_prefix(&self) -> crate::Result<&'a str> { + let offset = self.php_class_prefix_offset.ok_or(crate::RotoError::FieldNotFound)?; + let (bytes, _) = self.accessor.get_value_at(offset)?; + str::from_utf8(bytes).map_err(|_| crate::RotoError::WireFormatViolation) + } + + pub fn php_namespace(&self) -> crate::Result<&'a str> { + let offset = self.php_namespace_offset.ok_or(crate::RotoError::FieldNotFound)?; + let (bytes, _) = self.accessor.get_value_at(offset)?; + str::from_utf8(bytes).map_err(|_| crate::RotoError::WireFormatViolation) + } + + pub fn php_metadata_namespace(&self) -> crate::Result<&'a str> { + let offset = self.php_metadata_namespace_offset.ok_or(crate::RotoError::FieldNotFound)?; + let (bytes, _) = self.accessor.get_value_at(offset)?; + str::from_utf8(bytes).map_err(|_| crate::RotoError::WireFormatViolation) + } + + pub fn ruby_package(&self) -> crate::Result<&'a str> { + let offset = self.ruby_package_offset.ok_or(crate::RotoError::FieldNotFound)?; + let (bytes, _) = self.accessor.get_value_at(offset)?; + str::from_utf8(bytes).map_err(|_| crate::RotoError::WireFormatViolation) + } + + pub fn features(&self) -> crate::Result<&'a [u8]> { + let offset = self.features_offset.ok_or(crate::RotoError::FieldNotFound)?; + let (bytes, _) = self.accessor.get_value_at(offset)?; + Ok(bytes) + } + + pub fn uninterpreted_option(&self) -> crate::RepeatedFieldIterator<'a> { + 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), + } + } + +} + +pub struct FileOptionsBuilder<'b> { + builder: crate::ProtoBuilder<'b>, +} + +impl<'b> FileOptionsBuilder<'b> { + pub fn builder(buf: &mut [u8]) -> FileOptionsBuilder<'_> { + FileOptionsBuilder { + builder: crate::ProtoBuilder::new(buf), + } + } + + pub fn java_package(mut self, value: &str) -> crate::Result { + self.builder.write_string(1, value)?; + Ok(self) + } + + pub fn java_outer_classname(mut self, value: &str) -> crate::Result { + self.builder.write_string(8, value)?; + Ok(self) + } + + pub fn java_multiple_files(mut self, value: u64) -> crate::Result { + self.builder.write_varint(10, value)?; + Ok(self) + } + + pub fn java_generate_equals_and_hash(mut self, value: u64) -> crate::Result { + self.builder.write_varint(20, value)?; + Ok(self) + } + + pub fn java_string_check_utf8(mut self, value: u64) -> crate::Result { + self.builder.write_varint(27, value)?; + Ok(self) + } + + pub fn optimize_for(mut self, value: u64) -> crate::Result { + self.builder.write_varint(9, value)?; + Ok(self) + } + + pub fn go_package(mut self, value: &str) -> crate::Result { + self.builder.write_string(11, value)?; + Ok(self) + } + + pub fn cc_generic_services(mut self, value: u64) -> crate::Result { + self.builder.write_varint(16, value)?; + Ok(self) + } + + pub fn java_generic_services(mut self, value: u64) -> crate::Result { + self.builder.write_varint(17, value)?; + Ok(self) + } + + pub fn py_generic_services(mut self, value: u64) -> crate::Result { + self.builder.write_varint(18, value)?; + Ok(self) + } + + pub fn deprecated(mut self, value: u64) -> crate::Result { + self.builder.write_varint(23, value)?; + Ok(self) + } + + pub fn cc_enable_arenas(mut self, value: u64) -> crate::Result { + self.builder.write_varint(31, value)?; + Ok(self) + } + + pub fn objc_class_prefix(mut self, value: &str) -> crate::Result { + self.builder.write_string(36, value)?; + Ok(self) + } + + pub fn csharp_namespace(mut self, value: &str) -> crate::Result { + self.builder.write_string(37, value)?; + Ok(self) + } + + pub fn swift_prefix(mut self, value: &str) -> crate::Result { + self.builder.write_string(39, value)?; + Ok(self) + } + + pub fn php_class_prefix(mut self, value: &str) -> crate::Result { + self.builder.write_string(40, value)?; + Ok(self) + } + + pub fn php_namespace(mut self, value: &str) -> crate::Result { + self.builder.write_string(41, value)?; + Ok(self) + } + + pub fn php_metadata_namespace(mut self, value: &str) -> crate::Result { + self.builder.write_string(44, value)?; + Ok(self) + } + + pub fn ruby_package(mut self, value: &str) -> crate::Result { + self.builder.write_string(45, value)?; + Ok(self) + } + + pub fn features(mut self, value: &[u8]) -> crate::Result { + self.builder.write_bytes(50, value)?; + Ok(self) + } + + pub fn uninterpreted_option(mut self, value: &[u8]) -> crate::Result { + self.builder.write_bytes(999, value)?; + Ok(self) + } + + pub fn finish(self) -> crate::Result<&'b mut [u8]> { + self.builder.finish() + } +} + +pub mod file_options { +#[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, + } + } +} + +} + +pub struct MessageOptions<'a> { + accessor: crate::ProtoAccessor<'a>, + message_set_wire_format_offset: Option, + no_standard_descriptor_accessor_offset: Option, + deprecated_offset: Option, + map_entry_offset: Option, + deprecated_legacy_json_field_conflicts_offset: Option, + features_offset: Option, + uninterpreted_option_start: Option, + uninterpreted_option_end: Option, +} + +impl<'a> MessageOptions<'a> { + pub fn new(data: &'a [u8]) -> crate::Result { + let accessor = crate::ProtoAccessor::new(data)?; + let mut message_set_wire_format_offset = None; + let mut no_standard_descriptor_accessor_offset = None; + let mut deprecated_offset = None; + let mut map_entry_offset = None; + let mut deprecated_legacy_json_field_conflicts_offset = None; + let mut features_offset = None; + let mut uninterpreted_option_start = None; + 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 == 999 { + 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, + }) + } + + pub fn message_set_wire_format(&self) -> crate::Result { + let offset = self.message_set_wire_format_offset.ok_or(crate::RotoError::FieldNotFound)?; + let (bytes, _) = self.accessor.get_value_at(offset)?; + crate::read_varint(bytes).map(|(v, _)| v != 0).map_err(|_| crate::RotoError::WireFormatViolation) + } + + pub fn no_standard_descriptor_accessor(&self) -> crate::Result { + let offset = self.no_standard_descriptor_accessor_offset.ok_or(crate::RotoError::FieldNotFound)?; + let (bytes, _) = self.accessor.get_value_at(offset)?; + crate::read_varint(bytes).map(|(v, _)| v != 0).map_err(|_| crate::RotoError::WireFormatViolation) + } + + pub fn deprecated(&self) -> crate::Result { + let offset = self.deprecated_offset.ok_or(crate::RotoError::FieldNotFound)?; + let (bytes, _) = self.accessor.get_value_at(offset)?; + crate::read_varint(bytes).map(|(v, _)| v != 0).map_err(|_| crate::RotoError::WireFormatViolation) + } + + pub fn map_entry(&self) -> crate::Result { + let offset = self.map_entry_offset.ok_or(crate::RotoError::FieldNotFound)?; + let (bytes, _) = self.accessor.get_value_at(offset)?; + crate::read_varint(bytes).map(|(v, _)| v != 0).map_err(|_| crate::RotoError::WireFormatViolation) + } + + pub fn deprecated_legacy_json_field_conflicts(&self) -> crate::Result { + let offset = self.deprecated_legacy_json_field_conflicts_offset.ok_or(crate::RotoError::FieldNotFound)?; + let (bytes, _) = self.accessor.get_value_at(offset)?; + crate::read_varint(bytes).map(|(v, _)| v != 0).map_err(|_| crate::RotoError::WireFormatViolation) + } + + pub fn features(&self) -> crate::Result<&'a [u8]> { + let offset = self.features_offset.ok_or(crate::RotoError::FieldNotFound)?; + let (bytes, _) = self.accessor.get_value_at(offset)?; + Ok(bytes) + } + + pub fn uninterpreted_option(&self) -> crate::RepeatedFieldIterator<'a> { + 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), + } + } + +} + +pub struct MessageOptionsBuilder<'b> { + builder: crate::ProtoBuilder<'b>, +} + +impl<'b> MessageOptionsBuilder<'b> { + pub fn builder(buf: &mut [u8]) -> MessageOptionsBuilder<'_> { + MessageOptionsBuilder { + builder: crate::ProtoBuilder::new(buf), + } + } + + pub fn message_set_wire_format(mut self, value: u64) -> crate::Result { + self.builder.write_varint(1, value)?; + Ok(self) + } + + pub fn no_standard_descriptor_accessor(mut self, value: u64) -> crate::Result { + self.builder.write_varint(2, value)?; + Ok(self) + } + + pub fn deprecated(mut self, value: u64) -> crate::Result { + self.builder.write_varint(3, value)?; + Ok(self) + } + + pub fn map_entry(mut self, value: u64) -> crate::Result { + self.builder.write_varint(7, value)?; + Ok(self) + } + + pub fn deprecated_legacy_json_field_conflicts(mut self, value: u64) -> crate::Result { + self.builder.write_varint(11, value)?; + Ok(self) + } + + pub fn features(mut self, value: &[u8]) -> crate::Result { + self.builder.write_bytes(12, value)?; + Ok(self) + } + + pub fn uninterpreted_option(mut self, value: &[u8]) -> crate::Result { + self.builder.write_bytes(999, value)?; + Ok(self) + } + + pub fn finish(self) -> crate::Result<&'b mut [u8]> { + self.builder.finish() + } +} + +pub struct FieldOptions<'a> { + accessor: crate::ProtoAccessor<'a>, + ctype_offset: Option, + packed_offset: Option, + jstype_offset: Option, + lazy_offset: Option, + unverified_lazy_offset: Option, + deprecated_offset: Option, + weak_offset: Option, + debug_redact_offset: Option, + retention_offset: Option, + targets_start: Option, + targets_end: Option, + edition_defaults_start: Option, + edition_defaults_end: Option, + features_offset: Option, + feature_support_offset: Option, + uninterpreted_option_start: Option, + uninterpreted_option_end: Option, +} + +impl<'a> FieldOptions<'a> { + pub fn new(data: &'a [u8]) -> crate::Result { + let accessor = crate::ProtoAccessor::new(data)?; + let mut ctype_offset = None; + let mut packed_offset = None; + let mut jstype_offset = None; + let mut lazy_offset = None; + let mut unverified_lazy_offset = None; + let mut deprecated_offset = None; + let mut weak_offset = None; + let mut debug_redact_offset = None; + let mut retention_offset = None; + let mut targets_start = None; + let mut targets_end = None; + let mut edition_defaults_start = None; + let mut edition_defaults_end = None; + let mut features_offset = None; + let mut feature_support_offset = None; + let mut uninterpreted_option_start = None; + 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 == 19 { + 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); } + 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 == 999 { + 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, + }) + } + + pub fn ctype(&self) -> crate::Result { + let offset = self.ctype_offset.ok_or(crate::RotoError::FieldNotFound)?; + let (bytes, _) = self.accessor.get_value_at(offset)?; + crate::read_varint(bytes).map(|(v, _)| v as u64).map_err(|_| crate::RotoError::WireFormatViolation) + } + + pub fn packed(&self) -> crate::Result { + let offset = self.packed_offset.ok_or(crate::RotoError::FieldNotFound)?; + let (bytes, _) = self.accessor.get_value_at(offset)?; + crate::read_varint(bytes).map(|(v, _)| v != 0).map_err(|_| crate::RotoError::WireFormatViolation) + } + + pub fn jstype(&self) -> crate::Result { + let offset = self.jstype_offset.ok_or(crate::RotoError::FieldNotFound)?; + let (bytes, _) = self.accessor.get_value_at(offset)?; + crate::read_varint(bytes).map(|(v, _)| v as u64).map_err(|_| crate::RotoError::WireFormatViolation) + } + + pub fn lazy(&self) -> crate::Result { + let offset = self.lazy_offset.ok_or(crate::RotoError::FieldNotFound)?; + let (bytes, _) = self.accessor.get_value_at(offset)?; + crate::read_varint(bytes).map(|(v, _)| v != 0).map_err(|_| crate::RotoError::WireFormatViolation) + } + + pub fn unverified_lazy(&self) -> crate::Result { + let offset = self.unverified_lazy_offset.ok_or(crate::RotoError::FieldNotFound)?; + let (bytes, _) = self.accessor.get_value_at(offset)?; + crate::read_varint(bytes).map(|(v, _)| v != 0).map_err(|_| crate::RotoError::WireFormatViolation) + } + + pub fn deprecated(&self) -> crate::Result { + let offset = self.deprecated_offset.ok_or(crate::RotoError::FieldNotFound)?; + let (bytes, _) = self.accessor.get_value_at(offset)?; + crate::read_varint(bytes).map(|(v, _)| v != 0).map_err(|_| crate::RotoError::WireFormatViolation) + } + + pub fn weak(&self) -> crate::Result { + let offset = self.weak_offset.ok_or(crate::RotoError::FieldNotFound)?; + let (bytes, _) = self.accessor.get_value_at(offset)?; + crate::read_varint(bytes).map(|(v, _)| v != 0).map_err(|_| crate::RotoError::WireFormatViolation) + } + + pub fn debug_redact(&self) -> crate::Result { + let offset = self.debug_redact_offset.ok_or(crate::RotoError::FieldNotFound)?; + let (bytes, _) = self.accessor.get_value_at(offset)?; + crate::read_varint(bytes).map(|(v, _)| v != 0).map_err(|_| crate::RotoError::WireFormatViolation) + } + + pub fn retention(&self) -> crate::Result { + let offset = self.retention_offset.ok_or(crate::RotoError::FieldNotFound)?; + let (bytes, _) = self.accessor.get_value_at(offset)?; + crate::read_varint(bytes).map(|(v, _)| v as u64).map_err(|_| crate::RotoError::WireFormatViolation) + } + + pub fn targets(&self) -> crate::RepeatedFieldIterator<'a> { + match (self.targets_start, self.targets_end) { + (Some(start), Some(end)) => self.accessor.iter_repeated_range(19, start, end), + _ => self.accessor.iter_repeated(19), + } + } + + pub fn edition_defaults(&self) -> crate::RepeatedFieldIterator<'a> { + match (self.edition_defaults_start, self.edition_defaults_end) { + (Some(start), Some(end)) => self.accessor.iter_repeated_range(20, start, end), + _ => self.accessor.iter_repeated(20), + } + } + + pub fn features(&self) -> crate::Result<&'a [u8]> { + let offset = self.features_offset.ok_or(crate::RotoError::FieldNotFound)?; + let (bytes, _) = self.accessor.get_value_at(offset)?; + Ok(bytes) + } + + pub fn feature_support(&self) -> crate::Result<&'a [u8]> { + let offset = self.feature_support_offset.ok_or(crate::RotoError::FieldNotFound)?; + let (bytes, _) = self.accessor.get_value_at(offset)?; + Ok(bytes) + } + + pub fn uninterpreted_option(&self) -> crate::RepeatedFieldIterator<'a> { + 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), + } + } + +} + +pub struct FieldOptionsBuilder<'b> { + builder: crate::ProtoBuilder<'b>, +} + +impl<'b> FieldOptionsBuilder<'b> { + pub fn builder(buf: &mut [u8]) -> FieldOptionsBuilder<'_> { + FieldOptionsBuilder { + builder: crate::ProtoBuilder::new(buf), + } + } + + pub fn ctype(mut self, value: u64) -> crate::Result { + self.builder.write_varint(1, value)?; + Ok(self) + } + + pub fn packed(mut self, value: u64) -> crate::Result { + self.builder.write_varint(2, value)?; + Ok(self) + } + + pub fn jstype(mut self, value: u64) -> crate::Result { + self.builder.write_varint(6, value)?; + Ok(self) + } + + pub fn lazy(mut self, value: u64) -> crate::Result { + self.builder.write_varint(5, value)?; + Ok(self) + } + + pub fn unverified_lazy(mut self, value: u64) -> crate::Result { + self.builder.write_varint(15, value)?; + Ok(self) + } + + pub fn deprecated(mut self, value: u64) -> crate::Result { + self.builder.write_varint(3, value)?; + Ok(self) + } + + pub fn weak(mut self, value: u64) -> crate::Result { + self.builder.write_varint(10, value)?; + Ok(self) + } + + pub fn debug_redact(mut self, value: u64) -> crate::Result { + self.builder.write_varint(16, value)?; + Ok(self) + } + + pub fn retention(mut self, value: u64) -> crate::Result { + self.builder.write_varint(17, value)?; + Ok(self) + } + + pub fn targets(mut self, value: u64) -> crate::Result { + self.builder.write_varint(19, value)?; + Ok(self) + } + + pub fn edition_defaults(mut self, value: &[u8]) -> crate::Result { + self.builder.write_bytes(20, value)?; + Ok(self) + } + + pub fn features(mut self, value: &[u8]) -> crate::Result { + self.builder.write_bytes(21, value)?; + Ok(self) + } + + pub fn feature_support(mut self, value: &[u8]) -> crate::Result { + self.builder.write_bytes(22, value)?; + Ok(self) + } + + pub fn uninterpreted_option(mut self, value: &[u8]) -> crate::Result { + self.builder.write_bytes(999, value)?; + Ok(self) + } + + pub fn finish(self) -> crate::Result<&'b mut [u8]> { + self.builder.finish() + } +} + +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::ProtoAccessor<'a>, + edition_offset: Option, + value_offset: Option, +} + +impl<'a> EditionDefault<'a> { + pub fn new(data: &'a [u8]) -> crate::Result { + let accessor = crate::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::Result { + let offset = self.edition_offset.ok_or(crate::RotoError::FieldNotFound)?; + let (bytes, _) = self.accessor.get_value_at(offset)?; + crate::read_varint(bytes).map(|(v, _)| v as u64).map_err(|_| crate::RotoError::WireFormatViolation) + } + + pub fn value(&self) -> crate::Result<&'a str> { + let offset = self.value_offset.ok_or(crate::RotoError::FieldNotFound)?; + let (bytes, _) = self.accessor.get_value_at(offset)?; + str::from_utf8(bytes).map_err(|_| crate::RotoError::WireFormatViolation) + } + +} + +pub struct EditionDefaultBuilder<'b> { + builder: crate::ProtoBuilder<'b>, +} + +impl<'b> EditionDefaultBuilder<'b> { + pub fn builder(buf: &mut [u8]) -> EditionDefaultBuilder<'_> { + EditionDefaultBuilder { + builder: crate::ProtoBuilder::new(buf), + } + } + + pub fn edition(mut self, value: u64) -> crate::Result { + self.builder.write_varint(3, value)?; + Ok(self) + } + + pub fn value(mut self, value: &str) -> crate::Result { + self.builder.write_string(2, value)?; + Ok(self) + } + + pub fn finish(self) -> crate::Result<&'b mut [u8]> { + self.builder.finish() + } +} + +pub struct FeatureSupport<'a> { + accessor: crate::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::Result { + let accessor = crate::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::Result { + let offset = self.edition_introduced_offset.ok_or(crate::RotoError::FieldNotFound)?; + let (bytes, _) = self.accessor.get_value_at(offset)?; + crate::read_varint(bytes).map(|(v, _)| v as u64).map_err(|_| crate::RotoError::WireFormatViolation) + } + + pub fn edition_deprecated(&self) -> crate::Result { + let offset = self.edition_deprecated_offset.ok_or(crate::RotoError::FieldNotFound)?; + let (bytes, _) = self.accessor.get_value_at(offset)?; + crate::read_varint(bytes).map(|(v, _)| v as u64).map_err(|_| crate::RotoError::WireFormatViolation) + } + + pub fn deprecation_warning(&self) -> crate::Result<&'a str> { + let offset = self.deprecation_warning_offset.ok_or(crate::RotoError::FieldNotFound)?; + let (bytes, _) = self.accessor.get_value_at(offset)?; + str::from_utf8(bytes).map_err(|_| crate::RotoError::WireFormatViolation) + } + + pub fn edition_removed(&self) -> crate::Result { + let offset = self.edition_removed_offset.ok_or(crate::RotoError::FieldNotFound)?; + let (bytes, _) = self.accessor.get_value_at(offset)?; + crate::read_varint(bytes).map(|(v, _)| v as u64).map_err(|_| crate::RotoError::WireFormatViolation) + } + + pub fn removal_error(&self) -> crate::Result<&'a str> { + let offset = self.removal_error_offset.ok_or(crate::RotoError::FieldNotFound)?; + let (bytes, _) = self.accessor.get_value_at(offset)?; + str::from_utf8(bytes).map_err(|_| crate::RotoError::WireFormatViolation) + } + +} + +pub struct FeatureSupportBuilder<'b> { + builder: crate::ProtoBuilder<'b>, +} + +impl<'b> FeatureSupportBuilder<'b> { + pub fn builder(buf: &mut [u8]) -> FeatureSupportBuilder<'_> { + FeatureSupportBuilder { + builder: crate::ProtoBuilder::new(buf), + } + } + + pub fn edition_introduced(mut self, value: u64) -> crate::Result { + self.builder.write_varint(1, value)?; + Ok(self) + } + + pub fn edition_deprecated(mut self, value: u64) -> crate::Result { + self.builder.write_varint(2, value)?; + Ok(self) + } + + pub fn deprecation_warning(mut self, value: &str) -> crate::Result { + self.builder.write_string(3, value)?; + Ok(self) + } + + pub fn edition_removed(mut self, value: u64) -> crate::Result { + self.builder.write_varint(4, value)?; + Ok(self) + } + + pub fn removal_error(mut self, value: &str) -> crate::Result { + self.builder.write_string(5, value)?; + Ok(self) + } + + pub fn finish(self) -> crate::Result<&'b mut [u8]> { + self.builder.finish() + } +} + +} + +pub struct OneofOptions<'a> { + accessor: crate::ProtoAccessor<'a>, + features_offset: Option, + uninterpreted_option_start: Option, + uninterpreted_option_end: Option, +} + +impl<'a> OneofOptions<'a> { + pub fn new(data: &'a [u8]) -> crate::Result { + let accessor = crate::ProtoAccessor::new(data)?; + let mut features_offset = None; + let mut uninterpreted_option_start = None; + 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 == 999 { + 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, + }) + } + + pub fn features(&self) -> crate::Result<&'a [u8]> { + let offset = self.features_offset.ok_or(crate::RotoError::FieldNotFound)?; + let (bytes, _) = self.accessor.get_value_at(offset)?; + Ok(bytes) + } + + pub fn uninterpreted_option(&self) -> crate::RepeatedFieldIterator<'a> { + 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), + } + } + +} + +pub struct OneofOptionsBuilder<'b> { + builder: crate::ProtoBuilder<'b>, +} + +impl<'b> OneofOptionsBuilder<'b> { + pub fn builder(buf: &mut [u8]) -> OneofOptionsBuilder<'_> { + OneofOptionsBuilder { + builder: crate::ProtoBuilder::new(buf), + } + } + + pub fn features(mut self, value: &[u8]) -> crate::Result { + self.builder.write_bytes(1, value)?; + Ok(self) + } + + pub fn uninterpreted_option(mut self, value: &[u8]) -> crate::Result { + self.builder.write_bytes(999, value)?; + Ok(self) + } + + pub fn finish(self) -> crate::Result<&'b mut [u8]> { + self.builder.finish() + } +} + +pub struct EnumOptions<'a> { + accessor: crate::ProtoAccessor<'a>, + allow_alias_offset: Option, + deprecated_offset: Option, + deprecated_legacy_json_field_conflicts_offset: Option, + features_offset: Option, + uninterpreted_option_start: Option, + uninterpreted_option_end: Option, +} + +impl<'a> EnumOptions<'a> { + pub fn new(data: &'a [u8]) -> crate::Result { + let accessor = crate::ProtoAccessor::new(data)?; + let mut allow_alias_offset = None; + let mut deprecated_offset = None; + let mut deprecated_legacy_json_field_conflicts_offset = None; + let mut features_offset = None; + let mut uninterpreted_option_start = None; + 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 == 999 { + 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, + }) + } + + pub fn allow_alias(&self) -> crate::Result { + let offset = self.allow_alias_offset.ok_or(crate::RotoError::FieldNotFound)?; + let (bytes, _) = self.accessor.get_value_at(offset)?; + crate::read_varint(bytes).map(|(v, _)| v != 0).map_err(|_| crate::RotoError::WireFormatViolation) + } + + pub fn deprecated(&self) -> crate::Result { + let offset = self.deprecated_offset.ok_or(crate::RotoError::FieldNotFound)?; + let (bytes, _) = self.accessor.get_value_at(offset)?; + crate::read_varint(bytes).map(|(v, _)| v != 0).map_err(|_| crate::RotoError::WireFormatViolation) + } + + pub fn deprecated_legacy_json_field_conflicts(&self) -> crate::Result { + let offset = self.deprecated_legacy_json_field_conflicts_offset.ok_or(crate::RotoError::FieldNotFound)?; + let (bytes, _) = self.accessor.get_value_at(offset)?; + crate::read_varint(bytes).map(|(v, _)| v != 0).map_err(|_| crate::RotoError::WireFormatViolation) + } + + pub fn features(&self) -> crate::Result<&'a [u8]> { + let offset = self.features_offset.ok_or(crate::RotoError::FieldNotFound)?; + let (bytes, _) = self.accessor.get_value_at(offset)?; + Ok(bytes) + } + + pub fn uninterpreted_option(&self) -> crate::RepeatedFieldIterator<'a> { + 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), + } + } + +} + +pub struct EnumOptionsBuilder<'b> { + builder: crate::ProtoBuilder<'b>, +} + +impl<'b> EnumOptionsBuilder<'b> { + pub fn builder(buf: &mut [u8]) -> EnumOptionsBuilder<'_> { + EnumOptionsBuilder { + builder: crate::ProtoBuilder::new(buf), + } + } + + pub fn allow_alias(mut self, value: u64) -> crate::Result { + self.builder.write_varint(2, value)?; + Ok(self) + } + + pub fn deprecated(mut self, value: u64) -> crate::Result { + self.builder.write_varint(3, value)?; + Ok(self) + } + + pub fn deprecated_legacy_json_field_conflicts(mut self, value: u64) -> crate::Result { + self.builder.write_varint(6, value)?; + Ok(self) + } + + pub fn features(mut self, value: &[u8]) -> crate::Result { + self.builder.write_bytes(7, value)?; + Ok(self) + } + + pub fn uninterpreted_option(mut self, value: &[u8]) -> crate::Result { + self.builder.write_bytes(999, value)?; + Ok(self) + } + + pub fn finish(self) -> crate::Result<&'b mut [u8]> { + self.builder.finish() + } +} + +pub struct EnumValueOptions<'a> { + accessor: crate::ProtoAccessor<'a>, + deprecated_offset: Option, + features_offset: Option, + debug_redact_offset: Option, + feature_support_offset: Option, + uninterpreted_option_start: Option, + uninterpreted_option_end: Option, +} + +impl<'a> EnumValueOptions<'a> { + pub fn new(data: &'a [u8]) -> crate::Result { + let accessor = crate::ProtoAccessor::new(data)?; + let mut deprecated_offset = None; + let mut features_offset = None; + let mut debug_redact_offset = None; + let mut feature_support_offset = None; + let mut uninterpreted_option_start = None; + 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 == 999 { + 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, + }) + } + + pub fn deprecated(&self) -> crate::Result { + let offset = self.deprecated_offset.ok_or(crate::RotoError::FieldNotFound)?; + let (bytes, _) = self.accessor.get_value_at(offset)?; + crate::read_varint(bytes).map(|(v, _)| v != 0).map_err(|_| crate::RotoError::WireFormatViolation) + } + + pub fn features(&self) -> crate::Result<&'a [u8]> { + let offset = self.features_offset.ok_or(crate::RotoError::FieldNotFound)?; + let (bytes, _) = self.accessor.get_value_at(offset)?; + Ok(bytes) + } + + pub fn debug_redact(&self) -> crate::Result { + let offset = self.debug_redact_offset.ok_or(crate::RotoError::FieldNotFound)?; + let (bytes, _) = self.accessor.get_value_at(offset)?; + crate::read_varint(bytes).map(|(v, _)| v != 0).map_err(|_| crate::RotoError::WireFormatViolation) + } + + pub fn feature_support(&self) -> crate::Result<&'a [u8]> { + let offset = self.feature_support_offset.ok_or(crate::RotoError::FieldNotFound)?; + let (bytes, _) = self.accessor.get_value_at(offset)?; + Ok(bytes) + } + + pub fn uninterpreted_option(&self) -> crate::RepeatedFieldIterator<'a> { + 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), + } + } + +} + +pub struct EnumValueOptionsBuilder<'b> { + builder: crate::ProtoBuilder<'b>, +} + +impl<'b> EnumValueOptionsBuilder<'b> { + pub fn builder(buf: &mut [u8]) -> EnumValueOptionsBuilder<'_> { + EnumValueOptionsBuilder { + builder: crate::ProtoBuilder::new(buf), + } + } + + pub fn deprecated(mut self, value: u64) -> crate::Result { + self.builder.write_varint(1, value)?; + Ok(self) + } + + pub fn features(mut self, value: &[u8]) -> crate::Result { + self.builder.write_bytes(2, value)?; + Ok(self) + } + + pub fn debug_redact(mut self, value: u64) -> crate::Result { + self.builder.write_varint(3, value)?; + Ok(self) + } + + pub fn feature_support(mut self, value: &[u8]) -> crate::Result { + self.builder.write_bytes(4, value)?; + Ok(self) + } + + pub fn uninterpreted_option(mut self, value: &[u8]) -> crate::Result { + self.builder.write_bytes(999, value)?; + Ok(self) + } + + pub fn finish(self) -> crate::Result<&'b mut [u8]> { + self.builder.finish() + } +} + +pub struct ServiceOptions<'a> { + accessor: crate::ProtoAccessor<'a>, + features_offset: Option, + deprecated_offset: Option, + uninterpreted_option_start: Option, + uninterpreted_option_end: Option, +} + +impl<'a> ServiceOptions<'a> { + pub fn new(data: &'a [u8]) -> crate::Result { + let accessor = crate::ProtoAccessor::new(data)?; + let mut features_offset = None; + let mut deprecated_offset = None; + let mut uninterpreted_option_start = None; + 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 == 999 { + 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, + }) + } + + pub fn features(&self) -> crate::Result<&'a [u8]> { + let offset = self.features_offset.ok_or(crate::RotoError::FieldNotFound)?; + let (bytes, _) = self.accessor.get_value_at(offset)?; + Ok(bytes) + } + + pub fn deprecated(&self) -> crate::Result { + let offset = self.deprecated_offset.ok_or(crate::RotoError::FieldNotFound)?; + let (bytes, _) = self.accessor.get_value_at(offset)?; + crate::read_varint(bytes).map(|(v, _)| v != 0).map_err(|_| crate::RotoError::WireFormatViolation) + } + + pub fn uninterpreted_option(&self) -> crate::RepeatedFieldIterator<'a> { + 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), + } + } + +} + +pub struct ServiceOptionsBuilder<'b> { + builder: crate::ProtoBuilder<'b>, +} + +impl<'b> ServiceOptionsBuilder<'b> { + pub fn builder(buf: &mut [u8]) -> ServiceOptionsBuilder<'_> { + ServiceOptionsBuilder { + builder: crate::ProtoBuilder::new(buf), + } + } + + pub fn features(mut self, value: &[u8]) -> crate::Result { + self.builder.write_bytes(34, value)?; + Ok(self) + } + + pub fn deprecated(mut self, value: u64) -> crate::Result { + self.builder.write_varint(33, value)?; + Ok(self) + } + + pub fn uninterpreted_option(mut self, value: &[u8]) -> crate::Result { + self.builder.write_bytes(999, value)?; + Ok(self) + } + + pub fn finish(self) -> crate::Result<&'b mut [u8]> { + self.builder.finish() + } +} + +pub struct MethodOptions<'a> { + accessor: crate::ProtoAccessor<'a>, + deprecated_offset: Option, + idempotency_level_offset: Option, + features_offset: Option, + uninterpreted_option_start: Option, + uninterpreted_option_end: Option, +} + +impl<'a> MethodOptions<'a> { + pub fn new(data: &'a [u8]) -> crate::Result { + let accessor = crate::ProtoAccessor::new(data)?; + let mut deprecated_offset = None; + let mut idempotency_level_offset = None; + let mut features_offset = None; + let mut uninterpreted_option_start = None; + 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 == 999 { + 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, + }) + } + + pub fn deprecated(&self) -> crate::Result { + let offset = self.deprecated_offset.ok_or(crate::RotoError::FieldNotFound)?; + let (bytes, _) = self.accessor.get_value_at(offset)?; + crate::read_varint(bytes).map(|(v, _)| v != 0).map_err(|_| crate::RotoError::WireFormatViolation) + } + + pub fn idempotency_level(&self) -> crate::Result { + let offset = self.idempotency_level_offset.ok_or(crate::RotoError::FieldNotFound)?; + let (bytes, _) = self.accessor.get_value_at(offset)?; + crate::read_varint(bytes).map(|(v, _)| v as u64).map_err(|_| crate::RotoError::WireFormatViolation) + } + + pub fn features(&self) -> crate::Result<&'a [u8]> { + let offset = self.features_offset.ok_or(crate::RotoError::FieldNotFound)?; + let (bytes, _) = self.accessor.get_value_at(offset)?; + Ok(bytes) + } + + pub fn uninterpreted_option(&self) -> crate::RepeatedFieldIterator<'a> { + 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), + } + } + +} + +pub struct MethodOptionsBuilder<'b> { + builder: crate::ProtoBuilder<'b>, +} + +impl<'b> MethodOptionsBuilder<'b> { + pub fn builder(buf: &mut [u8]) -> MethodOptionsBuilder<'_> { + MethodOptionsBuilder { + builder: crate::ProtoBuilder::new(buf), + } + } + + pub fn deprecated(mut self, value: u64) -> crate::Result { + self.builder.write_varint(33, value)?; + Ok(self) + } + + pub fn idempotency_level(mut self, value: u64) -> crate::Result { + self.builder.write_varint(34, value)?; + Ok(self) + } + + pub fn features(mut self, value: &[u8]) -> crate::Result { + self.builder.write_bytes(35, value)?; + Ok(self) + } + + pub fn uninterpreted_option(mut self, value: &[u8]) -> crate::Result { + self.builder.write_bytes(999, value)?; + Ok(self) + } + + pub fn finish(self) -> crate::Result<&'b mut [u8]> { + self.builder.finish() + } +} + +pub mod method_options { +#[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, + } + } +} + +} + +pub struct UninterpretedOption<'a> { + accessor: crate::ProtoAccessor<'a>, + name_start: Option, + name_end: Option, + identifier_value_offset: Option, + positive_int_value_offset: Option, + negative_int_value_offset: Option, + double_value_offset: Option, + string_value_offset: Option, + aggregate_value_offset: Option, +} + +impl<'a> UninterpretedOption<'a> { + pub fn new(data: &'a [u8]) -> crate::Result { + let accessor = crate::ProtoAccessor::new(data)?; + let mut name_start = None; + let mut name_end = None; + let mut identifier_value_offset = None; + let mut positive_int_value_offset = None; + let mut negative_int_value_offset = None; + let mut double_value_offset = None; + let mut string_value_offset = None; + let mut aggregate_value_offset = None; + for item in accessor.fields() { + let (offset, tag, _) = item?; + if tag.field_number == 2 { + 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); } + } + + 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, + }) + } + + pub fn name(&self) -> crate::RepeatedFieldIterator<'a> { + match (self.name_start, self.name_end) { + (Some(start), Some(end)) => self.accessor.iter_repeated_range(2, start, end), + _ => self.accessor.iter_repeated(2), + } + } + + pub fn identifier_value(&self) -> crate::Result<&'a str> { + let offset = self.identifier_value_offset.ok_or(crate::RotoError::FieldNotFound)?; + let (bytes, _) = self.accessor.get_value_at(offset)?; + str::from_utf8(bytes).map_err(|_| crate::RotoError::WireFormatViolation) + } + + pub fn positive_int_value(&self) -> crate::Result { + let offset = self.positive_int_value_offset.ok_or(crate::RotoError::FieldNotFound)?; + let (bytes, _) = self.accessor.get_value_at(offset)?; + crate::read_varint(bytes).map(|(v, _)| v as u32).map_err(|_| crate::RotoError::WireFormatViolation) + } + + pub fn negative_int_value(&self) -> crate::Result { + let offset = self.negative_int_value_offset.ok_or(crate::RotoError::FieldNotFound)?; + let (bytes, _) = self.accessor.get_value_at(offset)?; + crate::read_varint(bytes).map(|(v, _)| v as i32).map_err(|_| crate::RotoError::WireFormatViolation) + } + + pub fn double_value(&self) -> crate::Result { + let offset = self.double_value_offset.ok_or(crate::RotoError::FieldNotFound)?; + let (bytes, _) = self.accessor.get_value_at(offset)?; + Ok(f64::from_le_bytes(bytes.try_into().map_err(|_| crate::RotoError::WireFormatViolation)?)) + } + + pub fn string_value(&self) -> crate::Result<&'a [u8]> { + let offset = self.string_value_offset.ok_or(crate::RotoError::FieldNotFound)?; + let (bytes, _) = self.accessor.get_value_at(offset)?; + Ok(bytes) + } + + pub fn aggregate_value(&self) -> crate::Result<&'a str> { + let offset = self.aggregate_value_offset.ok_or(crate::RotoError::FieldNotFound)?; + let (bytes, _) = self.accessor.get_value_at(offset)?; + str::from_utf8(bytes).map_err(|_| crate::RotoError::WireFormatViolation) + } + +} + +pub struct UninterpretedOptionBuilder<'b> { + builder: crate::ProtoBuilder<'b>, +} + +impl<'b> UninterpretedOptionBuilder<'b> { + pub fn builder(buf: &mut [u8]) -> UninterpretedOptionBuilder<'_> { + UninterpretedOptionBuilder { + builder: crate::ProtoBuilder::new(buf), + } + } + + pub fn name(mut self, value: &[u8]) -> crate::Result { + self.builder.write_bytes(2, value)?; + Ok(self) + } + + pub fn identifier_value(mut self, value: &str) -> crate::Result { + self.builder.write_string(3, value)?; + Ok(self) + } + + pub fn positive_int_value(mut self, value: u64) -> crate::Result { + self.builder.write_varint(4, value)?; + Ok(self) + } + + pub fn negative_int_value(mut self, value: u64) -> crate::Result { + self.builder.write_varint(5, value)?; + Ok(self) + } + + pub fn double_value(mut self, value: &[u8]) -> crate::Result { + self.builder.write_bytes(6, value)?; + Ok(self) + } + + pub fn string_value(mut self, value: &[u8]) -> crate::Result { + self.builder.write_bytes(7, value)?; + Ok(self) + } + + pub fn aggregate_value(mut self, value: &str) -> crate::Result { + self.builder.write_string(8, value)?; + Ok(self) + } + + pub fn finish(self) -> crate::Result<&'b mut [u8]> { + self.builder.finish() + } +} + +pub mod uninterpreted_option { +pub struct NamePart<'a> { + accessor: crate::ProtoAccessor<'a>, + name_part_offset: Option, + is_extension_offset: Option, +} + +impl<'a> NamePart<'a> { + pub fn new(data: &'a [u8]) -> crate::Result { + let accessor = crate::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, + }) + } + + pub fn name_part(&self) -> crate::Result<&'a str> { + let offset = self.name_part_offset.ok_or(crate::RotoError::FieldNotFound)?; + let (bytes, _) = self.accessor.get_value_at(offset)?; + str::from_utf8(bytes).map_err(|_| crate::RotoError::WireFormatViolation) + } + + pub fn is_extension(&self) -> crate::Result { + let offset = self.is_extension_offset.ok_or(crate::RotoError::FieldNotFound)?; + let (bytes, _) = self.accessor.get_value_at(offset)?; + crate::read_varint(bytes).map(|(v, _)| v != 0).map_err(|_| crate::RotoError::WireFormatViolation) + } + +} + +pub struct NamePartBuilder<'b> { + builder: crate::ProtoBuilder<'b>, +} + +impl<'b> NamePartBuilder<'b> { + pub fn builder(buf: &mut [u8]) -> NamePartBuilder<'_> { + NamePartBuilder { + builder: crate::ProtoBuilder::new(buf), + } + } + + pub fn name_part(mut self, value: &str) -> crate::Result { + self.builder.write_string(1, value)?; + Ok(self) + } + + pub fn is_extension(mut self, value: u64) -> crate::Result { + self.builder.write_varint(2, value)?; + Ok(self) + } + + pub fn finish(self) -> crate::Result<&'b mut [u8]> { + self.builder.finish() + } +} + +} + +pub struct FeatureSet<'a> { + accessor: crate::ProtoAccessor<'a>, + field_presence_offset: Option, + enum_type_offset: Option, + repeated_field_encoding_offset: Option, + utf8_validation_offset: Option, + message_encoding_offset: Option, + json_format_offset: Option, + enforce_naming_style_offset: Option, + default_symbol_visibility_offset: Option, + enforce_proto_limits_offset: Option, +} + +impl<'a> FeatureSet<'a> { + pub fn new(data: &'a [u8]) -> crate::Result { + let accessor = crate::ProtoAccessor::new(data)?; + let mut field_presence_offset = None; + let mut enum_type_offset = None; + let mut repeated_field_encoding_offset = None; + let mut utf8_validation_offset = None; + let mut message_encoding_offset = None; + let mut json_format_offset = None; + let mut enforce_naming_style_offset = None; + let mut default_symbol_visibility_offset = None; + 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); } + } + + 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, + }) + } + + pub fn field_presence(&self) -> crate::Result { + let offset = self.field_presence_offset.ok_or(crate::RotoError::FieldNotFound)?; + let (bytes, _) = self.accessor.get_value_at(offset)?; + crate::read_varint(bytes).map(|(v, _)| v as u64).map_err(|_| crate::RotoError::WireFormatViolation) + } + + pub fn enum_type(&self) -> crate::Result { + let offset = self.enum_type_offset.ok_or(crate::RotoError::FieldNotFound)?; + let (bytes, _) = self.accessor.get_value_at(offset)?; + crate::read_varint(bytes).map(|(v, _)| v as u64).map_err(|_| crate::RotoError::WireFormatViolation) + } + + pub fn repeated_field_encoding(&self) -> crate::Result { + let offset = self.repeated_field_encoding_offset.ok_or(crate::RotoError::FieldNotFound)?; + let (bytes, _) = self.accessor.get_value_at(offset)?; + crate::read_varint(bytes).map(|(v, _)| v as u64).map_err(|_| crate::RotoError::WireFormatViolation) + } + + pub fn utf8_validation(&self) -> crate::Result { + let offset = self.utf8_validation_offset.ok_or(crate::RotoError::FieldNotFound)?; + let (bytes, _) = self.accessor.get_value_at(offset)?; + crate::read_varint(bytes).map(|(v, _)| v as u64).map_err(|_| crate::RotoError::WireFormatViolation) + } + + pub fn message_encoding(&self) -> crate::Result { + let offset = self.message_encoding_offset.ok_or(crate::RotoError::FieldNotFound)?; + let (bytes, _) = self.accessor.get_value_at(offset)?; + crate::read_varint(bytes).map(|(v, _)| v as u64).map_err(|_| crate::RotoError::WireFormatViolation) + } + + pub fn json_format(&self) -> crate::Result { + let offset = self.json_format_offset.ok_or(crate::RotoError::FieldNotFound)?; + let (bytes, _) = self.accessor.get_value_at(offset)?; + crate::read_varint(bytes).map(|(v, _)| v as u64).map_err(|_| crate::RotoError::WireFormatViolation) + } + + pub fn enforce_naming_style(&self) -> crate::Result { + let offset = self.enforce_naming_style_offset.ok_or(crate::RotoError::FieldNotFound)?; + let (bytes, _) = self.accessor.get_value_at(offset)?; + crate::read_varint(bytes).map(|(v, _)| v as u64).map_err(|_| crate::RotoError::WireFormatViolation) + } + + pub fn default_symbol_visibility(&self) -> crate::Result { + let offset = self.default_symbol_visibility_offset.ok_or(crate::RotoError::FieldNotFound)?; + let (bytes, _) = self.accessor.get_value_at(offset)?; + crate::read_varint(bytes).map(|(v, _)| v as u64).map_err(|_| crate::RotoError::WireFormatViolation) + } + + pub fn enforce_proto_limits(&self) -> crate::Result { + let offset = self.enforce_proto_limits_offset.ok_or(crate::RotoError::FieldNotFound)?; + let (bytes, _) = self.accessor.get_value_at(offset)?; + crate::read_varint(bytes).map(|(v, _)| v as u64).map_err(|_| crate::RotoError::WireFormatViolation) + } + +} + +pub struct FeatureSetBuilder<'b> { + builder: crate::ProtoBuilder<'b>, +} + +impl<'b> FeatureSetBuilder<'b> { + pub fn builder(buf: &mut [u8]) -> FeatureSetBuilder<'_> { + FeatureSetBuilder { + builder: crate::ProtoBuilder::new(buf), + } + } + + pub fn field_presence(mut self, value: u64) -> crate::Result { + self.builder.write_varint(1, value)?; + Ok(self) + } + + pub fn enum_type(mut self, value: u64) -> crate::Result { + self.builder.write_varint(2, value)?; + Ok(self) + } + + pub fn repeated_field_encoding(mut self, value: u64) -> crate::Result { + self.builder.write_varint(3, value)?; + Ok(self) + } + + pub fn utf8_validation(mut self, value: u64) -> crate::Result { + self.builder.write_varint(4, value)?; + Ok(self) + } + + pub fn message_encoding(mut self, value: u64) -> crate::Result { + self.builder.write_varint(5, value)?; + Ok(self) + } + + pub fn json_format(mut self, value: u64) -> crate::Result { + self.builder.write_varint(6, value)?; + Ok(self) + } + + pub fn enforce_naming_style(mut self, value: u64) -> crate::Result { + self.builder.write_varint(7, value)?; + Ok(self) + } + + pub fn default_symbol_visibility(mut self, value: u64) -> crate::Result { + self.builder.write_varint(8, value)?; + Ok(self) + } + + pub fn enforce_proto_limits(mut self, value: u64) -> crate::Result { + self.builder.write_varint(9, value)?; + Ok(self) + } + + pub fn finish(self) -> crate::Result<&'b mut [u8]> { + self.builder.finish() + } +} + +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::ProtoAccessor<'a>, +} + +impl<'a> VisibilityFeature<'a> { + pub fn new(data: &'a [u8]) -> crate::Result { + let accessor = crate::ProtoAccessor::new(data)?; + for item in accessor.fields() { + let (offset, tag, _) = item?; + } + + Ok(Self { + accessor, + }) + } + +} + +pub struct VisibilityFeatureBuilder<'b> { + builder: crate::ProtoBuilder<'b>, +} + +impl<'b> VisibilityFeatureBuilder<'b> { + pub fn builder(buf: &mut [u8]) -> VisibilityFeatureBuilder<'_> { + VisibilityFeatureBuilder { + builder: crate::ProtoBuilder::new(buf), + } + } + + pub fn finish(self) -> crate::Result<&'b mut [u8]> { + self.builder.finish() + } +} + +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::ProtoAccessor<'a>, +} + +impl<'a> ProtoLimitsFeature<'a> { + pub fn new(data: &'a [u8]) -> crate::Result { + let accessor = crate::ProtoAccessor::new(data)?; + for item in accessor.fields() { + let (offset, tag, _) = item?; + } + + Ok(Self { + accessor, + }) + } + +} + +pub struct ProtoLimitsFeatureBuilder<'b> { + builder: crate::ProtoBuilder<'b>, +} + +impl<'b> ProtoLimitsFeatureBuilder<'b> { + pub fn builder(buf: &mut [u8]) -> ProtoLimitsFeatureBuilder<'_> { + ProtoLimitsFeatureBuilder { + builder: crate::ProtoBuilder::new(buf), + } + } + + pub fn finish(self) -> crate::Result<&'b mut [u8]> { + self.builder.finish() + } +} + +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> { + accessor: crate::ProtoAccessor<'a>, + defaults_start: Option, + defaults_end: Option, + minimum_edition_offset: Option, + maximum_edition_offset: Option, +} + +impl<'a> FeatureSetDefaults<'a> { + pub fn new(data: &'a [u8]) -> crate::Result { + let accessor = crate::ProtoAccessor::new(data)?; + let mut defaults_start = None; + let mut defaults_end = None; + let mut minimum_edition_offset = None; + let mut maximum_edition_offset = None; + for item in accessor.fields() { + let (offset, tag, _) = item?; + if tag.field_number == 1 { + 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); } + } + + Ok(Self { + accessor, +defaults_start, defaults_end, +minimum_edition_offset, +maximum_edition_offset, + }) + } + + pub fn defaults(&self) -> crate::RepeatedFieldIterator<'a> { + match (self.defaults_start, self.defaults_end) { + (Some(start), Some(end)) => self.accessor.iter_repeated_range(1, start, end), + _ => self.accessor.iter_repeated(1), + } + } + + pub fn minimum_edition(&self) -> crate::Result { + let offset = self.minimum_edition_offset.ok_or(crate::RotoError::FieldNotFound)?; + let (bytes, _) = self.accessor.get_value_at(offset)?; + crate::read_varint(bytes).map(|(v, _)| v as u64).map_err(|_| crate::RotoError::WireFormatViolation) + } + + pub fn maximum_edition(&self) -> crate::Result { + let offset = self.maximum_edition_offset.ok_or(crate::RotoError::FieldNotFound)?; + let (bytes, _) = self.accessor.get_value_at(offset)?; + crate::read_varint(bytes).map(|(v, _)| v as u64).map_err(|_| crate::RotoError::WireFormatViolation) + } + +} + +pub struct FeatureSetDefaultsBuilder<'b> { + builder: crate::ProtoBuilder<'b>, +} + +impl<'b> FeatureSetDefaultsBuilder<'b> { + pub fn builder(buf: &mut [u8]) -> FeatureSetDefaultsBuilder<'_> { + FeatureSetDefaultsBuilder { + builder: crate::ProtoBuilder::new(buf), + } + } + + pub fn defaults(mut self, value: &[u8]) -> crate::Result { + self.builder.write_bytes(1, value)?; + Ok(self) + } + + pub fn minimum_edition(mut self, value: u64) -> crate::Result { + self.builder.write_varint(4, value)?; + Ok(self) + } + + pub fn maximum_edition(mut self, value: u64) -> crate::Result { + self.builder.write_varint(5, value)?; + Ok(self) + } + + pub fn finish(self) -> crate::Result<&'b mut [u8]> { + self.builder.finish() + } +} + +pub mod feature_set_defaults { +pub struct FeatureSetEditionDefault<'a> { + accessor: crate::ProtoAccessor<'a>, + edition_offset: Option, + overridable_features_offset: Option, + fixed_features_offset: Option, +} + +impl<'a> FeatureSetEditionDefault<'a> { + pub fn new(data: &'a [u8]) -> crate::Result { + let accessor = crate::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, + }) + } + + pub fn edition(&self) -> crate::Result { + let offset = self.edition_offset.ok_or(crate::RotoError::FieldNotFound)?; + let (bytes, _) = self.accessor.get_value_at(offset)?; + crate::read_varint(bytes).map(|(v, _)| v as u64).map_err(|_| crate::RotoError::WireFormatViolation) + } + + pub fn overridable_features(&self) -> crate::Result<&'a [u8]> { + let offset = self.overridable_features_offset.ok_or(crate::RotoError::FieldNotFound)?; + let (bytes, _) = self.accessor.get_value_at(offset)?; + Ok(bytes) + } + + pub fn fixed_features(&self) -> crate::Result<&'a [u8]> { + let offset = self.fixed_features_offset.ok_or(crate::RotoError::FieldNotFound)?; + let (bytes, _) = self.accessor.get_value_at(offset)?; + Ok(bytes) + } + +} + +pub struct FeatureSetEditionDefaultBuilder<'b> { + builder: crate::ProtoBuilder<'b>, +} + +impl<'b> FeatureSetEditionDefaultBuilder<'b> { + pub fn builder(buf: &mut [u8]) -> FeatureSetEditionDefaultBuilder<'_> { + FeatureSetEditionDefaultBuilder { + builder: crate::ProtoBuilder::new(buf), + } + } + + pub fn edition(mut self, value: u64) -> crate::Result { + self.builder.write_varint(3, value)?; + Ok(self) + } + + pub fn overridable_features(mut self, value: &[u8]) -> crate::Result { + self.builder.write_bytes(4, value)?; + Ok(self) + } + + pub fn fixed_features(mut self, value: &[u8]) -> crate::Result { + self.builder.write_bytes(5, value)?; + Ok(self) + } + + pub fn finish(self) -> crate::Result<&'b mut [u8]> { + self.builder.finish() + } +} + +} + +pub struct SourceCodeInfo<'a> { + accessor: crate::ProtoAccessor<'a>, + location_start: Option, + location_end: Option, +} + +impl<'a> SourceCodeInfo<'a> { + pub fn new(data: &'a [u8]) -> crate::Result { + let accessor = crate::ProtoAccessor::new(data)?; + let mut location_start = None; + let mut location_end = None; + for item in accessor.fields() { + let (offset, tag, _) = item?; + if tag.field_number == 1 { + if location_start.is_none() { location_start = Some(offset); } + location_end = Some(offset); + } + } + + Ok(Self { + accessor, +location_start, location_end, + }) + } + + pub fn location(&self) -> crate::RepeatedFieldIterator<'a> { + match (self.location_start, self.location_end) { + (Some(start), Some(end)) => self.accessor.iter_repeated_range(1, start, end), + _ => self.accessor.iter_repeated(1), + } + } + +} + +pub struct SourceCodeInfoBuilder<'b> { + builder: crate::ProtoBuilder<'b>, +} + +impl<'b> SourceCodeInfoBuilder<'b> { + pub fn builder(buf: &mut [u8]) -> SourceCodeInfoBuilder<'_> { + SourceCodeInfoBuilder { + builder: crate::ProtoBuilder::new(buf), + } + } + + pub fn location(mut self, value: &[u8]) -> crate::Result { + self.builder.write_bytes(1, value)?; + Ok(self) + } + + pub fn finish(self) -> crate::Result<&'b mut [u8]> { + self.builder.finish() + } +} + +pub mod source_code_info { +pub struct Location<'a> { + accessor: crate::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::Result { + let accessor = crate::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); + } + } + + 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::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::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::Result<&'a str> { + let offset = self.leading_comments_offset.ok_or(crate::RotoError::FieldNotFound)?; + let (bytes, _) = self.accessor.get_value_at(offset)?; + str::from_utf8(bytes).map_err(|_| crate::RotoError::WireFormatViolation) + } + + pub fn trailing_comments(&self) -> crate::Result<&'a str> { + let offset = self.trailing_comments_offset.ok_or(crate::RotoError::FieldNotFound)?; + let (bytes, _) = self.accessor.get_value_at(offset)?; + str::from_utf8(bytes).map_err(|_| crate::RotoError::WireFormatViolation) + } + + pub fn leading_detached_comments(&self) -> crate::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 struct LocationBuilder<'b> { + builder: crate::ProtoBuilder<'b>, +} + +impl<'b> LocationBuilder<'b> { + pub fn builder(buf: &mut [u8]) -> LocationBuilder<'_> { + LocationBuilder { + builder: crate::ProtoBuilder::new(buf), + } + } + + pub fn path(mut self, value: i32) -> crate::Result { + self.builder.write_int32(1, value)?; + Ok(self) + } + + pub fn span(mut self, value: i32) -> crate::Result { + self.builder.write_int32(2, value)?; + Ok(self) + } + + pub fn leading_comments(mut self, value: &str) -> crate::Result { + self.builder.write_string(3, value)?; + Ok(self) + } + + pub fn trailing_comments(mut self, value: &str) -> crate::Result { + self.builder.write_string(4, value)?; + Ok(self) + } + + pub fn leading_detached_comments(mut self, value: &str) -> crate::Result { + self.builder.write_string(6, value)?; + Ok(self) + } + + pub fn finish(self) -> crate::Result<&'b mut [u8]> { + self.builder.finish() + } +} + +} + +pub struct GeneratedCodeInfo<'a> { + accessor: crate::ProtoAccessor<'a>, + annotation_start: Option, + annotation_end: Option, +} + +impl<'a> GeneratedCodeInfo<'a> { + pub fn new(data: &'a [u8]) -> crate::Result { + let accessor = crate::ProtoAccessor::new(data)?; + let mut annotation_start = None; + let mut annotation_end = None; + for item in accessor.fields() { + let (offset, tag, _) = item?; + if tag.field_number == 1 { + if annotation_start.is_none() { annotation_start = Some(offset); } + annotation_end = Some(offset); + } + } + + Ok(Self { + accessor, +annotation_start, annotation_end, + }) + } + + pub fn annotation(&self) -> crate::RepeatedFieldIterator<'a> { + match (self.annotation_start, self.annotation_end) { + (Some(start), Some(end)) => self.accessor.iter_repeated_range(1, start, end), + _ => self.accessor.iter_repeated(1), + } + } + +} + +pub struct GeneratedCodeInfoBuilder<'b> { + builder: crate::ProtoBuilder<'b>, +} + +impl<'b> GeneratedCodeInfoBuilder<'b> { + pub fn builder(buf: &mut [u8]) -> GeneratedCodeInfoBuilder<'_> { + GeneratedCodeInfoBuilder { + builder: crate::ProtoBuilder::new(buf), + } + } + + pub fn annotation(mut self, value: &[u8]) -> crate::Result { + self.builder.write_bytes(1, value)?; + Ok(self) + } + + pub fn finish(self) -> crate::Result<&'b mut [u8]> { + self.builder.finish() + } +} + +pub mod generated_code_info { +pub struct Annotation<'a> { + accessor: crate::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::Result { + let accessor = crate::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); } + } + + Ok(Self { + accessor, +path_start, path_end, +source_file_offset, +begin_offset, +end_offset, +semantic_offset, + }) + } + + pub fn path(&self) -> crate::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::Result<&'a str> { + let offset = self.source_file_offset.ok_or(crate::RotoError::FieldNotFound)?; + let (bytes, _) = self.accessor.get_value_at(offset)?; + str::from_utf8(bytes).map_err(|_| crate::RotoError::WireFormatViolation) + } + + pub fn begin(&self) -> crate::Result { + let offset = self.begin_offset.ok_or(crate::RotoError::FieldNotFound)?; + let (bytes, _) = self.accessor.get_value_at(offset)?; + crate::read_varint(bytes).map(|(v, _)| v as i32).map_err(|_| crate::RotoError::WireFormatViolation) + } + + pub fn end(&self) -> crate::Result { + let offset = self.end_offset.ok_or(crate::RotoError::FieldNotFound)?; + let (bytes, _) = self.accessor.get_value_at(offset)?; + crate::read_varint(bytes).map(|(v, _)| v as i32).map_err(|_| crate::RotoError::WireFormatViolation) + } + + pub fn semantic(&self) -> crate::Result { + let offset = self.semantic_offset.ok_or(crate::RotoError::FieldNotFound)?; + let (bytes, _) = self.accessor.get_value_at(offset)?; + crate::read_varint(bytes).map(|(v, _)| v as u64).map_err(|_| crate::RotoError::WireFormatViolation) + } + +} + +pub struct AnnotationBuilder<'b> { + builder: crate::ProtoBuilder<'b>, +} + +impl<'b> AnnotationBuilder<'b> { + pub fn builder(buf: &mut [u8]) -> AnnotationBuilder<'_> { + AnnotationBuilder { + builder: crate::ProtoBuilder::new(buf), + } + } + + pub fn path(mut self, value: i32) -> crate::Result { + self.builder.write_int32(1, value)?; + Ok(self) + } + + pub fn source_file(mut self, value: &str) -> crate::Result { + self.builder.write_string(2, value)?; + Ok(self) + } + + pub fn begin(mut self, value: i32) -> crate::Result { + self.builder.write_int32(3, value)?; + Ok(self) + } + + pub fn end(mut self, value: i32) -> crate::Result { + self.builder.write_int32(4, value)?; + Ok(self) + } + + pub fn semantic(mut self, value: u64) -> crate::Result { + self.builder.write_varint(5, value)?; + Ok(self) + } + + pub fn finish(self) -> crate::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, +} + +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/src/google/protobuf/mod.rs b/src/google/protobuf/mod.rs new file mode 100644 index 0000000..e4b3346 --- /dev/null +++ b/src/google/protobuf/mod.rs @@ -0,0 +1,2 @@ +pub mod compiler; +pub mod descriptor; diff --git a/src/lib.rs b/src/lib.rs index 5f18759..0bb962f 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1,6 +1,6 @@ pub mod proto_gen; pub mod generator; -// pub mod google; +pub mod google; // Uncomment this to check if the code compiles // #[path = "../proto/google/protobuf/descriptor.rs"] // pub mod descriptor;