Skip to main content

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