fidl_test_sagcontrol__common/
fidl_test_sagcontrol__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
11/// Errors associated with SetSystemActivityGovernorState methods.
12#[derive(Copy, Clone, Debug, Eq, PartialEq, Ord, PartialOrd, Hash)]
13#[repr(u32)]
14pub enum SetSystemActivityGovernorStateError {
15    /// Indicates that the requested state is not supported by SAG's power
16    /// tooplogy.
17    NotSupported = 1,
18    /// Indicates that the request failed due to an internal error.
19    Internal = 2,
20}
21
22impl SetSystemActivityGovernorStateError {
23    #[inline]
24    pub fn from_primitive(prim: u32) -> Option<Self> {
25        match prim {
26            1 => Some(Self::NotSupported),
27            2 => Some(Self::Internal),
28            _ => None,
29        }
30    }
31
32    #[inline]
33    pub const fn into_primitive(self) -> u32 {
34        self as u32
35    }
36}
37
38#[derive(Clone, Debug, Default, PartialEq)]
39pub struct SystemActivityGovernorState {
40    pub execution_state_level: Option<fidl_fuchsia_power_system__common::ExecutionStateLevel>,
41    pub application_activity_level:
42        Option<fidl_fuchsia_power_system__common::ApplicationActivityLevel>,
43    #[doc(hidden)]
44    pub __source_breaking: fidl::marker::SourceBreaking,
45}
46
47impl fidl::Persistable for SystemActivityGovernorState {}
48
49mod internal {
50    use super::*;
51    unsafe impl fidl::encoding::TypeMarker for SetSystemActivityGovernorStateError {
52        type Owned = Self;
53
54        #[inline(always)]
55        fn inline_align(_context: fidl::encoding::Context) -> usize {
56            std::mem::align_of::<u32>()
57        }
58
59        #[inline(always)]
60        fn inline_size(_context: fidl::encoding::Context) -> usize {
61            std::mem::size_of::<u32>()
62        }
63
64        #[inline(always)]
65        fn encode_is_copy() -> bool {
66            true
67        }
68
69        #[inline(always)]
70        fn decode_is_copy() -> bool {
71            false
72        }
73    }
74
75    impl fidl::encoding::ValueTypeMarker for SetSystemActivityGovernorStateError {
76        type Borrowed<'a> = Self;
77        #[inline(always)]
78        fn borrow(value: &<Self as fidl::encoding::TypeMarker>::Owned) -> Self::Borrowed<'_> {
79            *value
80        }
81    }
82
83    unsafe impl<D: fidl::encoding::ResourceDialect> fidl::encoding::Encode<Self, D>
84        for SetSystemActivityGovernorStateError
85    {
86        #[inline]
87        unsafe fn encode(
88            self,
89            encoder: &mut fidl::encoding::Encoder<'_, D>,
90            offset: usize,
91            _depth: fidl::encoding::Depth,
92        ) -> fidl::Result<()> {
93            encoder.debug_check_bounds::<Self>(offset);
94            encoder.write_num(self.into_primitive(), offset);
95            Ok(())
96        }
97    }
98
99    impl<D: fidl::encoding::ResourceDialect> fidl::encoding::Decode<Self, D>
100        for SetSystemActivityGovernorStateError
101    {
102        #[inline(always)]
103        fn new_empty() -> Self {
104            Self::NotSupported
105        }
106
107        #[inline]
108        unsafe fn decode(
109            &mut self,
110            decoder: &mut fidl::encoding::Decoder<'_, D>,
111            offset: usize,
112            _depth: fidl::encoding::Depth,
113        ) -> fidl::Result<()> {
114            decoder.debug_check_bounds::<Self>(offset);
115            let prim = decoder.read_num::<u32>(offset);
116
117            *self = Self::from_primitive(prim).ok_or(fidl::Error::InvalidEnumValue)?;
118            Ok(())
119        }
120    }
121
122    impl SystemActivityGovernorState {
123        #[inline(always)]
124        fn max_ordinal_present(&self) -> u64 {
125            if let Some(_) = self.application_activity_level {
126                return 2;
127            }
128            if let Some(_) = self.execution_state_level {
129                return 1;
130            }
131            0
132        }
133    }
134
135    impl fidl::encoding::ValueTypeMarker for SystemActivityGovernorState {
136        type Borrowed<'a> = &'a Self;
137        fn borrow(value: &<Self as fidl::encoding::TypeMarker>::Owned) -> Self::Borrowed<'_> {
138            value
139        }
140    }
141
142    unsafe impl fidl::encoding::TypeMarker for SystemActivityGovernorState {
143        type Owned = Self;
144
145        #[inline(always)]
146        fn inline_align(_context: fidl::encoding::Context) -> usize {
147            8
148        }
149
150        #[inline(always)]
151        fn inline_size(_context: fidl::encoding::Context) -> usize {
152            16
153        }
154    }
155
156    unsafe impl<D: fidl::encoding::ResourceDialect>
157        fidl::encoding::Encode<SystemActivityGovernorState, D> for &SystemActivityGovernorState
158    {
159        unsafe fn encode(
160            self,
161            encoder: &mut fidl::encoding::Encoder<'_, D>,
162            offset: usize,
163            mut depth: fidl::encoding::Depth,
164        ) -> fidl::Result<()> {
165            encoder.debug_check_bounds::<SystemActivityGovernorState>(offset);
166            // Vector header
167            let max_ordinal: u64 = self.max_ordinal_present();
168            encoder.write_num(max_ordinal, offset);
169            encoder.write_num(fidl::encoding::ALLOC_PRESENT_U64, offset + 8);
170            // Calling encoder.out_of_line_offset(0) is not allowed.
171            if max_ordinal == 0 {
172                return Ok(());
173            }
174            depth.increment()?;
175            let envelope_size = 8;
176            let bytes_len = max_ordinal as usize * envelope_size;
177            #[allow(unused_variables)]
178            let offset = encoder.out_of_line_offset(bytes_len);
179            let mut _prev_end_offset: usize = 0;
180            if 1 > max_ordinal {
181                return Ok(());
182            }
183
184            // Write at offset+(ordinal-1)*envelope_size, since ordinals are one-based and envelopes
185            // are envelope_size bytes.
186            let cur_offset: usize = (1 - 1) * envelope_size;
187
188            // Zero reserved fields.
189            encoder.padding(offset + _prev_end_offset, cur_offset - _prev_end_offset);
190
191            // Safety:
192            // - bytes_len is calculated to fit envelope_size*max(member.ordinal).
193            // - Since cur_offset is envelope_size*(member.ordinal - 1) and the envelope takes
194            //   envelope_size bytes, there is always sufficient room.
195            fidl::encoding::encode_in_envelope_optional::<fidl_fuchsia_power_system__common::ExecutionStateLevel, D>(
196            self.execution_state_level.as_ref().map(<fidl_fuchsia_power_system__common::ExecutionStateLevel as fidl::encoding::ValueTypeMarker>::borrow),
197            encoder, offset + cur_offset, depth
198        )?;
199
200            _prev_end_offset = cur_offset + envelope_size;
201            if 2 > max_ordinal {
202                return Ok(());
203            }
204
205            // Write at offset+(ordinal-1)*envelope_size, since ordinals are one-based and envelopes
206            // are envelope_size bytes.
207            let cur_offset: usize = (2 - 1) * envelope_size;
208
209            // Zero reserved fields.
210            encoder.padding(offset + _prev_end_offset, cur_offset - _prev_end_offset);
211
212            // Safety:
213            // - bytes_len is calculated to fit envelope_size*max(member.ordinal).
214            // - Since cur_offset is envelope_size*(member.ordinal - 1) and the envelope takes
215            //   envelope_size bytes, there is always sufficient room.
216            fidl::encoding::encode_in_envelope_optional::<fidl_fuchsia_power_system__common::ApplicationActivityLevel, D>(
217            self.application_activity_level.as_ref().map(<fidl_fuchsia_power_system__common::ApplicationActivityLevel as fidl::encoding::ValueTypeMarker>::borrow),
218            encoder, offset + cur_offset, depth
219        )?;
220
221            _prev_end_offset = cur_offset + envelope_size;
222
223            Ok(())
224        }
225    }
226
227    impl<D: fidl::encoding::ResourceDialect> fidl::encoding::Decode<Self, D>
228        for SystemActivityGovernorState
229    {
230        #[inline(always)]
231        fn new_empty() -> Self {
232            Self::default()
233        }
234
235        unsafe fn decode(
236            &mut self,
237            decoder: &mut fidl::encoding::Decoder<'_, D>,
238            offset: usize,
239            mut depth: fidl::encoding::Depth,
240        ) -> fidl::Result<()> {
241            decoder.debug_check_bounds::<Self>(offset);
242            let len = match fidl::encoding::decode_vector_header(decoder, offset)? {
243                None => return Err(fidl::Error::NotNullable),
244                Some(len) => len,
245            };
246            // Calling decoder.out_of_line_offset(0) is not allowed.
247            if len == 0 {
248                return Ok(());
249            };
250            depth.increment()?;
251            let envelope_size = 8;
252            let bytes_len = len * envelope_size;
253            let offset = decoder.out_of_line_offset(bytes_len)?;
254            // Decode the envelope for each type.
255            let mut _next_ordinal_to_read = 0;
256            let mut next_offset = offset;
257            let end_offset = offset + bytes_len;
258            _next_ordinal_to_read += 1;
259            if next_offset >= end_offset {
260                return Ok(());
261            }
262
263            // Decode unknown envelopes for gaps in ordinals.
264            while _next_ordinal_to_read < 1 {
265                fidl::encoding::decode_unknown_envelope(decoder, next_offset, depth)?;
266                _next_ordinal_to_read += 1;
267                next_offset += envelope_size;
268            }
269
270            let next_out_of_line = decoder.next_out_of_line();
271            let handles_before = decoder.remaining_handles();
272            if let Some((inlined, num_bytes, num_handles)) =
273                fidl::encoding::decode_envelope_header(decoder, next_offset)?
274            {
275                let member_inline_size = <fidl_fuchsia_power_system__common::ExecutionStateLevel as fidl::encoding::TypeMarker>::inline_size(decoder.context);
276                if inlined != (member_inline_size <= 4) {
277                    return Err(fidl::Error::InvalidInlineBitInEnvelope);
278                }
279                let inner_offset;
280                let mut inner_depth = depth.clone();
281                if inlined {
282                    decoder.check_inline_envelope_padding(next_offset, member_inline_size)?;
283                    inner_offset = next_offset;
284                } else {
285                    inner_offset = decoder.out_of_line_offset(member_inline_size)?;
286                    inner_depth.increment()?;
287                }
288                let val_ref = self.execution_state_level.get_or_insert_with(|| {
289                    fidl::new_empty!(fidl_fuchsia_power_system__common::ExecutionStateLevel, D)
290                });
291                fidl::decode!(
292                    fidl_fuchsia_power_system__common::ExecutionStateLevel,
293                    D,
294                    val_ref,
295                    decoder,
296                    inner_offset,
297                    inner_depth
298                )?;
299                if !inlined && decoder.next_out_of_line() != next_out_of_line + (num_bytes as usize)
300                {
301                    return Err(fidl::Error::InvalidNumBytesInEnvelope);
302                }
303                if handles_before != decoder.remaining_handles() + (num_handles as usize) {
304                    return Err(fidl::Error::InvalidNumHandlesInEnvelope);
305                }
306            }
307
308            next_offset += envelope_size;
309            _next_ordinal_to_read += 1;
310            if next_offset >= end_offset {
311                return Ok(());
312            }
313
314            // Decode unknown envelopes for gaps in ordinals.
315            while _next_ordinal_to_read < 2 {
316                fidl::encoding::decode_unknown_envelope(decoder, next_offset, depth)?;
317                _next_ordinal_to_read += 1;
318                next_offset += envelope_size;
319            }
320
321            let next_out_of_line = decoder.next_out_of_line();
322            let handles_before = decoder.remaining_handles();
323            if let Some((inlined, num_bytes, num_handles)) =
324                fidl::encoding::decode_envelope_header(decoder, next_offset)?
325            {
326                let member_inline_size = <fidl_fuchsia_power_system__common::ApplicationActivityLevel as fidl::encoding::TypeMarker>::inline_size(decoder.context);
327                if inlined != (member_inline_size <= 4) {
328                    return Err(fidl::Error::InvalidInlineBitInEnvelope);
329                }
330                let inner_offset;
331                let mut inner_depth = depth.clone();
332                if inlined {
333                    decoder.check_inline_envelope_padding(next_offset, member_inline_size)?;
334                    inner_offset = next_offset;
335                } else {
336                    inner_offset = decoder.out_of_line_offset(member_inline_size)?;
337                    inner_depth.increment()?;
338                }
339                let val_ref = self.application_activity_level.get_or_insert_with(|| {
340                    fidl::new_empty!(fidl_fuchsia_power_system__common::ApplicationActivityLevel, D)
341                });
342                fidl::decode!(
343                    fidl_fuchsia_power_system__common::ApplicationActivityLevel,
344                    D,
345                    val_ref,
346                    decoder,
347                    inner_offset,
348                    inner_depth
349                )?;
350                if !inlined && decoder.next_out_of_line() != next_out_of_line + (num_bytes as usize)
351                {
352                    return Err(fidl::Error::InvalidNumBytesInEnvelope);
353                }
354                if handles_before != decoder.remaining_handles() + (num_handles as usize) {
355                    return Err(fidl::Error::InvalidNumHandlesInEnvelope);
356                }
357            }
358
359            next_offset += envelope_size;
360
361            // Decode the remaining unknown envelopes.
362            while next_offset < end_offset {
363                _next_ordinal_to_read += 1;
364                fidl::encoding::decode_unknown_envelope(decoder, next_offset, depth)?;
365                next_offset += envelope_size;
366            }
367
368            Ok(())
369        }
370    }
371}