Skip to main content

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 DeviceInjectRequest {
16    pub events: Vec<Event>,
17}
18
19impl fidl::Standalone<fidl::encoding::DefaultFuchsiaResourceDialect> for DeviceInjectRequest {}
20
21#[derive(Debug, PartialEq)]
22pub struct RegistryRegisterRequest {
23    pub config: Config,
24    pub injector: fidl::endpoints::ServerEnd<DeviceMarker>,
25}
26
27impl fidl::Standalone<fidl::encoding::DefaultFuchsiaResourceDialect> for RegistryRegisterRequest {}
28
29/// A specification for an injector |Device|.
30///
31/// All fields required.
32#[derive(Debug, Default, PartialEq)]
33pub struct Config {
34    /// An identifier for the pointer device that issues pointer event streams.
35    pub device_id: Option<u32>,
36    /// A characterization of the pointer device.
37    pub device_type: Option<DeviceType>,
38    /// The scope and coordinate system of the injector |Device|.
39    ///
40    /// Note: To avoid circular injection scenarios, |context| must be a
41    ///       strict ancestor of |target|.
42    pub context: Option<Context>,
43    /// The region where dispatch is attempted for injected events.
44    ///
45    /// Note: To avoid circular injection scenarios, |target| must be a strict
46    ///       descendant of |context|.
47    pub target: Option<Target>,
48    /// The initial viewport for injected events. Subsequent modifications to
49    /// the viewport can also be sent synchronously with injected events.
50    pub viewport: Option<Viewport>,
51    /// A specification of the UI clients in |target| that may have injected
52    /// events dispatched to them.
53    ///
54    /// For example, if |dispatch_policy| is |EXCLUSIVE|, then only |target| may
55    /// have injected events dispatched to it, regardless of other factors, such
56    /// as surface occlusion by clients inside and outside of |target|.
57    pub dispatch_policy: Option<DispatchPolicy>,
58    pub scroll_v_range: Option<fidl_fuchsia_input::Axis>,
59    pub scroll_h_range: Option<fidl_fuchsia_input::Axis>,
60    pub buttons: Option<Vec<u8>>,
61    /// Range of X and Y motion by a mouse device.
62    pub relative_motion_range: Option<[fidl_fuchsia_input::Axis; 2]>,
63    #[doc(hidden)]
64    pub __source_breaking: fidl::marker::SourceBreaking,
65}
66
67impl fidl::Standalone<fidl::encoding::DefaultFuchsiaResourceDialect> for Config {}
68
69#[derive(Debug, Default, PartialEq)]
70pub struct Event {
71    /// The time when this event was observed.
72    ///
73    /// Required.
74    pub timestamp: Option<i64>,
75    /// The event's data.
76    ///
77    /// Required.
78    pub data: Option<Data>,
79    /// An identifier to correlate this event's send/receive occurrence across
80    /// component boundaries or abstraction layers.
81    pub trace_flow_id: Option<u64>,
82    /// Optional wake lease for power baton passing.
83    pub wake_lease: Option<fidl::EventPair>,
84    #[doc(hidden)]
85    pub __source_breaking: fidl::marker::SourceBreaking,
86}
87
88impl fidl::Standalone<fidl::encoding::DefaultFuchsiaResourceDialect> for Event {}
89
90/// The region from which injection is attempted for injected events. As the
91/// context, it serves two purposes:
92/// (1) Scoping. It confirms the |Device|'s authority to inject pointer events
93///     on the specified target. Specifically, the context must be a view-tree
94///     ancestor of the target.
95/// (2) Coordinate System. It provides the reference coordinate system to define
96///     the viewport's position and size, relative to the target.
97#[derive(Debug, PartialEq)]
98pub enum Context {
99    /// A Scenic view from which injection is attempted for injected events.
100    /// - This view must be connected to the scene graph for injection.
101    /// - Injected events are confined to this view and its sub-views.
102    View(fidl_fuchsia_ui_views::ViewRef),
103}
104
105impl Context {
106    #[inline]
107    pub fn ordinal(&self) -> u64 {
108        match *self {
109            Self::View(_) => 1,
110        }
111    }
112}
113
114impl fidl::Standalone<fidl::encoding::DefaultFuchsiaResourceDialect> for Context {}
115
116/// The region in which dispatch is attempted for injected events.
117/// The particular dispatch policy is specified in |Config|.
118#[derive(Debug, PartialEq)]
119pub enum Target {
120    /// A Scenic view in which dispatch is attempted for injected events.
121    /// - This view must be connected to the scene graph for dispatch.
122    /// - Injected events are confined to this view and its sub-views.
123    View(fidl_fuchsia_ui_views::ViewRef),
124}
125
126impl Target {
127    #[inline]
128    pub fn ordinal(&self) -> u64 {
129        match *self {
130            Self::View(_) => 1,
131        }
132    }
133}
134
135impl fidl::Standalone<fidl::encoding::DefaultFuchsiaResourceDialect> for Target {}
136
137#[derive(Debug, Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Hash)]
138pub struct DeviceMarker;
139
140impl fidl::endpoints::ProtocolMarker for DeviceMarker {
141    type Proxy = DeviceProxy;
142    type RequestStream = DeviceRequestStream;
143    #[cfg(target_os = "fuchsia")]
144    type SynchronousProxy = DeviceSynchronousProxy;
145
146    const DEBUG_NAME: &'static str = "fuchsia.ui.pointerinjector.Device";
147}
148impl fidl::endpoints::DiscoverableProtocolMarker for DeviceMarker {}
149
150pub trait DeviceProxyInterface: Send + Sync {
151    type InjectResponseFut: std::future::Future<Output = Result<(), fidl::Error>> + Send;
152    fn r#inject(&self, events: Vec<Event>) -> Self::InjectResponseFut;
153    fn r#inject_events(&self, events: Vec<Event>) -> Result<(), fidl::Error>;
154}
155#[derive(Debug)]
156#[cfg(target_os = "fuchsia")]
157pub struct DeviceSynchronousProxy {
158    client: fidl::client::sync::Client,
159}
160
161#[cfg(target_os = "fuchsia")]
162impl fidl::endpoints::SynchronousProxy for DeviceSynchronousProxy {
163    type Proxy = DeviceProxy;
164    type Protocol = DeviceMarker;
165
166    fn from_channel(inner: fidl::Channel) -> Self {
167        Self::new(inner)
168    }
169
170    fn into_channel(self) -> fidl::Channel {
171        self.client.into_channel()
172    }
173
174    fn as_channel(&self) -> &fidl::Channel {
175        self.client.as_channel()
176    }
177}
178
179#[cfg(target_os = "fuchsia")]
180impl DeviceSynchronousProxy {
181    pub fn new(channel: fidl::Channel) -> Self {
182        Self { client: fidl::client::sync::Client::new(channel) }
183    }
184
185    pub fn into_channel(self) -> fidl::Channel {
186        self.client.into_channel()
187    }
188
189    /// Waits until an event arrives and returns it. It is safe for other
190    /// threads to make concurrent requests while waiting for an event.
191    pub fn wait_for_event(
192        &self,
193        deadline: zx::MonotonicInstant,
194    ) -> Result<DeviceEvent, fidl::Error> {
195        DeviceEvent::decode(self.client.wait_for_event::<DeviceMarker>(deadline)?)
196    }
197
198    /// Injects events into a target.
199    ///
200    /// Batching: The caller is expected to batch-inject all events that share the
201    /// same timestamp (e.g., multiple finger samples). There may be multiple such
202    /// batches per injection call.
203    ///
204    /// Flow control: The caller is allowed at most one in-flight |Inject| call
205    /// at at time: subsequent |Inject| calls must wait until the acknowledgment
206    /// returns. Non-compliance results in channel closure.
207    pub fn r#inject(
208        &self,
209        mut events: Vec<Event>,
210        ___deadline: zx::MonotonicInstant,
211    ) -> Result<(), fidl::Error> {
212        let _response = self
213            .client
214            .send_query::<DeviceInjectRequest, fidl::encoding::EmptyPayload, DeviceMarker>(
215                (events.as_mut(),),
216                0x123882bb65bff40,
217                fidl::encoding::DynamicFlags::empty(),
218                ___deadline,
219            )?;
220        Ok(_response)
221    }
222
223    /// Injects events into a target.
224    ///
225    /// Batching: The caller is expected to batch-inject all events that share the
226    /// same timestamp (e.g., multiple finger samples). There may be multiple such
227    /// batches per injection call.
228    pub fn r#inject_events(&self, mut events: Vec<Event>) -> Result<(), fidl::Error> {
229        self.client.send::<DeviceInjectRequest>(
230            (events.as_mut(),),
231            0x55a9b59dabe61637,
232            fidl::encoding::DynamicFlags::empty(),
233        )
234    }
235}
236
237#[cfg(target_os = "fuchsia")]
238impl From<DeviceSynchronousProxy> for zx::NullableHandle {
239    fn from(value: DeviceSynchronousProxy) -> Self {
240        value.into_channel().into()
241    }
242}
243
244#[cfg(target_os = "fuchsia")]
245impl From<fidl::Channel> for DeviceSynchronousProxy {
246    fn from(value: fidl::Channel) -> Self {
247        Self::new(value)
248    }
249}
250
251#[cfg(target_os = "fuchsia")]
252impl fidl::endpoints::FromClient for DeviceSynchronousProxy {
253    type Protocol = DeviceMarker;
254
255    fn from_client(value: fidl::endpoints::ClientEnd<DeviceMarker>) -> Self {
256        Self::new(value.into_channel())
257    }
258}
259
260#[derive(Debug, Clone)]
261pub struct DeviceProxy {
262    client: fidl::client::Client<fidl::encoding::DefaultFuchsiaResourceDialect>,
263}
264
265impl fidl::endpoints::Proxy for DeviceProxy {
266    type Protocol = DeviceMarker;
267
268    fn from_channel(inner: ::fidl::AsyncChannel) -> Self {
269        Self::new(inner)
270    }
271
272    fn into_channel(self) -> Result<::fidl::AsyncChannel, Self> {
273        self.client.into_channel().map_err(|client| Self { client })
274    }
275
276    fn as_channel(&self) -> &::fidl::AsyncChannel {
277        self.client.as_channel()
278    }
279}
280
281impl DeviceProxy {
282    /// Create a new Proxy for fuchsia.ui.pointerinjector/Device.
283    pub fn new(channel: ::fidl::AsyncChannel) -> Self {
284        let protocol_name = <DeviceMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME;
285        Self { client: fidl::client::Client::new(channel, protocol_name) }
286    }
287
288    /// Get a Stream of events from the remote end of the protocol.
289    ///
290    /// # Panics
291    ///
292    /// Panics if the event stream was already taken.
293    pub fn take_event_stream(&self) -> DeviceEventStream {
294        DeviceEventStream { event_receiver: self.client.take_event_receiver() }
295    }
296
297    /// Injects events into a target.
298    ///
299    /// Batching: The caller is expected to batch-inject all events that share the
300    /// same timestamp (e.g., multiple finger samples). There may be multiple such
301    /// batches per injection call.
302    ///
303    /// Flow control: The caller is allowed at most one in-flight |Inject| call
304    /// at at time: subsequent |Inject| calls must wait until the acknowledgment
305    /// returns. Non-compliance results in channel closure.
306    pub fn r#inject(
307        &self,
308        mut events: Vec<Event>,
309    ) -> fidl::client::QueryResponseFut<(), fidl::encoding::DefaultFuchsiaResourceDialect> {
310        DeviceProxyInterface::r#inject(self, events)
311    }
312
313    /// Injects events into a target.
314    ///
315    /// Batching: The caller is expected to batch-inject all events that share the
316    /// same timestamp (e.g., multiple finger samples). There may be multiple such
317    /// batches per injection call.
318    pub fn r#inject_events(&self, mut events: Vec<Event>) -> Result<(), fidl::Error> {
319        DeviceProxyInterface::r#inject_events(self, events)
320    }
321}
322
323impl DeviceProxyInterface for DeviceProxy {
324    type InjectResponseFut =
325        fidl::client::QueryResponseFut<(), fidl::encoding::DefaultFuchsiaResourceDialect>;
326    fn r#inject(&self, mut events: Vec<Event>) -> Self::InjectResponseFut {
327        fn _decode(
328            mut _buf: Result<<fidl::encoding::DefaultFuchsiaResourceDialect as fidl::encoding::ResourceDialect>::MessageBufEtc, fidl::Error>,
329        ) -> Result<(), fidl::Error> {
330            let _response = fidl::client::decode_transaction_body::<
331                fidl::encoding::EmptyPayload,
332                fidl::encoding::DefaultFuchsiaResourceDialect,
333                0x123882bb65bff40,
334            >(_buf?)?;
335            Ok(_response)
336        }
337        self.client.send_query_and_decode::<DeviceInjectRequest, ()>(
338            (events.as_mut(),),
339            0x123882bb65bff40,
340            fidl::encoding::DynamicFlags::empty(),
341            _decode,
342        )
343    }
344
345    fn r#inject_events(&self, mut events: Vec<Event>) -> Result<(), fidl::Error> {
346        self.client.send::<DeviceInjectRequest>(
347            (events.as_mut(),),
348            0x55a9b59dabe61637,
349            fidl::encoding::DynamicFlags::empty(),
350        )
351    }
352}
353
354pub struct DeviceEventStream {
355    event_receiver: fidl::client::EventReceiver<fidl::encoding::DefaultFuchsiaResourceDialect>,
356}
357
358impl std::marker::Unpin for DeviceEventStream {}
359
360impl futures::stream::FusedStream for DeviceEventStream {
361    fn is_terminated(&self) -> bool {
362        self.event_receiver.is_terminated()
363    }
364}
365
366impl futures::Stream for DeviceEventStream {
367    type Item = Result<DeviceEvent, fidl::Error>;
368
369    fn poll_next(
370        mut self: std::pin::Pin<&mut Self>,
371        cx: &mut std::task::Context<'_>,
372    ) -> std::task::Poll<Option<Self::Item>> {
373        match futures::ready!(futures::stream::StreamExt::poll_next_unpin(
374            &mut self.event_receiver,
375            cx
376        )?) {
377            Some(buf) => std::task::Poll::Ready(Some(DeviceEvent::decode(buf))),
378            None => std::task::Poll::Ready(None),
379        }
380    }
381}
382
383#[derive(Debug)]
384pub enum DeviceEvent {}
385
386impl DeviceEvent {
387    /// Decodes a message buffer as a [`DeviceEvent`].
388    fn decode(
389        mut buf: <fidl::encoding::DefaultFuchsiaResourceDialect as fidl::encoding::ResourceDialect>::MessageBufEtc,
390    ) -> Result<DeviceEvent, fidl::Error> {
391        let (bytes, _handles) = buf.split_mut();
392        let (tx_header, _body_bytes) = fidl::encoding::decode_transaction_header(bytes)?;
393        debug_assert_eq!(tx_header.tx_id, 0);
394        match tx_header.ordinal {
395            _ => Err(fidl::Error::UnknownOrdinal {
396                ordinal: tx_header.ordinal,
397                protocol_name: <DeviceMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME,
398            }),
399        }
400    }
401}
402
403/// A Stream of incoming requests for fuchsia.ui.pointerinjector/Device.
404pub struct DeviceRequestStream {
405    inner: std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>,
406    is_terminated: bool,
407}
408
409impl std::marker::Unpin for DeviceRequestStream {}
410
411impl futures::stream::FusedStream for DeviceRequestStream {
412    fn is_terminated(&self) -> bool {
413        self.is_terminated
414    }
415}
416
417impl fidl::endpoints::RequestStream for DeviceRequestStream {
418    type Protocol = DeviceMarker;
419    type ControlHandle = DeviceControlHandle;
420
421    fn from_channel(channel: ::fidl::AsyncChannel) -> Self {
422        Self { inner: std::sync::Arc::new(fidl::ServeInner::new(channel)), is_terminated: false }
423    }
424
425    fn control_handle(&self) -> Self::ControlHandle {
426        DeviceControlHandle { inner: self.inner.clone() }
427    }
428
429    fn into_inner(
430        self,
431    ) -> (::std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>, bool)
432    {
433        (self.inner, self.is_terminated)
434    }
435
436    fn from_inner(
437        inner: std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>,
438        is_terminated: bool,
439    ) -> Self {
440        Self { inner, is_terminated }
441    }
442}
443
444impl futures::Stream for DeviceRequestStream {
445    type Item = Result<DeviceRequest, fidl::Error>;
446
447    fn poll_next(
448        mut self: std::pin::Pin<&mut Self>,
449        cx: &mut std::task::Context<'_>,
450    ) -> std::task::Poll<Option<Self::Item>> {
451        let this = &mut *self;
452        if this.inner.check_shutdown(cx) {
453            this.is_terminated = true;
454            return std::task::Poll::Ready(None);
455        }
456        if this.is_terminated {
457            panic!("polled DeviceRequestStream after completion");
458        }
459        fidl::encoding::with_tls_decode_buf::<_, fidl::encoding::DefaultFuchsiaResourceDialect>(
460            |bytes, handles| {
461                match this.inner.channel().read_etc(cx, bytes, handles) {
462                    std::task::Poll::Ready(Ok(())) => {}
463                    std::task::Poll::Pending => return std::task::Poll::Pending,
464                    std::task::Poll::Ready(Err(zx_status::Status::PEER_CLOSED)) => {
465                        this.is_terminated = true;
466                        return std::task::Poll::Ready(None);
467                    }
468                    std::task::Poll::Ready(Err(e)) => {
469                        return std::task::Poll::Ready(Some(Err(fidl::Error::ServerRequestRead(
470                            e.into(),
471                        ))));
472                    }
473                }
474
475                // A message has been received from the channel
476                let (header, _body_bytes) = fidl::encoding::decode_transaction_header(bytes)?;
477
478                std::task::Poll::Ready(Some(match header.ordinal {
479                    0x123882bb65bff40 => {
480                        header.validate_request_tx_id(fidl::MethodType::TwoWay)?;
481                        let mut req = fidl::new_empty!(
482                            DeviceInjectRequest,
483                            fidl::encoding::DefaultFuchsiaResourceDialect
484                        );
485                        fidl::encoding::Decoder::<fidl::encoding::DefaultFuchsiaResourceDialect>::decode_into::<DeviceInjectRequest>(&header, _body_bytes, handles, &mut req)?;
486                        let control_handle = DeviceControlHandle { inner: this.inner.clone() };
487                        Ok(DeviceRequest::Inject {
488                            events: req.events,
489
490                            responder: DeviceInjectResponder {
491                                control_handle: std::mem::ManuallyDrop::new(control_handle),
492                                tx_id: header.tx_id,
493                            },
494                        })
495                    }
496                    0x55a9b59dabe61637 => {
497                        header.validate_request_tx_id(fidl::MethodType::OneWay)?;
498                        let mut req = fidl::new_empty!(
499                            DeviceInjectRequest,
500                            fidl::encoding::DefaultFuchsiaResourceDialect
501                        );
502                        fidl::encoding::Decoder::<fidl::encoding::DefaultFuchsiaResourceDialect>::decode_into::<DeviceInjectRequest>(&header, _body_bytes, handles, &mut req)?;
503                        let control_handle = DeviceControlHandle { inner: this.inner.clone() };
504                        Ok(DeviceRequest::InjectEvents { events: req.events, control_handle })
505                    }
506                    _ => Err(fidl::Error::UnknownOrdinal {
507                        ordinal: header.ordinal,
508                        protocol_name:
509                            <DeviceMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME,
510                    }),
511                }))
512            },
513        )
514    }
515}
516
517/// The channel for injecting pointer events into a target.
518/// The associated |Config| applies to injected pointer events.
519///
520/// A |Device| may *inject* pointer events into a target in the scene, but the
521/// *dispatch* of pointer events to UI clients within that target's view tree
522/// will depend on the dispatch policy and the scene topology.
523#[derive(Debug)]
524pub enum DeviceRequest {
525    /// Injects events into a target.
526    ///
527    /// Batching: The caller is expected to batch-inject all events that share the
528    /// same timestamp (e.g., multiple finger samples). There may be multiple such
529    /// batches per injection call.
530    ///
531    /// Flow control: The caller is allowed at most one in-flight |Inject| call
532    /// at at time: subsequent |Inject| calls must wait until the acknowledgment
533    /// returns. Non-compliance results in channel closure.
534    Inject { events: Vec<Event>, responder: DeviceInjectResponder },
535    /// Injects events into a target.
536    ///
537    /// Batching: The caller is expected to batch-inject all events that share the
538    /// same timestamp (e.g., multiple finger samples). There may be multiple such
539    /// batches per injection call.
540    InjectEvents { events: Vec<Event>, control_handle: DeviceControlHandle },
541}
542
543impl DeviceRequest {
544    #[allow(irrefutable_let_patterns)]
545    pub fn into_inject(self) -> Option<(Vec<Event>, DeviceInjectResponder)> {
546        if let DeviceRequest::Inject { events, responder } = self {
547            Some((events, responder))
548        } else {
549            None
550        }
551    }
552
553    #[allow(irrefutable_let_patterns)]
554    pub fn into_inject_events(self) -> Option<(Vec<Event>, DeviceControlHandle)> {
555        if let DeviceRequest::InjectEvents { events, control_handle } = self {
556            Some((events, control_handle))
557        } else {
558            None
559        }
560    }
561
562    /// Name of the method defined in FIDL
563    pub fn method_name(&self) -> &'static str {
564        match *self {
565            DeviceRequest::Inject { .. } => "inject",
566            DeviceRequest::InjectEvents { .. } => "inject_events",
567        }
568    }
569}
570
571#[derive(Debug, Clone)]
572pub struct DeviceControlHandle {
573    inner: std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>,
574}
575
576impl DeviceControlHandle {
577    pub fn shutdown_with_epitaph(&self, status: impl Into<fidl::Epitaph>) {
578        self.inner.shutdown_with_epitaph(status.into())
579    }
580}
581
582impl fidl::endpoints::ControlHandle for DeviceControlHandle {
583    fn shutdown(&self) {
584        self.inner.shutdown()
585    }
586
587    fn shutdown_with_epitaph(&self, status: fidl::Epitaph) {
588        self.inner.shutdown_with_epitaph(status)
589    }
590
591    fn is_closed(&self) -> bool {
592        self.inner.channel().is_closed()
593    }
594    fn on_closed(&self) -> fidl::OnSignalsRef<'_> {
595        self.inner.channel().on_closed()
596    }
597
598    #[cfg(target_os = "fuchsia")]
599    fn signal_peer(
600        &self,
601        clear_mask: zx::Signals,
602        set_mask: zx::Signals,
603    ) -> Result<(), zx_status::Status> {
604        use fidl::Peered;
605        self.inner.channel().signal_peer(clear_mask, set_mask)
606    }
607}
608
609impl DeviceControlHandle {}
610
611#[must_use = "FIDL methods require a response to be sent"]
612#[derive(Debug)]
613pub struct DeviceInjectResponder {
614    control_handle: std::mem::ManuallyDrop<DeviceControlHandle>,
615    tx_id: u32,
616}
617
618/// Set the the channel to be shutdown (see [`DeviceControlHandle::shutdown`])
619/// if the responder is dropped without sending a response, so that the client
620/// doesn't hang. To prevent this behavior, call `drop_without_shutdown`.
621impl std::ops::Drop for DeviceInjectResponder {
622    fn drop(&mut self) {
623        self.control_handle.shutdown();
624        // Safety: drops once, never accessed again
625        unsafe { std::mem::ManuallyDrop::drop(&mut self.control_handle) };
626    }
627}
628
629impl fidl::endpoints::Responder for DeviceInjectResponder {
630    type ControlHandle = DeviceControlHandle;
631
632    fn control_handle(&self) -> &DeviceControlHandle {
633        &self.control_handle
634    }
635
636    fn drop_without_shutdown(mut self) {
637        // Safety: drops once, never accessed again due to mem::forget
638        unsafe { std::mem::ManuallyDrop::drop(&mut self.control_handle) };
639        // Prevent Drop from running (which would shut down the channel)
640        std::mem::forget(self);
641    }
642}
643
644impl DeviceInjectResponder {
645    /// Sends a response to the FIDL transaction.
646    ///
647    /// Sets the channel to shutdown if an error occurs.
648    pub fn send(self) -> Result<(), fidl::Error> {
649        let _result = self.send_raw();
650        if _result.is_err() {
651            self.control_handle.shutdown();
652        }
653        self.drop_without_shutdown();
654        _result
655    }
656
657    /// Similar to "send" but does not shutdown the channel if an error occurs.
658    pub fn send_no_shutdown_on_err(self) -> Result<(), fidl::Error> {
659        let _result = self.send_raw();
660        self.drop_without_shutdown();
661        _result
662    }
663
664    fn send_raw(&self) -> Result<(), fidl::Error> {
665        self.control_handle.inner.send::<fidl::encoding::EmptyPayload>(
666            (),
667            self.tx_id,
668            0x123882bb65bff40,
669            fidl::encoding::DynamicFlags::empty(),
670        )
671    }
672}
673
674#[derive(Debug, Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Hash)]
675pub struct RegistryMarker;
676
677impl fidl::endpoints::ProtocolMarker for RegistryMarker {
678    type Proxy = RegistryProxy;
679    type RequestStream = RegistryRequestStream;
680    #[cfg(target_os = "fuchsia")]
681    type SynchronousProxy = RegistrySynchronousProxy;
682
683    const DEBUG_NAME: &'static str = "fuchsia.ui.pointerinjector.Registry";
684}
685impl fidl::endpoints::DiscoverableProtocolMarker for RegistryMarker {}
686
687pub trait RegistryProxyInterface: Send + Sync {
688    type RegisterResponseFut: std::future::Future<Output = Result<(), fidl::Error>> + Send;
689    fn r#register(
690        &self,
691        config: Config,
692        injector: fidl::endpoints::ServerEnd<DeviceMarker>,
693    ) -> Self::RegisterResponseFut;
694}
695#[derive(Debug)]
696#[cfg(target_os = "fuchsia")]
697pub struct RegistrySynchronousProxy {
698    client: fidl::client::sync::Client,
699}
700
701#[cfg(target_os = "fuchsia")]
702impl fidl::endpoints::SynchronousProxy for RegistrySynchronousProxy {
703    type Proxy = RegistryProxy;
704    type Protocol = RegistryMarker;
705
706    fn from_channel(inner: fidl::Channel) -> Self {
707        Self::new(inner)
708    }
709
710    fn into_channel(self) -> fidl::Channel {
711        self.client.into_channel()
712    }
713
714    fn as_channel(&self) -> &fidl::Channel {
715        self.client.as_channel()
716    }
717}
718
719#[cfg(target_os = "fuchsia")]
720impl RegistrySynchronousProxy {
721    pub fn new(channel: fidl::Channel) -> Self {
722        Self { client: fidl::client::sync::Client::new(channel) }
723    }
724
725    pub fn into_channel(self) -> fidl::Channel {
726        self.client.into_channel()
727    }
728
729    /// Waits until an event arrives and returns it. It is safe for other
730    /// threads to make concurrent requests while waiting for an event.
731    pub fn wait_for_event(
732        &self,
733        deadline: zx::MonotonicInstant,
734    ) -> Result<RegistryEvent, fidl::Error> {
735        RegistryEvent::decode(self.client.wait_for_event::<RegistryMarker>(deadline)?)
736    }
737
738    /// Sets up a context for a |Device|, the target for the |Device|, and
739    /// directs the |Device| at the target via a viewport, positioned in the
740    /// context. These parameters are specified in a |Config|.
741    ///
742    /// If |config| is invalid (e.g., missing important data), the |Device|
743    /// request will be denied: the channel will be closed.
744    ///
745    /// The return event tells the caller that (1) the server has processed the
746    /// call, and (2) the |Device| is connected.
747    pub fn r#register(
748        &self,
749        mut config: Config,
750        mut injector: fidl::endpoints::ServerEnd<DeviceMarker>,
751        ___deadline: zx::MonotonicInstant,
752    ) -> Result<(), fidl::Error> {
753        let _response = self
754            .client
755            .send_query::<RegistryRegisterRequest, fidl::encoding::EmptyPayload, RegistryMarker>(
756                (&mut config, injector),
757                0x9f8410fe7326a00,
758                fidl::encoding::DynamicFlags::empty(),
759                ___deadline,
760            )?;
761        Ok(_response)
762    }
763}
764
765#[cfg(target_os = "fuchsia")]
766impl From<RegistrySynchronousProxy> for zx::NullableHandle {
767    fn from(value: RegistrySynchronousProxy) -> Self {
768        value.into_channel().into()
769    }
770}
771
772#[cfg(target_os = "fuchsia")]
773impl From<fidl::Channel> for RegistrySynchronousProxy {
774    fn from(value: fidl::Channel) -> Self {
775        Self::new(value)
776    }
777}
778
779#[cfg(target_os = "fuchsia")]
780impl fidl::endpoints::FromClient for RegistrySynchronousProxy {
781    type Protocol = RegistryMarker;
782
783    fn from_client(value: fidl::endpoints::ClientEnd<RegistryMarker>) -> Self {
784        Self::new(value.into_channel())
785    }
786}
787
788#[derive(Debug, Clone)]
789pub struct RegistryProxy {
790    client: fidl::client::Client<fidl::encoding::DefaultFuchsiaResourceDialect>,
791}
792
793impl fidl::endpoints::Proxy for RegistryProxy {
794    type Protocol = RegistryMarker;
795
796    fn from_channel(inner: ::fidl::AsyncChannel) -> Self {
797        Self::new(inner)
798    }
799
800    fn into_channel(self) -> Result<::fidl::AsyncChannel, Self> {
801        self.client.into_channel().map_err(|client| Self { client })
802    }
803
804    fn as_channel(&self) -> &::fidl::AsyncChannel {
805        self.client.as_channel()
806    }
807}
808
809impl RegistryProxy {
810    /// Create a new Proxy for fuchsia.ui.pointerinjector/Registry.
811    pub fn new(channel: ::fidl::AsyncChannel) -> Self {
812        let protocol_name = <RegistryMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME;
813        Self { client: fidl::client::Client::new(channel, protocol_name) }
814    }
815
816    /// Get a Stream of events from the remote end of the protocol.
817    ///
818    /// # Panics
819    ///
820    /// Panics if the event stream was already taken.
821    pub fn take_event_stream(&self) -> RegistryEventStream {
822        RegistryEventStream { event_receiver: self.client.take_event_receiver() }
823    }
824
825    /// Sets up a context for a |Device|, the target for the |Device|, and
826    /// directs the |Device| at the target via a viewport, positioned in the
827    /// context. These parameters are specified in a |Config|.
828    ///
829    /// If |config| is invalid (e.g., missing important data), the |Device|
830    /// request will be denied: the channel will be closed.
831    ///
832    /// The return event tells the caller that (1) the server has processed the
833    /// call, and (2) the |Device| is connected.
834    pub fn r#register(
835        &self,
836        mut config: Config,
837        mut injector: fidl::endpoints::ServerEnd<DeviceMarker>,
838    ) -> fidl::client::QueryResponseFut<(), fidl::encoding::DefaultFuchsiaResourceDialect> {
839        RegistryProxyInterface::r#register(self, config, injector)
840    }
841}
842
843impl RegistryProxyInterface for RegistryProxy {
844    type RegisterResponseFut =
845        fidl::client::QueryResponseFut<(), fidl::encoding::DefaultFuchsiaResourceDialect>;
846    fn r#register(
847        &self,
848        mut config: Config,
849        mut injector: fidl::endpoints::ServerEnd<DeviceMarker>,
850    ) -> Self::RegisterResponseFut {
851        fn _decode(
852            mut _buf: Result<<fidl::encoding::DefaultFuchsiaResourceDialect as fidl::encoding::ResourceDialect>::MessageBufEtc, fidl::Error>,
853        ) -> Result<(), fidl::Error> {
854            let _response = fidl::client::decode_transaction_body::<
855                fidl::encoding::EmptyPayload,
856                fidl::encoding::DefaultFuchsiaResourceDialect,
857                0x9f8410fe7326a00,
858            >(_buf?)?;
859            Ok(_response)
860        }
861        self.client.send_query_and_decode::<RegistryRegisterRequest, ()>(
862            (&mut config, injector),
863            0x9f8410fe7326a00,
864            fidl::encoding::DynamicFlags::empty(),
865            _decode,
866        )
867    }
868}
869
870pub struct RegistryEventStream {
871    event_receiver: fidl::client::EventReceiver<fidl::encoding::DefaultFuchsiaResourceDialect>,
872}
873
874impl std::marker::Unpin for RegistryEventStream {}
875
876impl futures::stream::FusedStream for RegistryEventStream {
877    fn is_terminated(&self) -> bool {
878        self.event_receiver.is_terminated()
879    }
880}
881
882impl futures::Stream for RegistryEventStream {
883    type Item = Result<RegistryEvent, fidl::Error>;
884
885    fn poll_next(
886        mut self: std::pin::Pin<&mut Self>,
887        cx: &mut std::task::Context<'_>,
888    ) -> std::task::Poll<Option<Self::Item>> {
889        match futures::ready!(futures::stream::StreamExt::poll_next_unpin(
890            &mut self.event_receiver,
891            cx
892        )?) {
893            Some(buf) => std::task::Poll::Ready(Some(RegistryEvent::decode(buf))),
894            None => std::task::Poll::Ready(None),
895        }
896    }
897}
898
899#[derive(Debug)]
900pub enum RegistryEvent {}
901
902impl RegistryEvent {
903    /// Decodes a message buffer as a [`RegistryEvent`].
904    fn decode(
905        mut buf: <fidl::encoding::DefaultFuchsiaResourceDialect as fidl::encoding::ResourceDialect>::MessageBufEtc,
906    ) -> Result<RegistryEvent, fidl::Error> {
907        let (bytes, _handles) = buf.split_mut();
908        let (tx_header, _body_bytes) = fidl::encoding::decode_transaction_header(bytes)?;
909        debug_assert_eq!(tx_header.tx_id, 0);
910        match tx_header.ordinal {
911            _ => Err(fidl::Error::UnknownOrdinal {
912                ordinal: tx_header.ordinal,
913                protocol_name: <RegistryMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME,
914            }),
915        }
916    }
917}
918
919/// A Stream of incoming requests for fuchsia.ui.pointerinjector/Registry.
920pub struct RegistryRequestStream {
921    inner: std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>,
922    is_terminated: bool,
923}
924
925impl std::marker::Unpin for RegistryRequestStream {}
926
927impl futures::stream::FusedStream for RegistryRequestStream {
928    fn is_terminated(&self) -> bool {
929        self.is_terminated
930    }
931}
932
933impl fidl::endpoints::RequestStream for RegistryRequestStream {
934    type Protocol = RegistryMarker;
935    type ControlHandle = RegistryControlHandle;
936
937    fn from_channel(channel: ::fidl::AsyncChannel) -> Self {
938        Self { inner: std::sync::Arc::new(fidl::ServeInner::new(channel)), is_terminated: false }
939    }
940
941    fn control_handle(&self) -> Self::ControlHandle {
942        RegistryControlHandle { inner: self.inner.clone() }
943    }
944
945    fn into_inner(
946        self,
947    ) -> (::std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>, bool)
948    {
949        (self.inner, self.is_terminated)
950    }
951
952    fn from_inner(
953        inner: std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>,
954        is_terminated: bool,
955    ) -> Self {
956        Self { inner, is_terminated }
957    }
958}
959
960impl futures::Stream for RegistryRequestStream {
961    type Item = Result<RegistryRequest, fidl::Error>;
962
963    fn poll_next(
964        mut self: std::pin::Pin<&mut Self>,
965        cx: &mut std::task::Context<'_>,
966    ) -> std::task::Poll<Option<Self::Item>> {
967        let this = &mut *self;
968        if this.inner.check_shutdown(cx) {
969            this.is_terminated = true;
970            return std::task::Poll::Ready(None);
971        }
972        if this.is_terminated {
973            panic!("polled RegistryRequestStream after completion");
974        }
975        fidl::encoding::with_tls_decode_buf::<_, fidl::encoding::DefaultFuchsiaResourceDialect>(
976            |bytes, handles| {
977                match this.inner.channel().read_etc(cx, bytes, handles) {
978                    std::task::Poll::Ready(Ok(())) => {}
979                    std::task::Poll::Pending => return std::task::Poll::Pending,
980                    std::task::Poll::Ready(Err(zx_status::Status::PEER_CLOSED)) => {
981                        this.is_terminated = true;
982                        return std::task::Poll::Ready(None);
983                    }
984                    std::task::Poll::Ready(Err(e)) => {
985                        return std::task::Poll::Ready(Some(Err(fidl::Error::ServerRequestRead(
986                            e.into(),
987                        ))));
988                    }
989                }
990
991                // A message has been received from the channel
992                let (header, _body_bytes) = fidl::encoding::decode_transaction_header(bytes)?;
993
994                std::task::Poll::Ready(Some(match header.ordinal {
995                    0x9f8410fe7326a00 => {
996                        header.validate_request_tx_id(fidl::MethodType::TwoWay)?;
997                        let mut req = fidl::new_empty!(
998                            RegistryRegisterRequest,
999                            fidl::encoding::DefaultFuchsiaResourceDialect
1000                        );
1001                        fidl::encoding::Decoder::<fidl::encoding::DefaultFuchsiaResourceDialect>::decode_into::<RegistryRegisterRequest>(&header, _body_bytes, handles, &mut req)?;
1002                        let control_handle = RegistryControlHandle { inner: this.inner.clone() };
1003                        Ok(RegistryRequest::Register {
1004                            config: req.config,
1005                            injector: req.injector,
1006
1007                            responder: RegistryRegisterResponder {
1008                                control_handle: std::mem::ManuallyDrop::new(control_handle),
1009                                tx_id: header.tx_id,
1010                            },
1011                        })
1012                    }
1013                    _ => Err(fidl::Error::UnknownOrdinal {
1014                        ordinal: header.ordinal,
1015                        protocol_name:
1016                            <RegistryMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME,
1017                    }),
1018                }))
1019            },
1020        )
1021    }
1022}
1023
1024/// A coordination mechanism to clearly define the *injecting* of pointer events
1025/// into the scene (injection policy, injection context, etc), for *dispatching*
1026/// pointer events to UI clients (referenced by |fuchsia.ui.views.ViewRef|).
1027///
1028/// NOTE WELL! ONLY COMPONENTS IN THE TRUSTED COMPUTING BASE SHOULD BE GRANTED
1029///            ACCESS TO THIS PROTOCOL.
1030/// (1) The injector device acts with the user's authority. UI clients cannot
1031///     tell the difference between a real user and an injector device.
1032/// (2) The context is self-specified when registering the injector device. An
1033///     injector device that gains access to a sensitive context will operate in
1034///     that scope.
1035/// (3) The injected events may be arbitrary. An injector device can inject
1036///     whatever it wants to the clients it can reach.
1037///
1038/// This protocol defines the context and target for an injector |Device|,
1039/// places a viewport in spatial relation to the target, and connects the
1040/// |Device| to the viewport. These parameters are set up in the |Config|. A
1041/// |Device| may *inject* pointer events on the viewport, but the *dispatch* of
1042/// pointer events to UI clients in the target will depend on the dispatch
1043/// policy and the scene topology.
1044///
1045/// A |Device| operates within a context, and it serves two purposes:
1046/// (1) Scoping. It confirms the |Device|'s authority to inject pointer events
1047///     on the specified target.
1048/// (2) Coordinate system. It provides the reference coordinate system to define
1049///     the viewport's position and size, relative to the target.
1050///
1051/// Guarantees. A |Device| is directed at a specified target in the scene, and
1052/// such a target is afforded some guarantees against snooping and interference
1053/// from UI clients outside the target's view tree ("non-target clients").
1054/// Non-target clients never have injected events dispatched to them: a |Device|
1055/// preserves *confidentiality* for target clients.  Non-target clients never
1056/// block injected events from reaching the target on injection, or from
1057/// reaching target clients on dispatch: a |Device| preserves *integrity* and
1058/// *availability* for target clients. However, the |Device| itself is subject
1059/// to disruption by ancestor views of the target (see connectivity invariant).
1060///
1061/// Note. This protocol, and its policies, are *not* a sufficient guard against
1062///       UI redress attacks! The confidentiality, integrity, and availability
1063///       guarantees apply only with respect to non-target clients. Within a
1064///       target, UI redress attacks can still happen, between target clients.
1065///
1066/// Connectivity invariant. A |Device| operates in a stable view tree that is
1067/// connected to the root view. When either the target, or both context and
1068/// target, are disconnected from the view tree by a UI client, the |Device|
1069/// channel is closed. If an event stream was in flight, the server dispatches a
1070/// final CANCEL event following channel closure; this CANCEL event is then
1071/// propagated according to dispatch policy.
1072#[derive(Debug)]
1073pub enum RegistryRequest {
1074    /// Sets up a context for a |Device|, the target for the |Device|, and
1075    /// directs the |Device| at the target via a viewport, positioned in the
1076    /// context. These parameters are specified in a |Config|.
1077    ///
1078    /// If |config| is invalid (e.g., missing important data), the |Device|
1079    /// request will be denied: the channel will be closed.
1080    ///
1081    /// The return event tells the caller that (1) the server has processed the
1082    /// call, and (2) the |Device| is connected.
1083    Register {
1084        config: Config,
1085        injector: fidl::endpoints::ServerEnd<DeviceMarker>,
1086        responder: RegistryRegisterResponder,
1087    },
1088}
1089
1090impl RegistryRequest {
1091    #[allow(irrefutable_let_patterns)]
1092    pub fn into_register(
1093        self,
1094    ) -> Option<(Config, fidl::endpoints::ServerEnd<DeviceMarker>, RegistryRegisterResponder)> {
1095        if let RegistryRequest::Register { config, injector, responder } = self {
1096            Some((config, injector, responder))
1097        } else {
1098            None
1099        }
1100    }
1101
1102    /// Name of the method defined in FIDL
1103    pub fn method_name(&self) -> &'static str {
1104        match *self {
1105            RegistryRequest::Register { .. } => "register",
1106        }
1107    }
1108}
1109
1110#[derive(Debug, Clone)]
1111pub struct RegistryControlHandle {
1112    inner: std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>,
1113}
1114
1115impl RegistryControlHandle {
1116    pub fn shutdown_with_epitaph(&self, status: impl Into<fidl::Epitaph>) {
1117        self.inner.shutdown_with_epitaph(status.into())
1118    }
1119}
1120
1121impl fidl::endpoints::ControlHandle for RegistryControlHandle {
1122    fn shutdown(&self) {
1123        self.inner.shutdown()
1124    }
1125
1126    fn shutdown_with_epitaph(&self, status: fidl::Epitaph) {
1127        self.inner.shutdown_with_epitaph(status)
1128    }
1129
1130    fn is_closed(&self) -> bool {
1131        self.inner.channel().is_closed()
1132    }
1133    fn on_closed(&self) -> fidl::OnSignalsRef<'_> {
1134        self.inner.channel().on_closed()
1135    }
1136
1137    #[cfg(target_os = "fuchsia")]
1138    fn signal_peer(
1139        &self,
1140        clear_mask: zx::Signals,
1141        set_mask: zx::Signals,
1142    ) -> Result<(), zx_status::Status> {
1143        use fidl::Peered;
1144        self.inner.channel().signal_peer(clear_mask, set_mask)
1145    }
1146}
1147
1148impl RegistryControlHandle {}
1149
1150#[must_use = "FIDL methods require a response to be sent"]
1151#[derive(Debug)]
1152pub struct RegistryRegisterResponder {
1153    control_handle: std::mem::ManuallyDrop<RegistryControlHandle>,
1154    tx_id: u32,
1155}
1156
1157/// Set the the channel to be shutdown (see [`RegistryControlHandle::shutdown`])
1158/// if the responder is dropped without sending a response, so that the client
1159/// doesn't hang. To prevent this behavior, call `drop_without_shutdown`.
1160impl std::ops::Drop for RegistryRegisterResponder {
1161    fn drop(&mut self) {
1162        self.control_handle.shutdown();
1163        // Safety: drops once, never accessed again
1164        unsafe { std::mem::ManuallyDrop::drop(&mut self.control_handle) };
1165    }
1166}
1167
1168impl fidl::endpoints::Responder for RegistryRegisterResponder {
1169    type ControlHandle = RegistryControlHandle;
1170
1171    fn control_handle(&self) -> &RegistryControlHandle {
1172        &self.control_handle
1173    }
1174
1175    fn drop_without_shutdown(mut self) {
1176        // Safety: drops once, never accessed again due to mem::forget
1177        unsafe { std::mem::ManuallyDrop::drop(&mut self.control_handle) };
1178        // Prevent Drop from running (which would shut down the channel)
1179        std::mem::forget(self);
1180    }
1181}
1182
1183impl RegistryRegisterResponder {
1184    /// Sends a response to the FIDL transaction.
1185    ///
1186    /// Sets the channel to shutdown if an error occurs.
1187    pub fn send(self) -> Result<(), fidl::Error> {
1188        let _result = self.send_raw();
1189        if _result.is_err() {
1190            self.control_handle.shutdown();
1191        }
1192        self.drop_without_shutdown();
1193        _result
1194    }
1195
1196    /// Similar to "send" but does not shutdown the channel if an error occurs.
1197    pub fn send_no_shutdown_on_err(self) -> Result<(), fidl::Error> {
1198        let _result = self.send_raw();
1199        self.drop_without_shutdown();
1200        _result
1201    }
1202
1203    fn send_raw(&self) -> Result<(), fidl::Error> {
1204        self.control_handle.inner.send::<fidl::encoding::EmptyPayload>(
1205            (),
1206            self.tx_id,
1207            0x9f8410fe7326a00,
1208            fidl::encoding::DynamicFlags::empty(),
1209        )
1210    }
1211}
1212
1213mod internal {
1214    use super::*;
1215
1216    impl fidl::encoding::ResourceTypeMarker for DeviceInjectRequest {
1217        type Borrowed<'a> = &'a mut Self;
1218        fn take_or_borrow<'a>(
1219            value: &'a mut <Self as fidl::encoding::TypeMarker>::Owned,
1220        ) -> Self::Borrowed<'a> {
1221            value
1222        }
1223    }
1224
1225    unsafe impl fidl::encoding::TypeMarker for DeviceInjectRequest {
1226        type Owned = Self;
1227
1228        #[inline(always)]
1229        fn inline_align(_context: fidl::encoding::Context) -> usize {
1230            8
1231        }
1232
1233        #[inline(always)]
1234        fn inline_size(_context: fidl::encoding::Context) -> usize {
1235            16
1236        }
1237    }
1238
1239    unsafe impl
1240        fidl::encoding::Encode<DeviceInjectRequest, fidl::encoding::DefaultFuchsiaResourceDialect>
1241        for &mut DeviceInjectRequest
1242    {
1243        #[inline]
1244        unsafe fn encode(
1245            self,
1246            encoder: &mut fidl::encoding::Encoder<
1247                '_,
1248                fidl::encoding::DefaultFuchsiaResourceDialect,
1249            >,
1250            offset: usize,
1251            _depth: fidl::encoding::Depth,
1252        ) -> fidl::Result<()> {
1253            encoder.debug_check_bounds::<DeviceInjectRequest>(offset);
1254            // Delegate to tuple encoding.
1255            fidl::encoding::Encode::<DeviceInjectRequest, fidl::encoding::DefaultFuchsiaResourceDialect>::encode(
1256                (
1257                    <fidl::encoding::Vector<Event, 128> as fidl::encoding::ResourceTypeMarker>::take_or_borrow(&mut self.events),
1258                ),
1259                encoder, offset, _depth
1260            )
1261        }
1262    }
1263    unsafe impl<
1264        T0: fidl::encoding::Encode<
1265                fidl::encoding::Vector<Event, 128>,
1266                fidl::encoding::DefaultFuchsiaResourceDialect,
1267            >,
1268    > fidl::encoding::Encode<DeviceInjectRequest, fidl::encoding::DefaultFuchsiaResourceDialect>
1269        for (T0,)
1270    {
1271        #[inline]
1272        unsafe fn encode(
1273            self,
1274            encoder: &mut fidl::encoding::Encoder<
1275                '_,
1276                fidl::encoding::DefaultFuchsiaResourceDialect,
1277            >,
1278            offset: usize,
1279            depth: fidl::encoding::Depth,
1280        ) -> fidl::Result<()> {
1281            encoder.debug_check_bounds::<DeviceInjectRequest>(offset);
1282            // Zero out padding regions. There's no need to apply masks
1283            // because the unmasked parts will be overwritten by fields.
1284            // Write the fields.
1285            self.0.encode(encoder, offset + 0, depth)?;
1286            Ok(())
1287        }
1288    }
1289
1290    impl fidl::encoding::Decode<Self, fidl::encoding::DefaultFuchsiaResourceDialect>
1291        for DeviceInjectRequest
1292    {
1293        #[inline(always)]
1294        fn new_empty() -> Self {
1295            Self {
1296                events: fidl::new_empty!(fidl::encoding::Vector<Event, 128>, fidl::encoding::DefaultFuchsiaResourceDialect),
1297            }
1298        }
1299
1300        #[inline]
1301        unsafe fn decode(
1302            &mut self,
1303            decoder: &mut fidl::encoding::Decoder<
1304                '_,
1305                fidl::encoding::DefaultFuchsiaResourceDialect,
1306            >,
1307            offset: usize,
1308            _depth: fidl::encoding::Depth,
1309        ) -> fidl::Result<()> {
1310            decoder.debug_check_bounds::<Self>(offset);
1311            // Verify that padding bytes are zero.
1312            fidl::decode!(fidl::encoding::Vector<Event, 128>, fidl::encoding::DefaultFuchsiaResourceDialect, &mut self.events, decoder, offset + 0, _depth)?;
1313            Ok(())
1314        }
1315    }
1316
1317    impl fidl::encoding::ResourceTypeMarker for RegistryRegisterRequest {
1318        type Borrowed<'a> = &'a mut Self;
1319        fn take_or_borrow<'a>(
1320            value: &'a mut <Self as fidl::encoding::TypeMarker>::Owned,
1321        ) -> Self::Borrowed<'a> {
1322            value
1323        }
1324    }
1325
1326    unsafe impl fidl::encoding::TypeMarker for RegistryRegisterRequest {
1327        type Owned = Self;
1328
1329        #[inline(always)]
1330        fn inline_align(_context: fidl::encoding::Context) -> usize {
1331            8
1332        }
1333
1334        #[inline(always)]
1335        fn inline_size(_context: fidl::encoding::Context) -> usize {
1336            24
1337        }
1338    }
1339
1340    unsafe impl
1341        fidl::encoding::Encode<
1342            RegistryRegisterRequest,
1343            fidl::encoding::DefaultFuchsiaResourceDialect,
1344        > for &mut RegistryRegisterRequest
1345    {
1346        #[inline]
1347        unsafe fn encode(
1348            self,
1349            encoder: &mut fidl::encoding::Encoder<
1350                '_,
1351                fidl::encoding::DefaultFuchsiaResourceDialect,
1352            >,
1353            offset: usize,
1354            _depth: fidl::encoding::Depth,
1355        ) -> fidl::Result<()> {
1356            encoder.debug_check_bounds::<RegistryRegisterRequest>(offset);
1357            // Delegate to tuple encoding.
1358            fidl::encoding::Encode::<RegistryRegisterRequest, fidl::encoding::DefaultFuchsiaResourceDialect>::encode(
1359                (
1360                    <Config as fidl::encoding::ResourceTypeMarker>::take_or_borrow(&mut self.config),
1361                    <fidl::encoding::Endpoint<fidl::endpoints::ServerEnd<DeviceMarker>> as fidl::encoding::ResourceTypeMarker>::take_or_borrow(&mut self.injector),
1362                ),
1363                encoder, offset, _depth
1364            )
1365        }
1366    }
1367    unsafe impl<
1368        T0: fidl::encoding::Encode<Config, fidl::encoding::DefaultFuchsiaResourceDialect>,
1369        T1: fidl::encoding::Encode<
1370                fidl::encoding::Endpoint<fidl::endpoints::ServerEnd<DeviceMarker>>,
1371                fidl::encoding::DefaultFuchsiaResourceDialect,
1372            >,
1373    >
1374        fidl::encoding::Encode<
1375            RegistryRegisterRequest,
1376            fidl::encoding::DefaultFuchsiaResourceDialect,
1377        > for (T0, T1)
1378    {
1379        #[inline]
1380        unsafe fn encode(
1381            self,
1382            encoder: &mut fidl::encoding::Encoder<
1383                '_,
1384                fidl::encoding::DefaultFuchsiaResourceDialect,
1385            >,
1386            offset: usize,
1387            depth: fidl::encoding::Depth,
1388        ) -> fidl::Result<()> {
1389            encoder.debug_check_bounds::<RegistryRegisterRequest>(offset);
1390            // Zero out padding regions. There's no need to apply masks
1391            // because the unmasked parts will be overwritten by fields.
1392            unsafe {
1393                let ptr = encoder.buf.as_mut_ptr().add(offset).offset(16);
1394                (ptr as *mut u64).write_unaligned(0);
1395            }
1396            // Write the fields.
1397            self.0.encode(encoder, offset + 0, depth)?;
1398            self.1.encode(encoder, offset + 16, depth)?;
1399            Ok(())
1400        }
1401    }
1402
1403    impl fidl::encoding::Decode<Self, fidl::encoding::DefaultFuchsiaResourceDialect>
1404        for RegistryRegisterRequest
1405    {
1406        #[inline(always)]
1407        fn new_empty() -> Self {
1408            Self {
1409                config: fidl::new_empty!(Config, fidl::encoding::DefaultFuchsiaResourceDialect),
1410                injector: fidl::new_empty!(
1411                    fidl::encoding::Endpoint<fidl::endpoints::ServerEnd<DeviceMarker>>,
1412                    fidl::encoding::DefaultFuchsiaResourceDialect
1413                ),
1414            }
1415        }
1416
1417        #[inline]
1418        unsafe fn decode(
1419            &mut self,
1420            decoder: &mut fidl::encoding::Decoder<
1421                '_,
1422                fidl::encoding::DefaultFuchsiaResourceDialect,
1423            >,
1424            offset: usize,
1425            _depth: fidl::encoding::Depth,
1426        ) -> fidl::Result<()> {
1427            decoder.debug_check_bounds::<Self>(offset);
1428            // Verify that padding bytes are zero.
1429            let ptr = unsafe { decoder.buf.as_ptr().add(offset).offset(16) };
1430            let padval = unsafe { (ptr as *const u64).read_unaligned() };
1431            let mask = 0xffffffff00000000u64;
1432            let maskedval = padval & mask;
1433            if maskedval != 0 {
1434                return Err(fidl::Error::NonZeroPadding {
1435                    padding_start: offset + 16 + ((mask as u64).trailing_zeros() / 8) as usize,
1436                });
1437            }
1438            fidl::decode!(
1439                Config,
1440                fidl::encoding::DefaultFuchsiaResourceDialect,
1441                &mut self.config,
1442                decoder,
1443                offset + 0,
1444                _depth
1445            )?;
1446            fidl::decode!(
1447                fidl::encoding::Endpoint<fidl::endpoints::ServerEnd<DeviceMarker>>,
1448                fidl::encoding::DefaultFuchsiaResourceDialect,
1449                &mut self.injector,
1450                decoder,
1451                offset + 16,
1452                _depth
1453            )?;
1454            Ok(())
1455        }
1456    }
1457
1458    impl Config {
1459        #[inline(always)]
1460        fn max_ordinal_present(&self) -> u64 {
1461            if let Some(_) = self.relative_motion_range {
1462                return 10;
1463            }
1464            if let Some(_) = self.buttons {
1465                return 9;
1466            }
1467            if let Some(_) = self.scroll_h_range {
1468                return 8;
1469            }
1470            if let Some(_) = self.scroll_v_range {
1471                return 7;
1472            }
1473            if let Some(_) = self.dispatch_policy {
1474                return 6;
1475            }
1476            if let Some(_) = self.viewport {
1477                return 5;
1478            }
1479            if let Some(_) = self.target {
1480                return 4;
1481            }
1482            if let Some(_) = self.context {
1483                return 3;
1484            }
1485            if let Some(_) = self.device_type {
1486                return 2;
1487            }
1488            if let Some(_) = self.device_id {
1489                return 1;
1490            }
1491            0
1492        }
1493    }
1494
1495    impl fidl::encoding::ResourceTypeMarker for Config {
1496        type Borrowed<'a> = &'a mut Self;
1497        fn take_or_borrow<'a>(
1498            value: &'a mut <Self as fidl::encoding::TypeMarker>::Owned,
1499        ) -> Self::Borrowed<'a> {
1500            value
1501        }
1502    }
1503
1504    unsafe impl fidl::encoding::TypeMarker for Config {
1505        type Owned = Self;
1506
1507        #[inline(always)]
1508        fn inline_align(_context: fidl::encoding::Context) -> usize {
1509            8
1510        }
1511
1512        #[inline(always)]
1513        fn inline_size(_context: fidl::encoding::Context) -> usize {
1514            16
1515        }
1516    }
1517
1518    unsafe impl fidl::encoding::Encode<Config, fidl::encoding::DefaultFuchsiaResourceDialect>
1519        for &mut Config
1520    {
1521        unsafe fn encode(
1522            self,
1523            encoder: &mut fidl::encoding::Encoder<
1524                '_,
1525                fidl::encoding::DefaultFuchsiaResourceDialect,
1526            >,
1527            offset: usize,
1528            mut depth: fidl::encoding::Depth,
1529        ) -> fidl::Result<()> {
1530            encoder.debug_check_bounds::<Config>(offset);
1531            // Vector header
1532            let max_ordinal: u64 = self.max_ordinal_present();
1533            encoder.write_num(max_ordinal, offset);
1534            encoder.write_num(fidl::encoding::ALLOC_PRESENT_U64, offset + 8);
1535            // Calling encoder.out_of_line_offset(0) is not allowed.
1536            if max_ordinal == 0 {
1537                return Ok(());
1538            }
1539            depth.increment()?;
1540            let envelope_size = 8;
1541            let bytes_len = max_ordinal as usize * envelope_size;
1542            #[allow(unused_variables)]
1543            let offset = encoder.out_of_line_offset(bytes_len);
1544            let mut _prev_end_offset: usize = 0;
1545            if 1 > 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 = (1 - 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                u32,
1562                fidl::encoding::DefaultFuchsiaResourceDialect,
1563            >(
1564                self.device_id.as_ref().map(<u32 as fidl::encoding::ValueTypeMarker>::borrow),
1565                encoder,
1566                offset + cur_offset,
1567                depth,
1568            )?;
1569
1570            _prev_end_offset = cur_offset + envelope_size;
1571            if 2 > max_ordinal {
1572                return Ok(());
1573            }
1574
1575            // Write at offset+(ordinal-1)*envelope_size, since ordinals are one-based and envelopes
1576            // are envelope_size bytes.
1577            let cur_offset: usize = (2 - 1) * envelope_size;
1578
1579            // Zero reserved fields.
1580            encoder.padding(offset + _prev_end_offset, cur_offset - _prev_end_offset);
1581
1582            // Safety:
1583            // - bytes_len is calculated to fit envelope_size*max(member.ordinal).
1584            // - Since cur_offset is envelope_size*(member.ordinal - 1) and the envelope takes
1585            //   envelope_size bytes, there is always sufficient room.
1586            fidl::encoding::encode_in_envelope_optional::<
1587                DeviceType,
1588                fidl::encoding::DefaultFuchsiaResourceDialect,
1589            >(
1590                self.device_type
1591                    .as_ref()
1592                    .map(<DeviceType as fidl::encoding::ValueTypeMarker>::borrow),
1593                encoder,
1594                offset + cur_offset,
1595                depth,
1596            )?;
1597
1598            _prev_end_offset = cur_offset + envelope_size;
1599            if 3 > max_ordinal {
1600                return Ok(());
1601            }
1602
1603            // Write at offset+(ordinal-1)*envelope_size, since ordinals are one-based and envelopes
1604            // are envelope_size bytes.
1605            let cur_offset: usize = (3 - 1) * envelope_size;
1606
1607            // Zero reserved fields.
1608            encoder.padding(offset + _prev_end_offset, cur_offset - _prev_end_offset);
1609
1610            // Safety:
1611            // - bytes_len is calculated to fit envelope_size*max(member.ordinal).
1612            // - Since cur_offset is envelope_size*(member.ordinal - 1) and the envelope takes
1613            //   envelope_size bytes, there is always sufficient room.
1614            fidl::encoding::encode_in_envelope_optional::<
1615                Context,
1616                fidl::encoding::DefaultFuchsiaResourceDialect,
1617            >(
1618                self.context
1619                    .as_mut()
1620                    .map(<Context as fidl::encoding::ResourceTypeMarker>::take_or_borrow),
1621                encoder,
1622                offset + cur_offset,
1623                depth,
1624            )?;
1625
1626            _prev_end_offset = cur_offset + envelope_size;
1627            if 4 > max_ordinal {
1628                return Ok(());
1629            }
1630
1631            // Write at offset+(ordinal-1)*envelope_size, since ordinals are one-based and envelopes
1632            // are envelope_size bytes.
1633            let cur_offset: usize = (4 - 1) * envelope_size;
1634
1635            // Zero reserved fields.
1636            encoder.padding(offset + _prev_end_offset, cur_offset - _prev_end_offset);
1637
1638            // Safety:
1639            // - bytes_len is calculated to fit envelope_size*max(member.ordinal).
1640            // - Since cur_offset is envelope_size*(member.ordinal - 1) and the envelope takes
1641            //   envelope_size bytes, there is always sufficient room.
1642            fidl::encoding::encode_in_envelope_optional::<
1643                Target,
1644                fidl::encoding::DefaultFuchsiaResourceDialect,
1645            >(
1646                self.target
1647                    .as_mut()
1648                    .map(<Target as fidl::encoding::ResourceTypeMarker>::take_or_borrow),
1649                encoder,
1650                offset + cur_offset,
1651                depth,
1652            )?;
1653
1654            _prev_end_offset = cur_offset + envelope_size;
1655            if 5 > max_ordinal {
1656                return Ok(());
1657            }
1658
1659            // Write at offset+(ordinal-1)*envelope_size, since ordinals are one-based and envelopes
1660            // are envelope_size bytes.
1661            let cur_offset: usize = (5 - 1) * envelope_size;
1662
1663            // Zero reserved fields.
1664            encoder.padding(offset + _prev_end_offset, cur_offset - _prev_end_offset);
1665
1666            // Safety:
1667            // - bytes_len is calculated to fit envelope_size*max(member.ordinal).
1668            // - Since cur_offset is envelope_size*(member.ordinal - 1) and the envelope takes
1669            //   envelope_size bytes, there is always sufficient room.
1670            fidl::encoding::encode_in_envelope_optional::<
1671                Viewport,
1672                fidl::encoding::DefaultFuchsiaResourceDialect,
1673            >(
1674                self.viewport.as_ref().map(<Viewport as fidl::encoding::ValueTypeMarker>::borrow),
1675                encoder,
1676                offset + cur_offset,
1677                depth,
1678            )?;
1679
1680            _prev_end_offset = cur_offset + envelope_size;
1681            if 6 > max_ordinal {
1682                return Ok(());
1683            }
1684
1685            // Write at offset+(ordinal-1)*envelope_size, since ordinals are one-based and envelopes
1686            // are envelope_size bytes.
1687            let cur_offset: usize = (6 - 1) * envelope_size;
1688
1689            // Zero reserved fields.
1690            encoder.padding(offset + _prev_end_offset, cur_offset - _prev_end_offset);
1691
1692            // Safety:
1693            // - bytes_len is calculated to fit envelope_size*max(member.ordinal).
1694            // - Since cur_offset is envelope_size*(member.ordinal - 1) and the envelope takes
1695            //   envelope_size bytes, there is always sufficient room.
1696            fidl::encoding::encode_in_envelope_optional::<
1697                DispatchPolicy,
1698                fidl::encoding::DefaultFuchsiaResourceDialect,
1699            >(
1700                self.dispatch_policy
1701                    .as_ref()
1702                    .map(<DispatchPolicy as fidl::encoding::ValueTypeMarker>::borrow),
1703                encoder,
1704                offset + cur_offset,
1705                depth,
1706            )?;
1707
1708            _prev_end_offset = cur_offset + envelope_size;
1709            if 7 > max_ordinal {
1710                return Ok(());
1711            }
1712
1713            // Write at offset+(ordinal-1)*envelope_size, since ordinals are one-based and envelopes
1714            // are envelope_size bytes.
1715            let cur_offset: usize = (7 - 1) * envelope_size;
1716
1717            // Zero reserved fields.
1718            encoder.padding(offset + _prev_end_offset, cur_offset - _prev_end_offset);
1719
1720            // Safety:
1721            // - bytes_len is calculated to fit envelope_size*max(member.ordinal).
1722            // - Since cur_offset is envelope_size*(member.ordinal - 1) and the envelope takes
1723            //   envelope_size bytes, there is always sufficient room.
1724            fidl::encoding::encode_in_envelope_optional::<
1725                fidl_fuchsia_input::Axis,
1726                fidl::encoding::DefaultFuchsiaResourceDialect,
1727            >(
1728                self.scroll_v_range
1729                    .as_ref()
1730                    .map(<fidl_fuchsia_input::Axis as fidl::encoding::ValueTypeMarker>::borrow),
1731                encoder,
1732                offset + cur_offset,
1733                depth,
1734            )?;
1735
1736            _prev_end_offset = cur_offset + envelope_size;
1737            if 8 > max_ordinal {
1738                return Ok(());
1739            }
1740
1741            // Write at offset+(ordinal-1)*envelope_size, since ordinals are one-based and envelopes
1742            // are envelope_size bytes.
1743            let cur_offset: usize = (8 - 1) * envelope_size;
1744
1745            // Zero reserved fields.
1746            encoder.padding(offset + _prev_end_offset, cur_offset - _prev_end_offset);
1747
1748            // Safety:
1749            // - bytes_len is calculated to fit envelope_size*max(member.ordinal).
1750            // - Since cur_offset is envelope_size*(member.ordinal - 1) and the envelope takes
1751            //   envelope_size bytes, there is always sufficient room.
1752            fidl::encoding::encode_in_envelope_optional::<
1753                fidl_fuchsia_input::Axis,
1754                fidl::encoding::DefaultFuchsiaResourceDialect,
1755            >(
1756                self.scroll_h_range
1757                    .as_ref()
1758                    .map(<fidl_fuchsia_input::Axis as fidl::encoding::ValueTypeMarker>::borrow),
1759                encoder,
1760                offset + cur_offset,
1761                depth,
1762            )?;
1763
1764            _prev_end_offset = cur_offset + envelope_size;
1765            if 9 > max_ordinal {
1766                return Ok(());
1767            }
1768
1769            // Write at offset+(ordinal-1)*envelope_size, since ordinals are one-based and envelopes
1770            // are envelope_size bytes.
1771            let cur_offset: usize = (9 - 1) * envelope_size;
1772
1773            // Zero reserved fields.
1774            encoder.padding(offset + _prev_end_offset, cur_offset - _prev_end_offset);
1775
1776            // Safety:
1777            // - bytes_len is calculated to fit envelope_size*max(member.ordinal).
1778            // - Since cur_offset is envelope_size*(member.ordinal - 1) and the envelope takes
1779            //   envelope_size bytes, there is always sufficient room.
1780            fidl::encoding::encode_in_envelope_optional::<
1781                fidl::encoding::Vector<u8, 32>,
1782                fidl::encoding::DefaultFuchsiaResourceDialect,
1783            >(
1784                self.buttons.as_ref().map(
1785                    <fidl::encoding::Vector<u8, 32> as fidl::encoding::ValueTypeMarker>::borrow,
1786                ),
1787                encoder,
1788                offset + cur_offset,
1789                depth,
1790            )?;
1791
1792            _prev_end_offset = cur_offset + envelope_size;
1793            if 10 > max_ordinal {
1794                return Ok(());
1795            }
1796
1797            // Write at offset+(ordinal-1)*envelope_size, since ordinals are one-based and envelopes
1798            // are envelope_size bytes.
1799            let cur_offset: usize = (10 - 1) * envelope_size;
1800
1801            // Zero reserved fields.
1802            encoder.padding(offset + _prev_end_offset, cur_offset - _prev_end_offset);
1803
1804            // Safety:
1805            // - bytes_len is calculated to fit envelope_size*max(member.ordinal).
1806            // - Since cur_offset is envelope_size*(member.ordinal - 1) and the envelope takes
1807            //   envelope_size bytes, there is always sufficient room.
1808            fidl::encoding::encode_in_envelope_optional::<fidl::encoding::Array<fidl_fuchsia_input::Axis, 2>, fidl::encoding::DefaultFuchsiaResourceDialect>(
1809            self.relative_motion_range.as_ref().map(<fidl::encoding::Array<fidl_fuchsia_input::Axis, 2> as fidl::encoding::ValueTypeMarker>::borrow),
1810            encoder, offset + cur_offset, depth
1811        )?;
1812
1813            _prev_end_offset = cur_offset + envelope_size;
1814
1815            Ok(())
1816        }
1817    }
1818
1819    impl fidl::encoding::Decode<Self, fidl::encoding::DefaultFuchsiaResourceDialect> for Config {
1820        #[inline(always)]
1821        fn new_empty() -> Self {
1822            Self::default()
1823        }
1824
1825        unsafe fn decode(
1826            &mut self,
1827            decoder: &mut fidl::encoding::Decoder<
1828                '_,
1829                fidl::encoding::DefaultFuchsiaResourceDialect,
1830            >,
1831            offset: usize,
1832            mut depth: fidl::encoding::Depth,
1833        ) -> fidl::Result<()> {
1834            decoder.debug_check_bounds::<Self>(offset);
1835            let len = match fidl::encoding::decode_vector_header(decoder, offset)? {
1836                None => return Err(fidl::Error::NotNullable),
1837                Some(len) => len,
1838            };
1839            // Calling decoder.out_of_line_offset(0) is not allowed.
1840            if len == 0 {
1841                return Ok(());
1842            };
1843            depth.increment()?;
1844            let envelope_size = 8;
1845            let bytes_len = len * envelope_size;
1846            let offset = decoder.out_of_line_offset(bytes_len)?;
1847            // Decode the envelope for each type.
1848            let mut _next_ordinal_to_read = 0;
1849            let mut next_offset = offset;
1850            let end_offset = offset + bytes_len;
1851            _next_ordinal_to_read += 1;
1852            if next_offset >= end_offset {
1853                return Ok(());
1854            }
1855
1856            // Decode unknown envelopes for gaps in ordinals.
1857            while _next_ordinal_to_read < 1 {
1858                fidl::encoding::decode_unknown_envelope(decoder, next_offset, depth)?;
1859                _next_ordinal_to_read += 1;
1860                next_offset += envelope_size;
1861            }
1862
1863            let next_out_of_line = decoder.next_out_of_line();
1864            let handles_before = decoder.remaining_handles();
1865            if let Some((inlined, num_bytes, num_handles)) =
1866                fidl::encoding::decode_envelope_header(decoder, next_offset)?
1867            {
1868                let member_inline_size =
1869                    <u32 as fidl::encoding::TypeMarker>::inline_size(decoder.context);
1870                if inlined != (member_inline_size <= 4) {
1871                    return Err(fidl::Error::InvalidInlineBitInEnvelope);
1872                }
1873                let inner_offset;
1874                let mut inner_depth = depth.clone();
1875                if inlined {
1876                    decoder.check_inline_envelope_padding(next_offset, member_inline_size)?;
1877                    inner_offset = next_offset;
1878                } else {
1879                    inner_offset = decoder.out_of_line_offset(member_inline_size)?;
1880                    inner_depth.increment()?;
1881                }
1882                let val_ref = self.device_id.get_or_insert_with(|| {
1883                    fidl::new_empty!(u32, fidl::encoding::DefaultFuchsiaResourceDialect)
1884                });
1885                fidl::decode!(
1886                    u32,
1887                    fidl::encoding::DefaultFuchsiaResourceDialect,
1888                    val_ref,
1889                    decoder,
1890                    inner_offset,
1891                    inner_depth
1892                )?;
1893                if !inlined && decoder.next_out_of_line() != next_out_of_line + (num_bytes as usize)
1894                {
1895                    return Err(fidl::Error::InvalidNumBytesInEnvelope);
1896                }
1897                if handles_before != decoder.remaining_handles() + (num_handles as usize) {
1898                    return Err(fidl::Error::InvalidNumHandlesInEnvelope);
1899                }
1900            }
1901
1902            next_offset += envelope_size;
1903            _next_ordinal_to_read += 1;
1904            if next_offset >= end_offset {
1905                return Ok(());
1906            }
1907
1908            // Decode unknown envelopes for gaps in ordinals.
1909            while _next_ordinal_to_read < 2 {
1910                fidl::encoding::decode_unknown_envelope(decoder, next_offset, depth)?;
1911                _next_ordinal_to_read += 1;
1912                next_offset += envelope_size;
1913            }
1914
1915            let next_out_of_line = decoder.next_out_of_line();
1916            let handles_before = decoder.remaining_handles();
1917            if let Some((inlined, num_bytes, num_handles)) =
1918                fidl::encoding::decode_envelope_header(decoder, next_offset)?
1919            {
1920                let member_inline_size =
1921                    <DeviceType as fidl::encoding::TypeMarker>::inline_size(decoder.context);
1922                if inlined != (member_inline_size <= 4) {
1923                    return Err(fidl::Error::InvalidInlineBitInEnvelope);
1924                }
1925                let inner_offset;
1926                let mut inner_depth = depth.clone();
1927                if inlined {
1928                    decoder.check_inline_envelope_padding(next_offset, member_inline_size)?;
1929                    inner_offset = next_offset;
1930                } else {
1931                    inner_offset = decoder.out_of_line_offset(member_inline_size)?;
1932                    inner_depth.increment()?;
1933                }
1934                let val_ref = self.device_type.get_or_insert_with(|| {
1935                    fidl::new_empty!(DeviceType, fidl::encoding::DefaultFuchsiaResourceDialect)
1936                });
1937                fidl::decode!(
1938                    DeviceType,
1939                    fidl::encoding::DefaultFuchsiaResourceDialect,
1940                    val_ref,
1941                    decoder,
1942                    inner_offset,
1943                    inner_depth
1944                )?;
1945                if !inlined && decoder.next_out_of_line() != next_out_of_line + (num_bytes as usize)
1946                {
1947                    return Err(fidl::Error::InvalidNumBytesInEnvelope);
1948                }
1949                if handles_before != decoder.remaining_handles() + (num_handles as usize) {
1950                    return Err(fidl::Error::InvalidNumHandlesInEnvelope);
1951                }
1952            }
1953
1954            next_offset += envelope_size;
1955            _next_ordinal_to_read += 1;
1956            if next_offset >= end_offset {
1957                return Ok(());
1958            }
1959
1960            // Decode unknown envelopes for gaps in ordinals.
1961            while _next_ordinal_to_read < 3 {
1962                fidl::encoding::decode_unknown_envelope(decoder, next_offset, depth)?;
1963                _next_ordinal_to_read += 1;
1964                next_offset += envelope_size;
1965            }
1966
1967            let next_out_of_line = decoder.next_out_of_line();
1968            let handles_before = decoder.remaining_handles();
1969            if let Some((inlined, num_bytes, num_handles)) =
1970                fidl::encoding::decode_envelope_header(decoder, next_offset)?
1971            {
1972                let member_inline_size =
1973                    <Context as fidl::encoding::TypeMarker>::inline_size(decoder.context);
1974                if inlined != (member_inline_size <= 4) {
1975                    return Err(fidl::Error::InvalidInlineBitInEnvelope);
1976                }
1977                let inner_offset;
1978                let mut inner_depth = depth.clone();
1979                if inlined {
1980                    decoder.check_inline_envelope_padding(next_offset, member_inline_size)?;
1981                    inner_offset = next_offset;
1982                } else {
1983                    inner_offset = decoder.out_of_line_offset(member_inline_size)?;
1984                    inner_depth.increment()?;
1985                }
1986                let val_ref = self.context.get_or_insert_with(|| {
1987                    fidl::new_empty!(Context, fidl::encoding::DefaultFuchsiaResourceDialect)
1988                });
1989                fidl::decode!(
1990                    Context,
1991                    fidl::encoding::DefaultFuchsiaResourceDialect,
1992                    val_ref,
1993                    decoder,
1994                    inner_offset,
1995                    inner_depth
1996                )?;
1997                if !inlined && decoder.next_out_of_line() != next_out_of_line + (num_bytes as usize)
1998                {
1999                    return Err(fidl::Error::InvalidNumBytesInEnvelope);
2000                }
2001                if handles_before != decoder.remaining_handles() + (num_handles as usize) {
2002                    return Err(fidl::Error::InvalidNumHandlesInEnvelope);
2003                }
2004            }
2005
2006            next_offset += envelope_size;
2007            _next_ordinal_to_read += 1;
2008            if next_offset >= end_offset {
2009                return Ok(());
2010            }
2011
2012            // Decode unknown envelopes for gaps in ordinals.
2013            while _next_ordinal_to_read < 4 {
2014                fidl::encoding::decode_unknown_envelope(decoder, next_offset, depth)?;
2015                _next_ordinal_to_read += 1;
2016                next_offset += envelope_size;
2017            }
2018
2019            let next_out_of_line = decoder.next_out_of_line();
2020            let handles_before = decoder.remaining_handles();
2021            if let Some((inlined, num_bytes, num_handles)) =
2022                fidl::encoding::decode_envelope_header(decoder, next_offset)?
2023            {
2024                let member_inline_size =
2025                    <Target as fidl::encoding::TypeMarker>::inline_size(decoder.context);
2026                if inlined != (member_inline_size <= 4) {
2027                    return Err(fidl::Error::InvalidInlineBitInEnvelope);
2028                }
2029                let inner_offset;
2030                let mut inner_depth = depth.clone();
2031                if inlined {
2032                    decoder.check_inline_envelope_padding(next_offset, member_inline_size)?;
2033                    inner_offset = next_offset;
2034                } else {
2035                    inner_offset = decoder.out_of_line_offset(member_inline_size)?;
2036                    inner_depth.increment()?;
2037                }
2038                let val_ref = self.target.get_or_insert_with(|| {
2039                    fidl::new_empty!(Target, fidl::encoding::DefaultFuchsiaResourceDialect)
2040                });
2041                fidl::decode!(
2042                    Target,
2043                    fidl::encoding::DefaultFuchsiaResourceDialect,
2044                    val_ref,
2045                    decoder,
2046                    inner_offset,
2047                    inner_depth
2048                )?;
2049                if !inlined && decoder.next_out_of_line() != next_out_of_line + (num_bytes as usize)
2050                {
2051                    return Err(fidl::Error::InvalidNumBytesInEnvelope);
2052                }
2053                if handles_before != decoder.remaining_handles() + (num_handles as usize) {
2054                    return Err(fidl::Error::InvalidNumHandlesInEnvelope);
2055                }
2056            }
2057
2058            next_offset += envelope_size;
2059            _next_ordinal_to_read += 1;
2060            if next_offset >= end_offset {
2061                return Ok(());
2062            }
2063
2064            // Decode unknown envelopes for gaps in ordinals.
2065            while _next_ordinal_to_read < 5 {
2066                fidl::encoding::decode_unknown_envelope(decoder, next_offset, depth)?;
2067                _next_ordinal_to_read += 1;
2068                next_offset += envelope_size;
2069            }
2070
2071            let next_out_of_line = decoder.next_out_of_line();
2072            let handles_before = decoder.remaining_handles();
2073            if let Some((inlined, num_bytes, num_handles)) =
2074                fidl::encoding::decode_envelope_header(decoder, next_offset)?
2075            {
2076                let member_inline_size =
2077                    <Viewport as fidl::encoding::TypeMarker>::inline_size(decoder.context);
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 = self.viewport.get_or_insert_with(|| {
2091                    fidl::new_empty!(Viewport, fidl::encoding::DefaultFuchsiaResourceDialect)
2092                });
2093                fidl::decode!(
2094                    Viewport,
2095                    fidl::encoding::DefaultFuchsiaResourceDialect,
2096                    val_ref,
2097                    decoder,
2098                    inner_offset,
2099                    inner_depth
2100                )?;
2101                if !inlined && decoder.next_out_of_line() != next_out_of_line + (num_bytes as usize)
2102                {
2103                    return Err(fidl::Error::InvalidNumBytesInEnvelope);
2104                }
2105                if handles_before != decoder.remaining_handles() + (num_handles as usize) {
2106                    return Err(fidl::Error::InvalidNumHandlesInEnvelope);
2107                }
2108            }
2109
2110            next_offset += envelope_size;
2111            _next_ordinal_to_read += 1;
2112            if next_offset >= end_offset {
2113                return Ok(());
2114            }
2115
2116            // Decode unknown envelopes for gaps in ordinals.
2117            while _next_ordinal_to_read < 6 {
2118                fidl::encoding::decode_unknown_envelope(decoder, next_offset, depth)?;
2119                _next_ordinal_to_read += 1;
2120                next_offset += envelope_size;
2121            }
2122
2123            let next_out_of_line = decoder.next_out_of_line();
2124            let handles_before = decoder.remaining_handles();
2125            if let Some((inlined, num_bytes, num_handles)) =
2126                fidl::encoding::decode_envelope_header(decoder, next_offset)?
2127            {
2128                let member_inline_size =
2129                    <DispatchPolicy as fidl::encoding::TypeMarker>::inline_size(decoder.context);
2130                if inlined != (member_inline_size <= 4) {
2131                    return Err(fidl::Error::InvalidInlineBitInEnvelope);
2132                }
2133                let inner_offset;
2134                let mut inner_depth = depth.clone();
2135                if inlined {
2136                    decoder.check_inline_envelope_padding(next_offset, member_inline_size)?;
2137                    inner_offset = next_offset;
2138                } else {
2139                    inner_offset = decoder.out_of_line_offset(member_inline_size)?;
2140                    inner_depth.increment()?;
2141                }
2142                let val_ref = self.dispatch_policy.get_or_insert_with(|| {
2143                    fidl::new_empty!(DispatchPolicy, fidl::encoding::DefaultFuchsiaResourceDialect)
2144                });
2145                fidl::decode!(
2146                    DispatchPolicy,
2147                    fidl::encoding::DefaultFuchsiaResourceDialect,
2148                    val_ref,
2149                    decoder,
2150                    inner_offset,
2151                    inner_depth
2152                )?;
2153                if !inlined && decoder.next_out_of_line() != next_out_of_line + (num_bytes as usize)
2154                {
2155                    return Err(fidl::Error::InvalidNumBytesInEnvelope);
2156                }
2157                if handles_before != decoder.remaining_handles() + (num_handles as usize) {
2158                    return Err(fidl::Error::InvalidNumHandlesInEnvelope);
2159                }
2160            }
2161
2162            next_offset += envelope_size;
2163            _next_ordinal_to_read += 1;
2164            if next_offset >= end_offset {
2165                return Ok(());
2166            }
2167
2168            // Decode unknown envelopes for gaps in ordinals.
2169            while _next_ordinal_to_read < 7 {
2170                fidl::encoding::decode_unknown_envelope(decoder, next_offset, depth)?;
2171                _next_ordinal_to_read += 1;
2172                next_offset += envelope_size;
2173            }
2174
2175            let next_out_of_line = decoder.next_out_of_line();
2176            let handles_before = decoder.remaining_handles();
2177            if let Some((inlined, num_bytes, num_handles)) =
2178                fidl::encoding::decode_envelope_header(decoder, next_offset)?
2179            {
2180                let member_inline_size =
2181                    <fidl_fuchsia_input::Axis as fidl::encoding::TypeMarker>::inline_size(
2182                        decoder.context,
2183                    );
2184                if inlined != (member_inline_size <= 4) {
2185                    return Err(fidl::Error::InvalidInlineBitInEnvelope);
2186                }
2187                let inner_offset;
2188                let mut inner_depth = depth.clone();
2189                if inlined {
2190                    decoder.check_inline_envelope_padding(next_offset, member_inline_size)?;
2191                    inner_offset = next_offset;
2192                } else {
2193                    inner_offset = decoder.out_of_line_offset(member_inline_size)?;
2194                    inner_depth.increment()?;
2195                }
2196                let val_ref = self.scroll_v_range.get_or_insert_with(|| {
2197                    fidl::new_empty!(
2198                        fidl_fuchsia_input::Axis,
2199                        fidl::encoding::DefaultFuchsiaResourceDialect
2200                    )
2201                });
2202                fidl::decode!(
2203                    fidl_fuchsia_input::Axis,
2204                    fidl::encoding::DefaultFuchsiaResourceDialect,
2205                    val_ref,
2206                    decoder,
2207                    inner_offset,
2208                    inner_depth
2209                )?;
2210                if !inlined && decoder.next_out_of_line() != next_out_of_line + (num_bytes as usize)
2211                {
2212                    return Err(fidl::Error::InvalidNumBytesInEnvelope);
2213                }
2214                if handles_before != decoder.remaining_handles() + (num_handles as usize) {
2215                    return Err(fidl::Error::InvalidNumHandlesInEnvelope);
2216                }
2217            }
2218
2219            next_offset += envelope_size;
2220            _next_ordinal_to_read += 1;
2221            if next_offset >= end_offset {
2222                return Ok(());
2223            }
2224
2225            // Decode unknown envelopes for gaps in ordinals.
2226            while _next_ordinal_to_read < 8 {
2227                fidl::encoding::decode_unknown_envelope(decoder, next_offset, depth)?;
2228                _next_ordinal_to_read += 1;
2229                next_offset += envelope_size;
2230            }
2231
2232            let next_out_of_line = decoder.next_out_of_line();
2233            let handles_before = decoder.remaining_handles();
2234            if let Some((inlined, num_bytes, num_handles)) =
2235                fidl::encoding::decode_envelope_header(decoder, next_offset)?
2236            {
2237                let member_inline_size =
2238                    <fidl_fuchsia_input::Axis as fidl::encoding::TypeMarker>::inline_size(
2239                        decoder.context,
2240                    );
2241                if inlined != (member_inline_size <= 4) {
2242                    return Err(fidl::Error::InvalidInlineBitInEnvelope);
2243                }
2244                let inner_offset;
2245                let mut inner_depth = depth.clone();
2246                if inlined {
2247                    decoder.check_inline_envelope_padding(next_offset, member_inline_size)?;
2248                    inner_offset = next_offset;
2249                } else {
2250                    inner_offset = decoder.out_of_line_offset(member_inline_size)?;
2251                    inner_depth.increment()?;
2252                }
2253                let val_ref = self.scroll_h_range.get_or_insert_with(|| {
2254                    fidl::new_empty!(
2255                        fidl_fuchsia_input::Axis,
2256                        fidl::encoding::DefaultFuchsiaResourceDialect
2257                    )
2258                });
2259                fidl::decode!(
2260                    fidl_fuchsia_input::Axis,
2261                    fidl::encoding::DefaultFuchsiaResourceDialect,
2262                    val_ref,
2263                    decoder,
2264                    inner_offset,
2265                    inner_depth
2266                )?;
2267                if !inlined && decoder.next_out_of_line() != next_out_of_line + (num_bytes as usize)
2268                {
2269                    return Err(fidl::Error::InvalidNumBytesInEnvelope);
2270                }
2271                if handles_before != decoder.remaining_handles() + (num_handles as usize) {
2272                    return Err(fidl::Error::InvalidNumHandlesInEnvelope);
2273                }
2274            }
2275
2276            next_offset += envelope_size;
2277            _next_ordinal_to_read += 1;
2278            if next_offset >= end_offset {
2279                return Ok(());
2280            }
2281
2282            // Decode unknown envelopes for gaps in ordinals.
2283            while _next_ordinal_to_read < 9 {
2284                fidl::encoding::decode_unknown_envelope(decoder, next_offset, depth)?;
2285                _next_ordinal_to_read += 1;
2286                next_offset += envelope_size;
2287            }
2288
2289            let next_out_of_line = decoder.next_out_of_line();
2290            let handles_before = decoder.remaining_handles();
2291            if let Some((inlined, num_bytes, num_handles)) =
2292                fidl::encoding::decode_envelope_header(decoder, next_offset)?
2293            {
2294                let member_inline_size =
2295                    <fidl::encoding::Vector<u8, 32> as fidl::encoding::TypeMarker>::inline_size(
2296                        decoder.context,
2297                    );
2298                if inlined != (member_inline_size <= 4) {
2299                    return Err(fidl::Error::InvalidInlineBitInEnvelope);
2300                }
2301                let inner_offset;
2302                let mut inner_depth = depth.clone();
2303                if inlined {
2304                    decoder.check_inline_envelope_padding(next_offset, member_inline_size)?;
2305                    inner_offset = next_offset;
2306                } else {
2307                    inner_offset = decoder.out_of_line_offset(member_inline_size)?;
2308                    inner_depth.increment()?;
2309                }
2310                let val_ref =
2311                self.buttons.get_or_insert_with(|| fidl::new_empty!(fidl::encoding::Vector<u8, 32>, fidl::encoding::DefaultFuchsiaResourceDialect));
2312                fidl::decode!(fidl::encoding::Vector<u8, 32>, fidl::encoding::DefaultFuchsiaResourceDialect, val_ref, decoder, inner_offset, inner_depth)?;
2313                if !inlined && decoder.next_out_of_line() != next_out_of_line + (num_bytes as usize)
2314                {
2315                    return Err(fidl::Error::InvalidNumBytesInEnvelope);
2316                }
2317                if handles_before != decoder.remaining_handles() + (num_handles as usize) {
2318                    return Err(fidl::Error::InvalidNumHandlesInEnvelope);
2319                }
2320            }
2321
2322            next_offset += envelope_size;
2323            _next_ordinal_to_read += 1;
2324            if next_offset >= end_offset {
2325                return Ok(());
2326            }
2327
2328            // Decode unknown envelopes for gaps in ordinals.
2329            while _next_ordinal_to_read < 10 {
2330                fidl::encoding::decode_unknown_envelope(decoder, next_offset, depth)?;
2331                _next_ordinal_to_read += 1;
2332                next_offset += envelope_size;
2333            }
2334
2335            let next_out_of_line = decoder.next_out_of_line();
2336            let handles_before = decoder.remaining_handles();
2337            if let Some((inlined, num_bytes, num_handles)) =
2338                fidl::encoding::decode_envelope_header(decoder, next_offset)?
2339            {
2340                let member_inline_size = <fidl::encoding::Array<fidl_fuchsia_input::Axis, 2> as fidl::encoding::TypeMarker>::inline_size(decoder.context);
2341                if inlined != (member_inline_size <= 4) {
2342                    return Err(fidl::Error::InvalidInlineBitInEnvelope);
2343                }
2344                let inner_offset;
2345                let mut inner_depth = depth.clone();
2346                if inlined {
2347                    decoder.check_inline_envelope_padding(next_offset, member_inline_size)?;
2348                    inner_offset = next_offset;
2349                } else {
2350                    inner_offset = decoder.out_of_line_offset(member_inline_size)?;
2351                    inner_depth.increment()?;
2352                }
2353                let val_ref =
2354                self.relative_motion_range.get_or_insert_with(|| fidl::new_empty!(fidl::encoding::Array<fidl_fuchsia_input::Axis, 2>, fidl::encoding::DefaultFuchsiaResourceDialect));
2355                fidl::decode!(fidl::encoding::Array<fidl_fuchsia_input::Axis, 2>, fidl::encoding::DefaultFuchsiaResourceDialect, val_ref, decoder, inner_offset, inner_depth)?;
2356                if !inlined && decoder.next_out_of_line() != next_out_of_line + (num_bytes as usize)
2357                {
2358                    return Err(fidl::Error::InvalidNumBytesInEnvelope);
2359                }
2360                if handles_before != decoder.remaining_handles() + (num_handles as usize) {
2361                    return Err(fidl::Error::InvalidNumHandlesInEnvelope);
2362                }
2363            }
2364
2365            next_offset += envelope_size;
2366
2367            // Decode the remaining unknown envelopes.
2368            while next_offset < end_offset {
2369                _next_ordinal_to_read += 1;
2370                fidl::encoding::decode_unknown_envelope(decoder, next_offset, depth)?;
2371                next_offset += envelope_size;
2372            }
2373
2374            Ok(())
2375        }
2376    }
2377
2378    impl Event {
2379        #[inline(always)]
2380        fn max_ordinal_present(&self) -> u64 {
2381            if let Some(_) = self.wake_lease {
2382                return 4;
2383            }
2384            if let Some(_) = self.trace_flow_id {
2385                return 3;
2386            }
2387            if let Some(_) = self.data {
2388                return 2;
2389            }
2390            if let Some(_) = self.timestamp {
2391                return 1;
2392            }
2393            0
2394        }
2395    }
2396
2397    impl fidl::encoding::ResourceTypeMarker for Event {
2398        type Borrowed<'a> = &'a mut Self;
2399        fn take_or_borrow<'a>(
2400            value: &'a mut <Self as fidl::encoding::TypeMarker>::Owned,
2401        ) -> Self::Borrowed<'a> {
2402            value
2403        }
2404    }
2405
2406    unsafe impl fidl::encoding::TypeMarker for Event {
2407        type Owned = Self;
2408
2409        #[inline(always)]
2410        fn inline_align(_context: fidl::encoding::Context) -> usize {
2411            8
2412        }
2413
2414        #[inline(always)]
2415        fn inline_size(_context: fidl::encoding::Context) -> usize {
2416            16
2417        }
2418    }
2419
2420    unsafe impl fidl::encoding::Encode<Event, fidl::encoding::DefaultFuchsiaResourceDialect>
2421        for &mut Event
2422    {
2423        unsafe fn encode(
2424            self,
2425            encoder: &mut fidl::encoding::Encoder<
2426                '_,
2427                fidl::encoding::DefaultFuchsiaResourceDialect,
2428            >,
2429            offset: usize,
2430            mut depth: fidl::encoding::Depth,
2431        ) -> fidl::Result<()> {
2432            encoder.debug_check_bounds::<Event>(offset);
2433            // Vector header
2434            let max_ordinal: u64 = self.max_ordinal_present();
2435            encoder.write_num(max_ordinal, offset);
2436            encoder.write_num(fidl::encoding::ALLOC_PRESENT_U64, offset + 8);
2437            // Calling encoder.out_of_line_offset(0) is not allowed.
2438            if max_ordinal == 0 {
2439                return Ok(());
2440            }
2441            depth.increment()?;
2442            let envelope_size = 8;
2443            let bytes_len = max_ordinal as usize * envelope_size;
2444            #[allow(unused_variables)]
2445            let offset = encoder.out_of_line_offset(bytes_len);
2446            let mut _prev_end_offset: usize = 0;
2447            if 1 > max_ordinal {
2448                return Ok(());
2449            }
2450
2451            // Write at offset+(ordinal-1)*envelope_size, since ordinals are one-based and envelopes
2452            // are envelope_size bytes.
2453            let cur_offset: usize = (1 - 1) * envelope_size;
2454
2455            // Zero reserved fields.
2456            encoder.padding(offset + _prev_end_offset, cur_offset - _prev_end_offset);
2457
2458            // Safety:
2459            // - bytes_len is calculated to fit envelope_size*max(member.ordinal).
2460            // - Since cur_offset is envelope_size*(member.ordinal - 1) and the envelope takes
2461            //   envelope_size bytes, there is always sufficient room.
2462            fidl::encoding::encode_in_envelope_optional::<
2463                i64,
2464                fidl::encoding::DefaultFuchsiaResourceDialect,
2465            >(
2466                self.timestamp.as_ref().map(<i64 as fidl::encoding::ValueTypeMarker>::borrow),
2467                encoder,
2468                offset + cur_offset,
2469                depth,
2470            )?;
2471
2472            _prev_end_offset = cur_offset + envelope_size;
2473            if 2 > max_ordinal {
2474                return Ok(());
2475            }
2476
2477            // Write at offset+(ordinal-1)*envelope_size, since ordinals are one-based and envelopes
2478            // are envelope_size bytes.
2479            let cur_offset: usize = (2 - 1) * envelope_size;
2480
2481            // Zero reserved fields.
2482            encoder.padding(offset + _prev_end_offset, cur_offset - _prev_end_offset);
2483
2484            // Safety:
2485            // - bytes_len is calculated to fit envelope_size*max(member.ordinal).
2486            // - Since cur_offset is envelope_size*(member.ordinal - 1) and the envelope takes
2487            //   envelope_size bytes, there is always sufficient room.
2488            fidl::encoding::encode_in_envelope_optional::<
2489                Data,
2490                fidl::encoding::DefaultFuchsiaResourceDialect,
2491            >(
2492                self.data.as_ref().map(<Data as fidl::encoding::ValueTypeMarker>::borrow),
2493                encoder,
2494                offset + cur_offset,
2495                depth,
2496            )?;
2497
2498            _prev_end_offset = cur_offset + envelope_size;
2499            if 3 > max_ordinal {
2500                return Ok(());
2501            }
2502
2503            // Write at offset+(ordinal-1)*envelope_size, since ordinals are one-based and envelopes
2504            // are envelope_size bytes.
2505            let cur_offset: usize = (3 - 1) * envelope_size;
2506
2507            // Zero reserved fields.
2508            encoder.padding(offset + _prev_end_offset, cur_offset - _prev_end_offset);
2509
2510            // Safety:
2511            // - bytes_len is calculated to fit envelope_size*max(member.ordinal).
2512            // - Since cur_offset is envelope_size*(member.ordinal - 1) and the envelope takes
2513            //   envelope_size bytes, there is always sufficient room.
2514            fidl::encoding::encode_in_envelope_optional::<
2515                u64,
2516                fidl::encoding::DefaultFuchsiaResourceDialect,
2517            >(
2518                self.trace_flow_id.as_ref().map(<u64 as fidl::encoding::ValueTypeMarker>::borrow),
2519                encoder,
2520                offset + cur_offset,
2521                depth,
2522            )?;
2523
2524            _prev_end_offset = cur_offset + envelope_size;
2525            if 4 > max_ordinal {
2526                return Ok(());
2527            }
2528
2529            // Write at offset+(ordinal-1)*envelope_size, since ordinals are one-based and envelopes
2530            // are envelope_size bytes.
2531            let cur_offset: usize = (4 - 1) * envelope_size;
2532
2533            // Zero reserved fields.
2534            encoder.padding(offset + _prev_end_offset, cur_offset - _prev_end_offset);
2535
2536            // Safety:
2537            // - bytes_len is calculated to fit envelope_size*max(member.ordinal).
2538            // - Since cur_offset is envelope_size*(member.ordinal - 1) and the envelope takes
2539            //   envelope_size bytes, there is always sufficient room.
2540            fidl::encoding::encode_in_envelope_optional::<
2541                fidl::encoding::HandleType<
2542                    fidl::EventPair,
2543                    { fidl::ObjectType::EVENTPAIR.into_raw() },
2544                    2147483648,
2545                >,
2546                fidl::encoding::DefaultFuchsiaResourceDialect,
2547            >(
2548                self.wake_lease.as_mut().map(
2549                    <fidl::encoding::HandleType<
2550                        fidl::EventPair,
2551                        { fidl::ObjectType::EVENTPAIR.into_raw() },
2552                        2147483648,
2553                    > as fidl::encoding::ResourceTypeMarker>::take_or_borrow,
2554                ),
2555                encoder,
2556                offset + cur_offset,
2557                depth,
2558            )?;
2559
2560            _prev_end_offset = cur_offset + envelope_size;
2561
2562            Ok(())
2563        }
2564    }
2565
2566    impl fidl::encoding::Decode<Self, fidl::encoding::DefaultFuchsiaResourceDialect> for Event {
2567        #[inline(always)]
2568        fn new_empty() -> Self {
2569            Self::default()
2570        }
2571
2572        unsafe fn decode(
2573            &mut self,
2574            decoder: &mut fidl::encoding::Decoder<
2575                '_,
2576                fidl::encoding::DefaultFuchsiaResourceDialect,
2577            >,
2578            offset: usize,
2579            mut depth: fidl::encoding::Depth,
2580        ) -> fidl::Result<()> {
2581            decoder.debug_check_bounds::<Self>(offset);
2582            let len = match fidl::encoding::decode_vector_header(decoder, offset)? {
2583                None => return Err(fidl::Error::NotNullable),
2584                Some(len) => len,
2585            };
2586            // Calling decoder.out_of_line_offset(0) is not allowed.
2587            if len == 0 {
2588                return Ok(());
2589            };
2590            depth.increment()?;
2591            let envelope_size = 8;
2592            let bytes_len = len * envelope_size;
2593            let offset = decoder.out_of_line_offset(bytes_len)?;
2594            // Decode the envelope for each type.
2595            let mut _next_ordinal_to_read = 0;
2596            let mut next_offset = offset;
2597            let end_offset = offset + bytes_len;
2598            _next_ordinal_to_read += 1;
2599            if next_offset >= end_offset {
2600                return Ok(());
2601            }
2602
2603            // Decode unknown envelopes for gaps in ordinals.
2604            while _next_ordinal_to_read < 1 {
2605                fidl::encoding::decode_unknown_envelope(decoder, next_offset, depth)?;
2606                _next_ordinal_to_read += 1;
2607                next_offset += envelope_size;
2608            }
2609
2610            let next_out_of_line = decoder.next_out_of_line();
2611            let handles_before = decoder.remaining_handles();
2612            if let Some((inlined, num_bytes, num_handles)) =
2613                fidl::encoding::decode_envelope_header(decoder, next_offset)?
2614            {
2615                let member_inline_size =
2616                    <i64 as fidl::encoding::TypeMarker>::inline_size(decoder.context);
2617                if inlined != (member_inline_size <= 4) {
2618                    return Err(fidl::Error::InvalidInlineBitInEnvelope);
2619                }
2620                let inner_offset;
2621                let mut inner_depth = depth.clone();
2622                if inlined {
2623                    decoder.check_inline_envelope_padding(next_offset, member_inline_size)?;
2624                    inner_offset = next_offset;
2625                } else {
2626                    inner_offset = decoder.out_of_line_offset(member_inline_size)?;
2627                    inner_depth.increment()?;
2628                }
2629                let val_ref = self.timestamp.get_or_insert_with(|| {
2630                    fidl::new_empty!(i64, fidl::encoding::DefaultFuchsiaResourceDialect)
2631                });
2632                fidl::decode!(
2633                    i64,
2634                    fidl::encoding::DefaultFuchsiaResourceDialect,
2635                    val_ref,
2636                    decoder,
2637                    inner_offset,
2638                    inner_depth
2639                )?;
2640                if !inlined && decoder.next_out_of_line() != next_out_of_line + (num_bytes as usize)
2641                {
2642                    return Err(fidl::Error::InvalidNumBytesInEnvelope);
2643                }
2644                if handles_before != decoder.remaining_handles() + (num_handles as usize) {
2645                    return Err(fidl::Error::InvalidNumHandlesInEnvelope);
2646                }
2647            }
2648
2649            next_offset += envelope_size;
2650            _next_ordinal_to_read += 1;
2651            if next_offset >= end_offset {
2652                return Ok(());
2653            }
2654
2655            // Decode unknown envelopes for gaps in ordinals.
2656            while _next_ordinal_to_read < 2 {
2657                fidl::encoding::decode_unknown_envelope(decoder, next_offset, depth)?;
2658                _next_ordinal_to_read += 1;
2659                next_offset += envelope_size;
2660            }
2661
2662            let next_out_of_line = decoder.next_out_of_line();
2663            let handles_before = decoder.remaining_handles();
2664            if let Some((inlined, num_bytes, num_handles)) =
2665                fidl::encoding::decode_envelope_header(decoder, next_offset)?
2666            {
2667                let member_inline_size =
2668                    <Data as fidl::encoding::TypeMarker>::inline_size(decoder.context);
2669                if inlined != (member_inline_size <= 4) {
2670                    return Err(fidl::Error::InvalidInlineBitInEnvelope);
2671                }
2672                let inner_offset;
2673                let mut inner_depth = depth.clone();
2674                if inlined {
2675                    decoder.check_inline_envelope_padding(next_offset, member_inline_size)?;
2676                    inner_offset = next_offset;
2677                } else {
2678                    inner_offset = decoder.out_of_line_offset(member_inline_size)?;
2679                    inner_depth.increment()?;
2680                }
2681                let val_ref = self.data.get_or_insert_with(|| {
2682                    fidl::new_empty!(Data, fidl::encoding::DefaultFuchsiaResourceDialect)
2683                });
2684                fidl::decode!(
2685                    Data,
2686                    fidl::encoding::DefaultFuchsiaResourceDialect,
2687                    val_ref,
2688                    decoder,
2689                    inner_offset,
2690                    inner_depth
2691                )?;
2692                if !inlined && decoder.next_out_of_line() != next_out_of_line + (num_bytes as usize)
2693                {
2694                    return Err(fidl::Error::InvalidNumBytesInEnvelope);
2695                }
2696                if handles_before != decoder.remaining_handles() + (num_handles as usize) {
2697                    return Err(fidl::Error::InvalidNumHandlesInEnvelope);
2698                }
2699            }
2700
2701            next_offset += envelope_size;
2702            _next_ordinal_to_read += 1;
2703            if next_offset >= end_offset {
2704                return Ok(());
2705            }
2706
2707            // Decode unknown envelopes for gaps in ordinals.
2708            while _next_ordinal_to_read < 3 {
2709                fidl::encoding::decode_unknown_envelope(decoder, next_offset, depth)?;
2710                _next_ordinal_to_read += 1;
2711                next_offset += envelope_size;
2712            }
2713
2714            let next_out_of_line = decoder.next_out_of_line();
2715            let handles_before = decoder.remaining_handles();
2716            if let Some((inlined, num_bytes, num_handles)) =
2717                fidl::encoding::decode_envelope_header(decoder, next_offset)?
2718            {
2719                let member_inline_size =
2720                    <u64 as fidl::encoding::TypeMarker>::inline_size(decoder.context);
2721                if inlined != (member_inline_size <= 4) {
2722                    return Err(fidl::Error::InvalidInlineBitInEnvelope);
2723                }
2724                let inner_offset;
2725                let mut inner_depth = depth.clone();
2726                if inlined {
2727                    decoder.check_inline_envelope_padding(next_offset, member_inline_size)?;
2728                    inner_offset = next_offset;
2729                } else {
2730                    inner_offset = decoder.out_of_line_offset(member_inline_size)?;
2731                    inner_depth.increment()?;
2732                }
2733                let val_ref = self.trace_flow_id.get_or_insert_with(|| {
2734                    fidl::new_empty!(u64, fidl::encoding::DefaultFuchsiaResourceDialect)
2735                });
2736                fidl::decode!(
2737                    u64,
2738                    fidl::encoding::DefaultFuchsiaResourceDialect,
2739                    val_ref,
2740                    decoder,
2741                    inner_offset,
2742                    inner_depth
2743                )?;
2744                if !inlined && decoder.next_out_of_line() != next_out_of_line + (num_bytes as usize)
2745                {
2746                    return Err(fidl::Error::InvalidNumBytesInEnvelope);
2747                }
2748                if handles_before != decoder.remaining_handles() + (num_handles as usize) {
2749                    return Err(fidl::Error::InvalidNumHandlesInEnvelope);
2750                }
2751            }
2752
2753            next_offset += envelope_size;
2754            _next_ordinal_to_read += 1;
2755            if next_offset >= end_offset {
2756                return Ok(());
2757            }
2758
2759            // Decode unknown envelopes for gaps in ordinals.
2760            while _next_ordinal_to_read < 4 {
2761                fidl::encoding::decode_unknown_envelope(decoder, next_offset, depth)?;
2762                _next_ordinal_to_read += 1;
2763                next_offset += envelope_size;
2764            }
2765
2766            let next_out_of_line = decoder.next_out_of_line();
2767            let handles_before = decoder.remaining_handles();
2768            if let Some((inlined, num_bytes, num_handles)) =
2769                fidl::encoding::decode_envelope_header(decoder, next_offset)?
2770            {
2771                let member_inline_size = <fidl::encoding::HandleType<
2772                    fidl::EventPair,
2773                    { fidl::ObjectType::EVENTPAIR.into_raw() },
2774                    2147483648,
2775                > as fidl::encoding::TypeMarker>::inline_size(
2776                    decoder.context
2777                );
2778                if inlined != (member_inline_size <= 4) {
2779                    return Err(fidl::Error::InvalidInlineBitInEnvelope);
2780                }
2781                let inner_offset;
2782                let mut inner_depth = depth.clone();
2783                if inlined {
2784                    decoder.check_inline_envelope_padding(next_offset, member_inline_size)?;
2785                    inner_offset = next_offset;
2786                } else {
2787                    inner_offset = decoder.out_of_line_offset(member_inline_size)?;
2788                    inner_depth.increment()?;
2789                }
2790                let val_ref =
2791                self.wake_lease.get_or_insert_with(|| fidl::new_empty!(fidl::encoding::HandleType<fidl::EventPair, { fidl::ObjectType::EVENTPAIR.into_raw() }, 2147483648>, fidl::encoding::DefaultFuchsiaResourceDialect));
2792                fidl::decode!(fidl::encoding::HandleType<fidl::EventPair, { fidl::ObjectType::EVENTPAIR.into_raw() }, 2147483648>, fidl::encoding::DefaultFuchsiaResourceDialect, val_ref, decoder, inner_offset, inner_depth)?;
2793                if !inlined && decoder.next_out_of_line() != next_out_of_line + (num_bytes as usize)
2794                {
2795                    return Err(fidl::Error::InvalidNumBytesInEnvelope);
2796                }
2797                if handles_before != decoder.remaining_handles() + (num_handles as usize) {
2798                    return Err(fidl::Error::InvalidNumHandlesInEnvelope);
2799                }
2800            }
2801
2802            next_offset += envelope_size;
2803
2804            // Decode the remaining unknown envelopes.
2805            while next_offset < end_offset {
2806                _next_ordinal_to_read += 1;
2807                fidl::encoding::decode_unknown_envelope(decoder, next_offset, depth)?;
2808                next_offset += envelope_size;
2809            }
2810
2811            Ok(())
2812        }
2813    }
2814
2815    impl fidl::encoding::ResourceTypeMarker for Context {
2816        type Borrowed<'a> = &'a mut Self;
2817        fn take_or_borrow<'a>(
2818            value: &'a mut <Self as fidl::encoding::TypeMarker>::Owned,
2819        ) -> Self::Borrowed<'a> {
2820            value
2821        }
2822    }
2823
2824    unsafe impl fidl::encoding::TypeMarker for Context {
2825        type Owned = Self;
2826
2827        #[inline(always)]
2828        fn inline_align(_context: fidl::encoding::Context) -> usize {
2829            8
2830        }
2831
2832        #[inline(always)]
2833        fn inline_size(_context: fidl::encoding::Context) -> usize {
2834            16
2835        }
2836    }
2837
2838    unsafe impl fidl::encoding::Encode<Context, fidl::encoding::DefaultFuchsiaResourceDialect>
2839        for &mut Context
2840    {
2841        #[inline]
2842        unsafe fn encode(
2843            self,
2844            encoder: &mut fidl::encoding::Encoder<
2845                '_,
2846                fidl::encoding::DefaultFuchsiaResourceDialect,
2847            >,
2848            offset: usize,
2849            _depth: fidl::encoding::Depth,
2850        ) -> fidl::Result<()> {
2851            encoder.debug_check_bounds::<Context>(offset);
2852            encoder.write_num::<u64>(self.ordinal(), offset);
2853            match self {
2854            Context::View(ref mut val) => {
2855                fidl::encoding::encode_in_envelope::<fidl_fuchsia_ui_views::ViewRef, fidl::encoding::DefaultFuchsiaResourceDialect>(
2856                    <fidl_fuchsia_ui_views::ViewRef as fidl::encoding::ResourceTypeMarker>::take_or_borrow(val),
2857                    encoder, offset + 8, _depth
2858                )
2859            }
2860        }
2861        }
2862    }
2863
2864    impl fidl::encoding::Decode<Self, fidl::encoding::DefaultFuchsiaResourceDialect> for Context {
2865        #[inline(always)]
2866        fn new_empty() -> Self {
2867            Self::View(fidl::new_empty!(
2868                fidl_fuchsia_ui_views::ViewRef,
2869                fidl::encoding::DefaultFuchsiaResourceDialect
2870            ))
2871        }
2872
2873        #[inline]
2874        unsafe fn decode(
2875            &mut self,
2876            decoder: &mut fidl::encoding::Decoder<
2877                '_,
2878                fidl::encoding::DefaultFuchsiaResourceDialect,
2879            >,
2880            offset: usize,
2881            mut depth: fidl::encoding::Depth,
2882        ) -> fidl::Result<()> {
2883            decoder.debug_check_bounds::<Self>(offset);
2884            #[allow(unused_variables)]
2885            let next_out_of_line = decoder.next_out_of_line();
2886            let handles_before = decoder.remaining_handles();
2887            let (ordinal, inlined, num_bytes, num_handles) =
2888                fidl::encoding::decode_union_inline_portion(decoder, offset)?;
2889
2890            let member_inline_size = match ordinal {
2891                1 => <fidl_fuchsia_ui_views::ViewRef as fidl::encoding::TypeMarker>::inline_size(
2892                    decoder.context,
2893                ),
2894                _ => return Err(fidl::Error::UnknownUnionTag),
2895            };
2896
2897            if inlined != (member_inline_size <= 4) {
2898                return Err(fidl::Error::InvalidInlineBitInEnvelope);
2899            }
2900            let _inner_offset;
2901            if inlined {
2902                decoder.check_inline_envelope_padding(offset + 8, member_inline_size)?;
2903                _inner_offset = offset + 8;
2904            } else {
2905                depth.increment()?;
2906                _inner_offset = decoder.out_of_line_offset(member_inline_size)?;
2907            }
2908            match ordinal {
2909                1 => {
2910                    #[allow(irrefutable_let_patterns)]
2911                    if let Context::View(_) = self {
2912                        // Do nothing, read the value into the object
2913                    } else {
2914                        // Initialize `self` to the right variant
2915                        *self = Context::View(fidl::new_empty!(
2916                            fidl_fuchsia_ui_views::ViewRef,
2917                            fidl::encoding::DefaultFuchsiaResourceDialect
2918                        ));
2919                    }
2920                    #[allow(irrefutable_let_patterns)]
2921                    if let Context::View(ref mut val) = self {
2922                        fidl::decode!(
2923                            fidl_fuchsia_ui_views::ViewRef,
2924                            fidl::encoding::DefaultFuchsiaResourceDialect,
2925                            val,
2926                            decoder,
2927                            _inner_offset,
2928                            depth
2929                        )?;
2930                    } else {
2931                        unreachable!()
2932                    }
2933                }
2934                ordinal => panic!("unexpected ordinal {:?}", ordinal),
2935            }
2936            if !inlined && decoder.next_out_of_line() != next_out_of_line + (num_bytes as usize) {
2937                return Err(fidl::Error::InvalidNumBytesInEnvelope);
2938            }
2939            if handles_before != decoder.remaining_handles() + (num_handles as usize) {
2940                return Err(fidl::Error::InvalidNumHandlesInEnvelope);
2941            }
2942            Ok(())
2943        }
2944    }
2945
2946    impl fidl::encoding::ResourceTypeMarker for Target {
2947        type Borrowed<'a> = &'a mut Self;
2948        fn take_or_borrow<'a>(
2949            value: &'a mut <Self as fidl::encoding::TypeMarker>::Owned,
2950        ) -> Self::Borrowed<'a> {
2951            value
2952        }
2953    }
2954
2955    unsafe impl fidl::encoding::TypeMarker for Target {
2956        type Owned = Self;
2957
2958        #[inline(always)]
2959        fn inline_align(_context: fidl::encoding::Context) -> usize {
2960            8
2961        }
2962
2963        #[inline(always)]
2964        fn inline_size(_context: fidl::encoding::Context) -> usize {
2965            16
2966        }
2967    }
2968
2969    unsafe impl fidl::encoding::Encode<Target, fidl::encoding::DefaultFuchsiaResourceDialect>
2970        for &mut Target
2971    {
2972        #[inline]
2973        unsafe fn encode(
2974            self,
2975            encoder: &mut fidl::encoding::Encoder<
2976                '_,
2977                fidl::encoding::DefaultFuchsiaResourceDialect,
2978            >,
2979            offset: usize,
2980            _depth: fidl::encoding::Depth,
2981        ) -> fidl::Result<()> {
2982            encoder.debug_check_bounds::<Target>(offset);
2983            encoder.write_num::<u64>(self.ordinal(), offset);
2984            match self {
2985            Target::View(ref mut val) => {
2986                fidl::encoding::encode_in_envelope::<fidl_fuchsia_ui_views::ViewRef, fidl::encoding::DefaultFuchsiaResourceDialect>(
2987                    <fidl_fuchsia_ui_views::ViewRef as fidl::encoding::ResourceTypeMarker>::take_or_borrow(val),
2988                    encoder, offset + 8, _depth
2989                )
2990            }
2991        }
2992        }
2993    }
2994
2995    impl fidl::encoding::Decode<Self, fidl::encoding::DefaultFuchsiaResourceDialect> for Target {
2996        #[inline(always)]
2997        fn new_empty() -> Self {
2998            Self::View(fidl::new_empty!(
2999                fidl_fuchsia_ui_views::ViewRef,
3000                fidl::encoding::DefaultFuchsiaResourceDialect
3001            ))
3002        }
3003
3004        #[inline]
3005        unsafe fn decode(
3006            &mut self,
3007            decoder: &mut fidl::encoding::Decoder<
3008                '_,
3009                fidl::encoding::DefaultFuchsiaResourceDialect,
3010            >,
3011            offset: usize,
3012            mut depth: fidl::encoding::Depth,
3013        ) -> fidl::Result<()> {
3014            decoder.debug_check_bounds::<Self>(offset);
3015            #[allow(unused_variables)]
3016            let next_out_of_line = decoder.next_out_of_line();
3017            let handles_before = decoder.remaining_handles();
3018            let (ordinal, inlined, num_bytes, num_handles) =
3019                fidl::encoding::decode_union_inline_portion(decoder, offset)?;
3020
3021            let member_inline_size = match ordinal {
3022                1 => <fidl_fuchsia_ui_views::ViewRef as fidl::encoding::TypeMarker>::inline_size(
3023                    decoder.context,
3024                ),
3025                _ => return Err(fidl::Error::UnknownUnionTag),
3026            };
3027
3028            if inlined != (member_inline_size <= 4) {
3029                return Err(fidl::Error::InvalidInlineBitInEnvelope);
3030            }
3031            let _inner_offset;
3032            if inlined {
3033                decoder.check_inline_envelope_padding(offset + 8, member_inline_size)?;
3034                _inner_offset = offset + 8;
3035            } else {
3036                depth.increment()?;
3037                _inner_offset = decoder.out_of_line_offset(member_inline_size)?;
3038            }
3039            match ordinal {
3040                1 => {
3041                    #[allow(irrefutable_let_patterns)]
3042                    if let Target::View(_) = self {
3043                        // Do nothing, read the value into the object
3044                    } else {
3045                        // Initialize `self` to the right variant
3046                        *self = Target::View(fidl::new_empty!(
3047                            fidl_fuchsia_ui_views::ViewRef,
3048                            fidl::encoding::DefaultFuchsiaResourceDialect
3049                        ));
3050                    }
3051                    #[allow(irrefutable_let_patterns)]
3052                    if let Target::View(ref mut val) = self {
3053                        fidl::decode!(
3054                            fidl_fuchsia_ui_views::ViewRef,
3055                            fidl::encoding::DefaultFuchsiaResourceDialect,
3056                            val,
3057                            decoder,
3058                            _inner_offset,
3059                            depth
3060                        )?;
3061                    } else {
3062                        unreachable!()
3063                    }
3064                }
3065                ordinal => panic!("unexpected ordinal {:?}", ordinal),
3066            }
3067            if !inlined && decoder.next_out_of_line() != next_out_of_line + (num_bytes as usize) {
3068                return Err(fidl::Error::InvalidNumBytesInEnvelope);
3069            }
3070            if handles_before != decoder.remaining_handles() + (num_handles as usize) {
3071                return Err(fidl::Error::InvalidNumHandlesInEnvelope);
3072            }
3073            Ok(())
3074        }
3075    }
3076}