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> TimestampView<'a> {
123 /// Decode from `buf`, enforcing a recursion depth limit for nested messages.
124 ///
125 /// Called by [`::buffa::MessageView::decode_view`] with [`::buffa::RECURSION_LIMIT`]
126 /// and by generated sub-message decode arms with `depth - 1`.
127 ///
128 /// **Not part of the public API.** Named with a leading underscore to
129 /// signal that it is for generated-code use only.
130 #[doc(hidden)]
131 pub fn _decode_depth(
132 buf: &'a [u8],
133 depth: u32,
134 ) -> ::core::result::Result<Self, ::buffa::DecodeError> {
135 let mut view = Self::default();
136 view._merge_into_view(buf, depth)?;
137 ::core::result::Result::Ok(view)
138 }
139 /// Merge fields from `buf` into this view (proto merge semantics).
140 ///
141 /// Repeated fields append; singular fields last-wins; singular
142 /// MESSAGE fields merge recursively. Used by sub-message decode
143 /// arms when the same field appears multiple times on the wire.
144 ///
145 /// **Not part of the public API.**
146 #[doc(hidden)]
147 pub fn _merge_into_view(
148 &mut self,
149 buf: &'a [u8],
150 depth: u32,
151 ) -> ::core::result::Result<(), ::buffa::DecodeError> {
152 let _ = depth;
153 #[allow(unused_variables)]
154 let view = self;
155 let mut cur: &'a [u8] = buf;
156 while !cur.is_empty() {
157 let before_tag = cur;
158 let tag = ::buffa::encoding::Tag::decode(&mut cur)?;
159 match tag.field_number() {
160 1u32 => {
161 if tag.wire_type() != ::buffa::encoding::WireType::Varint {
162 return ::core::result::Result::Err(::buffa::DecodeError::WireTypeMismatch {
163 field_number: 1u32,
164 expected: 0u8,
165 actual: tag.wire_type() as u8,
166 });
167 }
168 view.seconds = ::buffa::types::decode_int64(&mut cur)?;
169 }
170 2u32 => {
171 if tag.wire_type() != ::buffa::encoding::WireType::Varint {
172 return ::core::result::Result::Err(::buffa::DecodeError::WireTypeMismatch {
173 field_number: 2u32,
174 expected: 0u8,
175 actual: tag.wire_type() as u8,
176 });
177 }
178 view.nanos = ::buffa::types::decode_int32(&mut cur)?;
179 }
180 _ => {
181 ::buffa::encoding::skip_field_depth(tag, &mut cur, depth)?;
182 let span_len = before_tag.len() - cur.len();
183 view.__buffa_unknown_fields.push_raw(&before_tag[..span_len]);
184 }
185 }
186 }
187 ::core::result::Result::Ok(())
188 }
189}
190impl<'a> ::buffa::MessageView<'a> for TimestampView<'a> {
191 type Owned = super::super::Timestamp;
192 fn decode_view(buf: &'a [u8]) -> ::core::result::Result<Self, ::buffa::DecodeError> {
193 Self::_decode_depth(buf, ::buffa::RECURSION_LIMIT)
194 }
195 fn decode_view_with_limit(
196 buf: &'a [u8],
197 depth: u32,
198 ) -> ::core::result::Result<Self, ::buffa::DecodeError> {
199 Self::_decode_depth(buf, depth)
200 }
201 fn to_owned_message(&self) -> super::super::Timestamp {
202 self.to_owned_from_source(None)
203 }
204 #[allow(clippy::useless_conversion, clippy::needless_update)]
205 fn to_owned_from_source(
206 &self,
207 __buffa_src: ::core::option::Option<&::buffa::bytes::Bytes>,
208 ) -> super::super::Timestamp {
209 #[allow(unused_imports)]
210 use ::buffa::alloc::string::ToString as _;
211 let _ = __buffa_src;
212 super::super::Timestamp {
213 seconds: self.seconds,
214 nanos: self.nanos,
215 __buffa_unknown_fields: self
216 .__buffa_unknown_fields
217 .to_owned()
218 .unwrap_or_default()
219 .into(),
220 ..::core::default::Default::default()
221 }
222 }
223}
224impl<'a> ::buffa::ViewEncode<'a> for TimestampView<'a> {
225 #[allow(clippy::needless_borrow, clippy::let_and_return)]
226 fn compute_size(&self, _cache: &mut ::buffa::SizeCache) -> u32 {
227 #[allow(unused_imports)]
228 use ::buffa::Enumeration as _;
229 let mut size = 0u32;
230 if self.seconds != 0i64 {
231 size += 1u32 + ::buffa::types::int64_encoded_len(self.seconds) as u32;
232 }
233 if self.nanos != 0i32 {
234 size += 1u32 + ::buffa::types::int32_encoded_len(self.nanos) as u32;
235 }
236 size += self.__buffa_unknown_fields.encoded_len() as u32;
237 size
238 }
239 #[allow(clippy::needless_borrow)]
240 fn write_to(
241 &self,
242 _cache: &mut ::buffa::SizeCache,
243 buf: &mut impl ::buffa::bytes::BufMut,
244 ) {
245 #[allow(unused_imports)]
246 use ::buffa::Enumeration as _;
247 if self.seconds != 0i64 {
248 ::buffa::encoding::Tag::new(1u32, ::buffa::encoding::WireType::Varint)
249 .encode(buf);
250 ::buffa::types::encode_int64(self.seconds, buf);
251 }
252 if self.nanos != 0i32 {
253 ::buffa::encoding::Tag::new(2u32, ::buffa::encoding::WireType::Varint)
254 .encode(buf);
255 ::buffa::types::encode_int32(self.nanos, buf);
256 }
257 self.__buffa_unknown_fields.write_to(buf);
258 }
259}
260impl<'a> ::buffa::MessageName for TimestampView<'a> {
261 const PACKAGE: &'static str = "google.protobuf";
262 const NAME: &'static str = "Timestamp";
263 const FULL_NAME: &'static str = "google.protobuf.Timestamp";
264 const TYPE_URL: &'static str = "type.googleapis.com/google.protobuf.Timestamp";
265}
266impl<'v> ::buffa::DefaultViewInstance for TimestampView<'v> {
267 fn default_view_instance<'a>() -> &'a Self
268 where
269 Self: 'a,
270 {
271 static VALUE: ::buffa::__private::OnceBox<TimestampView<'static>> = ::buffa::__private::OnceBox::new();
272 VALUE
273 .get_or_init(|| ::buffa::alloc::boxed::Box::new(
274 <TimestampView<'static>>::default(),
275 ))
276 }
277}
278impl ::buffa::ViewReborrow for TimestampView<'static> {
279 type Reborrowed<'b> = TimestampView<'b>;
280 fn reborrow<'b>(this: &'b Self) -> &'b Self::Reborrowed<'b> {
281 this
282 }
283}
284/** Self-contained, `'static` owned view of a `Timestamp` message.
285
286 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.
287
288 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.*/
289#[derive(Clone, Debug)]
290pub struct TimestampOwnedView(::buffa::OwnedView<TimestampView<'static>>);
291impl TimestampOwnedView {
292 /// Decode an owned view from a [`::buffa::bytes::Bytes`] buffer.
293 ///
294 /// The view borrows directly from the buffer's data; the buffer is
295 /// retained inside the returned handle.
296 ///
297 /// # Errors
298 ///
299 /// Returns [`::buffa::DecodeError`] if the buffer contains invalid
300 /// protobuf data.
301 pub fn decode(
302 bytes: ::buffa::bytes::Bytes,
303 ) -> ::core::result::Result<Self, ::buffa::DecodeError> {
304 ::core::result::Result::Ok(
305 TimestampOwnedView(::buffa::OwnedView::decode(bytes)?),
306 )
307 }
308 /// Decode with custom [`::buffa::DecodeOptions`] (recursion limit,
309 /// max message size).
310 ///
311 /// # Errors
312 ///
313 /// Returns [`::buffa::DecodeError`] if the buffer is invalid or
314 /// exceeds the configured limits.
315 pub fn decode_with_options(
316 bytes: ::buffa::bytes::Bytes,
317 opts: &::buffa::DecodeOptions,
318 ) -> ::core::result::Result<Self, ::buffa::DecodeError> {
319 ::core::result::Result::Ok(
320 TimestampOwnedView(::buffa::OwnedView::decode_with_options(bytes, opts)?),
321 )
322 }
323 /// Build from an owned message via an encode → decode round-trip.
324 ///
325 /// # Errors
326 ///
327 /// Returns [`::buffa::DecodeError`] if the re-encoded bytes are
328 /// somehow invalid (should not happen for well-formed messages).
329 pub fn from_owned(
330 msg: &super::super::Timestamp,
331 ) -> ::core::result::Result<Self, ::buffa::DecodeError> {
332 ::core::result::Result::Ok(
333 TimestampOwnedView(::buffa::OwnedView::from_owned(msg)?),
334 )
335 }
336 /// Borrow the full [`TimestampView`] with its lifetime tied to `&self`.
337 #[must_use]
338 pub fn view(&self) -> &TimestampView<'_> {
339 self.0.reborrow()
340 }
341 /// Convert to the owned message type.
342 #[must_use]
343 pub fn to_owned_message(&self) -> super::super::Timestamp {
344 self.0.to_owned_message()
345 }
346 /// The underlying bytes buffer.
347 #[must_use]
348 pub fn bytes(&self) -> &::buffa::bytes::Bytes {
349 self.0.bytes()
350 }
351 /// Consume the handle, returning the underlying bytes buffer.
352 #[must_use]
353 pub fn into_bytes(self) -> ::buffa::bytes::Bytes {
354 self.0.into_bytes()
355 }
356 /// Represents seconds of UTC time since Unix epoch
357 /// 1970-01-01T00:00:00Z. Must be from 0001-01-01T00:00:00Z to
358 /// 9999-12-31T23:59:59Z inclusive.
359 ///
360 /// Field 1: `seconds`
361 #[must_use]
362 pub fn seconds(&self) -> i64 {
363 self.0.reborrow().seconds
364 }
365 /// Non-negative fractions of a second at nanosecond resolution. Negative
366 /// second values with fractions must still have non-negative nanos values
367 /// that count forward in time. Must be from 0 to 999,999,999
368 /// inclusive.
369 ///
370 /// Field 2: `nanos`
371 #[must_use]
372 pub fn nanos(&self) -> i32 {
373 self.0.reborrow().nanos
374 }
375}
376impl ::core::convert::From<::buffa::OwnedView<TimestampView<'static>>>
377for TimestampOwnedView {
378 fn from(inner: ::buffa::OwnedView<TimestampView<'static>>) -> Self {
379 TimestampOwnedView(inner)
380 }
381}
382impl ::core::convert::From<TimestampOwnedView>
383for ::buffa::OwnedView<TimestampView<'static>> {
384 fn from(wrapper: TimestampOwnedView) -> Self {
385 wrapper.0
386 }
387}
388impl ::core::convert::AsRef<::buffa::OwnedView<TimestampView<'static>>>
389for TimestampOwnedView {
390 fn as_ref(&self) -> &::buffa::OwnedView<TimestampView<'static>> {
391 &self.0
392 }
393}
394impl ::buffa::HasMessageView for super::super::Timestamp {
395 type View<'a> = TimestampView<'a>;
396 type ViewHandle = TimestampOwnedView;
397}
398#[cfg(feature = "reflect")]
399const _: () = {
400 impl<'a> ::buffa_descriptor::reflect::ReflectMessage for TimestampView<'a> {
401 fn message_descriptor(&self) -> &::buffa_descriptor::MessageDescriptor {
402 super::super::__buffa::reflect::descriptor_pool()
403 .message(Self::__buffa_reflect_message_index())
404 }
405 fn pool(
406 &self,
407 ) -> &::buffa::alloc::sync::Arc<::buffa_descriptor::DescriptorPool> {
408 super::super::__buffa::reflect::descriptor_pool()
409 }
410 fn get(
411 &self,
412 field: &::buffa_descriptor::FieldDescriptor,
413 ) -> ::buffa_descriptor::reflect::ValueRef<'_> {
414 #[allow(unused_imports)]
415 use ::buffa::Enumeration as _;
416 match field.number() {
417 1u32 => ::buffa_descriptor::reflect::ValueRef::I64(self.seconds),
418 2u32 => ::buffa_descriptor::reflect::ValueRef::I32(self.nanos),
419 _ => {
420 ::core::debug_assert!(
421 false,
422 "field number {} is not a member of this view's reflect get()",
423 field.number(),
424 );
425 ::buffa_descriptor::reflect::ValueRef::Bool(false)
426 }
427 }
428 }
429 fn has(&self, field: &::buffa_descriptor::FieldDescriptor) -> bool {
430 match field.number() {
431 1u32 => self.seconds != 0,
432 2u32 => self.nanos != 0,
433 _ => false,
434 }
435 }
436 fn for_each_set(
437 &self,
438 f: &mut dyn ::core::ops::FnMut(
439 &::buffa_descriptor::FieldDescriptor,
440 ::buffa_descriptor::reflect::ValueRef<'_>,
441 ),
442 ) {
443 let md = ::buffa_descriptor::reflect::ReflectMessage::message_descriptor(
444 self,
445 );
446 for fd in md.fields() {
447 if ::buffa_descriptor::reflect::ReflectMessage::has(self, fd) {
448 f(fd, ::buffa_descriptor::reflect::ReflectMessage::get(self, fd));
449 }
450 }
451 }
452 fn to_dynamic(&self) -> ::buffa_descriptor::reflect::DynamicMessage {
453 let bytes = ::buffa::ViewEncode::encode_to_vec(self);
454 ::buffa_descriptor::reflect::DynamicMessage::decode(
455 ::buffa::alloc::sync::Arc::clone(
456 super::super::__buffa::reflect::descriptor_pool(),
457 ),
458 Self::__buffa_reflect_message_index(),
459 &bytes,
460 )
461 .expect("view re-encodes to bytes decodable against its own descriptor")
462 }
463 }
464 impl<'a> ::buffa_descriptor::reflect::ReflectElement for TimestampView<'a> {
465 fn as_value_ref(&self) -> ::buffa_descriptor::reflect::ValueRef<'_> {
466 ::buffa_descriptor::reflect::ValueRef::Message(
467 ::buffa_descriptor::reflect::ReflectCow::Borrowed(self),
468 )
469 }
470 }
471 impl<'a> TimestampView<'a> {
472 /// Memoized `MessageIndex` for this view's message type, resolved
473 /// once against the package's embedded descriptor pool. An inherent
474 /// associated fn (not a free fn) so sibling views in the same module
475 /// do not collide.
476 #[doc(hidden)]
477 fn __buffa_reflect_message_index() -> ::buffa_descriptor::MessageIndex {
478 static IDX: ::std::sync::OnceLock<::buffa_descriptor::MessageIndex> = ::std::sync::OnceLock::new();
479 *IDX
480 .get_or_init(|| {
481 super::super::__buffa::reflect::descriptor_pool()
482 .message_index(<Self as ::buffa::MessageName>::FULL_NAME)
483 .expect(
484 "generated view type is registered in the embedded descriptor pool",
485 )
486 })
487 }
488 }
489};