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::Handle {
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    fn shutdown_with_epitaph(&self, status: zx_status::Status) {
480        self.inner.shutdown_with_epitaph(status)
481    }
482
483    fn is_closed(&self) -> bool {
484        self.inner.channel().is_closed()
485    }
486    fn on_closed(&self) -> fidl::OnSignalsRef<'_> {
487        self.inner.channel().on_closed()
488    }
489
490    #[cfg(target_os = "fuchsia")]
491    fn signal_peer(
492        &self,
493        clear_mask: zx::Signals,
494        set_mask: zx::Signals,
495    ) -> Result<(), zx_status::Status> {
496        use fidl::Peered;
497        self.inner.channel().signal_peer(clear_mask, set_mask)
498    }
499}
500
501impl RealmFactoryControlHandle {}
502
503#[must_use = "FIDL methods require a response to be sent"]
504#[derive(Debug)]
505pub struct RealmFactoryCreateRealmResponder {
506    control_handle: std::mem::ManuallyDrop<RealmFactoryControlHandle>,
507    tx_id: u32,
508}
509
510/// Set the the channel to be shutdown (see [`RealmFactoryControlHandle::shutdown`])
511/// if the responder is dropped without sending a response, so that the client
512/// doesn't hang. To prevent this behavior, call `drop_without_shutdown`.
513impl std::ops::Drop for RealmFactoryCreateRealmResponder {
514    fn drop(&mut self) {
515        self.control_handle.shutdown();
516        // Safety: drops once, never accessed again
517        unsafe { std::mem::ManuallyDrop::drop(&mut self.control_handle) };
518    }
519}
520
521impl fidl::endpoints::Responder for RealmFactoryCreateRealmResponder {
522    type ControlHandle = RealmFactoryControlHandle;
523
524    fn control_handle(&self) -> &RealmFactoryControlHandle {
525        &self.control_handle
526    }
527
528    fn drop_without_shutdown(mut self) {
529        // Safety: drops once, never accessed again due to mem::forget
530        unsafe { std::mem::ManuallyDrop::drop(&mut self.control_handle) };
531        // Prevent Drop from running (which would shut down the channel)
532        std::mem::forget(self);
533    }
534}
535
536impl RealmFactoryCreateRealmResponder {
537    /// Sends a response to the FIDL transaction.
538    ///
539    /// Sets the channel to shutdown if an error occurs.
540    pub fn send(
541        self,
542        mut result: Result<
543            fidl::endpoints::ClientEnd<fidl_fuchsia_component_sandbox::DictionaryMarker>,
544            fidl_fuchsia_testing_harness::OperationError,
545        >,
546    ) -> Result<(), fidl::Error> {
547        let _result = self.send_raw(result);
548        if _result.is_err() {
549            self.control_handle.shutdown();
550        }
551        self.drop_without_shutdown();
552        _result
553    }
554
555    /// Similar to "send" but does not shutdown the channel if an error occurs.
556    pub fn send_no_shutdown_on_err(
557        self,
558        mut result: Result<
559            fidl::endpoints::ClientEnd<fidl_fuchsia_component_sandbox::DictionaryMarker>,
560            fidl_fuchsia_testing_harness::OperationError,
561        >,
562    ) -> Result<(), fidl::Error> {
563        let _result = self.send_raw(result);
564        self.drop_without_shutdown();
565        _result
566    }
567
568    fn send_raw(
569        &self,
570        mut result: Result<
571            fidl::endpoints::ClientEnd<fidl_fuchsia_component_sandbox::DictionaryMarker>,
572            fidl_fuchsia_testing_harness::OperationError,
573        >,
574    ) -> Result<(), fidl::Error> {
575        self.control_handle.inner.send::<fidl::encoding::FlexibleResultType<
576            RealmFactoryCreateRealmResponse,
577            fidl_fuchsia_testing_harness::OperationError,
578        >>(
579            fidl::encoding::FlexibleResult::new(result.map(|dictionary| (dictionary,))),
580            self.tx_id,
581            0x5484d2814b7a3c5c,
582            fidl::encoding::DynamicFlags::FLEXIBLE,
583        )
584    }
585}
586
587mod internal {
588    use super::*;
589
590    impl fidl::encoding::ResourceTypeMarker for RealmFactoryCreateRealmRequest {
591        type Borrowed<'a> = &'a mut Self;
592        fn take_or_borrow<'a>(
593            value: &'a mut <Self as fidl::encoding::TypeMarker>::Owned,
594        ) -> Self::Borrowed<'a> {
595            value
596        }
597    }
598
599    unsafe impl fidl::encoding::TypeMarker for RealmFactoryCreateRealmRequest {
600        type Owned = Self;
601
602        #[inline(always)]
603        fn inline_align(_context: fidl::encoding::Context) -> usize {
604            8
605        }
606
607        #[inline(always)]
608        fn inline_size(_context: fidl::encoding::Context) -> usize {
609            16
610        }
611    }
612
613    unsafe impl
614        fidl::encoding::Encode<
615            RealmFactoryCreateRealmRequest,
616            fidl::encoding::DefaultFuchsiaResourceDialect,
617        > for &mut RealmFactoryCreateRealmRequest
618    {
619        #[inline]
620        unsafe fn encode(
621            self,
622            encoder: &mut fidl::encoding::Encoder<
623                '_,
624                fidl::encoding::DefaultFuchsiaResourceDialect,
625            >,
626            offset: usize,
627            _depth: fidl::encoding::Depth,
628        ) -> fidl::Result<()> {
629            encoder.debug_check_bounds::<RealmFactoryCreateRealmRequest>(offset);
630            // Delegate to tuple encoding.
631            fidl::encoding::Encode::<
632                RealmFactoryCreateRealmRequest,
633                fidl::encoding::DefaultFuchsiaResourceDialect,
634            >::encode(
635                (<RealmOptions as fidl::encoding::ResourceTypeMarker>::take_or_borrow(
636                    &mut self.options,
637                ),),
638                encoder,
639                offset,
640                _depth,
641            )
642        }
643    }
644    unsafe impl<
645            T0: fidl::encoding::Encode<RealmOptions, fidl::encoding::DefaultFuchsiaResourceDialect>,
646        >
647        fidl::encoding::Encode<
648            RealmFactoryCreateRealmRequest,
649            fidl::encoding::DefaultFuchsiaResourceDialect,
650        > for (T0,)
651    {
652        #[inline]
653        unsafe fn encode(
654            self,
655            encoder: &mut fidl::encoding::Encoder<
656                '_,
657                fidl::encoding::DefaultFuchsiaResourceDialect,
658            >,
659            offset: usize,
660            depth: fidl::encoding::Depth,
661        ) -> fidl::Result<()> {
662            encoder.debug_check_bounds::<RealmFactoryCreateRealmRequest>(offset);
663            // Zero out padding regions. There's no need to apply masks
664            // because the unmasked parts will be overwritten by fields.
665            // Write the fields.
666            self.0.encode(encoder, offset + 0, depth)?;
667            Ok(())
668        }
669    }
670
671    impl fidl::encoding::Decode<Self, fidl::encoding::DefaultFuchsiaResourceDialect>
672        for RealmFactoryCreateRealmRequest
673    {
674        #[inline(always)]
675        fn new_empty() -> Self {
676            Self {
677                options: fidl::new_empty!(
678                    RealmOptions,
679                    fidl::encoding::DefaultFuchsiaResourceDialect
680                ),
681            }
682        }
683
684        #[inline]
685        unsafe fn decode(
686            &mut self,
687            decoder: &mut fidl::encoding::Decoder<
688                '_,
689                fidl::encoding::DefaultFuchsiaResourceDialect,
690            >,
691            offset: usize,
692            _depth: fidl::encoding::Depth,
693        ) -> fidl::Result<()> {
694            decoder.debug_check_bounds::<Self>(offset);
695            // Verify that padding bytes are zero.
696            fidl::decode!(
697                RealmOptions,
698                fidl::encoding::DefaultFuchsiaResourceDialect,
699                &mut self.options,
700                decoder,
701                offset + 0,
702                _depth
703            )?;
704            Ok(())
705        }
706    }
707
708    impl fidl::encoding::ResourceTypeMarker for RealmFactoryCreateRealmResponse {
709        type Borrowed<'a> = &'a mut Self;
710        fn take_or_borrow<'a>(
711            value: &'a mut <Self as fidl::encoding::TypeMarker>::Owned,
712        ) -> Self::Borrowed<'a> {
713            value
714        }
715    }
716
717    unsafe impl fidl::encoding::TypeMarker for RealmFactoryCreateRealmResponse {
718        type Owned = Self;
719
720        #[inline(always)]
721        fn inline_align(_context: fidl::encoding::Context) -> usize {
722            4
723        }
724
725        #[inline(always)]
726        fn inline_size(_context: fidl::encoding::Context) -> usize {
727            4
728        }
729    }
730
731    unsafe impl
732        fidl::encoding::Encode<
733            RealmFactoryCreateRealmResponse,
734            fidl::encoding::DefaultFuchsiaResourceDialect,
735        > for &mut RealmFactoryCreateRealmResponse
736    {
737        #[inline]
738        unsafe fn encode(
739            self,
740            encoder: &mut fidl::encoding::Encoder<
741                '_,
742                fidl::encoding::DefaultFuchsiaResourceDialect,
743            >,
744            offset: usize,
745            _depth: fidl::encoding::Depth,
746        ) -> fidl::Result<()> {
747            encoder.debug_check_bounds::<RealmFactoryCreateRealmResponse>(offset);
748            // Delegate to tuple encoding.
749            fidl::encoding::Encode::<
750                RealmFactoryCreateRealmResponse,
751                fidl::encoding::DefaultFuchsiaResourceDialect,
752            >::encode(
753                (<fidl::encoding::Endpoint<
754                    fidl::endpoints::ClientEnd<fidl_fuchsia_component_sandbox::DictionaryMarker>,
755                > as fidl::encoding::ResourceTypeMarker>::take_or_borrow(
756                    &mut self.dictionary
757                ),),
758                encoder,
759                offset,
760                _depth,
761            )
762        }
763    }
764    unsafe impl<
765            T0: fidl::encoding::Encode<
766                fidl::encoding::Endpoint<
767                    fidl::endpoints::ClientEnd<fidl_fuchsia_component_sandbox::DictionaryMarker>,
768                >,
769                fidl::encoding::DefaultFuchsiaResourceDialect,
770            >,
771        >
772        fidl::encoding::Encode<
773            RealmFactoryCreateRealmResponse,
774            fidl::encoding::DefaultFuchsiaResourceDialect,
775        > for (T0,)
776    {
777        #[inline]
778        unsafe fn encode(
779            self,
780            encoder: &mut fidl::encoding::Encoder<
781                '_,
782                fidl::encoding::DefaultFuchsiaResourceDialect,
783            >,
784            offset: usize,
785            depth: fidl::encoding::Depth,
786        ) -> fidl::Result<()> {
787            encoder.debug_check_bounds::<RealmFactoryCreateRealmResponse>(offset);
788            // Zero out padding regions. There's no need to apply masks
789            // because the unmasked parts will be overwritten by fields.
790            // Write the fields.
791            self.0.encode(encoder, offset + 0, depth)?;
792            Ok(())
793        }
794    }
795
796    impl fidl::encoding::Decode<Self, fidl::encoding::DefaultFuchsiaResourceDialect>
797        for RealmFactoryCreateRealmResponse
798    {
799        #[inline(always)]
800        fn new_empty() -> Self {
801            Self {
802                dictionary: fidl::new_empty!(
803                    fidl::encoding::Endpoint<
804                        fidl::endpoints::ClientEnd<
805                            fidl_fuchsia_component_sandbox::DictionaryMarker,
806                        >,
807                    >,
808                    fidl::encoding::DefaultFuchsiaResourceDialect
809                ),
810            }
811        }
812
813        #[inline]
814        unsafe fn decode(
815            &mut self,
816            decoder: &mut fidl::encoding::Decoder<
817                '_,
818                fidl::encoding::DefaultFuchsiaResourceDialect,
819            >,
820            offset: usize,
821            _depth: fidl::encoding::Depth,
822        ) -> fidl::Result<()> {
823            decoder.debug_check_bounds::<Self>(offset);
824            // Verify that padding bytes are zero.
825            fidl::decode!(
826                fidl::encoding::Endpoint<
827                    fidl::endpoints::ClientEnd<fidl_fuchsia_component_sandbox::DictionaryMarker>,
828                >,
829                fidl::encoding::DefaultFuchsiaResourceDialect,
830                &mut self.dictionary,
831                decoder,
832                offset + 0,
833                _depth
834            )?;
835            Ok(())
836        }
837    }
838
839    impl RealmOptions {
840        #[inline(always)]
841        fn max_ordinal_present(&self) -> u64 {
842            if let Some(_) = self.example_option {
843                return 1;
844            }
845            0
846        }
847    }
848
849    impl fidl::encoding::ResourceTypeMarker for RealmOptions {
850        type Borrowed<'a> = &'a mut Self;
851        fn take_or_borrow<'a>(
852            value: &'a mut <Self as fidl::encoding::TypeMarker>::Owned,
853        ) -> Self::Borrowed<'a> {
854            value
855        }
856    }
857
858    unsafe impl fidl::encoding::TypeMarker for RealmOptions {
859        type Owned = Self;
860
861        #[inline(always)]
862        fn inline_align(_context: fidl::encoding::Context) -> usize {
863            8
864        }
865
866        #[inline(always)]
867        fn inline_size(_context: fidl::encoding::Context) -> usize {
868            16
869        }
870    }
871
872    unsafe impl fidl::encoding::Encode<RealmOptions, fidl::encoding::DefaultFuchsiaResourceDialect>
873        for &mut RealmOptions
874    {
875        unsafe fn encode(
876            self,
877            encoder: &mut fidl::encoding::Encoder<
878                '_,
879                fidl::encoding::DefaultFuchsiaResourceDialect,
880            >,
881            offset: usize,
882            mut depth: fidl::encoding::Depth,
883        ) -> fidl::Result<()> {
884            encoder.debug_check_bounds::<RealmOptions>(offset);
885            // Vector header
886            let max_ordinal: u64 = self.max_ordinal_present();
887            encoder.write_num(max_ordinal, offset);
888            encoder.write_num(fidl::encoding::ALLOC_PRESENT_U64, offset + 8);
889            // Calling encoder.out_of_line_offset(0) is not allowed.
890            if max_ordinal == 0 {
891                return Ok(());
892            }
893            depth.increment()?;
894            let envelope_size = 8;
895            let bytes_len = max_ordinal as usize * envelope_size;
896            #[allow(unused_variables)]
897            let offset = encoder.out_of_line_offset(bytes_len);
898            let mut _prev_end_offset: usize = 0;
899            if 1 > max_ordinal {
900                return Ok(());
901            }
902
903            // Write at offset+(ordinal-1)*envelope_size, since ordinals are one-based and envelopes
904            // are envelope_size bytes.
905            let cur_offset: usize = (1 - 1) * envelope_size;
906
907            // Zero reserved fields.
908            encoder.padding(offset + _prev_end_offset, cur_offset - _prev_end_offset);
909
910            // Safety:
911            // - bytes_len is calculated to fit envelope_size*max(member.ordinal).
912            // - Since cur_offset is envelope_size*(member.ordinal - 1) and the envelope takes
913            //   envelope_size bytes, there is always sufficient room.
914            fidl::encoding::encode_in_envelope_optional::<
915                bool,
916                fidl::encoding::DefaultFuchsiaResourceDialect,
917            >(
918                self.example_option.as_ref().map(<bool as fidl::encoding::ValueTypeMarker>::borrow),
919                encoder,
920                offset + cur_offset,
921                depth,
922            )?;
923
924            _prev_end_offset = cur_offset + envelope_size;
925
926            Ok(())
927        }
928    }
929
930    impl fidl::encoding::Decode<Self, fidl::encoding::DefaultFuchsiaResourceDialect> for RealmOptions {
931        #[inline(always)]
932        fn new_empty() -> Self {
933            Self::default()
934        }
935
936        unsafe fn decode(
937            &mut self,
938            decoder: &mut fidl::encoding::Decoder<
939                '_,
940                fidl::encoding::DefaultFuchsiaResourceDialect,
941            >,
942            offset: usize,
943            mut depth: fidl::encoding::Depth,
944        ) -> fidl::Result<()> {
945            decoder.debug_check_bounds::<Self>(offset);
946            let len = match fidl::encoding::decode_vector_header(decoder, offset)? {
947                None => return Err(fidl::Error::NotNullable),
948                Some(len) => len,
949            };
950            // Calling decoder.out_of_line_offset(0) is not allowed.
951            if len == 0 {
952                return Ok(());
953            };
954            depth.increment()?;
955            let envelope_size = 8;
956            let bytes_len = len * envelope_size;
957            let offset = decoder.out_of_line_offset(bytes_len)?;
958            // Decode the envelope for each type.
959            let mut _next_ordinal_to_read = 0;
960            let mut next_offset = offset;
961            let end_offset = offset + bytes_len;
962            _next_ordinal_to_read += 1;
963            if next_offset >= end_offset {
964                return Ok(());
965            }
966
967            // Decode unknown envelopes for gaps in ordinals.
968            while _next_ordinal_to_read < 1 {
969                fidl::encoding::decode_unknown_envelope(decoder, next_offset, depth)?;
970                _next_ordinal_to_read += 1;
971                next_offset += envelope_size;
972            }
973
974            let next_out_of_line = decoder.next_out_of_line();
975            let handles_before = decoder.remaining_handles();
976            if let Some((inlined, num_bytes, num_handles)) =
977                fidl::encoding::decode_envelope_header(decoder, next_offset)?
978            {
979                let member_inline_size =
980                    <bool as fidl::encoding::TypeMarker>::inline_size(decoder.context);
981                if inlined != (member_inline_size <= 4) {
982                    return Err(fidl::Error::InvalidInlineBitInEnvelope);
983                }
984                let inner_offset;
985                let mut inner_depth = depth.clone();
986                if inlined {
987                    decoder.check_inline_envelope_padding(next_offset, member_inline_size)?;
988                    inner_offset = next_offset;
989                } else {
990                    inner_offset = decoder.out_of_line_offset(member_inline_size)?;
991                    inner_depth.increment()?;
992                }
993                let val_ref = self.example_option.get_or_insert_with(|| {
994                    fidl::new_empty!(bool, fidl::encoding::DefaultFuchsiaResourceDialect)
995                });
996                fidl::decode!(
997                    bool,
998                    fidl::encoding::DefaultFuchsiaResourceDialect,
999                    val_ref,
1000                    decoder,
1001                    inner_offset,
1002                    inner_depth
1003                )?;
1004                if !inlined && decoder.next_out_of_line() != next_out_of_line + (num_bytes as usize)
1005                {
1006                    return Err(fidl::Error::InvalidNumBytesInEnvelope);
1007                }
1008                if handles_before != decoder.remaining_handles() + (num_handles as usize) {
1009                    return Err(fidl::Error::InvalidNumHandlesInEnvelope);
1010                }
1011            }
1012
1013            next_offset += envelope_size;
1014
1015            // Decode the remaining unknown envelopes.
1016            while next_offset < end_offset {
1017                _next_ordinal_to_read += 1;
1018                fidl::encoding::decode_unknown_envelope(decoder, next_offset, depth)?;
1019                next_offset += envelope_size;
1020            }
1021
1022            Ok(())
1023        }
1024    }
1025}