fidl_test_examplecomponent/
fidl_test_examplecomponent.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_examplecomponent__common::*;
11use futures::future::{self, MaybeDone, TryFutureExt};
12use zx_status;
13
14#[derive(Debug, PartialEq)]
15pub struct RealmFactoryCreateRealmRequest {
16    pub options: RealmOptions,
17    pub realm_server: fidl::endpoints::ServerEnd<fidl_fuchsia_testing_harness::RealmProxy_Marker>,
18}
19
20impl fidl::Standalone<fidl::encoding::DefaultFuchsiaResourceDialect>
21    for RealmFactoryCreateRealmRequest
22{
23}
24
25/// RealmOptions tells the RealmFactory protocol how to create the test realm.
26#[derive(Debug, Default, PartialEq)]
27pub struct RealmOptions {
28    /// FIXME: Add some options here.
29    pub example_option: Option<bool>,
30    #[doc(hidden)]
31    pub __source_breaking: fidl::marker::SourceBreaking,
32}
33
34impl fidl::Standalone<fidl::encoding::DefaultFuchsiaResourceDialect> for RealmOptions {}
35
36#[derive(Debug, Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Hash)]
37pub struct RealmFactoryMarker;
38
39impl fidl::endpoints::ProtocolMarker for RealmFactoryMarker {
40    type Proxy = RealmFactoryProxy;
41    type RequestStream = RealmFactoryRequestStream;
42    #[cfg(target_os = "fuchsia")]
43    type SynchronousProxy = RealmFactorySynchronousProxy;
44
45    const DEBUG_NAME: &'static str = "test.examplecomponent.RealmFactory";
46}
47impl fidl::endpoints::DiscoverableProtocolMarker for RealmFactoryMarker {}
48pub type RealmFactoryCreateRealmResult = Result<(), fidl_fuchsia_testing_harness::OperationError>;
49
50pub trait RealmFactoryProxyInterface: Send + Sync {
51    type CreateRealmResponseFut: std::future::Future<Output = Result<RealmFactoryCreateRealmResult, fidl::Error>>
52        + Send;
53    fn r#create_realm(
54        &self,
55        options: RealmOptions,
56        realm_server: fidl::endpoints::ServerEnd<fidl_fuchsia_testing_harness::RealmProxy_Marker>,
57    ) -> Self::CreateRealmResponseFut;
58}
59#[derive(Debug)]
60#[cfg(target_os = "fuchsia")]
61pub struct RealmFactorySynchronousProxy {
62    client: fidl::client::sync::Client,
63}
64
65#[cfg(target_os = "fuchsia")]
66impl fidl::endpoints::SynchronousProxy for RealmFactorySynchronousProxy {
67    type Proxy = RealmFactoryProxy;
68    type Protocol = RealmFactoryMarker;
69
70    fn from_channel(inner: fidl::Channel) -> Self {
71        Self::new(inner)
72    }
73
74    fn into_channel(self) -> fidl::Channel {
75        self.client.into_channel()
76    }
77
78    fn as_channel(&self) -> &fidl::Channel {
79        self.client.as_channel()
80    }
81}
82
83#[cfg(target_os = "fuchsia")]
84impl RealmFactorySynchronousProxy {
85    pub fn new(channel: fidl::Channel) -> Self {
86        let protocol_name = <RealmFactoryMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME;
87        Self { client: fidl::client::sync::Client::new(channel, protocol_name) }
88    }
89
90    pub fn into_channel(self) -> fidl::Channel {
91        self.client.into_channel()
92    }
93
94    /// Waits until an event arrives and returns it. It is safe for other
95    /// threads to make concurrent requests while waiting for an event.
96    pub fn wait_for_event(
97        &self,
98        deadline: zx::MonotonicInstant,
99    ) -> Result<RealmFactoryEvent, fidl::Error> {
100        RealmFactoryEvent::decode(self.client.wait_for_event(deadline)?)
101    }
102
103    /// Creates a new realm and binds the given RealmProxy server end to it.
104    pub fn r#create_realm(
105        &self,
106        mut options: RealmOptions,
107        mut realm_server: fidl::endpoints::ServerEnd<
108            fidl_fuchsia_testing_harness::RealmProxy_Marker,
109        >,
110        ___deadline: zx::MonotonicInstant,
111    ) -> Result<RealmFactoryCreateRealmResult, fidl::Error> {
112        let _response = self
113            .client
114            .send_query::<RealmFactoryCreateRealmRequest, fidl::encoding::FlexibleResultType<
115                fidl::encoding::EmptyStruct,
116                fidl_fuchsia_testing_harness::OperationError,
117            >>(
118                (&mut options, realm_server),
119                0x32757e6ace9b16c9,
120                fidl::encoding::DynamicFlags::FLEXIBLE,
121                ___deadline,
122            )?
123            .into_result::<RealmFactoryMarker>("create_realm")?;
124        Ok(_response.map(|x| x))
125    }
126}
127
128#[cfg(target_os = "fuchsia")]
129impl From<RealmFactorySynchronousProxy> for zx::Handle {
130    fn from(value: RealmFactorySynchronousProxy) -> Self {
131        value.into_channel().into()
132    }
133}
134
135#[cfg(target_os = "fuchsia")]
136impl From<fidl::Channel> for RealmFactorySynchronousProxy {
137    fn from(value: fidl::Channel) -> Self {
138        Self::new(value)
139    }
140}
141
142#[cfg(target_os = "fuchsia")]
143impl fidl::endpoints::FromClient for RealmFactorySynchronousProxy {
144    type Protocol = RealmFactoryMarker;
145
146    fn from_client(value: fidl::endpoints::ClientEnd<RealmFactoryMarker>) -> Self {
147        Self::new(value.into_channel())
148    }
149}
150
151#[derive(Debug, Clone)]
152pub struct RealmFactoryProxy {
153    client: fidl::client::Client<fidl::encoding::DefaultFuchsiaResourceDialect>,
154}
155
156impl fidl::endpoints::Proxy for RealmFactoryProxy {
157    type Protocol = RealmFactoryMarker;
158
159    fn from_channel(inner: ::fidl::AsyncChannel) -> Self {
160        Self::new(inner)
161    }
162
163    fn into_channel(self) -> Result<::fidl::AsyncChannel, Self> {
164        self.client.into_channel().map_err(|client| Self { client })
165    }
166
167    fn as_channel(&self) -> &::fidl::AsyncChannel {
168        self.client.as_channel()
169    }
170}
171
172impl RealmFactoryProxy {
173    /// Create a new Proxy for test.examplecomponent/RealmFactory.
174    pub fn new(channel: ::fidl::AsyncChannel) -> Self {
175        let protocol_name = <RealmFactoryMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME;
176        Self { client: fidl::client::Client::new(channel, protocol_name) }
177    }
178
179    /// Get a Stream of events from the remote end of the protocol.
180    ///
181    /// # Panics
182    ///
183    /// Panics if the event stream was already taken.
184    pub fn take_event_stream(&self) -> RealmFactoryEventStream {
185        RealmFactoryEventStream { event_receiver: self.client.take_event_receiver() }
186    }
187
188    /// Creates a new realm and binds the given RealmProxy server end to it.
189    pub fn r#create_realm(
190        &self,
191        mut options: RealmOptions,
192        mut realm_server: fidl::endpoints::ServerEnd<
193            fidl_fuchsia_testing_harness::RealmProxy_Marker,
194        >,
195    ) -> fidl::client::QueryResponseFut<
196        RealmFactoryCreateRealmResult,
197        fidl::encoding::DefaultFuchsiaResourceDialect,
198    > {
199        RealmFactoryProxyInterface::r#create_realm(self, options, realm_server)
200    }
201}
202
203impl RealmFactoryProxyInterface for RealmFactoryProxy {
204    type CreateRealmResponseFut = fidl::client::QueryResponseFut<
205        RealmFactoryCreateRealmResult,
206        fidl::encoding::DefaultFuchsiaResourceDialect,
207    >;
208    fn r#create_realm(
209        &self,
210        mut options: RealmOptions,
211        mut realm_server: fidl::endpoints::ServerEnd<
212            fidl_fuchsia_testing_harness::RealmProxy_Marker,
213        >,
214    ) -> 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                    fidl::encoding::EmptyStruct,
221                    fidl_fuchsia_testing_harness::OperationError,
222                >,
223                fidl::encoding::DefaultFuchsiaResourceDialect,
224                0x32757e6ace9b16c9,
225            >(_buf?)?
226            .into_result::<RealmFactoryMarker>("create_realm")?;
227            Ok(_response.map(|x| x))
228        }
229        self.client
230            .send_query_and_decode::<RealmFactoryCreateRealmRequest, RealmFactoryCreateRealmResult>(
231                (&mut options, realm_server),
232                0x32757e6ace9b16c9,
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.examplecomponent/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                    0x32757e6ace9b16c9 => {
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                            realm_server: req.realm_server,
385
386                            responder: RealmFactoryCreateRealmResponder {
387                                control_handle: std::mem::ManuallyDrop::new(control_handle),
388                                tx_id: header.tx_id,
389                            },
390                        })
391                    }
392                    _ if header.tx_id == 0
393                        && header
394                            .dynamic_flags()
395                            .contains(fidl::encoding::DynamicFlags::FLEXIBLE) =>
396                    {
397                        Ok(RealmFactoryRequest::_UnknownMethod {
398                            ordinal: header.ordinal,
399                            control_handle: RealmFactoryControlHandle { inner: this.inner.clone() },
400                            method_type: fidl::MethodType::OneWay,
401                        })
402                    }
403                    _ if header
404                        .dynamic_flags()
405                        .contains(fidl::encoding::DynamicFlags::FLEXIBLE) =>
406                    {
407                        this.inner.send_framework_err(
408                            fidl::encoding::FrameworkErr::UnknownMethod,
409                            header.tx_id,
410                            header.ordinal,
411                            header.dynamic_flags(),
412                            (bytes, handles),
413                        )?;
414                        Ok(RealmFactoryRequest::_UnknownMethod {
415                            ordinal: header.ordinal,
416                            control_handle: RealmFactoryControlHandle { inner: this.inner.clone() },
417                            method_type: fidl::MethodType::TwoWay,
418                        })
419                    }
420                    _ => Err(fidl::Error::UnknownOrdinal {
421                        ordinal: header.ordinal,
422                        protocol_name:
423                            <RealmFactoryMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME,
424                    }),
425                }))
426            },
427        )
428    }
429}
430
431#[derive(Debug)]
432pub enum RealmFactoryRequest {
433    /// Creates a new realm and binds the given RealmProxy server end to it.
434    CreateRealm {
435        options: RealmOptions,
436        realm_server: fidl::endpoints::ServerEnd<fidl_fuchsia_testing_harness::RealmProxy_Marker>,
437        responder: RealmFactoryCreateRealmResponder,
438    },
439    /// An interaction was received which does not match any known method.
440    #[non_exhaustive]
441    _UnknownMethod {
442        /// Ordinal of the method that was called.
443        ordinal: u64,
444        control_handle: RealmFactoryControlHandle,
445        method_type: fidl::MethodType,
446    },
447}
448
449impl RealmFactoryRequest {
450    #[allow(irrefutable_let_patterns)]
451    pub fn into_create_realm(
452        self,
453    ) -> Option<(
454        RealmOptions,
455        fidl::endpoints::ServerEnd<fidl_fuchsia_testing_harness::RealmProxy_Marker>,
456        RealmFactoryCreateRealmResponder,
457    )> {
458        if let RealmFactoryRequest::CreateRealm { options, realm_server, responder } = self {
459            Some((options, realm_server, responder))
460        } else {
461            None
462        }
463    }
464
465    /// Name of the method defined in FIDL
466    pub fn method_name(&self) -> &'static str {
467        match *self {
468            RealmFactoryRequest::CreateRealm { .. } => "create_realm",
469            RealmFactoryRequest::_UnknownMethod {
470                method_type: fidl::MethodType::OneWay, ..
471            } => "unknown one-way method",
472            RealmFactoryRequest::_UnknownMethod {
473                method_type: fidl::MethodType::TwoWay, ..
474            } => "unknown two-way method",
475        }
476    }
477}
478
479#[derive(Debug, Clone)]
480pub struct RealmFactoryControlHandle {
481    inner: std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>,
482}
483
484impl fidl::endpoints::ControlHandle for RealmFactoryControlHandle {
485    fn shutdown(&self) {
486        self.inner.shutdown()
487    }
488    fn shutdown_with_epitaph(&self, status: zx_status::Status) {
489        self.inner.shutdown_with_epitaph(status)
490    }
491
492    fn is_closed(&self) -> bool {
493        self.inner.channel().is_closed()
494    }
495    fn on_closed(&self) -> fidl::OnSignalsRef<'_> {
496        self.inner.channel().on_closed()
497    }
498
499    #[cfg(target_os = "fuchsia")]
500    fn signal_peer(
501        &self,
502        clear_mask: zx::Signals,
503        set_mask: zx::Signals,
504    ) -> Result<(), zx_status::Status> {
505        use fidl::Peered;
506        self.inner.channel().signal_peer(clear_mask, set_mask)
507    }
508}
509
510impl RealmFactoryControlHandle {}
511
512#[must_use = "FIDL methods require a response to be sent"]
513#[derive(Debug)]
514pub struct RealmFactoryCreateRealmResponder {
515    control_handle: std::mem::ManuallyDrop<RealmFactoryControlHandle>,
516    tx_id: u32,
517}
518
519/// Set the the channel to be shutdown (see [`RealmFactoryControlHandle::shutdown`])
520/// if the responder is dropped without sending a response, so that the client
521/// doesn't hang. To prevent this behavior, call `drop_without_shutdown`.
522impl std::ops::Drop for RealmFactoryCreateRealmResponder {
523    fn drop(&mut self) {
524        self.control_handle.shutdown();
525        // Safety: drops once, never accessed again
526        unsafe { std::mem::ManuallyDrop::drop(&mut self.control_handle) };
527    }
528}
529
530impl fidl::endpoints::Responder for RealmFactoryCreateRealmResponder {
531    type ControlHandle = RealmFactoryControlHandle;
532
533    fn control_handle(&self) -> &RealmFactoryControlHandle {
534        &self.control_handle
535    }
536
537    fn drop_without_shutdown(mut self) {
538        // Safety: drops once, never accessed again due to mem::forget
539        unsafe { std::mem::ManuallyDrop::drop(&mut self.control_handle) };
540        // Prevent Drop from running (which would shut down the channel)
541        std::mem::forget(self);
542    }
543}
544
545impl RealmFactoryCreateRealmResponder {
546    /// Sends a response to the FIDL transaction.
547    ///
548    /// Sets the channel to shutdown if an error occurs.
549    pub fn send(
550        self,
551        mut result: Result<(), fidl_fuchsia_testing_harness::OperationError>,
552    ) -> Result<(), fidl::Error> {
553        let _result = self.send_raw(result);
554        if _result.is_err() {
555            self.control_handle.shutdown();
556        }
557        self.drop_without_shutdown();
558        _result
559    }
560
561    /// Similar to "send" but does not shutdown the channel if an error occurs.
562    pub fn send_no_shutdown_on_err(
563        self,
564        mut result: Result<(), fidl_fuchsia_testing_harness::OperationError>,
565    ) -> Result<(), fidl::Error> {
566        let _result = self.send_raw(result);
567        self.drop_without_shutdown();
568        _result
569    }
570
571    fn send_raw(
572        &self,
573        mut result: Result<(), fidl_fuchsia_testing_harness::OperationError>,
574    ) -> Result<(), fidl::Error> {
575        self.control_handle.inner.send::<fidl::encoding::FlexibleResultType<
576            fidl::encoding::EmptyStruct,
577            fidl_fuchsia_testing_harness::OperationError,
578        >>(
579            fidl::encoding::FlexibleResult::new(result),
580            self.tx_id,
581            0x32757e6ace9b16c9,
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            24
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                (
636                    <RealmOptions as fidl::encoding::ResourceTypeMarker>::take_or_borrow(
637                        &mut self.options,
638                    ),
639                    <fidl::encoding::Endpoint<
640                        fidl::endpoints::ServerEnd<fidl_fuchsia_testing_harness::RealmProxy_Marker>,
641                    > as fidl::encoding::ResourceTypeMarker>::take_or_borrow(
642                        &mut self.realm_server,
643                    ),
644                ),
645                encoder,
646                offset,
647                _depth,
648            )
649        }
650    }
651    unsafe impl<
652            T0: fidl::encoding::Encode<RealmOptions, fidl::encoding::DefaultFuchsiaResourceDialect>,
653            T1: fidl::encoding::Encode<
654                fidl::encoding::Endpoint<
655                    fidl::endpoints::ServerEnd<fidl_fuchsia_testing_harness::RealmProxy_Marker>,
656                >,
657                fidl::encoding::DefaultFuchsiaResourceDialect,
658            >,
659        >
660        fidl::encoding::Encode<
661            RealmFactoryCreateRealmRequest,
662            fidl::encoding::DefaultFuchsiaResourceDialect,
663        > for (T0, T1)
664    {
665        #[inline]
666        unsafe fn encode(
667            self,
668            encoder: &mut fidl::encoding::Encoder<
669                '_,
670                fidl::encoding::DefaultFuchsiaResourceDialect,
671            >,
672            offset: usize,
673            depth: fidl::encoding::Depth,
674        ) -> fidl::Result<()> {
675            encoder.debug_check_bounds::<RealmFactoryCreateRealmRequest>(offset);
676            // Zero out padding regions. There's no need to apply masks
677            // because the unmasked parts will be overwritten by fields.
678            unsafe {
679                let ptr = encoder.buf.as_mut_ptr().add(offset).offset(16);
680                (ptr as *mut u64).write_unaligned(0);
681            }
682            // Write the fields.
683            self.0.encode(encoder, offset + 0, depth)?;
684            self.1.encode(encoder, offset + 16, depth)?;
685            Ok(())
686        }
687    }
688
689    impl fidl::encoding::Decode<Self, fidl::encoding::DefaultFuchsiaResourceDialect>
690        for RealmFactoryCreateRealmRequest
691    {
692        #[inline(always)]
693        fn new_empty() -> Self {
694            Self {
695                options: fidl::new_empty!(
696                    RealmOptions,
697                    fidl::encoding::DefaultFuchsiaResourceDialect
698                ),
699                realm_server: fidl::new_empty!(
700                    fidl::encoding::Endpoint<
701                        fidl::endpoints::ServerEnd<fidl_fuchsia_testing_harness::RealmProxy_Marker>,
702                    >,
703                    fidl::encoding::DefaultFuchsiaResourceDialect
704                ),
705            }
706        }
707
708        #[inline]
709        unsafe fn decode(
710            &mut self,
711            decoder: &mut fidl::encoding::Decoder<
712                '_,
713                fidl::encoding::DefaultFuchsiaResourceDialect,
714            >,
715            offset: usize,
716            _depth: fidl::encoding::Depth,
717        ) -> fidl::Result<()> {
718            decoder.debug_check_bounds::<Self>(offset);
719            // Verify that padding bytes are zero.
720            let ptr = unsafe { decoder.buf.as_ptr().add(offset).offset(16) };
721            let padval = unsafe { (ptr as *const u64).read_unaligned() };
722            let mask = 0xffffffff00000000u64;
723            let maskedval = padval & mask;
724            if maskedval != 0 {
725                return Err(fidl::Error::NonZeroPadding {
726                    padding_start: offset + 16 + ((mask as u64).trailing_zeros() / 8) as usize,
727                });
728            }
729            fidl::decode!(
730                RealmOptions,
731                fidl::encoding::DefaultFuchsiaResourceDialect,
732                &mut self.options,
733                decoder,
734                offset + 0,
735                _depth
736            )?;
737            fidl::decode!(
738                fidl::encoding::Endpoint<
739                    fidl::endpoints::ServerEnd<fidl_fuchsia_testing_harness::RealmProxy_Marker>,
740                >,
741                fidl::encoding::DefaultFuchsiaResourceDialect,
742                &mut self.realm_server,
743                decoder,
744                offset + 16,
745                _depth
746            )?;
747            Ok(())
748        }
749    }
750
751    impl RealmOptions {
752        #[inline(always)]
753        fn max_ordinal_present(&self) -> u64 {
754            if let Some(_) = self.example_option {
755                return 1;
756            }
757            0
758        }
759    }
760
761    impl fidl::encoding::ResourceTypeMarker for RealmOptions {
762        type Borrowed<'a> = &'a mut Self;
763        fn take_or_borrow<'a>(
764            value: &'a mut <Self as fidl::encoding::TypeMarker>::Owned,
765        ) -> Self::Borrowed<'a> {
766            value
767        }
768    }
769
770    unsafe impl fidl::encoding::TypeMarker for RealmOptions {
771        type Owned = Self;
772
773        #[inline(always)]
774        fn inline_align(_context: fidl::encoding::Context) -> usize {
775            8
776        }
777
778        #[inline(always)]
779        fn inline_size(_context: fidl::encoding::Context) -> usize {
780            16
781        }
782    }
783
784    unsafe impl fidl::encoding::Encode<RealmOptions, fidl::encoding::DefaultFuchsiaResourceDialect>
785        for &mut RealmOptions
786    {
787        unsafe fn encode(
788            self,
789            encoder: &mut fidl::encoding::Encoder<
790                '_,
791                fidl::encoding::DefaultFuchsiaResourceDialect,
792            >,
793            offset: usize,
794            mut depth: fidl::encoding::Depth,
795        ) -> fidl::Result<()> {
796            encoder.debug_check_bounds::<RealmOptions>(offset);
797            // Vector header
798            let max_ordinal: u64 = self.max_ordinal_present();
799            encoder.write_num(max_ordinal, offset);
800            encoder.write_num(fidl::encoding::ALLOC_PRESENT_U64, offset + 8);
801            // Calling encoder.out_of_line_offset(0) is not allowed.
802            if max_ordinal == 0 {
803                return Ok(());
804            }
805            depth.increment()?;
806            let envelope_size = 8;
807            let bytes_len = max_ordinal as usize * envelope_size;
808            #[allow(unused_variables)]
809            let offset = encoder.out_of_line_offset(bytes_len);
810            let mut _prev_end_offset: usize = 0;
811            if 1 > max_ordinal {
812                return Ok(());
813            }
814
815            // Write at offset+(ordinal-1)*envelope_size, since ordinals are one-based and envelopes
816            // are envelope_size bytes.
817            let cur_offset: usize = (1 - 1) * envelope_size;
818
819            // Zero reserved fields.
820            encoder.padding(offset + _prev_end_offset, cur_offset - _prev_end_offset);
821
822            // Safety:
823            // - bytes_len is calculated to fit envelope_size*max(member.ordinal).
824            // - Since cur_offset is envelope_size*(member.ordinal - 1) and the envelope takes
825            //   envelope_size bytes, there is always sufficient room.
826            fidl::encoding::encode_in_envelope_optional::<
827                bool,
828                fidl::encoding::DefaultFuchsiaResourceDialect,
829            >(
830                self.example_option.as_ref().map(<bool as fidl::encoding::ValueTypeMarker>::borrow),
831                encoder,
832                offset + cur_offset,
833                depth,
834            )?;
835
836            _prev_end_offset = cur_offset + envelope_size;
837
838            Ok(())
839        }
840    }
841
842    impl fidl::encoding::Decode<Self, fidl::encoding::DefaultFuchsiaResourceDialect> for RealmOptions {
843        #[inline(always)]
844        fn new_empty() -> Self {
845            Self::default()
846        }
847
848        unsafe fn decode(
849            &mut self,
850            decoder: &mut fidl::encoding::Decoder<
851                '_,
852                fidl::encoding::DefaultFuchsiaResourceDialect,
853            >,
854            offset: usize,
855            mut depth: fidl::encoding::Depth,
856        ) -> fidl::Result<()> {
857            decoder.debug_check_bounds::<Self>(offset);
858            let len = match fidl::encoding::decode_vector_header(decoder, offset)? {
859                None => return Err(fidl::Error::NotNullable),
860                Some(len) => len,
861            };
862            // Calling decoder.out_of_line_offset(0) is not allowed.
863            if len == 0 {
864                return Ok(());
865            };
866            depth.increment()?;
867            let envelope_size = 8;
868            let bytes_len = len * envelope_size;
869            let offset = decoder.out_of_line_offset(bytes_len)?;
870            // Decode the envelope for each type.
871            let mut _next_ordinal_to_read = 0;
872            let mut next_offset = offset;
873            let end_offset = offset + bytes_len;
874            _next_ordinal_to_read += 1;
875            if next_offset >= end_offset {
876                return Ok(());
877            }
878
879            // Decode unknown envelopes for gaps in ordinals.
880            while _next_ordinal_to_read < 1 {
881                fidl::encoding::decode_unknown_envelope(decoder, next_offset, depth)?;
882                _next_ordinal_to_read += 1;
883                next_offset += envelope_size;
884            }
885
886            let next_out_of_line = decoder.next_out_of_line();
887            let handles_before = decoder.remaining_handles();
888            if let Some((inlined, num_bytes, num_handles)) =
889                fidl::encoding::decode_envelope_header(decoder, next_offset)?
890            {
891                let member_inline_size =
892                    <bool as fidl::encoding::TypeMarker>::inline_size(decoder.context);
893                if inlined != (member_inline_size <= 4) {
894                    return Err(fidl::Error::InvalidInlineBitInEnvelope);
895                }
896                let inner_offset;
897                let mut inner_depth = depth.clone();
898                if inlined {
899                    decoder.check_inline_envelope_padding(next_offset, member_inline_size)?;
900                    inner_offset = next_offset;
901                } else {
902                    inner_offset = decoder.out_of_line_offset(member_inline_size)?;
903                    inner_depth.increment()?;
904                }
905                let val_ref = self.example_option.get_or_insert_with(|| {
906                    fidl::new_empty!(bool, fidl::encoding::DefaultFuchsiaResourceDialect)
907                });
908                fidl::decode!(
909                    bool,
910                    fidl::encoding::DefaultFuchsiaResourceDialect,
911                    val_ref,
912                    decoder,
913                    inner_offset,
914                    inner_depth
915                )?;
916                if !inlined && decoder.next_out_of_line() != next_out_of_line + (num_bytes as usize)
917                {
918                    return Err(fidl::Error::InvalidNumBytesInEnvelope);
919                }
920                if handles_before != decoder.remaining_handles() + (num_handles as usize) {
921                    return Err(fidl::Error::InvalidNumHandlesInEnvelope);
922                }
923            }
924
925            next_offset += envelope_size;
926
927            // Decode the remaining unknown envelopes.
928            while next_offset < end_offset {
929                _next_ordinal_to_read += 1;
930                fidl::encoding::decode_unknown_envelope(decoder, next_offset, depth)?;
931                next_offset += envelope_size;
932            }
933
934            Ok(())
935        }
936    }
937}