// @generated by protoc-gen-roto — do not edit
#[allow(unused_imports)]

use roto_runtime::{ProtoAccessor, ProtoBuilder, Result, RotoError, read_varint, RepeatedFieldIterator};
use std::str;
use bytes::{Bytes, BytesMut, Buf, BufMut};
use tonic::{Request, Response, Status};
use tokio_stream::Stream;
use std::pin::Pin;
use std::sync::Arc;
use std::task::{Context, Poll};
use std::future::Future;
use tonic::body::BoxBody;
use tower::Service;
use futures_util::StreamExt;
use http_body_util::BodyExt;
use http_body::Body;
use roto_tonic::{BufferPool, StatusBody};


#[derive(Debug, Clone, Copy, PartialEq, Eq)]
#[repr(i32)]
pub enum Edition {
    EDITIONUNKNOWN = 0,
    EDITIONLEGACY = 900,
    EDITIONPROTO2 = 998,
    EDITIONPROTO3 = 999,
    EDITION2023 = 1000,
    EDITION2024 = 1001,
    EDITION2026 = 1002,
    EDITIONUNSTABLE = 9999,
    EDITION1TESTONLY = 1,
    EDITION2TESTONLY = 2,
    EDITION99997TESTONLY = 99997,
    EDITION99998TESTONLY = 99998,
    EDITION99999TESTONLY = 99999,
    EDITIONMAX = 2147483647,
}

impl Edition {
    pub fn from_i32(value: i32) -> Self {
        match value {
            0 => Edition::EDITIONUNKNOWN,
            900 => Edition::EDITIONLEGACY,
            998 => Edition::EDITIONPROTO2,
            999 => Edition::EDITIONPROTO3,
            1000 => Edition::EDITION2023,
            1001 => Edition::EDITION2024,
            1002 => Edition::EDITION2026,
            9999 => Edition::EDITIONUNSTABLE,
            1 => Edition::EDITION1TESTONLY,
            2 => Edition::EDITION2TESTONLY,
            99997 => Edition::EDITION99997TESTONLY,
            99998 => Edition::EDITION99998TESTONLY,
            99999 => Edition::EDITION99999TESTONLY,
            2147483647 => Edition::EDITIONMAX,
            _ => Edition::EDITIONUNKNOWN,
        }
    }
}

#[derive(Debug, Clone, Copy, PartialEq, Eq)]
#[repr(i32)]
pub enum SymbolVisibility {
    VISIBILITYUNSET = 0,
    VISIBILITYLOCAL = 1,
    VISIBILITYEXPORT = 2,
}

impl SymbolVisibility {
    pub fn from_i32(value: i32) -> Self {
        match value {
            0 => SymbolVisibility::VISIBILITYUNSET,
            1 => SymbolVisibility::VISIBILITYLOCAL,
            2 => SymbolVisibility::VISIBILITYEXPORT,
            _ => SymbolVisibility::VISIBILITYUNSET,
        }
    }
}

pub struct FileDescriptorSet<'a> {
    accessor: roto_runtime::ProtoAccessor<'a>,
    file_start: Option<usize>,
    file_end: Option<usize>,
}

impl<'a> FileDescriptorSet<'a> {
    pub fn new(data: &'a [u8]) -> roto_runtime::Result<Self> {
        let accessor = roto_runtime::ProtoAccessor::new(data)?;
        let mut file_start = None;
        let mut file_end = None;
        for item in accessor.fields() {
            let (offset, tag, _) = item?;
            if tag.field_number == 1 {
                if file_start.is_none() { file_start = Some(offset); }
                file_end = Some(offset);
            }
        }

        Ok(Self {
            accessor,
file_start, file_end,
        })
    }

    pub fn file(&self) -> roto_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> {
        self.accessor.raw_fields()
    }

}

pub struct FileDescriptorSetBuilder<'b> {
    builder: roto_runtime::ProtoBuilder<'b>,
    file_written: bool,
}

impl<'b> FileDescriptorSetBuilder<'b> {
    pub fn builder(buf: &mut [u8]) -> FileDescriptorSetBuilder<'_> {
        FileDescriptorSetBuilder {
            builder: roto_runtime::ProtoBuilder::new(buf),
            file_written: false,
        }
    }

    pub fn file(mut self, value: &[u8]) -> roto_runtime::Result<Self> {
        self.builder.write_bytes(1, value)?;
        self.file_written = true;
        Ok(self)
    }

    pub fn with(mut self, msg: &FileDescriptorSet<'_>) -> roto_runtime::Result<Self> {
        for item in msg.raw_fields() {
            let (field_number, raw_bytes) = item?;
            let is_written = match field_number {
                1 => self.file_written,
                _ => false,
            };
            if !is_written {
                self.builder.write_raw(raw_bytes)?;
            }
        }
        Ok(self)
    }

    pub fn finish(self) -> roto_runtime::Result<&'b mut [u8]> {
        self.builder.finish()
    }
}

pub struct OwnedFileDescriptorSet {
    pub data: bytes::Bytes,
}

impl roto_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<Self> {
        Ok(OwnedFileDescriptorSet { data: buf })
    }

    fn bytes(&self) -> bytes::Bytes {
        self.data.clone()
    }
}

pub struct FileDescriptorProto<'a> {
    accessor: roto_runtime::ProtoAccessor<'a>,
    name_offset: Option<usize>,
    package_offset: Option<usize>,
    dependency_start: Option<usize>,
    dependency_end: Option<usize>,
    public_dependency_start: Option<usize>,
    public_dependency_end: Option<usize>,
    weak_dependency_start: Option<usize>,
    weak_dependency_end: Option<usize>,
    option_dependency_start: Option<usize>,
    option_dependency_end: Option<usize>,
    message_type_start: Option<usize>,
    message_type_end: Option<usize>,
    enum_type_start: Option<usize>,
    enum_type_end: Option<usize>,
    service_start: Option<usize>,
    service_end: Option<usize>,
    extension_start: Option<usize>,
    extension_end: Option<usize>,
    options_offset: Option<usize>,
    source_code_info_offset: Option<usize>,
    syntax_offset: Option<usize>,
    edition_offset: Option<usize>,
}

impl<'a> FileDescriptorProto<'a> {
    pub fn new(data: &'a [u8]) -> roto_runtime::Result<Self> {
        let accessor = roto_runtime::ProtoAccessor::new(data)?;
        let mut name_offset = None;
        let mut package_offset = None;
        let mut dependency_start = None;
        let mut dependency_end = None;
        let mut public_dependency_start = None;
        let mut public_dependency_end = None;
        let mut weak_dependency_start = None;
        let mut weak_dependency_end = None;
        let mut option_dependency_start = None;
        let mut option_dependency_end = None;
        let mut message_type_start = None;
        let mut message_type_end = None;
        let mut enum_type_start = None;
        let mut enum_type_end = None;
        let mut service_start = None;
        let mut service_end = None;
        let mut extension_start = None;
        let mut extension_end = None;
        let mut options_offset = None;
        let mut source_code_info_offset = None;
        let mut syntax_offset = None;
        let mut edition_offset = None;
        for item in accessor.fields() {
            let (offset, tag, _) = item?;
            if tag.field_number == 1 { name_offset = Some(offset); }
            if tag.field_number == 2 { package_offset = Some(offset); }
            if tag.field_number == 3 {
                if dependency_start.is_none() { dependency_start = Some(offset); }
                dependency_end = Some(offset);
            }
            if tag.field_number == 10 {
                if public_dependency_start.is_none() { public_dependency_start = Some(offset); }
                public_dependency_end = Some(offset);
            }
            if tag.field_number == 11 {
                if weak_dependency_start.is_none() { weak_dependency_start = Some(offset); }
                weak_dependency_end = Some(offset);
            }
            if tag.field_number == 15 {
                if option_dependency_start.is_none() { option_dependency_start = Some(offset); }
                option_dependency_end = Some(offset);
            }
            if tag.field_number == 4 {
                if message_type_start.is_none() { message_type_start = Some(offset); }
                message_type_end = Some(offset);
            }
            if tag.field_number == 5 {
                if enum_type_start.is_none() { enum_type_start = Some(offset); }
                enum_type_end = Some(offset);
            }
            if tag.field_number == 6 {
                if service_start.is_none() { service_start = Some(offset); }
                service_end = Some(offset);
            }
            if tag.field_number == 7 {
                if extension_start.is_none() { extension_start = Some(offset); }
                extension_end = Some(offset);
            }
            if tag.field_number == 8 { options_offset = Some(offset); }
            if tag.field_number == 9 { source_code_info_offset = Some(offset); }
            if tag.field_number == 12 { syntax_offset = Some(offset); }
            if tag.field_number == 14 { edition_offset = Some(offset); }
        }

        Ok(Self {
            accessor,
name_offset,
package_offset,
dependency_start, dependency_end,
public_dependency_start, public_dependency_end,
weak_dependency_start, weak_dependency_end,
option_dependency_start, option_dependency_end,
message_type_start, message_type_end,
enum_type_start, enum_type_end,
service_start, service_end,
extension_start, extension_end,
options_offset,
source_code_info_offset,
syntax_offset,
edition_offset,
        })
    }

    pub fn name(&self) -> roto_runtime::Result<&'a str> {
        let offset = self.name_offset.ok_or(roto_runtime::RotoError::FieldNotFound)?;
        let (bytes, _) = self.accessor.get_value_at(offset)?;
        str::from_utf8(bytes).map_err(|_| roto_runtime::RotoError::WireFormatViolation)
    }

    pub fn name_or_default(&self) -> roto_runtime::Result<&'a str> {
        self.name().or(Ok(""))
    }

    pub fn has_name(&self) -> bool { self.name_offset.is_some() }

    pub fn package(&self) -> roto_runtime::Result<&'a str> {
        let offset = self.package_offset.ok_or(roto_runtime::RotoError::FieldNotFound)?;
        let (bytes, _) = self.accessor.get_value_at(offset)?;
        str::from_utf8(bytes).map_err(|_| roto_runtime::RotoError::WireFormatViolation)
    }

    pub fn package_or_default(&self) -> roto_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> {
        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> {
        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> {
        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> {
        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> {
        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> {
        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> {
        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> {
        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)?;
        let (bytes, _) = self.accessor.get_value_at(offset)?;
        Ok(bytes)
    }

    pub fn options_or_default(&self) -> roto_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)?;
        let (bytes, _) = self.accessor.get_value_at(offset)?;
        Ok(bytes)
    }

    pub fn source_code_info_or_default(&self) -> roto_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)?;
        let (bytes, _) = self.accessor.get_value_at(offset)?;
        str::from_utf8(bytes).map_err(|_| roto_runtime::RotoError::WireFormatViolation)
    }

    pub fn syntax_or_default(&self) -> roto_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<u64> {
        let offset = self.edition_offset.ok_or(roto_runtime::RotoError::FieldNotFound)?;
        let (bytes, _) = self.accessor.get_value_at(offset)?;
        roto_runtime::read_varint(bytes).map(|(v, _)| v as u64).map_err(|_| roto_runtime::RotoError::WireFormatViolation)
    }

    pub fn edition_or_default(&self) -> roto_runtime::Result<u64> {
        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> {
        self.accessor.raw_fields()
    }

}

pub struct FileDescriptorProtoBuilder<'b> {
    builder: roto_runtime::ProtoBuilder<'b>,
    name_written: bool,
    package_written: bool,
    dependency_written: bool,
    public_dependency_written: bool,
    weak_dependency_written: bool,
    option_dependency_written: bool,
    message_type_written: bool,
    enum_type_written: bool,
    service_written: bool,
    extension_written: bool,
    options_written: bool,
    source_code_info_written: bool,
    syntax_written: bool,
    edition_written: bool,
}

impl<'b> FileDescriptorProtoBuilder<'b> {
    pub fn builder(buf: &mut [u8]) -> FileDescriptorProtoBuilder<'_> {
        FileDescriptorProtoBuilder {
            builder: roto_runtime::ProtoBuilder::new(buf),
            name_written: false,
            package_written: false,
            dependency_written: false,
            public_dependency_written: false,
            weak_dependency_written: false,
            option_dependency_written: false,
            message_type_written: false,
            enum_type_written: false,
            service_written: false,
            extension_written: false,
            options_written: false,
            source_code_info_written: false,
            syntax_written: false,
            edition_written: false,
        }
    }

    pub fn name(mut self, value: &str) -> roto_runtime::Result<Self> {
        self.builder.write_string(1, value)?;
        self.name_written = true;
        Ok(self)
    }

    pub fn package(mut self, value: &str) -> roto_runtime::Result<Self> {
        self.builder.write_string(2, value)?;
        self.package_written = true;
        Ok(self)
    }

    pub fn dependency(mut self, value: &str) -> roto_runtime::Result<Self> {
        self.builder.write_string(3, value)?;
        self.dependency_written = true;
        Ok(self)
    }

    pub fn public_dependency(mut self, value: i32) -> roto_runtime::Result<Self> {
        self.builder.write_int32(10, value)?;
        self.public_dependency_written = true;
        Ok(self)
    }

    pub fn weak_dependency(mut self, value: i32) -> roto_runtime::Result<Self> {
        self.builder.write_int32(11, value)?;
        self.weak_dependency_written = true;
        Ok(self)
    }

    pub fn option_dependency(mut self, value: &str) -> roto_runtime::Result<Self> {
        self.builder.write_string(15, value)?;
        self.option_dependency_written = true;
        Ok(self)
    }

    pub fn message_type(mut self, value: &[u8]) -> roto_runtime::Result<Self> {
        self.builder.write_bytes(4, value)?;
        self.message_type_written = true;
        Ok(self)
    }

    pub fn enum_type(mut self, value: &[u8]) -> roto_runtime::Result<Self> {
        self.builder.write_bytes(5, value)?;
        self.enum_type_written = true;
        Ok(self)
    }

    pub fn service(mut self, value: &[u8]) -> roto_runtime::Result<Self> {
        self.builder.write_bytes(6, value)?;
        self.service_written = true;
        Ok(self)
    }

    pub fn extension(mut self, value: &[u8]) -> roto_runtime::Result<Self> {
        self.builder.write_bytes(7, value)?;
        self.extension_written = true;
        Ok(self)
    }

    pub fn options(mut self, value: &[u8]) -> roto_runtime::Result<Self> {
        self.builder.write_bytes(8, value)?;
        self.options_written = true;
        Ok(self)
    }

    pub fn source_code_info(mut self, value: &[u8]) -> roto_runtime::Result<Self> {
        self.builder.write_bytes(9, value)?;
        self.source_code_info_written = true;
        Ok(self)
    }

    pub fn syntax(mut self, value: &str) -> roto_runtime::Result<Self> {
        self.builder.write_string(12, value)?;
        self.syntax_written = true;
        Ok(self)
    }

    pub fn edition(mut self, value: u64) -> roto_runtime::Result<Self> {
        self.builder.write_varint(14, value)?;
        self.edition_written = true;
        Ok(self)
    }

    pub fn with(mut self, msg: &FileDescriptorProto<'_>) -> roto_runtime::Result<Self> {
        for item in msg.raw_fields() {
            let (field_number, raw_bytes) = item?;
            let is_written = match field_number {
                1 => self.name_written,
                2 => self.package_written,
                3 => self.dependency_written,
                10 => self.public_dependency_written,
                11 => self.weak_dependency_written,
                15 => self.option_dependency_written,
                4 => self.message_type_written,
                5 => self.enum_type_written,
                6 => self.service_written,
                7 => self.extension_written,
                8 => self.options_written,
                9 => self.source_code_info_written,
                12 => self.syntax_written,
                14 => self.edition_written,
                _ => false,
            };
            if !is_written {
                self.builder.write_raw(raw_bytes)?;
            }
        }
        Ok(self)
    }

    pub fn finish(self) -> roto_runtime::Result<&'b mut [u8]> {
        self.builder.finish()
    }
}

pub struct OwnedFileDescriptorProto {
    pub data: bytes::Bytes,
}

impl roto_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<Self> {
        Ok(OwnedFileDescriptorProto { data: buf })
    }

    fn bytes(&self) -> bytes::Bytes {
        self.data.clone()
    }
}

pub struct DescriptorProto<'a> {
    accessor: roto_runtime::ProtoAccessor<'a>,
    name_offset: Option<usize>,
    field_start: Option<usize>,
    field_end: Option<usize>,
    extension_start: Option<usize>,
    extension_end: Option<usize>,
    nested_type_start: Option<usize>,
    nested_type_end: Option<usize>,
    enum_type_start: Option<usize>,
    enum_type_end: Option<usize>,
    extension_range_start: Option<usize>,
    extension_range_end: Option<usize>,
    oneof_decl_start: Option<usize>,
    oneof_decl_end: Option<usize>,
    options_offset: Option<usize>,
    reserved_range_start: Option<usize>,
    reserved_range_end: Option<usize>,
    reserved_name_start: Option<usize>,
    reserved_name_end: Option<usize>,
    visibility_offset: Option<usize>,
}

impl<'a> DescriptorProto<'a> {
    pub fn new(data: &'a [u8]) -> roto_runtime::Result<Self> {
        let accessor = roto_runtime::ProtoAccessor::new(data)?;
        let mut name_offset = None;
        let mut field_start = None;
        let mut field_end = None;
        let mut extension_start = None;
        let mut extension_end = None;
        let mut nested_type_start = None;
        let mut nested_type_end = None;
        let mut enum_type_start = None;
        let mut enum_type_end = None;
        let mut extension_range_start = None;
        let mut extension_range_end = None;
        let mut oneof_decl_start = None;
        let mut oneof_decl_end = None;
        let mut options_offset = None;
        let mut reserved_range_start = None;
        let mut reserved_range_end = None;
        let mut reserved_name_start = None;
        let mut reserved_name_end = None;
        let mut visibility_offset = None;
        for item in accessor.fields() {
            let (offset, tag, _) = item?;
            if tag.field_number == 1 { name_offset = Some(offset); }
            if tag.field_number == 2 {
                if field_start.is_none() { field_start = Some(offset); }
                field_end = Some(offset);
            }
            if tag.field_number == 6 {
                if extension_start.is_none() { extension_start = Some(offset); }
                extension_end = Some(offset);
            }
            if tag.field_number == 3 {
                if nested_type_start.is_none() { nested_type_start = Some(offset); }
                nested_type_end = Some(offset);
            }
            if tag.field_number == 4 {
                if enum_type_start.is_none() { enum_type_start = Some(offset); }
                enum_type_end = Some(offset);
            }
            if tag.field_number == 5 {
                if extension_range_start.is_none() { extension_range_start = Some(offset); }
                extension_range_end = Some(offset);
            }
            if tag.field_number == 8 {
                if oneof_decl_start.is_none() { oneof_decl_start = Some(offset); }
                oneof_decl_end = Some(offset);
            }
            if tag.field_number == 7 { options_offset = Some(offset); }
            if tag.field_number == 9 {
                if reserved_range_start.is_none() { reserved_range_start = Some(offset); }
                reserved_range_end = Some(offset);
            }
            if tag.field_number == 10 {
                if reserved_name_start.is_none() { reserved_name_start = Some(offset); }
                reserved_name_end = Some(offset);
            }
            if tag.field_number == 11 { visibility_offset = Some(offset); }
        }

        Ok(Self {
            accessor,
name_offset,
field_start, field_end,
extension_start, extension_end,
nested_type_start, nested_type_end,
enum_type_start, enum_type_end,
extension_range_start, extension_range_end,
oneof_decl_start, oneof_decl_end,
options_offset,
reserved_range_start, reserved_range_end,
reserved_name_start, reserved_name_end,
visibility_offset,
        })
    }

    pub fn name(&self) -> roto_runtime::Result<&'a str> {
        let offset = self.name_offset.ok_or(roto_runtime::RotoError::FieldNotFound)?;
        let (bytes, _) = self.accessor.get_value_at(offset)?;
        str::from_utf8(bytes).map_err(|_| roto_runtime::RotoError::WireFormatViolation)
    }

    pub fn name_or_default(&self) -> roto_runtime::Result<&'a str> {
        self.name().or(Ok(""))
    }

    pub fn has_name(&self) -> bool { self.name_offset.is_some() }

    pub fn field(&self) -> roto_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> {
        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> {
        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> {
        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> {
        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> {
        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)?;
        let (bytes, _) = self.accessor.get_value_at(offset)?;
        Ok(bytes)
    }

    pub fn options_or_default(&self) -> roto_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> {
        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> {
        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<u64> {
        let offset = self.visibility_offset.ok_or(roto_runtime::RotoError::FieldNotFound)?;
        let (bytes, _) = self.accessor.get_value_at(offset)?;
        roto_runtime::read_varint(bytes).map(|(v, _)| v as u64).map_err(|_| roto_runtime::RotoError::WireFormatViolation)
    }

    pub fn visibility_or_default(&self) -> roto_runtime::Result<u64> {
        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> {
        self.accessor.raw_fields()
    }

}

pub struct DescriptorProtoBuilder<'b> {
    builder: roto_runtime::ProtoBuilder<'b>,
    name_written: bool,
    field_written: bool,
    extension_written: bool,
    nested_type_written: bool,
    enum_type_written: bool,
    extension_range_written: bool,
    oneof_decl_written: bool,
    options_written: bool,
    reserved_range_written: bool,
    reserved_name_written: bool,
    visibility_written: bool,
}

impl<'b> DescriptorProtoBuilder<'b> {
    pub fn builder(buf: &mut [u8]) -> DescriptorProtoBuilder<'_> {
        DescriptorProtoBuilder {
            builder: roto_runtime::ProtoBuilder::new(buf),
            name_written: false,
            field_written: false,
            extension_written: false,
            nested_type_written: false,
            enum_type_written: false,
            extension_range_written: false,
            oneof_decl_written: false,
            options_written: false,
            reserved_range_written: false,
            reserved_name_written: false,
            visibility_written: false,
        }
    }

    pub fn name(mut self, value: &str) -> roto_runtime::Result<Self> {
        self.builder.write_string(1, value)?;
        self.name_written = true;
        Ok(self)
    }

    pub fn field(mut self, value: &[u8]) -> roto_runtime::Result<Self> {
        self.builder.write_bytes(2, value)?;
        self.field_written = true;
        Ok(self)
    }

    pub fn extension(mut self, value: &[u8]) -> roto_runtime::Result<Self> {
        self.builder.write_bytes(6, value)?;
        self.extension_written = true;
        Ok(self)
    }

    pub fn nested_type(mut self, value: &[u8]) -> roto_runtime::Result<Self> {
        self.builder.write_bytes(3, value)?;
        self.nested_type_written = true;
        Ok(self)
    }

    pub fn enum_type(mut self, value: &[u8]) -> roto_runtime::Result<Self> {
        self.builder.write_bytes(4, value)?;
        self.enum_type_written = true;
        Ok(self)
    }

    pub fn extension_range(mut self, value: &[u8]) -> roto_runtime::Result<Self> {
        self.builder.write_bytes(5, value)?;
        self.extension_range_written = true;
        Ok(self)
    }

    pub fn oneof_decl(mut self, value: &[u8]) -> roto_runtime::Result<Self> {
        self.builder.write_bytes(8, value)?;
        self.oneof_decl_written = true;
        Ok(self)
    }

    pub fn options(mut self, value: &[u8]) -> roto_runtime::Result<Self> {
        self.builder.write_bytes(7, value)?;
        self.options_written = true;
        Ok(self)
    }

    pub fn reserved_range(mut self, value: &[u8]) -> roto_runtime::Result<Self> {
        self.builder.write_bytes(9, value)?;
        self.reserved_range_written = true;
        Ok(self)
    }

    pub fn reserved_name(mut self, value: &str) -> roto_runtime::Result<Self> {
        self.builder.write_string(10, value)?;
        self.reserved_name_written = true;
        Ok(self)
    }

    pub fn visibility(mut self, value: u64) -> roto_runtime::Result<Self> {
        self.builder.write_varint(11, value)?;
        self.visibility_written = true;
        Ok(self)
    }

    pub fn with(mut self, msg: &DescriptorProto<'_>) -> roto_runtime::Result<Self> {
        for item in msg.raw_fields() {
            let (field_number, raw_bytes) = item?;
            let is_written = match field_number {
                1 => self.name_written,
                2 => self.field_written,
                6 => self.extension_written,
                3 => self.nested_type_written,
                4 => self.enum_type_written,
                5 => self.extension_range_written,
                8 => self.oneof_decl_written,
                7 => self.options_written,
                9 => self.reserved_range_written,
                10 => self.reserved_name_written,
                11 => self.visibility_written,
                _ => false,
            };
            if !is_written {
                self.builder.write_raw(raw_bytes)?;
            }
        }
        Ok(self)
    }

    pub fn finish(self) -> roto_runtime::Result<&'b mut [u8]> {
        self.builder.finish()
    }
}

pub struct OwnedDescriptorProto {
    pub data: bytes::Bytes,
}

impl roto_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<Self> {
        Ok(OwnedDescriptorProto { data: buf })
    }

    fn bytes(&self) -> bytes::Bytes {
        self.data.clone()
    }
}

pub mod descriptor_proto {
pub struct ExtensionRange<'a> {
    accessor: roto_runtime::ProtoAccessor<'a>,
    start_offset: Option<usize>,
    end_offset: Option<usize>,
    options_offset: Option<usize>,
}

impl<'a> ExtensionRange<'a> {
    pub fn new(data: &'a [u8]) -> roto_runtime::Result<Self> {
        let accessor = roto_runtime::ProtoAccessor::new(data)?;
        let mut start_offset = None;
        let mut end_offset = None;
        let mut options_offset = None;
        for item in accessor.fields() {
            let (offset, tag, _) = item?;
            if tag.field_number == 1 { start_offset = Some(offset); }
            if tag.field_number == 2 { end_offset = Some(offset); }
            if tag.field_number == 3 { options_offset = Some(offset); }
        }

        Ok(Self {
            accessor,
start_offset,
end_offset,
options_offset,
        })
    }

    pub fn start(&self) -> roto_runtime::Result<i32> {
        let offset = self.start_offset.ok_or(roto_runtime::RotoError::FieldNotFound)?;
        let (bytes, _) = self.accessor.get_value_at(offset)?;
        roto_runtime::read_varint(bytes).map(|(v, _)| v as i32).map_err(|_| roto_runtime::RotoError::WireFormatViolation)
    }

    pub fn start_or_default(&self) -> roto_runtime::Result<i32> {
        self.start().or(Ok(0))
    }

    pub fn has_start(&self) -> bool { self.start_offset.is_some() }

    pub fn end(&self) -> roto_runtime::Result<i32> {
        let offset = self.end_offset.ok_or(roto_runtime::RotoError::FieldNotFound)?;
        let (bytes, _) = self.accessor.get_value_at(offset)?;
        roto_runtime::read_varint(bytes).map(|(v, _)| v as i32).map_err(|_| roto_runtime::RotoError::WireFormatViolation)
    }

    pub fn end_or_default(&self) -> roto_runtime::Result<i32> {
        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)?;
        let (bytes, _) = self.accessor.get_value_at(offset)?;
        Ok(bytes)
    }

    pub fn options_or_default(&self) -> roto_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> {
        self.accessor.raw_fields()
    }

}

pub struct ExtensionRangeBuilder<'b> {
    builder: roto_runtime::ProtoBuilder<'b>,
    start_written: bool,
    end_written: bool,
    options_written: bool,
}

impl<'b> ExtensionRangeBuilder<'b> {
    pub fn builder(buf: &mut [u8]) -> ExtensionRangeBuilder<'_> {
        ExtensionRangeBuilder {
            builder: roto_runtime::ProtoBuilder::new(buf),
            start_written: false,
            end_written: false,
            options_written: false,
        }
    }

    pub fn start(mut self, value: i32) -> roto_runtime::Result<Self> {
        self.builder.write_int32(1, value)?;
        self.start_written = true;
        Ok(self)
    }

    pub fn end(mut self, value: i32) -> roto_runtime::Result<Self> {
        self.builder.write_int32(2, value)?;
        self.end_written = true;
        Ok(self)
    }

    pub fn options(mut self, value: &[u8]) -> roto_runtime::Result<Self> {
        self.builder.write_bytes(3, value)?;
        self.options_written = true;
        Ok(self)
    }

    pub fn with(mut self, msg: &ExtensionRange<'_>) -> roto_runtime::Result<Self> {
        for item in msg.raw_fields() {
            let (field_number, raw_bytes) = item?;
            let is_written = match field_number {
                1 => self.start_written,
                2 => self.end_written,
                3 => self.options_written,
                _ => false,
            };
            if !is_written {
                self.builder.write_raw(raw_bytes)?;
            }
        }
        Ok(self)
    }

    pub fn finish(self) -> roto_runtime::Result<&'b mut [u8]> {
        self.builder.finish()
    }
}

pub struct OwnedExtensionRange {
    pub data: bytes::Bytes,
}

impl roto_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<Self> {
        Ok(OwnedExtensionRange { data: buf })
    }

    fn bytes(&self) -> bytes::Bytes {
        self.data.clone()
    }
}

pub struct ReservedRange<'a> {
    accessor: roto_runtime::ProtoAccessor<'a>,
    start_offset: Option<usize>,
    end_offset: Option<usize>,
}

impl<'a> ReservedRange<'a> {
    pub fn new(data: &'a [u8]) -> roto_runtime::Result<Self> {
        let accessor = roto_runtime::ProtoAccessor::new(data)?;
        let mut start_offset = None;
        let mut end_offset = None;
        for item in accessor.fields() {
            let (offset, tag, _) = item?;
            if tag.field_number == 1 { start_offset = Some(offset); }
            if tag.field_number == 2 { end_offset = Some(offset); }
        }

        Ok(Self {
            accessor,
start_offset,
end_offset,
        })
    }

    pub fn start(&self) -> roto_runtime::Result<i32> {
        let offset = self.start_offset.ok_or(roto_runtime::RotoError::FieldNotFound)?;
        let (bytes, _) = self.accessor.get_value_at(offset)?;
        roto_runtime::read_varint(bytes).map(|(v, _)| v as i32).map_err(|_| roto_runtime::RotoError::WireFormatViolation)
    }

    pub fn start_or_default(&self) -> roto_runtime::Result<i32> {
        self.start().or(Ok(0))
    }

    pub fn has_start(&self) -> bool { self.start_offset.is_some() }

    pub fn end(&self) -> roto_runtime::Result<i32> {
        let offset = self.end_offset.ok_or(roto_runtime::RotoError::FieldNotFound)?;
        let (bytes, _) = self.accessor.get_value_at(offset)?;
        roto_runtime::read_varint(bytes).map(|(v, _)| v as i32).map_err(|_| roto_runtime::RotoError::WireFormatViolation)
    }

    pub fn end_or_default(&self) -> roto_runtime::Result<i32> {
        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> {
        self.accessor.raw_fields()
    }

}

pub struct ReservedRangeBuilder<'b> {
    builder: roto_runtime::ProtoBuilder<'b>,
    start_written: bool,
    end_written: bool,
}

impl<'b> ReservedRangeBuilder<'b> {
    pub fn builder(buf: &mut [u8]) -> ReservedRangeBuilder<'_> {
        ReservedRangeBuilder {
            builder: roto_runtime::ProtoBuilder::new(buf),
            start_written: false,
            end_written: false,
        }
    }

    pub fn start(mut self, value: i32) -> roto_runtime::Result<Self> {
        self.builder.write_int32(1, value)?;
        self.start_written = true;
        Ok(self)
    }

    pub fn end(mut self, value: i32) -> roto_runtime::Result<Self> {
        self.builder.write_int32(2, value)?;
        self.end_written = true;
        Ok(self)
    }

    pub fn with(mut self, msg: &ReservedRange<'_>) -> roto_runtime::Result<Self> {
        for item in msg.raw_fields() {
            let (field_number, raw_bytes) = item?;
            let is_written = match field_number {
                1 => self.start_written,
                2 => self.end_written,
                _ => false,
            };
            if !is_written {
                self.builder.write_raw(raw_bytes)?;
            }
        }
        Ok(self)
    }

    pub fn finish(self) -> roto_runtime::Result<&'b mut [u8]> {
        self.builder.finish()
    }
}

pub struct OwnedReservedRange {
    pub data: bytes::Bytes,
}

impl roto_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<Self> {
        Ok(OwnedReservedRange { data: buf })
    }

    fn bytes(&self) -> bytes::Bytes {
        self.data.clone()
    }
}

}

pub struct ExtensionRangeOptions<'a> {
    accessor: roto_runtime::ProtoAccessor<'a>,
    uninterpreted_option_start: Option<usize>,
    uninterpreted_option_end: Option<usize>,
    declaration_start: Option<usize>,
    declaration_end: Option<usize>,
    features_offset: Option<usize>,
    verification_offset: Option<usize>,
}

impl<'a> ExtensionRangeOptions<'a> {
    pub fn new(data: &'a [u8]) -> roto_runtime::Result<Self> {
        let accessor = roto_runtime::ProtoAccessor::new(data)?;
        let mut uninterpreted_option_start = None;
        let mut uninterpreted_option_end = None;
        let mut declaration_start = None;
        let mut declaration_end = None;
        let mut features_offset = None;
        let mut verification_offset = None;
        for item in accessor.fields() {
            let (offset, tag, _) = item?;
            if tag.field_number == 999 {
                if uninterpreted_option_start.is_none() { uninterpreted_option_start = Some(offset); }
                uninterpreted_option_end = Some(offset);
            }
            if tag.field_number == 2 {
                if declaration_start.is_none() { declaration_start = Some(offset); }
                declaration_end = Some(offset);
            }
            if tag.field_number == 50 { features_offset = Some(offset); }
            if tag.field_number == 3 { verification_offset = Some(offset); }
        }

        Ok(Self {
            accessor,
uninterpreted_option_start, uninterpreted_option_end,
declaration_start, declaration_end,
features_offset,
verification_offset,
        })
    }

    pub fn uninterpreted_option(&self) -> roto_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> {
        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)?;
        let (bytes, _) = self.accessor.get_value_at(offset)?;
        Ok(bytes)
    }

    pub fn features_or_default(&self) -> roto_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<u64> {
        let offset = self.verification_offset.ok_or(roto_runtime::RotoError::FieldNotFound)?;
        let (bytes, _) = self.accessor.get_value_at(offset)?;
        roto_runtime::read_varint(bytes).map(|(v, _)| v as u64).map_err(|_| roto_runtime::RotoError::WireFormatViolation)
    }

    pub fn verification_or_default(&self) -> roto_runtime::Result<u64> {
        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> {
        self.accessor.raw_fields()
    }

}

pub struct ExtensionRangeOptionsBuilder<'b> {
    builder: roto_runtime::ProtoBuilder<'b>,
    uninterpreted_option_written: bool,
    declaration_written: bool,
    features_written: bool,
    verification_written: bool,
}

impl<'b> ExtensionRangeOptionsBuilder<'b> {
    pub fn builder(buf: &mut [u8]) -> ExtensionRangeOptionsBuilder<'_> {
        ExtensionRangeOptionsBuilder {
            builder: roto_runtime::ProtoBuilder::new(buf),
            uninterpreted_option_written: false,
            declaration_written: false,
            features_written: false,
            verification_written: false,
        }
    }

    pub fn uninterpreted_option(mut self, value: &[u8]) -> roto_runtime::Result<Self> {
        self.builder.write_bytes(999, value)?;
        self.uninterpreted_option_written = true;
        Ok(self)
    }

    pub fn declaration(mut self, value: &[u8]) -> roto_runtime::Result<Self> {
        self.builder.write_bytes(2, value)?;
        self.declaration_written = true;
        Ok(self)
    }

    pub fn features(mut self, value: &[u8]) -> roto_runtime::Result<Self> {
        self.builder.write_bytes(50, value)?;
        self.features_written = true;
        Ok(self)
    }

    pub fn verification(mut self, value: u64) -> roto_runtime::Result<Self> {
        self.builder.write_varint(3, value)?;
        self.verification_written = true;
        Ok(self)
    }

    pub fn with(mut self, msg: &ExtensionRangeOptions<'_>) -> roto_runtime::Result<Self> {
        for item in msg.raw_fields() {
            let (field_number, raw_bytes) = item?;
            let is_written = match field_number {
                999 => self.uninterpreted_option_written,
                2 => self.declaration_written,
                50 => self.features_written,
                3 => self.verification_written,
                _ => false,
            };
            if !is_written {
                self.builder.write_raw(raw_bytes)?;
            }
        }
        Ok(self)
    }

    pub fn finish(self) -> roto_runtime::Result<&'b mut [u8]> {
        self.builder.finish()
    }
}

pub struct OwnedExtensionRangeOptions {
    pub data: bytes::Bytes,
}

impl roto_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<Self> {
        Ok(OwnedExtensionRangeOptions { data: buf })
    }

    fn bytes(&self) -> bytes::Bytes {
        self.data.clone()
    }
}

pub mod extension_range_options {
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
#[repr(i32)]
pub enum VerificationState {
    DECLARATION = 0,
    UNVERIFIED = 1,
}

impl VerificationState {
    pub fn from_i32(value: i32) -> Self {
        match value {
            0 => VerificationState::DECLARATION,
            1 => VerificationState::UNVERIFIED,
            _ => VerificationState::DECLARATION,
        }
    }
}

pub struct Declaration<'a> {
    accessor: roto_runtime::ProtoAccessor<'a>,
    number_offset: Option<usize>,
    full_name_offset: Option<usize>,
    type_offset: Option<usize>,
    reserved_offset: Option<usize>,
    repeated_offset: Option<usize>,
}

impl<'a> Declaration<'a> {
    pub fn new(data: &'a [u8]) -> roto_runtime::Result<Self> {
        let accessor = roto_runtime::ProtoAccessor::new(data)?;
        let mut number_offset = None;
        let mut full_name_offset = None;
        let mut type_offset = None;
        let mut reserved_offset = None;
        let mut repeated_offset = None;
        for item in accessor.fields() {
            let (offset, tag, _) = item?;
            if tag.field_number == 1 { number_offset = Some(offset); }
            if tag.field_number == 2 { full_name_offset = Some(offset); }
            if tag.field_number == 3 { type_offset = Some(offset); }
            if tag.field_number == 5 { reserved_offset = Some(offset); }
            if tag.field_number == 6 { repeated_offset = Some(offset); }
        }

        Ok(Self {
            accessor,
number_offset,
full_name_offset,
type_offset,
reserved_offset,
repeated_offset,
        })
    }

    pub fn number(&self) -> roto_runtime::Result<i32> {
        let offset = self.number_offset.ok_or(roto_runtime::RotoError::FieldNotFound)?;
        let (bytes, _) = self.accessor.get_value_at(offset)?;
        roto_runtime::read_varint(bytes).map(|(v, _)| v as i32).map_err(|_| roto_runtime::RotoError::WireFormatViolation)
    }

    pub fn number_or_default(&self) -> roto_runtime::Result<i32> {
        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)?;
        let (bytes, _) = self.accessor.get_value_at(offset)?;
        str::from_utf8(bytes).map_err(|_| roto_runtime::RotoError::WireFormatViolation)
    }

    pub fn full_name_or_default(&self) -> roto_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)?;
        let (bytes, _) = self.accessor.get_value_at(offset)?;
        str::from_utf8(bytes).map_err(|_| roto_runtime::RotoError::WireFormatViolation)
    }

    pub fn r#type_or_default(&self) -> roto_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<bool> {
        let offset = self.reserved_offset.ok_or(roto_runtime::RotoError::FieldNotFound)?;
        let (bytes, _) = self.accessor.get_value_at(offset)?;
        roto_runtime::read_varint(bytes).map(|(v, _)| v != 0).map_err(|_| roto_runtime::RotoError::WireFormatViolation)
    }

    pub fn reserved_or_default(&self) -> roto_runtime::Result<bool> {
        self.reserved().or(Ok(false))
    }

    pub fn has_reserved(&self) -> bool { self.reserved_offset.is_some() }

    pub fn repeated(&self) -> roto_runtime::Result<bool> {
        let offset = self.repeated_offset.ok_or(roto_runtime::RotoError::FieldNotFound)?;
        let (bytes, _) = self.accessor.get_value_at(offset)?;
        roto_runtime::read_varint(bytes).map(|(v, _)| v != 0).map_err(|_| roto_runtime::RotoError::WireFormatViolation)
    }

    pub fn repeated_or_default(&self) -> roto_runtime::Result<bool> {
        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> {
        self.accessor.raw_fields()
    }

}

pub struct DeclarationBuilder<'b> {
    builder: roto_runtime::ProtoBuilder<'b>,
    number_written: bool,
    full_name_written: bool,
    type_written: bool,
    reserved_written: bool,
    repeated_written: bool,
}

impl<'b> DeclarationBuilder<'b> {
    pub fn builder(buf: &mut [u8]) -> DeclarationBuilder<'_> {
        DeclarationBuilder {
            builder: roto_runtime::ProtoBuilder::new(buf),
            number_written: false,
            full_name_written: false,
            type_written: false,
            reserved_written: false,
            repeated_written: false,
        }
    }

    pub fn number(mut self, value: i32) -> roto_runtime::Result<Self> {
        self.builder.write_int32(1, value)?;
        self.number_written = true;
        Ok(self)
    }

    pub fn full_name(mut self, value: &str) -> roto_runtime::Result<Self> {
        self.builder.write_string(2, value)?;
        self.full_name_written = true;
        Ok(self)
    }

    pub fn r#type(mut self, value: &str) -> roto_runtime::Result<Self> {
        self.builder.write_string(3, value)?;
        self.type_written = true;
        Ok(self)
    }

    pub fn reserved(mut self, value: u64) -> roto_runtime::Result<Self> {
        self.builder.write_varint(5, value)?;
        self.reserved_written = true;
        Ok(self)
    }

    pub fn repeated(mut self, value: u64) -> roto_runtime::Result<Self> {
        self.builder.write_varint(6, value)?;
        self.repeated_written = true;
        Ok(self)
    }

    pub fn with(mut self, msg: &Declaration<'_>) -> roto_runtime::Result<Self> {
        for item in msg.raw_fields() {
            let (field_number, raw_bytes) = item?;
            let is_written = match field_number {
                1 => self.number_written,
                2 => self.full_name_written,
                3 => self.type_written,
                5 => self.reserved_written,
                6 => self.repeated_written,
                _ => false,
            };
            if !is_written {
                self.builder.write_raw(raw_bytes)?;
            }
        }
        Ok(self)
    }

    pub fn finish(self) -> roto_runtime::Result<&'b mut [u8]> {
        self.builder.finish()
    }
}

pub struct OwnedDeclaration {
    pub data: bytes::Bytes,
}

impl roto_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<Self> {
        Ok(OwnedDeclaration { data: buf })
    }

    fn bytes(&self) -> bytes::Bytes {
        self.data.clone()
    }
}

}

pub struct FieldDescriptorProto<'a> {
    accessor: roto_runtime::ProtoAccessor<'a>,
    name_offset: Option<usize>,
    number_offset: Option<usize>,
    label_offset: Option<usize>,
    type_offset: Option<usize>,
    type_name_offset: Option<usize>,
    extendee_offset: Option<usize>,
    default_value_offset: Option<usize>,
    oneof_index_offset: Option<usize>,
    json_name_offset: Option<usize>,
    options_offset: Option<usize>,
    proto3_optional_offset: Option<usize>,
}

impl<'a> FieldDescriptorProto<'a> {
    pub fn new(data: &'a [u8]) -> roto_runtime::Result<Self> {
        let accessor = roto_runtime::ProtoAccessor::new(data)?;
        let mut name_offset = None;
        let mut number_offset = None;
        let mut label_offset = None;
        let mut type_offset = None;
        let mut type_name_offset = None;
        let mut extendee_offset = None;
        let mut default_value_offset = None;
        let mut oneof_index_offset = None;
        let mut json_name_offset = None;
        let mut options_offset = None;
        let mut proto3_optional_offset = None;
        for item in accessor.fields() {
            let (offset, tag, _) = item?;
            if tag.field_number == 1 { name_offset = Some(offset); }
            if tag.field_number == 3 { number_offset = Some(offset); }
            if tag.field_number == 4 { label_offset = Some(offset); }
            if tag.field_number == 5 { type_offset = Some(offset); }
            if tag.field_number == 6 { type_name_offset = Some(offset); }
            if tag.field_number == 2 { extendee_offset = Some(offset); }
            if tag.field_number == 7 { default_value_offset = Some(offset); }
            if tag.field_number == 9 { oneof_index_offset = Some(offset); }
            if tag.field_number == 10 { json_name_offset = Some(offset); }
            if tag.field_number == 8 { options_offset = Some(offset); }
            if tag.field_number == 17 { proto3_optional_offset = Some(offset); }
        }

        Ok(Self {
            accessor,
name_offset,
number_offset,
label_offset,
type_offset,
type_name_offset,
extendee_offset,
default_value_offset,
oneof_index_offset,
json_name_offset,
options_offset,
proto3_optional_offset,
        })
    }

    pub fn name(&self) -> roto_runtime::Result<&'a str> {
        let offset = self.name_offset.ok_or(roto_runtime::RotoError::FieldNotFound)?;
        let (bytes, _) = self.accessor.get_value_at(offset)?;
        str::from_utf8(bytes).map_err(|_| roto_runtime::RotoError::WireFormatViolation)
    }

    pub fn name_or_default(&self) -> roto_runtime::Result<&'a str> {
        self.name().or(Ok(""))
    }

    pub fn has_name(&self) -> bool { self.name_offset.is_some() }

    pub fn number(&self) -> roto_runtime::Result<i32> {
        let offset = self.number_offset.ok_or(roto_runtime::RotoError::FieldNotFound)?;
        let (bytes, _) = self.accessor.get_value_at(offset)?;
        roto_runtime::read_varint(bytes).map(|(v, _)| v as i32).map_err(|_| roto_runtime::RotoError::WireFormatViolation)
    }

    pub fn number_or_default(&self) -> roto_runtime::Result<i32> {
        self.number().or(Ok(0))
    }

    pub fn has_number(&self) -> bool { self.number_offset.is_some() }

    pub fn label(&self) -> roto_runtime::Result<u64> {
        let offset = self.label_offset.ok_or(roto_runtime::RotoError::FieldNotFound)?;
        let (bytes, _) = self.accessor.get_value_at(offset)?;
        roto_runtime::read_varint(bytes).map(|(v, _)| v as u64).map_err(|_| roto_runtime::RotoError::WireFormatViolation)
    }

    pub fn label_or_default(&self) -> roto_runtime::Result<u64> {
        self.label().or(Ok(0))
    }

    pub fn has_label(&self) -> bool { self.label_offset.is_some() }

    pub fn r#type(&self) -> roto_runtime::Result<u64> {
        let offset = self.type_offset.ok_or(roto_runtime::RotoError::FieldNotFound)?;
        let (bytes, _) = self.accessor.get_value_at(offset)?;
        roto_runtime::read_varint(bytes).map(|(v, _)| v as u64).map_err(|_| roto_runtime::RotoError::WireFormatViolation)
    }

    pub fn r#type_or_default(&self) -> roto_runtime::Result<u64> {
        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)?;
        let (bytes, _) = self.accessor.get_value_at(offset)?;
        str::from_utf8(bytes).map_err(|_| roto_runtime::RotoError::WireFormatViolation)
    }

    pub fn type_name_or_default(&self) -> roto_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)?;
        let (bytes, _) = self.accessor.get_value_at(offset)?;
        str::from_utf8(bytes).map_err(|_| roto_runtime::RotoError::WireFormatViolation)
    }

    pub fn extendee_or_default(&self) -> roto_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)?;
        let (bytes, _) = self.accessor.get_value_at(offset)?;
        str::from_utf8(bytes).map_err(|_| roto_runtime::RotoError::WireFormatViolation)
    }

    pub fn default_value_or_default(&self) -> roto_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<i32> {
        let offset = self.oneof_index_offset.ok_or(roto_runtime::RotoError::FieldNotFound)?;
        let (bytes, _) = self.accessor.get_value_at(offset)?;
        roto_runtime::read_varint(bytes).map(|(v, _)| v as i32).map_err(|_| roto_runtime::RotoError::WireFormatViolation)
    }

    pub fn oneof_index_or_default(&self) -> roto_runtime::Result<i32> {
        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)?;
        let (bytes, _) = self.accessor.get_value_at(offset)?;
        str::from_utf8(bytes).map_err(|_| roto_runtime::RotoError::WireFormatViolation)
    }

    pub fn json_name_or_default(&self) -> roto_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)?;
        let (bytes, _) = self.accessor.get_value_at(offset)?;
        Ok(bytes)
    }

    pub fn options_or_default(&self) -> roto_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<bool> {
        let offset = self.proto3_optional_offset.ok_or(roto_runtime::RotoError::FieldNotFound)?;
        let (bytes, _) = self.accessor.get_value_at(offset)?;
        roto_runtime::read_varint(bytes).map(|(v, _)| v != 0).map_err(|_| roto_runtime::RotoError::WireFormatViolation)
    }

    pub fn proto3_optional_or_default(&self) -> roto_runtime::Result<bool> {
        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> {
        self.accessor.raw_fields()
    }

}

pub struct FieldDescriptorProtoBuilder<'b> {
    builder: roto_runtime::ProtoBuilder<'b>,
    name_written: bool,
    number_written: bool,
    label_written: bool,
    type_written: bool,
    type_name_written: bool,
    extendee_written: bool,
    default_value_written: bool,
    oneof_index_written: bool,
    json_name_written: bool,
    options_written: bool,
    proto3_optional_written: bool,
}

impl<'b> FieldDescriptorProtoBuilder<'b> {
    pub fn builder(buf: &mut [u8]) -> FieldDescriptorProtoBuilder<'_> {
        FieldDescriptorProtoBuilder {
            builder: roto_runtime::ProtoBuilder::new(buf),
            name_written: false,
            number_written: false,
            label_written: false,
            type_written: false,
            type_name_written: false,
            extendee_written: false,
            default_value_written: false,
            oneof_index_written: false,
            json_name_written: false,
            options_written: false,
            proto3_optional_written: false,
        }
    }

    pub fn name(mut self, value: &str) -> roto_runtime::Result<Self> {
        self.builder.write_string(1, value)?;
        self.name_written = true;
        Ok(self)
    }

    pub fn number(mut self, value: i32) -> roto_runtime::Result<Self> {
        self.builder.write_int32(3, value)?;
        self.number_written = true;
        Ok(self)
    }

    pub fn label(mut self, value: u64) -> roto_runtime::Result<Self> {
        self.builder.write_varint(4, value)?;
        self.label_written = true;
        Ok(self)
    }

    pub fn r#type(mut self, value: u64) -> roto_runtime::Result<Self> {
        self.builder.write_varint(5, value)?;
        self.type_written = true;
        Ok(self)
    }

    pub fn type_name(mut self, value: &str) -> roto_runtime::Result<Self> {
        self.builder.write_string(6, value)?;
        self.type_name_written = true;
        Ok(self)
    }

    pub fn extendee(mut self, value: &str) -> roto_runtime::Result<Self> {
        self.builder.write_string(2, value)?;
        self.extendee_written = true;
        Ok(self)
    }

    pub fn default_value(mut self, value: &str) -> roto_runtime::Result<Self> {
        self.builder.write_string(7, value)?;
        self.default_value_written = true;
        Ok(self)
    }

    pub fn oneof_index(mut self, value: i32) -> roto_runtime::Result<Self> {
        self.builder.write_int32(9, value)?;
        self.oneof_index_written = true;
        Ok(self)
    }

    pub fn json_name(mut self, value: &str) -> roto_runtime::Result<Self> {
        self.builder.write_string(10, value)?;
        self.json_name_written = true;
        Ok(self)
    }

    pub fn options(mut self, value: &[u8]) -> roto_runtime::Result<Self> {
        self.builder.write_bytes(8, value)?;
        self.options_written = true;
        Ok(self)
    }

    pub fn proto3_optional(mut self, value: u64) -> roto_runtime::Result<Self> {
        self.builder.write_varint(17, value)?;
        self.proto3_optional_written = true;
        Ok(self)
    }

    pub fn with(mut self, msg: &FieldDescriptorProto<'_>) -> roto_runtime::Result<Self> {
        for item in msg.raw_fields() {
            let (field_number, raw_bytes) = item?;
            let is_written = match field_number {
                1 => self.name_written,
                3 => self.number_written,
                4 => self.label_written,
                5 => self.type_written,
                6 => self.type_name_written,
                2 => self.extendee_written,
                7 => self.default_value_written,
                9 => self.oneof_index_written,
                10 => self.json_name_written,
                8 => self.options_written,
                17 => self.proto3_optional_written,
                _ => false,
            };
            if !is_written {
                self.builder.write_raw(raw_bytes)?;
            }
        }
        Ok(self)
    }

    pub fn finish(self) -> roto_runtime::Result<&'b mut [u8]> {
        self.builder.finish()
    }
}

pub struct OwnedFieldDescriptorProto {
    pub data: bytes::Bytes,
}

impl roto_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<Self> {
        Ok(OwnedFieldDescriptorProto { data: buf })
    }

    fn bytes(&self) -> bytes::Bytes {
        self.data.clone()
    }
}

pub mod field_descriptor_proto {
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
#[repr(i32)]
pub enum Type {
    TYPEDOUBLE = 1,
    TYPEFLOAT = 2,
    TYPEINT64 = 3,
    TYPEUINT64 = 4,
    TYPEINT32 = 5,
    TYPEFIXED64 = 6,
    TYPEFIXED32 = 7,
    TYPEBOOL = 8,
    TYPESTRING = 9,
    TYPEGROUP = 10,
    TYPEMESSAGE = 11,
    TYPEBYTES = 12,
    TYPEUINT32 = 13,
    TYPEENUM = 14,
    TYPESFIXED32 = 15,
    TYPESFIXED64 = 16,
    TYPESINT32 = 17,
    TYPESINT64 = 18,
    Unknown = 0,
}

impl Type {
    pub fn from_i32(value: i32) -> Self {
        match value {
            1 => Type::TYPEDOUBLE,
            2 => Type::TYPEFLOAT,
            3 => Type::TYPEINT64,
            4 => Type::TYPEUINT64,
            5 => Type::TYPEINT32,
            6 => Type::TYPEFIXED64,
            7 => Type::TYPEFIXED32,
            8 => Type::TYPEBOOL,
            9 => Type::TYPESTRING,
            10 => Type::TYPEGROUP,
            11 => Type::TYPEMESSAGE,
            12 => Type::TYPEBYTES,
            13 => Type::TYPEUINT32,
            14 => Type::TYPEENUM,
            15 => Type::TYPESFIXED32,
            16 => Type::TYPESFIXED64,
            17 => Type::TYPESINT32,
            18 => Type::TYPESINT64,
            _ => Type::Unknown,
        }
    }
}

#[derive(Debug, Clone, Copy, PartialEq, Eq)]
#[repr(i32)]
pub enum Label {
    LABELOPTIONAL = 1,
    LABELREPEATED = 3,
    LABELREQUIRED = 2,
    Unknown = 0,
}

impl Label {
    pub fn from_i32(value: i32) -> Self {
        match value {
            1 => Label::LABELOPTIONAL,
            3 => Label::LABELREPEATED,
            2 => Label::LABELREQUIRED,
            _ => Label::Unknown,
        }
    }
}

}

pub struct OneofDescriptorProto<'a> {
    accessor: roto_runtime::ProtoAccessor<'a>,
    name_offset: Option<usize>,
    options_offset: Option<usize>,
}

impl<'a> OneofDescriptorProto<'a> {
    pub fn new(data: &'a [u8]) -> roto_runtime::Result<Self> {
        let accessor = roto_runtime::ProtoAccessor::new(data)?;
        let mut name_offset = None;
        let mut options_offset = None;
        for item in accessor.fields() {
            let (offset, tag, _) = item?;
            if tag.field_number == 1 { name_offset = Some(offset); }
            if tag.field_number == 2 { options_offset = Some(offset); }
        }

        Ok(Self {
            accessor,
name_offset,
options_offset,
        })
    }

    pub fn name(&self) -> roto_runtime::Result<&'a str> {
        let offset = self.name_offset.ok_or(roto_runtime::RotoError::FieldNotFound)?;
        let (bytes, _) = self.accessor.get_value_at(offset)?;
        str::from_utf8(bytes).map_err(|_| roto_runtime::RotoError::WireFormatViolation)
    }

    pub fn name_or_default(&self) -> roto_runtime::Result<&'a str> {
        self.name().or(Ok(""))
    }

    pub fn has_name(&self) -> bool { self.name_offset.is_some() }

    pub fn options(&self) -> roto_runtime::Result<&'a [u8]> {
        let offset = self.options_offset.ok_or(roto_runtime::RotoError::FieldNotFound)?;
        let (bytes, _) = self.accessor.get_value_at(offset)?;
        Ok(bytes)
    }

    pub fn options_or_default(&self) -> roto_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> {
        self.accessor.raw_fields()
    }

}

pub struct OneofDescriptorProtoBuilder<'b> {
    builder: roto_runtime::ProtoBuilder<'b>,
    name_written: bool,
    options_written: bool,
}

impl<'b> OneofDescriptorProtoBuilder<'b> {
    pub fn builder(buf: &mut [u8]) -> OneofDescriptorProtoBuilder<'_> {
        OneofDescriptorProtoBuilder {
            builder: roto_runtime::ProtoBuilder::new(buf),
            name_written: false,
            options_written: false,
        }
    }

    pub fn name(mut self, value: &str) -> roto_runtime::Result<Self> {
        self.builder.write_string(1, value)?;
        self.name_written = true;
        Ok(self)
    }

    pub fn options(mut self, value: &[u8]) -> roto_runtime::Result<Self> {
        self.builder.write_bytes(2, value)?;
        self.options_written = true;
        Ok(self)
    }

    pub fn with(mut self, msg: &OneofDescriptorProto<'_>) -> roto_runtime::Result<Self> {
        for item in msg.raw_fields() {
            let (field_number, raw_bytes) = item?;
            let is_written = match field_number {
                1 => self.name_written,
                2 => self.options_written,
                _ => false,
            };
            if !is_written {
                self.builder.write_raw(raw_bytes)?;
            }
        }
        Ok(self)
    }

    pub fn finish(self) -> roto_runtime::Result<&'b mut [u8]> {
        self.builder.finish()
    }
}

pub struct OwnedOneofDescriptorProto {
    pub data: bytes::Bytes,
}

impl roto_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<Self> {
        Ok(OwnedOneofDescriptorProto { data: buf })
    }

    fn bytes(&self) -> bytes::Bytes {
        self.data.clone()
    }
}

pub struct EnumDescriptorProto<'a> {
    accessor: roto_runtime::ProtoAccessor<'a>,
    name_offset: Option<usize>,
    value_start: Option<usize>,
    value_end: Option<usize>,
    options_offset: Option<usize>,
    reserved_range_start: Option<usize>,
    reserved_range_end: Option<usize>,
    reserved_name_start: Option<usize>,
    reserved_name_end: Option<usize>,
    visibility_offset: Option<usize>,
}

impl<'a> EnumDescriptorProto<'a> {
    pub fn new(data: &'a [u8]) -> roto_runtime::Result<Self> {
        let accessor = roto_runtime::ProtoAccessor::new(data)?;
        let mut name_offset = None;
        let mut value_start = None;
        let mut value_end = None;
        let mut options_offset = None;
        let mut reserved_range_start = None;
        let mut reserved_range_end = None;
        let mut reserved_name_start = None;
        let mut reserved_name_end = None;
        let mut visibility_offset = None;
        for item in accessor.fields() {
            let (offset, tag, _) = item?;
            if tag.field_number == 1 { name_offset = Some(offset); }
            if tag.field_number == 2 {
                if value_start.is_none() { value_start = Some(offset); }
                value_end = Some(offset);
            }
            if tag.field_number == 3 { options_offset = Some(offset); }
            if tag.field_number == 4 {
                if reserved_range_start.is_none() { reserved_range_start = Some(offset); }
                reserved_range_end = Some(offset);
            }
            if tag.field_number == 5 {
                if reserved_name_start.is_none() { reserved_name_start = Some(offset); }
                reserved_name_end = Some(offset);
            }
            if tag.field_number == 6 { visibility_offset = Some(offset); }
        }

        Ok(Self {
            accessor,
name_offset,
value_start, value_end,
options_offset,
reserved_range_start, reserved_range_end,
reserved_name_start, reserved_name_end,
visibility_offset,
        })
    }

    pub fn name(&self) -> roto_runtime::Result<&'a str> {
        let offset = self.name_offset.ok_or(roto_runtime::RotoError::FieldNotFound)?;
        let (bytes, _) = self.accessor.get_value_at(offset)?;
        str::from_utf8(bytes).map_err(|_| roto_runtime::RotoError::WireFormatViolation)
    }

    pub fn name_or_default(&self) -> roto_runtime::Result<&'a str> {
        self.name().or(Ok(""))
    }

    pub fn has_name(&self) -> bool { self.name_offset.is_some() }

    pub fn value(&self) -> roto_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)?;
        let (bytes, _) = self.accessor.get_value_at(offset)?;
        Ok(bytes)
    }

    pub fn options_or_default(&self) -> roto_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> {
        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> {
        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<u64> {
        let offset = self.visibility_offset.ok_or(roto_runtime::RotoError::FieldNotFound)?;
        let (bytes, _) = self.accessor.get_value_at(offset)?;
        roto_runtime::read_varint(bytes).map(|(v, _)| v as u64).map_err(|_| roto_runtime::RotoError::WireFormatViolation)
    }

    pub fn visibility_or_default(&self) -> roto_runtime::Result<u64> {
        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> {
        self.accessor.raw_fields()
    }

}

pub struct EnumDescriptorProtoBuilder<'b> {
    builder: roto_runtime::ProtoBuilder<'b>,
    name_written: bool,
    value_written: bool,
    options_written: bool,
    reserved_range_written: bool,
    reserved_name_written: bool,
    visibility_written: bool,
}

impl<'b> EnumDescriptorProtoBuilder<'b> {
    pub fn builder(buf: &mut [u8]) -> EnumDescriptorProtoBuilder<'_> {
        EnumDescriptorProtoBuilder {
            builder: roto_runtime::ProtoBuilder::new(buf),
            name_written: false,
            value_written: false,
            options_written: false,
            reserved_range_written: false,
            reserved_name_written: false,
            visibility_written: false,
        }
    }

    pub fn name(mut self, value: &str) -> roto_runtime::Result<Self> {
        self.builder.write_string(1, value)?;
        self.name_written = true;
        Ok(self)
    }

    pub fn value(mut self, value: &[u8]) -> roto_runtime::Result<Self> {
        self.builder.write_bytes(2, value)?;
        self.value_written = true;
        Ok(self)
    }

    pub fn options(mut self, value: &[u8]) -> roto_runtime::Result<Self> {
        self.builder.write_bytes(3, value)?;
        self.options_written = true;
        Ok(self)
    }

    pub fn reserved_range(mut self, value: &[u8]) -> roto_runtime::Result<Self> {
        self.builder.write_bytes(4, value)?;
        self.reserved_range_written = true;
        Ok(self)
    }

    pub fn reserved_name(mut self, value: &str) -> roto_runtime::Result<Self> {
        self.builder.write_string(5, value)?;
        self.reserved_name_written = true;
        Ok(self)
    }

    pub fn visibility(mut self, value: u64) -> roto_runtime::Result<Self> {
        self.builder.write_varint(6, value)?;
        self.visibility_written = true;
        Ok(self)
    }

    pub fn with(mut self, msg: &EnumDescriptorProto<'_>) -> roto_runtime::Result<Self> {
        for item in msg.raw_fields() {
            let (field_number, raw_bytes) = item?;
            let is_written = match field_number {
                1 => self.name_written,
                2 => self.value_written,
                3 => self.options_written,
                4 => self.reserved_range_written,
                5 => self.reserved_name_written,
                6 => self.visibility_written,
                _ => false,
            };
            if !is_written {
                self.builder.write_raw(raw_bytes)?;
            }
        }
        Ok(self)
    }

    pub fn finish(self) -> roto_runtime::Result<&'b mut [u8]> {
        self.builder.finish()
    }
}

pub struct OwnedEnumDescriptorProto {
    pub data: bytes::Bytes,
}

impl roto_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<Self> {
        Ok(OwnedEnumDescriptorProto { data: buf })
    }

    fn bytes(&self) -> bytes::Bytes {
        self.data.clone()
    }
}

pub mod enum_descriptor_proto {
pub struct EnumReservedRange<'a> {
    accessor: roto_runtime::ProtoAccessor<'a>,
    start_offset: Option<usize>,
    end_offset: Option<usize>,
}

impl<'a> EnumReservedRange<'a> {
    pub fn new(data: &'a [u8]) -> roto_runtime::Result<Self> {
        let accessor = roto_runtime::ProtoAccessor::new(data)?;
        let mut start_offset = None;
        let mut end_offset = None;
        for item in accessor.fields() {
            let (offset, tag, _) = item?;
            if tag.field_number == 1 { start_offset = Some(offset); }
            if tag.field_number == 2 { end_offset = Some(offset); }
        }

        Ok(Self {
            accessor,
start_offset,
end_offset,
        })
    }

    pub fn start(&self) -> roto_runtime::Result<i32> {
        let offset = self.start_offset.ok_or(roto_runtime::RotoError::FieldNotFound)?;
        let (bytes, _) = self.accessor.get_value_at(offset)?;
        roto_runtime::read_varint(bytes).map(|(v, _)| v as i32).map_err(|_| roto_runtime::RotoError::WireFormatViolation)
    }

    pub fn start_or_default(&self) -> roto_runtime::Result<i32> {
        self.start().or(Ok(0))
    }

    pub fn has_start(&self) -> bool { self.start_offset.is_some() }

    pub fn end(&self) -> roto_runtime::Result<i32> {
        let offset = self.end_offset.ok_or(roto_runtime::RotoError::FieldNotFound)?;
        let (bytes, _) = self.accessor.get_value_at(offset)?;
        roto_runtime::read_varint(bytes).map(|(v, _)| v as i32).map_err(|_| roto_runtime::RotoError::WireFormatViolation)
    }

    pub fn end_or_default(&self) -> roto_runtime::Result<i32> {
        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> {
        self.accessor.raw_fields()
    }

}

pub struct EnumReservedRangeBuilder<'b> {
    builder: roto_runtime::ProtoBuilder<'b>,
    start_written: bool,
    end_written: bool,
}

impl<'b> EnumReservedRangeBuilder<'b> {
    pub fn builder(buf: &mut [u8]) -> EnumReservedRangeBuilder<'_> {
        EnumReservedRangeBuilder {
            builder: roto_runtime::ProtoBuilder::new(buf),
            start_written: false,
            end_written: false,
        }
    }

    pub fn start(mut self, value: i32) -> roto_runtime::Result<Self> {
        self.builder.write_int32(1, value)?;
        self.start_written = true;
        Ok(self)
    }

    pub fn end(mut self, value: i32) -> roto_runtime::Result<Self> {
        self.builder.write_int32(2, value)?;
        self.end_written = true;
        Ok(self)
    }

    pub fn with(mut self, msg: &EnumReservedRange<'_>) -> roto_runtime::Result<Self> {
        for item in msg.raw_fields() {
            let (field_number, raw_bytes) = item?;
            let is_written = match field_number {
                1 => self.start_written,
                2 => self.end_written,
                _ => false,
            };
            if !is_written {
                self.builder.write_raw(raw_bytes)?;
            }
        }
        Ok(self)
    }

    pub fn finish(self) -> roto_runtime::Result<&'b mut [u8]> {
        self.builder.finish()
    }
}

pub struct OwnedEnumReservedRange {
    pub data: bytes::Bytes,
}

impl roto_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<Self> {
        Ok(OwnedEnumReservedRange { data: buf })
    }

    fn bytes(&self) -> bytes::Bytes {
        self.data.clone()
    }
}

}

pub struct EnumValueDescriptorProto<'a> {
    accessor: roto_runtime::ProtoAccessor<'a>,
    name_offset: Option<usize>,
    number_offset: Option<usize>,
    options_offset: Option<usize>,
}

impl<'a> EnumValueDescriptorProto<'a> {
    pub fn new(data: &'a [u8]) -> roto_runtime::Result<Self> {
        let accessor = roto_runtime::ProtoAccessor::new(data)?;
        let mut name_offset = None;
        let mut number_offset = None;
        let mut options_offset = None;
        for item in accessor.fields() {
            let (offset, tag, _) = item?;
            if tag.field_number == 1 { name_offset = Some(offset); }
            if tag.field_number == 2 { number_offset = Some(offset); }
            if tag.field_number == 3 { options_offset = Some(offset); }
        }

        Ok(Self {
            accessor,
name_offset,
number_offset,
options_offset,
        })
    }

    pub fn name(&self) -> roto_runtime::Result<&'a str> {
        let offset = self.name_offset.ok_or(roto_runtime::RotoError::FieldNotFound)?;
        let (bytes, _) = self.accessor.get_value_at(offset)?;
        str::from_utf8(bytes).map_err(|_| roto_runtime::RotoError::WireFormatViolation)
    }

    pub fn name_or_default(&self) -> roto_runtime::Result<&'a str> {
        self.name().or(Ok(""))
    }

    pub fn has_name(&self) -> bool { self.name_offset.is_some() }

    pub fn number(&self) -> roto_runtime::Result<i32> {
        let offset = self.number_offset.ok_or(roto_runtime::RotoError::FieldNotFound)?;
        let (bytes, _) = self.accessor.get_value_at(offset)?;
        roto_runtime::read_varint(bytes).map(|(v, _)| v as i32).map_err(|_| roto_runtime::RotoError::WireFormatViolation)
    }

    pub fn number_or_default(&self) -> roto_runtime::Result<i32> {
        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)?;
        let (bytes, _) = self.accessor.get_value_at(offset)?;
        Ok(bytes)
    }

    pub fn options_or_default(&self) -> roto_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> {
        self.accessor.raw_fields()
    }

}

pub struct EnumValueDescriptorProtoBuilder<'b> {
    builder: roto_runtime::ProtoBuilder<'b>,
    name_written: bool,
    number_written: bool,
    options_written: bool,
}

impl<'b> EnumValueDescriptorProtoBuilder<'b> {
    pub fn builder(buf: &mut [u8]) -> EnumValueDescriptorProtoBuilder<'_> {
        EnumValueDescriptorProtoBuilder {
            builder: roto_runtime::ProtoBuilder::new(buf),
            name_written: false,
            number_written: false,
            options_written: false,
        }
    }

    pub fn name(mut self, value: &str) -> roto_runtime::Result<Self> {
        self.builder.write_string(1, value)?;
        self.name_written = true;
        Ok(self)
    }

    pub fn number(mut self, value: i32) -> roto_runtime::Result<Self> {
        self.builder.write_int32(2, value)?;
        self.number_written = true;
        Ok(self)
    }

    pub fn options(mut self, value: &[u8]) -> roto_runtime::Result<Self> {
        self.builder.write_bytes(3, value)?;
        self.options_written = true;
        Ok(self)
    }

    pub fn with(mut self, msg: &EnumValueDescriptorProto<'_>) -> roto_runtime::Result<Self> {
        for item in msg.raw_fields() {
            let (field_number, raw_bytes) = item?;
            let is_written = match field_number {
                1 => self.name_written,
                2 => self.number_written,
                3 => self.options_written,
                _ => false,
            };
            if !is_written {
                self.builder.write_raw(raw_bytes)?;
            }
        }
        Ok(self)
    }

    pub fn finish(self) -> roto_runtime::Result<&'b mut [u8]> {
        self.builder.finish()
    }
}

pub struct OwnedEnumValueDescriptorProto {
    pub data: bytes::Bytes,
}

impl roto_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<Self> {
        Ok(OwnedEnumValueDescriptorProto { data: buf })
    }

    fn bytes(&self) -> bytes::Bytes {
        self.data.clone()
    }
}

pub struct ServiceDescriptorProto<'a> {
    accessor: roto_runtime::ProtoAccessor<'a>,
    name_offset: Option<usize>,
    method_start: Option<usize>,
    method_end: Option<usize>,
    options_offset: Option<usize>,
}

impl<'a> ServiceDescriptorProto<'a> {
    pub fn new(data: &'a [u8]) -> roto_runtime::Result<Self> {
        let accessor = roto_runtime::ProtoAccessor::new(data)?;
        let mut name_offset = None;
        let mut method_start = None;
        let mut method_end = None;
        let mut options_offset = None;
        for item in accessor.fields() {
            let (offset, tag, _) = item?;
            if tag.field_number == 1 { name_offset = Some(offset); }
            if tag.field_number == 2 {
                if method_start.is_none() { method_start = Some(offset); }
                method_end = Some(offset);
            }
            if tag.field_number == 3 { options_offset = Some(offset); }
        }

        Ok(Self {
            accessor,
name_offset,
method_start, method_end,
options_offset,
        })
    }

    pub fn name(&self) -> roto_runtime::Result<&'a str> {
        let offset = self.name_offset.ok_or(roto_runtime::RotoError::FieldNotFound)?;
        let (bytes, _) = self.accessor.get_value_at(offset)?;
        str::from_utf8(bytes).map_err(|_| roto_runtime::RotoError::WireFormatViolation)
    }

    pub fn name_or_default(&self) -> roto_runtime::Result<&'a str> {
        self.name().or(Ok(""))
    }

    pub fn has_name(&self) -> bool { self.name_offset.is_some() }

    pub fn method(&self) -> roto_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)?;
        let (bytes, _) = self.accessor.get_value_at(offset)?;
        Ok(bytes)
    }

    pub fn options_or_default(&self) -> roto_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> {
        self.accessor.raw_fields()
    }

}

pub struct ServiceDescriptorProtoBuilder<'b> {
    builder: roto_runtime::ProtoBuilder<'b>,
    name_written: bool,
    method_written: bool,
    options_written: bool,
}

impl<'b> ServiceDescriptorProtoBuilder<'b> {
    pub fn builder(buf: &mut [u8]) -> ServiceDescriptorProtoBuilder<'_> {
        ServiceDescriptorProtoBuilder {
            builder: roto_runtime::ProtoBuilder::new(buf),
            name_written: false,
            method_written: false,
            options_written: false,
        }
    }

    pub fn name(mut self, value: &str) -> roto_runtime::Result<Self> {
        self.builder.write_string(1, value)?;
        self.name_written = true;
        Ok(self)
    }

    pub fn method(mut self, value: &[u8]) -> roto_runtime::Result<Self> {
        self.builder.write_bytes(2, value)?;
        self.method_written = true;
        Ok(self)
    }

    pub fn options(mut self, value: &[u8]) -> roto_runtime::Result<Self> {
        self.builder.write_bytes(3, value)?;
        self.options_written = true;
        Ok(self)
    }

    pub fn with(mut self, msg: &ServiceDescriptorProto<'_>) -> roto_runtime::Result<Self> {
        for item in msg.raw_fields() {
            let (field_number, raw_bytes) = item?;
            let is_written = match field_number {
                1 => self.name_written,
                2 => self.method_written,
                3 => self.options_written,
                _ => false,
            };
            if !is_written {
                self.builder.write_raw(raw_bytes)?;
            }
        }
        Ok(self)
    }

    pub fn finish(self) -> roto_runtime::Result<&'b mut [u8]> {
        self.builder.finish()
    }
}

pub struct OwnedServiceDescriptorProto {
    pub data: bytes::Bytes,
}

impl roto_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<Self> {
        Ok(OwnedServiceDescriptorProto { data: buf })
    }

    fn bytes(&self) -> bytes::Bytes {
        self.data.clone()
    }
}

pub struct MethodDescriptorProto<'a> {
    accessor: roto_runtime::ProtoAccessor<'a>,
    name_offset: Option<usize>,
    input_type_offset: Option<usize>,
    output_type_offset: Option<usize>,
    options_offset: Option<usize>,
    client_streaming_offset: Option<usize>,
    server_streaming_offset: Option<usize>,
}

impl<'a> MethodDescriptorProto<'a> {
    pub fn new(data: &'a [u8]) -> roto_runtime::Result<Self> {
        let accessor = roto_runtime::ProtoAccessor::new(data)?;
        let mut name_offset = None;
        let mut input_type_offset = None;
        let mut output_type_offset = None;
        let mut options_offset = None;
        let mut client_streaming_offset = None;
        let mut server_streaming_offset = None;
        for item in accessor.fields() {
            let (offset, tag, _) = item?;
            if tag.field_number == 1 { name_offset = Some(offset); }
            if tag.field_number == 2 { input_type_offset = Some(offset); }
            if tag.field_number == 3 { output_type_offset = Some(offset); }
            if tag.field_number == 4 { options_offset = Some(offset); }
            if tag.field_number == 5 { client_streaming_offset = Some(offset); }
            if tag.field_number == 6 { server_streaming_offset = Some(offset); }
        }

        Ok(Self {
            accessor,
name_offset,
input_type_offset,
output_type_offset,
options_offset,
client_streaming_offset,
server_streaming_offset,
        })
    }

    pub fn name(&self) -> roto_runtime::Result<&'a str> {
        let offset = self.name_offset.ok_or(roto_runtime::RotoError::FieldNotFound)?;
        let (bytes, _) = self.accessor.get_value_at(offset)?;
        str::from_utf8(bytes).map_err(|_| roto_runtime::RotoError::WireFormatViolation)
    }

    pub fn name_or_default(&self) -> roto_runtime::Result<&'a str> {
        self.name().or(Ok(""))
    }

    pub fn has_name(&self) -> bool { self.name_offset.is_some() }

    pub fn input_type(&self) -> roto_runtime::Result<&'a str> {
        let offset = self.input_type_offset.ok_or(roto_runtime::RotoError::FieldNotFound)?;
        let (bytes, _) = self.accessor.get_value_at(offset)?;
        str::from_utf8(bytes).map_err(|_| roto_runtime::RotoError::WireFormatViolation)
    }

    pub fn input_type_or_default(&self) -> roto_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)?;
        let (bytes, _) = self.accessor.get_value_at(offset)?;
        str::from_utf8(bytes).map_err(|_| roto_runtime::RotoError::WireFormatViolation)
    }

    pub fn output_type_or_default(&self) -> roto_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)?;
        let (bytes, _) = self.accessor.get_value_at(offset)?;
        Ok(bytes)
    }

    pub fn options_or_default(&self) -> roto_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<bool> {
        let offset = self.client_streaming_offset.ok_or(roto_runtime::RotoError::FieldNotFound)?;
        let (bytes, _) = self.accessor.get_value_at(offset)?;
        roto_runtime::read_varint(bytes).map(|(v, _)| v != 0).map_err(|_| roto_runtime::RotoError::WireFormatViolation)
    }

    pub fn client_streaming_or_default(&self) -> roto_runtime::Result<bool> {
        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<bool> {
        let offset = self.server_streaming_offset.ok_or(roto_runtime::RotoError::FieldNotFound)?;
        let (bytes, _) = self.accessor.get_value_at(offset)?;
        roto_runtime::read_varint(bytes).map(|(v, _)| v != 0).map_err(|_| roto_runtime::RotoError::WireFormatViolation)
    }

    pub fn server_streaming_or_default(&self) -> roto_runtime::Result<bool> {
        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> {
        self.accessor.raw_fields()
    }

}

pub struct MethodDescriptorProtoBuilder<'b> {
    builder: roto_runtime::ProtoBuilder<'b>,
    name_written: bool,
    input_type_written: bool,
    output_type_written: bool,
    options_written: bool,
    client_streaming_written: bool,
    server_streaming_written: bool,
}

impl<'b> MethodDescriptorProtoBuilder<'b> {
    pub fn builder(buf: &mut [u8]) -> MethodDescriptorProtoBuilder<'_> {
        MethodDescriptorProtoBuilder {
            builder: roto_runtime::ProtoBuilder::new(buf),
            name_written: false,
            input_type_written: false,
            output_type_written: false,
            options_written: false,
            client_streaming_written: false,
            server_streaming_written: false,
        }
    }

    pub fn name(mut self, value: &str) -> roto_runtime::Result<Self> {
        self.builder.write_string(1, value)?;
        self.name_written = true;
        Ok(self)
    }

    pub fn input_type(mut self, value: &str) -> roto_runtime::Result<Self> {
        self.builder.write_string(2, value)?;
        self.input_type_written = true;
        Ok(self)
    }

    pub fn output_type(mut self, value: &str) -> roto_runtime::Result<Self> {
        self.builder.write_string(3, value)?;
        self.output_type_written = true;
        Ok(self)
    }

    pub fn options(mut self, value: &[u8]) -> roto_runtime::Result<Self> {
        self.builder.write_bytes(4, value)?;
        self.options_written = true;
        Ok(self)
    }

    pub fn client_streaming(mut self, value: u64) -> roto_runtime::Result<Self> {
        self.builder.write_varint(5, value)?;
        self.client_streaming_written = true;
        Ok(self)
    }

    pub fn server_streaming(mut self, value: u64) -> roto_runtime::Result<Self> {
        self.builder.write_varint(6, value)?;
        self.server_streaming_written = true;
        Ok(self)
    }

    pub fn with(mut self, msg: &MethodDescriptorProto<'_>) -> roto_runtime::Result<Self> {
        for item in msg.raw_fields() {
            let (field_number, raw_bytes) = item?;
            let is_written = match field_number {
                1 => self.name_written,
                2 => self.input_type_written,
                3 => self.output_type_written,
                4 => self.options_written,
                5 => self.client_streaming_written,
                6 => self.server_streaming_written,
                _ => false,
            };
            if !is_written {
                self.builder.write_raw(raw_bytes)?;
            }
        }
        Ok(self)
    }

    pub fn finish(self) -> roto_runtime::Result<&'b mut [u8]> {
        self.builder.finish()
    }
}

pub struct OwnedMethodDescriptorProto {
    pub data: bytes::Bytes,
}

impl roto_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<Self> {
        Ok(OwnedMethodDescriptorProto { data: buf })
    }

    fn bytes(&self) -> bytes::Bytes {
        self.data.clone()
    }
}

pub struct FileOptions<'a> {
    accessor: roto_runtime::ProtoAccessor<'a>,
    java_package_offset: Option<usize>,
    java_outer_classname_offset: Option<usize>,
    java_multiple_files_offset: Option<usize>,
    java_generate_equals_and_hash_offset: Option<usize>,
    java_string_check_utf8_offset: Option<usize>,
    optimize_for_offset: Option<usize>,
    go_package_offset: Option<usize>,
    cc_generic_services_offset: Option<usize>,
    java_generic_services_offset: Option<usize>,
    py_generic_services_offset: Option<usize>,
    deprecated_offset: Option<usize>,
    cc_enable_arenas_offset: Option<usize>,
    objc_class_prefix_offset: Option<usize>,
    csharp_namespace_offset: Option<usize>,
    swift_prefix_offset: Option<usize>,
    php_class_prefix_offset: Option<usize>,
    php_namespace_offset: Option<usize>,
    php_metadata_namespace_offset: Option<usize>,
    ruby_package_offset: Option<usize>,
    features_offset: Option<usize>,
    uninterpreted_option_start: Option<usize>,
    uninterpreted_option_end: Option<usize>,
}

impl<'a> FileOptions<'a> {
    pub fn new(data: &'a [u8]) -> roto_runtime::Result<Self> {
        let accessor = roto_runtime::ProtoAccessor::new(data)?;
        let mut java_package_offset = None;
        let mut java_outer_classname_offset = None;
        let mut java_multiple_files_offset = None;
        let mut java_generate_equals_and_hash_offset = None;
        let mut java_string_check_utf8_offset = None;
        let mut optimize_for_offset = None;
        let mut go_package_offset = None;
        let mut cc_generic_services_offset = None;
        let mut java_generic_services_offset = None;
        let mut py_generic_services_offset = None;
        let mut deprecated_offset = None;
        let mut cc_enable_arenas_offset = None;
        let mut objc_class_prefix_offset = None;
        let mut csharp_namespace_offset = None;
        let mut swift_prefix_offset = None;
        let mut php_class_prefix_offset = None;
        let mut php_namespace_offset = None;
        let mut php_metadata_namespace_offset = None;
        let mut ruby_package_offset = None;
        let mut features_offset = None;
        let mut uninterpreted_option_start = None;
        let mut uninterpreted_option_end = None;
        for item in accessor.fields() {
            let (offset, tag, _) = item?;
            if tag.field_number == 1 { java_package_offset = Some(offset); }
            if tag.field_number == 8 { java_outer_classname_offset = Some(offset); }
            if tag.field_number == 10 { java_multiple_files_offset = Some(offset); }
            if tag.field_number == 20 { java_generate_equals_and_hash_offset = Some(offset); }
            if tag.field_number == 27 { java_string_check_utf8_offset = Some(offset); }
            if tag.field_number == 9 { optimize_for_offset = Some(offset); }
            if tag.field_number == 11 { go_package_offset = Some(offset); }
            if tag.field_number == 16 { cc_generic_services_offset = Some(offset); }
            if tag.field_number == 17 { java_generic_services_offset = Some(offset); }
            if tag.field_number == 18 { py_generic_services_offset = Some(offset); }
            if tag.field_number == 23 { deprecated_offset = Some(offset); }
            if tag.field_number == 31 { cc_enable_arenas_offset = Some(offset); }
            if tag.field_number == 36 { objc_class_prefix_offset = Some(offset); }
            if tag.field_number == 37 { csharp_namespace_offset = Some(offset); }
            if tag.field_number == 39 { swift_prefix_offset = Some(offset); }
            if tag.field_number == 40 { php_class_prefix_offset = Some(offset); }
            if tag.field_number == 41 { php_namespace_offset = Some(offset); }
            if tag.field_number == 44 { php_metadata_namespace_offset = Some(offset); }
            if tag.field_number == 45 { ruby_package_offset = Some(offset); }
            if tag.field_number == 50 { features_offset = Some(offset); }
            if tag.field_number == 999 {
                if uninterpreted_option_start.is_none() { uninterpreted_option_start = Some(offset); }
                uninterpreted_option_end = Some(offset);
            }
        }

        Ok(Self {
            accessor,
java_package_offset,
java_outer_classname_offset,
java_multiple_files_offset,
java_generate_equals_and_hash_offset,
java_string_check_utf8_offset,
optimize_for_offset,
go_package_offset,
cc_generic_services_offset,
java_generic_services_offset,
py_generic_services_offset,
deprecated_offset,
cc_enable_arenas_offset,
objc_class_prefix_offset,
csharp_namespace_offset,
swift_prefix_offset,
php_class_prefix_offset,
php_namespace_offset,
php_metadata_namespace_offset,
ruby_package_offset,
features_offset,
uninterpreted_option_start, uninterpreted_option_end,
        })
    }

    pub fn java_package(&self) -> roto_runtime::Result<&'a str> {
        let offset = self.java_package_offset.ok_or(roto_runtime::RotoError::FieldNotFound)?;
        let (bytes, _) = self.accessor.get_value_at(offset)?;
        str::from_utf8(bytes).map_err(|_| roto_runtime::RotoError::WireFormatViolation)
    }

    pub fn java_package_or_default(&self) -> roto_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)?;
        let (bytes, _) = self.accessor.get_value_at(offset)?;
        str::from_utf8(bytes).map_err(|_| roto_runtime::RotoError::WireFormatViolation)
    }

    pub fn java_outer_classname_or_default(&self) -> roto_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<bool> {
        let offset = self.java_multiple_files_offset.ok_or(roto_runtime::RotoError::FieldNotFound)?;
        let (bytes, _) = self.accessor.get_value_at(offset)?;
        roto_runtime::read_varint(bytes).map(|(v, _)| v != 0).map_err(|_| roto_runtime::RotoError::WireFormatViolation)
    }

    pub fn java_multiple_files_or_default(&self) -> roto_runtime::Result<bool> {
        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<bool> {
        let offset = self.java_generate_equals_and_hash_offset.ok_or(roto_runtime::RotoError::FieldNotFound)?;
        let (bytes, _) = self.accessor.get_value_at(offset)?;
        roto_runtime::read_varint(bytes).map(|(v, _)| v != 0).map_err(|_| roto_runtime::RotoError::WireFormatViolation)
    }

    pub fn java_generate_equals_and_hash_or_default(&self) -> roto_runtime::Result<bool> {
        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<bool> {
        let offset = self.java_string_check_utf8_offset.ok_or(roto_runtime::RotoError::FieldNotFound)?;
        let (bytes, _) = self.accessor.get_value_at(offset)?;
        roto_runtime::read_varint(bytes).map(|(v, _)| v != 0).map_err(|_| roto_runtime::RotoError::WireFormatViolation)
    }

    pub fn java_string_check_utf8_or_default(&self) -> roto_runtime::Result<bool> {
        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<u64> {
        let offset = self.optimize_for_offset.ok_or(roto_runtime::RotoError::FieldNotFound)?;
        let (bytes, _) = self.accessor.get_value_at(offset)?;
        roto_runtime::read_varint(bytes).map(|(v, _)| v as u64).map_err(|_| roto_runtime::RotoError::WireFormatViolation)
    }

    pub fn optimize_for_or_default(&self) -> roto_runtime::Result<u64> {
        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)?;
        let (bytes, _) = self.accessor.get_value_at(offset)?;
        str::from_utf8(bytes).map_err(|_| roto_runtime::RotoError::WireFormatViolation)
    }

    pub fn go_package_or_default(&self) -> roto_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<bool> {
        let offset = self.cc_generic_services_offset.ok_or(roto_runtime::RotoError::FieldNotFound)?;
        let (bytes, _) = self.accessor.get_value_at(offset)?;
        roto_runtime::read_varint(bytes).map(|(v, _)| v != 0).map_err(|_| roto_runtime::RotoError::WireFormatViolation)
    }

    pub fn cc_generic_services_or_default(&self) -> roto_runtime::Result<bool> {
        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<bool> {
        let offset = self.java_generic_services_offset.ok_or(roto_runtime::RotoError::FieldNotFound)?;
        let (bytes, _) = self.accessor.get_value_at(offset)?;
        roto_runtime::read_varint(bytes).map(|(v, _)| v != 0).map_err(|_| roto_runtime::RotoError::WireFormatViolation)
    }

    pub fn java_generic_services_or_default(&self) -> roto_runtime::Result<bool> {
        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<bool> {
        let offset = self.py_generic_services_offset.ok_or(roto_runtime::RotoError::FieldNotFound)?;
        let (bytes, _) = self.accessor.get_value_at(offset)?;
        roto_runtime::read_varint(bytes).map(|(v, _)| v != 0).map_err(|_| roto_runtime::RotoError::WireFormatViolation)
    }

    pub fn py_generic_services_or_default(&self) -> roto_runtime::Result<bool> {
        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<bool> {
        let offset = self.deprecated_offset.ok_or(roto_runtime::RotoError::FieldNotFound)?;
        let (bytes, _) = self.accessor.get_value_at(offset)?;
        roto_runtime::read_varint(bytes).map(|(v, _)| v != 0).map_err(|_| roto_runtime::RotoError::WireFormatViolation)
    }

    pub fn deprecated_or_default(&self) -> roto_runtime::Result<bool> {
        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<bool> {
        let offset = self.cc_enable_arenas_offset.ok_or(roto_runtime::RotoError::FieldNotFound)?;
        let (bytes, _) = self.accessor.get_value_at(offset)?;
        roto_runtime::read_varint(bytes).map(|(v, _)| v != 0).map_err(|_| roto_runtime::RotoError::WireFormatViolation)
    }

    pub fn cc_enable_arenas_or_default(&self) -> roto_runtime::Result<bool> {
        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)?;
        let (bytes, _) = self.accessor.get_value_at(offset)?;
        str::from_utf8(bytes).map_err(|_| roto_runtime::RotoError::WireFormatViolation)
    }

    pub fn objc_class_prefix_or_default(&self) -> roto_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)?;
        let (bytes, _) = self.accessor.get_value_at(offset)?;
        str::from_utf8(bytes).map_err(|_| roto_runtime::RotoError::WireFormatViolation)
    }

    pub fn csharp_namespace_or_default(&self) -> roto_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)?;
        let (bytes, _) = self.accessor.get_value_at(offset)?;
        str::from_utf8(bytes).map_err(|_| roto_runtime::RotoError::WireFormatViolation)
    }

    pub fn swift_prefix_or_default(&self) -> roto_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)?;
        let (bytes, _) = self.accessor.get_value_at(offset)?;
        str::from_utf8(bytes).map_err(|_| roto_runtime::RotoError::WireFormatViolation)
    }

    pub fn php_class_prefix_or_default(&self) -> roto_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)?;
        let (bytes, _) = self.accessor.get_value_at(offset)?;
        str::from_utf8(bytes).map_err(|_| roto_runtime::RotoError::WireFormatViolation)
    }

    pub fn php_namespace_or_default(&self) -> roto_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)?;
        let (bytes, _) = self.accessor.get_value_at(offset)?;
        str::from_utf8(bytes).map_err(|_| roto_runtime::RotoError::WireFormatViolation)
    }

    pub fn php_metadata_namespace_or_default(&self) -> roto_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)?;
        let (bytes, _) = self.accessor.get_value_at(offset)?;
        str::from_utf8(bytes).map_err(|_| roto_runtime::RotoError::WireFormatViolation)
    }

    pub fn ruby_package_or_default(&self) -> roto_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)?;
        let (bytes, _) = self.accessor.get_value_at(offset)?;
        Ok(bytes)
    }

    pub fn features_or_default(&self) -> roto_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> {
        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> {
        self.accessor.raw_fields()
    }

}

pub struct FileOptionsBuilder<'b> {
    builder: roto_runtime::ProtoBuilder<'b>,
    java_package_written: bool,
    java_outer_classname_written: bool,
    java_multiple_files_written: bool,
    java_generate_equals_and_hash_written: bool,
    java_string_check_utf8_written: bool,
    optimize_for_written: bool,
    go_package_written: bool,
    cc_generic_services_written: bool,
    java_generic_services_written: bool,
    py_generic_services_written: bool,
    deprecated_written: bool,
    cc_enable_arenas_written: bool,
    objc_class_prefix_written: bool,
    csharp_namespace_written: bool,
    swift_prefix_written: bool,
    php_class_prefix_written: bool,
    php_namespace_written: bool,
    php_metadata_namespace_written: bool,
    ruby_package_written: bool,
    features_written: bool,
    uninterpreted_option_written: bool,
}

impl<'b> FileOptionsBuilder<'b> {
    pub fn builder(buf: &mut [u8]) -> FileOptionsBuilder<'_> {
        FileOptionsBuilder {
            builder: roto_runtime::ProtoBuilder::new(buf),
            java_package_written: false,
            java_outer_classname_written: false,
            java_multiple_files_written: false,
            java_generate_equals_and_hash_written: false,
            java_string_check_utf8_written: false,
            optimize_for_written: false,
            go_package_written: false,
            cc_generic_services_written: false,
            java_generic_services_written: false,
            py_generic_services_written: false,
            deprecated_written: false,
            cc_enable_arenas_written: false,
            objc_class_prefix_written: false,
            csharp_namespace_written: false,
            swift_prefix_written: false,
            php_class_prefix_written: false,
            php_namespace_written: false,
            php_metadata_namespace_written: false,
            ruby_package_written: false,
            features_written: false,
            uninterpreted_option_written: false,
        }
    }

    pub fn java_package(mut self, value: &str) -> roto_runtime::Result<Self> {
        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<Self> {
        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<Self> {
        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<Self> {
        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<Self> {
        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<Self> {
        self.builder.write_varint(9, value)?;
        self.optimize_for_written = true;
        Ok(self)
    }

    pub fn go_package(mut self, value: &str) -> roto_runtime::Result<Self> {
        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<Self> {
        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<Self> {
        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<Self> {
        self.builder.write_varint(18, value)?;
        self.py_generic_services_written = true;
        Ok(self)
    }

    pub fn deprecated(mut self, value: u64) -> roto_runtime::Result<Self> {
        self.builder.write_varint(23, value)?;
        self.deprecated_written = true;
        Ok(self)
    }

    pub fn cc_enable_arenas(mut self, value: u64) -> roto_runtime::Result<Self> {
        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<Self> {
        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<Self> {
        self.builder.write_string(37, value)?;
        self.csharp_namespace_written = true;
        Ok(self)
    }

    pub fn swift_prefix(mut self, value: &str) -> roto_runtime::Result<Self> {
        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<Self> {
        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<Self> {
        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<Self> {
        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<Self> {
        self.builder.write_string(45, value)?;
        self.ruby_package_written = true;
        Ok(self)
    }

    pub fn features(mut self, value: &[u8]) -> roto_runtime::Result<Self> {
        self.builder.write_bytes(50, value)?;
        self.features_written = true;
        Ok(self)
    }

    pub fn uninterpreted_option(mut self, value: &[u8]) -> roto_runtime::Result<Self> {
        self.builder.write_bytes(999, value)?;
        self.uninterpreted_option_written = true;
        Ok(self)
    }

    pub fn with(mut self, msg: &FileOptions<'_>) -> roto_runtime::Result<Self> {
        for item in msg.raw_fields() {
            let (field_number, raw_bytes) = item?;
            let is_written = match field_number {
                1 => self.java_package_written,
                8 => self.java_outer_classname_written,
                10 => self.java_multiple_files_written,
                20 => self.java_generate_equals_and_hash_written,
                27 => self.java_string_check_utf8_written,
                9 => self.optimize_for_written,
                11 => self.go_package_written,
                16 => self.cc_generic_services_written,
                17 => self.java_generic_services_written,
                18 => self.py_generic_services_written,
                23 => self.deprecated_written,
                31 => self.cc_enable_arenas_written,
                36 => self.objc_class_prefix_written,
                37 => self.csharp_namespace_written,
                39 => self.swift_prefix_written,
                40 => self.php_class_prefix_written,
                41 => self.php_namespace_written,
                44 => self.php_metadata_namespace_written,
                45 => self.ruby_package_written,
                50 => self.features_written,
                999 => self.uninterpreted_option_written,
                _ => false,
            };
            if !is_written {
                self.builder.write_raw(raw_bytes)?;
            }
        }
        Ok(self)
    }

    pub fn finish(self) -> roto_runtime::Result<&'b mut [u8]> {
        self.builder.finish()
    }
}

pub struct OwnedFileOptions {
    pub data: bytes::Bytes,
}

impl roto_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<Self> {
        Ok(OwnedFileOptions { data: buf })
    }

    fn bytes(&self) -> bytes::Bytes {
        self.data.clone()
    }
}

pub mod file_options {
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
#[repr(i32)]
pub enum OptimizeMode {
    SPEED = 1,
    CODESIZE = 2,
    LITERUNTIME = 3,
    Unknown = 0,
}

impl OptimizeMode {
    pub fn from_i32(value: i32) -> Self {
        match value {
            1 => OptimizeMode::SPEED,
            2 => OptimizeMode::CODESIZE,
            3 => OptimizeMode::LITERUNTIME,
            _ => OptimizeMode::Unknown,
        }
    }
}

}

pub struct MessageOptions<'a> {
    accessor: roto_runtime::ProtoAccessor<'a>,
    message_set_wire_format_offset: Option<usize>,
    no_standard_descriptor_accessor_offset: Option<usize>,
    deprecated_offset: Option<usize>,
    map_entry_offset: Option<usize>,
    deprecated_legacy_json_field_conflicts_offset: Option<usize>,
    features_offset: Option<usize>,
    uninterpreted_option_start: Option<usize>,
    uninterpreted_option_end: Option<usize>,
}

impl<'a> MessageOptions<'a> {
    pub fn new(data: &'a [u8]) -> roto_runtime::Result<Self> {
        let accessor = roto_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;
        let mut map_entry_offset = None;
        let mut deprecated_legacy_json_field_conflicts_offset = None;
        let mut features_offset = None;
        let mut uninterpreted_option_start = None;
        let mut uninterpreted_option_end = None;
        for item in accessor.fields() {
            let (offset, tag, _) = item?;
            if tag.field_number == 1 { message_set_wire_format_offset = Some(offset); }
            if tag.field_number == 2 { no_standard_descriptor_accessor_offset = Some(offset); }
            if tag.field_number == 3 { deprecated_offset = Some(offset); }
            if tag.field_number == 7 { map_entry_offset = Some(offset); }
            if tag.field_number == 11 { deprecated_legacy_json_field_conflicts_offset = Some(offset); }
            if tag.field_number == 12 { features_offset = Some(offset); }
            if tag.field_number == 999 {
                if uninterpreted_option_start.is_none() { uninterpreted_option_start = Some(offset); }
                uninterpreted_option_end = Some(offset);
            }
        }

        Ok(Self {
            accessor,
message_set_wire_format_offset,
no_standard_descriptor_accessor_offset,
deprecated_offset,
map_entry_offset,
deprecated_legacy_json_field_conflicts_offset,
features_offset,
uninterpreted_option_start, uninterpreted_option_end,
        })
    }

    pub fn message_set_wire_format(&self) -> roto_runtime::Result<bool> {
        let offset = self.message_set_wire_format_offset.ok_or(roto_runtime::RotoError::FieldNotFound)?;
        let (bytes, _) = self.accessor.get_value_at(offset)?;
        roto_runtime::read_varint(bytes).map(|(v, _)| v != 0).map_err(|_| roto_runtime::RotoError::WireFormatViolation)
    }

    pub fn message_set_wire_format_or_default(&self) -> roto_runtime::Result<bool> {
        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<bool> {
        let offset = self.no_standard_descriptor_accessor_offset.ok_or(roto_runtime::RotoError::FieldNotFound)?;
        let (bytes, _) = self.accessor.get_value_at(offset)?;
        roto_runtime::read_varint(bytes).map(|(v, _)| v != 0).map_err(|_| roto_runtime::RotoError::WireFormatViolation)
    }

    pub fn no_standard_descriptor_accessor_or_default(&self) -> roto_runtime::Result<bool> {
        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<bool> {
        let offset = self.deprecated_offset.ok_or(roto_runtime::RotoError::FieldNotFound)?;
        let (bytes, _) = self.accessor.get_value_at(offset)?;
        roto_runtime::read_varint(bytes).map(|(v, _)| v != 0).map_err(|_| roto_runtime::RotoError::WireFormatViolation)
    }

    pub fn deprecated_or_default(&self) -> roto_runtime::Result<bool> {
        self.deprecated().or(Ok(false))
    }

    pub fn has_deprecated(&self) -> bool { self.deprecated_offset.is_some() }

    pub fn map_entry(&self) -> roto_runtime::Result<bool> {
        let offset = self.map_entry_offset.ok_or(roto_runtime::RotoError::FieldNotFound)?;
        let (bytes, _) = self.accessor.get_value_at(offset)?;
        roto_runtime::read_varint(bytes).map(|(v, _)| v != 0).map_err(|_| roto_runtime::RotoError::WireFormatViolation)
    }

    pub fn map_entry_or_default(&self) -> roto_runtime::Result<bool> {
        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<bool> {
        let offset = self.deprecated_legacy_json_field_conflicts_offset.ok_or(roto_runtime::RotoError::FieldNotFound)?;
        let (bytes, _) = self.accessor.get_value_at(offset)?;
        roto_runtime::read_varint(bytes).map(|(v, _)| v != 0).map_err(|_| roto_runtime::RotoError::WireFormatViolation)
    }

    pub fn deprecated_legacy_json_field_conflicts_or_default(&self) -> roto_runtime::Result<bool> {
        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)?;
        let (bytes, _) = self.accessor.get_value_at(offset)?;
        Ok(bytes)
    }

    pub fn features_or_default(&self) -> roto_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> {
        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> {
        self.accessor.raw_fields()
    }

}

pub struct MessageOptionsBuilder<'b> {
    builder: roto_runtime::ProtoBuilder<'b>,
    message_set_wire_format_written: bool,
    no_standard_descriptor_accessor_written: bool,
    deprecated_written: bool,
    map_entry_written: bool,
    deprecated_legacy_json_field_conflicts_written: bool,
    features_written: bool,
    uninterpreted_option_written: bool,
}

impl<'b> MessageOptionsBuilder<'b> {
    pub fn builder(buf: &mut [u8]) -> MessageOptionsBuilder<'_> {
        MessageOptionsBuilder {
            builder: roto_runtime::ProtoBuilder::new(buf),
            message_set_wire_format_written: false,
            no_standard_descriptor_accessor_written: false,
            deprecated_written: false,
            map_entry_written: false,
            deprecated_legacy_json_field_conflicts_written: false,
            features_written: false,
            uninterpreted_option_written: false,
        }
    }

    pub fn message_set_wire_format(mut self, value: u64) -> roto_runtime::Result<Self> {
        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<Self> {
        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<Self> {
        self.builder.write_varint(3, value)?;
        self.deprecated_written = true;
        Ok(self)
    }

    pub fn map_entry(mut self, value: u64) -> roto_runtime::Result<Self> {
        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<Self> {
        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<Self> {
        self.builder.write_bytes(12, value)?;
        self.features_written = true;
        Ok(self)
    }

    pub fn uninterpreted_option(mut self, value: &[u8]) -> roto_runtime::Result<Self> {
        self.builder.write_bytes(999, value)?;
        self.uninterpreted_option_written = true;
        Ok(self)
    }

    pub fn with(mut self, msg: &MessageOptions<'_>) -> roto_runtime::Result<Self> {
        for item in msg.raw_fields() {
            let (field_number, raw_bytes) = item?;
            let is_written = match field_number {
                1 => self.message_set_wire_format_written,
                2 => self.no_standard_descriptor_accessor_written,
                3 => self.deprecated_written,
                7 => self.map_entry_written,
                11 => self.deprecated_legacy_json_field_conflicts_written,
                12 => self.features_written,
                999 => self.uninterpreted_option_written,
                _ => false,
            };
            if !is_written {
                self.builder.write_raw(raw_bytes)?;
            }
        }
        Ok(self)
    }

    pub fn finish(self) -> roto_runtime::Result<&'b mut [u8]> {
        self.builder.finish()
    }
}

pub struct OwnedMessageOptions {
    pub data: bytes::Bytes,
}

impl roto_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<Self> {
        Ok(OwnedMessageOptions { data: buf })
    }

    fn bytes(&self) -> bytes::Bytes {
        self.data.clone()
    }
}

pub struct FieldOptions<'a> {
    accessor: roto_runtime::ProtoAccessor<'a>,
    ctype_offset: Option<usize>,
    packed_offset: Option<usize>,
    jstype_offset: Option<usize>,
    lazy_offset: Option<usize>,
    unverified_lazy_offset: Option<usize>,
    deprecated_offset: Option<usize>,
    weak_offset: Option<usize>,
    debug_redact_offset: Option<usize>,
    retention_offset: Option<usize>,
    targets_start: Option<usize>,
    targets_end: Option<usize>,
    edition_defaults_start: Option<usize>,
    edition_defaults_end: Option<usize>,
    features_offset: Option<usize>,
    feature_support_offset: Option<usize>,
    uninterpreted_option_start: Option<usize>,
    uninterpreted_option_end: Option<usize>,
}

impl<'a> FieldOptions<'a> {
    pub fn new(data: &'a [u8]) -> roto_runtime::Result<Self> {
        let accessor = roto_runtime::ProtoAccessor::new(data)?;
        let mut ctype_offset = None;
        let mut packed_offset = None;
        let mut jstype_offset = None;
        let mut lazy_offset = None;
        let mut unverified_lazy_offset = None;
        let mut deprecated_offset = None;
        let mut weak_offset = None;
        let mut debug_redact_offset = None;
        let mut retention_offset = None;
        let mut targets_start = None;
        let mut targets_end = None;
        let mut edition_defaults_start = None;
        let mut edition_defaults_end = None;
        let mut features_offset = None;
        let mut feature_support_offset = None;
        let mut uninterpreted_option_start = None;
        let mut uninterpreted_option_end = None;
        for item in accessor.fields() {
            let (offset, tag, _) = item?;
            if tag.field_number == 1 { ctype_offset = Some(offset); }
            if tag.field_number == 2 { packed_offset = Some(offset); }
            if tag.field_number == 6 { jstype_offset = Some(offset); }
            if tag.field_number == 5 { lazy_offset = Some(offset); }
            if tag.field_number == 15 { unverified_lazy_offset = Some(offset); }
            if tag.field_number == 3 { deprecated_offset = Some(offset); }
            if tag.field_number == 10 { weak_offset = Some(offset); }
            if tag.field_number == 16 { debug_redact_offset = Some(offset); }
            if tag.field_number == 17 { retention_offset = Some(offset); }
            if tag.field_number == 19 {
                if targets_start.is_none() { targets_start = Some(offset); }
                targets_end = Some(offset);
            }
            if tag.field_number == 20 {
                if edition_defaults_start.is_none() { edition_defaults_start = Some(offset); }
                edition_defaults_end = Some(offset);
            }
            if tag.field_number == 21 { features_offset = Some(offset); }
            if tag.field_number == 22 { feature_support_offset = Some(offset); }
            if tag.field_number == 999 {
                if uninterpreted_option_start.is_none() { uninterpreted_option_start = Some(offset); }
                uninterpreted_option_end = Some(offset);
            }
        }

        Ok(Self {
            accessor,
ctype_offset,
packed_offset,
jstype_offset,
lazy_offset,
unverified_lazy_offset,
deprecated_offset,
weak_offset,
debug_redact_offset,
retention_offset,
targets_start, targets_end,
edition_defaults_start, edition_defaults_end,
features_offset,
feature_support_offset,
uninterpreted_option_start, uninterpreted_option_end,
        })
    }

    pub fn ctype(&self) -> roto_runtime::Result<u64> {
        let offset = self.ctype_offset.ok_or(roto_runtime::RotoError::FieldNotFound)?;
        let (bytes, _) = self.accessor.get_value_at(offset)?;
        roto_runtime::read_varint(bytes).map(|(v, _)| v as u64).map_err(|_| roto_runtime::RotoError::WireFormatViolation)
    }

    pub fn ctype_or_default(&self) -> roto_runtime::Result<u64> {
        self.ctype().or(Ok(0))
    }

    pub fn has_ctype(&self) -> bool { self.ctype_offset.is_some() }

    pub fn packed(&self) -> roto_runtime::Result<bool> {
        let offset = self.packed_offset.ok_or(roto_runtime::RotoError::FieldNotFound)?;
        let (bytes, _) = self.accessor.get_value_at(offset)?;
        roto_runtime::read_varint(bytes).map(|(v, _)| v != 0).map_err(|_| roto_runtime::RotoError::WireFormatViolation)
    }

    pub fn packed_or_default(&self) -> roto_runtime::Result<bool> {
        self.packed().or(Ok(false))
    }

    pub fn has_packed(&self) -> bool { self.packed_offset.is_some() }

    pub fn jstype(&self) -> roto_runtime::Result<u64> {
        let offset = self.jstype_offset.ok_or(roto_runtime::RotoError::FieldNotFound)?;
        let (bytes, _) = self.accessor.get_value_at(offset)?;
        roto_runtime::read_varint(bytes).map(|(v, _)| v as u64).map_err(|_| roto_runtime::RotoError::WireFormatViolation)
    }

    pub fn jstype_or_default(&self) -> roto_runtime::Result<u64> {
        self.jstype().or(Ok(0))
    }

    pub fn has_jstype(&self) -> bool { self.jstype_offset.is_some() }

    pub fn lazy(&self) -> roto_runtime::Result<bool> {
        let offset = self.lazy_offset.ok_or(roto_runtime::RotoError::FieldNotFound)?;
        let (bytes, _) = self.accessor.get_value_at(offset)?;
        roto_runtime::read_varint(bytes).map(|(v, _)| v != 0).map_err(|_| roto_runtime::RotoError::WireFormatViolation)
    }

    pub fn lazy_or_default(&self) -> roto_runtime::Result<bool> {
        self.lazy().or(Ok(false))
    }

    pub fn has_lazy(&self) -> bool { self.lazy_offset.is_some() }

    pub fn unverified_lazy(&self) -> roto_runtime::Result<bool> {
        let offset = self.unverified_lazy_offset.ok_or(roto_runtime::RotoError::FieldNotFound)?;
        let (bytes, _) = self.accessor.get_value_at(offset)?;
        roto_runtime::read_varint(bytes).map(|(v, _)| v != 0).map_err(|_| roto_runtime::RotoError::WireFormatViolation)
    }

    pub fn unverified_lazy_or_default(&self) -> roto_runtime::Result<bool> {
        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<bool> {
        let offset = self.deprecated_offset.ok_or(roto_runtime::RotoError::FieldNotFound)?;
        let (bytes, _) = self.accessor.get_value_at(offset)?;
        roto_runtime::read_varint(bytes).map(|(v, _)| v != 0).map_err(|_| roto_runtime::RotoError::WireFormatViolation)
    }

    pub fn deprecated_or_default(&self) -> roto_runtime::Result<bool> {
        self.deprecated().or(Ok(false))
    }

    pub fn has_deprecated(&self) -> bool { self.deprecated_offset.is_some() }

    pub fn weak(&self) -> roto_runtime::Result<bool> {
        let offset = self.weak_offset.ok_or(roto_runtime::RotoError::FieldNotFound)?;
        let (bytes, _) = self.accessor.get_value_at(offset)?;
        roto_runtime::read_varint(bytes).map(|(v, _)| v != 0).map_err(|_| roto_runtime::RotoError::WireFormatViolation)
    }

    pub fn weak_or_default(&self) -> roto_runtime::Result<bool> {
        self.weak().or(Ok(false))
    }

    pub fn has_weak(&self) -> bool { self.weak_offset.is_some() }

    pub fn debug_redact(&self) -> roto_runtime::Result<bool> {
        let offset = self.debug_redact_offset.ok_or(roto_runtime::RotoError::FieldNotFound)?;
        let (bytes, _) = self.accessor.get_value_at(offset)?;
        roto_runtime::read_varint(bytes).map(|(v, _)| v != 0).map_err(|_| roto_runtime::RotoError::WireFormatViolation)
    }

    pub fn debug_redact_or_default(&self) -> roto_runtime::Result<bool> {
        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<u64> {
        let offset = self.retention_offset.ok_or(roto_runtime::RotoError::FieldNotFound)?;
        let (bytes, _) = self.accessor.get_value_at(offset)?;
        roto_runtime::read_varint(bytes).map(|(v, _)| v as u64).map_err(|_| roto_runtime::RotoError::WireFormatViolation)
    }

    pub fn retention_or_default(&self) -> roto_runtime::Result<u64> {
        self.retention().or(Ok(0))
    }

    pub fn has_retention(&self) -> bool { self.retention_offset.is_some() }

    pub fn targets(&self) -> roto_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> {
        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)?;
        let (bytes, _) = self.accessor.get_value_at(offset)?;
        Ok(bytes)
    }

    pub fn features_or_default(&self) -> roto_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)?;
        let (bytes, _) = self.accessor.get_value_at(offset)?;
        Ok(bytes)
    }

    pub fn feature_support_or_default(&self) -> roto_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> {
        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> {
        self.accessor.raw_fields()
    }

}

pub struct FieldOptionsBuilder<'b> {
    builder: roto_runtime::ProtoBuilder<'b>,
    ctype_written: bool,
    packed_written: bool,
    jstype_written: bool,
    lazy_written: bool,
    unverified_lazy_written: bool,
    deprecated_written: bool,
    weak_written: bool,
    debug_redact_written: bool,
    retention_written: bool,
    targets_written: bool,
    edition_defaults_written: bool,
    features_written: bool,
    feature_support_written: bool,
    uninterpreted_option_written: bool,
}

impl<'b> FieldOptionsBuilder<'b> {
    pub fn builder(buf: &mut [u8]) -> FieldOptionsBuilder<'_> {
        FieldOptionsBuilder {
            builder: roto_runtime::ProtoBuilder::new(buf),
            ctype_written: false,
            packed_written: false,
            jstype_written: false,
            lazy_written: false,
            unverified_lazy_written: false,
            deprecated_written: false,
            weak_written: false,
            debug_redact_written: false,
            retention_written: false,
            targets_written: false,
            edition_defaults_written: false,
            features_written: false,
            feature_support_written: false,
            uninterpreted_option_written: false,
        }
    }

    pub fn ctype(mut self, value: u64) -> roto_runtime::Result<Self> {
        self.builder.write_varint(1, value)?;
        self.ctype_written = true;
        Ok(self)
    }

    pub fn packed(mut self, value: u64) -> roto_runtime::Result<Self> {
        self.builder.write_varint(2, value)?;
        self.packed_written = true;
        Ok(self)
    }

    pub fn jstype(mut self, value: u64) -> roto_runtime::Result<Self> {
        self.builder.write_varint(6, value)?;
        self.jstype_written = true;
        Ok(self)
    }

    pub fn lazy(mut self, value: u64) -> roto_runtime::Result<Self> {
        self.builder.write_varint(5, value)?;
        self.lazy_written = true;
        Ok(self)
    }

    pub fn unverified_lazy(mut self, value: u64) -> roto_runtime::Result<Self> {
        self.builder.write_varint(15, value)?;
        self.unverified_lazy_written = true;
        Ok(self)
    }

    pub fn deprecated(mut self, value: u64) -> roto_runtime::Result<Self> {
        self.builder.write_varint(3, value)?;
        self.deprecated_written = true;
        Ok(self)
    }

    pub fn weak(mut self, value: u64) -> roto_runtime::Result<Self> {
        self.builder.write_varint(10, value)?;
        self.weak_written = true;
        Ok(self)
    }

    pub fn debug_redact(mut self, value: u64) -> roto_runtime::Result<Self> {
        self.builder.write_varint(16, value)?;
        self.debug_redact_written = true;
        Ok(self)
    }

    pub fn retention(mut self, value: u64) -> roto_runtime::Result<Self> {
        self.builder.write_varint(17, value)?;
        self.retention_written = true;
        Ok(self)
    }

    pub fn targets(mut self, value: u64) -> roto_runtime::Result<Self> {
        self.builder.write_varint(19, value)?;
        self.targets_written = true;
        Ok(self)
    }

    pub fn edition_defaults(mut self, value: &[u8]) -> roto_runtime::Result<Self> {
        self.builder.write_bytes(20, value)?;
        self.edition_defaults_written = true;
        Ok(self)
    }

    pub fn features(mut self, value: &[u8]) -> roto_runtime::Result<Self> {
        self.builder.write_bytes(21, value)?;
        self.features_written = true;
        Ok(self)
    }

    pub fn feature_support(mut self, value: &[u8]) -> roto_runtime::Result<Self> {
        self.builder.write_bytes(22, value)?;
        self.feature_support_written = true;
        Ok(self)
    }

    pub fn uninterpreted_option(mut self, value: &[u8]) -> roto_runtime::Result<Self> {
        self.builder.write_bytes(999, value)?;
        self.uninterpreted_option_written = true;
        Ok(self)
    }

    pub fn with(mut self, msg: &FieldOptions<'_>) -> roto_runtime::Result<Self> {
        for item in msg.raw_fields() {
            let (field_number, raw_bytes) = item?;
            let is_written = match field_number {
                1 => self.ctype_written,
                2 => self.packed_written,
                6 => self.jstype_written,
                5 => self.lazy_written,
                15 => self.unverified_lazy_written,
                3 => self.deprecated_written,
                10 => self.weak_written,
                16 => self.debug_redact_written,
                17 => self.retention_written,
                19 => self.targets_written,
                20 => self.edition_defaults_written,
                21 => self.features_written,
                22 => self.feature_support_written,
                999 => self.uninterpreted_option_written,
                _ => false,
            };
            if !is_written {
                self.builder.write_raw(raw_bytes)?;
            }
        }
        Ok(self)
    }

    pub fn finish(self) -> roto_runtime::Result<&'b mut [u8]> {
        self.builder.finish()
    }
}

pub struct OwnedFieldOptions {
    pub data: bytes::Bytes,
}

impl roto_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<Self> {
        Ok(OwnedFieldOptions { data: buf })
    }

    fn bytes(&self) -> bytes::Bytes {
        self.data.clone()
    }
}

pub mod field_options {
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
#[repr(i32)]
pub enum CType {
    STRING = 0,
    CORD = 1,
    STRINGPIECE = 2,
}

impl CType {
    pub fn from_i32(value: i32) -> Self {
        match value {
            0 => CType::STRING,
            1 => CType::CORD,
            2 => CType::STRINGPIECE,
            _ => CType::STRING,
        }
    }
}

#[derive(Debug, Clone, Copy, PartialEq, Eq)]
#[repr(i32)]
pub enum JSType {
    JSNORMAL = 0,
    JSSTRING = 1,
    JSNUMBER = 2,
}

impl JSType {
    pub fn from_i32(value: i32) -> Self {
        match value {
            0 => JSType::JSNORMAL,
            1 => JSType::JSSTRING,
            2 => JSType::JSNUMBER,
            _ => JSType::JSNORMAL,
        }
    }
}

#[derive(Debug, Clone, Copy, PartialEq, Eq)]
#[repr(i32)]
pub enum OptionRetention {
    RETENTIONUNKNOWN = 0,
    RETENTIONRUNTIME = 1,
    RETENTIONSOURCE = 2,
}

impl OptionRetention {
    pub fn from_i32(value: i32) -> Self {
        match value {
            0 => OptionRetention::RETENTIONUNKNOWN,
            1 => OptionRetention::RETENTIONRUNTIME,
            2 => OptionRetention::RETENTIONSOURCE,
            _ => OptionRetention::RETENTIONUNKNOWN,
        }
    }
}

#[derive(Debug, Clone, Copy, PartialEq, Eq)]
#[repr(i32)]
pub enum OptionTargetType {
    TARGETTYPEUNKNOWN = 0,
    TARGETTYPEFILE = 1,
    TARGETTYPEEXTENSIONRANGE = 2,
    TARGETTYPEMESSAGE = 3,
    TARGETTYPEFIELD = 4,
    TARGETTYPEONEOF = 5,
    TARGETTYPEENUM = 6,
    TARGETTYPEENUMENTRY = 7,
    TARGETTYPESERVICE = 8,
    TARGETTYPEMETHOD = 9,
}

impl OptionTargetType {
    pub fn from_i32(value: i32) -> Self {
        match value {
            0 => OptionTargetType::TARGETTYPEUNKNOWN,
            1 => OptionTargetType::TARGETTYPEFILE,
            2 => OptionTargetType::TARGETTYPEEXTENSIONRANGE,
            3 => OptionTargetType::TARGETTYPEMESSAGE,
            4 => OptionTargetType::TARGETTYPEFIELD,
            5 => OptionTargetType::TARGETTYPEONEOF,
            6 => OptionTargetType::TARGETTYPEENUM,
            7 => OptionTargetType::TARGETTYPEENUMENTRY,
            8 => OptionTargetType::TARGETTYPESERVICE,
            9 => OptionTargetType::TARGETTYPEMETHOD,
            _ => OptionTargetType::TARGETTYPEUNKNOWN,
        }
    }
}

pub struct EditionDefault<'a> {
    accessor: roto_runtime::ProtoAccessor<'a>,
    edition_offset: Option<usize>,
    value_offset: Option<usize>,
}

impl<'a> EditionDefault<'a> {
    pub fn new(data: &'a [u8]) -> roto_runtime::Result<Self> {
        let accessor = roto_runtime::ProtoAccessor::new(data)?;
        let mut edition_offset = None;
        let mut value_offset = None;
        for item in accessor.fields() {
            let (offset, tag, _) = item?;
            if tag.field_number == 3 { edition_offset = Some(offset); }
            if tag.field_number == 2 { value_offset = Some(offset); }
        }

        Ok(Self {
            accessor,
edition_offset,
value_offset,
        })
    }

    pub fn edition(&self) -> roto_runtime::Result<u64> {
        let offset = self.edition_offset.ok_or(roto_runtime::RotoError::FieldNotFound)?;
        let (bytes, _) = self.accessor.get_value_at(offset)?;
        roto_runtime::read_varint(bytes).map(|(v, _)| v as u64).map_err(|_| roto_runtime::RotoError::WireFormatViolation)
    }

    pub fn edition_or_default(&self) -> roto_runtime::Result<u64> {
        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)?;
        let (bytes, _) = self.accessor.get_value_at(offset)?;
        str::from_utf8(bytes).map_err(|_| roto_runtime::RotoError::WireFormatViolation)
    }

    pub fn value_or_default(&self) -> roto_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> {
        self.accessor.raw_fields()
    }

}

pub struct EditionDefaultBuilder<'b> {
    builder: roto_runtime::ProtoBuilder<'b>,
    edition_written: bool,
    value_written: bool,
}

impl<'b> EditionDefaultBuilder<'b> {
    pub fn builder(buf: &mut [u8]) -> EditionDefaultBuilder<'_> {
        EditionDefaultBuilder {
            builder: roto_runtime::ProtoBuilder::new(buf),
            edition_written: false,
            value_written: false,
        }
    }

    pub fn edition(mut self, value: u64) -> roto_runtime::Result<Self> {
        self.builder.write_varint(3, value)?;
        self.edition_written = true;
        Ok(self)
    }

    pub fn value(mut self, value: &str) -> roto_runtime::Result<Self> {
        self.builder.write_string(2, value)?;
        self.value_written = true;
        Ok(self)
    }

    pub fn with(mut self, msg: &EditionDefault<'_>) -> roto_runtime::Result<Self> {
        for item in msg.raw_fields() {
            let (field_number, raw_bytes) = item?;
            let is_written = match field_number {
                3 => self.edition_written,
                2 => self.value_written,
                _ => false,
            };
            if !is_written {
                self.builder.write_raw(raw_bytes)?;
            }
        }
        Ok(self)
    }

    pub fn finish(self) -> roto_runtime::Result<&'b mut [u8]> {
        self.builder.finish()
    }
}

pub struct OwnedEditionDefault {
    pub data: bytes::Bytes,
}

impl roto_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<Self> {
        Ok(OwnedEditionDefault { data: buf })
    }

    fn bytes(&self) -> bytes::Bytes {
        self.data.clone()
    }
}

pub struct FeatureSupport<'a> {
    accessor: roto_runtime::ProtoAccessor<'a>,
    edition_introduced_offset: Option<usize>,
    edition_deprecated_offset: Option<usize>,
    deprecation_warning_offset: Option<usize>,
    edition_removed_offset: Option<usize>,
    removal_error_offset: Option<usize>,
}

impl<'a> FeatureSupport<'a> {
    pub fn new(data: &'a [u8]) -> roto_runtime::Result<Self> {
        let accessor = roto_runtime::ProtoAccessor::new(data)?;
        let mut edition_introduced_offset = None;
        let mut edition_deprecated_offset = None;
        let mut deprecation_warning_offset = None;
        let mut edition_removed_offset = None;
        let mut removal_error_offset = None;
        for item in accessor.fields() {
            let (offset, tag, _) = item?;
            if tag.field_number == 1 { edition_introduced_offset = Some(offset); }
            if tag.field_number == 2 { edition_deprecated_offset = Some(offset); }
            if tag.field_number == 3 { deprecation_warning_offset = Some(offset); }
            if tag.field_number == 4 { edition_removed_offset = Some(offset); }
            if tag.field_number == 5 { removal_error_offset = Some(offset); }
        }

        Ok(Self {
            accessor,
edition_introduced_offset,
edition_deprecated_offset,
deprecation_warning_offset,
edition_removed_offset,
removal_error_offset,
        })
    }

    pub fn edition_introduced(&self) -> roto_runtime::Result<u64> {
        let offset = self.edition_introduced_offset.ok_or(roto_runtime::RotoError::FieldNotFound)?;
        let (bytes, _) = self.accessor.get_value_at(offset)?;
        roto_runtime::read_varint(bytes).map(|(v, _)| v as u64).map_err(|_| roto_runtime::RotoError::WireFormatViolation)
    }

    pub fn edition_introduced_or_default(&self) -> roto_runtime::Result<u64> {
        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<u64> {
        let offset = self.edition_deprecated_offset.ok_or(roto_runtime::RotoError::FieldNotFound)?;
        let (bytes, _) = self.accessor.get_value_at(offset)?;
        roto_runtime::read_varint(bytes).map(|(v, _)| v as u64).map_err(|_| roto_runtime::RotoError::WireFormatViolation)
    }

    pub fn edition_deprecated_or_default(&self) -> roto_runtime::Result<u64> {
        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)?;
        let (bytes, _) = self.accessor.get_value_at(offset)?;
        str::from_utf8(bytes).map_err(|_| roto_runtime::RotoError::WireFormatViolation)
    }

    pub fn deprecation_warning_or_default(&self) -> roto_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<u64> {
        let offset = self.edition_removed_offset.ok_or(roto_runtime::RotoError::FieldNotFound)?;
        let (bytes, _) = self.accessor.get_value_at(offset)?;
        roto_runtime::read_varint(bytes).map(|(v, _)| v as u64).map_err(|_| roto_runtime::RotoError::WireFormatViolation)
    }

    pub fn edition_removed_or_default(&self) -> roto_runtime::Result<u64> {
        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)?;
        let (bytes, _) = self.accessor.get_value_at(offset)?;
        str::from_utf8(bytes).map_err(|_| roto_runtime::RotoError::WireFormatViolation)
    }

    pub fn removal_error_or_default(&self) -> roto_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> {
        self.accessor.raw_fields()
    }

}

pub struct FeatureSupportBuilder<'b> {
    builder: roto_runtime::ProtoBuilder<'b>,
    edition_introduced_written: bool,
    edition_deprecated_written: bool,
    deprecation_warning_written: bool,
    edition_removed_written: bool,
    removal_error_written: bool,
}

impl<'b> FeatureSupportBuilder<'b> {
    pub fn builder(buf: &mut [u8]) -> FeatureSupportBuilder<'_> {
        FeatureSupportBuilder {
            builder: roto_runtime::ProtoBuilder::new(buf),
            edition_introduced_written: false,
            edition_deprecated_written: false,
            deprecation_warning_written: false,
            edition_removed_written: false,
            removal_error_written: false,
        }
    }

    pub fn edition_introduced(mut self, value: u64) -> roto_runtime::Result<Self> {
        self.builder.write_varint(1, value)?;
        self.edition_introduced_written = true;
        Ok(self)
    }

    pub fn edition_deprecated(mut self, value: u64) -> roto_runtime::Result<Self> {
        self.builder.write_varint(2, value)?;
        self.edition_deprecated_written = true;
        Ok(self)
    }

    pub fn deprecation_warning(mut self, value: &str) -> roto_runtime::Result<Self> {
        self.builder.write_string(3, value)?;
        self.deprecation_warning_written = true;
        Ok(self)
    }

    pub fn edition_removed(mut self, value: u64) -> roto_runtime::Result<Self> {
        self.builder.write_varint(4, value)?;
        self.edition_removed_written = true;
        Ok(self)
    }

    pub fn removal_error(mut self, value: &str) -> roto_runtime::Result<Self> {
        self.builder.write_string(5, value)?;
        self.removal_error_written = true;
        Ok(self)
    }

    pub fn with(mut self, msg: &FeatureSupport<'_>) -> roto_runtime::Result<Self> {
        for item in msg.raw_fields() {
            let (field_number, raw_bytes) = item?;
            let is_written = match field_number {
                1 => self.edition_introduced_written,
                2 => self.edition_deprecated_written,
                3 => self.deprecation_warning_written,
                4 => self.edition_removed_written,
                5 => self.removal_error_written,
                _ => false,
            };
            if !is_written {
                self.builder.write_raw(raw_bytes)?;
            }
        }
        Ok(self)
    }

    pub fn finish(self) -> roto_runtime::Result<&'b mut [u8]> {
        self.builder.finish()
    }
}

pub struct OwnedFeatureSupport {
    pub data: bytes::Bytes,
}

impl roto_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<Self> {
        Ok(OwnedFeatureSupport { data: buf })
    }

    fn bytes(&self) -> bytes::Bytes {
        self.data.clone()
    }
}

}

pub struct OneofOptions<'a> {
    accessor: roto_runtime::ProtoAccessor<'a>,
    features_offset: Option<usize>,
    uninterpreted_option_start: Option<usize>,
    uninterpreted_option_end: Option<usize>,
}

impl<'a> OneofOptions<'a> {
    pub fn new(data: &'a [u8]) -> roto_runtime::Result<Self> {
        let accessor = roto_runtime::ProtoAccessor::new(data)?;
        let mut features_offset = None;
        let mut uninterpreted_option_start = None;
        let mut uninterpreted_option_end = None;
        for item in accessor.fields() {
            let (offset, tag, _) = item?;
            if tag.field_number == 1 { features_offset = Some(offset); }
            if tag.field_number == 999 {
                if uninterpreted_option_start.is_none() { uninterpreted_option_start = Some(offset); }
                uninterpreted_option_end = Some(offset);
            }
        }

        Ok(Self {
            accessor,
features_offset,
uninterpreted_option_start, uninterpreted_option_end,
        })
    }

    pub fn features(&self) -> roto_runtime::Result<&'a [u8]> {
        let offset = self.features_offset.ok_or(roto_runtime::RotoError::FieldNotFound)?;
        let (bytes, _) = self.accessor.get_value_at(offset)?;
        Ok(bytes)
    }

    pub fn features_or_default(&self) -> roto_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> {
        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> {
        self.accessor.raw_fields()
    }

}

pub struct OneofOptionsBuilder<'b> {
    builder: roto_runtime::ProtoBuilder<'b>,
    features_written: bool,
    uninterpreted_option_written: bool,
}

impl<'b> OneofOptionsBuilder<'b> {
    pub fn builder(buf: &mut [u8]) -> OneofOptionsBuilder<'_> {
        OneofOptionsBuilder {
            builder: roto_runtime::ProtoBuilder::new(buf),
            features_written: false,
            uninterpreted_option_written: false,
        }
    }

    pub fn features(mut self, value: &[u8]) -> roto_runtime::Result<Self> {
        self.builder.write_bytes(1, value)?;
        self.features_written = true;
        Ok(self)
    }

    pub fn uninterpreted_option(mut self, value: &[u8]) -> roto_runtime::Result<Self> {
        self.builder.write_bytes(999, value)?;
        self.uninterpreted_option_written = true;
        Ok(self)
    }

    pub fn with(mut self, msg: &OneofOptions<'_>) -> roto_runtime::Result<Self> {
        for item in msg.raw_fields() {
            let (field_number, raw_bytes) = item?;
            let is_written = match field_number {
                1 => self.features_written,
                999 => self.uninterpreted_option_written,
                _ => false,
            };
            if !is_written {
                self.builder.write_raw(raw_bytes)?;
            }
        }
        Ok(self)
    }

    pub fn finish(self) -> roto_runtime::Result<&'b mut [u8]> {
        self.builder.finish()
    }
}

pub struct OwnedOneofOptions {
    pub data: bytes::Bytes,
}

impl roto_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<Self> {
        Ok(OwnedOneofOptions { data: buf })
    }

    fn bytes(&self) -> bytes::Bytes {
        self.data.clone()
    }
}

pub struct EnumOptions<'a> {
    accessor: roto_runtime::ProtoAccessor<'a>,
    allow_alias_offset: Option<usize>,
    deprecated_offset: Option<usize>,
    deprecated_legacy_json_field_conflicts_offset: Option<usize>,
    features_offset: Option<usize>,
    uninterpreted_option_start: Option<usize>,
    uninterpreted_option_end: Option<usize>,
}

impl<'a> EnumOptions<'a> {
    pub fn new(data: &'a [u8]) -> roto_runtime::Result<Self> {
        let accessor = roto_runtime::ProtoAccessor::new(data)?;
        let mut allow_alias_offset = None;
        let mut deprecated_offset = None;
        let mut deprecated_legacy_json_field_conflicts_offset = None;
        let mut features_offset = None;
        let mut uninterpreted_option_start = None;
        let mut uninterpreted_option_end = None;
        for item in accessor.fields() {
            let (offset, tag, _) = item?;
            if tag.field_number == 2 { allow_alias_offset = Some(offset); }
            if tag.field_number == 3 { deprecated_offset = Some(offset); }
            if tag.field_number == 6 { deprecated_legacy_json_field_conflicts_offset = Some(offset); }
            if tag.field_number == 7 { features_offset = Some(offset); }
            if tag.field_number == 999 {
                if uninterpreted_option_start.is_none() { uninterpreted_option_start = Some(offset); }
                uninterpreted_option_end = Some(offset);
            }
        }

        Ok(Self {
            accessor,
allow_alias_offset,
deprecated_offset,
deprecated_legacy_json_field_conflicts_offset,
features_offset,
uninterpreted_option_start, uninterpreted_option_end,
        })
    }

    pub fn allow_alias(&self) -> roto_runtime::Result<bool> {
        let offset = self.allow_alias_offset.ok_or(roto_runtime::RotoError::FieldNotFound)?;
        let (bytes, _) = self.accessor.get_value_at(offset)?;
        roto_runtime::read_varint(bytes).map(|(v, _)| v != 0).map_err(|_| roto_runtime::RotoError::WireFormatViolation)
    }

    pub fn allow_alias_or_default(&self) -> roto_runtime::Result<bool> {
        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<bool> {
        let offset = self.deprecated_offset.ok_or(roto_runtime::RotoError::FieldNotFound)?;
        let (bytes, _) = self.accessor.get_value_at(offset)?;
        roto_runtime::read_varint(bytes).map(|(v, _)| v != 0).map_err(|_| roto_runtime::RotoError::WireFormatViolation)
    }

    pub fn deprecated_or_default(&self) -> roto_runtime::Result<bool> {
        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<bool> {
        let offset = self.deprecated_legacy_json_field_conflicts_offset.ok_or(roto_runtime::RotoError::FieldNotFound)?;
        let (bytes, _) = self.accessor.get_value_at(offset)?;
        roto_runtime::read_varint(bytes).map(|(v, _)| v != 0).map_err(|_| roto_runtime::RotoError::WireFormatViolation)
    }

    pub fn deprecated_legacy_json_field_conflicts_or_default(&self) -> roto_runtime::Result<bool> {
        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)?;
        let (bytes, _) = self.accessor.get_value_at(offset)?;
        Ok(bytes)
    }

    pub fn features_or_default(&self) -> roto_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> {
        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> {
        self.accessor.raw_fields()
    }

}

pub struct EnumOptionsBuilder<'b> {
    builder: roto_runtime::ProtoBuilder<'b>,
    allow_alias_written: bool,
    deprecated_written: bool,
    deprecated_legacy_json_field_conflicts_written: bool,
    features_written: bool,
    uninterpreted_option_written: bool,
}

impl<'b> EnumOptionsBuilder<'b> {
    pub fn builder(buf: &mut [u8]) -> EnumOptionsBuilder<'_> {
        EnumOptionsBuilder {
            builder: roto_runtime::ProtoBuilder::new(buf),
            allow_alias_written: false,
            deprecated_written: false,
            deprecated_legacy_json_field_conflicts_written: false,
            features_written: false,
            uninterpreted_option_written: false,
        }
    }

    pub fn allow_alias(mut self, value: u64) -> roto_runtime::Result<Self> {
        self.builder.write_varint(2, value)?;
        self.allow_alias_written = true;
        Ok(self)
    }

    pub fn deprecated(mut self, value: u64) -> roto_runtime::Result<Self> {
        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<Self> {
        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<Self> {
        self.builder.write_bytes(7, value)?;
        self.features_written = true;
        Ok(self)
    }

    pub fn uninterpreted_option(mut self, value: &[u8]) -> roto_runtime::Result<Self> {
        self.builder.write_bytes(999, value)?;
        self.uninterpreted_option_written = true;
        Ok(self)
    }

    pub fn with(mut self, msg: &EnumOptions<'_>) -> roto_runtime::Result<Self> {
        for item in msg.raw_fields() {
            let (field_number, raw_bytes) = item?;
            let is_written = match field_number {
                2 => self.allow_alias_written,
                3 => self.deprecated_written,
                6 => self.deprecated_legacy_json_field_conflicts_written,
                7 => self.features_written,
                999 => self.uninterpreted_option_written,
                _ => false,
            };
            if !is_written {
                self.builder.write_raw(raw_bytes)?;
            }
        }
        Ok(self)
    }

    pub fn finish(self) -> roto_runtime::Result<&'b mut [u8]> {
        self.builder.finish()
    }
}

pub struct OwnedEnumOptions {
    pub data: bytes::Bytes,
}

impl roto_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<Self> {
        Ok(OwnedEnumOptions { data: buf })
    }

    fn bytes(&self) -> bytes::Bytes {
        self.data.clone()
    }
}

pub struct EnumValueOptions<'a> {
    accessor: roto_runtime::ProtoAccessor<'a>,
    deprecated_offset: Option<usize>,
    features_offset: Option<usize>,
    debug_redact_offset: Option<usize>,
    feature_support_offset: Option<usize>,
    uninterpreted_option_start: Option<usize>,
    uninterpreted_option_end: Option<usize>,
}

impl<'a> EnumValueOptions<'a> {
    pub fn new(data: &'a [u8]) -> roto_runtime::Result<Self> {
        let accessor = roto_runtime::ProtoAccessor::new(data)?;
        let mut deprecated_offset = None;
        let mut features_offset = None;
        let mut debug_redact_offset = None;
        let mut feature_support_offset = None;
        let mut uninterpreted_option_start = None;
        let mut uninterpreted_option_end = None;
        for item in accessor.fields() {
            let (offset, tag, _) = item?;
            if tag.field_number == 1 { deprecated_offset = Some(offset); }
            if tag.field_number == 2 { features_offset = Some(offset); }
            if tag.field_number == 3 { debug_redact_offset = Some(offset); }
            if tag.field_number == 4 { feature_support_offset = Some(offset); }
            if tag.field_number == 999 {
                if uninterpreted_option_start.is_none() { uninterpreted_option_start = Some(offset); }
                uninterpreted_option_end = Some(offset);
            }
        }

        Ok(Self {
            accessor,
deprecated_offset,
features_offset,
debug_redact_offset,
feature_support_offset,
uninterpreted_option_start, uninterpreted_option_end,
        })
    }

    pub fn deprecated(&self) -> roto_runtime::Result<bool> {
        let offset = self.deprecated_offset.ok_or(roto_runtime::RotoError::FieldNotFound)?;
        let (bytes, _) = self.accessor.get_value_at(offset)?;
        roto_runtime::read_varint(bytes).map(|(v, _)| v != 0).map_err(|_| roto_runtime::RotoError::WireFormatViolation)
    }

    pub fn deprecated_or_default(&self) -> roto_runtime::Result<bool> {
        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)?;
        let (bytes, _) = self.accessor.get_value_at(offset)?;
        Ok(bytes)
    }

    pub fn features_or_default(&self) -> roto_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<bool> {
        let offset = self.debug_redact_offset.ok_or(roto_runtime::RotoError::FieldNotFound)?;
        let (bytes, _) = self.accessor.get_value_at(offset)?;
        roto_runtime::read_varint(bytes).map(|(v, _)| v != 0).map_err(|_| roto_runtime::RotoError::WireFormatViolation)
    }

    pub fn debug_redact_or_default(&self) -> roto_runtime::Result<bool> {
        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)?;
        let (bytes, _) = self.accessor.get_value_at(offset)?;
        Ok(bytes)
    }

    pub fn feature_support_or_default(&self) -> roto_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> {
        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> {
        self.accessor.raw_fields()
    }

}

pub struct EnumValueOptionsBuilder<'b> {
    builder: roto_runtime::ProtoBuilder<'b>,
    deprecated_written: bool,
    features_written: bool,
    debug_redact_written: bool,
    feature_support_written: bool,
    uninterpreted_option_written: bool,
}

impl<'b> EnumValueOptionsBuilder<'b> {
    pub fn builder(buf: &mut [u8]) -> EnumValueOptionsBuilder<'_> {
        EnumValueOptionsBuilder {
            builder: roto_runtime::ProtoBuilder::new(buf),
            deprecated_written: false,
            features_written: false,
            debug_redact_written: false,
            feature_support_written: false,
            uninterpreted_option_written: false,
        }
    }

    pub fn deprecated(mut self, value: u64) -> roto_runtime::Result<Self> {
        self.builder.write_varint(1, value)?;
        self.deprecated_written = true;
        Ok(self)
    }

    pub fn features(mut self, value: &[u8]) -> roto_runtime::Result<Self> {
        self.builder.write_bytes(2, value)?;
        self.features_written = true;
        Ok(self)
    }

    pub fn debug_redact(mut self, value: u64) -> roto_runtime::Result<Self> {
        self.builder.write_varint(3, value)?;
        self.debug_redact_written = true;
        Ok(self)
    }

    pub fn feature_support(mut self, value: &[u8]) -> roto_runtime::Result<Self> {
        self.builder.write_bytes(4, value)?;
        self.feature_support_written = true;
        Ok(self)
    }

    pub fn uninterpreted_option(mut self, value: &[u8]) -> roto_runtime::Result<Self> {
        self.builder.write_bytes(999, value)?;
        self.uninterpreted_option_written = true;
        Ok(self)
    }

    pub fn with(mut self, msg: &EnumValueOptions<'_>) -> roto_runtime::Result<Self> {
        for item in msg.raw_fields() {
            let (field_number, raw_bytes) = item?;
            let is_written = match field_number {
                1 => self.deprecated_written,
                2 => self.features_written,
                3 => self.debug_redact_written,
                4 => self.feature_support_written,
                999 => self.uninterpreted_option_written,
                _ => false,
            };
            if !is_written {
                self.builder.write_raw(raw_bytes)?;
            }
        }
        Ok(self)
    }

    pub fn finish(self) -> roto_runtime::Result<&'b mut [u8]> {
        self.builder.finish()
    }
}

pub struct OwnedEnumValueOptions {
    pub data: bytes::Bytes,
}

impl roto_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<Self> {
        Ok(OwnedEnumValueOptions { data: buf })
    }

    fn bytes(&self) -> bytes::Bytes {
        self.data.clone()
    }
}

pub struct ServiceOptions<'a> {
    accessor: roto_runtime::ProtoAccessor<'a>,
    features_offset: Option<usize>,
    deprecated_offset: Option<usize>,
    uninterpreted_option_start: Option<usize>,
    uninterpreted_option_end: Option<usize>,
}

impl<'a> ServiceOptions<'a> {
    pub fn new(data: &'a [u8]) -> roto_runtime::Result<Self> {
        let accessor = roto_runtime::ProtoAccessor::new(data)?;
        let mut features_offset = None;
        let mut deprecated_offset = None;
        let mut uninterpreted_option_start = None;
        let mut uninterpreted_option_end = None;
        for item in accessor.fields() {
            let (offset, tag, _) = item?;
            if tag.field_number == 34 { features_offset = Some(offset); }
            if tag.field_number == 33 { deprecated_offset = Some(offset); }
            if tag.field_number == 999 {
                if uninterpreted_option_start.is_none() { uninterpreted_option_start = Some(offset); }
                uninterpreted_option_end = Some(offset);
            }
        }

        Ok(Self {
            accessor,
features_offset,
deprecated_offset,
uninterpreted_option_start, uninterpreted_option_end,
        })
    }

    pub fn features(&self) -> roto_runtime::Result<&'a [u8]> {
        let offset = self.features_offset.ok_or(roto_runtime::RotoError::FieldNotFound)?;
        let (bytes, _) = self.accessor.get_value_at(offset)?;
        Ok(bytes)
    }

    pub fn features_or_default(&self) -> roto_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<bool> {
        let offset = self.deprecated_offset.ok_or(roto_runtime::RotoError::FieldNotFound)?;
        let (bytes, _) = self.accessor.get_value_at(offset)?;
        roto_runtime::read_varint(bytes).map(|(v, _)| v != 0).map_err(|_| roto_runtime::RotoError::WireFormatViolation)
    }

    pub fn deprecated_or_default(&self) -> roto_runtime::Result<bool> {
        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> {
        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> {
        self.accessor.raw_fields()
    }

}

pub struct ServiceOptionsBuilder<'b> {
    builder: roto_runtime::ProtoBuilder<'b>,
    features_written: bool,
    deprecated_written: bool,
    uninterpreted_option_written: bool,
}

impl<'b> ServiceOptionsBuilder<'b> {
    pub fn builder(buf: &mut [u8]) -> ServiceOptionsBuilder<'_> {
        ServiceOptionsBuilder {
            builder: roto_runtime::ProtoBuilder::new(buf),
            features_written: false,
            deprecated_written: false,
            uninterpreted_option_written: false,
        }
    }

    pub fn features(mut self, value: &[u8]) -> roto_runtime::Result<Self> {
        self.builder.write_bytes(34, value)?;
        self.features_written = true;
        Ok(self)
    }

    pub fn deprecated(mut self, value: u64) -> roto_runtime::Result<Self> {
        self.builder.write_varint(33, value)?;
        self.deprecated_written = true;
        Ok(self)
    }

    pub fn uninterpreted_option(mut self, value: &[u8]) -> roto_runtime::Result<Self> {
        self.builder.write_bytes(999, value)?;
        self.uninterpreted_option_written = true;
        Ok(self)
    }

    pub fn with(mut self, msg: &ServiceOptions<'_>) -> roto_runtime::Result<Self> {
        for item in msg.raw_fields() {
            let (field_number, raw_bytes) = item?;
            let is_written = match field_number {
                34 => self.features_written,
                33 => self.deprecated_written,
                999 => self.uninterpreted_option_written,
                _ => false,
            };
            if !is_written {
                self.builder.write_raw(raw_bytes)?;
            }
        }
        Ok(self)
    }

    pub fn finish(self) -> roto_runtime::Result<&'b mut [u8]> {
        self.builder.finish()
    }
}

pub struct OwnedServiceOptions {
    pub data: bytes::Bytes,
}

impl roto_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<Self> {
        Ok(OwnedServiceOptions { data: buf })
    }

    fn bytes(&self) -> bytes::Bytes {
        self.data.clone()
    }
}

pub struct MethodOptions<'a> {
    accessor: roto_runtime::ProtoAccessor<'a>,
    deprecated_offset: Option<usize>,
    idempotency_level_offset: Option<usize>,
    features_offset: Option<usize>,
    uninterpreted_option_start: Option<usize>,
    uninterpreted_option_end: Option<usize>,
}

impl<'a> MethodOptions<'a> {
    pub fn new(data: &'a [u8]) -> roto_runtime::Result<Self> {
        let accessor = roto_runtime::ProtoAccessor::new(data)?;
        let mut deprecated_offset = None;
        let mut idempotency_level_offset = None;
        let mut features_offset = None;
        let mut uninterpreted_option_start = None;
        let mut uninterpreted_option_end = None;
        for item in accessor.fields() {
            let (offset, tag, _) = item?;
            if tag.field_number == 33 { deprecated_offset = Some(offset); }
            if tag.field_number == 34 { idempotency_level_offset = Some(offset); }
            if tag.field_number == 35 { features_offset = Some(offset); }
            if tag.field_number == 999 {
                if uninterpreted_option_start.is_none() { uninterpreted_option_start = Some(offset); }
                uninterpreted_option_end = Some(offset);
            }
        }

        Ok(Self {
            accessor,
deprecated_offset,
idempotency_level_offset,
features_offset,
uninterpreted_option_start, uninterpreted_option_end,
        })
    }

    pub fn deprecated(&self) -> roto_runtime::Result<bool> {
        let offset = self.deprecated_offset.ok_or(roto_runtime::RotoError::FieldNotFound)?;
        let (bytes, _) = self.accessor.get_value_at(offset)?;
        roto_runtime::read_varint(bytes).map(|(v, _)| v != 0).map_err(|_| roto_runtime::RotoError::WireFormatViolation)
    }

    pub fn deprecated_or_default(&self) -> roto_runtime::Result<bool> {
        self.deprecated().or(Ok(false))
    }

    pub fn has_deprecated(&self) -> bool { self.deprecated_offset.is_some() }

    pub fn idempotency_level(&self) -> roto_runtime::Result<u64> {
        let offset = self.idempotency_level_offset.ok_or(roto_runtime::RotoError::FieldNotFound)?;
        let (bytes, _) = self.accessor.get_value_at(offset)?;
        roto_runtime::read_varint(bytes).map(|(v, _)| v as u64).map_err(|_| roto_runtime::RotoError::WireFormatViolation)
    }

    pub fn idempotency_level_or_default(&self) -> roto_runtime::Result<u64> {
        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)?;
        let (bytes, _) = self.accessor.get_value_at(offset)?;
        Ok(bytes)
    }

    pub fn features_or_default(&self) -> roto_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> {
        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> {
        self.accessor.raw_fields()
    }

}

pub struct MethodOptionsBuilder<'b> {
    builder: roto_runtime::ProtoBuilder<'b>,
    deprecated_written: bool,
    idempotency_level_written: bool,
    features_written: bool,
    uninterpreted_option_written: bool,
}

impl<'b> MethodOptionsBuilder<'b> {
    pub fn builder(buf: &mut [u8]) -> MethodOptionsBuilder<'_> {
        MethodOptionsBuilder {
            builder: roto_runtime::ProtoBuilder::new(buf),
            deprecated_written: false,
            idempotency_level_written: false,
            features_written: false,
            uninterpreted_option_written: false,
        }
    }

    pub fn deprecated(mut self, value: u64) -> roto_runtime::Result<Self> {
        self.builder.write_varint(33, value)?;
        self.deprecated_written = true;
        Ok(self)
    }

    pub fn idempotency_level(mut self, value: u64) -> roto_runtime::Result<Self> {
        self.builder.write_varint(34, value)?;
        self.idempotency_level_written = true;
        Ok(self)
    }

    pub fn features(mut self, value: &[u8]) -> roto_runtime::Result<Self> {
        self.builder.write_bytes(35, value)?;
        self.features_written = true;
        Ok(self)
    }

    pub fn uninterpreted_option(mut self, value: &[u8]) -> roto_runtime::Result<Self> {
        self.builder.write_bytes(999, value)?;
        self.uninterpreted_option_written = true;
        Ok(self)
    }

    pub fn with(mut self, msg: &MethodOptions<'_>) -> roto_runtime::Result<Self> {
        for item in msg.raw_fields() {
            let (field_number, raw_bytes) = item?;
            let is_written = match field_number {
                33 => self.deprecated_written,
                34 => self.idempotency_level_written,
                35 => self.features_written,
                999 => self.uninterpreted_option_written,
                _ => false,
            };
            if !is_written {
                self.builder.write_raw(raw_bytes)?;
            }
        }
        Ok(self)
    }

    pub fn finish(self) -> roto_runtime::Result<&'b mut [u8]> {
        self.builder.finish()
    }
}

pub struct OwnedMethodOptions {
    pub data: bytes::Bytes,
}

impl roto_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<Self> {
        Ok(OwnedMethodOptions { data: buf })
    }

    fn bytes(&self) -> bytes::Bytes {
        self.data.clone()
    }
}

pub mod method_options {
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
#[repr(i32)]
pub enum IdempotencyLevel {
    IDEMPOTENCYUNKNOWN = 0,
    NOSIDEEFFECTS = 1,
    IDEMPOTENT = 2,
}

impl IdempotencyLevel {
    pub fn from_i32(value: i32) -> Self {
        match value {
            0 => IdempotencyLevel::IDEMPOTENCYUNKNOWN,
            1 => IdempotencyLevel::NOSIDEEFFECTS,
            2 => IdempotencyLevel::IDEMPOTENT,
            _ => IdempotencyLevel::IDEMPOTENCYUNKNOWN,
        }
    }
}

}

pub struct UninterpretedOption<'a> {
    accessor: roto_runtime::ProtoAccessor<'a>,
    name_start: Option<usize>,
    name_end: Option<usize>,
    identifier_value_offset: Option<usize>,
    positive_int_value_offset: Option<usize>,
    negative_int_value_offset: Option<usize>,
    double_value_offset: Option<usize>,
    string_value_offset: Option<usize>,
    aggregate_value_offset: Option<usize>,
}

impl<'a> UninterpretedOption<'a> {
    pub fn new(data: &'a [u8]) -> roto_runtime::Result<Self> {
        let accessor = roto_runtime::ProtoAccessor::new(data)?;
        let mut name_start = None;
        let mut name_end = None;
        let mut identifier_value_offset = None;
        let mut positive_int_value_offset = None;
        let mut negative_int_value_offset = None;
        let mut double_value_offset = None;
        let mut string_value_offset = None;
        let mut aggregate_value_offset = None;
        for item in accessor.fields() {
            let (offset, tag, _) = item?;
            if tag.field_number == 2 {
                if name_start.is_none() { name_start = Some(offset); }
                name_end = Some(offset);
            }
            if tag.field_number == 3 { identifier_value_offset = Some(offset); }
            if tag.field_number == 4 { positive_int_value_offset = Some(offset); }
            if tag.field_number == 5 { negative_int_value_offset = Some(offset); }
            if tag.field_number == 6 { double_value_offset = Some(offset); }
            if tag.field_number == 7 { string_value_offset = Some(offset); }
            if tag.field_number == 8 { aggregate_value_offset = Some(offset); }
        }

        Ok(Self {
            accessor,
name_start, name_end,
identifier_value_offset,
positive_int_value_offset,
negative_int_value_offset,
double_value_offset,
string_value_offset,
aggregate_value_offset,
        })
    }

    pub fn name(&self) -> roto_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)?;
        let (bytes, _) = self.accessor.get_value_at(offset)?;
        str::from_utf8(bytes).map_err(|_| roto_runtime::RotoError::WireFormatViolation)
    }

    pub fn identifier_value_or_default(&self) -> roto_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<u32> {
        let offset = self.positive_int_value_offset.ok_or(roto_runtime::RotoError::FieldNotFound)?;
        let (bytes, _) = self.accessor.get_value_at(offset)?;
        roto_runtime::read_varint(bytes).map(|(v, _)| v as u32).map_err(|_| roto_runtime::RotoError::WireFormatViolation)
    }

    pub fn positive_int_value_or_default(&self) -> roto_runtime::Result<u32> {
        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<i32> {
        let offset = self.negative_int_value_offset.ok_or(roto_runtime::RotoError::FieldNotFound)?;
        let (bytes, _) = self.accessor.get_value_at(offset)?;
        roto_runtime::read_varint(bytes).map(|(v, _)| v as i32).map_err(|_| roto_runtime::RotoError::WireFormatViolation)
    }

    pub fn negative_int_value_or_default(&self) -> roto_runtime::Result<i32> {
        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<f64> {
        let offset = self.double_value_offset.ok_or(roto_runtime::RotoError::FieldNotFound)?;
        let (bytes, _) = self.accessor.get_value_at(offset)?;
        Ok(f64::from_le_bytes(bytes.try_into().map_err(|_| roto_runtime::RotoError::WireFormatViolation)?))
    }

    pub fn double_value_or_default(&self) -> roto_runtime::Result<f64> {
        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)?;
        let (bytes, _) = self.accessor.get_value_at(offset)?;
        Ok(bytes)
    }

    pub fn string_value_or_default(&self) -> roto_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)?;
        let (bytes, _) = self.accessor.get_value_at(offset)?;
        str::from_utf8(bytes).map_err(|_| roto_runtime::RotoError::WireFormatViolation)
    }

    pub fn aggregate_value_or_default(&self) -> roto_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> {
        self.accessor.raw_fields()
    }

}

pub struct UninterpretedOptionBuilder<'b> {
    builder: roto_runtime::ProtoBuilder<'b>,
    name_written: bool,
    identifier_value_written: bool,
    positive_int_value_written: bool,
    negative_int_value_written: bool,
    double_value_written: bool,
    string_value_written: bool,
    aggregate_value_written: bool,
}

impl<'b> UninterpretedOptionBuilder<'b> {
    pub fn builder(buf: &mut [u8]) -> UninterpretedOptionBuilder<'_> {
        UninterpretedOptionBuilder {
            builder: roto_runtime::ProtoBuilder::new(buf),
            name_written: false,
            identifier_value_written: false,
            positive_int_value_written: false,
            negative_int_value_written: false,
            double_value_written: false,
            string_value_written: false,
            aggregate_value_written: false,
        }
    }

    pub fn name(mut self, value: &[u8]) -> roto_runtime::Result<Self> {
        self.builder.write_bytes(2, value)?;
        self.name_written = true;
        Ok(self)
    }

    pub fn identifier_value(mut self, value: &str) -> roto_runtime::Result<Self> {
        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<Self> {
        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<Self> {
        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<Self> {
        self.builder.write_bytes(6, value)?;
        self.double_value_written = true;
        Ok(self)
    }

    pub fn string_value(mut self, value: &[u8]) -> roto_runtime::Result<Self> {
        self.builder.write_bytes(7, value)?;
        self.string_value_written = true;
        Ok(self)
    }

    pub fn aggregate_value(mut self, value: &str) -> roto_runtime::Result<Self> {
        self.builder.write_string(8, value)?;
        self.aggregate_value_written = true;
        Ok(self)
    }

    pub fn with(mut self, msg: &UninterpretedOption<'_>) -> roto_runtime::Result<Self> {
        for item in msg.raw_fields() {
            let (field_number, raw_bytes) = item?;
            let is_written = match field_number {
                2 => self.name_written,
                3 => self.identifier_value_written,
                4 => self.positive_int_value_written,
                5 => self.negative_int_value_written,
                6 => self.double_value_written,
                7 => self.string_value_written,
                8 => self.aggregate_value_written,
                _ => false,
            };
            if !is_written {
                self.builder.write_raw(raw_bytes)?;
            }
        }
        Ok(self)
    }

    pub fn finish(self) -> roto_runtime::Result<&'b mut [u8]> {
        self.builder.finish()
    }
}

pub struct OwnedUninterpretedOption {
    pub data: bytes::Bytes,
}

impl roto_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<Self> {
        Ok(OwnedUninterpretedOption { data: buf })
    }

    fn bytes(&self) -> bytes::Bytes {
        self.data.clone()
    }
}

pub mod uninterpreted_option {
pub struct NamePart<'a> {
    accessor: roto_runtime::ProtoAccessor<'a>,
    name_part_offset: Option<usize>,
    is_extension_offset: Option<usize>,
}

impl<'a> NamePart<'a> {
    pub fn new(data: &'a [u8]) -> roto_runtime::Result<Self> {
        let accessor = roto_runtime::ProtoAccessor::new(data)?;
        let mut name_part_offset = None;
        let mut is_extension_offset = None;
        for item in accessor.fields() {
            let (offset, tag, _) = item?;
            if tag.field_number == 1 { name_part_offset = Some(offset); }
            if tag.field_number == 2 { is_extension_offset = Some(offset); }
        }

        Ok(Self {
            accessor,
name_part_offset,
is_extension_offset,
        })
    }

    pub fn name_part(&self) -> roto_runtime::Result<&'a str> {
        let offset = self.name_part_offset.ok_or(roto_runtime::RotoError::FieldNotFound)?;
        let (bytes, _) = self.accessor.get_value_at(offset)?;
        str::from_utf8(bytes).map_err(|_| roto_runtime::RotoError::WireFormatViolation)
    }

    pub fn name_part_or_default(&self) -> roto_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<bool> {
        let offset = self.is_extension_offset.ok_or(roto_runtime::RotoError::FieldNotFound)?;
        let (bytes, _) = self.accessor.get_value_at(offset)?;
        roto_runtime::read_varint(bytes).map(|(v, _)| v != 0).map_err(|_| roto_runtime::RotoError::WireFormatViolation)
    }

    pub fn is_extension_or_default(&self) -> roto_runtime::Result<bool> {
        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> {
        self.accessor.raw_fields()
    }

}

pub struct NamePartBuilder<'b> {
    builder: roto_runtime::ProtoBuilder<'b>,
    name_part_written: bool,
    is_extension_written: bool,
}

impl<'b> NamePartBuilder<'b> {
    pub fn builder(buf: &mut [u8]) -> NamePartBuilder<'_> {
        NamePartBuilder {
            builder: roto_runtime::ProtoBuilder::new(buf),
            name_part_written: false,
            is_extension_written: false,
        }
    }

    pub fn name_part(mut self, value: &str) -> roto_runtime::Result<Self> {
        self.builder.write_string(1, value)?;
        self.name_part_written = true;
        Ok(self)
    }

    pub fn is_extension(mut self, value: u64) -> roto_runtime::Result<Self> {
        self.builder.write_varint(2, value)?;
        self.is_extension_written = true;
        Ok(self)
    }

    pub fn with(mut self, msg: &NamePart<'_>) -> roto_runtime::Result<Self> {
        for item in msg.raw_fields() {
            let (field_number, raw_bytes) = item?;
            let is_written = match field_number {
                1 => self.name_part_written,
                2 => self.is_extension_written,
                _ => false,
            };
            if !is_written {
                self.builder.write_raw(raw_bytes)?;
            }
        }
        Ok(self)
    }

    pub fn finish(self) -> roto_runtime::Result<&'b mut [u8]> {
        self.builder.finish()
    }
}

pub struct OwnedNamePart {
    pub data: bytes::Bytes,
}

impl roto_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<Self> {
        Ok(OwnedNamePart { data: buf })
    }

    fn bytes(&self) -> bytes::Bytes {
        self.data.clone()
    }
}

}

pub struct FeatureSet<'a> {
    accessor: roto_runtime::ProtoAccessor<'a>,
    field_presence_offset: Option<usize>,
    enum_type_offset: Option<usize>,
    repeated_field_encoding_offset: Option<usize>,
    utf8_validation_offset: Option<usize>,
    message_encoding_offset: Option<usize>,
    json_format_offset: Option<usize>,
    enforce_naming_style_offset: Option<usize>,
    default_symbol_visibility_offset: Option<usize>,
    enforce_proto_limits_offset: Option<usize>,
}

impl<'a> FeatureSet<'a> {
    pub fn new(data: &'a [u8]) -> roto_runtime::Result<Self> {
        let accessor = roto_runtime::ProtoAccessor::new(data)?;
        let mut field_presence_offset = None;
        let mut enum_type_offset = None;
        let mut repeated_field_encoding_offset = None;
        let mut utf8_validation_offset = None;
        let mut message_encoding_offset = None;
        let mut json_format_offset = None;
        let mut enforce_naming_style_offset = None;
        let mut default_symbol_visibility_offset = None;
        let mut enforce_proto_limits_offset = None;
        for item in accessor.fields() {
            let (offset, tag, _) = item?;
            if tag.field_number == 1 { field_presence_offset = Some(offset); }
            if tag.field_number == 2 { enum_type_offset = Some(offset); }
            if tag.field_number == 3 { repeated_field_encoding_offset = Some(offset); }
            if tag.field_number == 4 { utf8_validation_offset = Some(offset); }
            if tag.field_number == 5 { message_encoding_offset = Some(offset); }
            if tag.field_number == 6 { json_format_offset = Some(offset); }
            if tag.field_number == 7 { enforce_naming_style_offset = Some(offset); }
            if tag.field_number == 8 { default_symbol_visibility_offset = Some(offset); }
            if tag.field_number == 9 { enforce_proto_limits_offset = Some(offset); }
        }

        Ok(Self {
            accessor,
field_presence_offset,
enum_type_offset,
repeated_field_encoding_offset,
utf8_validation_offset,
message_encoding_offset,
json_format_offset,
enforce_naming_style_offset,
default_symbol_visibility_offset,
enforce_proto_limits_offset,
        })
    }

    pub fn field_presence(&self) -> roto_runtime::Result<u64> {
        let offset = self.field_presence_offset.ok_or(roto_runtime::RotoError::FieldNotFound)?;
        let (bytes, _) = self.accessor.get_value_at(offset)?;
        roto_runtime::read_varint(bytes).map(|(v, _)| v as u64).map_err(|_| roto_runtime::RotoError::WireFormatViolation)
    }

    pub fn field_presence_or_default(&self) -> roto_runtime::Result<u64> {
        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<u64> {
        let offset = self.enum_type_offset.ok_or(roto_runtime::RotoError::FieldNotFound)?;
        let (bytes, _) = self.accessor.get_value_at(offset)?;
        roto_runtime::read_varint(bytes).map(|(v, _)| v as u64).map_err(|_| roto_runtime::RotoError::WireFormatViolation)
    }

    pub fn enum_type_or_default(&self) -> roto_runtime::Result<u64> {
        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<u64> {
        let offset = self.repeated_field_encoding_offset.ok_or(roto_runtime::RotoError::FieldNotFound)?;
        let (bytes, _) = self.accessor.get_value_at(offset)?;
        roto_runtime::read_varint(bytes).map(|(v, _)| v as u64).map_err(|_| roto_runtime::RotoError::WireFormatViolation)
    }

    pub fn repeated_field_encoding_or_default(&self) -> roto_runtime::Result<u64> {
        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<u64> {
        let offset = self.utf8_validation_offset.ok_or(roto_runtime::RotoError::FieldNotFound)?;
        let (bytes, _) = self.accessor.get_value_at(offset)?;
        roto_runtime::read_varint(bytes).map(|(v, _)| v as u64).map_err(|_| roto_runtime::RotoError::WireFormatViolation)
    }

    pub fn utf8_validation_or_default(&self) -> roto_runtime::Result<u64> {
        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<u64> {
        let offset = self.message_encoding_offset.ok_or(roto_runtime::RotoError::FieldNotFound)?;
        let (bytes, _) = self.accessor.get_value_at(offset)?;
        roto_runtime::read_varint(bytes).map(|(v, _)| v as u64).map_err(|_| roto_runtime::RotoError::WireFormatViolation)
    }

    pub fn message_encoding_or_default(&self) -> roto_runtime::Result<u64> {
        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<u64> {
        let offset = self.json_format_offset.ok_or(roto_runtime::RotoError::FieldNotFound)?;
        let (bytes, _) = self.accessor.get_value_at(offset)?;
        roto_runtime::read_varint(bytes).map(|(v, _)| v as u64).map_err(|_| roto_runtime::RotoError::WireFormatViolation)
    }

    pub fn json_format_or_default(&self) -> roto_runtime::Result<u64> {
        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<u64> {
        let offset = self.enforce_naming_style_offset.ok_or(roto_runtime::RotoError::FieldNotFound)?;
        let (bytes, _) = self.accessor.get_value_at(offset)?;
        roto_runtime::read_varint(bytes).map(|(v, _)| v as u64).map_err(|_| roto_runtime::RotoError::WireFormatViolation)
    }

    pub fn enforce_naming_style_or_default(&self) -> roto_runtime::Result<u64> {
        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<u64> {
        let offset = self.default_symbol_visibility_offset.ok_or(roto_runtime::RotoError::FieldNotFound)?;
        let (bytes, _) = self.accessor.get_value_at(offset)?;
        roto_runtime::read_varint(bytes).map(|(v, _)| v as u64).map_err(|_| roto_runtime::RotoError::WireFormatViolation)
    }

    pub fn default_symbol_visibility_or_default(&self) -> roto_runtime::Result<u64> {
        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<u64> {
        let offset = self.enforce_proto_limits_offset.ok_or(roto_runtime::RotoError::FieldNotFound)?;
        let (bytes, _) = self.accessor.get_value_at(offset)?;
        roto_runtime::read_varint(bytes).map(|(v, _)| v as u64).map_err(|_| roto_runtime::RotoError::WireFormatViolation)
    }

    pub fn enforce_proto_limits_or_default(&self) -> roto_runtime::Result<u64> {
        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> {
        self.accessor.raw_fields()
    }

}

pub struct FeatureSetBuilder<'b> {
    builder: roto_runtime::ProtoBuilder<'b>,
    field_presence_written: bool,
    enum_type_written: bool,
    repeated_field_encoding_written: bool,
    utf8_validation_written: bool,
    message_encoding_written: bool,
    json_format_written: bool,
    enforce_naming_style_written: bool,
    default_symbol_visibility_written: bool,
    enforce_proto_limits_written: bool,
}

impl<'b> FeatureSetBuilder<'b> {
    pub fn builder(buf: &mut [u8]) -> FeatureSetBuilder<'_> {
        FeatureSetBuilder {
            builder: roto_runtime::ProtoBuilder::new(buf),
            field_presence_written: false,
            enum_type_written: false,
            repeated_field_encoding_written: false,
            utf8_validation_written: false,
            message_encoding_written: false,
            json_format_written: false,
            enforce_naming_style_written: false,
            default_symbol_visibility_written: false,
            enforce_proto_limits_written: false,
        }
    }

    pub fn field_presence(mut self, value: u64) -> roto_runtime::Result<Self> {
        self.builder.write_varint(1, value)?;
        self.field_presence_written = true;
        Ok(self)
    }

    pub fn enum_type(mut self, value: u64) -> roto_runtime::Result<Self> {
        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<Self> {
        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<Self> {
        self.builder.write_varint(4, value)?;
        self.utf8_validation_written = true;
        Ok(self)
    }

    pub fn message_encoding(mut self, value: u64) -> roto_runtime::Result<Self> {
        self.builder.write_varint(5, value)?;
        self.message_encoding_written = true;
        Ok(self)
    }

    pub fn json_format(mut self, value: u64) -> roto_runtime::Result<Self> {
        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<Self> {
        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<Self> {
        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<Self> {
        self.builder.write_varint(9, value)?;
        self.enforce_proto_limits_written = true;
        Ok(self)
    }

    pub fn with(mut self, msg: &FeatureSet<'_>) -> roto_runtime::Result<Self> {
        for item in msg.raw_fields() {
            let (field_number, raw_bytes) = item?;
            let is_written = match field_number {
                1 => self.field_presence_written,
                2 => self.enum_type_written,
                3 => self.repeated_field_encoding_written,
                4 => self.utf8_validation_written,
                5 => self.message_encoding_written,
                6 => self.json_format_written,
                7 => self.enforce_naming_style_written,
                8 => self.default_symbol_visibility_written,
                9 => self.enforce_proto_limits_written,
                _ => false,
            };
            if !is_written {
                self.builder.write_raw(raw_bytes)?;
            }
        }
        Ok(self)
    }

    pub fn finish(self) -> roto_runtime::Result<&'b mut [u8]> {
        self.builder.finish()
    }
}

pub struct OwnedFeatureSet {
    pub data: bytes::Bytes,
}

impl roto_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<Self> {
        Ok(OwnedFeatureSet { data: buf })
    }

    fn bytes(&self) -> bytes::Bytes {
        self.data.clone()
    }
}

pub mod feature_set {
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
#[repr(i32)]
pub enum FieldPresence {
    FIELDPRESENCEUNKNOWN = 0,
    EXPLICIT = 1,
    IMPLICIT = 2,
    LEGACYREQUIRED = 3,
}

impl FieldPresence {
    pub fn from_i32(value: i32) -> Self {
        match value {
            0 => FieldPresence::FIELDPRESENCEUNKNOWN,
            1 => FieldPresence::EXPLICIT,
            2 => FieldPresence::IMPLICIT,
            3 => FieldPresence::LEGACYREQUIRED,
            _ => FieldPresence::FIELDPRESENCEUNKNOWN,
        }
    }
}

#[derive(Debug, Clone, Copy, PartialEq, Eq)]
#[repr(i32)]
pub enum EnumType {
    ENUMTYPEUNKNOWN = 0,
    OPEN = 1,
    CLOSED = 2,
}

impl EnumType {
    pub fn from_i32(value: i32) -> Self {
        match value {
            0 => EnumType::ENUMTYPEUNKNOWN,
            1 => EnumType::OPEN,
            2 => EnumType::CLOSED,
            _ => EnumType::ENUMTYPEUNKNOWN,
        }
    }
}

#[derive(Debug, Clone, Copy, PartialEq, Eq)]
#[repr(i32)]
pub enum RepeatedFieldEncoding {
    REPEATEDFIELDENCODINGUNKNOWN = 0,
    PACKED = 1,
    EXPANDED = 2,
}

impl RepeatedFieldEncoding {
    pub fn from_i32(value: i32) -> Self {
        match value {
            0 => RepeatedFieldEncoding::REPEATEDFIELDENCODINGUNKNOWN,
            1 => RepeatedFieldEncoding::PACKED,
            2 => RepeatedFieldEncoding::EXPANDED,
            _ => RepeatedFieldEncoding::REPEATEDFIELDENCODINGUNKNOWN,
        }
    }
}

#[derive(Debug, Clone, Copy, PartialEq, Eq)]
#[repr(i32)]
pub enum Utf8Validation {
    UTF8VALIDATIONUNKNOWN = 0,
    VERIFY = 2,
    NONE = 3,
}

impl Utf8Validation {
    pub fn from_i32(value: i32) -> Self {
        match value {
            0 => Utf8Validation::UTF8VALIDATIONUNKNOWN,
            2 => Utf8Validation::VERIFY,
            3 => Utf8Validation::NONE,
            _ => Utf8Validation::UTF8VALIDATIONUNKNOWN,
        }
    }
}

#[derive(Debug, Clone, Copy, PartialEq, Eq)]
#[repr(i32)]
pub enum MessageEncoding {
    MESSAGEENCODINGUNKNOWN = 0,
    LENGTHPREFIXED = 1,
    DELIMITED = 2,
}

impl MessageEncoding {
    pub fn from_i32(value: i32) -> Self {
        match value {
            0 => MessageEncoding::MESSAGEENCODINGUNKNOWN,
            1 => MessageEncoding::LENGTHPREFIXED,
            2 => MessageEncoding::DELIMITED,
            _ => MessageEncoding::MESSAGEENCODINGUNKNOWN,
        }
    }
}

#[derive(Debug, Clone, Copy, PartialEq, Eq)]
#[repr(i32)]
pub enum JsonFormat {
    JSONFORMATUNKNOWN = 0,
    ALLOW = 1,
    LEGACYBESTEFFORT = 2,
}

impl JsonFormat {
    pub fn from_i32(value: i32) -> Self {
        match value {
            0 => JsonFormat::JSONFORMATUNKNOWN,
            1 => JsonFormat::ALLOW,
            2 => JsonFormat::LEGACYBESTEFFORT,
            _ => JsonFormat::JSONFORMATUNKNOWN,
        }
    }
}

#[derive(Debug, Clone, Copy, PartialEq, Eq)]
#[repr(i32)]
pub enum EnforceNamingStyle {
    ENFORCENAMINGSTYLEUNKNOWN = 0,
    STYLE2024 = 1,
    STYLELEGACY = 2,
    STYLE2026 = 3,
}

impl EnforceNamingStyle {
    pub fn from_i32(value: i32) -> Self {
        match value {
            0 => EnforceNamingStyle::ENFORCENAMINGSTYLEUNKNOWN,
            1 => EnforceNamingStyle::STYLE2024,
            2 => EnforceNamingStyle::STYLELEGACY,
            3 => EnforceNamingStyle::STYLE2026,
            _ => EnforceNamingStyle::ENFORCENAMINGSTYLEUNKNOWN,
        }
    }
}

pub struct VisibilityFeature<'a> {
    accessor: roto_runtime::ProtoAccessor<'a>,
}

impl<'a> VisibilityFeature<'a> {
    pub fn new(data: &'a [u8]) -> roto_runtime::Result<Self> {
        let accessor = roto_runtime::ProtoAccessor::new(data)?;
        for item in accessor.fields() {
            let (offset, tag, _) = item?;
        }

        Ok(Self {
            accessor,
        })
    }

    pub fn raw_fields(&self) -> roto_runtime::RawFieldIterator<'a> {
        self.accessor.raw_fields()
    }

}

pub struct VisibilityFeatureBuilder<'b> {
    builder: roto_runtime::ProtoBuilder<'b>,
}

impl<'b> VisibilityFeatureBuilder<'b> {
    pub fn builder(buf: &mut [u8]) -> VisibilityFeatureBuilder<'_> {
        VisibilityFeatureBuilder {
            builder: roto_runtime::ProtoBuilder::new(buf),
        }
    }

    pub fn with(mut self, msg: &VisibilityFeature<'_>) -> roto_runtime::Result<Self> {
        for item in msg.raw_fields() {
            let (field_number, raw_bytes) = item?;
            let is_written = match field_number {
                _ => false,
            };
            if !is_written {
                self.builder.write_raw(raw_bytes)?;
            }
        }
        Ok(self)
    }

    pub fn finish(self) -> roto_runtime::Result<&'b mut [u8]> {
        self.builder.finish()
    }
}

pub struct OwnedVisibilityFeature {
    pub data: bytes::Bytes,
}

impl roto_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<Self> {
        Ok(OwnedVisibilityFeature { data: buf })
    }

    fn bytes(&self) -> bytes::Bytes {
        self.data.clone()
    }
}

pub mod visibility_feature {
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
#[repr(i32)]
pub enum DefaultSymbolVisibility {
    DEFAULTSYMBOLVISIBILITYUNKNOWN = 0,
    EXPORTALL = 1,
    EXPORTTOPLEVEL = 2,
    LOCALALL = 3,
    STRICT = 4,
}

impl DefaultSymbolVisibility {
    pub fn from_i32(value: i32) -> Self {
        match value {
            0 => DefaultSymbolVisibility::DEFAULTSYMBOLVISIBILITYUNKNOWN,
            1 => DefaultSymbolVisibility::EXPORTALL,
            2 => DefaultSymbolVisibility::EXPORTTOPLEVEL,
            3 => DefaultSymbolVisibility::LOCALALL,
            4 => DefaultSymbolVisibility::STRICT,
            _ => DefaultSymbolVisibility::DEFAULTSYMBOLVISIBILITYUNKNOWN,
        }
    }
}

}

pub struct ProtoLimitsFeature<'a> {
    accessor: roto_runtime::ProtoAccessor<'a>,
}

impl<'a> ProtoLimitsFeature<'a> {
    pub fn new(data: &'a [u8]) -> roto_runtime::Result<Self> {
        let accessor = roto_runtime::ProtoAccessor::new(data)?;
        for item in accessor.fields() {
            let (offset, tag, _) = item?;
        }

        Ok(Self {
            accessor,
        })
    }

    pub fn raw_fields(&self) -> roto_runtime::RawFieldIterator<'a> {
        self.accessor.raw_fields()
    }

}

pub struct ProtoLimitsFeatureBuilder<'b> {
    builder: roto_runtime::ProtoBuilder<'b>,
}

impl<'b> ProtoLimitsFeatureBuilder<'b> {
    pub fn builder(buf: &mut [u8]) -> ProtoLimitsFeatureBuilder<'_> {
        ProtoLimitsFeatureBuilder {
            builder: roto_runtime::ProtoBuilder::new(buf),
        }
    }

    pub fn with(mut self, msg: &ProtoLimitsFeature<'_>) -> roto_runtime::Result<Self> {
        for item in msg.raw_fields() {
            let (field_number, raw_bytes) = item?;
            let is_written = match field_number {
                _ => false,
            };
            if !is_written {
                self.builder.write_raw(raw_bytes)?;
            }
        }
        Ok(self)
    }

    pub fn finish(self) -> roto_runtime::Result<&'b mut [u8]> {
        self.builder.finish()
    }
}

pub struct OwnedProtoLimitsFeature {
    pub data: bytes::Bytes,
}

impl roto_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<Self> {
        Ok(OwnedProtoLimitsFeature { data: buf })
    }

    fn bytes(&self) -> bytes::Bytes {
        self.data.clone()
    }
}

pub mod proto_limits_feature {
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
#[repr(i32)]
pub enum EnforceProtoLimits {
    PROTOLIMITSUNKNOWN = 0,
    LEGACYNOEXPLICITLIMITS = 1,
    PROTOLIMITS2026 = 2,
}

impl EnforceProtoLimits {
    pub fn from_i32(value: i32) -> Self {
        match value {
            0 => EnforceProtoLimits::PROTOLIMITSUNKNOWN,
            1 => EnforceProtoLimits::LEGACYNOEXPLICITLIMITS,
            2 => EnforceProtoLimits::PROTOLIMITS2026,
            _ => EnforceProtoLimits::PROTOLIMITSUNKNOWN,
        }
    }
}

}

}

pub struct FeatureSetDefaults<'a> {
    accessor: roto_runtime::ProtoAccessor<'a>,
    defaults_start: Option<usize>,
    defaults_end: Option<usize>,
    minimum_edition_offset: Option<usize>,
    maximum_edition_offset: Option<usize>,
}

impl<'a> FeatureSetDefaults<'a> {
    pub fn new(data: &'a [u8]) -> roto_runtime::Result<Self> {
        let accessor = roto_runtime::ProtoAccessor::new(data)?;
        let mut defaults_start = None;
        let mut defaults_end = None;
        let mut minimum_edition_offset = None;
        let mut maximum_edition_offset = None;
        for item in accessor.fields() {
            let (offset, tag, _) = item?;
            if tag.field_number == 1 {
                if defaults_start.is_none() { defaults_start = Some(offset); }
                defaults_end = Some(offset);
            }
            if tag.field_number == 4 { minimum_edition_offset = Some(offset); }
            if tag.field_number == 5 { maximum_edition_offset = Some(offset); }
        }

        Ok(Self {
            accessor,
defaults_start, defaults_end,
minimum_edition_offset,
maximum_edition_offset,
        })
    }

    pub fn defaults(&self) -> roto_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<u64> {
        let offset = self.minimum_edition_offset.ok_or(roto_runtime::RotoError::FieldNotFound)?;
        let (bytes, _) = self.accessor.get_value_at(offset)?;
        roto_runtime::read_varint(bytes).map(|(v, _)| v as u64).map_err(|_| roto_runtime::RotoError::WireFormatViolation)
    }

    pub fn minimum_edition_or_default(&self) -> roto_runtime::Result<u64> {
        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<u64> {
        let offset = self.maximum_edition_offset.ok_or(roto_runtime::RotoError::FieldNotFound)?;
        let (bytes, _) = self.accessor.get_value_at(offset)?;
        roto_runtime::read_varint(bytes).map(|(v, _)| v as u64).map_err(|_| roto_runtime::RotoError::WireFormatViolation)
    }

    pub fn maximum_edition_or_default(&self) -> roto_runtime::Result<u64> {
        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> {
        self.accessor.raw_fields()
    }

}

pub struct FeatureSetDefaultsBuilder<'b> {
    builder: roto_runtime::ProtoBuilder<'b>,
    defaults_written: bool,
    minimum_edition_written: bool,
    maximum_edition_written: bool,
}

impl<'b> FeatureSetDefaultsBuilder<'b> {
    pub fn builder(buf: &mut [u8]) -> FeatureSetDefaultsBuilder<'_> {
        FeatureSetDefaultsBuilder {
            builder: roto_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<Self> {
        self.builder.write_bytes(1, value)?;
        self.defaults_written = true;
        Ok(self)
    }

    pub fn minimum_edition(mut self, value: u64) -> roto_runtime::Result<Self> {
        self.builder.write_varint(4, value)?;
        self.minimum_edition_written = true;
        Ok(self)
    }

    pub fn maximum_edition(mut self, value: u64) -> roto_runtime::Result<Self> {
        self.builder.write_varint(5, value)?;
        self.maximum_edition_written = true;
        Ok(self)
    }

    pub fn with(mut self, msg: &FeatureSetDefaults<'_>) -> roto_runtime::Result<Self> {
        for item in msg.raw_fields() {
            let (field_number, raw_bytes) = item?;
            let is_written = match field_number {
                1 => self.defaults_written,
                4 => self.minimum_edition_written,
                5 => self.maximum_edition_written,
                _ => false,
            };
            if !is_written {
                self.builder.write_raw(raw_bytes)?;
            }
        }
        Ok(self)
    }

    pub fn finish(self) -> roto_runtime::Result<&'b mut [u8]> {
        self.builder.finish()
    }
}

pub struct OwnedFeatureSetDefaults {
    pub data: bytes::Bytes,
}

impl roto_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<Self> {
        Ok(OwnedFeatureSetDefaults { data: buf })
    }

    fn bytes(&self) -> bytes::Bytes {
        self.data.clone()
    }
}

pub mod feature_set_defaults {
pub struct FeatureSetEditionDefault<'a> {
    accessor: roto_runtime::ProtoAccessor<'a>,
    edition_offset: Option<usize>,
    overridable_features_offset: Option<usize>,
    fixed_features_offset: Option<usize>,
}

impl<'a> FeatureSetEditionDefault<'a> {
    pub fn new(data: &'a [u8]) -> roto_runtime::Result<Self> {
        let accessor = roto_runtime::ProtoAccessor::new(data)?;
        let mut edition_offset = None;
        let mut overridable_features_offset = None;
        let mut fixed_features_offset = None;
        for item in accessor.fields() {
            let (offset, tag, _) = item?;
            if tag.field_number == 3 { edition_offset = Some(offset); }
            if tag.field_number == 4 { overridable_features_offset = Some(offset); }
            if tag.field_number == 5 { fixed_features_offset = Some(offset); }
        }

        Ok(Self {
            accessor,
edition_offset,
overridable_features_offset,
fixed_features_offset,
        })
    }

    pub fn edition(&self) -> roto_runtime::Result<u64> {
        let offset = self.edition_offset.ok_or(roto_runtime::RotoError::FieldNotFound)?;
        let (bytes, _) = self.accessor.get_value_at(offset)?;
        roto_runtime::read_varint(bytes).map(|(v, _)| v as u64).map_err(|_| roto_runtime::RotoError::WireFormatViolation)
    }

    pub fn edition_or_default(&self) -> roto_runtime::Result<u64> {
        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)?;
        let (bytes, _) = self.accessor.get_value_at(offset)?;
        Ok(bytes)
    }

    pub fn overridable_features_or_default(&self) -> roto_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)?;
        let (bytes, _) = self.accessor.get_value_at(offset)?;
        Ok(bytes)
    }

    pub fn fixed_features_or_default(&self) -> roto_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> {
        self.accessor.raw_fields()
    }

}

pub struct FeatureSetEditionDefaultBuilder<'b> {
    builder: roto_runtime::ProtoBuilder<'b>,
    edition_written: bool,
    overridable_features_written: bool,
    fixed_features_written: bool,
}

impl<'b> FeatureSetEditionDefaultBuilder<'b> {
    pub fn builder(buf: &mut [u8]) -> FeatureSetEditionDefaultBuilder<'_> {
        FeatureSetEditionDefaultBuilder {
            builder: roto_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<Self> {
        self.builder.write_varint(3, value)?;
        self.edition_written = true;
        Ok(self)
    }

    pub fn overridable_features(mut self, value: &[u8]) -> roto_runtime::Result<Self> {
        self.builder.write_bytes(4, value)?;
        self.overridable_features_written = true;
        Ok(self)
    }

    pub fn fixed_features(mut self, value: &[u8]) -> roto_runtime::Result<Self> {
        self.builder.write_bytes(5, value)?;
        self.fixed_features_written = true;
        Ok(self)
    }

    pub fn with(mut self, msg: &FeatureSetEditionDefault<'_>) -> roto_runtime::Result<Self> {
        for item in msg.raw_fields() {
            let (field_number, raw_bytes) = item?;
            let is_written = match field_number {
                3 => self.edition_written,
                4 => self.overridable_features_written,
                5 => self.fixed_features_written,
                _ => false,
            };
            if !is_written {
                self.builder.write_raw(raw_bytes)?;
            }
        }
        Ok(self)
    }

    pub fn finish(self) -> roto_runtime::Result<&'b mut [u8]> {
        self.builder.finish()
    }
}

pub struct OwnedFeatureSetEditionDefault {
    pub data: bytes::Bytes,
}

impl roto_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<Self> {
        Ok(OwnedFeatureSetEditionDefault { data: buf })
    }

    fn bytes(&self) -> bytes::Bytes {
        self.data.clone()
    }
}

}

pub struct SourceCodeInfo<'a> {
    accessor: roto_runtime::ProtoAccessor<'a>,
    location_start: Option<usize>,
    location_end: Option<usize>,
}

impl<'a> SourceCodeInfo<'a> {
    pub fn new(data: &'a [u8]) -> roto_runtime::Result<Self> {
        let accessor = roto_runtime::ProtoAccessor::new(data)?;
        let mut location_start = None;
        let mut location_end = None;
        for item in accessor.fields() {
            let (offset, tag, _) = item?;
            if tag.field_number == 1 {
                if location_start.is_none() { location_start = Some(offset); }
                location_end = Some(offset);
            }
        }

        Ok(Self {
            accessor,
location_start, location_end,
        })
    }

    pub fn location(&self) -> roto_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> {
        self.accessor.raw_fields()
    }

}

pub struct SourceCodeInfoBuilder<'b> {
    builder: roto_runtime::ProtoBuilder<'b>,
    location_written: bool,
}

impl<'b> SourceCodeInfoBuilder<'b> {
    pub fn builder(buf: &mut [u8]) -> SourceCodeInfoBuilder<'_> {
        SourceCodeInfoBuilder {
            builder: roto_runtime::ProtoBuilder::new(buf),
            location_written: false,
        }
    }

    pub fn location(mut self, value: &[u8]) -> roto_runtime::Result<Self> {
        self.builder.write_bytes(1, value)?;
        self.location_written = true;
        Ok(self)
    }

    pub fn with(mut self, msg: &SourceCodeInfo<'_>) -> roto_runtime::Result<Self> {
        for item in msg.raw_fields() {
            let (field_number, raw_bytes) = item?;
            let is_written = match field_number {
                1 => self.location_written,
                _ => false,
            };
            if !is_written {
                self.builder.write_raw(raw_bytes)?;
            }
        }
        Ok(self)
    }

    pub fn finish(self) -> roto_runtime::Result<&'b mut [u8]> {
        self.builder.finish()
    }
}

pub struct OwnedSourceCodeInfo {
    pub data: bytes::Bytes,
}

impl roto_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<Self> {
        Ok(OwnedSourceCodeInfo { data: buf })
    }

    fn bytes(&self) -> bytes::Bytes {
        self.data.clone()
    }
}

pub mod source_code_info {
pub struct Location<'a> {
    accessor: roto_runtime::ProtoAccessor<'a>,
    path_start: Option<usize>,
    path_end: Option<usize>,
    span_start: Option<usize>,
    span_end: Option<usize>,
    leading_comments_offset: Option<usize>,
    trailing_comments_offset: Option<usize>,
    leading_detached_comments_start: Option<usize>,
    leading_detached_comments_end: Option<usize>,
}

impl<'a> Location<'a> {
    pub fn new(data: &'a [u8]) -> roto_runtime::Result<Self> {
        let accessor = roto_runtime::ProtoAccessor::new(data)?;
        let mut path_start = None;
        let mut path_end = None;
        let mut span_start = None;
        let mut span_end = None;
        let mut leading_comments_offset = None;
        let mut trailing_comments_offset = None;
        let mut leading_detached_comments_start = None;
        let mut leading_detached_comments_end = None;
        for item in accessor.fields() {
            let (offset, tag, _) = item?;
            if tag.field_number == 1 {
                if path_start.is_none() { path_start = Some(offset); }
                path_end = Some(offset);
            }
            if tag.field_number == 2 {
                if span_start.is_none() { span_start = Some(offset); }
                span_end = Some(offset);
            }
            if tag.field_number == 3 { leading_comments_offset = Some(offset); }
            if tag.field_number == 4 { trailing_comments_offset = Some(offset); }
            if tag.field_number == 6 {
                if leading_detached_comments_start.is_none() { leading_detached_comments_start = Some(offset); }
                leading_detached_comments_end = Some(offset);
            }
        }

        Ok(Self {
            accessor,
path_start, path_end,
span_start, span_end,
leading_comments_offset,
trailing_comments_offset,
leading_detached_comments_start, leading_detached_comments_end,
        })
    }

    pub fn path(&self) -> roto_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> {
        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)?;
        let (bytes, _) = self.accessor.get_value_at(offset)?;
        str::from_utf8(bytes).map_err(|_| roto_runtime::RotoError::WireFormatViolation)
    }

    pub fn leading_comments_or_default(&self) -> roto_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)?;
        let (bytes, _) = self.accessor.get_value_at(offset)?;
        str::from_utf8(bytes).map_err(|_| roto_runtime::RotoError::WireFormatViolation)
    }

    pub fn trailing_comments_or_default(&self) -> roto_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> {
        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> {
        self.accessor.raw_fields()
    }

}

pub struct LocationBuilder<'b> {
    builder: roto_runtime::ProtoBuilder<'b>,
    path_written: bool,
    span_written: bool,
    leading_comments_written: bool,
    trailing_comments_written: bool,
    leading_detached_comments_written: bool,
}

impl<'b> LocationBuilder<'b> {
    pub fn builder(buf: &mut [u8]) -> LocationBuilder<'_> {
        LocationBuilder {
            builder: roto_runtime::ProtoBuilder::new(buf),
            path_written: false,
            span_written: false,
            leading_comments_written: false,
            trailing_comments_written: false,
            leading_detached_comments_written: false,
        }
    }

    pub fn path(mut self, value: i32) -> roto_runtime::Result<Self> {
        self.builder.write_int32(1, value)?;
        self.path_written = true;
        Ok(self)
    }

    pub fn span(mut self, value: i32) -> roto_runtime::Result<Self> {
        self.builder.write_int32(2, value)?;
        self.span_written = true;
        Ok(self)
    }

    pub fn leading_comments(mut self, value: &str) -> roto_runtime::Result<Self> {
        self.builder.write_string(3, value)?;
        self.leading_comments_written = true;
        Ok(self)
    }

    pub fn trailing_comments(mut self, value: &str) -> roto_runtime::Result<Self> {
        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<Self> {
        self.builder.write_string(6, value)?;
        self.leading_detached_comments_written = true;
        Ok(self)
    }

    pub fn with(mut self, msg: &Location<'_>) -> roto_runtime::Result<Self> {
        for item in msg.raw_fields() {
            let (field_number, raw_bytes) = item?;
            let is_written = match field_number {
                1 => self.path_written,
                2 => self.span_written,
                3 => self.leading_comments_written,
                4 => self.trailing_comments_written,
                6 => self.leading_detached_comments_written,
                _ => false,
            };
            if !is_written {
                self.builder.write_raw(raw_bytes)?;
            }
        }
        Ok(self)
    }

    pub fn finish(self) -> roto_runtime::Result<&'b mut [u8]> {
        self.builder.finish()
    }
}

pub struct OwnedLocation {
    pub data: bytes::Bytes,
}

impl roto_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<Self> {
        Ok(OwnedLocation { data: buf })
    }

    fn bytes(&self) -> bytes::Bytes {
        self.data.clone()
    }
}

}

pub struct GeneratedCodeInfo<'a> {
    accessor: roto_runtime::ProtoAccessor<'a>,
    annotation_start: Option<usize>,
    annotation_end: Option<usize>,
}

impl<'a> GeneratedCodeInfo<'a> {
    pub fn new(data: &'a [u8]) -> roto_runtime::Result<Self> {
        let accessor = roto_runtime::ProtoAccessor::new(data)?;
        let mut annotation_start = None;
        let mut annotation_end = None;
        for item in accessor.fields() {
            let (offset, tag, _) = item?;
            if tag.field_number == 1 {
                if annotation_start.is_none() { annotation_start = Some(offset); }
                annotation_end = Some(offset);
            }
        }

        Ok(Self {
            accessor,
annotation_start, annotation_end,
        })
    }

    pub fn annotation(&self) -> roto_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> {
        self.accessor.raw_fields()
    }

}

pub struct GeneratedCodeInfoBuilder<'b> {
    builder: roto_runtime::ProtoBuilder<'b>,
    annotation_written: bool,
}

impl<'b> GeneratedCodeInfoBuilder<'b> {
    pub fn builder(buf: &mut [u8]) -> GeneratedCodeInfoBuilder<'_> {
        GeneratedCodeInfoBuilder {
            builder: roto_runtime::ProtoBuilder::new(buf),
            annotation_written: false,
        }
    }

    pub fn annotation(mut self, value: &[u8]) -> roto_runtime::Result<Self> {
        self.builder.write_bytes(1, value)?;
        self.annotation_written = true;
        Ok(self)
    }

    pub fn with(mut self, msg: &GeneratedCodeInfo<'_>) -> roto_runtime::Result<Self> {
        for item in msg.raw_fields() {
            let (field_number, raw_bytes) = item?;
            let is_written = match field_number {
                1 => self.annotation_written,
                _ => false,
            };
            if !is_written {
                self.builder.write_raw(raw_bytes)?;
            }
        }
        Ok(self)
    }

    pub fn finish(self) -> roto_runtime::Result<&'b mut [u8]> {
        self.builder.finish()
    }
}

pub struct OwnedGeneratedCodeInfo {
    pub data: bytes::Bytes,
}

impl roto_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<Self> {
        Ok(OwnedGeneratedCodeInfo { data: buf })
    }

    fn bytes(&self) -> bytes::Bytes {
        self.data.clone()
    }
}

pub mod generated_code_info {
pub struct Annotation<'a> {
    accessor: roto_runtime::ProtoAccessor<'a>,
    path_start: Option<usize>,
    path_end: Option<usize>,
    source_file_offset: Option<usize>,
    begin_offset: Option<usize>,
    end_offset: Option<usize>,
    semantic_offset: Option<usize>,
}

impl<'a> Annotation<'a> {
    pub fn new(data: &'a [u8]) -> roto_runtime::Result<Self> {
        let accessor = roto_runtime::ProtoAccessor::new(data)?;
        let mut path_start = None;
        let mut path_end = None;
        let mut source_file_offset = None;
        let mut begin_offset = None;
        let mut end_offset = None;
        let mut semantic_offset = None;
        for item in accessor.fields() {
            let (offset, tag, _) = item?;
            if tag.field_number == 1 {
                if path_start.is_none() { path_start = Some(offset); }
                path_end = Some(offset);
            }
            if tag.field_number == 2 { source_file_offset = Some(offset); }
            if tag.field_number == 3 { begin_offset = Some(offset); }
            if tag.field_number == 4 { end_offset = Some(offset); }
            if tag.field_number == 5 { semantic_offset = Some(offset); }
        }

        Ok(Self {
            accessor,
path_start, path_end,
source_file_offset,
begin_offset,
end_offset,
semantic_offset,
        })
    }

    pub fn path(&self) -> roto_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)?;
        let (bytes, _) = self.accessor.get_value_at(offset)?;
        str::from_utf8(bytes).map_err(|_| roto_runtime::RotoError::WireFormatViolation)
    }

    pub fn source_file_or_default(&self) -> roto_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<i32> {
        let offset = self.begin_offset.ok_or(roto_runtime::RotoError::FieldNotFound)?;
        let (bytes, _) = self.accessor.get_value_at(offset)?;
        roto_runtime::read_varint(bytes).map(|(v, _)| v as i32).map_err(|_| roto_runtime::RotoError::WireFormatViolation)
    }

    pub fn begin_or_default(&self) -> roto_runtime::Result<i32> {
        self.begin().or(Ok(0))
    }

    pub fn has_begin(&self) -> bool { self.begin_offset.is_some() }

    pub fn end(&self) -> roto_runtime::Result<i32> {
        let offset = self.end_offset.ok_or(roto_runtime::RotoError::FieldNotFound)?;
        let (bytes, _) = self.accessor.get_value_at(offset)?;
        roto_runtime::read_varint(bytes).map(|(v, _)| v as i32).map_err(|_| roto_runtime::RotoError::WireFormatViolation)
    }

    pub fn end_or_default(&self) -> roto_runtime::Result<i32> {
        self.end().or(Ok(0))
    }

    pub fn has_end(&self) -> bool { self.end_offset.is_some() }

    pub fn semantic(&self) -> roto_runtime::Result<u64> {
        let offset = self.semantic_offset.ok_or(roto_runtime::RotoError::FieldNotFound)?;
        let (bytes, _) = self.accessor.get_value_at(offset)?;
        roto_runtime::read_varint(bytes).map(|(v, _)| v as u64).map_err(|_| roto_runtime::RotoError::WireFormatViolation)
    }

    pub fn semantic_or_default(&self) -> roto_runtime::Result<u64> {
        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> {
        self.accessor.raw_fields()
    }

}

pub struct AnnotationBuilder<'b> {
    builder: roto_runtime::ProtoBuilder<'b>,
    path_written: bool,
    source_file_written: bool,
    begin_written: bool,
    end_written: bool,
    semantic_written: bool,
}

impl<'b> AnnotationBuilder<'b> {
    pub fn builder(buf: &mut [u8]) -> AnnotationBuilder<'_> {
        AnnotationBuilder {
            builder: roto_runtime::ProtoBuilder::new(buf),
            path_written: false,
            source_file_written: false,
            begin_written: false,
            end_written: false,
            semantic_written: false,
        }
    }

    pub fn path(mut self, value: i32) -> roto_runtime::Result<Self> {
        self.builder.write_int32(1, value)?;
        self.path_written = true;
        Ok(self)
    }

    pub fn source_file(mut self, value: &str) -> roto_runtime::Result<Self> {
        self.builder.write_string(2, value)?;
        self.source_file_written = true;
        Ok(self)
    }

    pub fn begin(mut self, value: i32) -> roto_runtime::Result<Self> {
        self.builder.write_int32(3, value)?;
        self.begin_written = true;
        Ok(self)
    }

    pub fn end(mut self, value: i32) -> roto_runtime::Result<Self> {
        self.builder.write_int32(4, value)?;
        self.end_written = true;
        Ok(self)
    }

    pub fn semantic(mut self, value: u64) -> roto_runtime::Result<Self> {
        self.builder.write_varint(5, value)?;
        self.semantic_written = true;
        Ok(self)
    }

    pub fn with(mut self, msg: &Annotation<'_>) -> roto_runtime::Result<Self> {
        for item in msg.raw_fields() {
            let (field_number, raw_bytes) = item?;
            let is_written = match field_number {
                1 => self.path_written,
                2 => self.source_file_written,
                3 => self.begin_written,
                4 => self.end_written,
                5 => self.semantic_written,
                _ => false,
            };
            if !is_written {
                self.builder.write_raw(raw_bytes)?;
            }
        }
        Ok(self)
    }

    pub fn finish(self) -> roto_runtime::Result<&'b mut [u8]> {
        self.builder.finish()
    }
}

pub struct OwnedAnnotation {
    pub data: bytes::Bytes,
}

impl roto_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<Self> {
        Ok(OwnedAnnotation { data: buf })
    }

    fn bytes(&self) -> bytes::Bytes {
        self.data.clone()
    }
}

pub mod annotation {
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
#[repr(i32)]
pub enum Semantic {
    NONE = 0,
    SET = 1,
    ALIAS = 2,
}

impl Semantic {
    pub fn from_i32(value: i32) -> Self {
        match value {
            0 => Semantic::NONE,
            1 => Semantic::SET,
            2 => Semantic::ALIAS,
            _ => Semantic::NONE,
        }
    }
}

}

}

