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}
145impl ::buffa::Message for Timestamp {
146    /// Returns the total encoded size in bytes.
147    ///
148    /// The result is a `u32`; the protobuf specification requires all
149    /// messages to fit within 2 GiB (2,147,483,647 bytes), so a
150    /// compliant message will never overflow this type.
151    #[allow(clippy::let_and_return)]
152    fn compute_size(&self, _cache: &mut ::buffa::SizeCache) -> u32 {
153        #[allow(unused_imports)]
154        use ::buffa::Enumeration as _;
155        let mut size = 0u32;
156        if self.seconds != 0i64 {
157            size += 1u32 + ::buffa::types::int64_encoded_len(self.seconds) as u32;
158        }
159        if self.nanos != 0i32 {
160            size += 1u32 + ::buffa::types::int32_encoded_len(self.nanos) as u32;
161        }
162        size += self.__buffa_unknown_fields.encoded_len() as u32;
163        size
164    }
165    fn write_to(
166        &self,
167        _cache: &mut ::buffa::SizeCache,
168        buf: &mut impl ::buffa::bytes::BufMut,
169    ) {
170        #[allow(unused_imports)]
171        use ::buffa::Enumeration as _;
172        if self.seconds != 0i64 {
173            ::buffa::encoding::Tag::new(1u32, ::buffa::encoding::WireType::Varint)
174                .encode(buf);
175            ::buffa::types::encode_int64(self.seconds, buf);
176        }
177        if self.nanos != 0i32 {
178            ::buffa::encoding::Tag::new(2u32, ::buffa::encoding::WireType::Varint)
179                .encode(buf);
180            ::buffa::types::encode_int32(self.nanos, buf);
181        }
182        self.__buffa_unknown_fields.write_to(buf);
183    }
184    fn merge_field(
185        &mut self,
186        tag: ::buffa::encoding::Tag,
187        buf: &mut impl ::buffa::bytes::Buf,
188        depth: u32,
189    ) -> ::core::result::Result<(), ::buffa::DecodeError> {
190        #[allow(unused_imports)]
191        use ::buffa::bytes::Buf as _;
192        #[allow(unused_imports)]
193        use ::buffa::Enumeration as _;
194        match tag.field_number() {
195            1u32 => {
196                if tag.wire_type() != ::buffa::encoding::WireType::Varint {
197                    return ::core::result::Result::Err(::buffa::DecodeError::WireTypeMismatch {
198                        field_number: 1u32,
199                        expected: 0u8,
200                        actual: tag.wire_type() as u8,
201                    });
202                }
203                self.seconds = ::buffa::types::decode_int64(buf)?;
204            }
205            2u32 => {
206                if tag.wire_type() != ::buffa::encoding::WireType::Varint {
207                    return ::core::result::Result::Err(::buffa::DecodeError::WireTypeMismatch {
208                        field_number: 2u32,
209                        expected: 0u8,
210                        actual: tag.wire_type() as u8,
211                    });
212                }
213                self.nanos = ::buffa::types::decode_int32(buf)?;
214            }
215            _ => {
216                self.__buffa_unknown_fields
217                    .push(::buffa::encoding::decode_unknown_field(tag, buf, depth)?);
218            }
219        }
220        ::core::result::Result::Ok(())
221    }
222    fn clear(&mut self) {
223        self.seconds = 0i64;
224        self.nanos = 0i32;
225        self.__buffa_unknown_fields.clear();
226    }
227}
228impl ::buffa::ExtensionSet for Timestamp {
229    const PROTO_FQN: &'static str = "google.protobuf.Timestamp";
230    fn unknown_fields(&self) -> &::buffa::UnknownFields {
231        &self.__buffa_unknown_fields
232    }
233    fn unknown_fields_mut(&mut self) -> &mut ::buffa::UnknownFields {
234        &mut self.__buffa_unknown_fields
235    }
236}
237impl ::buffa::text::TextFormat for Timestamp {
238    fn encode_text(
239        &self,
240        enc: &mut ::buffa::text::TextEncoder<'_>,
241    ) -> ::core::fmt::Result {
242        #[allow(unused_imports)]
243        use ::buffa::Enumeration as _;
244        if self.seconds != 0i64 {
245            enc.write_field_name("seconds")?;
246            enc.write_i64(self.seconds)?;
247        }
248        if self.nanos != 0i32 {
249            enc.write_field_name("nanos")?;
250            enc.write_i32(self.nanos)?;
251        }
252        enc.write_unknown_fields(&self.__buffa_unknown_fields)?;
253        ::core::result::Result::Ok(())
254    }
255    fn merge_text(
256        &mut self,
257        dec: &mut ::buffa::text::TextDecoder<'_>,
258    ) -> ::core::result::Result<(), ::buffa::text::ParseError> {
259        #[allow(unused_imports)]
260        use ::buffa::Enumeration as _;
261        while let ::core::option::Option::Some(__name) = dec.read_field_name()? {
262            match __name {
263                "seconds" => self.seconds = dec.read_i64()?,
264                "nanos" => self.nanos = dec.read_i32()?,
265                _ => dec.skip_value()?,
266            }
267        }
268        ::core::result::Result::Ok(())
269    }
270}
271#[doc(hidden)]
272pub const __TIMESTAMP_TEXT_ANY: ::buffa::type_registry::TextAnyEntry = ::buffa::type_registry::TextAnyEntry {
273    type_url: "type.googleapis.com/google.protobuf.Timestamp",
274    text_encode: ::buffa::type_registry::any_encode_text::<Timestamp>,
275    text_merge: ::buffa::type_registry::any_merge_text::<Timestamp>,
276};