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