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