Skip to main content

fidl_test_echoserver/
fidl_test_echoserver.rs

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