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