Skip to main content

buffa_types/generated/
google.protobuf.empty.__view.rs

1// @generated by buffa-codegen. DO NOT EDIT.
2// source: google/protobuf/empty.proto
3
4/// A generic empty message that you can re-use to avoid defining duplicated
5/// empty messages in your APIs.
6///
7/// Example usage: gRPC uses google.protobuf.Empty as the input and output
8/// type for RPCs defined as returning or accepting "nothing":
9///
10/// ```text
11/// rpc Bar(google.protobuf.Empty) returns (google.protobuf.Empty);
12/// ```
13#[derive(Clone, Debug, Default)]
14pub struct EmptyView<'a> {
15    pub __buffa_unknown_fields: ::buffa::UnknownFieldsView<'a>,
16}
17impl<'a> ::buffa::MessageView<'a> for EmptyView<'a> {
18    type Owned = super::super::Empty;
19    fn decode_view(buf: &'a [u8]) -> ::core::result::Result<Self, ::buffa::DecodeError> {
20        let __limit = ::core::cell::Cell::new(::buffa::DEFAULT_UNKNOWN_FIELD_LIMIT);
21        let __elem = ::core::cell::Cell::new(::buffa::DEFAULT_ELEMENT_MEMORY_LIMIT);
22        <Self as ::buffa::MessageView>::decode_view_ctx(
23            buf,
24            ::buffa::DecodeContext::new(::buffa::RECURSION_LIMIT, &__limit)
25                .with_element_memory(&__elem),
26        )
27    }
28    fn decode_view_with_ctx(
29        buf: &'a [u8],
30        ctx: ::buffa::DecodeContext<'_>,
31    ) -> ::core::result::Result<Self, ::buffa::DecodeError> {
32        <Self as ::buffa::MessageView>::decode_view_ctx(buf, ctx)
33    }
34    #[inline]
35    fn merge_view_field(
36        &mut self,
37        tag: ::buffa::encoding::Tag,
38        cur: &'a [u8],
39        before_tag: &'a [u8],
40        ctx: ::buffa::DecodeContext<'_>,
41    ) -> ::core::result::Result<&'a [u8], ::buffa::DecodeError> {
42        let _ = ctx;
43        #[allow(unused_variables)]
44        let view = self;
45        let mut cur = cur;
46        match tag.field_number() {
47            _ => {
48                ::buffa::encoding::skip_field_depth(tag, &mut cur, ctx.depth())?;
49                let span_len = before_tag.len() - cur.len();
50                view.__buffa_unknown_fields.push_record(before_tag, span_len, ctx)?;
51            }
52        }
53        ::core::result::Result::Ok(cur)
54    }
55    fn to_owned_message(
56        &self,
57    ) -> ::core::result::Result<super::super::Empty, ::buffa::DecodeError> {
58        self.to_owned_from_source(None)
59    }
60    #[allow(clippy::useless_conversion, clippy::needless_update)]
61    fn to_owned_from_source(
62        &self,
63        __buffa_src: ::core::option::Option<&::buffa::bytes::Bytes>,
64    ) -> ::core::result::Result<super::super::Empty, ::buffa::DecodeError> {
65        #[allow(unused_imports)]
66        use ::buffa::alloc::string::ToString as _;
67        let _ = __buffa_src;
68        ::core::result::Result::Ok(super::super::Empty {
69            __buffa_unknown_fields: self.__buffa_unknown_fields.to_owned()?.into(),
70            ..::core::default::Default::default()
71        })
72    }
73}
74impl<'a> ::buffa::ViewEncode<'a> for EmptyView<'a> {
75    #[allow(clippy::needless_borrow, clippy::let_and_return)]
76    fn compute_size(&self, _cache: &mut ::buffa::SizeCache) -> u32 {
77        #[allow(unused_imports)]
78        use ::buffa::Enumeration as _;
79        let mut size = 0u64;
80        size += self.__buffa_unknown_fields.encoded_len() as u64;
81        ::buffa::saturate_size(size)
82    }
83    #[allow(clippy::needless_borrow)]
84    fn write_to(
85        &self,
86        _cache: &mut ::buffa::SizeCache,
87        buf: &mut impl ::buffa::EncodeSink,
88    ) {
89        #[allow(unused_imports)]
90        use ::buffa::Enumeration as _;
91        self.__buffa_unknown_fields.write_to(buf);
92    }
93}
94impl<'a> ::buffa::MessageName for EmptyView<'a> {
95    const PACKAGE: &'static str = "google.protobuf";
96    const NAME: &'static str = "Empty";
97    const FULL_NAME: &'static str = "google.protobuf.Empty";
98    const TYPE_URL: &'static str = "type.googleapis.com/google.protobuf.Empty";
99}
100::buffa::impl_default_view_instance!(EmptyView);
101::buffa::impl_view_reborrow!(EmptyView);
102/** Self-contained, `'static` owned view of a `Empty` message.
103
104 Wraps [`::buffa::OwnedView`]`<`[`EmptyView`]`<'static>>`: the decoded view and the [`::buffa::bytes::Bytes`] buffer it borrows from travel together, so the handle is `'static` and `Send + Sync` — suitable for async handlers, spawned tasks, and anywhere a `'static` bound is required.
105
106 Field accessors return borrows tied to `&self`. Use [`Self::view`] to get the full [`EmptyView`] when you need struct patterns, iteration helpers, or to pass the view to lifetime-parameterised code.*/
107#[derive(Clone, Debug)]
108pub struct EmptyOwnedView(::buffa::OwnedView<EmptyView<'static>>);
109impl EmptyOwnedView {
110    /// Decode an owned view from a [`::buffa::bytes::Bytes`] buffer.
111    ///
112    /// The view borrows directly from the buffer's data; the buffer is
113    /// retained inside the returned handle.
114    ///
115    /// # Errors
116    ///
117    /// Returns [`::buffa::DecodeError`] if the buffer contains invalid
118    /// protobuf data.
119    pub fn decode(
120        bytes: ::buffa::bytes::Bytes,
121    ) -> ::core::result::Result<Self, ::buffa::DecodeError> {
122        ::core::result::Result::Ok(EmptyOwnedView(::buffa::OwnedView::decode(bytes)?))
123    }
124    /// Decode with custom [`::buffa::DecodeOptions`] (recursion limit,
125    /// max message size).
126    ///
127    /// # Errors
128    ///
129    /// Returns [`::buffa::DecodeError`] if the buffer is invalid or
130    /// exceeds the configured limits.
131    pub fn decode_with_options(
132        bytes: ::buffa::bytes::Bytes,
133        opts: &::buffa::DecodeOptions,
134    ) -> ::core::result::Result<Self, ::buffa::DecodeError> {
135        ::core::result::Result::Ok(
136            EmptyOwnedView(::buffa::OwnedView::decode_with_options(bytes, opts)?),
137        )
138    }
139    /// Build from an owned message via an encode → decode round-trip.
140    ///
141    /// # Errors
142    ///
143    /// Returns [`::buffa::DecodeError::MessageTooLarge`] if the
144    /// message's encoded size exceeds the 2 GiB protobuf limit, or
145    /// another [`::buffa::DecodeError`] if the re-encoded bytes are
146    /// somehow invalid (should not happen for well-formed messages).
147    pub fn from_owned(
148        msg: &super::super::Empty,
149    ) -> ::core::result::Result<Self, ::buffa::DecodeError> {
150        ::core::result::Result::Ok(EmptyOwnedView(::buffa::OwnedView::from_owned(msg)?))
151    }
152    /// Borrow the full [`EmptyView`] with its lifetime tied to `&self`.
153    #[must_use]
154    pub fn view(&self) -> &EmptyView<'_> {
155        self.0.reborrow()
156    }
157    /// Convert to the owned message type.
158    ///
159    /// Infallible: this type's constructors wire-decode their
160    /// buffer, and a view produced by wire decoding always
161    /// converts. Delegates to [`::buffa::OwnedView::to_owned_message`],
162    /// whose contract also governs handles converted from a raw
163    /// [`::buffa::OwnedView`].
164    #[must_use]
165    pub fn to_owned_message(&self) -> super::super::Empty {
166        self.0.to_owned_message()
167    }
168    /// The underlying bytes buffer.
169    #[must_use]
170    pub fn bytes(&self) -> &::buffa::bytes::Bytes {
171        self.0.bytes()
172    }
173    /// Consume the handle, returning the underlying bytes buffer.
174    #[must_use]
175    pub fn into_bytes(self) -> ::buffa::bytes::Bytes {
176        self.0.into_bytes()
177    }
178}
179impl ::core::convert::From<::buffa::OwnedView<EmptyView<'static>>> for EmptyOwnedView {
180    fn from(inner: ::buffa::OwnedView<EmptyView<'static>>) -> Self {
181        EmptyOwnedView(inner)
182    }
183}
184impl ::core::convert::From<EmptyOwnedView> for ::buffa::OwnedView<EmptyView<'static>> {
185    fn from(wrapper: EmptyOwnedView) -> Self {
186        wrapper.0
187    }
188}
189impl ::core::convert::AsRef<::buffa::OwnedView<EmptyView<'static>>> for EmptyOwnedView {
190    fn as_ref(&self) -> &::buffa::OwnedView<EmptyView<'static>> {
191        &self.0
192    }
193}
194impl ::buffa::HasMessageView for super::super::Empty {
195    type View<'a> = EmptyView<'a>;
196    type ViewHandle = EmptyOwnedView;
197}
198#[cfg(feature = "reflect")]
199const _: () = {
200    impl<'a> ::buffa_descriptor::reflect::ReflectMessage for EmptyView<'a> {
201        fn message_descriptor(&self) -> &::buffa_descriptor::MessageDescriptor {
202            super::super::__buffa::reflect::descriptor_pool()
203                .message(Self::__buffa_reflect_message_index())
204        }
205        fn pool(
206            &self,
207        ) -> &::buffa::alloc::sync::Arc<::buffa_descriptor::DescriptorPool> {
208            super::super::__buffa::reflect::descriptor_pool()
209        }
210        fn get(
211            &self,
212            field: &::buffa_descriptor::FieldDescriptor,
213        ) -> ::buffa_descriptor::reflect::ValueRef<'_> {
214            #[allow(unused_imports)]
215            use ::buffa::Enumeration as _;
216            match field.number() {
217                _ => {
218                    ::core::debug_assert!(
219                        false,
220                        "field number {} is not a member of this view's reflect get()",
221                        field.number(),
222                    );
223                    ::buffa_descriptor::reflect::ValueRef::Bool(false)
224                }
225            }
226        }
227        fn has(&self, field: &::buffa_descriptor::FieldDescriptor) -> bool {
228            match field.number() {
229                _ => false,
230            }
231        }
232        fn for_each_set(
233            &self,
234            f: &mut dyn ::core::ops::FnMut(
235                &::buffa_descriptor::FieldDescriptor,
236                ::buffa_descriptor::reflect::ValueRef<'_>,
237            ),
238        ) {
239            let md = ::buffa_descriptor::reflect::ReflectMessage::message_descriptor(
240                self,
241            );
242            for fd in md.fields() {
243                if ::buffa_descriptor::reflect::ReflectMessage::has(self, fd) {
244                    f(fd, ::buffa_descriptor::reflect::ReflectMessage::get(self, fd));
245                }
246            }
247        }
248        fn to_dynamic(&self) -> ::buffa_descriptor::reflect::DynamicMessage {
249            let bytes = ::buffa::ViewEncode::encode_to_vec(self);
250            let options = ::buffa::DecodeOptions::new()
251                .with_element_memory_limit(
252                    bytes
253                        .len()
254                        .saturating_mul(128)
255                        .max(::buffa::DEFAULT_ELEMENT_MEMORY_LIMIT),
256                )
257                .with_unknown_field_limit(
258                    bytes.len().max(::buffa::DEFAULT_UNKNOWN_FIELD_LIMIT),
259                );
260            ::buffa_descriptor::reflect::DynamicMessage::decode_with_options(
261                    ::buffa::alloc::sync::Arc::clone(
262                        super::super::__buffa::reflect::descriptor_pool(),
263                    ),
264                    Self::__buffa_reflect_message_index(),
265                    &bytes,
266                    &options,
267                )
268                .expect("view re-encodes to bytes decodable against its own descriptor")
269        }
270    }
271    impl<'a> ::buffa_descriptor::reflect::ReflectElement for EmptyView<'a> {
272        fn as_value_ref(&self) -> ::buffa_descriptor::reflect::ValueRef<'_> {
273            ::buffa_descriptor::reflect::ValueRef::Message(
274                ::buffa_descriptor::reflect::ReflectCow::Borrowed(self),
275            )
276        }
277    }
278    impl<'a> EmptyView<'a> {
279        /// Memoized `MessageIndex` for this view's message type, resolved
280        /// once against the package's embedded descriptor pool. An inherent
281        /// associated fn (not a free fn) so sibling views in the same module
282        /// do not collide.
283        #[doc(hidden)]
284        fn __buffa_reflect_message_index() -> ::buffa_descriptor::MessageIndex {
285            static IDX: ::std::sync::OnceLock<::buffa_descriptor::MessageIndex> = ::std::sync::OnceLock::new();
286            *IDX
287                .get_or_init(|| {
288                    super::super::__buffa::reflect::descriptor_pool()
289                        .message_index(<Self as ::buffa::MessageName>::FULL_NAME)
290                        .expect(
291                            "generated view type is registered in the embedded descriptor pool",
292                        )
293                })
294        }
295    }
296};