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