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