Skip to main content

fidl_fuchsia_driver_metadata_common/
fidl_fuchsia_driver_metadata_common.rs

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