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