fidl_fuchsia_element_manager_persistence/
fidl_fuchsia_element_manager_persistence.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::client::QueryResponseFut;
8use fidl::encoding::{MessageBufFor, ProxyChannelBox, ResourceDialect};
9use fidl::endpoints::{ControlHandle as _, Responder as _};
10use futures::future::{self, MaybeDone, TryFutureExt};
11use zx_status;
12
13/// Same as Annotation but can be persisted.
14#[derive(Clone, Debug, PartialEq)]
15pub struct PersistentAnnotation {
16    /// An identifier for this annotation.
17    pub key: fidl_fuchsia_element::AnnotationKey,
18    /// The content of this annotation.
19    pub value: PersistentAnnotationValue,
20}
21
22impl fidl::Persistable for PersistentAnnotation {}
23
24/// Each element is described by its annotations. As a minimum this will include the elements name
25/// and the component URL.
26#[derive(Clone, Debug, Default, PartialEq)]
27pub struct Element {
28    pub annotations: Option<Vec<PersistentAnnotation>>,
29    #[doc(hidden)]
30    pub __source_breaking: fidl::marker::SourceBreaking,
31}
32
33impl fidl::Persistable for Element {}
34
35/// Element Manager stores this top-level object (a list of persistent elements to launch at boot
36/// time) in persistent storage.
37#[derive(Clone, Debug, Default, PartialEq)]
38pub struct PersistentElements {
39    pub elements: Option<Vec<Element>>,
40    #[doc(hidden)]
41    pub __source_breaking: fidl::marker::SourceBreaking,
42}
43
44impl fidl::Persistable for PersistentElements {}
45
46/// Same as AnnotationValue but can be persisted.
47#[derive(Clone, Debug, Eq, Hash, Ord, PartialEq, PartialOrd)]
48pub enum PersistentAnnotationValue {
49    Text(String),
50}
51
52impl PersistentAnnotationValue {
53    #[inline]
54    pub fn ordinal(&self) -> u64 {
55        match *self {
56            Self::Text(_) => 1,
57        }
58    }
59
60    #[deprecated = "Strict unions should not use `is_unknown`"]
61    #[inline]
62    pub fn is_unknown(&self) -> bool {
63        false
64    }
65}
66
67impl fidl::Persistable for PersistentAnnotationValue {}
68
69mod internal {
70    use super::*;
71
72    impl fidl::encoding::ValueTypeMarker for PersistentAnnotation {
73        type Borrowed<'a> = &'a Self;
74        fn borrow(value: &<Self as fidl::encoding::TypeMarker>::Owned) -> Self::Borrowed<'_> {
75            value
76        }
77    }
78
79    unsafe impl fidl::encoding::TypeMarker for PersistentAnnotation {
80        type Owned = Self;
81
82        #[inline(always)]
83        fn inline_align(_context: fidl::encoding::Context) -> usize {
84            8
85        }
86
87        #[inline(always)]
88        fn inline_size(_context: fidl::encoding::Context) -> usize {
89            48
90        }
91    }
92
93    unsafe impl<D: fidl::encoding::ResourceDialect> fidl::encoding::Encode<PersistentAnnotation, D>
94        for &PersistentAnnotation
95    {
96        #[inline]
97        unsafe fn encode(
98            self,
99            encoder: &mut fidl::encoding::Encoder<'_, D>,
100            offset: usize,
101            _depth: fidl::encoding::Depth,
102        ) -> fidl::Result<()> {
103            encoder.debug_check_bounds::<PersistentAnnotation>(offset);
104            // Delegate to tuple encoding.
105            fidl::encoding::Encode::<PersistentAnnotation, D>::encode(
106                (
107                    <fidl_fuchsia_element::AnnotationKey as fidl::encoding::ValueTypeMarker>::borrow(&self.key),
108                    <PersistentAnnotationValue as fidl::encoding::ValueTypeMarker>::borrow(&self.value),
109                ),
110                encoder, offset, _depth
111            )
112        }
113    }
114    unsafe impl<
115            D: fidl::encoding::ResourceDialect,
116            T0: fidl::encoding::Encode<fidl_fuchsia_element::AnnotationKey, D>,
117            T1: fidl::encoding::Encode<PersistentAnnotationValue, D>,
118        > fidl::encoding::Encode<PersistentAnnotation, D> for (T0, T1)
119    {
120        #[inline]
121        unsafe fn encode(
122            self,
123            encoder: &mut fidl::encoding::Encoder<'_, D>,
124            offset: usize,
125            depth: fidl::encoding::Depth,
126        ) -> fidl::Result<()> {
127            encoder.debug_check_bounds::<PersistentAnnotation>(offset);
128            // Zero out padding regions. There's no need to apply masks
129            // because the unmasked parts will be overwritten by fields.
130            // Write the fields.
131            self.0.encode(encoder, offset + 0, depth)?;
132            self.1.encode(encoder, offset + 32, depth)?;
133            Ok(())
134        }
135    }
136
137    impl<D: fidl::encoding::ResourceDialect> fidl::encoding::Decode<Self, D> for PersistentAnnotation {
138        #[inline(always)]
139        fn new_empty() -> Self {
140            Self {
141                key: fidl::new_empty!(fidl_fuchsia_element::AnnotationKey, D),
142                value: fidl::new_empty!(PersistentAnnotationValue, D),
143            }
144        }
145
146        #[inline]
147        unsafe fn decode(
148            &mut self,
149            decoder: &mut fidl::encoding::Decoder<'_, D>,
150            offset: usize,
151            _depth: fidl::encoding::Depth,
152        ) -> fidl::Result<()> {
153            decoder.debug_check_bounds::<Self>(offset);
154            // Verify that padding bytes are zero.
155            fidl::decode!(
156                fidl_fuchsia_element::AnnotationKey,
157                D,
158                &mut self.key,
159                decoder,
160                offset + 0,
161                _depth
162            )?;
163            fidl::decode!(
164                PersistentAnnotationValue,
165                D,
166                &mut self.value,
167                decoder,
168                offset + 32,
169                _depth
170            )?;
171            Ok(())
172        }
173    }
174
175    impl Element {
176        #[inline(always)]
177        fn max_ordinal_present(&self) -> u64 {
178            if let Some(_) = self.annotations {
179                return 1;
180            }
181            0
182        }
183    }
184
185    impl fidl::encoding::ValueTypeMarker for Element {
186        type Borrowed<'a> = &'a Self;
187        fn borrow(value: &<Self as fidl::encoding::TypeMarker>::Owned) -> Self::Borrowed<'_> {
188            value
189        }
190    }
191
192    unsafe impl fidl::encoding::TypeMarker for Element {
193        type Owned = Self;
194
195        #[inline(always)]
196        fn inline_align(_context: fidl::encoding::Context) -> usize {
197            8
198        }
199
200        #[inline(always)]
201        fn inline_size(_context: fidl::encoding::Context) -> usize {
202            16
203        }
204    }
205
206    unsafe impl<D: fidl::encoding::ResourceDialect> fidl::encoding::Encode<Element, D> for &Element {
207        unsafe fn encode(
208            self,
209            encoder: &mut fidl::encoding::Encoder<'_, D>,
210            offset: usize,
211            mut depth: fidl::encoding::Depth,
212        ) -> fidl::Result<()> {
213            encoder.debug_check_bounds::<Element>(offset);
214            // Vector header
215            let max_ordinal: u64 = self.max_ordinal_present();
216            encoder.write_num(max_ordinal, offset);
217            encoder.write_num(fidl::encoding::ALLOC_PRESENT_U64, offset + 8);
218            // Calling encoder.out_of_line_offset(0) is not allowed.
219            if max_ordinal == 0 {
220                return Ok(());
221            }
222            depth.increment()?;
223            let envelope_size = 8;
224            let bytes_len = max_ordinal as usize * envelope_size;
225            #[allow(unused_variables)]
226            let offset = encoder.out_of_line_offset(bytes_len);
227            let mut _prev_end_offset: usize = 0;
228            if 1 > max_ordinal {
229                return Ok(());
230            }
231
232            // Write at offset+(ordinal-1)*envelope_size, since ordinals are one-based and envelopes
233            // are envelope_size bytes.
234            let cur_offset: usize = (1 - 1) * envelope_size;
235
236            // Zero reserved fields.
237            encoder.padding(offset + _prev_end_offset, cur_offset - _prev_end_offset);
238
239            // Safety:
240            // - bytes_len is calculated to fit envelope_size*max(member.ordinal).
241            // - Since cur_offset is envelope_size*(member.ordinal - 1) and the envelope takes
242            //   envelope_size bytes, there is always sufficient room.
243            fidl::encoding::encode_in_envelope_optional::<fidl::encoding::UnboundedVector<PersistentAnnotation>, D>(
244            self.annotations.as_ref().map(<fidl::encoding::UnboundedVector<PersistentAnnotation> as fidl::encoding::ValueTypeMarker>::borrow),
245            encoder, offset + cur_offset, depth
246        )?;
247
248            _prev_end_offset = cur_offset + envelope_size;
249
250            Ok(())
251        }
252    }
253
254    impl<D: fidl::encoding::ResourceDialect> fidl::encoding::Decode<Self, D> for Element {
255        #[inline(always)]
256        fn new_empty() -> Self {
257            Self::default()
258        }
259
260        unsafe fn decode(
261            &mut self,
262            decoder: &mut fidl::encoding::Decoder<'_, D>,
263            offset: usize,
264            mut depth: fidl::encoding::Depth,
265        ) -> fidl::Result<()> {
266            decoder.debug_check_bounds::<Self>(offset);
267            let len = match fidl::encoding::decode_vector_header(decoder, offset)? {
268                None => return Err(fidl::Error::NotNullable),
269                Some(len) => len,
270            };
271            // Calling decoder.out_of_line_offset(0) is not allowed.
272            if len == 0 {
273                return Ok(());
274            };
275            depth.increment()?;
276            let envelope_size = 8;
277            let bytes_len = len * envelope_size;
278            let offset = decoder.out_of_line_offset(bytes_len)?;
279            // Decode the envelope for each type.
280            let mut _next_ordinal_to_read = 0;
281            let mut next_offset = offset;
282            let end_offset = offset + bytes_len;
283            _next_ordinal_to_read += 1;
284            if next_offset >= end_offset {
285                return Ok(());
286            }
287
288            // Decode unknown envelopes for gaps in ordinals.
289            while _next_ordinal_to_read < 1 {
290                fidl::encoding::decode_unknown_envelope(decoder, next_offset, depth)?;
291                _next_ordinal_to_read += 1;
292                next_offset += envelope_size;
293            }
294
295            let next_out_of_line = decoder.next_out_of_line();
296            let handles_before = decoder.remaining_handles();
297            if let Some((inlined, num_bytes, num_handles)) =
298                fidl::encoding::decode_envelope_header(decoder, next_offset)?
299            {
300                let member_inline_size = <fidl::encoding::UnboundedVector<PersistentAnnotation> as fidl::encoding::TypeMarker>::inline_size(decoder.context);
301                if inlined != (member_inline_size <= 4) {
302                    return Err(fidl::Error::InvalidInlineBitInEnvelope);
303                }
304                let inner_offset;
305                let mut inner_depth = depth.clone();
306                if inlined {
307                    decoder.check_inline_envelope_padding(next_offset, member_inline_size)?;
308                    inner_offset = next_offset;
309                } else {
310                    inner_offset = decoder.out_of_line_offset(member_inline_size)?;
311                    inner_depth.increment()?;
312                }
313                let val_ref = self.annotations.get_or_insert_with(|| {
314                    fidl::new_empty!(fidl::encoding::UnboundedVector<PersistentAnnotation>, D)
315                });
316                fidl::decode!(
317                    fidl::encoding::UnboundedVector<PersistentAnnotation>,
318                    D,
319                    val_ref,
320                    decoder,
321                    inner_offset,
322                    inner_depth
323                )?;
324                if !inlined && decoder.next_out_of_line() != next_out_of_line + (num_bytes as usize)
325                {
326                    return Err(fidl::Error::InvalidNumBytesInEnvelope);
327                }
328                if handles_before != decoder.remaining_handles() + (num_handles as usize) {
329                    return Err(fidl::Error::InvalidNumHandlesInEnvelope);
330                }
331            }
332
333            next_offset += envelope_size;
334
335            // Decode the remaining unknown envelopes.
336            while next_offset < end_offset {
337                _next_ordinal_to_read += 1;
338                fidl::encoding::decode_unknown_envelope(decoder, next_offset, depth)?;
339                next_offset += envelope_size;
340            }
341
342            Ok(())
343        }
344    }
345
346    impl PersistentElements {
347        #[inline(always)]
348        fn max_ordinal_present(&self) -> u64 {
349            if let Some(_) = self.elements {
350                return 1;
351            }
352            0
353        }
354    }
355
356    impl fidl::encoding::ValueTypeMarker for PersistentElements {
357        type Borrowed<'a> = &'a Self;
358        fn borrow(value: &<Self as fidl::encoding::TypeMarker>::Owned) -> Self::Borrowed<'_> {
359            value
360        }
361    }
362
363    unsafe impl fidl::encoding::TypeMarker for PersistentElements {
364        type Owned = Self;
365
366        #[inline(always)]
367        fn inline_align(_context: fidl::encoding::Context) -> usize {
368            8
369        }
370
371        #[inline(always)]
372        fn inline_size(_context: fidl::encoding::Context) -> usize {
373            16
374        }
375    }
376
377    unsafe impl<D: fidl::encoding::ResourceDialect> fidl::encoding::Encode<PersistentElements, D>
378        for &PersistentElements
379    {
380        unsafe fn encode(
381            self,
382            encoder: &mut fidl::encoding::Encoder<'_, D>,
383            offset: usize,
384            mut depth: fidl::encoding::Depth,
385        ) -> fidl::Result<()> {
386            encoder.debug_check_bounds::<PersistentElements>(offset);
387            // Vector header
388            let max_ordinal: u64 = self.max_ordinal_present();
389            encoder.write_num(max_ordinal, offset);
390            encoder.write_num(fidl::encoding::ALLOC_PRESENT_U64, offset + 8);
391            // Calling encoder.out_of_line_offset(0) is not allowed.
392            if max_ordinal == 0 {
393                return Ok(());
394            }
395            depth.increment()?;
396            let envelope_size = 8;
397            let bytes_len = max_ordinal as usize * envelope_size;
398            #[allow(unused_variables)]
399            let offset = encoder.out_of_line_offset(bytes_len);
400            let mut _prev_end_offset: usize = 0;
401            if 1 > max_ordinal {
402                return Ok(());
403            }
404
405            // Write at offset+(ordinal-1)*envelope_size, since ordinals are one-based and envelopes
406            // are envelope_size bytes.
407            let cur_offset: usize = (1 - 1) * envelope_size;
408
409            // Zero reserved fields.
410            encoder.padding(offset + _prev_end_offset, cur_offset - _prev_end_offset);
411
412            // Safety:
413            // - bytes_len is calculated to fit envelope_size*max(member.ordinal).
414            // - Since cur_offset is envelope_size*(member.ordinal - 1) and the envelope takes
415            //   envelope_size bytes, there is always sufficient room.
416            fidl::encoding::encode_in_envelope_optional::<fidl::encoding::UnboundedVector<Element>, D>(
417            self.elements.as_ref().map(<fidl::encoding::UnboundedVector<Element> as fidl::encoding::ValueTypeMarker>::borrow),
418            encoder, offset + cur_offset, depth
419        )?;
420
421            _prev_end_offset = cur_offset + envelope_size;
422
423            Ok(())
424        }
425    }
426
427    impl<D: fidl::encoding::ResourceDialect> fidl::encoding::Decode<Self, D> for PersistentElements {
428        #[inline(always)]
429        fn new_empty() -> Self {
430            Self::default()
431        }
432
433        unsafe fn decode(
434            &mut self,
435            decoder: &mut fidl::encoding::Decoder<'_, D>,
436            offset: usize,
437            mut depth: fidl::encoding::Depth,
438        ) -> fidl::Result<()> {
439            decoder.debug_check_bounds::<Self>(offset);
440            let len = match fidl::encoding::decode_vector_header(decoder, offset)? {
441                None => return Err(fidl::Error::NotNullable),
442                Some(len) => len,
443            };
444            // Calling decoder.out_of_line_offset(0) is not allowed.
445            if len == 0 {
446                return Ok(());
447            };
448            depth.increment()?;
449            let envelope_size = 8;
450            let bytes_len = len * envelope_size;
451            let offset = decoder.out_of_line_offset(bytes_len)?;
452            // Decode the envelope for each type.
453            let mut _next_ordinal_to_read = 0;
454            let mut next_offset = offset;
455            let end_offset = offset + bytes_len;
456            _next_ordinal_to_read += 1;
457            if next_offset >= end_offset {
458                return Ok(());
459            }
460
461            // Decode unknown envelopes for gaps in ordinals.
462            while _next_ordinal_to_read < 1 {
463                fidl::encoding::decode_unknown_envelope(decoder, next_offset, depth)?;
464                _next_ordinal_to_read += 1;
465                next_offset += envelope_size;
466            }
467
468            let next_out_of_line = decoder.next_out_of_line();
469            let handles_before = decoder.remaining_handles();
470            if let Some((inlined, num_bytes, num_handles)) =
471                fidl::encoding::decode_envelope_header(decoder, next_offset)?
472            {
473                let member_inline_size = <fidl::encoding::UnboundedVector<Element> as fidl::encoding::TypeMarker>::inline_size(decoder.context);
474                if inlined != (member_inline_size <= 4) {
475                    return Err(fidl::Error::InvalidInlineBitInEnvelope);
476                }
477                let inner_offset;
478                let mut inner_depth = depth.clone();
479                if inlined {
480                    decoder.check_inline_envelope_padding(next_offset, member_inline_size)?;
481                    inner_offset = next_offset;
482                } else {
483                    inner_offset = decoder.out_of_line_offset(member_inline_size)?;
484                    inner_depth.increment()?;
485                }
486                let val_ref = self.elements.get_or_insert_with(|| {
487                    fidl::new_empty!(fidl::encoding::UnboundedVector<Element>, D)
488                });
489                fidl::decode!(
490                    fidl::encoding::UnboundedVector<Element>,
491                    D,
492                    val_ref,
493                    decoder,
494                    inner_offset,
495                    inner_depth
496                )?;
497                if !inlined && decoder.next_out_of_line() != next_out_of_line + (num_bytes as usize)
498                {
499                    return Err(fidl::Error::InvalidNumBytesInEnvelope);
500                }
501                if handles_before != decoder.remaining_handles() + (num_handles as usize) {
502                    return Err(fidl::Error::InvalidNumHandlesInEnvelope);
503                }
504            }
505
506            next_offset += envelope_size;
507
508            // Decode the remaining unknown envelopes.
509            while next_offset < end_offset {
510                _next_ordinal_to_read += 1;
511                fidl::encoding::decode_unknown_envelope(decoder, next_offset, depth)?;
512                next_offset += envelope_size;
513            }
514
515            Ok(())
516        }
517    }
518
519    impl fidl::encoding::ValueTypeMarker for PersistentAnnotationValue {
520        type Borrowed<'a> = &'a Self;
521        fn borrow(value: &<Self as fidl::encoding::TypeMarker>::Owned) -> Self::Borrowed<'_> {
522            value
523        }
524    }
525
526    unsafe impl fidl::encoding::TypeMarker for PersistentAnnotationValue {
527        type Owned = Self;
528
529        #[inline(always)]
530        fn inline_align(_context: fidl::encoding::Context) -> usize {
531            8
532        }
533
534        #[inline(always)]
535        fn inline_size(_context: fidl::encoding::Context) -> usize {
536            16
537        }
538    }
539
540    unsafe impl<D: fidl::encoding::ResourceDialect>
541        fidl::encoding::Encode<PersistentAnnotationValue, D> for &PersistentAnnotationValue
542    {
543        #[inline]
544        unsafe fn encode(
545            self,
546            encoder: &mut fidl::encoding::Encoder<'_, D>,
547            offset: usize,
548            _depth: fidl::encoding::Depth,
549        ) -> fidl::Result<()> {
550            encoder.debug_check_bounds::<PersistentAnnotationValue>(offset);
551            encoder.write_num::<u64>(self.ordinal(), offset);
552            match self {
553                PersistentAnnotationValue::Text(ref val) => fidl::encoding::encode_in_envelope::<
554                    fidl::encoding::UnboundedString,
555                    D,
556                >(
557                    <fidl::encoding::UnboundedString as fidl::encoding::ValueTypeMarker>::borrow(
558                        val,
559                    ),
560                    encoder,
561                    offset + 8,
562                    _depth,
563                ),
564            }
565        }
566    }
567
568    impl<D: fidl::encoding::ResourceDialect> fidl::encoding::Decode<Self, D>
569        for PersistentAnnotationValue
570    {
571        #[inline(always)]
572        fn new_empty() -> Self {
573            Self::Text(fidl::new_empty!(fidl::encoding::UnboundedString, D))
574        }
575
576        #[inline]
577        unsafe fn decode(
578            &mut self,
579            decoder: &mut fidl::encoding::Decoder<'_, D>,
580            offset: usize,
581            mut depth: fidl::encoding::Depth,
582        ) -> fidl::Result<()> {
583            decoder.debug_check_bounds::<Self>(offset);
584            #[allow(unused_variables)]
585            let next_out_of_line = decoder.next_out_of_line();
586            let handles_before = decoder.remaining_handles();
587            let (ordinal, inlined, num_bytes, num_handles) =
588                fidl::encoding::decode_union_inline_portion(decoder, offset)?;
589
590            let member_inline_size = match ordinal {
591                1 => <fidl::encoding::UnboundedString as fidl::encoding::TypeMarker>::inline_size(
592                    decoder.context,
593                ),
594                _ => return Err(fidl::Error::UnknownUnionTag),
595            };
596
597            if inlined != (member_inline_size <= 4) {
598                return Err(fidl::Error::InvalidInlineBitInEnvelope);
599            }
600            let _inner_offset;
601            if inlined {
602                decoder.check_inline_envelope_padding(offset + 8, member_inline_size)?;
603                _inner_offset = offset + 8;
604            } else {
605                depth.increment()?;
606                _inner_offset = decoder.out_of_line_offset(member_inline_size)?;
607            }
608            match ordinal {
609                1 => {
610                    #[allow(irrefutable_let_patterns)]
611                    if let PersistentAnnotationValue::Text(_) = self {
612                        // Do nothing, read the value into the object
613                    } else {
614                        // Initialize `self` to the right variant
615                        *self = PersistentAnnotationValue::Text(fidl::new_empty!(
616                            fidl::encoding::UnboundedString,
617                            D
618                        ));
619                    }
620                    #[allow(irrefutable_let_patterns)]
621                    if let PersistentAnnotationValue::Text(ref mut val) = self {
622                        fidl::decode!(
623                            fidl::encoding::UnboundedString,
624                            D,
625                            val,
626                            decoder,
627                            _inner_offset,
628                            depth
629                        )?;
630                    } else {
631                        unreachable!()
632                    }
633                }
634                ordinal => panic!("unexpected ordinal {:?}", ordinal),
635            }
636            if !inlined && decoder.next_out_of_line() != next_out_of_line + (num_bytes as usize) {
637                return Err(fidl::Error::InvalidNumBytesInEnvelope);
638            }
639            if handles_before != decoder.remaining_handles() + (num_handles as usize) {
640                return Err(fidl::Error::InvalidNumHandlesInEnvelope);
641            }
642            Ok(())
643        }
644    }
645}