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