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