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