Skip to main content

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