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> DurationView<'a> {
88 #[doc(hidden)]
96 pub fn _decode_depth(
97 buf: &'a [u8],
98 depth: u32,
99 ) -> ::core::result::Result<Self, ::buffa::DecodeError> {
100 let mut view = Self::default();
101 view._merge_into_view(buf, depth)?;
102 ::core::result::Result::Ok(view)
103 }
104 #[doc(hidden)]
112 pub fn _merge_into_view(
113 &mut self,
114 buf: &'a [u8],
115 depth: u32,
116 ) -> ::core::result::Result<(), ::buffa::DecodeError> {
117 let _ = depth;
118 #[allow(unused_variables)]
119 let view = self;
120 let mut cur: &'a [u8] = buf;
121 while !cur.is_empty() {
122 let before_tag = cur;
123 let tag = ::buffa::encoding::Tag::decode(&mut cur)?;
124 match tag.field_number() {
125 1u32 => {
126 if tag.wire_type() != ::buffa::encoding::WireType::Varint {
127 return ::core::result::Result::Err(::buffa::DecodeError::WireTypeMismatch {
128 field_number: 1u32,
129 expected: 0u8,
130 actual: tag.wire_type() as u8,
131 });
132 }
133 view.seconds = ::buffa::types::decode_int64(&mut cur)?;
134 }
135 2u32 => {
136 if tag.wire_type() != ::buffa::encoding::WireType::Varint {
137 return ::core::result::Result::Err(::buffa::DecodeError::WireTypeMismatch {
138 field_number: 2u32,
139 expected: 0u8,
140 actual: tag.wire_type() as u8,
141 });
142 }
143 view.nanos = ::buffa::types::decode_int32(&mut cur)?;
144 }
145 _ => {
146 ::buffa::encoding::skip_field_depth(tag, &mut cur, depth)?;
147 let span_len = before_tag.len() - cur.len();
148 view.__buffa_unknown_fields.push_raw(&before_tag[..span_len]);
149 }
150 }
151 }
152 ::core::result::Result::Ok(())
153 }
154}
155impl<'a> ::buffa::MessageView<'a> for DurationView<'a> {
156 type Owned = super::super::Duration;
157 fn decode_view(buf: &'a [u8]) -> ::core::result::Result<Self, ::buffa::DecodeError> {
158 Self::_decode_depth(buf, ::buffa::RECURSION_LIMIT)
159 }
160 fn decode_view_with_limit(
161 buf: &'a [u8],
162 depth: u32,
163 ) -> ::core::result::Result<Self, ::buffa::DecodeError> {
164 Self::_decode_depth(buf, depth)
165 }
166 fn to_owned_message(&self) -> super::super::Duration {
167 self.to_owned_from_source(None)
168 }
169 #[allow(clippy::useless_conversion, clippy::needless_update)]
170 fn to_owned_from_source(
171 &self,
172 __buffa_src: ::core::option::Option<&::buffa::bytes::Bytes>,
173 ) -> super::super::Duration {
174 #[allow(unused_imports)]
175 use ::buffa::alloc::string::ToString as _;
176 let _ = __buffa_src;
177 super::super::Duration {
178 seconds: self.seconds,
179 nanos: self.nanos,
180 __buffa_unknown_fields: self
181 .__buffa_unknown_fields
182 .to_owned()
183 .unwrap_or_default()
184 .into(),
185 ..::core::default::Default::default()
186 }
187 }
188}
189impl<'a> ::buffa::ViewEncode<'a> for DurationView<'a> {
190 #[allow(clippy::needless_borrow, clippy::let_and_return)]
191 fn compute_size(&self, _cache: &mut ::buffa::SizeCache) -> u32 {
192 #[allow(unused_imports)]
193 use ::buffa::Enumeration as _;
194 let mut size = 0u32;
195 if self.seconds != 0i64 {
196 size += 1u32 + ::buffa::types::int64_encoded_len(self.seconds) as u32;
197 }
198 if self.nanos != 0i32 {
199 size += 1u32 + ::buffa::types::int32_encoded_len(self.nanos) as u32;
200 }
201 size += self.__buffa_unknown_fields.encoded_len() as u32;
202 size
203 }
204 #[allow(clippy::needless_borrow)]
205 fn write_to(
206 &self,
207 _cache: &mut ::buffa::SizeCache,
208 buf: &mut impl ::buffa::bytes::BufMut,
209 ) {
210 #[allow(unused_imports)]
211 use ::buffa::Enumeration as _;
212 if self.seconds != 0i64 {
213 ::buffa::encoding::Tag::new(1u32, ::buffa::encoding::WireType::Varint)
214 .encode(buf);
215 ::buffa::types::encode_int64(self.seconds, buf);
216 }
217 if self.nanos != 0i32 {
218 ::buffa::encoding::Tag::new(2u32, ::buffa::encoding::WireType::Varint)
219 .encode(buf);
220 ::buffa::types::encode_int32(self.nanos, buf);
221 }
222 self.__buffa_unknown_fields.write_to(buf);
223 }
224}
225impl<'a> ::buffa::MessageName for DurationView<'a> {
226 const PACKAGE: &'static str = "google.protobuf";
227 const NAME: &'static str = "Duration";
228 const FULL_NAME: &'static str = "google.protobuf.Duration";
229 const TYPE_URL: &'static str = "type.googleapis.com/google.protobuf.Duration";
230}
231impl<'v> ::buffa::DefaultViewInstance for DurationView<'v> {
232 fn default_view_instance<'a>() -> &'a Self
233 where
234 Self: 'a,
235 {
236 static VALUE: ::buffa::__private::OnceBox<DurationView<'static>> = ::buffa::__private::OnceBox::new();
237 VALUE
238 .get_or_init(|| ::buffa::alloc::boxed::Box::new(
239 <DurationView<'static>>::default(),
240 ))
241 }
242}
243impl ::buffa::ViewReborrow for DurationView<'static> {
244 type Reborrowed<'b> = DurationView<'b>;
245 fn reborrow<'b>(this: &'b Self) -> &'b Self::Reborrowed<'b> {
246 this
247 }
248}
249#[derive(Clone, Debug)]
255pub struct DurationOwnedView(::buffa::OwnedView<DurationView<'static>>);
256impl DurationOwnedView {
257 pub fn decode(
267 bytes: ::buffa::bytes::Bytes,
268 ) -> ::core::result::Result<Self, ::buffa::DecodeError> {
269 ::core::result::Result::Ok(DurationOwnedView(::buffa::OwnedView::decode(bytes)?))
270 }
271 pub fn decode_with_options(
279 bytes: ::buffa::bytes::Bytes,
280 opts: &::buffa::DecodeOptions,
281 ) -> ::core::result::Result<Self, ::buffa::DecodeError> {
282 ::core::result::Result::Ok(
283 DurationOwnedView(::buffa::OwnedView::decode_with_options(bytes, opts)?),
284 )
285 }
286 pub fn from_owned(
293 msg: &super::super::Duration,
294 ) -> ::core::result::Result<Self, ::buffa::DecodeError> {
295 ::core::result::Result::Ok(
296 DurationOwnedView(::buffa::OwnedView::from_owned(msg)?),
297 )
298 }
299 #[must_use]
301 pub fn view(&self) -> &DurationView<'_> {
302 self.0.reborrow()
303 }
304 #[must_use]
306 pub fn to_owned_message(&self) -> super::super::Duration {
307 self.0.to_owned_message()
308 }
309 #[must_use]
311 pub fn bytes(&self) -> &::buffa::bytes::Bytes {
312 self.0.bytes()
313 }
314 #[must_use]
316 pub fn into_bytes(self) -> ::buffa::bytes::Bytes {
317 self.0.into_bytes()
318 }
319 #[must_use]
325 pub fn seconds(&self) -> i64 {
326 self.0.reborrow().seconds
327 }
328 #[must_use]
337 pub fn nanos(&self) -> i32 {
338 self.0.reborrow().nanos
339 }
340}
341impl ::core::convert::From<::buffa::OwnedView<DurationView<'static>>>
342for DurationOwnedView {
343 fn from(inner: ::buffa::OwnedView<DurationView<'static>>) -> Self {
344 DurationOwnedView(inner)
345 }
346}
347impl ::core::convert::From<DurationOwnedView>
348for ::buffa::OwnedView<DurationView<'static>> {
349 fn from(wrapper: DurationOwnedView) -> Self {
350 wrapper.0
351 }
352}
353impl ::core::convert::AsRef<::buffa::OwnedView<DurationView<'static>>>
354for DurationOwnedView {
355 fn as_ref(&self) -> &::buffa::OwnedView<DurationView<'static>> {
356 &self.0
357 }
358}
359impl ::buffa::HasMessageView for super::super::Duration {
360 type View<'a> = DurationView<'a>;
361 type ViewHandle = DurationOwnedView;
362}
363#[cfg(feature = "reflect")]
364const _: () = {
365 impl<'a> ::buffa_descriptor::reflect::ReflectMessage for DurationView<'a> {
366 fn message_descriptor(&self) -> &::buffa_descriptor::MessageDescriptor {
367 super::super::__buffa::reflect::descriptor_pool()
368 .message(Self::__buffa_reflect_message_index())
369 }
370 fn pool(
371 &self,
372 ) -> &::buffa::alloc::sync::Arc<::buffa_descriptor::DescriptorPool> {
373 super::super::__buffa::reflect::descriptor_pool()
374 }
375 fn get(
376 &self,
377 field: &::buffa_descriptor::FieldDescriptor,
378 ) -> ::buffa_descriptor::reflect::ValueRef<'_> {
379 #[allow(unused_imports)]
380 use ::buffa::Enumeration as _;
381 match field.number() {
382 1u32 => ::buffa_descriptor::reflect::ValueRef::I64(self.seconds),
383 2u32 => ::buffa_descriptor::reflect::ValueRef::I32(self.nanos),
384 _ => {
385 ::core::debug_assert!(
386 false,
387 "field number {} is not a member of this view's reflect get()",
388 field.number(),
389 );
390 ::buffa_descriptor::reflect::ValueRef::Bool(false)
391 }
392 }
393 }
394 fn has(&self, field: &::buffa_descriptor::FieldDescriptor) -> bool {
395 match field.number() {
396 1u32 => self.seconds != 0,
397 2u32 => self.nanos != 0,
398 _ => false,
399 }
400 }
401 fn for_each_set(
402 &self,
403 f: &mut dyn ::core::ops::FnMut(
404 &::buffa_descriptor::FieldDescriptor,
405 ::buffa_descriptor::reflect::ValueRef<'_>,
406 ),
407 ) {
408 let md = ::buffa_descriptor::reflect::ReflectMessage::message_descriptor(
409 self,
410 );
411 for fd in md.fields() {
412 if ::buffa_descriptor::reflect::ReflectMessage::has(self, fd) {
413 f(fd, ::buffa_descriptor::reflect::ReflectMessage::get(self, fd));
414 }
415 }
416 }
417 fn to_dynamic(&self) -> ::buffa_descriptor::reflect::DynamicMessage {
418 let bytes = ::buffa::ViewEncode::encode_to_vec(self);
419 ::buffa_descriptor::reflect::DynamicMessage::decode(
420 ::buffa::alloc::sync::Arc::clone(
421 super::super::__buffa::reflect::descriptor_pool(),
422 ),
423 Self::__buffa_reflect_message_index(),
424 &bytes,
425 )
426 .expect("view re-encodes to bytes decodable against its own descriptor")
427 }
428 }
429 impl<'a> ::buffa_descriptor::reflect::ReflectElement for DurationView<'a> {
430 fn as_value_ref(&self) -> ::buffa_descriptor::reflect::ValueRef<'_> {
431 ::buffa_descriptor::reflect::ValueRef::Message(
432 ::buffa_descriptor::reflect::ReflectCow::Borrowed(self),
433 )
434 }
435 }
436 impl<'a> DurationView<'a> {
437 #[doc(hidden)]
442 fn __buffa_reflect_message_index() -> ::buffa_descriptor::MessageIndex {
443 static IDX: ::std::sync::OnceLock<::buffa_descriptor::MessageIndex> = ::std::sync::OnceLock::new();
444 *IDX
445 .get_or_init(|| {
446 super::super::__buffa::reflect::descriptor_pool()
447 .message_index(<Self as ::buffa::MessageName>::FULL_NAME)
448 .expect(
449 "generated view type is registered in the embedded descriptor pool",
450 )
451 })
452 }
453 }
454};