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