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}
104::buffa::impl_default_instance!(Duration);
105#[cfg(feature = "reflect")]
106const _: () = {
107    impl ::buffa_descriptor::reflect::ReflectMessage for Duration {
108        fn message_descriptor(&self) -> &::buffa_descriptor::MessageDescriptor {
109            __buffa::reflect::descriptor_pool()
110                .message(Self::__buffa_reflect_message_index())
111        }
112        fn pool(
113            &self,
114        ) -> &::buffa::alloc::sync::Arc<::buffa_descriptor::DescriptorPool> {
115            __buffa::reflect::descriptor_pool()
116        }
117        fn unknown_fields(&self) -> &::buffa::UnknownFields {
118            &self.__buffa_unknown_fields
119        }
120        fn get(
121            &self,
122            field: &::buffa_descriptor::FieldDescriptor,
123        ) -> ::buffa_descriptor::reflect::ValueRef<'_> {
124            #[allow(unused_imports)]
125            use ::buffa::Enumeration as _;
126            match field.number() {
127                1u32 => ::buffa_descriptor::reflect::ValueRef::I64(self.seconds),
128                2u32 => ::buffa_descriptor::reflect::ValueRef::I32(self.nanos),
129                _ => {
130                    ::core::debug_assert!(
131                        false,
132                        "field number {} is not a member of this message's reflect get()",
133                        field.number(),
134                    );
135                    ::buffa_descriptor::reflect::ValueRef::Bool(false)
136                }
137            }
138        }
139        fn has(&self, field: &::buffa_descriptor::FieldDescriptor) -> bool {
140            match field.number() {
141                1u32 => self.seconds != 0,
142                2u32 => self.nanos != 0,
143                _ => false,
144            }
145        }
146        fn for_each_set(
147            &self,
148            f: &mut dyn ::core::ops::FnMut(
149                &::buffa_descriptor::FieldDescriptor,
150                ::buffa_descriptor::reflect::ValueRef<'_>,
151            ),
152        ) {
153            let md = ::buffa_descriptor::reflect::ReflectMessage::message_descriptor(
154                self,
155            );
156            for fd in md.fields() {
157                if ::buffa_descriptor::reflect::ReflectMessage::has(self, fd) {
158                    f(fd, ::buffa_descriptor::reflect::ReflectMessage::get(self, fd));
159                }
160            }
161        }
162        fn to_dynamic(&self) -> ::buffa_descriptor::reflect::DynamicMessage {
163            ::buffa_descriptor::reflect::DynamicMessage::from_message(
164                self,
165                ::buffa::alloc::sync::Arc::clone(__buffa::reflect::descriptor_pool()),
166                Self::__buffa_reflect_message_index(),
167            )
168        }
169    }
170    impl ::buffa_descriptor::reflect::ReflectElement for Duration {
171        #[inline]
172        fn as_value_ref(&self) -> ::buffa_descriptor::reflect::ValueRef<'_> {
173            ::buffa_descriptor::reflect::ValueRef::Message(
174                ::buffa_descriptor::reflect::ReflectCow::Borrowed(self),
175            )
176        }
177    }
178    impl Duration {
179        /// Memoized `MessageIndex` for this message type, resolved once
180        /// against the package's embedded descriptor pool.
181        #[doc(hidden)]
182        fn __buffa_reflect_message_index() -> ::buffa_descriptor::MessageIndex {
183            static IDX: ::std::sync::OnceLock<::buffa_descriptor::MessageIndex> = ::std::sync::OnceLock::new();
184            *IDX
185                .get_or_init(|| {
186                    __buffa::reflect::descriptor_pool()
187                        .message_index(<Self as ::buffa::MessageName>::FULL_NAME)
188                        .expect(
189                            "generated message is registered in the embedded descriptor pool",
190                        )
191                })
192        }
193    }
194    impl ::buffa_descriptor::reflect::Reflectable for Duration {
195        /// Vtable-mode reflective handle: borrows `self` directly. No
196        /// encode/decode round-trip and no allocation — the reflective
197        /// accessors read this message's fields in place.
198        #[inline]
199        fn reflect(&self) -> ::buffa_descriptor::reflect::ReflectCow<'_> {
200            ::buffa_descriptor::reflect::ReflectCow::Borrowed(self)
201        }
202    }
203};
204impl ::buffa::MessageName for Duration {
205    const PACKAGE: &'static str = "google.protobuf";
206    const NAME: &'static str = "Duration";
207    const FULL_NAME: &'static str = "google.protobuf.Duration";
208    const TYPE_URL: &'static str = "type.googleapis.com/google.protobuf.Duration";
209}
210impl ::buffa::Message for Duration {
211    /// Returns the total encoded size in bytes.
212    ///
213    /// Accumulates in `u64` (which cannot overflow for in-memory
214    /// data) and saturates to `u32` at return, so a message whose
215    /// encoded size exceeds the 2 GiB protobuf limit yields a value
216    /// above [`::buffa::MAX_MESSAGE_BYTES`] that the encode entry
217    /// points reject, never a silently wrapped size.
218    #[allow(clippy::let_and_return)]
219    fn compute_size(&self, _cache: &mut ::buffa::SizeCache) -> u32 {
220        #[allow(unused_imports)]
221        use ::buffa::Enumeration as _;
222        let mut size = 0u64;
223        if self.seconds != 0i64 {
224            size += 1u64 + ::buffa::types::int64_encoded_len(self.seconds) as u64;
225        }
226        if self.nanos != 0i32 {
227            size += 1u64 + ::buffa::types::int32_encoded_len(self.nanos) as u64;
228        }
229        size += self.__buffa_unknown_fields.encoded_len() as u64;
230        ::buffa::saturate_size(size)
231    }
232    fn write_to(
233        &self,
234        _cache: &mut ::buffa::SizeCache,
235        buf: &mut impl ::buffa::EncodeSink,
236    ) {
237        #[allow(unused_imports)]
238        use ::buffa::Enumeration as _;
239        if self.seconds != 0i64 {
240            ::buffa::types::put_int64_field(1u32, self.seconds, buf);
241        }
242        if self.nanos != 0i32 {
243            ::buffa::types::put_int32_field(2u32, self.nanos, buf);
244        }
245        self.__buffa_unknown_fields.write_to(buf);
246    }
247    fn merge_field(
248        &mut self,
249        tag: ::buffa::encoding::Tag,
250        buf: &mut impl ::buffa::bytes::Buf,
251        ctx: ::buffa::DecodeContext<'_>,
252    ) -> ::core::result::Result<(), ::buffa::DecodeError> {
253        #[allow(unused_imports)]
254        use ::buffa::bytes::Buf as _;
255        #[allow(unused_imports)]
256        use ::buffa::Enumeration as _;
257        match tag.field_number() {
258            1u32 => {
259                ::buffa::encoding::check_wire_type(
260                    tag,
261                    ::buffa::encoding::WireType::Varint,
262                )?;
263                self.seconds = ::buffa::types::decode_int64(buf)?;
264            }
265            2u32 => {
266                ::buffa::encoding::check_wire_type(
267                    tag,
268                    ::buffa::encoding::WireType::Varint,
269                )?;
270                self.nanos = ::buffa::types::decode_int32(buf)?;
271            }
272            _ => {
273                self.__buffa_unknown_fields
274                    .push(::buffa::encoding::decode_unknown_field(tag, buf, ctx)?);
275            }
276        }
277        ::core::result::Result::Ok(())
278    }
279    fn clear(&mut self) {
280        self.seconds = 0i64;
281        self.nanos = 0i32;
282        self.__buffa_unknown_fields.clear();
283    }
284}
285impl ::buffa::ExtensionSet for Duration {
286    const PROTO_FQN: &'static str = "google.protobuf.Duration";
287    fn unknown_fields(&self) -> &::buffa::UnknownFields {
288        &self.__buffa_unknown_fields
289    }
290    fn unknown_fields_mut(&mut self) -> &mut ::buffa::UnknownFields {
291        &mut self.__buffa_unknown_fields
292    }
293}
294impl ::buffa::text::TextFormat for Duration {
295    fn encode_text(
296        &self,
297        enc: &mut ::buffa::text::TextEncoder<'_>,
298    ) -> ::core::fmt::Result {
299        #[allow(unused_imports)]
300        use ::buffa::Enumeration as _;
301        if self.seconds != 0i64 {
302            enc.write_field_name("seconds")?;
303            enc.write_i64(self.seconds)?;
304        }
305        if self.nanos != 0i32 {
306            enc.write_field_name("nanos")?;
307            enc.write_i32(self.nanos)?;
308        }
309        enc.write_unknown_fields(&self.__buffa_unknown_fields)?;
310        ::core::result::Result::Ok(())
311    }
312    fn merge_text(
313        &mut self,
314        dec: &mut ::buffa::text::TextDecoder<'_>,
315    ) -> ::core::result::Result<(), ::buffa::text::ParseError> {
316        #[allow(unused_imports)]
317        use ::buffa::Enumeration as _;
318        while let ::core::option::Option::Some(__name) = dec.read_field_name()? {
319            match __name {
320                "seconds" => self.seconds = dec.read_i64()?,
321                "nanos" => self.nanos = dec.read_i32()?,
322                _ => dec.skip_value()?,
323            }
324        }
325        ::core::result::Result::Ok(())
326    }
327}
328#[doc(hidden)]
329pub const __DURATION_TEXT_ANY: ::buffa::type_registry::TextAnyEntry = ::buffa::type_registry::TextAnyEntry {
330    type_url: "type.googleapis.com/google.protobuf.Duration",
331    text_encode: ::buffa::type_registry::any_encode_text::<Duration>,
332    text_merge: ::buffa::type_registry::any_merge_text::<Duration>,
333};