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 RealmFactoryControlHandle {
484    pub fn shutdown_with_epitaph(&self, status: impl Into<fidl::Epitaph>) {
485        self.inner.shutdown_with_epitaph(status.into())
486    }
487}
488
489impl fidl::endpoints::ControlHandle for RealmFactoryControlHandle {
490    fn shutdown(&self) {
491        self.inner.shutdown()
492    }
493
494    fn shutdown_with_epitaph(&self, status: fidl::Epitaph) {
495        self.inner.shutdown_with_epitaph(status)
496    }
497
498    fn is_closed(&self) -> bool {
499        self.inner.channel().is_closed()
500    }
501    fn on_closed(&self) -> fidl::OnSignalsRef<'_> {
502        self.inner.channel().on_closed()
503    }
504
505    #[cfg(target_os = "fuchsia")]
506    fn signal_peer(
507        &self,
508        clear_mask: zx::Signals,
509        set_mask: zx::Signals,
510    ) -> Result<(), zx_status::Status> {
511        use fidl::Peered;
512        self.inner.channel().signal_peer(clear_mask, set_mask)
513    }
514}
515
516impl RealmFactoryControlHandle {}
517
518#[must_use = "FIDL methods require a response to be sent"]
519#[derive(Debug)]
520pub struct RealmFactoryCreateRealmResponder {
521    control_handle: std::mem::ManuallyDrop<RealmFactoryControlHandle>,
522    tx_id: u32,
523}
524
525/// Set the the channel to be shutdown (see [`RealmFactoryControlHandle::shutdown`])
526/// if the responder is dropped without sending a response, so that the client
527/// doesn't hang. To prevent this behavior, call `drop_without_shutdown`.
528impl std::ops::Drop for RealmFactoryCreateRealmResponder {
529    fn drop(&mut self) {
530        self.control_handle.shutdown();
531        // Safety: drops once, never accessed again
532        unsafe { std::mem::ManuallyDrop::drop(&mut self.control_handle) };
533    }
534}
535
536impl fidl::endpoints::Responder for RealmFactoryCreateRealmResponder {
537    type ControlHandle = RealmFactoryControlHandle;
538
539    fn control_handle(&self) -> &RealmFactoryControlHandle {
540        &self.control_handle
541    }
542
543    fn drop_without_shutdown(mut self) {
544        // Safety: drops once, never accessed again due to mem::forget
545        unsafe { std::mem::ManuallyDrop::drop(&mut self.control_handle) };
546        // Prevent Drop from running (which would shut down the channel)
547        std::mem::forget(self);
548    }
549}
550
551impl RealmFactoryCreateRealmResponder {
552    /// Sends a response to the FIDL transaction.
553    ///
554    /// Sets the channel to shutdown if an error occurs.
555    pub fn send(
556        self,
557        mut result: Result<(), fidl_fuchsia_testing_harness::OperationError>,
558    ) -> Result<(), fidl::Error> {
559        let _result = self.send_raw(result);
560        if _result.is_err() {
561            self.control_handle.shutdown();
562        }
563        self.drop_without_shutdown();
564        _result
565    }
566
567    /// Similar to "send" but does not shutdown the channel if an error occurs.
568    pub fn send_no_shutdown_on_err(
569        self,
570        mut result: Result<(), fidl_fuchsia_testing_harness::OperationError>,
571    ) -> Result<(), fidl::Error> {
572        let _result = self.send_raw(result);
573        self.drop_without_shutdown();
574        _result
575    }
576
577    fn send_raw(
578        &self,
579        mut result: Result<(), fidl_fuchsia_testing_harness::OperationError>,
580    ) -> Result<(), fidl::Error> {
581        self.control_handle.inner.send::<fidl::encoding::FlexibleResultType<
582            fidl::encoding::EmptyStruct,
583            fidl_fuchsia_testing_harness::OperationError,
584        >>(
585            fidl::encoding::FlexibleResult::new(result),
586            self.tx_id,
587            0x32757e6ace9b16c9,
588            fidl::encoding::DynamicFlags::FLEXIBLE,
589        )
590    }
591}
592
593mod internal {
594    use super::*;
595
596    impl fidl::encoding::ResourceTypeMarker for RealmFactoryCreateRealmRequest {
597        type Borrowed<'a> = &'a mut Self;
598        fn take_or_borrow<'a>(
599            value: &'a mut <Self as fidl::encoding::TypeMarker>::Owned,
600        ) -> Self::Borrowed<'a> {
601            value
602        }
603    }
604
605    unsafe impl fidl::encoding::TypeMarker for RealmFactoryCreateRealmRequest {
606        type Owned = Self;
607
608        #[inline(always)]
609        fn inline_align(_context: fidl::encoding::Context) -> usize {
610            8
611        }
612
613        #[inline(always)]
614        fn inline_size(_context: fidl::encoding::Context) -> usize {
615            24
616        }
617    }
618
619    unsafe impl
620        fidl::encoding::Encode<
621            RealmFactoryCreateRealmRequest,
622            fidl::encoding::DefaultFuchsiaResourceDialect,
623        > for &mut RealmFactoryCreateRealmRequest
624    {
625        #[inline]
626        unsafe fn encode(
627            self,
628            encoder: &mut fidl::encoding::Encoder<
629                '_,
630                fidl::encoding::DefaultFuchsiaResourceDialect,
631            >,
632            offset: usize,
633            _depth: fidl::encoding::Depth,
634        ) -> fidl::Result<()> {
635            encoder.debug_check_bounds::<RealmFactoryCreateRealmRequest>(offset);
636            // Delegate to tuple encoding.
637            fidl::encoding::Encode::<
638                RealmFactoryCreateRealmRequest,
639                fidl::encoding::DefaultFuchsiaResourceDialect,
640            >::encode(
641                (
642                    <RealmOptions as fidl::encoding::ResourceTypeMarker>::take_or_borrow(
643                        &mut self.options,
644                    ),
645                    <fidl::encoding::Endpoint<
646                        fidl::endpoints::ServerEnd<fidl_fuchsia_testing_harness::RealmProxy_Marker>,
647                    > as fidl::encoding::ResourceTypeMarker>::take_or_borrow(
648                        &mut self.realm_server,
649                    ),
650                ),
651                encoder,
652                offset,
653                _depth,
654            )
655        }
656    }
657    unsafe impl<
658        T0: fidl::encoding::Encode<RealmOptions, fidl::encoding::DefaultFuchsiaResourceDialect>,
659        T1: fidl::encoding::Encode<
660                fidl::encoding::Endpoint<
661                    fidl::endpoints::ServerEnd<fidl_fuchsia_testing_harness::RealmProxy_Marker>,
662                >,
663                fidl::encoding::DefaultFuchsiaResourceDialect,
664            >,
665    >
666        fidl::encoding::Encode<
667            RealmFactoryCreateRealmRequest,
668            fidl::encoding::DefaultFuchsiaResourceDialect,
669        > for (T0, T1)
670    {
671        #[inline]
672        unsafe fn encode(
673            self,
674            encoder: &mut fidl::encoding::Encoder<
675                '_,
676                fidl::encoding::DefaultFuchsiaResourceDialect,
677            >,
678            offset: usize,
679            depth: fidl::encoding::Depth,
680        ) -> fidl::Result<()> {
681            encoder.debug_check_bounds::<RealmFactoryCreateRealmRequest>(offset);
682            // Zero out padding regions. There's no need to apply masks
683            // because the unmasked parts will be overwritten by fields.
684            unsafe {
685                let ptr = encoder.buf.as_mut_ptr().add(offset).offset(16);
686                (ptr as *mut u64).write_unaligned(0);
687            }
688            // Write the fields.
689            self.0.encode(encoder, offset + 0, depth)?;
690            self.1.encode(encoder, offset + 16, depth)?;
691            Ok(())
692        }
693    }
694
695    impl fidl::encoding::Decode<Self, fidl::encoding::DefaultFuchsiaResourceDialect>
696        for RealmFactoryCreateRealmRequest
697    {
698        #[inline(always)]
699        fn new_empty() -> Self {
700            Self {
701                options: fidl::new_empty!(
702                    RealmOptions,
703                    fidl::encoding::DefaultFuchsiaResourceDialect
704                ),
705                realm_server: fidl::new_empty!(
706                    fidl::encoding::Endpoint<
707                        fidl::endpoints::ServerEnd<fidl_fuchsia_testing_harness::RealmProxy_Marker>,
708                    >,
709                    fidl::encoding::DefaultFuchsiaResourceDialect
710                ),
711            }
712        }
713
714        #[inline]
715        unsafe fn decode(
716            &mut self,
717            decoder: &mut fidl::encoding::Decoder<
718                '_,
719                fidl::encoding::DefaultFuchsiaResourceDialect,
720            >,
721            offset: usize,
722            _depth: fidl::encoding::Depth,
723        ) -> fidl::Result<()> {
724            decoder.debug_check_bounds::<Self>(offset);
725            // Verify that padding bytes are zero.
726            let ptr = unsafe { decoder.buf.as_ptr().add(offset).offset(16) };
727            let padval = unsafe { (ptr as *const u64).read_unaligned() };
728            let mask = 0xffffffff00000000u64;
729            let maskedval = padval & mask;
730            if maskedval != 0 {
731                return Err(fidl::Error::NonZeroPadding {
732                    padding_start: offset + 16 + ((mask as u64).trailing_zeros() / 8) as usize,
733                });
734            }
735            fidl::decode!(
736                RealmOptions,
737                fidl::encoding::DefaultFuchsiaResourceDialect,
738                &mut self.options,
739                decoder,
740                offset + 0,
741                _depth
742            )?;
743            fidl::decode!(
744                fidl::encoding::Endpoint<
745                    fidl::endpoints::ServerEnd<fidl_fuchsia_testing_harness::RealmProxy_Marker>,
746                >,
747                fidl::encoding::DefaultFuchsiaResourceDialect,
748                &mut self.realm_server,
749                decoder,
750                offset + 16,
751                _depth
752            )?;
753            Ok(())
754        }
755    }
756
757    impl RealmOptions {
758        #[inline(always)]
759        fn max_ordinal_present(&self) -> u64 {
760            if let Some(_) = self.example_option {
761                return 1;
762            }
763            0
764        }
765    }
766
767    impl fidl::encoding::ResourceTypeMarker for RealmOptions {
768        type Borrowed<'a> = &'a mut Self;
769        fn take_or_borrow<'a>(
770            value: &'a mut <Self as fidl::encoding::TypeMarker>::Owned,
771        ) -> Self::Borrowed<'a> {
772            value
773        }
774    }
775
776    unsafe impl fidl::encoding::TypeMarker for RealmOptions {
777        type Owned = Self;
778
779        #[inline(always)]
780        fn inline_align(_context: fidl::encoding::Context) -> usize {
781            8
782        }
783
784        #[inline(always)]
785        fn inline_size(_context: fidl::encoding::Context) -> usize {
786            16
787        }
788    }
789
790    unsafe impl fidl::encoding::Encode<RealmOptions, fidl::encoding::DefaultFuchsiaResourceDialect>
791        for &mut RealmOptions
792    {
793        unsafe fn encode(
794            self,
795            encoder: &mut fidl::encoding::Encoder<
796                '_,
797                fidl::encoding::DefaultFuchsiaResourceDialect,
798            >,
799            offset: usize,
800            mut depth: fidl::encoding::Depth,
801        ) -> fidl::Result<()> {
802            encoder.debug_check_bounds::<RealmOptions>(offset);
803            // Vector header
804            let max_ordinal: u64 = self.max_ordinal_present();
805            encoder.write_num(max_ordinal, offset);
806            encoder.write_num(fidl::encoding::ALLOC_PRESENT_U64, offset + 8);
807            // Calling encoder.out_of_line_offset(0) is not allowed.
808            if max_ordinal == 0 {
809                return Ok(());
810            }
811            depth.increment()?;
812            let envelope_size = 8;
813            let bytes_len = max_ordinal as usize * envelope_size;
814            #[allow(unused_variables)]
815            let offset = encoder.out_of_line_offset(bytes_len);
816            let mut _prev_end_offset: usize = 0;
817            if 1 > max_ordinal {
818                return Ok(());
819            }
820
821            // Write at offset+(ordinal-1)*envelope_size, since ordinals are one-based and envelopes
822            // are envelope_size bytes.
823            let cur_offset: usize = (1 - 1) * envelope_size;
824
825            // Zero reserved fields.
826            encoder.padding(offset + _prev_end_offset, cur_offset - _prev_end_offset);
827
828            // Safety:
829            // - bytes_len is calculated to fit envelope_size*max(member.ordinal).
830            // - Since cur_offset is envelope_size*(member.ordinal - 1) and the envelope takes
831            //   envelope_size bytes, there is always sufficient room.
832            fidl::encoding::encode_in_envelope_optional::<
833                bool,
834                fidl::encoding::DefaultFuchsiaResourceDialect,
835            >(
836                self.example_option.as_ref().map(<bool as fidl::encoding::ValueTypeMarker>::borrow),
837                encoder,
838                offset + cur_offset,
839                depth,
840            )?;
841
842            _prev_end_offset = cur_offset + envelope_size;
843
844            Ok(())
845        }
846    }
847
848    impl fidl::encoding::Decode<Self, fidl::encoding::DefaultFuchsiaResourceDialect> for RealmOptions {
849        #[inline(always)]
850        fn new_empty() -> Self {
851            Self::default()
852        }
853
854        unsafe fn decode(
855            &mut self,
856            decoder: &mut fidl::encoding::Decoder<
857                '_,
858                fidl::encoding::DefaultFuchsiaResourceDialect,
859            >,
860            offset: usize,
861            mut depth: fidl::encoding::Depth,
862        ) -> fidl::Result<()> {
863            decoder.debug_check_bounds::<Self>(offset);
864            let len = match fidl::encoding::decode_vector_header(decoder, offset)? {
865                None => return Err(fidl::Error::NotNullable),
866                Some(len) => len,
867            };
868            // Calling decoder.out_of_line_offset(0) is not allowed.
869            if len == 0 {
870                return Ok(());
871            };
872            depth.increment()?;
873            let envelope_size = 8;
874            let bytes_len = len * envelope_size;
875            let offset = decoder.out_of_line_offset(bytes_len)?;
876            // Decode the envelope for each type.
877            let mut _next_ordinal_to_read = 0;
878            let mut next_offset = offset;
879            let end_offset = offset + bytes_len;
880            _next_ordinal_to_read += 1;
881            if next_offset >= end_offset {
882                return Ok(());
883            }
884
885            // Decode unknown envelopes for gaps in ordinals.
886            while _next_ordinal_to_read < 1 {
887                fidl::encoding::decode_unknown_envelope(decoder, next_offset, depth)?;
888                _next_ordinal_to_read += 1;
889                next_offset += envelope_size;
890            }
891
892            let next_out_of_line = decoder.next_out_of_line();
893            let handles_before = decoder.remaining_handles();
894            if let Some((inlined, num_bytes, num_handles)) =
895                fidl::encoding::decode_envelope_header(decoder, next_offset)?
896            {
897                let member_inline_size =
898                    <bool as fidl::encoding::TypeMarker>::inline_size(decoder.context);
899                if inlined != (member_inline_size <= 4) {
900                    return Err(fidl::Error::InvalidInlineBitInEnvelope);
901                }
902                let inner_offset;
903                let mut inner_depth = depth.clone();
904                if inlined {
905                    decoder.check_inline_envelope_padding(next_offset, member_inline_size)?;
906                    inner_offset = next_offset;
907                } else {
908                    inner_offset = decoder.out_of_line_offset(member_inline_size)?;
909                    inner_depth.increment()?;
910                }
911                let val_ref = self.example_option.get_or_insert_with(|| {
912                    fidl::new_empty!(bool, fidl::encoding::DefaultFuchsiaResourceDialect)
913                });
914                fidl::decode!(
915                    bool,
916                    fidl::encoding::DefaultFuchsiaResourceDialect,
917                    val_ref,
918                    decoder,
919                    inner_offset,
920                    inner_depth
921                )?;
922                if !inlined && decoder.next_out_of_line() != next_out_of_line + (num_bytes as usize)
923                {
924                    return Err(fidl::Error::InvalidNumBytesInEnvelope);
925                }
926                if handles_before != decoder.remaining_handles() + (num_handles as usize) {
927                    return Err(fidl::Error::InvalidNumHandlesInEnvelope);
928                }
929            }
930
931            next_offset += envelope_size;
932
933            // Decode the remaining unknown envelopes.
934            while next_offset < end_offset {
935                _next_ordinal_to_read += 1;
936                fidl::encoding::decode_unknown_envelope(decoder, next_offset, depth)?;
937                next_offset += envelope_size;
938            }
939
940            Ok(())
941        }
942    }
943}