Skip to main content

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