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 fidl::endpoints::ControlHandle for ControllerControlHandle {
815    fn shutdown(&self) {
816        self.inner.shutdown()
817    }
818
819    fn shutdown_with_epitaph(&self, status: zx_status::Status) {
820        self.inner.shutdown_with_epitaph(status)
821    }
822
823    fn is_closed(&self) -> bool {
824        self.inner.channel().is_closed()
825    }
826    fn on_closed(&self) -> fidl::OnSignalsRef<'_> {
827        self.inner.channel().on_closed()
828    }
829
830    #[cfg(target_os = "fuchsia")]
831    fn signal_peer(
832        &self,
833        clear_mask: zx::Signals,
834        set_mask: zx::Signals,
835    ) -> Result<(), zx_status::Status> {
836        use fidl::Peered;
837        self.inner.channel().signal_peer(clear_mask, set_mask)
838    }
839}
840
841impl ControllerControlHandle {}
842
843#[must_use = "FIDL methods require a response to be sent"]
844#[derive(Debug)]
845pub struct ControllerAttachClientViewResponder {
846    control_handle: std::mem::ManuallyDrop<ControllerControlHandle>,
847    tx_id: u32,
848}
849
850/// Set the the channel to be shutdown (see [`ControllerControlHandle::shutdown`])
851/// if the responder is dropped without sending a response, so that the client
852/// doesn't hang. To prevent this behavior, call `drop_without_shutdown`.
853impl std::ops::Drop for ControllerAttachClientViewResponder {
854    fn drop(&mut self) {
855        self.control_handle.shutdown();
856        // Safety: drops once, never accessed again
857        unsafe { std::mem::ManuallyDrop::drop(&mut self.control_handle) };
858    }
859}
860
861impl fidl::endpoints::Responder for ControllerAttachClientViewResponder {
862    type ControlHandle = ControllerControlHandle;
863
864    fn control_handle(&self) -> &ControllerControlHandle {
865        &self.control_handle
866    }
867
868    fn drop_without_shutdown(mut self) {
869        // Safety: drops once, never accessed again due to mem::forget
870        unsafe { std::mem::ManuallyDrop::drop(&mut self.control_handle) };
871        // Prevent Drop from running (which would shut down the channel)
872        std::mem::forget(self);
873    }
874}
875
876impl ControllerAttachClientViewResponder {
877    /// Sends a response to the FIDL transaction.
878    ///
879    /// Sets the channel to shutdown if an error occurs.
880    pub fn send(self, mut view_ref_koid: u64) -> Result<(), fidl::Error> {
881        let _result = self.send_raw(view_ref_koid);
882        if _result.is_err() {
883            self.control_handle.shutdown();
884        }
885        self.drop_without_shutdown();
886        _result
887    }
888
889    /// Similar to "send" but does not shutdown the channel if an error occurs.
890    pub fn send_no_shutdown_on_err(self, mut view_ref_koid: u64) -> Result<(), fidl::Error> {
891        let _result = self.send_raw(view_ref_koid);
892        self.drop_without_shutdown();
893        _result
894    }
895
896    fn send_raw(&self, mut view_ref_koid: u64) -> Result<(), fidl::Error> {
897        self.control_handle.inner.send::<ControllerAttachClientViewResponse>(
898            (view_ref_koid,),
899            self.tx_id,
900            0x271d621cc0687761,
901            fidl::encoding::DynamicFlags::empty(),
902        )
903    }
904}
905
906#[must_use = "FIDL methods require a response to be sent"]
907#[derive(Debug)]
908pub struct ControllerRegisterViewTreeWatcherResponder {
909    control_handle: std::mem::ManuallyDrop<ControllerControlHandle>,
910    tx_id: u32,
911}
912
913/// Set the the channel to be shutdown (see [`ControllerControlHandle::shutdown`])
914/// if the responder is dropped without sending a response, so that the client
915/// doesn't hang. To prevent this behavior, call `drop_without_shutdown`.
916impl std::ops::Drop for ControllerRegisterViewTreeWatcherResponder {
917    fn drop(&mut self) {
918        self.control_handle.shutdown();
919        // Safety: drops once, never accessed again
920        unsafe { std::mem::ManuallyDrop::drop(&mut self.control_handle) };
921    }
922}
923
924impl fidl::endpoints::Responder for ControllerRegisterViewTreeWatcherResponder {
925    type ControlHandle = ControllerControlHandle;
926
927    fn control_handle(&self) -> &ControllerControlHandle {
928        &self.control_handle
929    }
930
931    fn drop_without_shutdown(mut self) {
932        // Safety: drops once, never accessed again due to mem::forget
933        unsafe { std::mem::ManuallyDrop::drop(&mut self.control_handle) };
934        // Prevent Drop from running (which would shut down the channel)
935        std::mem::forget(self);
936    }
937}
938
939impl ControllerRegisterViewTreeWatcherResponder {
940    /// Sends a response to the FIDL transaction.
941    ///
942    /// Sets the channel to shutdown if an error occurs.
943    pub fn send(self) -> Result<(), fidl::Error> {
944        let _result = self.send_raw();
945        if _result.is_err() {
946            self.control_handle.shutdown();
947        }
948        self.drop_without_shutdown();
949        _result
950    }
951
952    /// Similar to "send" but does not shutdown the channel if an error occurs.
953    pub fn send_no_shutdown_on_err(self) -> Result<(), fidl::Error> {
954        let _result = self.send_raw();
955        self.drop_without_shutdown();
956        _result
957    }
958
959    fn send_raw(&self) -> Result<(), fidl::Error> {
960        self.control_handle.inner.send::<fidl::encoding::EmptyPayload>(
961            (),
962            self.tx_id,
963            0x1370345f4914064,
964            fidl::encoding::DynamicFlags::empty(),
965        )
966    }
967}
968
969#[must_use = "FIDL methods require a response to be sent"]
970#[derive(Debug)]
971pub struct ControllerWatchViewPresentationResponder {
972    control_handle: std::mem::ManuallyDrop<ControllerControlHandle>,
973    tx_id: u32,
974}
975
976/// Set the the channel to be shutdown (see [`ControllerControlHandle::shutdown`])
977/// if the responder is dropped without sending a response, so that the client
978/// doesn't hang. To prevent this behavior, call `drop_without_shutdown`.
979impl std::ops::Drop for ControllerWatchViewPresentationResponder {
980    fn drop(&mut self) {
981        self.control_handle.shutdown();
982        // Safety: drops once, never accessed again
983        unsafe { std::mem::ManuallyDrop::drop(&mut self.control_handle) };
984    }
985}
986
987impl fidl::endpoints::Responder for ControllerWatchViewPresentationResponder {
988    type ControlHandle = ControllerControlHandle;
989
990    fn control_handle(&self) -> &ControllerControlHandle {
991        &self.control_handle
992    }
993
994    fn drop_without_shutdown(mut self) {
995        // Safety: drops once, never accessed again due to mem::forget
996        unsafe { std::mem::ManuallyDrop::drop(&mut self.control_handle) };
997        // Prevent Drop from running (which would shut down the channel)
998        std::mem::forget(self);
999    }
1000}
1001
1002impl ControllerWatchViewPresentationResponder {
1003    /// Sends a response to the FIDL transaction.
1004    ///
1005    /// Sets the channel to shutdown if an error occurs.
1006    pub fn send(self) -> Result<(), fidl::Error> {
1007        let _result = self.send_raw();
1008        if _result.is_err() {
1009            self.control_handle.shutdown();
1010        }
1011        self.drop_without_shutdown();
1012        _result
1013    }
1014
1015    /// Similar to "send" but does not shutdown the channel if an error occurs.
1016    pub fn send_no_shutdown_on_err(self) -> Result<(), fidl::Error> {
1017        let _result = self.send_raw();
1018        self.drop_without_shutdown();
1019        _result
1020    }
1021
1022    fn send_raw(&self) -> Result<(), fidl::Error> {
1023        self.control_handle.inner.send::<fidl::encoding::EmptyPayload>(
1024            (),
1025            self.tx_id,
1026            0x15439375bfe6d21d,
1027            fidl::encoding::DynamicFlags::empty(),
1028        )
1029    }
1030}
1031
1032mod internal {
1033    use super::*;
1034
1035    impl fidl::encoding::ResourceTypeMarker for ControllerRegisterViewTreeWatcherRequest {
1036        type Borrowed<'a> = &'a mut Self;
1037        fn take_or_borrow<'a>(
1038            value: &'a mut <Self as fidl::encoding::TypeMarker>::Owned,
1039        ) -> Self::Borrowed<'a> {
1040            value
1041        }
1042    }
1043
1044    unsafe impl fidl::encoding::TypeMarker for ControllerRegisterViewTreeWatcherRequest {
1045        type Owned = Self;
1046
1047        #[inline(always)]
1048        fn inline_align(_context: fidl::encoding::Context) -> usize {
1049            4
1050        }
1051
1052        #[inline(always)]
1053        fn inline_size(_context: fidl::encoding::Context) -> usize {
1054            4
1055        }
1056    }
1057
1058    unsafe impl
1059        fidl::encoding::Encode<
1060            ControllerRegisterViewTreeWatcherRequest,
1061            fidl::encoding::DefaultFuchsiaResourceDialect,
1062        > for &mut ControllerRegisterViewTreeWatcherRequest
1063    {
1064        #[inline]
1065        unsafe fn encode(
1066            self,
1067            encoder: &mut fidl::encoding::Encoder<
1068                '_,
1069                fidl::encoding::DefaultFuchsiaResourceDialect,
1070            >,
1071            offset: usize,
1072            _depth: fidl::encoding::Depth,
1073        ) -> fidl::Result<()> {
1074            encoder.debug_check_bounds::<ControllerRegisterViewTreeWatcherRequest>(offset);
1075            // Delegate to tuple encoding.
1076            fidl::encoding::Encode::<
1077                ControllerRegisterViewTreeWatcherRequest,
1078                fidl::encoding::DefaultFuchsiaResourceDialect,
1079            >::encode(
1080                (<fidl::encoding::Endpoint<
1081                    fidl::endpoints::ServerEnd<
1082                        fidl_fuchsia_ui_observation_geometry::ViewTreeWatcherMarker,
1083                    >,
1084                > as fidl::encoding::ResourceTypeMarker>::take_or_borrow(
1085                    &mut self.watcher
1086                ),),
1087                encoder,
1088                offset,
1089                _depth,
1090            )
1091        }
1092    }
1093    unsafe impl<
1094        T0: fidl::encoding::Encode<
1095                fidl::encoding::Endpoint<
1096                    fidl::endpoints::ServerEnd<
1097                        fidl_fuchsia_ui_observation_geometry::ViewTreeWatcherMarker,
1098                    >,
1099                >,
1100                fidl::encoding::DefaultFuchsiaResourceDialect,
1101            >,
1102    >
1103        fidl::encoding::Encode<
1104            ControllerRegisterViewTreeWatcherRequest,
1105            fidl::encoding::DefaultFuchsiaResourceDialect,
1106        > for (T0,)
1107    {
1108        #[inline]
1109        unsafe fn encode(
1110            self,
1111            encoder: &mut fidl::encoding::Encoder<
1112                '_,
1113                fidl::encoding::DefaultFuchsiaResourceDialect,
1114            >,
1115            offset: usize,
1116            depth: fidl::encoding::Depth,
1117        ) -> fidl::Result<()> {
1118            encoder.debug_check_bounds::<ControllerRegisterViewTreeWatcherRequest>(offset);
1119            // Zero out padding regions. There's no need to apply masks
1120            // because the unmasked parts will be overwritten by fields.
1121            // Write the fields.
1122            self.0.encode(encoder, offset + 0, depth)?;
1123            Ok(())
1124        }
1125    }
1126
1127    impl fidl::encoding::Decode<Self, fidl::encoding::DefaultFuchsiaResourceDialect>
1128        for ControllerRegisterViewTreeWatcherRequest
1129    {
1130        #[inline(always)]
1131        fn new_empty() -> Self {
1132            Self {
1133                watcher: fidl::new_empty!(
1134                    fidl::encoding::Endpoint<
1135                        fidl::endpoints::ServerEnd<
1136                            fidl_fuchsia_ui_observation_geometry::ViewTreeWatcherMarker,
1137                        >,
1138                    >,
1139                    fidl::encoding::DefaultFuchsiaResourceDialect
1140                ),
1141            }
1142        }
1143
1144        #[inline]
1145        unsafe fn decode(
1146            &mut self,
1147            decoder: &mut fidl::encoding::Decoder<
1148                '_,
1149                fidl::encoding::DefaultFuchsiaResourceDialect,
1150            >,
1151            offset: usize,
1152            _depth: fidl::encoding::Depth,
1153        ) -> fidl::Result<()> {
1154            decoder.debug_check_bounds::<Self>(offset);
1155            // Verify that padding bytes are zero.
1156            fidl::decode!(
1157                fidl::encoding::Endpoint<
1158                    fidl::endpoints::ServerEnd<
1159                        fidl_fuchsia_ui_observation_geometry::ViewTreeWatcherMarker,
1160                    >,
1161                >,
1162                fidl::encoding::DefaultFuchsiaResourceDialect,
1163                &mut self.watcher,
1164                decoder,
1165                offset + 0,
1166                _depth
1167            )?;
1168            Ok(())
1169        }
1170    }
1171
1172    impl ControllerAttachClientViewRequest {
1173        #[inline(always)]
1174        fn max_ordinal_present(&self) -> u64 {
1175            if let Some(_) = self.view_provider {
1176                return 1;
1177            }
1178            0
1179        }
1180    }
1181
1182    impl fidl::encoding::ResourceTypeMarker for ControllerAttachClientViewRequest {
1183        type Borrowed<'a> = &'a mut Self;
1184        fn take_or_borrow<'a>(
1185            value: &'a mut <Self as fidl::encoding::TypeMarker>::Owned,
1186        ) -> Self::Borrowed<'a> {
1187            value
1188        }
1189    }
1190
1191    unsafe impl fidl::encoding::TypeMarker for ControllerAttachClientViewRequest {
1192        type Owned = Self;
1193
1194        #[inline(always)]
1195        fn inline_align(_context: fidl::encoding::Context) -> usize {
1196            8
1197        }
1198
1199        #[inline(always)]
1200        fn inline_size(_context: fidl::encoding::Context) -> usize {
1201            16
1202        }
1203    }
1204
1205    unsafe impl
1206        fidl::encoding::Encode<
1207            ControllerAttachClientViewRequest,
1208            fidl::encoding::DefaultFuchsiaResourceDialect,
1209        > for &mut ControllerAttachClientViewRequest
1210    {
1211        unsafe fn encode(
1212            self,
1213            encoder: &mut fidl::encoding::Encoder<
1214                '_,
1215                fidl::encoding::DefaultFuchsiaResourceDialect,
1216            >,
1217            offset: usize,
1218            mut depth: fidl::encoding::Depth,
1219        ) -> fidl::Result<()> {
1220            encoder.debug_check_bounds::<ControllerAttachClientViewRequest>(offset);
1221            // Vector header
1222            let max_ordinal: u64 = self.max_ordinal_present();
1223            encoder.write_num(max_ordinal, offset);
1224            encoder.write_num(fidl::encoding::ALLOC_PRESENT_U64, offset + 8);
1225            // Calling encoder.out_of_line_offset(0) is not allowed.
1226            if max_ordinal == 0 {
1227                return Ok(());
1228            }
1229            depth.increment()?;
1230            let envelope_size = 8;
1231            let bytes_len = max_ordinal as usize * envelope_size;
1232            #[allow(unused_variables)]
1233            let offset = encoder.out_of_line_offset(bytes_len);
1234            let mut _prev_end_offset: usize = 0;
1235            if 1 > max_ordinal {
1236                return Ok(());
1237            }
1238
1239            // Write at offset+(ordinal-1)*envelope_size, since ordinals are one-based and envelopes
1240            // are envelope_size bytes.
1241            let cur_offset: usize = (1 - 1) * envelope_size;
1242
1243            // Zero reserved fields.
1244            encoder.padding(offset + _prev_end_offset, cur_offset - _prev_end_offset);
1245
1246            // Safety:
1247            // - bytes_len is calculated to fit envelope_size*max(member.ordinal).
1248            // - Since cur_offset is envelope_size*(member.ordinal - 1) and the envelope takes
1249            //   envelope_size bytes, there is always sufficient room.
1250            fidl::encoding::encode_in_envelope_optional::<
1251                fidl::encoding::Endpoint<
1252                    fidl::endpoints::ClientEnd<fidl_fuchsia_ui_app::ViewProviderMarker>,
1253                >,
1254                fidl::encoding::DefaultFuchsiaResourceDialect,
1255            >(
1256                self.view_provider.as_mut().map(
1257                    <fidl::encoding::Endpoint<
1258                        fidl::endpoints::ClientEnd<fidl_fuchsia_ui_app::ViewProviderMarker>,
1259                    > as fidl::encoding::ResourceTypeMarker>::take_or_borrow,
1260                ),
1261                encoder,
1262                offset + cur_offset,
1263                depth,
1264            )?;
1265
1266            _prev_end_offset = cur_offset + envelope_size;
1267
1268            Ok(())
1269        }
1270    }
1271
1272    impl fidl::encoding::Decode<Self, fidl::encoding::DefaultFuchsiaResourceDialect>
1273        for ControllerAttachClientViewRequest
1274    {
1275        #[inline(always)]
1276        fn new_empty() -> Self {
1277            Self::default()
1278        }
1279
1280        unsafe fn decode(
1281            &mut self,
1282            decoder: &mut fidl::encoding::Decoder<
1283                '_,
1284                fidl::encoding::DefaultFuchsiaResourceDialect,
1285            >,
1286            offset: usize,
1287            mut depth: fidl::encoding::Depth,
1288        ) -> fidl::Result<()> {
1289            decoder.debug_check_bounds::<Self>(offset);
1290            let len = match fidl::encoding::decode_vector_header(decoder, offset)? {
1291                None => return Err(fidl::Error::NotNullable),
1292                Some(len) => len,
1293            };
1294            // Calling decoder.out_of_line_offset(0) is not allowed.
1295            if len == 0 {
1296                return Ok(());
1297            };
1298            depth.increment()?;
1299            let envelope_size = 8;
1300            let bytes_len = len * envelope_size;
1301            let offset = decoder.out_of_line_offset(bytes_len)?;
1302            // Decode the envelope for each type.
1303            let mut _next_ordinal_to_read = 0;
1304            let mut next_offset = offset;
1305            let end_offset = offset + bytes_len;
1306            _next_ordinal_to_read += 1;
1307            if next_offset >= end_offset {
1308                return Ok(());
1309            }
1310
1311            // Decode unknown envelopes for gaps in ordinals.
1312            while _next_ordinal_to_read < 1 {
1313                fidl::encoding::decode_unknown_envelope(decoder, next_offset, depth)?;
1314                _next_ordinal_to_read += 1;
1315                next_offset += envelope_size;
1316            }
1317
1318            let next_out_of_line = decoder.next_out_of_line();
1319            let handles_before = decoder.remaining_handles();
1320            if let Some((inlined, num_bytes, num_handles)) =
1321                fidl::encoding::decode_envelope_header(decoder, next_offset)?
1322            {
1323                let member_inline_size = <fidl::encoding::Endpoint<
1324                    fidl::endpoints::ClientEnd<fidl_fuchsia_ui_app::ViewProviderMarker>,
1325                > as fidl::encoding::TypeMarker>::inline_size(
1326                    decoder.context
1327                );
1328                if inlined != (member_inline_size <= 4) {
1329                    return Err(fidl::Error::InvalidInlineBitInEnvelope);
1330                }
1331                let inner_offset;
1332                let mut inner_depth = depth.clone();
1333                if inlined {
1334                    decoder.check_inline_envelope_padding(next_offset, member_inline_size)?;
1335                    inner_offset = next_offset;
1336                } else {
1337                    inner_offset = decoder.out_of_line_offset(member_inline_size)?;
1338                    inner_depth.increment()?;
1339                }
1340                let val_ref = self.view_provider.get_or_insert_with(|| {
1341                    fidl::new_empty!(
1342                        fidl::encoding::Endpoint<
1343                            fidl::endpoints::ClientEnd<fidl_fuchsia_ui_app::ViewProviderMarker>,
1344                        >,
1345                        fidl::encoding::DefaultFuchsiaResourceDialect
1346                    )
1347                });
1348                fidl::decode!(
1349                    fidl::encoding::Endpoint<
1350                        fidl::endpoints::ClientEnd<fidl_fuchsia_ui_app::ViewProviderMarker>,
1351                    >,
1352                    fidl::encoding::DefaultFuchsiaResourceDialect,
1353                    val_ref,
1354                    decoder,
1355                    inner_offset,
1356                    inner_depth
1357                )?;
1358                if !inlined && decoder.next_out_of_line() != next_out_of_line + (num_bytes as usize)
1359                {
1360                    return Err(fidl::Error::InvalidNumBytesInEnvelope);
1361                }
1362                if handles_before != decoder.remaining_handles() + (num_handles as usize) {
1363                    return Err(fidl::Error::InvalidNumHandlesInEnvelope);
1364                }
1365            }
1366
1367            next_offset += envelope_size;
1368
1369            // Decode the remaining unknown envelopes.
1370            while next_offset < end_offset {
1371                _next_ordinal_to_read += 1;
1372                fidl::encoding::decode_unknown_envelope(decoder, next_offset, depth)?;
1373                next_offset += envelope_size;
1374            }
1375
1376            Ok(())
1377        }
1378    }
1379
1380    impl ControllerPresentClientViewRequest {
1381        #[inline(always)]
1382        fn max_ordinal_present(&self) -> u64 {
1383            if let Some(_) = self.viewport_creation_token {
1384                return 1;
1385            }
1386            0
1387        }
1388    }
1389
1390    impl fidl::encoding::ResourceTypeMarker for ControllerPresentClientViewRequest {
1391        type Borrowed<'a> = &'a mut Self;
1392        fn take_or_borrow<'a>(
1393            value: &'a mut <Self as fidl::encoding::TypeMarker>::Owned,
1394        ) -> Self::Borrowed<'a> {
1395            value
1396        }
1397    }
1398
1399    unsafe impl fidl::encoding::TypeMarker for ControllerPresentClientViewRequest {
1400        type Owned = Self;
1401
1402        #[inline(always)]
1403        fn inline_align(_context: fidl::encoding::Context) -> usize {
1404            8
1405        }
1406
1407        #[inline(always)]
1408        fn inline_size(_context: fidl::encoding::Context) -> usize {
1409            16
1410        }
1411    }
1412
1413    unsafe impl
1414        fidl::encoding::Encode<
1415            ControllerPresentClientViewRequest,
1416            fidl::encoding::DefaultFuchsiaResourceDialect,
1417        > for &mut ControllerPresentClientViewRequest
1418    {
1419        unsafe fn encode(
1420            self,
1421            encoder: &mut fidl::encoding::Encoder<
1422                '_,
1423                fidl::encoding::DefaultFuchsiaResourceDialect,
1424            >,
1425            offset: usize,
1426            mut depth: fidl::encoding::Depth,
1427        ) -> fidl::Result<()> {
1428            encoder.debug_check_bounds::<ControllerPresentClientViewRequest>(offset);
1429            // Vector header
1430            let max_ordinal: u64 = self.max_ordinal_present();
1431            encoder.write_num(max_ordinal, offset);
1432            encoder.write_num(fidl::encoding::ALLOC_PRESENT_U64, offset + 8);
1433            // Calling encoder.out_of_line_offset(0) is not allowed.
1434            if max_ordinal == 0 {
1435                return Ok(());
1436            }
1437            depth.increment()?;
1438            let envelope_size = 8;
1439            let bytes_len = max_ordinal as usize * envelope_size;
1440            #[allow(unused_variables)]
1441            let offset = encoder.out_of_line_offset(bytes_len);
1442            let mut _prev_end_offset: usize = 0;
1443            if 1 > max_ordinal {
1444                return Ok(());
1445            }
1446
1447            // Write at offset+(ordinal-1)*envelope_size, since ordinals are one-based and envelopes
1448            // are envelope_size bytes.
1449            let cur_offset: usize = (1 - 1) * envelope_size;
1450
1451            // Zero reserved fields.
1452            encoder.padding(offset + _prev_end_offset, cur_offset - _prev_end_offset);
1453
1454            // Safety:
1455            // - bytes_len is calculated to fit envelope_size*max(member.ordinal).
1456            // - Since cur_offset is envelope_size*(member.ordinal - 1) and the envelope takes
1457            //   envelope_size bytes, there is always sufficient room.
1458            fidl::encoding::encode_in_envelope_optional::<fidl_fuchsia_ui_views::ViewportCreationToken, fidl::encoding::DefaultFuchsiaResourceDialect>(
1459            self.viewport_creation_token.as_mut().map(<fidl_fuchsia_ui_views::ViewportCreationToken as fidl::encoding::ResourceTypeMarker>::take_or_borrow),
1460            encoder, offset + cur_offset, depth
1461        )?;
1462
1463            _prev_end_offset = cur_offset + envelope_size;
1464
1465            Ok(())
1466        }
1467    }
1468
1469    impl fidl::encoding::Decode<Self, fidl::encoding::DefaultFuchsiaResourceDialect>
1470        for ControllerPresentClientViewRequest
1471    {
1472        #[inline(always)]
1473        fn new_empty() -> Self {
1474            Self::default()
1475        }
1476
1477        unsafe fn decode(
1478            &mut self,
1479            decoder: &mut fidl::encoding::Decoder<
1480                '_,
1481                fidl::encoding::DefaultFuchsiaResourceDialect,
1482            >,
1483            offset: usize,
1484            mut depth: fidl::encoding::Depth,
1485        ) -> fidl::Result<()> {
1486            decoder.debug_check_bounds::<Self>(offset);
1487            let len = match fidl::encoding::decode_vector_header(decoder, offset)? {
1488                None => return Err(fidl::Error::NotNullable),
1489                Some(len) => len,
1490            };
1491            // Calling decoder.out_of_line_offset(0) is not allowed.
1492            if len == 0 {
1493                return Ok(());
1494            };
1495            depth.increment()?;
1496            let envelope_size = 8;
1497            let bytes_len = len * envelope_size;
1498            let offset = decoder.out_of_line_offset(bytes_len)?;
1499            // Decode the envelope for each type.
1500            let mut _next_ordinal_to_read = 0;
1501            let mut next_offset = offset;
1502            let end_offset = offset + bytes_len;
1503            _next_ordinal_to_read += 1;
1504            if next_offset >= end_offset {
1505                return Ok(());
1506            }
1507
1508            // Decode unknown envelopes for gaps in ordinals.
1509            while _next_ordinal_to_read < 1 {
1510                fidl::encoding::decode_unknown_envelope(decoder, next_offset, depth)?;
1511                _next_ordinal_to_read += 1;
1512                next_offset += envelope_size;
1513            }
1514
1515            let next_out_of_line = decoder.next_out_of_line();
1516            let handles_before = decoder.remaining_handles();
1517            if let Some((inlined, num_bytes, num_handles)) =
1518                fidl::encoding::decode_envelope_header(decoder, next_offset)?
1519            {
1520                let member_inline_size = <fidl_fuchsia_ui_views::ViewportCreationToken as fidl::encoding::TypeMarker>::inline_size(decoder.context);
1521                if inlined != (member_inline_size <= 4) {
1522                    return Err(fidl::Error::InvalidInlineBitInEnvelope);
1523                }
1524                let inner_offset;
1525                let mut inner_depth = depth.clone();
1526                if inlined {
1527                    decoder.check_inline_envelope_padding(next_offset, member_inline_size)?;
1528                    inner_offset = next_offset;
1529                } else {
1530                    inner_offset = decoder.out_of_line_offset(member_inline_size)?;
1531                    inner_depth.increment()?;
1532                }
1533                let val_ref = self.viewport_creation_token.get_or_insert_with(|| {
1534                    fidl::new_empty!(
1535                        fidl_fuchsia_ui_views::ViewportCreationToken,
1536                        fidl::encoding::DefaultFuchsiaResourceDialect
1537                    )
1538                });
1539                fidl::decode!(
1540                    fidl_fuchsia_ui_views::ViewportCreationToken,
1541                    fidl::encoding::DefaultFuchsiaResourceDialect,
1542                    val_ref,
1543                    decoder,
1544                    inner_offset,
1545                    inner_depth
1546                )?;
1547                if !inlined && decoder.next_out_of_line() != next_out_of_line + (num_bytes as usize)
1548                {
1549                    return Err(fidl::Error::InvalidNumBytesInEnvelope);
1550                }
1551                if handles_before != decoder.remaining_handles() + (num_handles as usize) {
1552                    return Err(fidl::Error::InvalidNumHandlesInEnvelope);
1553                }
1554            }
1555
1556            next_offset += envelope_size;
1557
1558            // Decode the remaining unknown envelopes.
1559            while next_offset < end_offset {
1560                _next_ordinal_to_read += 1;
1561                fidl::encoding::decode_unknown_envelope(decoder, next_offset, depth)?;
1562                next_offset += envelope_size;
1563            }
1564
1565            Ok(())
1566        }
1567    }
1568}