Skip to main content

fidl_fuchsia_ui_test_scene/
fidl_fuchsia_ui_test_scene.rs

1// WARNING: This file is machine generated by fidlgen.
2
3#![warn(clippy::all)]
4#![allow(unused_parens, unused_mut, unused_imports, nonstandard_style)]
5
6use bitflags::bitflags;
7use fidl::client::QueryResponseFut;
8use fidl::encoding::{MessageBufFor, ProxyChannelBox, ResourceDialect};
9use fidl::endpoints::{ControlHandle as _, Responder as _};
10pub use fidl_fuchsia_ui_test_scene_common::*;
11use futures::future::{self, MaybeDone, TryFutureExt};
12use zx_status;
13
14#[derive(Debug, Eq, Hash, Ord, PartialEq, PartialOrd)]
15pub struct ControllerRegisterViewTreeWatcherRequest {
16    pub watcher:
17        fidl::endpoints::ServerEnd<fidl_fuchsia_ui_observation_geometry::ViewTreeWatcherMarker>,
18}
19
20impl fidl::Standalone<fidl::encoding::DefaultFuchsiaResourceDialect>
21    for ControllerRegisterViewTreeWatcherRequest
22{
23}
24
25#[derive(Debug, Default, PartialEq)]
26pub struct ControllerAttachClientViewRequest {
27    pub view_provider: Option<fidl::endpoints::ClientEnd<fidl_fuchsia_ui_app::ViewProviderMarker>>,
28    #[doc(hidden)]
29    pub __source_breaking: fidl::marker::SourceBreaking,
30}
31
32impl fidl::Standalone<fidl::encoding::DefaultFuchsiaResourceDialect>
33    for ControllerAttachClientViewRequest
34{
35}
36
37#[derive(Debug, Default, PartialEq)]
38pub struct ControllerPresentClientViewRequest {
39    pub viewport_creation_token: Option<fidl_fuchsia_ui_views::ViewportCreationToken>,
40    #[doc(hidden)]
41    pub __source_breaking: fidl::marker::SourceBreaking,
42}
43
44impl fidl::Standalone<fidl::encoding::DefaultFuchsiaResourceDialect>
45    for ControllerPresentClientViewRequest
46{
47}
48
49#[derive(Debug, Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Hash)]
50pub struct ControllerMarker;
51
52impl fidl::endpoints::ProtocolMarker for ControllerMarker {
53    type Proxy = ControllerProxy;
54    type RequestStream = ControllerRequestStream;
55    #[cfg(target_os = "fuchsia")]
56    type SynchronousProxy = ControllerSynchronousProxy;
57
58    const DEBUG_NAME: &'static str = "fuchsia.ui.test.scene.Controller";
59}
60impl fidl::endpoints::DiscoverableProtocolMarker for ControllerMarker {}
61
62pub trait ControllerProxyInterface: Send + Sync {
63    type AttachClientViewResponseFut: std::future::Future<Output = Result<u64, fidl::Error>> + Send;
64    fn r#attach_client_view(
65        &self,
66        payload: ControllerAttachClientViewRequest,
67    ) -> Self::AttachClientViewResponseFut;
68    fn r#present_client_view(
69        &self,
70        payload: ControllerPresentClientViewRequest,
71    ) -> Result<(), fidl::Error>;
72    type RegisterViewTreeWatcherResponseFut: std::future::Future<Output = Result<(), fidl::Error>>
73        + Send;
74    fn r#register_view_tree_watcher(
75        &self,
76        watcher: fidl::endpoints::ServerEnd<
77            fidl_fuchsia_ui_observation_geometry::ViewTreeWatcherMarker,
78        >,
79    ) -> Self::RegisterViewTreeWatcherResponseFut;
80    type WatchViewPresentationResponseFut: std::future::Future<Output = Result<(), fidl::Error>>
81        + Send;
82    fn r#watch_view_presentation(&self) -> Self::WatchViewPresentationResponseFut;
83}
84#[derive(Debug)]
85#[cfg(target_os = "fuchsia")]
86pub struct ControllerSynchronousProxy {
87    client: fidl::client::sync::Client,
88}
89
90#[cfg(target_os = "fuchsia")]
91impl fidl::endpoints::SynchronousProxy for ControllerSynchronousProxy {
92    type Proxy = ControllerProxy;
93    type Protocol = ControllerMarker;
94
95    fn from_channel(inner: fidl::Channel) -> Self {
96        Self::new(inner)
97    }
98
99    fn into_channel(self) -> fidl::Channel {
100        self.client.into_channel()
101    }
102
103    fn as_channel(&self) -> &fidl::Channel {
104        self.client.as_channel()
105    }
106}
107
108#[cfg(target_os = "fuchsia")]
109impl ControllerSynchronousProxy {
110    pub fn new(channel: fidl::Channel) -> Self {
111        Self { client: fidl::client::sync::Client::new(channel) }
112    }
113
114    pub fn into_channel(self) -> fidl::Channel {
115        self.client.into_channel()
116    }
117
118    /// Waits until an event arrives and returns it. It is safe for other
119    /// threads to make concurrent requests while waiting for an event.
120    pub fn wait_for_event(
121        &self,
122        deadline: zx::MonotonicInstant,
123    ) -> Result<ControllerEvent, fidl::Error> {
124        ControllerEvent::decode(self.client.wait_for_event::<ControllerMarker>(deadline)?)
125    }
126
127    /// *** NOTE: `ViewProvider` is no longer the preferred way for a parent
128    /// and child view to agree on a ViewportCreationToken / ViewCreationToken
129    /// pair. Flatland-based clients are encouraged to use `PresentView` (below)
130    /// instead of `AttachClientView`.
131    ///
132    /// Elicits the server to request a view using the
133    /// `fuchsia.ui.app.ViewProvider` handle provided, and attach it to the
134    /// scene.
135    ///
136    /// RETURN VALUE
137    ///
138    /// This method returns the KOID for the client view's `ViewRef`.
139    ///
140    /// SYNCHRONIZATION
141    ///
142    /// This call returns as soon as the client `ViewRef` is available. Note
143    /// that this signal does NOT necessarily indicate that the view has been
144    /// attached to the scene.
145    ///
146    /// LIFE CYCLE
147    ///
148    /// Clients may drop the `Controller` connection once `AttachClientView` has
149    /// returned.
150    pub fn r#attach_client_view(
151        &self,
152        mut payload: ControllerAttachClientViewRequest,
153        ___deadline: zx::MonotonicInstant,
154    ) -> Result<u64, fidl::Error> {
155        let _response = self.client.send_query::<
156            ControllerAttachClientViewRequest,
157            ControllerAttachClientViewResponse,
158            ControllerMarker,
159        >(
160            &mut payload,
161            0x271d621cc0687761,
162            fidl::encoding::DynamicFlags::empty(),
163            ___deadline,
164        )?;
165        Ok(_response.view_ref_koid)
166    }
167
168    /// Elicits the server to create a viewport using `viewport_creation_token`.
169    ///
170    /// LIFE CYCLE
171    ///
172    /// Clients may drop the `Controller` connection once `PresentClientView` has
173    /// returned.
174    pub fn r#present_client_view(
175        &self,
176        mut payload: ControllerPresentClientViewRequest,
177    ) -> Result<(), fidl::Error> {
178        self.client.send::<ControllerPresentClientViewRequest>(
179            &mut payload,
180            0x50b3378ecc810ca9,
181            fidl::encoding::DynamicFlags::empty(),
182        )
183    }
184
185    /// Registers a `ViewTreeWatcher` on the client's behalf.
186    ///
187    /// The `ViewTreeWatcher` registered on behalf of the client will currently
188    /// be scoped globally; we intend to restrict the scope to the client view's
189    /// subtree as soon as it's feasible to do so.
190    ///
191    /// For more information on geometry observation, see the documentation
192    /// in //sdk/fidl/fuchsia.ui.observation.geometry/watcher.fidl.
193    pub fn r#register_view_tree_watcher(
194        &self,
195        mut watcher: fidl::endpoints::ServerEnd<
196            fidl_fuchsia_ui_observation_geometry::ViewTreeWatcherMarker,
197        >,
198        ___deadline: zx::MonotonicInstant,
199    ) -> Result<(), fidl::Error> {
200        let _response = self.client.send_query::<
201            ControllerRegisterViewTreeWatcherRequest,
202            fidl::encoding::EmptyPayload,
203            ControllerMarker,
204        >(
205            (watcher,),
206            0x1370345f4914064,
207            fidl::encoding::DynamicFlags::empty(),
208            ___deadline,
209        )?;
210        Ok(_response)
211    }
212
213    /// A hanging get to watch for updates to view presentation.
214    ///
215    /// Callers can use this method to wait until a `ClientView` has
216    /// `Present()`-ed through any of the following view presentation methods:
217    ///   * `fuchsia.ui.test.scene.Controller/AttachClientView()`
218    ///   * `fuchsia.ui.test.scene.Controller/PresentClientView()`
219    ///   * `fuchsia.element.GraphicalPresenter/PresentView()`
220    ///
221    /// Callers should expect to call this method once for each view they
222    /// expect to wait for.
223    ///
224    /// Note that callers must take care when interleaving calls, since
225    /// this method has no way to
226    ///   a) associate a `Present()` with a specific `ClientView`, or
227    ///   b) associate a `Present()` with an `AttachClientView()` call, rather
228    ///    than a `PresentClientView()` or `PresentView` call.
229    ///
230    /// It is invalid to call `WatchViewPresentation` while a previous call is
231    /// still pending; subsequent requests will be ignored.
232    pub fn r#watch_view_presentation(
233        &self,
234        ___deadline: zx::MonotonicInstant,
235    ) -> Result<(), fidl::Error> {
236        let _response = self.client.send_query::<
237            fidl::encoding::EmptyPayload,
238            fidl::encoding::EmptyPayload,
239            ControllerMarker,
240        >(
241            (),
242            0x15439375bfe6d21d,
243            fidl::encoding::DynamicFlags::empty(),
244            ___deadline,
245        )?;
246        Ok(_response)
247    }
248}
249
250#[cfg(target_os = "fuchsia")]
251impl From<ControllerSynchronousProxy> for zx::NullableHandle {
252    fn from(value: ControllerSynchronousProxy) -> Self {
253        value.into_channel().into()
254    }
255}
256
257#[cfg(target_os = "fuchsia")]
258impl From<fidl::Channel> for ControllerSynchronousProxy {
259    fn from(value: fidl::Channel) -> Self {
260        Self::new(value)
261    }
262}
263
264#[cfg(target_os = "fuchsia")]
265impl fidl::endpoints::FromClient for ControllerSynchronousProxy {
266    type Protocol = ControllerMarker;
267
268    fn from_client(value: fidl::endpoints::ClientEnd<ControllerMarker>) -> Self {
269        Self::new(value.into_channel())
270    }
271}
272
273#[derive(Debug, Clone)]
274pub struct ControllerProxy {
275    client: fidl::client::Client<fidl::encoding::DefaultFuchsiaResourceDialect>,
276}
277
278impl fidl::endpoints::Proxy for ControllerProxy {
279    type Protocol = ControllerMarker;
280
281    fn from_channel(inner: ::fidl::AsyncChannel) -> Self {
282        Self::new(inner)
283    }
284
285    fn into_channel(self) -> Result<::fidl::AsyncChannel, Self> {
286        self.client.into_channel().map_err(|client| Self { client })
287    }
288
289    fn as_channel(&self) -> &::fidl::AsyncChannel {
290        self.client.as_channel()
291    }
292}
293
294impl ControllerProxy {
295    /// Create a new Proxy for fuchsia.ui.test.scene/Controller.
296    pub fn new(channel: ::fidl::AsyncChannel) -> Self {
297        let protocol_name = <ControllerMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME;
298        Self { client: fidl::client::Client::new(channel, protocol_name) }
299    }
300
301    /// Get a Stream of events from the remote end of the protocol.
302    ///
303    /// # Panics
304    ///
305    /// Panics if the event stream was already taken.
306    pub fn take_event_stream(&self) -> ControllerEventStream {
307        ControllerEventStream { event_receiver: self.client.take_event_receiver() }
308    }
309
310    /// *** NOTE: `ViewProvider` is no longer the preferred way for a parent
311    /// and child view to agree on a ViewportCreationToken / ViewCreationToken
312    /// pair. Flatland-based clients are encouraged to use `PresentView` (below)
313    /// instead of `AttachClientView`.
314    ///
315    /// Elicits the server to request a view using the
316    /// `fuchsia.ui.app.ViewProvider` handle provided, and attach it to the
317    /// scene.
318    ///
319    /// RETURN VALUE
320    ///
321    /// This method returns the KOID for the client view's `ViewRef`.
322    ///
323    /// SYNCHRONIZATION
324    ///
325    /// This call returns as soon as the client `ViewRef` is available. Note
326    /// that this signal does NOT necessarily indicate that the view has been
327    /// attached to the scene.
328    ///
329    /// LIFE CYCLE
330    ///
331    /// Clients may drop the `Controller` connection once `AttachClientView` has
332    /// returned.
333    pub fn r#attach_client_view(
334        &self,
335        mut payload: ControllerAttachClientViewRequest,
336    ) -> fidl::client::QueryResponseFut<u64, fidl::encoding::DefaultFuchsiaResourceDialect> {
337        ControllerProxyInterface::r#attach_client_view(self, payload)
338    }
339
340    /// Elicits the server to create a viewport using `viewport_creation_token`.
341    ///
342    /// LIFE CYCLE
343    ///
344    /// Clients may drop the `Controller` connection once `PresentClientView` has
345    /// returned.
346    pub fn r#present_client_view(
347        &self,
348        mut payload: ControllerPresentClientViewRequest,
349    ) -> Result<(), fidl::Error> {
350        ControllerProxyInterface::r#present_client_view(self, payload)
351    }
352
353    /// Registers a `ViewTreeWatcher` on the client's behalf.
354    ///
355    /// The `ViewTreeWatcher` registered on behalf of the client will currently
356    /// be scoped globally; we intend to restrict the scope to the client view's
357    /// subtree as soon as it's feasible to do so.
358    ///
359    /// For more information on geometry observation, see the documentation
360    /// in //sdk/fidl/fuchsia.ui.observation.geometry/watcher.fidl.
361    pub fn r#register_view_tree_watcher(
362        &self,
363        mut watcher: fidl::endpoints::ServerEnd<
364            fidl_fuchsia_ui_observation_geometry::ViewTreeWatcherMarker,
365        >,
366    ) -> fidl::client::QueryResponseFut<(), fidl::encoding::DefaultFuchsiaResourceDialect> {
367        ControllerProxyInterface::r#register_view_tree_watcher(self, watcher)
368    }
369
370    /// A hanging get to watch for updates to view presentation.
371    ///
372    /// Callers can use this method to wait until a `ClientView` has
373    /// `Present()`-ed through any of the following view presentation methods:
374    ///   * `fuchsia.ui.test.scene.Controller/AttachClientView()`
375    ///   * `fuchsia.ui.test.scene.Controller/PresentClientView()`
376    ///   * `fuchsia.element.GraphicalPresenter/PresentView()`
377    ///
378    /// Callers should expect to call this method once for each view they
379    /// expect to wait for.
380    ///
381    /// Note that callers must take care when interleaving calls, since
382    /// this method has no way to
383    ///   a) associate a `Present()` with a specific `ClientView`, or
384    ///   b) associate a `Present()` with an `AttachClientView()` call, rather
385    ///    than a `PresentClientView()` or `PresentView` call.
386    ///
387    /// It is invalid to call `WatchViewPresentation` while a previous call is
388    /// still pending; subsequent requests will be ignored.
389    pub fn r#watch_view_presentation(
390        &self,
391    ) -> fidl::client::QueryResponseFut<(), fidl::encoding::DefaultFuchsiaResourceDialect> {
392        ControllerProxyInterface::r#watch_view_presentation(self)
393    }
394}
395
396impl ControllerProxyInterface for ControllerProxy {
397    type AttachClientViewResponseFut =
398        fidl::client::QueryResponseFut<u64, fidl::encoding::DefaultFuchsiaResourceDialect>;
399    fn r#attach_client_view(
400        &self,
401        mut payload: ControllerAttachClientViewRequest,
402    ) -> Self::AttachClientViewResponseFut {
403        fn _decode(
404            mut _buf: Result<<fidl::encoding::DefaultFuchsiaResourceDialect as fidl::encoding::ResourceDialect>::MessageBufEtc, fidl::Error>,
405        ) -> Result<u64, fidl::Error> {
406            let _response = fidl::client::decode_transaction_body::<
407                ControllerAttachClientViewResponse,
408                fidl::encoding::DefaultFuchsiaResourceDialect,
409                0x271d621cc0687761,
410            >(_buf?)?;
411            Ok(_response.view_ref_koid)
412        }
413        self.client.send_query_and_decode::<ControllerAttachClientViewRequest, u64>(
414            &mut payload,
415            0x271d621cc0687761,
416            fidl::encoding::DynamicFlags::empty(),
417            _decode,
418        )
419    }
420
421    fn r#present_client_view(
422        &self,
423        mut payload: ControllerPresentClientViewRequest,
424    ) -> Result<(), fidl::Error> {
425        self.client.send::<ControllerPresentClientViewRequest>(
426            &mut payload,
427            0x50b3378ecc810ca9,
428            fidl::encoding::DynamicFlags::empty(),
429        )
430    }
431
432    type RegisterViewTreeWatcherResponseFut =
433        fidl::client::QueryResponseFut<(), fidl::encoding::DefaultFuchsiaResourceDialect>;
434    fn r#register_view_tree_watcher(
435        &self,
436        mut watcher: fidl::endpoints::ServerEnd<
437            fidl_fuchsia_ui_observation_geometry::ViewTreeWatcherMarker,
438        >,
439    ) -> Self::RegisterViewTreeWatcherResponseFut {
440        fn _decode(
441            mut _buf: Result<<fidl::encoding::DefaultFuchsiaResourceDialect as fidl::encoding::ResourceDialect>::MessageBufEtc, fidl::Error>,
442        ) -> Result<(), fidl::Error> {
443            let _response = fidl::client::decode_transaction_body::<
444                fidl::encoding::EmptyPayload,
445                fidl::encoding::DefaultFuchsiaResourceDialect,
446                0x1370345f4914064,
447            >(_buf?)?;
448            Ok(_response)
449        }
450        self.client.send_query_and_decode::<ControllerRegisterViewTreeWatcherRequest, ()>(
451            (watcher,),
452            0x1370345f4914064,
453            fidl::encoding::DynamicFlags::empty(),
454            _decode,
455        )
456    }
457
458    type WatchViewPresentationResponseFut =
459        fidl::client::QueryResponseFut<(), fidl::encoding::DefaultFuchsiaResourceDialect>;
460    fn r#watch_view_presentation(&self) -> Self::WatchViewPresentationResponseFut {
461        fn _decode(
462            mut _buf: Result<<fidl::encoding::DefaultFuchsiaResourceDialect as fidl::encoding::ResourceDialect>::MessageBufEtc, fidl::Error>,
463        ) -> Result<(), fidl::Error> {
464            let _response = fidl::client::decode_transaction_body::<
465                fidl::encoding::EmptyPayload,
466                fidl::encoding::DefaultFuchsiaResourceDialect,
467                0x15439375bfe6d21d,
468            >(_buf?)?;
469            Ok(_response)
470        }
471        self.client.send_query_and_decode::<fidl::encoding::EmptyPayload, ()>(
472            (),
473            0x15439375bfe6d21d,
474            fidl::encoding::DynamicFlags::empty(),
475            _decode,
476        )
477    }
478}
479
480pub struct ControllerEventStream {
481    event_receiver: fidl::client::EventReceiver<fidl::encoding::DefaultFuchsiaResourceDialect>,
482}
483
484impl std::marker::Unpin for ControllerEventStream {}
485
486impl futures::stream::FusedStream for ControllerEventStream {
487    fn is_terminated(&self) -> bool {
488        self.event_receiver.is_terminated()
489    }
490}
491
492impl futures::Stream for ControllerEventStream {
493    type Item = Result<ControllerEvent, fidl::Error>;
494
495    fn poll_next(
496        mut self: std::pin::Pin<&mut Self>,
497        cx: &mut std::task::Context<'_>,
498    ) -> std::task::Poll<Option<Self::Item>> {
499        match futures::ready!(futures::stream::StreamExt::poll_next_unpin(
500            &mut self.event_receiver,
501            cx
502        )?) {
503            Some(buf) => std::task::Poll::Ready(Some(ControllerEvent::decode(buf))),
504            None => std::task::Poll::Ready(None),
505        }
506    }
507}
508
509#[derive(Debug)]
510pub enum ControllerEvent {}
511
512impl ControllerEvent {
513    /// Decodes a message buffer as a [`ControllerEvent`].
514    fn decode(
515        mut buf: <fidl::encoding::DefaultFuchsiaResourceDialect as fidl::encoding::ResourceDialect>::MessageBufEtc,
516    ) -> Result<ControllerEvent, fidl::Error> {
517        let (bytes, _handles) = buf.split_mut();
518        let (tx_header, _body_bytes) = fidl::encoding::decode_transaction_header(bytes)?;
519        debug_assert_eq!(tx_header.tx_id, 0);
520        match tx_header.ordinal {
521            _ => Err(fidl::Error::UnknownOrdinal {
522                ordinal: tx_header.ordinal,
523                protocol_name: <ControllerMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME,
524            }),
525        }
526    }
527}
528
529/// A Stream of incoming requests for fuchsia.ui.test.scene/Controller.
530pub struct ControllerRequestStream {
531    inner: std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>,
532    is_terminated: bool,
533}
534
535impl std::marker::Unpin for ControllerRequestStream {}
536
537impl futures::stream::FusedStream for ControllerRequestStream {
538    fn is_terminated(&self) -> bool {
539        self.is_terminated
540    }
541}
542
543impl fidl::endpoints::RequestStream for ControllerRequestStream {
544    type Protocol = ControllerMarker;
545    type ControlHandle = ControllerControlHandle;
546
547    fn from_channel(channel: ::fidl::AsyncChannel) -> Self {
548        Self { inner: std::sync::Arc::new(fidl::ServeInner::new(channel)), is_terminated: false }
549    }
550
551    fn control_handle(&self) -> Self::ControlHandle {
552        ControllerControlHandle { inner: self.inner.clone() }
553    }
554
555    fn into_inner(
556        self,
557    ) -> (::std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>, bool)
558    {
559        (self.inner, self.is_terminated)
560    }
561
562    fn from_inner(
563        inner: std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>,
564        is_terminated: bool,
565    ) -> Self {
566        Self { inner, is_terminated }
567    }
568}
569
570impl futures::Stream for ControllerRequestStream {
571    type Item = Result<ControllerRequest, fidl::Error>;
572
573    fn poll_next(
574        mut self: std::pin::Pin<&mut Self>,
575        cx: &mut std::task::Context<'_>,
576    ) -> std::task::Poll<Option<Self::Item>> {
577        let this = &mut *self;
578        if this.inner.check_shutdown(cx) {
579            this.is_terminated = true;
580            return std::task::Poll::Ready(None);
581        }
582        if this.is_terminated {
583            panic!("polled ControllerRequestStream after completion");
584        }
585        fidl::encoding::with_tls_decode_buf::<_, fidl::encoding::DefaultFuchsiaResourceDialect>(
586            |bytes, handles| {
587                match this.inner.channel().read_etc(cx, bytes, handles) {
588                    std::task::Poll::Ready(Ok(())) => {}
589                    std::task::Poll::Pending => return std::task::Poll::Pending,
590                    std::task::Poll::Ready(Err(zx_status::Status::PEER_CLOSED)) => {
591                        this.is_terminated = true;
592                        return std::task::Poll::Ready(None);
593                    }
594                    std::task::Poll::Ready(Err(e)) => {
595                        return std::task::Poll::Ready(Some(Err(fidl::Error::ServerRequestRead(
596                            e.into(),
597                        ))));
598                    }
599                }
600
601                // A message has been received from the channel
602                let (header, _body_bytes) = fidl::encoding::decode_transaction_header(bytes)?;
603
604                std::task::Poll::Ready(Some(match header.ordinal {
605                    0x271d621cc0687761 => {
606                        header.validate_request_tx_id(fidl::MethodType::TwoWay)?;
607                        let mut req = fidl::new_empty!(
608                            ControllerAttachClientViewRequest,
609                            fidl::encoding::DefaultFuchsiaResourceDialect
610                        );
611                        fidl::encoding::Decoder::<fidl::encoding::DefaultFuchsiaResourceDialect>::decode_into::<ControllerAttachClientViewRequest>(&header, _body_bytes, handles, &mut req)?;
612                        let control_handle = ControllerControlHandle { inner: this.inner.clone() };
613                        Ok(ControllerRequest::AttachClientView {
614                            payload: req,
615                            responder: ControllerAttachClientViewResponder {
616                                control_handle: std::mem::ManuallyDrop::new(control_handle),
617                                tx_id: header.tx_id,
618                            },
619                        })
620                    }
621                    0x50b3378ecc810ca9 => {
622                        header.validate_request_tx_id(fidl::MethodType::OneWay)?;
623                        let mut req = fidl::new_empty!(
624                            ControllerPresentClientViewRequest,
625                            fidl::encoding::DefaultFuchsiaResourceDialect
626                        );
627                        fidl::encoding::Decoder::<fidl::encoding::DefaultFuchsiaResourceDialect>::decode_into::<ControllerPresentClientViewRequest>(&header, _body_bytes, handles, &mut req)?;
628                        let control_handle = ControllerControlHandle { inner: this.inner.clone() };
629                        Ok(ControllerRequest::PresentClientView { payload: req, control_handle })
630                    }
631                    0x1370345f4914064 => {
632                        header.validate_request_tx_id(fidl::MethodType::TwoWay)?;
633                        let mut req = fidl::new_empty!(
634                            ControllerRegisterViewTreeWatcherRequest,
635                            fidl::encoding::DefaultFuchsiaResourceDialect
636                        );
637                        fidl::encoding::Decoder::<fidl::encoding::DefaultFuchsiaResourceDialect>::decode_into::<ControllerRegisterViewTreeWatcherRequest>(&header, _body_bytes, handles, &mut req)?;
638                        let control_handle = ControllerControlHandle { inner: this.inner.clone() };
639                        Ok(ControllerRequest::RegisterViewTreeWatcher {
640                            watcher: req.watcher,
641
642                            responder: ControllerRegisterViewTreeWatcherResponder {
643                                control_handle: std::mem::ManuallyDrop::new(control_handle),
644                                tx_id: header.tx_id,
645                            },
646                        })
647                    }
648                    0x15439375bfe6d21d => {
649                        header.validate_request_tx_id(fidl::MethodType::TwoWay)?;
650                        let mut req = fidl::new_empty!(
651                            fidl::encoding::EmptyPayload,
652                            fidl::encoding::DefaultFuchsiaResourceDialect
653                        );
654                        fidl::encoding::Decoder::<fidl::encoding::DefaultFuchsiaResourceDialect>::decode_into::<fidl::encoding::EmptyPayload>(&header, _body_bytes, handles, &mut req)?;
655                        let control_handle = ControllerControlHandle { inner: this.inner.clone() };
656                        Ok(ControllerRequest::WatchViewPresentation {
657                            responder: ControllerWatchViewPresentationResponder {
658                                control_handle: std::mem::ManuallyDrop::new(control_handle),
659                                tx_id: header.tx_id,
660                            },
661                        })
662                    }
663                    _ => Err(fidl::Error::UnknownOrdinal {
664                        ordinal: header.ordinal,
665                        protocol_name:
666                            <ControllerMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME,
667                    }),
668                }))
669            },
670        )
671    }
672}
673
674/// Controls a UI test scene. Allows a test to attach test Views to the scene
675/// and add View-related instrumentation.
676#[derive(Debug)]
677pub enum ControllerRequest {
678    /// *** NOTE: `ViewProvider` is no longer the preferred way for a parent
679    /// and child view to agree on a ViewportCreationToken / ViewCreationToken
680    /// pair. Flatland-based clients are encouraged to use `PresentView` (below)
681    /// instead of `AttachClientView`.
682    ///
683    /// Elicits the server to request a view using the
684    /// `fuchsia.ui.app.ViewProvider` handle provided, and attach it to the
685    /// scene.
686    ///
687    /// RETURN VALUE
688    ///
689    /// This method returns the KOID for the client view's `ViewRef`.
690    ///
691    /// SYNCHRONIZATION
692    ///
693    /// This call returns as soon as the client `ViewRef` is available. Note
694    /// that this signal does NOT necessarily indicate that the view has been
695    /// attached to the scene.
696    ///
697    /// LIFE CYCLE
698    ///
699    /// Clients may drop the `Controller` connection once `AttachClientView` has
700    /// returned.
701    AttachClientView {
702        payload: ControllerAttachClientViewRequest,
703        responder: ControllerAttachClientViewResponder,
704    },
705    /// Elicits the server to create a viewport using `viewport_creation_token`.
706    ///
707    /// LIFE CYCLE
708    ///
709    /// Clients may drop the `Controller` connection once `PresentClientView` has
710    /// returned.
711    PresentClientView {
712        payload: ControllerPresentClientViewRequest,
713        control_handle: ControllerControlHandle,
714    },
715    /// Registers a `ViewTreeWatcher` on the client's behalf.
716    ///
717    /// The `ViewTreeWatcher` registered on behalf of the client will currently
718    /// be scoped globally; we intend to restrict the scope to the client view's
719    /// subtree as soon as it's feasible to do so.
720    ///
721    /// For more information on geometry observation, see the documentation
722    /// in //sdk/fidl/fuchsia.ui.observation.geometry/watcher.fidl.
723    RegisterViewTreeWatcher {
724        watcher:
725            fidl::endpoints::ServerEnd<fidl_fuchsia_ui_observation_geometry::ViewTreeWatcherMarker>,
726        responder: ControllerRegisterViewTreeWatcherResponder,
727    },
728    /// A hanging get to watch for updates to view presentation.
729    ///
730    /// Callers can use this method to wait until a `ClientView` has
731    /// `Present()`-ed through any of the following view presentation methods:
732    ///   * `fuchsia.ui.test.scene.Controller/AttachClientView()`
733    ///   * `fuchsia.ui.test.scene.Controller/PresentClientView()`
734    ///   * `fuchsia.element.GraphicalPresenter/PresentView()`
735    ///
736    /// Callers should expect to call this method once for each view they
737    /// expect to wait for.
738    ///
739    /// Note that callers must take care when interleaving calls, since
740    /// this method has no way to
741    ///   a) associate a `Present()` with a specific `ClientView`, or
742    ///   b) associate a `Present()` with an `AttachClientView()` call, rather
743    ///    than a `PresentClientView()` or `PresentView` call.
744    ///
745    /// It is invalid to call `WatchViewPresentation` while a previous call is
746    /// still pending; subsequent requests will be ignored.
747    WatchViewPresentation { responder: ControllerWatchViewPresentationResponder },
748}
749
750impl ControllerRequest {
751    #[allow(irrefutable_let_patterns)]
752    pub fn into_attach_client_view(
753        self,
754    ) -> Option<(ControllerAttachClientViewRequest, ControllerAttachClientViewResponder)> {
755        if let ControllerRequest::AttachClientView { payload, responder } = self {
756            Some((payload, responder))
757        } else {
758            None
759        }
760    }
761
762    #[allow(irrefutable_let_patterns)]
763    pub fn into_present_client_view(
764        self,
765    ) -> Option<(ControllerPresentClientViewRequest, ControllerControlHandle)> {
766        if let ControllerRequest::PresentClientView { payload, control_handle } = self {
767            Some((payload, control_handle))
768        } else {
769            None
770        }
771    }
772
773    #[allow(irrefutable_let_patterns)]
774    pub fn into_register_view_tree_watcher(
775        self,
776    ) -> Option<(
777        fidl::endpoints::ServerEnd<fidl_fuchsia_ui_observation_geometry::ViewTreeWatcherMarker>,
778        ControllerRegisterViewTreeWatcherResponder,
779    )> {
780        if let ControllerRequest::RegisterViewTreeWatcher { watcher, responder } = self {
781            Some((watcher, responder))
782        } else {
783            None
784        }
785    }
786
787    #[allow(irrefutable_let_patterns)]
788    pub fn into_watch_view_presentation(
789        self,
790    ) -> Option<(ControllerWatchViewPresentationResponder)> {
791        if let ControllerRequest::WatchViewPresentation { responder } = self {
792            Some((responder))
793        } else {
794            None
795        }
796    }
797
798    /// Name of the method defined in FIDL
799    pub fn method_name(&self) -> &'static str {
800        match *self {
801            ControllerRequest::AttachClientView { .. } => "attach_client_view",
802            ControllerRequest::PresentClientView { .. } => "present_client_view",
803            ControllerRequest::RegisterViewTreeWatcher { .. } => "register_view_tree_watcher",
804            ControllerRequest::WatchViewPresentation { .. } => "watch_view_presentation",
805        }
806    }
807}
808
809#[derive(Debug, Clone)]
810pub struct ControllerControlHandle {
811    inner: std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>,
812}
813
814impl ControllerControlHandle {
815    pub fn shutdown_with_epitaph(&self, status: impl Into<fidl::Epitaph>) {
816        self.inner.shutdown_with_epitaph(status.into())
817    }
818}
819
820impl fidl::endpoints::ControlHandle for ControllerControlHandle {
821    fn shutdown(&self) {
822        self.inner.shutdown()
823    }
824
825    fn shutdown_with_epitaph(&self, status: fidl::Epitaph) {
826        self.inner.shutdown_with_epitaph(status)
827    }
828
829    fn is_closed(&self) -> bool {
830        self.inner.channel().is_closed()
831    }
832    fn on_closed(&self) -> fidl::OnSignalsRef<'_> {
833        self.inner.channel().on_closed()
834    }
835
836    #[cfg(target_os = "fuchsia")]
837    fn signal_peer(
838        &self,
839        clear_mask: zx::Signals,
840        set_mask: zx::Signals,
841    ) -> Result<(), zx_status::Status> {
842        use fidl::Peered;
843        self.inner.channel().signal_peer(clear_mask, set_mask)
844    }
845}
846
847impl ControllerControlHandle {}
848
849#[must_use = "FIDL methods require a response to be sent"]
850#[derive(Debug)]
851pub struct ControllerAttachClientViewResponder {
852    control_handle: std::mem::ManuallyDrop<ControllerControlHandle>,
853    tx_id: u32,
854}
855
856/// Set the the channel to be shutdown (see [`ControllerControlHandle::shutdown`])
857/// if the responder is dropped without sending a response, so that the client
858/// doesn't hang. To prevent this behavior, call `drop_without_shutdown`.
859impl std::ops::Drop for ControllerAttachClientViewResponder {
860    fn drop(&mut self) {
861        self.control_handle.shutdown();
862        // Safety: drops once, never accessed again
863        unsafe { std::mem::ManuallyDrop::drop(&mut self.control_handle) };
864    }
865}
866
867impl fidl::endpoints::Responder for ControllerAttachClientViewResponder {
868    type ControlHandle = ControllerControlHandle;
869
870    fn control_handle(&self) -> &ControllerControlHandle {
871        &self.control_handle
872    }
873
874    fn drop_without_shutdown(mut self) {
875        // Safety: drops once, never accessed again due to mem::forget
876        unsafe { std::mem::ManuallyDrop::drop(&mut self.control_handle) };
877        // Prevent Drop from running (which would shut down the channel)
878        std::mem::forget(self);
879    }
880}
881
882impl ControllerAttachClientViewResponder {
883    /// Sends a response to the FIDL transaction.
884    ///
885    /// Sets the channel to shutdown if an error occurs.
886    pub fn send(self, mut view_ref_koid: u64) -> Result<(), fidl::Error> {
887        let _result = self.send_raw(view_ref_koid);
888        if _result.is_err() {
889            self.control_handle.shutdown();
890        }
891        self.drop_without_shutdown();
892        _result
893    }
894
895    /// Similar to "send" but does not shutdown the channel if an error occurs.
896    pub fn send_no_shutdown_on_err(self, mut view_ref_koid: u64) -> Result<(), fidl::Error> {
897        let _result = self.send_raw(view_ref_koid);
898        self.drop_without_shutdown();
899        _result
900    }
901
902    fn send_raw(&self, mut view_ref_koid: u64) -> Result<(), fidl::Error> {
903        self.control_handle.inner.send::<ControllerAttachClientViewResponse>(
904            (view_ref_koid,),
905            self.tx_id,
906            0x271d621cc0687761,
907            fidl::encoding::DynamicFlags::empty(),
908        )
909    }
910}
911
912#[must_use = "FIDL methods require a response to be sent"]
913#[derive(Debug)]
914pub struct ControllerRegisterViewTreeWatcherResponder {
915    control_handle: std::mem::ManuallyDrop<ControllerControlHandle>,
916    tx_id: u32,
917}
918
919/// Set the the channel to be shutdown (see [`ControllerControlHandle::shutdown`])
920/// if the responder is dropped without sending a response, so that the client
921/// doesn't hang. To prevent this behavior, call `drop_without_shutdown`.
922impl std::ops::Drop for ControllerRegisterViewTreeWatcherResponder {
923    fn drop(&mut self) {
924        self.control_handle.shutdown();
925        // Safety: drops once, never accessed again
926        unsafe { std::mem::ManuallyDrop::drop(&mut self.control_handle) };
927    }
928}
929
930impl fidl::endpoints::Responder for ControllerRegisterViewTreeWatcherResponder {
931    type ControlHandle = ControllerControlHandle;
932
933    fn control_handle(&self) -> &ControllerControlHandle {
934        &self.control_handle
935    }
936
937    fn drop_without_shutdown(mut self) {
938        // Safety: drops once, never accessed again due to mem::forget
939        unsafe { std::mem::ManuallyDrop::drop(&mut self.control_handle) };
940        // Prevent Drop from running (which would shut down the channel)
941        std::mem::forget(self);
942    }
943}
944
945impl ControllerRegisterViewTreeWatcherResponder {
946    /// Sends a response to the FIDL transaction.
947    ///
948    /// Sets the channel to shutdown if an error occurs.
949    pub fn send(self) -> Result<(), fidl::Error> {
950        let _result = self.send_raw();
951        if _result.is_err() {
952            self.control_handle.shutdown();
953        }
954        self.drop_without_shutdown();
955        _result
956    }
957
958    /// Similar to "send" but does not shutdown the channel if an error occurs.
959    pub fn send_no_shutdown_on_err(self) -> Result<(), fidl::Error> {
960        let _result = self.send_raw();
961        self.drop_without_shutdown();
962        _result
963    }
964
965    fn send_raw(&self) -> Result<(), fidl::Error> {
966        self.control_handle.inner.send::<fidl::encoding::EmptyPayload>(
967            (),
968            self.tx_id,
969            0x1370345f4914064,
970            fidl::encoding::DynamicFlags::empty(),
971        )
972    }
973}
974
975#[must_use = "FIDL methods require a response to be sent"]
976#[derive(Debug)]
977pub struct ControllerWatchViewPresentationResponder {
978    control_handle: std::mem::ManuallyDrop<ControllerControlHandle>,
979    tx_id: u32,
980}
981
982/// Set the the channel to be shutdown (see [`ControllerControlHandle::shutdown`])
983/// if the responder is dropped without sending a response, so that the client
984/// doesn't hang. To prevent this behavior, call `drop_without_shutdown`.
985impl std::ops::Drop for ControllerWatchViewPresentationResponder {
986    fn drop(&mut self) {
987        self.control_handle.shutdown();
988        // Safety: drops once, never accessed again
989        unsafe { std::mem::ManuallyDrop::drop(&mut self.control_handle) };
990    }
991}
992
993impl fidl::endpoints::Responder for ControllerWatchViewPresentationResponder {
994    type ControlHandle = ControllerControlHandle;
995
996    fn control_handle(&self) -> &ControllerControlHandle {
997        &self.control_handle
998    }
999
1000    fn drop_without_shutdown(mut self) {
1001        // Safety: drops once, never accessed again due to mem::forget
1002        unsafe { std::mem::ManuallyDrop::drop(&mut self.control_handle) };
1003        // Prevent Drop from running (which would shut down the channel)
1004        std::mem::forget(self);
1005    }
1006}
1007
1008impl ControllerWatchViewPresentationResponder {
1009    /// Sends a response to the FIDL transaction.
1010    ///
1011    /// Sets the channel to shutdown if an error occurs.
1012    pub fn send(self) -> Result<(), fidl::Error> {
1013        let _result = self.send_raw();
1014        if _result.is_err() {
1015            self.control_handle.shutdown();
1016        }
1017        self.drop_without_shutdown();
1018        _result
1019    }
1020
1021    /// Similar to "send" but does not shutdown the channel if an error occurs.
1022    pub fn send_no_shutdown_on_err(self) -> Result<(), fidl::Error> {
1023        let _result = self.send_raw();
1024        self.drop_without_shutdown();
1025        _result
1026    }
1027
1028    fn send_raw(&self) -> Result<(), fidl::Error> {
1029        self.control_handle.inner.send::<fidl::encoding::EmptyPayload>(
1030            (),
1031            self.tx_id,
1032            0x15439375bfe6d21d,
1033            fidl::encoding::DynamicFlags::empty(),
1034        )
1035    }
1036}
1037
1038mod internal {
1039    use super::*;
1040
1041    impl fidl::encoding::ResourceTypeMarker for ControllerRegisterViewTreeWatcherRequest {
1042        type Borrowed<'a> = &'a mut Self;
1043        fn take_or_borrow<'a>(
1044            value: &'a mut <Self as fidl::encoding::TypeMarker>::Owned,
1045        ) -> Self::Borrowed<'a> {
1046            value
1047        }
1048    }
1049
1050    unsafe impl fidl::encoding::TypeMarker for ControllerRegisterViewTreeWatcherRequest {
1051        type Owned = Self;
1052
1053        #[inline(always)]
1054        fn inline_align(_context: fidl::encoding::Context) -> usize {
1055            4
1056        }
1057
1058        #[inline(always)]
1059        fn inline_size(_context: fidl::encoding::Context) -> usize {
1060            4
1061        }
1062    }
1063
1064    unsafe impl
1065        fidl::encoding::Encode<
1066            ControllerRegisterViewTreeWatcherRequest,
1067            fidl::encoding::DefaultFuchsiaResourceDialect,
1068        > for &mut ControllerRegisterViewTreeWatcherRequest
1069    {
1070        #[inline]
1071        unsafe fn encode(
1072            self,
1073            encoder: &mut fidl::encoding::Encoder<
1074                '_,
1075                fidl::encoding::DefaultFuchsiaResourceDialect,
1076            >,
1077            offset: usize,
1078            _depth: fidl::encoding::Depth,
1079        ) -> fidl::Result<()> {
1080            encoder.debug_check_bounds::<ControllerRegisterViewTreeWatcherRequest>(offset);
1081            // Delegate to tuple encoding.
1082            fidl::encoding::Encode::<
1083                ControllerRegisterViewTreeWatcherRequest,
1084                fidl::encoding::DefaultFuchsiaResourceDialect,
1085            >::encode(
1086                (<fidl::encoding::Endpoint<
1087                    fidl::endpoints::ServerEnd<
1088                        fidl_fuchsia_ui_observation_geometry::ViewTreeWatcherMarker,
1089                    >,
1090                > as fidl::encoding::ResourceTypeMarker>::take_or_borrow(
1091                    &mut self.watcher
1092                ),),
1093                encoder,
1094                offset,
1095                _depth,
1096            )
1097        }
1098    }
1099    unsafe impl<
1100        T0: fidl::encoding::Encode<
1101                fidl::encoding::Endpoint<
1102                    fidl::endpoints::ServerEnd<
1103                        fidl_fuchsia_ui_observation_geometry::ViewTreeWatcherMarker,
1104                    >,
1105                >,
1106                fidl::encoding::DefaultFuchsiaResourceDialect,
1107            >,
1108    >
1109        fidl::encoding::Encode<
1110            ControllerRegisterViewTreeWatcherRequest,
1111            fidl::encoding::DefaultFuchsiaResourceDialect,
1112        > for (T0,)
1113    {
1114        #[inline]
1115        unsafe fn encode(
1116            self,
1117            encoder: &mut fidl::encoding::Encoder<
1118                '_,
1119                fidl::encoding::DefaultFuchsiaResourceDialect,
1120            >,
1121            offset: usize,
1122            depth: fidl::encoding::Depth,
1123        ) -> fidl::Result<()> {
1124            encoder.debug_check_bounds::<ControllerRegisterViewTreeWatcherRequest>(offset);
1125            // Zero out padding regions. There's no need to apply masks
1126            // because the unmasked parts will be overwritten by fields.
1127            // Write the fields.
1128            self.0.encode(encoder, offset + 0, depth)?;
1129            Ok(())
1130        }
1131    }
1132
1133    impl fidl::encoding::Decode<Self, fidl::encoding::DefaultFuchsiaResourceDialect>
1134        for ControllerRegisterViewTreeWatcherRequest
1135    {
1136        #[inline(always)]
1137        fn new_empty() -> Self {
1138            Self {
1139                watcher: fidl::new_empty!(
1140                    fidl::encoding::Endpoint<
1141                        fidl::endpoints::ServerEnd<
1142                            fidl_fuchsia_ui_observation_geometry::ViewTreeWatcherMarker,
1143                        >,
1144                    >,
1145                    fidl::encoding::DefaultFuchsiaResourceDialect
1146                ),
1147            }
1148        }
1149
1150        #[inline]
1151        unsafe fn decode(
1152            &mut self,
1153            decoder: &mut fidl::encoding::Decoder<
1154                '_,
1155                fidl::encoding::DefaultFuchsiaResourceDialect,
1156            >,
1157            offset: usize,
1158            _depth: fidl::encoding::Depth,
1159        ) -> fidl::Result<()> {
1160            decoder.debug_check_bounds::<Self>(offset);
1161            // Verify that padding bytes are zero.
1162            fidl::decode!(
1163                fidl::encoding::Endpoint<
1164                    fidl::endpoints::ServerEnd<
1165                        fidl_fuchsia_ui_observation_geometry::ViewTreeWatcherMarker,
1166                    >,
1167                >,
1168                fidl::encoding::DefaultFuchsiaResourceDialect,
1169                &mut self.watcher,
1170                decoder,
1171                offset + 0,
1172                _depth
1173            )?;
1174            Ok(())
1175        }
1176    }
1177
1178    impl ControllerAttachClientViewRequest {
1179        #[inline(always)]
1180        fn max_ordinal_present(&self) -> u64 {
1181            if let Some(_) = self.view_provider {
1182                return 1;
1183            }
1184            0
1185        }
1186    }
1187
1188    impl fidl::encoding::ResourceTypeMarker for ControllerAttachClientViewRequest {
1189        type Borrowed<'a> = &'a mut Self;
1190        fn take_or_borrow<'a>(
1191            value: &'a mut <Self as fidl::encoding::TypeMarker>::Owned,
1192        ) -> Self::Borrowed<'a> {
1193            value
1194        }
1195    }
1196
1197    unsafe impl fidl::encoding::TypeMarker for ControllerAttachClientViewRequest {
1198        type Owned = Self;
1199
1200        #[inline(always)]
1201        fn inline_align(_context: fidl::encoding::Context) -> usize {
1202            8
1203        }
1204
1205        #[inline(always)]
1206        fn inline_size(_context: fidl::encoding::Context) -> usize {
1207            16
1208        }
1209    }
1210
1211    unsafe impl
1212        fidl::encoding::Encode<
1213            ControllerAttachClientViewRequest,
1214            fidl::encoding::DefaultFuchsiaResourceDialect,
1215        > for &mut ControllerAttachClientViewRequest
1216    {
1217        unsafe fn encode(
1218            self,
1219            encoder: &mut fidl::encoding::Encoder<
1220                '_,
1221                fidl::encoding::DefaultFuchsiaResourceDialect,
1222            >,
1223            offset: usize,
1224            mut depth: fidl::encoding::Depth,
1225        ) -> fidl::Result<()> {
1226            encoder.debug_check_bounds::<ControllerAttachClientViewRequest>(offset);
1227            // Vector header
1228            let max_ordinal: u64 = self.max_ordinal_present();
1229            encoder.write_num(max_ordinal, offset);
1230            encoder.write_num(fidl::encoding::ALLOC_PRESENT_U64, offset + 8);
1231            // Calling encoder.out_of_line_offset(0) is not allowed.
1232            if max_ordinal == 0 {
1233                return Ok(());
1234            }
1235            depth.increment()?;
1236            let envelope_size = 8;
1237            let bytes_len = max_ordinal as usize * envelope_size;
1238            #[allow(unused_variables)]
1239            let offset = encoder.out_of_line_offset(bytes_len);
1240            let mut _prev_end_offset: usize = 0;
1241            if 1 > max_ordinal {
1242                return Ok(());
1243            }
1244
1245            // Write at offset+(ordinal-1)*envelope_size, since ordinals are one-based and envelopes
1246            // are envelope_size bytes.
1247            let cur_offset: usize = (1 - 1) * envelope_size;
1248
1249            // Zero reserved fields.
1250            encoder.padding(offset + _prev_end_offset, cur_offset - _prev_end_offset);
1251
1252            // Safety:
1253            // - bytes_len is calculated to fit envelope_size*max(member.ordinal).
1254            // - Since cur_offset is envelope_size*(member.ordinal - 1) and the envelope takes
1255            //   envelope_size bytes, there is always sufficient room.
1256            fidl::encoding::encode_in_envelope_optional::<
1257                fidl::encoding::Endpoint<
1258                    fidl::endpoints::ClientEnd<fidl_fuchsia_ui_app::ViewProviderMarker>,
1259                >,
1260                fidl::encoding::DefaultFuchsiaResourceDialect,
1261            >(
1262                self.view_provider.as_mut().map(
1263                    <fidl::encoding::Endpoint<
1264                        fidl::endpoints::ClientEnd<fidl_fuchsia_ui_app::ViewProviderMarker>,
1265                    > as fidl::encoding::ResourceTypeMarker>::take_or_borrow,
1266                ),
1267                encoder,
1268                offset + cur_offset,
1269                depth,
1270            )?;
1271
1272            _prev_end_offset = cur_offset + envelope_size;
1273
1274            Ok(())
1275        }
1276    }
1277
1278    impl fidl::encoding::Decode<Self, fidl::encoding::DefaultFuchsiaResourceDialect>
1279        for ControllerAttachClientViewRequest
1280    {
1281        #[inline(always)]
1282        fn new_empty() -> Self {
1283            Self::default()
1284        }
1285
1286        unsafe fn decode(
1287            &mut self,
1288            decoder: &mut fidl::encoding::Decoder<
1289                '_,
1290                fidl::encoding::DefaultFuchsiaResourceDialect,
1291            >,
1292            offset: usize,
1293            mut depth: fidl::encoding::Depth,
1294        ) -> fidl::Result<()> {
1295            decoder.debug_check_bounds::<Self>(offset);
1296            let len = match fidl::encoding::decode_vector_header(decoder, offset)? {
1297                None => return Err(fidl::Error::NotNullable),
1298                Some(len) => len,
1299            };
1300            // Calling decoder.out_of_line_offset(0) is not allowed.
1301            if len == 0 {
1302                return Ok(());
1303            };
1304            depth.increment()?;
1305            let envelope_size = 8;
1306            let bytes_len = len * envelope_size;
1307            let offset = decoder.out_of_line_offset(bytes_len)?;
1308            // Decode the envelope for each type.
1309            let mut _next_ordinal_to_read = 0;
1310            let mut next_offset = offset;
1311            let end_offset = offset + bytes_len;
1312            _next_ordinal_to_read += 1;
1313            if next_offset >= end_offset {
1314                return Ok(());
1315            }
1316
1317            // Decode unknown envelopes for gaps in ordinals.
1318            while _next_ordinal_to_read < 1 {
1319                fidl::encoding::decode_unknown_envelope(decoder, next_offset, depth)?;
1320                _next_ordinal_to_read += 1;
1321                next_offset += envelope_size;
1322            }
1323
1324            let next_out_of_line = decoder.next_out_of_line();
1325            let handles_before = decoder.remaining_handles();
1326            if let Some((inlined, num_bytes, num_handles)) =
1327                fidl::encoding::decode_envelope_header(decoder, next_offset)?
1328            {
1329                let member_inline_size = <fidl::encoding::Endpoint<
1330                    fidl::endpoints::ClientEnd<fidl_fuchsia_ui_app::ViewProviderMarker>,
1331                > as fidl::encoding::TypeMarker>::inline_size(
1332                    decoder.context
1333                );
1334                if inlined != (member_inline_size <= 4) {
1335                    return Err(fidl::Error::InvalidInlineBitInEnvelope);
1336                }
1337                let inner_offset;
1338                let mut inner_depth = depth.clone();
1339                if inlined {
1340                    decoder.check_inline_envelope_padding(next_offset, member_inline_size)?;
1341                    inner_offset = next_offset;
1342                } else {
1343                    inner_offset = decoder.out_of_line_offset(member_inline_size)?;
1344                    inner_depth.increment()?;
1345                }
1346                let val_ref = self.view_provider.get_or_insert_with(|| {
1347                    fidl::new_empty!(
1348                        fidl::encoding::Endpoint<
1349                            fidl::endpoints::ClientEnd<fidl_fuchsia_ui_app::ViewProviderMarker>,
1350                        >,
1351                        fidl::encoding::DefaultFuchsiaResourceDialect
1352                    )
1353                });
1354                fidl::decode!(
1355                    fidl::encoding::Endpoint<
1356                        fidl::endpoints::ClientEnd<fidl_fuchsia_ui_app::ViewProviderMarker>,
1357                    >,
1358                    fidl::encoding::DefaultFuchsiaResourceDialect,
1359                    val_ref,
1360                    decoder,
1361                    inner_offset,
1362                    inner_depth
1363                )?;
1364                if !inlined && decoder.next_out_of_line() != next_out_of_line + (num_bytes as usize)
1365                {
1366                    return Err(fidl::Error::InvalidNumBytesInEnvelope);
1367                }
1368                if handles_before != decoder.remaining_handles() + (num_handles as usize) {
1369                    return Err(fidl::Error::InvalidNumHandlesInEnvelope);
1370                }
1371            }
1372
1373            next_offset += envelope_size;
1374
1375            // Decode the remaining unknown envelopes.
1376            while next_offset < end_offset {
1377                _next_ordinal_to_read += 1;
1378                fidl::encoding::decode_unknown_envelope(decoder, next_offset, depth)?;
1379                next_offset += envelope_size;
1380            }
1381
1382            Ok(())
1383        }
1384    }
1385
1386    impl ControllerPresentClientViewRequest {
1387        #[inline(always)]
1388        fn max_ordinal_present(&self) -> u64 {
1389            if let Some(_) = self.viewport_creation_token {
1390                return 1;
1391            }
1392            0
1393        }
1394    }
1395
1396    impl fidl::encoding::ResourceTypeMarker for ControllerPresentClientViewRequest {
1397        type Borrowed<'a> = &'a mut Self;
1398        fn take_or_borrow<'a>(
1399            value: &'a mut <Self as fidl::encoding::TypeMarker>::Owned,
1400        ) -> Self::Borrowed<'a> {
1401            value
1402        }
1403    }
1404
1405    unsafe impl fidl::encoding::TypeMarker for ControllerPresentClientViewRequest {
1406        type Owned = Self;
1407
1408        #[inline(always)]
1409        fn inline_align(_context: fidl::encoding::Context) -> usize {
1410            8
1411        }
1412
1413        #[inline(always)]
1414        fn inline_size(_context: fidl::encoding::Context) -> usize {
1415            16
1416        }
1417    }
1418
1419    unsafe impl
1420        fidl::encoding::Encode<
1421            ControllerPresentClientViewRequest,
1422            fidl::encoding::DefaultFuchsiaResourceDialect,
1423        > for &mut ControllerPresentClientViewRequest
1424    {
1425        unsafe fn encode(
1426            self,
1427            encoder: &mut fidl::encoding::Encoder<
1428                '_,
1429                fidl::encoding::DefaultFuchsiaResourceDialect,
1430            >,
1431            offset: usize,
1432            mut depth: fidl::encoding::Depth,
1433        ) -> fidl::Result<()> {
1434            encoder.debug_check_bounds::<ControllerPresentClientViewRequest>(offset);
1435            // Vector header
1436            let max_ordinal: u64 = self.max_ordinal_present();
1437            encoder.write_num(max_ordinal, offset);
1438            encoder.write_num(fidl::encoding::ALLOC_PRESENT_U64, offset + 8);
1439            // Calling encoder.out_of_line_offset(0) is not allowed.
1440            if max_ordinal == 0 {
1441                return Ok(());
1442            }
1443            depth.increment()?;
1444            let envelope_size = 8;
1445            let bytes_len = max_ordinal as usize * envelope_size;
1446            #[allow(unused_variables)]
1447            let offset = encoder.out_of_line_offset(bytes_len);
1448            let mut _prev_end_offset: usize = 0;
1449            if 1 > max_ordinal {
1450                return Ok(());
1451            }
1452
1453            // Write at offset+(ordinal-1)*envelope_size, since ordinals are one-based and envelopes
1454            // are envelope_size bytes.
1455            let cur_offset: usize = (1 - 1) * envelope_size;
1456
1457            // Zero reserved fields.
1458            encoder.padding(offset + _prev_end_offset, cur_offset - _prev_end_offset);
1459
1460            // Safety:
1461            // - bytes_len is calculated to fit envelope_size*max(member.ordinal).
1462            // - Since cur_offset is envelope_size*(member.ordinal - 1) and the envelope takes
1463            //   envelope_size bytes, there is always sufficient room.
1464            fidl::encoding::encode_in_envelope_optional::<fidl_fuchsia_ui_views::ViewportCreationToken, fidl::encoding::DefaultFuchsiaResourceDialect>(
1465            self.viewport_creation_token.as_mut().map(<fidl_fuchsia_ui_views::ViewportCreationToken as fidl::encoding::ResourceTypeMarker>::take_or_borrow),
1466            encoder, offset + cur_offset, depth
1467        )?;
1468
1469            _prev_end_offset = cur_offset + envelope_size;
1470
1471            Ok(())
1472        }
1473    }
1474
1475    impl fidl::encoding::Decode<Self, fidl::encoding::DefaultFuchsiaResourceDialect>
1476        for ControllerPresentClientViewRequest
1477    {
1478        #[inline(always)]
1479        fn new_empty() -> Self {
1480            Self::default()
1481        }
1482
1483        unsafe fn decode(
1484            &mut self,
1485            decoder: &mut fidl::encoding::Decoder<
1486                '_,
1487                fidl::encoding::DefaultFuchsiaResourceDialect,
1488            >,
1489            offset: usize,
1490            mut depth: fidl::encoding::Depth,
1491        ) -> fidl::Result<()> {
1492            decoder.debug_check_bounds::<Self>(offset);
1493            let len = match fidl::encoding::decode_vector_header(decoder, offset)? {
1494                None => return Err(fidl::Error::NotNullable),
1495                Some(len) => len,
1496            };
1497            // Calling decoder.out_of_line_offset(0) is not allowed.
1498            if len == 0 {
1499                return Ok(());
1500            };
1501            depth.increment()?;
1502            let envelope_size = 8;
1503            let bytes_len = len * envelope_size;
1504            let offset = decoder.out_of_line_offset(bytes_len)?;
1505            // Decode the envelope for each type.
1506            let mut _next_ordinal_to_read = 0;
1507            let mut next_offset = offset;
1508            let end_offset = offset + bytes_len;
1509            _next_ordinal_to_read += 1;
1510            if next_offset >= end_offset {
1511                return Ok(());
1512            }
1513
1514            // Decode unknown envelopes for gaps in ordinals.
1515            while _next_ordinal_to_read < 1 {
1516                fidl::encoding::decode_unknown_envelope(decoder, next_offset, depth)?;
1517                _next_ordinal_to_read += 1;
1518                next_offset += envelope_size;
1519            }
1520
1521            let next_out_of_line = decoder.next_out_of_line();
1522            let handles_before = decoder.remaining_handles();
1523            if let Some((inlined, num_bytes, num_handles)) =
1524                fidl::encoding::decode_envelope_header(decoder, next_offset)?
1525            {
1526                let member_inline_size = <fidl_fuchsia_ui_views::ViewportCreationToken as fidl::encoding::TypeMarker>::inline_size(decoder.context);
1527                if inlined != (member_inline_size <= 4) {
1528                    return Err(fidl::Error::InvalidInlineBitInEnvelope);
1529                }
1530                let inner_offset;
1531                let mut inner_depth = depth.clone();
1532                if inlined {
1533                    decoder.check_inline_envelope_padding(next_offset, member_inline_size)?;
1534                    inner_offset = next_offset;
1535                } else {
1536                    inner_offset = decoder.out_of_line_offset(member_inline_size)?;
1537                    inner_depth.increment()?;
1538                }
1539                let val_ref = self.viewport_creation_token.get_or_insert_with(|| {
1540                    fidl::new_empty!(
1541                        fidl_fuchsia_ui_views::ViewportCreationToken,
1542                        fidl::encoding::DefaultFuchsiaResourceDialect
1543                    )
1544                });
1545                fidl::decode!(
1546                    fidl_fuchsia_ui_views::ViewportCreationToken,
1547                    fidl::encoding::DefaultFuchsiaResourceDialect,
1548                    val_ref,
1549                    decoder,
1550                    inner_offset,
1551                    inner_depth
1552                )?;
1553                if !inlined && decoder.next_out_of_line() != next_out_of_line + (num_bytes as usize)
1554                {
1555                    return Err(fidl::Error::InvalidNumBytesInEnvelope);
1556                }
1557                if handles_before != decoder.remaining_handles() + (num_handles as usize) {
1558                    return Err(fidl::Error::InvalidNumHandlesInEnvelope);
1559                }
1560            }
1561
1562            next_offset += envelope_size;
1563
1564            // Decode the remaining unknown envelopes.
1565            while next_offset < end_offset {
1566                _next_ordinal_to_read += 1;
1567                fidl::encoding::decode_unknown_envelope(decoder, next_offset, depth)?;
1568                next_offset += envelope_size;
1569            }
1570
1571            Ok(())
1572        }
1573    }
1574}