From 6ac13ff43e40adca36d40b69da0d96de3be86c4b Mon Sep 17 00:00:00 2001 From: openhands Date: Tue, 26 May 2026 05:11:41 +0000 Subject: [PATCH] Make code generator self-contained by integrating runtime support --- Cargo.lock | 1 - codegen/Cargo.toml | 2 +- codegen/src/bin/protoc-gen-roto.rs | 4 +- codegen/src/generator/messages.rs | 6 +- codegen/src/generator/mod.rs | 6 +- .../src/google/protobuf/compiler/plugin.rs | 242 +- codegen/src/google/protobuf/descriptor.rs | 2248 ++++++++--------- codegen/src/lib.rs | 2 + codegen/src/runtime/mod.rs | 921 +++++++ 9 files changed, 2177 insertions(+), 1255 deletions(-) create mode 100644 codegen/src/runtime/mod.rs diff --git a/Cargo.lock b/Cargo.lock index 0485d4b..56c9fe8 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1186,7 +1186,6 @@ dependencies = [ "http-body", "http-body-util", "log", - "roto-runtime", "roto-tonic", "tokio-stream", "tonic", diff --git a/codegen/Cargo.toml b/codegen/Cargo.toml index f10c40c..c3b457b 100644 --- a/codegen/Cargo.toml +++ b/codegen/Cargo.toml @@ -4,7 +4,7 @@ version = "0.1.0" edition = "2024" [dependencies] -roto-runtime = { path = "../runtime" } + roto-tonic = { path = "../roto-tonic" } clap = { version = "4", features = ["derive"] } log = "0.4" diff --git a/codegen/src/bin/protoc-gen-roto.rs b/codegen/src/bin/protoc-gen-roto.rs index 444aedf..02a26b6 100644 --- a/codegen/src/bin/protoc-gen-roto.rs +++ b/codegen/src/bin/protoc-gen-roto.rs @@ -5,7 +5,7 @@ use roto_codegen::google::protobuf::compiler::plugin::{ CodeGeneratorRequest, CodeGeneratorResponseBuilder, code_generator_response::FileBuilder, }; use roto_codegen::google::protobuf::descriptor::FileDescriptorSet; -// use roto_runtime::ProtoBuilder; +// use roto_codegen::runtime::ProtoBuilder; use std::io::{self, Read, Write}; fn main() { @@ -58,7 +58,7 @@ fn handle_request( // Write length as varint let len = file_data.len() as u64; let mut len_buf = [0u8; 10]; - let len_size = roto_runtime::write_varint(len, &mut len_buf).map_err(|e| { + let len_size = roto_codegen::runtime::write_varint(len, &mut len_buf).map_err(|e| { error!("Failed to write varint length: {:?}", e); e })?; diff --git a/codegen/src/generator/messages.rs b/codegen/src/generator/messages.rs index 923aeca..365714b 100644 --- a/codegen/src/generator/messages.rs +++ b/codegen/src/generator/messages.rs @@ -2,7 +2,7 @@ use crate::google::protobuf::descriptor::{DescriptorProto, EnumDescriptorProto, use crate::google::protobuf::descriptor::FileDescriptorSet; use crate::generator::types::map_type_to_rust_builder; -use roto_runtime::ProtoAccessor; +use crate::runtime::ProtoAccessor; use crate::generator::utils::{to_pascal_case, to_snake_case}; use crate::generator::types::map_type_to_rust_accessor; @@ -25,7 +25,7 @@ pub fn write_enum(enum_proto: &EnumDescriptorProto, output: &mut String) { let name = std::str::from_utf8(name_bytes).expect("Enum value name invalid utf8"); let (num_bytes, _) = accessor.get_value(2).expect("Enum value number missing"); let (num, _) = - roto_runtime::read_varint(num_bytes).expect("Enum value number invalid varint"); + crate::runtime::read_varint(num_bytes).expect("Enum value number invalid varint"); let pascal_name = to_pascal_case(name); if num == 0 { @@ -55,7 +55,7 @@ pub fn write_enum(enum_proto: &EnumDescriptorProto, output: &mut String) { let name = std::str::from_utf8(name_bytes).expect("Enum value name invalid utf8"); let (num_bytes, _) = accessor.get_value(2).expect("Enum value number missing"); let (num, _) = - roto_runtime::read_varint(num_bytes).expect("Enum value number invalid varint"); + crate::runtime::read_varint(num_bytes).expect("Enum value number invalid varint"); output.push_str(&format!( " {} => {}::{},\n", diff --git a/codegen/src/generator/mod.rs b/codegen/src/generator/mod.rs index 2a177dd..a0b5ac9 100644 --- a/codegen/src/generator/mod.rs +++ b/codegen/src/generator/mod.rs @@ -3,7 +3,7 @@ use crate::google::protobuf::descriptor::{ FileDescriptorSet, MessageOptions, MethodDescriptorProto, OneofDescriptorProto, ServiceDescriptorProto, }; -use roto_runtime::ProtoAccessor; +use crate::runtime::ProtoAccessor; use std::collections::{HashMap, HashSet}; use std::str; @@ -139,7 +139,7 @@ fn write_enum(enum_proto: &EnumDescriptorProto, output: &mut String) { let name = std::str::from_utf8(name_bytes).expect("Enum value name invalid utf8"); let (num_bytes, _) = accessor.get_value(2).expect("Enum value number missing"); let (num, _) = - roto_runtime::read_varint(num_bytes).expect("Enum value number invalid varint"); + crate::runtime::read_varint(num_bytes).expect("Enum value number invalid varint"); let pascal_name = to_pascal_case(name); if num == 0 { @@ -169,7 +169,7 @@ fn write_enum(enum_proto: &EnumDescriptorProto, output: &mut String) { let name = std::str::from_utf8(name_bytes).expect("Enum value name invalid utf8"); let (num_bytes, _) = accessor.get_value(2).expect("Enum value number missing"); let (num, _) = - roto_runtime::read_varint(num_bytes).expect("Enum value number invalid varint"); + crate::runtime::read_varint(num_bytes).expect("Enum value number invalid varint"); output.push_str(&format!( " {} => {}::{},\n", diff --git a/codegen/src/google/protobuf/compiler/plugin.rs b/codegen/src/google/protobuf/compiler/plugin.rs index 7f46172..a81a835 100644 --- a/codegen/src/google/protobuf/compiler/plugin.rs +++ b/codegen/src/google/protobuf/compiler/plugin.rs @@ -1,7 +1,7 @@ // @generated by protoc-gen-roto — do not edit #[allow(unused_imports)] -use roto_runtime::{ProtoAccessor, ProtoBuilder, Result, RotoError, read_varint, RepeatedFieldIterator}; +use crate::runtime::{ProtoAccessor, ProtoBuilder, Result, RotoError, read_varint, RepeatedFieldIterator}; use std::str; use bytes::{Bytes, BytesMut, Buf, BufMut}; use tonic::{Request, Response, Status}; @@ -20,7 +20,7 @@ use roto_tonic::{BufferPool, StatusBody}; use crate::google::protobuf::descriptor; pub struct Version<'a> { - accessor: roto_runtime::ProtoAccessor<'a>, + accessor: crate::runtime::ProtoAccessor<'a>, major_offset: Option, minor_offset: Option, patch_offset: Option, @@ -28,8 +28,8 @@ pub struct Version<'a> { } impl<'a> Version<'a> { - pub fn new(data: &'a [u8]) -> roto_runtime::Result { - let accessor = roto_runtime::ProtoAccessor::new(data)?; + pub fn new(data: &'a [u8]) -> crate::runtime::Result { + let accessor = crate::runtime::ProtoAccessor::new(data)?; let mut major_offset = None; let mut minor_offset = None; let mut patch_offset = None; @@ -51,62 +51,62 @@ suffix_offset, }) } - pub fn major(&self) -> roto_runtime::Result { - let offset = self.major_offset.ok_or(roto_runtime::RotoError::FieldNotFound)?; + pub fn major(&self) -> crate::runtime::Result { + let offset = self.major_offset.ok_or(crate::runtime::RotoError::FieldNotFound)?; let (bytes, _) = self.accessor.get_value_at(offset)?; - roto_runtime::read_varint(bytes).map(|(v, _)| v as i32).map_err(|_| roto_runtime::RotoError::WireFormatViolation) + crate::runtime::read_varint(bytes).map(|(v, _)| v as i32).map_err(|_| crate::runtime::RotoError::WireFormatViolation) } - pub fn major_or_default(&self) -> roto_runtime::Result { + pub fn major_or_default(&self) -> crate::runtime::Result { self.major().or(Ok(0)) } pub fn has_major(&self) -> bool { self.major_offset.is_some() } - pub fn minor(&self) -> roto_runtime::Result { - let offset = self.minor_offset.ok_or(roto_runtime::RotoError::FieldNotFound)?; + pub fn minor(&self) -> crate::runtime::Result { + let offset = self.minor_offset.ok_or(crate::runtime::RotoError::FieldNotFound)?; let (bytes, _) = self.accessor.get_value_at(offset)?; - roto_runtime::read_varint(bytes).map(|(v, _)| v as i32).map_err(|_| roto_runtime::RotoError::WireFormatViolation) + crate::runtime::read_varint(bytes).map(|(v, _)| v as i32).map_err(|_| crate::runtime::RotoError::WireFormatViolation) } - pub fn minor_or_default(&self) -> roto_runtime::Result { + pub fn minor_or_default(&self) -> crate::runtime::Result { self.minor().or(Ok(0)) } pub fn has_minor(&self) -> bool { self.minor_offset.is_some() } - pub fn patch(&self) -> roto_runtime::Result { - let offset = self.patch_offset.ok_or(roto_runtime::RotoError::FieldNotFound)?; + pub fn patch(&self) -> crate::runtime::Result { + let offset = self.patch_offset.ok_or(crate::runtime::RotoError::FieldNotFound)?; let (bytes, _) = self.accessor.get_value_at(offset)?; - roto_runtime::read_varint(bytes).map(|(v, _)| v as i32).map_err(|_| roto_runtime::RotoError::WireFormatViolation) + crate::runtime::read_varint(bytes).map(|(v, _)| v as i32).map_err(|_| crate::runtime::RotoError::WireFormatViolation) } - pub fn patch_or_default(&self) -> roto_runtime::Result { + pub fn patch_or_default(&self) -> crate::runtime::Result { self.patch().or(Ok(0)) } pub fn has_patch(&self) -> bool { self.patch_offset.is_some() } - pub fn suffix(&self) -> roto_runtime::Result<&'a str> { - let offset = self.suffix_offset.ok_or(roto_runtime::RotoError::FieldNotFound)?; + pub fn suffix(&self) -> crate::runtime::Result<&'a str> { + let offset = self.suffix_offset.ok_or(crate::runtime::RotoError::FieldNotFound)?; let (bytes, _) = self.accessor.get_value_at(offset)?; - str::from_utf8(bytes).map_err(|_| roto_runtime::RotoError::WireFormatViolation) + str::from_utf8(bytes).map_err(|_| crate::runtime::RotoError::WireFormatViolation) } - pub fn suffix_or_default(&self) -> roto_runtime::Result<&'a str> { + pub fn suffix_or_default(&self) -> crate::runtime::Result<&'a str> { self.suffix().or(Ok("")) } pub fn has_suffix(&self) -> bool { self.suffix_offset.is_some() } - pub fn raw_fields(&self) -> roto_runtime::RawFieldIterator<'a> { + pub fn raw_fields(&self) -> crate::runtime::RawFieldIterator<'a> { self.accessor.raw_fields() } } pub struct VersionBuilder<'b> { - builder: roto_runtime::ProtoBuilder<'b>, + builder: crate::runtime::ProtoBuilder<'b>, major_written: bool, minor_written: bool, patch_written: bool, @@ -116,7 +116,7 @@ pub struct VersionBuilder<'b> { impl<'b> VersionBuilder<'b> { pub fn builder(buf: &mut [u8]) -> VersionBuilder<'_> { VersionBuilder { - builder: roto_runtime::ProtoBuilder::new(buf), + builder: crate::runtime::ProtoBuilder::new(buf), major_written: false, minor_written: false, patch_written: false, @@ -124,31 +124,31 @@ impl<'b> VersionBuilder<'b> { } } - pub fn major(mut self, value: i32) -> roto_runtime::Result { + pub fn major(mut self, value: i32) -> crate::runtime::Result { self.builder.write_int32(1, value)?; self.major_written = true; Ok(self) } - pub fn minor(mut self, value: i32) -> roto_runtime::Result { + pub fn minor(mut self, value: i32) -> crate::runtime::Result { self.builder.write_int32(2, value)?; self.minor_written = true; Ok(self) } - pub fn patch(mut self, value: i32) -> roto_runtime::Result { + pub fn patch(mut self, value: i32) -> crate::runtime::Result { self.builder.write_int32(3, value)?; self.patch_written = true; Ok(self) } - pub fn suffix(mut self, value: &str) -> roto_runtime::Result { + pub fn suffix(mut self, value: &str) -> crate::runtime::Result { self.builder.write_string(4, value)?; self.suffix_written = true; Ok(self) } - pub fn with(mut self, msg: &Version<'_>) -> roto_runtime::Result { + pub fn with(mut self, msg: &Version<'_>) -> crate::runtime::Result { for item in msg.raw_fields() { let (field_number, raw_bytes) = item?; let is_written = match field_number { @@ -165,7 +165,7 @@ impl<'b> VersionBuilder<'b> { Ok(self) } - pub fn finish(self) -> roto_runtime::Result<&'b mut [u8]> { + pub fn finish(self) -> crate::runtime::Result<&'b mut [u8]> { self.builder.finish() } } @@ -174,15 +174,15 @@ pub struct OwnedVersion { pub data: bytes::Bytes, } -impl roto_runtime::RotoOwned for OwnedVersion { +impl crate::runtime::RotoOwned for OwnedVersion { type Reader<'a> = Version<'a>; fn reader(&self) -> Version<'_> { Version::new(&self.data).expect("failed to create reader") } } -impl roto_runtime::RotoMessage for OwnedVersion { - fn decode(buf: bytes::Bytes) -> roto_runtime::Result { +impl crate::runtime::RotoMessage for OwnedVersion { + fn decode(buf: bytes::Bytes) -> crate::runtime::Result { Ok(OwnedVersion { data: buf }) } @@ -192,7 +192,7 @@ impl roto_runtime::RotoMessage for OwnedVersion { } pub struct CodeGeneratorRequest<'a> { - accessor: roto_runtime::ProtoAccessor<'a>, + accessor: crate::runtime::ProtoAccessor<'a>, file_to_generate_start: Option, file_to_generate_end: Option, parameter_offset: Option, @@ -204,8 +204,8 @@ pub struct CodeGeneratorRequest<'a> { } impl<'a> CodeGeneratorRequest<'a> { - pub fn new(data: &'a [u8]) -> roto_runtime::Result { - let accessor = roto_runtime::ProtoAccessor::new(data)?; + pub fn new(data: &'a [u8]) -> crate::runtime::Result { + let accessor = crate::runtime::ProtoAccessor::new(data)?; let mut file_to_generate_start = None; let mut file_to_generate_end = None; let mut parameter_offset = None; @@ -242,59 +242,59 @@ compiler_version_offset, }) } - pub fn file_to_generate(&self) -> roto_runtime::RepeatedFieldIterator<'a> { + pub fn file_to_generate(&self) -> crate::runtime::RepeatedFieldIterator<'a> { match (self.file_to_generate_start, self.file_to_generate_end) { (Some(start), Some(end)) => self.accessor.iter_repeated_range(1, start, end), _ => self.accessor.iter_repeated(1), } } - pub fn parameter(&self) -> roto_runtime::Result<&'a str> { - let offset = self.parameter_offset.ok_or(roto_runtime::RotoError::FieldNotFound)?; + pub fn parameter(&self) -> crate::runtime::Result<&'a str> { + let offset = self.parameter_offset.ok_or(crate::runtime::RotoError::FieldNotFound)?; let (bytes, _) = self.accessor.get_value_at(offset)?; - str::from_utf8(bytes).map_err(|_| roto_runtime::RotoError::WireFormatViolation) + str::from_utf8(bytes).map_err(|_| crate::runtime::RotoError::WireFormatViolation) } - pub fn parameter_or_default(&self) -> roto_runtime::Result<&'a str> { + pub fn parameter_or_default(&self) -> crate::runtime::Result<&'a str> { self.parameter().or(Ok("")) } pub fn has_parameter(&self) -> bool { self.parameter_offset.is_some() } - pub fn proto_file(&self) -> roto_runtime::RepeatedFieldIterator<'a> { + pub fn proto_file(&self) -> crate::runtime::RepeatedFieldIterator<'a> { match (self.proto_file_start, self.proto_file_end) { (Some(start), Some(end)) => self.accessor.iter_repeated_range(15, start, end), _ => self.accessor.iter_repeated(15), } } - pub fn source_file_descriptors(&self) -> roto_runtime::RepeatedFieldIterator<'a> { + pub fn source_file_descriptors(&self) -> crate::runtime::RepeatedFieldIterator<'a> { match (self.source_file_descriptors_start, self.source_file_descriptors_end) { (Some(start), Some(end)) => self.accessor.iter_repeated_range(17, start, end), _ => self.accessor.iter_repeated(17), } } - pub fn compiler_version(&self) -> roto_runtime::Result<&'a [u8]> { - let offset = self.compiler_version_offset.ok_or(roto_runtime::RotoError::FieldNotFound)?; + pub fn compiler_version(&self) -> crate::runtime::Result<&'a [u8]> { + let offset = self.compiler_version_offset.ok_or(crate::runtime::RotoError::FieldNotFound)?; let (bytes, _) = self.accessor.get_value_at(offset)?; Ok(bytes) } - pub fn compiler_version_or_default(&self) -> roto_runtime::Result<&'a [u8]> { + pub fn compiler_version_or_default(&self) -> crate::runtime::Result<&'a [u8]> { self.compiler_version().or(Ok(&[])) } pub fn has_compiler_version(&self) -> bool { self.compiler_version_offset.is_some() } - pub fn raw_fields(&self) -> roto_runtime::RawFieldIterator<'a> { + pub fn raw_fields(&self) -> crate::runtime::RawFieldIterator<'a> { self.accessor.raw_fields() } } pub struct CodeGeneratorRequestBuilder<'b> { - builder: roto_runtime::ProtoBuilder<'b>, + builder: crate::runtime::ProtoBuilder<'b>, file_to_generate_written: bool, parameter_written: bool, proto_file_written: bool, @@ -305,7 +305,7 @@ pub struct CodeGeneratorRequestBuilder<'b> { impl<'b> CodeGeneratorRequestBuilder<'b> { pub fn builder(buf: &mut [u8]) -> CodeGeneratorRequestBuilder<'_> { CodeGeneratorRequestBuilder { - builder: roto_runtime::ProtoBuilder::new(buf), + builder: crate::runtime::ProtoBuilder::new(buf), file_to_generate_written: false, parameter_written: false, proto_file_written: false, @@ -314,37 +314,37 @@ impl<'b> CodeGeneratorRequestBuilder<'b> { } } - pub fn file_to_generate(mut self, value: &str) -> roto_runtime::Result { + pub fn file_to_generate(mut self, value: &str) -> crate::runtime::Result { self.builder.write_string(1, value)?; self.file_to_generate_written = true; Ok(self) } - pub fn parameter(mut self, value: &str) -> roto_runtime::Result { + pub fn parameter(mut self, value: &str) -> crate::runtime::Result { self.builder.write_string(2, value)?; self.parameter_written = true; Ok(self) } - pub fn proto_file(mut self, value: &[u8]) -> roto_runtime::Result { + pub fn proto_file(mut self, value: &[u8]) -> crate::runtime::Result { self.builder.write_bytes(15, value)?; self.proto_file_written = true; Ok(self) } - pub fn source_file_descriptors(mut self, value: &[u8]) -> roto_runtime::Result { + pub fn source_file_descriptors(mut self, value: &[u8]) -> crate::runtime::Result { self.builder.write_bytes(17, value)?; self.source_file_descriptors_written = true; Ok(self) } - pub fn compiler_version(mut self, value: &[u8]) -> roto_runtime::Result { + pub fn compiler_version(mut self, value: &[u8]) -> crate::runtime::Result { self.builder.write_bytes(3, value)?; self.compiler_version_written = true; Ok(self) } - pub fn with(mut self, msg: &CodeGeneratorRequest<'_>) -> roto_runtime::Result { + pub fn with(mut self, msg: &CodeGeneratorRequest<'_>) -> crate::runtime::Result { for item in msg.raw_fields() { let (field_number, raw_bytes) = item?; let is_written = match field_number { @@ -362,7 +362,7 @@ impl<'b> CodeGeneratorRequestBuilder<'b> { Ok(self) } - pub fn finish(self) -> roto_runtime::Result<&'b mut [u8]> { + pub fn finish(self) -> crate::runtime::Result<&'b mut [u8]> { self.builder.finish() } } @@ -371,15 +371,15 @@ pub struct OwnedCodeGeneratorRequest { pub data: bytes::Bytes, } -impl roto_runtime::RotoOwned for OwnedCodeGeneratorRequest { +impl crate::runtime::RotoOwned for OwnedCodeGeneratorRequest { type Reader<'a> = CodeGeneratorRequest<'a>; fn reader(&self) -> CodeGeneratorRequest<'_> { CodeGeneratorRequest::new(&self.data).expect("failed to create reader") } } -impl roto_runtime::RotoMessage for OwnedCodeGeneratorRequest { - fn decode(buf: bytes::Bytes) -> roto_runtime::Result { +impl crate::runtime::RotoMessage for OwnedCodeGeneratorRequest { + fn decode(buf: bytes::Bytes) -> crate::runtime::Result { Ok(OwnedCodeGeneratorRequest { data: buf }) } @@ -389,7 +389,7 @@ impl roto_runtime::RotoMessage for OwnedCodeGeneratorRequest { } pub struct CodeGeneratorResponse<'a> { - accessor: roto_runtime::ProtoAccessor<'a>, + accessor: crate::runtime::ProtoAccessor<'a>, error_offset: Option, supported_features_offset: Option, minimum_edition_offset: Option, @@ -399,8 +399,8 @@ pub struct CodeGeneratorResponse<'a> { } impl<'a> CodeGeneratorResponse<'a> { - pub fn new(data: &'a [u8]) -> roto_runtime::Result { - let accessor = roto_runtime::ProtoAccessor::new(data)?; + pub fn new(data: &'a [u8]) -> crate::runtime::Result { + let accessor = crate::runtime::ProtoAccessor::new(data)?; let mut error_offset = None; let mut supported_features_offset = None; let mut minimum_edition_offset = None; @@ -429,69 +429,69 @@ file_start, file_end, }) } - pub fn error(&self) -> roto_runtime::Result<&'a str> { - let offset = self.error_offset.ok_or(roto_runtime::RotoError::FieldNotFound)?; + pub fn error(&self) -> crate::runtime::Result<&'a str> { + let offset = self.error_offset.ok_or(crate::runtime::RotoError::FieldNotFound)?; let (bytes, _) = self.accessor.get_value_at(offset)?; - str::from_utf8(bytes).map_err(|_| roto_runtime::RotoError::WireFormatViolation) + str::from_utf8(bytes).map_err(|_| crate::runtime::RotoError::WireFormatViolation) } - pub fn error_or_default(&self) -> roto_runtime::Result<&'a str> { + pub fn error_or_default(&self) -> crate::runtime::Result<&'a str> { self.error().or(Ok("")) } pub fn has_error(&self) -> bool { self.error_offset.is_some() } - pub fn supported_features(&self) -> roto_runtime::Result { - let offset = self.supported_features_offset.ok_or(roto_runtime::RotoError::FieldNotFound)?; + pub fn supported_features(&self) -> crate::runtime::Result { + let offset = self.supported_features_offset.ok_or(crate::runtime::RotoError::FieldNotFound)?; let (bytes, _) = self.accessor.get_value_at(offset)?; - roto_runtime::read_varint(bytes).map(|(v, _)| v as u32).map_err(|_| roto_runtime::RotoError::WireFormatViolation) + crate::runtime::read_varint(bytes).map(|(v, _)| v as u32).map_err(|_| crate::runtime::RotoError::WireFormatViolation) } - pub fn supported_features_or_default(&self) -> roto_runtime::Result { + pub fn supported_features_or_default(&self) -> crate::runtime::Result { self.supported_features().or(Ok(0)) } pub fn has_supported_features(&self) -> bool { self.supported_features_offset.is_some() } - pub fn minimum_edition(&self) -> roto_runtime::Result { - let offset = self.minimum_edition_offset.ok_or(roto_runtime::RotoError::FieldNotFound)?; + pub fn minimum_edition(&self) -> crate::runtime::Result { + let offset = self.minimum_edition_offset.ok_or(crate::runtime::RotoError::FieldNotFound)?; let (bytes, _) = self.accessor.get_value_at(offset)?; - roto_runtime::read_varint(bytes).map(|(v, _)| v as i32).map_err(|_| roto_runtime::RotoError::WireFormatViolation) + crate::runtime::read_varint(bytes).map(|(v, _)| v as i32).map_err(|_| crate::runtime::RotoError::WireFormatViolation) } - pub fn minimum_edition_or_default(&self) -> roto_runtime::Result { + pub fn minimum_edition_or_default(&self) -> crate::runtime::Result { self.minimum_edition().or(Ok(0)) } pub fn has_minimum_edition(&self) -> bool { self.minimum_edition_offset.is_some() } - pub fn maximum_edition(&self) -> roto_runtime::Result { - let offset = self.maximum_edition_offset.ok_or(roto_runtime::RotoError::FieldNotFound)?; + pub fn maximum_edition(&self) -> crate::runtime::Result { + let offset = self.maximum_edition_offset.ok_or(crate::runtime::RotoError::FieldNotFound)?; let (bytes, _) = self.accessor.get_value_at(offset)?; - roto_runtime::read_varint(bytes).map(|(v, _)| v as i32).map_err(|_| roto_runtime::RotoError::WireFormatViolation) + crate::runtime::read_varint(bytes).map(|(v, _)| v as i32).map_err(|_| crate::runtime::RotoError::WireFormatViolation) } - pub fn maximum_edition_or_default(&self) -> roto_runtime::Result { + pub fn maximum_edition_or_default(&self) -> crate::runtime::Result { self.maximum_edition().or(Ok(0)) } pub fn has_maximum_edition(&self) -> bool { self.maximum_edition_offset.is_some() } - pub fn file(&self) -> roto_runtime::RepeatedFieldIterator<'a> { + pub fn file(&self) -> crate::runtime::RepeatedFieldIterator<'a> { match (self.file_start, self.file_end) { (Some(start), Some(end)) => self.accessor.iter_repeated_range(15, start, end), _ => self.accessor.iter_repeated(15), } } - pub fn raw_fields(&self) -> roto_runtime::RawFieldIterator<'a> { + pub fn raw_fields(&self) -> crate::runtime::RawFieldIterator<'a> { self.accessor.raw_fields() } } pub struct CodeGeneratorResponseBuilder<'b> { - builder: roto_runtime::ProtoBuilder<'b>, + builder: crate::runtime::ProtoBuilder<'b>, error_written: bool, supported_features_written: bool, minimum_edition_written: bool, @@ -502,7 +502,7 @@ pub struct CodeGeneratorResponseBuilder<'b> { impl<'b> CodeGeneratorResponseBuilder<'b> { pub fn builder(buf: &mut [u8]) -> CodeGeneratorResponseBuilder<'_> { CodeGeneratorResponseBuilder { - builder: roto_runtime::ProtoBuilder::new(buf), + builder: crate::runtime::ProtoBuilder::new(buf), error_written: false, supported_features_written: false, minimum_edition_written: false, @@ -511,37 +511,37 @@ impl<'b> CodeGeneratorResponseBuilder<'b> { } } - pub fn error(mut self, value: &str) -> roto_runtime::Result { + pub fn error(mut self, value: &str) -> crate::runtime::Result { self.builder.write_string(1, value)?; self.error_written = true; Ok(self) } - pub fn supported_features(mut self, value: u64) -> roto_runtime::Result { + pub fn supported_features(mut self, value: u64) -> crate::runtime::Result { self.builder.write_varint(2, value)?; self.supported_features_written = true; Ok(self) } - pub fn minimum_edition(mut self, value: i32) -> roto_runtime::Result { + pub fn minimum_edition(mut self, value: i32) -> crate::runtime::Result { self.builder.write_int32(3, value)?; self.minimum_edition_written = true; Ok(self) } - pub fn maximum_edition(mut self, value: i32) -> roto_runtime::Result { + pub fn maximum_edition(mut self, value: i32) -> crate::runtime::Result { self.builder.write_int32(4, value)?; self.maximum_edition_written = true; Ok(self) } - pub fn file(mut self, value: &[u8]) -> roto_runtime::Result { + pub fn file(mut self, value: &[u8]) -> crate::runtime::Result { self.builder.write_bytes(15, value)?; self.file_written = true; Ok(self) } - pub fn with(mut self, msg: &CodeGeneratorResponse<'_>) -> roto_runtime::Result { + pub fn with(mut self, msg: &CodeGeneratorResponse<'_>) -> crate::runtime::Result { for item in msg.raw_fields() { let (field_number, raw_bytes) = item?; let is_written = match field_number { @@ -559,7 +559,7 @@ impl<'b> CodeGeneratorResponseBuilder<'b> { Ok(self) } - pub fn finish(self) -> roto_runtime::Result<&'b mut [u8]> { + pub fn finish(self) -> crate::runtime::Result<&'b mut [u8]> { self.builder.finish() } } @@ -568,15 +568,15 @@ pub struct OwnedCodeGeneratorResponse { pub data: bytes::Bytes, } -impl roto_runtime::RotoOwned for OwnedCodeGeneratorResponse { +impl crate::runtime::RotoOwned for OwnedCodeGeneratorResponse { type Reader<'a> = CodeGeneratorResponse<'a>; fn reader(&self) -> CodeGeneratorResponse<'_> { CodeGeneratorResponse::new(&self.data).expect("failed to create reader") } } -impl roto_runtime::RotoMessage for OwnedCodeGeneratorResponse { - fn decode(buf: bytes::Bytes) -> roto_runtime::Result { +impl crate::runtime::RotoMessage for OwnedCodeGeneratorResponse { + fn decode(buf: bytes::Bytes) -> crate::runtime::Result { Ok(OwnedCodeGeneratorResponse { data: buf }) } @@ -606,7 +606,7 @@ impl Feature { } pub struct File<'a> { - accessor: roto_runtime::ProtoAccessor<'a>, + accessor: crate::runtime::ProtoAccessor<'a>, name_offset: Option, insertion_point_offset: Option, content_offset: Option, @@ -614,8 +614,8 @@ pub struct File<'a> { } impl<'a> File<'a> { - pub fn new(data: &'a [u8]) -> roto_runtime::Result { - let accessor = roto_runtime::ProtoAccessor::new(data)?; + pub fn new(data: &'a [u8]) -> crate::runtime::Result { + let accessor = crate::runtime::ProtoAccessor::new(data)?; let mut name_offset = None; let mut insertion_point_offset = None; let mut content_offset = None; @@ -637,62 +637,62 @@ generated_code_info_offset, }) } - pub fn name(&self) -> roto_runtime::Result<&'a str> { - let offset = self.name_offset.ok_or(roto_runtime::RotoError::FieldNotFound)?; + pub fn name(&self) -> crate::runtime::Result<&'a str> { + let offset = self.name_offset.ok_or(crate::runtime::RotoError::FieldNotFound)?; let (bytes, _) = self.accessor.get_value_at(offset)?; - str::from_utf8(bytes).map_err(|_| roto_runtime::RotoError::WireFormatViolation) + str::from_utf8(bytes).map_err(|_| crate::runtime::RotoError::WireFormatViolation) } - pub fn name_or_default(&self) -> roto_runtime::Result<&'a str> { + pub fn name_or_default(&self) -> crate::runtime::Result<&'a str> { self.name().or(Ok("")) } pub fn has_name(&self) -> bool { self.name_offset.is_some() } - pub fn insertion_point(&self) -> roto_runtime::Result<&'a str> { - let offset = self.insertion_point_offset.ok_or(roto_runtime::RotoError::FieldNotFound)?; + pub fn insertion_point(&self) -> crate::runtime::Result<&'a str> { + let offset = self.insertion_point_offset.ok_or(crate::runtime::RotoError::FieldNotFound)?; let (bytes, _) = self.accessor.get_value_at(offset)?; - str::from_utf8(bytes).map_err(|_| roto_runtime::RotoError::WireFormatViolation) + str::from_utf8(bytes).map_err(|_| crate::runtime::RotoError::WireFormatViolation) } - pub fn insertion_point_or_default(&self) -> roto_runtime::Result<&'a str> { + pub fn insertion_point_or_default(&self) -> crate::runtime::Result<&'a str> { self.insertion_point().or(Ok("")) } pub fn has_insertion_point(&self) -> bool { self.insertion_point_offset.is_some() } - pub fn content(&self) -> roto_runtime::Result<&'a str> { - let offset = self.content_offset.ok_or(roto_runtime::RotoError::FieldNotFound)?; + pub fn content(&self) -> crate::runtime::Result<&'a str> { + let offset = self.content_offset.ok_or(crate::runtime::RotoError::FieldNotFound)?; let (bytes, _) = self.accessor.get_value_at(offset)?; - str::from_utf8(bytes).map_err(|_| roto_runtime::RotoError::WireFormatViolation) + str::from_utf8(bytes).map_err(|_| crate::runtime::RotoError::WireFormatViolation) } - pub fn content_or_default(&self) -> roto_runtime::Result<&'a str> { + pub fn content_or_default(&self) -> crate::runtime::Result<&'a str> { self.content().or(Ok("")) } pub fn has_content(&self) -> bool { self.content_offset.is_some() } - pub fn generated_code_info(&self) -> roto_runtime::Result<&'a [u8]> { - let offset = self.generated_code_info_offset.ok_or(roto_runtime::RotoError::FieldNotFound)?; + pub fn generated_code_info(&self) -> crate::runtime::Result<&'a [u8]> { + let offset = self.generated_code_info_offset.ok_or(crate::runtime::RotoError::FieldNotFound)?; let (bytes, _) = self.accessor.get_value_at(offset)?; Ok(bytes) } - pub fn generated_code_info_or_default(&self) -> roto_runtime::Result<&'a [u8]> { + pub fn generated_code_info_or_default(&self) -> crate::runtime::Result<&'a [u8]> { self.generated_code_info().or(Ok(&[])) } pub fn has_generated_code_info(&self) -> bool { self.generated_code_info_offset.is_some() } - pub fn raw_fields(&self) -> roto_runtime::RawFieldIterator<'a> { + pub fn raw_fields(&self) -> crate::runtime::RawFieldIterator<'a> { self.accessor.raw_fields() } } pub struct FileBuilder<'b> { - builder: roto_runtime::ProtoBuilder<'b>, + builder: crate::runtime::ProtoBuilder<'b>, name_written: bool, insertion_point_written: bool, content_written: bool, @@ -702,7 +702,7 @@ pub struct FileBuilder<'b> { impl<'b> FileBuilder<'b> { pub fn builder(buf: &mut [u8]) -> FileBuilder<'_> { FileBuilder { - builder: roto_runtime::ProtoBuilder::new(buf), + builder: crate::runtime::ProtoBuilder::new(buf), name_written: false, insertion_point_written: false, content_written: false, @@ -710,31 +710,31 @@ impl<'b> FileBuilder<'b> { } } - pub fn name(mut self, value: &str) -> roto_runtime::Result { + pub fn name(mut self, value: &str) -> crate::runtime::Result { self.builder.write_string(1, value)?; self.name_written = true; Ok(self) } - pub fn insertion_point(mut self, value: &str) -> roto_runtime::Result { + pub fn insertion_point(mut self, value: &str) -> crate::runtime::Result { self.builder.write_string(2, value)?; self.insertion_point_written = true; Ok(self) } - pub fn content(mut self, value: &str) -> roto_runtime::Result { + pub fn content(mut self, value: &str) -> crate::runtime::Result { self.builder.write_string(15, value)?; self.content_written = true; Ok(self) } - pub fn generated_code_info(mut self, value: &[u8]) -> roto_runtime::Result { + pub fn generated_code_info(mut self, value: &[u8]) -> crate::runtime::Result { self.builder.write_bytes(16, value)?; self.generated_code_info_written = true; Ok(self) } - pub fn with(mut self, msg: &File<'_>) -> roto_runtime::Result { + pub fn with(mut self, msg: &File<'_>) -> crate::runtime::Result { for item in msg.raw_fields() { let (field_number, raw_bytes) = item?; let is_written = match field_number { @@ -751,7 +751,7 @@ impl<'b> FileBuilder<'b> { Ok(self) } - pub fn finish(self) -> roto_runtime::Result<&'b mut [u8]> { + pub fn finish(self) -> crate::runtime::Result<&'b mut [u8]> { self.builder.finish() } } @@ -760,15 +760,15 @@ pub struct OwnedFile { pub data: bytes::Bytes, } -impl roto_runtime::RotoOwned for OwnedFile { +impl crate::runtime::RotoOwned for OwnedFile { type Reader<'a> = File<'a>; fn reader(&self) -> File<'_> { File::new(&self.data).expect("failed to create reader") } } -impl roto_runtime::RotoMessage for OwnedFile { - fn decode(buf: bytes::Bytes) -> roto_runtime::Result { +impl crate::runtime::RotoMessage for OwnedFile { + fn decode(buf: bytes::Bytes) -> crate::runtime::Result { Ok(OwnedFile { data: buf }) } diff --git a/codegen/src/google/protobuf/descriptor.rs b/codegen/src/google/protobuf/descriptor.rs index e57b526..210f0be 100644 --- a/codegen/src/google/protobuf/descriptor.rs +++ b/codegen/src/google/protobuf/descriptor.rs @@ -1,7 +1,7 @@ // @generated by protoc-gen-roto — do not edit #[allow(unused_imports)] -use roto_runtime::{ProtoAccessor, ProtoBuilder, Result, RotoError, read_varint, RepeatedFieldIterator}; +use crate::runtime::{ProtoAccessor, ProtoBuilder, Result, RotoError, read_varint, RepeatedFieldIterator}; use std::str; use bytes::{Bytes, BytesMut, Buf, BufMut}; use tonic::{Request, Response, Status}; @@ -79,14 +79,14 @@ impl SymbolVisibility { } pub struct FileDescriptorSet<'a> { - accessor: roto_runtime::ProtoAccessor<'a>, + accessor: crate::runtime::ProtoAccessor<'a>, file_start: Option, file_end: Option, } impl<'a> FileDescriptorSet<'a> { - pub fn new(data: &'a [u8]) -> roto_runtime::Result { - let accessor = roto_runtime::ProtoAccessor::new(data)?; + pub fn new(data: &'a [u8]) -> crate::runtime::Result { + let accessor = crate::runtime::ProtoAccessor::new(data)?; let mut file_start = None; let mut file_end = None; for item in accessor.fields() { @@ -103,39 +103,39 @@ file_start, file_end, }) } - pub fn file(&self) -> roto_runtime::RepeatedFieldIterator<'a> { + pub fn file(&self) -> crate::runtime::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 fn raw_fields(&self) -> roto_runtime::RawFieldIterator<'a> { + pub fn raw_fields(&self) -> crate::runtime::RawFieldIterator<'a> { self.accessor.raw_fields() } } pub struct FileDescriptorSetBuilder<'b> { - builder: roto_runtime::ProtoBuilder<'b>, + builder: crate::runtime::ProtoBuilder<'b>, file_written: bool, } impl<'b> FileDescriptorSetBuilder<'b> { pub fn builder(buf: &mut [u8]) -> FileDescriptorSetBuilder<'_> { FileDescriptorSetBuilder { - builder: roto_runtime::ProtoBuilder::new(buf), + builder: crate::runtime::ProtoBuilder::new(buf), file_written: false, } } - pub fn file(mut self, value: &[u8]) -> roto_runtime::Result { + pub fn file(mut self, value: &[u8]) -> crate::runtime::Result { self.builder.write_bytes(1, value)?; self.file_written = true; Ok(self) } - pub fn with(mut self, msg: &FileDescriptorSet<'_>) -> roto_runtime::Result { + pub fn with(mut self, msg: &FileDescriptorSet<'_>) -> crate::runtime::Result { for item in msg.raw_fields() { let (field_number, raw_bytes) = item?; let is_written = match field_number { @@ -149,7 +149,7 @@ impl<'b> FileDescriptorSetBuilder<'b> { Ok(self) } - pub fn finish(self) -> roto_runtime::Result<&'b mut [u8]> { + pub fn finish(self) -> crate::runtime::Result<&'b mut [u8]> { self.builder.finish() } } @@ -158,15 +158,15 @@ pub struct OwnedFileDescriptorSet { pub data: bytes::Bytes, } -impl roto_runtime::RotoOwned for OwnedFileDescriptorSet { +impl crate::runtime::RotoOwned for OwnedFileDescriptorSet { type Reader<'a> = FileDescriptorSet<'a>; fn reader(&self) -> FileDescriptorSet<'_> { FileDescriptorSet::new(&self.data).expect("failed to create reader") } } -impl roto_runtime::RotoMessage for OwnedFileDescriptorSet { - fn decode(buf: bytes::Bytes) -> roto_runtime::Result { +impl crate::runtime::RotoMessage for OwnedFileDescriptorSet { + fn decode(buf: bytes::Bytes) -> crate::runtime::Result { Ok(OwnedFileDescriptorSet { data: buf }) } @@ -176,7 +176,7 @@ impl roto_runtime::RotoMessage for OwnedFileDescriptorSet { } pub struct FileDescriptorProto<'a> { - accessor: roto_runtime::ProtoAccessor<'a>, + accessor: crate::runtime::ProtoAccessor<'a>, name_offset: Option, package_offset: Option, dependency_start: Option, @@ -202,8 +202,8 @@ pub struct FileDescriptorProto<'a> { } impl<'a> FileDescriptorProto<'a> { - pub fn new(data: &'a [u8]) -> roto_runtime::Result { - let accessor = roto_runtime::ProtoAccessor::new(data)?; + pub fn new(data: &'a [u8]) -> crate::runtime::Result { + let accessor = crate::runtime::ProtoAccessor::new(data)?; let mut name_offset = None; let mut package_offset = None; let mut dependency_start = None; @@ -287,142 +287,142 @@ edition_offset, }) } - pub fn name(&self) -> roto_runtime::Result<&'a str> { - let offset = self.name_offset.ok_or(roto_runtime::RotoError::FieldNotFound)?; + pub fn name(&self) -> crate::runtime::Result<&'a str> { + let offset = self.name_offset.ok_or(crate::runtime::RotoError::FieldNotFound)?; let (bytes, _) = self.accessor.get_value_at(offset)?; - str::from_utf8(bytes).map_err(|_| roto_runtime::RotoError::WireFormatViolation) + str::from_utf8(bytes).map_err(|_| crate::runtime::RotoError::WireFormatViolation) } - pub fn name_or_default(&self) -> roto_runtime::Result<&'a str> { + pub fn name_or_default(&self) -> crate::runtime::Result<&'a str> { self.name().or(Ok("")) } pub fn has_name(&self) -> bool { self.name_offset.is_some() } - pub fn package(&self) -> roto_runtime::Result<&'a str> { - let offset = self.package_offset.ok_or(roto_runtime::RotoError::FieldNotFound)?; + pub fn package(&self) -> crate::runtime::Result<&'a str> { + let offset = self.package_offset.ok_or(crate::runtime::RotoError::FieldNotFound)?; let (bytes, _) = self.accessor.get_value_at(offset)?; - str::from_utf8(bytes).map_err(|_| roto_runtime::RotoError::WireFormatViolation) + str::from_utf8(bytes).map_err(|_| crate::runtime::RotoError::WireFormatViolation) } - pub fn package_or_default(&self) -> roto_runtime::Result<&'a str> { + pub fn package_or_default(&self) -> crate::runtime::Result<&'a str> { self.package().or(Ok("")) } pub fn has_package(&self) -> bool { self.package_offset.is_some() } - pub fn dependency(&self) -> roto_runtime::RepeatedFieldIterator<'a> { + pub fn dependency(&self) -> crate::runtime::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) -> roto_runtime::RepeatedFieldIterator<'a> { + pub fn public_dependency(&self) -> crate::runtime::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) -> roto_runtime::RepeatedFieldIterator<'a> { + pub fn weak_dependency(&self) -> crate::runtime::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) -> roto_runtime::RepeatedFieldIterator<'a> { + pub fn option_dependency(&self) -> crate::runtime::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) -> roto_runtime::RepeatedFieldIterator<'a> { + pub fn message_type(&self) -> crate::runtime::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) -> roto_runtime::RepeatedFieldIterator<'a> { + pub fn enum_type(&self) -> crate::runtime::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) -> roto_runtime::RepeatedFieldIterator<'a> { + pub fn service(&self) -> crate::runtime::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) -> roto_runtime::RepeatedFieldIterator<'a> { + pub fn extension(&self) -> crate::runtime::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) -> roto_runtime::Result<&'a [u8]> { - let offset = self.options_offset.ok_or(roto_runtime::RotoError::FieldNotFound)?; + pub fn options(&self) -> crate::runtime::Result<&'a [u8]> { + let offset = self.options_offset.ok_or(crate::runtime::RotoError::FieldNotFound)?; let (bytes, _) = self.accessor.get_value_at(offset)?; Ok(bytes) } - pub fn options_or_default(&self) -> roto_runtime::Result<&'a [u8]> { + pub fn options_or_default(&self) -> crate::runtime::Result<&'a [u8]> { self.options().or(Ok(&[])) } pub fn has_options(&self) -> bool { self.options_offset.is_some() } - pub fn source_code_info(&self) -> roto_runtime::Result<&'a [u8]> { - let offset = self.source_code_info_offset.ok_or(roto_runtime::RotoError::FieldNotFound)?; + pub fn source_code_info(&self) -> crate::runtime::Result<&'a [u8]> { + let offset = self.source_code_info_offset.ok_or(crate::runtime::RotoError::FieldNotFound)?; let (bytes, _) = self.accessor.get_value_at(offset)?; Ok(bytes) } - pub fn source_code_info_or_default(&self) -> roto_runtime::Result<&'a [u8]> { + pub fn source_code_info_or_default(&self) -> crate::runtime::Result<&'a [u8]> { self.source_code_info().or(Ok(&[])) } pub fn has_source_code_info(&self) -> bool { self.source_code_info_offset.is_some() } - pub fn syntax(&self) -> roto_runtime::Result<&'a str> { - let offset = self.syntax_offset.ok_or(roto_runtime::RotoError::FieldNotFound)?; + pub fn syntax(&self) -> crate::runtime::Result<&'a str> { + let offset = self.syntax_offset.ok_or(crate::runtime::RotoError::FieldNotFound)?; let (bytes, _) = self.accessor.get_value_at(offset)?; - str::from_utf8(bytes).map_err(|_| roto_runtime::RotoError::WireFormatViolation) + str::from_utf8(bytes).map_err(|_| crate::runtime::RotoError::WireFormatViolation) } - pub fn syntax_or_default(&self) -> roto_runtime::Result<&'a str> { + pub fn syntax_or_default(&self) -> crate::runtime::Result<&'a str> { self.syntax().or(Ok("")) } pub fn has_syntax(&self) -> bool { self.syntax_offset.is_some() } - pub fn edition(&self) -> roto_runtime::Result { - let offset = self.edition_offset.ok_or(roto_runtime::RotoError::FieldNotFound)?; + pub fn edition(&self) -> crate::runtime::Result { + let offset = self.edition_offset.ok_or(crate::runtime::RotoError::FieldNotFound)?; let (bytes, _) = self.accessor.get_value_at(offset)?; - roto_runtime::read_varint(bytes).map(|(v, _)| v as u64).map_err(|_| roto_runtime::RotoError::WireFormatViolation) + crate::runtime::read_varint(bytes).map(|(v, _)| v as u64).map_err(|_| crate::runtime::RotoError::WireFormatViolation) } - pub fn edition_or_default(&self) -> roto_runtime::Result { + pub fn edition_or_default(&self) -> crate::runtime::Result { self.edition().or(Ok(0)) } pub fn has_edition(&self) -> bool { self.edition_offset.is_some() } - pub fn raw_fields(&self) -> roto_runtime::RawFieldIterator<'a> { + pub fn raw_fields(&self) -> crate::runtime::RawFieldIterator<'a> { self.accessor.raw_fields() } } pub struct FileDescriptorProtoBuilder<'b> { - builder: roto_runtime::ProtoBuilder<'b>, + builder: crate::runtime::ProtoBuilder<'b>, name_written: bool, package_written: bool, dependency_written: bool, @@ -442,7 +442,7 @@ pub struct FileDescriptorProtoBuilder<'b> { impl<'b> FileDescriptorProtoBuilder<'b> { pub fn builder(buf: &mut [u8]) -> FileDescriptorProtoBuilder<'_> { FileDescriptorProtoBuilder { - builder: roto_runtime::ProtoBuilder::new(buf), + builder: crate::runtime::ProtoBuilder::new(buf), name_written: false, package_written: false, dependency_written: false, @@ -460,91 +460,91 @@ impl<'b> FileDescriptorProtoBuilder<'b> { } } - pub fn name(mut self, value: &str) -> roto_runtime::Result { + pub fn name(mut self, value: &str) -> crate::runtime::Result { self.builder.write_string(1, value)?; self.name_written = true; Ok(self) } - pub fn package(mut self, value: &str) -> roto_runtime::Result { + pub fn package(mut self, value: &str) -> crate::runtime::Result { self.builder.write_string(2, value)?; self.package_written = true; Ok(self) } - pub fn dependency(mut self, value: &str) -> roto_runtime::Result { + pub fn dependency(mut self, value: &str) -> crate::runtime::Result { self.builder.write_string(3, value)?; self.dependency_written = true; Ok(self) } - pub fn public_dependency(mut self, value: i32) -> roto_runtime::Result { + pub fn public_dependency(mut self, value: i32) -> crate::runtime::Result { self.builder.write_int32(10, value)?; self.public_dependency_written = true; Ok(self) } - pub fn weak_dependency(mut self, value: i32) -> roto_runtime::Result { + pub fn weak_dependency(mut self, value: i32) -> crate::runtime::Result { self.builder.write_int32(11, value)?; self.weak_dependency_written = true; Ok(self) } - pub fn option_dependency(mut self, value: &str) -> roto_runtime::Result { + pub fn option_dependency(mut self, value: &str) -> crate::runtime::Result { self.builder.write_string(15, value)?; self.option_dependency_written = true; Ok(self) } - pub fn message_type(mut self, value: &[u8]) -> roto_runtime::Result { + pub fn message_type(mut self, value: &[u8]) -> crate::runtime::Result { self.builder.write_bytes(4, value)?; self.message_type_written = true; Ok(self) } - pub fn enum_type(mut self, value: &[u8]) -> roto_runtime::Result { + pub fn enum_type(mut self, value: &[u8]) -> crate::runtime::Result { self.builder.write_bytes(5, value)?; self.enum_type_written = true; Ok(self) } - pub fn service(mut self, value: &[u8]) -> roto_runtime::Result { + pub fn service(mut self, value: &[u8]) -> crate::runtime::Result { self.builder.write_bytes(6, value)?; self.service_written = true; Ok(self) } - pub fn extension(mut self, value: &[u8]) -> roto_runtime::Result { + pub fn extension(mut self, value: &[u8]) -> crate::runtime::Result { self.builder.write_bytes(7, value)?; self.extension_written = true; Ok(self) } - pub fn options(mut self, value: &[u8]) -> roto_runtime::Result { + pub fn options(mut self, value: &[u8]) -> crate::runtime::Result { self.builder.write_bytes(8, value)?; self.options_written = true; Ok(self) } - pub fn source_code_info(mut self, value: &[u8]) -> roto_runtime::Result { + pub fn source_code_info(mut self, value: &[u8]) -> crate::runtime::Result { self.builder.write_bytes(9, value)?; self.source_code_info_written = true; Ok(self) } - pub fn syntax(mut self, value: &str) -> roto_runtime::Result { + pub fn syntax(mut self, value: &str) -> crate::runtime::Result { self.builder.write_string(12, value)?; self.syntax_written = true; Ok(self) } - pub fn edition(mut self, value: u64) -> roto_runtime::Result { + pub fn edition(mut self, value: u64) -> crate::runtime::Result { self.builder.write_varint(14, value)?; self.edition_written = true; Ok(self) } - pub fn with(mut self, msg: &FileDescriptorProto<'_>) -> roto_runtime::Result { + pub fn with(mut self, msg: &FileDescriptorProto<'_>) -> crate::runtime::Result { for item in msg.raw_fields() { let (field_number, raw_bytes) = item?; let is_written = match field_number { @@ -571,7 +571,7 @@ impl<'b> FileDescriptorProtoBuilder<'b> { Ok(self) } - pub fn finish(self) -> roto_runtime::Result<&'b mut [u8]> { + pub fn finish(self) -> crate::runtime::Result<&'b mut [u8]> { self.builder.finish() } } @@ -580,15 +580,15 @@ pub struct OwnedFileDescriptorProto { pub data: bytes::Bytes, } -impl roto_runtime::RotoOwned for OwnedFileDescriptorProto { +impl crate::runtime::RotoOwned for OwnedFileDescriptorProto { type Reader<'a> = FileDescriptorProto<'a>; fn reader(&self) -> FileDescriptorProto<'_> { FileDescriptorProto::new(&self.data).expect("failed to create reader") } } -impl roto_runtime::RotoMessage for OwnedFileDescriptorProto { - fn decode(buf: bytes::Bytes) -> roto_runtime::Result { +impl crate::runtime::RotoMessage for OwnedFileDescriptorProto { + fn decode(buf: bytes::Bytes) -> crate::runtime::Result { Ok(OwnedFileDescriptorProto { data: buf }) } @@ -598,7 +598,7 @@ impl roto_runtime::RotoMessage for OwnedFileDescriptorProto { } pub struct DescriptorProto<'a> { - accessor: roto_runtime::ProtoAccessor<'a>, + accessor: crate::runtime::ProtoAccessor<'a>, name_offset: Option, field_start: Option, field_end: Option, @@ -621,8 +621,8 @@ pub struct DescriptorProto<'a> { } impl<'a> DescriptorProto<'a> { - pub fn new(data: &'a [u8]) -> roto_runtime::Result { - let accessor = roto_runtime::ProtoAccessor::new(data)?; + pub fn new(data: &'a [u8]) -> crate::runtime::Result { + let accessor = crate::runtime::ProtoAccessor::new(data)?; let mut name_offset = None; let mut field_start = None; let mut field_end = None; @@ -697,106 +697,106 @@ visibility_offset, }) } - pub fn name(&self) -> roto_runtime::Result<&'a str> { - let offset = self.name_offset.ok_or(roto_runtime::RotoError::FieldNotFound)?; + pub fn name(&self) -> crate::runtime::Result<&'a str> { + let offset = self.name_offset.ok_or(crate::runtime::RotoError::FieldNotFound)?; let (bytes, _) = self.accessor.get_value_at(offset)?; - str::from_utf8(bytes).map_err(|_| roto_runtime::RotoError::WireFormatViolation) + str::from_utf8(bytes).map_err(|_| crate::runtime::RotoError::WireFormatViolation) } - pub fn name_or_default(&self) -> roto_runtime::Result<&'a str> { + pub fn name_or_default(&self) -> crate::runtime::Result<&'a str> { self.name().or(Ok("")) } pub fn has_name(&self) -> bool { self.name_offset.is_some() } - pub fn field(&self) -> roto_runtime::RepeatedFieldIterator<'a> { + pub fn field(&self) -> crate::runtime::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) -> roto_runtime::RepeatedFieldIterator<'a> { + pub fn extension(&self) -> crate::runtime::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) -> roto_runtime::RepeatedFieldIterator<'a> { + pub fn nested_type(&self) -> crate::runtime::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) -> roto_runtime::RepeatedFieldIterator<'a> { + pub fn enum_type(&self) -> crate::runtime::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) -> roto_runtime::RepeatedFieldIterator<'a> { + pub fn extension_range(&self) -> crate::runtime::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) -> roto_runtime::RepeatedFieldIterator<'a> { + pub fn oneof_decl(&self) -> crate::runtime::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) -> roto_runtime::Result<&'a [u8]> { - let offset = self.options_offset.ok_or(roto_runtime::RotoError::FieldNotFound)?; + pub fn options(&self) -> crate::runtime::Result<&'a [u8]> { + let offset = self.options_offset.ok_or(crate::runtime::RotoError::FieldNotFound)?; let (bytes, _) = self.accessor.get_value_at(offset)?; Ok(bytes) } - pub fn options_or_default(&self) -> roto_runtime::Result<&'a [u8]> { + pub fn options_or_default(&self) -> crate::runtime::Result<&'a [u8]> { self.options().or(Ok(&[])) } pub fn has_options(&self) -> bool { self.options_offset.is_some() } - pub fn reserved_range(&self) -> roto_runtime::RepeatedFieldIterator<'a> { + pub fn reserved_range(&self) -> crate::runtime::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) -> roto_runtime::RepeatedFieldIterator<'a> { + pub fn reserved_name(&self) -> crate::runtime::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) -> roto_runtime::Result { - let offset = self.visibility_offset.ok_or(roto_runtime::RotoError::FieldNotFound)?; + pub fn visibility(&self) -> crate::runtime::Result { + let offset = self.visibility_offset.ok_or(crate::runtime::RotoError::FieldNotFound)?; let (bytes, _) = self.accessor.get_value_at(offset)?; - roto_runtime::read_varint(bytes).map(|(v, _)| v as u64).map_err(|_| roto_runtime::RotoError::WireFormatViolation) + crate::runtime::read_varint(bytes).map(|(v, _)| v as u64).map_err(|_| crate::runtime::RotoError::WireFormatViolation) } - pub fn visibility_or_default(&self) -> roto_runtime::Result { + pub fn visibility_or_default(&self) -> crate::runtime::Result { self.visibility().or(Ok(0)) } pub fn has_visibility(&self) -> bool { self.visibility_offset.is_some() } - pub fn raw_fields(&self) -> roto_runtime::RawFieldIterator<'a> { + pub fn raw_fields(&self) -> crate::runtime::RawFieldIterator<'a> { self.accessor.raw_fields() } } pub struct DescriptorProtoBuilder<'b> { - builder: roto_runtime::ProtoBuilder<'b>, + builder: crate::runtime::ProtoBuilder<'b>, name_written: bool, field_written: bool, extension_written: bool, @@ -813,7 +813,7 @@ pub struct DescriptorProtoBuilder<'b> { impl<'b> DescriptorProtoBuilder<'b> { pub fn builder(buf: &mut [u8]) -> DescriptorProtoBuilder<'_> { DescriptorProtoBuilder { - builder: roto_runtime::ProtoBuilder::new(buf), + builder: crate::runtime::ProtoBuilder::new(buf), name_written: false, field_written: false, extension_written: false, @@ -828,73 +828,73 @@ impl<'b> DescriptorProtoBuilder<'b> { } } - pub fn name(mut self, value: &str) -> roto_runtime::Result { + pub fn name(mut self, value: &str) -> crate::runtime::Result { self.builder.write_string(1, value)?; self.name_written = true; Ok(self) } - pub fn field(mut self, value: &[u8]) -> roto_runtime::Result { + pub fn field(mut self, value: &[u8]) -> crate::runtime::Result { self.builder.write_bytes(2, value)?; self.field_written = true; Ok(self) } - pub fn extension(mut self, value: &[u8]) -> roto_runtime::Result { + pub fn extension(mut self, value: &[u8]) -> crate::runtime::Result { self.builder.write_bytes(6, value)?; self.extension_written = true; Ok(self) } - pub fn nested_type(mut self, value: &[u8]) -> roto_runtime::Result { + pub fn nested_type(mut self, value: &[u8]) -> crate::runtime::Result { self.builder.write_bytes(3, value)?; self.nested_type_written = true; Ok(self) } - pub fn enum_type(mut self, value: &[u8]) -> roto_runtime::Result { + pub fn enum_type(mut self, value: &[u8]) -> crate::runtime::Result { self.builder.write_bytes(4, value)?; self.enum_type_written = true; Ok(self) } - pub fn extension_range(mut self, value: &[u8]) -> roto_runtime::Result { + pub fn extension_range(mut self, value: &[u8]) -> crate::runtime::Result { self.builder.write_bytes(5, value)?; self.extension_range_written = true; Ok(self) } - pub fn oneof_decl(mut self, value: &[u8]) -> roto_runtime::Result { + pub fn oneof_decl(mut self, value: &[u8]) -> crate::runtime::Result { self.builder.write_bytes(8, value)?; self.oneof_decl_written = true; Ok(self) } - pub fn options(mut self, value: &[u8]) -> roto_runtime::Result { + pub fn options(mut self, value: &[u8]) -> crate::runtime::Result { self.builder.write_bytes(7, value)?; self.options_written = true; Ok(self) } - pub fn reserved_range(mut self, value: &[u8]) -> roto_runtime::Result { + pub fn reserved_range(mut self, value: &[u8]) -> crate::runtime::Result { self.builder.write_bytes(9, value)?; self.reserved_range_written = true; Ok(self) } - pub fn reserved_name(mut self, value: &str) -> roto_runtime::Result { + pub fn reserved_name(mut self, value: &str) -> crate::runtime::Result { self.builder.write_string(10, value)?; self.reserved_name_written = true; Ok(self) } - pub fn visibility(mut self, value: u64) -> roto_runtime::Result { + pub fn visibility(mut self, value: u64) -> crate::runtime::Result { self.builder.write_varint(11, value)?; self.visibility_written = true; Ok(self) } - pub fn with(mut self, msg: &DescriptorProto<'_>) -> roto_runtime::Result { + pub fn with(mut self, msg: &DescriptorProto<'_>) -> crate::runtime::Result { for item in msg.raw_fields() { let (field_number, raw_bytes) = item?; let is_written = match field_number { @@ -918,7 +918,7 @@ impl<'b> DescriptorProtoBuilder<'b> { Ok(self) } - pub fn finish(self) -> roto_runtime::Result<&'b mut [u8]> { + pub fn finish(self) -> crate::runtime::Result<&'b mut [u8]> { self.builder.finish() } } @@ -927,15 +927,15 @@ pub struct OwnedDescriptorProto { pub data: bytes::Bytes, } -impl roto_runtime::RotoOwned for OwnedDescriptorProto { +impl crate::runtime::RotoOwned for OwnedDescriptorProto { type Reader<'a> = DescriptorProto<'a>; fn reader(&self) -> DescriptorProto<'_> { DescriptorProto::new(&self.data).expect("failed to create reader") } } -impl roto_runtime::RotoMessage for OwnedDescriptorProto { - fn decode(buf: bytes::Bytes) -> roto_runtime::Result { +impl crate::runtime::RotoMessage for OwnedDescriptorProto { + fn decode(buf: bytes::Bytes) -> crate::runtime::Result { Ok(OwnedDescriptorProto { data: buf }) } @@ -946,15 +946,15 @@ impl roto_runtime::RotoMessage for OwnedDescriptorProto { pub mod descriptor_proto { pub struct ExtensionRange<'a> { - accessor: roto_runtime::ProtoAccessor<'a>, + accessor: crate::runtime::ProtoAccessor<'a>, start_offset: Option, end_offset: Option, options_offset: Option, } impl<'a> ExtensionRange<'a> { - pub fn new(data: &'a [u8]) -> roto_runtime::Result { - let accessor = roto_runtime::ProtoAccessor::new(data)?; + pub fn new(data: &'a [u8]) -> crate::runtime::Result { + let accessor = crate::runtime::ProtoAccessor::new(data)?; let mut start_offset = None; let mut end_offset = None; let mut options_offset = None; @@ -973,50 +973,50 @@ options_offset, }) } - pub fn start(&self) -> roto_runtime::Result { - let offset = self.start_offset.ok_or(roto_runtime::RotoError::FieldNotFound)?; + pub fn start(&self) -> crate::runtime::Result { + let offset = self.start_offset.ok_or(crate::runtime::RotoError::FieldNotFound)?; let (bytes, _) = self.accessor.get_value_at(offset)?; - roto_runtime::read_varint(bytes).map(|(v, _)| v as i32).map_err(|_| roto_runtime::RotoError::WireFormatViolation) + crate::runtime::read_varint(bytes).map(|(v, _)| v as i32).map_err(|_| crate::runtime::RotoError::WireFormatViolation) } - pub fn start_or_default(&self) -> roto_runtime::Result { + pub fn start_or_default(&self) -> crate::runtime::Result { self.start().or(Ok(0)) } pub fn has_start(&self) -> bool { self.start_offset.is_some() } - pub fn end(&self) -> roto_runtime::Result { - let offset = self.end_offset.ok_or(roto_runtime::RotoError::FieldNotFound)?; + pub fn end(&self) -> crate::runtime::Result { + let offset = self.end_offset.ok_or(crate::runtime::RotoError::FieldNotFound)?; let (bytes, _) = self.accessor.get_value_at(offset)?; - roto_runtime::read_varint(bytes).map(|(v, _)| v as i32).map_err(|_| roto_runtime::RotoError::WireFormatViolation) + crate::runtime::read_varint(bytes).map(|(v, _)| v as i32).map_err(|_| crate::runtime::RotoError::WireFormatViolation) } - pub fn end_or_default(&self) -> roto_runtime::Result { + pub fn end_or_default(&self) -> crate::runtime::Result { self.end().or(Ok(0)) } pub fn has_end(&self) -> bool { self.end_offset.is_some() } - pub fn options(&self) -> roto_runtime::Result<&'a [u8]> { - let offset = self.options_offset.ok_or(roto_runtime::RotoError::FieldNotFound)?; + pub fn options(&self) -> crate::runtime::Result<&'a [u8]> { + let offset = self.options_offset.ok_or(crate::runtime::RotoError::FieldNotFound)?; let (bytes, _) = self.accessor.get_value_at(offset)?; Ok(bytes) } - pub fn options_or_default(&self) -> roto_runtime::Result<&'a [u8]> { + pub fn options_or_default(&self) -> crate::runtime::Result<&'a [u8]> { self.options().or(Ok(&[])) } pub fn has_options(&self) -> bool { self.options_offset.is_some() } - pub fn raw_fields(&self) -> roto_runtime::RawFieldIterator<'a> { + pub fn raw_fields(&self) -> crate::runtime::RawFieldIterator<'a> { self.accessor.raw_fields() } } pub struct ExtensionRangeBuilder<'b> { - builder: roto_runtime::ProtoBuilder<'b>, + builder: crate::runtime::ProtoBuilder<'b>, start_written: bool, end_written: bool, options_written: bool, @@ -1025,32 +1025,32 @@ pub struct ExtensionRangeBuilder<'b> { impl<'b> ExtensionRangeBuilder<'b> { pub fn builder(buf: &mut [u8]) -> ExtensionRangeBuilder<'_> { ExtensionRangeBuilder { - builder: roto_runtime::ProtoBuilder::new(buf), + builder: crate::runtime::ProtoBuilder::new(buf), start_written: false, end_written: false, options_written: false, } } - pub fn start(mut self, value: i32) -> roto_runtime::Result { + pub fn start(mut self, value: i32) -> crate::runtime::Result { self.builder.write_int32(1, value)?; self.start_written = true; Ok(self) } - pub fn end(mut self, value: i32) -> roto_runtime::Result { + pub fn end(mut self, value: i32) -> crate::runtime::Result { self.builder.write_int32(2, value)?; self.end_written = true; Ok(self) } - pub fn options(mut self, value: &[u8]) -> roto_runtime::Result { + pub fn options(mut self, value: &[u8]) -> crate::runtime::Result { self.builder.write_bytes(3, value)?; self.options_written = true; Ok(self) } - pub fn with(mut self, msg: &ExtensionRange<'_>) -> roto_runtime::Result { + pub fn with(mut self, msg: &ExtensionRange<'_>) -> crate::runtime::Result { for item in msg.raw_fields() { let (field_number, raw_bytes) = item?; let is_written = match field_number { @@ -1066,7 +1066,7 @@ impl<'b> ExtensionRangeBuilder<'b> { Ok(self) } - pub fn finish(self) -> roto_runtime::Result<&'b mut [u8]> { + pub fn finish(self) -> crate::runtime::Result<&'b mut [u8]> { self.builder.finish() } } @@ -1075,15 +1075,15 @@ pub struct OwnedExtensionRange { pub data: bytes::Bytes, } -impl roto_runtime::RotoOwned for OwnedExtensionRange { +impl crate::runtime::RotoOwned for OwnedExtensionRange { type Reader<'a> = ExtensionRange<'a>; fn reader(&self) -> ExtensionRange<'_> { ExtensionRange::new(&self.data).expect("failed to create reader") } } -impl roto_runtime::RotoMessage for OwnedExtensionRange { - fn decode(buf: bytes::Bytes) -> roto_runtime::Result { +impl crate::runtime::RotoMessage for OwnedExtensionRange { + fn decode(buf: bytes::Bytes) -> crate::runtime::Result { Ok(OwnedExtensionRange { data: buf }) } @@ -1093,14 +1093,14 @@ impl roto_runtime::RotoMessage for OwnedExtensionRange { } pub struct ReservedRange<'a> { - accessor: roto_runtime::ProtoAccessor<'a>, + accessor: crate::runtime::ProtoAccessor<'a>, start_offset: Option, end_offset: Option, } impl<'a> ReservedRange<'a> { - pub fn new(data: &'a [u8]) -> roto_runtime::Result { - let accessor = roto_runtime::ProtoAccessor::new(data)?; + pub fn new(data: &'a [u8]) -> crate::runtime::Result { + let accessor = crate::runtime::ProtoAccessor::new(data)?; let mut start_offset = None; let mut end_offset = None; for item in accessor.fields() { @@ -1116,38 +1116,38 @@ end_offset, }) } - pub fn start(&self) -> roto_runtime::Result { - let offset = self.start_offset.ok_or(roto_runtime::RotoError::FieldNotFound)?; + pub fn start(&self) -> crate::runtime::Result { + let offset = self.start_offset.ok_or(crate::runtime::RotoError::FieldNotFound)?; let (bytes, _) = self.accessor.get_value_at(offset)?; - roto_runtime::read_varint(bytes).map(|(v, _)| v as i32).map_err(|_| roto_runtime::RotoError::WireFormatViolation) + crate::runtime::read_varint(bytes).map(|(v, _)| v as i32).map_err(|_| crate::runtime::RotoError::WireFormatViolation) } - pub fn start_or_default(&self) -> roto_runtime::Result { + pub fn start_or_default(&self) -> crate::runtime::Result { self.start().or(Ok(0)) } pub fn has_start(&self) -> bool { self.start_offset.is_some() } - pub fn end(&self) -> roto_runtime::Result { - let offset = self.end_offset.ok_or(roto_runtime::RotoError::FieldNotFound)?; + pub fn end(&self) -> crate::runtime::Result { + let offset = self.end_offset.ok_or(crate::runtime::RotoError::FieldNotFound)?; let (bytes, _) = self.accessor.get_value_at(offset)?; - roto_runtime::read_varint(bytes).map(|(v, _)| v as i32).map_err(|_| roto_runtime::RotoError::WireFormatViolation) + crate::runtime::read_varint(bytes).map(|(v, _)| v as i32).map_err(|_| crate::runtime::RotoError::WireFormatViolation) } - pub fn end_or_default(&self) -> roto_runtime::Result { + pub fn end_or_default(&self) -> crate::runtime::Result { self.end().or(Ok(0)) } pub fn has_end(&self) -> bool { self.end_offset.is_some() } - pub fn raw_fields(&self) -> roto_runtime::RawFieldIterator<'a> { + pub fn raw_fields(&self) -> crate::runtime::RawFieldIterator<'a> { self.accessor.raw_fields() } } pub struct ReservedRangeBuilder<'b> { - builder: roto_runtime::ProtoBuilder<'b>, + builder: crate::runtime::ProtoBuilder<'b>, start_written: bool, end_written: bool, } @@ -1155,25 +1155,25 @@ pub struct ReservedRangeBuilder<'b> { impl<'b> ReservedRangeBuilder<'b> { pub fn builder(buf: &mut [u8]) -> ReservedRangeBuilder<'_> { ReservedRangeBuilder { - builder: roto_runtime::ProtoBuilder::new(buf), + builder: crate::runtime::ProtoBuilder::new(buf), start_written: false, end_written: false, } } - pub fn start(mut self, value: i32) -> roto_runtime::Result { + pub fn start(mut self, value: i32) -> crate::runtime::Result { self.builder.write_int32(1, value)?; self.start_written = true; Ok(self) } - pub fn end(mut self, value: i32) -> roto_runtime::Result { + pub fn end(mut self, value: i32) -> crate::runtime::Result { self.builder.write_int32(2, value)?; self.end_written = true; Ok(self) } - pub fn with(mut self, msg: &ReservedRange<'_>) -> roto_runtime::Result { + pub fn with(mut self, msg: &ReservedRange<'_>) -> crate::runtime::Result { for item in msg.raw_fields() { let (field_number, raw_bytes) = item?; let is_written = match field_number { @@ -1188,7 +1188,7 @@ impl<'b> ReservedRangeBuilder<'b> { Ok(self) } - pub fn finish(self) -> roto_runtime::Result<&'b mut [u8]> { + pub fn finish(self) -> crate::runtime::Result<&'b mut [u8]> { self.builder.finish() } } @@ -1197,15 +1197,15 @@ pub struct OwnedReservedRange { pub data: bytes::Bytes, } -impl roto_runtime::RotoOwned for OwnedReservedRange { +impl crate::runtime::RotoOwned for OwnedReservedRange { type Reader<'a> = ReservedRange<'a>; fn reader(&self) -> ReservedRange<'_> { ReservedRange::new(&self.data).expect("failed to create reader") } } -impl roto_runtime::RotoMessage for OwnedReservedRange { - fn decode(buf: bytes::Bytes) -> roto_runtime::Result { +impl crate::runtime::RotoMessage for OwnedReservedRange { + fn decode(buf: bytes::Bytes) -> crate::runtime::Result { Ok(OwnedReservedRange { data: buf }) } @@ -1217,7 +1217,7 @@ impl roto_runtime::RotoMessage for OwnedReservedRange { } pub struct ExtensionRangeOptions<'a> { - accessor: roto_runtime::ProtoAccessor<'a>, + accessor: crate::runtime::ProtoAccessor<'a>, uninterpreted_option_start: Option, uninterpreted_option_end: Option, declaration_start: Option, @@ -1227,8 +1227,8 @@ pub struct ExtensionRangeOptions<'a> { } impl<'a> ExtensionRangeOptions<'a> { - pub fn new(data: &'a [u8]) -> roto_runtime::Result { - let accessor = roto_runtime::ProtoAccessor::new(data)?; + pub fn new(data: &'a [u8]) -> crate::runtime::Result { + let accessor = crate::runtime::ProtoAccessor::new(data)?; let mut uninterpreted_option_start = None; let mut uninterpreted_option_end = None; let mut declaration_start = None; @@ -1258,52 +1258,52 @@ verification_offset, }) } - pub fn uninterpreted_option(&self) -> roto_runtime::RepeatedFieldIterator<'a> { + pub fn uninterpreted_option(&self) -> crate::runtime::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) -> roto_runtime::RepeatedFieldIterator<'a> { + pub fn declaration(&self) -> crate::runtime::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) -> roto_runtime::Result<&'a [u8]> { - let offset = self.features_offset.ok_or(roto_runtime::RotoError::FieldNotFound)?; + pub fn features(&self) -> crate::runtime::Result<&'a [u8]> { + let offset = self.features_offset.ok_or(crate::runtime::RotoError::FieldNotFound)?; let (bytes, _) = self.accessor.get_value_at(offset)?; Ok(bytes) } - pub fn features_or_default(&self) -> roto_runtime::Result<&'a [u8]> { + pub fn features_or_default(&self) -> crate::runtime::Result<&'a [u8]> { self.features().or(Ok(&[])) } pub fn has_features(&self) -> bool { self.features_offset.is_some() } - pub fn verification(&self) -> roto_runtime::Result { - let offset = self.verification_offset.ok_or(roto_runtime::RotoError::FieldNotFound)?; + pub fn verification(&self) -> crate::runtime::Result { + let offset = self.verification_offset.ok_or(crate::runtime::RotoError::FieldNotFound)?; let (bytes, _) = self.accessor.get_value_at(offset)?; - roto_runtime::read_varint(bytes).map(|(v, _)| v as u64).map_err(|_| roto_runtime::RotoError::WireFormatViolation) + crate::runtime::read_varint(bytes).map(|(v, _)| v as u64).map_err(|_| crate::runtime::RotoError::WireFormatViolation) } - pub fn verification_or_default(&self) -> roto_runtime::Result { + pub fn verification_or_default(&self) -> crate::runtime::Result { self.verification().or(Ok(0)) } pub fn has_verification(&self) -> bool { self.verification_offset.is_some() } - pub fn raw_fields(&self) -> roto_runtime::RawFieldIterator<'a> { + pub fn raw_fields(&self) -> crate::runtime::RawFieldIterator<'a> { self.accessor.raw_fields() } } pub struct ExtensionRangeOptionsBuilder<'b> { - builder: roto_runtime::ProtoBuilder<'b>, + builder: crate::runtime::ProtoBuilder<'b>, uninterpreted_option_written: bool, declaration_written: bool, features_written: bool, @@ -1313,7 +1313,7 @@ pub struct ExtensionRangeOptionsBuilder<'b> { impl<'b> ExtensionRangeOptionsBuilder<'b> { pub fn builder(buf: &mut [u8]) -> ExtensionRangeOptionsBuilder<'_> { ExtensionRangeOptionsBuilder { - builder: roto_runtime::ProtoBuilder::new(buf), + builder: crate::runtime::ProtoBuilder::new(buf), uninterpreted_option_written: false, declaration_written: false, features_written: false, @@ -1321,31 +1321,31 @@ impl<'b> ExtensionRangeOptionsBuilder<'b> { } } - pub fn uninterpreted_option(mut self, value: &[u8]) -> roto_runtime::Result { + pub fn uninterpreted_option(mut self, value: &[u8]) -> crate::runtime::Result { self.builder.write_bytes(999, value)?; self.uninterpreted_option_written = true; Ok(self) } - pub fn declaration(mut self, value: &[u8]) -> roto_runtime::Result { + pub fn declaration(mut self, value: &[u8]) -> crate::runtime::Result { self.builder.write_bytes(2, value)?; self.declaration_written = true; Ok(self) } - pub fn features(mut self, value: &[u8]) -> roto_runtime::Result { + pub fn features(mut self, value: &[u8]) -> crate::runtime::Result { self.builder.write_bytes(50, value)?; self.features_written = true; Ok(self) } - pub fn verification(mut self, value: u64) -> roto_runtime::Result { + pub fn verification(mut self, value: u64) -> crate::runtime::Result { self.builder.write_varint(3, value)?; self.verification_written = true; Ok(self) } - pub fn with(mut self, msg: &ExtensionRangeOptions<'_>) -> roto_runtime::Result { + pub fn with(mut self, msg: &ExtensionRangeOptions<'_>) -> crate::runtime::Result { for item in msg.raw_fields() { let (field_number, raw_bytes) = item?; let is_written = match field_number { @@ -1362,7 +1362,7 @@ impl<'b> ExtensionRangeOptionsBuilder<'b> { Ok(self) } - pub fn finish(self) -> roto_runtime::Result<&'b mut [u8]> { + pub fn finish(self) -> crate::runtime::Result<&'b mut [u8]> { self.builder.finish() } } @@ -1371,15 +1371,15 @@ pub struct OwnedExtensionRangeOptions { pub data: bytes::Bytes, } -impl roto_runtime::RotoOwned for OwnedExtensionRangeOptions { +impl crate::runtime::RotoOwned for OwnedExtensionRangeOptions { type Reader<'a> = ExtensionRangeOptions<'a>; fn reader(&self) -> ExtensionRangeOptions<'_> { ExtensionRangeOptions::new(&self.data).expect("failed to create reader") } } -impl roto_runtime::RotoMessage for OwnedExtensionRangeOptions { - fn decode(buf: bytes::Bytes) -> roto_runtime::Result { +impl crate::runtime::RotoMessage for OwnedExtensionRangeOptions { + fn decode(buf: bytes::Bytes) -> crate::runtime::Result { Ok(OwnedExtensionRangeOptions { data: buf }) } @@ -1407,7 +1407,7 @@ impl VerificationState { } pub struct Declaration<'a> { - accessor: roto_runtime::ProtoAccessor<'a>, + accessor: crate::runtime::ProtoAccessor<'a>, number_offset: Option, full_name_offset: Option, type_offset: Option, @@ -1416,8 +1416,8 @@ pub struct Declaration<'a> { } impl<'a> Declaration<'a> { - pub fn new(data: &'a [u8]) -> roto_runtime::Result { - let accessor = roto_runtime::ProtoAccessor::new(data)?; + pub fn new(data: &'a [u8]) -> crate::runtime::Result { + let accessor = crate::runtime::ProtoAccessor::new(data)?; let mut number_offset = None; let mut full_name_offset = None; let mut type_offset = None; @@ -1442,74 +1442,74 @@ repeated_offset, }) } - pub fn number(&self) -> roto_runtime::Result { - let offset = self.number_offset.ok_or(roto_runtime::RotoError::FieldNotFound)?; + pub fn number(&self) -> crate::runtime::Result { + let offset = self.number_offset.ok_or(crate::runtime::RotoError::FieldNotFound)?; let (bytes, _) = self.accessor.get_value_at(offset)?; - roto_runtime::read_varint(bytes).map(|(v, _)| v as i32).map_err(|_| roto_runtime::RotoError::WireFormatViolation) + crate::runtime::read_varint(bytes).map(|(v, _)| v as i32).map_err(|_| crate::runtime::RotoError::WireFormatViolation) } - pub fn number_or_default(&self) -> roto_runtime::Result { + pub fn number_or_default(&self) -> crate::runtime::Result { self.number().or(Ok(0)) } pub fn has_number(&self) -> bool { self.number_offset.is_some() } - pub fn full_name(&self) -> roto_runtime::Result<&'a str> { - let offset = self.full_name_offset.ok_or(roto_runtime::RotoError::FieldNotFound)?; + pub fn full_name(&self) -> crate::runtime::Result<&'a str> { + let offset = self.full_name_offset.ok_or(crate::runtime::RotoError::FieldNotFound)?; let (bytes, _) = self.accessor.get_value_at(offset)?; - str::from_utf8(bytes).map_err(|_| roto_runtime::RotoError::WireFormatViolation) + str::from_utf8(bytes).map_err(|_| crate::runtime::RotoError::WireFormatViolation) } - pub fn full_name_or_default(&self) -> roto_runtime::Result<&'a str> { + pub fn full_name_or_default(&self) -> crate::runtime::Result<&'a str> { self.full_name().or(Ok("")) } pub fn has_full_name(&self) -> bool { self.full_name_offset.is_some() } - pub fn r#type(&self) -> roto_runtime::Result<&'a str> { - let offset = self.type_offset.ok_or(roto_runtime::RotoError::FieldNotFound)?; + pub fn r#type(&self) -> crate::runtime::Result<&'a str> { + let offset = self.type_offset.ok_or(crate::runtime::RotoError::FieldNotFound)?; let (bytes, _) = self.accessor.get_value_at(offset)?; - str::from_utf8(bytes).map_err(|_| roto_runtime::RotoError::WireFormatViolation) + str::from_utf8(bytes).map_err(|_| crate::runtime::RotoError::WireFormatViolation) } - pub fn r#type_or_default(&self) -> roto_runtime::Result<&'a str> { + pub fn r#type_or_default(&self) -> crate::runtime::Result<&'a str> { self.r#type().or(Ok("")) } pub fn has_type(&self) -> bool { self.type_offset.is_some() } - pub fn reserved(&self) -> roto_runtime::Result { - let offset = self.reserved_offset.ok_or(roto_runtime::RotoError::FieldNotFound)?; + pub fn reserved(&self) -> crate::runtime::Result { + let offset = self.reserved_offset.ok_or(crate::runtime::RotoError::FieldNotFound)?; let (bytes, _) = self.accessor.get_value_at(offset)?; - roto_runtime::read_varint(bytes).map(|(v, _)| v != 0).map_err(|_| roto_runtime::RotoError::WireFormatViolation) + crate::runtime::read_varint(bytes).map(|(v, _)| v != 0).map_err(|_| crate::runtime::RotoError::WireFormatViolation) } - pub fn reserved_or_default(&self) -> roto_runtime::Result { + pub fn reserved_or_default(&self) -> crate::runtime::Result { self.reserved().or(Ok(false)) } pub fn has_reserved(&self) -> bool { self.reserved_offset.is_some() } - pub fn repeated(&self) -> roto_runtime::Result { - let offset = self.repeated_offset.ok_or(roto_runtime::RotoError::FieldNotFound)?; + pub fn repeated(&self) -> crate::runtime::Result { + let offset = self.repeated_offset.ok_or(crate::runtime::RotoError::FieldNotFound)?; let (bytes, _) = self.accessor.get_value_at(offset)?; - roto_runtime::read_varint(bytes).map(|(v, _)| v != 0).map_err(|_| roto_runtime::RotoError::WireFormatViolation) + crate::runtime::read_varint(bytes).map(|(v, _)| v != 0).map_err(|_| crate::runtime::RotoError::WireFormatViolation) } - pub fn repeated_or_default(&self) -> roto_runtime::Result { + pub fn repeated_or_default(&self) -> crate::runtime::Result { self.repeated().or(Ok(false)) } pub fn has_repeated(&self) -> bool { self.repeated_offset.is_some() } - pub fn raw_fields(&self) -> roto_runtime::RawFieldIterator<'a> { + pub fn raw_fields(&self) -> crate::runtime::RawFieldIterator<'a> { self.accessor.raw_fields() } } pub struct DeclarationBuilder<'b> { - builder: roto_runtime::ProtoBuilder<'b>, + builder: crate::runtime::ProtoBuilder<'b>, number_written: bool, full_name_written: bool, type_written: bool, @@ -1520,7 +1520,7 @@ pub struct DeclarationBuilder<'b> { impl<'b> DeclarationBuilder<'b> { pub fn builder(buf: &mut [u8]) -> DeclarationBuilder<'_> { DeclarationBuilder { - builder: roto_runtime::ProtoBuilder::new(buf), + builder: crate::runtime::ProtoBuilder::new(buf), number_written: false, full_name_written: false, type_written: false, @@ -1529,37 +1529,37 @@ impl<'b> DeclarationBuilder<'b> { } } - pub fn number(mut self, value: i32) -> roto_runtime::Result { + pub fn number(mut self, value: i32) -> crate::runtime::Result { self.builder.write_int32(1, value)?; self.number_written = true; Ok(self) } - pub fn full_name(mut self, value: &str) -> roto_runtime::Result { + pub fn full_name(mut self, value: &str) -> crate::runtime::Result { self.builder.write_string(2, value)?; self.full_name_written = true; Ok(self) } - pub fn r#type(mut self, value: &str) -> roto_runtime::Result { + pub fn r#type(mut self, value: &str) -> crate::runtime::Result { self.builder.write_string(3, value)?; self.type_written = true; Ok(self) } - pub fn reserved(mut self, value: u64) -> roto_runtime::Result { + pub fn reserved(mut self, value: u64) -> crate::runtime::Result { self.builder.write_varint(5, value)?; self.reserved_written = true; Ok(self) } - pub fn repeated(mut self, value: u64) -> roto_runtime::Result { + pub fn repeated(mut self, value: u64) -> crate::runtime::Result { self.builder.write_varint(6, value)?; self.repeated_written = true; Ok(self) } - pub fn with(mut self, msg: &Declaration<'_>) -> roto_runtime::Result { + pub fn with(mut self, msg: &Declaration<'_>) -> crate::runtime::Result { for item in msg.raw_fields() { let (field_number, raw_bytes) = item?; let is_written = match field_number { @@ -1577,7 +1577,7 @@ impl<'b> DeclarationBuilder<'b> { Ok(self) } - pub fn finish(self) -> roto_runtime::Result<&'b mut [u8]> { + pub fn finish(self) -> crate::runtime::Result<&'b mut [u8]> { self.builder.finish() } } @@ -1586,15 +1586,15 @@ pub struct OwnedDeclaration { pub data: bytes::Bytes, } -impl roto_runtime::RotoOwned for OwnedDeclaration { +impl crate::runtime::RotoOwned for OwnedDeclaration { type Reader<'a> = Declaration<'a>; fn reader(&self) -> Declaration<'_> { Declaration::new(&self.data).expect("failed to create reader") } } -impl roto_runtime::RotoMessage for OwnedDeclaration { - fn decode(buf: bytes::Bytes) -> roto_runtime::Result { +impl crate::runtime::RotoMessage for OwnedDeclaration { + fn decode(buf: bytes::Bytes) -> crate::runtime::Result { Ok(OwnedDeclaration { data: buf }) } @@ -1606,7 +1606,7 @@ impl roto_runtime::RotoMessage for OwnedDeclaration { } pub struct FieldDescriptorProto<'a> { - accessor: roto_runtime::ProtoAccessor<'a>, + accessor: crate::runtime::ProtoAccessor<'a>, name_offset: Option, number_offset: Option, label_offset: Option, @@ -1621,8 +1621,8 @@ pub struct FieldDescriptorProto<'a> { } impl<'a> FieldDescriptorProto<'a> { - pub fn new(data: &'a [u8]) -> roto_runtime::Result { - let accessor = roto_runtime::ProtoAccessor::new(data)?; + pub fn new(data: &'a [u8]) -> crate::runtime::Result { + let accessor = crate::runtime::ProtoAccessor::new(data)?; let mut name_offset = None; let mut number_offset = None; let mut label_offset = None; @@ -1665,146 +1665,146 @@ proto3_optional_offset, }) } - pub fn name(&self) -> roto_runtime::Result<&'a str> { - let offset = self.name_offset.ok_or(roto_runtime::RotoError::FieldNotFound)?; + pub fn name(&self) -> crate::runtime::Result<&'a str> { + let offset = self.name_offset.ok_or(crate::runtime::RotoError::FieldNotFound)?; let (bytes, _) = self.accessor.get_value_at(offset)?; - str::from_utf8(bytes).map_err(|_| roto_runtime::RotoError::WireFormatViolation) + str::from_utf8(bytes).map_err(|_| crate::runtime::RotoError::WireFormatViolation) } - pub fn name_or_default(&self) -> roto_runtime::Result<&'a str> { + pub fn name_or_default(&self) -> crate::runtime::Result<&'a str> { self.name().or(Ok("")) } pub fn has_name(&self) -> bool { self.name_offset.is_some() } - pub fn number(&self) -> roto_runtime::Result { - let offset = self.number_offset.ok_or(roto_runtime::RotoError::FieldNotFound)?; + pub fn number(&self) -> crate::runtime::Result { + let offset = self.number_offset.ok_or(crate::runtime::RotoError::FieldNotFound)?; let (bytes, _) = self.accessor.get_value_at(offset)?; - roto_runtime::read_varint(bytes).map(|(v, _)| v as i32).map_err(|_| roto_runtime::RotoError::WireFormatViolation) + crate::runtime::read_varint(bytes).map(|(v, _)| v as i32).map_err(|_| crate::runtime::RotoError::WireFormatViolation) } - pub fn number_or_default(&self) -> roto_runtime::Result { + pub fn number_or_default(&self) -> crate::runtime::Result { self.number().or(Ok(0)) } pub fn has_number(&self) -> bool { self.number_offset.is_some() } - pub fn label(&self) -> roto_runtime::Result { - let offset = self.label_offset.ok_or(roto_runtime::RotoError::FieldNotFound)?; + pub fn label(&self) -> crate::runtime::Result { + let offset = self.label_offset.ok_or(crate::runtime::RotoError::FieldNotFound)?; let (bytes, _) = self.accessor.get_value_at(offset)?; - roto_runtime::read_varint(bytes).map(|(v, _)| v as u64).map_err(|_| roto_runtime::RotoError::WireFormatViolation) + crate::runtime::read_varint(bytes).map(|(v, _)| v as u64).map_err(|_| crate::runtime::RotoError::WireFormatViolation) } - pub fn label_or_default(&self) -> roto_runtime::Result { + pub fn label_or_default(&self) -> crate::runtime::Result { self.label().or(Ok(0)) } pub fn has_label(&self) -> bool { self.label_offset.is_some() } - pub fn r#type(&self) -> roto_runtime::Result { - let offset = self.type_offset.ok_or(roto_runtime::RotoError::FieldNotFound)?; + pub fn r#type(&self) -> crate::runtime::Result { + let offset = self.type_offset.ok_or(crate::runtime::RotoError::FieldNotFound)?; let (bytes, _) = self.accessor.get_value_at(offset)?; - roto_runtime::read_varint(bytes).map(|(v, _)| v as u64).map_err(|_| roto_runtime::RotoError::WireFormatViolation) + crate::runtime::read_varint(bytes).map(|(v, _)| v as u64).map_err(|_| crate::runtime::RotoError::WireFormatViolation) } - pub fn r#type_or_default(&self) -> roto_runtime::Result { + pub fn r#type_or_default(&self) -> crate::runtime::Result { self.r#type().or(Ok(0)) } pub fn has_type(&self) -> bool { self.type_offset.is_some() } - pub fn type_name(&self) -> roto_runtime::Result<&'a str> { - let offset = self.type_name_offset.ok_or(roto_runtime::RotoError::FieldNotFound)?; + pub fn type_name(&self) -> crate::runtime::Result<&'a str> { + let offset = self.type_name_offset.ok_or(crate::runtime::RotoError::FieldNotFound)?; let (bytes, _) = self.accessor.get_value_at(offset)?; - str::from_utf8(bytes).map_err(|_| roto_runtime::RotoError::WireFormatViolation) + str::from_utf8(bytes).map_err(|_| crate::runtime::RotoError::WireFormatViolation) } - pub fn type_name_or_default(&self) -> roto_runtime::Result<&'a str> { + pub fn type_name_or_default(&self) -> crate::runtime::Result<&'a str> { self.type_name().or(Ok("")) } pub fn has_type_name(&self) -> bool { self.type_name_offset.is_some() } - pub fn extendee(&self) -> roto_runtime::Result<&'a str> { - let offset = self.extendee_offset.ok_or(roto_runtime::RotoError::FieldNotFound)?; + pub fn extendee(&self) -> crate::runtime::Result<&'a str> { + let offset = self.extendee_offset.ok_or(crate::runtime::RotoError::FieldNotFound)?; let (bytes, _) = self.accessor.get_value_at(offset)?; - str::from_utf8(bytes).map_err(|_| roto_runtime::RotoError::WireFormatViolation) + str::from_utf8(bytes).map_err(|_| crate::runtime::RotoError::WireFormatViolation) } - pub fn extendee_or_default(&self) -> roto_runtime::Result<&'a str> { + pub fn extendee_or_default(&self) -> crate::runtime::Result<&'a str> { self.extendee().or(Ok("")) } pub fn has_extendee(&self) -> bool { self.extendee_offset.is_some() } - pub fn default_value(&self) -> roto_runtime::Result<&'a str> { - let offset = self.default_value_offset.ok_or(roto_runtime::RotoError::FieldNotFound)?; + pub fn default_value(&self) -> crate::runtime::Result<&'a str> { + let offset = self.default_value_offset.ok_or(crate::runtime::RotoError::FieldNotFound)?; let (bytes, _) = self.accessor.get_value_at(offset)?; - str::from_utf8(bytes).map_err(|_| roto_runtime::RotoError::WireFormatViolation) + str::from_utf8(bytes).map_err(|_| crate::runtime::RotoError::WireFormatViolation) } - pub fn default_value_or_default(&self) -> roto_runtime::Result<&'a str> { + pub fn default_value_or_default(&self) -> crate::runtime::Result<&'a str> { self.default_value().or(Ok("")) } pub fn has_default_value(&self) -> bool { self.default_value_offset.is_some() } - pub fn oneof_index(&self) -> roto_runtime::Result { - let offset = self.oneof_index_offset.ok_or(roto_runtime::RotoError::FieldNotFound)?; + pub fn oneof_index(&self) -> crate::runtime::Result { + let offset = self.oneof_index_offset.ok_or(crate::runtime::RotoError::FieldNotFound)?; let (bytes, _) = self.accessor.get_value_at(offset)?; - roto_runtime::read_varint(bytes).map(|(v, _)| v as i32).map_err(|_| roto_runtime::RotoError::WireFormatViolation) + crate::runtime::read_varint(bytes).map(|(v, _)| v as i32).map_err(|_| crate::runtime::RotoError::WireFormatViolation) } - pub fn oneof_index_or_default(&self) -> roto_runtime::Result { + pub fn oneof_index_or_default(&self) -> crate::runtime::Result { self.oneof_index().or(Ok(0)) } pub fn has_oneof_index(&self) -> bool { self.oneof_index_offset.is_some() } - pub fn json_name(&self) -> roto_runtime::Result<&'a str> { - let offset = self.json_name_offset.ok_or(roto_runtime::RotoError::FieldNotFound)?; + pub fn json_name(&self) -> crate::runtime::Result<&'a str> { + let offset = self.json_name_offset.ok_or(crate::runtime::RotoError::FieldNotFound)?; let (bytes, _) = self.accessor.get_value_at(offset)?; - str::from_utf8(bytes).map_err(|_| roto_runtime::RotoError::WireFormatViolation) + str::from_utf8(bytes).map_err(|_| crate::runtime::RotoError::WireFormatViolation) } - pub fn json_name_or_default(&self) -> roto_runtime::Result<&'a str> { + pub fn json_name_or_default(&self) -> crate::runtime::Result<&'a str> { self.json_name().or(Ok("")) } pub fn has_json_name(&self) -> bool { self.json_name_offset.is_some() } - pub fn options(&self) -> roto_runtime::Result<&'a [u8]> { - let offset = self.options_offset.ok_or(roto_runtime::RotoError::FieldNotFound)?; + pub fn options(&self) -> crate::runtime::Result<&'a [u8]> { + let offset = self.options_offset.ok_or(crate::runtime::RotoError::FieldNotFound)?; let (bytes, _) = self.accessor.get_value_at(offset)?; Ok(bytes) } - pub fn options_or_default(&self) -> roto_runtime::Result<&'a [u8]> { + pub fn options_or_default(&self) -> crate::runtime::Result<&'a [u8]> { self.options().or(Ok(&[])) } pub fn has_options(&self) -> bool { self.options_offset.is_some() } - pub fn proto3_optional(&self) -> roto_runtime::Result { - let offset = self.proto3_optional_offset.ok_or(roto_runtime::RotoError::FieldNotFound)?; + pub fn proto3_optional(&self) -> crate::runtime::Result { + let offset = self.proto3_optional_offset.ok_or(crate::runtime::RotoError::FieldNotFound)?; let (bytes, _) = self.accessor.get_value_at(offset)?; - roto_runtime::read_varint(bytes).map(|(v, _)| v != 0).map_err(|_| roto_runtime::RotoError::WireFormatViolation) + crate::runtime::read_varint(bytes).map(|(v, _)| v != 0).map_err(|_| crate::runtime::RotoError::WireFormatViolation) } - pub fn proto3_optional_or_default(&self) -> roto_runtime::Result { + pub fn proto3_optional_or_default(&self) -> crate::runtime::Result { self.proto3_optional().or(Ok(false)) } pub fn has_proto3_optional(&self) -> bool { self.proto3_optional_offset.is_some() } - pub fn raw_fields(&self) -> roto_runtime::RawFieldIterator<'a> { + pub fn raw_fields(&self) -> crate::runtime::RawFieldIterator<'a> { self.accessor.raw_fields() } } pub struct FieldDescriptorProtoBuilder<'b> { - builder: roto_runtime::ProtoBuilder<'b>, + builder: crate::runtime::ProtoBuilder<'b>, name_written: bool, number_written: bool, label_written: bool, @@ -1821,7 +1821,7 @@ pub struct FieldDescriptorProtoBuilder<'b> { impl<'b> FieldDescriptorProtoBuilder<'b> { pub fn builder(buf: &mut [u8]) -> FieldDescriptorProtoBuilder<'_> { FieldDescriptorProtoBuilder { - builder: roto_runtime::ProtoBuilder::new(buf), + builder: crate::runtime::ProtoBuilder::new(buf), name_written: false, number_written: false, label_written: false, @@ -1836,73 +1836,73 @@ impl<'b> FieldDescriptorProtoBuilder<'b> { } } - pub fn name(mut self, value: &str) -> roto_runtime::Result { + pub fn name(mut self, value: &str) -> crate::runtime::Result { self.builder.write_string(1, value)?; self.name_written = true; Ok(self) } - pub fn number(mut self, value: i32) -> roto_runtime::Result { + pub fn number(mut self, value: i32) -> crate::runtime::Result { self.builder.write_int32(3, value)?; self.number_written = true; Ok(self) } - pub fn label(mut self, value: u64) -> roto_runtime::Result { + pub fn label(mut self, value: u64) -> crate::runtime::Result { self.builder.write_varint(4, value)?; self.label_written = true; Ok(self) } - pub fn r#type(mut self, value: u64) -> roto_runtime::Result { + pub fn r#type(mut self, value: u64) -> crate::runtime::Result { self.builder.write_varint(5, value)?; self.type_written = true; Ok(self) } - pub fn type_name(mut self, value: &str) -> roto_runtime::Result { + pub fn type_name(mut self, value: &str) -> crate::runtime::Result { self.builder.write_string(6, value)?; self.type_name_written = true; Ok(self) } - pub fn extendee(mut self, value: &str) -> roto_runtime::Result { + pub fn extendee(mut self, value: &str) -> crate::runtime::Result { self.builder.write_string(2, value)?; self.extendee_written = true; Ok(self) } - pub fn default_value(mut self, value: &str) -> roto_runtime::Result { + pub fn default_value(mut self, value: &str) -> crate::runtime::Result { self.builder.write_string(7, value)?; self.default_value_written = true; Ok(self) } - pub fn oneof_index(mut self, value: i32) -> roto_runtime::Result { + pub fn oneof_index(mut self, value: i32) -> crate::runtime::Result { self.builder.write_int32(9, value)?; self.oneof_index_written = true; Ok(self) } - pub fn json_name(mut self, value: &str) -> roto_runtime::Result { + pub fn json_name(mut self, value: &str) -> crate::runtime::Result { self.builder.write_string(10, value)?; self.json_name_written = true; Ok(self) } - pub fn options(mut self, value: &[u8]) -> roto_runtime::Result { + pub fn options(mut self, value: &[u8]) -> crate::runtime::Result { self.builder.write_bytes(8, value)?; self.options_written = true; Ok(self) } - pub fn proto3_optional(mut self, value: u64) -> roto_runtime::Result { + pub fn proto3_optional(mut self, value: u64) -> crate::runtime::Result { self.builder.write_varint(17, value)?; self.proto3_optional_written = true; Ok(self) } - pub fn with(mut self, msg: &FieldDescriptorProto<'_>) -> roto_runtime::Result { + pub fn with(mut self, msg: &FieldDescriptorProto<'_>) -> crate::runtime::Result { for item in msg.raw_fields() { let (field_number, raw_bytes) = item?; let is_written = match field_number { @@ -1926,7 +1926,7 @@ impl<'b> FieldDescriptorProtoBuilder<'b> { Ok(self) } - pub fn finish(self) -> roto_runtime::Result<&'b mut [u8]> { + pub fn finish(self) -> crate::runtime::Result<&'b mut [u8]> { self.builder.finish() } } @@ -1935,15 +1935,15 @@ pub struct OwnedFieldDescriptorProto { pub data: bytes::Bytes, } -impl roto_runtime::RotoOwned for OwnedFieldDescriptorProto { +impl crate::runtime::RotoOwned for OwnedFieldDescriptorProto { type Reader<'a> = FieldDescriptorProto<'a>; fn reader(&self) -> FieldDescriptorProto<'_> { FieldDescriptorProto::new(&self.data).expect("failed to create reader") } } -impl roto_runtime::RotoMessage for OwnedFieldDescriptorProto { - fn decode(buf: bytes::Bytes) -> roto_runtime::Result { +impl crate::runtime::RotoMessage for OwnedFieldDescriptorProto { + fn decode(buf: bytes::Bytes) -> crate::runtime::Result { Ok(OwnedFieldDescriptorProto { data: buf }) } @@ -2026,14 +2026,14 @@ impl Label { } pub struct OneofDescriptorProto<'a> { - accessor: roto_runtime::ProtoAccessor<'a>, + accessor: crate::runtime::ProtoAccessor<'a>, name_offset: Option, options_offset: Option, } impl<'a> OneofDescriptorProto<'a> { - pub fn new(data: &'a [u8]) -> roto_runtime::Result { - let accessor = roto_runtime::ProtoAccessor::new(data)?; + pub fn new(data: &'a [u8]) -> crate::runtime::Result { + let accessor = crate::runtime::ProtoAccessor::new(data)?; let mut name_offset = None; let mut options_offset = None; for item in accessor.fields() { @@ -2049,38 +2049,38 @@ options_offset, }) } - pub fn name(&self) -> roto_runtime::Result<&'a str> { - let offset = self.name_offset.ok_or(roto_runtime::RotoError::FieldNotFound)?; + pub fn name(&self) -> crate::runtime::Result<&'a str> { + let offset = self.name_offset.ok_or(crate::runtime::RotoError::FieldNotFound)?; let (bytes, _) = self.accessor.get_value_at(offset)?; - str::from_utf8(bytes).map_err(|_| roto_runtime::RotoError::WireFormatViolation) + str::from_utf8(bytes).map_err(|_| crate::runtime::RotoError::WireFormatViolation) } - pub fn name_or_default(&self) -> roto_runtime::Result<&'a str> { + pub fn name_or_default(&self) -> crate::runtime::Result<&'a str> { self.name().or(Ok("")) } pub fn has_name(&self) -> bool { self.name_offset.is_some() } - pub fn options(&self) -> roto_runtime::Result<&'a [u8]> { - let offset = self.options_offset.ok_or(roto_runtime::RotoError::FieldNotFound)?; + pub fn options(&self) -> crate::runtime::Result<&'a [u8]> { + let offset = self.options_offset.ok_or(crate::runtime::RotoError::FieldNotFound)?; let (bytes, _) = self.accessor.get_value_at(offset)?; Ok(bytes) } - pub fn options_or_default(&self) -> roto_runtime::Result<&'a [u8]> { + pub fn options_or_default(&self) -> crate::runtime::Result<&'a [u8]> { self.options().or(Ok(&[])) } pub fn has_options(&self) -> bool { self.options_offset.is_some() } - pub fn raw_fields(&self) -> roto_runtime::RawFieldIterator<'a> { + pub fn raw_fields(&self) -> crate::runtime::RawFieldIterator<'a> { self.accessor.raw_fields() } } pub struct OneofDescriptorProtoBuilder<'b> { - builder: roto_runtime::ProtoBuilder<'b>, + builder: crate::runtime::ProtoBuilder<'b>, name_written: bool, options_written: bool, } @@ -2088,25 +2088,25 @@ pub struct OneofDescriptorProtoBuilder<'b> { impl<'b> OneofDescriptorProtoBuilder<'b> { pub fn builder(buf: &mut [u8]) -> OneofDescriptorProtoBuilder<'_> { OneofDescriptorProtoBuilder { - builder: roto_runtime::ProtoBuilder::new(buf), + builder: crate::runtime::ProtoBuilder::new(buf), name_written: false, options_written: false, } } - pub fn name(mut self, value: &str) -> roto_runtime::Result { + pub fn name(mut self, value: &str) -> crate::runtime::Result { self.builder.write_string(1, value)?; self.name_written = true; Ok(self) } - pub fn options(mut self, value: &[u8]) -> roto_runtime::Result { + pub fn options(mut self, value: &[u8]) -> crate::runtime::Result { self.builder.write_bytes(2, value)?; self.options_written = true; Ok(self) } - pub fn with(mut self, msg: &OneofDescriptorProto<'_>) -> roto_runtime::Result { + pub fn with(mut self, msg: &OneofDescriptorProto<'_>) -> crate::runtime::Result { for item in msg.raw_fields() { let (field_number, raw_bytes) = item?; let is_written = match field_number { @@ -2121,7 +2121,7 @@ impl<'b> OneofDescriptorProtoBuilder<'b> { Ok(self) } - pub fn finish(self) -> roto_runtime::Result<&'b mut [u8]> { + pub fn finish(self) -> crate::runtime::Result<&'b mut [u8]> { self.builder.finish() } } @@ -2130,15 +2130,15 @@ pub struct OwnedOneofDescriptorProto { pub data: bytes::Bytes, } -impl roto_runtime::RotoOwned for OwnedOneofDescriptorProto { +impl crate::runtime::RotoOwned for OwnedOneofDescriptorProto { type Reader<'a> = OneofDescriptorProto<'a>; fn reader(&self) -> OneofDescriptorProto<'_> { OneofDescriptorProto::new(&self.data).expect("failed to create reader") } } -impl roto_runtime::RotoMessage for OwnedOneofDescriptorProto { - fn decode(buf: bytes::Bytes) -> roto_runtime::Result { +impl crate::runtime::RotoMessage for OwnedOneofDescriptorProto { + fn decode(buf: bytes::Bytes) -> crate::runtime::Result { Ok(OwnedOneofDescriptorProto { data: buf }) } @@ -2148,7 +2148,7 @@ impl roto_runtime::RotoMessage for OwnedOneofDescriptorProto { } pub struct EnumDescriptorProto<'a> { - accessor: roto_runtime::ProtoAccessor<'a>, + accessor: crate::runtime::ProtoAccessor<'a>, name_offset: Option, value_start: Option, value_end: Option, @@ -2161,8 +2161,8 @@ pub struct EnumDescriptorProto<'a> { } impl<'a> EnumDescriptorProto<'a> { - pub fn new(data: &'a [u8]) -> roto_runtime::Result { - let accessor = roto_runtime::ProtoAccessor::new(data)?; + pub fn new(data: &'a [u8]) -> crate::runtime::Result { + let accessor = crate::runtime::ProtoAccessor::new(data)?; let mut name_offset = None; let mut value_start = None; let mut value_end = None; @@ -2202,71 +2202,71 @@ visibility_offset, }) } - pub fn name(&self) -> roto_runtime::Result<&'a str> { - let offset = self.name_offset.ok_or(roto_runtime::RotoError::FieldNotFound)?; + pub fn name(&self) -> crate::runtime::Result<&'a str> { + let offset = self.name_offset.ok_or(crate::runtime::RotoError::FieldNotFound)?; let (bytes, _) = self.accessor.get_value_at(offset)?; - str::from_utf8(bytes).map_err(|_| roto_runtime::RotoError::WireFormatViolation) + str::from_utf8(bytes).map_err(|_| crate::runtime::RotoError::WireFormatViolation) } - pub fn name_or_default(&self) -> roto_runtime::Result<&'a str> { + pub fn name_or_default(&self) -> crate::runtime::Result<&'a str> { self.name().or(Ok("")) } pub fn has_name(&self) -> bool { self.name_offset.is_some() } - pub fn value(&self) -> roto_runtime::RepeatedFieldIterator<'a> { + pub fn value(&self) -> crate::runtime::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) -> roto_runtime::Result<&'a [u8]> { - let offset = self.options_offset.ok_or(roto_runtime::RotoError::FieldNotFound)?; + pub fn options(&self) -> crate::runtime::Result<&'a [u8]> { + let offset = self.options_offset.ok_or(crate::runtime::RotoError::FieldNotFound)?; let (bytes, _) = self.accessor.get_value_at(offset)?; Ok(bytes) } - pub fn options_or_default(&self) -> roto_runtime::Result<&'a [u8]> { + pub fn options_or_default(&self) -> crate::runtime::Result<&'a [u8]> { self.options().or(Ok(&[])) } pub fn has_options(&self) -> bool { self.options_offset.is_some() } - pub fn reserved_range(&self) -> roto_runtime::RepeatedFieldIterator<'a> { + pub fn reserved_range(&self) -> crate::runtime::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) -> roto_runtime::RepeatedFieldIterator<'a> { + pub fn reserved_name(&self) -> crate::runtime::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) -> roto_runtime::Result { - let offset = self.visibility_offset.ok_or(roto_runtime::RotoError::FieldNotFound)?; + pub fn visibility(&self) -> crate::runtime::Result { + let offset = self.visibility_offset.ok_or(crate::runtime::RotoError::FieldNotFound)?; let (bytes, _) = self.accessor.get_value_at(offset)?; - roto_runtime::read_varint(bytes).map(|(v, _)| v as u64).map_err(|_| roto_runtime::RotoError::WireFormatViolation) + crate::runtime::read_varint(bytes).map(|(v, _)| v as u64).map_err(|_| crate::runtime::RotoError::WireFormatViolation) } - pub fn visibility_or_default(&self) -> roto_runtime::Result { + pub fn visibility_or_default(&self) -> crate::runtime::Result { self.visibility().or(Ok(0)) } pub fn has_visibility(&self) -> bool { self.visibility_offset.is_some() } - pub fn raw_fields(&self) -> roto_runtime::RawFieldIterator<'a> { + pub fn raw_fields(&self) -> crate::runtime::RawFieldIterator<'a> { self.accessor.raw_fields() } } pub struct EnumDescriptorProtoBuilder<'b> { - builder: roto_runtime::ProtoBuilder<'b>, + builder: crate::runtime::ProtoBuilder<'b>, name_written: bool, value_written: bool, options_written: bool, @@ -2278,7 +2278,7 @@ pub struct EnumDescriptorProtoBuilder<'b> { impl<'b> EnumDescriptorProtoBuilder<'b> { pub fn builder(buf: &mut [u8]) -> EnumDescriptorProtoBuilder<'_> { EnumDescriptorProtoBuilder { - builder: roto_runtime::ProtoBuilder::new(buf), + builder: crate::runtime::ProtoBuilder::new(buf), name_written: false, value_written: false, options_written: false, @@ -2288,43 +2288,43 @@ impl<'b> EnumDescriptorProtoBuilder<'b> { } } - pub fn name(mut self, value: &str) -> roto_runtime::Result { + pub fn name(mut self, value: &str) -> crate::runtime::Result { self.builder.write_string(1, value)?; self.name_written = true; Ok(self) } - pub fn value(mut self, value: &[u8]) -> roto_runtime::Result { + pub fn value(mut self, value: &[u8]) -> crate::runtime::Result { self.builder.write_bytes(2, value)?; self.value_written = true; Ok(self) } - pub fn options(mut self, value: &[u8]) -> roto_runtime::Result { + pub fn options(mut self, value: &[u8]) -> crate::runtime::Result { self.builder.write_bytes(3, value)?; self.options_written = true; Ok(self) } - pub fn reserved_range(mut self, value: &[u8]) -> roto_runtime::Result { + pub fn reserved_range(mut self, value: &[u8]) -> crate::runtime::Result { self.builder.write_bytes(4, value)?; self.reserved_range_written = true; Ok(self) } - pub fn reserved_name(mut self, value: &str) -> roto_runtime::Result { + pub fn reserved_name(mut self, value: &str) -> crate::runtime::Result { self.builder.write_string(5, value)?; self.reserved_name_written = true; Ok(self) } - pub fn visibility(mut self, value: u64) -> roto_runtime::Result { + pub fn visibility(mut self, value: u64) -> crate::runtime::Result { self.builder.write_varint(6, value)?; self.visibility_written = true; Ok(self) } - pub fn with(mut self, msg: &EnumDescriptorProto<'_>) -> roto_runtime::Result { + pub fn with(mut self, msg: &EnumDescriptorProto<'_>) -> crate::runtime::Result { for item in msg.raw_fields() { let (field_number, raw_bytes) = item?; let is_written = match field_number { @@ -2343,7 +2343,7 @@ impl<'b> EnumDescriptorProtoBuilder<'b> { Ok(self) } - pub fn finish(self) -> roto_runtime::Result<&'b mut [u8]> { + pub fn finish(self) -> crate::runtime::Result<&'b mut [u8]> { self.builder.finish() } } @@ -2352,15 +2352,15 @@ pub struct OwnedEnumDescriptorProto { pub data: bytes::Bytes, } -impl roto_runtime::RotoOwned for OwnedEnumDescriptorProto { +impl crate::runtime::RotoOwned for OwnedEnumDescriptorProto { type Reader<'a> = EnumDescriptorProto<'a>; fn reader(&self) -> EnumDescriptorProto<'_> { EnumDescriptorProto::new(&self.data).expect("failed to create reader") } } -impl roto_runtime::RotoMessage for OwnedEnumDescriptorProto { - fn decode(buf: bytes::Bytes) -> roto_runtime::Result { +impl crate::runtime::RotoMessage for OwnedEnumDescriptorProto { + fn decode(buf: bytes::Bytes) -> crate::runtime::Result { Ok(OwnedEnumDescriptorProto { data: buf }) } @@ -2371,14 +2371,14 @@ impl roto_runtime::RotoMessage for OwnedEnumDescriptorProto { pub mod enum_descriptor_proto { pub struct EnumReservedRange<'a> { - accessor: roto_runtime::ProtoAccessor<'a>, + accessor: crate::runtime::ProtoAccessor<'a>, start_offset: Option, end_offset: Option, } impl<'a> EnumReservedRange<'a> { - pub fn new(data: &'a [u8]) -> roto_runtime::Result { - let accessor = roto_runtime::ProtoAccessor::new(data)?; + pub fn new(data: &'a [u8]) -> crate::runtime::Result { + let accessor = crate::runtime::ProtoAccessor::new(data)?; let mut start_offset = None; let mut end_offset = None; for item in accessor.fields() { @@ -2394,38 +2394,38 @@ end_offset, }) } - pub fn start(&self) -> roto_runtime::Result { - let offset = self.start_offset.ok_or(roto_runtime::RotoError::FieldNotFound)?; + pub fn start(&self) -> crate::runtime::Result { + let offset = self.start_offset.ok_or(crate::runtime::RotoError::FieldNotFound)?; let (bytes, _) = self.accessor.get_value_at(offset)?; - roto_runtime::read_varint(bytes).map(|(v, _)| v as i32).map_err(|_| roto_runtime::RotoError::WireFormatViolation) + crate::runtime::read_varint(bytes).map(|(v, _)| v as i32).map_err(|_| crate::runtime::RotoError::WireFormatViolation) } - pub fn start_or_default(&self) -> roto_runtime::Result { + pub fn start_or_default(&self) -> crate::runtime::Result { self.start().or(Ok(0)) } pub fn has_start(&self) -> bool { self.start_offset.is_some() } - pub fn end(&self) -> roto_runtime::Result { - let offset = self.end_offset.ok_or(roto_runtime::RotoError::FieldNotFound)?; + pub fn end(&self) -> crate::runtime::Result { + let offset = self.end_offset.ok_or(crate::runtime::RotoError::FieldNotFound)?; let (bytes, _) = self.accessor.get_value_at(offset)?; - roto_runtime::read_varint(bytes).map(|(v, _)| v as i32).map_err(|_| roto_runtime::RotoError::WireFormatViolation) + crate::runtime::read_varint(bytes).map(|(v, _)| v as i32).map_err(|_| crate::runtime::RotoError::WireFormatViolation) } - pub fn end_or_default(&self) -> roto_runtime::Result { + pub fn end_or_default(&self) -> crate::runtime::Result { self.end().or(Ok(0)) } pub fn has_end(&self) -> bool { self.end_offset.is_some() } - pub fn raw_fields(&self) -> roto_runtime::RawFieldIterator<'a> { + pub fn raw_fields(&self) -> crate::runtime::RawFieldIterator<'a> { self.accessor.raw_fields() } } pub struct EnumReservedRangeBuilder<'b> { - builder: roto_runtime::ProtoBuilder<'b>, + builder: crate::runtime::ProtoBuilder<'b>, start_written: bool, end_written: bool, } @@ -2433,25 +2433,25 @@ pub struct EnumReservedRangeBuilder<'b> { impl<'b> EnumReservedRangeBuilder<'b> { pub fn builder(buf: &mut [u8]) -> EnumReservedRangeBuilder<'_> { EnumReservedRangeBuilder { - builder: roto_runtime::ProtoBuilder::new(buf), + builder: crate::runtime::ProtoBuilder::new(buf), start_written: false, end_written: false, } } - pub fn start(mut self, value: i32) -> roto_runtime::Result { + pub fn start(mut self, value: i32) -> crate::runtime::Result { self.builder.write_int32(1, value)?; self.start_written = true; Ok(self) } - pub fn end(mut self, value: i32) -> roto_runtime::Result { + pub fn end(mut self, value: i32) -> crate::runtime::Result { self.builder.write_int32(2, value)?; self.end_written = true; Ok(self) } - pub fn with(mut self, msg: &EnumReservedRange<'_>) -> roto_runtime::Result { + pub fn with(mut self, msg: &EnumReservedRange<'_>) -> crate::runtime::Result { for item in msg.raw_fields() { let (field_number, raw_bytes) = item?; let is_written = match field_number { @@ -2466,7 +2466,7 @@ impl<'b> EnumReservedRangeBuilder<'b> { Ok(self) } - pub fn finish(self) -> roto_runtime::Result<&'b mut [u8]> { + pub fn finish(self) -> crate::runtime::Result<&'b mut [u8]> { self.builder.finish() } } @@ -2475,15 +2475,15 @@ pub struct OwnedEnumReservedRange { pub data: bytes::Bytes, } -impl roto_runtime::RotoOwned for OwnedEnumReservedRange { +impl crate::runtime::RotoOwned for OwnedEnumReservedRange { type Reader<'a> = EnumReservedRange<'a>; fn reader(&self) -> EnumReservedRange<'_> { EnumReservedRange::new(&self.data).expect("failed to create reader") } } -impl roto_runtime::RotoMessage for OwnedEnumReservedRange { - fn decode(buf: bytes::Bytes) -> roto_runtime::Result { +impl crate::runtime::RotoMessage for OwnedEnumReservedRange { + fn decode(buf: bytes::Bytes) -> crate::runtime::Result { Ok(OwnedEnumReservedRange { data: buf }) } @@ -2495,15 +2495,15 @@ impl roto_runtime::RotoMessage for OwnedEnumReservedRange { } pub struct EnumValueDescriptorProto<'a> { - accessor: roto_runtime::ProtoAccessor<'a>, + accessor: crate::runtime::ProtoAccessor<'a>, name_offset: Option, number_offset: Option, options_offset: Option, } impl<'a> EnumValueDescriptorProto<'a> { - pub fn new(data: &'a [u8]) -> roto_runtime::Result { - let accessor = roto_runtime::ProtoAccessor::new(data)?; + pub fn new(data: &'a [u8]) -> crate::runtime::Result { + let accessor = crate::runtime::ProtoAccessor::new(data)?; let mut name_offset = None; let mut number_offset = None; let mut options_offset = None; @@ -2522,50 +2522,50 @@ options_offset, }) } - pub fn name(&self) -> roto_runtime::Result<&'a str> { - let offset = self.name_offset.ok_or(roto_runtime::RotoError::FieldNotFound)?; + pub fn name(&self) -> crate::runtime::Result<&'a str> { + let offset = self.name_offset.ok_or(crate::runtime::RotoError::FieldNotFound)?; let (bytes, _) = self.accessor.get_value_at(offset)?; - str::from_utf8(bytes).map_err(|_| roto_runtime::RotoError::WireFormatViolation) + str::from_utf8(bytes).map_err(|_| crate::runtime::RotoError::WireFormatViolation) } - pub fn name_or_default(&self) -> roto_runtime::Result<&'a str> { + pub fn name_or_default(&self) -> crate::runtime::Result<&'a str> { self.name().or(Ok("")) } pub fn has_name(&self) -> bool { self.name_offset.is_some() } - pub fn number(&self) -> roto_runtime::Result { - let offset = self.number_offset.ok_or(roto_runtime::RotoError::FieldNotFound)?; + pub fn number(&self) -> crate::runtime::Result { + let offset = self.number_offset.ok_or(crate::runtime::RotoError::FieldNotFound)?; let (bytes, _) = self.accessor.get_value_at(offset)?; - roto_runtime::read_varint(bytes).map(|(v, _)| v as i32).map_err(|_| roto_runtime::RotoError::WireFormatViolation) + crate::runtime::read_varint(bytes).map(|(v, _)| v as i32).map_err(|_| crate::runtime::RotoError::WireFormatViolation) } - pub fn number_or_default(&self) -> roto_runtime::Result { + pub fn number_or_default(&self) -> crate::runtime::Result { self.number().or(Ok(0)) } pub fn has_number(&self) -> bool { self.number_offset.is_some() } - pub fn options(&self) -> roto_runtime::Result<&'a [u8]> { - let offset = self.options_offset.ok_or(roto_runtime::RotoError::FieldNotFound)?; + pub fn options(&self) -> crate::runtime::Result<&'a [u8]> { + let offset = self.options_offset.ok_or(crate::runtime::RotoError::FieldNotFound)?; let (bytes, _) = self.accessor.get_value_at(offset)?; Ok(bytes) } - pub fn options_or_default(&self) -> roto_runtime::Result<&'a [u8]> { + pub fn options_or_default(&self) -> crate::runtime::Result<&'a [u8]> { self.options().or(Ok(&[])) } pub fn has_options(&self) -> bool { self.options_offset.is_some() } - pub fn raw_fields(&self) -> roto_runtime::RawFieldIterator<'a> { + pub fn raw_fields(&self) -> crate::runtime::RawFieldIterator<'a> { self.accessor.raw_fields() } } pub struct EnumValueDescriptorProtoBuilder<'b> { - builder: roto_runtime::ProtoBuilder<'b>, + builder: crate::runtime::ProtoBuilder<'b>, name_written: bool, number_written: bool, options_written: bool, @@ -2574,32 +2574,32 @@ pub struct EnumValueDescriptorProtoBuilder<'b> { impl<'b> EnumValueDescriptorProtoBuilder<'b> { pub fn builder(buf: &mut [u8]) -> EnumValueDescriptorProtoBuilder<'_> { EnumValueDescriptorProtoBuilder { - builder: roto_runtime::ProtoBuilder::new(buf), + builder: crate::runtime::ProtoBuilder::new(buf), name_written: false, number_written: false, options_written: false, } } - pub fn name(mut self, value: &str) -> roto_runtime::Result { + pub fn name(mut self, value: &str) -> crate::runtime::Result { self.builder.write_string(1, value)?; self.name_written = true; Ok(self) } - pub fn number(mut self, value: i32) -> roto_runtime::Result { + pub fn number(mut self, value: i32) -> crate::runtime::Result { self.builder.write_int32(2, value)?; self.number_written = true; Ok(self) } - pub fn options(mut self, value: &[u8]) -> roto_runtime::Result { + pub fn options(mut self, value: &[u8]) -> crate::runtime::Result { self.builder.write_bytes(3, value)?; self.options_written = true; Ok(self) } - pub fn with(mut self, msg: &EnumValueDescriptorProto<'_>) -> roto_runtime::Result { + pub fn with(mut self, msg: &EnumValueDescriptorProto<'_>) -> crate::runtime::Result { for item in msg.raw_fields() { let (field_number, raw_bytes) = item?; let is_written = match field_number { @@ -2615,7 +2615,7 @@ impl<'b> EnumValueDescriptorProtoBuilder<'b> { Ok(self) } - pub fn finish(self) -> roto_runtime::Result<&'b mut [u8]> { + pub fn finish(self) -> crate::runtime::Result<&'b mut [u8]> { self.builder.finish() } } @@ -2624,15 +2624,15 @@ pub struct OwnedEnumValueDescriptorProto { pub data: bytes::Bytes, } -impl roto_runtime::RotoOwned for OwnedEnumValueDescriptorProto { +impl crate::runtime::RotoOwned for OwnedEnumValueDescriptorProto { type Reader<'a> = EnumValueDescriptorProto<'a>; fn reader(&self) -> EnumValueDescriptorProto<'_> { EnumValueDescriptorProto::new(&self.data).expect("failed to create reader") } } -impl roto_runtime::RotoMessage for OwnedEnumValueDescriptorProto { - fn decode(buf: bytes::Bytes) -> roto_runtime::Result { +impl crate::runtime::RotoMessage for OwnedEnumValueDescriptorProto { + fn decode(buf: bytes::Bytes) -> crate::runtime::Result { Ok(OwnedEnumValueDescriptorProto { data: buf }) } @@ -2642,7 +2642,7 @@ impl roto_runtime::RotoMessage for OwnedEnumValueDescriptorProto { } pub struct ServiceDescriptorProto<'a> { - accessor: roto_runtime::ProtoAccessor<'a>, + accessor: crate::runtime::ProtoAccessor<'a>, name_offset: Option, method_start: Option, method_end: Option, @@ -2650,8 +2650,8 @@ pub struct ServiceDescriptorProto<'a> { } impl<'a> ServiceDescriptorProto<'a> { - pub fn new(data: &'a [u8]) -> roto_runtime::Result { - let accessor = roto_runtime::ProtoAccessor::new(data)?; + pub fn new(data: &'a [u8]) -> crate::runtime::Result { + let accessor = crate::runtime::ProtoAccessor::new(data)?; let mut name_offset = None; let mut method_start = None; let mut method_end = None; @@ -2674,45 +2674,45 @@ options_offset, }) } - pub fn name(&self) -> roto_runtime::Result<&'a str> { - let offset = self.name_offset.ok_or(roto_runtime::RotoError::FieldNotFound)?; + pub fn name(&self) -> crate::runtime::Result<&'a str> { + let offset = self.name_offset.ok_or(crate::runtime::RotoError::FieldNotFound)?; let (bytes, _) = self.accessor.get_value_at(offset)?; - str::from_utf8(bytes).map_err(|_| roto_runtime::RotoError::WireFormatViolation) + str::from_utf8(bytes).map_err(|_| crate::runtime::RotoError::WireFormatViolation) } - pub fn name_or_default(&self) -> roto_runtime::Result<&'a str> { + pub fn name_or_default(&self) -> crate::runtime::Result<&'a str> { self.name().or(Ok("")) } pub fn has_name(&self) -> bool { self.name_offset.is_some() } - pub fn method(&self) -> roto_runtime::RepeatedFieldIterator<'a> { + pub fn method(&self) -> crate::runtime::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) -> roto_runtime::Result<&'a [u8]> { - let offset = self.options_offset.ok_or(roto_runtime::RotoError::FieldNotFound)?; + pub fn options(&self) -> crate::runtime::Result<&'a [u8]> { + let offset = self.options_offset.ok_or(crate::runtime::RotoError::FieldNotFound)?; let (bytes, _) = self.accessor.get_value_at(offset)?; Ok(bytes) } - pub fn options_or_default(&self) -> roto_runtime::Result<&'a [u8]> { + pub fn options_or_default(&self) -> crate::runtime::Result<&'a [u8]> { self.options().or(Ok(&[])) } pub fn has_options(&self) -> bool { self.options_offset.is_some() } - pub fn raw_fields(&self) -> roto_runtime::RawFieldIterator<'a> { + pub fn raw_fields(&self) -> crate::runtime::RawFieldIterator<'a> { self.accessor.raw_fields() } } pub struct ServiceDescriptorProtoBuilder<'b> { - builder: roto_runtime::ProtoBuilder<'b>, + builder: crate::runtime::ProtoBuilder<'b>, name_written: bool, method_written: bool, options_written: bool, @@ -2721,32 +2721,32 @@ pub struct ServiceDescriptorProtoBuilder<'b> { impl<'b> ServiceDescriptorProtoBuilder<'b> { pub fn builder(buf: &mut [u8]) -> ServiceDescriptorProtoBuilder<'_> { ServiceDescriptorProtoBuilder { - builder: roto_runtime::ProtoBuilder::new(buf), + builder: crate::runtime::ProtoBuilder::new(buf), name_written: false, method_written: false, options_written: false, } } - pub fn name(mut self, value: &str) -> roto_runtime::Result { + pub fn name(mut self, value: &str) -> crate::runtime::Result { self.builder.write_string(1, value)?; self.name_written = true; Ok(self) } - pub fn method(mut self, value: &[u8]) -> roto_runtime::Result { + pub fn method(mut self, value: &[u8]) -> crate::runtime::Result { self.builder.write_bytes(2, value)?; self.method_written = true; Ok(self) } - pub fn options(mut self, value: &[u8]) -> roto_runtime::Result { + pub fn options(mut self, value: &[u8]) -> crate::runtime::Result { self.builder.write_bytes(3, value)?; self.options_written = true; Ok(self) } - pub fn with(mut self, msg: &ServiceDescriptorProto<'_>) -> roto_runtime::Result { + pub fn with(mut self, msg: &ServiceDescriptorProto<'_>) -> crate::runtime::Result { for item in msg.raw_fields() { let (field_number, raw_bytes) = item?; let is_written = match field_number { @@ -2762,7 +2762,7 @@ impl<'b> ServiceDescriptorProtoBuilder<'b> { Ok(self) } - pub fn finish(self) -> roto_runtime::Result<&'b mut [u8]> { + pub fn finish(self) -> crate::runtime::Result<&'b mut [u8]> { self.builder.finish() } } @@ -2771,15 +2771,15 @@ pub struct OwnedServiceDescriptorProto { pub data: bytes::Bytes, } -impl roto_runtime::RotoOwned for OwnedServiceDescriptorProto { +impl crate::runtime::RotoOwned for OwnedServiceDescriptorProto { type Reader<'a> = ServiceDescriptorProto<'a>; fn reader(&self) -> ServiceDescriptorProto<'_> { ServiceDescriptorProto::new(&self.data).expect("failed to create reader") } } -impl roto_runtime::RotoMessage for OwnedServiceDescriptorProto { - fn decode(buf: bytes::Bytes) -> roto_runtime::Result { +impl crate::runtime::RotoMessage for OwnedServiceDescriptorProto { + fn decode(buf: bytes::Bytes) -> crate::runtime::Result { Ok(OwnedServiceDescriptorProto { data: buf }) } @@ -2789,7 +2789,7 @@ impl roto_runtime::RotoMessage for OwnedServiceDescriptorProto { } pub struct MethodDescriptorProto<'a> { - accessor: roto_runtime::ProtoAccessor<'a>, + accessor: crate::runtime::ProtoAccessor<'a>, name_offset: Option, input_type_offset: Option, output_type_offset: Option, @@ -2799,8 +2799,8 @@ pub struct MethodDescriptorProto<'a> { } impl<'a> MethodDescriptorProto<'a> { - pub fn new(data: &'a [u8]) -> roto_runtime::Result { - let accessor = roto_runtime::ProtoAccessor::new(data)?; + pub fn new(data: &'a [u8]) -> crate::runtime::Result { + let accessor = crate::runtime::ProtoAccessor::new(data)?; let mut name_offset = None; let mut input_type_offset = None; let mut output_type_offset = None; @@ -2828,86 +2828,86 @@ server_streaming_offset, }) } - pub fn name(&self) -> roto_runtime::Result<&'a str> { - let offset = self.name_offset.ok_or(roto_runtime::RotoError::FieldNotFound)?; + pub fn name(&self) -> crate::runtime::Result<&'a str> { + let offset = self.name_offset.ok_or(crate::runtime::RotoError::FieldNotFound)?; let (bytes, _) = self.accessor.get_value_at(offset)?; - str::from_utf8(bytes).map_err(|_| roto_runtime::RotoError::WireFormatViolation) + str::from_utf8(bytes).map_err(|_| crate::runtime::RotoError::WireFormatViolation) } - pub fn name_or_default(&self) -> roto_runtime::Result<&'a str> { + pub fn name_or_default(&self) -> crate::runtime::Result<&'a str> { self.name().or(Ok("")) } pub fn has_name(&self) -> bool { self.name_offset.is_some() } - pub fn input_type(&self) -> roto_runtime::Result<&'a str> { - let offset = self.input_type_offset.ok_or(roto_runtime::RotoError::FieldNotFound)?; + pub fn input_type(&self) -> crate::runtime::Result<&'a str> { + let offset = self.input_type_offset.ok_or(crate::runtime::RotoError::FieldNotFound)?; let (bytes, _) = self.accessor.get_value_at(offset)?; - str::from_utf8(bytes).map_err(|_| roto_runtime::RotoError::WireFormatViolation) + str::from_utf8(bytes).map_err(|_| crate::runtime::RotoError::WireFormatViolation) } - pub fn input_type_or_default(&self) -> roto_runtime::Result<&'a str> { + pub fn input_type_or_default(&self) -> crate::runtime::Result<&'a str> { self.input_type().or(Ok("")) } pub fn has_input_type(&self) -> bool { self.input_type_offset.is_some() } - pub fn output_type(&self) -> roto_runtime::Result<&'a str> { - let offset = self.output_type_offset.ok_or(roto_runtime::RotoError::FieldNotFound)?; + pub fn output_type(&self) -> crate::runtime::Result<&'a str> { + let offset = self.output_type_offset.ok_or(crate::runtime::RotoError::FieldNotFound)?; let (bytes, _) = self.accessor.get_value_at(offset)?; - str::from_utf8(bytes).map_err(|_| roto_runtime::RotoError::WireFormatViolation) + str::from_utf8(bytes).map_err(|_| crate::runtime::RotoError::WireFormatViolation) } - pub fn output_type_or_default(&self) -> roto_runtime::Result<&'a str> { + pub fn output_type_or_default(&self) -> crate::runtime::Result<&'a str> { self.output_type().or(Ok("")) } pub fn has_output_type(&self) -> bool { self.output_type_offset.is_some() } - pub fn options(&self) -> roto_runtime::Result<&'a [u8]> { - let offset = self.options_offset.ok_or(roto_runtime::RotoError::FieldNotFound)?; + pub fn options(&self) -> crate::runtime::Result<&'a [u8]> { + let offset = self.options_offset.ok_or(crate::runtime::RotoError::FieldNotFound)?; let (bytes, _) = self.accessor.get_value_at(offset)?; Ok(bytes) } - pub fn options_or_default(&self) -> roto_runtime::Result<&'a [u8]> { + pub fn options_or_default(&self) -> crate::runtime::Result<&'a [u8]> { self.options().or(Ok(&[])) } pub fn has_options(&self) -> bool { self.options_offset.is_some() } - pub fn client_streaming(&self) -> roto_runtime::Result { - let offset = self.client_streaming_offset.ok_or(roto_runtime::RotoError::FieldNotFound)?; + pub fn client_streaming(&self) -> crate::runtime::Result { + let offset = self.client_streaming_offset.ok_or(crate::runtime::RotoError::FieldNotFound)?; let (bytes, _) = self.accessor.get_value_at(offset)?; - roto_runtime::read_varint(bytes).map(|(v, _)| v != 0).map_err(|_| roto_runtime::RotoError::WireFormatViolation) + crate::runtime::read_varint(bytes).map(|(v, _)| v != 0).map_err(|_| crate::runtime::RotoError::WireFormatViolation) } - pub fn client_streaming_or_default(&self) -> roto_runtime::Result { + pub fn client_streaming_or_default(&self) -> crate::runtime::Result { self.client_streaming().or(Ok(false)) } pub fn has_client_streaming(&self) -> bool { self.client_streaming_offset.is_some() } - pub fn server_streaming(&self) -> roto_runtime::Result { - let offset = self.server_streaming_offset.ok_or(roto_runtime::RotoError::FieldNotFound)?; + pub fn server_streaming(&self) -> crate::runtime::Result { + let offset = self.server_streaming_offset.ok_or(crate::runtime::RotoError::FieldNotFound)?; let (bytes, _) = self.accessor.get_value_at(offset)?; - roto_runtime::read_varint(bytes).map(|(v, _)| v != 0).map_err(|_| roto_runtime::RotoError::WireFormatViolation) + crate::runtime::read_varint(bytes).map(|(v, _)| v != 0).map_err(|_| crate::runtime::RotoError::WireFormatViolation) } - pub fn server_streaming_or_default(&self) -> roto_runtime::Result { + pub fn server_streaming_or_default(&self) -> crate::runtime::Result { self.server_streaming().or(Ok(false)) } pub fn has_server_streaming(&self) -> bool { self.server_streaming_offset.is_some() } - pub fn raw_fields(&self) -> roto_runtime::RawFieldIterator<'a> { + pub fn raw_fields(&self) -> crate::runtime::RawFieldIterator<'a> { self.accessor.raw_fields() } } pub struct MethodDescriptorProtoBuilder<'b> { - builder: roto_runtime::ProtoBuilder<'b>, + builder: crate::runtime::ProtoBuilder<'b>, name_written: bool, input_type_written: bool, output_type_written: bool, @@ -2919,7 +2919,7 @@ pub struct MethodDescriptorProtoBuilder<'b> { impl<'b> MethodDescriptorProtoBuilder<'b> { pub fn builder(buf: &mut [u8]) -> MethodDescriptorProtoBuilder<'_> { MethodDescriptorProtoBuilder { - builder: roto_runtime::ProtoBuilder::new(buf), + builder: crate::runtime::ProtoBuilder::new(buf), name_written: false, input_type_written: false, output_type_written: false, @@ -2929,43 +2929,43 @@ impl<'b> MethodDescriptorProtoBuilder<'b> { } } - pub fn name(mut self, value: &str) -> roto_runtime::Result { + pub fn name(mut self, value: &str) -> crate::runtime::Result { self.builder.write_string(1, value)?; self.name_written = true; Ok(self) } - pub fn input_type(mut self, value: &str) -> roto_runtime::Result { + pub fn input_type(mut self, value: &str) -> crate::runtime::Result { self.builder.write_string(2, value)?; self.input_type_written = true; Ok(self) } - pub fn output_type(mut self, value: &str) -> roto_runtime::Result { + pub fn output_type(mut self, value: &str) -> crate::runtime::Result { self.builder.write_string(3, value)?; self.output_type_written = true; Ok(self) } - pub fn options(mut self, value: &[u8]) -> roto_runtime::Result { + pub fn options(mut self, value: &[u8]) -> crate::runtime::Result { self.builder.write_bytes(4, value)?; self.options_written = true; Ok(self) } - pub fn client_streaming(mut self, value: u64) -> roto_runtime::Result { + pub fn client_streaming(mut self, value: u64) -> crate::runtime::Result { self.builder.write_varint(5, value)?; self.client_streaming_written = true; Ok(self) } - pub fn server_streaming(mut self, value: u64) -> roto_runtime::Result { + pub fn server_streaming(mut self, value: u64) -> crate::runtime::Result { self.builder.write_varint(6, value)?; self.server_streaming_written = true; Ok(self) } - pub fn with(mut self, msg: &MethodDescriptorProto<'_>) -> roto_runtime::Result { + pub fn with(mut self, msg: &MethodDescriptorProto<'_>) -> crate::runtime::Result { for item in msg.raw_fields() { let (field_number, raw_bytes) = item?; let is_written = match field_number { @@ -2984,7 +2984,7 @@ impl<'b> MethodDescriptorProtoBuilder<'b> { Ok(self) } - pub fn finish(self) -> roto_runtime::Result<&'b mut [u8]> { + pub fn finish(self) -> crate::runtime::Result<&'b mut [u8]> { self.builder.finish() } } @@ -2993,15 +2993,15 @@ pub struct OwnedMethodDescriptorProto { pub data: bytes::Bytes, } -impl roto_runtime::RotoOwned for OwnedMethodDescriptorProto { +impl crate::runtime::RotoOwned for OwnedMethodDescriptorProto { type Reader<'a> = MethodDescriptorProto<'a>; fn reader(&self) -> MethodDescriptorProto<'_> { MethodDescriptorProto::new(&self.data).expect("failed to create reader") } } -impl roto_runtime::RotoMessage for OwnedMethodDescriptorProto { - fn decode(buf: bytes::Bytes) -> roto_runtime::Result { +impl crate::runtime::RotoMessage for OwnedMethodDescriptorProto { + fn decode(buf: bytes::Bytes) -> crate::runtime::Result { Ok(OwnedMethodDescriptorProto { data: buf }) } @@ -3011,7 +3011,7 @@ impl roto_runtime::RotoMessage for OwnedMethodDescriptorProto { } pub struct FileOptions<'a> { - accessor: roto_runtime::ProtoAccessor<'a>, + accessor: crate::runtime::ProtoAccessor<'a>, java_package_offset: Option, java_outer_classname_offset: Option, java_multiple_files_offset: Option, @@ -3037,8 +3037,8 @@ pub struct FileOptions<'a> { } impl<'a> FileOptions<'a> { - pub fn new(data: &'a [u8]) -> roto_runtime::Result { - let accessor = roto_runtime::ProtoAccessor::new(data)?; + pub fn new(data: &'a [u8]) -> crate::runtime::Result { + let accessor = crate::runtime::ProtoAccessor::new(data)?; let mut java_package_offset = None; let mut java_outer_classname_offset = None; let mut java_multiple_files_offset = None; @@ -3115,261 +3115,261 @@ uninterpreted_option_start, uninterpreted_option_end, }) } - pub fn java_package(&self) -> roto_runtime::Result<&'a str> { - let offset = self.java_package_offset.ok_or(roto_runtime::RotoError::FieldNotFound)?; + pub fn java_package(&self) -> crate::runtime::Result<&'a str> { + let offset = self.java_package_offset.ok_or(crate::runtime::RotoError::FieldNotFound)?; let (bytes, _) = self.accessor.get_value_at(offset)?; - str::from_utf8(bytes).map_err(|_| roto_runtime::RotoError::WireFormatViolation) + str::from_utf8(bytes).map_err(|_| crate::runtime::RotoError::WireFormatViolation) } - pub fn java_package_or_default(&self) -> roto_runtime::Result<&'a str> { + pub fn java_package_or_default(&self) -> crate::runtime::Result<&'a str> { self.java_package().or(Ok("")) } pub fn has_java_package(&self) -> bool { self.java_package_offset.is_some() } - pub fn java_outer_classname(&self) -> roto_runtime::Result<&'a str> { - let offset = self.java_outer_classname_offset.ok_or(roto_runtime::RotoError::FieldNotFound)?; + pub fn java_outer_classname(&self) -> crate::runtime::Result<&'a str> { + let offset = self.java_outer_classname_offset.ok_or(crate::runtime::RotoError::FieldNotFound)?; let (bytes, _) = self.accessor.get_value_at(offset)?; - str::from_utf8(bytes).map_err(|_| roto_runtime::RotoError::WireFormatViolation) + str::from_utf8(bytes).map_err(|_| crate::runtime::RotoError::WireFormatViolation) } - pub fn java_outer_classname_or_default(&self) -> roto_runtime::Result<&'a str> { + pub fn java_outer_classname_or_default(&self) -> crate::runtime::Result<&'a str> { self.java_outer_classname().or(Ok("")) } pub fn has_java_outer_classname(&self) -> bool { self.java_outer_classname_offset.is_some() } - pub fn java_multiple_files(&self) -> roto_runtime::Result { - let offset = self.java_multiple_files_offset.ok_or(roto_runtime::RotoError::FieldNotFound)?; + pub fn java_multiple_files(&self) -> crate::runtime::Result { + let offset = self.java_multiple_files_offset.ok_or(crate::runtime::RotoError::FieldNotFound)?; let (bytes, _) = self.accessor.get_value_at(offset)?; - roto_runtime::read_varint(bytes).map(|(v, _)| v != 0).map_err(|_| roto_runtime::RotoError::WireFormatViolation) + crate::runtime::read_varint(bytes).map(|(v, _)| v != 0).map_err(|_| crate::runtime::RotoError::WireFormatViolation) } - pub fn java_multiple_files_or_default(&self) -> roto_runtime::Result { + pub fn java_multiple_files_or_default(&self) -> crate::runtime::Result { self.java_multiple_files().or(Ok(false)) } pub fn has_java_multiple_files(&self) -> bool { self.java_multiple_files_offset.is_some() } - pub fn java_generate_equals_and_hash(&self) -> roto_runtime::Result { - let offset = self.java_generate_equals_and_hash_offset.ok_or(roto_runtime::RotoError::FieldNotFound)?; + pub fn java_generate_equals_and_hash(&self) -> crate::runtime::Result { + let offset = self.java_generate_equals_and_hash_offset.ok_or(crate::runtime::RotoError::FieldNotFound)?; let (bytes, _) = self.accessor.get_value_at(offset)?; - roto_runtime::read_varint(bytes).map(|(v, _)| v != 0).map_err(|_| roto_runtime::RotoError::WireFormatViolation) + crate::runtime::read_varint(bytes).map(|(v, _)| v != 0).map_err(|_| crate::runtime::RotoError::WireFormatViolation) } - pub fn java_generate_equals_and_hash_or_default(&self) -> roto_runtime::Result { + pub fn java_generate_equals_and_hash_or_default(&self) -> crate::runtime::Result { self.java_generate_equals_and_hash().or(Ok(false)) } pub fn has_java_generate_equals_and_hash(&self) -> bool { self.java_generate_equals_and_hash_offset.is_some() } - pub fn java_string_check_utf8(&self) -> roto_runtime::Result { - let offset = self.java_string_check_utf8_offset.ok_or(roto_runtime::RotoError::FieldNotFound)?; + pub fn java_string_check_utf8(&self) -> crate::runtime::Result { + let offset = self.java_string_check_utf8_offset.ok_or(crate::runtime::RotoError::FieldNotFound)?; let (bytes, _) = self.accessor.get_value_at(offset)?; - roto_runtime::read_varint(bytes).map(|(v, _)| v != 0).map_err(|_| roto_runtime::RotoError::WireFormatViolation) + crate::runtime::read_varint(bytes).map(|(v, _)| v != 0).map_err(|_| crate::runtime::RotoError::WireFormatViolation) } - pub fn java_string_check_utf8_or_default(&self) -> roto_runtime::Result { + pub fn java_string_check_utf8_or_default(&self) -> crate::runtime::Result { self.java_string_check_utf8().or(Ok(false)) } pub fn has_java_string_check_utf8(&self) -> bool { self.java_string_check_utf8_offset.is_some() } - pub fn optimize_for(&self) -> roto_runtime::Result { - let offset = self.optimize_for_offset.ok_or(roto_runtime::RotoError::FieldNotFound)?; + pub fn optimize_for(&self) -> crate::runtime::Result { + let offset = self.optimize_for_offset.ok_or(crate::runtime::RotoError::FieldNotFound)?; let (bytes, _) = self.accessor.get_value_at(offset)?; - roto_runtime::read_varint(bytes).map(|(v, _)| v as u64).map_err(|_| roto_runtime::RotoError::WireFormatViolation) + crate::runtime::read_varint(bytes).map(|(v, _)| v as u64).map_err(|_| crate::runtime::RotoError::WireFormatViolation) } - pub fn optimize_for_or_default(&self) -> roto_runtime::Result { + pub fn optimize_for_or_default(&self) -> crate::runtime::Result { self.optimize_for().or(Ok(0)) } pub fn has_optimize_for(&self) -> bool { self.optimize_for_offset.is_some() } - pub fn go_package(&self) -> roto_runtime::Result<&'a str> { - let offset = self.go_package_offset.ok_or(roto_runtime::RotoError::FieldNotFound)?; + pub fn go_package(&self) -> crate::runtime::Result<&'a str> { + let offset = self.go_package_offset.ok_or(crate::runtime::RotoError::FieldNotFound)?; let (bytes, _) = self.accessor.get_value_at(offset)?; - str::from_utf8(bytes).map_err(|_| roto_runtime::RotoError::WireFormatViolation) + str::from_utf8(bytes).map_err(|_| crate::runtime::RotoError::WireFormatViolation) } - pub fn go_package_or_default(&self) -> roto_runtime::Result<&'a str> { + pub fn go_package_or_default(&self) -> crate::runtime::Result<&'a str> { self.go_package().or(Ok("")) } pub fn has_go_package(&self) -> bool { self.go_package_offset.is_some() } - pub fn cc_generic_services(&self) -> roto_runtime::Result { - let offset = self.cc_generic_services_offset.ok_or(roto_runtime::RotoError::FieldNotFound)?; + pub fn cc_generic_services(&self) -> crate::runtime::Result { + let offset = self.cc_generic_services_offset.ok_or(crate::runtime::RotoError::FieldNotFound)?; let (bytes, _) = self.accessor.get_value_at(offset)?; - roto_runtime::read_varint(bytes).map(|(v, _)| v != 0).map_err(|_| roto_runtime::RotoError::WireFormatViolation) + crate::runtime::read_varint(bytes).map(|(v, _)| v != 0).map_err(|_| crate::runtime::RotoError::WireFormatViolation) } - pub fn cc_generic_services_or_default(&self) -> roto_runtime::Result { + pub fn cc_generic_services_or_default(&self) -> crate::runtime::Result { self.cc_generic_services().or(Ok(false)) } pub fn has_cc_generic_services(&self) -> bool { self.cc_generic_services_offset.is_some() } - pub fn java_generic_services(&self) -> roto_runtime::Result { - let offset = self.java_generic_services_offset.ok_or(roto_runtime::RotoError::FieldNotFound)?; + pub fn java_generic_services(&self) -> crate::runtime::Result { + let offset = self.java_generic_services_offset.ok_or(crate::runtime::RotoError::FieldNotFound)?; let (bytes, _) = self.accessor.get_value_at(offset)?; - roto_runtime::read_varint(bytes).map(|(v, _)| v != 0).map_err(|_| roto_runtime::RotoError::WireFormatViolation) + crate::runtime::read_varint(bytes).map(|(v, _)| v != 0).map_err(|_| crate::runtime::RotoError::WireFormatViolation) } - pub fn java_generic_services_or_default(&self) -> roto_runtime::Result { + pub fn java_generic_services_or_default(&self) -> crate::runtime::Result { self.java_generic_services().or(Ok(false)) } pub fn has_java_generic_services(&self) -> bool { self.java_generic_services_offset.is_some() } - pub fn py_generic_services(&self) -> roto_runtime::Result { - let offset = self.py_generic_services_offset.ok_or(roto_runtime::RotoError::FieldNotFound)?; + pub fn py_generic_services(&self) -> crate::runtime::Result { + let offset = self.py_generic_services_offset.ok_or(crate::runtime::RotoError::FieldNotFound)?; let (bytes, _) = self.accessor.get_value_at(offset)?; - roto_runtime::read_varint(bytes).map(|(v, _)| v != 0).map_err(|_| roto_runtime::RotoError::WireFormatViolation) + crate::runtime::read_varint(bytes).map(|(v, _)| v != 0).map_err(|_| crate::runtime::RotoError::WireFormatViolation) } - pub fn py_generic_services_or_default(&self) -> roto_runtime::Result { + pub fn py_generic_services_or_default(&self) -> crate::runtime::Result { self.py_generic_services().or(Ok(false)) } pub fn has_py_generic_services(&self) -> bool { self.py_generic_services_offset.is_some() } - pub fn deprecated(&self) -> roto_runtime::Result { - let offset = self.deprecated_offset.ok_or(roto_runtime::RotoError::FieldNotFound)?; + pub fn deprecated(&self) -> crate::runtime::Result { + let offset = self.deprecated_offset.ok_or(crate::runtime::RotoError::FieldNotFound)?; let (bytes, _) = self.accessor.get_value_at(offset)?; - roto_runtime::read_varint(bytes).map(|(v, _)| v != 0).map_err(|_| roto_runtime::RotoError::WireFormatViolation) + crate::runtime::read_varint(bytes).map(|(v, _)| v != 0).map_err(|_| crate::runtime::RotoError::WireFormatViolation) } - pub fn deprecated_or_default(&self) -> roto_runtime::Result { + pub fn deprecated_or_default(&self) -> crate::runtime::Result { self.deprecated().or(Ok(false)) } pub fn has_deprecated(&self) -> bool { self.deprecated_offset.is_some() } - pub fn cc_enable_arenas(&self) -> roto_runtime::Result { - let offset = self.cc_enable_arenas_offset.ok_or(roto_runtime::RotoError::FieldNotFound)?; + pub fn cc_enable_arenas(&self) -> crate::runtime::Result { + let offset = self.cc_enable_arenas_offset.ok_or(crate::runtime::RotoError::FieldNotFound)?; let (bytes, _) = self.accessor.get_value_at(offset)?; - roto_runtime::read_varint(bytes).map(|(v, _)| v != 0).map_err(|_| roto_runtime::RotoError::WireFormatViolation) + crate::runtime::read_varint(bytes).map(|(v, _)| v != 0).map_err(|_| crate::runtime::RotoError::WireFormatViolation) } - pub fn cc_enable_arenas_or_default(&self) -> roto_runtime::Result { + pub fn cc_enable_arenas_or_default(&self) -> crate::runtime::Result { self.cc_enable_arenas().or(Ok(false)) } pub fn has_cc_enable_arenas(&self) -> bool { self.cc_enable_arenas_offset.is_some() } - pub fn objc_class_prefix(&self) -> roto_runtime::Result<&'a str> { - let offset = self.objc_class_prefix_offset.ok_or(roto_runtime::RotoError::FieldNotFound)?; + pub fn objc_class_prefix(&self) -> crate::runtime::Result<&'a str> { + let offset = self.objc_class_prefix_offset.ok_or(crate::runtime::RotoError::FieldNotFound)?; let (bytes, _) = self.accessor.get_value_at(offset)?; - str::from_utf8(bytes).map_err(|_| roto_runtime::RotoError::WireFormatViolation) + str::from_utf8(bytes).map_err(|_| crate::runtime::RotoError::WireFormatViolation) } - pub fn objc_class_prefix_or_default(&self) -> roto_runtime::Result<&'a str> { + pub fn objc_class_prefix_or_default(&self) -> crate::runtime::Result<&'a str> { self.objc_class_prefix().or(Ok("")) } pub fn has_objc_class_prefix(&self) -> bool { self.objc_class_prefix_offset.is_some() } - pub fn csharp_namespace(&self) -> roto_runtime::Result<&'a str> { - let offset = self.csharp_namespace_offset.ok_or(roto_runtime::RotoError::FieldNotFound)?; + pub fn csharp_namespace(&self) -> crate::runtime::Result<&'a str> { + let offset = self.csharp_namespace_offset.ok_or(crate::runtime::RotoError::FieldNotFound)?; let (bytes, _) = self.accessor.get_value_at(offset)?; - str::from_utf8(bytes).map_err(|_| roto_runtime::RotoError::WireFormatViolation) + str::from_utf8(bytes).map_err(|_| crate::runtime::RotoError::WireFormatViolation) } - pub fn csharp_namespace_or_default(&self) -> roto_runtime::Result<&'a str> { + pub fn csharp_namespace_or_default(&self) -> crate::runtime::Result<&'a str> { self.csharp_namespace().or(Ok("")) } pub fn has_csharp_namespace(&self) -> bool { self.csharp_namespace_offset.is_some() } - pub fn swift_prefix(&self) -> roto_runtime::Result<&'a str> { - let offset = self.swift_prefix_offset.ok_or(roto_runtime::RotoError::FieldNotFound)?; + pub fn swift_prefix(&self) -> crate::runtime::Result<&'a str> { + let offset = self.swift_prefix_offset.ok_or(crate::runtime::RotoError::FieldNotFound)?; let (bytes, _) = self.accessor.get_value_at(offset)?; - str::from_utf8(bytes).map_err(|_| roto_runtime::RotoError::WireFormatViolation) + str::from_utf8(bytes).map_err(|_| crate::runtime::RotoError::WireFormatViolation) } - pub fn swift_prefix_or_default(&self) -> roto_runtime::Result<&'a str> { + pub fn swift_prefix_or_default(&self) -> crate::runtime::Result<&'a str> { self.swift_prefix().or(Ok("")) } pub fn has_swift_prefix(&self) -> bool { self.swift_prefix_offset.is_some() } - pub fn php_class_prefix(&self) -> roto_runtime::Result<&'a str> { - let offset = self.php_class_prefix_offset.ok_or(roto_runtime::RotoError::FieldNotFound)?; + pub fn php_class_prefix(&self) -> crate::runtime::Result<&'a str> { + let offset = self.php_class_prefix_offset.ok_or(crate::runtime::RotoError::FieldNotFound)?; let (bytes, _) = self.accessor.get_value_at(offset)?; - str::from_utf8(bytes).map_err(|_| roto_runtime::RotoError::WireFormatViolation) + str::from_utf8(bytes).map_err(|_| crate::runtime::RotoError::WireFormatViolation) } - pub fn php_class_prefix_or_default(&self) -> roto_runtime::Result<&'a str> { + pub fn php_class_prefix_or_default(&self) -> crate::runtime::Result<&'a str> { self.php_class_prefix().or(Ok("")) } pub fn has_php_class_prefix(&self) -> bool { self.php_class_prefix_offset.is_some() } - pub fn php_namespace(&self) -> roto_runtime::Result<&'a str> { - let offset = self.php_namespace_offset.ok_or(roto_runtime::RotoError::FieldNotFound)?; + pub fn php_namespace(&self) -> crate::runtime::Result<&'a str> { + let offset = self.php_namespace_offset.ok_or(crate::runtime::RotoError::FieldNotFound)?; let (bytes, _) = self.accessor.get_value_at(offset)?; - str::from_utf8(bytes).map_err(|_| roto_runtime::RotoError::WireFormatViolation) + str::from_utf8(bytes).map_err(|_| crate::runtime::RotoError::WireFormatViolation) } - pub fn php_namespace_or_default(&self) -> roto_runtime::Result<&'a str> { + pub fn php_namespace_or_default(&self) -> crate::runtime::Result<&'a str> { self.php_namespace().or(Ok("")) } pub fn has_php_namespace(&self) -> bool { self.php_namespace_offset.is_some() } - pub fn php_metadata_namespace(&self) -> roto_runtime::Result<&'a str> { - let offset = self.php_metadata_namespace_offset.ok_or(roto_runtime::RotoError::FieldNotFound)?; + pub fn php_metadata_namespace(&self) -> crate::runtime::Result<&'a str> { + let offset = self.php_metadata_namespace_offset.ok_or(crate::runtime::RotoError::FieldNotFound)?; let (bytes, _) = self.accessor.get_value_at(offset)?; - str::from_utf8(bytes).map_err(|_| roto_runtime::RotoError::WireFormatViolation) + str::from_utf8(bytes).map_err(|_| crate::runtime::RotoError::WireFormatViolation) } - pub fn php_metadata_namespace_or_default(&self) -> roto_runtime::Result<&'a str> { + pub fn php_metadata_namespace_or_default(&self) -> crate::runtime::Result<&'a str> { self.php_metadata_namespace().or(Ok("")) } pub fn has_php_metadata_namespace(&self) -> bool { self.php_metadata_namespace_offset.is_some() } - pub fn ruby_package(&self) -> roto_runtime::Result<&'a str> { - let offset = self.ruby_package_offset.ok_or(roto_runtime::RotoError::FieldNotFound)?; + pub fn ruby_package(&self) -> crate::runtime::Result<&'a str> { + let offset = self.ruby_package_offset.ok_or(crate::runtime::RotoError::FieldNotFound)?; let (bytes, _) = self.accessor.get_value_at(offset)?; - str::from_utf8(bytes).map_err(|_| roto_runtime::RotoError::WireFormatViolation) + str::from_utf8(bytes).map_err(|_| crate::runtime::RotoError::WireFormatViolation) } - pub fn ruby_package_or_default(&self) -> roto_runtime::Result<&'a str> { + pub fn ruby_package_or_default(&self) -> crate::runtime::Result<&'a str> { self.ruby_package().or(Ok("")) } pub fn has_ruby_package(&self) -> bool { self.ruby_package_offset.is_some() } - pub fn features(&self) -> roto_runtime::Result<&'a [u8]> { - let offset = self.features_offset.ok_or(roto_runtime::RotoError::FieldNotFound)?; + pub fn features(&self) -> crate::runtime::Result<&'a [u8]> { + let offset = self.features_offset.ok_or(crate::runtime::RotoError::FieldNotFound)?; let (bytes, _) = self.accessor.get_value_at(offset)?; Ok(bytes) } - pub fn features_or_default(&self) -> roto_runtime::Result<&'a [u8]> { + pub fn features_or_default(&self) -> crate::runtime::Result<&'a [u8]> { self.features().or(Ok(&[])) } pub fn has_features(&self) -> bool { self.features_offset.is_some() } - pub fn uninterpreted_option(&self) -> roto_runtime::RepeatedFieldIterator<'a> { + pub fn uninterpreted_option(&self) -> crate::runtime::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 raw_fields(&self) -> roto_runtime::RawFieldIterator<'a> { + pub fn raw_fields(&self) -> crate::runtime::RawFieldIterator<'a> { self.accessor.raw_fields() } } pub struct FileOptionsBuilder<'b> { - builder: roto_runtime::ProtoBuilder<'b>, + builder: crate::runtime::ProtoBuilder<'b>, java_package_written: bool, java_outer_classname_written: bool, java_multiple_files_written: bool, @@ -3396,7 +3396,7 @@ pub struct FileOptionsBuilder<'b> { impl<'b> FileOptionsBuilder<'b> { pub fn builder(buf: &mut [u8]) -> FileOptionsBuilder<'_> { FileOptionsBuilder { - builder: roto_runtime::ProtoBuilder::new(buf), + builder: crate::runtime::ProtoBuilder::new(buf), java_package_written: false, java_outer_classname_written: false, java_multiple_files_written: false, @@ -3421,133 +3421,133 @@ impl<'b> FileOptionsBuilder<'b> { } } - pub fn java_package(mut self, value: &str) -> roto_runtime::Result { + pub fn java_package(mut self, value: &str) -> crate::runtime::Result { self.builder.write_string(1, value)?; self.java_package_written = true; Ok(self) } - pub fn java_outer_classname(mut self, value: &str) -> roto_runtime::Result { + pub fn java_outer_classname(mut self, value: &str) -> crate::runtime::Result { self.builder.write_string(8, value)?; self.java_outer_classname_written = true; Ok(self) } - pub fn java_multiple_files(mut self, value: u64) -> roto_runtime::Result { + pub fn java_multiple_files(mut self, value: u64) -> crate::runtime::Result { self.builder.write_varint(10, value)?; self.java_multiple_files_written = true; Ok(self) } - pub fn java_generate_equals_and_hash(mut self, value: u64) -> roto_runtime::Result { + pub fn java_generate_equals_and_hash(mut self, value: u64) -> crate::runtime::Result { self.builder.write_varint(20, value)?; self.java_generate_equals_and_hash_written = true; Ok(self) } - pub fn java_string_check_utf8(mut self, value: u64) -> roto_runtime::Result { + pub fn java_string_check_utf8(mut self, value: u64) -> crate::runtime::Result { self.builder.write_varint(27, value)?; self.java_string_check_utf8_written = true; Ok(self) } - pub fn optimize_for(mut self, value: u64) -> roto_runtime::Result { + pub fn optimize_for(mut self, value: u64) -> crate::runtime::Result { self.builder.write_varint(9, value)?; self.optimize_for_written = true; Ok(self) } - pub fn go_package(mut self, value: &str) -> roto_runtime::Result { + pub fn go_package(mut self, value: &str) -> crate::runtime::Result { self.builder.write_string(11, value)?; self.go_package_written = true; Ok(self) } - pub fn cc_generic_services(mut self, value: u64) -> roto_runtime::Result { + pub fn cc_generic_services(mut self, value: u64) -> crate::runtime::Result { self.builder.write_varint(16, value)?; self.cc_generic_services_written = true; Ok(self) } - pub fn java_generic_services(mut self, value: u64) -> roto_runtime::Result { + pub fn java_generic_services(mut self, value: u64) -> crate::runtime::Result { self.builder.write_varint(17, value)?; self.java_generic_services_written = true; Ok(self) } - pub fn py_generic_services(mut self, value: u64) -> roto_runtime::Result { + pub fn py_generic_services(mut self, value: u64) -> crate::runtime::Result { self.builder.write_varint(18, value)?; self.py_generic_services_written = true; Ok(self) } - pub fn deprecated(mut self, value: u64) -> roto_runtime::Result { + pub fn deprecated(mut self, value: u64) -> crate::runtime::Result { self.builder.write_varint(23, value)?; self.deprecated_written = true; Ok(self) } - pub fn cc_enable_arenas(mut self, value: u64) -> roto_runtime::Result { + pub fn cc_enable_arenas(mut self, value: u64) -> crate::runtime::Result { self.builder.write_varint(31, value)?; self.cc_enable_arenas_written = true; Ok(self) } - pub fn objc_class_prefix(mut self, value: &str) -> roto_runtime::Result { + pub fn objc_class_prefix(mut self, value: &str) -> crate::runtime::Result { self.builder.write_string(36, value)?; self.objc_class_prefix_written = true; Ok(self) } - pub fn csharp_namespace(mut self, value: &str) -> roto_runtime::Result { + pub fn csharp_namespace(mut self, value: &str) -> crate::runtime::Result { self.builder.write_string(37, value)?; self.csharp_namespace_written = true; Ok(self) } - pub fn swift_prefix(mut self, value: &str) -> roto_runtime::Result { + pub fn swift_prefix(mut self, value: &str) -> crate::runtime::Result { self.builder.write_string(39, value)?; self.swift_prefix_written = true; Ok(self) } - pub fn php_class_prefix(mut self, value: &str) -> roto_runtime::Result { + pub fn php_class_prefix(mut self, value: &str) -> crate::runtime::Result { self.builder.write_string(40, value)?; self.php_class_prefix_written = true; Ok(self) } - pub fn php_namespace(mut self, value: &str) -> roto_runtime::Result { + pub fn php_namespace(mut self, value: &str) -> crate::runtime::Result { self.builder.write_string(41, value)?; self.php_namespace_written = true; Ok(self) } - pub fn php_metadata_namespace(mut self, value: &str) -> roto_runtime::Result { + pub fn php_metadata_namespace(mut self, value: &str) -> crate::runtime::Result { self.builder.write_string(44, value)?; self.php_metadata_namespace_written = true; Ok(self) } - pub fn ruby_package(mut self, value: &str) -> roto_runtime::Result { + pub fn ruby_package(mut self, value: &str) -> crate::runtime::Result { self.builder.write_string(45, value)?; self.ruby_package_written = true; Ok(self) } - pub fn features(mut self, value: &[u8]) -> roto_runtime::Result { + pub fn features(mut self, value: &[u8]) -> crate::runtime::Result { self.builder.write_bytes(50, value)?; self.features_written = true; Ok(self) } - pub fn uninterpreted_option(mut self, value: &[u8]) -> roto_runtime::Result { + pub fn uninterpreted_option(mut self, value: &[u8]) -> crate::runtime::Result { self.builder.write_bytes(999, value)?; self.uninterpreted_option_written = true; Ok(self) } - pub fn with(mut self, msg: &FileOptions<'_>) -> roto_runtime::Result { + pub fn with(mut self, msg: &FileOptions<'_>) -> crate::runtime::Result { for item in msg.raw_fields() { let (field_number, raw_bytes) = item?; let is_written = match field_number { @@ -3581,7 +3581,7 @@ impl<'b> FileOptionsBuilder<'b> { Ok(self) } - pub fn finish(self) -> roto_runtime::Result<&'b mut [u8]> { + pub fn finish(self) -> crate::runtime::Result<&'b mut [u8]> { self.builder.finish() } } @@ -3590,15 +3590,15 @@ pub struct OwnedFileOptions { pub data: bytes::Bytes, } -impl roto_runtime::RotoOwned for OwnedFileOptions { +impl crate::runtime::RotoOwned for OwnedFileOptions { type Reader<'a> = FileOptions<'a>; fn reader(&self) -> FileOptions<'_> { FileOptions::new(&self.data).expect("failed to create reader") } } -impl roto_runtime::RotoMessage for OwnedFileOptions { - fn decode(buf: bytes::Bytes) -> roto_runtime::Result { +impl crate::runtime::RotoMessage for OwnedFileOptions { + fn decode(buf: bytes::Bytes) -> crate::runtime::Result { Ok(OwnedFileOptions { data: buf }) } @@ -3631,7 +3631,7 @@ impl OptimizeMode { } pub struct MessageOptions<'a> { - accessor: roto_runtime::ProtoAccessor<'a>, + accessor: crate::runtime::ProtoAccessor<'a>, message_set_wire_format_offset: Option, no_standard_descriptor_accessor_offset: Option, deprecated_offset: Option, @@ -3643,8 +3643,8 @@ pub struct MessageOptions<'a> { } impl<'a> MessageOptions<'a> { - pub fn new(data: &'a [u8]) -> roto_runtime::Result { - let accessor = roto_runtime::ProtoAccessor::new(data)?; + pub fn new(data: &'a [u8]) -> crate::runtime::Result { + let accessor = crate::runtime::ProtoAccessor::new(data)?; let mut message_set_wire_format_offset = None; let mut no_standard_descriptor_accessor_offset = None; let mut deprecated_offset = None; @@ -3679,93 +3679,93 @@ uninterpreted_option_start, uninterpreted_option_end, }) } - pub fn message_set_wire_format(&self) -> roto_runtime::Result { - let offset = self.message_set_wire_format_offset.ok_or(roto_runtime::RotoError::FieldNotFound)?; + pub fn message_set_wire_format(&self) -> crate::runtime::Result { + let offset = self.message_set_wire_format_offset.ok_or(crate::runtime::RotoError::FieldNotFound)?; let (bytes, _) = self.accessor.get_value_at(offset)?; - roto_runtime::read_varint(bytes).map(|(v, _)| v != 0).map_err(|_| roto_runtime::RotoError::WireFormatViolation) + crate::runtime::read_varint(bytes).map(|(v, _)| v != 0).map_err(|_| crate::runtime::RotoError::WireFormatViolation) } - pub fn message_set_wire_format_or_default(&self) -> roto_runtime::Result { + pub fn message_set_wire_format_or_default(&self) -> crate::runtime::Result { self.message_set_wire_format().or(Ok(false)) } pub fn has_message_set_wire_format(&self) -> bool { self.message_set_wire_format_offset.is_some() } - pub fn no_standard_descriptor_accessor(&self) -> roto_runtime::Result { - let offset = self.no_standard_descriptor_accessor_offset.ok_or(roto_runtime::RotoError::FieldNotFound)?; + pub fn no_standard_descriptor_accessor(&self) -> crate::runtime::Result { + let offset = self.no_standard_descriptor_accessor_offset.ok_or(crate::runtime::RotoError::FieldNotFound)?; let (bytes, _) = self.accessor.get_value_at(offset)?; - roto_runtime::read_varint(bytes).map(|(v, _)| v != 0).map_err(|_| roto_runtime::RotoError::WireFormatViolation) + crate::runtime::read_varint(bytes).map(|(v, _)| v != 0).map_err(|_| crate::runtime::RotoError::WireFormatViolation) } - pub fn no_standard_descriptor_accessor_or_default(&self) -> roto_runtime::Result { + pub fn no_standard_descriptor_accessor_or_default(&self) -> crate::runtime::Result { self.no_standard_descriptor_accessor().or(Ok(false)) } pub fn has_no_standard_descriptor_accessor(&self) -> bool { self.no_standard_descriptor_accessor_offset.is_some() } - pub fn deprecated(&self) -> roto_runtime::Result { - let offset = self.deprecated_offset.ok_or(roto_runtime::RotoError::FieldNotFound)?; + pub fn deprecated(&self) -> crate::runtime::Result { + let offset = self.deprecated_offset.ok_or(crate::runtime::RotoError::FieldNotFound)?; let (bytes, _) = self.accessor.get_value_at(offset)?; - roto_runtime::read_varint(bytes).map(|(v, _)| v != 0).map_err(|_| roto_runtime::RotoError::WireFormatViolation) + crate::runtime::read_varint(bytes).map(|(v, _)| v != 0).map_err(|_| crate::runtime::RotoError::WireFormatViolation) } - pub fn deprecated_or_default(&self) -> roto_runtime::Result { + pub fn deprecated_or_default(&self) -> crate::runtime::Result { self.deprecated().or(Ok(false)) } pub fn has_deprecated(&self) -> bool { self.deprecated_offset.is_some() } - pub fn map_entry(&self) -> roto_runtime::Result { - let offset = self.map_entry_offset.ok_or(roto_runtime::RotoError::FieldNotFound)?; + pub fn map_entry(&self) -> crate::runtime::Result { + let offset = self.map_entry_offset.ok_or(crate::runtime::RotoError::FieldNotFound)?; let (bytes, _) = self.accessor.get_value_at(offset)?; - roto_runtime::read_varint(bytes).map(|(v, _)| v != 0).map_err(|_| roto_runtime::RotoError::WireFormatViolation) + crate::runtime::read_varint(bytes).map(|(v, _)| v != 0).map_err(|_| crate::runtime::RotoError::WireFormatViolation) } - pub fn map_entry_or_default(&self) -> roto_runtime::Result { + pub fn map_entry_or_default(&self) -> crate::runtime::Result { self.map_entry().or(Ok(false)) } pub fn has_map_entry(&self) -> bool { self.map_entry_offset.is_some() } - pub fn deprecated_legacy_json_field_conflicts(&self) -> roto_runtime::Result { - let offset = self.deprecated_legacy_json_field_conflicts_offset.ok_or(roto_runtime::RotoError::FieldNotFound)?; + pub fn deprecated_legacy_json_field_conflicts(&self) -> crate::runtime::Result { + let offset = self.deprecated_legacy_json_field_conflicts_offset.ok_or(crate::runtime::RotoError::FieldNotFound)?; let (bytes, _) = self.accessor.get_value_at(offset)?; - roto_runtime::read_varint(bytes).map(|(v, _)| v != 0).map_err(|_| roto_runtime::RotoError::WireFormatViolation) + crate::runtime::read_varint(bytes).map(|(v, _)| v != 0).map_err(|_| crate::runtime::RotoError::WireFormatViolation) } - pub fn deprecated_legacy_json_field_conflicts_or_default(&self) -> roto_runtime::Result { + pub fn deprecated_legacy_json_field_conflicts_or_default(&self) -> crate::runtime::Result { self.deprecated_legacy_json_field_conflicts().or(Ok(false)) } pub fn has_deprecated_legacy_json_field_conflicts(&self) -> bool { self.deprecated_legacy_json_field_conflicts_offset.is_some() } - pub fn features(&self) -> roto_runtime::Result<&'a [u8]> { - let offset = self.features_offset.ok_or(roto_runtime::RotoError::FieldNotFound)?; + pub fn features(&self) -> crate::runtime::Result<&'a [u8]> { + let offset = self.features_offset.ok_or(crate::runtime::RotoError::FieldNotFound)?; let (bytes, _) = self.accessor.get_value_at(offset)?; Ok(bytes) } - pub fn features_or_default(&self) -> roto_runtime::Result<&'a [u8]> { + pub fn features_or_default(&self) -> crate::runtime::Result<&'a [u8]> { self.features().or(Ok(&[])) } pub fn has_features(&self) -> bool { self.features_offset.is_some() } - pub fn uninterpreted_option(&self) -> roto_runtime::RepeatedFieldIterator<'a> { + pub fn uninterpreted_option(&self) -> crate::runtime::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 raw_fields(&self) -> roto_runtime::RawFieldIterator<'a> { + pub fn raw_fields(&self) -> crate::runtime::RawFieldIterator<'a> { self.accessor.raw_fields() } } pub struct MessageOptionsBuilder<'b> { - builder: roto_runtime::ProtoBuilder<'b>, + builder: crate::runtime::ProtoBuilder<'b>, message_set_wire_format_written: bool, no_standard_descriptor_accessor_written: bool, deprecated_written: bool, @@ -3778,7 +3778,7 @@ pub struct MessageOptionsBuilder<'b> { impl<'b> MessageOptionsBuilder<'b> { pub fn builder(buf: &mut [u8]) -> MessageOptionsBuilder<'_> { MessageOptionsBuilder { - builder: roto_runtime::ProtoBuilder::new(buf), + builder: crate::runtime::ProtoBuilder::new(buf), message_set_wire_format_written: false, no_standard_descriptor_accessor_written: false, deprecated_written: false, @@ -3789,49 +3789,49 @@ impl<'b> MessageOptionsBuilder<'b> { } } - pub fn message_set_wire_format(mut self, value: u64) -> roto_runtime::Result { + pub fn message_set_wire_format(mut self, value: u64) -> crate::runtime::Result { self.builder.write_varint(1, value)?; self.message_set_wire_format_written = true; Ok(self) } - pub fn no_standard_descriptor_accessor(mut self, value: u64) -> roto_runtime::Result { + pub fn no_standard_descriptor_accessor(mut self, value: u64) -> crate::runtime::Result { self.builder.write_varint(2, value)?; self.no_standard_descriptor_accessor_written = true; Ok(self) } - pub fn deprecated(mut self, value: u64) -> roto_runtime::Result { + pub fn deprecated(mut self, value: u64) -> crate::runtime::Result { self.builder.write_varint(3, value)?; self.deprecated_written = true; Ok(self) } - pub fn map_entry(mut self, value: u64) -> roto_runtime::Result { + pub fn map_entry(mut self, value: u64) -> crate::runtime::Result { self.builder.write_varint(7, value)?; self.map_entry_written = true; Ok(self) } - pub fn deprecated_legacy_json_field_conflicts(mut self, value: u64) -> roto_runtime::Result { + pub fn deprecated_legacy_json_field_conflicts(mut self, value: u64) -> crate::runtime::Result { self.builder.write_varint(11, value)?; self.deprecated_legacy_json_field_conflicts_written = true; Ok(self) } - pub fn features(mut self, value: &[u8]) -> roto_runtime::Result { + pub fn features(mut self, value: &[u8]) -> crate::runtime::Result { self.builder.write_bytes(12, value)?; self.features_written = true; Ok(self) } - pub fn uninterpreted_option(mut self, value: &[u8]) -> roto_runtime::Result { + pub fn uninterpreted_option(mut self, value: &[u8]) -> crate::runtime::Result { self.builder.write_bytes(999, value)?; self.uninterpreted_option_written = true; Ok(self) } - pub fn with(mut self, msg: &MessageOptions<'_>) -> roto_runtime::Result { + pub fn with(mut self, msg: &MessageOptions<'_>) -> crate::runtime::Result { for item in msg.raw_fields() { let (field_number, raw_bytes) = item?; let is_written = match field_number { @@ -3851,7 +3851,7 @@ impl<'b> MessageOptionsBuilder<'b> { Ok(self) } - pub fn finish(self) -> roto_runtime::Result<&'b mut [u8]> { + pub fn finish(self) -> crate::runtime::Result<&'b mut [u8]> { self.builder.finish() } } @@ -3860,15 +3860,15 @@ pub struct OwnedMessageOptions { pub data: bytes::Bytes, } -impl roto_runtime::RotoOwned for OwnedMessageOptions { +impl crate::runtime::RotoOwned for OwnedMessageOptions { type Reader<'a> = MessageOptions<'a>; fn reader(&self) -> MessageOptions<'_> { MessageOptions::new(&self.data).expect("failed to create reader") } } -impl roto_runtime::RotoMessage for OwnedMessageOptions { - fn decode(buf: bytes::Bytes) -> roto_runtime::Result { +impl crate::runtime::RotoMessage for OwnedMessageOptions { + fn decode(buf: bytes::Bytes) -> crate::runtime::Result { Ok(OwnedMessageOptions { data: buf }) } @@ -3878,7 +3878,7 @@ impl roto_runtime::RotoMessage for OwnedMessageOptions { } pub struct FieldOptions<'a> { - accessor: roto_runtime::ProtoAccessor<'a>, + accessor: crate::runtime::ProtoAccessor<'a>, ctype_offset: Option, packed_offset: Option, jstype_offset: Option, @@ -3899,8 +3899,8 @@ pub struct FieldOptions<'a> { } impl<'a> FieldOptions<'a> { - pub fn new(data: &'a [u8]) -> roto_runtime::Result { - let accessor = roto_runtime::ProtoAccessor::new(data)?; + pub fn new(data: &'a [u8]) -> crate::runtime::Result { + let accessor = crate::runtime::ProtoAccessor::new(data)?; let mut ctype_offset = None; let mut packed_offset = None; let mut jstype_offset = None; @@ -3964,167 +3964,167 @@ uninterpreted_option_start, uninterpreted_option_end, }) } - pub fn ctype(&self) -> roto_runtime::Result { - let offset = self.ctype_offset.ok_or(roto_runtime::RotoError::FieldNotFound)?; + pub fn ctype(&self) -> crate::runtime::Result { + let offset = self.ctype_offset.ok_or(crate::runtime::RotoError::FieldNotFound)?; let (bytes, _) = self.accessor.get_value_at(offset)?; - roto_runtime::read_varint(bytes).map(|(v, _)| v as u64).map_err(|_| roto_runtime::RotoError::WireFormatViolation) + crate::runtime::read_varint(bytes).map(|(v, _)| v as u64).map_err(|_| crate::runtime::RotoError::WireFormatViolation) } - pub fn ctype_or_default(&self) -> roto_runtime::Result { + pub fn ctype_or_default(&self) -> crate::runtime::Result { self.ctype().or(Ok(0)) } pub fn has_ctype(&self) -> bool { self.ctype_offset.is_some() } - pub fn packed(&self) -> roto_runtime::Result { - let offset = self.packed_offset.ok_or(roto_runtime::RotoError::FieldNotFound)?; + pub fn packed(&self) -> crate::runtime::Result { + let offset = self.packed_offset.ok_or(crate::runtime::RotoError::FieldNotFound)?; let (bytes, _) = self.accessor.get_value_at(offset)?; - roto_runtime::read_varint(bytes).map(|(v, _)| v != 0).map_err(|_| roto_runtime::RotoError::WireFormatViolation) + crate::runtime::read_varint(bytes).map(|(v, _)| v != 0).map_err(|_| crate::runtime::RotoError::WireFormatViolation) } - pub fn packed_or_default(&self) -> roto_runtime::Result { + pub fn packed_or_default(&self) -> crate::runtime::Result { self.packed().or(Ok(false)) } pub fn has_packed(&self) -> bool { self.packed_offset.is_some() } - pub fn jstype(&self) -> roto_runtime::Result { - let offset = self.jstype_offset.ok_or(roto_runtime::RotoError::FieldNotFound)?; + pub fn jstype(&self) -> crate::runtime::Result { + let offset = self.jstype_offset.ok_or(crate::runtime::RotoError::FieldNotFound)?; let (bytes, _) = self.accessor.get_value_at(offset)?; - roto_runtime::read_varint(bytes).map(|(v, _)| v as u64).map_err(|_| roto_runtime::RotoError::WireFormatViolation) + crate::runtime::read_varint(bytes).map(|(v, _)| v as u64).map_err(|_| crate::runtime::RotoError::WireFormatViolation) } - pub fn jstype_or_default(&self) -> roto_runtime::Result { + pub fn jstype_or_default(&self) -> crate::runtime::Result { self.jstype().or(Ok(0)) } pub fn has_jstype(&self) -> bool { self.jstype_offset.is_some() } - pub fn lazy(&self) -> roto_runtime::Result { - let offset = self.lazy_offset.ok_or(roto_runtime::RotoError::FieldNotFound)?; + pub fn lazy(&self) -> crate::runtime::Result { + let offset = self.lazy_offset.ok_or(crate::runtime::RotoError::FieldNotFound)?; let (bytes, _) = self.accessor.get_value_at(offset)?; - roto_runtime::read_varint(bytes).map(|(v, _)| v != 0).map_err(|_| roto_runtime::RotoError::WireFormatViolation) + crate::runtime::read_varint(bytes).map(|(v, _)| v != 0).map_err(|_| crate::runtime::RotoError::WireFormatViolation) } - pub fn lazy_or_default(&self) -> roto_runtime::Result { + pub fn lazy_or_default(&self) -> crate::runtime::Result { self.lazy().or(Ok(false)) } pub fn has_lazy(&self) -> bool { self.lazy_offset.is_some() } - pub fn unverified_lazy(&self) -> roto_runtime::Result { - let offset = self.unverified_lazy_offset.ok_or(roto_runtime::RotoError::FieldNotFound)?; + pub fn unverified_lazy(&self) -> crate::runtime::Result { + let offset = self.unverified_lazy_offset.ok_or(crate::runtime::RotoError::FieldNotFound)?; let (bytes, _) = self.accessor.get_value_at(offset)?; - roto_runtime::read_varint(bytes).map(|(v, _)| v != 0).map_err(|_| roto_runtime::RotoError::WireFormatViolation) + crate::runtime::read_varint(bytes).map(|(v, _)| v != 0).map_err(|_| crate::runtime::RotoError::WireFormatViolation) } - pub fn unverified_lazy_or_default(&self) -> roto_runtime::Result { + pub fn unverified_lazy_or_default(&self) -> crate::runtime::Result { self.unverified_lazy().or(Ok(false)) } pub fn has_unverified_lazy(&self) -> bool { self.unverified_lazy_offset.is_some() } - pub fn deprecated(&self) -> roto_runtime::Result { - let offset = self.deprecated_offset.ok_or(roto_runtime::RotoError::FieldNotFound)?; + pub fn deprecated(&self) -> crate::runtime::Result { + let offset = self.deprecated_offset.ok_or(crate::runtime::RotoError::FieldNotFound)?; let (bytes, _) = self.accessor.get_value_at(offset)?; - roto_runtime::read_varint(bytes).map(|(v, _)| v != 0).map_err(|_| roto_runtime::RotoError::WireFormatViolation) + crate::runtime::read_varint(bytes).map(|(v, _)| v != 0).map_err(|_| crate::runtime::RotoError::WireFormatViolation) } - pub fn deprecated_or_default(&self) -> roto_runtime::Result { + pub fn deprecated_or_default(&self) -> crate::runtime::Result { self.deprecated().or(Ok(false)) } pub fn has_deprecated(&self) -> bool { self.deprecated_offset.is_some() } - pub fn weak(&self) -> roto_runtime::Result { - let offset = self.weak_offset.ok_or(roto_runtime::RotoError::FieldNotFound)?; + pub fn weak(&self) -> crate::runtime::Result { + let offset = self.weak_offset.ok_or(crate::runtime::RotoError::FieldNotFound)?; let (bytes, _) = self.accessor.get_value_at(offset)?; - roto_runtime::read_varint(bytes).map(|(v, _)| v != 0).map_err(|_| roto_runtime::RotoError::WireFormatViolation) + crate::runtime::read_varint(bytes).map(|(v, _)| v != 0).map_err(|_| crate::runtime::RotoError::WireFormatViolation) } - pub fn weak_or_default(&self) -> roto_runtime::Result { + pub fn weak_or_default(&self) -> crate::runtime::Result { self.weak().or(Ok(false)) } pub fn has_weak(&self) -> bool { self.weak_offset.is_some() } - pub fn debug_redact(&self) -> roto_runtime::Result { - let offset = self.debug_redact_offset.ok_or(roto_runtime::RotoError::FieldNotFound)?; + pub fn debug_redact(&self) -> crate::runtime::Result { + let offset = self.debug_redact_offset.ok_or(crate::runtime::RotoError::FieldNotFound)?; let (bytes, _) = self.accessor.get_value_at(offset)?; - roto_runtime::read_varint(bytes).map(|(v, _)| v != 0).map_err(|_| roto_runtime::RotoError::WireFormatViolation) + crate::runtime::read_varint(bytes).map(|(v, _)| v != 0).map_err(|_| crate::runtime::RotoError::WireFormatViolation) } - pub fn debug_redact_or_default(&self) -> roto_runtime::Result { + pub fn debug_redact_or_default(&self) -> crate::runtime::Result { self.debug_redact().or(Ok(false)) } pub fn has_debug_redact(&self) -> bool { self.debug_redact_offset.is_some() } - pub fn retention(&self) -> roto_runtime::Result { - let offset = self.retention_offset.ok_or(roto_runtime::RotoError::FieldNotFound)?; + pub fn retention(&self) -> crate::runtime::Result { + let offset = self.retention_offset.ok_or(crate::runtime::RotoError::FieldNotFound)?; let (bytes, _) = self.accessor.get_value_at(offset)?; - roto_runtime::read_varint(bytes).map(|(v, _)| v as u64).map_err(|_| roto_runtime::RotoError::WireFormatViolation) + crate::runtime::read_varint(bytes).map(|(v, _)| v as u64).map_err(|_| crate::runtime::RotoError::WireFormatViolation) } - pub fn retention_or_default(&self) -> roto_runtime::Result { + pub fn retention_or_default(&self) -> crate::runtime::Result { self.retention().or(Ok(0)) } pub fn has_retention(&self) -> bool { self.retention_offset.is_some() } - pub fn targets(&self) -> roto_runtime::RepeatedFieldIterator<'a> { + pub fn targets(&self) -> crate::runtime::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) -> roto_runtime::RepeatedFieldIterator<'a> { + pub fn edition_defaults(&self) -> crate::runtime::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) -> roto_runtime::Result<&'a [u8]> { - let offset = self.features_offset.ok_or(roto_runtime::RotoError::FieldNotFound)?; + pub fn features(&self) -> crate::runtime::Result<&'a [u8]> { + let offset = self.features_offset.ok_or(crate::runtime::RotoError::FieldNotFound)?; let (bytes, _) = self.accessor.get_value_at(offset)?; Ok(bytes) } - pub fn features_or_default(&self) -> roto_runtime::Result<&'a [u8]> { + pub fn features_or_default(&self) -> crate::runtime::Result<&'a [u8]> { self.features().or(Ok(&[])) } pub fn has_features(&self) -> bool { self.features_offset.is_some() } - pub fn feature_support(&self) -> roto_runtime::Result<&'a [u8]> { - let offset = self.feature_support_offset.ok_or(roto_runtime::RotoError::FieldNotFound)?; + pub fn feature_support(&self) -> crate::runtime::Result<&'a [u8]> { + let offset = self.feature_support_offset.ok_or(crate::runtime::RotoError::FieldNotFound)?; let (bytes, _) = self.accessor.get_value_at(offset)?; Ok(bytes) } - pub fn feature_support_or_default(&self) -> roto_runtime::Result<&'a [u8]> { + pub fn feature_support_or_default(&self) -> crate::runtime::Result<&'a [u8]> { self.feature_support().or(Ok(&[])) } pub fn has_feature_support(&self) -> bool { self.feature_support_offset.is_some() } - pub fn uninterpreted_option(&self) -> roto_runtime::RepeatedFieldIterator<'a> { + pub fn uninterpreted_option(&self) -> crate::runtime::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 raw_fields(&self) -> roto_runtime::RawFieldIterator<'a> { + pub fn raw_fields(&self) -> crate::runtime::RawFieldIterator<'a> { self.accessor.raw_fields() } } pub struct FieldOptionsBuilder<'b> { - builder: roto_runtime::ProtoBuilder<'b>, + builder: crate::runtime::ProtoBuilder<'b>, ctype_written: bool, packed_written: bool, jstype_written: bool, @@ -4144,7 +4144,7 @@ pub struct FieldOptionsBuilder<'b> { impl<'b> FieldOptionsBuilder<'b> { pub fn builder(buf: &mut [u8]) -> FieldOptionsBuilder<'_> { FieldOptionsBuilder { - builder: roto_runtime::ProtoBuilder::new(buf), + builder: crate::runtime::ProtoBuilder::new(buf), ctype_written: false, packed_written: false, jstype_written: false, @@ -4162,91 +4162,91 @@ impl<'b> FieldOptionsBuilder<'b> { } } - pub fn ctype(mut self, value: u64) -> roto_runtime::Result { + pub fn ctype(mut self, value: u64) -> crate::runtime::Result { self.builder.write_varint(1, value)?; self.ctype_written = true; Ok(self) } - pub fn packed(mut self, value: u64) -> roto_runtime::Result { + pub fn packed(mut self, value: u64) -> crate::runtime::Result { self.builder.write_varint(2, value)?; self.packed_written = true; Ok(self) } - pub fn jstype(mut self, value: u64) -> roto_runtime::Result { + pub fn jstype(mut self, value: u64) -> crate::runtime::Result { self.builder.write_varint(6, value)?; self.jstype_written = true; Ok(self) } - pub fn lazy(mut self, value: u64) -> roto_runtime::Result { + pub fn lazy(mut self, value: u64) -> crate::runtime::Result { self.builder.write_varint(5, value)?; self.lazy_written = true; Ok(self) } - pub fn unverified_lazy(mut self, value: u64) -> roto_runtime::Result { + pub fn unverified_lazy(mut self, value: u64) -> crate::runtime::Result { self.builder.write_varint(15, value)?; self.unverified_lazy_written = true; Ok(self) } - pub fn deprecated(mut self, value: u64) -> roto_runtime::Result { + pub fn deprecated(mut self, value: u64) -> crate::runtime::Result { self.builder.write_varint(3, value)?; self.deprecated_written = true; Ok(self) } - pub fn weak(mut self, value: u64) -> roto_runtime::Result { + pub fn weak(mut self, value: u64) -> crate::runtime::Result { self.builder.write_varint(10, value)?; self.weak_written = true; Ok(self) } - pub fn debug_redact(mut self, value: u64) -> roto_runtime::Result { + pub fn debug_redact(mut self, value: u64) -> crate::runtime::Result { self.builder.write_varint(16, value)?; self.debug_redact_written = true; Ok(self) } - pub fn retention(mut self, value: u64) -> roto_runtime::Result { + pub fn retention(mut self, value: u64) -> crate::runtime::Result { self.builder.write_varint(17, value)?; self.retention_written = true; Ok(self) } - pub fn targets(mut self, value: u64) -> roto_runtime::Result { + pub fn targets(mut self, value: u64) -> crate::runtime::Result { self.builder.write_varint(19, value)?; self.targets_written = true; Ok(self) } - pub fn edition_defaults(mut self, value: &[u8]) -> roto_runtime::Result { + pub fn edition_defaults(mut self, value: &[u8]) -> crate::runtime::Result { self.builder.write_bytes(20, value)?; self.edition_defaults_written = true; Ok(self) } - pub fn features(mut self, value: &[u8]) -> roto_runtime::Result { + pub fn features(mut self, value: &[u8]) -> crate::runtime::Result { self.builder.write_bytes(21, value)?; self.features_written = true; Ok(self) } - pub fn feature_support(mut self, value: &[u8]) -> roto_runtime::Result { + pub fn feature_support(mut self, value: &[u8]) -> crate::runtime::Result { self.builder.write_bytes(22, value)?; self.feature_support_written = true; Ok(self) } - pub fn uninterpreted_option(mut self, value: &[u8]) -> roto_runtime::Result { + pub fn uninterpreted_option(mut self, value: &[u8]) -> crate::runtime::Result { self.builder.write_bytes(999, value)?; self.uninterpreted_option_written = true; Ok(self) } - pub fn with(mut self, msg: &FieldOptions<'_>) -> roto_runtime::Result { + pub fn with(mut self, msg: &FieldOptions<'_>) -> crate::runtime::Result { for item in msg.raw_fields() { let (field_number, raw_bytes) = item?; let is_written = match field_number { @@ -4273,7 +4273,7 @@ impl<'b> FieldOptionsBuilder<'b> { Ok(self) } - pub fn finish(self) -> roto_runtime::Result<&'b mut [u8]> { + pub fn finish(self) -> crate::runtime::Result<&'b mut [u8]> { self.builder.finish() } } @@ -4282,15 +4282,15 @@ pub struct OwnedFieldOptions { pub data: bytes::Bytes, } -impl roto_runtime::RotoOwned for OwnedFieldOptions { +impl crate::runtime::RotoOwned for OwnedFieldOptions { type Reader<'a> = FieldOptions<'a>; fn reader(&self) -> FieldOptions<'_> { FieldOptions::new(&self.data).expect("failed to create reader") } } -impl roto_runtime::RotoMessage for OwnedFieldOptions { - fn decode(buf: bytes::Bytes) -> roto_runtime::Result { +impl crate::runtime::RotoMessage for OwnedFieldOptions { + fn decode(buf: bytes::Bytes) -> crate::runtime::Result { Ok(OwnedFieldOptions { data: buf }) } @@ -4391,14 +4391,14 @@ impl OptionTargetType { } pub struct EditionDefault<'a> { - accessor: roto_runtime::ProtoAccessor<'a>, + accessor: crate::runtime::ProtoAccessor<'a>, edition_offset: Option, value_offset: Option, } impl<'a> EditionDefault<'a> { - pub fn new(data: &'a [u8]) -> roto_runtime::Result { - let accessor = roto_runtime::ProtoAccessor::new(data)?; + pub fn new(data: &'a [u8]) -> crate::runtime::Result { + let accessor = crate::runtime::ProtoAccessor::new(data)?; let mut edition_offset = None; let mut value_offset = None; for item in accessor.fields() { @@ -4414,38 +4414,38 @@ value_offset, }) } - pub fn edition(&self) -> roto_runtime::Result { - let offset = self.edition_offset.ok_or(roto_runtime::RotoError::FieldNotFound)?; + pub fn edition(&self) -> crate::runtime::Result { + let offset = self.edition_offset.ok_or(crate::runtime::RotoError::FieldNotFound)?; let (bytes, _) = self.accessor.get_value_at(offset)?; - roto_runtime::read_varint(bytes).map(|(v, _)| v as u64).map_err(|_| roto_runtime::RotoError::WireFormatViolation) + crate::runtime::read_varint(bytes).map(|(v, _)| v as u64).map_err(|_| crate::runtime::RotoError::WireFormatViolation) } - pub fn edition_or_default(&self) -> roto_runtime::Result { + pub fn edition_or_default(&self) -> crate::runtime::Result { self.edition().or(Ok(0)) } pub fn has_edition(&self) -> bool { self.edition_offset.is_some() } - pub fn value(&self) -> roto_runtime::Result<&'a str> { - let offset = self.value_offset.ok_or(roto_runtime::RotoError::FieldNotFound)?; + pub fn value(&self) -> crate::runtime::Result<&'a str> { + let offset = self.value_offset.ok_or(crate::runtime::RotoError::FieldNotFound)?; let (bytes, _) = self.accessor.get_value_at(offset)?; - str::from_utf8(bytes).map_err(|_| roto_runtime::RotoError::WireFormatViolation) + str::from_utf8(bytes).map_err(|_| crate::runtime::RotoError::WireFormatViolation) } - pub fn value_or_default(&self) -> roto_runtime::Result<&'a str> { + pub fn value_or_default(&self) -> crate::runtime::Result<&'a str> { self.value().or(Ok("")) } pub fn has_value(&self) -> bool { self.value_offset.is_some() } - pub fn raw_fields(&self) -> roto_runtime::RawFieldIterator<'a> { + pub fn raw_fields(&self) -> crate::runtime::RawFieldIterator<'a> { self.accessor.raw_fields() } } pub struct EditionDefaultBuilder<'b> { - builder: roto_runtime::ProtoBuilder<'b>, + builder: crate::runtime::ProtoBuilder<'b>, edition_written: bool, value_written: bool, } @@ -4453,25 +4453,25 @@ pub struct EditionDefaultBuilder<'b> { impl<'b> EditionDefaultBuilder<'b> { pub fn builder(buf: &mut [u8]) -> EditionDefaultBuilder<'_> { EditionDefaultBuilder { - builder: roto_runtime::ProtoBuilder::new(buf), + builder: crate::runtime::ProtoBuilder::new(buf), edition_written: false, value_written: false, } } - pub fn edition(mut self, value: u64) -> roto_runtime::Result { + pub fn edition(mut self, value: u64) -> crate::runtime::Result { self.builder.write_varint(3, value)?; self.edition_written = true; Ok(self) } - pub fn value(mut self, value: &str) -> roto_runtime::Result { + pub fn value(mut self, value: &str) -> crate::runtime::Result { self.builder.write_string(2, value)?; self.value_written = true; Ok(self) } - pub fn with(mut self, msg: &EditionDefault<'_>) -> roto_runtime::Result { + pub fn with(mut self, msg: &EditionDefault<'_>) -> crate::runtime::Result { for item in msg.raw_fields() { let (field_number, raw_bytes) = item?; let is_written = match field_number { @@ -4486,7 +4486,7 @@ impl<'b> EditionDefaultBuilder<'b> { Ok(self) } - pub fn finish(self) -> roto_runtime::Result<&'b mut [u8]> { + pub fn finish(self) -> crate::runtime::Result<&'b mut [u8]> { self.builder.finish() } } @@ -4495,15 +4495,15 @@ pub struct OwnedEditionDefault { pub data: bytes::Bytes, } -impl roto_runtime::RotoOwned for OwnedEditionDefault { +impl crate::runtime::RotoOwned for OwnedEditionDefault { type Reader<'a> = EditionDefault<'a>; fn reader(&self) -> EditionDefault<'_> { EditionDefault::new(&self.data).expect("failed to create reader") } } -impl roto_runtime::RotoMessage for OwnedEditionDefault { - fn decode(buf: bytes::Bytes) -> roto_runtime::Result { +impl crate::runtime::RotoMessage for OwnedEditionDefault { + fn decode(buf: bytes::Bytes) -> crate::runtime::Result { Ok(OwnedEditionDefault { data: buf }) } @@ -4513,7 +4513,7 @@ impl roto_runtime::RotoMessage for OwnedEditionDefault { } pub struct FeatureSupport<'a> { - accessor: roto_runtime::ProtoAccessor<'a>, + accessor: crate::runtime::ProtoAccessor<'a>, edition_introduced_offset: Option, edition_deprecated_offset: Option, deprecation_warning_offset: Option, @@ -4522,8 +4522,8 @@ pub struct FeatureSupport<'a> { } impl<'a> FeatureSupport<'a> { - pub fn new(data: &'a [u8]) -> roto_runtime::Result { - let accessor = roto_runtime::ProtoAccessor::new(data)?; + pub fn new(data: &'a [u8]) -> crate::runtime::Result { + let accessor = crate::runtime::ProtoAccessor::new(data)?; let mut edition_introduced_offset = None; let mut edition_deprecated_offset = None; let mut deprecation_warning_offset = None; @@ -4548,74 +4548,74 @@ removal_error_offset, }) } - pub fn edition_introduced(&self) -> roto_runtime::Result { - let offset = self.edition_introduced_offset.ok_or(roto_runtime::RotoError::FieldNotFound)?; + pub fn edition_introduced(&self) -> crate::runtime::Result { + let offset = self.edition_introduced_offset.ok_or(crate::runtime::RotoError::FieldNotFound)?; let (bytes, _) = self.accessor.get_value_at(offset)?; - roto_runtime::read_varint(bytes).map(|(v, _)| v as u64).map_err(|_| roto_runtime::RotoError::WireFormatViolation) + crate::runtime::read_varint(bytes).map(|(v, _)| v as u64).map_err(|_| crate::runtime::RotoError::WireFormatViolation) } - pub fn edition_introduced_or_default(&self) -> roto_runtime::Result { + pub fn edition_introduced_or_default(&self) -> crate::runtime::Result { self.edition_introduced().or(Ok(0)) } pub fn has_edition_introduced(&self) -> bool { self.edition_introduced_offset.is_some() } - pub fn edition_deprecated(&self) -> roto_runtime::Result { - let offset = self.edition_deprecated_offset.ok_or(roto_runtime::RotoError::FieldNotFound)?; + pub fn edition_deprecated(&self) -> crate::runtime::Result { + let offset = self.edition_deprecated_offset.ok_or(crate::runtime::RotoError::FieldNotFound)?; let (bytes, _) = self.accessor.get_value_at(offset)?; - roto_runtime::read_varint(bytes).map(|(v, _)| v as u64).map_err(|_| roto_runtime::RotoError::WireFormatViolation) + crate::runtime::read_varint(bytes).map(|(v, _)| v as u64).map_err(|_| crate::runtime::RotoError::WireFormatViolation) } - pub fn edition_deprecated_or_default(&self) -> roto_runtime::Result { + pub fn edition_deprecated_or_default(&self) -> crate::runtime::Result { self.edition_deprecated().or(Ok(0)) } pub fn has_edition_deprecated(&self) -> bool { self.edition_deprecated_offset.is_some() } - pub fn deprecation_warning(&self) -> roto_runtime::Result<&'a str> { - let offset = self.deprecation_warning_offset.ok_or(roto_runtime::RotoError::FieldNotFound)?; + pub fn deprecation_warning(&self) -> crate::runtime::Result<&'a str> { + let offset = self.deprecation_warning_offset.ok_or(crate::runtime::RotoError::FieldNotFound)?; let (bytes, _) = self.accessor.get_value_at(offset)?; - str::from_utf8(bytes).map_err(|_| roto_runtime::RotoError::WireFormatViolation) + str::from_utf8(bytes).map_err(|_| crate::runtime::RotoError::WireFormatViolation) } - pub fn deprecation_warning_or_default(&self) -> roto_runtime::Result<&'a str> { + pub fn deprecation_warning_or_default(&self) -> crate::runtime::Result<&'a str> { self.deprecation_warning().or(Ok("")) } pub fn has_deprecation_warning(&self) -> bool { self.deprecation_warning_offset.is_some() } - pub fn edition_removed(&self) -> roto_runtime::Result { - let offset = self.edition_removed_offset.ok_or(roto_runtime::RotoError::FieldNotFound)?; + pub fn edition_removed(&self) -> crate::runtime::Result { + let offset = self.edition_removed_offset.ok_or(crate::runtime::RotoError::FieldNotFound)?; let (bytes, _) = self.accessor.get_value_at(offset)?; - roto_runtime::read_varint(bytes).map(|(v, _)| v as u64).map_err(|_| roto_runtime::RotoError::WireFormatViolation) + crate::runtime::read_varint(bytes).map(|(v, _)| v as u64).map_err(|_| crate::runtime::RotoError::WireFormatViolation) } - pub fn edition_removed_or_default(&self) -> roto_runtime::Result { + pub fn edition_removed_or_default(&self) -> crate::runtime::Result { self.edition_removed().or(Ok(0)) } pub fn has_edition_removed(&self) -> bool { self.edition_removed_offset.is_some() } - pub fn removal_error(&self) -> roto_runtime::Result<&'a str> { - let offset = self.removal_error_offset.ok_or(roto_runtime::RotoError::FieldNotFound)?; + pub fn removal_error(&self) -> crate::runtime::Result<&'a str> { + let offset = self.removal_error_offset.ok_or(crate::runtime::RotoError::FieldNotFound)?; let (bytes, _) = self.accessor.get_value_at(offset)?; - str::from_utf8(bytes).map_err(|_| roto_runtime::RotoError::WireFormatViolation) + str::from_utf8(bytes).map_err(|_| crate::runtime::RotoError::WireFormatViolation) } - pub fn removal_error_or_default(&self) -> roto_runtime::Result<&'a str> { + pub fn removal_error_or_default(&self) -> crate::runtime::Result<&'a str> { self.removal_error().or(Ok("")) } pub fn has_removal_error(&self) -> bool { self.removal_error_offset.is_some() } - pub fn raw_fields(&self) -> roto_runtime::RawFieldIterator<'a> { + pub fn raw_fields(&self) -> crate::runtime::RawFieldIterator<'a> { self.accessor.raw_fields() } } pub struct FeatureSupportBuilder<'b> { - builder: roto_runtime::ProtoBuilder<'b>, + builder: crate::runtime::ProtoBuilder<'b>, edition_introduced_written: bool, edition_deprecated_written: bool, deprecation_warning_written: bool, @@ -4626,7 +4626,7 @@ pub struct FeatureSupportBuilder<'b> { impl<'b> FeatureSupportBuilder<'b> { pub fn builder(buf: &mut [u8]) -> FeatureSupportBuilder<'_> { FeatureSupportBuilder { - builder: roto_runtime::ProtoBuilder::new(buf), + builder: crate::runtime::ProtoBuilder::new(buf), edition_introduced_written: false, edition_deprecated_written: false, deprecation_warning_written: false, @@ -4635,37 +4635,37 @@ impl<'b> FeatureSupportBuilder<'b> { } } - pub fn edition_introduced(mut self, value: u64) -> roto_runtime::Result { + pub fn edition_introduced(mut self, value: u64) -> crate::runtime::Result { self.builder.write_varint(1, value)?; self.edition_introduced_written = true; Ok(self) } - pub fn edition_deprecated(mut self, value: u64) -> roto_runtime::Result { + pub fn edition_deprecated(mut self, value: u64) -> crate::runtime::Result { self.builder.write_varint(2, value)?; self.edition_deprecated_written = true; Ok(self) } - pub fn deprecation_warning(mut self, value: &str) -> roto_runtime::Result { + pub fn deprecation_warning(mut self, value: &str) -> crate::runtime::Result { self.builder.write_string(3, value)?; self.deprecation_warning_written = true; Ok(self) } - pub fn edition_removed(mut self, value: u64) -> roto_runtime::Result { + pub fn edition_removed(mut self, value: u64) -> crate::runtime::Result { self.builder.write_varint(4, value)?; self.edition_removed_written = true; Ok(self) } - pub fn removal_error(mut self, value: &str) -> roto_runtime::Result { + pub fn removal_error(mut self, value: &str) -> crate::runtime::Result { self.builder.write_string(5, value)?; self.removal_error_written = true; Ok(self) } - pub fn with(mut self, msg: &FeatureSupport<'_>) -> roto_runtime::Result { + pub fn with(mut self, msg: &FeatureSupport<'_>) -> crate::runtime::Result { for item in msg.raw_fields() { let (field_number, raw_bytes) = item?; let is_written = match field_number { @@ -4683,7 +4683,7 @@ impl<'b> FeatureSupportBuilder<'b> { Ok(self) } - pub fn finish(self) -> roto_runtime::Result<&'b mut [u8]> { + pub fn finish(self) -> crate::runtime::Result<&'b mut [u8]> { self.builder.finish() } } @@ -4692,15 +4692,15 @@ pub struct OwnedFeatureSupport { pub data: bytes::Bytes, } -impl roto_runtime::RotoOwned for OwnedFeatureSupport { +impl crate::runtime::RotoOwned for OwnedFeatureSupport { type Reader<'a> = FeatureSupport<'a>; fn reader(&self) -> FeatureSupport<'_> { FeatureSupport::new(&self.data).expect("failed to create reader") } } -impl roto_runtime::RotoMessage for OwnedFeatureSupport { - fn decode(buf: bytes::Bytes) -> roto_runtime::Result { +impl crate::runtime::RotoMessage for OwnedFeatureSupport { + fn decode(buf: bytes::Bytes) -> crate::runtime::Result { Ok(OwnedFeatureSupport { data: buf }) } @@ -4712,15 +4712,15 @@ impl roto_runtime::RotoMessage for OwnedFeatureSupport { } pub struct OneofOptions<'a> { - accessor: roto_runtime::ProtoAccessor<'a>, + accessor: crate::runtime::ProtoAccessor<'a>, features_offset: Option, uninterpreted_option_start: Option, uninterpreted_option_end: Option, } impl<'a> OneofOptions<'a> { - pub fn new(data: &'a [u8]) -> roto_runtime::Result { - let accessor = roto_runtime::ProtoAccessor::new(data)?; + pub fn new(data: &'a [u8]) -> crate::runtime::Result { + let accessor = crate::runtime::ProtoAccessor::new(data)?; let mut features_offset = None; let mut uninterpreted_option_start = None; let mut uninterpreted_option_end = None; @@ -4740,33 +4740,33 @@ uninterpreted_option_start, uninterpreted_option_end, }) } - pub fn features(&self) -> roto_runtime::Result<&'a [u8]> { - let offset = self.features_offset.ok_or(roto_runtime::RotoError::FieldNotFound)?; + pub fn features(&self) -> crate::runtime::Result<&'a [u8]> { + let offset = self.features_offset.ok_or(crate::runtime::RotoError::FieldNotFound)?; let (bytes, _) = self.accessor.get_value_at(offset)?; Ok(bytes) } - pub fn features_or_default(&self) -> roto_runtime::Result<&'a [u8]> { + pub fn features_or_default(&self) -> crate::runtime::Result<&'a [u8]> { self.features().or(Ok(&[])) } pub fn has_features(&self) -> bool { self.features_offset.is_some() } - pub fn uninterpreted_option(&self) -> roto_runtime::RepeatedFieldIterator<'a> { + pub fn uninterpreted_option(&self) -> crate::runtime::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 raw_fields(&self) -> roto_runtime::RawFieldIterator<'a> { + pub fn raw_fields(&self) -> crate::runtime::RawFieldIterator<'a> { self.accessor.raw_fields() } } pub struct OneofOptionsBuilder<'b> { - builder: roto_runtime::ProtoBuilder<'b>, + builder: crate::runtime::ProtoBuilder<'b>, features_written: bool, uninterpreted_option_written: bool, } @@ -4774,25 +4774,25 @@ pub struct OneofOptionsBuilder<'b> { impl<'b> OneofOptionsBuilder<'b> { pub fn builder(buf: &mut [u8]) -> OneofOptionsBuilder<'_> { OneofOptionsBuilder { - builder: roto_runtime::ProtoBuilder::new(buf), + builder: crate::runtime::ProtoBuilder::new(buf), features_written: false, uninterpreted_option_written: false, } } - pub fn features(mut self, value: &[u8]) -> roto_runtime::Result { + pub fn features(mut self, value: &[u8]) -> crate::runtime::Result { self.builder.write_bytes(1, value)?; self.features_written = true; Ok(self) } - pub fn uninterpreted_option(mut self, value: &[u8]) -> roto_runtime::Result { + pub fn uninterpreted_option(mut self, value: &[u8]) -> crate::runtime::Result { self.builder.write_bytes(999, value)?; self.uninterpreted_option_written = true; Ok(self) } - pub fn with(mut self, msg: &OneofOptions<'_>) -> roto_runtime::Result { + pub fn with(mut self, msg: &OneofOptions<'_>) -> crate::runtime::Result { for item in msg.raw_fields() { let (field_number, raw_bytes) = item?; let is_written = match field_number { @@ -4807,7 +4807,7 @@ impl<'b> OneofOptionsBuilder<'b> { Ok(self) } - pub fn finish(self) -> roto_runtime::Result<&'b mut [u8]> { + pub fn finish(self) -> crate::runtime::Result<&'b mut [u8]> { self.builder.finish() } } @@ -4816,15 +4816,15 @@ pub struct OwnedOneofOptions { pub data: bytes::Bytes, } -impl roto_runtime::RotoOwned for OwnedOneofOptions { +impl crate::runtime::RotoOwned for OwnedOneofOptions { type Reader<'a> = OneofOptions<'a>; fn reader(&self) -> OneofOptions<'_> { OneofOptions::new(&self.data).expect("failed to create reader") } } -impl roto_runtime::RotoMessage for OwnedOneofOptions { - fn decode(buf: bytes::Bytes) -> roto_runtime::Result { +impl crate::runtime::RotoMessage for OwnedOneofOptions { + fn decode(buf: bytes::Bytes) -> crate::runtime::Result { Ok(OwnedOneofOptions { data: buf }) } @@ -4834,7 +4834,7 @@ impl roto_runtime::RotoMessage for OwnedOneofOptions { } pub struct EnumOptions<'a> { - accessor: roto_runtime::ProtoAccessor<'a>, + accessor: crate::runtime::ProtoAccessor<'a>, allow_alias_offset: Option, deprecated_offset: Option, deprecated_legacy_json_field_conflicts_offset: Option, @@ -4844,8 +4844,8 @@ pub struct EnumOptions<'a> { } impl<'a> EnumOptions<'a> { - pub fn new(data: &'a [u8]) -> roto_runtime::Result { - let accessor = roto_runtime::ProtoAccessor::new(data)?; + pub fn new(data: &'a [u8]) -> crate::runtime::Result { + let accessor = crate::runtime::ProtoAccessor::new(data)?; let mut allow_alias_offset = None; let mut deprecated_offset = None; let mut deprecated_legacy_json_field_conflicts_offset = None; @@ -4874,69 +4874,69 @@ uninterpreted_option_start, uninterpreted_option_end, }) } - pub fn allow_alias(&self) -> roto_runtime::Result { - let offset = self.allow_alias_offset.ok_or(roto_runtime::RotoError::FieldNotFound)?; + pub fn allow_alias(&self) -> crate::runtime::Result { + let offset = self.allow_alias_offset.ok_or(crate::runtime::RotoError::FieldNotFound)?; let (bytes, _) = self.accessor.get_value_at(offset)?; - roto_runtime::read_varint(bytes).map(|(v, _)| v != 0).map_err(|_| roto_runtime::RotoError::WireFormatViolation) + crate::runtime::read_varint(bytes).map(|(v, _)| v != 0).map_err(|_| crate::runtime::RotoError::WireFormatViolation) } - pub fn allow_alias_or_default(&self) -> roto_runtime::Result { + pub fn allow_alias_or_default(&self) -> crate::runtime::Result { self.allow_alias().or(Ok(false)) } pub fn has_allow_alias(&self) -> bool { self.allow_alias_offset.is_some() } - pub fn deprecated(&self) -> roto_runtime::Result { - let offset = self.deprecated_offset.ok_or(roto_runtime::RotoError::FieldNotFound)?; + pub fn deprecated(&self) -> crate::runtime::Result { + let offset = self.deprecated_offset.ok_or(crate::runtime::RotoError::FieldNotFound)?; let (bytes, _) = self.accessor.get_value_at(offset)?; - roto_runtime::read_varint(bytes).map(|(v, _)| v != 0).map_err(|_| roto_runtime::RotoError::WireFormatViolation) + crate::runtime::read_varint(bytes).map(|(v, _)| v != 0).map_err(|_| crate::runtime::RotoError::WireFormatViolation) } - pub fn deprecated_or_default(&self) -> roto_runtime::Result { + pub fn deprecated_or_default(&self) -> crate::runtime::Result { self.deprecated().or(Ok(false)) } pub fn has_deprecated(&self) -> bool { self.deprecated_offset.is_some() } - pub fn deprecated_legacy_json_field_conflicts(&self) -> roto_runtime::Result { - let offset = self.deprecated_legacy_json_field_conflicts_offset.ok_or(roto_runtime::RotoError::FieldNotFound)?; + pub fn deprecated_legacy_json_field_conflicts(&self) -> crate::runtime::Result { + let offset = self.deprecated_legacy_json_field_conflicts_offset.ok_or(crate::runtime::RotoError::FieldNotFound)?; let (bytes, _) = self.accessor.get_value_at(offset)?; - roto_runtime::read_varint(bytes).map(|(v, _)| v != 0).map_err(|_| roto_runtime::RotoError::WireFormatViolation) + crate::runtime::read_varint(bytes).map(|(v, _)| v != 0).map_err(|_| crate::runtime::RotoError::WireFormatViolation) } - pub fn deprecated_legacy_json_field_conflicts_or_default(&self) -> roto_runtime::Result { + pub fn deprecated_legacy_json_field_conflicts_or_default(&self) -> crate::runtime::Result { self.deprecated_legacy_json_field_conflicts().or(Ok(false)) } pub fn has_deprecated_legacy_json_field_conflicts(&self) -> bool { self.deprecated_legacy_json_field_conflicts_offset.is_some() } - pub fn features(&self) -> roto_runtime::Result<&'a [u8]> { - let offset = self.features_offset.ok_or(roto_runtime::RotoError::FieldNotFound)?; + pub fn features(&self) -> crate::runtime::Result<&'a [u8]> { + let offset = self.features_offset.ok_or(crate::runtime::RotoError::FieldNotFound)?; let (bytes, _) = self.accessor.get_value_at(offset)?; Ok(bytes) } - pub fn features_or_default(&self) -> roto_runtime::Result<&'a [u8]> { + pub fn features_or_default(&self) -> crate::runtime::Result<&'a [u8]> { self.features().or(Ok(&[])) } pub fn has_features(&self) -> bool { self.features_offset.is_some() } - pub fn uninterpreted_option(&self) -> roto_runtime::RepeatedFieldIterator<'a> { + pub fn uninterpreted_option(&self) -> crate::runtime::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 raw_fields(&self) -> roto_runtime::RawFieldIterator<'a> { + pub fn raw_fields(&self) -> crate::runtime::RawFieldIterator<'a> { self.accessor.raw_fields() } } pub struct EnumOptionsBuilder<'b> { - builder: roto_runtime::ProtoBuilder<'b>, + builder: crate::runtime::ProtoBuilder<'b>, allow_alias_written: bool, deprecated_written: bool, deprecated_legacy_json_field_conflicts_written: bool, @@ -4947,7 +4947,7 @@ pub struct EnumOptionsBuilder<'b> { impl<'b> EnumOptionsBuilder<'b> { pub fn builder(buf: &mut [u8]) -> EnumOptionsBuilder<'_> { EnumOptionsBuilder { - builder: roto_runtime::ProtoBuilder::new(buf), + builder: crate::runtime::ProtoBuilder::new(buf), allow_alias_written: false, deprecated_written: false, deprecated_legacy_json_field_conflicts_written: false, @@ -4956,37 +4956,37 @@ impl<'b> EnumOptionsBuilder<'b> { } } - pub fn allow_alias(mut self, value: u64) -> roto_runtime::Result { + pub fn allow_alias(mut self, value: u64) -> crate::runtime::Result { self.builder.write_varint(2, value)?; self.allow_alias_written = true; Ok(self) } - pub fn deprecated(mut self, value: u64) -> roto_runtime::Result { + pub fn deprecated(mut self, value: u64) -> crate::runtime::Result { self.builder.write_varint(3, value)?; self.deprecated_written = true; Ok(self) } - pub fn deprecated_legacy_json_field_conflicts(mut self, value: u64) -> roto_runtime::Result { + pub fn deprecated_legacy_json_field_conflicts(mut self, value: u64) -> crate::runtime::Result { self.builder.write_varint(6, value)?; self.deprecated_legacy_json_field_conflicts_written = true; Ok(self) } - pub fn features(mut self, value: &[u8]) -> roto_runtime::Result { + pub fn features(mut self, value: &[u8]) -> crate::runtime::Result { self.builder.write_bytes(7, value)?; self.features_written = true; Ok(self) } - pub fn uninterpreted_option(mut self, value: &[u8]) -> roto_runtime::Result { + pub fn uninterpreted_option(mut self, value: &[u8]) -> crate::runtime::Result { self.builder.write_bytes(999, value)?; self.uninterpreted_option_written = true; Ok(self) } - pub fn with(mut self, msg: &EnumOptions<'_>) -> roto_runtime::Result { + pub fn with(mut self, msg: &EnumOptions<'_>) -> crate::runtime::Result { for item in msg.raw_fields() { let (field_number, raw_bytes) = item?; let is_written = match field_number { @@ -5004,7 +5004,7 @@ impl<'b> EnumOptionsBuilder<'b> { Ok(self) } - pub fn finish(self) -> roto_runtime::Result<&'b mut [u8]> { + pub fn finish(self) -> crate::runtime::Result<&'b mut [u8]> { self.builder.finish() } } @@ -5013,15 +5013,15 @@ pub struct OwnedEnumOptions { pub data: bytes::Bytes, } -impl roto_runtime::RotoOwned for OwnedEnumOptions { +impl crate::runtime::RotoOwned for OwnedEnumOptions { type Reader<'a> = EnumOptions<'a>; fn reader(&self) -> EnumOptions<'_> { EnumOptions::new(&self.data).expect("failed to create reader") } } -impl roto_runtime::RotoMessage for OwnedEnumOptions { - fn decode(buf: bytes::Bytes) -> roto_runtime::Result { +impl crate::runtime::RotoMessage for OwnedEnumOptions { + fn decode(buf: bytes::Bytes) -> crate::runtime::Result { Ok(OwnedEnumOptions { data: buf }) } @@ -5031,7 +5031,7 @@ impl roto_runtime::RotoMessage for OwnedEnumOptions { } pub struct EnumValueOptions<'a> { - accessor: roto_runtime::ProtoAccessor<'a>, + accessor: crate::runtime::ProtoAccessor<'a>, deprecated_offset: Option, features_offset: Option, debug_redact_offset: Option, @@ -5041,8 +5041,8 @@ pub struct EnumValueOptions<'a> { } impl<'a> EnumValueOptions<'a> { - pub fn new(data: &'a [u8]) -> roto_runtime::Result { - let accessor = roto_runtime::ProtoAccessor::new(data)?; + pub fn new(data: &'a [u8]) -> crate::runtime::Result { + let accessor = crate::runtime::ProtoAccessor::new(data)?; let mut deprecated_offset = None; let mut features_offset = None; let mut debug_redact_offset = None; @@ -5071,69 +5071,69 @@ uninterpreted_option_start, uninterpreted_option_end, }) } - pub fn deprecated(&self) -> roto_runtime::Result { - let offset = self.deprecated_offset.ok_or(roto_runtime::RotoError::FieldNotFound)?; + pub fn deprecated(&self) -> crate::runtime::Result { + let offset = self.deprecated_offset.ok_or(crate::runtime::RotoError::FieldNotFound)?; let (bytes, _) = self.accessor.get_value_at(offset)?; - roto_runtime::read_varint(bytes).map(|(v, _)| v != 0).map_err(|_| roto_runtime::RotoError::WireFormatViolation) + crate::runtime::read_varint(bytes).map(|(v, _)| v != 0).map_err(|_| crate::runtime::RotoError::WireFormatViolation) } - pub fn deprecated_or_default(&self) -> roto_runtime::Result { + pub fn deprecated_or_default(&self) -> crate::runtime::Result { self.deprecated().or(Ok(false)) } pub fn has_deprecated(&self) -> bool { self.deprecated_offset.is_some() } - pub fn features(&self) -> roto_runtime::Result<&'a [u8]> { - let offset = self.features_offset.ok_or(roto_runtime::RotoError::FieldNotFound)?; + pub fn features(&self) -> crate::runtime::Result<&'a [u8]> { + let offset = self.features_offset.ok_or(crate::runtime::RotoError::FieldNotFound)?; let (bytes, _) = self.accessor.get_value_at(offset)?; Ok(bytes) } - pub fn features_or_default(&self) -> roto_runtime::Result<&'a [u8]> { + pub fn features_or_default(&self) -> crate::runtime::Result<&'a [u8]> { self.features().or(Ok(&[])) } pub fn has_features(&self) -> bool { self.features_offset.is_some() } - pub fn debug_redact(&self) -> roto_runtime::Result { - let offset = self.debug_redact_offset.ok_or(roto_runtime::RotoError::FieldNotFound)?; + pub fn debug_redact(&self) -> crate::runtime::Result { + let offset = self.debug_redact_offset.ok_or(crate::runtime::RotoError::FieldNotFound)?; let (bytes, _) = self.accessor.get_value_at(offset)?; - roto_runtime::read_varint(bytes).map(|(v, _)| v != 0).map_err(|_| roto_runtime::RotoError::WireFormatViolation) + crate::runtime::read_varint(bytes).map(|(v, _)| v != 0).map_err(|_| crate::runtime::RotoError::WireFormatViolation) } - pub fn debug_redact_or_default(&self) -> roto_runtime::Result { + pub fn debug_redact_or_default(&self) -> crate::runtime::Result { self.debug_redact().or(Ok(false)) } pub fn has_debug_redact(&self) -> bool { self.debug_redact_offset.is_some() } - pub fn feature_support(&self) -> roto_runtime::Result<&'a [u8]> { - let offset = self.feature_support_offset.ok_or(roto_runtime::RotoError::FieldNotFound)?; + pub fn feature_support(&self) -> crate::runtime::Result<&'a [u8]> { + let offset = self.feature_support_offset.ok_or(crate::runtime::RotoError::FieldNotFound)?; let (bytes, _) = self.accessor.get_value_at(offset)?; Ok(bytes) } - pub fn feature_support_or_default(&self) -> roto_runtime::Result<&'a [u8]> { + pub fn feature_support_or_default(&self) -> crate::runtime::Result<&'a [u8]> { self.feature_support().or(Ok(&[])) } pub fn has_feature_support(&self) -> bool { self.feature_support_offset.is_some() } - pub fn uninterpreted_option(&self) -> roto_runtime::RepeatedFieldIterator<'a> { + pub fn uninterpreted_option(&self) -> crate::runtime::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 raw_fields(&self) -> roto_runtime::RawFieldIterator<'a> { + pub fn raw_fields(&self) -> crate::runtime::RawFieldIterator<'a> { self.accessor.raw_fields() } } pub struct EnumValueOptionsBuilder<'b> { - builder: roto_runtime::ProtoBuilder<'b>, + builder: crate::runtime::ProtoBuilder<'b>, deprecated_written: bool, features_written: bool, debug_redact_written: bool, @@ -5144,7 +5144,7 @@ pub struct EnumValueOptionsBuilder<'b> { impl<'b> EnumValueOptionsBuilder<'b> { pub fn builder(buf: &mut [u8]) -> EnumValueOptionsBuilder<'_> { EnumValueOptionsBuilder { - builder: roto_runtime::ProtoBuilder::new(buf), + builder: crate::runtime::ProtoBuilder::new(buf), deprecated_written: false, features_written: false, debug_redact_written: false, @@ -5153,37 +5153,37 @@ impl<'b> EnumValueOptionsBuilder<'b> { } } - pub fn deprecated(mut self, value: u64) -> roto_runtime::Result { + pub fn deprecated(mut self, value: u64) -> crate::runtime::Result { self.builder.write_varint(1, value)?; self.deprecated_written = true; Ok(self) } - pub fn features(mut self, value: &[u8]) -> roto_runtime::Result { + pub fn features(mut self, value: &[u8]) -> crate::runtime::Result { self.builder.write_bytes(2, value)?; self.features_written = true; Ok(self) } - pub fn debug_redact(mut self, value: u64) -> roto_runtime::Result { + pub fn debug_redact(mut self, value: u64) -> crate::runtime::Result { self.builder.write_varint(3, value)?; self.debug_redact_written = true; Ok(self) } - pub fn feature_support(mut self, value: &[u8]) -> roto_runtime::Result { + pub fn feature_support(mut self, value: &[u8]) -> crate::runtime::Result { self.builder.write_bytes(4, value)?; self.feature_support_written = true; Ok(self) } - pub fn uninterpreted_option(mut self, value: &[u8]) -> roto_runtime::Result { + pub fn uninterpreted_option(mut self, value: &[u8]) -> crate::runtime::Result { self.builder.write_bytes(999, value)?; self.uninterpreted_option_written = true; Ok(self) } - pub fn with(mut self, msg: &EnumValueOptions<'_>) -> roto_runtime::Result { + pub fn with(mut self, msg: &EnumValueOptions<'_>) -> crate::runtime::Result { for item in msg.raw_fields() { let (field_number, raw_bytes) = item?; let is_written = match field_number { @@ -5201,7 +5201,7 @@ impl<'b> EnumValueOptionsBuilder<'b> { Ok(self) } - pub fn finish(self) -> roto_runtime::Result<&'b mut [u8]> { + pub fn finish(self) -> crate::runtime::Result<&'b mut [u8]> { self.builder.finish() } } @@ -5210,15 +5210,15 @@ pub struct OwnedEnumValueOptions { pub data: bytes::Bytes, } -impl roto_runtime::RotoOwned for OwnedEnumValueOptions { +impl crate::runtime::RotoOwned for OwnedEnumValueOptions { type Reader<'a> = EnumValueOptions<'a>; fn reader(&self) -> EnumValueOptions<'_> { EnumValueOptions::new(&self.data).expect("failed to create reader") } } -impl roto_runtime::RotoMessage for OwnedEnumValueOptions { - fn decode(buf: bytes::Bytes) -> roto_runtime::Result { +impl crate::runtime::RotoMessage for OwnedEnumValueOptions { + fn decode(buf: bytes::Bytes) -> crate::runtime::Result { Ok(OwnedEnumValueOptions { data: buf }) } @@ -5228,7 +5228,7 @@ impl roto_runtime::RotoMessage for OwnedEnumValueOptions { } pub struct ServiceOptions<'a> { - accessor: roto_runtime::ProtoAccessor<'a>, + accessor: crate::runtime::ProtoAccessor<'a>, features_offset: Option, deprecated_offset: Option, uninterpreted_option_start: Option, @@ -5236,8 +5236,8 @@ pub struct ServiceOptions<'a> { } impl<'a> ServiceOptions<'a> { - pub fn new(data: &'a [u8]) -> roto_runtime::Result { - let accessor = roto_runtime::ProtoAccessor::new(data)?; + pub fn new(data: &'a [u8]) -> crate::runtime::Result { + let accessor = crate::runtime::ProtoAccessor::new(data)?; let mut features_offset = None; let mut deprecated_offset = None; let mut uninterpreted_option_start = None; @@ -5260,45 +5260,45 @@ uninterpreted_option_start, uninterpreted_option_end, }) } - pub fn features(&self) -> roto_runtime::Result<&'a [u8]> { - let offset = self.features_offset.ok_or(roto_runtime::RotoError::FieldNotFound)?; + pub fn features(&self) -> crate::runtime::Result<&'a [u8]> { + let offset = self.features_offset.ok_or(crate::runtime::RotoError::FieldNotFound)?; let (bytes, _) = self.accessor.get_value_at(offset)?; Ok(bytes) } - pub fn features_or_default(&self) -> roto_runtime::Result<&'a [u8]> { + pub fn features_or_default(&self) -> crate::runtime::Result<&'a [u8]> { self.features().or(Ok(&[])) } pub fn has_features(&self) -> bool { self.features_offset.is_some() } - pub fn deprecated(&self) -> roto_runtime::Result { - let offset = self.deprecated_offset.ok_or(roto_runtime::RotoError::FieldNotFound)?; + pub fn deprecated(&self) -> crate::runtime::Result { + let offset = self.deprecated_offset.ok_or(crate::runtime::RotoError::FieldNotFound)?; let (bytes, _) = self.accessor.get_value_at(offset)?; - roto_runtime::read_varint(bytes).map(|(v, _)| v != 0).map_err(|_| roto_runtime::RotoError::WireFormatViolation) + crate::runtime::read_varint(bytes).map(|(v, _)| v != 0).map_err(|_| crate::runtime::RotoError::WireFormatViolation) } - pub fn deprecated_or_default(&self) -> roto_runtime::Result { + pub fn deprecated_or_default(&self) -> crate::runtime::Result { self.deprecated().or(Ok(false)) } pub fn has_deprecated(&self) -> bool { self.deprecated_offset.is_some() } - pub fn uninterpreted_option(&self) -> roto_runtime::RepeatedFieldIterator<'a> { + pub fn uninterpreted_option(&self) -> crate::runtime::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 raw_fields(&self) -> roto_runtime::RawFieldIterator<'a> { + pub fn raw_fields(&self) -> crate::runtime::RawFieldIterator<'a> { self.accessor.raw_fields() } } pub struct ServiceOptionsBuilder<'b> { - builder: roto_runtime::ProtoBuilder<'b>, + builder: crate::runtime::ProtoBuilder<'b>, features_written: bool, deprecated_written: bool, uninterpreted_option_written: bool, @@ -5307,32 +5307,32 @@ pub struct ServiceOptionsBuilder<'b> { impl<'b> ServiceOptionsBuilder<'b> { pub fn builder(buf: &mut [u8]) -> ServiceOptionsBuilder<'_> { ServiceOptionsBuilder { - builder: roto_runtime::ProtoBuilder::new(buf), + builder: crate::runtime::ProtoBuilder::new(buf), features_written: false, deprecated_written: false, uninterpreted_option_written: false, } } - pub fn features(mut self, value: &[u8]) -> roto_runtime::Result { + pub fn features(mut self, value: &[u8]) -> crate::runtime::Result { self.builder.write_bytes(34, value)?; self.features_written = true; Ok(self) } - pub fn deprecated(mut self, value: u64) -> roto_runtime::Result { + pub fn deprecated(mut self, value: u64) -> crate::runtime::Result { self.builder.write_varint(33, value)?; self.deprecated_written = true; Ok(self) } - pub fn uninterpreted_option(mut self, value: &[u8]) -> roto_runtime::Result { + pub fn uninterpreted_option(mut self, value: &[u8]) -> crate::runtime::Result { self.builder.write_bytes(999, value)?; self.uninterpreted_option_written = true; Ok(self) } - pub fn with(mut self, msg: &ServiceOptions<'_>) -> roto_runtime::Result { + pub fn with(mut self, msg: &ServiceOptions<'_>) -> crate::runtime::Result { for item in msg.raw_fields() { let (field_number, raw_bytes) = item?; let is_written = match field_number { @@ -5348,7 +5348,7 @@ impl<'b> ServiceOptionsBuilder<'b> { Ok(self) } - pub fn finish(self) -> roto_runtime::Result<&'b mut [u8]> { + pub fn finish(self) -> crate::runtime::Result<&'b mut [u8]> { self.builder.finish() } } @@ -5357,15 +5357,15 @@ pub struct OwnedServiceOptions { pub data: bytes::Bytes, } -impl roto_runtime::RotoOwned for OwnedServiceOptions { +impl crate::runtime::RotoOwned for OwnedServiceOptions { type Reader<'a> = ServiceOptions<'a>; fn reader(&self) -> ServiceOptions<'_> { ServiceOptions::new(&self.data).expect("failed to create reader") } } -impl roto_runtime::RotoMessage for OwnedServiceOptions { - fn decode(buf: bytes::Bytes) -> roto_runtime::Result { +impl crate::runtime::RotoMessage for OwnedServiceOptions { + fn decode(buf: bytes::Bytes) -> crate::runtime::Result { Ok(OwnedServiceOptions { data: buf }) } @@ -5375,7 +5375,7 @@ impl roto_runtime::RotoMessage for OwnedServiceOptions { } pub struct MethodOptions<'a> { - accessor: roto_runtime::ProtoAccessor<'a>, + accessor: crate::runtime::ProtoAccessor<'a>, deprecated_offset: Option, idempotency_level_offset: Option, features_offset: Option, @@ -5384,8 +5384,8 @@ pub struct MethodOptions<'a> { } impl<'a> MethodOptions<'a> { - pub fn new(data: &'a [u8]) -> roto_runtime::Result { - let accessor = roto_runtime::ProtoAccessor::new(data)?; + pub fn new(data: &'a [u8]) -> crate::runtime::Result { + let accessor = crate::runtime::ProtoAccessor::new(data)?; let mut deprecated_offset = None; let mut idempotency_level_offset = None; let mut features_offset = None; @@ -5411,57 +5411,57 @@ uninterpreted_option_start, uninterpreted_option_end, }) } - pub fn deprecated(&self) -> roto_runtime::Result { - let offset = self.deprecated_offset.ok_or(roto_runtime::RotoError::FieldNotFound)?; + pub fn deprecated(&self) -> crate::runtime::Result { + let offset = self.deprecated_offset.ok_or(crate::runtime::RotoError::FieldNotFound)?; let (bytes, _) = self.accessor.get_value_at(offset)?; - roto_runtime::read_varint(bytes).map(|(v, _)| v != 0).map_err(|_| roto_runtime::RotoError::WireFormatViolation) + crate::runtime::read_varint(bytes).map(|(v, _)| v != 0).map_err(|_| crate::runtime::RotoError::WireFormatViolation) } - pub fn deprecated_or_default(&self) -> roto_runtime::Result { + pub fn deprecated_or_default(&self) -> crate::runtime::Result { self.deprecated().or(Ok(false)) } pub fn has_deprecated(&self) -> bool { self.deprecated_offset.is_some() } - pub fn idempotency_level(&self) -> roto_runtime::Result { - let offset = self.idempotency_level_offset.ok_or(roto_runtime::RotoError::FieldNotFound)?; + pub fn idempotency_level(&self) -> crate::runtime::Result { + let offset = self.idempotency_level_offset.ok_or(crate::runtime::RotoError::FieldNotFound)?; let (bytes, _) = self.accessor.get_value_at(offset)?; - roto_runtime::read_varint(bytes).map(|(v, _)| v as u64).map_err(|_| roto_runtime::RotoError::WireFormatViolation) + crate::runtime::read_varint(bytes).map(|(v, _)| v as u64).map_err(|_| crate::runtime::RotoError::WireFormatViolation) } - pub fn idempotency_level_or_default(&self) -> roto_runtime::Result { + pub fn idempotency_level_or_default(&self) -> crate::runtime::Result { self.idempotency_level().or(Ok(0)) } pub fn has_idempotency_level(&self) -> bool { self.idempotency_level_offset.is_some() } - pub fn features(&self) -> roto_runtime::Result<&'a [u8]> { - let offset = self.features_offset.ok_or(roto_runtime::RotoError::FieldNotFound)?; + pub fn features(&self) -> crate::runtime::Result<&'a [u8]> { + let offset = self.features_offset.ok_or(crate::runtime::RotoError::FieldNotFound)?; let (bytes, _) = self.accessor.get_value_at(offset)?; Ok(bytes) } - pub fn features_or_default(&self) -> roto_runtime::Result<&'a [u8]> { + pub fn features_or_default(&self) -> crate::runtime::Result<&'a [u8]> { self.features().or(Ok(&[])) } pub fn has_features(&self) -> bool { self.features_offset.is_some() } - pub fn uninterpreted_option(&self) -> roto_runtime::RepeatedFieldIterator<'a> { + pub fn uninterpreted_option(&self) -> crate::runtime::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 raw_fields(&self) -> roto_runtime::RawFieldIterator<'a> { + pub fn raw_fields(&self) -> crate::runtime::RawFieldIterator<'a> { self.accessor.raw_fields() } } pub struct MethodOptionsBuilder<'b> { - builder: roto_runtime::ProtoBuilder<'b>, + builder: crate::runtime::ProtoBuilder<'b>, deprecated_written: bool, idempotency_level_written: bool, features_written: bool, @@ -5471,7 +5471,7 @@ pub struct MethodOptionsBuilder<'b> { impl<'b> MethodOptionsBuilder<'b> { pub fn builder(buf: &mut [u8]) -> MethodOptionsBuilder<'_> { MethodOptionsBuilder { - builder: roto_runtime::ProtoBuilder::new(buf), + builder: crate::runtime::ProtoBuilder::new(buf), deprecated_written: false, idempotency_level_written: false, features_written: false, @@ -5479,31 +5479,31 @@ impl<'b> MethodOptionsBuilder<'b> { } } - pub fn deprecated(mut self, value: u64) -> roto_runtime::Result { + pub fn deprecated(mut self, value: u64) -> crate::runtime::Result { self.builder.write_varint(33, value)?; self.deprecated_written = true; Ok(self) } - pub fn idempotency_level(mut self, value: u64) -> roto_runtime::Result { + pub fn idempotency_level(mut self, value: u64) -> crate::runtime::Result { self.builder.write_varint(34, value)?; self.idempotency_level_written = true; Ok(self) } - pub fn features(mut self, value: &[u8]) -> roto_runtime::Result { + pub fn features(mut self, value: &[u8]) -> crate::runtime::Result { self.builder.write_bytes(35, value)?; self.features_written = true; Ok(self) } - pub fn uninterpreted_option(mut self, value: &[u8]) -> roto_runtime::Result { + pub fn uninterpreted_option(mut self, value: &[u8]) -> crate::runtime::Result { self.builder.write_bytes(999, value)?; self.uninterpreted_option_written = true; Ok(self) } - pub fn with(mut self, msg: &MethodOptions<'_>) -> roto_runtime::Result { + pub fn with(mut self, msg: &MethodOptions<'_>) -> crate::runtime::Result { for item in msg.raw_fields() { let (field_number, raw_bytes) = item?; let is_written = match field_number { @@ -5520,7 +5520,7 @@ impl<'b> MethodOptionsBuilder<'b> { Ok(self) } - pub fn finish(self) -> roto_runtime::Result<&'b mut [u8]> { + pub fn finish(self) -> crate::runtime::Result<&'b mut [u8]> { self.builder.finish() } } @@ -5529,15 +5529,15 @@ pub struct OwnedMethodOptions { pub data: bytes::Bytes, } -impl roto_runtime::RotoOwned for OwnedMethodOptions { +impl crate::runtime::RotoOwned for OwnedMethodOptions { type Reader<'a> = MethodOptions<'a>; fn reader(&self) -> MethodOptions<'_> { MethodOptions::new(&self.data).expect("failed to create reader") } } -impl roto_runtime::RotoMessage for OwnedMethodOptions { - fn decode(buf: bytes::Bytes) -> roto_runtime::Result { +impl crate::runtime::RotoMessage for OwnedMethodOptions { + fn decode(buf: bytes::Bytes) -> crate::runtime::Result { Ok(OwnedMethodOptions { data: buf }) } @@ -5569,7 +5569,7 @@ impl IdempotencyLevel { } pub struct UninterpretedOption<'a> { - accessor: roto_runtime::ProtoAccessor<'a>, + accessor: crate::runtime::ProtoAccessor<'a>, name_start: Option, name_end: Option, identifier_value_offset: Option, @@ -5581,8 +5581,8 @@ pub struct UninterpretedOption<'a> { } impl<'a> UninterpretedOption<'a> { - pub fn new(data: &'a [u8]) -> roto_runtime::Result { - let accessor = roto_runtime::ProtoAccessor::new(data)?; + pub fn new(data: &'a [u8]) -> crate::runtime::Result { + let accessor = crate::runtime::ProtoAccessor::new(data)?; let mut name_start = None; let mut name_end = None; let mut identifier_value_offset = None; @@ -5617,93 +5617,93 @@ aggregate_value_offset, }) } - pub fn name(&self) -> roto_runtime::RepeatedFieldIterator<'a> { + pub fn name(&self) -> crate::runtime::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) -> roto_runtime::Result<&'a str> { - let offset = self.identifier_value_offset.ok_or(roto_runtime::RotoError::FieldNotFound)?; + pub fn identifier_value(&self) -> crate::runtime::Result<&'a str> { + let offset = self.identifier_value_offset.ok_or(crate::runtime::RotoError::FieldNotFound)?; let (bytes, _) = self.accessor.get_value_at(offset)?; - str::from_utf8(bytes).map_err(|_| roto_runtime::RotoError::WireFormatViolation) + str::from_utf8(bytes).map_err(|_| crate::runtime::RotoError::WireFormatViolation) } - pub fn identifier_value_or_default(&self) -> roto_runtime::Result<&'a str> { + pub fn identifier_value_or_default(&self) -> crate::runtime::Result<&'a str> { self.identifier_value().or(Ok("")) } pub fn has_identifier_value(&self) -> bool { self.identifier_value_offset.is_some() } - pub fn positive_int_value(&self) -> roto_runtime::Result { - let offset = self.positive_int_value_offset.ok_or(roto_runtime::RotoError::FieldNotFound)?; + pub fn positive_int_value(&self) -> crate::runtime::Result { + let offset = self.positive_int_value_offset.ok_or(crate::runtime::RotoError::FieldNotFound)?; let (bytes, _) = self.accessor.get_value_at(offset)?; - roto_runtime::read_varint(bytes).map(|(v, _)| v as u32).map_err(|_| roto_runtime::RotoError::WireFormatViolation) + crate::runtime::read_varint(bytes).map(|(v, _)| v as u32).map_err(|_| crate::runtime::RotoError::WireFormatViolation) } - pub fn positive_int_value_or_default(&self) -> roto_runtime::Result { + pub fn positive_int_value_or_default(&self) -> crate::runtime::Result { self.positive_int_value().or(Ok(0)) } pub fn has_positive_int_value(&self) -> bool { self.positive_int_value_offset.is_some() } - pub fn negative_int_value(&self) -> roto_runtime::Result { - let offset = self.negative_int_value_offset.ok_or(roto_runtime::RotoError::FieldNotFound)?; + pub fn negative_int_value(&self) -> crate::runtime::Result { + let offset = self.negative_int_value_offset.ok_or(crate::runtime::RotoError::FieldNotFound)?; let (bytes, _) = self.accessor.get_value_at(offset)?; - roto_runtime::read_varint(bytes).map(|(v, _)| v as i32).map_err(|_| roto_runtime::RotoError::WireFormatViolation) + crate::runtime::read_varint(bytes).map(|(v, _)| v as i32).map_err(|_| crate::runtime::RotoError::WireFormatViolation) } - pub fn negative_int_value_or_default(&self) -> roto_runtime::Result { + pub fn negative_int_value_or_default(&self) -> crate::runtime::Result { self.negative_int_value().or(Ok(0)) } pub fn has_negative_int_value(&self) -> bool { self.negative_int_value_offset.is_some() } - pub fn double_value(&self) -> roto_runtime::Result { - let offset = self.double_value_offset.ok_or(roto_runtime::RotoError::FieldNotFound)?; + pub fn double_value(&self) -> crate::runtime::Result { + let offset = self.double_value_offset.ok_or(crate::runtime::RotoError::FieldNotFound)?; let (bytes, _) = self.accessor.get_value_at(offset)?; - Ok(f64::from_le_bytes(bytes.try_into().map_err(|_| roto_runtime::RotoError::WireFormatViolation)?)) + Ok(f64::from_le_bytes(bytes.try_into().map_err(|_| crate::runtime::RotoError::WireFormatViolation)?)) } - pub fn double_value_or_default(&self) -> roto_runtime::Result { + pub fn double_value_or_default(&self) -> crate::runtime::Result { self.double_value().or(Ok(0.0)) } pub fn has_double_value(&self) -> bool { self.double_value_offset.is_some() } - pub fn string_value(&self) -> roto_runtime::Result<&'a [u8]> { - let offset = self.string_value_offset.ok_or(roto_runtime::RotoError::FieldNotFound)?; + pub fn string_value(&self) -> crate::runtime::Result<&'a [u8]> { + let offset = self.string_value_offset.ok_or(crate::runtime::RotoError::FieldNotFound)?; let (bytes, _) = self.accessor.get_value_at(offset)?; Ok(bytes) } - pub fn string_value_or_default(&self) -> roto_runtime::Result<&'a [u8]> { + pub fn string_value_or_default(&self) -> crate::runtime::Result<&'a [u8]> { self.string_value().or(Ok(&[])) } pub fn has_string_value(&self) -> bool { self.string_value_offset.is_some() } - pub fn aggregate_value(&self) -> roto_runtime::Result<&'a str> { - let offset = self.aggregate_value_offset.ok_or(roto_runtime::RotoError::FieldNotFound)?; + pub fn aggregate_value(&self) -> crate::runtime::Result<&'a str> { + let offset = self.aggregate_value_offset.ok_or(crate::runtime::RotoError::FieldNotFound)?; let (bytes, _) = self.accessor.get_value_at(offset)?; - str::from_utf8(bytes).map_err(|_| roto_runtime::RotoError::WireFormatViolation) + str::from_utf8(bytes).map_err(|_| crate::runtime::RotoError::WireFormatViolation) } - pub fn aggregate_value_or_default(&self) -> roto_runtime::Result<&'a str> { + pub fn aggregate_value_or_default(&self) -> crate::runtime::Result<&'a str> { self.aggregate_value().or(Ok("")) } pub fn has_aggregate_value(&self) -> bool { self.aggregate_value_offset.is_some() } - pub fn raw_fields(&self) -> roto_runtime::RawFieldIterator<'a> { + pub fn raw_fields(&self) -> crate::runtime::RawFieldIterator<'a> { self.accessor.raw_fields() } } pub struct UninterpretedOptionBuilder<'b> { - builder: roto_runtime::ProtoBuilder<'b>, + builder: crate::runtime::ProtoBuilder<'b>, name_written: bool, identifier_value_written: bool, positive_int_value_written: bool, @@ -5716,7 +5716,7 @@ pub struct UninterpretedOptionBuilder<'b> { impl<'b> UninterpretedOptionBuilder<'b> { pub fn builder(buf: &mut [u8]) -> UninterpretedOptionBuilder<'_> { UninterpretedOptionBuilder { - builder: roto_runtime::ProtoBuilder::new(buf), + builder: crate::runtime::ProtoBuilder::new(buf), name_written: false, identifier_value_written: false, positive_int_value_written: false, @@ -5727,49 +5727,49 @@ impl<'b> UninterpretedOptionBuilder<'b> { } } - pub fn name(mut self, value: &[u8]) -> roto_runtime::Result { + pub fn name(mut self, value: &[u8]) -> crate::runtime::Result { self.builder.write_bytes(2, value)?; self.name_written = true; Ok(self) } - pub fn identifier_value(mut self, value: &str) -> roto_runtime::Result { + pub fn identifier_value(mut self, value: &str) -> crate::runtime::Result { self.builder.write_string(3, value)?; self.identifier_value_written = true; Ok(self) } - pub fn positive_int_value(mut self, value: u64) -> roto_runtime::Result { + pub fn positive_int_value(mut self, value: u64) -> crate::runtime::Result { self.builder.write_varint(4, value)?; self.positive_int_value_written = true; Ok(self) } - pub fn negative_int_value(mut self, value: u64) -> roto_runtime::Result { + pub fn negative_int_value(mut self, value: u64) -> crate::runtime::Result { self.builder.write_varint(5, value)?; self.negative_int_value_written = true; Ok(self) } - pub fn double_value(mut self, value: &[u8]) -> roto_runtime::Result { + pub fn double_value(mut self, value: &[u8]) -> crate::runtime::Result { self.builder.write_bytes(6, value)?; self.double_value_written = true; Ok(self) } - pub fn string_value(mut self, value: &[u8]) -> roto_runtime::Result { + pub fn string_value(mut self, value: &[u8]) -> crate::runtime::Result { self.builder.write_bytes(7, value)?; self.string_value_written = true; Ok(self) } - pub fn aggregate_value(mut self, value: &str) -> roto_runtime::Result { + pub fn aggregate_value(mut self, value: &str) -> crate::runtime::Result { self.builder.write_string(8, value)?; self.aggregate_value_written = true; Ok(self) } - pub fn with(mut self, msg: &UninterpretedOption<'_>) -> roto_runtime::Result { + pub fn with(mut self, msg: &UninterpretedOption<'_>) -> crate::runtime::Result { for item in msg.raw_fields() { let (field_number, raw_bytes) = item?; let is_written = match field_number { @@ -5789,7 +5789,7 @@ impl<'b> UninterpretedOptionBuilder<'b> { Ok(self) } - pub fn finish(self) -> roto_runtime::Result<&'b mut [u8]> { + pub fn finish(self) -> crate::runtime::Result<&'b mut [u8]> { self.builder.finish() } } @@ -5798,15 +5798,15 @@ pub struct OwnedUninterpretedOption { pub data: bytes::Bytes, } -impl roto_runtime::RotoOwned for OwnedUninterpretedOption { +impl crate::runtime::RotoOwned for OwnedUninterpretedOption { type Reader<'a> = UninterpretedOption<'a>; fn reader(&self) -> UninterpretedOption<'_> { UninterpretedOption::new(&self.data).expect("failed to create reader") } } -impl roto_runtime::RotoMessage for OwnedUninterpretedOption { - fn decode(buf: bytes::Bytes) -> roto_runtime::Result { +impl crate::runtime::RotoMessage for OwnedUninterpretedOption { + fn decode(buf: bytes::Bytes) -> crate::runtime::Result { Ok(OwnedUninterpretedOption { data: buf }) } @@ -5817,14 +5817,14 @@ impl roto_runtime::RotoMessage for OwnedUninterpretedOption { pub mod uninterpreted_option { pub struct NamePart<'a> { - accessor: roto_runtime::ProtoAccessor<'a>, + accessor: crate::runtime::ProtoAccessor<'a>, name_part_offset: Option, is_extension_offset: Option, } impl<'a> NamePart<'a> { - pub fn new(data: &'a [u8]) -> roto_runtime::Result { - let accessor = roto_runtime::ProtoAccessor::new(data)?; + pub fn new(data: &'a [u8]) -> crate::runtime::Result { + let accessor = crate::runtime::ProtoAccessor::new(data)?; let mut name_part_offset = None; let mut is_extension_offset = None; for item in accessor.fields() { @@ -5840,38 +5840,38 @@ is_extension_offset, }) } - pub fn name_part(&self) -> roto_runtime::Result<&'a str> { - let offset = self.name_part_offset.ok_or(roto_runtime::RotoError::FieldNotFound)?; + pub fn name_part(&self) -> crate::runtime::Result<&'a str> { + let offset = self.name_part_offset.ok_or(crate::runtime::RotoError::FieldNotFound)?; let (bytes, _) = self.accessor.get_value_at(offset)?; - str::from_utf8(bytes).map_err(|_| roto_runtime::RotoError::WireFormatViolation) + str::from_utf8(bytes).map_err(|_| crate::runtime::RotoError::WireFormatViolation) } - pub fn name_part_or_default(&self) -> roto_runtime::Result<&'a str> { + pub fn name_part_or_default(&self) -> crate::runtime::Result<&'a str> { self.name_part().or(Ok("")) } pub fn has_name_part(&self) -> bool { self.name_part_offset.is_some() } - pub fn is_extension(&self) -> roto_runtime::Result { - let offset = self.is_extension_offset.ok_or(roto_runtime::RotoError::FieldNotFound)?; + pub fn is_extension(&self) -> crate::runtime::Result { + let offset = self.is_extension_offset.ok_or(crate::runtime::RotoError::FieldNotFound)?; let (bytes, _) = self.accessor.get_value_at(offset)?; - roto_runtime::read_varint(bytes).map(|(v, _)| v != 0).map_err(|_| roto_runtime::RotoError::WireFormatViolation) + crate::runtime::read_varint(bytes).map(|(v, _)| v != 0).map_err(|_| crate::runtime::RotoError::WireFormatViolation) } - pub fn is_extension_or_default(&self) -> roto_runtime::Result { + pub fn is_extension_or_default(&self) -> crate::runtime::Result { self.is_extension().or(Ok(false)) } pub fn has_is_extension(&self) -> bool { self.is_extension_offset.is_some() } - pub fn raw_fields(&self) -> roto_runtime::RawFieldIterator<'a> { + pub fn raw_fields(&self) -> crate::runtime::RawFieldIterator<'a> { self.accessor.raw_fields() } } pub struct NamePartBuilder<'b> { - builder: roto_runtime::ProtoBuilder<'b>, + builder: crate::runtime::ProtoBuilder<'b>, name_part_written: bool, is_extension_written: bool, } @@ -5879,25 +5879,25 @@ pub struct NamePartBuilder<'b> { impl<'b> NamePartBuilder<'b> { pub fn builder(buf: &mut [u8]) -> NamePartBuilder<'_> { NamePartBuilder { - builder: roto_runtime::ProtoBuilder::new(buf), + builder: crate::runtime::ProtoBuilder::new(buf), name_part_written: false, is_extension_written: false, } } - pub fn name_part(mut self, value: &str) -> roto_runtime::Result { + pub fn name_part(mut self, value: &str) -> crate::runtime::Result { self.builder.write_string(1, value)?; self.name_part_written = true; Ok(self) } - pub fn is_extension(mut self, value: u64) -> roto_runtime::Result { + pub fn is_extension(mut self, value: u64) -> crate::runtime::Result { self.builder.write_varint(2, value)?; self.is_extension_written = true; Ok(self) } - pub fn with(mut self, msg: &NamePart<'_>) -> roto_runtime::Result { + pub fn with(mut self, msg: &NamePart<'_>) -> crate::runtime::Result { for item in msg.raw_fields() { let (field_number, raw_bytes) = item?; let is_written = match field_number { @@ -5912,7 +5912,7 @@ impl<'b> NamePartBuilder<'b> { Ok(self) } - pub fn finish(self) -> roto_runtime::Result<&'b mut [u8]> { + pub fn finish(self) -> crate::runtime::Result<&'b mut [u8]> { self.builder.finish() } } @@ -5921,15 +5921,15 @@ pub struct OwnedNamePart { pub data: bytes::Bytes, } -impl roto_runtime::RotoOwned for OwnedNamePart { +impl crate::runtime::RotoOwned for OwnedNamePart { type Reader<'a> = NamePart<'a>; fn reader(&self) -> NamePart<'_> { NamePart::new(&self.data).expect("failed to create reader") } } -impl roto_runtime::RotoMessage for OwnedNamePart { - fn decode(buf: bytes::Bytes) -> roto_runtime::Result { +impl crate::runtime::RotoMessage for OwnedNamePart { + fn decode(buf: bytes::Bytes) -> crate::runtime::Result { Ok(OwnedNamePart { data: buf }) } @@ -5941,7 +5941,7 @@ impl roto_runtime::RotoMessage for OwnedNamePart { } pub struct FeatureSet<'a> { - accessor: roto_runtime::ProtoAccessor<'a>, + accessor: crate::runtime::ProtoAccessor<'a>, field_presence_offset: Option, enum_type_offset: Option, repeated_field_encoding_offset: Option, @@ -5954,8 +5954,8 @@ pub struct FeatureSet<'a> { } impl<'a> FeatureSet<'a> { - pub fn new(data: &'a [u8]) -> roto_runtime::Result { - let accessor = roto_runtime::ProtoAccessor::new(data)?; + pub fn new(data: &'a [u8]) -> crate::runtime::Result { + let accessor = crate::runtime::ProtoAccessor::new(data)?; let mut field_presence_offset = None; let mut enum_type_offset = None; let mut repeated_field_encoding_offset = None; @@ -5992,122 +5992,122 @@ enforce_proto_limits_offset, }) } - pub fn field_presence(&self) -> roto_runtime::Result { - let offset = self.field_presence_offset.ok_or(roto_runtime::RotoError::FieldNotFound)?; + pub fn field_presence(&self) -> crate::runtime::Result { + let offset = self.field_presence_offset.ok_or(crate::runtime::RotoError::FieldNotFound)?; let (bytes, _) = self.accessor.get_value_at(offset)?; - roto_runtime::read_varint(bytes).map(|(v, _)| v as u64).map_err(|_| roto_runtime::RotoError::WireFormatViolation) + crate::runtime::read_varint(bytes).map(|(v, _)| v as u64).map_err(|_| crate::runtime::RotoError::WireFormatViolation) } - pub fn field_presence_or_default(&self) -> roto_runtime::Result { + pub fn field_presence_or_default(&self) -> crate::runtime::Result { self.field_presence().or(Ok(0)) } pub fn has_field_presence(&self) -> bool { self.field_presence_offset.is_some() } - pub fn enum_type(&self) -> roto_runtime::Result { - let offset = self.enum_type_offset.ok_or(roto_runtime::RotoError::FieldNotFound)?; + pub fn enum_type(&self) -> crate::runtime::Result { + let offset = self.enum_type_offset.ok_or(crate::runtime::RotoError::FieldNotFound)?; let (bytes, _) = self.accessor.get_value_at(offset)?; - roto_runtime::read_varint(bytes).map(|(v, _)| v as u64).map_err(|_| roto_runtime::RotoError::WireFormatViolation) + crate::runtime::read_varint(bytes).map(|(v, _)| v as u64).map_err(|_| crate::runtime::RotoError::WireFormatViolation) } - pub fn enum_type_or_default(&self) -> roto_runtime::Result { + pub fn enum_type_or_default(&self) -> crate::runtime::Result { self.enum_type().or(Ok(0)) } pub fn has_enum_type(&self) -> bool { self.enum_type_offset.is_some() } - pub fn repeated_field_encoding(&self) -> roto_runtime::Result { - let offset = self.repeated_field_encoding_offset.ok_or(roto_runtime::RotoError::FieldNotFound)?; + pub fn repeated_field_encoding(&self) -> crate::runtime::Result { + let offset = self.repeated_field_encoding_offset.ok_or(crate::runtime::RotoError::FieldNotFound)?; let (bytes, _) = self.accessor.get_value_at(offset)?; - roto_runtime::read_varint(bytes).map(|(v, _)| v as u64).map_err(|_| roto_runtime::RotoError::WireFormatViolation) + crate::runtime::read_varint(bytes).map(|(v, _)| v as u64).map_err(|_| crate::runtime::RotoError::WireFormatViolation) } - pub fn repeated_field_encoding_or_default(&self) -> roto_runtime::Result { + pub fn repeated_field_encoding_or_default(&self) -> crate::runtime::Result { self.repeated_field_encoding().or(Ok(0)) } pub fn has_repeated_field_encoding(&self) -> bool { self.repeated_field_encoding_offset.is_some() } - pub fn utf8_validation(&self) -> roto_runtime::Result { - let offset = self.utf8_validation_offset.ok_or(roto_runtime::RotoError::FieldNotFound)?; + pub fn utf8_validation(&self) -> crate::runtime::Result { + let offset = self.utf8_validation_offset.ok_or(crate::runtime::RotoError::FieldNotFound)?; let (bytes, _) = self.accessor.get_value_at(offset)?; - roto_runtime::read_varint(bytes).map(|(v, _)| v as u64).map_err(|_| roto_runtime::RotoError::WireFormatViolation) + crate::runtime::read_varint(bytes).map(|(v, _)| v as u64).map_err(|_| crate::runtime::RotoError::WireFormatViolation) } - pub fn utf8_validation_or_default(&self) -> roto_runtime::Result { + pub fn utf8_validation_or_default(&self) -> crate::runtime::Result { self.utf8_validation().or(Ok(0)) } pub fn has_utf8_validation(&self) -> bool { self.utf8_validation_offset.is_some() } - pub fn message_encoding(&self) -> roto_runtime::Result { - let offset = self.message_encoding_offset.ok_or(roto_runtime::RotoError::FieldNotFound)?; + pub fn message_encoding(&self) -> crate::runtime::Result { + let offset = self.message_encoding_offset.ok_or(crate::runtime::RotoError::FieldNotFound)?; let (bytes, _) = self.accessor.get_value_at(offset)?; - roto_runtime::read_varint(bytes).map(|(v, _)| v as u64).map_err(|_| roto_runtime::RotoError::WireFormatViolation) + crate::runtime::read_varint(bytes).map(|(v, _)| v as u64).map_err(|_| crate::runtime::RotoError::WireFormatViolation) } - pub fn message_encoding_or_default(&self) -> roto_runtime::Result { + pub fn message_encoding_or_default(&self) -> crate::runtime::Result { self.message_encoding().or(Ok(0)) } pub fn has_message_encoding(&self) -> bool { self.message_encoding_offset.is_some() } - pub fn json_format(&self) -> roto_runtime::Result { - let offset = self.json_format_offset.ok_or(roto_runtime::RotoError::FieldNotFound)?; + pub fn json_format(&self) -> crate::runtime::Result { + let offset = self.json_format_offset.ok_or(crate::runtime::RotoError::FieldNotFound)?; let (bytes, _) = self.accessor.get_value_at(offset)?; - roto_runtime::read_varint(bytes).map(|(v, _)| v as u64).map_err(|_| roto_runtime::RotoError::WireFormatViolation) + crate::runtime::read_varint(bytes).map(|(v, _)| v as u64).map_err(|_| crate::runtime::RotoError::WireFormatViolation) } - pub fn json_format_or_default(&self) -> roto_runtime::Result { + pub fn json_format_or_default(&self) -> crate::runtime::Result { self.json_format().or(Ok(0)) } pub fn has_json_format(&self) -> bool { self.json_format_offset.is_some() } - pub fn enforce_naming_style(&self) -> roto_runtime::Result { - let offset = self.enforce_naming_style_offset.ok_or(roto_runtime::RotoError::FieldNotFound)?; + pub fn enforce_naming_style(&self) -> crate::runtime::Result { + let offset = self.enforce_naming_style_offset.ok_or(crate::runtime::RotoError::FieldNotFound)?; let (bytes, _) = self.accessor.get_value_at(offset)?; - roto_runtime::read_varint(bytes).map(|(v, _)| v as u64).map_err(|_| roto_runtime::RotoError::WireFormatViolation) + crate::runtime::read_varint(bytes).map(|(v, _)| v as u64).map_err(|_| crate::runtime::RotoError::WireFormatViolation) } - pub fn enforce_naming_style_or_default(&self) -> roto_runtime::Result { + pub fn enforce_naming_style_or_default(&self) -> crate::runtime::Result { self.enforce_naming_style().or(Ok(0)) } pub fn has_enforce_naming_style(&self) -> bool { self.enforce_naming_style_offset.is_some() } - pub fn default_symbol_visibility(&self) -> roto_runtime::Result { - let offset = self.default_symbol_visibility_offset.ok_or(roto_runtime::RotoError::FieldNotFound)?; + pub fn default_symbol_visibility(&self) -> crate::runtime::Result { + let offset = self.default_symbol_visibility_offset.ok_or(crate::runtime::RotoError::FieldNotFound)?; let (bytes, _) = self.accessor.get_value_at(offset)?; - roto_runtime::read_varint(bytes).map(|(v, _)| v as u64).map_err(|_| roto_runtime::RotoError::WireFormatViolation) + crate::runtime::read_varint(bytes).map(|(v, _)| v as u64).map_err(|_| crate::runtime::RotoError::WireFormatViolation) } - pub fn default_symbol_visibility_or_default(&self) -> roto_runtime::Result { + pub fn default_symbol_visibility_or_default(&self) -> crate::runtime::Result { self.default_symbol_visibility().or(Ok(0)) } pub fn has_default_symbol_visibility(&self) -> bool { self.default_symbol_visibility_offset.is_some() } - pub fn enforce_proto_limits(&self) -> roto_runtime::Result { - let offset = self.enforce_proto_limits_offset.ok_or(roto_runtime::RotoError::FieldNotFound)?; + pub fn enforce_proto_limits(&self) -> crate::runtime::Result { + let offset = self.enforce_proto_limits_offset.ok_or(crate::runtime::RotoError::FieldNotFound)?; let (bytes, _) = self.accessor.get_value_at(offset)?; - roto_runtime::read_varint(bytes).map(|(v, _)| v as u64).map_err(|_| roto_runtime::RotoError::WireFormatViolation) + crate::runtime::read_varint(bytes).map(|(v, _)| v as u64).map_err(|_| crate::runtime::RotoError::WireFormatViolation) } - pub fn enforce_proto_limits_or_default(&self) -> roto_runtime::Result { + pub fn enforce_proto_limits_or_default(&self) -> crate::runtime::Result { self.enforce_proto_limits().or(Ok(0)) } pub fn has_enforce_proto_limits(&self) -> bool { self.enforce_proto_limits_offset.is_some() } - pub fn raw_fields(&self) -> roto_runtime::RawFieldIterator<'a> { + pub fn raw_fields(&self) -> crate::runtime::RawFieldIterator<'a> { self.accessor.raw_fields() } } pub struct FeatureSetBuilder<'b> { - builder: roto_runtime::ProtoBuilder<'b>, + builder: crate::runtime::ProtoBuilder<'b>, field_presence_written: bool, enum_type_written: bool, repeated_field_encoding_written: bool, @@ -6122,7 +6122,7 @@ pub struct FeatureSetBuilder<'b> { impl<'b> FeatureSetBuilder<'b> { pub fn builder(buf: &mut [u8]) -> FeatureSetBuilder<'_> { FeatureSetBuilder { - builder: roto_runtime::ProtoBuilder::new(buf), + builder: crate::runtime::ProtoBuilder::new(buf), field_presence_written: false, enum_type_written: false, repeated_field_encoding_written: false, @@ -6135,61 +6135,61 @@ impl<'b> FeatureSetBuilder<'b> { } } - pub fn field_presence(mut self, value: u64) -> roto_runtime::Result { + pub fn field_presence(mut self, value: u64) -> crate::runtime::Result { self.builder.write_varint(1, value)?; self.field_presence_written = true; Ok(self) } - pub fn enum_type(mut self, value: u64) -> roto_runtime::Result { + pub fn enum_type(mut self, value: u64) -> crate::runtime::Result { self.builder.write_varint(2, value)?; self.enum_type_written = true; Ok(self) } - pub fn repeated_field_encoding(mut self, value: u64) -> roto_runtime::Result { + pub fn repeated_field_encoding(mut self, value: u64) -> crate::runtime::Result { self.builder.write_varint(3, value)?; self.repeated_field_encoding_written = true; Ok(self) } - pub fn utf8_validation(mut self, value: u64) -> roto_runtime::Result { + pub fn utf8_validation(mut self, value: u64) -> crate::runtime::Result { self.builder.write_varint(4, value)?; self.utf8_validation_written = true; Ok(self) } - pub fn message_encoding(mut self, value: u64) -> roto_runtime::Result { + pub fn message_encoding(mut self, value: u64) -> crate::runtime::Result { self.builder.write_varint(5, value)?; self.message_encoding_written = true; Ok(self) } - pub fn json_format(mut self, value: u64) -> roto_runtime::Result { + pub fn json_format(mut self, value: u64) -> crate::runtime::Result { self.builder.write_varint(6, value)?; self.json_format_written = true; Ok(self) } - pub fn enforce_naming_style(mut self, value: u64) -> roto_runtime::Result { + pub fn enforce_naming_style(mut self, value: u64) -> crate::runtime::Result { self.builder.write_varint(7, value)?; self.enforce_naming_style_written = true; Ok(self) } - pub fn default_symbol_visibility(mut self, value: u64) -> roto_runtime::Result { + pub fn default_symbol_visibility(mut self, value: u64) -> crate::runtime::Result { self.builder.write_varint(8, value)?; self.default_symbol_visibility_written = true; Ok(self) } - pub fn enforce_proto_limits(mut self, value: u64) -> roto_runtime::Result { + pub fn enforce_proto_limits(mut self, value: u64) -> crate::runtime::Result { self.builder.write_varint(9, value)?; self.enforce_proto_limits_written = true; Ok(self) } - pub fn with(mut self, msg: &FeatureSet<'_>) -> roto_runtime::Result { + pub fn with(mut self, msg: &FeatureSet<'_>) -> crate::runtime::Result { for item in msg.raw_fields() { let (field_number, raw_bytes) = item?; let is_written = match field_number { @@ -6211,7 +6211,7 @@ impl<'b> FeatureSetBuilder<'b> { Ok(self) } - pub fn finish(self) -> roto_runtime::Result<&'b mut [u8]> { + pub fn finish(self) -> crate::runtime::Result<&'b mut [u8]> { self.builder.finish() } } @@ -6220,15 +6220,15 @@ pub struct OwnedFeatureSet { pub data: bytes::Bytes, } -impl roto_runtime::RotoOwned for OwnedFeatureSet { +impl crate::runtime::RotoOwned for OwnedFeatureSet { type Reader<'a> = FeatureSet<'a>; fn reader(&self) -> FeatureSet<'_> { FeatureSet::new(&self.data).expect("failed to create reader") } } -impl roto_runtime::RotoMessage for OwnedFeatureSet { - fn decode(buf: bytes::Bytes) -> roto_runtime::Result { +impl crate::runtime::RotoMessage for OwnedFeatureSet { + fn decode(buf: bytes::Bytes) -> crate::runtime::Result { Ok(OwnedFeatureSet { data: buf }) } @@ -6376,12 +6376,12 @@ impl EnforceNamingStyle { } pub struct VisibilityFeature<'a> { - accessor: roto_runtime::ProtoAccessor<'a>, + accessor: crate::runtime::ProtoAccessor<'a>, } impl<'a> VisibilityFeature<'a> { - pub fn new(data: &'a [u8]) -> roto_runtime::Result { - let accessor = roto_runtime::ProtoAccessor::new(data)?; + pub fn new(data: &'a [u8]) -> crate::runtime::Result { + let accessor = crate::runtime::ProtoAccessor::new(data)?; for item in accessor.fields() { let (offset, tag, _) = item?; } @@ -6391,24 +6391,24 @@ impl<'a> VisibilityFeature<'a> { }) } - pub fn raw_fields(&self) -> roto_runtime::RawFieldIterator<'a> { + pub fn raw_fields(&self) -> crate::runtime::RawFieldIterator<'a> { self.accessor.raw_fields() } } pub struct VisibilityFeatureBuilder<'b> { - builder: roto_runtime::ProtoBuilder<'b>, + builder: crate::runtime::ProtoBuilder<'b>, } impl<'b> VisibilityFeatureBuilder<'b> { pub fn builder(buf: &mut [u8]) -> VisibilityFeatureBuilder<'_> { VisibilityFeatureBuilder { - builder: roto_runtime::ProtoBuilder::new(buf), + builder: crate::runtime::ProtoBuilder::new(buf), } } - pub fn with(mut self, msg: &VisibilityFeature<'_>) -> roto_runtime::Result { + pub fn with(mut self, msg: &VisibilityFeature<'_>) -> crate::runtime::Result { for item in msg.raw_fields() { let (field_number, raw_bytes) = item?; let is_written = match field_number { @@ -6421,7 +6421,7 @@ impl<'b> VisibilityFeatureBuilder<'b> { Ok(self) } - pub fn finish(self) -> roto_runtime::Result<&'b mut [u8]> { + pub fn finish(self) -> crate::runtime::Result<&'b mut [u8]> { self.builder.finish() } } @@ -6430,15 +6430,15 @@ pub struct OwnedVisibilityFeature { pub data: bytes::Bytes, } -impl roto_runtime::RotoOwned for OwnedVisibilityFeature { +impl crate::runtime::RotoOwned for OwnedVisibilityFeature { type Reader<'a> = VisibilityFeature<'a>; fn reader(&self) -> VisibilityFeature<'_> { VisibilityFeature::new(&self.data).expect("failed to create reader") } } -impl roto_runtime::RotoMessage for OwnedVisibilityFeature { - fn decode(buf: bytes::Bytes) -> roto_runtime::Result { +impl crate::runtime::RotoMessage for OwnedVisibilityFeature { + fn decode(buf: bytes::Bytes) -> crate::runtime::Result { Ok(OwnedVisibilityFeature { data: buf }) } @@ -6474,12 +6474,12 @@ impl DefaultSymbolVisibility { } pub struct ProtoLimitsFeature<'a> { - accessor: roto_runtime::ProtoAccessor<'a>, + accessor: crate::runtime::ProtoAccessor<'a>, } impl<'a> ProtoLimitsFeature<'a> { - pub fn new(data: &'a [u8]) -> roto_runtime::Result { - let accessor = roto_runtime::ProtoAccessor::new(data)?; + pub fn new(data: &'a [u8]) -> crate::runtime::Result { + let accessor = crate::runtime::ProtoAccessor::new(data)?; for item in accessor.fields() { let (offset, tag, _) = item?; } @@ -6489,24 +6489,24 @@ impl<'a> ProtoLimitsFeature<'a> { }) } - pub fn raw_fields(&self) -> roto_runtime::RawFieldIterator<'a> { + pub fn raw_fields(&self) -> crate::runtime::RawFieldIterator<'a> { self.accessor.raw_fields() } } pub struct ProtoLimitsFeatureBuilder<'b> { - builder: roto_runtime::ProtoBuilder<'b>, + builder: crate::runtime::ProtoBuilder<'b>, } impl<'b> ProtoLimitsFeatureBuilder<'b> { pub fn builder(buf: &mut [u8]) -> ProtoLimitsFeatureBuilder<'_> { ProtoLimitsFeatureBuilder { - builder: roto_runtime::ProtoBuilder::new(buf), + builder: crate::runtime::ProtoBuilder::new(buf), } } - pub fn with(mut self, msg: &ProtoLimitsFeature<'_>) -> roto_runtime::Result { + pub fn with(mut self, msg: &ProtoLimitsFeature<'_>) -> crate::runtime::Result { for item in msg.raw_fields() { let (field_number, raw_bytes) = item?; let is_written = match field_number { @@ -6519,7 +6519,7 @@ impl<'b> ProtoLimitsFeatureBuilder<'b> { Ok(self) } - pub fn finish(self) -> roto_runtime::Result<&'b mut [u8]> { + pub fn finish(self) -> crate::runtime::Result<&'b mut [u8]> { self.builder.finish() } } @@ -6528,15 +6528,15 @@ pub struct OwnedProtoLimitsFeature { pub data: bytes::Bytes, } -impl roto_runtime::RotoOwned for OwnedProtoLimitsFeature { +impl crate::runtime::RotoOwned for OwnedProtoLimitsFeature { type Reader<'a> = ProtoLimitsFeature<'a>; fn reader(&self) -> ProtoLimitsFeature<'_> { ProtoLimitsFeature::new(&self.data).expect("failed to create reader") } } -impl roto_runtime::RotoMessage for OwnedProtoLimitsFeature { - fn decode(buf: bytes::Bytes) -> roto_runtime::Result { +impl crate::runtime::RotoMessage for OwnedProtoLimitsFeature { + fn decode(buf: bytes::Bytes) -> crate::runtime::Result { Ok(OwnedProtoLimitsFeature { data: buf }) } @@ -6570,7 +6570,7 @@ impl EnforceProtoLimits { } pub struct FeatureSetDefaults<'a> { - accessor: roto_runtime::ProtoAccessor<'a>, + accessor: crate::runtime::ProtoAccessor<'a>, defaults_start: Option, defaults_end: Option, minimum_edition_offset: Option, @@ -6578,8 +6578,8 @@ pub struct FeatureSetDefaults<'a> { } impl<'a> FeatureSetDefaults<'a> { - pub fn new(data: &'a [u8]) -> roto_runtime::Result { - let accessor = roto_runtime::ProtoAccessor::new(data)?; + pub fn new(data: &'a [u8]) -> crate::runtime::Result { + let accessor = crate::runtime::ProtoAccessor::new(data)?; let mut defaults_start = None; let mut defaults_end = None; let mut minimum_edition_offset = None; @@ -6602,45 +6602,45 @@ maximum_edition_offset, }) } - pub fn defaults(&self) -> roto_runtime::RepeatedFieldIterator<'a> { + pub fn defaults(&self) -> crate::runtime::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) -> roto_runtime::Result { - let offset = self.minimum_edition_offset.ok_or(roto_runtime::RotoError::FieldNotFound)?; + pub fn minimum_edition(&self) -> crate::runtime::Result { + let offset = self.minimum_edition_offset.ok_or(crate::runtime::RotoError::FieldNotFound)?; let (bytes, _) = self.accessor.get_value_at(offset)?; - roto_runtime::read_varint(bytes).map(|(v, _)| v as u64).map_err(|_| roto_runtime::RotoError::WireFormatViolation) + crate::runtime::read_varint(bytes).map(|(v, _)| v as u64).map_err(|_| crate::runtime::RotoError::WireFormatViolation) } - pub fn minimum_edition_or_default(&self) -> roto_runtime::Result { + pub fn minimum_edition_or_default(&self) -> crate::runtime::Result { self.minimum_edition().or(Ok(0)) } pub fn has_minimum_edition(&self) -> bool { self.minimum_edition_offset.is_some() } - pub fn maximum_edition(&self) -> roto_runtime::Result { - let offset = self.maximum_edition_offset.ok_or(roto_runtime::RotoError::FieldNotFound)?; + pub fn maximum_edition(&self) -> crate::runtime::Result { + let offset = self.maximum_edition_offset.ok_or(crate::runtime::RotoError::FieldNotFound)?; let (bytes, _) = self.accessor.get_value_at(offset)?; - roto_runtime::read_varint(bytes).map(|(v, _)| v as u64).map_err(|_| roto_runtime::RotoError::WireFormatViolation) + crate::runtime::read_varint(bytes).map(|(v, _)| v as u64).map_err(|_| crate::runtime::RotoError::WireFormatViolation) } - pub fn maximum_edition_or_default(&self) -> roto_runtime::Result { + pub fn maximum_edition_or_default(&self) -> crate::runtime::Result { self.maximum_edition().or(Ok(0)) } pub fn has_maximum_edition(&self) -> bool { self.maximum_edition_offset.is_some() } - pub fn raw_fields(&self) -> roto_runtime::RawFieldIterator<'a> { + pub fn raw_fields(&self) -> crate::runtime::RawFieldIterator<'a> { self.accessor.raw_fields() } } pub struct FeatureSetDefaultsBuilder<'b> { - builder: roto_runtime::ProtoBuilder<'b>, + builder: crate::runtime::ProtoBuilder<'b>, defaults_written: bool, minimum_edition_written: bool, maximum_edition_written: bool, @@ -6649,32 +6649,32 @@ pub struct FeatureSetDefaultsBuilder<'b> { impl<'b> FeatureSetDefaultsBuilder<'b> { pub fn builder(buf: &mut [u8]) -> FeatureSetDefaultsBuilder<'_> { FeatureSetDefaultsBuilder { - builder: roto_runtime::ProtoBuilder::new(buf), + builder: crate::runtime::ProtoBuilder::new(buf), defaults_written: false, minimum_edition_written: false, maximum_edition_written: false, } } - pub fn defaults(mut self, value: &[u8]) -> roto_runtime::Result { + pub fn defaults(mut self, value: &[u8]) -> crate::runtime::Result { self.builder.write_bytes(1, value)?; self.defaults_written = true; Ok(self) } - pub fn minimum_edition(mut self, value: u64) -> roto_runtime::Result { + pub fn minimum_edition(mut self, value: u64) -> crate::runtime::Result { self.builder.write_varint(4, value)?; self.minimum_edition_written = true; Ok(self) } - pub fn maximum_edition(mut self, value: u64) -> roto_runtime::Result { + pub fn maximum_edition(mut self, value: u64) -> crate::runtime::Result { self.builder.write_varint(5, value)?; self.maximum_edition_written = true; Ok(self) } - pub fn with(mut self, msg: &FeatureSetDefaults<'_>) -> roto_runtime::Result { + pub fn with(mut self, msg: &FeatureSetDefaults<'_>) -> crate::runtime::Result { for item in msg.raw_fields() { let (field_number, raw_bytes) = item?; let is_written = match field_number { @@ -6690,7 +6690,7 @@ impl<'b> FeatureSetDefaultsBuilder<'b> { Ok(self) } - pub fn finish(self) -> roto_runtime::Result<&'b mut [u8]> { + pub fn finish(self) -> crate::runtime::Result<&'b mut [u8]> { self.builder.finish() } } @@ -6699,15 +6699,15 @@ pub struct OwnedFeatureSetDefaults { pub data: bytes::Bytes, } -impl roto_runtime::RotoOwned for OwnedFeatureSetDefaults { +impl crate::runtime::RotoOwned for OwnedFeatureSetDefaults { type Reader<'a> = FeatureSetDefaults<'a>; fn reader(&self) -> FeatureSetDefaults<'_> { FeatureSetDefaults::new(&self.data).expect("failed to create reader") } } -impl roto_runtime::RotoMessage for OwnedFeatureSetDefaults { - fn decode(buf: bytes::Bytes) -> roto_runtime::Result { +impl crate::runtime::RotoMessage for OwnedFeatureSetDefaults { + fn decode(buf: bytes::Bytes) -> crate::runtime::Result { Ok(OwnedFeatureSetDefaults { data: buf }) } @@ -6718,15 +6718,15 @@ impl roto_runtime::RotoMessage for OwnedFeatureSetDefaults { pub mod feature_set_defaults { pub struct FeatureSetEditionDefault<'a> { - accessor: roto_runtime::ProtoAccessor<'a>, + accessor: crate::runtime::ProtoAccessor<'a>, edition_offset: Option, overridable_features_offset: Option, fixed_features_offset: Option, } impl<'a> FeatureSetEditionDefault<'a> { - pub fn new(data: &'a [u8]) -> roto_runtime::Result { - let accessor = roto_runtime::ProtoAccessor::new(data)?; + pub fn new(data: &'a [u8]) -> crate::runtime::Result { + let accessor = crate::runtime::ProtoAccessor::new(data)?; let mut edition_offset = None; let mut overridable_features_offset = None; let mut fixed_features_offset = None; @@ -6745,50 +6745,50 @@ fixed_features_offset, }) } - pub fn edition(&self) -> roto_runtime::Result { - let offset = self.edition_offset.ok_or(roto_runtime::RotoError::FieldNotFound)?; + pub fn edition(&self) -> crate::runtime::Result { + let offset = self.edition_offset.ok_or(crate::runtime::RotoError::FieldNotFound)?; let (bytes, _) = self.accessor.get_value_at(offset)?; - roto_runtime::read_varint(bytes).map(|(v, _)| v as u64).map_err(|_| roto_runtime::RotoError::WireFormatViolation) + crate::runtime::read_varint(bytes).map(|(v, _)| v as u64).map_err(|_| crate::runtime::RotoError::WireFormatViolation) } - pub fn edition_or_default(&self) -> roto_runtime::Result { + pub fn edition_or_default(&self) -> crate::runtime::Result { self.edition().or(Ok(0)) } pub fn has_edition(&self) -> bool { self.edition_offset.is_some() } - pub fn overridable_features(&self) -> roto_runtime::Result<&'a [u8]> { - let offset = self.overridable_features_offset.ok_or(roto_runtime::RotoError::FieldNotFound)?; + pub fn overridable_features(&self) -> crate::runtime::Result<&'a [u8]> { + let offset = self.overridable_features_offset.ok_or(crate::runtime::RotoError::FieldNotFound)?; let (bytes, _) = self.accessor.get_value_at(offset)?; Ok(bytes) } - pub fn overridable_features_or_default(&self) -> roto_runtime::Result<&'a [u8]> { + pub fn overridable_features_or_default(&self) -> crate::runtime::Result<&'a [u8]> { self.overridable_features().or(Ok(&[])) } pub fn has_overridable_features(&self) -> bool { self.overridable_features_offset.is_some() } - pub fn fixed_features(&self) -> roto_runtime::Result<&'a [u8]> { - let offset = self.fixed_features_offset.ok_or(roto_runtime::RotoError::FieldNotFound)?; + pub fn fixed_features(&self) -> crate::runtime::Result<&'a [u8]> { + let offset = self.fixed_features_offset.ok_or(crate::runtime::RotoError::FieldNotFound)?; let (bytes, _) = self.accessor.get_value_at(offset)?; Ok(bytes) } - pub fn fixed_features_or_default(&self) -> roto_runtime::Result<&'a [u8]> { + pub fn fixed_features_or_default(&self) -> crate::runtime::Result<&'a [u8]> { self.fixed_features().or(Ok(&[])) } pub fn has_fixed_features(&self) -> bool { self.fixed_features_offset.is_some() } - pub fn raw_fields(&self) -> roto_runtime::RawFieldIterator<'a> { + pub fn raw_fields(&self) -> crate::runtime::RawFieldIterator<'a> { self.accessor.raw_fields() } } pub struct FeatureSetEditionDefaultBuilder<'b> { - builder: roto_runtime::ProtoBuilder<'b>, + builder: crate::runtime::ProtoBuilder<'b>, edition_written: bool, overridable_features_written: bool, fixed_features_written: bool, @@ -6797,32 +6797,32 @@ pub struct FeatureSetEditionDefaultBuilder<'b> { impl<'b> FeatureSetEditionDefaultBuilder<'b> { pub fn builder(buf: &mut [u8]) -> FeatureSetEditionDefaultBuilder<'_> { FeatureSetEditionDefaultBuilder { - builder: roto_runtime::ProtoBuilder::new(buf), + builder: crate::runtime::ProtoBuilder::new(buf), edition_written: false, overridable_features_written: false, fixed_features_written: false, } } - pub fn edition(mut self, value: u64) -> roto_runtime::Result { + pub fn edition(mut self, value: u64) -> crate::runtime::Result { self.builder.write_varint(3, value)?; self.edition_written = true; Ok(self) } - pub fn overridable_features(mut self, value: &[u8]) -> roto_runtime::Result { + pub fn overridable_features(mut self, value: &[u8]) -> crate::runtime::Result { self.builder.write_bytes(4, value)?; self.overridable_features_written = true; Ok(self) } - pub fn fixed_features(mut self, value: &[u8]) -> roto_runtime::Result { + pub fn fixed_features(mut self, value: &[u8]) -> crate::runtime::Result { self.builder.write_bytes(5, value)?; self.fixed_features_written = true; Ok(self) } - pub fn with(mut self, msg: &FeatureSetEditionDefault<'_>) -> roto_runtime::Result { + pub fn with(mut self, msg: &FeatureSetEditionDefault<'_>) -> crate::runtime::Result { for item in msg.raw_fields() { let (field_number, raw_bytes) = item?; let is_written = match field_number { @@ -6838,7 +6838,7 @@ impl<'b> FeatureSetEditionDefaultBuilder<'b> { Ok(self) } - pub fn finish(self) -> roto_runtime::Result<&'b mut [u8]> { + pub fn finish(self) -> crate::runtime::Result<&'b mut [u8]> { self.builder.finish() } } @@ -6847,15 +6847,15 @@ pub struct OwnedFeatureSetEditionDefault { pub data: bytes::Bytes, } -impl roto_runtime::RotoOwned for OwnedFeatureSetEditionDefault { +impl crate::runtime::RotoOwned for OwnedFeatureSetEditionDefault { type Reader<'a> = FeatureSetEditionDefault<'a>; fn reader(&self) -> FeatureSetEditionDefault<'_> { FeatureSetEditionDefault::new(&self.data).expect("failed to create reader") } } -impl roto_runtime::RotoMessage for OwnedFeatureSetEditionDefault { - fn decode(buf: bytes::Bytes) -> roto_runtime::Result { +impl crate::runtime::RotoMessage for OwnedFeatureSetEditionDefault { + fn decode(buf: bytes::Bytes) -> crate::runtime::Result { Ok(OwnedFeatureSetEditionDefault { data: buf }) } @@ -6867,14 +6867,14 @@ impl roto_runtime::RotoMessage for OwnedFeatureSetEditionDefault { } pub struct SourceCodeInfo<'a> { - accessor: roto_runtime::ProtoAccessor<'a>, + accessor: crate::runtime::ProtoAccessor<'a>, location_start: Option, location_end: Option, } impl<'a> SourceCodeInfo<'a> { - pub fn new(data: &'a [u8]) -> roto_runtime::Result { - let accessor = roto_runtime::ProtoAccessor::new(data)?; + pub fn new(data: &'a [u8]) -> crate::runtime::Result { + let accessor = crate::runtime::ProtoAccessor::new(data)?; let mut location_start = None; let mut location_end = None; for item in accessor.fields() { @@ -6891,39 +6891,39 @@ location_start, location_end, }) } - pub fn location(&self) -> roto_runtime::RepeatedFieldIterator<'a> { + pub fn location(&self) -> crate::runtime::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 fn raw_fields(&self) -> roto_runtime::RawFieldIterator<'a> { + pub fn raw_fields(&self) -> crate::runtime::RawFieldIterator<'a> { self.accessor.raw_fields() } } pub struct SourceCodeInfoBuilder<'b> { - builder: roto_runtime::ProtoBuilder<'b>, + builder: crate::runtime::ProtoBuilder<'b>, location_written: bool, } impl<'b> SourceCodeInfoBuilder<'b> { pub fn builder(buf: &mut [u8]) -> SourceCodeInfoBuilder<'_> { SourceCodeInfoBuilder { - builder: roto_runtime::ProtoBuilder::new(buf), + builder: crate::runtime::ProtoBuilder::new(buf), location_written: false, } } - pub fn location(mut self, value: &[u8]) -> roto_runtime::Result { + pub fn location(mut self, value: &[u8]) -> crate::runtime::Result { self.builder.write_bytes(1, value)?; self.location_written = true; Ok(self) } - pub fn with(mut self, msg: &SourceCodeInfo<'_>) -> roto_runtime::Result { + pub fn with(mut self, msg: &SourceCodeInfo<'_>) -> crate::runtime::Result { for item in msg.raw_fields() { let (field_number, raw_bytes) = item?; let is_written = match field_number { @@ -6937,7 +6937,7 @@ impl<'b> SourceCodeInfoBuilder<'b> { Ok(self) } - pub fn finish(self) -> roto_runtime::Result<&'b mut [u8]> { + pub fn finish(self) -> crate::runtime::Result<&'b mut [u8]> { self.builder.finish() } } @@ -6946,15 +6946,15 @@ pub struct OwnedSourceCodeInfo { pub data: bytes::Bytes, } -impl roto_runtime::RotoOwned for OwnedSourceCodeInfo { +impl crate::runtime::RotoOwned for OwnedSourceCodeInfo { type Reader<'a> = SourceCodeInfo<'a>; fn reader(&self) -> SourceCodeInfo<'_> { SourceCodeInfo::new(&self.data).expect("failed to create reader") } } -impl roto_runtime::RotoMessage for OwnedSourceCodeInfo { - fn decode(buf: bytes::Bytes) -> roto_runtime::Result { +impl crate::runtime::RotoMessage for OwnedSourceCodeInfo { + fn decode(buf: bytes::Bytes) -> crate::runtime::Result { Ok(OwnedSourceCodeInfo { data: buf }) } @@ -6965,7 +6965,7 @@ impl roto_runtime::RotoMessage for OwnedSourceCodeInfo { pub mod source_code_info { pub struct Location<'a> { - accessor: roto_runtime::ProtoAccessor<'a>, + accessor: crate::runtime::ProtoAccessor<'a>, path_start: Option, path_end: Option, span_start: Option, @@ -6977,8 +6977,8 @@ pub struct Location<'a> { } impl<'a> Location<'a> { - pub fn new(data: &'a [u8]) -> roto_runtime::Result { - let accessor = roto_runtime::ProtoAccessor::new(data)?; + pub fn new(data: &'a [u8]) -> crate::runtime::Result { + let accessor = crate::runtime::ProtoAccessor::new(data)?; let mut path_start = None; let mut path_end = None; let mut span_start = None; @@ -7015,59 +7015,59 @@ leading_detached_comments_start, leading_detached_comments_end, }) } - pub fn path(&self) -> roto_runtime::RepeatedFieldIterator<'a> { + pub fn path(&self) -> crate::runtime::RepeatedFieldIterator<'a> { match (self.path_start, self.path_end) { (Some(start), Some(end)) => self.accessor.iter_repeated_range(1, start, end), _ => self.accessor.iter_repeated(1), } } - pub fn span(&self) -> roto_runtime::RepeatedFieldIterator<'a> { + pub fn span(&self) -> crate::runtime::RepeatedFieldIterator<'a> { match (self.span_start, self.span_end) { (Some(start), Some(end)) => self.accessor.iter_repeated_range(2, start, end), _ => self.accessor.iter_repeated(2), } } - pub fn leading_comments(&self) -> roto_runtime::Result<&'a str> { - let offset = self.leading_comments_offset.ok_or(roto_runtime::RotoError::FieldNotFound)?; + pub fn leading_comments(&self) -> crate::runtime::Result<&'a str> { + let offset = self.leading_comments_offset.ok_or(crate::runtime::RotoError::FieldNotFound)?; let (bytes, _) = self.accessor.get_value_at(offset)?; - str::from_utf8(bytes).map_err(|_| roto_runtime::RotoError::WireFormatViolation) + str::from_utf8(bytes).map_err(|_| crate::runtime::RotoError::WireFormatViolation) } - pub fn leading_comments_or_default(&self) -> roto_runtime::Result<&'a str> { + pub fn leading_comments_or_default(&self) -> crate::runtime::Result<&'a str> { self.leading_comments().or(Ok("")) } pub fn has_leading_comments(&self) -> bool { self.leading_comments_offset.is_some() } - pub fn trailing_comments(&self) -> roto_runtime::Result<&'a str> { - let offset = self.trailing_comments_offset.ok_or(roto_runtime::RotoError::FieldNotFound)?; + pub fn trailing_comments(&self) -> crate::runtime::Result<&'a str> { + let offset = self.trailing_comments_offset.ok_or(crate::runtime::RotoError::FieldNotFound)?; let (bytes, _) = self.accessor.get_value_at(offset)?; - str::from_utf8(bytes).map_err(|_| roto_runtime::RotoError::WireFormatViolation) + str::from_utf8(bytes).map_err(|_| crate::runtime::RotoError::WireFormatViolation) } - pub fn trailing_comments_or_default(&self) -> roto_runtime::Result<&'a str> { + pub fn trailing_comments_or_default(&self) -> crate::runtime::Result<&'a str> { self.trailing_comments().or(Ok("")) } pub fn has_trailing_comments(&self) -> bool { self.trailing_comments_offset.is_some() } - pub fn leading_detached_comments(&self) -> roto_runtime::RepeatedFieldIterator<'a> { + pub fn leading_detached_comments(&self) -> crate::runtime::RepeatedFieldIterator<'a> { match (self.leading_detached_comments_start, self.leading_detached_comments_end) { (Some(start), Some(end)) => self.accessor.iter_repeated_range(6, start, end), _ => self.accessor.iter_repeated(6), } } - pub fn raw_fields(&self) -> roto_runtime::RawFieldIterator<'a> { + pub fn raw_fields(&self) -> crate::runtime::RawFieldIterator<'a> { self.accessor.raw_fields() } } pub struct LocationBuilder<'b> { - builder: roto_runtime::ProtoBuilder<'b>, + builder: crate::runtime::ProtoBuilder<'b>, path_written: bool, span_written: bool, leading_comments_written: bool, @@ -7078,7 +7078,7 @@ pub struct LocationBuilder<'b> { impl<'b> LocationBuilder<'b> { pub fn builder(buf: &mut [u8]) -> LocationBuilder<'_> { LocationBuilder { - builder: roto_runtime::ProtoBuilder::new(buf), + builder: crate::runtime::ProtoBuilder::new(buf), path_written: false, span_written: false, leading_comments_written: false, @@ -7087,37 +7087,37 @@ impl<'b> LocationBuilder<'b> { } } - pub fn path(mut self, value: i32) -> roto_runtime::Result { + pub fn path(mut self, value: i32) -> crate::runtime::Result { self.builder.write_int32(1, value)?; self.path_written = true; Ok(self) } - pub fn span(mut self, value: i32) -> roto_runtime::Result { + pub fn span(mut self, value: i32) -> crate::runtime::Result { self.builder.write_int32(2, value)?; self.span_written = true; Ok(self) } - pub fn leading_comments(mut self, value: &str) -> roto_runtime::Result { + pub fn leading_comments(mut self, value: &str) -> crate::runtime::Result { self.builder.write_string(3, value)?; self.leading_comments_written = true; Ok(self) } - pub fn trailing_comments(mut self, value: &str) -> roto_runtime::Result { + pub fn trailing_comments(mut self, value: &str) -> crate::runtime::Result { self.builder.write_string(4, value)?; self.trailing_comments_written = true; Ok(self) } - pub fn leading_detached_comments(mut self, value: &str) -> roto_runtime::Result { + pub fn leading_detached_comments(mut self, value: &str) -> crate::runtime::Result { self.builder.write_string(6, value)?; self.leading_detached_comments_written = true; Ok(self) } - pub fn with(mut self, msg: &Location<'_>) -> roto_runtime::Result { + pub fn with(mut self, msg: &Location<'_>) -> crate::runtime::Result { for item in msg.raw_fields() { let (field_number, raw_bytes) = item?; let is_written = match field_number { @@ -7135,7 +7135,7 @@ impl<'b> LocationBuilder<'b> { Ok(self) } - pub fn finish(self) -> roto_runtime::Result<&'b mut [u8]> { + pub fn finish(self) -> crate::runtime::Result<&'b mut [u8]> { self.builder.finish() } } @@ -7144,15 +7144,15 @@ pub struct OwnedLocation { pub data: bytes::Bytes, } -impl roto_runtime::RotoOwned for OwnedLocation { +impl crate::runtime::RotoOwned for OwnedLocation { type Reader<'a> = Location<'a>; fn reader(&self) -> Location<'_> { Location::new(&self.data).expect("failed to create reader") } } -impl roto_runtime::RotoMessage for OwnedLocation { - fn decode(buf: bytes::Bytes) -> roto_runtime::Result { +impl crate::runtime::RotoMessage for OwnedLocation { + fn decode(buf: bytes::Bytes) -> crate::runtime::Result { Ok(OwnedLocation { data: buf }) } @@ -7164,14 +7164,14 @@ impl roto_runtime::RotoMessage for OwnedLocation { } pub struct GeneratedCodeInfo<'a> { - accessor: roto_runtime::ProtoAccessor<'a>, + accessor: crate::runtime::ProtoAccessor<'a>, annotation_start: Option, annotation_end: Option, } impl<'a> GeneratedCodeInfo<'a> { - pub fn new(data: &'a [u8]) -> roto_runtime::Result { - let accessor = roto_runtime::ProtoAccessor::new(data)?; + pub fn new(data: &'a [u8]) -> crate::runtime::Result { + let accessor = crate::runtime::ProtoAccessor::new(data)?; let mut annotation_start = None; let mut annotation_end = None; for item in accessor.fields() { @@ -7188,39 +7188,39 @@ annotation_start, annotation_end, }) } - pub fn annotation(&self) -> roto_runtime::RepeatedFieldIterator<'a> { + pub fn annotation(&self) -> crate::runtime::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 fn raw_fields(&self) -> roto_runtime::RawFieldIterator<'a> { + pub fn raw_fields(&self) -> crate::runtime::RawFieldIterator<'a> { self.accessor.raw_fields() } } pub struct GeneratedCodeInfoBuilder<'b> { - builder: roto_runtime::ProtoBuilder<'b>, + builder: crate::runtime::ProtoBuilder<'b>, annotation_written: bool, } impl<'b> GeneratedCodeInfoBuilder<'b> { pub fn builder(buf: &mut [u8]) -> GeneratedCodeInfoBuilder<'_> { GeneratedCodeInfoBuilder { - builder: roto_runtime::ProtoBuilder::new(buf), + builder: crate::runtime::ProtoBuilder::new(buf), annotation_written: false, } } - pub fn annotation(mut self, value: &[u8]) -> roto_runtime::Result { + pub fn annotation(mut self, value: &[u8]) -> crate::runtime::Result { self.builder.write_bytes(1, value)?; self.annotation_written = true; Ok(self) } - pub fn with(mut self, msg: &GeneratedCodeInfo<'_>) -> roto_runtime::Result { + pub fn with(mut self, msg: &GeneratedCodeInfo<'_>) -> crate::runtime::Result { for item in msg.raw_fields() { let (field_number, raw_bytes) = item?; let is_written = match field_number { @@ -7234,7 +7234,7 @@ impl<'b> GeneratedCodeInfoBuilder<'b> { Ok(self) } - pub fn finish(self) -> roto_runtime::Result<&'b mut [u8]> { + pub fn finish(self) -> crate::runtime::Result<&'b mut [u8]> { self.builder.finish() } } @@ -7243,15 +7243,15 @@ pub struct OwnedGeneratedCodeInfo { pub data: bytes::Bytes, } -impl roto_runtime::RotoOwned for OwnedGeneratedCodeInfo { +impl crate::runtime::RotoOwned for OwnedGeneratedCodeInfo { type Reader<'a> = GeneratedCodeInfo<'a>; fn reader(&self) -> GeneratedCodeInfo<'_> { GeneratedCodeInfo::new(&self.data).expect("failed to create reader") } } -impl roto_runtime::RotoMessage for OwnedGeneratedCodeInfo { - fn decode(buf: bytes::Bytes) -> roto_runtime::Result { +impl crate::runtime::RotoMessage for OwnedGeneratedCodeInfo { + fn decode(buf: bytes::Bytes) -> crate::runtime::Result { Ok(OwnedGeneratedCodeInfo { data: buf }) } @@ -7262,7 +7262,7 @@ impl roto_runtime::RotoMessage for OwnedGeneratedCodeInfo { pub mod generated_code_info { pub struct Annotation<'a> { - accessor: roto_runtime::ProtoAccessor<'a>, + accessor: crate::runtime::ProtoAccessor<'a>, path_start: Option, path_end: Option, source_file_offset: Option, @@ -7272,8 +7272,8 @@ pub struct Annotation<'a> { } impl<'a> Annotation<'a> { - pub fn new(data: &'a [u8]) -> roto_runtime::Result { - let accessor = roto_runtime::ProtoAccessor::new(data)?; + pub fn new(data: &'a [u8]) -> crate::runtime::Result { + let accessor = crate::runtime::ProtoAccessor::new(data)?; let mut path_start = None; let mut path_end = None; let mut source_file_offset = None; @@ -7302,69 +7302,69 @@ semantic_offset, }) } - pub fn path(&self) -> roto_runtime::RepeatedFieldIterator<'a> { + pub fn path(&self) -> crate::runtime::RepeatedFieldIterator<'a> { match (self.path_start, self.path_end) { (Some(start), Some(end)) => self.accessor.iter_repeated_range(1, start, end), _ => self.accessor.iter_repeated(1), } } - pub fn source_file(&self) -> roto_runtime::Result<&'a str> { - let offset = self.source_file_offset.ok_or(roto_runtime::RotoError::FieldNotFound)?; + pub fn source_file(&self) -> crate::runtime::Result<&'a str> { + let offset = self.source_file_offset.ok_or(crate::runtime::RotoError::FieldNotFound)?; let (bytes, _) = self.accessor.get_value_at(offset)?; - str::from_utf8(bytes).map_err(|_| roto_runtime::RotoError::WireFormatViolation) + str::from_utf8(bytes).map_err(|_| crate::runtime::RotoError::WireFormatViolation) } - pub fn source_file_or_default(&self) -> roto_runtime::Result<&'a str> { + pub fn source_file_or_default(&self) -> crate::runtime::Result<&'a str> { self.source_file().or(Ok("")) } pub fn has_source_file(&self) -> bool { self.source_file_offset.is_some() } - pub fn begin(&self) -> roto_runtime::Result { - let offset = self.begin_offset.ok_or(roto_runtime::RotoError::FieldNotFound)?; + pub fn begin(&self) -> crate::runtime::Result { + let offset = self.begin_offset.ok_or(crate::runtime::RotoError::FieldNotFound)?; let (bytes, _) = self.accessor.get_value_at(offset)?; - roto_runtime::read_varint(bytes).map(|(v, _)| v as i32).map_err(|_| roto_runtime::RotoError::WireFormatViolation) + crate::runtime::read_varint(bytes).map(|(v, _)| v as i32).map_err(|_| crate::runtime::RotoError::WireFormatViolation) } - pub fn begin_or_default(&self) -> roto_runtime::Result { + pub fn begin_or_default(&self) -> crate::runtime::Result { self.begin().or(Ok(0)) } pub fn has_begin(&self) -> bool { self.begin_offset.is_some() } - pub fn end(&self) -> roto_runtime::Result { - let offset = self.end_offset.ok_or(roto_runtime::RotoError::FieldNotFound)?; + pub fn end(&self) -> crate::runtime::Result { + let offset = self.end_offset.ok_or(crate::runtime::RotoError::FieldNotFound)?; let (bytes, _) = self.accessor.get_value_at(offset)?; - roto_runtime::read_varint(bytes).map(|(v, _)| v as i32).map_err(|_| roto_runtime::RotoError::WireFormatViolation) + crate::runtime::read_varint(bytes).map(|(v, _)| v as i32).map_err(|_| crate::runtime::RotoError::WireFormatViolation) } - pub fn end_or_default(&self) -> roto_runtime::Result { + pub fn end_or_default(&self) -> crate::runtime::Result { self.end().or(Ok(0)) } pub fn has_end(&self) -> bool { self.end_offset.is_some() } - pub fn semantic(&self) -> roto_runtime::Result { - let offset = self.semantic_offset.ok_or(roto_runtime::RotoError::FieldNotFound)?; + pub fn semantic(&self) -> crate::runtime::Result { + let offset = self.semantic_offset.ok_or(crate::runtime::RotoError::FieldNotFound)?; let (bytes, _) = self.accessor.get_value_at(offset)?; - roto_runtime::read_varint(bytes).map(|(v, _)| v as u64).map_err(|_| roto_runtime::RotoError::WireFormatViolation) + crate::runtime::read_varint(bytes).map(|(v, _)| v as u64).map_err(|_| crate::runtime::RotoError::WireFormatViolation) } - pub fn semantic_or_default(&self) -> roto_runtime::Result { + pub fn semantic_or_default(&self) -> crate::runtime::Result { self.semantic().or(Ok(0)) } pub fn has_semantic(&self) -> bool { self.semantic_offset.is_some() } - pub fn raw_fields(&self) -> roto_runtime::RawFieldIterator<'a> { + pub fn raw_fields(&self) -> crate::runtime::RawFieldIterator<'a> { self.accessor.raw_fields() } } pub struct AnnotationBuilder<'b> { - builder: roto_runtime::ProtoBuilder<'b>, + builder: crate::runtime::ProtoBuilder<'b>, path_written: bool, source_file_written: bool, begin_written: bool, @@ -7375,7 +7375,7 @@ pub struct AnnotationBuilder<'b> { impl<'b> AnnotationBuilder<'b> { pub fn builder(buf: &mut [u8]) -> AnnotationBuilder<'_> { AnnotationBuilder { - builder: roto_runtime::ProtoBuilder::new(buf), + builder: crate::runtime::ProtoBuilder::new(buf), path_written: false, source_file_written: false, begin_written: false, @@ -7384,37 +7384,37 @@ impl<'b> AnnotationBuilder<'b> { } } - pub fn path(mut self, value: i32) -> roto_runtime::Result { + pub fn path(mut self, value: i32) -> crate::runtime::Result { self.builder.write_int32(1, value)?; self.path_written = true; Ok(self) } - pub fn source_file(mut self, value: &str) -> roto_runtime::Result { + pub fn source_file(mut self, value: &str) -> crate::runtime::Result { self.builder.write_string(2, value)?; self.source_file_written = true; Ok(self) } - pub fn begin(mut self, value: i32) -> roto_runtime::Result { + pub fn begin(mut self, value: i32) -> crate::runtime::Result { self.builder.write_int32(3, value)?; self.begin_written = true; Ok(self) } - pub fn end(mut self, value: i32) -> roto_runtime::Result { + pub fn end(mut self, value: i32) -> crate::runtime::Result { self.builder.write_int32(4, value)?; self.end_written = true; Ok(self) } - pub fn semantic(mut self, value: u64) -> roto_runtime::Result { + pub fn semantic(mut self, value: u64) -> crate::runtime::Result { self.builder.write_varint(5, value)?; self.semantic_written = true; Ok(self) } - pub fn with(mut self, msg: &Annotation<'_>) -> roto_runtime::Result { + pub fn with(mut self, msg: &Annotation<'_>) -> crate::runtime::Result { for item in msg.raw_fields() { let (field_number, raw_bytes) = item?; let is_written = match field_number { @@ -7432,7 +7432,7 @@ impl<'b> AnnotationBuilder<'b> { Ok(self) } - pub fn finish(self) -> roto_runtime::Result<&'b mut [u8]> { + pub fn finish(self) -> crate::runtime::Result<&'b mut [u8]> { self.builder.finish() } } @@ -7441,15 +7441,15 @@ pub struct OwnedAnnotation { pub data: bytes::Bytes, } -impl roto_runtime::RotoOwned for OwnedAnnotation { +impl crate::runtime::RotoOwned for OwnedAnnotation { type Reader<'a> = Annotation<'a>; fn reader(&self) -> Annotation<'_> { Annotation::new(&self.data).expect("failed to create reader") } } -impl roto_runtime::RotoMessage for OwnedAnnotation { - fn decode(buf: bytes::Bytes) -> roto_runtime::Result { +impl crate::runtime::RotoMessage for OwnedAnnotation { + fn decode(buf: bytes::Bytes) -> crate::runtime::Result { Ok(OwnedAnnotation { data: buf }) } diff --git a/codegen/src/lib.rs b/codegen/src/lib.rs index 8038813..2935f4d 100644 --- a/codegen/src/lib.rs +++ b/codegen/src/lib.rs @@ -1,2 +1,4 @@ pub mod generator; pub mod google; +pub mod runtime; + diff --git a/codegen/src/runtime/mod.rs b/codegen/src/runtime/mod.rs new file mode 100644 index 0000000..5123f12 --- /dev/null +++ b/codegen/src/runtime/mod.rs @@ -0,0 +1,921 @@ + + + + + + +use core::fmt; +use bytes::BufMut; + +pub struct MapFieldIterator<'a> { + inner: RepeatedFieldIterator<'a>, +} + +impl<'a> MapFieldIterator<'a> { + pub fn new(inner: RepeatedFieldIterator<'a>) -> Self { + Self { inner } + } +} + +impl<'a> Iterator for MapFieldIterator<'a> { + type Item = Result<(&'a [u8], &'a [u8])>; + + fn next(&mut self) -> Option { + match self.inner.next() { + Some(Ok((value, _wire_type))) => { + let accessor = ProtoAccessor::new(value).ok()?; + let (key_bytes, _) = accessor.get_value(1).ok()?; + let (val_bytes, _) = accessor.get_value(2).ok()?; + Some(Ok((key_bytes, val_bytes))) + } + Some(Err(e)) => Some(Err(e)), + None => None, + } + } +} + +#[derive(Debug, PartialEq)] +pub enum RotoError { + UnexpectedEndOfBuffer, + InvalidVarint, + InvalidWireType(u8), + BufferOverflow, + FieldNotFound, + WireFormatViolation, +} + +impl fmt::Display for RotoError { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + match self { + RotoError::UnexpectedEndOfBuffer => write!(f, "Unexpected end of buffer"), + RotoError::InvalidVarint => write!(f, "Invalid varint encoding"), + RotoError::InvalidWireType(t) => write!(f, "Invalid wire type: {t}"), + RotoError::BufferOverflow => write!(f, "Buffer overflow during write"), + RotoError::FieldNotFound => write!(f, "Requested field not found in message"), + RotoError::WireFormatViolation => write!(f, "Wire format violation"), + } + } +} + +impl std::error::Error for RotoError {} + +pub type Result = core::result::Result; + +pub trait RotoOwned { + type Reader<'a> where Self: 'a; + fn reader(&self) -> Self::Reader<'_>; +} + +pub trait RotoMessage: Sized { + fn decode(buf: bytes::Bytes) -> Result; + fn bytes(&self) -> bytes::Bytes; +} + +#[derive(Debug, Clone, Copy, PartialEq, Eq)] +pub enum WireType { + Varint = 0, + Fixed64 = 1, + LengthDelimited = 2, + StartGroup = 3, // Deprecated + EndGroup = 4, // Deprecated + Fixed32 = 5, +} + +impl WireType { + pub fn from_u8(value: u8) -> Result { + match value { + 0 => Ok(WireType::Varint), + 1 => Ok(WireType::Fixed64), + 2 => Ok(WireType::LengthDelimited), + 3 => Ok(WireType::StartGroup), + 4 => Ok(WireType::EndGroup), + 5 => Ok(WireType::Fixed32), + _ => Err(RotoError::InvalidWireType(value)), + } + } +} + +#[derive(Debug, Clone, Copy, PartialEq, Eq)] +pub struct Tag { + pub field_number: u32, + pub wire_type: WireType, +} + +impl Tag { + /// Decodes a tag from the buffer, returning the tag and the number of bytes read. + pub fn decode(data: &[u8]) -> Result<(Self, usize)> { + let (val, len) = read_varint(data)?; + let wire_type_raw = (val & 0x7) as u8; + let field_number = (val >> 3) as u32; + + Ok(( + Tag { + field_number, + wire_type: WireType::from_u8(wire_type_raw)?, + }, + len, + )) + } + + /// Encodes a tag into the provided buffer. + pub fn encode(field_number: u32, wire_type: WireType, buf: &mut [u8]) -> Result { + let val = ((field_number as u64) << 3) | (wire_type as u64); + write_varint(val, buf) + } +} + +/// Reads a varint from the start of the buffer. +pub fn read_varint(data: &[u8]) -> Result<(u64, usize)> { + let mut result = 0u64; + let mut shift = 0; + let mut bytes_read = 0; + + for &byte in data { + bytes_read += 1; + if bytes_read > 10 { + return Err(RotoError::InvalidVarint); + } + + let value = (byte & 0x7F) as u64; + if shift >= 64 { + return Err(RotoError::InvalidVarint); + } + result |= value << shift; + shift += 7; + + if (byte & 0x80) == 0 { + return Ok((result, bytes_read)); + } + } + + Err(RotoError::UnexpectedEndOfBuffer) +} + +/// Writes a varint into the buffer. +pub fn write_varint(mut value: u64, buf: &mut [u8]) -> Result { + let mut bytes_written = 0; + while value >= 0x80 { + if bytes_written >= buf.len() { + return Err(RotoError::BufferOverflow); + } + buf[bytes_written] = (value as u8 & 0x7F) | 0x80; + value >>= 7; + bytes_written += 1; + } + + if bytes_written >= buf.len() { + return Err(RotoError::BufferOverflow); + } + buf[bytes_written] = value as u8; + bytes_written += 1; + Ok(bytes_written) +} + +/// Returns the number of bytes that should be skipped for a given wire type and the current data slice. +pub fn skip_value(wire_type: WireType, data: &[u8]) -> Result { + match wire_type { + WireType::Varint => { + let (_, len) = read_varint(data)?; + Ok(len) + } + WireType::Fixed64 => { + if data.len() < 8 { + return Err(RotoError::UnexpectedEndOfBuffer); + } + Ok(8) + } + WireType::LengthDelimited => { + let (len, varint_len) = read_varint(data)?; + let total_len = varint_len + len as usize; + if data.len() < total_len { + return Err(RotoError::UnexpectedEndOfBuffer); + } + Ok(total_len) + } + WireType::Fixed32 => { + if data.len() < 4 { + return Err(RotoError::UnexpectedEndOfBuffer); + } + Ok(4) + } + WireType::StartGroup | WireType::EndGroup => { + // These are deprecated and not fully supported in this runtime. + Err(RotoError::WireFormatViolation) + } + } +} + +pub struct ProtoAccessor<'a> { + data: &'a [u8], +} + +impl<'a> ProtoAccessor<'a> { + pub fn new(data: &'a [u8]) -> Result { + Ok(Self { data }) + } + + /// Returns an iterator over all fields in the message. + pub fn fields(&self) -> FieldIterator<'a> { + FieldIterator { + data: self.data, + cursor: 0, + } + } + + /// Returns the value and wire type of the last occurrence of the specified field. + pub fn get_value(&self, field_number: u32) -> Result<(&'a [u8], WireType)> { + let mut last_value = None; + for item in self.fields() { + let (_offset, tag, value) = item?; + if tag.field_number == field_number { + last_value = Some((value, tag.wire_type)); + } + } + last_value.ok_or(RotoError::FieldNotFound) + } + + /// Returns an iterator that scans the entire buffer for all occurrences of the specified field. + pub fn iter_repeated(&self, field_number: u32) -> RepeatedFieldIterator<'a> { + RepeatedFieldIterator::new(self.data, field_number) + } + + /// Returns the value and wire type of a field at a specific offset. + pub fn get_value_at(&self, offset: usize) -> Result<(&'a [u8], WireType)> { + if offset >= self.data.len() { + return Err(RotoError::UnexpectedEndOfBuffer); + } + let (tag, tag_len) = Tag::decode(&self.data[offset..])?; + let cursor_after_tag = offset + tag_len; + if cursor_after_tag > self.data.len() { + return Err(RotoError::UnexpectedEndOfBuffer); + } + let value_len = skip_value(tag.wire_type, &self.data[cursor_after_tag..])?; + let (value_offset, actual_value_len) = match tag.wire_type { + WireType::LengthDelimited => { + let (_, varint_len) = read_varint(&self.data[cursor_after_tag..])?; + (cursor_after_tag + varint_len, value_len - varint_len) + } + _ => (cursor_after_tag, value_len), + }; + Ok(( + &self.data[value_offset..value_offset + actual_value_len], + tag.wire_type, + )) + } + + /// Returns an iterator that scans a specific range of the buffer for all occurrences of the specified field. + pub fn iter_repeated_range( + &self, + field_number: u32, + start: usize, + end: usize, + ) -> RepeatedFieldIterator<'a> { + RepeatedFieldIterator::new_range(self.data, field_number, start, end) + } + + /// Returns an iterator that yields `(field_number, raw_bytes)` for every + /// field in the message. `raw_bytes` is the complete on-wire encoding + /// (tag + value, including any length prefix), suitable for passing + /// directly to `ProtoBuilder::write_raw`. + pub fn raw_fields(&self) -> RawFieldIterator<'a> { + RawFieldIterator { + data: self.data, + cursor: 0, + } + } +} + +pub struct FieldIterator<'a> { + data: &'a [u8], + cursor: usize, +} + +impl<'a> Iterator for FieldIterator<'a> { + type Item = Result<(usize, Tag, &'a [u8])>; + + fn next(&mut self) -> Option { + if self.cursor >= self.data.len() { + return None; + } + + let (tag, tag_len) = match Tag::decode(&self.data[self.cursor..]) { + Ok(t) => t, + Err(e) => { + self.cursor = self.data.len(); + return Some(Err(e)); + } + }; + + let cursor_after_tag = self.cursor + tag_len; + if cursor_after_tag > self.data.len() { + self.cursor = self.data.len(); + return Some(Err(RotoError::UnexpectedEndOfBuffer)); + } + + let value_len = match skip_value(tag.wire_type, &self.data[cursor_after_tag..]) { + Ok(l) => l, + Err(e) => { + self.cursor = self.data.len(); + return Some(Err(e)); + } + }; + + let (value_offset, actual_value_len) = match tag.wire_type { + WireType::LengthDelimited => { + let (_, varint_len) = match read_varint(&self.data[cursor_after_tag..]) { + Ok(v) => v, + Err(e) => { + self.cursor = self.data.len(); + return Some(Err(e)); + } + }; + (cursor_after_tag + varint_len, value_len - varint_len) + } + _ => (cursor_after_tag, value_len), + }; + + self.cursor = cursor_after_tag + value_len; + + Some(Ok(( + self.cursor - tag_len - value_len, + tag, + &self.data[value_offset..value_offset + actual_value_len], + ))) + } +} + +pub struct RepeatedFieldIterator<'a> { + iterator: FieldIterator<'a>, + field_number: u32, + end_offset: Option, +} + +impl<'a> RepeatedFieldIterator<'a> { + pub fn new(data: &'a [u8], field_number: u32) -> Self { + Self { + iterator: FieldIterator { data, cursor: 0 }, + field_number, + end_offset: None, + } + } + + pub fn new_range(data: &'a [u8], field_number: u32, start: usize, end: usize) -> Self { + Self { + iterator: FieldIterator { + data, + cursor: start, + }, + field_number, + end_offset: Some(end), + } + } +} + +impl<'a> Iterator for RepeatedFieldIterator<'a> { + type Item = Result<(&'a [u8], WireType)>; + + fn next(&mut self) -> Option { + while let Some(item) = self.iterator.next() { + match item { + Ok((offset, tag, value)) if tag.field_number == self.field_number => { + if let Some(end) = self.end_offset { + if offset > end { + return None; + } + } + return Some(Ok((value, tag.wire_type))); + } + Ok(_) => continue, + Err(e) => return Some(Err(e)), + } + } + None + } +} + +/// An iterator that yields `(field_number, raw_bytes)` for every field in a +/// protobuf message, where `raw_bytes` is the complete on-wire encoding of the +/// field: tag varint + value bytes (including the length prefix for +/// length-delimited fields). This is the slice needed by +/// `ProtoBuilder::write_raw` to copy a field verbatim. +pub struct RawFieldIterator<'a> { + data: &'a [u8], + cursor: usize, +} + +impl<'a> Iterator for RawFieldIterator<'a> { + type Item = Result<(u32, &'a [u8])>; + + fn next(&mut self) -> Option { + if self.cursor >= self.data.len() { + return None; + } + let field_start = self.cursor; + let (tag, tag_len) = match Tag::decode(&self.data[self.cursor..]) { + Ok(t) => t, + Err(e) => { + self.cursor = self.data.len(); + return Some(Err(e)); + } + }; + let cursor_after_tag = self.cursor + tag_len; + if cursor_after_tag > self.data.len() { + self.cursor = self.data.len(); + return Some(Err(RotoError::UnexpectedEndOfBuffer)); + } + let value_len = match skip_value(tag.wire_type, &self.data[cursor_after_tag..]) { + Ok(l) => l, + Err(e) => { + self.cursor = self.data.len(); + return Some(Err(e)); + } + }; + self.cursor = cursor_after_tag + value_len; + Some(Ok((tag.field_number, &self.data[field_start..self.cursor]))) + } +} + +#[cfg(test)] +mod tests { + use super::*; + #[cfg(feature = "alloc")] + use alloc::{vec, vec::{Vec}}; + + #[test] + fn test_varint_read_write() { + let mut buf = [0u8; 10]; + let val = 300u64; + let len = write_varint(val, &mut buf).unwrap(); + assert_eq!(len, 2); + assert_eq!(&buf[..2], &[0xAC, 0x02]); + + let (read_val, read_len) = read_varint(&buf[..2]).unwrap(); + assert_eq!(read_val, val); + assert_eq!(read_len, 2); + } + + #[test] + fn test_tag_decode() { + // Field 1, WireType Varint: (1 << 3) | 0 = 8 + let data = [8u8]; + let (tag, len) = Tag::decode(&data).unwrap(); + assert_eq!(tag.field_number, 1); + assert_eq!(tag.wire_type, WireType::Varint); + assert_eq!(len, 1); + + // Field 15, WireType LengthDelimited: (15 << 3) | 2 = 120 | 2 = 122 + let data2 = [122u8]; + let (tag2, len2) = Tag::decode(&data2).unwrap(); + assert_eq!(tag2.field_number, 15); + assert_eq!(tag2.wire_type, WireType::LengthDelimited); + assert_eq!(len2, 1); + } + + #[test] + fn test_skip_value() { + // Varint: 300 (2 bytes) + let data_varint = [0xAC, 0x02]; + assert_eq!(skip_value(WireType::Varint, &data_varint).unwrap(), 2); + + // Fixed32: 4 bytes + let data_fixed32 = [0u8; 4]; + assert_eq!(skip_value(WireType::Fixed32, &data_fixed32).unwrap(), 4); + + // Length delimited: len=3, data=[1,2,3] (1 byte varint for length + 3 bytes) + let data_len = [3, 1, 2, 3]; + assert_eq!(skip_value(WireType::LengthDelimited, &data_len).unwrap(), 4); + } + + #[test] + fn test_accessor_basic() { + // Field 1 (Varint): 150 + // Tag: (1 << 3) | 0 = 8. Value: 150 = [150, 1] + // Field 2 (LengthDelimited): "hi" + // Tag: (2 << 3) | 2 = 18. Length: 2. Value: [104, 105] + let data = [8, 150, 1, 18, 2, 104, 105]; + let acc = ProtoAccessor::new(&data).unwrap(); + + let (val1, type1) = acc.get_value(1).unwrap(); + assert_eq!(type1, WireType::Varint); + assert_eq!(val1, &[150, 1]); + + let (val2, type2) = acc.get_value(2).unwrap(); + assert_eq!(type2, WireType::LengthDelimited); + assert_eq!(val2, &[104, 105]); + } + + #[test] + fn test_accessor_repeated() { + // Field 1: 10, Field 1: 20, Field 1: 30 + // Tags: 8, 8, 8. Values: 10, 20, 30 + let data = [8, 10, 8, 20, 8, 30]; + let acc = ProtoAccessor::new(&data).unwrap(); + + // Last value should be 30 + let (val, _) = acc.get_value(1).unwrap(); + assert_eq!(val, &[30]); + + // Iteration should find all three + let results: Vec<_> = acc.iter_repeated(1).collect(); + assert_eq!(results.len(), 3); + assert_eq!(results[0].as_ref().unwrap().0, &[10]); + assert_eq!(results[1].as_ref().unwrap().0, &[20]); + assert_eq!(results[2].as_ref().unwrap().0, &[30]); + } + + #[test] + fn test_builder_basic() { + let mut buf = [0u8; 1024]; + let mut builder = ProtoBuilder::new(&mut buf); + builder.write_string(1, "hello").unwrap(); + builder.write_int32(2, 42).unwrap(); + let data = builder.finish().unwrap(); + + let acc = ProtoAccessor::new(data).unwrap(); + let (val1, _) = acc.get_value(1).unwrap(); + assert_eq!(val1, "hello".as_bytes()); + let (val2, _) = acc.get_value(2).unwrap(); + assert_eq!(val2, &[42]); + } + + #[test] + fn test_builder_overflow() { + let mut buf = [0u8; 2]; + let mut builder = ProtoBuilder::new(&mut buf); + let result = builder.write_string(1, "too long"); + assert_eq!(result, Err(RotoError::BufferOverflow)); + } + + #[test] + fn test_raw_field_iterator_yields_correct_bytes() { + // Build: field 1 = string "hi", field 2 = int32 42 + let mut buf = [0u8; 64]; + let mut builder = ProtoBuilder::new(&mut buf); + builder.write_string(1, "hi").unwrap(); + builder.write_int32(2, 42).unwrap(); + let data = builder.finish().unwrap().to_vec(); + + let acc = ProtoAccessor::new(&data).unwrap(); + let raw: Vec<_> = acc.raw_fields().collect(); + assert_eq!(raw.len(), 2); + + // Field 1: tag = (1 << 3) | 2 = 0x0A, len varint = 0x02, "hi" = [0x68, 0x69] + let (fn1, bytes1) = raw[0].as_ref().unwrap(); + assert_eq!(*fn1, 1); + assert_eq!(*bytes1, [0x0A, 0x02, b'h', b'i']); + + // Field 2: tag = (2 << 3) | 0 = 0x10, varint 42 = 0x2A + let (fn2, bytes2) = raw[1].as_ref().unwrap(); + assert_eq!(*fn2, 2); + assert_eq!(*bytes2, [0x10, 0x2A]); + } + + #[test] + fn test_write_raw_copies_field_verbatim() { + // Build source: field 1 = string "hello", field 2 = int32 99 + let mut src_buf = [0u8; 64]; + let mut src_builder = ProtoBuilder::new(&mut src_buf); + src_builder.write_string(1, "hello").unwrap(); + src_builder.write_int32(2, 99).unwrap(); + let src_data = src_builder.finish().unwrap().to_vec(); + + // Copy every raw field verbatim into a new buffer + let src_acc = ProtoAccessor::new(&src_data).unwrap(); + let mut dst_buf = [0u8; 64]; + let mut dst_builder = ProtoBuilder::new(&mut dst_buf); + for item in src_acc.raw_fields() { + let (_, raw_bytes) = item.unwrap(); + dst_builder.write_raw(raw_bytes).unwrap(); + } + let dst_data = dst_builder.finish().unwrap(); + + // The copy must be byte-identical to the source + assert_eq!(dst_data, src_data.as_slice()); + } + + #[test] + fn test_with_pattern_copies_unseen_fields() { + // Build an existing source message with 3 fields + let mut src_buf = [0u8; 128]; + let mut src_builder = ProtoBuilder::new(&mut src_buf); + src_builder.write_string(1, "original").unwrap(); + src_builder.write_int32(2, 99).unwrap(); + src_builder.write_varint(3, 1u64).unwrap(); // bool + let src_data = src_builder.finish().unwrap().to_vec(); + let src_acc = ProtoAccessor::new(&src_data).unwrap(); + + // Simulate what a generated `with` method does: + // field 1 was explicitly written; fields 2 and 3 come from source. + let field1_written = true; + let field2_written = false; + let field3_written = false; + + let mut dst_buf = [0u8; 128]; + let mut dst_builder = ProtoBuilder::new(&mut dst_buf); + dst_builder.write_string(1, "updated").unwrap(); + + for item in src_acc.raw_fields() { + let (field_number, raw_bytes) = item.unwrap(); + let is_written = match field_number { + 1 => field1_written, + 2 => field2_written, + 3 => field3_written, + _ => false, + }; + if !is_written { + dst_builder.write_raw(raw_bytes).unwrap(); + } + } + let dst_data = dst_builder.finish().unwrap(); + let dst_acc = ProtoAccessor::new(dst_data).unwrap(); + + // Field 1: overridden value + let (val1, _) = dst_acc.get_value(1).unwrap(); + assert_eq!(val1, b"updated"); + + // Field 2: copied from source + let (val2, _) = dst_acc.get_value(2).unwrap(); + let (v2, _) = read_varint(val2).unwrap(); + assert_eq!(v2 as i32, 99); + + // Field 3: copied from source + let (val3, _) = dst_acc.get_value(3).unwrap(); + let (v3, _) = read_varint(val3).unwrap(); + assert_eq!(v3, 1u64); + } + + #[test] + fn test_protoc_binary_compatibility() { + let data = include_bytes!("../data/test_data.pb"); + let acc = ProtoAccessor::new(data).unwrap(); + + // 1. Varints (Integers, Booleans, Enums) + let (val_i32, type_i32) = acc.get_value(3).expect("i32_val not found"); + assert_eq!(type_i32, WireType::Varint); + let (v, _) = read_varint(val_i32).unwrap(); + assert_eq!(v, 42); + + let (val_b, type_b) = acc.get_value(13).expect("b_val not found"); + assert_eq!(type_b, WireType::Varint); + let (v_b, _) = read_varint(val_b).unwrap(); + assert_eq!(v_b, 1); // true + + let (val_status, type_status) = acc.get_value(16).expect("status not found"); + assert_eq!(type_status, WireType::Varint); + let (v_s, _) = read_varint(val_status).unwrap(); + assert_eq!(v_s, 1); // ACTIVE + + // 2. Length Delimited (Strings, Bytes) + let (val_s, type_s) = acc.get_value(14).expect("s_val not found"); + assert_eq!(type_s, WireType::LengthDelimited); + assert_eq!(val_s, "Hello Roto!".as_bytes()); + + // 3. Fixed Width (Floats) + let (val_f, type_f) = acc.get_value(2).expect("f_val not found"); + assert_eq!(type_f, WireType::Fixed32); + let f_val = f32::from_le_bytes(val_f.try_into().expect("Expected 4 bytes for f32")); + assert!((f_val - 2.71828).abs() < 1e-5); + + // 4. Repeated Fields + // Note: primitive repeated fields are packed in proto3, so we iterate over the blob + let mut i32_vals = Vec::new(); + for item in acc.iter_repeated(17) { + let (blob, _) = item.expect("Failed to decode repeated i32"); + let mut cursor = 0; + while cursor < blob.len() { + let (v, len) = read_varint(&blob[cursor..]).unwrap(); + i32_vals.push(v); + cursor += len; + } + } + assert_eq!(i32_vals, vec![1, 2, 3, 4, 5]); + + let repeated_strings: Vec<_> = acc + .iter_repeated(18) + .map(|r| { + let (val, _) = r.expect("Failed to decode repeated string"); + core::str::from_utf8(val).expect("Invalid utf8") + }) + .collect(); + assert_eq!(repeated_strings, vec!["one", "two", "three"]); + + let repeated_nested: Vec<_> = acc + .iter_repeated(19) + .map(|r| { + let (val, _) = r.expect("Failed to decode repeated nested"); + let nested_acc = ProtoAccessor::new(val).unwrap(); + let (id_val, _) = nested_acc.get_value(1).expect("Nested id not found"); + let (id, _) = read_varint(id_val).unwrap(); + id + }) + .collect(); + assert_eq!(repeated_nested, vec![101, 102]); + + // 5. Single Nested Message + let (val_nested, type_nested) = acc.get_value(20).expect("single_nested not found"); + assert_eq!(type_nested, WireType::LengthDelimited); + let nested_acc = ProtoAccessor::new(val_nested).unwrap(); + let (val_id, _) = nested_acc.get_value(1).expect("Nested id not found"); + let (id, _) = read_varint(val_id).unwrap(); + assert_eq!(id, 200); + + // Validate that fields appear in the expected relative order + let field_numbers: Vec = acc + .fields() + .map(|r| r.expect("Failed to decode field").1.field_number) + .collect(); + + let essential_fields = [1, 2, 3, 14, 16, 20]; + let mut last_field = 0; + let mut found_count = 0; + for &f in &field_numbers { + if essential_fields.contains(&f) { + assert!( + f >= last_field, + "Fields appeared out of order: {} came after {}", + f, + last_field + ); + last_field = f; + found_count += 1; + } + } + assert_eq!(found_count, essential_fields.len()); + } +} + +pub struct ProtoBuilder<'a> { + buf: &'a mut [u8], + pos: usize, +} + +impl<'a> ProtoBuilder<'a> { + pub fn new(buf: &'a mut [u8]) -> Self { + Self { buf, pos: 0 } + } + + fn write_tag(&mut self, field_number: u32, wire_type: WireType) -> Result<()> { + let mut temp = [0u8; 10]; + let len = Tag::encode(field_number, wire_type, &mut temp)?; + self.append_bytes(&temp[..len]) + } + + fn append_bytes(&mut self, bytes: &[u8]) -> Result<()> { + if self.pos + bytes.len() > self.buf.len() { + return Err(RotoError::BufferOverflow); + } + self.buf[self.pos..self.pos + bytes.len()].copy_from_slice(bytes); + self.pos += bytes.len(); + Ok(()) + } + + pub fn write_varint(&mut self, field_number: u32, value: u64) -> Result<()> { + self.write_tag(field_number, WireType::Varint)?; + let mut temp = [0u8; 10]; + let len = write_varint(value, &mut temp)?; + self.append_bytes(&temp[..len]) + } + + pub fn write_int32(&mut self, field_number: u32, value: i32) -> Result<()> { + self.write_varint(field_number, value as u64) + } + + pub fn write_string(&mut self, field_number: u32, value: &str) -> Result<()> { + self.write_tag(field_number, WireType::LengthDelimited)?; + let bytes = value.as_bytes(); + let mut len_buf = [0u8; 10]; + let len_len = write_varint(bytes.len() as u64, &mut len_buf)?; + self.append_bytes(&len_buf[..len_len])?; + self.append_bytes(bytes) + } + + pub fn write_fixed32(&mut self, field_number: u32, value: u32) -> Result<()> { + self.write_tag(field_number, WireType::Fixed32)?; + self.append_bytes(&value.to_le_bytes()) + } + + pub fn write_fixed64(&mut self, field_number: u32, value: u64) -> Result<()> { + self.write_tag(field_number, WireType::Fixed64)?; + self.append_bytes(&value.to_le_bytes()) + } + + pub fn write_bytes(&mut self, field_number: u32, value: &[u8]) -> Result<()> { + self.write_tag(field_number, WireType::LengthDelimited)?; + let mut len_buf = [0u8; 10]; + let len_len = write_varint(value.len() as u64, &mut len_buf)?; + self.append_bytes(&len_buf[..len_len])?; + self.append_bytes(value) + } + + /// Appends a pre-encoded field (tag + value bytes) verbatim into the + /// buffer. Use this together with `ProtoAccessor::raw_fields` to copy + /// fields from an existing message into a builder without re-encoding them. + pub fn write_raw(&mut self, raw_bytes: &[u8]) -> Result<()> { + self.append_bytes(raw_bytes) + } + + pub fn write_map_entry( + &mut self, + field_number: u32, + key_encoded: &[u8], + value_encoded: &[u8], + ) -> Result<()> { + let entry_len = key_encoded.len() + value_encoded.len(); + self.write_tag(field_number, WireType::LengthDelimited)?; + + let mut len_buf = [0u8; 10]; + let len_len = write_varint(entry_len as u64, &mut len_buf)?; + self.append_bytes(&len_buf[..len_len])?; + + self.append_bytes(key_encoded)?; + self.append_bytes(value_encoded)?; + Ok(()) + } + + pub fn finish(self) -> Result<&'a mut [u8]> { + Ok(&mut self.buf[..self.pos]) + } +} + +pub struct BufMutBuilder<'a, B: BufMut> { + buf: &'a mut B, +} + +impl<'a, B: BufMut> BufMutBuilder<'a, B> { + pub fn new(buf: &'a mut B) -> Self { + Self { buf } + } + + fn write_tag(&mut self, field_number: u32, wire_type: WireType) -> Result<()> { + let mut temp = [0u8; 10]; + let len = Tag::encode(field_number, wire_type, &mut temp)?; + self.buf.put_slice(&temp[..len]); + Ok(()) + } + + pub fn write_varint(&mut self, field_number: u32, value: u64) -> Result<()> { + self.write_tag(field_number, WireType::Varint)?; + let mut temp = [0u8; 10]; + let len = write_varint(value, &mut temp)?; + self.buf.put_slice(&temp[..len]); + Ok(()) + } + + pub fn write_int32(&mut self, field_number: u32, value: i32) -> Result<()> { + self.write_varint(field_number, value as u64) + } + + pub fn write_string(&mut self, field_number: u32, value: &str) -> Result<()> { + self.write_tag(field_number, WireType::LengthDelimited)?; + let bytes = value.as_bytes(); + let mut len_buf = [0u8; 10]; + let len_len = write_varint(bytes.len() as u64, &mut len_buf)?; + self.buf.put_slice(&len_buf[..len_len]); + self.buf.put_slice(bytes); + Ok(()) + } + + pub fn write_fixed32(&mut self, field_number: u32, value: u32) -> Result<()> { + self.write_tag(field_number, WireType::Fixed32)?; + self.buf.put_slice(&value.to_le_bytes()); + Ok(()) + } + + pub fn write_fixed64(&mut self, field_number: u32, value: u64) -> Result<()> { + self.write_tag(field_number, WireType::Fixed64)?; + self.buf.put_slice(&value.to_le_bytes()); + Ok(()) + } + + pub fn write_bytes(&mut self, field_number: u32, value: &[u8]) -> Result<()> { + self.write_tag(field_number, WireType::LengthDelimited)?; + let mut len_buf = [0u8; 10]; + let len_len = write_varint(value.len() as u64, &mut len_buf)?; + self.buf.put_slice(&len_buf[..len_len]); + self.buf.put_slice(value); + Ok(()) + } + + pub fn write_raw(&mut self, raw_bytes: &[u8]) -> Result<()> { + self.buf.put_slice(raw_bytes); + Ok(()) + } + + pub fn write_map_entry( + &mut self, + field_number: u32, + key_encoded: &[u8], + value_encoded: &[u8], + ) -> Result<()> { + let entry_len = key_encoded.len() + value_encoded.len(); + self.write_tag(field_number, WireType::LengthDelimited)?; + + let mut len_buf = [0u8; 10]; + let len_len = write_varint(entry_len as u64, &mut len_buf)?; + self.buf.put_slice(&len_buf[..len_len]); + + self.buf.put_slice(key_encoded); + self.buf.put_slice(value_encoded); + Ok(()) + } +}