pbrs 0.1.0

Pure-Rust Protocol Buffers kernel with the Google protobuf v4 application API
Documentation
// @generated by protoc-gen-pbrs
#[allow(
    unused,
    non_snake_case,
    non_camel_case_types,
    clippy::all,
    unreachable_pub,
    reason = "generated by protoc-gen-pbrs"
)]
mod __gen {
    #![allow(
        unused,
        non_snake_case,
        non_camel_case_types,
        clippy::all,
        unsafe_code,
        unreachable_pub,
        reason = "generated by protoc-gen-pbrs"
    )]
    use pbrs::prelude::*;
    use pbrs::UnknownFields;
    use pbrs::{
        Enum, Map, MapMut, MapView, ParseError, ProtoBytes, ProtoString, Repeated, RepeatedMut,
        RepeatedView, SerializeError, UnknownEnumValue,
    };

    fn generated_pool() -> std::sync::Arc<pbrs::DescriptorPool> {
        pbrs::gencode::conformance_pool()
    }

    #[derive(Clone, Debug)]
    pub struct Empty {
        unknown: UnknownFields,
        cached_size: pbrs::rt::CachedSize,
    }
    impl PartialEq for Empty {
        fn eq(&self, other: &Self) -> bool {
            self.unknown == other.unknown
        }
    }
    impl Eq for Empty {}
    impl Default for Empty {
        #[inline(always)]
        fn default() -> Self {
            unsafe { pbrs::rt::zeroed_message() }
        }
    }
    impl Empty {
        pub fn new() -> Self {
            Self::default()
        }
        pub const EMPTY_PARSE_OK: bool = true;
        pub const FULL_NAME: &'static str = "google.protobuf.Empty";
        #[inline(always)]
        fn check_required(&self) -> Result<(), ParseError> {
            Ok(())
        }
        fn merge_bytes(&mut self, data: &[u8], depth: u32) -> Result<(), ParseError> {
            if data.is_empty() {
                return self.check_required();
            }
            let mut pos = 0;
            let mut wire = None;
            self.merge_inner(data, &mut wire, &mut pos, depth, true, None)
        }
        fn merge_bytes_dont_enforce(&mut self, data: &[u8], depth: u32) -> Result<(), ParseError> {
            if data.is_empty() {
                return Ok(());
            }
            let mut pos = 0;
            let mut wire = None;
            self.merge_inner(data, &mut wire, &mut pos, depth, false, None)
        }
        fn merge_group(
            &mut self,
            data: &[u8],
            wire: &mut Option<pbrs::rt::Wire>,
            pos: &mut usize,
            num: u32,
            depth: u32,
        ) -> Result<(), ParseError> {
            self.merge_inner(data, wire, pos, depth, false, Some(num))
        }
        fn merge_inner(
            &mut self,
            data: &[u8],
            wire: &mut Option<pbrs::rt::Wire>,
            pos: &mut usize,
            depth: u32,
            enforce: bool,
            until: Option<u32>,
        ) -> Result<(), ParseError> {
            if depth > pbrs::RECURSION_LIMIT {
                return Err(ParseError::new("recursion limit exceeded"));
            }
            let _ = enforce;
            self.cached_size.dirty();
            while *pos < data.len() {
                let (n, w) = pbrs::rt::decode_tag(data, pos)?;
                if let Some(g) = until {
                    if w == pbrs::rt::WIRE_EGROUP {
                        if n != g {
                            return Err(ParseError::new("mismatched end-group"));
                        }
                        return Ok(());
                    }
                }
                match n {
                    _ => self
                        .unknown
                        .fields
                        .push(pbrs::rt::capture_unknown(data, pos, n, w)?),
                }
            }
            if until.is_some() {
                return Err(ParseError::new("truncated group"));
            }
            if enforce {
                self.check_required()?;
            }
            Ok(())
        }
        fn validate_inner(
            wire: &pbrs::rt::Wire,
            pos: &mut usize,
            depth: u32,
        ) -> Result<(), ParseError> {
            Self::validate_until(wire, pos, depth, None)
        }
        fn validate_until(
            wire: &pbrs::rt::Wire,
            pos: &mut usize,
            depth: u32,
            until: Option<u32>,
        ) -> Result<(), ParseError> {
            if depth > pbrs::RECURSION_LIMIT {
                return Err(ParseError::new("recursion limit exceeded"));
            }
            let data = wire.as_slice();
            while *pos < data.len() {
                let (n, w) = pbrs::rt::decode_tag(data, pos)?;
                if let Some(g) = until {
                    if w == pbrs::rt::WIRE_EGROUP {
                        if n != g {
                            return Err(ParseError::new("mismatched end-group"));
                        }
                        return Ok(());
                    }
                }
                match n {
                    _ => pbrs::rt::skip_field(data, pos, w)?,
                }
            }
            if until.is_some() {
                return Err(ParseError::new("truncated group"));
            }
            Ok(())
        }
        fn compute_size(&self) -> u64 {
            if let Some(n) = self.cached_size.get() {
                return n;
            }
            let mut n = self.unknown.encoded_len();
            self.cached_size.set(n);
            n
        }
        fn write_to(&self, out: &mut impl pbrs::rt::WireOut) {
            self.unknown.encode(out);
        }
        pub fn to_json(&self) -> Result<String, SerializeError> {
            Ok(self.to_json_value()?.to_string())
        }
        pub fn from_json(json: &str) -> Result<Self, ParseError> {
            Self::from_json_ignore(json, false)
        }
        pub fn from_json_ignore(json: &str, ignore: bool) -> Result<Self, ParseError> {
            let v = pbrs::json::parse(json)?;
            Self::from_json_value(&v, ignore)
        }
        fn to_json_value(&self) -> Result<pbrs::json::Json, SerializeError> {
            Ok(pbrs::json::empty())
        }
        fn from_json_value(v: &pbrs::json::Json, ignore: bool) -> Result<Self, ParseError> {
            pbrs::json::as_empty(v, ignore)?;
            Ok(Self::new())
        }
        pub fn to_text(&self) -> Result<String, SerializeError> {
            let mut out = String::new();
            self.write_text(&mut out, 0)?;
            Ok(out)
        }
        pub fn to_text_with_unknown(&self) -> Result<String, SerializeError> {
            let mut out = String::new();
            self.write_text(&mut out, 0)?;
            pbrs::text::write_unknown_fields(&self.unknown, &mut out, 0);
            Ok(out)
        }
        pub fn from_text(text: &str) -> Result<Self, ParseError> {
            Self::from_text_value(&pbrs::text::parse(text)?)
        }
        fn write_text(&self, out: &mut String, indent: usize) -> Result<(), SerializeError> {
            Ok(())
        }
        fn from_text_value(fields: &[(String, pbrs::text::TextValue)]) -> Result<Self, ParseError> {
            let mut msg = Self::new();
            for (key, val) in fields {
                match key.as_str() {
                    _ => return Err(ParseError::owned(format!("unknown field {key}"))),
                }
            }
            Ok(msg)
        }
    }
    pbrs::impl_typed_message!(Empty, EmptyView, EmptyMut);
}
#[allow(unused_imports, reason = "generated by protoc-gen-pbrs")]
pub use __gen::*;