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