protobuf/well_known_types/
duration.rs1#![allow(unknown_lints)]
6#![allow(clippy::all)]
7
8#![allow(unused_attributes)]
9#![cfg_attr(rustfmt, rustfmt::skip)]
10
11#![allow(box_pointers)]
12#![allow(dead_code)]
13#![allow(missing_docs)]
14#![allow(non_camel_case_types)]
15#![allow(non_snake_case)]
16#![allow(non_upper_case_globals)]
17#![allow(trivial_casts)]
18#![allow(unused_imports)]
19#![allow(unused_results)]
20#[derive(PartialEq,Clone,Default)]
23#[cfg_attr(feature = "with-serde", derive(::serde::Serialize, ::serde::Deserialize))]
24pub struct Duration {
25 pub seconds: i64,
27 pub nanos: i32,
28 #[cfg_attr(feature = "with-serde", serde(skip))]
30 pub unknown_fields: crate::UnknownFields,
31 #[cfg_attr(feature = "with-serde", serde(skip))]
32 pub cached_size: crate::CachedSize,
33}
34
35impl<'a> ::std::default::Default for &'a Duration {
36 fn default() -> &'a Duration {
37 <Duration as crate::Message>::default_instance()
38 }
39}
40
41impl Duration {
42 pub fn new() -> Duration {
43 ::std::default::Default::default()
44 }
45
46 pub fn get_seconds(&self) -> i64 {
50 self.seconds
51 }
52 pub fn clear_seconds(&mut self) {
53 self.seconds = 0;
54 }
55
56 pub fn set_seconds(&mut self, v: i64) {
58 self.seconds = v;
59 }
60
61 pub fn get_nanos(&self) -> i32 {
65 self.nanos
66 }
67 pub fn clear_nanos(&mut self) {
68 self.nanos = 0;
69 }
70
71 pub fn set_nanos(&mut self, v: i32) {
73 self.nanos = v;
74 }
75}
76
77impl crate::Message for Duration {
78 fn is_initialized(&self) -> bool {
79 true
80 }
81
82 fn merge_from(&mut self, is: &mut crate::CodedInputStream<'_>) -> crate::ProtobufResult<()> {
83 while !is.eof()? {
84 let (field_number, wire_type) = is.read_tag_unpack()?;
85 match field_number {
86 1 => {
87 if wire_type != crate::wire_format::WireTypeVarint {
88 return ::std::result::Result::Err(crate::rt::unexpected_wire_type(wire_type));
89 }
90 let tmp = is.read_int64()?;
91 self.seconds = tmp;
92 },
93 2 => {
94 if wire_type != crate::wire_format::WireTypeVarint {
95 return ::std::result::Result::Err(crate::rt::unexpected_wire_type(wire_type));
96 }
97 let tmp = is.read_int32()?;
98 self.nanos = tmp;
99 },
100 _ => {
101 crate::rt::read_unknown_or_skip_group(field_number, wire_type, is, self.mut_unknown_fields())?;
102 },
103 };
104 }
105 ::std::result::Result::Ok(())
106 }
107
108 #[allow(unused_variables)]
110 fn compute_size(&self) -> u32 {
111 let mut my_size = 0;
112 if self.seconds != 0 {
113 my_size += crate::rt::value_size(1, self.seconds, crate::wire_format::WireTypeVarint);
114 }
115 if self.nanos != 0 {
116 my_size += crate::rt::value_size(2, self.nanos, crate::wire_format::WireTypeVarint);
117 }
118 my_size += crate::rt::unknown_fields_size(self.get_unknown_fields());
119 self.cached_size.set(my_size);
120 my_size
121 }
122
123 fn write_to_with_cached_sizes(&self, os: &mut crate::CodedOutputStream<'_>) -> crate::ProtobufResult<()> {
124 if self.seconds != 0 {
125 os.write_int64(1, self.seconds)?;
126 }
127 if self.nanos != 0 {
128 os.write_int32(2, self.nanos)?;
129 }
130 os.write_unknown_fields(self.get_unknown_fields())?;
131 ::std::result::Result::Ok(())
132 }
133
134 fn get_cached_size(&self) -> u32 {
135 self.cached_size.get()
136 }
137
138 fn get_unknown_fields(&self) -> &crate::UnknownFields {
139 &self.unknown_fields
140 }
141
142 fn mut_unknown_fields(&mut self) -> &mut crate::UnknownFields {
143 &mut self.unknown_fields
144 }
145
146 fn as_any(&self) -> &dyn (::std::any::Any) {
147 self as &dyn (::std::any::Any)
148 }
149 fn as_any_mut(&mut self) -> &mut dyn (::std::any::Any) {
150 self as &mut dyn (::std::any::Any)
151 }
152 fn into_any(self: ::std::boxed::Box<Self>) -> ::std::boxed::Box<dyn (::std::any::Any)> {
153 self
154 }
155
156 fn descriptor(&self) -> &'static crate::reflect::MessageDescriptor {
157 Self::descriptor_static()
158 }
159
160 fn new() -> Duration {
161 Duration::new()
162 }
163
164 fn descriptor_static() -> &'static crate::reflect::MessageDescriptor {
165 static descriptor: crate::rt::LazyV2<crate::reflect::MessageDescriptor> = crate::rt::LazyV2::INIT;
166 descriptor.get(|| {
167 let mut fields = ::std::vec::Vec::new();
168 fields.push(crate::reflect::accessor::make_simple_field_accessor::<_, crate::types::ProtobufTypeInt64>(
169 "seconds",
170 |m: &Duration| { &m.seconds },
171 |m: &mut Duration| { &mut m.seconds },
172 ));
173 fields.push(crate::reflect::accessor::make_simple_field_accessor::<_, crate::types::ProtobufTypeInt32>(
174 "nanos",
175 |m: &Duration| { &m.nanos },
176 |m: &mut Duration| { &mut m.nanos },
177 ));
178 crate::reflect::MessageDescriptor::new_pb_name::<Duration>(
179 "Duration",
180 fields,
181 file_descriptor_proto()
182 )
183 })
184 }
185
186 fn default_instance() -> &'static Duration {
187 static instance: crate::rt::LazyV2<Duration> = crate::rt::LazyV2::INIT;
188 instance.get(Duration::new)
189 }
190}
191
192impl crate::Clear for Duration {
193 fn clear(&mut self) {
194 self.seconds = 0;
195 self.nanos = 0;
196 self.unknown_fields.clear();
197 }
198}
199
200impl ::std::fmt::Debug for Duration {
201 fn fmt(&self, f: &mut ::std::fmt::Formatter<'_>) -> ::std::fmt::Result {
202 crate::text_format::fmt(self, f)
203 }
204}
205
206impl crate::reflect::ProtobufValue for Duration {
207 fn as_ref(&self) -> crate::reflect::ReflectValueRef {
208 crate::reflect::ReflectValueRef::Message(self)
209 }
210}
211
212static file_descriptor_proto_data: &'static [u8] = b"\
213 \n\x1egoogle/protobuf/duration.proto\x12\x0fgoogle.protobuf\":\n\x08Dura\
214 tion\x12\x18\n\x07seconds\x18\x01\x20\x01(\x03R\x07seconds\x12\x14\n\x05\
215 nanos\x18\x02\x20\x01(\x05R\x05nanosB\x83\x01\n\x13com.google.protobufB\
216 \rDurationProtoP\x01Z1google.golang.org/protobuf/types/known/durationpb\
217 \xf8\x01\x01\xa2\x02\x03GPB\xaa\x02\x1eGoogle.Protobuf.WellKnownTypesJ\
218 \xda#\n\x06\x12\x04\x1e\0s\x01\n\xcc\x0c\n\x01\x0c\x12\x03\x1e\0\x122\
219 \xc1\x0c\x20Protocol\x20Buffers\x20-\x20Google's\x20data\x20interchange\
220 \x20format\n\x20Copyright\x202008\x20Google\x20Inc.\x20\x20All\x20rights\
221 \x20reserved.\n\x20https://developers.google.com/protocol-buffers/\n\n\
222 \x20Redistribution\x20and\x20use\x20in\x20source\x20and\x20binary\x20for\
223 ms,\x20with\x20or\x20without\n\x20modification,\x20are\x20permitted\x20p\
224 rovided\x20that\x20the\x20following\x20conditions\x20are\n\x20met:\n\n\
225 \x20\x20\x20\x20\x20*\x20Redistributions\x20of\x20source\x20code\x20must\
226 \x20retain\x20the\x20above\x20copyright\n\x20notice,\x20this\x20list\x20\
227 of\x20conditions\x20and\x20the\x20following\x20disclaimer.\n\x20\x20\x20\
228 \x20\x20*\x20Redistributions\x20in\x20binary\x20form\x20must\x20reproduc\
229 e\x20the\x20above\n\x20copyright\x20notice,\x20this\x20list\x20of\x20con\
230 ditions\x20and\x20the\x20following\x20disclaimer\n\x20in\x20the\x20docum\
231 entation\x20and/or\x20other\x20materials\x20provided\x20with\x20the\n\
232 \x20distribution.\n\x20\x20\x20\x20\x20*\x20Neither\x20the\x20name\x20of\
233 \x20Google\x20Inc.\x20nor\x20the\x20names\x20of\x20its\n\x20contributors\
234 \x20may\x20be\x20used\x20to\x20endorse\x20or\x20promote\x20products\x20d\
235 erived\x20from\n\x20this\x20software\x20without\x20specific\x20prior\x20\
236 written\x20permission.\n\n\x20THIS\x20SOFTWARE\x20IS\x20PROVIDED\x20BY\
237 \x20THE\x20COPYRIGHT\x20HOLDERS\x20AND\x20CONTRIBUTORS\n\x20\"AS\x20IS\"\
238 \x20AND\x20ANY\x20EXPRESS\x20OR\x20IMPLIED\x20WARRANTIES,\x20INCLUDING,\
239 \x20BUT\x20NOT\n\x20LIMITED\x20TO,\x20THE\x20IMPLIED\x20WARRANTIES\x20OF\
240 \x20MERCHANTABILITY\x20AND\x20FITNESS\x20FOR\n\x20A\x20PARTICULAR\x20PUR\
241 POSE\x20ARE\x20DISCLAIMED.\x20IN\x20NO\x20EVENT\x20SHALL\x20THE\x20COPYR\
242 IGHT\n\x20OWNER\x20OR\x20CONTRIBUTORS\x20BE\x20LIABLE\x20FOR\x20ANY\x20D\
243 IRECT,\x20INDIRECT,\x20INCIDENTAL,\n\x20SPECIAL,\x20EXEMPLARY,\x20OR\x20\
244 CONSEQUENTIAL\x20DAMAGES\x20(INCLUDING,\x20BUT\x20NOT\n\x20LIMITED\x20TO\
245 ,\x20PROCUREMENT\x20OF\x20SUBSTITUTE\x20GOODS\x20OR\x20SERVICES;\x20LOSS\
246 \x20OF\x20USE,\n\x20DATA,\x20OR\x20PROFITS;\x20OR\x20BUSINESS\x20INTERRU\
247 PTION)\x20HOWEVER\x20CAUSED\x20AND\x20ON\x20ANY\n\x20THEORY\x20OF\x20LIA\
248 BILITY,\x20WHETHER\x20IN\x20CONTRACT,\x20STRICT\x20LIABILITY,\x20OR\x20T\
249 ORT\n\x20(INCLUDING\x20NEGLIGENCE\x20OR\x20OTHERWISE)\x20ARISING\x20IN\
250 \x20ANY\x20WAY\x20OUT\x20OF\x20THE\x20USE\n\x20OF\x20THIS\x20SOFTWARE,\
251 \x20EVEN\x20IF\x20ADVISED\x20OF\x20THE\x20POSSIBILITY\x20OF\x20SUCH\x20D\
252 AMAGE.\n\n\x08\n\x01\x02\x12\x03\x20\0\x18\n\x08\n\x01\x08\x12\x03\"\0;\
253 \n\t\n\x02\x08%\x12\x03\"\0;\n\x08\n\x01\x08\x12\x03#\0\x1f\n\t\n\x02\
254 \x08\x1f\x12\x03#\0\x1f\n\x08\n\x01\x08\x12\x03$\0H\n\t\n\x02\x08\x0b\
255 \x12\x03$\0H\n\x08\n\x01\x08\x12\x03%\0,\n\t\n\x02\x08\x01\x12\x03%\0,\n\
256 \x08\n\x01\x08\x12\x03&\0.\n\t\n\x02\x08\x08\x12\x03&\0.\n\x08\n\x01\x08\
257 \x12\x03'\0\"\n\t\n\x02\x08\n\x12\x03'\0\"\n\x08\n\x01\x08\x12\x03(\0!\n\
258 \t\n\x02\x08$\x12\x03(\0!\n\x9e\x10\n\x02\x04\0\x12\x04f\0s\x01\x1a\x91\
259 \x10\x20A\x20Duration\x20represents\x20a\x20signed,\x20fixed-length\x20s\
260 pan\x20of\x20time\x20represented\n\x20as\x20a\x20count\x20of\x20seconds\
261 \x20and\x20fractions\x20of\x20seconds\x20at\x20nanosecond\n\x20resolutio\
262 n.\x20It\x20is\x20independent\x20of\x20any\x20calendar\x20and\x20concept\
263 s\x20like\x20\"day\"\n\x20or\x20\"month\".\x20It\x20is\x20related\x20to\
264 \x20Timestamp\x20in\x20that\x20the\x20difference\x20between\n\x20two\x20\
265 Timestamp\x20values\x20is\x20a\x20Duration\x20and\x20it\x20can\x20be\x20\
266 added\x20or\x20subtracted\n\x20from\x20a\x20Timestamp.\x20Range\x20is\
267 \x20approximately\x20+-10,000\x20years.\n\n\x20#\x20Examples\n\n\x20Exam\
268 ple\x201:\x20Compute\x20Duration\x20from\x20two\x20Timestamps\x20in\x20p\
269 seudo\x20code.\n\n\x20\x20\x20\x20\x20Timestamp\x20start\x20=\x20...;\n\
270 \x20\x20\x20\x20\x20Timestamp\x20end\x20=\x20...;\n\x20\x20\x20\x20\x20D\
271 uration\x20duration\x20=\x20...;\n\n\x20\x20\x20\x20\x20duration.seconds\
272 \x20=\x20end.seconds\x20-\x20start.seconds;\n\x20\x20\x20\x20\x20duratio\
273 n.nanos\x20=\x20end.nanos\x20-\x20start.nanos;\n\n\x20\x20\x20\x20\x20if\
274 \x20(duration.seconds\x20<\x200\x20&&\x20duration.nanos\x20>\x200)\x20{\
275 \n\x20\x20\x20\x20\x20\x20\x20duration.seconds\x20+=\x201;\n\x20\x20\x20\
276 \x20\x20\x20\x20duration.nanos\x20-=\x201000000000;\n\x20\x20\x20\x20\
277 \x20}\x20else\x20if\x20(duration.seconds\x20>\x200\x20&&\x20duration.nan\
278 os\x20<\x200)\x20{\n\x20\x20\x20\x20\x20\x20\x20duration.seconds\x20-=\
279 \x201;\n\x20\x20\x20\x20\x20\x20\x20duration.nanos\x20+=\x201000000000;\
280 \n\x20\x20\x20\x20\x20}\n\n\x20Example\x202:\x20Compute\x20Timestamp\x20\
281 from\x20Timestamp\x20+\x20Duration\x20in\x20pseudo\x20code.\n\n\x20\x20\
282 \x20\x20\x20Timestamp\x20start\x20=\x20...;\n\x20\x20\x20\x20\x20Duratio\
283 n\x20duration\x20=\x20...;\n\x20\x20\x20\x20\x20Timestamp\x20end\x20=\
284 \x20...;\n\n\x20\x20\x20\x20\x20end.seconds\x20=\x20start.seconds\x20+\
285 \x20duration.seconds;\n\x20\x20\x20\x20\x20end.nanos\x20=\x20start.nanos\
286 \x20+\x20duration.nanos;\n\n\x20\x20\x20\x20\x20if\x20(end.nanos\x20<\
287 \x200)\x20{\n\x20\x20\x20\x20\x20\x20\x20end.seconds\x20-=\x201;\n\x20\
288 \x20\x20\x20\x20\x20\x20end.nanos\x20+=\x201000000000;\n\x20\x20\x20\x20\
289 \x20}\x20else\x20if\x20(end.nanos\x20>=\x201000000000)\x20{\n\x20\x20\
290 \x20\x20\x20\x20\x20end.seconds\x20+=\x201;\n\x20\x20\x20\x20\x20\x20\
291 \x20end.nanos\x20-=\x201000000000;\n\x20\x20\x20\x20\x20}\n\n\x20Example\
292 \x203:\x20Compute\x20Duration\x20from\x20datetime.timedelta\x20in\x20Pyt\
293 hon.\n\n\x20\x20\x20\x20\x20td\x20=\x20datetime.timedelta(days=3,\x20min\
294 utes=10)\n\x20\x20\x20\x20\x20duration\x20=\x20Duration()\n\x20\x20\x20\
295 \x20\x20duration.FromTimedelta(td)\n\n\x20#\x20JSON\x20Mapping\n\n\x20In\
296 \x20JSON\x20format,\x20the\x20Duration\x20type\x20is\x20encoded\x20as\
297 \x20a\x20string\x20rather\x20than\x20an\n\x20object,\x20where\x20the\x20\
298 string\x20ends\x20in\x20the\x20suffix\x20\"s\"\x20(indicating\x20seconds\
299 )\x20and\n\x20is\x20preceded\x20by\x20the\x20number\x20of\x20seconds,\
300 \x20with\x20nanoseconds\x20expressed\x20as\n\x20fractional\x20seconds.\
301 \x20For\x20example,\x203\x20seconds\x20with\x200\x20nanoseconds\x20shoul\
302 d\x20be\n\x20encoded\x20in\x20JSON\x20format\x20as\x20\"3s\",\x20while\
303 \x203\x20seconds\x20and\x201\x20nanosecond\x20should\n\x20be\x20expresse\
304 d\x20in\x20JSON\x20format\x20as\x20\"3.000000001s\",\x20and\x203\x20seco\
305 nds\x20and\x201\n\x20microsecond\x20should\x20be\x20expressed\x20in\x20J\
306 SON\x20format\x20as\x20\"3.000001s\".\n\n\n\n\n\n\x03\x04\0\x01\x12\x03f\
307 \x08\x10\n\xdc\x01\n\x04\x04\0\x02\0\x12\x03j\x02\x14\x1a\xce\x01\x20Sig\
308 ned\x20seconds\x20of\x20the\x20span\x20of\x20time.\x20Must\x20be\x20from\
309 \x20-315,576,000,000\n\x20to\x20+315,576,000,000\x20inclusive.\x20Note:\
310 \x20these\x20bounds\x20are\x20computed\x20from:\n\x2060\x20sec/min\x20*\
311 \x2060\x20min/hr\x20*\x2024\x20hr/day\x20*\x20365.25\x20days/year\x20*\
312 \x2010000\x20years\n\n\x0c\n\x05\x04\0\x02\0\x05\x12\x03j\x02\x07\n\x0c\
313 \n\x05\x04\0\x02\0\x01\x12\x03j\x08\x0f\n\x0c\n\x05\x04\0\x02\0\x03\x12\
314 \x03j\x12\x13\n\x83\x03\n\x04\x04\0\x02\x01\x12\x03r\x02\x12\x1a\xf5\x02\
315 \x20Signed\x20fractions\x20of\x20a\x20second\x20at\x20nanosecond\x20reso\
316 lution\x20of\x20the\x20span\n\x20of\x20time.\x20Durations\x20less\x20tha\
317 n\x20one\x20second\x20are\x20represented\x20with\x20a\x200\n\x20`seconds\
318 `\x20field\x20and\x20a\x20positive\x20or\x20negative\x20`nanos`\x20field\
319 .\x20For\x20durations\n\x20of\x20one\x20second\x20or\x20more,\x20a\x20no\
320 n-zero\x20value\x20for\x20the\x20`nanos`\x20field\x20must\x20be\n\x20of\
321 \x20the\x20same\x20sign\x20as\x20the\x20`seconds`\x20field.\x20Must\x20b\
322 e\x20from\x20-999,999,999\n\x20to\x20+999,999,999\x20inclusive.\n\n\x0c\
323 \n\x05\x04\0\x02\x01\x05\x12\x03r\x02\x07\n\x0c\n\x05\x04\0\x02\x01\x01\
324 \x12\x03r\x08\r\n\x0c\n\x05\x04\0\x02\x01\x03\x12\x03r\x10\x11b\x06proto\
325 3\
326";
327
328static file_descriptor_proto_lazy: crate::rt::LazyV2<crate::descriptor::FileDescriptorProto> = crate::rt::LazyV2::INIT;
329
330fn parse_descriptor_proto() -> crate::descriptor::FileDescriptorProto {
331 crate::Message::parse_from_bytes(file_descriptor_proto_data).unwrap()
332}
333
334pub fn file_descriptor_proto() -> &'static crate::descriptor::FileDescriptorProto {
335 file_descriptor_proto_lazy.get(|| {
336 parse_descriptor_proto()
337 })
338}