fidl_examples_keyvaluestore_usegenericvalues__common/
fidl_examples_keyvaluestore_usegenericvalues__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
11bitflags! {
12    #[derive(Clone, Copy, Debug, Default, PartialEq, Eq, PartialOrd, Ord, Hash)]
13    pub struct WriteOptions: u8 {
14        const OVERWRITE = 1;
15        const CONCAT = 2;
16    }
17}
18
19impl WriteOptions {
20    #[inline(always)]
21    pub fn from_bits_allow_unknown(bits: u8) -> Self {
22        Self::from_bits_retain(bits)
23    }
24
25    #[inline(always)]
26    pub fn has_unknown_bits(&self) -> bool {
27        self.get_unknown_bits() != 0
28    }
29
30    #[inline(always)]
31    pub fn get_unknown_bits(&self) -> u8 {
32        self.bits() & !Self::all().bits()
33    }
34}
35
36/// An enumeration of things that may go wrong when trying to write a value to our store.
37#[derive(Copy, Clone, Debug, Eq, PartialEq, Ord, PartialOrd, Hash)]
38pub enum WriteError {
39    Unknown,
40    InvalidKey,
41    InvalidValue,
42    AlreadyExists,
43    #[doc(hidden)]
44    __SourceBreaking {
45        unknown_ordinal: u32,
46    },
47}
48
49/// Pattern that matches an unknown `WriteError` member.
50#[macro_export]
51macro_rules! WriteErrorUnknown {
52    () => {
53        _
54    };
55}
56
57impl WriteError {
58    #[inline]
59    pub fn from_primitive(prim: u32) -> Option<Self> {
60        match prim {
61            0 => Some(Self::Unknown),
62            1 => Some(Self::InvalidKey),
63            2 => Some(Self::InvalidValue),
64            3 => Some(Self::AlreadyExists),
65            _ => None,
66        }
67    }
68
69    #[inline]
70    pub fn from_primitive_allow_unknown(prim: u32) -> Self {
71        match prim {
72            0 => Self::Unknown,
73            1 => Self::InvalidKey,
74            2 => Self::InvalidValue,
75            3 => Self::AlreadyExists,
76            unknown_ordinal => Self::__SourceBreaking { unknown_ordinal },
77        }
78    }
79
80    #[inline]
81    pub fn unknown() -> Self {
82        Self::__SourceBreaking { unknown_ordinal: 0xffffffff }
83    }
84
85    #[inline]
86    pub const fn into_primitive(self) -> u32 {
87        match self {
88            Self::Unknown => 0,
89            Self::InvalidKey => 1,
90            Self::InvalidValue => 2,
91            Self::AlreadyExists => 3,
92            Self::__SourceBreaking { unknown_ordinal } => unknown_ordinal,
93        }
94    }
95
96    #[inline]
97    pub fn is_unknown(&self) -> bool {
98        match self {
99            Self::__SourceBreaking { unknown_ordinal: _ } => true,
100            _ => false,
101        }
102    }
103}
104
105/// An item in the store. The key must match the regex `^[A-z][A-z0-9_\.\/]{2,62}[A-z0-9]$`. That
106/// is, it must start with a letter, end with a letter or number, contain only letters, numbers,
107/// periods, and slashes, and be between 4 and 64 characters long.
108#[derive(Clone, Debug, PartialEq)]
109pub struct Item {
110    pub key: String,
111    pub value: Value,
112}
113
114impl fidl::Persistable for Item {}
115
116#[derive(Clone, Debug, Default, PartialEq)]
117pub struct StoreWriteItemRequest {
118    pub attempt: Option<Item>,
119    pub options: Option<WriteOptions>,
120    #[doc(hidden)]
121    pub __source_breaking: fidl::marker::SourceBreaking,
122}
123
124impl fidl::Persistable for StoreWriteItemRequest {}
125
126#[derive(Clone, Debug)]
127pub enum Value {
128    Bytes(Vec<u8>),
129    String(String),
130    Bool(bool),
131    Uint8(u8),
132    Int8(i8),
133    Uint16(u16),
134    Int16(i16),
135    Uint32(u32),
136    Int32(i32),
137    Float32(f32),
138    Uint64(u64),
139    Int64(i64),
140    Float64(f64),
141    Uint128([u64; 2]),
142    #[doc(hidden)]
143    __SourceBreaking {
144        unknown_ordinal: u64,
145    },
146}
147
148/// Pattern that matches an unknown `Value` member.
149#[macro_export]
150macro_rules! ValueUnknown {
151    () => {
152        _
153    };
154}
155
156// Custom PartialEq so that unknown variants are not equal to themselves.
157impl PartialEq for Value {
158    fn eq(&self, other: &Self) -> bool {
159        match (self, other) {
160            (Self::Bytes(x), Self::Bytes(y)) => *x == *y,
161            (Self::String(x), Self::String(y)) => *x == *y,
162            (Self::Bool(x), Self::Bool(y)) => *x == *y,
163            (Self::Uint8(x), Self::Uint8(y)) => *x == *y,
164            (Self::Int8(x), Self::Int8(y)) => *x == *y,
165            (Self::Uint16(x), Self::Uint16(y)) => *x == *y,
166            (Self::Int16(x), Self::Int16(y)) => *x == *y,
167            (Self::Uint32(x), Self::Uint32(y)) => *x == *y,
168            (Self::Int32(x), Self::Int32(y)) => *x == *y,
169            (Self::Float32(x), Self::Float32(y)) => *x == *y,
170            (Self::Uint64(x), Self::Uint64(y)) => *x == *y,
171            (Self::Int64(x), Self::Int64(y)) => *x == *y,
172            (Self::Float64(x), Self::Float64(y)) => *x == *y,
173            (Self::Uint128(x), Self::Uint128(y)) => *x == *y,
174            _ => false,
175        }
176    }
177}
178
179impl Value {
180    #[inline]
181    pub fn ordinal(&self) -> u64 {
182        match *self {
183            Self::Bytes(_) => 1,
184            Self::String(_) => 2,
185            Self::Bool(_) => 3,
186            Self::Uint8(_) => 4,
187            Self::Int8(_) => 5,
188            Self::Uint16(_) => 6,
189            Self::Int16(_) => 7,
190            Self::Uint32(_) => 8,
191            Self::Int32(_) => 9,
192            Self::Float32(_) => 10,
193            Self::Uint64(_) => 11,
194            Self::Int64(_) => 12,
195            Self::Float64(_) => 13,
196            Self::Uint128(_) => 14,
197            Self::__SourceBreaking { unknown_ordinal } => unknown_ordinal,
198        }
199    }
200
201    #[inline]
202    pub fn unknown_variant_for_testing() -> Self {
203        Self::__SourceBreaking { unknown_ordinal: 0 }
204    }
205
206    #[inline]
207    pub fn is_unknown(&self) -> bool {
208        match self {
209            Self::__SourceBreaking { .. } => true,
210            _ => false,
211        }
212    }
213}
214
215impl fidl::Persistable for Value {}
216
217pub mod store_ordinals {
218    pub const WRITE_ITEM: u64 = 0xdbd4bf1e49abe6e;
219}
220
221mod internal {
222    use super::*;
223    unsafe impl fidl::encoding::TypeMarker for WriteOptions {
224        type Owned = Self;
225
226        #[inline(always)]
227        fn inline_align(_context: fidl::encoding::Context) -> usize {
228            1
229        }
230
231        #[inline(always)]
232        fn inline_size(_context: fidl::encoding::Context) -> usize {
233            1
234        }
235    }
236
237    impl fidl::encoding::ValueTypeMarker for WriteOptions {
238        type Borrowed<'a> = Self;
239        #[inline(always)]
240        fn borrow(value: &<Self as fidl::encoding::TypeMarker>::Owned) -> Self::Borrowed<'_> {
241            *value
242        }
243    }
244
245    unsafe impl<D: fidl::encoding::ResourceDialect> fidl::encoding::Encode<Self, D> for WriteOptions {
246        #[inline]
247        unsafe fn encode(
248            self,
249            encoder: &mut fidl::encoding::Encoder<'_, D>,
250            offset: usize,
251            _depth: fidl::encoding::Depth,
252        ) -> fidl::Result<()> {
253            encoder.debug_check_bounds::<Self>(offset);
254            encoder.write_num(self.bits(), offset);
255            Ok(())
256        }
257    }
258
259    impl<D: fidl::encoding::ResourceDialect> fidl::encoding::Decode<Self, D> for WriteOptions {
260        #[inline(always)]
261        fn new_empty() -> Self {
262            Self::empty()
263        }
264
265        #[inline]
266        unsafe fn decode(
267            &mut self,
268            decoder: &mut fidl::encoding::Decoder<'_, D>,
269            offset: usize,
270            _depth: fidl::encoding::Depth,
271        ) -> fidl::Result<()> {
272            decoder.debug_check_bounds::<Self>(offset);
273            let prim = decoder.read_num::<u8>(offset);
274            *self = Self::from_bits_allow_unknown(prim);
275            Ok(())
276        }
277    }
278    unsafe impl fidl::encoding::TypeMarker for WriteError {
279        type Owned = Self;
280
281        #[inline(always)]
282        fn inline_align(_context: fidl::encoding::Context) -> usize {
283            std::mem::align_of::<u32>()
284        }
285
286        #[inline(always)]
287        fn inline_size(_context: fidl::encoding::Context) -> usize {
288            std::mem::size_of::<u32>()
289        }
290
291        #[inline(always)]
292        fn encode_is_copy() -> bool {
293            false
294        }
295
296        #[inline(always)]
297        fn decode_is_copy() -> bool {
298            false
299        }
300    }
301
302    impl fidl::encoding::ValueTypeMarker for WriteError {
303        type Borrowed<'a> = Self;
304        #[inline(always)]
305        fn borrow(value: &<Self as fidl::encoding::TypeMarker>::Owned) -> Self::Borrowed<'_> {
306            *value
307        }
308    }
309
310    unsafe impl<D: fidl::encoding::ResourceDialect> fidl::encoding::Encode<Self, D> for WriteError {
311        #[inline]
312        unsafe fn encode(
313            self,
314            encoder: &mut fidl::encoding::Encoder<'_, D>,
315            offset: usize,
316            _depth: fidl::encoding::Depth,
317        ) -> fidl::Result<()> {
318            encoder.debug_check_bounds::<Self>(offset);
319            encoder.write_num(self.into_primitive(), offset);
320            Ok(())
321        }
322    }
323
324    impl<D: fidl::encoding::ResourceDialect> fidl::encoding::Decode<Self, D> for WriteError {
325        #[inline(always)]
326        fn new_empty() -> Self {
327            Self::unknown()
328        }
329
330        #[inline]
331        unsafe fn decode(
332            &mut self,
333            decoder: &mut fidl::encoding::Decoder<'_, D>,
334            offset: usize,
335            _depth: fidl::encoding::Depth,
336        ) -> fidl::Result<()> {
337            decoder.debug_check_bounds::<Self>(offset);
338            let prim = decoder.read_num::<u32>(offset);
339
340            *self = Self::from_primitive_allow_unknown(prim);
341            Ok(())
342        }
343    }
344
345    impl fidl::encoding::ValueTypeMarker for Item {
346        type Borrowed<'a> = &'a Self;
347        fn borrow(value: &<Self as fidl::encoding::TypeMarker>::Owned) -> Self::Borrowed<'_> {
348            value
349        }
350    }
351
352    unsafe impl fidl::encoding::TypeMarker for Item {
353        type Owned = Self;
354
355        #[inline(always)]
356        fn inline_align(_context: fidl::encoding::Context) -> usize {
357            8
358        }
359
360        #[inline(always)]
361        fn inline_size(_context: fidl::encoding::Context) -> usize {
362            32
363        }
364    }
365
366    unsafe impl<D: fidl::encoding::ResourceDialect> fidl::encoding::Encode<Item, D> for &Item {
367        #[inline]
368        unsafe fn encode(
369            self,
370            encoder: &mut fidl::encoding::Encoder<'_, D>,
371            offset: usize,
372            _depth: fidl::encoding::Depth,
373        ) -> fidl::Result<()> {
374            encoder.debug_check_bounds::<Item>(offset);
375            // Delegate to tuple encoding.
376            fidl::encoding::Encode::<Item, D>::encode(
377                (
378                    <fidl::encoding::BoundedString<128> as fidl::encoding::ValueTypeMarker>::borrow(
379                        &self.key,
380                    ),
381                    <Value as fidl::encoding::ValueTypeMarker>::borrow(&self.value),
382                ),
383                encoder,
384                offset,
385                _depth,
386            )
387        }
388    }
389    unsafe impl<
390            D: fidl::encoding::ResourceDialect,
391            T0: fidl::encoding::Encode<fidl::encoding::BoundedString<128>, D>,
392            T1: fidl::encoding::Encode<Value, D>,
393        > fidl::encoding::Encode<Item, D> for (T0, T1)
394    {
395        #[inline]
396        unsafe fn encode(
397            self,
398            encoder: &mut fidl::encoding::Encoder<'_, D>,
399            offset: usize,
400            depth: fidl::encoding::Depth,
401        ) -> fidl::Result<()> {
402            encoder.debug_check_bounds::<Item>(offset);
403            // Zero out padding regions. There's no need to apply masks
404            // because the unmasked parts will be overwritten by fields.
405            // Write the fields.
406            self.0.encode(encoder, offset + 0, depth)?;
407            self.1.encode(encoder, offset + 16, depth)?;
408            Ok(())
409        }
410    }
411
412    impl<D: fidl::encoding::ResourceDialect> fidl::encoding::Decode<Self, D> for Item {
413        #[inline(always)]
414        fn new_empty() -> Self {
415            Self {
416                key: fidl::new_empty!(fidl::encoding::BoundedString<128>, D),
417                value: fidl::new_empty!(Value, D),
418            }
419        }
420
421        #[inline]
422        unsafe fn decode(
423            &mut self,
424            decoder: &mut fidl::encoding::Decoder<'_, D>,
425            offset: usize,
426            _depth: fidl::encoding::Depth,
427        ) -> fidl::Result<()> {
428            decoder.debug_check_bounds::<Self>(offset);
429            // Verify that padding bytes are zero.
430            fidl::decode!(
431                fidl::encoding::BoundedString<128>,
432                D,
433                &mut self.key,
434                decoder,
435                offset + 0,
436                _depth
437            )?;
438            fidl::decode!(Value, D, &mut self.value, decoder, offset + 16, _depth)?;
439            Ok(())
440        }
441    }
442
443    impl StoreWriteItemRequest {
444        #[inline(always)]
445        fn max_ordinal_present(&self) -> u64 {
446            if let Some(_) = self.options {
447                return 2;
448            }
449            if let Some(_) = self.attempt {
450                return 1;
451            }
452            0
453        }
454    }
455
456    impl fidl::encoding::ValueTypeMarker for StoreWriteItemRequest {
457        type Borrowed<'a> = &'a Self;
458        fn borrow(value: &<Self as fidl::encoding::TypeMarker>::Owned) -> Self::Borrowed<'_> {
459            value
460        }
461    }
462
463    unsafe impl fidl::encoding::TypeMarker for StoreWriteItemRequest {
464        type Owned = Self;
465
466        #[inline(always)]
467        fn inline_align(_context: fidl::encoding::Context) -> usize {
468            8
469        }
470
471        #[inline(always)]
472        fn inline_size(_context: fidl::encoding::Context) -> usize {
473            16
474        }
475    }
476
477    unsafe impl<D: fidl::encoding::ResourceDialect> fidl::encoding::Encode<StoreWriteItemRequest, D>
478        for &StoreWriteItemRequest
479    {
480        unsafe fn encode(
481            self,
482            encoder: &mut fidl::encoding::Encoder<'_, D>,
483            offset: usize,
484            mut depth: fidl::encoding::Depth,
485        ) -> fidl::Result<()> {
486            encoder.debug_check_bounds::<StoreWriteItemRequest>(offset);
487            // Vector header
488            let max_ordinal: u64 = self.max_ordinal_present();
489            encoder.write_num(max_ordinal, offset);
490            encoder.write_num(fidl::encoding::ALLOC_PRESENT_U64, offset + 8);
491            // Calling encoder.out_of_line_offset(0) is not allowed.
492            if max_ordinal == 0 {
493                return Ok(());
494            }
495            depth.increment()?;
496            let envelope_size = 8;
497            let bytes_len = max_ordinal as usize * envelope_size;
498            #[allow(unused_variables)]
499            let offset = encoder.out_of_line_offset(bytes_len);
500            let mut _prev_end_offset: usize = 0;
501            if 1 > max_ordinal {
502                return Ok(());
503            }
504
505            // Write at offset+(ordinal-1)*envelope_size, since ordinals are one-based and envelopes
506            // are envelope_size bytes.
507            let cur_offset: usize = (1 - 1) * envelope_size;
508
509            // Zero reserved fields.
510            encoder.padding(offset + _prev_end_offset, cur_offset - _prev_end_offset);
511
512            // Safety:
513            // - bytes_len is calculated to fit envelope_size*max(member.ordinal).
514            // - Since cur_offset is envelope_size*(member.ordinal - 1) and the envelope takes
515            //   envelope_size bytes, there is always sufficient room.
516            fidl::encoding::encode_in_envelope_optional::<Item, D>(
517                self.attempt.as_ref().map(<Item as fidl::encoding::ValueTypeMarker>::borrow),
518                encoder,
519                offset + cur_offset,
520                depth,
521            )?;
522
523            _prev_end_offset = cur_offset + envelope_size;
524            if 2 > max_ordinal {
525                return Ok(());
526            }
527
528            // Write at offset+(ordinal-1)*envelope_size, since ordinals are one-based and envelopes
529            // are envelope_size bytes.
530            let cur_offset: usize = (2 - 1) * envelope_size;
531
532            // Zero reserved fields.
533            encoder.padding(offset + _prev_end_offset, cur_offset - _prev_end_offset);
534
535            // Safety:
536            // - bytes_len is calculated to fit envelope_size*max(member.ordinal).
537            // - Since cur_offset is envelope_size*(member.ordinal - 1) and the envelope takes
538            //   envelope_size bytes, there is always sufficient room.
539            fidl::encoding::encode_in_envelope_optional::<WriteOptions, D>(
540                self.options
541                    .as_ref()
542                    .map(<WriteOptions as fidl::encoding::ValueTypeMarker>::borrow),
543                encoder,
544                offset + cur_offset,
545                depth,
546            )?;
547
548            _prev_end_offset = cur_offset + envelope_size;
549
550            Ok(())
551        }
552    }
553
554    impl<D: fidl::encoding::ResourceDialect> fidl::encoding::Decode<Self, D> for StoreWriteItemRequest {
555        #[inline(always)]
556        fn new_empty() -> Self {
557            Self::default()
558        }
559
560        unsafe fn decode(
561            &mut self,
562            decoder: &mut fidl::encoding::Decoder<'_, D>,
563            offset: usize,
564            mut depth: fidl::encoding::Depth,
565        ) -> fidl::Result<()> {
566            decoder.debug_check_bounds::<Self>(offset);
567            let len = match fidl::encoding::decode_vector_header(decoder, offset)? {
568                None => return Err(fidl::Error::NotNullable),
569                Some(len) => len,
570            };
571            // Calling decoder.out_of_line_offset(0) is not allowed.
572            if len == 0 {
573                return Ok(());
574            };
575            depth.increment()?;
576            let envelope_size = 8;
577            let bytes_len = len * envelope_size;
578            let offset = decoder.out_of_line_offset(bytes_len)?;
579            // Decode the envelope for each type.
580            let mut _next_ordinal_to_read = 0;
581            let mut next_offset = offset;
582            let end_offset = offset + bytes_len;
583            _next_ordinal_to_read += 1;
584            if next_offset >= end_offset {
585                return Ok(());
586            }
587
588            // Decode unknown envelopes for gaps in ordinals.
589            while _next_ordinal_to_read < 1 {
590                fidl::encoding::decode_unknown_envelope(decoder, next_offset, depth)?;
591                _next_ordinal_to_read += 1;
592                next_offset += envelope_size;
593            }
594
595            let next_out_of_line = decoder.next_out_of_line();
596            let handles_before = decoder.remaining_handles();
597            if let Some((inlined, num_bytes, num_handles)) =
598                fidl::encoding::decode_envelope_header(decoder, next_offset)?
599            {
600                let member_inline_size =
601                    <Item as fidl::encoding::TypeMarker>::inline_size(decoder.context);
602                if inlined != (member_inline_size <= 4) {
603                    return Err(fidl::Error::InvalidInlineBitInEnvelope);
604                }
605                let inner_offset;
606                let mut inner_depth = depth.clone();
607                if inlined {
608                    decoder.check_inline_envelope_padding(next_offset, member_inline_size)?;
609                    inner_offset = next_offset;
610                } else {
611                    inner_offset = decoder.out_of_line_offset(member_inline_size)?;
612                    inner_depth.increment()?;
613                }
614                let val_ref = self.attempt.get_or_insert_with(|| fidl::new_empty!(Item, D));
615                fidl::decode!(Item, D, val_ref, decoder, inner_offset, inner_depth)?;
616                if !inlined && decoder.next_out_of_line() != next_out_of_line + (num_bytes as usize)
617                {
618                    return Err(fidl::Error::InvalidNumBytesInEnvelope);
619                }
620                if handles_before != decoder.remaining_handles() + (num_handles as usize) {
621                    return Err(fidl::Error::InvalidNumHandlesInEnvelope);
622                }
623            }
624
625            next_offset += envelope_size;
626            _next_ordinal_to_read += 1;
627            if next_offset >= end_offset {
628                return Ok(());
629            }
630
631            // Decode unknown envelopes for gaps in ordinals.
632            while _next_ordinal_to_read < 2 {
633                fidl::encoding::decode_unknown_envelope(decoder, next_offset, depth)?;
634                _next_ordinal_to_read += 1;
635                next_offset += envelope_size;
636            }
637
638            let next_out_of_line = decoder.next_out_of_line();
639            let handles_before = decoder.remaining_handles();
640            if let Some((inlined, num_bytes, num_handles)) =
641                fidl::encoding::decode_envelope_header(decoder, next_offset)?
642            {
643                let member_inline_size =
644                    <WriteOptions as fidl::encoding::TypeMarker>::inline_size(decoder.context);
645                if inlined != (member_inline_size <= 4) {
646                    return Err(fidl::Error::InvalidInlineBitInEnvelope);
647                }
648                let inner_offset;
649                let mut inner_depth = depth.clone();
650                if inlined {
651                    decoder.check_inline_envelope_padding(next_offset, member_inline_size)?;
652                    inner_offset = next_offset;
653                } else {
654                    inner_offset = decoder.out_of_line_offset(member_inline_size)?;
655                    inner_depth.increment()?;
656                }
657                let val_ref = self.options.get_or_insert_with(|| fidl::new_empty!(WriteOptions, D));
658                fidl::decode!(WriteOptions, D, val_ref, decoder, inner_offset, inner_depth)?;
659                if !inlined && decoder.next_out_of_line() != next_out_of_line + (num_bytes as usize)
660                {
661                    return Err(fidl::Error::InvalidNumBytesInEnvelope);
662                }
663                if handles_before != decoder.remaining_handles() + (num_handles as usize) {
664                    return Err(fidl::Error::InvalidNumHandlesInEnvelope);
665                }
666            }
667
668            next_offset += envelope_size;
669
670            // Decode the remaining unknown envelopes.
671            while next_offset < end_offset {
672                _next_ordinal_to_read += 1;
673                fidl::encoding::decode_unknown_envelope(decoder, next_offset, depth)?;
674                next_offset += envelope_size;
675            }
676
677            Ok(())
678        }
679    }
680
681    impl fidl::encoding::ValueTypeMarker for Value {
682        type Borrowed<'a> = &'a Self;
683        fn borrow(value: &<Self as fidl::encoding::TypeMarker>::Owned) -> Self::Borrowed<'_> {
684            value
685        }
686    }
687
688    unsafe impl fidl::encoding::TypeMarker for Value {
689        type Owned = Self;
690
691        #[inline(always)]
692        fn inline_align(_context: fidl::encoding::Context) -> usize {
693            8
694        }
695
696        #[inline(always)]
697        fn inline_size(_context: fidl::encoding::Context) -> usize {
698            16
699        }
700    }
701
702    unsafe impl<D: fidl::encoding::ResourceDialect> fidl::encoding::Encode<Value, D> for &Value {
703        #[inline]
704        unsafe fn encode(
705            self,
706            encoder: &mut fidl::encoding::Encoder<'_, D>,
707            offset: usize,
708            _depth: fidl::encoding::Depth,
709        ) -> fidl::Result<()> {
710            encoder.debug_check_bounds::<Value>(offset);
711            encoder.write_num::<u64>(self.ordinal(), offset);
712            match self {
713            Value::Bytes(ref val) => {
714                fidl::encoding::encode_in_envelope::<fidl::encoding::Vector<u8, 64000>, D>(
715                    <fidl::encoding::Vector<u8, 64000> as fidl::encoding::ValueTypeMarker>::borrow(val),
716                    encoder, offset + 8, _depth
717                )
718            }
719            Value::String(ref val) => {
720                fidl::encoding::encode_in_envelope::<fidl::encoding::BoundedString<64000>, D>(
721                    <fidl::encoding::BoundedString<64000> as fidl::encoding::ValueTypeMarker>::borrow(val),
722                    encoder, offset + 8, _depth
723                )
724            }
725            Value::Bool(ref val) => {
726                fidl::encoding::encode_in_envelope::<bool, D>(
727                    <bool as fidl::encoding::ValueTypeMarker>::borrow(val),
728                    encoder, offset + 8, _depth
729                )
730            }
731            Value::Uint8(ref val) => {
732                fidl::encoding::encode_in_envelope::<u8, D>(
733                    <u8 as fidl::encoding::ValueTypeMarker>::borrow(val),
734                    encoder, offset + 8, _depth
735                )
736            }
737            Value::Int8(ref val) => {
738                fidl::encoding::encode_in_envelope::<i8, D>(
739                    <i8 as fidl::encoding::ValueTypeMarker>::borrow(val),
740                    encoder, offset + 8, _depth
741                )
742            }
743            Value::Uint16(ref val) => {
744                fidl::encoding::encode_in_envelope::<u16, D>(
745                    <u16 as fidl::encoding::ValueTypeMarker>::borrow(val),
746                    encoder, offset + 8, _depth
747                )
748            }
749            Value::Int16(ref val) => {
750                fidl::encoding::encode_in_envelope::<i16, D>(
751                    <i16 as fidl::encoding::ValueTypeMarker>::borrow(val),
752                    encoder, offset + 8, _depth
753                )
754            }
755            Value::Uint32(ref val) => {
756                fidl::encoding::encode_in_envelope::<u32, D>(
757                    <u32 as fidl::encoding::ValueTypeMarker>::borrow(val),
758                    encoder, offset + 8, _depth
759                )
760            }
761            Value::Int32(ref val) => {
762                fidl::encoding::encode_in_envelope::<i32, D>(
763                    <i32 as fidl::encoding::ValueTypeMarker>::borrow(val),
764                    encoder, offset + 8, _depth
765                )
766            }
767            Value::Float32(ref val) => {
768                fidl::encoding::encode_in_envelope::<f32, D>(
769                    <f32 as fidl::encoding::ValueTypeMarker>::borrow(val),
770                    encoder, offset + 8, _depth
771                )
772            }
773            Value::Uint64(ref val) => {
774                fidl::encoding::encode_in_envelope::<u64, D>(
775                    <u64 as fidl::encoding::ValueTypeMarker>::borrow(val),
776                    encoder, offset + 8, _depth
777                )
778            }
779            Value::Int64(ref val) => {
780                fidl::encoding::encode_in_envelope::<i64, D>(
781                    <i64 as fidl::encoding::ValueTypeMarker>::borrow(val),
782                    encoder, offset + 8, _depth
783                )
784            }
785            Value::Float64(ref val) => {
786                fidl::encoding::encode_in_envelope::<f64, D>(
787                    <f64 as fidl::encoding::ValueTypeMarker>::borrow(val),
788                    encoder, offset + 8, _depth
789                )
790            }
791            Value::Uint128(ref val) => {
792                fidl::encoding::encode_in_envelope::<fidl::encoding::Array<u64, 2>, D>(
793                    <fidl::encoding::Array<u64, 2> as fidl::encoding::ValueTypeMarker>::borrow(val),
794                    encoder, offset + 8, _depth
795                )
796            }
797            Value::__SourceBreaking { .. } => Err(fidl::Error::UnknownUnionTag),
798        }
799        }
800    }
801
802    impl<D: fidl::encoding::ResourceDialect> fidl::encoding::Decode<Self, D> for Value {
803        #[inline(always)]
804        fn new_empty() -> Self {
805            Self::__SourceBreaking { unknown_ordinal: 0 }
806        }
807
808        #[inline]
809        unsafe fn decode(
810            &mut self,
811            decoder: &mut fidl::encoding::Decoder<'_, D>,
812            offset: usize,
813            mut depth: fidl::encoding::Depth,
814        ) -> fidl::Result<()> {
815            decoder.debug_check_bounds::<Self>(offset);
816            #[allow(unused_variables)]
817            let next_out_of_line = decoder.next_out_of_line();
818            let handles_before = decoder.remaining_handles();
819            let (ordinal, inlined, num_bytes, num_handles) =
820                fidl::encoding::decode_union_inline_portion(decoder, offset)?;
821
822            let member_inline_size = match ordinal {
823            1 => <fidl::encoding::Vector<u8, 64000> as fidl::encoding::TypeMarker>::inline_size(decoder.context),
824            2 => <fidl::encoding::BoundedString<64000> as fidl::encoding::TypeMarker>::inline_size(decoder.context),
825            3 => <bool as fidl::encoding::TypeMarker>::inline_size(decoder.context),
826            4 => <u8 as fidl::encoding::TypeMarker>::inline_size(decoder.context),
827            5 => <i8 as fidl::encoding::TypeMarker>::inline_size(decoder.context),
828            6 => <u16 as fidl::encoding::TypeMarker>::inline_size(decoder.context),
829            7 => <i16 as fidl::encoding::TypeMarker>::inline_size(decoder.context),
830            8 => <u32 as fidl::encoding::TypeMarker>::inline_size(decoder.context),
831            9 => <i32 as fidl::encoding::TypeMarker>::inline_size(decoder.context),
832            10 => <f32 as fidl::encoding::TypeMarker>::inline_size(decoder.context),
833            11 => <u64 as fidl::encoding::TypeMarker>::inline_size(decoder.context),
834            12 => <i64 as fidl::encoding::TypeMarker>::inline_size(decoder.context),
835            13 => <f64 as fidl::encoding::TypeMarker>::inline_size(decoder.context),
836            14 => <fidl::encoding::Array<u64, 2> as fidl::encoding::TypeMarker>::inline_size(decoder.context),
837            0 => return Err(fidl::Error::UnknownUnionTag),
838            _ => num_bytes as usize,
839        };
840
841            if inlined != (member_inline_size <= 4) {
842                return Err(fidl::Error::InvalidInlineBitInEnvelope);
843            }
844            let _inner_offset;
845            if inlined {
846                decoder.check_inline_envelope_padding(offset + 8, member_inline_size)?;
847                _inner_offset = offset + 8;
848            } else {
849                depth.increment()?;
850                _inner_offset = decoder.out_of_line_offset(member_inline_size)?;
851            }
852            match ordinal {
853                1 => {
854                    #[allow(irrefutable_let_patterns)]
855                    if let Value::Bytes(_) = self {
856                        // Do nothing, read the value into the object
857                    } else {
858                        // Initialize `self` to the right variant
859                        *self =
860                            Value::Bytes(fidl::new_empty!(fidl::encoding::Vector<u8, 64000>, D));
861                    }
862                    #[allow(irrefutable_let_patterns)]
863                    if let Value::Bytes(ref mut val) = self {
864                        fidl::decode!(fidl::encoding::Vector<u8, 64000>, D, val, decoder, _inner_offset, depth)?;
865                    } else {
866                        unreachable!()
867                    }
868                }
869                2 => {
870                    #[allow(irrefutable_let_patterns)]
871                    if let Value::String(_) = self {
872                        // Do nothing, read the value into the object
873                    } else {
874                        // Initialize `self` to the right variant
875                        *self = Value::String(fidl::new_empty!(
876                            fidl::encoding::BoundedString<64000>,
877                            D
878                        ));
879                    }
880                    #[allow(irrefutable_let_patterns)]
881                    if let Value::String(ref mut val) = self {
882                        fidl::decode!(
883                            fidl::encoding::BoundedString<64000>,
884                            D,
885                            val,
886                            decoder,
887                            _inner_offset,
888                            depth
889                        )?;
890                    } else {
891                        unreachable!()
892                    }
893                }
894                3 => {
895                    #[allow(irrefutable_let_patterns)]
896                    if let Value::Bool(_) = self {
897                        // Do nothing, read the value into the object
898                    } else {
899                        // Initialize `self` to the right variant
900                        *self = Value::Bool(fidl::new_empty!(bool, D));
901                    }
902                    #[allow(irrefutable_let_patterns)]
903                    if let Value::Bool(ref mut val) = self {
904                        fidl::decode!(bool, D, val, decoder, _inner_offset, depth)?;
905                    } else {
906                        unreachable!()
907                    }
908                }
909                4 => {
910                    #[allow(irrefutable_let_patterns)]
911                    if let Value::Uint8(_) = self {
912                        // Do nothing, read the value into the object
913                    } else {
914                        // Initialize `self` to the right variant
915                        *self = Value::Uint8(fidl::new_empty!(u8, D));
916                    }
917                    #[allow(irrefutable_let_patterns)]
918                    if let Value::Uint8(ref mut val) = self {
919                        fidl::decode!(u8, D, val, decoder, _inner_offset, depth)?;
920                    } else {
921                        unreachable!()
922                    }
923                }
924                5 => {
925                    #[allow(irrefutable_let_patterns)]
926                    if let Value::Int8(_) = self {
927                        // Do nothing, read the value into the object
928                    } else {
929                        // Initialize `self` to the right variant
930                        *self = Value::Int8(fidl::new_empty!(i8, D));
931                    }
932                    #[allow(irrefutable_let_patterns)]
933                    if let Value::Int8(ref mut val) = self {
934                        fidl::decode!(i8, D, val, decoder, _inner_offset, depth)?;
935                    } else {
936                        unreachable!()
937                    }
938                }
939                6 => {
940                    #[allow(irrefutable_let_patterns)]
941                    if let Value::Uint16(_) = self {
942                        // Do nothing, read the value into the object
943                    } else {
944                        // Initialize `self` to the right variant
945                        *self = Value::Uint16(fidl::new_empty!(u16, D));
946                    }
947                    #[allow(irrefutable_let_patterns)]
948                    if let Value::Uint16(ref mut val) = self {
949                        fidl::decode!(u16, D, val, decoder, _inner_offset, depth)?;
950                    } else {
951                        unreachable!()
952                    }
953                }
954                7 => {
955                    #[allow(irrefutable_let_patterns)]
956                    if let Value::Int16(_) = self {
957                        // Do nothing, read the value into the object
958                    } else {
959                        // Initialize `self` to the right variant
960                        *self = Value::Int16(fidl::new_empty!(i16, D));
961                    }
962                    #[allow(irrefutable_let_patterns)]
963                    if let Value::Int16(ref mut val) = self {
964                        fidl::decode!(i16, D, val, decoder, _inner_offset, depth)?;
965                    } else {
966                        unreachable!()
967                    }
968                }
969                8 => {
970                    #[allow(irrefutable_let_patterns)]
971                    if let Value::Uint32(_) = self {
972                        // Do nothing, read the value into the object
973                    } else {
974                        // Initialize `self` to the right variant
975                        *self = Value::Uint32(fidl::new_empty!(u32, D));
976                    }
977                    #[allow(irrefutable_let_patterns)]
978                    if let Value::Uint32(ref mut val) = self {
979                        fidl::decode!(u32, D, val, decoder, _inner_offset, depth)?;
980                    } else {
981                        unreachable!()
982                    }
983                }
984                9 => {
985                    #[allow(irrefutable_let_patterns)]
986                    if let Value::Int32(_) = self {
987                        // Do nothing, read the value into the object
988                    } else {
989                        // Initialize `self` to the right variant
990                        *self = Value::Int32(fidl::new_empty!(i32, D));
991                    }
992                    #[allow(irrefutable_let_patterns)]
993                    if let Value::Int32(ref mut val) = self {
994                        fidl::decode!(i32, D, val, decoder, _inner_offset, depth)?;
995                    } else {
996                        unreachable!()
997                    }
998                }
999                10 => {
1000                    #[allow(irrefutable_let_patterns)]
1001                    if let Value::Float32(_) = self {
1002                        // Do nothing, read the value into the object
1003                    } else {
1004                        // Initialize `self` to the right variant
1005                        *self = Value::Float32(fidl::new_empty!(f32, D));
1006                    }
1007                    #[allow(irrefutable_let_patterns)]
1008                    if let Value::Float32(ref mut val) = self {
1009                        fidl::decode!(f32, D, val, decoder, _inner_offset, depth)?;
1010                    } else {
1011                        unreachable!()
1012                    }
1013                }
1014                11 => {
1015                    #[allow(irrefutable_let_patterns)]
1016                    if let Value::Uint64(_) = self {
1017                        // Do nothing, read the value into the object
1018                    } else {
1019                        // Initialize `self` to the right variant
1020                        *self = Value::Uint64(fidl::new_empty!(u64, D));
1021                    }
1022                    #[allow(irrefutable_let_patterns)]
1023                    if let Value::Uint64(ref mut val) = self {
1024                        fidl::decode!(u64, D, val, decoder, _inner_offset, depth)?;
1025                    } else {
1026                        unreachable!()
1027                    }
1028                }
1029                12 => {
1030                    #[allow(irrefutable_let_patterns)]
1031                    if let Value::Int64(_) = self {
1032                        // Do nothing, read the value into the object
1033                    } else {
1034                        // Initialize `self` to the right variant
1035                        *self = Value::Int64(fidl::new_empty!(i64, D));
1036                    }
1037                    #[allow(irrefutable_let_patterns)]
1038                    if let Value::Int64(ref mut val) = self {
1039                        fidl::decode!(i64, D, val, decoder, _inner_offset, depth)?;
1040                    } else {
1041                        unreachable!()
1042                    }
1043                }
1044                13 => {
1045                    #[allow(irrefutable_let_patterns)]
1046                    if let Value::Float64(_) = self {
1047                        // Do nothing, read the value into the object
1048                    } else {
1049                        // Initialize `self` to the right variant
1050                        *self = Value::Float64(fidl::new_empty!(f64, D));
1051                    }
1052                    #[allow(irrefutable_let_patterns)]
1053                    if let Value::Float64(ref mut val) = self {
1054                        fidl::decode!(f64, D, val, decoder, _inner_offset, depth)?;
1055                    } else {
1056                        unreachable!()
1057                    }
1058                }
1059                14 => {
1060                    #[allow(irrefutable_let_patterns)]
1061                    if let Value::Uint128(_) = self {
1062                        // Do nothing, read the value into the object
1063                    } else {
1064                        // Initialize `self` to the right variant
1065                        *self = Value::Uint128(fidl::new_empty!(fidl::encoding::Array<u64, 2>, D));
1066                    }
1067                    #[allow(irrefutable_let_patterns)]
1068                    if let Value::Uint128(ref mut val) = self {
1069                        fidl::decode!(fidl::encoding::Array<u64, 2>, D, val, decoder, _inner_offset, depth)?;
1070                    } else {
1071                        unreachable!()
1072                    }
1073                }
1074                #[allow(deprecated)]
1075                ordinal => {
1076                    for _ in 0..num_handles {
1077                        decoder.drop_next_handle()?;
1078                    }
1079                    *self = Value::__SourceBreaking { unknown_ordinal: ordinal };
1080                }
1081            }
1082            if !inlined && decoder.next_out_of_line() != next_out_of_line + (num_bytes as usize) {
1083                return Err(fidl::Error::InvalidNumBytesInEnvelope);
1084            }
1085            if handles_before != decoder.remaining_handles() + (num_handles as usize) {
1086                return Err(fidl::Error::InvalidNumHandlesInEnvelope);
1087            }
1088            Ok(())
1089        }
1090    }
1091}