Skip to main content

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