fidl_fuchsia_ui_pointerinjector/
fidl_fuchsia_ui_pointerinjector.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_pointerinjector_common::*;
11use futures::future::{self, MaybeDone, TryFutureExt};
12use zx_status;
13
14#[derive(Debug, PartialEq)]
15pub struct RegistryRegisterRequest {
16    pub config: Config,
17    pub injector: fidl::endpoints::ServerEnd<DeviceMarker>,
18}
19
20impl fidl::Standalone<fidl::encoding::DefaultFuchsiaResourceDialect> for RegistryRegisterRequest {}
21
22/// A specification for an injector |Device|.
23///
24/// All fields required.
25#[derive(Debug, Default, PartialEq)]
26pub struct Config {
27    /// An identifier for the pointer device that issues pointer event streams.
28    pub device_id: Option<u32>,
29    /// A characterization of the pointer device.
30    pub device_type: Option<DeviceType>,
31    /// The scope and coordinate system of the injector |Device|.
32    ///
33    /// Note: To avoid circular injection scenarios, |context| must be a
34    ///       strict ancestor of |target|.
35    pub context: Option<Context>,
36    /// The region where dispatch is attempted for injected events.
37    ///
38    /// Note: To avoid circular injection scenarios, |target| must be a strict
39    ///       descendant of |context|.
40    pub target: Option<Target>,
41    /// The initial viewport for injected events. Subsequent modifications to
42    /// the viewport can also be sent synchronously with injected events.
43    pub viewport: Option<Viewport>,
44    /// A specification of the UI clients in |target| that may have injected
45    /// events dispatched to them.
46    ///
47    /// For example, if |dispatch_policy| is |EXCLUSIVE|, then only |target| may
48    /// have injected events dispatched to it, regardless of other factors, such
49    /// as surface occlusion by clients inside and outside of |target|.
50    pub dispatch_policy: Option<DispatchPolicy>,
51    /// Range of vertical scroll values issued by the device.
52    pub scroll_v_range: Option<fidl_fuchsia_input_report::Axis>,
53    /// Range of horizontal scroll values issued by the device.
54    pub scroll_h_range: Option<fidl_fuchsia_input_report::Axis>,
55    /// Mouse button identifiers issued by the device, in priority order.
56    ///
57    /// The priority order of mouse buttons is a policy choice enacted by the injector.
58    /// This priority order is conveyed verbatim to UI clients via
59    /// [`fuchsia.ui.pointer.MouseDeviceInfo.buttons`], so button priority is shared consistently
60    /// between multiple UI clients. For example, to swap the left-side (0x1) and right-side (0x2)
61    /// physical buttons from their traditional roles of primary and secondary mouse buttons, the
62    /// injector can specify [0x2, 0x1, ... ] in this [`buttons`] vector.
63    ///
64    /// Note that preserving the physical button ID is also a policy choice. If preserved, a
65    /// discerning UI client can distinguish between the ground truth (which physical button was
66    /// pressed) versus the desired interpretation (what priority does that physical button have, on
67    /// the current system).
68    pub buttons: Option<Vec<u8>>,
69    /// Range of X and Y motion by a mouse device.
70    pub relative_motion_range: Option<[fidl_fuchsia_input_report::Axis; 2]>,
71    #[doc(hidden)]
72    pub __source_breaking: fidl::marker::SourceBreaking,
73}
74
75impl fidl::Standalone<fidl::encoding::DefaultFuchsiaResourceDialect> for Config {}
76
77/// The region from which injection is attempted for injected events. As the
78/// context, it serves two purposes:
79/// (1) Scoping. It confirms the |Device|'s authority to inject pointer events
80///     on the specified target. Specifically, the context must be a view-tree
81///     ancestor of the target.
82/// (2) Coordinate System. It provides the reference coordinate system to define
83///     the viewport's position and size, relative to the target.
84#[derive(Debug, PartialEq)]
85pub enum Context {
86    /// A Scenic view from which injection is attempted for injected events.
87    /// - This view must be connected to the scene graph for injection.
88    /// - Injected events are confined to this view and its sub-views.
89    View(fidl_fuchsia_ui_views::ViewRef),
90}
91
92impl Context {
93    #[inline]
94    pub fn ordinal(&self) -> u64 {
95        match *self {
96            Self::View(_) => 1,
97        }
98    }
99
100    #[deprecated = "Strict unions should not use `is_unknown`"]
101    #[inline]
102    pub fn is_unknown(&self) -> bool {
103        false
104    }
105}
106
107impl fidl::Standalone<fidl::encoding::DefaultFuchsiaResourceDialect> for Context {}
108
109/// The region in which dispatch is attempted for injected events.
110/// The particular dispatch policy is specified in |Config|.
111#[derive(Debug, PartialEq)]
112pub enum Target {
113    /// A Scenic view in which dispatch is attempted for injected events.
114    /// - This view must be connected to the scene graph for dispatch.
115    /// - Injected events are confined to this view and its sub-views.
116    View(fidl_fuchsia_ui_views::ViewRef),
117}
118
119impl Target {
120    #[inline]
121    pub fn ordinal(&self) -> u64 {
122        match *self {
123            Self::View(_) => 1,
124        }
125    }
126
127    #[deprecated = "Strict unions should not use `is_unknown`"]
128    #[inline]
129    pub fn is_unknown(&self) -> bool {
130        false
131    }
132}
133
134impl fidl::Standalone<fidl::encoding::DefaultFuchsiaResourceDialect> for Target {}
135
136#[derive(Debug, Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Hash)]
137pub struct DeviceMarker;
138
139impl fidl::endpoints::ProtocolMarker for DeviceMarker {
140    type Proxy = DeviceProxy;
141    type RequestStream = DeviceRequestStream;
142    #[cfg(target_os = "fuchsia")]
143    type SynchronousProxy = DeviceSynchronousProxy;
144
145    const DEBUG_NAME: &'static str = "(anonymous) Device";
146}
147
148pub trait DeviceProxyInterface: Send + Sync {
149    type InjectResponseFut: std::future::Future<Output = Result<(), fidl::Error>> + Send;
150    fn r#inject(&self, events: &[Event]) -> Self::InjectResponseFut;
151}
152#[derive(Debug)]
153#[cfg(target_os = "fuchsia")]
154pub struct DeviceSynchronousProxy {
155    client: fidl::client::sync::Client,
156}
157
158#[cfg(target_os = "fuchsia")]
159impl fidl::endpoints::SynchronousProxy for DeviceSynchronousProxy {
160    type Proxy = DeviceProxy;
161    type Protocol = DeviceMarker;
162
163    fn from_channel(inner: fidl::Channel) -> Self {
164        Self::new(inner)
165    }
166
167    fn into_channel(self) -> fidl::Channel {
168        self.client.into_channel()
169    }
170
171    fn as_channel(&self) -> &fidl::Channel {
172        self.client.as_channel()
173    }
174}
175
176#[cfg(target_os = "fuchsia")]
177impl DeviceSynchronousProxy {
178    pub fn new(channel: fidl::Channel) -> Self {
179        let protocol_name = <DeviceMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME;
180        Self { client: fidl::client::sync::Client::new(channel, protocol_name) }
181    }
182
183    pub fn into_channel(self) -> fidl::Channel {
184        self.client.into_channel()
185    }
186
187    /// Waits until an event arrives and returns it. It is safe for other
188    /// threads to make concurrent requests while waiting for an event.
189    pub fn wait_for_event(
190        &self,
191        deadline: zx::MonotonicInstant,
192    ) -> Result<DeviceEvent, fidl::Error> {
193        DeviceEvent::decode(self.client.wait_for_event(deadline)?)
194    }
195
196    /// Injects events into a target.
197    ///
198    /// Batching: The caller is expected to batch-inject all events that share the
199    /// same timestamp (e.g., multiple finger samples). There may be multiple such
200    /// batches per injection call.
201    ///
202    /// Flow control: The caller is allowed at most one in-flight |Inject| call
203    /// at at time: subsequent |Inject| calls must wait until the acknowledgment
204    /// returns. Non-compliance results in channel closure.
205    pub fn r#inject(
206        &self,
207        mut events: &[Event],
208        ___deadline: zx::MonotonicInstant,
209    ) -> Result<(), fidl::Error> {
210        let _response =
211            self.client.send_query::<DeviceInjectRequest, fidl::encoding::EmptyPayload>(
212                (events,),
213                0x123882bb65bff40,
214                fidl::encoding::DynamicFlags::empty(),
215                ___deadline,
216            )?;
217        Ok(_response)
218    }
219}
220
221#[derive(Debug, Clone)]
222pub struct DeviceProxy {
223    client: fidl::client::Client<fidl::encoding::DefaultFuchsiaResourceDialect>,
224}
225
226impl fidl::endpoints::Proxy for DeviceProxy {
227    type Protocol = DeviceMarker;
228
229    fn from_channel(inner: ::fidl::AsyncChannel) -> Self {
230        Self::new(inner)
231    }
232
233    fn into_channel(self) -> Result<::fidl::AsyncChannel, Self> {
234        self.client.into_channel().map_err(|client| Self { client })
235    }
236
237    fn as_channel(&self) -> &::fidl::AsyncChannel {
238        self.client.as_channel()
239    }
240}
241
242impl DeviceProxy {
243    /// Create a new Proxy for fuchsia.ui.pointerinjector/Device.
244    pub fn new(channel: ::fidl::AsyncChannel) -> Self {
245        let protocol_name = <DeviceMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME;
246        Self { client: fidl::client::Client::new(channel, protocol_name) }
247    }
248
249    /// Get a Stream of events from the remote end of the protocol.
250    ///
251    /// # Panics
252    ///
253    /// Panics if the event stream was already taken.
254    pub fn take_event_stream(&self) -> DeviceEventStream {
255        DeviceEventStream { event_receiver: self.client.take_event_receiver() }
256    }
257
258    /// Injects events into a target.
259    ///
260    /// Batching: The caller is expected to batch-inject all events that share the
261    /// same timestamp (e.g., multiple finger samples). There may be multiple such
262    /// batches per injection call.
263    ///
264    /// Flow control: The caller is allowed at most one in-flight |Inject| call
265    /// at at time: subsequent |Inject| calls must wait until the acknowledgment
266    /// returns. Non-compliance results in channel closure.
267    pub fn r#inject(
268        &self,
269        mut events: &[Event],
270    ) -> fidl::client::QueryResponseFut<(), fidl::encoding::DefaultFuchsiaResourceDialect> {
271        DeviceProxyInterface::r#inject(self, events)
272    }
273}
274
275impl DeviceProxyInterface for DeviceProxy {
276    type InjectResponseFut =
277        fidl::client::QueryResponseFut<(), fidl::encoding::DefaultFuchsiaResourceDialect>;
278    fn r#inject(&self, mut events: &[Event]) -> Self::InjectResponseFut {
279        fn _decode(
280            mut _buf: Result<<fidl::encoding::DefaultFuchsiaResourceDialect as fidl::encoding::ResourceDialect>::MessageBufEtc, fidl::Error>,
281        ) -> Result<(), fidl::Error> {
282            let _response = fidl::client::decode_transaction_body::<
283                fidl::encoding::EmptyPayload,
284                fidl::encoding::DefaultFuchsiaResourceDialect,
285                0x123882bb65bff40,
286            >(_buf?)?;
287            Ok(_response)
288        }
289        self.client.send_query_and_decode::<DeviceInjectRequest, ()>(
290            (events,),
291            0x123882bb65bff40,
292            fidl::encoding::DynamicFlags::empty(),
293            _decode,
294        )
295    }
296}
297
298pub struct DeviceEventStream {
299    event_receiver: fidl::client::EventReceiver<fidl::encoding::DefaultFuchsiaResourceDialect>,
300}
301
302impl std::marker::Unpin for DeviceEventStream {}
303
304impl futures::stream::FusedStream for DeviceEventStream {
305    fn is_terminated(&self) -> bool {
306        self.event_receiver.is_terminated()
307    }
308}
309
310impl futures::Stream for DeviceEventStream {
311    type Item = Result<DeviceEvent, fidl::Error>;
312
313    fn poll_next(
314        mut self: std::pin::Pin<&mut Self>,
315        cx: &mut std::task::Context<'_>,
316    ) -> std::task::Poll<Option<Self::Item>> {
317        match futures::ready!(futures::stream::StreamExt::poll_next_unpin(
318            &mut self.event_receiver,
319            cx
320        )?) {
321            Some(buf) => std::task::Poll::Ready(Some(DeviceEvent::decode(buf))),
322            None => std::task::Poll::Ready(None),
323        }
324    }
325}
326
327#[derive(Debug)]
328pub enum DeviceEvent {}
329
330impl DeviceEvent {
331    /// Decodes a message buffer as a [`DeviceEvent`].
332    fn decode(
333        mut buf: <fidl::encoding::DefaultFuchsiaResourceDialect as fidl::encoding::ResourceDialect>::MessageBufEtc,
334    ) -> Result<DeviceEvent, fidl::Error> {
335        let (bytes, _handles) = buf.split_mut();
336        let (tx_header, _body_bytes) = fidl::encoding::decode_transaction_header(bytes)?;
337        debug_assert_eq!(tx_header.tx_id, 0);
338        match tx_header.ordinal {
339            _ => Err(fidl::Error::UnknownOrdinal {
340                ordinal: tx_header.ordinal,
341                protocol_name: <DeviceMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME,
342            }),
343        }
344    }
345}
346
347/// A Stream of incoming requests for fuchsia.ui.pointerinjector/Device.
348pub struct DeviceRequestStream {
349    inner: std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>,
350    is_terminated: bool,
351}
352
353impl std::marker::Unpin for DeviceRequestStream {}
354
355impl futures::stream::FusedStream for DeviceRequestStream {
356    fn is_terminated(&self) -> bool {
357        self.is_terminated
358    }
359}
360
361impl fidl::endpoints::RequestStream for DeviceRequestStream {
362    type Protocol = DeviceMarker;
363    type ControlHandle = DeviceControlHandle;
364
365    fn from_channel(channel: ::fidl::AsyncChannel) -> Self {
366        Self { inner: std::sync::Arc::new(fidl::ServeInner::new(channel)), is_terminated: false }
367    }
368
369    fn control_handle(&self) -> Self::ControlHandle {
370        DeviceControlHandle { inner: self.inner.clone() }
371    }
372
373    fn into_inner(
374        self,
375    ) -> (::std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>, bool)
376    {
377        (self.inner, self.is_terminated)
378    }
379
380    fn from_inner(
381        inner: std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>,
382        is_terminated: bool,
383    ) -> Self {
384        Self { inner, is_terminated }
385    }
386}
387
388impl futures::Stream for DeviceRequestStream {
389    type Item = Result<DeviceRequest, fidl::Error>;
390
391    fn poll_next(
392        mut self: std::pin::Pin<&mut Self>,
393        cx: &mut std::task::Context<'_>,
394    ) -> std::task::Poll<Option<Self::Item>> {
395        let this = &mut *self;
396        if this.inner.check_shutdown(cx) {
397            this.is_terminated = true;
398            return std::task::Poll::Ready(None);
399        }
400        if this.is_terminated {
401            panic!("polled DeviceRequestStream after completion");
402        }
403        fidl::encoding::with_tls_decode_buf::<_, fidl::encoding::DefaultFuchsiaResourceDialect>(
404            |bytes, handles| {
405                match this.inner.channel().read_etc(cx, bytes, handles) {
406                    std::task::Poll::Ready(Ok(())) => {}
407                    std::task::Poll::Pending => return std::task::Poll::Pending,
408                    std::task::Poll::Ready(Err(zx_status::Status::PEER_CLOSED)) => {
409                        this.is_terminated = true;
410                        return std::task::Poll::Ready(None);
411                    }
412                    std::task::Poll::Ready(Err(e)) => {
413                        return std::task::Poll::Ready(Some(Err(fidl::Error::ServerRequestRead(
414                            e.into(),
415                        ))))
416                    }
417                }
418
419                // A message has been received from the channel
420                let (header, _body_bytes) = fidl::encoding::decode_transaction_header(bytes)?;
421
422                std::task::Poll::Ready(Some(match header.ordinal {
423                    0x123882bb65bff40 => {
424                        header.validate_request_tx_id(fidl::MethodType::TwoWay)?;
425                        let mut req = fidl::new_empty!(
426                            DeviceInjectRequest,
427                            fidl::encoding::DefaultFuchsiaResourceDialect
428                        );
429                        fidl::encoding::Decoder::<fidl::encoding::DefaultFuchsiaResourceDialect>::decode_into::<DeviceInjectRequest>(&header, _body_bytes, handles, &mut req)?;
430                        let control_handle = DeviceControlHandle { inner: this.inner.clone() };
431                        Ok(DeviceRequest::Inject {
432                            events: req.events,
433
434                            responder: DeviceInjectResponder {
435                                control_handle: std::mem::ManuallyDrop::new(control_handle),
436                                tx_id: header.tx_id,
437                            },
438                        })
439                    }
440                    _ => Err(fidl::Error::UnknownOrdinal {
441                        ordinal: header.ordinal,
442                        protocol_name:
443                            <DeviceMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME,
444                    }),
445                }))
446            },
447        )
448    }
449}
450
451/// The channel for injecting pointer events into a target.
452/// The associated |Config| applies to injected pointer events.
453///
454/// A |Device| may *inject* pointer events into a target in the scene, but the
455/// *dispatch* of pointer events to UI clients within that target's view tree
456/// will depend on the dispatch policy and the scene topology.
457#[derive(Debug)]
458pub enum DeviceRequest {
459    /// Injects events into a target.
460    ///
461    /// Batching: The caller is expected to batch-inject all events that share the
462    /// same timestamp (e.g., multiple finger samples). There may be multiple such
463    /// batches per injection call.
464    ///
465    /// Flow control: The caller is allowed at most one in-flight |Inject| call
466    /// at at time: subsequent |Inject| calls must wait until the acknowledgment
467    /// returns. Non-compliance results in channel closure.
468    Inject { events: Vec<Event>, responder: DeviceInjectResponder },
469}
470
471impl DeviceRequest {
472    #[allow(irrefutable_let_patterns)]
473    pub fn into_inject(self) -> Option<(Vec<Event>, DeviceInjectResponder)> {
474        if let DeviceRequest::Inject { events, responder } = self {
475            Some((events, responder))
476        } else {
477            None
478        }
479    }
480
481    /// Name of the method defined in FIDL
482    pub fn method_name(&self) -> &'static str {
483        match *self {
484            DeviceRequest::Inject { .. } => "inject",
485        }
486    }
487}
488
489#[derive(Debug, Clone)]
490pub struct DeviceControlHandle {
491    inner: std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>,
492}
493
494impl fidl::endpoints::ControlHandle for DeviceControlHandle {
495    fn shutdown(&self) {
496        self.inner.shutdown()
497    }
498    fn shutdown_with_epitaph(&self, status: zx_status::Status) {
499        self.inner.shutdown_with_epitaph(status)
500    }
501
502    fn is_closed(&self) -> bool {
503        self.inner.channel().is_closed()
504    }
505    fn on_closed(&self) -> fidl::OnSignalsRef<'_> {
506        self.inner.channel().on_closed()
507    }
508
509    #[cfg(target_os = "fuchsia")]
510    fn signal_peer(
511        &self,
512        clear_mask: zx::Signals,
513        set_mask: zx::Signals,
514    ) -> Result<(), zx_status::Status> {
515        use fidl::Peered;
516        self.inner.channel().signal_peer(clear_mask, set_mask)
517    }
518}
519
520impl DeviceControlHandle {}
521
522#[must_use = "FIDL methods require a response to be sent"]
523#[derive(Debug)]
524pub struct DeviceInjectResponder {
525    control_handle: std::mem::ManuallyDrop<DeviceControlHandle>,
526    tx_id: u32,
527}
528
529/// Set the the channel to be shutdown (see [`DeviceControlHandle::shutdown`])
530/// if the responder is dropped without sending a response, so that the client
531/// doesn't hang. To prevent this behavior, call `drop_without_shutdown`.
532impl std::ops::Drop for DeviceInjectResponder {
533    fn drop(&mut self) {
534        self.control_handle.shutdown();
535        // Safety: drops once, never accessed again
536        unsafe { std::mem::ManuallyDrop::drop(&mut self.control_handle) };
537    }
538}
539
540impl fidl::endpoints::Responder for DeviceInjectResponder {
541    type ControlHandle = DeviceControlHandle;
542
543    fn control_handle(&self) -> &DeviceControlHandle {
544        &self.control_handle
545    }
546
547    fn drop_without_shutdown(mut self) {
548        // Safety: drops once, never accessed again due to mem::forget
549        unsafe { std::mem::ManuallyDrop::drop(&mut self.control_handle) };
550        // Prevent Drop from running (which would shut down the channel)
551        std::mem::forget(self);
552    }
553}
554
555impl DeviceInjectResponder {
556    /// Sends a response to the FIDL transaction.
557    ///
558    /// Sets the channel to shutdown if an error occurs.
559    pub fn send(self) -> Result<(), fidl::Error> {
560        let _result = self.send_raw();
561        if _result.is_err() {
562            self.control_handle.shutdown();
563        }
564        self.drop_without_shutdown();
565        _result
566    }
567
568    /// Similar to "send" but does not shutdown the channel if an error occurs.
569    pub fn send_no_shutdown_on_err(self) -> Result<(), fidl::Error> {
570        let _result = self.send_raw();
571        self.drop_without_shutdown();
572        _result
573    }
574
575    fn send_raw(&self) -> Result<(), fidl::Error> {
576        self.control_handle.inner.send::<fidl::encoding::EmptyPayload>(
577            (),
578            self.tx_id,
579            0x123882bb65bff40,
580            fidl::encoding::DynamicFlags::empty(),
581        )
582    }
583}
584
585#[derive(Debug, Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Hash)]
586pub struct RegistryMarker;
587
588impl fidl::endpoints::ProtocolMarker for RegistryMarker {
589    type Proxy = RegistryProxy;
590    type RequestStream = RegistryRequestStream;
591    #[cfg(target_os = "fuchsia")]
592    type SynchronousProxy = RegistrySynchronousProxy;
593
594    const DEBUG_NAME: &'static str = "fuchsia.ui.pointerinjector.Registry";
595}
596impl fidl::endpoints::DiscoverableProtocolMarker for RegistryMarker {}
597
598pub trait RegistryProxyInterface: Send + Sync {
599    type RegisterResponseFut: std::future::Future<Output = Result<(), fidl::Error>> + Send;
600    fn r#register(
601        &self,
602        config: Config,
603        injector: fidl::endpoints::ServerEnd<DeviceMarker>,
604    ) -> Self::RegisterResponseFut;
605}
606#[derive(Debug)]
607#[cfg(target_os = "fuchsia")]
608pub struct RegistrySynchronousProxy {
609    client: fidl::client::sync::Client,
610}
611
612#[cfg(target_os = "fuchsia")]
613impl fidl::endpoints::SynchronousProxy for RegistrySynchronousProxy {
614    type Proxy = RegistryProxy;
615    type Protocol = RegistryMarker;
616
617    fn from_channel(inner: fidl::Channel) -> Self {
618        Self::new(inner)
619    }
620
621    fn into_channel(self) -> fidl::Channel {
622        self.client.into_channel()
623    }
624
625    fn as_channel(&self) -> &fidl::Channel {
626        self.client.as_channel()
627    }
628}
629
630#[cfg(target_os = "fuchsia")]
631impl RegistrySynchronousProxy {
632    pub fn new(channel: fidl::Channel) -> Self {
633        let protocol_name = <RegistryMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME;
634        Self { client: fidl::client::sync::Client::new(channel, protocol_name) }
635    }
636
637    pub fn into_channel(self) -> fidl::Channel {
638        self.client.into_channel()
639    }
640
641    /// Waits until an event arrives and returns it. It is safe for other
642    /// threads to make concurrent requests while waiting for an event.
643    pub fn wait_for_event(
644        &self,
645        deadline: zx::MonotonicInstant,
646    ) -> Result<RegistryEvent, fidl::Error> {
647        RegistryEvent::decode(self.client.wait_for_event(deadline)?)
648    }
649
650    /// Sets up a context for a |Device|, the target for the |Device|, and
651    /// directs the |Device| at the target via a viewport, positioned in the
652    /// context. These parameters are specified in a |Config|.
653    ///
654    /// If |config| is invalid (e.g., missing important data), the |Device|
655    /// request will be denied: the channel will be closed.
656    ///
657    /// The return event tells the caller that (1) the server has processed the
658    /// call, and (2) the |Device| is connected.
659    pub fn r#register(
660        &self,
661        mut config: Config,
662        mut injector: fidl::endpoints::ServerEnd<DeviceMarker>,
663        ___deadline: zx::MonotonicInstant,
664    ) -> Result<(), fidl::Error> {
665        let _response =
666            self.client.send_query::<RegistryRegisterRequest, fidl::encoding::EmptyPayload>(
667                (&mut config, injector),
668                0x9f8410fe7326a00,
669                fidl::encoding::DynamicFlags::empty(),
670                ___deadline,
671            )?;
672        Ok(_response)
673    }
674}
675
676#[derive(Debug, Clone)]
677pub struct RegistryProxy {
678    client: fidl::client::Client<fidl::encoding::DefaultFuchsiaResourceDialect>,
679}
680
681impl fidl::endpoints::Proxy for RegistryProxy {
682    type Protocol = RegistryMarker;
683
684    fn from_channel(inner: ::fidl::AsyncChannel) -> Self {
685        Self::new(inner)
686    }
687
688    fn into_channel(self) -> Result<::fidl::AsyncChannel, Self> {
689        self.client.into_channel().map_err(|client| Self { client })
690    }
691
692    fn as_channel(&self) -> &::fidl::AsyncChannel {
693        self.client.as_channel()
694    }
695}
696
697impl RegistryProxy {
698    /// Create a new Proxy for fuchsia.ui.pointerinjector/Registry.
699    pub fn new(channel: ::fidl::AsyncChannel) -> Self {
700        let protocol_name = <RegistryMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME;
701        Self { client: fidl::client::Client::new(channel, protocol_name) }
702    }
703
704    /// Get a Stream of events from the remote end of the protocol.
705    ///
706    /// # Panics
707    ///
708    /// Panics if the event stream was already taken.
709    pub fn take_event_stream(&self) -> RegistryEventStream {
710        RegistryEventStream { event_receiver: self.client.take_event_receiver() }
711    }
712
713    /// Sets up a context for a |Device|, the target for the |Device|, and
714    /// directs the |Device| at the target via a viewport, positioned in the
715    /// context. These parameters are specified in a |Config|.
716    ///
717    /// If |config| is invalid (e.g., missing important data), the |Device|
718    /// request will be denied: the channel will be closed.
719    ///
720    /// The return event tells the caller that (1) the server has processed the
721    /// call, and (2) the |Device| is connected.
722    pub fn r#register(
723        &self,
724        mut config: Config,
725        mut injector: fidl::endpoints::ServerEnd<DeviceMarker>,
726    ) -> fidl::client::QueryResponseFut<(), fidl::encoding::DefaultFuchsiaResourceDialect> {
727        RegistryProxyInterface::r#register(self, config, injector)
728    }
729}
730
731impl RegistryProxyInterface for RegistryProxy {
732    type RegisterResponseFut =
733        fidl::client::QueryResponseFut<(), fidl::encoding::DefaultFuchsiaResourceDialect>;
734    fn r#register(
735        &self,
736        mut config: Config,
737        mut injector: fidl::endpoints::ServerEnd<DeviceMarker>,
738    ) -> Self::RegisterResponseFut {
739        fn _decode(
740            mut _buf: Result<<fidl::encoding::DefaultFuchsiaResourceDialect as fidl::encoding::ResourceDialect>::MessageBufEtc, fidl::Error>,
741        ) -> Result<(), fidl::Error> {
742            let _response = fidl::client::decode_transaction_body::<
743                fidl::encoding::EmptyPayload,
744                fidl::encoding::DefaultFuchsiaResourceDialect,
745                0x9f8410fe7326a00,
746            >(_buf?)?;
747            Ok(_response)
748        }
749        self.client.send_query_and_decode::<RegistryRegisterRequest, ()>(
750            (&mut config, injector),
751            0x9f8410fe7326a00,
752            fidl::encoding::DynamicFlags::empty(),
753            _decode,
754        )
755    }
756}
757
758pub struct RegistryEventStream {
759    event_receiver: fidl::client::EventReceiver<fidl::encoding::DefaultFuchsiaResourceDialect>,
760}
761
762impl std::marker::Unpin for RegistryEventStream {}
763
764impl futures::stream::FusedStream for RegistryEventStream {
765    fn is_terminated(&self) -> bool {
766        self.event_receiver.is_terminated()
767    }
768}
769
770impl futures::Stream for RegistryEventStream {
771    type Item = Result<RegistryEvent, fidl::Error>;
772
773    fn poll_next(
774        mut self: std::pin::Pin<&mut Self>,
775        cx: &mut std::task::Context<'_>,
776    ) -> std::task::Poll<Option<Self::Item>> {
777        match futures::ready!(futures::stream::StreamExt::poll_next_unpin(
778            &mut self.event_receiver,
779            cx
780        )?) {
781            Some(buf) => std::task::Poll::Ready(Some(RegistryEvent::decode(buf))),
782            None => std::task::Poll::Ready(None),
783        }
784    }
785}
786
787#[derive(Debug)]
788pub enum RegistryEvent {}
789
790impl RegistryEvent {
791    /// Decodes a message buffer as a [`RegistryEvent`].
792    fn decode(
793        mut buf: <fidl::encoding::DefaultFuchsiaResourceDialect as fidl::encoding::ResourceDialect>::MessageBufEtc,
794    ) -> Result<RegistryEvent, fidl::Error> {
795        let (bytes, _handles) = buf.split_mut();
796        let (tx_header, _body_bytes) = fidl::encoding::decode_transaction_header(bytes)?;
797        debug_assert_eq!(tx_header.tx_id, 0);
798        match tx_header.ordinal {
799            _ => Err(fidl::Error::UnknownOrdinal {
800                ordinal: tx_header.ordinal,
801                protocol_name: <RegistryMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME,
802            }),
803        }
804    }
805}
806
807/// A Stream of incoming requests for fuchsia.ui.pointerinjector/Registry.
808pub struct RegistryRequestStream {
809    inner: std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>,
810    is_terminated: bool,
811}
812
813impl std::marker::Unpin for RegistryRequestStream {}
814
815impl futures::stream::FusedStream for RegistryRequestStream {
816    fn is_terminated(&self) -> bool {
817        self.is_terminated
818    }
819}
820
821impl fidl::endpoints::RequestStream for RegistryRequestStream {
822    type Protocol = RegistryMarker;
823    type ControlHandle = RegistryControlHandle;
824
825    fn from_channel(channel: ::fidl::AsyncChannel) -> Self {
826        Self { inner: std::sync::Arc::new(fidl::ServeInner::new(channel)), is_terminated: false }
827    }
828
829    fn control_handle(&self) -> Self::ControlHandle {
830        RegistryControlHandle { inner: self.inner.clone() }
831    }
832
833    fn into_inner(
834        self,
835    ) -> (::std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>, bool)
836    {
837        (self.inner, self.is_terminated)
838    }
839
840    fn from_inner(
841        inner: std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>,
842        is_terminated: bool,
843    ) -> Self {
844        Self { inner, is_terminated }
845    }
846}
847
848impl futures::Stream for RegistryRequestStream {
849    type Item = Result<RegistryRequest, fidl::Error>;
850
851    fn poll_next(
852        mut self: std::pin::Pin<&mut Self>,
853        cx: &mut std::task::Context<'_>,
854    ) -> std::task::Poll<Option<Self::Item>> {
855        let this = &mut *self;
856        if this.inner.check_shutdown(cx) {
857            this.is_terminated = true;
858            return std::task::Poll::Ready(None);
859        }
860        if this.is_terminated {
861            panic!("polled RegistryRequestStream after completion");
862        }
863        fidl::encoding::with_tls_decode_buf::<_, fidl::encoding::DefaultFuchsiaResourceDialect>(
864            |bytes, handles| {
865                match this.inner.channel().read_etc(cx, bytes, handles) {
866                    std::task::Poll::Ready(Ok(())) => {}
867                    std::task::Poll::Pending => return std::task::Poll::Pending,
868                    std::task::Poll::Ready(Err(zx_status::Status::PEER_CLOSED)) => {
869                        this.is_terminated = true;
870                        return std::task::Poll::Ready(None);
871                    }
872                    std::task::Poll::Ready(Err(e)) => {
873                        return std::task::Poll::Ready(Some(Err(fidl::Error::ServerRequestRead(
874                            e.into(),
875                        ))))
876                    }
877                }
878
879                // A message has been received from the channel
880                let (header, _body_bytes) = fidl::encoding::decode_transaction_header(bytes)?;
881
882                std::task::Poll::Ready(Some(match header.ordinal {
883                    0x9f8410fe7326a00 => {
884                        header.validate_request_tx_id(fidl::MethodType::TwoWay)?;
885                        let mut req = fidl::new_empty!(
886                            RegistryRegisterRequest,
887                            fidl::encoding::DefaultFuchsiaResourceDialect
888                        );
889                        fidl::encoding::Decoder::<fidl::encoding::DefaultFuchsiaResourceDialect>::decode_into::<RegistryRegisterRequest>(&header, _body_bytes, handles, &mut req)?;
890                        let control_handle = RegistryControlHandle { inner: this.inner.clone() };
891                        Ok(RegistryRequest::Register {
892                            config: req.config,
893                            injector: req.injector,
894
895                            responder: RegistryRegisterResponder {
896                                control_handle: std::mem::ManuallyDrop::new(control_handle),
897                                tx_id: header.tx_id,
898                            },
899                        })
900                    }
901                    _ => Err(fidl::Error::UnknownOrdinal {
902                        ordinal: header.ordinal,
903                        protocol_name:
904                            <RegistryMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME,
905                    }),
906                }))
907            },
908        )
909    }
910}
911
912/// A coordination mechanism to clearly define the *injecting* of pointer events
913/// into the scene (injection policy, injection context, etc), for *dispatching*
914/// pointer events to UI clients (referenced by |fuchsia.ui.views.ViewRef|).
915///
916/// NOTE WELL! ONLY COMPONENTS IN THE TRUSTED COMPUTING BASE SHOULD BE GRANTED
917///            ACCESS TO THIS PROTOCOL.
918/// (1) The injector device acts with the user's authority. UI clients cannot
919///     tell the difference between a real user and an injector device.
920/// (2) The context is self-specified when registering the injector device. An
921///     injector device that gains access to a sensitive context will operate in
922///     that scope.
923/// (3) The injected events may be arbitrary. An injector device can inject
924///     whatever it wants to the clients it can reach.
925///
926/// This protocol defines the context and target for an injector |Device|,
927/// places a viewport in spatial relation to the target, and connects the
928/// |Device| to the viewport. These parameters are set up in the |Config|. A
929/// |Device| may *inject* pointer events on the viewport, but the *dispatch* of
930/// pointer events to UI clients in the target will depend on the dispatch
931/// policy and the scene topology.
932///
933/// A |Device| operates within a context, and it serves two purposes:
934/// (1) Scoping. It confirms the |Device|'s authority to inject pointer events
935///     on the specified target.
936/// (2) Coordinate system. It provides the reference coordinate system to define
937///     the viewport's position and size, relative to the target.
938///
939/// Guarantees. A |Device| is directed at a specified target in the scene, and
940/// such a target is afforded some guarantees against snooping and interference
941/// from UI clients outside the target's view tree ("non-target clients").
942/// Non-target clients never have injected events dispatched to them: a |Device|
943/// preserves *confidentiality* for target clients.  Non-target clients never
944/// block injected events from reaching the target on injection, or from
945/// reaching target clients on dispatch: a |Device| preserves *integrity* and
946/// *availability* for target clients. However, the |Device| itself is subject
947/// to disruption by ancestor views of the target (see connectivity invariant).
948///
949/// Note. This protocol, and its policies, are *not* a sufficient guard against
950///       UI redress attacks! The confidentiality, integrity, and availability
951///       guarantees apply only with respect to non-target clients. Within a
952///       target, UI redress attacks can still happen, between target clients.
953///
954/// Connectivity invariant. A |Device| operates in a stable view tree that is
955/// connected to the root view. When either the target, or both context and
956/// target, are disconnected from the view tree by a UI client, the |Device|
957/// channel is closed. If an event stream was in flight, the server dispatches a
958/// final CANCEL event following channel closure; this CANCEL event is then
959/// propagated according to dispatch policy.
960#[derive(Debug)]
961pub enum RegistryRequest {
962    /// Sets up a context for a |Device|, the target for the |Device|, and
963    /// directs the |Device| at the target via a viewport, positioned in the
964    /// context. These parameters are specified in a |Config|.
965    ///
966    /// If |config| is invalid (e.g., missing important data), the |Device|
967    /// request will be denied: the channel will be closed.
968    ///
969    /// The return event tells the caller that (1) the server has processed the
970    /// call, and (2) the |Device| is connected.
971    Register {
972        config: Config,
973        injector: fidl::endpoints::ServerEnd<DeviceMarker>,
974        responder: RegistryRegisterResponder,
975    },
976}
977
978impl RegistryRequest {
979    #[allow(irrefutable_let_patterns)]
980    pub fn into_register(
981        self,
982    ) -> Option<(Config, fidl::endpoints::ServerEnd<DeviceMarker>, RegistryRegisterResponder)> {
983        if let RegistryRequest::Register { config, injector, responder } = self {
984            Some((config, injector, responder))
985        } else {
986            None
987        }
988    }
989
990    /// Name of the method defined in FIDL
991    pub fn method_name(&self) -> &'static str {
992        match *self {
993            RegistryRequest::Register { .. } => "register",
994        }
995    }
996}
997
998#[derive(Debug, Clone)]
999pub struct RegistryControlHandle {
1000    inner: std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>,
1001}
1002
1003impl fidl::endpoints::ControlHandle for RegistryControlHandle {
1004    fn shutdown(&self) {
1005        self.inner.shutdown()
1006    }
1007    fn shutdown_with_epitaph(&self, status: zx_status::Status) {
1008        self.inner.shutdown_with_epitaph(status)
1009    }
1010
1011    fn is_closed(&self) -> bool {
1012        self.inner.channel().is_closed()
1013    }
1014    fn on_closed(&self) -> fidl::OnSignalsRef<'_> {
1015        self.inner.channel().on_closed()
1016    }
1017
1018    #[cfg(target_os = "fuchsia")]
1019    fn signal_peer(
1020        &self,
1021        clear_mask: zx::Signals,
1022        set_mask: zx::Signals,
1023    ) -> Result<(), zx_status::Status> {
1024        use fidl::Peered;
1025        self.inner.channel().signal_peer(clear_mask, set_mask)
1026    }
1027}
1028
1029impl RegistryControlHandle {}
1030
1031#[must_use = "FIDL methods require a response to be sent"]
1032#[derive(Debug)]
1033pub struct RegistryRegisterResponder {
1034    control_handle: std::mem::ManuallyDrop<RegistryControlHandle>,
1035    tx_id: u32,
1036}
1037
1038/// Set the the channel to be shutdown (see [`RegistryControlHandle::shutdown`])
1039/// if the responder is dropped without sending a response, so that the client
1040/// doesn't hang. To prevent this behavior, call `drop_without_shutdown`.
1041impl std::ops::Drop for RegistryRegisterResponder {
1042    fn drop(&mut self) {
1043        self.control_handle.shutdown();
1044        // Safety: drops once, never accessed again
1045        unsafe { std::mem::ManuallyDrop::drop(&mut self.control_handle) };
1046    }
1047}
1048
1049impl fidl::endpoints::Responder for RegistryRegisterResponder {
1050    type ControlHandle = RegistryControlHandle;
1051
1052    fn control_handle(&self) -> &RegistryControlHandle {
1053        &self.control_handle
1054    }
1055
1056    fn drop_without_shutdown(mut self) {
1057        // Safety: drops once, never accessed again due to mem::forget
1058        unsafe { std::mem::ManuallyDrop::drop(&mut self.control_handle) };
1059        // Prevent Drop from running (which would shut down the channel)
1060        std::mem::forget(self);
1061    }
1062}
1063
1064impl RegistryRegisterResponder {
1065    /// Sends a response to the FIDL transaction.
1066    ///
1067    /// Sets the channel to shutdown if an error occurs.
1068    pub fn send(self) -> Result<(), fidl::Error> {
1069        let _result = self.send_raw();
1070        if _result.is_err() {
1071            self.control_handle.shutdown();
1072        }
1073        self.drop_without_shutdown();
1074        _result
1075    }
1076
1077    /// Similar to "send" but does not shutdown the channel if an error occurs.
1078    pub fn send_no_shutdown_on_err(self) -> Result<(), fidl::Error> {
1079        let _result = self.send_raw();
1080        self.drop_without_shutdown();
1081        _result
1082    }
1083
1084    fn send_raw(&self) -> Result<(), fidl::Error> {
1085        self.control_handle.inner.send::<fidl::encoding::EmptyPayload>(
1086            (),
1087            self.tx_id,
1088            0x9f8410fe7326a00,
1089            fidl::encoding::DynamicFlags::empty(),
1090        )
1091    }
1092}
1093
1094mod internal {
1095    use super::*;
1096
1097    impl fidl::encoding::ResourceTypeMarker for RegistryRegisterRequest {
1098        type Borrowed<'a> = &'a mut Self;
1099        fn take_or_borrow<'a>(
1100            value: &'a mut <Self as fidl::encoding::TypeMarker>::Owned,
1101        ) -> Self::Borrowed<'a> {
1102            value
1103        }
1104    }
1105
1106    unsafe impl fidl::encoding::TypeMarker for RegistryRegisterRequest {
1107        type Owned = Self;
1108
1109        #[inline(always)]
1110        fn inline_align(_context: fidl::encoding::Context) -> usize {
1111            8
1112        }
1113
1114        #[inline(always)]
1115        fn inline_size(_context: fidl::encoding::Context) -> usize {
1116            24
1117        }
1118    }
1119
1120    unsafe impl
1121        fidl::encoding::Encode<
1122            RegistryRegisterRequest,
1123            fidl::encoding::DefaultFuchsiaResourceDialect,
1124        > for &mut RegistryRegisterRequest
1125    {
1126        #[inline]
1127        unsafe fn encode(
1128            self,
1129            encoder: &mut fidl::encoding::Encoder<
1130                '_,
1131                fidl::encoding::DefaultFuchsiaResourceDialect,
1132            >,
1133            offset: usize,
1134            _depth: fidl::encoding::Depth,
1135        ) -> fidl::Result<()> {
1136            encoder.debug_check_bounds::<RegistryRegisterRequest>(offset);
1137            // Delegate to tuple encoding.
1138            fidl::encoding::Encode::<RegistryRegisterRequest, fidl::encoding::DefaultFuchsiaResourceDialect>::encode(
1139                (
1140                    <Config as fidl::encoding::ResourceTypeMarker>::take_or_borrow(&mut self.config),
1141                    <fidl::encoding::Endpoint<fidl::endpoints::ServerEnd<DeviceMarker>> as fidl::encoding::ResourceTypeMarker>::take_or_borrow(&mut self.injector),
1142                ),
1143                encoder, offset, _depth
1144            )
1145        }
1146    }
1147    unsafe impl<
1148            T0: fidl::encoding::Encode<Config, fidl::encoding::DefaultFuchsiaResourceDialect>,
1149            T1: fidl::encoding::Encode<
1150                fidl::encoding::Endpoint<fidl::endpoints::ServerEnd<DeviceMarker>>,
1151                fidl::encoding::DefaultFuchsiaResourceDialect,
1152            >,
1153        >
1154        fidl::encoding::Encode<
1155            RegistryRegisterRequest,
1156            fidl::encoding::DefaultFuchsiaResourceDialect,
1157        > for (T0, T1)
1158    {
1159        #[inline]
1160        unsafe fn encode(
1161            self,
1162            encoder: &mut fidl::encoding::Encoder<
1163                '_,
1164                fidl::encoding::DefaultFuchsiaResourceDialect,
1165            >,
1166            offset: usize,
1167            depth: fidl::encoding::Depth,
1168        ) -> fidl::Result<()> {
1169            encoder.debug_check_bounds::<RegistryRegisterRequest>(offset);
1170            // Zero out padding regions. There's no need to apply masks
1171            // because the unmasked parts will be overwritten by fields.
1172            unsafe {
1173                let ptr = encoder.buf.as_mut_ptr().add(offset).offset(16);
1174                (ptr as *mut u64).write_unaligned(0);
1175            }
1176            // Write the fields.
1177            self.0.encode(encoder, offset + 0, depth)?;
1178            self.1.encode(encoder, offset + 16, depth)?;
1179            Ok(())
1180        }
1181    }
1182
1183    impl fidl::encoding::Decode<Self, fidl::encoding::DefaultFuchsiaResourceDialect>
1184        for RegistryRegisterRequest
1185    {
1186        #[inline(always)]
1187        fn new_empty() -> Self {
1188            Self {
1189                config: fidl::new_empty!(Config, fidl::encoding::DefaultFuchsiaResourceDialect),
1190                injector: fidl::new_empty!(
1191                    fidl::encoding::Endpoint<fidl::endpoints::ServerEnd<DeviceMarker>>,
1192                    fidl::encoding::DefaultFuchsiaResourceDialect
1193                ),
1194            }
1195        }
1196
1197        #[inline]
1198        unsafe fn decode(
1199            &mut self,
1200            decoder: &mut fidl::encoding::Decoder<
1201                '_,
1202                fidl::encoding::DefaultFuchsiaResourceDialect,
1203            >,
1204            offset: usize,
1205            _depth: fidl::encoding::Depth,
1206        ) -> fidl::Result<()> {
1207            decoder.debug_check_bounds::<Self>(offset);
1208            // Verify that padding bytes are zero.
1209            let ptr = unsafe { decoder.buf.as_ptr().add(offset).offset(16) };
1210            let padval = unsafe { (ptr as *const u64).read_unaligned() };
1211            let mask = 0xffffffff00000000u64;
1212            let maskedval = padval & mask;
1213            if maskedval != 0 {
1214                return Err(fidl::Error::NonZeroPadding {
1215                    padding_start: offset + 16 + ((mask as u64).trailing_zeros() / 8) as usize,
1216                });
1217            }
1218            fidl::decode!(
1219                Config,
1220                fidl::encoding::DefaultFuchsiaResourceDialect,
1221                &mut self.config,
1222                decoder,
1223                offset + 0,
1224                _depth
1225            )?;
1226            fidl::decode!(
1227                fidl::encoding::Endpoint<fidl::endpoints::ServerEnd<DeviceMarker>>,
1228                fidl::encoding::DefaultFuchsiaResourceDialect,
1229                &mut self.injector,
1230                decoder,
1231                offset + 16,
1232                _depth
1233            )?;
1234            Ok(())
1235        }
1236    }
1237
1238    impl Config {
1239        #[inline(always)]
1240        fn max_ordinal_present(&self) -> u64 {
1241            if let Some(_) = self.relative_motion_range {
1242                return 10;
1243            }
1244            if let Some(_) = self.buttons {
1245                return 9;
1246            }
1247            if let Some(_) = self.scroll_h_range {
1248                return 8;
1249            }
1250            if let Some(_) = self.scroll_v_range {
1251                return 7;
1252            }
1253            if let Some(_) = self.dispatch_policy {
1254                return 6;
1255            }
1256            if let Some(_) = self.viewport {
1257                return 5;
1258            }
1259            if let Some(_) = self.target {
1260                return 4;
1261            }
1262            if let Some(_) = self.context {
1263                return 3;
1264            }
1265            if let Some(_) = self.device_type {
1266                return 2;
1267            }
1268            if let Some(_) = self.device_id {
1269                return 1;
1270            }
1271            0
1272        }
1273    }
1274
1275    impl fidl::encoding::ResourceTypeMarker for Config {
1276        type Borrowed<'a> = &'a mut Self;
1277        fn take_or_borrow<'a>(
1278            value: &'a mut <Self as fidl::encoding::TypeMarker>::Owned,
1279        ) -> Self::Borrowed<'a> {
1280            value
1281        }
1282    }
1283
1284    unsafe impl fidl::encoding::TypeMarker for Config {
1285        type Owned = Self;
1286
1287        #[inline(always)]
1288        fn inline_align(_context: fidl::encoding::Context) -> usize {
1289            8
1290        }
1291
1292        #[inline(always)]
1293        fn inline_size(_context: fidl::encoding::Context) -> usize {
1294            16
1295        }
1296    }
1297
1298    unsafe impl fidl::encoding::Encode<Config, fidl::encoding::DefaultFuchsiaResourceDialect>
1299        for &mut Config
1300    {
1301        unsafe fn encode(
1302            self,
1303            encoder: &mut fidl::encoding::Encoder<
1304                '_,
1305                fidl::encoding::DefaultFuchsiaResourceDialect,
1306            >,
1307            offset: usize,
1308            mut depth: fidl::encoding::Depth,
1309        ) -> fidl::Result<()> {
1310            encoder.debug_check_bounds::<Config>(offset);
1311            // Vector header
1312            let max_ordinal: u64 = self.max_ordinal_present();
1313            encoder.write_num(max_ordinal, offset);
1314            encoder.write_num(fidl::encoding::ALLOC_PRESENT_U64, offset + 8);
1315            // Calling encoder.out_of_line_offset(0) is not allowed.
1316            if max_ordinal == 0 {
1317                return Ok(());
1318            }
1319            depth.increment()?;
1320            let envelope_size = 8;
1321            let bytes_len = max_ordinal as usize * envelope_size;
1322            #[allow(unused_variables)]
1323            let offset = encoder.out_of_line_offset(bytes_len);
1324            let mut _prev_end_offset: usize = 0;
1325            if 1 > max_ordinal {
1326                return Ok(());
1327            }
1328
1329            // Write at offset+(ordinal-1)*envelope_size, since ordinals are one-based and envelopes
1330            // are envelope_size bytes.
1331            let cur_offset: usize = (1 - 1) * envelope_size;
1332
1333            // Zero reserved fields.
1334            encoder.padding(offset + _prev_end_offset, cur_offset - _prev_end_offset);
1335
1336            // Safety:
1337            // - bytes_len is calculated to fit envelope_size*max(member.ordinal).
1338            // - Since cur_offset is envelope_size*(member.ordinal - 1) and the envelope takes
1339            //   envelope_size bytes, there is always sufficient room.
1340            fidl::encoding::encode_in_envelope_optional::<
1341                u32,
1342                fidl::encoding::DefaultFuchsiaResourceDialect,
1343            >(
1344                self.device_id.as_ref().map(<u32 as fidl::encoding::ValueTypeMarker>::borrow),
1345                encoder,
1346                offset + cur_offset,
1347                depth,
1348            )?;
1349
1350            _prev_end_offset = cur_offset + envelope_size;
1351            if 2 > max_ordinal {
1352                return Ok(());
1353            }
1354
1355            // Write at offset+(ordinal-1)*envelope_size, since ordinals are one-based and envelopes
1356            // are envelope_size bytes.
1357            let cur_offset: usize = (2 - 1) * envelope_size;
1358
1359            // Zero reserved fields.
1360            encoder.padding(offset + _prev_end_offset, cur_offset - _prev_end_offset);
1361
1362            // Safety:
1363            // - bytes_len is calculated to fit envelope_size*max(member.ordinal).
1364            // - Since cur_offset is envelope_size*(member.ordinal - 1) and the envelope takes
1365            //   envelope_size bytes, there is always sufficient room.
1366            fidl::encoding::encode_in_envelope_optional::<
1367                DeviceType,
1368                fidl::encoding::DefaultFuchsiaResourceDialect,
1369            >(
1370                self.device_type
1371                    .as_ref()
1372                    .map(<DeviceType as fidl::encoding::ValueTypeMarker>::borrow),
1373                encoder,
1374                offset + cur_offset,
1375                depth,
1376            )?;
1377
1378            _prev_end_offset = cur_offset + envelope_size;
1379            if 3 > max_ordinal {
1380                return Ok(());
1381            }
1382
1383            // Write at offset+(ordinal-1)*envelope_size, since ordinals are one-based and envelopes
1384            // are envelope_size bytes.
1385            let cur_offset: usize = (3 - 1) * envelope_size;
1386
1387            // Zero reserved fields.
1388            encoder.padding(offset + _prev_end_offset, cur_offset - _prev_end_offset);
1389
1390            // Safety:
1391            // - bytes_len is calculated to fit envelope_size*max(member.ordinal).
1392            // - Since cur_offset is envelope_size*(member.ordinal - 1) and the envelope takes
1393            //   envelope_size bytes, there is always sufficient room.
1394            fidl::encoding::encode_in_envelope_optional::<
1395                Context,
1396                fidl::encoding::DefaultFuchsiaResourceDialect,
1397            >(
1398                self.context
1399                    .as_mut()
1400                    .map(<Context as fidl::encoding::ResourceTypeMarker>::take_or_borrow),
1401                encoder,
1402                offset + cur_offset,
1403                depth,
1404            )?;
1405
1406            _prev_end_offset = cur_offset + envelope_size;
1407            if 4 > max_ordinal {
1408                return Ok(());
1409            }
1410
1411            // Write at offset+(ordinal-1)*envelope_size, since ordinals are one-based and envelopes
1412            // are envelope_size bytes.
1413            let cur_offset: usize = (4 - 1) * envelope_size;
1414
1415            // Zero reserved fields.
1416            encoder.padding(offset + _prev_end_offset, cur_offset - _prev_end_offset);
1417
1418            // Safety:
1419            // - bytes_len is calculated to fit envelope_size*max(member.ordinal).
1420            // - Since cur_offset is envelope_size*(member.ordinal - 1) and the envelope takes
1421            //   envelope_size bytes, there is always sufficient room.
1422            fidl::encoding::encode_in_envelope_optional::<
1423                Target,
1424                fidl::encoding::DefaultFuchsiaResourceDialect,
1425            >(
1426                self.target
1427                    .as_mut()
1428                    .map(<Target as fidl::encoding::ResourceTypeMarker>::take_or_borrow),
1429                encoder,
1430                offset + cur_offset,
1431                depth,
1432            )?;
1433
1434            _prev_end_offset = cur_offset + envelope_size;
1435            if 5 > max_ordinal {
1436                return Ok(());
1437            }
1438
1439            // Write at offset+(ordinal-1)*envelope_size, since ordinals are one-based and envelopes
1440            // are envelope_size bytes.
1441            let cur_offset: usize = (5 - 1) * envelope_size;
1442
1443            // Zero reserved fields.
1444            encoder.padding(offset + _prev_end_offset, cur_offset - _prev_end_offset);
1445
1446            // Safety:
1447            // - bytes_len is calculated to fit envelope_size*max(member.ordinal).
1448            // - Since cur_offset is envelope_size*(member.ordinal - 1) and the envelope takes
1449            //   envelope_size bytes, there is always sufficient room.
1450            fidl::encoding::encode_in_envelope_optional::<
1451                Viewport,
1452                fidl::encoding::DefaultFuchsiaResourceDialect,
1453            >(
1454                self.viewport.as_ref().map(<Viewport as fidl::encoding::ValueTypeMarker>::borrow),
1455                encoder,
1456                offset + cur_offset,
1457                depth,
1458            )?;
1459
1460            _prev_end_offset = cur_offset + envelope_size;
1461            if 6 > max_ordinal {
1462                return Ok(());
1463            }
1464
1465            // Write at offset+(ordinal-1)*envelope_size, since ordinals are one-based and envelopes
1466            // are envelope_size bytes.
1467            let cur_offset: usize = (6 - 1) * envelope_size;
1468
1469            // Zero reserved fields.
1470            encoder.padding(offset + _prev_end_offset, cur_offset - _prev_end_offset);
1471
1472            // Safety:
1473            // - bytes_len is calculated to fit envelope_size*max(member.ordinal).
1474            // - Since cur_offset is envelope_size*(member.ordinal - 1) and the envelope takes
1475            //   envelope_size bytes, there is always sufficient room.
1476            fidl::encoding::encode_in_envelope_optional::<
1477                DispatchPolicy,
1478                fidl::encoding::DefaultFuchsiaResourceDialect,
1479            >(
1480                self.dispatch_policy
1481                    .as_ref()
1482                    .map(<DispatchPolicy as fidl::encoding::ValueTypeMarker>::borrow),
1483                encoder,
1484                offset + cur_offset,
1485                depth,
1486            )?;
1487
1488            _prev_end_offset = cur_offset + envelope_size;
1489            if 7 > max_ordinal {
1490                return Ok(());
1491            }
1492
1493            // Write at offset+(ordinal-1)*envelope_size, since ordinals are one-based and envelopes
1494            // are envelope_size bytes.
1495            let cur_offset: usize = (7 - 1) * envelope_size;
1496
1497            // Zero reserved fields.
1498            encoder.padding(offset + _prev_end_offset, cur_offset - _prev_end_offset);
1499
1500            // Safety:
1501            // - bytes_len is calculated to fit envelope_size*max(member.ordinal).
1502            // - Since cur_offset is envelope_size*(member.ordinal - 1) and the envelope takes
1503            //   envelope_size bytes, there is always sufficient room.
1504            fidl::encoding::encode_in_envelope_optional::<
1505                fidl_fuchsia_input_report::Axis,
1506                fidl::encoding::DefaultFuchsiaResourceDialect,
1507            >(
1508                self.scroll_v_range.as_ref().map(
1509                    <fidl_fuchsia_input_report::Axis as fidl::encoding::ValueTypeMarker>::borrow,
1510                ),
1511                encoder,
1512                offset + cur_offset,
1513                depth,
1514            )?;
1515
1516            _prev_end_offset = cur_offset + envelope_size;
1517            if 8 > max_ordinal {
1518                return Ok(());
1519            }
1520
1521            // Write at offset+(ordinal-1)*envelope_size, since ordinals are one-based and envelopes
1522            // are envelope_size bytes.
1523            let cur_offset: usize = (8 - 1) * envelope_size;
1524
1525            // Zero reserved fields.
1526            encoder.padding(offset + _prev_end_offset, cur_offset - _prev_end_offset);
1527
1528            // Safety:
1529            // - bytes_len is calculated to fit envelope_size*max(member.ordinal).
1530            // - Since cur_offset is envelope_size*(member.ordinal - 1) and the envelope takes
1531            //   envelope_size bytes, there is always sufficient room.
1532            fidl::encoding::encode_in_envelope_optional::<
1533                fidl_fuchsia_input_report::Axis,
1534                fidl::encoding::DefaultFuchsiaResourceDialect,
1535            >(
1536                self.scroll_h_range.as_ref().map(
1537                    <fidl_fuchsia_input_report::Axis as fidl::encoding::ValueTypeMarker>::borrow,
1538                ),
1539                encoder,
1540                offset + cur_offset,
1541                depth,
1542            )?;
1543
1544            _prev_end_offset = cur_offset + envelope_size;
1545            if 9 > max_ordinal {
1546                return Ok(());
1547            }
1548
1549            // Write at offset+(ordinal-1)*envelope_size, since ordinals are one-based and envelopes
1550            // are envelope_size bytes.
1551            let cur_offset: usize = (9 - 1) * envelope_size;
1552
1553            // Zero reserved fields.
1554            encoder.padding(offset + _prev_end_offset, cur_offset - _prev_end_offset);
1555
1556            // Safety:
1557            // - bytes_len is calculated to fit envelope_size*max(member.ordinal).
1558            // - Since cur_offset is envelope_size*(member.ordinal - 1) and the envelope takes
1559            //   envelope_size bytes, there is always sufficient room.
1560            fidl::encoding::encode_in_envelope_optional::<
1561                fidl::encoding::Vector<u8, 32>,
1562                fidl::encoding::DefaultFuchsiaResourceDialect,
1563            >(
1564                self.buttons.as_ref().map(
1565                    <fidl::encoding::Vector<u8, 32> as fidl::encoding::ValueTypeMarker>::borrow,
1566                ),
1567                encoder,
1568                offset + cur_offset,
1569                depth,
1570            )?;
1571
1572            _prev_end_offset = cur_offset + envelope_size;
1573            if 10 > max_ordinal {
1574                return Ok(());
1575            }
1576
1577            // Write at offset+(ordinal-1)*envelope_size, since ordinals are one-based and envelopes
1578            // are envelope_size bytes.
1579            let cur_offset: usize = (10 - 1) * envelope_size;
1580
1581            // Zero reserved fields.
1582            encoder.padding(offset + _prev_end_offset, cur_offset - _prev_end_offset);
1583
1584            // Safety:
1585            // - bytes_len is calculated to fit envelope_size*max(member.ordinal).
1586            // - Since cur_offset is envelope_size*(member.ordinal - 1) and the envelope takes
1587            //   envelope_size bytes, there is always sufficient room.
1588            fidl::encoding::encode_in_envelope_optional::<fidl::encoding::Array<fidl_fuchsia_input_report::Axis, 2>, fidl::encoding::DefaultFuchsiaResourceDialect>(
1589            self.relative_motion_range.as_ref().map(<fidl::encoding::Array<fidl_fuchsia_input_report::Axis, 2> as fidl::encoding::ValueTypeMarker>::borrow),
1590            encoder, offset + cur_offset, depth
1591        )?;
1592
1593            _prev_end_offset = cur_offset + envelope_size;
1594
1595            Ok(())
1596        }
1597    }
1598
1599    impl fidl::encoding::Decode<Self, fidl::encoding::DefaultFuchsiaResourceDialect> for Config {
1600        #[inline(always)]
1601        fn new_empty() -> Self {
1602            Self::default()
1603        }
1604
1605        unsafe fn decode(
1606            &mut self,
1607            decoder: &mut fidl::encoding::Decoder<
1608                '_,
1609                fidl::encoding::DefaultFuchsiaResourceDialect,
1610            >,
1611            offset: usize,
1612            mut depth: fidl::encoding::Depth,
1613        ) -> fidl::Result<()> {
1614            decoder.debug_check_bounds::<Self>(offset);
1615            let len = match fidl::encoding::decode_vector_header(decoder, offset)? {
1616                None => return Err(fidl::Error::NotNullable),
1617                Some(len) => len,
1618            };
1619            // Calling decoder.out_of_line_offset(0) is not allowed.
1620            if len == 0 {
1621                return Ok(());
1622            };
1623            depth.increment()?;
1624            let envelope_size = 8;
1625            let bytes_len = len * envelope_size;
1626            let offset = decoder.out_of_line_offset(bytes_len)?;
1627            // Decode the envelope for each type.
1628            let mut _next_ordinal_to_read = 0;
1629            let mut next_offset = offset;
1630            let end_offset = offset + bytes_len;
1631            _next_ordinal_to_read += 1;
1632            if next_offset >= end_offset {
1633                return Ok(());
1634            }
1635
1636            // Decode unknown envelopes for gaps in ordinals.
1637            while _next_ordinal_to_read < 1 {
1638                fidl::encoding::decode_unknown_envelope(decoder, next_offset, depth)?;
1639                _next_ordinal_to_read += 1;
1640                next_offset += envelope_size;
1641            }
1642
1643            let next_out_of_line = decoder.next_out_of_line();
1644            let handles_before = decoder.remaining_handles();
1645            if let Some((inlined, num_bytes, num_handles)) =
1646                fidl::encoding::decode_envelope_header(decoder, next_offset)?
1647            {
1648                let member_inline_size =
1649                    <u32 as fidl::encoding::TypeMarker>::inline_size(decoder.context);
1650                if inlined != (member_inline_size <= 4) {
1651                    return Err(fidl::Error::InvalidInlineBitInEnvelope);
1652                }
1653                let inner_offset;
1654                let mut inner_depth = depth.clone();
1655                if inlined {
1656                    decoder.check_inline_envelope_padding(next_offset, member_inline_size)?;
1657                    inner_offset = next_offset;
1658                } else {
1659                    inner_offset = decoder.out_of_line_offset(member_inline_size)?;
1660                    inner_depth.increment()?;
1661                }
1662                let val_ref = self.device_id.get_or_insert_with(|| {
1663                    fidl::new_empty!(u32, fidl::encoding::DefaultFuchsiaResourceDialect)
1664                });
1665                fidl::decode!(
1666                    u32,
1667                    fidl::encoding::DefaultFuchsiaResourceDialect,
1668                    val_ref,
1669                    decoder,
1670                    inner_offset,
1671                    inner_depth
1672                )?;
1673                if !inlined && decoder.next_out_of_line() != next_out_of_line + (num_bytes as usize)
1674                {
1675                    return Err(fidl::Error::InvalidNumBytesInEnvelope);
1676                }
1677                if handles_before != decoder.remaining_handles() + (num_handles as usize) {
1678                    return Err(fidl::Error::InvalidNumHandlesInEnvelope);
1679                }
1680            }
1681
1682            next_offset += envelope_size;
1683            _next_ordinal_to_read += 1;
1684            if next_offset >= end_offset {
1685                return Ok(());
1686            }
1687
1688            // Decode unknown envelopes for gaps in ordinals.
1689            while _next_ordinal_to_read < 2 {
1690                fidl::encoding::decode_unknown_envelope(decoder, next_offset, depth)?;
1691                _next_ordinal_to_read += 1;
1692                next_offset += envelope_size;
1693            }
1694
1695            let next_out_of_line = decoder.next_out_of_line();
1696            let handles_before = decoder.remaining_handles();
1697            if let Some((inlined, num_bytes, num_handles)) =
1698                fidl::encoding::decode_envelope_header(decoder, next_offset)?
1699            {
1700                let member_inline_size =
1701                    <DeviceType as fidl::encoding::TypeMarker>::inline_size(decoder.context);
1702                if inlined != (member_inline_size <= 4) {
1703                    return Err(fidl::Error::InvalidInlineBitInEnvelope);
1704                }
1705                let inner_offset;
1706                let mut inner_depth = depth.clone();
1707                if inlined {
1708                    decoder.check_inline_envelope_padding(next_offset, member_inline_size)?;
1709                    inner_offset = next_offset;
1710                } else {
1711                    inner_offset = decoder.out_of_line_offset(member_inline_size)?;
1712                    inner_depth.increment()?;
1713                }
1714                let val_ref = self.device_type.get_or_insert_with(|| {
1715                    fidl::new_empty!(DeviceType, fidl::encoding::DefaultFuchsiaResourceDialect)
1716                });
1717                fidl::decode!(
1718                    DeviceType,
1719                    fidl::encoding::DefaultFuchsiaResourceDialect,
1720                    val_ref,
1721                    decoder,
1722                    inner_offset,
1723                    inner_depth
1724                )?;
1725                if !inlined && decoder.next_out_of_line() != next_out_of_line + (num_bytes as usize)
1726                {
1727                    return Err(fidl::Error::InvalidNumBytesInEnvelope);
1728                }
1729                if handles_before != decoder.remaining_handles() + (num_handles as usize) {
1730                    return Err(fidl::Error::InvalidNumHandlesInEnvelope);
1731                }
1732            }
1733
1734            next_offset += envelope_size;
1735            _next_ordinal_to_read += 1;
1736            if next_offset >= end_offset {
1737                return Ok(());
1738            }
1739
1740            // Decode unknown envelopes for gaps in ordinals.
1741            while _next_ordinal_to_read < 3 {
1742                fidl::encoding::decode_unknown_envelope(decoder, next_offset, depth)?;
1743                _next_ordinal_to_read += 1;
1744                next_offset += envelope_size;
1745            }
1746
1747            let next_out_of_line = decoder.next_out_of_line();
1748            let handles_before = decoder.remaining_handles();
1749            if let Some((inlined, num_bytes, num_handles)) =
1750                fidl::encoding::decode_envelope_header(decoder, next_offset)?
1751            {
1752                let member_inline_size =
1753                    <Context as fidl::encoding::TypeMarker>::inline_size(decoder.context);
1754                if inlined != (member_inline_size <= 4) {
1755                    return Err(fidl::Error::InvalidInlineBitInEnvelope);
1756                }
1757                let inner_offset;
1758                let mut inner_depth = depth.clone();
1759                if inlined {
1760                    decoder.check_inline_envelope_padding(next_offset, member_inline_size)?;
1761                    inner_offset = next_offset;
1762                } else {
1763                    inner_offset = decoder.out_of_line_offset(member_inline_size)?;
1764                    inner_depth.increment()?;
1765                }
1766                let val_ref = self.context.get_or_insert_with(|| {
1767                    fidl::new_empty!(Context, fidl::encoding::DefaultFuchsiaResourceDialect)
1768                });
1769                fidl::decode!(
1770                    Context,
1771                    fidl::encoding::DefaultFuchsiaResourceDialect,
1772                    val_ref,
1773                    decoder,
1774                    inner_offset,
1775                    inner_depth
1776                )?;
1777                if !inlined && decoder.next_out_of_line() != next_out_of_line + (num_bytes as usize)
1778                {
1779                    return Err(fidl::Error::InvalidNumBytesInEnvelope);
1780                }
1781                if handles_before != decoder.remaining_handles() + (num_handles as usize) {
1782                    return Err(fidl::Error::InvalidNumHandlesInEnvelope);
1783                }
1784            }
1785
1786            next_offset += envelope_size;
1787            _next_ordinal_to_read += 1;
1788            if next_offset >= end_offset {
1789                return Ok(());
1790            }
1791
1792            // Decode unknown envelopes for gaps in ordinals.
1793            while _next_ordinal_to_read < 4 {
1794                fidl::encoding::decode_unknown_envelope(decoder, next_offset, depth)?;
1795                _next_ordinal_to_read += 1;
1796                next_offset += envelope_size;
1797            }
1798
1799            let next_out_of_line = decoder.next_out_of_line();
1800            let handles_before = decoder.remaining_handles();
1801            if let Some((inlined, num_bytes, num_handles)) =
1802                fidl::encoding::decode_envelope_header(decoder, next_offset)?
1803            {
1804                let member_inline_size =
1805                    <Target as fidl::encoding::TypeMarker>::inline_size(decoder.context);
1806                if inlined != (member_inline_size <= 4) {
1807                    return Err(fidl::Error::InvalidInlineBitInEnvelope);
1808                }
1809                let inner_offset;
1810                let mut inner_depth = depth.clone();
1811                if inlined {
1812                    decoder.check_inline_envelope_padding(next_offset, member_inline_size)?;
1813                    inner_offset = next_offset;
1814                } else {
1815                    inner_offset = decoder.out_of_line_offset(member_inline_size)?;
1816                    inner_depth.increment()?;
1817                }
1818                let val_ref = self.target.get_or_insert_with(|| {
1819                    fidl::new_empty!(Target, fidl::encoding::DefaultFuchsiaResourceDialect)
1820                });
1821                fidl::decode!(
1822                    Target,
1823                    fidl::encoding::DefaultFuchsiaResourceDialect,
1824                    val_ref,
1825                    decoder,
1826                    inner_offset,
1827                    inner_depth
1828                )?;
1829                if !inlined && decoder.next_out_of_line() != next_out_of_line + (num_bytes as usize)
1830                {
1831                    return Err(fidl::Error::InvalidNumBytesInEnvelope);
1832                }
1833                if handles_before != decoder.remaining_handles() + (num_handles as usize) {
1834                    return Err(fidl::Error::InvalidNumHandlesInEnvelope);
1835                }
1836            }
1837
1838            next_offset += envelope_size;
1839            _next_ordinal_to_read += 1;
1840            if next_offset >= end_offset {
1841                return Ok(());
1842            }
1843
1844            // Decode unknown envelopes for gaps in ordinals.
1845            while _next_ordinal_to_read < 5 {
1846                fidl::encoding::decode_unknown_envelope(decoder, next_offset, depth)?;
1847                _next_ordinal_to_read += 1;
1848                next_offset += envelope_size;
1849            }
1850
1851            let next_out_of_line = decoder.next_out_of_line();
1852            let handles_before = decoder.remaining_handles();
1853            if let Some((inlined, num_bytes, num_handles)) =
1854                fidl::encoding::decode_envelope_header(decoder, next_offset)?
1855            {
1856                let member_inline_size =
1857                    <Viewport as fidl::encoding::TypeMarker>::inline_size(decoder.context);
1858                if inlined != (member_inline_size <= 4) {
1859                    return Err(fidl::Error::InvalidInlineBitInEnvelope);
1860                }
1861                let inner_offset;
1862                let mut inner_depth = depth.clone();
1863                if inlined {
1864                    decoder.check_inline_envelope_padding(next_offset, member_inline_size)?;
1865                    inner_offset = next_offset;
1866                } else {
1867                    inner_offset = decoder.out_of_line_offset(member_inline_size)?;
1868                    inner_depth.increment()?;
1869                }
1870                let val_ref = self.viewport.get_or_insert_with(|| {
1871                    fidl::new_empty!(Viewport, fidl::encoding::DefaultFuchsiaResourceDialect)
1872                });
1873                fidl::decode!(
1874                    Viewport,
1875                    fidl::encoding::DefaultFuchsiaResourceDialect,
1876                    val_ref,
1877                    decoder,
1878                    inner_offset,
1879                    inner_depth
1880                )?;
1881                if !inlined && decoder.next_out_of_line() != next_out_of_line + (num_bytes as usize)
1882                {
1883                    return Err(fidl::Error::InvalidNumBytesInEnvelope);
1884                }
1885                if handles_before != decoder.remaining_handles() + (num_handles as usize) {
1886                    return Err(fidl::Error::InvalidNumHandlesInEnvelope);
1887                }
1888            }
1889
1890            next_offset += envelope_size;
1891            _next_ordinal_to_read += 1;
1892            if next_offset >= end_offset {
1893                return Ok(());
1894            }
1895
1896            // Decode unknown envelopes for gaps in ordinals.
1897            while _next_ordinal_to_read < 6 {
1898                fidl::encoding::decode_unknown_envelope(decoder, next_offset, depth)?;
1899                _next_ordinal_to_read += 1;
1900                next_offset += envelope_size;
1901            }
1902
1903            let next_out_of_line = decoder.next_out_of_line();
1904            let handles_before = decoder.remaining_handles();
1905            if let Some((inlined, num_bytes, num_handles)) =
1906                fidl::encoding::decode_envelope_header(decoder, next_offset)?
1907            {
1908                let member_inline_size =
1909                    <DispatchPolicy as fidl::encoding::TypeMarker>::inline_size(decoder.context);
1910                if inlined != (member_inline_size <= 4) {
1911                    return Err(fidl::Error::InvalidInlineBitInEnvelope);
1912                }
1913                let inner_offset;
1914                let mut inner_depth = depth.clone();
1915                if inlined {
1916                    decoder.check_inline_envelope_padding(next_offset, member_inline_size)?;
1917                    inner_offset = next_offset;
1918                } else {
1919                    inner_offset = decoder.out_of_line_offset(member_inline_size)?;
1920                    inner_depth.increment()?;
1921                }
1922                let val_ref = self.dispatch_policy.get_or_insert_with(|| {
1923                    fidl::new_empty!(DispatchPolicy, fidl::encoding::DefaultFuchsiaResourceDialect)
1924                });
1925                fidl::decode!(
1926                    DispatchPolicy,
1927                    fidl::encoding::DefaultFuchsiaResourceDialect,
1928                    val_ref,
1929                    decoder,
1930                    inner_offset,
1931                    inner_depth
1932                )?;
1933                if !inlined && decoder.next_out_of_line() != next_out_of_line + (num_bytes as usize)
1934                {
1935                    return Err(fidl::Error::InvalidNumBytesInEnvelope);
1936                }
1937                if handles_before != decoder.remaining_handles() + (num_handles as usize) {
1938                    return Err(fidl::Error::InvalidNumHandlesInEnvelope);
1939                }
1940            }
1941
1942            next_offset += envelope_size;
1943            _next_ordinal_to_read += 1;
1944            if next_offset >= end_offset {
1945                return Ok(());
1946            }
1947
1948            // Decode unknown envelopes for gaps in ordinals.
1949            while _next_ordinal_to_read < 7 {
1950                fidl::encoding::decode_unknown_envelope(decoder, next_offset, depth)?;
1951                _next_ordinal_to_read += 1;
1952                next_offset += envelope_size;
1953            }
1954
1955            let next_out_of_line = decoder.next_out_of_line();
1956            let handles_before = decoder.remaining_handles();
1957            if let Some((inlined, num_bytes, num_handles)) =
1958                fidl::encoding::decode_envelope_header(decoder, next_offset)?
1959            {
1960                let member_inline_size =
1961                    <fidl_fuchsia_input_report::Axis as fidl::encoding::TypeMarker>::inline_size(
1962                        decoder.context,
1963                    );
1964                if inlined != (member_inline_size <= 4) {
1965                    return Err(fidl::Error::InvalidInlineBitInEnvelope);
1966                }
1967                let inner_offset;
1968                let mut inner_depth = depth.clone();
1969                if inlined {
1970                    decoder.check_inline_envelope_padding(next_offset, member_inline_size)?;
1971                    inner_offset = next_offset;
1972                } else {
1973                    inner_offset = decoder.out_of_line_offset(member_inline_size)?;
1974                    inner_depth.increment()?;
1975                }
1976                let val_ref = self.scroll_v_range.get_or_insert_with(|| {
1977                    fidl::new_empty!(
1978                        fidl_fuchsia_input_report::Axis,
1979                        fidl::encoding::DefaultFuchsiaResourceDialect
1980                    )
1981                });
1982                fidl::decode!(
1983                    fidl_fuchsia_input_report::Axis,
1984                    fidl::encoding::DefaultFuchsiaResourceDialect,
1985                    val_ref,
1986                    decoder,
1987                    inner_offset,
1988                    inner_depth
1989                )?;
1990                if !inlined && decoder.next_out_of_line() != next_out_of_line + (num_bytes as usize)
1991                {
1992                    return Err(fidl::Error::InvalidNumBytesInEnvelope);
1993                }
1994                if handles_before != decoder.remaining_handles() + (num_handles as usize) {
1995                    return Err(fidl::Error::InvalidNumHandlesInEnvelope);
1996                }
1997            }
1998
1999            next_offset += envelope_size;
2000            _next_ordinal_to_read += 1;
2001            if next_offset >= end_offset {
2002                return Ok(());
2003            }
2004
2005            // Decode unknown envelopes for gaps in ordinals.
2006            while _next_ordinal_to_read < 8 {
2007                fidl::encoding::decode_unknown_envelope(decoder, next_offset, depth)?;
2008                _next_ordinal_to_read += 1;
2009                next_offset += envelope_size;
2010            }
2011
2012            let next_out_of_line = decoder.next_out_of_line();
2013            let handles_before = decoder.remaining_handles();
2014            if let Some((inlined, num_bytes, num_handles)) =
2015                fidl::encoding::decode_envelope_header(decoder, next_offset)?
2016            {
2017                let member_inline_size =
2018                    <fidl_fuchsia_input_report::Axis as fidl::encoding::TypeMarker>::inline_size(
2019                        decoder.context,
2020                    );
2021                if inlined != (member_inline_size <= 4) {
2022                    return Err(fidl::Error::InvalidInlineBitInEnvelope);
2023                }
2024                let inner_offset;
2025                let mut inner_depth = depth.clone();
2026                if inlined {
2027                    decoder.check_inline_envelope_padding(next_offset, member_inline_size)?;
2028                    inner_offset = next_offset;
2029                } else {
2030                    inner_offset = decoder.out_of_line_offset(member_inline_size)?;
2031                    inner_depth.increment()?;
2032                }
2033                let val_ref = self.scroll_h_range.get_or_insert_with(|| {
2034                    fidl::new_empty!(
2035                        fidl_fuchsia_input_report::Axis,
2036                        fidl::encoding::DefaultFuchsiaResourceDialect
2037                    )
2038                });
2039                fidl::decode!(
2040                    fidl_fuchsia_input_report::Axis,
2041                    fidl::encoding::DefaultFuchsiaResourceDialect,
2042                    val_ref,
2043                    decoder,
2044                    inner_offset,
2045                    inner_depth
2046                )?;
2047                if !inlined && decoder.next_out_of_line() != next_out_of_line + (num_bytes as usize)
2048                {
2049                    return Err(fidl::Error::InvalidNumBytesInEnvelope);
2050                }
2051                if handles_before != decoder.remaining_handles() + (num_handles as usize) {
2052                    return Err(fidl::Error::InvalidNumHandlesInEnvelope);
2053                }
2054            }
2055
2056            next_offset += envelope_size;
2057            _next_ordinal_to_read += 1;
2058            if next_offset >= end_offset {
2059                return Ok(());
2060            }
2061
2062            // Decode unknown envelopes for gaps in ordinals.
2063            while _next_ordinal_to_read < 9 {
2064                fidl::encoding::decode_unknown_envelope(decoder, next_offset, depth)?;
2065                _next_ordinal_to_read += 1;
2066                next_offset += envelope_size;
2067            }
2068
2069            let next_out_of_line = decoder.next_out_of_line();
2070            let handles_before = decoder.remaining_handles();
2071            if let Some((inlined, num_bytes, num_handles)) =
2072                fidl::encoding::decode_envelope_header(decoder, next_offset)?
2073            {
2074                let member_inline_size =
2075                    <fidl::encoding::Vector<u8, 32> as fidl::encoding::TypeMarker>::inline_size(
2076                        decoder.context,
2077                    );
2078                if inlined != (member_inline_size <= 4) {
2079                    return Err(fidl::Error::InvalidInlineBitInEnvelope);
2080                }
2081                let inner_offset;
2082                let mut inner_depth = depth.clone();
2083                if inlined {
2084                    decoder.check_inline_envelope_padding(next_offset, member_inline_size)?;
2085                    inner_offset = next_offset;
2086                } else {
2087                    inner_offset = decoder.out_of_line_offset(member_inline_size)?;
2088                    inner_depth.increment()?;
2089                }
2090                let val_ref =
2091                self.buttons.get_or_insert_with(|| fidl::new_empty!(fidl::encoding::Vector<u8, 32>, fidl::encoding::DefaultFuchsiaResourceDialect));
2092                fidl::decode!(fidl::encoding::Vector<u8, 32>, fidl::encoding::DefaultFuchsiaResourceDialect, val_ref, decoder, inner_offset, inner_depth)?;
2093                if !inlined && decoder.next_out_of_line() != next_out_of_line + (num_bytes as usize)
2094                {
2095                    return Err(fidl::Error::InvalidNumBytesInEnvelope);
2096                }
2097                if handles_before != decoder.remaining_handles() + (num_handles as usize) {
2098                    return Err(fidl::Error::InvalidNumHandlesInEnvelope);
2099                }
2100            }
2101
2102            next_offset += envelope_size;
2103            _next_ordinal_to_read += 1;
2104            if next_offset >= end_offset {
2105                return Ok(());
2106            }
2107
2108            // Decode unknown envelopes for gaps in ordinals.
2109            while _next_ordinal_to_read < 10 {
2110                fidl::encoding::decode_unknown_envelope(decoder, next_offset, depth)?;
2111                _next_ordinal_to_read += 1;
2112                next_offset += envelope_size;
2113            }
2114
2115            let next_out_of_line = decoder.next_out_of_line();
2116            let handles_before = decoder.remaining_handles();
2117            if let Some((inlined, num_bytes, num_handles)) =
2118                fidl::encoding::decode_envelope_header(decoder, next_offset)?
2119            {
2120                let member_inline_size = <fidl::encoding::Array<fidl_fuchsia_input_report::Axis, 2> as fidl::encoding::TypeMarker>::inline_size(decoder.context);
2121                if inlined != (member_inline_size <= 4) {
2122                    return Err(fidl::Error::InvalidInlineBitInEnvelope);
2123                }
2124                let inner_offset;
2125                let mut inner_depth = depth.clone();
2126                if inlined {
2127                    decoder.check_inline_envelope_padding(next_offset, member_inline_size)?;
2128                    inner_offset = next_offset;
2129                } else {
2130                    inner_offset = decoder.out_of_line_offset(member_inline_size)?;
2131                    inner_depth.increment()?;
2132                }
2133                let val_ref =
2134                self.relative_motion_range.get_or_insert_with(|| fidl::new_empty!(fidl::encoding::Array<fidl_fuchsia_input_report::Axis, 2>, fidl::encoding::DefaultFuchsiaResourceDialect));
2135                fidl::decode!(fidl::encoding::Array<fidl_fuchsia_input_report::Axis, 2>, fidl::encoding::DefaultFuchsiaResourceDialect, val_ref, decoder, inner_offset, inner_depth)?;
2136                if !inlined && decoder.next_out_of_line() != next_out_of_line + (num_bytes as usize)
2137                {
2138                    return Err(fidl::Error::InvalidNumBytesInEnvelope);
2139                }
2140                if handles_before != decoder.remaining_handles() + (num_handles as usize) {
2141                    return Err(fidl::Error::InvalidNumHandlesInEnvelope);
2142                }
2143            }
2144
2145            next_offset += envelope_size;
2146
2147            // Decode the remaining unknown envelopes.
2148            while next_offset < end_offset {
2149                _next_ordinal_to_read += 1;
2150                fidl::encoding::decode_unknown_envelope(decoder, next_offset, depth)?;
2151                next_offset += envelope_size;
2152            }
2153
2154            Ok(())
2155        }
2156    }
2157
2158    impl fidl::encoding::ResourceTypeMarker for Context {
2159        type Borrowed<'a> = &'a mut Self;
2160        fn take_or_borrow<'a>(
2161            value: &'a mut <Self as fidl::encoding::TypeMarker>::Owned,
2162        ) -> Self::Borrowed<'a> {
2163            value
2164        }
2165    }
2166
2167    unsafe impl fidl::encoding::TypeMarker for Context {
2168        type Owned = Self;
2169
2170        #[inline(always)]
2171        fn inline_align(_context: fidl::encoding::Context) -> usize {
2172            8
2173        }
2174
2175        #[inline(always)]
2176        fn inline_size(_context: fidl::encoding::Context) -> usize {
2177            16
2178        }
2179    }
2180
2181    unsafe impl fidl::encoding::Encode<Context, fidl::encoding::DefaultFuchsiaResourceDialect>
2182        for &mut Context
2183    {
2184        #[inline]
2185        unsafe fn encode(
2186            self,
2187            encoder: &mut fidl::encoding::Encoder<
2188                '_,
2189                fidl::encoding::DefaultFuchsiaResourceDialect,
2190            >,
2191            offset: usize,
2192            _depth: fidl::encoding::Depth,
2193        ) -> fidl::Result<()> {
2194            encoder.debug_check_bounds::<Context>(offset);
2195            encoder.write_num::<u64>(self.ordinal(), offset);
2196            match self {
2197            Context::View(ref mut val) => {
2198                fidl::encoding::encode_in_envelope::<fidl_fuchsia_ui_views::ViewRef, fidl::encoding::DefaultFuchsiaResourceDialect>(
2199                    <fidl_fuchsia_ui_views::ViewRef as fidl::encoding::ResourceTypeMarker>::take_or_borrow(val),
2200                    encoder, offset + 8, _depth
2201                )
2202            }
2203        }
2204        }
2205    }
2206
2207    impl fidl::encoding::Decode<Self, fidl::encoding::DefaultFuchsiaResourceDialect> for Context {
2208        #[inline(always)]
2209        fn new_empty() -> Self {
2210            Self::View(fidl::new_empty!(
2211                fidl_fuchsia_ui_views::ViewRef,
2212                fidl::encoding::DefaultFuchsiaResourceDialect
2213            ))
2214        }
2215
2216        #[inline]
2217        unsafe fn decode(
2218            &mut self,
2219            decoder: &mut fidl::encoding::Decoder<
2220                '_,
2221                fidl::encoding::DefaultFuchsiaResourceDialect,
2222            >,
2223            offset: usize,
2224            mut depth: fidl::encoding::Depth,
2225        ) -> fidl::Result<()> {
2226            decoder.debug_check_bounds::<Self>(offset);
2227            #[allow(unused_variables)]
2228            let next_out_of_line = decoder.next_out_of_line();
2229            let handles_before = decoder.remaining_handles();
2230            let (ordinal, inlined, num_bytes, num_handles) =
2231                fidl::encoding::decode_union_inline_portion(decoder, offset)?;
2232
2233            let member_inline_size = match ordinal {
2234                1 => <fidl_fuchsia_ui_views::ViewRef as fidl::encoding::TypeMarker>::inline_size(
2235                    decoder.context,
2236                ),
2237                _ => return Err(fidl::Error::UnknownUnionTag),
2238            };
2239
2240            if inlined != (member_inline_size <= 4) {
2241                return Err(fidl::Error::InvalidInlineBitInEnvelope);
2242            }
2243            let _inner_offset;
2244            if inlined {
2245                decoder.check_inline_envelope_padding(offset + 8, member_inline_size)?;
2246                _inner_offset = offset + 8;
2247            } else {
2248                depth.increment()?;
2249                _inner_offset = decoder.out_of_line_offset(member_inline_size)?;
2250            }
2251            match ordinal {
2252                1 => {
2253                    #[allow(irrefutable_let_patterns)]
2254                    if let Context::View(_) = self {
2255                        // Do nothing, read the value into the object
2256                    } else {
2257                        // Initialize `self` to the right variant
2258                        *self = Context::View(fidl::new_empty!(
2259                            fidl_fuchsia_ui_views::ViewRef,
2260                            fidl::encoding::DefaultFuchsiaResourceDialect
2261                        ));
2262                    }
2263                    #[allow(irrefutable_let_patterns)]
2264                    if let Context::View(ref mut val) = self {
2265                        fidl::decode!(
2266                            fidl_fuchsia_ui_views::ViewRef,
2267                            fidl::encoding::DefaultFuchsiaResourceDialect,
2268                            val,
2269                            decoder,
2270                            _inner_offset,
2271                            depth
2272                        )?;
2273                    } else {
2274                        unreachable!()
2275                    }
2276                }
2277                ordinal => panic!("unexpected ordinal {:?}", ordinal),
2278            }
2279            if !inlined && decoder.next_out_of_line() != next_out_of_line + (num_bytes as usize) {
2280                return Err(fidl::Error::InvalidNumBytesInEnvelope);
2281            }
2282            if handles_before != decoder.remaining_handles() + (num_handles as usize) {
2283                return Err(fidl::Error::InvalidNumHandlesInEnvelope);
2284            }
2285            Ok(())
2286        }
2287    }
2288
2289    impl fidl::encoding::ResourceTypeMarker for Target {
2290        type Borrowed<'a> = &'a mut Self;
2291        fn take_or_borrow<'a>(
2292            value: &'a mut <Self as fidl::encoding::TypeMarker>::Owned,
2293        ) -> Self::Borrowed<'a> {
2294            value
2295        }
2296    }
2297
2298    unsafe impl fidl::encoding::TypeMarker for Target {
2299        type Owned = Self;
2300
2301        #[inline(always)]
2302        fn inline_align(_context: fidl::encoding::Context) -> usize {
2303            8
2304        }
2305
2306        #[inline(always)]
2307        fn inline_size(_context: fidl::encoding::Context) -> usize {
2308            16
2309        }
2310    }
2311
2312    unsafe impl fidl::encoding::Encode<Target, fidl::encoding::DefaultFuchsiaResourceDialect>
2313        for &mut Target
2314    {
2315        #[inline]
2316        unsafe fn encode(
2317            self,
2318            encoder: &mut fidl::encoding::Encoder<
2319                '_,
2320                fidl::encoding::DefaultFuchsiaResourceDialect,
2321            >,
2322            offset: usize,
2323            _depth: fidl::encoding::Depth,
2324        ) -> fidl::Result<()> {
2325            encoder.debug_check_bounds::<Target>(offset);
2326            encoder.write_num::<u64>(self.ordinal(), offset);
2327            match self {
2328            Target::View(ref mut val) => {
2329                fidl::encoding::encode_in_envelope::<fidl_fuchsia_ui_views::ViewRef, fidl::encoding::DefaultFuchsiaResourceDialect>(
2330                    <fidl_fuchsia_ui_views::ViewRef as fidl::encoding::ResourceTypeMarker>::take_or_borrow(val),
2331                    encoder, offset + 8, _depth
2332                )
2333            }
2334        }
2335        }
2336    }
2337
2338    impl fidl::encoding::Decode<Self, fidl::encoding::DefaultFuchsiaResourceDialect> for Target {
2339        #[inline(always)]
2340        fn new_empty() -> Self {
2341            Self::View(fidl::new_empty!(
2342                fidl_fuchsia_ui_views::ViewRef,
2343                fidl::encoding::DefaultFuchsiaResourceDialect
2344            ))
2345        }
2346
2347        #[inline]
2348        unsafe fn decode(
2349            &mut self,
2350            decoder: &mut fidl::encoding::Decoder<
2351                '_,
2352                fidl::encoding::DefaultFuchsiaResourceDialect,
2353            >,
2354            offset: usize,
2355            mut depth: fidl::encoding::Depth,
2356        ) -> fidl::Result<()> {
2357            decoder.debug_check_bounds::<Self>(offset);
2358            #[allow(unused_variables)]
2359            let next_out_of_line = decoder.next_out_of_line();
2360            let handles_before = decoder.remaining_handles();
2361            let (ordinal, inlined, num_bytes, num_handles) =
2362                fidl::encoding::decode_union_inline_portion(decoder, offset)?;
2363
2364            let member_inline_size = match ordinal {
2365                1 => <fidl_fuchsia_ui_views::ViewRef as fidl::encoding::TypeMarker>::inline_size(
2366                    decoder.context,
2367                ),
2368                _ => return Err(fidl::Error::UnknownUnionTag),
2369            };
2370
2371            if inlined != (member_inline_size <= 4) {
2372                return Err(fidl::Error::InvalidInlineBitInEnvelope);
2373            }
2374            let _inner_offset;
2375            if inlined {
2376                decoder.check_inline_envelope_padding(offset + 8, member_inline_size)?;
2377                _inner_offset = offset + 8;
2378            } else {
2379                depth.increment()?;
2380                _inner_offset = decoder.out_of_line_offset(member_inline_size)?;
2381            }
2382            match ordinal {
2383                1 => {
2384                    #[allow(irrefutable_let_patterns)]
2385                    if let Target::View(_) = self {
2386                        // Do nothing, read the value into the object
2387                    } else {
2388                        // Initialize `self` to the right variant
2389                        *self = Target::View(fidl::new_empty!(
2390                            fidl_fuchsia_ui_views::ViewRef,
2391                            fidl::encoding::DefaultFuchsiaResourceDialect
2392                        ));
2393                    }
2394                    #[allow(irrefutable_let_patterns)]
2395                    if let Target::View(ref mut val) = self {
2396                        fidl::decode!(
2397                            fidl_fuchsia_ui_views::ViewRef,
2398                            fidl::encoding::DefaultFuchsiaResourceDialect,
2399                            val,
2400                            decoder,
2401                            _inner_offset,
2402                            depth
2403                        )?;
2404                    } else {
2405                        unreachable!()
2406                    }
2407                }
2408                ordinal => panic!("unexpected ordinal {:?}", ordinal),
2409            }
2410            if !inlined && decoder.next_out_of_line() != next_out_of_line + (num_bytes as usize) {
2411                return Err(fidl::Error::InvalidNumBytesInEnvelope);
2412            }
2413            if handles_before != decoder.remaining_handles() + (num_handles as usize) {
2414                return Err(fidl::Error::InvalidNumHandlesInEnvelope);
2415            }
2416            Ok(())
2417        }
2418    }
2419}