buffa_types/generated/
google.protobuf.duration.__view.rs1#[derive(Clone, Debug, Default)]
69pub struct DurationView<'a> {
70 pub seconds: i64,
76 pub nanos: i32,
85 pub __buffa_unknown_fields: ::buffa::UnknownFieldsView<'a>,
86}
87impl<'a> ::buffa::MessageView<'a> for DurationView<'a> {
88 type Owned = super::super::Duration;
89 fn decode_view(buf: &'a [u8]) -> ::core::result::Result<Self, ::buffa::DecodeError> {
90 let __limit = ::core::cell::Cell::new(::buffa::DEFAULT_UNKNOWN_FIELD_LIMIT);
91 <Self as ::buffa::MessageView>::decode_view_ctx(
92 buf,
93 ::buffa::DecodeContext::new(::buffa::RECURSION_LIMIT, &__limit),
94 )
95 }
96 fn decode_view_with_ctx(
97 buf: &'a [u8],
98 ctx: ::buffa::DecodeContext<'_>,
99 ) -> ::core::result::Result<Self, ::buffa::DecodeError> {
100 <Self as ::buffa::MessageView>::decode_view_ctx(buf, ctx)
101 }
102 fn merge_view_field(
103 &mut self,
104 tag: ::buffa::encoding::Tag,
105 cur: &'a [u8],
106 before_tag: &'a [u8],
107 ctx: ::buffa::DecodeContext<'_>,
108 ) -> ::core::result::Result<&'a [u8], ::buffa::DecodeError> {
109 let _ = ctx;
110 #[allow(unused_variables)]
111 let view = self;
112 let mut cur = cur;
113 match tag.field_number() {
114 1u32 => {
115 ::buffa::encoding::check_wire_type(
116 tag,
117 ::buffa::encoding::WireType::Varint,
118 )?;
119 view.seconds = ::buffa::types::decode_int64(&mut cur)?;
120 }
121 2u32 => {
122 ::buffa::encoding::check_wire_type(
123 tag,
124 ::buffa::encoding::WireType::Varint,
125 )?;
126 view.nanos = ::buffa::types::decode_int32(&mut cur)?;
127 }
128 _ => {
129 ::buffa::encoding::skip_field_depth(tag, &mut cur, ctx.depth())?;
130 let span_len = before_tag.len() - cur.len();
131 view.__buffa_unknown_fields.push_record(before_tag, span_len, ctx)?;
132 }
133 }
134 ::core::result::Result::Ok(cur)
135 }
136 fn to_owned_message(
137 &self,
138 ) -> ::core::result::Result<super::super::Duration, ::buffa::DecodeError> {
139 self.to_owned_from_source(None)
140 }
141 #[allow(clippy::useless_conversion, clippy::needless_update)]
142 fn to_owned_from_source(
143 &self,
144 __buffa_src: ::core::option::Option<&::buffa::bytes::Bytes>,
145 ) -> ::core::result::Result<super::super::Duration, ::buffa::DecodeError> {
146 #[allow(unused_imports)]
147 use ::buffa::alloc::string::ToString as _;
148 let _ = __buffa_src;
149 ::core::result::Result::Ok(super::super::Duration {
150 seconds: self.seconds,
151 nanos: self.nanos,
152 __buffa_unknown_fields: self.__buffa_unknown_fields.to_owned()?.into(),
153 ..::core::default::Default::default()
154 })
155 }
156}
157impl<'a> ::buffa::ViewEncode<'a> for DurationView<'a> {
158 #[allow(clippy::needless_borrow, clippy::let_and_return)]
159 fn compute_size(&self, _cache: &mut ::buffa::SizeCache) -> u32 {
160 #[allow(unused_imports)]
161 use ::buffa::Enumeration as _;
162 let mut size = 0u32;
163 if self.seconds != 0i64 {
164 size += 1u32 + ::buffa::types::int64_encoded_len(self.seconds) as u32;
165 }
166 if self.nanos != 0i32 {
167 size += 1u32 + ::buffa::types::int32_encoded_len(self.nanos) as u32;
168 }
169 size += self.__buffa_unknown_fields.encoded_len() as u32;
170 size
171 }
172 #[allow(clippy::needless_borrow)]
173 fn write_to(
174 &self,
175 _cache: &mut ::buffa::SizeCache,
176 buf: &mut impl ::buffa::bytes::BufMut,
177 ) {
178 #[allow(unused_imports)]
179 use ::buffa::Enumeration as _;
180 if self.seconds != 0i64 {
181 ::buffa::types::put_int64_field(1u32, self.seconds, buf);
182 }
183 if self.nanos != 0i32 {
184 ::buffa::types::put_int32_field(2u32, self.nanos, buf);
185 }
186 self.__buffa_unknown_fields.write_to(buf);
187 }
188}
189impl<'a> ::buffa::MessageName for DurationView<'a> {
190 const PACKAGE: &'static str = "google.protobuf";
191 const NAME: &'static str = "Duration";
192 const FULL_NAME: &'static str = "google.protobuf.Duration";
193 const TYPE_URL: &'static str = "type.googleapis.com/google.protobuf.Duration";
194}
195::buffa::impl_default_view_instance!(DurationView);
196::buffa::impl_view_reborrow!(DurationView);
197#[derive(Clone, Debug)]
203pub struct DurationOwnedView(::buffa::OwnedView<DurationView<'static>>);
204impl DurationOwnedView {
205 pub fn decode(
215 bytes: ::buffa::bytes::Bytes,
216 ) -> ::core::result::Result<Self, ::buffa::DecodeError> {
217 ::core::result::Result::Ok(DurationOwnedView(::buffa::OwnedView::decode(bytes)?))
218 }
219 pub fn decode_with_options(
227 bytes: ::buffa::bytes::Bytes,
228 opts: &::buffa::DecodeOptions,
229 ) -> ::core::result::Result<Self, ::buffa::DecodeError> {
230 ::core::result::Result::Ok(
231 DurationOwnedView(::buffa::OwnedView::decode_with_options(bytes, opts)?),
232 )
233 }
234 pub fn from_owned(
241 msg: &super::super::Duration,
242 ) -> ::core::result::Result<Self, ::buffa::DecodeError> {
243 ::core::result::Result::Ok(
244 DurationOwnedView(::buffa::OwnedView::from_owned(msg)?),
245 )
246 }
247 #[must_use]
249 pub fn view(&self) -> &DurationView<'_> {
250 self.0.reborrow()
251 }
252 pub fn to_owned_message(
259 &self,
260 ) -> ::core::result::Result<super::super::Duration, ::buffa::DecodeError> {
261 self.0.to_owned_message()
262 }
263 #[must_use]
265 pub fn bytes(&self) -> &::buffa::bytes::Bytes {
266 self.0.bytes()
267 }
268 #[must_use]
270 pub fn into_bytes(self) -> ::buffa::bytes::Bytes {
271 self.0.into_bytes()
272 }
273 #[must_use]
279 pub fn seconds(&self) -> i64 {
280 self.0.reborrow().seconds
281 }
282 #[must_use]
291 pub fn nanos(&self) -> i32 {
292 self.0.reborrow().nanos
293 }
294}
295impl ::core::convert::From<::buffa::OwnedView<DurationView<'static>>>
296for DurationOwnedView {
297 fn from(inner: ::buffa::OwnedView<DurationView<'static>>) -> Self {
298 DurationOwnedView(inner)
299 }
300}
301impl ::core::convert::From<DurationOwnedView>
302for ::buffa::OwnedView<DurationView<'static>> {
303 fn from(wrapper: DurationOwnedView) -> Self {
304 wrapper.0
305 }
306}
307impl ::core::convert::AsRef<::buffa::OwnedView<DurationView<'static>>>
308for DurationOwnedView {
309 fn as_ref(&self) -> &::buffa::OwnedView<DurationView<'static>> {
310 &self.0
311 }
312}
313impl ::buffa::HasMessageView for super::super::Duration {
314 type View<'a> = DurationView<'a>;
315 type ViewHandle = DurationOwnedView;
316}
317#[cfg(feature = "reflect")]
318const _: () = {
319 impl<'a> ::buffa_descriptor::reflect::ReflectMessage for DurationView<'a> {
320 fn message_descriptor(&self) -> &::buffa_descriptor::MessageDescriptor {
321 super::super::__buffa::reflect::descriptor_pool()
322 .message(Self::__buffa_reflect_message_index())
323 }
324 fn pool(
325 &self,
326 ) -> &::buffa::alloc::sync::Arc<::buffa_descriptor::DescriptorPool> {
327 super::super::__buffa::reflect::descriptor_pool()
328 }
329 fn get(
330 &self,
331 field: &::buffa_descriptor::FieldDescriptor,
332 ) -> ::buffa_descriptor::reflect::ValueRef<'_> {
333 #[allow(unused_imports)]
334 use ::buffa::Enumeration as _;
335 match field.number() {
336 1u32 => ::buffa_descriptor::reflect::ValueRef::I64(self.seconds),
337 2u32 => ::buffa_descriptor::reflect::ValueRef::I32(self.nanos),
338 _ => {
339 ::core::debug_assert!(
340 false,
341 "field number {} is not a member of this view's reflect get()",
342 field.number(),
343 );
344 ::buffa_descriptor::reflect::ValueRef::Bool(false)
345 }
346 }
347 }
348 fn has(&self, field: &::buffa_descriptor::FieldDescriptor) -> bool {
349 match field.number() {
350 1u32 => self.seconds != 0,
351 2u32 => self.nanos != 0,
352 _ => false,
353 }
354 }
355 fn for_each_set(
356 &self,
357 f: &mut dyn ::core::ops::FnMut(
358 &::buffa_descriptor::FieldDescriptor,
359 ::buffa_descriptor::reflect::ValueRef<'_>,
360 ),
361 ) {
362 let md = ::buffa_descriptor::reflect::ReflectMessage::message_descriptor(
363 self,
364 );
365 for fd in md.fields() {
366 if ::buffa_descriptor::reflect::ReflectMessage::has(self, fd) {
367 f(fd, ::buffa_descriptor::reflect::ReflectMessage::get(self, fd));
368 }
369 }
370 }
371 fn to_dynamic(&self) -> ::buffa_descriptor::reflect::DynamicMessage {
372 let bytes = ::buffa::ViewEncode::encode_to_vec(self);
373 ::buffa_descriptor::reflect::DynamicMessage::decode(
374 ::buffa::alloc::sync::Arc::clone(
375 super::super::__buffa::reflect::descriptor_pool(),
376 ),
377 Self::__buffa_reflect_message_index(),
378 &bytes,
379 )
380 .expect("view re-encodes to bytes decodable against its own descriptor")
381 }
382 }
383 impl<'a> ::buffa_descriptor::reflect::ReflectElement for DurationView<'a> {
384 fn as_value_ref(&self) -> ::buffa_descriptor::reflect::ValueRef<'_> {
385 ::buffa_descriptor::reflect::ValueRef::Message(
386 ::buffa_descriptor::reflect::ReflectCow::Borrowed(self),
387 )
388 }
389 }
390 impl<'a> DurationView<'a> {
391 #[doc(hidden)]
396 fn __buffa_reflect_message_index() -> ::buffa_descriptor::MessageIndex {
397 static IDX: ::std::sync::OnceLock<::buffa_descriptor::MessageIndex> = ::std::sync::OnceLock::new();
398 *IDX
399 .get_or_init(|| {
400 super::super::__buffa::reflect::descriptor_pool()
401 .message_index(<Self as ::buffa::MessageName>::FULL_NAME)
402 .expect(
403 "generated view type is registered in the embedded descriptor pool",
404 )
405 })
406 }
407 }
408};