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
278pub mod echo_handle_protocol_ordinals {
279    pub const ECHO_HANDLE_REQUEST_RESPONSE_REDUCED_RIGHTS: u64 = 0x5c6c0f3032f3bcc6;
280    pub const ECHO_HANDLE_REQUEST_REDUCED_RIGHTS: u64 = 0x6f73455d31eb2f42;
281    pub const ECHO_HANDLE_REQUEST_SAME_RIGHTS: u64 = 0x7bd6b869de1eb0b7;
282    pub const ECHO_HANDLE_RESPONSE_REDUCED_RIGHTS: u64 = 0x458d1c6d39e34f1e;
283    pub const ECHO_HANDLE_RESPONSE_SAME_RIGHTS: u64 = 0x57334c827816fe5;
284}
285
286pub mod error_syntax_protocol_ordinals {
287    pub const TEST_ERROR_SYNTAX: u64 = 0x3fcbffd51b21cd91;
288}
289
290pub mod push_event_protocol_ordinals {
291    pub const PUSH_EVENT_REDUCED_RIGHTS: u64 = 0x6f5a2e2e57c07079;
292    pub const PUSH_EVENT_SAME_RIGHTS: u64 = 0x4fca4ce8755a1967;
293}
294
295pub mod send_handle_protocol_ordinals {
296    pub const SEND_HANDLE_REDUCED_RIGHTS: u64 = 0x7675407e0eb5f825;
297    pub const SEND_HANDLE_SAME_RIGHTS: u64 = 0x1d43414e5560333a;
298}
299
300mod internal {
301    use super::*;
302    unsafe impl fidl::encoding::TypeMarker for FlexibleButtons {
303        type Owned = Self;
304
305        #[inline(always)]
306        fn inline_align(_context: fidl::encoding::Context) -> usize {
307            4
308        }
309
310        #[inline(always)]
311        fn inline_size(_context: fidl::encoding::Context) -> usize {
312            4
313        }
314    }
315
316    impl fidl::encoding::ValueTypeMarker for FlexibleButtons {
317        type Borrowed<'a> = Self;
318        #[inline(always)]
319        fn borrow(value: &<Self as fidl::encoding::TypeMarker>::Owned) -> Self::Borrowed<'_> {
320            *value
321        }
322    }
323
324    unsafe impl<D: fidl::encoding::ResourceDialect> fidl::encoding::Encode<Self, D>
325        for FlexibleButtons
326    {
327        #[inline]
328        unsafe fn encode(
329            self,
330            encoder: &mut fidl::encoding::Encoder<'_, D>,
331            offset: usize,
332            _depth: fidl::encoding::Depth,
333        ) -> fidl::Result<()> {
334            encoder.debug_check_bounds::<Self>(offset);
335            encoder.write_num(self.bits(), offset);
336            Ok(())
337        }
338    }
339
340    impl<D: fidl::encoding::ResourceDialect> fidl::encoding::Decode<Self, D> for FlexibleButtons {
341        #[inline(always)]
342        fn new_empty() -> Self {
343            Self::empty()
344        }
345
346        #[inline]
347        unsafe fn decode(
348            &mut self,
349            decoder: &mut fidl::encoding::Decoder<'_, D>,
350            offset: usize,
351            _depth: fidl::encoding::Depth,
352        ) -> fidl::Result<()> {
353            decoder.debug_check_bounds::<Self>(offset);
354            let prim = decoder.read_num::<u32>(offset);
355            *self = Self::from_bits_allow_unknown(prim);
356            Ok(())
357        }
358    }
359    unsafe impl fidl::encoding::TypeMarker for StrictButtons {
360        type Owned = Self;
361
362        #[inline(always)]
363        fn inline_align(_context: fidl::encoding::Context) -> usize {
364            4
365        }
366
367        #[inline(always)]
368        fn inline_size(_context: fidl::encoding::Context) -> usize {
369            4
370        }
371    }
372
373    impl fidl::encoding::ValueTypeMarker for StrictButtons {
374        type Borrowed<'a> = Self;
375        #[inline(always)]
376        fn borrow(value: &<Self as fidl::encoding::TypeMarker>::Owned) -> Self::Borrowed<'_> {
377            *value
378        }
379    }
380
381    unsafe impl<D: fidl::encoding::ResourceDialect> fidl::encoding::Encode<Self, D> for StrictButtons {
382        #[inline]
383        unsafe fn encode(
384            self,
385            encoder: &mut fidl::encoding::Encoder<'_, D>,
386            offset: usize,
387            _depth: fidl::encoding::Depth,
388        ) -> fidl::Result<()> {
389            encoder.debug_check_bounds::<Self>(offset);
390            if self.bits() & Self::all().bits() != self.bits() {
391                return Err(fidl::Error::InvalidBitsValue);
392            }
393            encoder.write_num(self.bits(), offset);
394            Ok(())
395        }
396    }
397
398    impl<D: fidl::encoding::ResourceDialect> fidl::encoding::Decode<Self, D> for StrictButtons {
399        #[inline(always)]
400        fn new_empty() -> Self {
401            Self::empty()
402        }
403
404        #[inline]
405        unsafe fn decode(
406            &mut self,
407            decoder: &mut fidl::encoding::Decoder<'_, D>,
408            offset: usize,
409            _depth: fidl::encoding::Depth,
410        ) -> fidl::Result<()> {
411            decoder.debug_check_bounds::<Self>(offset);
412            let prim = decoder.read_num::<u32>(offset);
413            *self = Self::from_bits(prim).ok_or(fidl::Error::InvalidBitsValue)?;
414            Ok(())
415        }
416    }
417    unsafe impl fidl::encoding::TypeMarker for FlexibleAnimal {
418        type Owned = Self;
419
420        #[inline(always)]
421        fn inline_align(_context: fidl::encoding::Context) -> usize {
422            std::mem::align_of::<i32>()
423        }
424
425        #[inline(always)]
426        fn inline_size(_context: fidl::encoding::Context) -> usize {
427            std::mem::size_of::<i32>()
428        }
429
430        #[inline(always)]
431        fn encode_is_copy() -> bool {
432            false
433        }
434
435        #[inline(always)]
436        fn decode_is_copy() -> bool {
437            false
438        }
439    }
440
441    impl fidl::encoding::ValueTypeMarker for FlexibleAnimal {
442        type Borrowed<'a> = Self;
443        #[inline(always)]
444        fn borrow(value: &<Self as fidl::encoding::TypeMarker>::Owned) -> Self::Borrowed<'_> {
445            *value
446        }
447    }
448
449    unsafe impl<D: fidl::encoding::ResourceDialect> fidl::encoding::Encode<Self, D> for FlexibleAnimal {
450        #[inline]
451        unsafe fn encode(
452            self,
453            encoder: &mut fidl::encoding::Encoder<'_, D>,
454            offset: usize,
455            _depth: fidl::encoding::Depth,
456        ) -> fidl::Result<()> {
457            encoder.debug_check_bounds::<Self>(offset);
458            encoder.write_num(self.into_primitive(), offset);
459            Ok(())
460        }
461    }
462
463    impl<D: fidl::encoding::ResourceDialect> fidl::encoding::Decode<Self, D> for FlexibleAnimal {
464        #[inline(always)]
465        fn new_empty() -> Self {
466            Self::unknown()
467        }
468
469        #[inline]
470        unsafe fn decode(
471            &mut self,
472            decoder: &mut fidl::encoding::Decoder<'_, D>,
473            offset: usize,
474            _depth: fidl::encoding::Depth,
475        ) -> fidl::Result<()> {
476            decoder.debug_check_bounds::<Self>(offset);
477            let prim = decoder.read_num::<i32>(offset);
478
479            *self = Self::from_primitive_allow_unknown(prim);
480            Ok(())
481        }
482    }
483    unsafe impl fidl::encoding::TypeMarker for FlexibleEmptyEnum {
484        type Owned = Self;
485
486        #[inline(always)]
487        fn inline_align(_context: fidl::encoding::Context) -> usize {
488            std::mem::align_of::<i32>()
489        }
490
491        #[inline(always)]
492        fn inline_size(_context: fidl::encoding::Context) -> usize {
493            std::mem::size_of::<i32>()
494        }
495
496        #[inline(always)]
497        fn encode_is_copy() -> bool {
498            false
499        }
500
501        #[inline(always)]
502        fn decode_is_copy() -> bool {
503            false
504        }
505    }
506
507    impl fidl::encoding::ValueTypeMarker for FlexibleEmptyEnum {
508        type Borrowed<'a> = Self;
509        #[inline(always)]
510        fn borrow(value: &<Self as fidl::encoding::TypeMarker>::Owned) -> Self::Borrowed<'_> {
511            *value
512        }
513    }
514
515    unsafe impl<D: fidl::encoding::ResourceDialect> fidl::encoding::Encode<Self, D>
516        for FlexibleEmptyEnum
517    {
518        #[inline]
519        unsafe fn encode(
520            self,
521            encoder: &mut fidl::encoding::Encoder<'_, D>,
522            offset: usize,
523            _depth: fidl::encoding::Depth,
524        ) -> fidl::Result<()> {
525            encoder.debug_check_bounds::<Self>(offset);
526            encoder.write_num(self.into_primitive(), offset);
527            Ok(())
528        }
529    }
530
531    impl<D: fidl::encoding::ResourceDialect> fidl::encoding::Decode<Self, D> for FlexibleEmptyEnum {
532        #[inline(always)]
533        fn new_empty() -> Self {
534            Self::unknown()
535        }
536
537        #[inline]
538        unsafe fn decode(
539            &mut self,
540            decoder: &mut fidl::encoding::Decoder<'_, D>,
541            offset: usize,
542            _depth: fidl::encoding::Depth,
543        ) -> fidl::Result<()> {
544            decoder.debug_check_bounds::<Self>(offset);
545            let prim = decoder.read_num::<i32>(offset);
546
547            *self = Self::from_primitive_allow_unknown(prim);
548            Ok(())
549        }
550    }
551    unsafe impl fidl::encoding::TypeMarker for StrictAnimal {
552        type Owned = Self;
553
554        #[inline(always)]
555        fn inline_align(_context: fidl::encoding::Context) -> usize {
556            std::mem::align_of::<i32>()
557        }
558
559        #[inline(always)]
560        fn inline_size(_context: fidl::encoding::Context) -> usize {
561            std::mem::size_of::<i32>()
562        }
563
564        #[inline(always)]
565        fn encode_is_copy() -> bool {
566            true
567        }
568
569        #[inline(always)]
570        fn decode_is_copy() -> bool {
571            false
572        }
573    }
574
575    impl fidl::encoding::ValueTypeMarker for StrictAnimal {
576        type Borrowed<'a> = Self;
577        #[inline(always)]
578        fn borrow(value: &<Self as fidl::encoding::TypeMarker>::Owned) -> Self::Borrowed<'_> {
579            *value
580        }
581    }
582
583    unsafe impl<D: fidl::encoding::ResourceDialect> fidl::encoding::Encode<Self, D> for StrictAnimal {
584        #[inline]
585        unsafe fn encode(
586            self,
587            encoder: &mut fidl::encoding::Encoder<'_, D>,
588            offset: usize,
589            _depth: fidl::encoding::Depth,
590        ) -> fidl::Result<()> {
591            encoder.debug_check_bounds::<Self>(offset);
592            encoder.write_num(self.into_primitive(), offset);
593            Ok(())
594        }
595    }
596
597    impl<D: fidl::encoding::ResourceDialect> fidl::encoding::Decode<Self, D> for StrictAnimal {
598        #[inline(always)]
599        fn new_empty() -> Self {
600            Self::Dog
601        }
602
603        #[inline]
604        unsafe fn decode(
605            &mut self,
606            decoder: &mut fidl::encoding::Decoder<'_, D>,
607            offset: usize,
608            _depth: fidl::encoding::Depth,
609        ) -> fidl::Result<()> {
610            decoder.debug_check_bounds::<Self>(offset);
611            let prim = decoder.read_num::<i32>(offset);
612
613            *self = Self::from_primitive(prim).ok_or(fidl::Error::InvalidEnumValue)?;
614            Ok(())
615        }
616    }
617
618    impl fidl::encoding::ValueTypeMarker for Coordinate {
619        type Borrowed<'a> = &'a Self;
620        fn borrow(value: &<Self as fidl::encoding::TypeMarker>::Owned) -> Self::Borrowed<'_> {
621            value
622        }
623    }
624
625    unsafe impl fidl::encoding::TypeMarker for Coordinate {
626        type Owned = Self;
627
628        #[inline(always)]
629        fn inline_align(_context: fidl::encoding::Context) -> usize {
630            1
631        }
632
633        #[inline(always)]
634        fn inline_size(_context: fidl::encoding::Context) -> usize {
635            2
636        }
637        #[inline(always)]
638        fn encode_is_copy() -> bool {
639            true
640        }
641
642        #[inline(always)]
643        fn decode_is_copy() -> bool {
644            true
645        }
646    }
647
648    unsafe impl<D: fidl::encoding::ResourceDialect> fidl::encoding::Encode<Coordinate, D>
649        for &Coordinate
650    {
651        #[inline]
652        unsafe fn encode(
653            self,
654            encoder: &mut fidl::encoding::Encoder<'_, D>,
655            offset: usize,
656            _depth: fidl::encoding::Depth,
657        ) -> fidl::Result<()> {
658            encoder.debug_check_bounds::<Coordinate>(offset);
659            unsafe {
660                // Copy the object into the buffer.
661                let buf_ptr = encoder.buf.as_mut_ptr().add(offset);
662                (buf_ptr as *mut Coordinate).write_unaligned((self as *const Coordinate).read());
663                // Zero out padding regions. Unlike `fidl_struct_impl_noncopy!`, this must be
664                // done second because the memcpy will write garbage to these bytes.
665            }
666            Ok(())
667        }
668    }
669    unsafe impl<
670            D: fidl::encoding::ResourceDialect,
671            T0: fidl::encoding::Encode<u8, D>,
672            T1: fidl::encoding::Encode<u8, D>,
673        > fidl::encoding::Encode<Coordinate, D> for (T0, T1)
674    {
675        #[inline]
676        unsafe fn encode(
677            self,
678            encoder: &mut fidl::encoding::Encoder<'_, D>,
679            offset: usize,
680            depth: fidl::encoding::Depth,
681        ) -> fidl::Result<()> {
682            encoder.debug_check_bounds::<Coordinate>(offset);
683            // Zero out padding regions. There's no need to apply masks
684            // because the unmasked parts will be overwritten by fields.
685            // Write the fields.
686            self.0.encode(encoder, offset + 0, depth)?;
687            self.1.encode(encoder, offset + 1, depth)?;
688            Ok(())
689        }
690    }
691
692    impl<D: fidl::encoding::ResourceDialect> fidl::encoding::Decode<Self, D> for Coordinate {
693        #[inline(always)]
694        fn new_empty() -> Self {
695            Self { x: fidl::new_empty!(u8, D), y: fidl::new_empty!(u8, D) }
696        }
697
698        #[inline]
699        unsafe fn decode(
700            &mut self,
701            decoder: &mut fidl::encoding::Decoder<'_, D>,
702            offset: usize,
703            _depth: fidl::encoding::Depth,
704        ) -> fidl::Result<()> {
705            decoder.debug_check_bounds::<Self>(offset);
706            let buf_ptr = unsafe { decoder.buf.as_ptr().add(offset) };
707            // Verify that padding bytes are zero.
708            // Copy from the buffer into the object.
709            unsafe {
710                std::ptr::copy_nonoverlapping(buf_ptr, self as *mut Self as *mut u8, 2);
711            }
712            Ok(())
713        }
714    }
715
716    impl ValueRecord {
717        #[inline(always)]
718        fn max_ordinal_present(&self) -> u64 {
719            if let Some(_) = self.age {
720                return 2;
721            }
722            if let Some(_) = self.name {
723                return 1;
724            }
725            0
726        }
727    }
728
729    impl fidl::encoding::ValueTypeMarker for ValueRecord {
730        type Borrowed<'a> = &'a Self;
731        fn borrow(value: &<Self as fidl::encoding::TypeMarker>::Owned) -> Self::Borrowed<'_> {
732            value
733        }
734    }
735
736    unsafe impl fidl::encoding::TypeMarker for ValueRecord {
737        type Owned = Self;
738
739        #[inline(always)]
740        fn inline_align(_context: fidl::encoding::Context) -> usize {
741            8
742        }
743
744        #[inline(always)]
745        fn inline_size(_context: fidl::encoding::Context) -> usize {
746            16
747        }
748    }
749
750    unsafe impl<D: fidl::encoding::ResourceDialect> fidl::encoding::Encode<ValueRecord, D>
751        for &ValueRecord
752    {
753        unsafe fn encode(
754            self,
755            encoder: &mut fidl::encoding::Encoder<'_, D>,
756            offset: usize,
757            mut depth: fidl::encoding::Depth,
758        ) -> fidl::Result<()> {
759            encoder.debug_check_bounds::<ValueRecord>(offset);
760            // Vector header
761            let max_ordinal: u64 = self.max_ordinal_present();
762            encoder.write_num(max_ordinal, offset);
763            encoder.write_num(fidl::encoding::ALLOC_PRESENT_U64, offset + 8);
764            // Calling encoder.out_of_line_offset(0) is not allowed.
765            if max_ordinal == 0 {
766                return Ok(());
767            }
768            depth.increment()?;
769            let envelope_size = 8;
770            let bytes_len = max_ordinal as usize * envelope_size;
771            #[allow(unused_variables)]
772            let offset = encoder.out_of_line_offset(bytes_len);
773            let mut _prev_end_offset: usize = 0;
774            if 1 > max_ordinal {
775                return Ok(());
776            }
777
778            // Write at offset+(ordinal-1)*envelope_size, since ordinals are one-based and envelopes
779            // are envelope_size bytes.
780            let cur_offset: usize = (1 - 1) * envelope_size;
781
782            // Zero reserved fields.
783            encoder.padding(offset + _prev_end_offset, cur_offset - _prev_end_offset);
784
785            // Safety:
786            // - bytes_len is calculated to fit envelope_size*max(member.ordinal).
787            // - Since cur_offset is envelope_size*(member.ordinal - 1) and the envelope takes
788            //   envelope_size bytes, there is always sufficient room.
789            fidl::encoding::encode_in_envelope_optional::<fidl::encoding::UnboundedString, D>(
790                self.name.as_ref().map(
791                    <fidl::encoding::UnboundedString as fidl::encoding::ValueTypeMarker>::borrow,
792                ),
793                encoder,
794                offset + cur_offset,
795                depth,
796            )?;
797
798            _prev_end_offset = cur_offset + envelope_size;
799            if 2 > max_ordinal {
800                return Ok(());
801            }
802
803            // Write at offset+(ordinal-1)*envelope_size, since ordinals are one-based and envelopes
804            // are envelope_size bytes.
805            let cur_offset: usize = (2 - 1) * envelope_size;
806
807            // Zero reserved fields.
808            encoder.padding(offset + _prev_end_offset, cur_offset - _prev_end_offset);
809
810            // Safety:
811            // - bytes_len is calculated to fit envelope_size*max(member.ordinal).
812            // - Since cur_offset is envelope_size*(member.ordinal - 1) and the envelope takes
813            //   envelope_size bytes, there is always sufficient room.
814            fidl::encoding::encode_in_envelope_optional::<u8, D>(
815                self.age.as_ref().map(<u8 as fidl::encoding::ValueTypeMarker>::borrow),
816                encoder,
817                offset + cur_offset,
818                depth,
819            )?;
820
821            _prev_end_offset = cur_offset + envelope_size;
822
823            Ok(())
824        }
825    }
826
827    impl<D: fidl::encoding::ResourceDialect> fidl::encoding::Decode<Self, D> for ValueRecord {
828        #[inline(always)]
829        fn new_empty() -> Self {
830            Self::default()
831        }
832
833        unsafe fn decode(
834            &mut self,
835            decoder: &mut fidl::encoding::Decoder<'_, D>,
836            offset: usize,
837            mut depth: fidl::encoding::Depth,
838        ) -> fidl::Result<()> {
839            decoder.debug_check_bounds::<Self>(offset);
840            let len = match fidl::encoding::decode_vector_header(decoder, offset)? {
841                None => return Err(fidl::Error::NotNullable),
842                Some(len) => len,
843            };
844            // Calling decoder.out_of_line_offset(0) is not allowed.
845            if len == 0 {
846                return Ok(());
847            };
848            depth.increment()?;
849            let envelope_size = 8;
850            let bytes_len = len * envelope_size;
851            let offset = decoder.out_of_line_offset(bytes_len)?;
852            // Decode the envelope for each type.
853            let mut _next_ordinal_to_read = 0;
854            let mut next_offset = offset;
855            let end_offset = offset + bytes_len;
856            _next_ordinal_to_read += 1;
857            if next_offset >= end_offset {
858                return Ok(());
859            }
860
861            // Decode unknown envelopes for gaps in ordinals.
862            while _next_ordinal_to_read < 1 {
863                fidl::encoding::decode_unknown_envelope(decoder, next_offset, depth)?;
864                _next_ordinal_to_read += 1;
865                next_offset += envelope_size;
866            }
867
868            let next_out_of_line = decoder.next_out_of_line();
869            let handles_before = decoder.remaining_handles();
870            if let Some((inlined, num_bytes, num_handles)) =
871                fidl::encoding::decode_envelope_header(decoder, next_offset)?
872            {
873                let member_inline_size =
874                    <fidl::encoding::UnboundedString as fidl::encoding::TypeMarker>::inline_size(
875                        decoder.context,
876                    );
877                if inlined != (member_inline_size <= 4) {
878                    return Err(fidl::Error::InvalidInlineBitInEnvelope);
879                }
880                let inner_offset;
881                let mut inner_depth = depth.clone();
882                if inlined {
883                    decoder.check_inline_envelope_padding(next_offset, member_inline_size)?;
884                    inner_offset = next_offset;
885                } else {
886                    inner_offset = decoder.out_of_line_offset(member_inline_size)?;
887                    inner_depth.increment()?;
888                }
889                let val_ref = self
890                    .name
891                    .get_or_insert_with(|| fidl::new_empty!(fidl::encoding::UnboundedString, D));
892                fidl::decode!(
893                    fidl::encoding::UnboundedString,
894                    D,
895                    val_ref,
896                    decoder,
897                    inner_offset,
898                    inner_depth
899                )?;
900                if !inlined && decoder.next_out_of_line() != next_out_of_line + (num_bytes as usize)
901                {
902                    return Err(fidl::Error::InvalidNumBytesInEnvelope);
903                }
904                if handles_before != decoder.remaining_handles() + (num_handles as usize) {
905                    return Err(fidl::Error::InvalidNumHandlesInEnvelope);
906                }
907            }
908
909            next_offset += envelope_size;
910            _next_ordinal_to_read += 1;
911            if next_offset >= end_offset {
912                return Ok(());
913            }
914
915            // Decode unknown envelopes for gaps in ordinals.
916            while _next_ordinal_to_read < 2 {
917                fidl::encoding::decode_unknown_envelope(decoder, next_offset, depth)?;
918                _next_ordinal_to_read += 1;
919                next_offset += envelope_size;
920            }
921
922            let next_out_of_line = decoder.next_out_of_line();
923            let handles_before = decoder.remaining_handles();
924            if let Some((inlined, num_bytes, num_handles)) =
925                fidl::encoding::decode_envelope_header(decoder, next_offset)?
926            {
927                let member_inline_size =
928                    <u8 as fidl::encoding::TypeMarker>::inline_size(decoder.context);
929                if inlined != (member_inline_size <= 4) {
930                    return Err(fidl::Error::InvalidInlineBitInEnvelope);
931                }
932                let inner_offset;
933                let mut inner_depth = depth.clone();
934                if inlined {
935                    decoder.check_inline_envelope_padding(next_offset, member_inline_size)?;
936                    inner_offset = next_offset;
937                } else {
938                    inner_offset = decoder.out_of_line_offset(member_inline_size)?;
939                    inner_depth.increment()?;
940                }
941                let val_ref = self.age.get_or_insert_with(|| fidl::new_empty!(u8, D));
942                fidl::decode!(u8, D, val_ref, decoder, inner_offset, inner_depth)?;
943                if !inlined && decoder.next_out_of_line() != next_out_of_line + (num_bytes as usize)
944                {
945                    return Err(fidl::Error::InvalidNumBytesInEnvelope);
946                }
947                if handles_before != decoder.remaining_handles() + (num_handles as usize) {
948                    return Err(fidl::Error::InvalidNumHandlesInEnvelope);
949                }
950            }
951
952            next_offset += envelope_size;
953
954            // Decode the remaining unknown envelopes.
955            while next_offset < end_offset {
956                _next_ordinal_to_read += 1;
957                fidl::encoding::decode_unknown_envelope(decoder, next_offset, depth)?;
958                next_offset += envelope_size;
959            }
960
961            Ok(())
962        }
963    }
964
965    impl fidl::encoding::ValueTypeMarker for FlexibleValueThing {
966        type Borrowed<'a> = &'a Self;
967        fn borrow(value: &<Self as fidl::encoding::TypeMarker>::Owned) -> Self::Borrowed<'_> {
968            value
969        }
970    }
971
972    unsafe impl fidl::encoding::TypeMarker for FlexibleValueThing {
973        type Owned = Self;
974
975        #[inline(always)]
976        fn inline_align(_context: fidl::encoding::Context) -> usize {
977            8
978        }
979
980        #[inline(always)]
981        fn inline_size(_context: fidl::encoding::Context) -> usize {
982            16
983        }
984    }
985
986    unsafe impl<D: fidl::encoding::ResourceDialect> fidl::encoding::Encode<FlexibleValueThing, D>
987        for &FlexibleValueThing
988    {
989        #[inline]
990        unsafe fn encode(
991            self,
992            encoder: &mut fidl::encoding::Encoder<'_, D>,
993            offset: usize,
994            _depth: fidl::encoding::Depth,
995        ) -> fidl::Result<()> {
996            encoder.debug_check_bounds::<FlexibleValueThing>(offset);
997            encoder.write_num::<u64>(self.ordinal(), offset);
998            match self {
999                FlexibleValueThing::Number(ref val) => {
1000                    fidl::encoding::encode_in_envelope::<u32, D>(
1001                        <u32 as fidl::encoding::ValueTypeMarker>::borrow(val),
1002                        encoder,
1003                        offset + 8,
1004                        _depth,
1005                    )
1006                }
1007                FlexibleValueThing::Name(ref val) => fidl::encoding::encode_in_envelope::<
1008                    fidl::encoding::UnboundedString,
1009                    D,
1010                >(
1011                    <fidl::encoding::UnboundedString as fidl::encoding::ValueTypeMarker>::borrow(
1012                        val,
1013                    ),
1014                    encoder,
1015                    offset + 8,
1016                    _depth,
1017                ),
1018                FlexibleValueThing::__SourceBreaking { .. } => Err(fidl::Error::UnknownUnionTag),
1019            }
1020        }
1021    }
1022
1023    impl<D: fidl::encoding::ResourceDialect> fidl::encoding::Decode<Self, D> for FlexibleValueThing {
1024        #[inline(always)]
1025        fn new_empty() -> Self {
1026            Self::__SourceBreaking { unknown_ordinal: 0 }
1027        }
1028
1029        #[inline]
1030        unsafe fn decode(
1031            &mut self,
1032            decoder: &mut fidl::encoding::Decoder<'_, D>,
1033            offset: usize,
1034            mut depth: fidl::encoding::Depth,
1035        ) -> fidl::Result<()> {
1036            decoder.debug_check_bounds::<Self>(offset);
1037            #[allow(unused_variables)]
1038            let next_out_of_line = decoder.next_out_of_line();
1039            let handles_before = decoder.remaining_handles();
1040            let (ordinal, inlined, num_bytes, num_handles) =
1041                fidl::encoding::decode_union_inline_portion(decoder, offset)?;
1042
1043            let member_inline_size = match ordinal {
1044                1 => <u32 as fidl::encoding::TypeMarker>::inline_size(decoder.context),
1045                2 => <fidl::encoding::UnboundedString as fidl::encoding::TypeMarker>::inline_size(
1046                    decoder.context,
1047                ),
1048                0 => return Err(fidl::Error::UnknownUnionTag),
1049                _ => num_bytes as usize,
1050            };
1051
1052            if inlined != (member_inline_size <= 4) {
1053                return Err(fidl::Error::InvalidInlineBitInEnvelope);
1054            }
1055            let _inner_offset;
1056            if inlined {
1057                decoder.check_inline_envelope_padding(offset + 8, member_inline_size)?;
1058                _inner_offset = offset + 8;
1059            } else {
1060                depth.increment()?;
1061                _inner_offset = decoder.out_of_line_offset(member_inline_size)?;
1062            }
1063            match ordinal {
1064                1 => {
1065                    #[allow(irrefutable_let_patterns)]
1066                    if let FlexibleValueThing::Number(_) = self {
1067                        // Do nothing, read the value into the object
1068                    } else {
1069                        // Initialize `self` to the right variant
1070                        *self = FlexibleValueThing::Number(fidl::new_empty!(u32, D));
1071                    }
1072                    #[allow(irrefutable_let_patterns)]
1073                    if let FlexibleValueThing::Number(ref mut val) = self {
1074                        fidl::decode!(u32, D, val, decoder, _inner_offset, depth)?;
1075                    } else {
1076                        unreachable!()
1077                    }
1078                }
1079                2 => {
1080                    #[allow(irrefutable_let_patterns)]
1081                    if let FlexibleValueThing::Name(_) = self {
1082                        // Do nothing, read the value into the object
1083                    } else {
1084                        // Initialize `self` to the right variant
1085                        *self = FlexibleValueThing::Name(fidl::new_empty!(
1086                            fidl::encoding::UnboundedString,
1087                            D
1088                        ));
1089                    }
1090                    #[allow(irrefutable_let_patterns)]
1091                    if let FlexibleValueThing::Name(ref mut val) = self {
1092                        fidl::decode!(
1093                            fidl::encoding::UnboundedString,
1094                            D,
1095                            val,
1096                            decoder,
1097                            _inner_offset,
1098                            depth
1099                        )?;
1100                    } else {
1101                        unreachable!()
1102                    }
1103                }
1104                #[allow(deprecated)]
1105                ordinal => {
1106                    for _ in 0..num_handles {
1107                        decoder.drop_next_handle()?;
1108                    }
1109                    *self = FlexibleValueThing::__SourceBreaking { unknown_ordinal: ordinal };
1110                }
1111            }
1112            if !inlined && decoder.next_out_of_line() != next_out_of_line + (num_bytes as usize) {
1113                return Err(fidl::Error::InvalidNumBytesInEnvelope);
1114            }
1115            if handles_before != decoder.remaining_handles() + (num_handles as usize) {
1116                return Err(fidl::Error::InvalidNumHandlesInEnvelope);
1117            }
1118            Ok(())
1119        }
1120    }
1121
1122    impl fidl::encoding::ValueTypeMarker for StrictValueThing {
1123        type Borrowed<'a> = &'a Self;
1124        fn borrow(value: &<Self as fidl::encoding::TypeMarker>::Owned) -> Self::Borrowed<'_> {
1125            value
1126        }
1127    }
1128
1129    unsafe impl fidl::encoding::TypeMarker for StrictValueThing {
1130        type Owned = Self;
1131
1132        #[inline(always)]
1133        fn inline_align(_context: fidl::encoding::Context) -> usize {
1134            8
1135        }
1136
1137        #[inline(always)]
1138        fn inline_size(_context: fidl::encoding::Context) -> usize {
1139            16
1140        }
1141    }
1142
1143    unsafe impl<D: fidl::encoding::ResourceDialect> fidl::encoding::Encode<StrictValueThing, D>
1144        for &StrictValueThing
1145    {
1146        #[inline]
1147        unsafe fn encode(
1148            self,
1149            encoder: &mut fidl::encoding::Encoder<'_, D>,
1150            offset: usize,
1151            _depth: fidl::encoding::Depth,
1152        ) -> fidl::Result<()> {
1153            encoder.debug_check_bounds::<StrictValueThing>(offset);
1154            encoder.write_num::<u64>(self.ordinal(), offset);
1155            match self {
1156                StrictValueThing::Number(ref val) => fidl::encoding::encode_in_envelope::<u32, D>(
1157                    <u32 as fidl::encoding::ValueTypeMarker>::borrow(val),
1158                    encoder,
1159                    offset + 8,
1160                    _depth,
1161                ),
1162                StrictValueThing::Name(ref val) => fidl::encoding::encode_in_envelope::<
1163                    fidl::encoding::UnboundedString,
1164                    D,
1165                >(
1166                    <fidl::encoding::UnboundedString as fidl::encoding::ValueTypeMarker>::borrow(
1167                        val,
1168                    ),
1169                    encoder,
1170                    offset + 8,
1171                    _depth,
1172                ),
1173            }
1174        }
1175    }
1176
1177    impl<D: fidl::encoding::ResourceDialect> fidl::encoding::Decode<Self, D> for StrictValueThing {
1178        #[inline(always)]
1179        fn new_empty() -> Self {
1180            Self::Number(fidl::new_empty!(u32, D))
1181        }
1182
1183        #[inline]
1184        unsafe fn decode(
1185            &mut self,
1186            decoder: &mut fidl::encoding::Decoder<'_, D>,
1187            offset: usize,
1188            mut depth: fidl::encoding::Depth,
1189        ) -> fidl::Result<()> {
1190            decoder.debug_check_bounds::<Self>(offset);
1191            #[allow(unused_variables)]
1192            let next_out_of_line = decoder.next_out_of_line();
1193            let handles_before = decoder.remaining_handles();
1194            let (ordinal, inlined, num_bytes, num_handles) =
1195                fidl::encoding::decode_union_inline_portion(decoder, offset)?;
1196
1197            let member_inline_size = match ordinal {
1198                1 => <u32 as fidl::encoding::TypeMarker>::inline_size(decoder.context),
1199                2 => <fidl::encoding::UnboundedString as fidl::encoding::TypeMarker>::inline_size(
1200                    decoder.context,
1201                ),
1202                _ => return Err(fidl::Error::UnknownUnionTag),
1203            };
1204
1205            if inlined != (member_inline_size <= 4) {
1206                return Err(fidl::Error::InvalidInlineBitInEnvelope);
1207            }
1208            let _inner_offset;
1209            if inlined {
1210                decoder.check_inline_envelope_padding(offset + 8, member_inline_size)?;
1211                _inner_offset = offset + 8;
1212            } else {
1213                depth.increment()?;
1214                _inner_offset = decoder.out_of_line_offset(member_inline_size)?;
1215            }
1216            match ordinal {
1217                1 => {
1218                    #[allow(irrefutable_let_patterns)]
1219                    if let StrictValueThing::Number(_) = self {
1220                        // Do nothing, read the value into the object
1221                    } else {
1222                        // Initialize `self` to the right variant
1223                        *self = StrictValueThing::Number(fidl::new_empty!(u32, D));
1224                    }
1225                    #[allow(irrefutable_let_patterns)]
1226                    if let StrictValueThing::Number(ref mut val) = self {
1227                        fidl::decode!(u32, D, val, decoder, _inner_offset, depth)?;
1228                    } else {
1229                        unreachable!()
1230                    }
1231                }
1232                2 => {
1233                    #[allow(irrefutable_let_patterns)]
1234                    if let StrictValueThing::Name(_) = self {
1235                        // Do nothing, read the value into the object
1236                    } else {
1237                        // Initialize `self` to the right variant
1238                        *self = StrictValueThing::Name(fidl::new_empty!(
1239                            fidl::encoding::UnboundedString,
1240                            D
1241                        ));
1242                    }
1243                    #[allow(irrefutable_let_patterns)]
1244                    if let StrictValueThing::Name(ref mut val) = self {
1245                        fidl::decode!(
1246                            fidl::encoding::UnboundedString,
1247                            D,
1248                            val,
1249                            decoder,
1250                            _inner_offset,
1251                            depth
1252                        )?;
1253                    } else {
1254                        unreachable!()
1255                    }
1256                }
1257                ordinal => panic!("unexpected ordinal {:?}", ordinal),
1258            }
1259            if !inlined && decoder.next_out_of_line() != next_out_of_line + (num_bytes as usize) {
1260                return Err(fidl::Error::InvalidNumBytesInEnvelope);
1261            }
1262            if handles_before != decoder.remaining_handles() + (num_handles as usize) {
1263                return Err(fidl::Error::InvalidNumHandlesInEnvelope);
1264            }
1265            Ok(())
1266        }
1267    }
1268}