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