fidl_fuchsia_power_suspend_common/
fidl_fuchsia_power_suspend_common.rs1#![warn(clippy::all)]
4#![allow(unused_parens, unused_mut, unused_imports, nonstandard_style)]
5
6use bitflags::bitflags;
7use fidl::encoding::{MessageBufFor, ProxyChannelBox, ResourceDialect};
8use futures::future::{self, MaybeDone, TryFutureExt};
9use zx_status;
10
11#[derive(Clone, Debug, Default, PartialEq)]
13pub struct SuspendStats {
14 pub success_count: Option<u64>,
16 pub fail_count: Option<u64>,
18 pub last_failed_error: Option<i32>,
20 pub last_time_in_suspend: Option<i64>,
23 pub last_time_in_suspend_operations: Option<i64>,
28 #[doc(hidden)]
29 pub __source_breaking: fidl::marker::SourceBreaking,
30}
31
32impl fidl::Persistable for SuspendStats {}
33
34mod internal {
35 use super::*;
36
37 impl SuspendStats {
38 #[inline(always)]
39 fn max_ordinal_present(&self) -> u64 {
40 if let Some(_) = self.last_time_in_suspend_operations {
41 return 5;
42 }
43 if let Some(_) = self.last_time_in_suspend {
44 return 4;
45 }
46 if let Some(_) = self.last_failed_error {
47 return 3;
48 }
49 if let Some(_) = self.fail_count {
50 return 2;
51 }
52 if let Some(_) = self.success_count {
53 return 1;
54 }
55 0
56 }
57 }
58
59 impl fidl::encoding::ValueTypeMarker for SuspendStats {
60 type Borrowed<'a> = &'a Self;
61 fn borrow(value: &<Self as fidl::encoding::TypeMarker>::Owned) -> Self::Borrowed<'_> {
62 value
63 }
64 }
65
66 unsafe impl fidl::encoding::TypeMarker for SuspendStats {
67 type Owned = Self;
68
69 #[inline(always)]
70 fn inline_align(_context: fidl::encoding::Context) -> usize {
71 8
72 }
73
74 #[inline(always)]
75 fn inline_size(_context: fidl::encoding::Context) -> usize {
76 16
77 }
78 }
79
80 unsafe impl<D: fidl::encoding::ResourceDialect> fidl::encoding::Encode<SuspendStats, D>
81 for &SuspendStats
82 {
83 unsafe fn encode(
84 self,
85 encoder: &mut fidl::encoding::Encoder<'_, D>,
86 offset: usize,
87 mut depth: fidl::encoding::Depth,
88 ) -> fidl::Result<()> {
89 encoder.debug_check_bounds::<SuspendStats>(offset);
90 let max_ordinal: u64 = self.max_ordinal_present();
92 encoder.write_num(max_ordinal, offset);
93 encoder.write_num(fidl::encoding::ALLOC_PRESENT_U64, offset + 8);
94 if max_ordinal == 0 {
96 return Ok(());
97 }
98 depth.increment()?;
99 let envelope_size = 8;
100 let bytes_len = max_ordinal as usize * envelope_size;
101 #[allow(unused_variables)]
102 let offset = encoder.out_of_line_offset(bytes_len);
103 let mut _prev_end_offset: usize = 0;
104 if 1 > max_ordinal {
105 return Ok(());
106 }
107
108 let cur_offset: usize = (1 - 1) * envelope_size;
111
112 encoder.padding(offset + _prev_end_offset, cur_offset - _prev_end_offset);
114
115 fidl::encoding::encode_in_envelope_optional::<u64, D>(
120 self.success_count.as_ref().map(<u64 as fidl::encoding::ValueTypeMarker>::borrow),
121 encoder,
122 offset + cur_offset,
123 depth,
124 )?;
125
126 _prev_end_offset = cur_offset + envelope_size;
127 if 2 > max_ordinal {
128 return Ok(());
129 }
130
131 let cur_offset: usize = (2 - 1) * envelope_size;
134
135 encoder.padding(offset + _prev_end_offset, cur_offset - _prev_end_offset);
137
138 fidl::encoding::encode_in_envelope_optional::<u64, D>(
143 self.fail_count.as_ref().map(<u64 as fidl::encoding::ValueTypeMarker>::borrow),
144 encoder,
145 offset + cur_offset,
146 depth,
147 )?;
148
149 _prev_end_offset = cur_offset + envelope_size;
150 if 3 > max_ordinal {
151 return Ok(());
152 }
153
154 let cur_offset: usize = (3 - 1) * envelope_size;
157
158 encoder.padding(offset + _prev_end_offset, cur_offset - _prev_end_offset);
160
161 fidl::encoding::encode_in_envelope_optional::<i32, D>(
166 self.last_failed_error
167 .as_ref()
168 .map(<i32 as fidl::encoding::ValueTypeMarker>::borrow),
169 encoder,
170 offset + cur_offset,
171 depth,
172 )?;
173
174 _prev_end_offset = cur_offset + envelope_size;
175 if 4 > max_ordinal {
176 return Ok(());
177 }
178
179 let cur_offset: usize = (4 - 1) * envelope_size;
182
183 encoder.padding(offset + _prev_end_offset, cur_offset - _prev_end_offset);
185
186 fidl::encoding::encode_in_envelope_optional::<i64, D>(
191 self.last_time_in_suspend
192 .as_ref()
193 .map(<i64 as fidl::encoding::ValueTypeMarker>::borrow),
194 encoder,
195 offset + cur_offset,
196 depth,
197 )?;
198
199 _prev_end_offset = cur_offset + envelope_size;
200 if 5 > max_ordinal {
201 return Ok(());
202 }
203
204 let cur_offset: usize = (5 - 1) * envelope_size;
207
208 encoder.padding(offset + _prev_end_offset, cur_offset - _prev_end_offset);
210
211 fidl::encoding::encode_in_envelope_optional::<i64, D>(
216 self.last_time_in_suspend_operations
217 .as_ref()
218 .map(<i64 as fidl::encoding::ValueTypeMarker>::borrow),
219 encoder,
220 offset + cur_offset,
221 depth,
222 )?;
223
224 _prev_end_offset = cur_offset + envelope_size;
225
226 Ok(())
227 }
228 }
229
230 impl<D: fidl::encoding::ResourceDialect> fidl::encoding::Decode<Self, D> for SuspendStats {
231 #[inline(always)]
232 fn new_empty() -> Self {
233 Self::default()
234 }
235
236 unsafe fn decode(
237 &mut self,
238 decoder: &mut fidl::encoding::Decoder<'_, D>,
239 offset: usize,
240 mut depth: fidl::encoding::Depth,
241 ) -> fidl::Result<()> {
242 decoder.debug_check_bounds::<Self>(offset);
243 let len = match fidl::encoding::decode_vector_header(decoder, offset)? {
244 None => return Err(fidl::Error::NotNullable),
245 Some(len) => len,
246 };
247 if len == 0 {
249 return Ok(());
250 };
251 depth.increment()?;
252 let envelope_size = 8;
253 let bytes_len = len * envelope_size;
254 let offset = decoder.out_of_line_offset(bytes_len)?;
255 let mut _next_ordinal_to_read = 0;
257 let mut next_offset = offset;
258 let end_offset = offset + bytes_len;
259 _next_ordinal_to_read += 1;
260 if next_offset >= end_offset {
261 return Ok(());
262 }
263
264 while _next_ordinal_to_read < 1 {
266 fidl::encoding::decode_unknown_envelope(decoder, next_offset, depth)?;
267 _next_ordinal_to_read += 1;
268 next_offset += envelope_size;
269 }
270
271 let next_out_of_line = decoder.next_out_of_line();
272 let handles_before = decoder.remaining_handles();
273 if let Some((inlined, num_bytes, num_handles)) =
274 fidl::encoding::decode_envelope_header(decoder, next_offset)?
275 {
276 let member_inline_size =
277 <u64 as fidl::encoding::TypeMarker>::inline_size(decoder.context);
278 if inlined != (member_inline_size <= 4) {
279 return Err(fidl::Error::InvalidInlineBitInEnvelope);
280 }
281 let inner_offset;
282 let mut inner_depth = depth.clone();
283 if inlined {
284 decoder.check_inline_envelope_padding(next_offset, member_inline_size)?;
285 inner_offset = next_offset;
286 } else {
287 inner_offset = decoder.out_of_line_offset(member_inline_size)?;
288 inner_depth.increment()?;
289 }
290 let val_ref = self.success_count.get_or_insert_with(|| fidl::new_empty!(u64, D));
291 fidl::decode!(u64, D, val_ref, decoder, inner_offset, inner_depth)?;
292 if !inlined && decoder.next_out_of_line() != next_out_of_line + (num_bytes as usize)
293 {
294 return Err(fidl::Error::InvalidNumBytesInEnvelope);
295 }
296 if handles_before != decoder.remaining_handles() + (num_handles as usize) {
297 return Err(fidl::Error::InvalidNumHandlesInEnvelope);
298 }
299 }
300
301 next_offset += envelope_size;
302 _next_ordinal_to_read += 1;
303 if next_offset >= end_offset {
304 return Ok(());
305 }
306
307 while _next_ordinal_to_read < 2 {
309 fidl::encoding::decode_unknown_envelope(decoder, next_offset, depth)?;
310 _next_ordinal_to_read += 1;
311 next_offset += envelope_size;
312 }
313
314 let next_out_of_line = decoder.next_out_of_line();
315 let handles_before = decoder.remaining_handles();
316 if let Some((inlined, num_bytes, num_handles)) =
317 fidl::encoding::decode_envelope_header(decoder, next_offset)?
318 {
319 let member_inline_size =
320 <u64 as fidl::encoding::TypeMarker>::inline_size(decoder.context);
321 if inlined != (member_inline_size <= 4) {
322 return Err(fidl::Error::InvalidInlineBitInEnvelope);
323 }
324 let inner_offset;
325 let mut inner_depth = depth.clone();
326 if inlined {
327 decoder.check_inline_envelope_padding(next_offset, member_inline_size)?;
328 inner_offset = next_offset;
329 } else {
330 inner_offset = decoder.out_of_line_offset(member_inline_size)?;
331 inner_depth.increment()?;
332 }
333 let val_ref = self.fail_count.get_or_insert_with(|| fidl::new_empty!(u64, D));
334 fidl::decode!(u64, D, val_ref, decoder, inner_offset, inner_depth)?;
335 if !inlined && decoder.next_out_of_line() != next_out_of_line + (num_bytes as usize)
336 {
337 return Err(fidl::Error::InvalidNumBytesInEnvelope);
338 }
339 if handles_before != decoder.remaining_handles() + (num_handles as usize) {
340 return Err(fidl::Error::InvalidNumHandlesInEnvelope);
341 }
342 }
343
344 next_offset += envelope_size;
345 _next_ordinal_to_read += 1;
346 if next_offset >= end_offset {
347 return Ok(());
348 }
349
350 while _next_ordinal_to_read < 3 {
352 fidl::encoding::decode_unknown_envelope(decoder, next_offset, depth)?;
353 _next_ordinal_to_read += 1;
354 next_offset += envelope_size;
355 }
356
357 let next_out_of_line = decoder.next_out_of_line();
358 let handles_before = decoder.remaining_handles();
359 if let Some((inlined, num_bytes, num_handles)) =
360 fidl::encoding::decode_envelope_header(decoder, next_offset)?
361 {
362 let member_inline_size =
363 <i32 as fidl::encoding::TypeMarker>::inline_size(decoder.context);
364 if inlined != (member_inline_size <= 4) {
365 return Err(fidl::Error::InvalidInlineBitInEnvelope);
366 }
367 let inner_offset;
368 let mut inner_depth = depth.clone();
369 if inlined {
370 decoder.check_inline_envelope_padding(next_offset, member_inline_size)?;
371 inner_offset = next_offset;
372 } else {
373 inner_offset = decoder.out_of_line_offset(member_inline_size)?;
374 inner_depth.increment()?;
375 }
376 let val_ref =
377 self.last_failed_error.get_or_insert_with(|| fidl::new_empty!(i32, D));
378 fidl::decode!(i32, D, val_ref, decoder, inner_offset, inner_depth)?;
379 if !inlined && decoder.next_out_of_line() != next_out_of_line + (num_bytes as usize)
380 {
381 return Err(fidl::Error::InvalidNumBytesInEnvelope);
382 }
383 if handles_before != decoder.remaining_handles() + (num_handles as usize) {
384 return Err(fidl::Error::InvalidNumHandlesInEnvelope);
385 }
386 }
387
388 next_offset += envelope_size;
389 _next_ordinal_to_read += 1;
390 if next_offset >= end_offset {
391 return Ok(());
392 }
393
394 while _next_ordinal_to_read < 4 {
396 fidl::encoding::decode_unknown_envelope(decoder, next_offset, depth)?;
397 _next_ordinal_to_read += 1;
398 next_offset += envelope_size;
399 }
400
401 let next_out_of_line = decoder.next_out_of_line();
402 let handles_before = decoder.remaining_handles();
403 if let Some((inlined, num_bytes, num_handles)) =
404 fidl::encoding::decode_envelope_header(decoder, next_offset)?
405 {
406 let member_inline_size =
407 <i64 as fidl::encoding::TypeMarker>::inline_size(decoder.context);
408 if inlined != (member_inline_size <= 4) {
409 return Err(fidl::Error::InvalidInlineBitInEnvelope);
410 }
411 let inner_offset;
412 let mut inner_depth = depth.clone();
413 if inlined {
414 decoder.check_inline_envelope_padding(next_offset, member_inline_size)?;
415 inner_offset = next_offset;
416 } else {
417 inner_offset = decoder.out_of_line_offset(member_inline_size)?;
418 inner_depth.increment()?;
419 }
420 let val_ref =
421 self.last_time_in_suspend.get_or_insert_with(|| fidl::new_empty!(i64, D));
422 fidl::decode!(i64, D, val_ref, decoder, inner_offset, inner_depth)?;
423 if !inlined && decoder.next_out_of_line() != next_out_of_line + (num_bytes as usize)
424 {
425 return Err(fidl::Error::InvalidNumBytesInEnvelope);
426 }
427 if handles_before != decoder.remaining_handles() + (num_handles as usize) {
428 return Err(fidl::Error::InvalidNumHandlesInEnvelope);
429 }
430 }
431
432 next_offset += envelope_size;
433 _next_ordinal_to_read += 1;
434 if next_offset >= end_offset {
435 return Ok(());
436 }
437
438 while _next_ordinal_to_read < 5 {
440 fidl::encoding::decode_unknown_envelope(decoder, next_offset, depth)?;
441 _next_ordinal_to_read += 1;
442 next_offset += envelope_size;
443 }
444
445 let next_out_of_line = decoder.next_out_of_line();
446 let handles_before = decoder.remaining_handles();
447 if let Some((inlined, num_bytes, num_handles)) =
448 fidl::encoding::decode_envelope_header(decoder, next_offset)?
449 {
450 let member_inline_size =
451 <i64 as fidl::encoding::TypeMarker>::inline_size(decoder.context);
452 if inlined != (member_inline_size <= 4) {
453 return Err(fidl::Error::InvalidInlineBitInEnvelope);
454 }
455 let inner_offset;
456 let mut inner_depth = depth.clone();
457 if inlined {
458 decoder.check_inline_envelope_padding(next_offset, member_inline_size)?;
459 inner_offset = next_offset;
460 } else {
461 inner_offset = decoder.out_of_line_offset(member_inline_size)?;
462 inner_depth.increment()?;
463 }
464 let val_ref = self
465 .last_time_in_suspend_operations
466 .get_or_insert_with(|| fidl::new_empty!(i64, D));
467 fidl::decode!(i64, D, val_ref, decoder, inner_offset, inner_depth)?;
468 if !inlined && decoder.next_out_of_line() != next_out_of_line + (num_bytes as usize)
469 {
470 return Err(fidl::Error::InvalidNumBytesInEnvelope);
471 }
472 if handles_before != decoder.remaining_handles() + (num_handles as usize) {
473 return Err(fidl::Error::InvalidNumHandlesInEnvelope);
474 }
475 }
476
477 next_offset += envelope_size;
478
479 while next_offset < end_offset {
481 _next_ordinal_to_read += 1;
482 fidl::encoding::decode_unknown_envelope(decoder, next_offset, depth)?;
483 next_offset += envelope_size;
484 }
485
486 Ok(())
487 }
488 }
489}