fidl_test_sampler/
fidl_test_sampler.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_sampler_common::*;
11use futures::future::{self, MaybeDone, TryFutureExt};
12use zx_status;
13
14#[derive(Debug, PartialEq)]
15pub struct RealmFactoryCreateRealmRequest {
16    pub options: RealmOptions,
17    pub dictionary: fidl::endpoints::ServerEnd<fidl_fuchsia_component_sandbox::DictionaryMarker>,
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    /// Optional name to give to the Sampler realm component.
29    /// Defaults to "sampler".
30    pub sampler_component_name: Option<String>,
31    /// Optional name to give to the "Single Counter" realm component.
32    /// Defaults to "single_counter".
33    pub single_counter_name: Option<String>,
34    /// Optional name to give to the fake Cobalt realm component.
35    /// Defaults to "fake_cobalt".
36    pub fake_cobalt_name: Option<String>,
37    /// Optional name to give to the Archivist realm component.
38    /// Defaults to "test_case_archivist".
39    pub test_archivist_name: Option<String>,
40    #[doc(hidden)]
41    pub __source_breaking: fidl::marker::SourceBreaking,
42}
43
44impl fidl::Standalone<fidl::encoding::DefaultFuchsiaResourceDialect> for RealmOptions {}
45
46#[derive(Debug, Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Hash)]
47pub struct RealmFactoryMarker;
48
49impl fidl::endpoints::ProtocolMarker for RealmFactoryMarker {
50    type Proxy = RealmFactoryProxy;
51    type RequestStream = RealmFactoryRequestStream;
52    #[cfg(target_os = "fuchsia")]
53    type SynchronousProxy = RealmFactorySynchronousProxy;
54
55    const DEBUG_NAME: &'static str = "test.sampler.RealmFactory";
56}
57impl fidl::endpoints::DiscoverableProtocolMarker for RealmFactoryMarker {}
58pub type RealmFactoryCreateRealmResult = Result<(), fidl_fuchsia_testing_harness::OperationError>;
59
60pub trait RealmFactoryProxyInterface: Send + Sync {
61    type CreateRealmResponseFut: std::future::Future<Output = Result<RealmFactoryCreateRealmResult, fidl::Error>>
62        + Send;
63    fn r#create_realm(
64        &self,
65        options: RealmOptions,
66        dictionary: fidl::endpoints::ServerEnd<fidl_fuchsia_component_sandbox::DictionaryMarker>,
67    ) -> Self::CreateRealmResponseFut;
68}
69#[derive(Debug)]
70#[cfg(target_os = "fuchsia")]
71pub struct RealmFactorySynchronousProxy {
72    client: fidl::client::sync::Client,
73}
74
75#[cfg(target_os = "fuchsia")]
76impl fidl::endpoints::SynchronousProxy for RealmFactorySynchronousProxy {
77    type Proxy = RealmFactoryProxy;
78    type Protocol = RealmFactoryMarker;
79
80    fn from_channel(inner: fidl::Channel) -> Self {
81        Self::new(inner)
82    }
83
84    fn into_channel(self) -> fidl::Channel {
85        self.client.into_channel()
86    }
87
88    fn as_channel(&self) -> &fidl::Channel {
89        self.client.as_channel()
90    }
91}
92
93#[cfg(target_os = "fuchsia")]
94impl RealmFactorySynchronousProxy {
95    pub fn new(channel: fidl::Channel) -> Self {
96        let protocol_name = <RealmFactoryMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME;
97        Self { client: fidl::client::sync::Client::new(channel, protocol_name) }
98    }
99
100    pub fn into_channel(self) -> fidl::Channel {
101        self.client.into_channel()
102    }
103
104    /// Waits until an event arrives and returns it. It is safe for other
105    /// threads to make concurrent requests while waiting for an event.
106    pub fn wait_for_event(
107        &self,
108        deadline: zx::MonotonicInstant,
109    ) -> Result<RealmFactoryEvent, fidl::Error> {
110        RealmFactoryEvent::decode(self.client.wait_for_event(deadline)?)
111    }
112
113    /// Specifies the options to use when creating the realm.
114    ///
115    /// Returns OperationError.INVALID if called more than once.
116    pub fn r#create_realm(
117        &self,
118        mut options: RealmOptions,
119        mut dictionary: fidl::endpoints::ServerEnd<
120            fidl_fuchsia_component_sandbox::DictionaryMarker,
121        >,
122        ___deadline: zx::MonotonicInstant,
123    ) -> Result<RealmFactoryCreateRealmResult, fidl::Error> {
124        let _response = self
125            .client
126            .send_query::<RealmFactoryCreateRealmRequest, fidl::encoding::FlexibleResultType<
127                fidl::encoding::EmptyStruct,
128                fidl_fuchsia_testing_harness::OperationError,
129            >>(
130                (&mut options, dictionary),
131                0x3c060dc24a5d0788,
132                fidl::encoding::DynamicFlags::FLEXIBLE,
133                ___deadline,
134            )?
135            .into_result::<RealmFactoryMarker>("create_realm")?;
136        Ok(_response.map(|x| x))
137    }
138}
139
140#[derive(Debug, Clone)]
141pub struct RealmFactoryProxy {
142    client: fidl::client::Client<fidl::encoding::DefaultFuchsiaResourceDialect>,
143}
144
145impl fidl::endpoints::Proxy for RealmFactoryProxy {
146    type Protocol = RealmFactoryMarker;
147
148    fn from_channel(inner: ::fidl::AsyncChannel) -> Self {
149        Self::new(inner)
150    }
151
152    fn into_channel(self) -> Result<::fidl::AsyncChannel, Self> {
153        self.client.into_channel().map_err(|client| Self { client })
154    }
155
156    fn as_channel(&self) -> &::fidl::AsyncChannel {
157        self.client.as_channel()
158    }
159}
160
161impl RealmFactoryProxy {
162    /// Create a new Proxy for test.sampler/RealmFactory.
163    pub fn new(channel: ::fidl::AsyncChannel) -> Self {
164        let protocol_name = <RealmFactoryMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME;
165        Self { client: fidl::client::Client::new(channel, protocol_name) }
166    }
167
168    /// Get a Stream of events from the remote end of the protocol.
169    ///
170    /// # Panics
171    ///
172    /// Panics if the event stream was already taken.
173    pub fn take_event_stream(&self) -> RealmFactoryEventStream {
174        RealmFactoryEventStream { event_receiver: self.client.take_event_receiver() }
175    }
176
177    /// Specifies the options to use when creating the realm.
178    ///
179    /// Returns OperationError.INVALID if called more than once.
180    pub fn r#create_realm(
181        &self,
182        mut options: RealmOptions,
183        mut dictionary: fidl::endpoints::ServerEnd<
184            fidl_fuchsia_component_sandbox::DictionaryMarker,
185        >,
186    ) -> fidl::client::QueryResponseFut<
187        RealmFactoryCreateRealmResult,
188        fidl::encoding::DefaultFuchsiaResourceDialect,
189    > {
190        RealmFactoryProxyInterface::r#create_realm(self, options, dictionary)
191    }
192}
193
194impl RealmFactoryProxyInterface for RealmFactoryProxy {
195    type CreateRealmResponseFut = fidl::client::QueryResponseFut<
196        RealmFactoryCreateRealmResult,
197        fidl::encoding::DefaultFuchsiaResourceDialect,
198    >;
199    fn r#create_realm(
200        &self,
201        mut options: RealmOptions,
202        mut dictionary: fidl::endpoints::ServerEnd<
203            fidl_fuchsia_component_sandbox::DictionaryMarker,
204        >,
205    ) -> Self::CreateRealmResponseFut {
206        fn _decode(
207            mut _buf: Result<<fidl::encoding::DefaultFuchsiaResourceDialect as fidl::encoding::ResourceDialect>::MessageBufEtc, fidl::Error>,
208        ) -> Result<RealmFactoryCreateRealmResult, fidl::Error> {
209            let _response = fidl::client::decode_transaction_body::<
210                fidl::encoding::FlexibleResultType<
211                    fidl::encoding::EmptyStruct,
212                    fidl_fuchsia_testing_harness::OperationError,
213                >,
214                fidl::encoding::DefaultFuchsiaResourceDialect,
215                0x3c060dc24a5d0788,
216            >(_buf?)?
217            .into_result::<RealmFactoryMarker>("create_realm")?;
218            Ok(_response.map(|x| x))
219        }
220        self.client
221            .send_query_and_decode::<RealmFactoryCreateRealmRequest, RealmFactoryCreateRealmResult>(
222                (&mut options, dictionary),
223                0x3c060dc24a5d0788,
224                fidl::encoding::DynamicFlags::FLEXIBLE,
225                _decode,
226            )
227    }
228}
229
230pub struct RealmFactoryEventStream {
231    event_receiver: fidl::client::EventReceiver<fidl::encoding::DefaultFuchsiaResourceDialect>,
232}
233
234impl std::marker::Unpin for RealmFactoryEventStream {}
235
236impl futures::stream::FusedStream for RealmFactoryEventStream {
237    fn is_terminated(&self) -> bool {
238        self.event_receiver.is_terminated()
239    }
240}
241
242impl futures::Stream for RealmFactoryEventStream {
243    type Item = Result<RealmFactoryEvent, fidl::Error>;
244
245    fn poll_next(
246        mut self: std::pin::Pin<&mut Self>,
247        cx: &mut std::task::Context<'_>,
248    ) -> std::task::Poll<Option<Self::Item>> {
249        match futures::ready!(futures::stream::StreamExt::poll_next_unpin(
250            &mut self.event_receiver,
251            cx
252        )?) {
253            Some(buf) => std::task::Poll::Ready(Some(RealmFactoryEvent::decode(buf))),
254            None => std::task::Poll::Ready(None),
255        }
256    }
257}
258
259#[derive(Debug)]
260pub enum RealmFactoryEvent {
261    #[non_exhaustive]
262    _UnknownEvent {
263        /// Ordinal of the event that was sent.
264        ordinal: u64,
265    },
266}
267
268impl RealmFactoryEvent {
269    /// Decodes a message buffer as a [`RealmFactoryEvent`].
270    fn decode(
271        mut buf: <fidl::encoding::DefaultFuchsiaResourceDialect as fidl::encoding::ResourceDialect>::MessageBufEtc,
272    ) -> Result<RealmFactoryEvent, fidl::Error> {
273        let (bytes, _handles) = buf.split_mut();
274        let (tx_header, _body_bytes) = fidl::encoding::decode_transaction_header(bytes)?;
275        debug_assert_eq!(tx_header.tx_id, 0);
276        match tx_header.ordinal {
277            _ if tx_header.dynamic_flags().contains(fidl::encoding::DynamicFlags::FLEXIBLE) => {
278                Ok(RealmFactoryEvent::_UnknownEvent { ordinal: tx_header.ordinal })
279            }
280            _ => Err(fidl::Error::UnknownOrdinal {
281                ordinal: tx_header.ordinal,
282                protocol_name: <RealmFactoryMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME,
283            }),
284        }
285    }
286}
287
288/// A Stream of incoming requests for test.sampler/RealmFactory.
289pub struct RealmFactoryRequestStream {
290    inner: std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>,
291    is_terminated: bool,
292}
293
294impl std::marker::Unpin for RealmFactoryRequestStream {}
295
296impl futures::stream::FusedStream for RealmFactoryRequestStream {
297    fn is_terminated(&self) -> bool {
298        self.is_terminated
299    }
300}
301
302impl fidl::endpoints::RequestStream for RealmFactoryRequestStream {
303    type Protocol = RealmFactoryMarker;
304    type ControlHandle = RealmFactoryControlHandle;
305
306    fn from_channel(channel: ::fidl::AsyncChannel) -> Self {
307        Self { inner: std::sync::Arc::new(fidl::ServeInner::new(channel)), is_terminated: false }
308    }
309
310    fn control_handle(&self) -> Self::ControlHandle {
311        RealmFactoryControlHandle { inner: self.inner.clone() }
312    }
313
314    fn into_inner(
315        self,
316    ) -> (::std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>, bool)
317    {
318        (self.inner, self.is_terminated)
319    }
320
321    fn from_inner(
322        inner: std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>,
323        is_terminated: bool,
324    ) -> Self {
325        Self { inner, is_terminated }
326    }
327}
328
329impl futures::Stream for RealmFactoryRequestStream {
330    type Item = Result<RealmFactoryRequest, fidl::Error>;
331
332    fn poll_next(
333        mut self: std::pin::Pin<&mut Self>,
334        cx: &mut std::task::Context<'_>,
335    ) -> std::task::Poll<Option<Self::Item>> {
336        let this = &mut *self;
337        if this.inner.check_shutdown(cx) {
338            this.is_terminated = true;
339            return std::task::Poll::Ready(None);
340        }
341        if this.is_terminated {
342            panic!("polled RealmFactoryRequestStream after completion");
343        }
344        fidl::encoding::with_tls_decode_buf::<_, fidl::encoding::DefaultFuchsiaResourceDialect>(
345            |bytes, handles| {
346                match this.inner.channel().read_etc(cx, bytes, handles) {
347                    std::task::Poll::Ready(Ok(())) => {}
348                    std::task::Poll::Pending => return std::task::Poll::Pending,
349                    std::task::Poll::Ready(Err(zx_status::Status::PEER_CLOSED)) => {
350                        this.is_terminated = true;
351                        return std::task::Poll::Ready(None);
352                    }
353                    std::task::Poll::Ready(Err(e)) => {
354                        return std::task::Poll::Ready(Some(Err(fidl::Error::ServerRequestRead(
355                            e.into(),
356                        ))))
357                    }
358                }
359
360                // A message has been received from the channel
361                let (header, _body_bytes) = fidl::encoding::decode_transaction_header(bytes)?;
362
363                std::task::Poll::Ready(Some(match header.ordinal {
364                    0x3c060dc24a5d0788 => {
365                        header.validate_request_tx_id(fidl::MethodType::TwoWay)?;
366                        let mut req = fidl::new_empty!(
367                            RealmFactoryCreateRealmRequest,
368                            fidl::encoding::DefaultFuchsiaResourceDialect
369                        );
370                        fidl::encoding::Decoder::<fidl::encoding::DefaultFuchsiaResourceDialect>::decode_into::<RealmFactoryCreateRealmRequest>(&header, _body_bytes, handles, &mut req)?;
371                        let control_handle =
372                            RealmFactoryControlHandle { inner: this.inner.clone() };
373                        Ok(RealmFactoryRequest::CreateRealm {
374                            options: req.options,
375                            dictionary: req.dictionary,
376
377                            responder: RealmFactoryCreateRealmResponder {
378                                control_handle: std::mem::ManuallyDrop::new(control_handle),
379                                tx_id: header.tx_id,
380                            },
381                        })
382                    }
383                    _ if header.tx_id == 0
384                        && header
385                            .dynamic_flags()
386                            .contains(fidl::encoding::DynamicFlags::FLEXIBLE) =>
387                    {
388                        Ok(RealmFactoryRequest::_UnknownMethod {
389                            ordinal: header.ordinal,
390                            control_handle: RealmFactoryControlHandle { inner: this.inner.clone() },
391                            method_type: fidl::MethodType::OneWay,
392                        })
393                    }
394                    _ if header
395                        .dynamic_flags()
396                        .contains(fidl::encoding::DynamicFlags::FLEXIBLE) =>
397                    {
398                        this.inner.send_framework_err(
399                            fidl::encoding::FrameworkErr::UnknownMethod,
400                            header.tx_id,
401                            header.ordinal,
402                            header.dynamic_flags(),
403                            (bytes, handles),
404                        )?;
405                        Ok(RealmFactoryRequest::_UnknownMethod {
406                            ordinal: header.ordinal,
407                            control_handle: RealmFactoryControlHandle { inner: this.inner.clone() },
408                            method_type: fidl::MethodType::TwoWay,
409                        })
410                    }
411                    _ => Err(fidl::Error::UnknownOrdinal {
412                        ordinal: header.ordinal,
413                        protocol_name:
414                            <RealmFactoryMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME,
415                    }),
416                }))
417            },
418        )
419    }
420}
421
422#[derive(Debug)]
423pub enum RealmFactoryRequest {
424    /// Specifies the options to use when creating the realm.
425    ///
426    /// Returns OperationError.INVALID if called more than once.
427    CreateRealm {
428        options: RealmOptions,
429        dictionary: fidl::endpoints::ServerEnd<fidl_fuchsia_component_sandbox::DictionaryMarker>,
430        responder: RealmFactoryCreateRealmResponder,
431    },
432    /// An interaction was received which does not match any known method.
433    #[non_exhaustive]
434    _UnknownMethod {
435        /// Ordinal of the method that was called.
436        ordinal: u64,
437        control_handle: RealmFactoryControlHandle,
438        method_type: fidl::MethodType,
439    },
440}
441
442impl RealmFactoryRequest {
443    #[allow(irrefutable_let_patterns)]
444    pub fn into_create_realm(
445        self,
446    ) -> Option<(
447        RealmOptions,
448        fidl::endpoints::ServerEnd<fidl_fuchsia_component_sandbox::DictionaryMarker>,
449        RealmFactoryCreateRealmResponder,
450    )> {
451        if let RealmFactoryRequest::CreateRealm { options, dictionary, responder } = self {
452            Some((options, dictionary, responder))
453        } else {
454            None
455        }
456    }
457
458    /// Name of the method defined in FIDL
459    pub fn method_name(&self) -> &'static str {
460        match *self {
461            RealmFactoryRequest::CreateRealm { .. } => "create_realm",
462            RealmFactoryRequest::_UnknownMethod {
463                method_type: fidl::MethodType::OneWay, ..
464            } => "unknown one-way method",
465            RealmFactoryRequest::_UnknownMethod {
466                method_type: fidl::MethodType::TwoWay, ..
467            } => "unknown two-way method",
468        }
469    }
470}
471
472#[derive(Debug, Clone)]
473pub struct RealmFactoryControlHandle {
474    inner: std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>,
475}
476
477impl fidl::endpoints::ControlHandle for RealmFactoryControlHandle {
478    fn shutdown(&self) {
479        self.inner.shutdown()
480    }
481    fn shutdown_with_epitaph(&self, status: zx_status::Status) {
482        self.inner.shutdown_with_epitaph(status)
483    }
484
485    fn is_closed(&self) -> bool {
486        self.inner.channel().is_closed()
487    }
488    fn on_closed(&self) -> fidl::OnSignalsRef<'_> {
489        self.inner.channel().on_closed()
490    }
491
492    #[cfg(target_os = "fuchsia")]
493    fn signal_peer(
494        &self,
495        clear_mask: zx::Signals,
496        set_mask: zx::Signals,
497    ) -> Result<(), zx_status::Status> {
498        use fidl::Peered;
499        self.inner.channel().signal_peer(clear_mask, set_mask)
500    }
501}
502
503impl RealmFactoryControlHandle {}
504
505#[must_use = "FIDL methods require a response to be sent"]
506#[derive(Debug)]
507pub struct RealmFactoryCreateRealmResponder {
508    control_handle: std::mem::ManuallyDrop<RealmFactoryControlHandle>,
509    tx_id: u32,
510}
511
512/// Set the the channel to be shutdown (see [`RealmFactoryControlHandle::shutdown`])
513/// if the responder is dropped without sending a response, so that the client
514/// doesn't hang. To prevent this behavior, call `drop_without_shutdown`.
515impl std::ops::Drop for RealmFactoryCreateRealmResponder {
516    fn drop(&mut self) {
517        self.control_handle.shutdown();
518        // Safety: drops once, never accessed again
519        unsafe { std::mem::ManuallyDrop::drop(&mut self.control_handle) };
520    }
521}
522
523impl fidl::endpoints::Responder for RealmFactoryCreateRealmResponder {
524    type ControlHandle = RealmFactoryControlHandle;
525
526    fn control_handle(&self) -> &RealmFactoryControlHandle {
527        &self.control_handle
528    }
529
530    fn drop_without_shutdown(mut self) {
531        // Safety: drops once, never accessed again due to mem::forget
532        unsafe { std::mem::ManuallyDrop::drop(&mut self.control_handle) };
533        // Prevent Drop from running (which would shut down the channel)
534        std::mem::forget(self);
535    }
536}
537
538impl RealmFactoryCreateRealmResponder {
539    /// Sends a response to the FIDL transaction.
540    ///
541    /// Sets the channel to shutdown if an error occurs.
542    pub fn send(
543        self,
544        mut result: Result<(), fidl_fuchsia_testing_harness::OperationError>,
545    ) -> Result<(), fidl::Error> {
546        let _result = self.send_raw(result);
547        if _result.is_err() {
548            self.control_handle.shutdown();
549        }
550        self.drop_without_shutdown();
551        _result
552    }
553
554    /// Similar to "send" but does not shutdown the channel if an error occurs.
555    pub fn send_no_shutdown_on_err(
556        self,
557        mut result: Result<(), fidl_fuchsia_testing_harness::OperationError>,
558    ) -> Result<(), fidl::Error> {
559        let _result = self.send_raw(result);
560        self.drop_without_shutdown();
561        _result
562    }
563
564    fn send_raw(
565        &self,
566        mut result: Result<(), fidl_fuchsia_testing_harness::OperationError>,
567    ) -> Result<(), fidl::Error> {
568        self.control_handle.inner.send::<fidl::encoding::FlexibleResultType<
569            fidl::encoding::EmptyStruct,
570            fidl_fuchsia_testing_harness::OperationError,
571        >>(
572            fidl::encoding::FlexibleResult::new(result),
573            self.tx_id,
574            0x3c060dc24a5d0788,
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            24
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                (
629                    <RealmOptions as fidl::encoding::ResourceTypeMarker>::take_or_borrow(
630                        &mut self.options,
631                    ),
632                    <fidl::encoding::Endpoint<
633                        fidl::endpoints::ServerEnd<
634                            fidl_fuchsia_component_sandbox::DictionaryMarker,
635                        >,
636                    > as fidl::encoding::ResourceTypeMarker>::take_or_borrow(
637                        &mut self.dictionary
638                    ),
639                ),
640                encoder,
641                offset,
642                _depth,
643            )
644        }
645    }
646    unsafe impl<
647            T0: fidl::encoding::Encode<RealmOptions, fidl::encoding::DefaultFuchsiaResourceDialect>,
648            T1: fidl::encoding::Encode<
649                fidl::encoding::Endpoint<
650                    fidl::endpoints::ServerEnd<fidl_fuchsia_component_sandbox::DictionaryMarker>,
651                >,
652                fidl::encoding::DefaultFuchsiaResourceDialect,
653            >,
654        >
655        fidl::encoding::Encode<
656            RealmFactoryCreateRealmRequest,
657            fidl::encoding::DefaultFuchsiaResourceDialect,
658        > for (T0, T1)
659    {
660        #[inline]
661        unsafe fn encode(
662            self,
663            encoder: &mut fidl::encoding::Encoder<
664                '_,
665                fidl::encoding::DefaultFuchsiaResourceDialect,
666            >,
667            offset: usize,
668            depth: fidl::encoding::Depth,
669        ) -> fidl::Result<()> {
670            encoder.debug_check_bounds::<RealmFactoryCreateRealmRequest>(offset);
671            // Zero out padding regions. There's no need to apply masks
672            // because the unmasked parts will be overwritten by fields.
673            unsafe {
674                let ptr = encoder.buf.as_mut_ptr().add(offset).offset(16);
675                (ptr as *mut u64).write_unaligned(0);
676            }
677            // Write the fields.
678            self.0.encode(encoder, offset + 0, depth)?;
679            self.1.encode(encoder, offset + 16, depth)?;
680            Ok(())
681        }
682    }
683
684    impl fidl::encoding::Decode<Self, fidl::encoding::DefaultFuchsiaResourceDialect>
685        for RealmFactoryCreateRealmRequest
686    {
687        #[inline(always)]
688        fn new_empty() -> Self {
689            Self {
690                options: fidl::new_empty!(
691                    RealmOptions,
692                    fidl::encoding::DefaultFuchsiaResourceDialect
693                ),
694                dictionary: fidl::new_empty!(
695                    fidl::encoding::Endpoint<
696                        fidl::endpoints::ServerEnd<
697                            fidl_fuchsia_component_sandbox::DictionaryMarker,
698                        >,
699                    >,
700                    fidl::encoding::DefaultFuchsiaResourceDialect
701                ),
702            }
703        }
704
705        #[inline]
706        unsafe fn decode(
707            &mut self,
708            decoder: &mut fidl::encoding::Decoder<
709                '_,
710                fidl::encoding::DefaultFuchsiaResourceDialect,
711            >,
712            offset: usize,
713            _depth: fidl::encoding::Depth,
714        ) -> fidl::Result<()> {
715            decoder.debug_check_bounds::<Self>(offset);
716            // Verify that padding bytes are zero.
717            let ptr = unsafe { decoder.buf.as_ptr().add(offset).offset(16) };
718            let padval = unsafe { (ptr as *const u64).read_unaligned() };
719            let mask = 0xffffffff00000000u64;
720            let maskedval = padval & mask;
721            if maskedval != 0 {
722                return Err(fidl::Error::NonZeroPadding {
723                    padding_start: offset + 16 + ((mask as u64).trailing_zeros() / 8) as usize,
724                });
725            }
726            fidl::decode!(
727                RealmOptions,
728                fidl::encoding::DefaultFuchsiaResourceDialect,
729                &mut self.options,
730                decoder,
731                offset + 0,
732                _depth
733            )?;
734            fidl::decode!(
735                fidl::encoding::Endpoint<
736                    fidl::endpoints::ServerEnd<fidl_fuchsia_component_sandbox::DictionaryMarker>,
737                >,
738                fidl::encoding::DefaultFuchsiaResourceDialect,
739                &mut self.dictionary,
740                decoder,
741                offset + 16,
742                _depth
743            )?;
744            Ok(())
745        }
746    }
747
748    impl RealmOptions {
749        #[inline(always)]
750        fn max_ordinal_present(&self) -> u64 {
751            if let Some(_) = self.test_archivist_name {
752                return 4;
753            }
754            if let Some(_) = self.fake_cobalt_name {
755                return 3;
756            }
757            if let Some(_) = self.single_counter_name {
758                return 2;
759            }
760            if let Some(_) = self.sampler_component_name {
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                fidl::encoding::UnboundedString,
834                fidl::encoding::DefaultFuchsiaResourceDialect,
835            >(
836                self.sampler_component_name.as_ref().map(
837                    <fidl::encoding::UnboundedString as fidl::encoding::ValueTypeMarker>::borrow,
838                ),
839                encoder,
840                offset + cur_offset,
841                depth,
842            )?;
843
844            _prev_end_offset = cur_offset + envelope_size;
845            if 2 > max_ordinal {
846                return Ok(());
847            }
848
849            // Write at offset+(ordinal-1)*envelope_size, since ordinals are one-based and envelopes
850            // are envelope_size bytes.
851            let cur_offset: usize = (2 - 1) * envelope_size;
852
853            // Zero reserved fields.
854            encoder.padding(offset + _prev_end_offset, cur_offset - _prev_end_offset);
855
856            // Safety:
857            // - bytes_len is calculated to fit envelope_size*max(member.ordinal).
858            // - Since cur_offset is envelope_size*(member.ordinal - 1) and the envelope takes
859            //   envelope_size bytes, there is always sufficient room.
860            fidl::encoding::encode_in_envelope_optional::<
861                fidl::encoding::UnboundedString,
862                fidl::encoding::DefaultFuchsiaResourceDialect,
863            >(
864                self.single_counter_name.as_ref().map(
865                    <fidl::encoding::UnboundedString as fidl::encoding::ValueTypeMarker>::borrow,
866                ),
867                encoder,
868                offset + cur_offset,
869                depth,
870            )?;
871
872            _prev_end_offset = cur_offset + envelope_size;
873            if 3 > max_ordinal {
874                return Ok(());
875            }
876
877            // Write at offset+(ordinal-1)*envelope_size, since ordinals are one-based and envelopes
878            // are envelope_size bytes.
879            let cur_offset: usize = (3 - 1) * envelope_size;
880
881            // Zero reserved fields.
882            encoder.padding(offset + _prev_end_offset, cur_offset - _prev_end_offset);
883
884            // Safety:
885            // - bytes_len is calculated to fit envelope_size*max(member.ordinal).
886            // - Since cur_offset is envelope_size*(member.ordinal - 1) and the envelope takes
887            //   envelope_size bytes, there is always sufficient room.
888            fidl::encoding::encode_in_envelope_optional::<
889                fidl::encoding::UnboundedString,
890                fidl::encoding::DefaultFuchsiaResourceDialect,
891            >(
892                self.fake_cobalt_name.as_ref().map(
893                    <fidl::encoding::UnboundedString as fidl::encoding::ValueTypeMarker>::borrow,
894                ),
895                encoder,
896                offset + cur_offset,
897                depth,
898            )?;
899
900            _prev_end_offset = cur_offset + envelope_size;
901            if 4 > max_ordinal {
902                return Ok(());
903            }
904
905            // Write at offset+(ordinal-1)*envelope_size, since ordinals are one-based and envelopes
906            // are envelope_size bytes.
907            let cur_offset: usize = (4 - 1) * envelope_size;
908
909            // Zero reserved fields.
910            encoder.padding(offset + _prev_end_offset, cur_offset - _prev_end_offset);
911
912            // Safety:
913            // - bytes_len is calculated to fit envelope_size*max(member.ordinal).
914            // - Since cur_offset is envelope_size*(member.ordinal - 1) and the envelope takes
915            //   envelope_size bytes, there is always sufficient room.
916            fidl::encoding::encode_in_envelope_optional::<
917                fidl::encoding::UnboundedString,
918                fidl::encoding::DefaultFuchsiaResourceDialect,
919            >(
920                self.test_archivist_name.as_ref().map(
921                    <fidl::encoding::UnboundedString as fidl::encoding::ValueTypeMarker>::borrow,
922                ),
923                encoder,
924                offset + cur_offset,
925                depth,
926            )?;
927
928            _prev_end_offset = cur_offset + envelope_size;
929
930            Ok(())
931        }
932    }
933
934    impl fidl::encoding::Decode<Self, fidl::encoding::DefaultFuchsiaResourceDialect> for RealmOptions {
935        #[inline(always)]
936        fn new_empty() -> Self {
937            Self::default()
938        }
939
940        unsafe fn decode(
941            &mut self,
942            decoder: &mut fidl::encoding::Decoder<
943                '_,
944                fidl::encoding::DefaultFuchsiaResourceDialect,
945            >,
946            offset: usize,
947            mut depth: fidl::encoding::Depth,
948        ) -> fidl::Result<()> {
949            decoder.debug_check_bounds::<Self>(offset);
950            let len = match fidl::encoding::decode_vector_header(decoder, offset)? {
951                None => return Err(fidl::Error::NotNullable),
952                Some(len) => len,
953            };
954            // Calling decoder.out_of_line_offset(0) is not allowed.
955            if len == 0 {
956                return Ok(());
957            };
958            depth.increment()?;
959            let envelope_size = 8;
960            let bytes_len = len * envelope_size;
961            let offset = decoder.out_of_line_offset(bytes_len)?;
962            // Decode the envelope for each type.
963            let mut _next_ordinal_to_read = 0;
964            let mut next_offset = offset;
965            let end_offset = offset + bytes_len;
966            _next_ordinal_to_read += 1;
967            if next_offset >= end_offset {
968                return Ok(());
969            }
970
971            // Decode unknown envelopes for gaps in ordinals.
972            while _next_ordinal_to_read < 1 {
973                fidl::encoding::decode_unknown_envelope(decoder, next_offset, depth)?;
974                _next_ordinal_to_read += 1;
975                next_offset += envelope_size;
976            }
977
978            let next_out_of_line = decoder.next_out_of_line();
979            let handles_before = decoder.remaining_handles();
980            if let Some((inlined, num_bytes, num_handles)) =
981                fidl::encoding::decode_envelope_header(decoder, next_offset)?
982            {
983                let member_inline_size =
984                    <fidl::encoding::UnboundedString as fidl::encoding::TypeMarker>::inline_size(
985                        decoder.context,
986                    );
987                if inlined != (member_inline_size <= 4) {
988                    return Err(fidl::Error::InvalidInlineBitInEnvelope);
989                }
990                let inner_offset;
991                let mut inner_depth = depth.clone();
992                if inlined {
993                    decoder.check_inline_envelope_padding(next_offset, member_inline_size)?;
994                    inner_offset = next_offset;
995                } else {
996                    inner_offset = decoder.out_of_line_offset(member_inline_size)?;
997                    inner_depth.increment()?;
998                }
999                let val_ref = self.sampler_component_name.get_or_insert_with(|| {
1000                    fidl::new_empty!(
1001                        fidl::encoding::UnboundedString,
1002                        fidl::encoding::DefaultFuchsiaResourceDialect
1003                    )
1004                });
1005                fidl::decode!(
1006                    fidl::encoding::UnboundedString,
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            _next_ordinal_to_read += 1;
1024            if next_offset >= end_offset {
1025                return Ok(());
1026            }
1027
1028            // Decode unknown envelopes for gaps in ordinals.
1029            while _next_ordinal_to_read < 2 {
1030                fidl::encoding::decode_unknown_envelope(decoder, next_offset, depth)?;
1031                _next_ordinal_to_read += 1;
1032                next_offset += envelope_size;
1033            }
1034
1035            let next_out_of_line = decoder.next_out_of_line();
1036            let handles_before = decoder.remaining_handles();
1037            if let Some((inlined, num_bytes, num_handles)) =
1038                fidl::encoding::decode_envelope_header(decoder, next_offset)?
1039            {
1040                let member_inline_size =
1041                    <fidl::encoding::UnboundedString as fidl::encoding::TypeMarker>::inline_size(
1042                        decoder.context,
1043                    );
1044                if inlined != (member_inline_size <= 4) {
1045                    return Err(fidl::Error::InvalidInlineBitInEnvelope);
1046                }
1047                let inner_offset;
1048                let mut inner_depth = depth.clone();
1049                if inlined {
1050                    decoder.check_inline_envelope_padding(next_offset, member_inline_size)?;
1051                    inner_offset = next_offset;
1052                } else {
1053                    inner_offset = decoder.out_of_line_offset(member_inline_size)?;
1054                    inner_depth.increment()?;
1055                }
1056                let val_ref = self.single_counter_name.get_or_insert_with(|| {
1057                    fidl::new_empty!(
1058                        fidl::encoding::UnboundedString,
1059                        fidl::encoding::DefaultFuchsiaResourceDialect
1060                    )
1061                });
1062                fidl::decode!(
1063                    fidl::encoding::UnboundedString,
1064                    fidl::encoding::DefaultFuchsiaResourceDialect,
1065                    val_ref,
1066                    decoder,
1067                    inner_offset,
1068                    inner_depth
1069                )?;
1070                if !inlined && decoder.next_out_of_line() != next_out_of_line + (num_bytes as usize)
1071                {
1072                    return Err(fidl::Error::InvalidNumBytesInEnvelope);
1073                }
1074                if handles_before != decoder.remaining_handles() + (num_handles as usize) {
1075                    return Err(fidl::Error::InvalidNumHandlesInEnvelope);
1076                }
1077            }
1078
1079            next_offset += envelope_size;
1080            _next_ordinal_to_read += 1;
1081            if next_offset >= end_offset {
1082                return Ok(());
1083            }
1084
1085            // Decode unknown envelopes for gaps in ordinals.
1086            while _next_ordinal_to_read < 3 {
1087                fidl::encoding::decode_unknown_envelope(decoder, next_offset, depth)?;
1088                _next_ordinal_to_read += 1;
1089                next_offset += envelope_size;
1090            }
1091
1092            let next_out_of_line = decoder.next_out_of_line();
1093            let handles_before = decoder.remaining_handles();
1094            if let Some((inlined, num_bytes, num_handles)) =
1095                fidl::encoding::decode_envelope_header(decoder, next_offset)?
1096            {
1097                let member_inline_size =
1098                    <fidl::encoding::UnboundedString as fidl::encoding::TypeMarker>::inline_size(
1099                        decoder.context,
1100                    );
1101                if inlined != (member_inline_size <= 4) {
1102                    return Err(fidl::Error::InvalidInlineBitInEnvelope);
1103                }
1104                let inner_offset;
1105                let mut inner_depth = depth.clone();
1106                if inlined {
1107                    decoder.check_inline_envelope_padding(next_offset, member_inline_size)?;
1108                    inner_offset = next_offset;
1109                } else {
1110                    inner_offset = decoder.out_of_line_offset(member_inline_size)?;
1111                    inner_depth.increment()?;
1112                }
1113                let val_ref = self.fake_cobalt_name.get_or_insert_with(|| {
1114                    fidl::new_empty!(
1115                        fidl::encoding::UnboundedString,
1116                        fidl::encoding::DefaultFuchsiaResourceDialect
1117                    )
1118                });
1119                fidl::decode!(
1120                    fidl::encoding::UnboundedString,
1121                    fidl::encoding::DefaultFuchsiaResourceDialect,
1122                    val_ref,
1123                    decoder,
1124                    inner_offset,
1125                    inner_depth
1126                )?;
1127                if !inlined && decoder.next_out_of_line() != next_out_of_line + (num_bytes as usize)
1128                {
1129                    return Err(fidl::Error::InvalidNumBytesInEnvelope);
1130                }
1131                if handles_before != decoder.remaining_handles() + (num_handles as usize) {
1132                    return Err(fidl::Error::InvalidNumHandlesInEnvelope);
1133                }
1134            }
1135
1136            next_offset += envelope_size;
1137            _next_ordinal_to_read += 1;
1138            if next_offset >= end_offset {
1139                return Ok(());
1140            }
1141
1142            // Decode unknown envelopes for gaps in ordinals.
1143            while _next_ordinal_to_read < 4 {
1144                fidl::encoding::decode_unknown_envelope(decoder, next_offset, depth)?;
1145                _next_ordinal_to_read += 1;
1146                next_offset += envelope_size;
1147            }
1148
1149            let next_out_of_line = decoder.next_out_of_line();
1150            let handles_before = decoder.remaining_handles();
1151            if let Some((inlined, num_bytes, num_handles)) =
1152                fidl::encoding::decode_envelope_header(decoder, next_offset)?
1153            {
1154                let member_inline_size =
1155                    <fidl::encoding::UnboundedString as fidl::encoding::TypeMarker>::inline_size(
1156                        decoder.context,
1157                    );
1158                if inlined != (member_inline_size <= 4) {
1159                    return Err(fidl::Error::InvalidInlineBitInEnvelope);
1160                }
1161                let inner_offset;
1162                let mut inner_depth = depth.clone();
1163                if inlined {
1164                    decoder.check_inline_envelope_padding(next_offset, member_inline_size)?;
1165                    inner_offset = next_offset;
1166                } else {
1167                    inner_offset = decoder.out_of_line_offset(member_inline_size)?;
1168                    inner_depth.increment()?;
1169                }
1170                let val_ref = self.test_archivist_name.get_or_insert_with(|| {
1171                    fidl::new_empty!(
1172                        fidl::encoding::UnboundedString,
1173                        fidl::encoding::DefaultFuchsiaResourceDialect
1174                    )
1175                });
1176                fidl::decode!(
1177                    fidl::encoding::UnboundedString,
1178                    fidl::encoding::DefaultFuchsiaResourceDialect,
1179                    val_ref,
1180                    decoder,
1181                    inner_offset,
1182                    inner_depth
1183                )?;
1184                if !inlined && decoder.next_out_of_line() != next_out_of_line + (num_bytes as usize)
1185                {
1186                    return Err(fidl::Error::InvalidNumBytesInEnvelope);
1187                }
1188                if handles_before != decoder.remaining_handles() + (num_handles as usize) {
1189                    return Err(fidl::Error::InvalidNumHandlesInEnvelope);
1190                }
1191            }
1192
1193            next_offset += envelope_size;
1194
1195            // Decode the remaining unknown envelopes.
1196            while next_offset < end_offset {
1197                _next_ordinal_to_read += 1;
1198                fidl::encoding::decode_unknown_envelope(decoder, next_offset, depth)?;
1199                next_offset += envelope_size;
1200            }
1201
1202            Ok(())
1203        }
1204    }
1205}