ntex_grpc/google_types/duration.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 Duration represents a signed, fixed-length span of time represented
19/// as a count of seconds and fractions of seconds at nanosecond
20/// resolution. It is independent of any calendar and concepts like "day"
21/// or "month". It is related to Timestamp in that the difference between
22/// two Timestamp values is a Duration and it can be added or subtracted
23/// from a Timestamp. Range is approximately +-10,000 years.
24///
25/// # Examples
26///
27/// Example 1: Compute Duration from two Timestamps in pseudo code.
28///
29/// Timestamp start = ...;
30/// Timestamp end = ...;
31/// Duration duration = ...;
32///
33/// duration.seconds = end.seconds - start.seconds;
34/// duration.nanos = end.nanos - start.nanos;
35///
36/// if (duration.seconds < 0 && duration.nanos > 0) {
37/// duration.seconds += 1;
38/// duration.nanos -= 1000000000;
39/// } else if (duration.seconds > 0 && duration.nanos < 0) {
40/// duration.seconds -= 1;
41/// duration.nanos += 1000000000;
42/// }
43///
44/// Example 2: Compute Timestamp from Timestamp + Duration in pseudo code.
45///
46/// Timestamp start = ...;
47/// Duration duration = ...;
48/// Timestamp end = ...;
49///
50/// end.seconds = start.seconds + duration.seconds;
51/// end.nanos = start.nanos + duration.nanos;
52///
53/// if (end.nanos < 0) {
54/// end.seconds -= 1;
55/// end.nanos += 1000000000;
56/// } else if (end.nanos >= 1000000000) {
57/// end.seconds += 1;
58/// end.nanos -= 1000000000;
59/// }
60///
61/// Example 3: Compute Duration from datetime.timedelta in Python.
62///
63/// td = datetime.timedelta(days=3, minutes=10)
64/// duration = Duration()
65/// duration.FromTimedelta(td)
66///
67/// # JSON Mapping
68///
69/// In JSON format, the Duration type is encoded as a string rather than an
70/// object, where the string ends in the suffix "s" (indicating seconds) and
71/// is preceded by the number of seconds, with nanoseconds expressed as
72/// fractional seconds. For example, 3 seconds with 0 nanoseconds should be
73/// encoded in JSON format as "3s", while 3 seconds and 1 nanosecond should
74/// be expressed in JSON format as "3.000000001s", and 3 seconds and 1
75/// microsecond should be expressed in JSON format as "3.000001s".
76///
77///
78#[derive(Clone, PartialEq, Debug)]
79pub struct Duration {
80 /// Signed seconds of the span of time. Must be from -315,576,000,000
81 /// to +315,576,000,000 inclusive. Note: these bounds are computed from:
82 /// 60 sec/min * 60 min/hr * 24 hr/day * 365.25 days/year * 10000 years
83 pub seconds: i64,
84 /// Signed fractions of a second at nanosecond resolution of the span
85 /// of time. Durations less than one second are represented with a 0
86 /// `seconds` field and a positive or negative `nanos` field. For durations
87 /// of one second or more, a non-zero value for the `nanos` field must be
88 /// of the same sign as the `seconds` field. Must be from -999,999,999
89 /// to +999,999,999 inclusive.
90 pub nanos: i32,
91}
92
93mod _priv_impl_duration {
94 use super::*;
95
96 impl crate::Message for Duration {
97 #[inline]
98 fn write(&self, dst: &mut crate::BytePages) {
99 crate::NativeType::serialize(
100 &self.seconds,
101 1,
102 crate::types::DefaultValue::Default,
103 dst,
104 );
105 crate::NativeType::serialize(&self.nanos, 2, crate::types::DefaultValue::Default, dst);
106 }
107
108 #[inline]
109 fn read(src: &mut crate::Bytes) -> ::std::result::Result<Self, crate::DecodeError> {
110 const STRUCT_NAME: &str = "Duration";
111 let mut msg = Self::default();
112 while !src.is_empty() {
113 let (tag, wire_type) = crate::encoding::decode_key(src)?;
114 match tag {
115 1 => crate::NativeType::deserialize(&mut msg.seconds, tag, wire_type, src)
116 .map_err(|err| err.push(STRUCT_NAME, "seconds"))?,
117 2 => crate::NativeType::deserialize(&mut msg.nanos, tag, wire_type, src)
118 .map_err(|err| err.push(STRUCT_NAME, "nanos"))?,
119 _ => crate::encoding::skip_field(wire_type, tag, src)?,
120 }
121 }
122 Ok(msg)
123 }
124
125 #[inline]
126 fn encoded_len(&self) -> usize {
127 0 + crate::NativeType::serialized_len(
128 &self.seconds,
129 1,
130 crate::types::DefaultValue::Default,
131 ) + crate::NativeType::serialized_len(
132 &self.nanos,
133 2,
134 crate::types::DefaultValue::Default,
135 )
136 }
137 }
138
139 impl ::std::default::Default for Duration {
140 #[inline]
141 fn default() -> Self {
142 Self {
143 seconds: ::core::default::Default::default(),
144 nanos: ::core::default::Default::default(),
145 }
146 }
147 }
148}