Skip to main content

buffa_types/generated/
google.protobuf.duration.rs

1// @generated by buffa-codegen. DO NOT EDIT.
2// source: google/protobuf/duration.proto
3
4/// A Duration represents a signed, fixed-length span of time represented
5/// as a count of seconds and fractions of seconds at nanosecond
6/// resolution. It is independent of any calendar and concepts like "day"
7/// or "month". It is related to Timestamp in that the difference between
8/// two Timestamp values is a Duration and it can be added or subtracted
9/// from a Timestamp. Range is approximately +-10,000 years.
10///
11/// # Examples
12///
13/// Example 1: Compute Duration from two Timestamps in pseudo code.
14///
15/// ```text
16/// Timestamp start = ...;
17/// Timestamp end = ...;
18/// Duration duration = ...;
19///
20/// duration.seconds = end.seconds - start.seconds;
21/// duration.nanos = end.nanos - start.nanos;
22///
23/// if (duration.seconds < 0 && duration.nanos > 0) {
24///   duration.seconds += 1;
25///   duration.nanos -= 1000000000;
26/// } else if (duration.seconds > 0 && duration.nanos < 0) {
27///   duration.seconds -= 1;
28///   duration.nanos += 1000000000;
29/// }
30/// ```
31///
32/// Example 2: Compute Timestamp from Timestamp + Duration in pseudo code.
33///
34/// ```text
35/// Timestamp start = ...;
36/// Duration duration = ...;
37/// Timestamp end = ...;
38///
39/// end.seconds = start.seconds + duration.seconds;
40/// end.nanos = start.nanos + duration.nanos;
41///
42/// if (end.nanos < 0) {
43///   end.seconds -= 1;
44///   end.nanos += 1000000000;
45/// } else if (end.nanos >= 1000000000) {
46///   end.seconds += 1;
47///   end.nanos -= 1000000000;
48/// }
49/// ```
50///
51/// Example 3: Compute Duration from datetime.timedelta in Python.
52///
53/// ```text
54/// td = datetime.timedelta(days=3, minutes=10)
55/// duration = Duration()
56/// duration.FromTimedelta(td)
57/// ```
58///
59/// # JSON Mapping
60///
61/// In JSON format, the Duration type is encoded as a string rather than an
62/// object, where the string ends in the suffix "s" (indicating seconds) and
63/// is preceded by the number of seconds, with nanoseconds expressed as
64/// fractional seconds. For example, 3 seconds with 0 nanoseconds should be
65/// encoded in JSON format as "3s", while 3 seconds and 1 nanosecond should
66/// be expressed in JSON format as "3.000000001s", and 3 seconds and 1
67/// microsecond should be expressed in JSON format as "3.000001s".
68#[derive(Clone, PartialEq, Default)]
69#[cfg_attr(feature = "arbitrary", derive(::arbitrary::Arbitrary))]
70pub struct Duration {
71    /// Signed seconds of the span of time. Must be from -315,576,000,000
72    /// to +315,576,000,000 inclusive. Note: these bounds are computed from:
73    /// 60 sec/min * 60 min/hr * 24 hr/day * 365.25 days/year * 10000 years
74    ///
75    /// Field 1: `seconds`
76    pub seconds: i64,
77    /// Signed fractions of a second at nanosecond resolution of the span
78    /// of time. Durations less than one second are represented with a 0
79    /// `seconds` field and a positive or negative `nanos` field. For durations
80    /// of one second or more, a non-zero value for the `nanos` field must be
81    /// of the same sign as the `seconds` field. Must be from -999,999,999
82    /// to +999,999,999 inclusive.
83    ///
84    /// Field 2: `nanos`
85    pub nanos: i32,
86    #[doc(hidden)]
87    pub __buffa_unknown_fields: ::buffa::UnknownFields,
88}
89impl ::core::fmt::Debug for Duration {
90    fn fmt(&self, f: &mut ::core::fmt::Formatter<'_>) -> ::core::fmt::Result {
91        f.debug_struct("Duration")
92            .field("seconds", &self.seconds)
93            .field("nanos", &self.nanos)
94            .finish()
95    }
96}
97impl Duration {
98    /// Protobuf type URL for this message, for use with `Any::pack` and
99    /// `Any::unpack_if`.
100    ///
101    /// Format: `type.googleapis.com/<fully.qualified.TypeName>`
102    pub const TYPE_URL: &'static str = "type.googleapis.com/google.protobuf.Duration";
103}
104impl ::buffa::DefaultInstance for Duration {
105    fn default_instance() -> &'static Self {
106        static VALUE: ::buffa::__private::OnceBox<Duration> = ::buffa::__private::OnceBox::new();
107        VALUE.get_or_init(|| ::buffa::alloc::boxed::Box::new(Self::default()))
108    }
109}
110#[cfg(feature = "reflect")]
111const _: () = {
112    impl ::buffa_descriptor::reflect::ReflectMessage for Duration {
113        fn message_descriptor(&self) -> &::buffa_descriptor::MessageDescriptor {
114            __buffa::reflect::descriptor_pool()
115                .message(Self::__buffa_reflect_message_index())
116        }
117        fn pool(
118            &self,
119        ) -> &::buffa::alloc::sync::Arc<::buffa_descriptor::DescriptorPool> {
120            __buffa::reflect::descriptor_pool()
121        }
122        fn unknown_fields(&self) -> &::buffa::UnknownFields {
123            &self.__buffa_unknown_fields
124        }
125        fn get(
126            &self,
127            field: &::buffa_descriptor::FieldDescriptor,
128        ) -> ::buffa_descriptor::reflect::ValueRef<'_> {
129            #[allow(unused_imports)]
130            use ::buffa::Enumeration as _;
131            match field.number() {
132                1u32 => ::buffa_descriptor::reflect::ValueRef::I64(self.seconds),
133                2u32 => ::buffa_descriptor::reflect::ValueRef::I32(self.nanos),
134                _ => {
135                    ::core::debug_assert!(
136                        false,
137                        "field number {} is not a member of this message's reflect get()",
138                        field.number(),
139                    );
140                    ::buffa_descriptor::reflect::ValueRef::Bool(false)
141                }
142            }
143        }
144        fn has(&self, field: &::buffa_descriptor::FieldDescriptor) -> bool {
145            match field.number() {
146                1u32 => self.seconds != 0,
147                2u32 => self.nanos != 0,
148                _ => false,
149            }
150        }
151        fn for_each_set(
152            &self,
153            f: &mut dyn ::core::ops::FnMut(
154                &::buffa_descriptor::FieldDescriptor,
155                ::buffa_descriptor::reflect::ValueRef<'_>,
156            ),
157        ) {
158            let md = ::buffa_descriptor::reflect::ReflectMessage::message_descriptor(
159                self,
160            );
161            for fd in md.fields() {
162                if ::buffa_descriptor::reflect::ReflectMessage::has(self, fd) {
163                    f(fd, ::buffa_descriptor::reflect::ReflectMessage::get(self, fd));
164                }
165            }
166        }
167        fn to_dynamic(&self) -> ::buffa_descriptor::reflect::DynamicMessage {
168            ::buffa_descriptor::reflect::DynamicMessage::from_message(
169                self,
170                ::buffa::alloc::sync::Arc::clone(__buffa::reflect::descriptor_pool()),
171                Self::__buffa_reflect_message_index(),
172            )
173        }
174    }
175    impl ::buffa_descriptor::reflect::ReflectElement for Duration {
176        fn as_value_ref(&self) -> ::buffa_descriptor::reflect::ValueRef<'_> {
177            ::buffa_descriptor::reflect::ValueRef::Message(
178                ::buffa_descriptor::reflect::ReflectCow::Borrowed(self),
179            )
180        }
181    }
182    impl Duration {
183        /// Memoized `MessageIndex` for this message type, resolved once
184        /// against the package's embedded descriptor pool.
185        #[doc(hidden)]
186        fn __buffa_reflect_message_index() -> ::buffa_descriptor::MessageIndex {
187            static IDX: ::std::sync::OnceLock<::buffa_descriptor::MessageIndex> = ::std::sync::OnceLock::new();
188            *IDX
189                .get_or_init(|| {
190                    __buffa::reflect::descriptor_pool()
191                        .message_index(<Self as ::buffa::MessageName>::FULL_NAME)
192                        .expect(
193                            "generated message is registered in the embedded descriptor pool",
194                        )
195                })
196        }
197    }
198    impl ::buffa_descriptor::reflect::Reflectable for Duration {
199        /// Vtable-mode reflective handle: borrows `self` directly. No
200        /// encode/decode round-trip and no allocation — the reflective
201        /// accessors read this message's fields in place.
202        fn reflect(&self) -> ::buffa_descriptor::reflect::ReflectCow<'_> {
203            ::buffa_descriptor::reflect::ReflectCow::Borrowed(self)
204        }
205    }
206};
207impl ::buffa::MessageName for Duration {
208    const PACKAGE: &'static str = "google.protobuf";
209    const NAME: &'static str = "Duration";
210    const FULL_NAME: &'static str = "google.protobuf.Duration";
211    const TYPE_URL: &'static str = "type.googleapis.com/google.protobuf.Duration";
212}
213impl ::buffa::Message for Duration {
214    /// Returns the total encoded size in bytes.
215    ///
216    /// The result is a `u32`; the protobuf specification requires all
217    /// messages to fit within 2 GiB (2,147,483,647 bytes), so a
218    /// compliant message will never overflow this type.
219    #[allow(clippy::let_and_return)]
220    fn compute_size(&self, _cache: &mut ::buffa::SizeCache) -> u32 {
221        #[allow(unused_imports)]
222        use ::buffa::Enumeration as _;
223        let mut size = 0u32;
224        if self.seconds != 0i64 {
225            size += 1u32 + ::buffa::types::int64_encoded_len(self.seconds) as u32;
226        }
227        if self.nanos != 0i32 {
228            size += 1u32 + ::buffa::types::int32_encoded_len(self.nanos) as u32;
229        }
230        size += self.__buffa_unknown_fields.encoded_len() as u32;
231        size
232    }
233    fn write_to(
234        &self,
235        _cache: &mut ::buffa::SizeCache,
236        buf: &mut impl ::buffa::bytes::BufMut,
237    ) {
238        #[allow(unused_imports)]
239        use ::buffa::Enumeration as _;
240        if self.seconds != 0i64 {
241            ::buffa::encoding::Tag::new(1u32, ::buffa::encoding::WireType::Varint)
242                .encode(buf);
243            ::buffa::types::encode_int64(self.seconds, buf);
244        }
245        if self.nanos != 0i32 {
246            ::buffa::encoding::Tag::new(2u32, ::buffa::encoding::WireType::Varint)
247                .encode(buf);
248            ::buffa::types::encode_int32(self.nanos, buf);
249        }
250        self.__buffa_unknown_fields.write_to(buf);
251    }
252    fn merge_field(
253        &mut self,
254        tag: ::buffa::encoding::Tag,
255        buf: &mut impl ::buffa::bytes::Buf,
256        depth: u32,
257    ) -> ::core::result::Result<(), ::buffa::DecodeError> {
258        #[allow(unused_imports)]
259        use ::buffa::bytes::Buf as _;
260        #[allow(unused_imports)]
261        use ::buffa::Enumeration as _;
262        match tag.field_number() {
263            1u32 => {
264                if tag.wire_type() != ::buffa::encoding::WireType::Varint {
265                    return ::core::result::Result::Err(::buffa::DecodeError::WireTypeMismatch {
266                        field_number: 1u32,
267                        expected: 0u8,
268                        actual: tag.wire_type() as u8,
269                    });
270                }
271                self.seconds = ::buffa::types::decode_int64(buf)?;
272            }
273            2u32 => {
274                if tag.wire_type() != ::buffa::encoding::WireType::Varint {
275                    return ::core::result::Result::Err(::buffa::DecodeError::WireTypeMismatch {
276                        field_number: 2u32,
277                        expected: 0u8,
278                        actual: tag.wire_type() as u8,
279                    });
280                }
281                self.nanos = ::buffa::types::decode_int32(buf)?;
282            }
283            _ => {
284                self.__buffa_unknown_fields
285                    .push(::buffa::encoding::decode_unknown_field(tag, buf, depth)?);
286            }
287        }
288        ::core::result::Result::Ok(())
289    }
290    fn clear(&mut self) {
291        self.seconds = 0i64;
292        self.nanos = 0i32;
293        self.__buffa_unknown_fields.clear();
294    }
295}
296impl ::buffa::ExtensionSet for Duration {
297    const PROTO_FQN: &'static str = "google.protobuf.Duration";
298    fn unknown_fields(&self) -> &::buffa::UnknownFields {
299        &self.__buffa_unknown_fields
300    }
301    fn unknown_fields_mut(&mut self) -> &mut ::buffa::UnknownFields {
302        &mut self.__buffa_unknown_fields
303    }
304}
305impl ::buffa::text::TextFormat for Duration {
306    fn encode_text(
307        &self,
308        enc: &mut ::buffa::text::TextEncoder<'_>,
309    ) -> ::core::fmt::Result {
310        #[allow(unused_imports)]
311        use ::buffa::Enumeration as _;
312        if self.seconds != 0i64 {
313            enc.write_field_name("seconds")?;
314            enc.write_i64(self.seconds)?;
315        }
316        if self.nanos != 0i32 {
317            enc.write_field_name("nanos")?;
318            enc.write_i32(self.nanos)?;
319        }
320        enc.write_unknown_fields(&self.__buffa_unknown_fields)?;
321        ::core::result::Result::Ok(())
322    }
323    fn merge_text(
324        &mut self,
325        dec: &mut ::buffa::text::TextDecoder<'_>,
326    ) -> ::core::result::Result<(), ::buffa::text::ParseError> {
327        #[allow(unused_imports)]
328        use ::buffa::Enumeration as _;
329        while let ::core::option::Option::Some(__name) = dec.read_field_name()? {
330            match __name {
331                "seconds" => self.seconds = dec.read_i64()?,
332                "nanos" => self.nanos = dec.read_i32()?,
333                _ => dec.skip_value()?,
334            }
335        }
336        ::core::result::Result::Ok(())
337    }
338}
339#[doc(hidden)]
340pub const __DURATION_TEXT_ANY: ::buffa::type_registry::TextAnyEntry = ::buffa::type_registry::TextAnyEntry {
341    type_url: "type.googleapis.com/google.protobuf.Duration",
342    text_encode: ::buffa::type_registry::any_encode_text::<Duration>,
343    text_merge: ::buffa::type_registry::any_merge_text::<Duration>,
344};