ntex_grpc/google_types/timestamp.rs
1#![allow(
2 dead_code,
3 unused_mut,
4 unused_variables,
5 clippy::identity_op,
6 clippy::too_many_lines,
7 clippy::derivable_impls,
8 clippy::unit_arg,
9 clippy::derive_partial_eq_without_eq,
10 clippy::manual_range_patterns,
11 clippy::default_trait_access,
12 clippy::semicolon_if_nothing_returned,
13 clippy::doc_markdown,
14 clippy::wildcard_imports
15)]
16//! DO NOT MODIFY. Auto-generated file
17
18/// A Timestamp represents a point in time independent of any time zone or local
19/// calendar, encoded as a count of seconds and fractions of seconds at
20/// nanosecond resolution. The count is relative to an epoch at UTC midnight on
21/// January 1, 1970, in the proleptic Gregorian calendar which extends the
22/// Gregorian calendar backwards to year one.
23///
24/// All minutes are 60 seconds long. Leap seconds are "smeared" so that no leap
25/// second table is needed for interpretation, using a [24-hour linear
26/// smear](<https://developers.google.com/time/smear>).
27///
28/// The range is from 0001-01-01T00:00:00Z to 9999-12-31T23:59:59.999999999Z. By
29/// restricting to that range, we ensure that we can convert to and from [RFC
30/// 3339](<https://www.ietf.org/rfc/rfc3339.txt>) date strings.
31///
32/// # Examples
33///
34/// Example 1: Compute Timestamp from POSIX `time()`.
35///
36/// Timestamp timestamp;
37/// timestamp.set_seconds(time(NULL));
38/// timestamp.set_nanos(0);
39///
40/// Example 2: Compute Timestamp from POSIX `gettimeofday()`.
41///
42/// struct timeval tv;
43/// gettimeofday(&tv, NULL);
44///
45/// Timestamp timestamp;
46/// timestamp.set_seconds(tv.tv_sec);
47/// timestamp.set_nanos(tv.tv_usec * 1000);
48///
49/// Example 3: Compute Timestamp from Win32 `GetSystemTimeAsFileTime()`.
50///
51/// FILETIME ft;
52/// GetSystemTimeAsFileTime(&ft);
53/// UINT64 ticks = (((UINT64)ft.dwHighDateTime) << 32) | ft.dwLowDateTime;
54///
55/// // A Windows tick is 100 nanoseconds. Windows epoch 1601-01-01T00:00:00Z
56/// // is 11644473600 seconds before Unix epoch 1970-01-01T00:00:00Z.
57/// Timestamp timestamp;
58/// timestamp.set_seconds((INT64) ((ticks / 10000000) - 11644473600LL));
59/// timestamp.set_nanos((INT32) ((ticks % 10000000) * 100));
60///
61/// Example 4: Compute Timestamp from Java `System.currentTimeMillis()`.
62///
63/// long millis = System.currentTimeMillis();
64///
65/// Timestamp timestamp = Timestamp.newBuilder().setSeconds(millis / 1000)
66/// .setNanos((int) ((millis % 1000) * 1000000)).build();
67///
68///
69/// Example 5: Compute Timestamp from Java `Instant.now()`.
70///
71/// Instant now = Instant.now();
72///
73/// Timestamp timestamp =
74/// Timestamp.newBuilder().setSeconds(now.getEpochSecond())
75/// .setNanos(now.getNano()).build();
76///
77///
78/// Example 6: Compute Timestamp from current time in Python.
79///
80/// timestamp = Timestamp()
81/// timestamp.GetCurrentTime()
82///
83/// # JSON Mapping
84///
85/// In JSON format, the Timestamp type is encoded as a string in the
86/// [RFC 3339](<https://www.ietf.org/rfc/rfc3339.txt>) format. That is, the
87/// format is "{year}-{month}-{day}T{hour}:{min}:{sec}\[.{frac_sec}\]Z"
88/// where {year} is always expressed using four digits while {month}, {day},
89/// {hour}, {min}, and {sec} are zero-padded to two digits each. The fractional
90/// seconds, which can go up to 9 digits (i.e. up to 1 nanosecond resolution),
91/// are optional. The "Z" suffix indicates the timezone ("UTC"); the timezone
92/// is required. A proto3 JSON serializer should always use UTC (as indicated by
93/// "Z") when printing the Timestamp type and a proto3 JSON parser should be
94/// able to accept both UTC and other timezones (as indicated by an offset).
95///
96/// For example, "2017-01-15T01:30:15.01Z" encodes 15.01 seconds past
97/// 01:30 UTC on January 15, 2017.
98///
99/// In JavaScript, one can convert a Date object to this format using the
100/// standard
101/// \[toISOString()\](<https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/toISOString>)
102/// method. In Python, a standard `datetime.datetime` object can be converted
103/// to this format using
104/// \[`strftime`\](<https://docs.python.org/2/library/time.html#time.strftime>) with
105/// the time format spec '%Y-%m-%dT%H:%M:%S.%fZ'. Likewise, in Java, one can use
106/// the Joda Time's \[`ISODateTimeFormat.dateTime()`\](
107/// <http://www.joda.org/joda-time/apidocs/org/joda/time/format/ISODateTimeFormat.html#dateTime%2D%2D>
108/// ) to obtain a formatter capable of generating timestamps in this format.
109///
110///
111#[derive(Clone, PartialEq, Debug)]
112pub struct Timestamp {
113 /// Represents seconds of UTC time since Unix epoch
114 /// 1970-01-01T00:00:00Z. Must be from 0001-01-01T00:00:00Z to
115 /// 9999-12-31T23:59:59Z inclusive.
116 pub seconds: i64,
117 /// Non-negative fractions of a second at nanosecond resolution. Negative
118 /// second values with fractions must still have non-negative nanos values
119 /// that count forward in time. Must be from 0 to 999,999,999
120 /// inclusive.
121 pub nanos: i32,
122}
123
124mod _priv_impl_timestamp {
125 use super::*;
126
127 impl crate::Message for Timestamp {
128 #[inline]
129 fn write(&self, dst: &mut crate::BytePages) {
130 crate::NativeType::serialize(
131 &self.seconds,
132 1,
133 crate::types::DefaultValue::Default,
134 dst,
135 );
136 crate::NativeType::serialize(&self.nanos, 2, crate::types::DefaultValue::Default, dst);
137 }
138
139 #[inline]
140 fn read(src: &mut crate::Bytes) -> ::std::result::Result<Self, crate::DecodeError> {
141 const STRUCT_NAME: &str = "Timestamp";
142 let mut msg = Self::default();
143 while !src.is_empty() {
144 let (tag, wire_type) = crate::encoding::decode_key(src)?;
145 match tag {
146 1 => crate::NativeType::deserialize(&mut msg.seconds, tag, wire_type, src)
147 .map_err(|err| err.push(STRUCT_NAME, "seconds"))?,
148 2 => crate::NativeType::deserialize(&mut msg.nanos, tag, wire_type, src)
149 .map_err(|err| err.push(STRUCT_NAME, "nanos"))?,
150 _ => crate::encoding::skip_field(wire_type, tag, src)?,
151 }
152 }
153 Ok(msg)
154 }
155
156 #[inline]
157 fn encoded_len(&self) -> usize {
158 0 + crate::NativeType::serialized_len(
159 &self.seconds,
160 1,
161 crate::types::DefaultValue::Default,
162 ) + crate::NativeType::serialized_len(
163 &self.nanos,
164 2,
165 crate::types::DefaultValue::Default,
166 )
167 }
168 }
169
170 impl ::std::default::Default for Timestamp {
171 #[inline]
172 fn default() -> Self {
173 Self {
174 seconds: ::core::default::Default::default(),
175 nanos: ::core::default::Default::default(),
176 }
177 }
178 }
179}