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