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