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}
139impl ::buffa::DefaultInstance for Timestamp {
140    fn default_instance() -> &'static Self {
141        static VALUE: ::buffa::__private::OnceBox<Timestamp> = ::buffa::__private::OnceBox::new();
142        VALUE.get_or_init(|| ::buffa::alloc::boxed::Box::new(Self::default()))
143    }
144}
145#[cfg(feature = "reflect")]
146const _: () = {
147    impl ::buffa_descriptor::reflect::ReflectMessage for Timestamp {
148        fn message_descriptor(&self) -> &::buffa_descriptor::MessageDescriptor {
149            __buffa::reflect::descriptor_pool()
150                .message(Self::__buffa_reflect_message_index())
151        }
152        fn pool(
153            &self,
154        ) -> &::buffa::alloc::sync::Arc<::buffa_descriptor::DescriptorPool> {
155            __buffa::reflect::descriptor_pool()
156        }
157        fn unknown_fields(&self) -> &::buffa::UnknownFields {
158            &self.__buffa_unknown_fields
159        }
160        fn get(
161            &self,
162            field: &::buffa_descriptor::FieldDescriptor,
163        ) -> ::buffa_descriptor::reflect::ValueRef<'_> {
164            #[allow(unused_imports)]
165            use ::buffa::Enumeration as _;
166            match field.number() {
167                1u32 => ::buffa_descriptor::reflect::ValueRef::I64(self.seconds),
168                2u32 => ::buffa_descriptor::reflect::ValueRef::I32(self.nanos),
169                _ => {
170                    ::core::debug_assert!(
171                        false,
172                        "field number {} is not a member of this message's reflect get()",
173                        field.number(),
174                    );
175                    ::buffa_descriptor::reflect::ValueRef::Bool(false)
176                }
177            }
178        }
179        fn has(&self, field: &::buffa_descriptor::FieldDescriptor) -> bool {
180            match field.number() {
181                1u32 => self.seconds != 0,
182                2u32 => self.nanos != 0,
183                _ => false,
184            }
185        }
186        fn for_each_set(
187            &self,
188            f: &mut dyn ::core::ops::FnMut(
189                &::buffa_descriptor::FieldDescriptor,
190                ::buffa_descriptor::reflect::ValueRef<'_>,
191            ),
192        ) {
193            let md = ::buffa_descriptor::reflect::ReflectMessage::message_descriptor(
194                self,
195            );
196            for fd in md.fields() {
197                if ::buffa_descriptor::reflect::ReflectMessage::has(self, fd) {
198                    f(fd, ::buffa_descriptor::reflect::ReflectMessage::get(self, fd));
199                }
200            }
201        }
202        fn to_dynamic(&self) -> ::buffa_descriptor::reflect::DynamicMessage {
203            ::buffa_descriptor::reflect::DynamicMessage::from_message(
204                self,
205                ::buffa::alloc::sync::Arc::clone(__buffa::reflect::descriptor_pool()),
206                Self::__buffa_reflect_message_index(),
207            )
208        }
209    }
210    impl ::buffa_descriptor::reflect::ReflectElement for Timestamp {
211        #[inline]
212        fn as_value_ref(&self) -> ::buffa_descriptor::reflect::ValueRef<'_> {
213            ::buffa_descriptor::reflect::ValueRef::Message(
214                ::buffa_descriptor::reflect::ReflectCow::Borrowed(self),
215            )
216        }
217    }
218    impl Timestamp {
219        /// Memoized `MessageIndex` for this message type, resolved once
220        /// against the package's embedded descriptor pool.
221        #[doc(hidden)]
222        fn __buffa_reflect_message_index() -> ::buffa_descriptor::MessageIndex {
223            static IDX: ::std::sync::OnceLock<::buffa_descriptor::MessageIndex> = ::std::sync::OnceLock::new();
224            *IDX
225                .get_or_init(|| {
226                    __buffa::reflect::descriptor_pool()
227                        .message_index(<Self as ::buffa::MessageName>::FULL_NAME)
228                        .expect(
229                            "generated message is registered in the embedded descriptor pool",
230                        )
231                })
232        }
233    }
234    impl ::buffa_descriptor::reflect::Reflectable for Timestamp {
235        /// Vtable-mode reflective handle: borrows `self` directly. No
236        /// encode/decode round-trip and no allocation — the reflective
237        /// accessors read this message's fields in place.
238        #[inline]
239        fn reflect(&self) -> ::buffa_descriptor::reflect::ReflectCow<'_> {
240            ::buffa_descriptor::reflect::ReflectCow::Borrowed(self)
241        }
242    }
243};
244impl ::buffa::MessageName for Timestamp {
245    const PACKAGE: &'static str = "google.protobuf";
246    const NAME: &'static str = "Timestamp";
247    const FULL_NAME: &'static str = "google.protobuf.Timestamp";
248    const TYPE_URL: &'static str = "type.googleapis.com/google.protobuf.Timestamp";
249}
250impl ::buffa::Message for Timestamp {
251    /// Returns the total encoded size in bytes.
252    ///
253    /// The result is a `u32`; the protobuf specification requires all
254    /// messages to fit within 2 GiB (2,147,483,647 bytes), so a
255    /// compliant message will never overflow this type.
256    #[allow(clippy::let_and_return)]
257    fn compute_size(&self, _cache: &mut ::buffa::SizeCache) -> u32 {
258        #[allow(unused_imports)]
259        use ::buffa::Enumeration as _;
260        let mut size = 0u32;
261        if self.seconds != 0i64 {
262            size += 1u32 + ::buffa::types::int64_encoded_len(self.seconds) as u32;
263        }
264        if self.nanos != 0i32 {
265            size += 1u32 + ::buffa::types::int32_encoded_len(self.nanos) as u32;
266        }
267        size += self.__buffa_unknown_fields.encoded_len() as u32;
268        size
269    }
270    fn write_to(
271        &self,
272        _cache: &mut ::buffa::SizeCache,
273        buf: &mut impl ::buffa::bytes::BufMut,
274    ) {
275        #[allow(unused_imports)]
276        use ::buffa::Enumeration as _;
277        if self.seconds != 0i64 {
278            ::buffa::encoding::Tag::new(1u32, ::buffa::encoding::WireType::Varint)
279                .encode(buf);
280            ::buffa::types::encode_int64(self.seconds, buf);
281        }
282        if self.nanos != 0i32 {
283            ::buffa::encoding::Tag::new(2u32, ::buffa::encoding::WireType::Varint)
284                .encode(buf);
285            ::buffa::types::encode_int32(self.nanos, buf);
286        }
287        self.__buffa_unknown_fields.write_to(buf);
288    }
289    fn merge_field(
290        &mut self,
291        tag: ::buffa::encoding::Tag,
292        buf: &mut impl ::buffa::bytes::Buf,
293        depth: u32,
294    ) -> ::core::result::Result<(), ::buffa::DecodeError> {
295        #[allow(unused_imports)]
296        use ::buffa::bytes::Buf as _;
297        #[allow(unused_imports)]
298        use ::buffa::Enumeration as _;
299        match tag.field_number() {
300            1u32 => {
301                if tag.wire_type() != ::buffa::encoding::WireType::Varint {
302                    return ::core::result::Result::Err(::buffa::DecodeError::WireTypeMismatch {
303                        field_number: 1u32,
304                        expected: 0u8,
305                        actual: tag.wire_type() as u8,
306                    });
307                }
308                self.seconds = ::buffa::types::decode_int64(buf)?;
309            }
310            2u32 => {
311                if tag.wire_type() != ::buffa::encoding::WireType::Varint {
312                    return ::core::result::Result::Err(::buffa::DecodeError::WireTypeMismatch {
313                        field_number: 2u32,
314                        expected: 0u8,
315                        actual: tag.wire_type() as u8,
316                    });
317                }
318                self.nanos = ::buffa::types::decode_int32(buf)?;
319            }
320            _ => {
321                self.__buffa_unknown_fields
322                    .push(::buffa::encoding::decode_unknown_field(tag, buf, depth)?);
323            }
324        }
325        ::core::result::Result::Ok(())
326    }
327    fn clear(&mut self) {
328        self.seconds = 0i64;
329        self.nanos = 0i32;
330        self.__buffa_unknown_fields.clear();
331    }
332}
333impl ::buffa::ExtensionSet for Timestamp {
334    const PROTO_FQN: &'static str = "google.protobuf.Timestamp";
335    fn unknown_fields(&self) -> &::buffa::UnknownFields {
336        &self.__buffa_unknown_fields
337    }
338    fn unknown_fields_mut(&mut self) -> &mut ::buffa::UnknownFields {
339        &mut self.__buffa_unknown_fields
340    }
341}
342impl ::buffa::text::TextFormat for Timestamp {
343    fn encode_text(
344        &self,
345        enc: &mut ::buffa::text::TextEncoder<'_>,
346    ) -> ::core::fmt::Result {
347        #[allow(unused_imports)]
348        use ::buffa::Enumeration as _;
349        if self.seconds != 0i64 {
350            enc.write_field_name("seconds")?;
351            enc.write_i64(self.seconds)?;
352        }
353        if self.nanos != 0i32 {
354            enc.write_field_name("nanos")?;
355            enc.write_i32(self.nanos)?;
356        }
357        enc.write_unknown_fields(&self.__buffa_unknown_fields)?;
358        ::core::result::Result::Ok(())
359    }
360    fn merge_text(
361        &mut self,
362        dec: &mut ::buffa::text::TextDecoder<'_>,
363    ) -> ::core::result::Result<(), ::buffa::text::ParseError> {
364        #[allow(unused_imports)]
365        use ::buffa::Enumeration as _;
366        while let ::core::option::Option::Some(__name) = dec.read_field_name()? {
367            match __name {
368                "seconds" => self.seconds = dec.read_i64()?,
369                "nanos" => self.nanos = dec.read_i32()?,
370                _ => dec.skip_value()?,
371            }
372        }
373        ::core::result::Result::Ok(())
374    }
375}
376#[doc(hidden)]
377pub const __TIMESTAMP_TEXT_ANY: ::buffa::type_registry::TextAnyEntry = ::buffa::type_registry::TextAnyEntry {
378    type_url: "type.googleapis.com/google.protobuf.Timestamp",
379    text_encode: ::buffa::type_registry::any_encode_text::<Timestamp>,
380    text_merge: ::buffa::type_registry::any_merge_text::<Timestamp>,
381};