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