fidl_test_echoserver/
fidl_test_echoserver.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::client::QueryResponseFut;
8use fidl::encoding::{MessageBufFor, ProxyChannelBox, ResourceDialect};
9use fidl::endpoints::{ControlHandle as _, Responder as _};
10pub use fidl_test_echoserver__common::*;
11use futures::future::{self, MaybeDone, TryFutureExt};
12use zx_status;
13
14#[derive(Debug, PartialEq)]
15pub struct RealmFactoryCreateRealmRequest {
16    pub options: RealmOptions,
17}
18
19impl fidl::Standalone<fidl::encoding::DefaultFuchsiaResourceDialect>
20    for RealmFactoryCreateRealmRequest
21{
22}
23
24#[derive(Debug, Eq, Hash, Ord, PartialEq, PartialOrd)]
25pub struct RealmFactoryCreateRealmResponse {
26    pub dictionary: fidl::EventPair,
27}
28
29impl fidl::Standalone<fidl::encoding::DefaultFuchsiaResourceDialect>
30    for RealmFactoryCreateRealmResponse
31{
32}
33
34/// RealmOptions tells the RealmFactory protocol how to create the test realm.
35#[derive(Debug, Default, PartialEq)]
36pub struct RealmOptions {
37    /// FIXME: Add some options here.
38    pub example_option: Option<bool>,
39    #[doc(hidden)]
40    pub __source_breaking: fidl::marker::SourceBreaking,
41}
42
43impl fidl::Standalone<fidl::encoding::DefaultFuchsiaResourceDialect> for RealmOptions {}
44
45#[derive(Debug, Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Hash)]
46pub struct RealmFactoryMarker;
47
48impl fidl::endpoints::ProtocolMarker for RealmFactoryMarker {
49    type Proxy = RealmFactoryProxy;
50    type RequestStream = RealmFactoryRequestStream;
51    #[cfg(target_os = "fuchsia")]
52    type SynchronousProxy = RealmFactorySynchronousProxy;
53
54    const DEBUG_NAME: &'static str = "test.echoserver.RealmFactory";
55}
56impl fidl::endpoints::DiscoverableProtocolMarker for RealmFactoryMarker {}
57pub type RealmFactoryCreateRealmResult =
58    Result<fidl::EventPair, fidl_fuchsia_testing_harness::OperationError>;
59
60pub trait RealmFactoryProxyInterface: Send + Sync {
61    type CreateRealmResponseFut: std::future::Future<Output = Result<RealmFactoryCreateRealmResult, fidl::Error>>
62        + Send;
63    fn r#create_realm(&self, options: RealmOptions) -> Self::CreateRealmResponseFut;
64}
65#[derive(Debug)]
66#[cfg(target_os = "fuchsia")]
67pub struct RealmFactorySynchronousProxy {
68    client: fidl::client::sync::Client,
69}
70
71#[cfg(target_os = "fuchsia")]
72impl fidl::endpoints::SynchronousProxy for RealmFactorySynchronousProxy {
73    type Proxy = RealmFactoryProxy;
74    type Protocol = RealmFactoryMarker;
75
76    fn from_channel(inner: fidl::Channel) -> Self {
77        Self::new(inner)
78    }
79
80    fn into_channel(self) -> fidl::Channel {
81        self.client.into_channel()
82    }
83
84    fn as_channel(&self) -> &fidl::Channel {
85        self.client.as_channel()
86    }
87}
88
89#[cfg(target_os = "fuchsia")]
90impl RealmFactorySynchronousProxy {
91    pub fn new(channel: fidl::Channel) -> Self {
92        let protocol_name = <RealmFactoryMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME;
93        Self { client: fidl::client::sync::Client::new(channel, protocol_name) }
94    }
95
96    pub fn into_channel(self) -> fidl::Channel {
97        self.client.into_channel()
98    }
99
100    /// Waits until an event arrives and returns it. It is safe for other
101    /// threads to make concurrent requests while waiting for an event.
102    pub fn wait_for_event(
103        &self,
104        deadline: zx::MonotonicInstant,
105    ) -> Result<RealmFactoryEvent, fidl::Error> {
106        RealmFactoryEvent::decode(self.client.wait_for_event(deadline)?)
107    }
108
109    /// Specifies the options to use when creating the realm.
110    ///
111    /// Returns OperationError.INVALID if called more than once.
112    pub fn r#create_realm(
113        &self,
114        mut options: RealmOptions,
115        ___deadline: zx::MonotonicInstant,
116    ) -> Result<RealmFactoryCreateRealmResult, fidl::Error> {
117        let _response = self
118            .client
119            .send_query::<RealmFactoryCreateRealmRequest, fidl::encoding::FlexibleResultType<
120                RealmFactoryCreateRealmResponse,
121                fidl_fuchsia_testing_harness::OperationError,
122            >>(
123                (&mut options,),
124                0x5484d2814b7a3c5c,
125                fidl::encoding::DynamicFlags::FLEXIBLE,
126                ___deadline,
127            )?
128            .into_result::<RealmFactoryMarker>("create_realm")?;
129        Ok(_response.map(|x| x.dictionary))
130    }
131}
132
133#[cfg(target_os = "fuchsia")]
134impl From<RealmFactorySynchronousProxy> for zx::NullableHandle {
135    fn from(value: RealmFactorySynchronousProxy) -> Self {
136        value.into_channel().into()
137    }
138}
139
140#[cfg(target_os = "fuchsia")]
141impl From<fidl::Channel> for RealmFactorySynchronousProxy {
142    fn from(value: fidl::Channel) -> Self {
143        Self::new(value)
144    }
145}
146
147#[cfg(target_os = "fuchsia")]
148impl fidl::endpoints::FromClient for RealmFactorySynchronousProxy {
149    type Protocol = RealmFactoryMarker;
150
151    fn from_client(value: fidl::endpoints::ClientEnd<RealmFactoryMarker>) -> Self {
152        Self::new(value.into_channel())
153    }
154}
155
156#[derive(Debug, Clone)]
157pub struct RealmFactoryProxy {
158    client: fidl::client::Client<fidl::encoding::DefaultFuchsiaResourceDialect>,
159}
160
161impl fidl::endpoints::Proxy for RealmFactoryProxy {
162    type Protocol = RealmFactoryMarker;
163
164    fn from_channel(inner: ::fidl::AsyncChannel) -> Self {
165        Self::new(inner)
166    }
167
168    fn into_channel(self) -> Result<::fidl::AsyncChannel, Self> {
169        self.client.into_channel().map_err(|client| Self { client })
170    }
171
172    fn as_channel(&self) -> &::fidl::AsyncChannel {
173        self.client.as_channel()
174    }
175}
176
177impl RealmFactoryProxy {
178    /// Create a new Proxy for test.echoserver/RealmFactory.
179    pub fn new(channel: ::fidl::AsyncChannel) -> Self {
180        let protocol_name = <RealmFactoryMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME;
181        Self { client: fidl::client::Client::new(channel, protocol_name) }
182    }
183
184    /// Get a Stream of events from the remote end of the protocol.
185    ///
186    /// # Panics
187    ///
188    /// Panics if the event stream was already taken.
189    pub fn take_event_stream(&self) -> RealmFactoryEventStream {
190        RealmFactoryEventStream { event_receiver: self.client.take_event_receiver() }
191    }
192
193    /// Specifies the options to use when creating the realm.
194    ///
195    /// Returns OperationError.INVALID if called more than once.
196    pub fn r#create_realm(
197        &self,
198        mut options: RealmOptions,
199    ) -> fidl::client::QueryResponseFut<
200        RealmFactoryCreateRealmResult,
201        fidl::encoding::DefaultFuchsiaResourceDialect,
202    > {
203        RealmFactoryProxyInterface::r#create_realm(self, options)
204    }
205}
206
207impl RealmFactoryProxyInterface for RealmFactoryProxy {
208    type CreateRealmResponseFut = fidl::client::QueryResponseFut<
209        RealmFactoryCreateRealmResult,
210        fidl::encoding::DefaultFuchsiaResourceDialect,
211    >;
212    fn r#create_realm(&self, mut options: RealmOptions) -> Self::CreateRealmResponseFut {
213        fn _decode(
214            mut _buf: Result<<fidl::encoding::DefaultFuchsiaResourceDialect as fidl::encoding::ResourceDialect>::MessageBufEtc, fidl::Error>,
215        ) -> Result<RealmFactoryCreateRealmResult, fidl::Error> {
216            let _response = fidl::client::decode_transaction_body::<
217                fidl::encoding::FlexibleResultType<
218                    RealmFactoryCreateRealmResponse,
219                    fidl_fuchsia_testing_harness::OperationError,
220                >,
221                fidl::encoding::DefaultFuchsiaResourceDialect,
222                0x5484d2814b7a3c5c,
223            >(_buf?)?
224            .into_result::<RealmFactoryMarker>("create_realm")?;
225            Ok(_response.map(|x| x.dictionary))
226        }
227        self.client
228            .send_query_and_decode::<RealmFactoryCreateRealmRequest, RealmFactoryCreateRealmResult>(
229                (&mut options,),
230                0x5484d2814b7a3c5c,
231                fidl::encoding::DynamicFlags::FLEXIBLE,
232                _decode,
233            )
234    }
235}
236
237pub struct RealmFactoryEventStream {
238    event_receiver: fidl::client::EventReceiver<fidl::encoding::DefaultFuchsiaResourceDialect>,
239}
240
241impl std::marker::Unpin for RealmFactoryEventStream {}
242
243impl futures::stream::FusedStream for RealmFactoryEventStream {
244    fn is_terminated(&self) -> bool {
245        self.event_receiver.is_terminated()
246    }
247}
248
249impl futures::Stream for RealmFactoryEventStream {
250    type Item = Result<RealmFactoryEvent, fidl::Error>;
251
252    fn poll_next(
253        mut self: std::pin::Pin<&mut Self>,
254        cx: &mut std::task::Context<'_>,
255    ) -> std::task::Poll<Option<Self::Item>> {
256        match futures::ready!(futures::stream::StreamExt::poll_next_unpin(
257            &mut self.event_receiver,
258            cx
259        )?) {
260            Some(buf) => std::task::Poll::Ready(Some(RealmFactoryEvent::decode(buf))),
261            None => std::task::Poll::Ready(None),
262        }
263    }
264}
265
266#[derive(Debug)]
267pub enum RealmFactoryEvent {
268    #[non_exhaustive]
269    _UnknownEvent {
270        /// Ordinal of the event that was sent.
271        ordinal: u64,
272    },
273}
274
275impl RealmFactoryEvent {
276    /// Decodes a message buffer as a [`RealmFactoryEvent`].
277    fn decode(
278        mut buf: <fidl::encoding::DefaultFuchsiaResourceDialect as fidl::encoding::ResourceDialect>::MessageBufEtc,
279    ) -> Result<RealmFactoryEvent, fidl::Error> {
280        let (bytes, _handles) = buf.split_mut();
281        let (tx_header, _body_bytes) = fidl::encoding::decode_transaction_header(bytes)?;
282        debug_assert_eq!(tx_header.tx_id, 0);
283        match tx_header.ordinal {
284            _ if tx_header.dynamic_flags().contains(fidl::encoding::DynamicFlags::FLEXIBLE) => {
285                Ok(RealmFactoryEvent::_UnknownEvent { ordinal: tx_header.ordinal })
286            }
287            _ => Err(fidl::Error::UnknownOrdinal {
288                ordinal: tx_header.ordinal,
289                protocol_name: <RealmFactoryMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME,
290            }),
291        }
292    }
293}
294
295/// A Stream of incoming requests for test.echoserver/RealmFactory.
296pub struct RealmFactoryRequestStream {
297    inner: std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>,
298    is_terminated: bool,
299}
300
301impl std::marker::Unpin for RealmFactoryRequestStream {}
302
303impl futures::stream::FusedStream for RealmFactoryRequestStream {
304    fn is_terminated(&self) -> bool {
305        self.is_terminated
306    }
307}
308
309impl fidl::endpoints::RequestStream for RealmFactoryRequestStream {
310    type Protocol = RealmFactoryMarker;
311    type ControlHandle = RealmFactoryControlHandle;
312
313    fn from_channel(channel: ::fidl::AsyncChannel) -> Self {
314        Self { inner: std::sync::Arc::new(fidl::ServeInner::new(channel)), is_terminated: false }
315    }
316
317    fn control_handle(&self) -> Self::ControlHandle {
318        RealmFactoryControlHandle { inner: self.inner.clone() }
319    }
320
321    fn into_inner(
322        self,
323    ) -> (::std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>, bool)
324    {
325        (self.inner, self.is_terminated)
326    }
327
328    fn from_inner(
329        inner: std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>,
330        is_terminated: bool,
331    ) -> Self {
332        Self { inner, is_terminated }
333    }
334}
335
336impl futures::Stream for RealmFactoryRequestStream {
337    type Item = Result<RealmFactoryRequest, fidl::Error>;
338
339    fn poll_next(
340        mut self: std::pin::Pin<&mut Self>,
341        cx: &mut std::task::Context<'_>,
342    ) -> std::task::Poll<Option<Self::Item>> {
343        let this = &mut *self;
344        if this.inner.check_shutdown(cx) {
345            this.is_terminated = true;
346            return std::task::Poll::Ready(None);
347        }
348        if this.is_terminated {
349            panic!("polled RealmFactoryRequestStream after completion");
350        }
351        fidl::encoding::with_tls_decode_buf::<_, fidl::encoding::DefaultFuchsiaResourceDialect>(
352            |bytes, handles| {
353                match this.inner.channel().read_etc(cx, bytes, handles) {
354                    std::task::Poll::Ready(Ok(())) => {}
355                    std::task::Poll::Pending => return std::task::Poll::Pending,
356                    std::task::Poll::Ready(Err(zx_status::Status::PEER_CLOSED)) => {
357                        this.is_terminated = true;
358                        return std::task::Poll::Ready(None);
359                    }
360                    std::task::Poll::Ready(Err(e)) => {
361                        return std::task::Poll::Ready(Some(Err(fidl::Error::ServerRequestRead(
362                            e.into(),
363                        ))));
364                    }
365                }
366
367                // A message has been received from the channel
368                let (header, _body_bytes) = fidl::encoding::decode_transaction_header(bytes)?;
369
370                std::task::Poll::Ready(Some(match header.ordinal {
371                    0x5484d2814b7a3c5c => {
372                        header.validate_request_tx_id(fidl::MethodType::TwoWay)?;
373                        let mut req = fidl::new_empty!(
374                            RealmFactoryCreateRealmRequest,
375                            fidl::encoding::DefaultFuchsiaResourceDialect
376                        );
377                        fidl::encoding::Decoder::<fidl::encoding::DefaultFuchsiaResourceDialect>::decode_into::<RealmFactoryCreateRealmRequest>(&header, _body_bytes, handles, &mut req)?;
378                        let control_handle =
379                            RealmFactoryControlHandle { inner: this.inner.clone() };
380                        Ok(RealmFactoryRequest::CreateRealm {
381                            options: req.options,
382
383                            responder: RealmFactoryCreateRealmResponder {
384                                control_handle: std::mem::ManuallyDrop::new(control_handle),
385                                tx_id: header.tx_id,
386                            },
387                        })
388                    }
389                    _ if header.tx_id == 0
390                        && header
391                            .dynamic_flags()
392                            .contains(fidl::encoding::DynamicFlags::FLEXIBLE) =>
393                    {
394                        Ok(RealmFactoryRequest::_UnknownMethod {
395                            ordinal: header.ordinal,
396                            control_handle: RealmFactoryControlHandle { inner: this.inner.clone() },
397                            method_type: fidl::MethodType::OneWay,
398                        })
399                    }
400                    _ if header
401                        .dynamic_flags()
402                        .contains(fidl::encoding::DynamicFlags::FLEXIBLE) =>
403                    {
404                        this.inner.send_framework_err(
405                            fidl::encoding::FrameworkErr::UnknownMethod,
406                            header.tx_id,
407                            header.ordinal,
408                            header.dynamic_flags(),
409                            (bytes, handles),
410                        )?;
411                        Ok(RealmFactoryRequest::_UnknownMethod {
412                            ordinal: header.ordinal,
413                            control_handle: RealmFactoryControlHandle { inner: this.inner.clone() },
414                            method_type: fidl::MethodType::TwoWay,
415                        })
416                    }
417                    _ => Err(fidl::Error::UnknownOrdinal {
418                        ordinal: header.ordinal,
419                        protocol_name:
420                            <RealmFactoryMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME,
421                    }),
422                }))
423            },
424        )
425    }
426}
427
428#[derive(Debug)]
429pub enum RealmFactoryRequest {
430    /// Specifies the options to use when creating the realm.
431    ///
432    /// Returns OperationError.INVALID if called more than once.
433    CreateRealm { options: RealmOptions, responder: RealmFactoryCreateRealmResponder },
434    /// An interaction was received which does not match any known method.
435    #[non_exhaustive]
436    _UnknownMethod {
437        /// Ordinal of the method that was called.
438        ordinal: u64,
439        control_handle: RealmFactoryControlHandle,
440        method_type: fidl::MethodType,
441    },
442}
443
444impl RealmFactoryRequest {
445    #[allow(irrefutable_let_patterns)]
446    pub fn into_create_realm(self) -> Option<(RealmOptions, RealmFactoryCreateRealmResponder)> {
447        if let RealmFactoryRequest::CreateRealm { options, responder } = self {
448            Some((options, responder))
449        } else {
450            None
451        }
452    }
453
454    /// Name of the method defined in FIDL
455    pub fn method_name(&self) -> &'static str {
456        match *self {
457            RealmFactoryRequest::CreateRealm { .. } => "create_realm",
458            RealmFactoryRequest::_UnknownMethod {
459                method_type: fidl::MethodType::OneWay, ..
460            } => "unknown one-way method",
461            RealmFactoryRequest::_UnknownMethod {
462                method_type: fidl::MethodType::TwoWay, ..
463            } => "unknown two-way method",
464        }
465    }
466}
467
468#[derive(Debug, Clone)]
469pub struct RealmFactoryControlHandle {
470    inner: std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>,
471}
472
473impl fidl::endpoints::ControlHandle for RealmFactoryControlHandle {
474    fn shutdown(&self) {
475        self.inner.shutdown()
476    }
477
478    fn shutdown_with_epitaph(&self, status: zx_status::Status) {
479        self.inner.shutdown_with_epitaph(status)
480    }
481
482    fn is_closed(&self) -> bool {
483        self.inner.channel().is_closed()
484    }
485    fn on_closed(&self) -> fidl::OnSignalsRef<'_> {
486        self.inner.channel().on_closed()
487    }
488
489    #[cfg(target_os = "fuchsia")]
490    fn signal_peer(
491        &self,
492        clear_mask: zx::Signals,
493        set_mask: zx::Signals,
494    ) -> Result<(), zx_status::Status> {
495        use fidl::Peered;
496        self.inner.channel().signal_peer(clear_mask, set_mask)
497    }
498}
499
500impl RealmFactoryControlHandle {}
501
502#[must_use = "FIDL methods require a response to be sent"]
503#[derive(Debug)]
504pub struct RealmFactoryCreateRealmResponder {
505    control_handle: std::mem::ManuallyDrop<RealmFactoryControlHandle>,
506    tx_id: u32,
507}
508
509/// Set the the channel to be shutdown (see [`RealmFactoryControlHandle::shutdown`])
510/// if the responder is dropped without sending a response, so that the client
511/// doesn't hang. To prevent this behavior, call `drop_without_shutdown`.
512impl std::ops::Drop for RealmFactoryCreateRealmResponder {
513    fn drop(&mut self) {
514        self.control_handle.shutdown();
515        // Safety: drops once, never accessed again
516        unsafe { std::mem::ManuallyDrop::drop(&mut self.control_handle) };
517    }
518}
519
520impl fidl::endpoints::Responder for RealmFactoryCreateRealmResponder {
521    type ControlHandle = RealmFactoryControlHandle;
522
523    fn control_handle(&self) -> &RealmFactoryControlHandle {
524        &self.control_handle
525    }
526
527    fn drop_without_shutdown(mut self) {
528        // Safety: drops once, never accessed again due to mem::forget
529        unsafe { std::mem::ManuallyDrop::drop(&mut self.control_handle) };
530        // Prevent Drop from running (which would shut down the channel)
531        std::mem::forget(self);
532    }
533}
534
535impl RealmFactoryCreateRealmResponder {
536    /// Sends a response to the FIDL transaction.
537    ///
538    /// Sets the channel to shutdown if an error occurs.
539    pub fn send(
540        self,
541        mut result: Result<fidl::EventPair, fidl_fuchsia_testing_harness::OperationError>,
542    ) -> Result<(), fidl::Error> {
543        let _result = self.send_raw(result);
544        if _result.is_err() {
545            self.control_handle.shutdown();
546        }
547        self.drop_without_shutdown();
548        _result
549    }
550
551    /// Similar to "send" but does not shutdown the channel if an error occurs.
552    pub fn send_no_shutdown_on_err(
553        self,
554        mut result: Result<fidl::EventPair, fidl_fuchsia_testing_harness::OperationError>,
555    ) -> Result<(), fidl::Error> {
556        let _result = self.send_raw(result);
557        self.drop_without_shutdown();
558        _result
559    }
560
561    fn send_raw(
562        &self,
563        mut result: Result<fidl::EventPair, fidl_fuchsia_testing_harness::OperationError>,
564    ) -> Result<(), fidl::Error> {
565        self.control_handle.inner.send::<fidl::encoding::FlexibleResultType<
566            RealmFactoryCreateRealmResponse,
567            fidl_fuchsia_testing_harness::OperationError,
568        >>(
569            fidl::encoding::FlexibleResult::new(result.map(|dictionary| (dictionary,))),
570            self.tx_id,
571            0x5484d2814b7a3c5c,
572            fidl::encoding::DynamicFlags::FLEXIBLE,
573        )
574    }
575}
576
577mod internal {
578    use super::*;
579
580    impl fidl::encoding::ResourceTypeMarker for RealmFactoryCreateRealmRequest {
581        type Borrowed<'a> = &'a mut Self;
582        fn take_or_borrow<'a>(
583            value: &'a mut <Self as fidl::encoding::TypeMarker>::Owned,
584        ) -> Self::Borrowed<'a> {
585            value
586        }
587    }
588
589    unsafe impl fidl::encoding::TypeMarker for RealmFactoryCreateRealmRequest {
590        type Owned = Self;
591
592        #[inline(always)]
593        fn inline_align(_context: fidl::encoding::Context) -> usize {
594            8
595        }
596
597        #[inline(always)]
598        fn inline_size(_context: fidl::encoding::Context) -> usize {
599            16
600        }
601    }
602
603    unsafe impl
604        fidl::encoding::Encode<
605            RealmFactoryCreateRealmRequest,
606            fidl::encoding::DefaultFuchsiaResourceDialect,
607        > for &mut RealmFactoryCreateRealmRequest
608    {
609        #[inline]
610        unsafe fn encode(
611            self,
612            encoder: &mut fidl::encoding::Encoder<
613                '_,
614                fidl::encoding::DefaultFuchsiaResourceDialect,
615            >,
616            offset: usize,
617            _depth: fidl::encoding::Depth,
618        ) -> fidl::Result<()> {
619            encoder.debug_check_bounds::<RealmFactoryCreateRealmRequest>(offset);
620            // Delegate to tuple encoding.
621            fidl::encoding::Encode::<
622                RealmFactoryCreateRealmRequest,
623                fidl::encoding::DefaultFuchsiaResourceDialect,
624            >::encode(
625                (<RealmOptions as fidl::encoding::ResourceTypeMarker>::take_or_borrow(
626                    &mut self.options,
627                ),),
628                encoder,
629                offset,
630                _depth,
631            )
632        }
633    }
634    unsafe impl<
635        T0: fidl::encoding::Encode<RealmOptions, fidl::encoding::DefaultFuchsiaResourceDialect>,
636    >
637        fidl::encoding::Encode<
638            RealmFactoryCreateRealmRequest,
639            fidl::encoding::DefaultFuchsiaResourceDialect,
640        > for (T0,)
641    {
642        #[inline]
643        unsafe fn encode(
644            self,
645            encoder: &mut fidl::encoding::Encoder<
646                '_,
647                fidl::encoding::DefaultFuchsiaResourceDialect,
648            >,
649            offset: usize,
650            depth: fidl::encoding::Depth,
651        ) -> fidl::Result<()> {
652            encoder.debug_check_bounds::<RealmFactoryCreateRealmRequest>(offset);
653            // Zero out padding regions. There's no need to apply masks
654            // because the unmasked parts will be overwritten by fields.
655            // Write the fields.
656            self.0.encode(encoder, offset + 0, depth)?;
657            Ok(())
658        }
659    }
660
661    impl fidl::encoding::Decode<Self, fidl::encoding::DefaultFuchsiaResourceDialect>
662        for RealmFactoryCreateRealmRequest
663    {
664        #[inline(always)]
665        fn new_empty() -> Self {
666            Self {
667                options: fidl::new_empty!(
668                    RealmOptions,
669                    fidl::encoding::DefaultFuchsiaResourceDialect
670                ),
671            }
672        }
673
674        #[inline]
675        unsafe fn decode(
676            &mut self,
677            decoder: &mut fidl::encoding::Decoder<
678                '_,
679                fidl::encoding::DefaultFuchsiaResourceDialect,
680            >,
681            offset: usize,
682            _depth: fidl::encoding::Depth,
683        ) -> fidl::Result<()> {
684            decoder.debug_check_bounds::<Self>(offset);
685            // Verify that padding bytes are zero.
686            fidl::decode!(
687                RealmOptions,
688                fidl::encoding::DefaultFuchsiaResourceDialect,
689                &mut self.options,
690                decoder,
691                offset + 0,
692                _depth
693            )?;
694            Ok(())
695        }
696    }
697
698    impl fidl::encoding::ResourceTypeMarker for RealmFactoryCreateRealmResponse {
699        type Borrowed<'a> = &'a mut Self;
700        fn take_or_borrow<'a>(
701            value: &'a mut <Self as fidl::encoding::TypeMarker>::Owned,
702        ) -> Self::Borrowed<'a> {
703            value
704        }
705    }
706
707    unsafe impl fidl::encoding::TypeMarker for RealmFactoryCreateRealmResponse {
708        type Owned = Self;
709
710        #[inline(always)]
711        fn inline_align(_context: fidl::encoding::Context) -> usize {
712            4
713        }
714
715        #[inline(always)]
716        fn inline_size(_context: fidl::encoding::Context) -> usize {
717            4
718        }
719    }
720
721    unsafe impl
722        fidl::encoding::Encode<
723            RealmFactoryCreateRealmResponse,
724            fidl::encoding::DefaultFuchsiaResourceDialect,
725        > for &mut RealmFactoryCreateRealmResponse
726    {
727        #[inline]
728        unsafe fn encode(
729            self,
730            encoder: &mut fidl::encoding::Encoder<
731                '_,
732                fidl::encoding::DefaultFuchsiaResourceDialect,
733            >,
734            offset: usize,
735            _depth: fidl::encoding::Depth,
736        ) -> fidl::Result<()> {
737            encoder.debug_check_bounds::<RealmFactoryCreateRealmResponse>(offset);
738            // Delegate to tuple encoding.
739            fidl::encoding::Encode::<
740                RealmFactoryCreateRealmResponse,
741                fidl::encoding::DefaultFuchsiaResourceDialect,
742            >::encode(
743                (<fidl::encoding::HandleType<
744                    fidl::EventPair,
745                    { fidl::ObjectType::EVENTPAIR.into_raw() },
746                    2147483648,
747                > as fidl::encoding::ResourceTypeMarker>::take_or_borrow(
748                    &mut self.dictionary
749                ),),
750                encoder,
751                offset,
752                _depth,
753            )
754        }
755    }
756    unsafe impl<
757        T0: fidl::encoding::Encode<
758                fidl::encoding::HandleType<
759                    fidl::EventPair,
760                    { fidl::ObjectType::EVENTPAIR.into_raw() },
761                    2147483648,
762                >,
763                fidl::encoding::DefaultFuchsiaResourceDialect,
764            >,
765    >
766        fidl::encoding::Encode<
767            RealmFactoryCreateRealmResponse,
768            fidl::encoding::DefaultFuchsiaResourceDialect,
769        > for (T0,)
770    {
771        #[inline]
772        unsafe fn encode(
773            self,
774            encoder: &mut fidl::encoding::Encoder<
775                '_,
776                fidl::encoding::DefaultFuchsiaResourceDialect,
777            >,
778            offset: usize,
779            depth: fidl::encoding::Depth,
780        ) -> fidl::Result<()> {
781            encoder.debug_check_bounds::<RealmFactoryCreateRealmResponse>(offset);
782            // Zero out padding regions. There's no need to apply masks
783            // because the unmasked parts will be overwritten by fields.
784            // Write the fields.
785            self.0.encode(encoder, offset + 0, depth)?;
786            Ok(())
787        }
788    }
789
790    impl fidl::encoding::Decode<Self, fidl::encoding::DefaultFuchsiaResourceDialect>
791        for RealmFactoryCreateRealmResponse
792    {
793        #[inline(always)]
794        fn new_empty() -> Self {
795            Self {
796                dictionary: fidl::new_empty!(fidl::encoding::HandleType<fidl::EventPair, { fidl::ObjectType::EVENTPAIR.into_raw() }, 2147483648>, fidl::encoding::DefaultFuchsiaResourceDialect),
797            }
798        }
799
800        #[inline]
801        unsafe fn decode(
802            &mut self,
803            decoder: &mut fidl::encoding::Decoder<
804                '_,
805                fidl::encoding::DefaultFuchsiaResourceDialect,
806            >,
807            offset: usize,
808            _depth: fidl::encoding::Depth,
809        ) -> fidl::Result<()> {
810            decoder.debug_check_bounds::<Self>(offset);
811            // Verify that padding bytes are zero.
812            fidl::decode!(fidl::encoding::HandleType<fidl::EventPair, { fidl::ObjectType::EVENTPAIR.into_raw() }, 2147483648>, fidl::encoding::DefaultFuchsiaResourceDialect, &mut self.dictionary, decoder, offset + 0, _depth)?;
813            Ok(())
814        }
815    }
816
817    impl RealmOptions {
818        #[inline(always)]
819        fn max_ordinal_present(&self) -> u64 {
820            if let Some(_) = self.example_option {
821                return 1;
822            }
823            0
824        }
825    }
826
827    impl fidl::encoding::ResourceTypeMarker for RealmOptions {
828        type Borrowed<'a> = &'a mut Self;
829        fn take_or_borrow<'a>(
830            value: &'a mut <Self as fidl::encoding::TypeMarker>::Owned,
831        ) -> Self::Borrowed<'a> {
832            value
833        }
834    }
835
836    unsafe impl fidl::encoding::TypeMarker for RealmOptions {
837        type Owned = Self;
838
839        #[inline(always)]
840        fn inline_align(_context: fidl::encoding::Context) -> usize {
841            8
842        }
843
844        #[inline(always)]
845        fn inline_size(_context: fidl::encoding::Context) -> usize {
846            16
847        }
848    }
849
850    unsafe impl fidl::encoding::Encode<RealmOptions, fidl::encoding::DefaultFuchsiaResourceDialect>
851        for &mut RealmOptions
852    {
853        unsafe fn encode(
854            self,
855            encoder: &mut fidl::encoding::Encoder<
856                '_,
857                fidl::encoding::DefaultFuchsiaResourceDialect,
858            >,
859            offset: usize,
860            mut depth: fidl::encoding::Depth,
861        ) -> fidl::Result<()> {
862            encoder.debug_check_bounds::<RealmOptions>(offset);
863            // Vector header
864            let max_ordinal: u64 = self.max_ordinal_present();
865            encoder.write_num(max_ordinal, offset);
866            encoder.write_num(fidl::encoding::ALLOC_PRESENT_U64, offset + 8);
867            // Calling encoder.out_of_line_offset(0) is not allowed.
868            if max_ordinal == 0 {
869                return Ok(());
870            }
871            depth.increment()?;
872            let envelope_size = 8;
873            let bytes_len = max_ordinal as usize * envelope_size;
874            #[allow(unused_variables)]
875            let offset = encoder.out_of_line_offset(bytes_len);
876            let mut _prev_end_offset: usize = 0;
877            if 1 > max_ordinal {
878                return Ok(());
879            }
880
881            // Write at offset+(ordinal-1)*envelope_size, since ordinals are one-based and envelopes
882            // are envelope_size bytes.
883            let cur_offset: usize = (1 - 1) * envelope_size;
884
885            // Zero reserved fields.
886            encoder.padding(offset + _prev_end_offset, cur_offset - _prev_end_offset);
887
888            // Safety:
889            // - bytes_len is calculated to fit envelope_size*max(member.ordinal).
890            // - Since cur_offset is envelope_size*(member.ordinal - 1) and the envelope takes
891            //   envelope_size bytes, there is always sufficient room.
892            fidl::encoding::encode_in_envelope_optional::<
893                bool,
894                fidl::encoding::DefaultFuchsiaResourceDialect,
895            >(
896                self.example_option.as_ref().map(<bool as fidl::encoding::ValueTypeMarker>::borrow),
897                encoder,
898                offset + cur_offset,
899                depth,
900            )?;
901
902            _prev_end_offset = cur_offset + envelope_size;
903
904            Ok(())
905        }
906    }
907
908    impl fidl::encoding::Decode<Self, fidl::encoding::DefaultFuchsiaResourceDialect> for RealmOptions {
909        #[inline(always)]
910        fn new_empty() -> Self {
911            Self::default()
912        }
913
914        unsafe fn decode(
915            &mut self,
916            decoder: &mut fidl::encoding::Decoder<
917                '_,
918                fidl::encoding::DefaultFuchsiaResourceDialect,
919            >,
920            offset: usize,
921            mut depth: fidl::encoding::Depth,
922        ) -> fidl::Result<()> {
923            decoder.debug_check_bounds::<Self>(offset);
924            let len = match fidl::encoding::decode_vector_header(decoder, offset)? {
925                None => return Err(fidl::Error::NotNullable),
926                Some(len) => len,
927            };
928            // Calling decoder.out_of_line_offset(0) is not allowed.
929            if len == 0 {
930                return Ok(());
931            };
932            depth.increment()?;
933            let envelope_size = 8;
934            let bytes_len = len * envelope_size;
935            let offset = decoder.out_of_line_offset(bytes_len)?;
936            // Decode the envelope for each type.
937            let mut _next_ordinal_to_read = 0;
938            let mut next_offset = offset;
939            let end_offset = offset + bytes_len;
940            _next_ordinal_to_read += 1;
941            if next_offset >= end_offset {
942                return Ok(());
943            }
944
945            // Decode unknown envelopes for gaps in ordinals.
946            while _next_ordinal_to_read < 1 {
947                fidl::encoding::decode_unknown_envelope(decoder, next_offset, depth)?;
948                _next_ordinal_to_read += 1;
949                next_offset += envelope_size;
950            }
951
952            let next_out_of_line = decoder.next_out_of_line();
953            let handles_before = decoder.remaining_handles();
954            if let Some((inlined, num_bytes, num_handles)) =
955                fidl::encoding::decode_envelope_header(decoder, next_offset)?
956            {
957                let member_inline_size =
958                    <bool as fidl::encoding::TypeMarker>::inline_size(decoder.context);
959                if inlined != (member_inline_size <= 4) {
960                    return Err(fidl::Error::InvalidInlineBitInEnvelope);
961                }
962                let inner_offset;
963                let mut inner_depth = depth.clone();
964                if inlined {
965                    decoder.check_inline_envelope_padding(next_offset, member_inline_size)?;
966                    inner_offset = next_offset;
967                } else {
968                    inner_offset = decoder.out_of_line_offset(member_inline_size)?;
969                    inner_depth.increment()?;
970                }
971                let val_ref = self.example_option.get_or_insert_with(|| {
972                    fidl::new_empty!(bool, fidl::encoding::DefaultFuchsiaResourceDialect)
973                });
974                fidl::decode!(
975                    bool,
976                    fidl::encoding::DefaultFuchsiaResourceDialect,
977                    val_ref,
978                    decoder,
979                    inner_offset,
980                    inner_depth
981                )?;
982                if !inlined && decoder.next_out_of_line() != next_out_of_line + (num_bytes as usize)
983                {
984                    return Err(fidl::Error::InvalidNumBytesInEnvelope);
985                }
986                if handles_before != decoder.remaining_handles() + (num_handles as usize) {
987                    return Err(fidl::Error::InvalidNumHandlesInEnvelope);
988                }
989            }
990
991            next_offset += envelope_size;
992
993            // Decode the remaining unknown envelopes.
994            while next_offset < end_offset {
995                _next_ordinal_to_read += 1;
996                fidl::encoding::decode_unknown_envelope(decoder, next_offset, depth)?;
997                next_offset += envelope_size;
998            }
999
1000            Ok(())
1001        }
1002    }
1003}