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