fidl_fuchsia_pkg_test/
fidl_fuchsia_pkg_test.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_fuchsia_pkg_test__common::*;
11use futures::future::{self, MaybeDone, TryFutureExt};
12use zx_status;
13
14#[derive(Debug, PartialEq)]
15pub struct RealmFactoryCreateRealmRequest {
16    pub options: RealmOptions,
17}
18
19impl fidl::Standalone<fidl::encoding::DefaultFuchsiaResourceDialect>
20    for RealmFactoryCreateRealmRequest
21{
22}
23
24#[derive(Debug, Eq, Hash, Ord, PartialEq, PartialOrd)]
25pub struct RealmFactoryCreateRealmResponse {
26    pub dictionary: fidl::endpoints::ClientEnd<fidl_fuchsia_component_sandbox::DictionaryMarker>,
27}
28
29impl fidl::Standalone<fidl::encoding::DefaultFuchsiaResourceDialect>
30    for RealmFactoryCreateRealmResponse
31{
32}
33
34/// RealmOptions tells the RealmFactory protocol how to create the test realm.
35#[derive(Debug, Default, PartialEq)]
36pub struct RealmOptions {
37    pub pkg_directory_server: Option<fidl::endpoints::ServerEnd<fidl_fuchsia_io::DirectoryMarker>>,
38    #[doc(hidden)]
39    pub __source_breaking: fidl::marker::SourceBreaking,
40}
41
42impl fidl::Standalone<fidl::encoding::DefaultFuchsiaResourceDialect> for RealmOptions {}
43
44#[derive(Debug, Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Hash)]
45pub struct RealmFactoryMarker;
46
47impl fidl::endpoints::ProtocolMarker for RealmFactoryMarker {
48    type Proxy = RealmFactoryProxy;
49    type RequestStream = RealmFactoryRequestStream;
50    #[cfg(target_os = "fuchsia")]
51    type SynchronousProxy = RealmFactorySynchronousProxy;
52
53    const DEBUG_NAME: &'static str = "fuchsia.pkg.test.RealmFactory";
54}
55impl fidl::endpoints::DiscoverableProtocolMarker for RealmFactoryMarker {}
56pub type RealmFactoryCreateRealmResult = Result<
57    fidl::endpoints::ClientEnd<fidl_fuchsia_component_sandbox::DictionaryMarker>,
58    fidl_fuchsia_testing_harness::OperationError,
59>;
60
61pub trait RealmFactoryProxyInterface: Send + Sync {
62    type CreateRealmResponseFut: std::future::Future<Output = Result<RealmFactoryCreateRealmResult, fidl::Error>>
63        + Send;
64    fn r#create_realm(&self, options: RealmOptions) -> Self::CreateRealmResponseFut;
65}
66#[derive(Debug)]
67#[cfg(target_os = "fuchsia")]
68pub struct RealmFactorySynchronousProxy {
69    client: fidl::client::sync::Client,
70}
71
72#[cfg(target_os = "fuchsia")]
73impl fidl::endpoints::SynchronousProxy for RealmFactorySynchronousProxy {
74    type Proxy = RealmFactoryProxy;
75    type Protocol = RealmFactoryMarker;
76
77    fn from_channel(inner: fidl::Channel) -> Self {
78        Self::new(inner)
79    }
80
81    fn into_channel(self) -> fidl::Channel {
82        self.client.into_channel()
83    }
84
85    fn as_channel(&self) -> &fidl::Channel {
86        self.client.as_channel()
87    }
88}
89
90#[cfg(target_os = "fuchsia")]
91impl RealmFactorySynchronousProxy {
92    pub fn new(channel: fidl::Channel) -> Self {
93        let protocol_name = <RealmFactoryMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME;
94        Self { client: fidl::client::sync::Client::new(channel, protocol_name) }
95    }
96
97    pub fn into_channel(self) -> fidl::Channel {
98        self.client.into_channel()
99    }
100
101    /// Waits until an event arrives and returns it. It is safe for other
102    /// threads to make concurrent requests while waiting for an event.
103    pub fn wait_for_event(
104        &self,
105        deadline: zx::MonotonicInstant,
106    ) -> Result<RealmFactoryEvent, fidl::Error> {
107        RealmFactoryEvent::decode(self.client.wait_for_event(deadline)?)
108    }
109
110    /// Creates a new realm and returns a dictionary containing its exposed capabilities.
111    pub fn r#create_realm(
112        &self,
113        mut options: RealmOptions,
114        ___deadline: zx::MonotonicInstant,
115    ) -> Result<RealmFactoryCreateRealmResult, fidl::Error> {
116        let _response = self
117            .client
118            .send_query::<RealmFactoryCreateRealmRequest, fidl::encoding::FlexibleResultType<
119                RealmFactoryCreateRealmResponse,
120                fidl_fuchsia_testing_harness::OperationError,
121            >>(
122                (&mut options,),
123                0x29ee78b460437125,
124                fidl::encoding::DynamicFlags::FLEXIBLE,
125                ___deadline,
126            )?
127            .into_result::<RealmFactoryMarker>("create_realm")?;
128        Ok(_response.map(|x| x.dictionary))
129    }
130}
131
132#[cfg(target_os = "fuchsia")]
133impl From<RealmFactorySynchronousProxy> for zx::Handle {
134    fn from(value: RealmFactorySynchronousProxy) -> Self {
135        value.into_channel().into()
136    }
137}
138
139#[cfg(target_os = "fuchsia")]
140impl From<fidl::Channel> for RealmFactorySynchronousProxy {
141    fn from(value: fidl::Channel) -> Self {
142        Self::new(value)
143    }
144}
145
146#[cfg(target_os = "fuchsia")]
147impl fidl::endpoints::FromClient for RealmFactorySynchronousProxy {
148    type Protocol = RealmFactoryMarker;
149
150    fn from_client(value: fidl::endpoints::ClientEnd<RealmFactoryMarker>) -> Self {
151        Self::new(value.into_channel())
152    }
153}
154
155#[derive(Debug, Clone)]
156pub struct RealmFactoryProxy {
157    client: fidl::client::Client<fidl::encoding::DefaultFuchsiaResourceDialect>,
158}
159
160impl fidl::endpoints::Proxy for RealmFactoryProxy {
161    type Protocol = RealmFactoryMarker;
162
163    fn from_channel(inner: ::fidl::AsyncChannel) -> Self {
164        Self::new(inner)
165    }
166
167    fn into_channel(self) -> Result<::fidl::AsyncChannel, Self> {
168        self.client.into_channel().map_err(|client| Self { client })
169    }
170
171    fn as_channel(&self) -> &::fidl::AsyncChannel {
172        self.client.as_channel()
173    }
174}
175
176impl RealmFactoryProxy {
177    /// Create a new Proxy for fuchsia.pkg.test/RealmFactory.
178    pub fn new(channel: ::fidl::AsyncChannel) -> Self {
179        let protocol_name = <RealmFactoryMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME;
180        Self { client: fidl::client::Client::new(channel, protocol_name) }
181    }
182
183    /// Get a Stream of events from the remote end of the protocol.
184    ///
185    /// # Panics
186    ///
187    /// Panics if the event stream was already taken.
188    pub fn take_event_stream(&self) -> RealmFactoryEventStream {
189        RealmFactoryEventStream { event_receiver: self.client.take_event_receiver() }
190    }
191
192    /// Creates a new realm and returns a dictionary containing its exposed capabilities.
193    pub fn r#create_realm(
194        &self,
195        mut options: RealmOptions,
196    ) -> fidl::client::QueryResponseFut<
197        RealmFactoryCreateRealmResult,
198        fidl::encoding::DefaultFuchsiaResourceDialect,
199    > {
200        RealmFactoryProxyInterface::r#create_realm(self, options)
201    }
202}
203
204impl RealmFactoryProxyInterface for RealmFactoryProxy {
205    type CreateRealmResponseFut = fidl::client::QueryResponseFut<
206        RealmFactoryCreateRealmResult,
207        fidl::encoding::DefaultFuchsiaResourceDialect,
208    >;
209    fn r#create_realm(&self, mut options: RealmOptions) -> Self::CreateRealmResponseFut {
210        fn _decode(
211            mut _buf: Result<<fidl::encoding::DefaultFuchsiaResourceDialect as fidl::encoding::ResourceDialect>::MessageBufEtc, fidl::Error>,
212        ) -> Result<RealmFactoryCreateRealmResult, fidl::Error> {
213            let _response = fidl::client::decode_transaction_body::<
214                fidl::encoding::FlexibleResultType<
215                    RealmFactoryCreateRealmResponse,
216                    fidl_fuchsia_testing_harness::OperationError,
217                >,
218                fidl::encoding::DefaultFuchsiaResourceDialect,
219                0x29ee78b460437125,
220            >(_buf?)?
221            .into_result::<RealmFactoryMarker>("create_realm")?;
222            Ok(_response.map(|x| x.dictionary))
223        }
224        self.client
225            .send_query_and_decode::<RealmFactoryCreateRealmRequest, RealmFactoryCreateRealmResult>(
226                (&mut options,),
227                0x29ee78b460437125,
228                fidl::encoding::DynamicFlags::FLEXIBLE,
229                _decode,
230            )
231    }
232}
233
234pub struct RealmFactoryEventStream {
235    event_receiver: fidl::client::EventReceiver<fidl::encoding::DefaultFuchsiaResourceDialect>,
236}
237
238impl std::marker::Unpin for RealmFactoryEventStream {}
239
240impl futures::stream::FusedStream for RealmFactoryEventStream {
241    fn is_terminated(&self) -> bool {
242        self.event_receiver.is_terminated()
243    }
244}
245
246impl futures::Stream for RealmFactoryEventStream {
247    type Item = Result<RealmFactoryEvent, fidl::Error>;
248
249    fn poll_next(
250        mut self: std::pin::Pin<&mut Self>,
251        cx: &mut std::task::Context<'_>,
252    ) -> std::task::Poll<Option<Self::Item>> {
253        match futures::ready!(futures::stream::StreamExt::poll_next_unpin(
254            &mut self.event_receiver,
255            cx
256        )?) {
257            Some(buf) => std::task::Poll::Ready(Some(RealmFactoryEvent::decode(buf))),
258            None => std::task::Poll::Ready(None),
259        }
260    }
261}
262
263#[derive(Debug)]
264pub enum RealmFactoryEvent {
265    #[non_exhaustive]
266    _UnknownEvent {
267        /// Ordinal of the event that was sent.
268        ordinal: u64,
269    },
270}
271
272impl RealmFactoryEvent {
273    /// Decodes a message buffer as a [`RealmFactoryEvent`].
274    fn decode(
275        mut buf: <fidl::encoding::DefaultFuchsiaResourceDialect as fidl::encoding::ResourceDialect>::MessageBufEtc,
276    ) -> Result<RealmFactoryEvent, fidl::Error> {
277        let (bytes, _handles) = buf.split_mut();
278        let (tx_header, _body_bytes) = fidl::encoding::decode_transaction_header(bytes)?;
279        debug_assert_eq!(tx_header.tx_id, 0);
280        match tx_header.ordinal {
281            _ if tx_header.dynamic_flags().contains(fidl::encoding::DynamicFlags::FLEXIBLE) => {
282                Ok(RealmFactoryEvent::_UnknownEvent { ordinal: tx_header.ordinal })
283            }
284            _ => Err(fidl::Error::UnknownOrdinal {
285                ordinal: tx_header.ordinal,
286                protocol_name: <RealmFactoryMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME,
287            }),
288        }
289    }
290}
291
292/// A Stream of incoming requests for fuchsia.pkg.test/RealmFactory.
293pub struct RealmFactoryRequestStream {
294    inner: std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>,
295    is_terminated: bool,
296}
297
298impl std::marker::Unpin for RealmFactoryRequestStream {}
299
300impl futures::stream::FusedStream for RealmFactoryRequestStream {
301    fn is_terminated(&self) -> bool {
302        self.is_terminated
303    }
304}
305
306impl fidl::endpoints::RequestStream for RealmFactoryRequestStream {
307    type Protocol = RealmFactoryMarker;
308    type ControlHandle = RealmFactoryControlHandle;
309
310    fn from_channel(channel: ::fidl::AsyncChannel) -> Self {
311        Self { inner: std::sync::Arc::new(fidl::ServeInner::new(channel)), is_terminated: false }
312    }
313
314    fn control_handle(&self) -> Self::ControlHandle {
315        RealmFactoryControlHandle { inner: self.inner.clone() }
316    }
317
318    fn into_inner(
319        self,
320    ) -> (::std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>, bool)
321    {
322        (self.inner, self.is_terminated)
323    }
324
325    fn from_inner(
326        inner: std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>,
327        is_terminated: bool,
328    ) -> Self {
329        Self { inner, is_terminated }
330    }
331}
332
333impl futures::Stream for RealmFactoryRequestStream {
334    type Item = Result<RealmFactoryRequest, fidl::Error>;
335
336    fn poll_next(
337        mut self: std::pin::Pin<&mut Self>,
338        cx: &mut std::task::Context<'_>,
339    ) -> std::task::Poll<Option<Self::Item>> {
340        let this = &mut *self;
341        if this.inner.check_shutdown(cx) {
342            this.is_terminated = true;
343            return std::task::Poll::Ready(None);
344        }
345        if this.is_terminated {
346            panic!("polled RealmFactoryRequestStream after completion");
347        }
348        fidl::encoding::with_tls_decode_buf::<_, fidl::encoding::DefaultFuchsiaResourceDialect>(
349            |bytes, handles| {
350                match this.inner.channel().read_etc(cx, bytes, handles) {
351                    std::task::Poll::Ready(Ok(())) => {}
352                    std::task::Poll::Pending => return std::task::Poll::Pending,
353                    std::task::Poll::Ready(Err(zx_status::Status::PEER_CLOSED)) => {
354                        this.is_terminated = true;
355                        return std::task::Poll::Ready(None);
356                    }
357                    std::task::Poll::Ready(Err(e)) => {
358                        return std::task::Poll::Ready(Some(Err(fidl::Error::ServerRequestRead(
359                            e.into(),
360                        ))))
361                    }
362                }
363
364                // A message has been received from the channel
365                let (header, _body_bytes) = fidl::encoding::decode_transaction_header(bytes)?;
366
367                std::task::Poll::Ready(Some(match header.ordinal {
368                    0x29ee78b460437125 => {
369                        header.validate_request_tx_id(fidl::MethodType::TwoWay)?;
370                        let mut req = fidl::new_empty!(
371                            RealmFactoryCreateRealmRequest,
372                            fidl::encoding::DefaultFuchsiaResourceDialect
373                        );
374                        fidl::encoding::Decoder::<fidl::encoding::DefaultFuchsiaResourceDialect>::decode_into::<RealmFactoryCreateRealmRequest>(&header, _body_bytes, handles, &mut req)?;
375                        let control_handle =
376                            RealmFactoryControlHandle { inner: this.inner.clone() };
377                        Ok(RealmFactoryRequest::CreateRealm {
378                            options: req.options,
379
380                            responder: RealmFactoryCreateRealmResponder {
381                                control_handle: std::mem::ManuallyDrop::new(control_handle),
382                                tx_id: header.tx_id,
383                            },
384                        })
385                    }
386                    _ if header.tx_id == 0
387                        && header
388                            .dynamic_flags()
389                            .contains(fidl::encoding::DynamicFlags::FLEXIBLE) =>
390                    {
391                        Ok(RealmFactoryRequest::_UnknownMethod {
392                            ordinal: header.ordinal,
393                            control_handle: RealmFactoryControlHandle { inner: this.inner.clone() },
394                            method_type: fidl::MethodType::OneWay,
395                        })
396                    }
397                    _ if header
398                        .dynamic_flags()
399                        .contains(fidl::encoding::DynamicFlags::FLEXIBLE) =>
400                    {
401                        this.inner.send_framework_err(
402                            fidl::encoding::FrameworkErr::UnknownMethod,
403                            header.tx_id,
404                            header.ordinal,
405                            header.dynamic_flags(),
406                            (bytes, handles),
407                        )?;
408                        Ok(RealmFactoryRequest::_UnknownMethod {
409                            ordinal: header.ordinal,
410                            control_handle: RealmFactoryControlHandle { inner: this.inner.clone() },
411                            method_type: fidl::MethodType::TwoWay,
412                        })
413                    }
414                    _ => Err(fidl::Error::UnknownOrdinal {
415                        ordinal: header.ordinal,
416                        protocol_name:
417                            <RealmFactoryMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME,
418                    }),
419                }))
420            },
421        )
422    }
423}
424
425#[derive(Debug)]
426pub enum RealmFactoryRequest {
427    /// Creates a new realm and returns a dictionary containing its exposed capabilities.
428    CreateRealm { options: RealmOptions, responder: RealmFactoryCreateRealmResponder },
429    /// An interaction was received which does not match any known method.
430    #[non_exhaustive]
431    _UnknownMethod {
432        /// Ordinal of the method that was called.
433        ordinal: u64,
434        control_handle: RealmFactoryControlHandle,
435        method_type: fidl::MethodType,
436    },
437}
438
439impl RealmFactoryRequest {
440    #[allow(irrefutable_let_patterns)]
441    pub fn into_create_realm(self) -> Option<(RealmOptions, RealmFactoryCreateRealmResponder)> {
442        if let RealmFactoryRequest::CreateRealm { options, responder } = self {
443            Some((options, responder))
444        } else {
445            None
446        }
447    }
448
449    /// Name of the method defined in FIDL
450    pub fn method_name(&self) -> &'static str {
451        match *self {
452            RealmFactoryRequest::CreateRealm { .. } => "create_realm",
453            RealmFactoryRequest::_UnknownMethod {
454                method_type: fidl::MethodType::OneWay, ..
455            } => "unknown one-way method",
456            RealmFactoryRequest::_UnknownMethod {
457                method_type: fidl::MethodType::TwoWay, ..
458            } => "unknown two-way method",
459        }
460    }
461}
462
463#[derive(Debug, Clone)]
464pub struct RealmFactoryControlHandle {
465    inner: std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>,
466}
467
468impl fidl::endpoints::ControlHandle for RealmFactoryControlHandle {
469    fn shutdown(&self) {
470        self.inner.shutdown()
471    }
472    fn shutdown_with_epitaph(&self, status: zx_status::Status) {
473        self.inner.shutdown_with_epitaph(status)
474    }
475
476    fn is_closed(&self) -> bool {
477        self.inner.channel().is_closed()
478    }
479    fn on_closed(&self) -> fidl::OnSignalsRef<'_> {
480        self.inner.channel().on_closed()
481    }
482
483    #[cfg(target_os = "fuchsia")]
484    fn signal_peer(
485        &self,
486        clear_mask: zx::Signals,
487        set_mask: zx::Signals,
488    ) -> Result<(), zx_status::Status> {
489        use fidl::Peered;
490        self.inner.channel().signal_peer(clear_mask, set_mask)
491    }
492}
493
494impl RealmFactoryControlHandle {}
495
496#[must_use = "FIDL methods require a response to be sent"]
497#[derive(Debug)]
498pub struct RealmFactoryCreateRealmResponder {
499    control_handle: std::mem::ManuallyDrop<RealmFactoryControlHandle>,
500    tx_id: u32,
501}
502
503/// Set the the channel to be shutdown (see [`RealmFactoryControlHandle::shutdown`])
504/// if the responder is dropped without sending a response, so that the client
505/// doesn't hang. To prevent this behavior, call `drop_without_shutdown`.
506impl std::ops::Drop for RealmFactoryCreateRealmResponder {
507    fn drop(&mut self) {
508        self.control_handle.shutdown();
509        // Safety: drops once, never accessed again
510        unsafe { std::mem::ManuallyDrop::drop(&mut self.control_handle) };
511    }
512}
513
514impl fidl::endpoints::Responder for RealmFactoryCreateRealmResponder {
515    type ControlHandle = RealmFactoryControlHandle;
516
517    fn control_handle(&self) -> &RealmFactoryControlHandle {
518        &self.control_handle
519    }
520
521    fn drop_without_shutdown(mut self) {
522        // Safety: drops once, never accessed again due to mem::forget
523        unsafe { std::mem::ManuallyDrop::drop(&mut self.control_handle) };
524        // Prevent Drop from running (which would shut down the channel)
525        std::mem::forget(self);
526    }
527}
528
529impl RealmFactoryCreateRealmResponder {
530    /// Sends a response to the FIDL transaction.
531    ///
532    /// Sets the channel to shutdown if an error occurs.
533    pub fn send(
534        self,
535        mut result: Result<
536            fidl::endpoints::ClientEnd<fidl_fuchsia_component_sandbox::DictionaryMarker>,
537            fidl_fuchsia_testing_harness::OperationError,
538        >,
539    ) -> Result<(), fidl::Error> {
540        let _result = self.send_raw(result);
541        if _result.is_err() {
542            self.control_handle.shutdown();
543        }
544        self.drop_without_shutdown();
545        _result
546    }
547
548    /// Similar to "send" but does not shutdown the channel if an error occurs.
549    pub fn send_no_shutdown_on_err(
550        self,
551        mut result: Result<
552            fidl::endpoints::ClientEnd<fidl_fuchsia_component_sandbox::DictionaryMarker>,
553            fidl_fuchsia_testing_harness::OperationError,
554        >,
555    ) -> Result<(), fidl::Error> {
556        let _result = self.send_raw(result);
557        self.drop_without_shutdown();
558        _result
559    }
560
561    fn send_raw(
562        &self,
563        mut result: Result<
564            fidl::endpoints::ClientEnd<fidl_fuchsia_component_sandbox::DictionaryMarker>,
565            fidl_fuchsia_testing_harness::OperationError,
566        >,
567    ) -> Result<(), fidl::Error> {
568        self.control_handle.inner.send::<fidl::encoding::FlexibleResultType<
569            RealmFactoryCreateRealmResponse,
570            fidl_fuchsia_testing_harness::OperationError,
571        >>(
572            fidl::encoding::FlexibleResult::new(result.map(|dictionary| (dictionary,))),
573            self.tx_id,
574            0x29ee78b460437125,
575            fidl::encoding::DynamicFlags::FLEXIBLE,
576        )
577    }
578}
579
580mod internal {
581    use super::*;
582
583    impl fidl::encoding::ResourceTypeMarker for RealmFactoryCreateRealmRequest {
584        type Borrowed<'a> = &'a mut Self;
585        fn take_or_borrow<'a>(
586            value: &'a mut <Self as fidl::encoding::TypeMarker>::Owned,
587        ) -> Self::Borrowed<'a> {
588            value
589        }
590    }
591
592    unsafe impl fidl::encoding::TypeMarker for RealmFactoryCreateRealmRequest {
593        type Owned = Self;
594
595        #[inline(always)]
596        fn inline_align(_context: fidl::encoding::Context) -> usize {
597            8
598        }
599
600        #[inline(always)]
601        fn inline_size(_context: fidl::encoding::Context) -> usize {
602            16
603        }
604    }
605
606    unsafe impl
607        fidl::encoding::Encode<
608            RealmFactoryCreateRealmRequest,
609            fidl::encoding::DefaultFuchsiaResourceDialect,
610        > for &mut RealmFactoryCreateRealmRequest
611    {
612        #[inline]
613        unsafe fn encode(
614            self,
615            encoder: &mut fidl::encoding::Encoder<
616                '_,
617                fidl::encoding::DefaultFuchsiaResourceDialect,
618            >,
619            offset: usize,
620            _depth: fidl::encoding::Depth,
621        ) -> fidl::Result<()> {
622            encoder.debug_check_bounds::<RealmFactoryCreateRealmRequest>(offset);
623            // Delegate to tuple encoding.
624            fidl::encoding::Encode::<
625                RealmFactoryCreateRealmRequest,
626                fidl::encoding::DefaultFuchsiaResourceDialect,
627            >::encode(
628                (<RealmOptions as fidl::encoding::ResourceTypeMarker>::take_or_borrow(
629                    &mut self.options,
630                ),),
631                encoder,
632                offset,
633                _depth,
634            )
635        }
636    }
637    unsafe impl<
638            T0: fidl::encoding::Encode<RealmOptions, fidl::encoding::DefaultFuchsiaResourceDialect>,
639        >
640        fidl::encoding::Encode<
641            RealmFactoryCreateRealmRequest,
642            fidl::encoding::DefaultFuchsiaResourceDialect,
643        > for (T0,)
644    {
645        #[inline]
646        unsafe fn encode(
647            self,
648            encoder: &mut fidl::encoding::Encoder<
649                '_,
650                fidl::encoding::DefaultFuchsiaResourceDialect,
651            >,
652            offset: usize,
653            depth: fidl::encoding::Depth,
654        ) -> fidl::Result<()> {
655            encoder.debug_check_bounds::<RealmFactoryCreateRealmRequest>(offset);
656            // Zero out padding regions. There's no need to apply masks
657            // because the unmasked parts will be overwritten by fields.
658            // Write the fields.
659            self.0.encode(encoder, offset + 0, depth)?;
660            Ok(())
661        }
662    }
663
664    impl fidl::encoding::Decode<Self, fidl::encoding::DefaultFuchsiaResourceDialect>
665        for RealmFactoryCreateRealmRequest
666    {
667        #[inline(always)]
668        fn new_empty() -> Self {
669            Self {
670                options: fidl::new_empty!(
671                    RealmOptions,
672                    fidl::encoding::DefaultFuchsiaResourceDialect
673                ),
674            }
675        }
676
677        #[inline]
678        unsafe fn decode(
679            &mut self,
680            decoder: &mut fidl::encoding::Decoder<
681                '_,
682                fidl::encoding::DefaultFuchsiaResourceDialect,
683            >,
684            offset: usize,
685            _depth: fidl::encoding::Depth,
686        ) -> fidl::Result<()> {
687            decoder.debug_check_bounds::<Self>(offset);
688            // Verify that padding bytes are zero.
689            fidl::decode!(
690                RealmOptions,
691                fidl::encoding::DefaultFuchsiaResourceDialect,
692                &mut self.options,
693                decoder,
694                offset + 0,
695                _depth
696            )?;
697            Ok(())
698        }
699    }
700
701    impl fidl::encoding::ResourceTypeMarker for RealmFactoryCreateRealmResponse {
702        type Borrowed<'a> = &'a mut Self;
703        fn take_or_borrow<'a>(
704            value: &'a mut <Self as fidl::encoding::TypeMarker>::Owned,
705        ) -> Self::Borrowed<'a> {
706            value
707        }
708    }
709
710    unsafe impl fidl::encoding::TypeMarker for RealmFactoryCreateRealmResponse {
711        type Owned = Self;
712
713        #[inline(always)]
714        fn inline_align(_context: fidl::encoding::Context) -> usize {
715            4
716        }
717
718        #[inline(always)]
719        fn inline_size(_context: fidl::encoding::Context) -> usize {
720            4
721        }
722    }
723
724    unsafe impl
725        fidl::encoding::Encode<
726            RealmFactoryCreateRealmResponse,
727            fidl::encoding::DefaultFuchsiaResourceDialect,
728        > for &mut RealmFactoryCreateRealmResponse
729    {
730        #[inline]
731        unsafe fn encode(
732            self,
733            encoder: &mut fidl::encoding::Encoder<
734                '_,
735                fidl::encoding::DefaultFuchsiaResourceDialect,
736            >,
737            offset: usize,
738            _depth: fidl::encoding::Depth,
739        ) -> fidl::Result<()> {
740            encoder.debug_check_bounds::<RealmFactoryCreateRealmResponse>(offset);
741            // Delegate to tuple encoding.
742            fidl::encoding::Encode::<
743                RealmFactoryCreateRealmResponse,
744                fidl::encoding::DefaultFuchsiaResourceDialect,
745            >::encode(
746                (<fidl::encoding::Endpoint<
747                    fidl::endpoints::ClientEnd<fidl_fuchsia_component_sandbox::DictionaryMarker>,
748                > as fidl::encoding::ResourceTypeMarker>::take_or_borrow(
749                    &mut self.dictionary
750                ),),
751                encoder,
752                offset,
753                _depth,
754            )
755        }
756    }
757    unsafe impl<
758            T0: fidl::encoding::Encode<
759                fidl::encoding::Endpoint<
760                    fidl::endpoints::ClientEnd<fidl_fuchsia_component_sandbox::DictionaryMarker>,
761                >,
762                fidl::encoding::DefaultFuchsiaResourceDialect,
763            >,
764        >
765        fidl::encoding::Encode<
766            RealmFactoryCreateRealmResponse,
767            fidl::encoding::DefaultFuchsiaResourceDialect,
768        > for (T0,)
769    {
770        #[inline]
771        unsafe fn encode(
772            self,
773            encoder: &mut fidl::encoding::Encoder<
774                '_,
775                fidl::encoding::DefaultFuchsiaResourceDialect,
776            >,
777            offset: usize,
778            depth: fidl::encoding::Depth,
779        ) -> fidl::Result<()> {
780            encoder.debug_check_bounds::<RealmFactoryCreateRealmResponse>(offset);
781            // Zero out padding regions. There's no need to apply masks
782            // because the unmasked parts will be overwritten by fields.
783            // Write the fields.
784            self.0.encode(encoder, offset + 0, depth)?;
785            Ok(())
786        }
787    }
788
789    impl fidl::encoding::Decode<Self, fidl::encoding::DefaultFuchsiaResourceDialect>
790        for RealmFactoryCreateRealmResponse
791    {
792        #[inline(always)]
793        fn new_empty() -> Self {
794            Self {
795                dictionary: fidl::new_empty!(
796                    fidl::encoding::Endpoint<
797                        fidl::endpoints::ClientEnd<
798                            fidl_fuchsia_component_sandbox::DictionaryMarker,
799                        >,
800                    >,
801                    fidl::encoding::DefaultFuchsiaResourceDialect
802                ),
803            }
804        }
805
806        #[inline]
807        unsafe fn decode(
808            &mut self,
809            decoder: &mut fidl::encoding::Decoder<
810                '_,
811                fidl::encoding::DefaultFuchsiaResourceDialect,
812            >,
813            offset: usize,
814            _depth: fidl::encoding::Depth,
815        ) -> fidl::Result<()> {
816            decoder.debug_check_bounds::<Self>(offset);
817            // Verify that padding bytes are zero.
818            fidl::decode!(
819                fidl::encoding::Endpoint<
820                    fidl::endpoints::ClientEnd<fidl_fuchsia_component_sandbox::DictionaryMarker>,
821                >,
822                fidl::encoding::DefaultFuchsiaResourceDialect,
823                &mut self.dictionary,
824                decoder,
825                offset + 0,
826                _depth
827            )?;
828            Ok(())
829        }
830    }
831
832    impl RealmOptions {
833        #[inline(always)]
834        fn max_ordinal_present(&self) -> u64 {
835            if let Some(_) = self.pkg_directory_server {
836                return 1;
837            }
838            0
839        }
840    }
841
842    impl fidl::encoding::ResourceTypeMarker for RealmOptions {
843        type Borrowed<'a> = &'a mut Self;
844        fn take_or_borrow<'a>(
845            value: &'a mut <Self as fidl::encoding::TypeMarker>::Owned,
846        ) -> Self::Borrowed<'a> {
847            value
848        }
849    }
850
851    unsafe impl fidl::encoding::TypeMarker for RealmOptions {
852        type Owned = Self;
853
854        #[inline(always)]
855        fn inline_align(_context: fidl::encoding::Context) -> usize {
856            8
857        }
858
859        #[inline(always)]
860        fn inline_size(_context: fidl::encoding::Context) -> usize {
861            16
862        }
863    }
864
865    unsafe impl fidl::encoding::Encode<RealmOptions, fidl::encoding::DefaultFuchsiaResourceDialect>
866        for &mut RealmOptions
867    {
868        unsafe fn encode(
869            self,
870            encoder: &mut fidl::encoding::Encoder<
871                '_,
872                fidl::encoding::DefaultFuchsiaResourceDialect,
873            >,
874            offset: usize,
875            mut depth: fidl::encoding::Depth,
876        ) -> fidl::Result<()> {
877            encoder.debug_check_bounds::<RealmOptions>(offset);
878            // Vector header
879            let max_ordinal: u64 = self.max_ordinal_present();
880            encoder.write_num(max_ordinal, offset);
881            encoder.write_num(fidl::encoding::ALLOC_PRESENT_U64, offset + 8);
882            // Calling encoder.out_of_line_offset(0) is not allowed.
883            if max_ordinal == 0 {
884                return Ok(());
885            }
886            depth.increment()?;
887            let envelope_size = 8;
888            let bytes_len = max_ordinal as usize * envelope_size;
889            #[allow(unused_variables)]
890            let offset = encoder.out_of_line_offset(bytes_len);
891            let mut _prev_end_offset: usize = 0;
892            if 1 > max_ordinal {
893                return Ok(());
894            }
895
896            // Write at offset+(ordinal-1)*envelope_size, since ordinals are one-based and envelopes
897            // are envelope_size bytes.
898            let cur_offset: usize = (1 - 1) * envelope_size;
899
900            // Zero reserved fields.
901            encoder.padding(offset + _prev_end_offset, cur_offset - _prev_end_offset);
902
903            // Safety:
904            // - bytes_len is calculated to fit envelope_size*max(member.ordinal).
905            // - Since cur_offset is envelope_size*(member.ordinal - 1) and the envelope takes
906            //   envelope_size bytes, there is always sufficient room.
907            fidl::encoding::encode_in_envelope_optional::<
908                fidl::encoding::Endpoint<
909                    fidl::endpoints::ServerEnd<fidl_fuchsia_io::DirectoryMarker>,
910                >,
911                fidl::encoding::DefaultFuchsiaResourceDialect,
912            >(
913                self.pkg_directory_server.as_mut().map(
914                    <fidl::encoding::Endpoint<
915                        fidl::endpoints::ServerEnd<fidl_fuchsia_io::DirectoryMarker>,
916                    > as fidl::encoding::ResourceTypeMarker>::take_or_borrow,
917                ),
918                encoder,
919                offset + cur_offset,
920                depth,
921            )?;
922
923            _prev_end_offset = cur_offset + envelope_size;
924
925            Ok(())
926        }
927    }
928
929    impl fidl::encoding::Decode<Self, fidl::encoding::DefaultFuchsiaResourceDialect> for RealmOptions {
930        #[inline(always)]
931        fn new_empty() -> Self {
932            Self::default()
933        }
934
935        unsafe fn decode(
936            &mut self,
937            decoder: &mut fidl::encoding::Decoder<
938                '_,
939                fidl::encoding::DefaultFuchsiaResourceDialect,
940            >,
941            offset: usize,
942            mut depth: fidl::encoding::Depth,
943        ) -> fidl::Result<()> {
944            decoder.debug_check_bounds::<Self>(offset);
945            let len = match fidl::encoding::decode_vector_header(decoder, offset)? {
946                None => return Err(fidl::Error::NotNullable),
947                Some(len) => len,
948            };
949            // Calling decoder.out_of_line_offset(0) is not allowed.
950            if len == 0 {
951                return Ok(());
952            };
953            depth.increment()?;
954            let envelope_size = 8;
955            let bytes_len = len * envelope_size;
956            let offset = decoder.out_of_line_offset(bytes_len)?;
957            // Decode the envelope for each type.
958            let mut _next_ordinal_to_read = 0;
959            let mut next_offset = offset;
960            let end_offset = offset + bytes_len;
961            _next_ordinal_to_read += 1;
962            if next_offset >= end_offset {
963                return Ok(());
964            }
965
966            // Decode unknown envelopes for gaps in ordinals.
967            while _next_ordinal_to_read < 1 {
968                fidl::encoding::decode_unknown_envelope(decoder, next_offset, depth)?;
969                _next_ordinal_to_read += 1;
970                next_offset += envelope_size;
971            }
972
973            let next_out_of_line = decoder.next_out_of_line();
974            let handles_before = decoder.remaining_handles();
975            if let Some((inlined, num_bytes, num_handles)) =
976                fidl::encoding::decode_envelope_header(decoder, next_offset)?
977            {
978                let member_inline_size = <fidl::encoding::Endpoint<
979                    fidl::endpoints::ServerEnd<fidl_fuchsia_io::DirectoryMarker>,
980                > as fidl::encoding::TypeMarker>::inline_size(
981                    decoder.context
982                );
983                if inlined != (member_inline_size <= 4) {
984                    return Err(fidl::Error::InvalidInlineBitInEnvelope);
985                }
986                let inner_offset;
987                let mut inner_depth = depth.clone();
988                if inlined {
989                    decoder.check_inline_envelope_padding(next_offset, member_inline_size)?;
990                    inner_offset = next_offset;
991                } else {
992                    inner_offset = decoder.out_of_line_offset(member_inline_size)?;
993                    inner_depth.increment()?;
994                }
995                let val_ref = self.pkg_directory_server.get_or_insert_with(|| {
996                    fidl::new_empty!(
997                        fidl::encoding::Endpoint<
998                            fidl::endpoints::ServerEnd<fidl_fuchsia_io::DirectoryMarker>,
999                        >,
1000                        fidl::encoding::DefaultFuchsiaResourceDialect
1001                    )
1002                });
1003                fidl::decode!(
1004                    fidl::encoding::Endpoint<
1005                        fidl::endpoints::ServerEnd<fidl_fuchsia_io::DirectoryMarker>,
1006                    >,
1007                    fidl::encoding::DefaultFuchsiaResourceDialect,
1008                    val_ref,
1009                    decoder,
1010                    inner_offset,
1011                    inner_depth
1012                )?;
1013                if !inlined && decoder.next_out_of_line() != next_out_of_line + (num_bytes as usize)
1014                {
1015                    return Err(fidl::Error::InvalidNumBytesInEnvelope);
1016                }
1017                if handles_before != decoder.remaining_handles() + (num_handles as usize) {
1018                    return Err(fidl::Error::InvalidNumHandlesInEnvelope);
1019                }
1020            }
1021
1022            next_offset += envelope_size;
1023
1024            // Decode the remaining unknown envelopes.
1025            while next_offset < end_offset {
1026                _next_ordinal_to_read += 1;
1027                fidl::encoding::decode_unknown_envelope(decoder, next_offset, depth)?;
1028                next_offset += envelope_size;
1029            }
1030
1031            Ok(())
1032        }
1033    }
1034}