Skip to main content

buffa_types/generated/
google.protobuf.timestamp.rs

1// @generated by protoc-gen-buffa. 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    #[doc(hidden)]
124    pub __buffa_cached_size: ::buffa::__private::CachedSize,
125}
126impl ::core::fmt::Debug for Timestamp {
127    fn fmt(&self, f: &mut ::core::fmt::Formatter<'_>) -> ::core::fmt::Result {
128        f.debug_struct("Timestamp")
129            .field("seconds", &self.seconds)
130            .field("nanos", &self.nanos)
131            .finish()
132    }
133}
134impl Timestamp {
135    /// Protobuf type URL for this message, for use with `Any::pack` and
136    /// `Any::unpack_if`.
137    ///
138    /// Format: `type.googleapis.com/<fully.qualified.TypeName>`
139    pub const TYPE_URL: &'static str = "type.googleapis.com/google.protobuf.Timestamp";
140}
141unsafe impl ::buffa::DefaultInstance for Timestamp {
142    fn default_instance() -> &'static Self {
143        static VALUE: ::buffa::__private::OnceBox<Timestamp> = ::buffa::__private::OnceBox::new();
144        VALUE.get_or_init(|| ::buffa::alloc::boxed::Box::new(Self::default()))
145    }
146}
147impl ::buffa::Message for Timestamp {
148    /// Returns the total encoded size in bytes.
149    ///
150    /// The result is a `u32`; the protobuf specification requires all
151    /// messages to fit within 2 GiB (2,147,483,647 bytes), so a
152    /// compliant message will never overflow this type.
153    fn compute_size(&self) -> u32 {
154        #[allow(unused_imports)]
155        use ::buffa::Enumeration as _;
156        let mut size = 0u32;
157        if self.seconds != 0i64 {
158            size += 1u32 + ::buffa::types::int64_encoded_len(self.seconds) as u32;
159        }
160        if self.nanos != 0i32 {
161            size += 1u32 + ::buffa::types::int32_encoded_len(self.nanos) as u32;
162        }
163        size += self.__buffa_unknown_fields.encoded_len() as u32;
164        self.__buffa_cached_size.set(size);
165        size
166    }
167    fn write_to(&self, buf: &mut impl ::buffa::bytes::BufMut) {
168        #[allow(unused_imports)]
169        use ::buffa::Enumeration as _;
170        if self.seconds != 0i64 {
171            ::buffa::encoding::Tag::new(1u32, ::buffa::encoding::WireType::Varint)
172                .encode(buf);
173            ::buffa::types::encode_int64(self.seconds, buf);
174        }
175        if self.nanos != 0i32 {
176            ::buffa::encoding::Tag::new(2u32, ::buffa::encoding::WireType::Varint)
177                .encode(buf);
178            ::buffa::types::encode_int32(self.nanos, buf);
179        }
180        self.__buffa_unknown_fields.write_to(buf);
181    }
182    fn merge_field(
183        &mut self,
184        tag: ::buffa::encoding::Tag,
185        buf: &mut impl ::buffa::bytes::Buf,
186        depth: u32,
187    ) -> ::core::result::Result<(), ::buffa::DecodeError> {
188        #[allow(unused_imports)]
189        use ::buffa::bytes::Buf as _;
190        #[allow(unused_imports)]
191        use ::buffa::Enumeration as _;
192        match tag.field_number() {
193            1u32 => {
194                if tag.wire_type() != ::buffa::encoding::WireType::Varint {
195                    return ::core::result::Result::Err(::buffa::DecodeError::WireTypeMismatch {
196                        field_number: 1u32,
197                        expected: 0u8,
198                        actual: tag.wire_type() as u8,
199                    });
200                }
201                self.seconds = ::buffa::types::decode_int64(buf)?;
202            }
203            2u32 => {
204                if tag.wire_type() != ::buffa::encoding::WireType::Varint {
205                    return ::core::result::Result::Err(::buffa::DecodeError::WireTypeMismatch {
206                        field_number: 2u32,
207                        expected: 0u8,
208                        actual: tag.wire_type() as u8,
209                    });
210                }
211                self.nanos = ::buffa::types::decode_int32(buf)?;
212            }
213            _ => {
214                self.__buffa_unknown_fields
215                    .push(::buffa::encoding::decode_unknown_field(tag, buf, depth)?);
216            }
217        }
218        ::core::result::Result::Ok(())
219    }
220    fn cached_size(&self) -> u32 {
221        self.__buffa_cached_size.get()
222    }
223    fn clear(&mut self) {
224        self.seconds = 0i64;
225        self.nanos = 0i32;
226        self.__buffa_unknown_fields.clear();
227        self.__buffa_cached_size.set(0);
228    }
229}
230impl ::buffa::ExtensionSet for Timestamp {
231    const PROTO_FQN: &'static str = "google.protobuf.Timestamp";
232    fn unknown_fields(&self) -> &::buffa::UnknownFields {
233        &self.__buffa_unknown_fields
234    }
235    fn unknown_fields_mut(&mut self) -> &mut ::buffa::UnknownFields {
236        &mut self.__buffa_unknown_fields
237    }
238}
239impl ::buffa::text::TextFormat for Timestamp {
240    fn encode_text(
241        &self,
242        enc: &mut ::buffa::text::TextEncoder<'_>,
243    ) -> ::core::fmt::Result {
244        #[allow(unused_imports)]
245        use ::buffa::Enumeration as _;
246        if self.seconds != 0i64 {
247            enc.write_field_name("seconds")?;
248            enc.write_i64(self.seconds)?;
249        }
250        if self.nanos != 0i32 {
251            enc.write_field_name("nanos")?;
252            enc.write_i32(self.nanos)?;
253        }
254        enc.write_unknown_fields(&self.__buffa_unknown_fields)?;
255        ::core::result::Result::Ok(())
256    }
257    fn merge_text(
258        &mut self,
259        dec: &mut ::buffa::text::TextDecoder<'_>,
260    ) -> ::core::result::Result<(), ::buffa::text::ParseError> {
261        #[allow(unused_imports)]
262        use ::buffa::Enumeration as _;
263        while let ::core::option::Option::Some(__name) = dec.read_field_name()? {
264            match __name {
265                "seconds" => self.seconds = dec.read_i64()?,
266                "nanos" => self.nanos = dec.read_i32()?,
267                _ => dec.skip_value()?,
268            }
269        }
270        ::core::result::Result::Ok(())
271    }
272}
273#[doc(hidden)]
274pub const __TIMESTAMP_TEXT_ANY: ::buffa::type_registry::TextAnyEntry = ::buffa::type_registry::TextAnyEntry {
275    type_url: "type.googleapis.com/google.protobuf.Timestamp",
276    text_encode: ::buffa::type_registry::any_encode_text::<Timestamp>,
277    text_merge: ::buffa::type_registry::any_merge_text::<Timestamp>,
278};
279/// A Timestamp represents a point in time independent of any time zone or local
280/// calendar, encoded as a count of seconds and fractions of seconds at
281/// nanosecond resolution. The count is relative to an epoch at UTC midnight on
282/// January 1, 1970, in the proleptic Gregorian calendar which extends the
283/// Gregorian calendar backwards to year one.
284///
285/// All minutes are 60 seconds long. Leap seconds are "smeared" so that no leap
286/// second table is needed for interpretation, using a \[24-hour linear
287/// smear\](<https://developers.google.com/time/smear>).
288///
289/// The range is from 0001-01-01T00:00:00Z to 9999-12-31T23:59:59.999999999Z. By
290/// restricting to that range, we ensure that we can convert to and from \[RFC
291/// 3339\](<https://www.ietf.org/rfc/rfc3339.txt>) date strings.
292///
293/// # Examples
294///
295/// Example 1: Compute Timestamp from POSIX `time()`.
296///
297/// ```text
298/// Timestamp timestamp;
299/// timestamp.set_seconds(time(NULL));
300/// timestamp.set_nanos(0);
301/// ```
302///
303/// Example 2: Compute Timestamp from POSIX `gettimeofday()`.
304///
305/// ```text
306/// struct timeval tv;
307/// gettimeofday(&tv, NULL);
308///
309/// Timestamp timestamp;
310/// timestamp.set_seconds(tv.tv_sec);
311/// timestamp.set_nanos(tv.tv_usec * 1000);
312/// ```
313///
314/// Example 3: Compute Timestamp from Win32 `GetSystemTimeAsFileTime()`.
315///
316/// ```text
317/// FILETIME ft;
318/// GetSystemTimeAsFileTime(&ft);
319/// UINT64 ticks = (((UINT64)ft.dwHighDateTime) << 32) | ft.dwLowDateTime;
320///
321/// // A Windows tick is 100 nanoseconds. Windows epoch 1601-01-01T00:00:00Z
322/// // is 11644473600 seconds before Unix epoch 1970-01-01T00:00:00Z.
323/// Timestamp timestamp;
324/// timestamp.set_seconds((INT64) ((ticks / 10000000) - 11644473600LL));
325/// timestamp.set_nanos((INT32) ((ticks % 10000000) * 100));
326/// ```
327///
328/// Example 4: Compute Timestamp from Java `System.currentTimeMillis()`.
329///
330/// ```text
331/// long millis = System.currentTimeMillis();
332///
333/// Timestamp timestamp = Timestamp.newBuilder().setSeconds(millis / 1000)
334///     .setNanos((int) ((millis % 1000) * 1000000)).build();
335/// ```
336///
337/// Example 5: Compute Timestamp from Java `Instant.now()`.
338///
339/// ```text
340/// Instant now = Instant.now();
341///
342/// Timestamp timestamp =
343///     Timestamp.newBuilder().setSeconds(now.getEpochSecond())
344///         .setNanos(now.getNano()).build();
345/// ```
346///
347/// Example 6: Compute Timestamp from current time in Python.
348///
349/// ```text
350/// timestamp = Timestamp()
351/// timestamp.GetCurrentTime()
352/// ```
353///
354/// # JSON Mapping
355///
356/// In JSON format, the Timestamp type is encoded as a string in the
357/// [RFC 3339](https://www.ietf.org/rfc/rfc3339.txt) format. That is, the
358/// format is "{year}-{month}-{day}T{hour}:{min}:{sec}\[.{frac_sec}\]Z"
359/// where {year} is always expressed using four digits while {month}, {day},
360/// {hour}, {min}, and {sec} are zero-padded to two digits each. The fractional
361/// seconds, which can go up to 9 digits (i.e. up to 1 nanosecond resolution),
362/// are optional. The "Z" suffix indicates the timezone ("UTC"); the timezone
363/// is required. A proto3 JSON serializer should always use UTC (as indicated by
364/// "Z") when printing the Timestamp type and a proto3 JSON parser should be
365/// able to accept both UTC and other timezones (as indicated by an offset).
366///
367/// For example, "2017-01-15T01:30:15.01Z" encodes 15.01 seconds past
368/// 01:30 UTC on January 15, 2017.
369///
370/// In JavaScript, one can convert a Date object to this format using the
371/// standard
372/// [toISOString()](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/toISOString)
373/// method. In Python, a standard `datetime.datetime` object can be converted
374/// to this format using
375/// [`strftime`](https://docs.python.org/2/library/time.html#time.strftime) with
376/// the time format spec '%Y-%m-%dT%H:%M:%S.%fZ'. Likewise, in Java, one can use
377/// the Joda Time's \[`ISODateTimeFormat.dateTime()`\](
378/// <http://joda-time.sourceforge.net/apidocs/org/joda/time/format/ISODateTimeFormat.html#dateTime(>)
379/// ) to obtain a formatter capable of generating timestamps in this format.
380#[derive(Clone, Debug, Default)]
381pub struct TimestampView<'a> {
382    /// Represents seconds of UTC time since Unix epoch
383    /// 1970-01-01T00:00:00Z. Must be from 0001-01-01T00:00:00Z to
384    /// 9999-12-31T23:59:59Z inclusive.
385    ///
386    /// Field 1: `seconds`
387    pub seconds: i64,
388    /// Non-negative fractions of a second at nanosecond resolution. Negative
389    /// second values with fractions must still have non-negative nanos values
390    /// that count forward in time. Must be from 0 to 999,999,999
391    /// inclusive.
392    ///
393    /// Field 2: `nanos`
394    pub nanos: i32,
395    pub __buffa_unknown_fields: ::buffa::UnknownFieldsView<'a>,
396}
397impl<'a> TimestampView<'a> {
398    /// Decode from `buf`, enforcing a recursion depth limit for nested messages.
399    ///
400    /// Called by [`::buffa::MessageView::decode_view`] with [`::buffa::RECURSION_LIMIT`]
401    /// and by generated sub-message decode arms with `depth - 1`.
402    ///
403    /// **Not part of the public API.** Named with a leading underscore to
404    /// signal that it is for generated-code use only.
405    #[doc(hidden)]
406    pub fn _decode_depth(
407        buf: &'a [u8],
408        depth: u32,
409    ) -> ::core::result::Result<Self, ::buffa::DecodeError> {
410        let mut view = Self::default();
411        view._merge_into_view(buf, depth)?;
412        ::core::result::Result::Ok(view)
413    }
414    /// Merge fields from `buf` into this view (proto merge semantics).
415    ///
416    /// Repeated fields append; singular fields last-wins; singular
417    /// MESSAGE fields merge recursively. Used by sub-message decode
418    /// arms when the same field appears multiple times on the wire.
419    ///
420    /// **Not part of the public API.**
421    #[doc(hidden)]
422    pub fn _merge_into_view(
423        &mut self,
424        buf: &'a [u8],
425        depth: u32,
426    ) -> ::core::result::Result<(), ::buffa::DecodeError> {
427        let _ = depth;
428        #[allow(unused_variables)]
429        let view = self;
430        let mut cur: &'a [u8] = buf;
431        while !cur.is_empty() {
432            let before_tag = cur;
433            let tag = ::buffa::encoding::Tag::decode(&mut cur)?;
434            match tag.field_number() {
435                1u32 => {
436                    if tag.wire_type() != ::buffa::encoding::WireType::Varint {
437                        return ::core::result::Result::Err(::buffa::DecodeError::WireTypeMismatch {
438                            field_number: 1u32,
439                            expected: 0u8,
440                            actual: tag.wire_type() as u8,
441                        });
442                    }
443                    view.seconds = ::buffa::types::decode_int64(&mut cur)?;
444                }
445                2u32 => {
446                    if tag.wire_type() != ::buffa::encoding::WireType::Varint {
447                        return ::core::result::Result::Err(::buffa::DecodeError::WireTypeMismatch {
448                            field_number: 2u32,
449                            expected: 0u8,
450                            actual: tag.wire_type() as u8,
451                        });
452                    }
453                    view.nanos = ::buffa::types::decode_int32(&mut cur)?;
454                }
455                _ => {
456                    ::buffa::encoding::skip_field_depth(tag, &mut cur, depth)?;
457                    let span_len = before_tag.len() - cur.len();
458                    view.__buffa_unknown_fields.push_raw(&before_tag[..span_len]);
459                }
460            }
461        }
462        ::core::result::Result::Ok(())
463    }
464}
465impl<'a> ::buffa::MessageView<'a> for TimestampView<'a> {
466    type Owned = Timestamp;
467    fn decode_view(buf: &'a [u8]) -> ::core::result::Result<Self, ::buffa::DecodeError> {
468        Self::_decode_depth(buf, ::buffa::RECURSION_LIMIT)
469    }
470    fn decode_view_with_limit(
471        buf: &'a [u8],
472        depth: u32,
473    ) -> ::core::result::Result<Self, ::buffa::DecodeError> {
474        Self::_decode_depth(buf, depth)
475    }
476    /// Convert this view to the owned message type.
477    #[allow(clippy::redundant_closure, clippy::useless_conversion)]
478    fn to_owned_message(&self) -> Timestamp {
479        #[allow(unused_imports)]
480        use ::buffa::alloc::string::ToString as _;
481        Timestamp {
482            seconds: self.seconds,
483            nanos: self.nanos,
484            __buffa_unknown_fields: self
485                .__buffa_unknown_fields
486                .to_owned()
487                .unwrap_or_default()
488                .into(),
489            ..::core::default::Default::default()
490        }
491    }
492}
493unsafe impl ::buffa::DefaultViewInstance for TimestampView<'static> {
494    fn default_view_instance() -> &'static Self {
495        static VALUE: ::buffa::__private::OnceBox<TimestampView<'static>> = ::buffa::__private::OnceBox::new();
496        VALUE.get_or_init(|| ::buffa::alloc::boxed::Box::new(Self::default()))
497    }
498}
499unsafe impl<'a> ::buffa::HasDefaultViewInstance for TimestampView<'a> {
500    type Static = TimestampView<'static>;
501}