Skip to main content

fidl_fuchsia_hardware_power_stats_common/
fidl_fuchsia_hardware_power_stats_common.rs

1// WARNING: This file is machine generated by fidlgen.
2
3#![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
11pub const MAX_NAME_LEN: u8 = 64;
12
13/// A representation of a platform subsystem, peripheral or power domain that impacts the total device power consumption.
14#[derive(Clone, Debug, Eq, Hash, Ord, PartialEq, PartialOrd)]
15pub struct Entity {
16    /// Unique name.
17    pub name: String,
18    /// All possible states.
19    pub states: Vec<State>,
20}
21
22impl fidl::Persistable for Entity {}
23
24/// A representation that a power entity may reside in.
25#[derive(Clone, Debug, Eq, Hash, Ord, PartialEq, PartialOrd)]
26pub struct State {
27    /// Unique id internally created by the server.
28    pub id: i32,
29    /// Unique name.
30    pub name: String,
31}
32
33impl fidl::Persistable for State {}
34
35#[derive(Clone, Debug, Eq, Hash, Ord, PartialEq, PartialOrd)]
36pub struct StateResidency {
37    /// Unique id of the State.
38    pub id: i32,
39    /// Unique name of the state.
40    pub name: String,
41    /// Total time in milliseconds that the corresponding PowerEntity resided
42    /// in this state since boot.
43    pub total_time_ms: u64,
44    ///  Total number of times that the state was entered since boot.
45    pub entry_count: u32,
46    /// Last time this state was entered, in milliseconds on the boot timeline
47    /// (see `zx_clock_get_boot`), or 0 if the provider does not track it.
48    pub last_entry_timestamp_ms: u64,
49}
50
51impl fidl::Persistable for StateResidency {}
52
53/// A state residencies result for a power entity.
54#[derive(Clone, Debug, Eq, Hash, Ord, PartialEq, PartialOrd)]
55pub struct Stats {
56    /// Name of the PowerEntity.
57    pub entity: String,
58    pub state_residency_data: Vec<StateResidency>,
59}
60
61impl fidl::Persistable for Stats {}
62
63pub mod device_ordinals {
64    pub const GET_STATS: u64 = 0x57fe9346ac73f056;
65    pub const GET_ENTITIES: u64 = 0xc34340e0675de11;
66}
67
68mod internal {
69    use super::*;
70
71    impl fidl::encoding::ValueTypeMarker for Entity {
72        type Borrowed<'a> = &'a Self;
73        fn borrow(value: &<Self as fidl::encoding::TypeMarker>::Owned) -> Self::Borrowed<'_> {
74            value
75        }
76    }
77
78    unsafe impl fidl::encoding::TypeMarker for Entity {
79        type Owned = Self;
80
81        #[inline(always)]
82        fn inline_align(_context: fidl::encoding::Context) -> usize {
83            8
84        }
85
86        #[inline(always)]
87        fn inline_size(_context: fidl::encoding::Context) -> usize {
88            32
89        }
90    }
91
92    unsafe impl<D: fidl::encoding::ResourceDialect> fidl::encoding::Encode<Entity, D> for &Entity {
93        #[inline]
94        unsafe fn encode(
95            self,
96            encoder: &mut fidl::encoding::Encoder<'_, D>,
97            offset: usize,
98            _depth: fidl::encoding::Depth,
99        ) -> fidl::Result<()> {
100            encoder.debug_check_bounds::<Entity>(offset);
101            // Delegate to tuple encoding.
102            fidl::encoding::Encode::<Entity, D>::encode(
103                (
104                    <fidl::encoding::BoundedString<64> as fidl::encoding::ValueTypeMarker>::borrow(&self.name),
105                    <fidl::encoding::UnboundedVector<State> as fidl::encoding::ValueTypeMarker>::borrow(&self.states),
106                ),
107                encoder, offset, _depth
108            )
109        }
110    }
111    unsafe impl<
112        D: fidl::encoding::ResourceDialect,
113        T0: fidl::encoding::Encode<fidl::encoding::BoundedString<64>, D>,
114        T1: fidl::encoding::Encode<fidl::encoding::UnboundedVector<State>, D>,
115    > fidl::encoding::Encode<Entity, D> for (T0, T1)
116    {
117        #[inline]
118        unsafe fn encode(
119            self,
120            encoder: &mut fidl::encoding::Encoder<'_, D>,
121            offset: usize,
122            depth: fidl::encoding::Depth,
123        ) -> fidl::Result<()> {
124            encoder.debug_check_bounds::<Entity>(offset);
125            // Zero out padding regions. There's no need to apply masks
126            // because the unmasked parts will be overwritten by fields.
127            // Write the fields.
128            self.0.encode(encoder, offset + 0, depth)?;
129            self.1.encode(encoder, offset + 16, depth)?;
130            Ok(())
131        }
132    }
133
134    impl<D: fidl::encoding::ResourceDialect> fidl::encoding::Decode<Self, D> for Entity {
135        #[inline(always)]
136        fn new_empty() -> Self {
137            Self {
138                name: fidl::new_empty!(fidl::encoding::BoundedString<64>, D),
139                states: fidl::new_empty!(fidl::encoding::UnboundedVector<State>, D),
140            }
141        }
142
143        #[inline]
144        unsafe fn decode(
145            &mut self,
146            decoder: &mut fidl::encoding::Decoder<'_, D>,
147            offset: usize,
148            _depth: fidl::encoding::Depth,
149        ) -> fidl::Result<()> {
150            decoder.debug_check_bounds::<Self>(offset);
151            // Verify that padding bytes are zero.
152            fidl::decode!(
153                fidl::encoding::BoundedString<64>,
154                D,
155                &mut self.name,
156                decoder,
157                offset + 0,
158                _depth
159            )?;
160            fidl::decode!(
161                fidl::encoding::UnboundedVector<State>,
162                D,
163                &mut self.states,
164                decoder,
165                offset + 16,
166                _depth
167            )?;
168            Ok(())
169        }
170    }
171
172    impl fidl::encoding::ValueTypeMarker for State {
173        type Borrowed<'a> = &'a Self;
174        fn borrow(value: &<Self as fidl::encoding::TypeMarker>::Owned) -> Self::Borrowed<'_> {
175            value
176        }
177    }
178
179    unsafe impl fidl::encoding::TypeMarker for State {
180        type Owned = Self;
181
182        #[inline(always)]
183        fn inline_align(_context: fidl::encoding::Context) -> usize {
184            8
185        }
186
187        #[inline(always)]
188        fn inline_size(_context: fidl::encoding::Context) -> usize {
189            24
190        }
191    }
192
193    unsafe impl<D: fidl::encoding::ResourceDialect> fidl::encoding::Encode<State, D> for &State {
194        #[inline]
195        unsafe fn encode(
196            self,
197            encoder: &mut fidl::encoding::Encoder<'_, D>,
198            offset: usize,
199            _depth: fidl::encoding::Depth,
200        ) -> fidl::Result<()> {
201            encoder.debug_check_bounds::<State>(offset);
202            // Delegate to tuple encoding.
203            fidl::encoding::Encode::<State, D>::encode(
204                (
205                    <i32 as fidl::encoding::ValueTypeMarker>::borrow(&self.id),
206                    <fidl::encoding::BoundedString<64> as fidl::encoding::ValueTypeMarker>::borrow(
207                        &self.name,
208                    ),
209                ),
210                encoder,
211                offset,
212                _depth,
213            )
214        }
215    }
216    unsafe impl<
217        D: fidl::encoding::ResourceDialect,
218        T0: fidl::encoding::Encode<i32, D>,
219        T1: fidl::encoding::Encode<fidl::encoding::BoundedString<64>, D>,
220    > fidl::encoding::Encode<State, D> for (T0, T1)
221    {
222        #[inline]
223        unsafe fn encode(
224            self,
225            encoder: &mut fidl::encoding::Encoder<'_, D>,
226            offset: usize,
227            depth: fidl::encoding::Depth,
228        ) -> fidl::Result<()> {
229            encoder.debug_check_bounds::<State>(offset);
230            // Zero out padding regions. There's no need to apply masks
231            // because the unmasked parts will be overwritten by fields.
232            unsafe {
233                let ptr = encoder.buf.as_mut_ptr().add(offset).offset(0);
234                (ptr as *mut u64).write_unaligned(0);
235            }
236            // Write the fields.
237            self.0.encode(encoder, offset + 0, depth)?;
238            self.1.encode(encoder, offset + 8, depth)?;
239            Ok(())
240        }
241    }
242
243    impl<D: fidl::encoding::ResourceDialect> fidl::encoding::Decode<Self, D> for State {
244        #[inline(always)]
245        fn new_empty() -> Self {
246            Self {
247                id: fidl::new_empty!(i32, D),
248                name: fidl::new_empty!(fidl::encoding::BoundedString<64>, D),
249            }
250        }
251
252        #[inline]
253        unsafe fn decode(
254            &mut self,
255            decoder: &mut fidl::encoding::Decoder<'_, D>,
256            offset: usize,
257            _depth: fidl::encoding::Depth,
258        ) -> fidl::Result<()> {
259            decoder.debug_check_bounds::<Self>(offset);
260            // Verify that padding bytes are zero.
261            let ptr = unsafe { decoder.buf.as_ptr().add(offset).offset(0) };
262            let padval = unsafe { (ptr as *const u64).read_unaligned() };
263            let mask = 0xffffffff00000000u64;
264            let maskedval = padval & mask;
265            if maskedval != 0 {
266                return Err(fidl::Error::NonZeroPadding {
267                    padding_start: offset + 0 + ((mask as u64).trailing_zeros() / 8) as usize,
268                });
269            }
270            fidl::decode!(i32, D, &mut self.id, decoder, offset + 0, _depth)?;
271            fidl::decode!(
272                fidl::encoding::BoundedString<64>,
273                D,
274                &mut self.name,
275                decoder,
276                offset + 8,
277                _depth
278            )?;
279            Ok(())
280        }
281    }
282
283    impl fidl::encoding::ValueTypeMarker for StateResidency {
284        type Borrowed<'a> = &'a Self;
285        fn borrow(value: &<Self as fidl::encoding::TypeMarker>::Owned) -> Self::Borrowed<'_> {
286            value
287        }
288    }
289
290    unsafe impl fidl::encoding::TypeMarker for StateResidency {
291        type Owned = Self;
292
293        #[inline(always)]
294        fn inline_align(_context: fidl::encoding::Context) -> usize {
295            8
296        }
297
298        #[inline(always)]
299        fn inline_size(_context: fidl::encoding::Context) -> usize {
300            48
301        }
302    }
303
304    unsafe impl<D: fidl::encoding::ResourceDialect> fidl::encoding::Encode<StateResidency, D>
305        for &StateResidency
306    {
307        #[inline]
308        unsafe fn encode(
309            self,
310            encoder: &mut fidl::encoding::Encoder<'_, D>,
311            offset: usize,
312            _depth: fidl::encoding::Depth,
313        ) -> fidl::Result<()> {
314            encoder.debug_check_bounds::<StateResidency>(offset);
315            // Delegate to tuple encoding.
316            fidl::encoding::Encode::<StateResidency, D>::encode(
317                (
318                    <i32 as fidl::encoding::ValueTypeMarker>::borrow(&self.id),
319                    <fidl::encoding::BoundedString<64> as fidl::encoding::ValueTypeMarker>::borrow(
320                        &self.name,
321                    ),
322                    <u64 as fidl::encoding::ValueTypeMarker>::borrow(&self.total_time_ms),
323                    <u32 as fidl::encoding::ValueTypeMarker>::borrow(&self.entry_count),
324                    <u64 as fidl::encoding::ValueTypeMarker>::borrow(&self.last_entry_timestamp_ms),
325                ),
326                encoder,
327                offset,
328                _depth,
329            )
330        }
331    }
332    unsafe impl<
333        D: fidl::encoding::ResourceDialect,
334        T0: fidl::encoding::Encode<i32, D>,
335        T1: fidl::encoding::Encode<fidl::encoding::BoundedString<64>, D>,
336        T2: fidl::encoding::Encode<u64, D>,
337        T3: fidl::encoding::Encode<u32, D>,
338        T4: fidl::encoding::Encode<u64, D>,
339    > fidl::encoding::Encode<StateResidency, D> for (T0, T1, T2, T3, T4)
340    {
341        #[inline]
342        unsafe fn encode(
343            self,
344            encoder: &mut fidl::encoding::Encoder<'_, D>,
345            offset: usize,
346            depth: fidl::encoding::Depth,
347        ) -> fidl::Result<()> {
348            encoder.debug_check_bounds::<StateResidency>(offset);
349            // Zero out padding regions. There's no need to apply masks
350            // because the unmasked parts will be overwritten by fields.
351            unsafe {
352                let ptr = encoder.buf.as_mut_ptr().add(offset).offset(0);
353                (ptr as *mut u64).write_unaligned(0);
354            }
355            unsafe {
356                let ptr = encoder.buf.as_mut_ptr().add(offset).offset(32);
357                (ptr as *mut u64).write_unaligned(0);
358            }
359            // Write the fields.
360            self.0.encode(encoder, offset + 0, depth)?;
361            self.1.encode(encoder, offset + 8, depth)?;
362            self.2.encode(encoder, offset + 24, depth)?;
363            self.3.encode(encoder, offset + 32, depth)?;
364            self.4.encode(encoder, offset + 40, depth)?;
365            Ok(())
366        }
367    }
368
369    impl<D: fidl::encoding::ResourceDialect> fidl::encoding::Decode<Self, D> for StateResidency {
370        #[inline(always)]
371        fn new_empty() -> Self {
372            Self {
373                id: fidl::new_empty!(i32, D),
374                name: fidl::new_empty!(fidl::encoding::BoundedString<64>, D),
375                total_time_ms: fidl::new_empty!(u64, D),
376                entry_count: fidl::new_empty!(u32, D),
377                last_entry_timestamp_ms: fidl::new_empty!(u64, D),
378            }
379        }
380
381        #[inline]
382        unsafe fn decode(
383            &mut self,
384            decoder: &mut fidl::encoding::Decoder<'_, D>,
385            offset: usize,
386            _depth: fidl::encoding::Depth,
387        ) -> fidl::Result<()> {
388            decoder.debug_check_bounds::<Self>(offset);
389            // Verify that padding bytes are zero.
390            let ptr = unsafe { decoder.buf.as_ptr().add(offset).offset(0) };
391            let padval = unsafe { (ptr as *const u64).read_unaligned() };
392            let mask = 0xffffffff00000000u64;
393            let maskedval = padval & mask;
394            if maskedval != 0 {
395                return Err(fidl::Error::NonZeroPadding {
396                    padding_start: offset + 0 + ((mask as u64).trailing_zeros() / 8) as usize,
397                });
398            }
399            let ptr = unsafe { decoder.buf.as_ptr().add(offset).offset(32) };
400            let padval = unsafe { (ptr as *const u64).read_unaligned() };
401            let mask = 0xffffffff00000000u64;
402            let maskedval = padval & mask;
403            if maskedval != 0 {
404                return Err(fidl::Error::NonZeroPadding {
405                    padding_start: offset + 32 + ((mask as u64).trailing_zeros() / 8) as usize,
406                });
407            }
408            fidl::decode!(i32, D, &mut self.id, decoder, offset + 0, _depth)?;
409            fidl::decode!(
410                fidl::encoding::BoundedString<64>,
411                D,
412                &mut self.name,
413                decoder,
414                offset + 8,
415                _depth
416            )?;
417            fidl::decode!(u64, D, &mut self.total_time_ms, decoder, offset + 24, _depth)?;
418            fidl::decode!(u32, D, &mut self.entry_count, decoder, offset + 32, _depth)?;
419            fidl::decode!(u64, D, &mut self.last_entry_timestamp_ms, decoder, offset + 40, _depth)?;
420            Ok(())
421        }
422    }
423
424    impl fidl::encoding::ValueTypeMarker for Stats {
425        type Borrowed<'a> = &'a Self;
426        fn borrow(value: &<Self as fidl::encoding::TypeMarker>::Owned) -> Self::Borrowed<'_> {
427            value
428        }
429    }
430
431    unsafe impl fidl::encoding::TypeMarker for Stats {
432        type Owned = Self;
433
434        #[inline(always)]
435        fn inline_align(_context: fidl::encoding::Context) -> usize {
436            8
437        }
438
439        #[inline(always)]
440        fn inline_size(_context: fidl::encoding::Context) -> usize {
441            32
442        }
443    }
444
445    unsafe impl<D: fidl::encoding::ResourceDialect> fidl::encoding::Encode<Stats, D> for &Stats {
446        #[inline]
447        unsafe fn encode(
448            self,
449            encoder: &mut fidl::encoding::Encoder<'_, D>,
450            offset: usize,
451            _depth: fidl::encoding::Depth,
452        ) -> fidl::Result<()> {
453            encoder.debug_check_bounds::<Stats>(offset);
454            // Delegate to tuple encoding.
455            fidl::encoding::Encode::<Stats, D>::encode(
456                (
457                    <fidl::encoding::BoundedString<64> as fidl::encoding::ValueTypeMarker>::borrow(&self.entity),
458                    <fidl::encoding::UnboundedVector<StateResidency> as fidl::encoding::ValueTypeMarker>::borrow(&self.state_residency_data),
459                ),
460                encoder, offset, _depth
461            )
462        }
463    }
464    unsafe impl<
465        D: fidl::encoding::ResourceDialect,
466        T0: fidl::encoding::Encode<fidl::encoding::BoundedString<64>, D>,
467        T1: fidl::encoding::Encode<fidl::encoding::UnboundedVector<StateResidency>, D>,
468    > fidl::encoding::Encode<Stats, D> for (T0, T1)
469    {
470        #[inline]
471        unsafe fn encode(
472            self,
473            encoder: &mut fidl::encoding::Encoder<'_, D>,
474            offset: usize,
475            depth: fidl::encoding::Depth,
476        ) -> fidl::Result<()> {
477            encoder.debug_check_bounds::<Stats>(offset);
478            // Zero out padding regions. There's no need to apply masks
479            // because the unmasked parts will be overwritten by fields.
480            // Write the fields.
481            self.0.encode(encoder, offset + 0, depth)?;
482            self.1.encode(encoder, offset + 16, depth)?;
483            Ok(())
484        }
485    }
486
487    impl<D: fidl::encoding::ResourceDialect> fidl::encoding::Decode<Self, D> for Stats {
488        #[inline(always)]
489        fn new_empty() -> Self {
490            Self {
491                entity: fidl::new_empty!(fidl::encoding::BoundedString<64>, D),
492                state_residency_data: fidl::new_empty!(
493                    fidl::encoding::UnboundedVector<StateResidency>,
494                    D
495                ),
496            }
497        }
498
499        #[inline]
500        unsafe fn decode(
501            &mut self,
502            decoder: &mut fidl::encoding::Decoder<'_, D>,
503            offset: usize,
504            _depth: fidl::encoding::Depth,
505        ) -> fidl::Result<()> {
506            decoder.debug_check_bounds::<Self>(offset);
507            // Verify that padding bytes are zero.
508            fidl::decode!(
509                fidl::encoding::BoundedString<64>,
510                D,
511                &mut self.entity,
512                decoder,
513                offset + 0,
514                _depth
515            )?;
516            fidl::decode!(
517                fidl::encoding::UnboundedVector<StateResidency>,
518                D,
519                &mut self.state_residency_data,
520                decoder,
521                offset + 16,
522                _depth
523            )?;
524            Ok(())
525        }
526    }
527}