Skip to main content

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        Self { client: fidl::client::sync::Client::new(channel) }
87    }
88
89    pub fn into_channel(self) -> fidl::Channel {
90        self.client.into_channel()
91    }
92
93    /// Waits until an event arrives and returns it. It is safe for other
94    /// threads to make concurrent requests while waiting for an event.
95    pub fn wait_for_event(
96        &self,
97        deadline: zx::MonotonicInstant,
98    ) -> Result<RealmFactoryEvent, fidl::Error> {
99        RealmFactoryEvent::decode(self.client.wait_for_event::<RealmFactoryMarker>(deadline)?)
100    }
101
102    /// Creates a new realm and binds the given RealmProxy server end to it.
103    pub fn r#create_realm(
104        &self,
105        mut options: RealmOptions,
106        mut realm_server: fidl::endpoints::ServerEnd<
107            fidl_fuchsia_testing_harness::RealmProxy_Marker,
108        >,
109        ___deadline: zx::MonotonicInstant,
110    ) -> Result<RealmFactoryCreateRealmResult, fidl::Error> {
111        let _response = self
112            .client
113            .send_query::<RealmFactoryCreateRealmRequest, fidl::encoding::FlexibleResultType<
114                fidl::encoding::EmptyStruct,
115                fidl_fuchsia_testing_harness::OperationError,
116            >, RealmFactoryMarker>(
117                (&mut options, realm_server),
118                0x32757e6ace9b16c9,
119                fidl::encoding::DynamicFlags::FLEXIBLE,
120                ___deadline,
121            )?
122            .into_result::<RealmFactoryMarker>("create_realm")?;
123        Ok(_response.map(|x| x))
124    }
125}
126
127#[cfg(target_os = "fuchsia")]
128impl From<RealmFactorySynchronousProxy> for zx::NullableHandle {
129    fn from(value: RealmFactorySynchronousProxy) -> Self {
130        value.into_channel().into()
131    }
132}
133
134#[cfg(target_os = "fuchsia")]
135impl From<fidl::Channel> for RealmFactorySynchronousProxy {
136    fn from(value: fidl::Channel) -> Self {
137        Self::new(value)
138    }
139}
140
141#[cfg(target_os = "fuchsia")]
142impl fidl::endpoints::FromClient for RealmFactorySynchronousProxy {
143    type Protocol = RealmFactoryMarker;
144
145    fn from_client(value: fidl::endpoints::ClientEnd<RealmFactoryMarker>) -> Self {
146        Self::new(value.into_channel())
147    }
148}
149
150#[derive(Debug, Clone)]
151pub struct RealmFactoryProxy {
152    client: fidl::client::Client<fidl::encoding::DefaultFuchsiaResourceDialect>,
153}
154
155impl fidl::endpoints::Proxy for RealmFactoryProxy {
156    type Protocol = RealmFactoryMarker;
157
158    fn from_channel(inner: ::fidl::AsyncChannel) -> Self {
159        Self::new(inner)
160    }
161
162    fn into_channel(self) -> Result<::fidl::AsyncChannel, Self> {
163        self.client.into_channel().map_err(|client| Self { client })
164    }
165
166    fn as_channel(&self) -> &::fidl::AsyncChannel {
167        self.client.as_channel()
168    }
169}
170
171impl RealmFactoryProxy {
172    /// Create a new Proxy for test.examplecomponent/RealmFactory.
173    pub fn new(channel: ::fidl::AsyncChannel) -> Self {
174        let protocol_name = <RealmFactoryMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME;
175        Self { client: fidl::client::Client::new(channel, protocol_name) }
176    }
177
178    /// Get a Stream of events from the remote end of the protocol.
179    ///
180    /// # Panics
181    ///
182    /// Panics if the event stream was already taken.
183    pub fn take_event_stream(&self) -> RealmFactoryEventStream {
184        RealmFactoryEventStream { event_receiver: self.client.take_event_receiver() }
185    }
186
187    /// Creates a new realm and binds the given RealmProxy server end to it.
188    pub fn r#create_realm(
189        &self,
190        mut options: RealmOptions,
191        mut realm_server: fidl::endpoints::ServerEnd<
192            fidl_fuchsia_testing_harness::RealmProxy_Marker,
193        >,
194    ) -> fidl::client::QueryResponseFut<
195        RealmFactoryCreateRealmResult,
196        fidl::encoding::DefaultFuchsiaResourceDialect,
197    > {
198        RealmFactoryProxyInterface::r#create_realm(self, options, realm_server)
199    }
200}
201
202impl RealmFactoryProxyInterface for RealmFactoryProxy {
203    type CreateRealmResponseFut = fidl::client::QueryResponseFut<
204        RealmFactoryCreateRealmResult,
205        fidl::encoding::DefaultFuchsiaResourceDialect,
206    >;
207    fn r#create_realm(
208        &self,
209        mut options: RealmOptions,
210        mut realm_server: fidl::endpoints::ServerEnd<
211            fidl_fuchsia_testing_harness::RealmProxy_Marker,
212        >,
213    ) -> Self::CreateRealmResponseFut {
214        fn _decode(
215            mut _buf: Result<<fidl::encoding::DefaultFuchsiaResourceDialect as fidl::encoding::ResourceDialect>::MessageBufEtc, fidl::Error>,
216        ) -> Result<RealmFactoryCreateRealmResult, fidl::Error> {
217            let _response = fidl::client::decode_transaction_body::<
218                fidl::encoding::FlexibleResultType<
219                    fidl::encoding::EmptyStruct,
220                    fidl_fuchsia_testing_harness::OperationError,
221                >,
222                fidl::encoding::DefaultFuchsiaResourceDialect,
223                0x32757e6ace9b16c9,
224            >(_buf?)?
225            .into_result::<RealmFactoryMarker>("create_realm")?;
226            Ok(_response.map(|x| x))
227        }
228        self.client
229            .send_query_and_decode::<RealmFactoryCreateRealmRequest, RealmFactoryCreateRealmResult>(
230                (&mut options, realm_server),
231                0x32757e6ace9b16c9,
232                fidl::encoding::DynamicFlags::FLEXIBLE,
233                _decode,
234            )
235    }
236}
237
238pub struct RealmFactoryEventStream {
239    event_receiver: fidl::client::EventReceiver<fidl::encoding::DefaultFuchsiaResourceDialect>,
240}
241
242impl std::marker::Unpin for RealmFactoryEventStream {}
243
244impl futures::stream::FusedStream for RealmFactoryEventStream {
245    fn is_terminated(&self) -> bool {
246        self.event_receiver.is_terminated()
247    }
248}
249
250impl futures::Stream for RealmFactoryEventStream {
251    type Item = Result<RealmFactoryEvent, fidl::Error>;
252
253    fn poll_next(
254        mut self: std::pin::Pin<&mut Self>,
255        cx: &mut std::task::Context<'_>,
256    ) -> std::task::Poll<Option<Self::Item>> {
257        match futures::ready!(futures::stream::StreamExt::poll_next_unpin(
258            &mut self.event_receiver,
259            cx
260        )?) {
261            Some(buf) => std::task::Poll::Ready(Some(RealmFactoryEvent::decode(buf))),
262            None => std::task::Poll::Ready(None),
263        }
264    }
265}
266
267#[derive(Debug)]
268pub enum RealmFactoryEvent {
269    #[non_exhaustive]
270    _UnknownEvent {
271        /// Ordinal of the event that was sent.
272        ordinal: u64,
273    },
274}
275
276impl RealmFactoryEvent {
277    /// Decodes a message buffer as a [`RealmFactoryEvent`].
278    fn decode(
279        mut buf: <fidl::encoding::DefaultFuchsiaResourceDialect as fidl::encoding::ResourceDialect>::MessageBufEtc,
280    ) -> Result<RealmFactoryEvent, fidl::Error> {
281        let (bytes, _handles) = buf.split_mut();
282        let (tx_header, _body_bytes) = fidl::encoding::decode_transaction_header(bytes)?;
283        debug_assert_eq!(tx_header.tx_id, 0);
284        match tx_header.ordinal {
285            _ if tx_header.dynamic_flags().contains(fidl::encoding::DynamicFlags::FLEXIBLE) => {
286                Ok(RealmFactoryEvent::_UnknownEvent { ordinal: tx_header.ordinal })
287            }
288            _ => Err(fidl::Error::UnknownOrdinal {
289                ordinal: tx_header.ordinal,
290                protocol_name: <RealmFactoryMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME,
291            }),
292        }
293    }
294}
295
296/// A Stream of incoming requests for test.examplecomponent/RealmFactory.
297pub struct RealmFactoryRequestStream {
298    inner: std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>,
299    is_terminated: bool,
300}
301
302impl std::marker::Unpin for RealmFactoryRequestStream {}
303
304impl futures::stream::FusedStream for RealmFactoryRequestStream {
305    fn is_terminated(&self) -> bool {
306        self.is_terminated
307    }
308}
309
310impl fidl::endpoints::RequestStream for RealmFactoryRequestStream {
311    type Protocol = RealmFactoryMarker;
312    type ControlHandle = RealmFactoryControlHandle;
313
314    fn from_channel(channel: ::fidl::AsyncChannel) -> Self {
315        Self { inner: std::sync::Arc::new(fidl::ServeInner::new(channel)), is_terminated: false }
316    }
317
318    fn control_handle(&self) -> Self::ControlHandle {
319        RealmFactoryControlHandle { inner: self.inner.clone() }
320    }
321
322    fn into_inner(
323        self,
324    ) -> (::std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>, bool)
325    {
326        (self.inner, self.is_terminated)
327    }
328
329    fn from_inner(
330        inner: std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>,
331        is_terminated: bool,
332    ) -> Self {
333        Self { inner, is_terminated }
334    }
335}
336
337impl futures::Stream for RealmFactoryRequestStream {
338    type Item = Result<RealmFactoryRequest, fidl::Error>;
339
340    fn poll_next(
341        mut self: std::pin::Pin<&mut Self>,
342        cx: &mut std::task::Context<'_>,
343    ) -> std::task::Poll<Option<Self::Item>> {
344        let this = &mut *self;
345        if this.inner.check_shutdown(cx) {
346            this.is_terminated = true;
347            return std::task::Poll::Ready(None);
348        }
349        if this.is_terminated {
350            panic!("polled RealmFactoryRequestStream after completion");
351        }
352        fidl::encoding::with_tls_decode_buf::<_, fidl::encoding::DefaultFuchsiaResourceDialect>(
353            |bytes, handles| {
354                match this.inner.channel().read_etc(cx, bytes, handles) {
355                    std::task::Poll::Ready(Ok(())) => {}
356                    std::task::Poll::Pending => return std::task::Poll::Pending,
357                    std::task::Poll::Ready(Err(zx_status::Status::PEER_CLOSED)) => {
358                        this.is_terminated = true;
359                        return std::task::Poll::Ready(None);
360                    }
361                    std::task::Poll::Ready(Err(e)) => {
362                        return std::task::Poll::Ready(Some(Err(fidl::Error::ServerRequestRead(
363                            e.into(),
364                        ))));
365                    }
366                }
367
368                // A message has been received from the channel
369                let (header, _body_bytes) = fidl::encoding::decode_transaction_header(bytes)?;
370
371                std::task::Poll::Ready(Some(match header.ordinal {
372                    0x32757e6ace9b16c9 => {
373                        header.validate_request_tx_id(fidl::MethodType::TwoWay)?;
374                        let mut req = fidl::new_empty!(
375                            RealmFactoryCreateRealmRequest,
376                            fidl::encoding::DefaultFuchsiaResourceDialect
377                        );
378                        fidl::encoding::Decoder::<fidl::encoding::DefaultFuchsiaResourceDialect>::decode_into::<RealmFactoryCreateRealmRequest>(&header, _body_bytes, handles, &mut req)?;
379                        let control_handle =
380                            RealmFactoryControlHandle { inner: this.inner.clone() };
381                        Ok(RealmFactoryRequest::CreateRealm {
382                            options: req.options,
383                            realm_server: req.realm_server,
384
385                            responder: RealmFactoryCreateRealmResponder {
386                                control_handle: std::mem::ManuallyDrop::new(control_handle),
387                                tx_id: header.tx_id,
388                            },
389                        })
390                    }
391                    _ if header.tx_id == 0
392                        && header
393                            .dynamic_flags()
394                            .contains(fidl::encoding::DynamicFlags::FLEXIBLE) =>
395                    {
396                        Ok(RealmFactoryRequest::_UnknownMethod {
397                            ordinal: header.ordinal,
398                            control_handle: RealmFactoryControlHandle { inner: this.inner.clone() },
399                            method_type: fidl::MethodType::OneWay,
400                        })
401                    }
402                    _ if header
403                        .dynamic_flags()
404                        .contains(fidl::encoding::DynamicFlags::FLEXIBLE) =>
405                    {
406                        this.inner.send_framework_err(
407                            fidl::encoding::FrameworkErr::UnknownMethod,
408                            header.tx_id,
409                            header.ordinal,
410                            header.dynamic_flags(),
411                            (bytes, handles),
412                        )?;
413                        Ok(RealmFactoryRequest::_UnknownMethod {
414                            ordinal: header.ordinal,
415                            control_handle: RealmFactoryControlHandle { inner: this.inner.clone() },
416                            method_type: fidl::MethodType::TwoWay,
417                        })
418                    }
419                    _ => Err(fidl::Error::UnknownOrdinal {
420                        ordinal: header.ordinal,
421                        protocol_name:
422                            <RealmFactoryMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME,
423                    }),
424                }))
425            },
426        )
427    }
428}
429
430#[derive(Debug)]
431pub enum RealmFactoryRequest {
432    /// Creates a new realm and binds the given RealmProxy server end to it.
433    CreateRealm {
434        options: RealmOptions,
435        realm_server: fidl::endpoints::ServerEnd<fidl_fuchsia_testing_harness::RealmProxy_Marker>,
436        responder: RealmFactoryCreateRealmResponder,
437    },
438    /// An interaction was received which does not match any known method.
439    #[non_exhaustive]
440    _UnknownMethod {
441        /// Ordinal of the method that was called.
442        ordinal: u64,
443        control_handle: RealmFactoryControlHandle,
444        method_type: fidl::MethodType,
445    },
446}
447
448impl RealmFactoryRequest {
449    #[allow(irrefutable_let_patterns)]
450    pub fn into_create_realm(
451        self,
452    ) -> Option<(
453        RealmOptions,
454        fidl::endpoints::ServerEnd<fidl_fuchsia_testing_harness::RealmProxy_Marker>,
455        RealmFactoryCreateRealmResponder,
456    )> {
457        if let RealmFactoryRequest::CreateRealm { options, realm_server, responder } = self {
458            Some((options, realm_server, responder))
459        } else {
460            None
461        }
462    }
463
464    /// Name of the method defined in FIDL
465    pub fn method_name(&self) -> &'static str {
466        match *self {
467            RealmFactoryRequest::CreateRealm { .. } => "create_realm",
468            RealmFactoryRequest::_UnknownMethod {
469                method_type: fidl::MethodType::OneWay, ..
470            } => "unknown one-way method",
471            RealmFactoryRequest::_UnknownMethod {
472                method_type: fidl::MethodType::TwoWay, ..
473            } => "unknown two-way method",
474        }
475    }
476}
477
478#[derive(Debug, Clone)]
479pub struct RealmFactoryControlHandle {
480    inner: std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>,
481}
482
483impl fidl::endpoints::ControlHandle for RealmFactoryControlHandle {
484    fn shutdown(&self) {
485        self.inner.shutdown()
486    }
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}