Skip to main content

buffa_types/generated/
google.protobuf.timestamp.rs

1// @generated by buffa-codegen. DO NOT EDIT.
2// source: google/protobuf/timestamp.proto
3
4/// A Timestamp represents a point in time independent of any time zone or local
5/// calendar, encoded as a count of seconds and fractions of seconds at
6/// nanosecond resolution. The count is relative to an epoch at UTC midnight on
7/// January 1, 1970, in the proleptic Gregorian calendar which extends the
8/// Gregorian calendar backwards to year one.
9///
10/// All minutes are 60 seconds long. Leap seconds are "smeared" so that no leap
11/// second table is needed for interpretation, using a \[24-hour linear
12/// smear\](<https://developers.google.com/time/smear>).
13///
14/// The range is from 0001-01-01T00:00:00Z to 9999-12-31T23:59:59.999999999Z. By
15/// restricting to that range, we ensure that we can convert to and from \[RFC
16/// 3339\](<https://www.ietf.org/rfc/rfc3339.txt>) date strings.
17///
18/// # Examples
19///
20/// Example 1: Compute Timestamp from POSIX `time()`.
21///
22/// ```text
23/// Timestamp timestamp;
24/// timestamp.set_seconds(time(NULL));
25/// timestamp.set_nanos(0);
26/// ```
27///
28/// Example 2: Compute Timestamp from POSIX `gettimeofday()`.
29///
30/// ```text
31/// struct timeval tv;
32/// gettimeofday(&tv, NULL);
33///
34/// Timestamp timestamp;
35/// timestamp.set_seconds(tv.tv_sec);
36/// timestamp.set_nanos(tv.tv_usec * 1000);
37/// ```
38///
39/// Example 3: Compute Timestamp from Win32 `GetSystemTimeAsFileTime()`.
40///
41/// ```text
42/// FILETIME ft;
43/// GetSystemTimeAsFileTime(&ft);
44/// UINT64 ticks = (((UINT64)ft.dwHighDateTime) << 32) | ft.dwLowDateTime;
45///
46/// // A Windows tick is 100 nanoseconds. Windows epoch 1601-01-01T00:00:00Z
47/// // is 11644473600 seconds before Unix epoch 1970-01-01T00:00:00Z.
48/// Timestamp timestamp;
49/// timestamp.set_seconds((INT64) ((ticks / 10000000) - 11644473600LL));
50/// timestamp.set_nanos((INT32) ((ticks % 10000000) * 100));
51/// ```
52///
53/// Example 4: Compute Timestamp from Java `System.currentTimeMillis()`.
54///
55/// ```text
56/// long millis = System.currentTimeMillis();
57///
58/// Timestamp timestamp = Timestamp.newBuilder().setSeconds(millis / 1000)
59///     .setNanos((int) ((millis % 1000) * 1000000)).build();
60/// ```
61///
62/// Example 5: Compute Timestamp from Java `Instant.now()`.
63///
64/// ```text
65/// Instant now = Instant.now();
66///
67/// Timestamp timestamp =
68///     Timestamp.newBuilder().setSeconds(now.getEpochSecond())
69///         .setNanos(now.getNano()).build();
70/// ```
71///
72/// Example 6: Compute Timestamp from current time in Python.
73///
74/// ```text
75/// timestamp = Timestamp()
76/// timestamp.GetCurrentTime()
77/// ```
78///
79/// # JSON Mapping
80///
81/// In JSON format, the Timestamp type is encoded as a string in the
82/// [RFC 3339](https://www.ietf.org/rfc/rfc3339.txt) format. That is, the
83/// format is "{year}-{month}-{day}T{hour}:{min}:{sec}\[.{frac_sec}\]Z"
84/// where {year} is always expressed using four digits while {month}, {day},
85/// {hour}, {min}, and {sec} are zero-padded to two digits each. The fractional
86/// seconds, which can go up to 9 digits (i.e. up to 1 nanosecond resolution),
87/// are optional. The "Z" suffix indicates the timezone ("UTC"); the timezone
88/// is required. A proto3 JSON serializer should always use UTC (as indicated by
89/// "Z") when printing the Timestamp type and a proto3 JSON parser should be
90/// able to accept both UTC and other timezones (as indicated by an offset).
91///
92/// For example, "2017-01-15T01:30:15.01Z" encodes 15.01 seconds past
93/// 01:30 UTC on January 15, 2017.
94///
95/// In JavaScript, one can convert a Date object to this format using the
96/// standard
97/// [toISOString()](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/toISOString)
98/// method. In Python, a standard `datetime.datetime` object can be converted
99/// to this format using
100/// [`strftime`](https://docs.python.org/2/library/time.html#time.strftime) with
101/// the time format spec '%Y-%m-%dT%H:%M:%S.%fZ'. Likewise, in Java, one can use
102/// the Joda Time's \[`ISODateTimeFormat.dateTime()`\](
103/// <http://joda-time.sourceforge.net/apidocs/org/joda/time/format/ISODateTimeFormat.html#dateTime(>)
104/// ) to obtain a formatter capable of generating timestamps in this format.
105#[derive(Clone, PartialEq, Default)]
106#[cfg_attr(feature = "arbitrary", derive(::arbitrary::Arbitrary))]
107pub struct Timestamp {
108    /// Represents seconds of UTC time since Unix epoch
109    /// 1970-01-01T00:00:00Z. Must be from 0001-01-01T00:00:00Z to
110    /// 9999-12-31T23:59:59Z inclusive.
111    ///
112    /// Field 1: `seconds`
113    pub seconds: i64,
114    /// Non-negative fractions of a second at nanosecond resolution. Negative
115    /// second values with fractions must still have non-negative nanos values
116    /// that count forward in time. Must be from 0 to 999,999,999
117    /// inclusive.
118    ///
119    /// Field 2: `nanos`
120    pub nanos: i32,
121    #[doc(hidden)]
122    pub __buffa_unknown_fields: ::buffa::UnknownFields,
123}
124impl ::core::fmt::Debug for Timestamp {
125    fn fmt(&self, f: &mut ::core::fmt::Formatter<'_>) -> ::core::fmt::Result {
126        f.debug_struct("Timestamp")
127            .field("seconds", &self.seconds)
128            .field("nanos", &self.nanos)
129            .finish()
130    }
131}
132impl Timestamp {
133    /// Protobuf type URL for this message, for use with `Any::pack` and
134    /// `Any::unpack_if`.
135    ///
136    /// Format: `type.googleapis.com/<fully.qualified.TypeName>`
137    pub const TYPE_URL: &'static str = "type.googleapis.com/google.protobuf.Timestamp";
138}
139::buffa::impl_default_instance!(Timestamp);
140#[cfg(feature = "reflect")]
141const _: () = {
142    impl ::buffa_descriptor::reflect::ReflectMessage for Timestamp {
143        fn message_descriptor(&self) -> &::buffa_descriptor::MessageDescriptor {
144            __buffa::reflect::descriptor_pool()
145                .message(Self::__buffa_reflect_message_index())
146        }
147        fn pool(
148            &self,
149        ) -> &::buffa::alloc::sync::Arc<::buffa_descriptor::DescriptorPool> {
150            __buffa::reflect::descriptor_pool()
151        }
152        fn unknown_fields(&self) -> &::buffa::UnknownFields {
153            &self.__buffa_unknown_fields
154        }
155        fn get(
156            &self,
157            field: &::buffa_descriptor::FieldDescriptor,
158        ) -> ::buffa_descriptor::reflect::ValueRef<'_> {
159            #[allow(unused_imports)]
160            use ::buffa::Enumeration as _;
161            match field.number() {
162                1u32 => ::buffa_descriptor::reflect::ValueRef::I64(self.seconds),
163                2u32 => ::buffa_descriptor::reflect::ValueRef::I32(self.nanos),
164                _ => {
165                    ::core::debug_assert!(
166                        false,
167                        "field number {} is not a member of this message's reflect get()",
168                        field.number(),
169                    );
170                    ::buffa_descriptor::reflect::ValueRef::Bool(false)
171                }
172            }
173        }
174        fn has(&self, field: &::buffa_descriptor::FieldDescriptor) -> bool {
175            match field.number() {
176                1u32 => self.seconds != 0,
177                2u32 => self.nanos != 0,
178                _ => false,
179            }
180        }
181        fn for_each_set(
182            &self,
183            f: &mut dyn ::core::ops::FnMut(
184                &::buffa_descriptor::FieldDescriptor,
185                ::buffa_descriptor::reflect::ValueRef<'_>,
186            ),
187        ) {
188            let md = ::buffa_descriptor::reflect::ReflectMessage::message_descriptor(
189                self,
190            );
191            for fd in md.fields() {
192                if ::buffa_descriptor::reflect::ReflectMessage::has(self, fd) {
193                    f(fd, ::buffa_descriptor::reflect::ReflectMessage::get(self, fd));
194                }
195            }
196        }
197        fn to_dynamic(&self) -> ::buffa_descriptor::reflect::DynamicMessage {
198            ::buffa_descriptor::reflect::DynamicMessage::from_message(
199                self,
200                ::buffa::alloc::sync::Arc::clone(__buffa::reflect::descriptor_pool()),
201                Self::__buffa_reflect_message_index(),
202            )
203        }
204    }
205    impl ::buffa_descriptor::reflect::ReflectElement for Timestamp {
206        #[inline]
207        fn as_value_ref(&self) -> ::buffa_descriptor::reflect::ValueRef<'_> {
208            ::buffa_descriptor::reflect::ValueRef::Message(
209                ::buffa_descriptor::reflect::ReflectCow::Borrowed(self),
210            )
211        }
212    }
213    impl Timestamp {
214        /// Memoized `MessageIndex` for this message type, resolved once
215        /// against the package's embedded descriptor pool.
216        #[doc(hidden)]
217        fn __buffa_reflect_message_index() -> ::buffa_descriptor::MessageIndex {
218            static IDX: ::std::sync::OnceLock<::buffa_descriptor::MessageIndex> = ::std::sync::OnceLock::new();
219            *IDX
220                .get_or_init(|| {
221                    __buffa::reflect::descriptor_pool()
222                        .message_index(<Self as ::buffa::MessageName>::FULL_NAME)
223                        .expect(
224                            "generated message is registered in the embedded descriptor pool",
225                        )
226                })
227        }
228    }
229    impl ::buffa_descriptor::reflect::Reflectable for Timestamp {
230        /// Vtable-mode reflective handle: borrows `self` directly. No
231        /// encode/decode round-trip and no allocation — the reflective
232        /// accessors read this message's fields in place.
233        #[inline]
234        fn reflect(&self) -> ::buffa_descriptor::reflect::ReflectCow<'_> {
235            ::buffa_descriptor::reflect::ReflectCow::Borrowed(self)
236        }
237    }
238};
239impl ::buffa::MessageName for Timestamp {
240    const PACKAGE: &'static str = "google.protobuf";
241    const NAME: &'static str = "Timestamp";
242    const FULL_NAME: &'static str = "google.protobuf.Timestamp";
243    const TYPE_URL: &'static str = "type.googleapis.com/google.protobuf.Timestamp";
244}
245impl ::buffa::Message for Timestamp {
246    /// Returns the total encoded size in bytes.
247    ///
248    /// Accumulates in `u64` (which cannot overflow for in-memory
249    /// data) and saturates to `u32` at return, so a message whose
250    /// encoded size exceeds the 2 GiB protobuf limit yields a value
251    /// above [`::buffa::MAX_MESSAGE_BYTES`] that the encode entry
252    /// points reject, never a silently wrapped size.
253    #[allow(clippy::let_and_return)]
254    fn compute_size(&self, _cache: &mut ::buffa::SizeCache) -> u32 {
255        #[allow(unused_imports)]
256        use ::buffa::Enumeration as _;
257        let mut size = 0u64;
258        if self.seconds != 0i64 {
259            size += 1u64 + ::buffa::types::int64_encoded_len(self.seconds) as u64;
260        }
261        if self.nanos != 0i32 {
262            size += 1u64 + ::buffa::types::int32_encoded_len(self.nanos) as u64;
263        }
264        size += self.__buffa_unknown_fields.encoded_len() as u64;
265        ::buffa::saturate_size(size)
266    }
267    fn write_to(
268        &self,
269        _cache: &mut ::buffa::SizeCache,
270        buf: &mut impl ::buffa::EncodeSink,
271    ) {
272        #[allow(unused_imports)]
273        use ::buffa::Enumeration as _;
274        if self.seconds != 0i64 {
275            ::buffa::types::put_int64_field(1u32, self.seconds, buf);
276        }
277        if self.nanos != 0i32 {
278            ::buffa::types::put_int32_field(2u32, self.nanos, buf);
279        }
280        self.__buffa_unknown_fields.write_to(buf);
281    }
282    fn merge_field(
283        &mut self,
284        tag: ::buffa::encoding::Tag,
285        buf: &mut impl ::buffa::bytes::Buf,
286        ctx: ::buffa::DecodeContext<'_>,
287    ) -> ::core::result::Result<(), ::buffa::DecodeError> {
288        #[allow(unused_imports)]
289        use ::buffa::bytes::Buf as _;
290        #[allow(unused_imports)]
291        use ::buffa::Enumeration as _;
292        match tag.field_number() {
293            1u32 => {
294                ::buffa::encoding::check_wire_type(
295                    tag,
296                    ::buffa::encoding::WireType::Varint,
297                )?;
298                self.seconds = ::buffa::types::decode_int64(buf)?;
299            }
300            2u32 => {
301                ::buffa::encoding::check_wire_type(
302                    tag,
303                    ::buffa::encoding::WireType::Varint,
304                )?;
305                self.nanos = ::buffa::types::decode_int32(buf)?;
306            }
307            _ => {
308                self.__buffa_unknown_fields
309                    .push(::buffa::encoding::decode_unknown_field(tag, buf, ctx)?);
310            }
311        }
312        ::core::result::Result::Ok(())
313    }
314    fn clear(&mut self) {
315        self.seconds = 0i64;
316        self.nanos = 0i32;
317        self.__buffa_unknown_fields.clear();
318    }
319}
320impl ::buffa::ExtensionSet for Timestamp {
321    const PROTO_FQN: &'static str = "google.protobuf.Timestamp";
322    fn unknown_fields(&self) -> &::buffa::UnknownFields {
323        &self.__buffa_unknown_fields
324    }
325    fn unknown_fields_mut(&mut self) -> &mut ::buffa::UnknownFields {
326        &mut self.__buffa_unknown_fields
327    }
328}
329impl ::buffa::text::TextFormat for Timestamp {
330    fn encode_text(
331        &self,
332        enc: &mut ::buffa::text::TextEncoder<'_>,
333    ) -> ::core::fmt::Result {
334        #[allow(unused_imports)]
335        use ::buffa::Enumeration as _;
336        if self.seconds != 0i64 {
337            enc.write_field_name("seconds")?;
338            enc.write_i64(self.seconds)?;
339        }
340        if self.nanos != 0i32 {
341            enc.write_field_name("nanos")?;
342            enc.write_i32(self.nanos)?;
343        }
344        enc.write_unknown_fields(&self.__buffa_unknown_fields)?;
345        ::core::result::Result::Ok(())
346    }
347    fn merge_text(
348        &mut self,
349        dec: &mut ::buffa::text::TextDecoder<'_>,
350    ) -> ::core::result::Result<(), ::buffa::text::ParseError> {
351        #[allow(unused_imports)]
352        use ::buffa::Enumeration as _;
353        while let ::core::option::Option::Some(__name) = dec.read_field_name()? {
354            match __name {
355                "seconds" => self.seconds = dec.read_i64()?,
356                "nanos" => self.nanos = dec.read_i32()?,
357                _ => dec.skip_value()?,
358            }
359        }
360        ::core::result::Result::Ok(())
361    }
362}
363#[doc(hidden)]
364pub const __TIMESTAMP_TEXT_ANY: ::buffa::type_registry::TextAnyEntry = ::buffa::type_registry::TextAnyEntry {
365    type_url: "type.googleapis.com/google.protobuf.Timestamp",
366    text_encode: ::buffa::type_registry::any_encode_text::<Timestamp>,
367    text_merge: ::buffa::type_registry::any_merge_text::<Timestamp>,
368};