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