buffa_types/generated/google.protobuf.timestamp.__view.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, Debug, Default)]
106pub struct TimestampView<'a> {
107 /// Represents seconds of UTC time since Unix epoch
108 /// 1970-01-01T00:00:00Z. Must be from 0001-01-01T00:00:00Z to
109 /// 9999-12-31T23:59:59Z inclusive.
110 ///
111 /// Field 1: `seconds`
112 pub seconds: i64,
113 /// Non-negative fractions of a second at nanosecond resolution. Negative
114 /// second values with fractions must still have non-negative nanos values
115 /// that count forward in time. Must be from 0 to 999,999,999
116 /// inclusive.
117 ///
118 /// Field 2: `nanos`
119 pub nanos: i32,
120 pub __buffa_unknown_fields: ::buffa::UnknownFieldsView<'a>,
121}
122impl<'a> ::buffa::MessageView<'a> for TimestampView<'a> {
123 type Owned = super::super::Timestamp;
124 fn decode_view(buf: &'a [u8]) -> ::core::result::Result<Self, ::buffa::DecodeError> {
125 let __limit = ::core::cell::Cell::new(::buffa::DEFAULT_UNKNOWN_FIELD_LIMIT);
126 <Self as ::buffa::MessageView>::decode_view_ctx(
127 buf,
128 ::buffa::DecodeContext::new(::buffa::RECURSION_LIMIT, &__limit),
129 )
130 }
131 fn decode_view_with_ctx(
132 buf: &'a [u8],
133 ctx: ::buffa::DecodeContext<'_>,
134 ) -> ::core::result::Result<Self, ::buffa::DecodeError> {
135 <Self as ::buffa::MessageView>::decode_view_ctx(buf, ctx)
136 }
137 #[inline]
138 fn merge_view_field(
139 &mut self,
140 tag: ::buffa::encoding::Tag,
141 cur: &'a [u8],
142 before_tag: &'a [u8],
143 ctx: ::buffa::DecodeContext<'_>,
144 ) -> ::core::result::Result<&'a [u8], ::buffa::DecodeError> {
145 let _ = ctx;
146 #[allow(unused_variables)]
147 let view = self;
148 let mut cur = cur;
149 match tag.field_number() {
150 1u32 => {
151 ::buffa::encoding::check_wire_type(
152 tag,
153 ::buffa::encoding::WireType::Varint,
154 )?;
155 view.seconds = ::buffa::types::decode_int64(&mut cur)?;
156 }
157 2u32 => {
158 ::buffa::encoding::check_wire_type(
159 tag,
160 ::buffa::encoding::WireType::Varint,
161 )?;
162 view.nanos = ::buffa::types::decode_int32(&mut cur)?;
163 }
164 _ => {
165 ::buffa::encoding::skip_field_depth(tag, &mut cur, ctx.depth())?;
166 let span_len = before_tag.len() - cur.len();
167 view.__buffa_unknown_fields.push_record(before_tag, span_len, ctx)?;
168 }
169 }
170 ::core::result::Result::Ok(cur)
171 }
172 fn to_owned_message(
173 &self,
174 ) -> ::core::result::Result<super::super::Timestamp, ::buffa::DecodeError> {
175 self.to_owned_from_source(None)
176 }
177 #[allow(clippy::useless_conversion, clippy::needless_update)]
178 fn to_owned_from_source(
179 &self,
180 __buffa_src: ::core::option::Option<&::buffa::bytes::Bytes>,
181 ) -> ::core::result::Result<super::super::Timestamp, ::buffa::DecodeError> {
182 #[allow(unused_imports)]
183 use ::buffa::alloc::string::ToString as _;
184 let _ = __buffa_src;
185 ::core::result::Result::Ok(super::super::Timestamp {
186 seconds: self.seconds,
187 nanos: self.nanos,
188 __buffa_unknown_fields: self.__buffa_unknown_fields.to_owned()?.into(),
189 ..::core::default::Default::default()
190 })
191 }
192}
193impl<'a> ::buffa::ViewEncode<'a> for TimestampView<'a> {
194 #[allow(clippy::needless_borrow, clippy::let_and_return)]
195 fn compute_size(&self, _cache: &mut ::buffa::SizeCache) -> u32 {
196 #[allow(unused_imports)]
197 use ::buffa::Enumeration as _;
198 let mut size = 0u64;
199 if self.seconds != 0i64 {
200 size += 1u64 + ::buffa::types::int64_encoded_len(self.seconds) as u64;
201 }
202 if self.nanos != 0i32 {
203 size += 1u64 + ::buffa::types::int32_encoded_len(self.nanos) as u64;
204 }
205 size += self.__buffa_unknown_fields.encoded_len() as u64;
206 ::buffa::saturate_size(size)
207 }
208 #[allow(clippy::needless_borrow)]
209 fn write_to(
210 &self,
211 _cache: &mut ::buffa::SizeCache,
212 buf: &mut impl ::buffa::EncodeSink,
213 ) {
214 #[allow(unused_imports)]
215 use ::buffa::Enumeration as _;
216 if self.seconds != 0i64 {
217 ::buffa::types::put_int64_field(1u32, self.seconds, buf);
218 }
219 if self.nanos != 0i32 {
220 ::buffa::types::put_int32_field(2u32, self.nanos, buf);
221 }
222 self.__buffa_unknown_fields.write_to(buf);
223 }
224}
225impl<'a> ::buffa::MessageName for TimestampView<'a> {
226 const PACKAGE: &'static str = "google.protobuf";
227 const NAME: &'static str = "Timestamp";
228 const FULL_NAME: &'static str = "google.protobuf.Timestamp";
229 const TYPE_URL: &'static str = "type.googleapis.com/google.protobuf.Timestamp";
230}
231::buffa::impl_default_view_instance!(TimestampView);
232::buffa::impl_view_reborrow!(TimestampView);
233/** Self-contained, `'static` owned view of a `Timestamp` message.
234
235 Wraps [`::buffa::OwnedView`]`<`[`TimestampView`]`<'static>>`: the decoded view and the [`::buffa::bytes::Bytes`] buffer it borrows from travel together, so the handle is `'static` and `Send + Sync` — suitable for async handlers, spawned tasks, and anywhere a `'static` bound is required.
236
237 Field accessors return borrows tied to `&self`. Use [`Self::view`] to get the full [`TimestampView`] when you need struct patterns, iteration helpers, or to pass the view to lifetime-parameterised code.*/
238#[derive(Clone, Debug)]
239pub struct TimestampOwnedView(::buffa::OwnedView<TimestampView<'static>>);
240impl TimestampOwnedView {
241 /// Decode an owned view from a [`::buffa::bytes::Bytes`] buffer.
242 ///
243 /// The view borrows directly from the buffer's data; the buffer is
244 /// retained inside the returned handle.
245 ///
246 /// # Errors
247 ///
248 /// Returns [`::buffa::DecodeError`] if the buffer contains invalid
249 /// protobuf data.
250 pub fn decode(
251 bytes: ::buffa::bytes::Bytes,
252 ) -> ::core::result::Result<Self, ::buffa::DecodeError> {
253 ::core::result::Result::Ok(
254 TimestampOwnedView(::buffa::OwnedView::decode(bytes)?),
255 )
256 }
257 /// Decode with custom [`::buffa::DecodeOptions`] (recursion limit,
258 /// max message size).
259 ///
260 /// # Errors
261 ///
262 /// Returns [`::buffa::DecodeError`] if the buffer is invalid or
263 /// exceeds the configured limits.
264 pub fn decode_with_options(
265 bytes: ::buffa::bytes::Bytes,
266 opts: &::buffa::DecodeOptions,
267 ) -> ::core::result::Result<Self, ::buffa::DecodeError> {
268 ::core::result::Result::Ok(
269 TimestampOwnedView(::buffa::OwnedView::decode_with_options(bytes, opts)?),
270 )
271 }
272 /// Build from an owned message via an encode → decode round-trip.
273 ///
274 /// # Errors
275 ///
276 /// Returns [`::buffa::DecodeError::MessageTooLarge`] if the
277 /// message's encoded size exceeds the 2 GiB protobuf limit, or
278 /// another [`::buffa::DecodeError`] if the re-encoded bytes are
279 /// somehow invalid (should not happen for well-formed messages).
280 pub fn from_owned(
281 msg: &super::super::Timestamp,
282 ) -> ::core::result::Result<Self, ::buffa::DecodeError> {
283 ::core::result::Result::Ok(
284 TimestampOwnedView(::buffa::OwnedView::from_owned(msg)?),
285 )
286 }
287 /// Borrow the full [`TimestampView`] with its lifetime tied to `&self`.
288 #[must_use]
289 pub fn view(&self) -> &TimestampView<'_> {
290 self.0.reborrow()
291 }
292 /// Convert to the owned message type.
293 ///
294 /// Infallible: this type's constructors wire-decode their
295 /// buffer, and a view produced by wire decoding always
296 /// converts. Delegates to [`::buffa::OwnedView::to_owned_message`],
297 /// whose contract also governs handles converted from a raw
298 /// [`::buffa::OwnedView`].
299 #[must_use]
300 pub fn to_owned_message(&self) -> super::super::Timestamp {
301 self.0.to_owned_message()
302 }
303 /// The underlying bytes buffer.
304 #[must_use]
305 pub fn bytes(&self) -> &::buffa::bytes::Bytes {
306 self.0.bytes()
307 }
308 /// Consume the handle, returning the underlying bytes buffer.
309 #[must_use]
310 pub fn into_bytes(self) -> ::buffa::bytes::Bytes {
311 self.0.into_bytes()
312 }
313 /// Represents seconds of UTC time since Unix epoch
314 /// 1970-01-01T00:00:00Z. Must be from 0001-01-01T00:00:00Z to
315 /// 9999-12-31T23:59:59Z inclusive.
316 ///
317 /// Field 1: `seconds`
318 #[must_use]
319 pub fn seconds(&self) -> i64 {
320 self.0.reborrow().seconds
321 }
322 /// Non-negative fractions of a second at nanosecond resolution. Negative
323 /// second values with fractions must still have non-negative nanos values
324 /// that count forward in time. Must be from 0 to 999,999,999
325 /// inclusive.
326 ///
327 /// Field 2: `nanos`
328 #[must_use]
329 pub fn nanos(&self) -> i32 {
330 self.0.reborrow().nanos
331 }
332}
333impl ::core::convert::From<::buffa::OwnedView<TimestampView<'static>>>
334for TimestampOwnedView {
335 fn from(inner: ::buffa::OwnedView<TimestampView<'static>>) -> Self {
336 TimestampOwnedView(inner)
337 }
338}
339impl ::core::convert::From<TimestampOwnedView>
340for ::buffa::OwnedView<TimestampView<'static>> {
341 fn from(wrapper: TimestampOwnedView) -> Self {
342 wrapper.0
343 }
344}
345impl ::core::convert::AsRef<::buffa::OwnedView<TimestampView<'static>>>
346for TimestampOwnedView {
347 fn as_ref(&self) -> &::buffa::OwnedView<TimestampView<'static>> {
348 &self.0
349 }
350}
351impl ::buffa::HasMessageView for super::super::Timestamp {
352 type View<'a> = TimestampView<'a>;
353 type ViewHandle = TimestampOwnedView;
354}
355#[cfg(feature = "reflect")]
356const _: () = {
357 impl<'a> ::buffa_descriptor::reflect::ReflectMessage for TimestampView<'a> {
358 fn message_descriptor(&self) -> &::buffa_descriptor::MessageDescriptor {
359 super::super::__buffa::reflect::descriptor_pool()
360 .message(Self::__buffa_reflect_message_index())
361 }
362 fn pool(
363 &self,
364 ) -> &::buffa::alloc::sync::Arc<::buffa_descriptor::DescriptorPool> {
365 super::super::__buffa::reflect::descriptor_pool()
366 }
367 fn get(
368 &self,
369 field: &::buffa_descriptor::FieldDescriptor,
370 ) -> ::buffa_descriptor::reflect::ValueRef<'_> {
371 #[allow(unused_imports)]
372 use ::buffa::Enumeration as _;
373 match field.number() {
374 1u32 => ::buffa_descriptor::reflect::ValueRef::I64(self.seconds),
375 2u32 => ::buffa_descriptor::reflect::ValueRef::I32(self.nanos),
376 _ => {
377 ::core::debug_assert!(
378 false,
379 "field number {} is not a member of this view's reflect get()",
380 field.number(),
381 );
382 ::buffa_descriptor::reflect::ValueRef::Bool(false)
383 }
384 }
385 }
386 fn has(&self, field: &::buffa_descriptor::FieldDescriptor) -> bool {
387 match field.number() {
388 1u32 => self.seconds != 0,
389 2u32 => self.nanos != 0,
390 _ => false,
391 }
392 }
393 fn for_each_set(
394 &self,
395 f: &mut dyn ::core::ops::FnMut(
396 &::buffa_descriptor::FieldDescriptor,
397 ::buffa_descriptor::reflect::ValueRef<'_>,
398 ),
399 ) {
400 let md = ::buffa_descriptor::reflect::ReflectMessage::message_descriptor(
401 self,
402 );
403 for fd in md.fields() {
404 if ::buffa_descriptor::reflect::ReflectMessage::has(self, fd) {
405 f(fd, ::buffa_descriptor::reflect::ReflectMessage::get(self, fd));
406 }
407 }
408 }
409 fn to_dynamic(&self) -> ::buffa_descriptor::reflect::DynamicMessage {
410 let bytes = ::buffa::ViewEncode::encode_to_vec(self);
411 ::buffa_descriptor::reflect::DynamicMessage::decode(
412 ::buffa::alloc::sync::Arc::clone(
413 super::super::__buffa::reflect::descriptor_pool(),
414 ),
415 Self::__buffa_reflect_message_index(),
416 &bytes,
417 )
418 .expect("view re-encodes to bytes decodable against its own descriptor")
419 }
420 }
421 impl<'a> ::buffa_descriptor::reflect::ReflectElement for TimestampView<'a> {
422 fn as_value_ref(&self) -> ::buffa_descriptor::reflect::ValueRef<'_> {
423 ::buffa_descriptor::reflect::ValueRef::Message(
424 ::buffa_descriptor::reflect::ReflectCow::Borrowed(self),
425 )
426 }
427 }
428 impl<'a> TimestampView<'a> {
429 /// Memoized `MessageIndex` for this view's message type, resolved
430 /// once against the package's embedded descriptor pool. An inherent
431 /// associated fn (not a free fn) so sibling views in the same module
432 /// do not collide.
433 #[doc(hidden)]
434 fn __buffa_reflect_message_index() -> ::buffa_descriptor::MessageIndex {
435 static IDX: ::std::sync::OnceLock<::buffa_descriptor::MessageIndex> = ::std::sync::OnceLock::new();
436 *IDX
437 .get_or_init(|| {
438 super::super::__buffa::reflect::descriptor_pool()
439 .message_index(<Self as ::buffa::MessageName>::FULL_NAME)
440 .expect(
441 "generated view type is registered in the embedded descriptor pool",
442 )
443 })
444 }
445 }
446};