Skip to main content

fidl_fuchsia_hardware_spmi/
fidl_fuchsia_hardware_spmi.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_hardware_spmi_common::*;
11use futures::future::{self, MaybeDone, TryFutureExt};
12use zx_status;
13
14#[derive(Debug, Eq, Hash, Ord, PartialEq, PartialOrd)]
15pub struct DebugConnectTargetRequest {
16    pub target_id: u8,
17    pub server: fidl::endpoints::ServerEnd<DeviceMarker>,
18}
19
20impl fidl::Standalone<fidl::encoding::DefaultFuchsiaResourceDialect> for DebugConnectTargetRequest {}
21
22#[derive(Debug, Eq, Hash, Ord, PartialEq, PartialOrd)]
23pub struct DeviceWatchControllerWriteCommandsRequest {
24    pub address: u8,
25    pub size: u16,
26    pub setup_wake_lease: Option<fidl::EventPair>,
27}
28
29impl fidl::Standalone<fidl::encoding::DefaultFuchsiaResourceDialect>
30    for DeviceWatchControllerWriteCommandsRequest
31{
32}
33
34#[derive(Debug, Eq, Hash, Ord, PartialEq, PartialOrd)]
35pub struct DeviceWatchControllerWriteCommandsResponse {
36    pub writes: Vec<Register8>,
37    pub wake_lease: Option<fidl::EventPair>,
38}
39
40impl fidl::Standalone<fidl::encoding::DefaultFuchsiaResourceDialect>
41    for DeviceWatchControllerWriteCommandsResponse
42{
43}
44
45#[derive(Debug, Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Hash)]
46pub struct DebugMarker;
47
48impl fidl::endpoints::ProtocolMarker for DebugMarker {
49    type Proxy = DebugProxy;
50    type RequestStream = DebugRequestStream;
51    #[cfg(target_os = "fuchsia")]
52    type SynchronousProxy = DebugSynchronousProxy;
53
54    const DEBUG_NAME: &'static str = "(anonymous) Debug";
55}
56pub type DebugConnectTargetResult = Result<(), DriverError>;
57
58pub trait DebugProxyInterface: Send + Sync {
59    type ConnectTargetResponseFut: std::future::Future<Output = Result<DebugConnectTargetResult, fidl::Error>>
60        + Send;
61    fn r#connect_target(
62        &self,
63        target_id: u8,
64        server: fidl::endpoints::ServerEnd<DeviceMarker>,
65    ) -> Self::ConnectTargetResponseFut;
66    type GetControllerPropertiesResponseFut: std::future::Future<Output = Result<DebugGetControllerPropertiesResponse, fidl::Error>>
67        + Send;
68    fn r#get_controller_properties(&self) -> Self::GetControllerPropertiesResponseFut;
69}
70#[derive(Debug)]
71#[cfg(target_os = "fuchsia")]
72pub struct DebugSynchronousProxy {
73    client: fidl::client::sync::Client,
74}
75
76#[cfg(target_os = "fuchsia")]
77impl fidl::endpoints::SynchronousProxy for DebugSynchronousProxy {
78    type Proxy = DebugProxy;
79    type Protocol = DebugMarker;
80
81    fn from_channel(inner: fidl::Channel) -> Self {
82        Self::new(inner)
83    }
84
85    fn into_channel(self) -> fidl::Channel {
86        self.client.into_channel()
87    }
88
89    fn as_channel(&self) -> &fidl::Channel {
90        self.client.as_channel()
91    }
92}
93
94#[cfg(target_os = "fuchsia")]
95impl DebugSynchronousProxy {
96    pub fn new(channel: fidl::Channel) -> Self {
97        Self { client: fidl::client::sync::Client::new(channel) }
98    }
99
100    pub fn into_channel(self) -> fidl::Channel {
101        self.client.into_channel()
102    }
103
104    /// Waits until an event arrives and returns it. It is safe for other
105    /// threads to make concurrent requests while waiting for an event.
106    pub fn wait_for_event(
107        &self,
108        deadline: zx::MonotonicInstant,
109    ) -> Result<DebugEvent, fidl::Error> {
110        DebugEvent::decode(self.client.wait_for_event::<DebugMarker>(deadline)?)
111    }
112
113    /// Connects to the target device with the given ID. Equivalent to connecting to `TargetService`
114    /// via the corresponding driver node.
115    ///
116    /// Returns `INVALID_ARGS` if `target_id` is greater than or equal to `MAX_TARGETS`.
117    /// May return an error if there is no such target on the bus; otherwise errors will be returned
118    /// when attempting to access the client.
119    pub fn r#connect_target(
120        &self,
121        mut target_id: u8,
122        mut server: fidl::endpoints::ServerEnd<DeviceMarker>,
123        ___deadline: zx::MonotonicInstant,
124    ) -> Result<DebugConnectTargetResult, fidl::Error> {
125        let _response = self.client.send_query::<
126            DebugConnectTargetRequest,
127            fidl::encoding::ResultType<fidl::encoding::EmptyStruct, DriverError>,
128            DebugMarker,
129        >(
130            (target_id, server,),
131            0xb18ebc371c68d19,
132            fidl::encoding::DynamicFlags::empty(),
133            ___deadline,
134        )?;
135        Ok(_response.map(|x| x))
136    }
137
138    /// Returns the properties of the host SPMI controller.
139    pub fn r#get_controller_properties(
140        &self,
141        ___deadline: zx::MonotonicInstant,
142    ) -> Result<DebugGetControllerPropertiesResponse, fidl::Error> {
143        let _response = self.client.send_query::<
144            fidl::encoding::EmptyPayload,
145            DebugGetControllerPropertiesResponse,
146            DebugMarker,
147        >(
148            (),
149            0x41b1c4ef901d051f,
150            fidl::encoding::DynamicFlags::empty(),
151            ___deadline,
152        )?;
153        Ok(_response)
154    }
155}
156
157#[cfg(target_os = "fuchsia")]
158impl From<DebugSynchronousProxy> for zx::NullableHandle {
159    fn from(value: DebugSynchronousProxy) -> Self {
160        value.into_channel().into()
161    }
162}
163
164#[cfg(target_os = "fuchsia")]
165impl From<fidl::Channel> for DebugSynchronousProxy {
166    fn from(value: fidl::Channel) -> Self {
167        Self::new(value)
168    }
169}
170
171#[cfg(target_os = "fuchsia")]
172impl fidl::endpoints::FromClient for DebugSynchronousProxy {
173    type Protocol = DebugMarker;
174
175    fn from_client(value: fidl::endpoints::ClientEnd<DebugMarker>) -> Self {
176        Self::new(value.into_channel())
177    }
178}
179
180#[derive(Debug, Clone)]
181pub struct DebugProxy {
182    client: fidl::client::Client<fidl::encoding::DefaultFuchsiaResourceDialect>,
183}
184
185impl fidl::endpoints::Proxy for DebugProxy {
186    type Protocol = DebugMarker;
187
188    fn from_channel(inner: ::fidl::AsyncChannel) -> Self {
189        Self::new(inner)
190    }
191
192    fn into_channel(self) -> Result<::fidl::AsyncChannel, Self> {
193        self.client.into_channel().map_err(|client| Self { client })
194    }
195
196    fn as_channel(&self) -> &::fidl::AsyncChannel {
197        self.client.as_channel()
198    }
199}
200
201impl DebugProxy {
202    /// Create a new Proxy for fuchsia.hardware.spmi/Debug.
203    pub fn new(channel: ::fidl::AsyncChannel) -> Self {
204        let protocol_name = <DebugMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME;
205        Self { client: fidl::client::Client::new(channel, protocol_name) }
206    }
207
208    /// Get a Stream of events from the remote end of the protocol.
209    ///
210    /// # Panics
211    ///
212    /// Panics if the event stream was already taken.
213    pub fn take_event_stream(&self) -> DebugEventStream {
214        DebugEventStream { event_receiver: self.client.take_event_receiver() }
215    }
216
217    /// Connects to the target device with the given ID. Equivalent to connecting to `TargetService`
218    /// via the corresponding driver node.
219    ///
220    /// Returns `INVALID_ARGS` if `target_id` is greater than or equal to `MAX_TARGETS`.
221    /// May return an error if there is no such target on the bus; otherwise errors will be returned
222    /// when attempting to access the client.
223    pub fn r#connect_target(
224        &self,
225        mut target_id: u8,
226        mut server: fidl::endpoints::ServerEnd<DeviceMarker>,
227    ) -> fidl::client::QueryResponseFut<
228        DebugConnectTargetResult,
229        fidl::encoding::DefaultFuchsiaResourceDialect,
230    > {
231        DebugProxyInterface::r#connect_target(self, target_id, server)
232    }
233
234    /// Returns the properties of the host SPMI controller.
235    pub fn r#get_controller_properties(
236        &self,
237    ) -> fidl::client::QueryResponseFut<
238        DebugGetControllerPropertiesResponse,
239        fidl::encoding::DefaultFuchsiaResourceDialect,
240    > {
241        DebugProxyInterface::r#get_controller_properties(self)
242    }
243}
244
245impl DebugProxyInterface for DebugProxy {
246    type ConnectTargetResponseFut = fidl::client::QueryResponseFut<
247        DebugConnectTargetResult,
248        fidl::encoding::DefaultFuchsiaResourceDialect,
249    >;
250    fn r#connect_target(
251        &self,
252        mut target_id: u8,
253        mut server: fidl::endpoints::ServerEnd<DeviceMarker>,
254    ) -> Self::ConnectTargetResponseFut {
255        fn _decode(
256            mut _buf: Result<<fidl::encoding::DefaultFuchsiaResourceDialect as fidl::encoding::ResourceDialect>::MessageBufEtc, fidl::Error>,
257        ) -> Result<DebugConnectTargetResult, fidl::Error> {
258            let _response = fidl::client::decode_transaction_body::<
259                fidl::encoding::ResultType<fidl::encoding::EmptyStruct, DriverError>,
260                fidl::encoding::DefaultFuchsiaResourceDialect,
261                0xb18ebc371c68d19,
262            >(_buf?)?;
263            Ok(_response.map(|x| x))
264        }
265        self.client.send_query_and_decode::<DebugConnectTargetRequest, DebugConnectTargetResult>(
266            (target_id, server),
267            0xb18ebc371c68d19,
268            fidl::encoding::DynamicFlags::empty(),
269            _decode,
270        )
271    }
272
273    type GetControllerPropertiesResponseFut = fidl::client::QueryResponseFut<
274        DebugGetControllerPropertiesResponse,
275        fidl::encoding::DefaultFuchsiaResourceDialect,
276    >;
277    fn r#get_controller_properties(&self) -> Self::GetControllerPropertiesResponseFut {
278        fn _decode(
279            mut _buf: Result<<fidl::encoding::DefaultFuchsiaResourceDialect as fidl::encoding::ResourceDialect>::MessageBufEtc, fidl::Error>,
280        ) -> Result<DebugGetControllerPropertiesResponse, fidl::Error> {
281            let _response = fidl::client::decode_transaction_body::<
282                DebugGetControllerPropertiesResponse,
283                fidl::encoding::DefaultFuchsiaResourceDialect,
284                0x41b1c4ef901d051f,
285            >(_buf?)?;
286            Ok(_response)
287        }
288        self.client.send_query_and_decode::<
289            fidl::encoding::EmptyPayload,
290            DebugGetControllerPropertiesResponse,
291        >(
292            (),
293            0x41b1c4ef901d051f,
294            fidl::encoding::DynamicFlags::empty(),
295            _decode,
296        )
297    }
298}
299
300pub struct DebugEventStream {
301    event_receiver: fidl::client::EventReceiver<fidl::encoding::DefaultFuchsiaResourceDialect>,
302}
303
304impl std::marker::Unpin for DebugEventStream {}
305
306impl futures::stream::FusedStream for DebugEventStream {
307    fn is_terminated(&self) -> bool {
308        self.event_receiver.is_terminated()
309    }
310}
311
312impl futures::Stream for DebugEventStream {
313    type Item = Result<DebugEvent, fidl::Error>;
314
315    fn poll_next(
316        mut self: std::pin::Pin<&mut Self>,
317        cx: &mut std::task::Context<'_>,
318    ) -> std::task::Poll<Option<Self::Item>> {
319        match futures::ready!(futures::stream::StreamExt::poll_next_unpin(
320            &mut self.event_receiver,
321            cx
322        )?) {
323            Some(buf) => std::task::Poll::Ready(Some(DebugEvent::decode(buf))),
324            None => std::task::Poll::Ready(None),
325        }
326    }
327}
328
329#[derive(Debug)]
330pub enum DebugEvent {
331    #[non_exhaustive]
332    _UnknownEvent {
333        /// Ordinal of the event that was sent.
334        ordinal: u64,
335    },
336}
337
338impl DebugEvent {
339    /// Decodes a message buffer as a [`DebugEvent`].
340    fn decode(
341        mut buf: <fidl::encoding::DefaultFuchsiaResourceDialect as fidl::encoding::ResourceDialect>::MessageBufEtc,
342    ) -> Result<DebugEvent, fidl::Error> {
343        let (bytes, _handles) = buf.split_mut();
344        let (tx_header, _body_bytes) = fidl::encoding::decode_transaction_header(bytes)?;
345        debug_assert_eq!(tx_header.tx_id, 0);
346        match tx_header.ordinal {
347            _ if tx_header.dynamic_flags().contains(fidl::encoding::DynamicFlags::FLEXIBLE) => {
348                Ok(DebugEvent::_UnknownEvent { ordinal: tx_header.ordinal })
349            }
350            _ => Err(fidl::Error::UnknownOrdinal {
351                ordinal: tx_header.ordinal,
352                protocol_name: <DebugMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME,
353            }),
354        }
355    }
356}
357
358/// A Stream of incoming requests for fuchsia.hardware.spmi/Debug.
359pub struct DebugRequestStream {
360    inner: std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>,
361    is_terminated: bool,
362}
363
364impl std::marker::Unpin for DebugRequestStream {}
365
366impl futures::stream::FusedStream for DebugRequestStream {
367    fn is_terminated(&self) -> bool {
368        self.is_terminated
369    }
370}
371
372impl fidl::endpoints::RequestStream for DebugRequestStream {
373    type Protocol = DebugMarker;
374    type ControlHandle = DebugControlHandle;
375
376    fn from_channel(channel: ::fidl::AsyncChannel) -> Self {
377        Self { inner: std::sync::Arc::new(fidl::ServeInner::new(channel)), is_terminated: false }
378    }
379
380    fn control_handle(&self) -> Self::ControlHandle {
381        DebugControlHandle { inner: self.inner.clone() }
382    }
383
384    fn into_inner(
385        self,
386    ) -> (::std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>, bool)
387    {
388        (self.inner, self.is_terminated)
389    }
390
391    fn from_inner(
392        inner: std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>,
393        is_terminated: bool,
394    ) -> Self {
395        Self { inner, is_terminated }
396    }
397}
398
399impl futures::Stream for DebugRequestStream {
400    type Item = Result<DebugRequest, fidl::Error>;
401
402    fn poll_next(
403        mut self: std::pin::Pin<&mut Self>,
404        cx: &mut std::task::Context<'_>,
405    ) -> std::task::Poll<Option<Self::Item>> {
406        let this = &mut *self;
407        if this.inner.check_shutdown(cx) {
408            this.is_terminated = true;
409            return std::task::Poll::Ready(None);
410        }
411        if this.is_terminated {
412            panic!("polled DebugRequestStream after completion");
413        }
414        fidl::encoding::with_tls_decode_buf::<_, fidl::encoding::DefaultFuchsiaResourceDialect>(
415            |bytes, handles| {
416                match this.inner.channel().read_etc(cx, bytes, handles) {
417                    std::task::Poll::Ready(Ok(())) => {}
418                    std::task::Poll::Pending => return std::task::Poll::Pending,
419                    std::task::Poll::Ready(Err(zx_status::Status::PEER_CLOSED)) => {
420                        this.is_terminated = true;
421                        return std::task::Poll::Ready(None);
422                    }
423                    std::task::Poll::Ready(Err(e)) => {
424                        return std::task::Poll::Ready(Some(Err(fidl::Error::ServerRequestRead(
425                            e.into(),
426                        ))));
427                    }
428                }
429
430                // A message has been received from the channel
431                let (header, _body_bytes) = fidl::encoding::decode_transaction_header(bytes)?;
432
433                std::task::Poll::Ready(Some(match header.ordinal {
434                    0xb18ebc371c68d19 => {
435                        header.validate_request_tx_id(fidl::MethodType::TwoWay)?;
436                        let mut req = fidl::new_empty!(
437                            DebugConnectTargetRequest,
438                            fidl::encoding::DefaultFuchsiaResourceDialect
439                        );
440                        fidl::encoding::Decoder::<fidl::encoding::DefaultFuchsiaResourceDialect>::decode_into::<DebugConnectTargetRequest>(&header, _body_bytes, handles, &mut req)?;
441                        let control_handle = DebugControlHandle { inner: this.inner.clone() };
442                        Ok(DebugRequest::ConnectTarget {
443                            target_id: req.target_id,
444                            server: req.server,
445
446                            responder: DebugConnectTargetResponder {
447                                control_handle: std::mem::ManuallyDrop::new(control_handle),
448                                tx_id: header.tx_id,
449                            },
450                        })
451                    }
452                    0x41b1c4ef901d051f => {
453                        header.validate_request_tx_id(fidl::MethodType::TwoWay)?;
454                        let mut req = fidl::new_empty!(
455                            fidl::encoding::EmptyPayload,
456                            fidl::encoding::DefaultFuchsiaResourceDialect
457                        );
458                        fidl::encoding::Decoder::<fidl::encoding::DefaultFuchsiaResourceDialect>::decode_into::<fidl::encoding::EmptyPayload>(&header, _body_bytes, handles, &mut req)?;
459                        let control_handle = DebugControlHandle { inner: this.inner.clone() };
460                        Ok(DebugRequest::GetControllerProperties {
461                            responder: DebugGetControllerPropertiesResponder {
462                                control_handle: std::mem::ManuallyDrop::new(control_handle),
463                                tx_id: header.tx_id,
464                            },
465                        })
466                    }
467                    _ if header.tx_id == 0
468                        && header
469                            .dynamic_flags()
470                            .contains(fidl::encoding::DynamicFlags::FLEXIBLE) =>
471                    {
472                        Ok(DebugRequest::_UnknownMethod {
473                            ordinal: header.ordinal,
474                            control_handle: DebugControlHandle { inner: this.inner.clone() },
475                            method_type: fidl::MethodType::OneWay,
476                        })
477                    }
478                    _ if header
479                        .dynamic_flags()
480                        .contains(fidl::encoding::DynamicFlags::FLEXIBLE) =>
481                    {
482                        this.inner.send_framework_err(
483                            fidl::encoding::FrameworkErr::UnknownMethod,
484                            header.tx_id,
485                            header.ordinal,
486                            header.dynamic_flags(),
487                            (bytes, handles),
488                        )?;
489                        Ok(DebugRequest::_UnknownMethod {
490                            ordinal: header.ordinal,
491                            control_handle: DebugControlHandle { inner: this.inner.clone() },
492                            method_type: fidl::MethodType::TwoWay,
493                        })
494                    }
495                    _ => Err(fidl::Error::UnknownOrdinal {
496                        ordinal: header.ordinal,
497                        protocol_name: <DebugMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME,
498                    }),
499                }))
500            },
501        )
502    }
503}
504
505#[derive(Debug)]
506pub enum DebugRequest {
507    /// Connects to the target device with the given ID. Equivalent to connecting to `TargetService`
508    /// via the corresponding driver node.
509    ///
510    /// Returns `INVALID_ARGS` if `target_id` is greater than or equal to `MAX_TARGETS`.
511    /// May return an error if there is no such target on the bus; otherwise errors will be returned
512    /// when attempting to access the client.
513    ConnectTarget {
514        target_id: u8,
515        server: fidl::endpoints::ServerEnd<DeviceMarker>,
516        responder: DebugConnectTargetResponder,
517    },
518    /// Returns the properties of the host SPMI controller.
519    GetControllerProperties { responder: DebugGetControllerPropertiesResponder },
520    /// An interaction was received which does not match any known method.
521    #[non_exhaustive]
522    _UnknownMethod {
523        /// Ordinal of the method that was called.
524        ordinal: u64,
525        control_handle: DebugControlHandle,
526        method_type: fidl::MethodType,
527    },
528}
529
530impl DebugRequest {
531    #[allow(irrefutable_let_patterns)]
532    pub fn into_connect_target(
533        self,
534    ) -> Option<(u8, fidl::endpoints::ServerEnd<DeviceMarker>, DebugConnectTargetResponder)> {
535        if let DebugRequest::ConnectTarget { target_id, server, responder } = self {
536            Some((target_id, server, responder))
537        } else {
538            None
539        }
540    }
541
542    #[allow(irrefutable_let_patterns)]
543    pub fn into_get_controller_properties(self) -> Option<(DebugGetControllerPropertiesResponder)> {
544        if let DebugRequest::GetControllerProperties { responder } = self {
545            Some((responder))
546        } else {
547            None
548        }
549    }
550
551    /// Name of the method defined in FIDL
552    pub fn method_name(&self) -> &'static str {
553        match *self {
554            DebugRequest::ConnectTarget { .. } => "connect_target",
555            DebugRequest::GetControllerProperties { .. } => "get_controller_properties",
556            DebugRequest::_UnknownMethod { method_type: fidl::MethodType::OneWay, .. } => {
557                "unknown one-way method"
558            }
559            DebugRequest::_UnknownMethod { method_type: fidl::MethodType::TwoWay, .. } => {
560                "unknown two-way method"
561            }
562        }
563    }
564}
565
566#[derive(Debug, Clone)]
567pub struct DebugControlHandle {
568    inner: std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>,
569}
570
571impl DebugControlHandle {
572    pub fn shutdown_with_epitaph(&self, status: impl Into<fidl::Epitaph>) {
573        self.inner.shutdown_with_epitaph(status.into())
574    }
575}
576
577impl fidl::endpoints::ControlHandle for DebugControlHandle {
578    fn shutdown(&self) {
579        self.inner.shutdown()
580    }
581
582    fn shutdown_with_epitaph(&self, status: fidl::Epitaph) {
583        self.inner.shutdown_with_epitaph(status)
584    }
585
586    fn is_closed(&self) -> bool {
587        self.inner.channel().is_closed()
588    }
589    fn on_closed(&self) -> fidl::OnSignalsRef<'_> {
590        self.inner.channel().on_closed()
591    }
592
593    #[cfg(target_os = "fuchsia")]
594    fn signal_peer(
595        &self,
596        clear_mask: zx::Signals,
597        set_mask: zx::Signals,
598    ) -> Result<(), zx_status::Status> {
599        use fidl::Peered;
600        self.inner.channel().signal_peer(clear_mask, set_mask)
601    }
602}
603
604impl DebugControlHandle {}
605
606#[must_use = "FIDL methods require a response to be sent"]
607#[derive(Debug)]
608pub struct DebugConnectTargetResponder {
609    control_handle: std::mem::ManuallyDrop<DebugControlHandle>,
610    tx_id: u32,
611}
612
613/// Set the the channel to be shutdown (see [`DebugControlHandle::shutdown`])
614/// if the responder is dropped without sending a response, so that the client
615/// doesn't hang. To prevent this behavior, call `drop_without_shutdown`.
616impl std::ops::Drop for DebugConnectTargetResponder {
617    fn drop(&mut self) {
618        self.control_handle.shutdown();
619        // Safety: drops once, never accessed again
620        unsafe { std::mem::ManuallyDrop::drop(&mut self.control_handle) };
621    }
622}
623
624impl fidl::endpoints::Responder for DebugConnectTargetResponder {
625    type ControlHandle = DebugControlHandle;
626
627    fn control_handle(&self) -> &DebugControlHandle {
628        &self.control_handle
629    }
630
631    fn drop_without_shutdown(mut self) {
632        // Safety: drops once, never accessed again due to mem::forget
633        unsafe { std::mem::ManuallyDrop::drop(&mut self.control_handle) };
634        // Prevent Drop from running (which would shut down the channel)
635        std::mem::forget(self);
636    }
637}
638
639impl DebugConnectTargetResponder {
640    /// Sends a response to the FIDL transaction.
641    ///
642    /// Sets the channel to shutdown if an error occurs.
643    pub fn send(self, mut result: Result<(), DriverError>) -> Result<(), fidl::Error> {
644        let _result = self.send_raw(result);
645        if _result.is_err() {
646            self.control_handle.shutdown();
647        }
648        self.drop_without_shutdown();
649        _result
650    }
651
652    /// Similar to "send" but does not shutdown the channel if an error occurs.
653    pub fn send_no_shutdown_on_err(
654        self,
655        mut result: Result<(), DriverError>,
656    ) -> Result<(), fidl::Error> {
657        let _result = self.send_raw(result);
658        self.drop_without_shutdown();
659        _result
660    }
661
662    fn send_raw(&self, mut result: Result<(), DriverError>) -> Result<(), fidl::Error> {
663        self.control_handle.inner.send::<fidl::encoding::ResultType<
664            fidl::encoding::EmptyStruct,
665            DriverError,
666        >>(
667            result,
668            self.tx_id,
669            0xb18ebc371c68d19,
670            fidl::encoding::DynamicFlags::empty(),
671        )
672    }
673}
674
675#[must_use = "FIDL methods require a response to be sent"]
676#[derive(Debug)]
677pub struct DebugGetControllerPropertiesResponder {
678    control_handle: std::mem::ManuallyDrop<DebugControlHandle>,
679    tx_id: u32,
680}
681
682/// Set the the channel to be shutdown (see [`DebugControlHandle::shutdown`])
683/// if the responder is dropped without sending a response, so that the client
684/// doesn't hang. To prevent this behavior, call `drop_without_shutdown`.
685impl std::ops::Drop for DebugGetControllerPropertiesResponder {
686    fn drop(&mut self) {
687        self.control_handle.shutdown();
688        // Safety: drops once, never accessed again
689        unsafe { std::mem::ManuallyDrop::drop(&mut self.control_handle) };
690    }
691}
692
693impl fidl::endpoints::Responder for DebugGetControllerPropertiesResponder {
694    type ControlHandle = DebugControlHandle;
695
696    fn control_handle(&self) -> &DebugControlHandle {
697        &self.control_handle
698    }
699
700    fn drop_without_shutdown(mut self) {
701        // Safety: drops once, never accessed again due to mem::forget
702        unsafe { std::mem::ManuallyDrop::drop(&mut self.control_handle) };
703        // Prevent Drop from running (which would shut down the channel)
704        std::mem::forget(self);
705    }
706}
707
708impl DebugGetControllerPropertiesResponder {
709    /// Sends a response to the FIDL transaction.
710    ///
711    /// Sets the channel to shutdown if an error occurs.
712    pub fn send(
713        self,
714        mut payload: &DebugGetControllerPropertiesResponse,
715    ) -> Result<(), fidl::Error> {
716        let _result = self.send_raw(payload);
717        if _result.is_err() {
718            self.control_handle.shutdown();
719        }
720        self.drop_without_shutdown();
721        _result
722    }
723
724    /// Similar to "send" but does not shutdown the channel if an error occurs.
725    pub fn send_no_shutdown_on_err(
726        self,
727        mut payload: &DebugGetControllerPropertiesResponse,
728    ) -> Result<(), fidl::Error> {
729        let _result = self.send_raw(payload);
730        self.drop_without_shutdown();
731        _result
732    }
733
734    fn send_raw(
735        &self,
736        mut payload: &DebugGetControllerPropertiesResponse,
737    ) -> Result<(), fidl::Error> {
738        self.control_handle.inner.send::<DebugGetControllerPropertiesResponse>(
739            payload,
740            self.tx_id,
741            0x41b1c4ef901d051f,
742            fidl::encoding::DynamicFlags::empty(),
743        )
744    }
745}
746
747#[derive(Debug, Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Hash)]
748pub struct DeviceMarker;
749
750impl fidl::endpoints::ProtocolMarker for DeviceMarker {
751    type Proxy = DeviceProxy;
752    type RequestStream = DeviceRequestStream;
753    #[cfg(target_os = "fuchsia")]
754    type SynchronousProxy = DeviceSynchronousProxy;
755
756    const DEBUG_NAME: &'static str = "fuchsia.hardware.spmi.Device";
757}
758impl fidl::endpoints::DiscoverableProtocolMarker for DeviceMarker {}
759pub type DeviceRegisterReadResult = Result<Vec<u8>, DriverError>;
760pub type DeviceRegisterWriteResult = Result<(), DriverError>;
761pub type DeviceWatchControllerWriteCommandsResult =
762    Result<(Vec<Register8>, Option<fidl::EventPair>), DriverError>;
763pub type DeviceCancelWatchControllerWriteCommandsResult = Result<(), DriverError>;
764
765pub trait DeviceProxyInterface: Send + Sync {
766    type RegisterReadResponseFut: std::future::Future<Output = Result<DeviceRegisterReadResult, fidl::Error>>
767        + Send;
768    fn r#register_read(&self, address: u16, size_bytes: u32) -> Self::RegisterReadResponseFut;
769    type RegisterWriteResponseFut: std::future::Future<Output = Result<DeviceRegisterWriteResult, fidl::Error>>
770        + Send;
771    fn r#register_write(&self, address: u16, data: &[u8]) -> Self::RegisterWriteResponseFut;
772    type GetPropertiesResponseFut: std::future::Future<Output = Result<DeviceGetPropertiesResponse, fidl::Error>>
773        + Send;
774    fn r#get_properties(&self) -> Self::GetPropertiesResponseFut;
775    type WatchControllerWriteCommandsResponseFut: std::future::Future<Output = Result<DeviceWatchControllerWriteCommandsResult, fidl::Error>>
776        + Send;
777    fn r#watch_controller_write_commands(
778        &self,
779        address: u8,
780        size: u16,
781        setup_wake_lease: Option<fidl::EventPair>,
782    ) -> Self::WatchControllerWriteCommandsResponseFut;
783    type CancelWatchControllerWriteCommandsResponseFut: std::future::Future<
784            Output = Result<DeviceCancelWatchControllerWriteCommandsResult, fidl::Error>,
785        > + Send;
786    fn r#cancel_watch_controller_write_commands(
787        &self,
788        address: u8,
789        size: u16,
790    ) -> Self::CancelWatchControllerWriteCommandsResponseFut;
791}
792#[derive(Debug)]
793#[cfg(target_os = "fuchsia")]
794pub struct DeviceSynchronousProxy {
795    client: fidl::client::sync::Client,
796}
797
798#[cfg(target_os = "fuchsia")]
799impl fidl::endpoints::SynchronousProxy for DeviceSynchronousProxy {
800    type Proxy = DeviceProxy;
801    type Protocol = DeviceMarker;
802
803    fn from_channel(inner: fidl::Channel) -> Self {
804        Self::new(inner)
805    }
806
807    fn into_channel(self) -> fidl::Channel {
808        self.client.into_channel()
809    }
810
811    fn as_channel(&self) -> &fidl::Channel {
812        self.client.as_channel()
813    }
814}
815
816#[cfg(target_os = "fuchsia")]
817impl DeviceSynchronousProxy {
818    pub fn new(channel: fidl::Channel) -> Self {
819        Self { client: fidl::client::sync::Client::new(channel) }
820    }
821
822    pub fn into_channel(self) -> fidl::Channel {
823        self.client.into_channel()
824    }
825
826    /// Waits until an event arrives and returns it. It is safe for other
827    /// threads to make concurrent requests while waiting for an event.
828    pub fn wait_for_event(
829        &self,
830        deadline: zx::MonotonicInstant,
831    ) -> Result<DeviceEvent, fidl::Error> {
832        DeviceEvent::decode(self.client.wait_for_event::<DeviceMarker>(deadline)?)
833    }
834
835    /// Issue register read commands to the SPMI device.
836    /// The implementation may choose which SPMI variation (e.g. extended, long) to use.
837    /// When successful, it returns `size_bytes` in `data` read contiguously starting from
838    /// `address` in the device.
839    pub fn r#register_read(
840        &self,
841        mut address: u16,
842        mut size_bytes: u32,
843        ___deadline: zx::MonotonicInstant,
844    ) -> Result<DeviceRegisterReadResult, fidl::Error> {
845        let _response = self.client.send_query::<
846            DeviceRegisterReadRequest,
847            fidl::encoding::FlexibleResultType<DeviceRegisterReadResponse, DriverError>,
848            DeviceMarker,
849        >(
850            (address, size_bytes,),
851            0x1b0f6eff7638b5,
852            fidl::encoding::DynamicFlags::FLEXIBLE,
853            ___deadline,
854        )?
855        .into_result::<DeviceMarker>("register_read")?;
856        Ok(_response.map(|x| x.data))
857    }
858
859    /// Issue register write commands to the SPMI device.
860    /// The implementation may choose which SPMI variation (e.g. extended, long) to use.
861    /// When this command is successful, `data` will be written contiguously starting from
862    /// `address` in the device.
863    pub fn r#register_write(
864        &self,
865        mut address: u16,
866        mut data: &[u8],
867        ___deadline: zx::MonotonicInstant,
868    ) -> Result<DeviceRegisterWriteResult, fidl::Error> {
869        let _response = self.client.send_query::<
870            DeviceRegisterWriteRequest,
871            fidl::encoding::FlexibleResultType<fidl::encoding::EmptyStruct, DriverError>,
872            DeviceMarker,
873        >(
874            (address, data,),
875            0xe7f4ed59770bb2b,
876            fidl::encoding::DynamicFlags::FLEXIBLE,
877            ___deadline,
878        )?
879        .into_result::<DeviceMarker>("register_write")?;
880        Ok(_response.map(|x| x))
881    }
882
883    /// Get the properties of the SPMI device.
884    pub fn r#get_properties(
885        &self,
886        ___deadline: zx::MonotonicInstant,
887    ) -> Result<DeviceGetPropertiesResponse, fidl::Error> {
888        let _response = self.client.send_query::<
889            fidl::encoding::EmptyPayload,
890            fidl::encoding::FlexibleType<DeviceGetPropertiesResponse>,
891            DeviceMarker,
892        >(
893            (),
894            0x1e946ec04006ffbb,
895            fidl::encoding::DynamicFlags::FLEXIBLE,
896            ___deadline,
897        )?
898        .into_result::<DeviceMarker>("get_properties")?;
899        Ok(_response)
900    }
901
902    /// Hanging-get method to receive controller write commands from the device. `address` and
903    /// `size` specify the register range to monitor for commands. Multiple overlapping calls to
904    /// this method are not allowed.
905    /// Returns `INVALID_ARGS` if `address` or `size` are invalid, or `BAD_STATE` if another call
906    /// is pending for this register range. Returns `CANCELED` if
907    /// `CancelWatchControllerWriteCommands()` was called for this register range.
908    ///
909    /// If this method is meant to keep the system awake (prevents suspension) while watch is setup,
910    /// use the passed-in `setup_wake_lease` `LeaseToken`. Then, when the watch is triggered this
911    /// method will return a second `wake_lease` `LeaseToken` to prevent suspension.
912    ///
913    /// These keep alive wake lease tokens are provided by the Power Framework's System Activity
914    /// Governor. A driver supporting keep alive must be able to get `wake_lease` from System
915    /// Activity Governor.
916    ///
917    /// When `wake_lease` is closed, then the created wake lease keeping the system from suspending
918    /// at the time of watch triggering is dropped. Hence, to guarantee that the system is not
919    /// suspended by the Power Framework a client must either keep this `wake_lease` for as long as
920    /// the system needs to stay awake, or a client must get its own wake lease from the Power
921    /// Framework before it drops `wake_lease` to prevent suspension.
922    pub fn r#watch_controller_write_commands(
923        &self,
924        mut address: u8,
925        mut size: u16,
926        mut setup_wake_lease: Option<fidl::EventPair>,
927        ___deadline: zx::MonotonicInstant,
928    ) -> Result<DeviceWatchControllerWriteCommandsResult, fidl::Error> {
929        let _response = self.client.send_query::<
930            DeviceWatchControllerWriteCommandsRequest,
931            fidl::encoding::FlexibleResultType<DeviceWatchControllerWriteCommandsResponse, DriverError>,
932            DeviceMarker,
933        >(
934            (address, size, setup_wake_lease,),
935            0x41674c1eba4d05ac,
936            fidl::encoding::DynamicFlags::FLEXIBLE,
937            ___deadline,
938        )?
939        .into_result::<DeviceMarker>("watch_controller_write_commands")?;
940        Ok(_response.map(|x| (x.writes, x.wake_lease)))
941    }
942
943    /// Cancels an pending call to `WatchControllerWriteCommands`. `address` and `size` must
944    /// exactly match a previous call to `WatchControllerWriteCommands()`, otherwise `NOT_FOUND`
945    /// is returned.
946    pub fn r#cancel_watch_controller_write_commands(
947        &self,
948        mut address: u8,
949        mut size: u16,
950        ___deadline: zx::MonotonicInstant,
951    ) -> Result<DeviceCancelWatchControllerWriteCommandsResult, fidl::Error> {
952        let _response = self.client.send_query::<
953            DeviceCancelWatchControllerWriteCommandsRequest,
954            fidl::encoding::FlexibleResultType<fidl::encoding::EmptyStruct, DriverError>,
955            DeviceMarker,
956        >(
957            (address, size,),
958            0x5057c280e6f0d420,
959            fidl::encoding::DynamicFlags::FLEXIBLE,
960            ___deadline,
961        )?
962        .into_result::<DeviceMarker>("cancel_watch_controller_write_commands")?;
963        Ok(_response.map(|x| x))
964    }
965}
966
967#[cfg(target_os = "fuchsia")]
968impl From<DeviceSynchronousProxy> for zx::NullableHandle {
969    fn from(value: DeviceSynchronousProxy) -> Self {
970        value.into_channel().into()
971    }
972}
973
974#[cfg(target_os = "fuchsia")]
975impl From<fidl::Channel> for DeviceSynchronousProxy {
976    fn from(value: fidl::Channel) -> Self {
977        Self::new(value)
978    }
979}
980
981#[cfg(target_os = "fuchsia")]
982impl fidl::endpoints::FromClient for DeviceSynchronousProxy {
983    type Protocol = DeviceMarker;
984
985    fn from_client(value: fidl::endpoints::ClientEnd<DeviceMarker>) -> Self {
986        Self::new(value.into_channel())
987    }
988}
989
990#[derive(Debug, Clone)]
991pub struct DeviceProxy {
992    client: fidl::client::Client<fidl::encoding::DefaultFuchsiaResourceDialect>,
993}
994
995impl fidl::endpoints::Proxy for DeviceProxy {
996    type Protocol = DeviceMarker;
997
998    fn from_channel(inner: ::fidl::AsyncChannel) -> Self {
999        Self::new(inner)
1000    }
1001
1002    fn into_channel(self) -> Result<::fidl::AsyncChannel, Self> {
1003        self.client.into_channel().map_err(|client| Self { client })
1004    }
1005
1006    fn as_channel(&self) -> &::fidl::AsyncChannel {
1007        self.client.as_channel()
1008    }
1009}
1010
1011impl DeviceProxy {
1012    /// Create a new Proxy for fuchsia.hardware.spmi/Device.
1013    pub fn new(channel: ::fidl::AsyncChannel) -> Self {
1014        let protocol_name = <DeviceMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME;
1015        Self { client: fidl::client::Client::new(channel, protocol_name) }
1016    }
1017
1018    /// Get a Stream of events from the remote end of the protocol.
1019    ///
1020    /// # Panics
1021    ///
1022    /// Panics if the event stream was already taken.
1023    pub fn take_event_stream(&self) -> DeviceEventStream {
1024        DeviceEventStream { event_receiver: self.client.take_event_receiver() }
1025    }
1026
1027    /// Issue register read commands to the SPMI device.
1028    /// The implementation may choose which SPMI variation (e.g. extended, long) to use.
1029    /// When successful, it returns `size_bytes` in `data` read contiguously starting from
1030    /// `address` in the device.
1031    pub fn r#register_read(
1032        &self,
1033        mut address: u16,
1034        mut size_bytes: u32,
1035    ) -> fidl::client::QueryResponseFut<
1036        DeviceRegisterReadResult,
1037        fidl::encoding::DefaultFuchsiaResourceDialect,
1038    > {
1039        DeviceProxyInterface::r#register_read(self, address, size_bytes)
1040    }
1041
1042    /// Issue register write commands to the SPMI device.
1043    /// The implementation may choose which SPMI variation (e.g. extended, long) to use.
1044    /// When this command is successful, `data` will be written contiguously starting from
1045    /// `address` in the device.
1046    pub fn r#register_write(
1047        &self,
1048        mut address: u16,
1049        mut data: &[u8],
1050    ) -> fidl::client::QueryResponseFut<
1051        DeviceRegisterWriteResult,
1052        fidl::encoding::DefaultFuchsiaResourceDialect,
1053    > {
1054        DeviceProxyInterface::r#register_write(self, address, data)
1055    }
1056
1057    /// Get the properties of the SPMI device.
1058    pub fn r#get_properties(
1059        &self,
1060    ) -> fidl::client::QueryResponseFut<
1061        DeviceGetPropertiesResponse,
1062        fidl::encoding::DefaultFuchsiaResourceDialect,
1063    > {
1064        DeviceProxyInterface::r#get_properties(self)
1065    }
1066
1067    /// Hanging-get method to receive controller write commands from the device. `address` and
1068    /// `size` specify the register range to monitor for commands. Multiple overlapping calls to
1069    /// this method are not allowed.
1070    /// Returns `INVALID_ARGS` if `address` or `size` are invalid, or `BAD_STATE` if another call
1071    /// is pending for this register range. Returns `CANCELED` if
1072    /// `CancelWatchControllerWriteCommands()` was called for this register range.
1073    ///
1074    /// If this method is meant to keep the system awake (prevents suspension) while watch is setup,
1075    /// use the passed-in `setup_wake_lease` `LeaseToken`. Then, when the watch is triggered this
1076    /// method will return a second `wake_lease` `LeaseToken` to prevent suspension.
1077    ///
1078    /// These keep alive wake lease tokens are provided by the Power Framework's System Activity
1079    /// Governor. A driver supporting keep alive must be able to get `wake_lease` from System
1080    /// Activity Governor.
1081    ///
1082    /// When `wake_lease` is closed, then the created wake lease keeping the system from suspending
1083    /// at the time of watch triggering is dropped. Hence, to guarantee that the system is not
1084    /// suspended by the Power Framework a client must either keep this `wake_lease` for as long as
1085    /// the system needs to stay awake, or a client must get its own wake lease from the Power
1086    /// Framework before it drops `wake_lease` to prevent suspension.
1087    pub fn r#watch_controller_write_commands(
1088        &self,
1089        mut address: u8,
1090        mut size: u16,
1091        mut setup_wake_lease: Option<fidl::EventPair>,
1092    ) -> fidl::client::QueryResponseFut<
1093        DeviceWatchControllerWriteCommandsResult,
1094        fidl::encoding::DefaultFuchsiaResourceDialect,
1095    > {
1096        DeviceProxyInterface::r#watch_controller_write_commands(
1097            self,
1098            address,
1099            size,
1100            setup_wake_lease,
1101        )
1102    }
1103
1104    /// Cancels an pending call to `WatchControllerWriteCommands`. `address` and `size` must
1105    /// exactly match a previous call to `WatchControllerWriteCommands()`, otherwise `NOT_FOUND`
1106    /// is returned.
1107    pub fn r#cancel_watch_controller_write_commands(
1108        &self,
1109        mut address: u8,
1110        mut size: u16,
1111    ) -> fidl::client::QueryResponseFut<
1112        DeviceCancelWatchControllerWriteCommandsResult,
1113        fidl::encoding::DefaultFuchsiaResourceDialect,
1114    > {
1115        DeviceProxyInterface::r#cancel_watch_controller_write_commands(self, address, size)
1116    }
1117}
1118
1119impl DeviceProxyInterface for DeviceProxy {
1120    type RegisterReadResponseFut = fidl::client::QueryResponseFut<
1121        DeviceRegisterReadResult,
1122        fidl::encoding::DefaultFuchsiaResourceDialect,
1123    >;
1124    fn r#register_read(
1125        &self,
1126        mut address: u16,
1127        mut size_bytes: u32,
1128    ) -> Self::RegisterReadResponseFut {
1129        fn _decode(
1130            mut _buf: Result<<fidl::encoding::DefaultFuchsiaResourceDialect as fidl::encoding::ResourceDialect>::MessageBufEtc, fidl::Error>,
1131        ) -> Result<DeviceRegisterReadResult, fidl::Error> {
1132            let _response = fidl::client::decode_transaction_body::<
1133                fidl::encoding::FlexibleResultType<DeviceRegisterReadResponse, DriverError>,
1134                fidl::encoding::DefaultFuchsiaResourceDialect,
1135                0x1b0f6eff7638b5,
1136            >(_buf?)?
1137            .into_result::<DeviceMarker>("register_read")?;
1138            Ok(_response.map(|x| x.data))
1139        }
1140        self.client.send_query_and_decode::<DeviceRegisterReadRequest, DeviceRegisterReadResult>(
1141            (address, size_bytes),
1142            0x1b0f6eff7638b5,
1143            fidl::encoding::DynamicFlags::FLEXIBLE,
1144            _decode,
1145        )
1146    }
1147
1148    type RegisterWriteResponseFut = fidl::client::QueryResponseFut<
1149        DeviceRegisterWriteResult,
1150        fidl::encoding::DefaultFuchsiaResourceDialect,
1151    >;
1152    fn r#register_write(
1153        &self,
1154        mut address: u16,
1155        mut data: &[u8],
1156    ) -> Self::RegisterWriteResponseFut {
1157        fn _decode(
1158            mut _buf: Result<<fidl::encoding::DefaultFuchsiaResourceDialect as fidl::encoding::ResourceDialect>::MessageBufEtc, fidl::Error>,
1159        ) -> Result<DeviceRegisterWriteResult, fidl::Error> {
1160            let _response = fidl::client::decode_transaction_body::<
1161                fidl::encoding::FlexibleResultType<fidl::encoding::EmptyStruct, DriverError>,
1162                fidl::encoding::DefaultFuchsiaResourceDialect,
1163                0xe7f4ed59770bb2b,
1164            >(_buf?)?
1165            .into_result::<DeviceMarker>("register_write")?;
1166            Ok(_response.map(|x| x))
1167        }
1168        self.client.send_query_and_decode::<DeviceRegisterWriteRequest, DeviceRegisterWriteResult>(
1169            (address, data),
1170            0xe7f4ed59770bb2b,
1171            fidl::encoding::DynamicFlags::FLEXIBLE,
1172            _decode,
1173        )
1174    }
1175
1176    type GetPropertiesResponseFut = fidl::client::QueryResponseFut<
1177        DeviceGetPropertiesResponse,
1178        fidl::encoding::DefaultFuchsiaResourceDialect,
1179    >;
1180    fn r#get_properties(&self) -> Self::GetPropertiesResponseFut {
1181        fn _decode(
1182            mut _buf: Result<<fidl::encoding::DefaultFuchsiaResourceDialect as fidl::encoding::ResourceDialect>::MessageBufEtc, fidl::Error>,
1183        ) -> Result<DeviceGetPropertiesResponse, fidl::Error> {
1184            let _response = fidl::client::decode_transaction_body::<
1185                fidl::encoding::FlexibleType<DeviceGetPropertiesResponse>,
1186                fidl::encoding::DefaultFuchsiaResourceDialect,
1187                0x1e946ec04006ffbb,
1188            >(_buf?)?
1189            .into_result::<DeviceMarker>("get_properties")?;
1190            Ok(_response)
1191        }
1192        self.client
1193            .send_query_and_decode::<fidl::encoding::EmptyPayload, DeviceGetPropertiesResponse>(
1194                (),
1195                0x1e946ec04006ffbb,
1196                fidl::encoding::DynamicFlags::FLEXIBLE,
1197                _decode,
1198            )
1199    }
1200
1201    type WatchControllerWriteCommandsResponseFut = fidl::client::QueryResponseFut<
1202        DeviceWatchControllerWriteCommandsResult,
1203        fidl::encoding::DefaultFuchsiaResourceDialect,
1204    >;
1205    fn r#watch_controller_write_commands(
1206        &self,
1207        mut address: u8,
1208        mut size: u16,
1209        mut setup_wake_lease: Option<fidl::EventPair>,
1210    ) -> Self::WatchControllerWriteCommandsResponseFut {
1211        fn _decode(
1212            mut _buf: Result<<fidl::encoding::DefaultFuchsiaResourceDialect as fidl::encoding::ResourceDialect>::MessageBufEtc, fidl::Error>,
1213        ) -> Result<DeviceWatchControllerWriteCommandsResult, fidl::Error> {
1214            let _response = fidl::client::decode_transaction_body::<
1215                fidl::encoding::FlexibleResultType<
1216                    DeviceWatchControllerWriteCommandsResponse,
1217                    DriverError,
1218                >,
1219                fidl::encoding::DefaultFuchsiaResourceDialect,
1220                0x41674c1eba4d05ac,
1221            >(_buf?)?
1222            .into_result::<DeviceMarker>("watch_controller_write_commands")?;
1223            Ok(_response.map(|x| (x.writes, x.wake_lease)))
1224        }
1225        self.client.send_query_and_decode::<
1226            DeviceWatchControllerWriteCommandsRequest,
1227            DeviceWatchControllerWriteCommandsResult,
1228        >(
1229            (address, size, setup_wake_lease,),
1230            0x41674c1eba4d05ac,
1231            fidl::encoding::DynamicFlags::FLEXIBLE,
1232            _decode,
1233        )
1234    }
1235
1236    type CancelWatchControllerWriteCommandsResponseFut = fidl::client::QueryResponseFut<
1237        DeviceCancelWatchControllerWriteCommandsResult,
1238        fidl::encoding::DefaultFuchsiaResourceDialect,
1239    >;
1240    fn r#cancel_watch_controller_write_commands(
1241        &self,
1242        mut address: u8,
1243        mut size: u16,
1244    ) -> Self::CancelWatchControllerWriteCommandsResponseFut {
1245        fn _decode(
1246            mut _buf: Result<<fidl::encoding::DefaultFuchsiaResourceDialect as fidl::encoding::ResourceDialect>::MessageBufEtc, fidl::Error>,
1247        ) -> Result<DeviceCancelWatchControllerWriteCommandsResult, fidl::Error> {
1248            let _response = fidl::client::decode_transaction_body::<
1249                fidl::encoding::FlexibleResultType<fidl::encoding::EmptyStruct, DriverError>,
1250                fidl::encoding::DefaultFuchsiaResourceDialect,
1251                0x5057c280e6f0d420,
1252            >(_buf?)?
1253            .into_result::<DeviceMarker>("cancel_watch_controller_write_commands")?;
1254            Ok(_response.map(|x| x))
1255        }
1256        self.client.send_query_and_decode::<
1257            DeviceCancelWatchControllerWriteCommandsRequest,
1258            DeviceCancelWatchControllerWriteCommandsResult,
1259        >(
1260            (address, size,),
1261            0x5057c280e6f0d420,
1262            fidl::encoding::DynamicFlags::FLEXIBLE,
1263            _decode,
1264        )
1265    }
1266}
1267
1268pub struct DeviceEventStream {
1269    event_receiver: fidl::client::EventReceiver<fidl::encoding::DefaultFuchsiaResourceDialect>,
1270}
1271
1272impl std::marker::Unpin for DeviceEventStream {}
1273
1274impl futures::stream::FusedStream for DeviceEventStream {
1275    fn is_terminated(&self) -> bool {
1276        self.event_receiver.is_terminated()
1277    }
1278}
1279
1280impl futures::Stream for DeviceEventStream {
1281    type Item = Result<DeviceEvent, fidl::Error>;
1282
1283    fn poll_next(
1284        mut self: std::pin::Pin<&mut Self>,
1285        cx: &mut std::task::Context<'_>,
1286    ) -> std::task::Poll<Option<Self::Item>> {
1287        match futures::ready!(futures::stream::StreamExt::poll_next_unpin(
1288            &mut self.event_receiver,
1289            cx
1290        )?) {
1291            Some(buf) => std::task::Poll::Ready(Some(DeviceEvent::decode(buf))),
1292            None => std::task::Poll::Ready(None),
1293        }
1294    }
1295}
1296
1297#[derive(Debug)]
1298pub enum DeviceEvent {
1299    #[non_exhaustive]
1300    _UnknownEvent {
1301        /// Ordinal of the event that was sent.
1302        ordinal: u64,
1303    },
1304}
1305
1306impl DeviceEvent {
1307    /// Decodes a message buffer as a [`DeviceEvent`].
1308    fn decode(
1309        mut buf: <fidl::encoding::DefaultFuchsiaResourceDialect as fidl::encoding::ResourceDialect>::MessageBufEtc,
1310    ) -> Result<DeviceEvent, fidl::Error> {
1311        let (bytes, _handles) = buf.split_mut();
1312        let (tx_header, _body_bytes) = fidl::encoding::decode_transaction_header(bytes)?;
1313        debug_assert_eq!(tx_header.tx_id, 0);
1314        match tx_header.ordinal {
1315            _ if tx_header.dynamic_flags().contains(fidl::encoding::DynamicFlags::FLEXIBLE) => {
1316                Ok(DeviceEvent::_UnknownEvent { ordinal: tx_header.ordinal })
1317            }
1318            _ => Err(fidl::Error::UnknownOrdinal {
1319                ordinal: tx_header.ordinal,
1320                protocol_name: <DeviceMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME,
1321            }),
1322        }
1323    }
1324}
1325
1326/// A Stream of incoming requests for fuchsia.hardware.spmi/Device.
1327pub struct DeviceRequestStream {
1328    inner: std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>,
1329    is_terminated: bool,
1330}
1331
1332impl std::marker::Unpin for DeviceRequestStream {}
1333
1334impl futures::stream::FusedStream for DeviceRequestStream {
1335    fn is_terminated(&self) -> bool {
1336        self.is_terminated
1337    }
1338}
1339
1340impl fidl::endpoints::RequestStream for DeviceRequestStream {
1341    type Protocol = DeviceMarker;
1342    type ControlHandle = DeviceControlHandle;
1343
1344    fn from_channel(channel: ::fidl::AsyncChannel) -> Self {
1345        Self { inner: std::sync::Arc::new(fidl::ServeInner::new(channel)), is_terminated: false }
1346    }
1347
1348    fn control_handle(&self) -> Self::ControlHandle {
1349        DeviceControlHandle { inner: self.inner.clone() }
1350    }
1351
1352    fn into_inner(
1353        self,
1354    ) -> (::std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>, bool)
1355    {
1356        (self.inner, self.is_terminated)
1357    }
1358
1359    fn from_inner(
1360        inner: std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>,
1361        is_terminated: bool,
1362    ) -> Self {
1363        Self { inner, is_terminated }
1364    }
1365}
1366
1367impl futures::Stream for DeviceRequestStream {
1368    type Item = Result<DeviceRequest, fidl::Error>;
1369
1370    fn poll_next(
1371        mut self: std::pin::Pin<&mut Self>,
1372        cx: &mut std::task::Context<'_>,
1373    ) -> std::task::Poll<Option<Self::Item>> {
1374        let this = &mut *self;
1375        if this.inner.check_shutdown(cx) {
1376            this.is_terminated = true;
1377            return std::task::Poll::Ready(None);
1378        }
1379        if this.is_terminated {
1380            panic!("polled DeviceRequestStream after completion");
1381        }
1382        fidl::encoding::with_tls_decode_buf::<_, fidl::encoding::DefaultFuchsiaResourceDialect>(
1383            |bytes, handles| {
1384                match this.inner.channel().read_etc(cx, bytes, handles) {
1385                    std::task::Poll::Ready(Ok(())) => {}
1386                    std::task::Poll::Pending => return std::task::Poll::Pending,
1387                    std::task::Poll::Ready(Err(zx_status::Status::PEER_CLOSED)) => {
1388                        this.is_terminated = true;
1389                        return std::task::Poll::Ready(None);
1390                    }
1391                    std::task::Poll::Ready(Err(e)) => {
1392                        return std::task::Poll::Ready(Some(Err(fidl::Error::ServerRequestRead(
1393                            e.into(),
1394                        ))));
1395                    }
1396                }
1397
1398                // A message has been received from the channel
1399                let (header, _body_bytes) = fidl::encoding::decode_transaction_header(bytes)?;
1400
1401                std::task::Poll::Ready(Some(match header.ordinal {
1402                    0x1b0f6eff7638b5 => {
1403                        header.validate_request_tx_id(fidl::MethodType::TwoWay)?;
1404                        let mut req = fidl::new_empty!(
1405                            DeviceRegisterReadRequest,
1406                            fidl::encoding::DefaultFuchsiaResourceDialect
1407                        );
1408                        fidl::encoding::Decoder::<fidl::encoding::DefaultFuchsiaResourceDialect>::decode_into::<DeviceRegisterReadRequest>(&header, _body_bytes, handles, &mut req)?;
1409                        let control_handle = DeviceControlHandle { inner: this.inner.clone() };
1410                        Ok(DeviceRequest::RegisterRead {
1411                            address: req.address,
1412                            size_bytes: req.size_bytes,
1413
1414                            responder: DeviceRegisterReadResponder {
1415                                control_handle: std::mem::ManuallyDrop::new(control_handle),
1416                                tx_id: header.tx_id,
1417                            },
1418                        })
1419                    }
1420                    0xe7f4ed59770bb2b => {
1421                        header.validate_request_tx_id(fidl::MethodType::TwoWay)?;
1422                        let mut req = fidl::new_empty!(
1423                            DeviceRegisterWriteRequest,
1424                            fidl::encoding::DefaultFuchsiaResourceDialect
1425                        );
1426                        fidl::encoding::Decoder::<fidl::encoding::DefaultFuchsiaResourceDialect>::decode_into::<DeviceRegisterWriteRequest>(&header, _body_bytes, handles, &mut req)?;
1427                        let control_handle = DeviceControlHandle { inner: this.inner.clone() };
1428                        Ok(DeviceRequest::RegisterWrite {
1429                            address: req.address,
1430                            data: req.data,
1431
1432                            responder: DeviceRegisterWriteResponder {
1433                                control_handle: std::mem::ManuallyDrop::new(control_handle),
1434                                tx_id: header.tx_id,
1435                            },
1436                        })
1437                    }
1438                    0x1e946ec04006ffbb => {
1439                        header.validate_request_tx_id(fidl::MethodType::TwoWay)?;
1440                        let mut req = fidl::new_empty!(
1441                            fidl::encoding::EmptyPayload,
1442                            fidl::encoding::DefaultFuchsiaResourceDialect
1443                        );
1444                        fidl::encoding::Decoder::<fidl::encoding::DefaultFuchsiaResourceDialect>::decode_into::<fidl::encoding::EmptyPayload>(&header, _body_bytes, handles, &mut req)?;
1445                        let control_handle = DeviceControlHandle { inner: this.inner.clone() };
1446                        Ok(DeviceRequest::GetProperties {
1447                            responder: DeviceGetPropertiesResponder {
1448                                control_handle: std::mem::ManuallyDrop::new(control_handle),
1449                                tx_id: header.tx_id,
1450                            },
1451                        })
1452                    }
1453                    0x41674c1eba4d05ac => {
1454                        header.validate_request_tx_id(fidl::MethodType::TwoWay)?;
1455                        let mut req = fidl::new_empty!(
1456                            DeviceWatchControllerWriteCommandsRequest,
1457                            fidl::encoding::DefaultFuchsiaResourceDialect
1458                        );
1459                        fidl::encoding::Decoder::<fidl::encoding::DefaultFuchsiaResourceDialect>::decode_into::<DeviceWatchControllerWriteCommandsRequest>(&header, _body_bytes, handles, &mut req)?;
1460                        let control_handle = DeviceControlHandle { inner: this.inner.clone() };
1461                        Ok(DeviceRequest::WatchControllerWriteCommands {
1462                            address: req.address,
1463                            size: req.size,
1464                            setup_wake_lease: req.setup_wake_lease,
1465
1466                            responder: DeviceWatchControllerWriteCommandsResponder {
1467                                control_handle: std::mem::ManuallyDrop::new(control_handle),
1468                                tx_id: header.tx_id,
1469                            },
1470                        })
1471                    }
1472                    0x5057c280e6f0d420 => {
1473                        header.validate_request_tx_id(fidl::MethodType::TwoWay)?;
1474                        let mut req = fidl::new_empty!(
1475                            DeviceCancelWatchControllerWriteCommandsRequest,
1476                            fidl::encoding::DefaultFuchsiaResourceDialect
1477                        );
1478                        fidl::encoding::Decoder::<fidl::encoding::DefaultFuchsiaResourceDialect>::decode_into::<DeviceCancelWatchControllerWriteCommandsRequest>(&header, _body_bytes, handles, &mut req)?;
1479                        let control_handle = DeviceControlHandle { inner: this.inner.clone() };
1480                        Ok(DeviceRequest::CancelWatchControllerWriteCommands {
1481                            address: req.address,
1482                            size: req.size,
1483
1484                            responder: DeviceCancelWatchControllerWriteCommandsResponder {
1485                                control_handle: std::mem::ManuallyDrop::new(control_handle),
1486                                tx_id: header.tx_id,
1487                            },
1488                        })
1489                    }
1490                    _ if header.tx_id == 0
1491                        && header
1492                            .dynamic_flags()
1493                            .contains(fidl::encoding::DynamicFlags::FLEXIBLE) =>
1494                    {
1495                        Ok(DeviceRequest::_UnknownMethod {
1496                            ordinal: header.ordinal,
1497                            control_handle: DeviceControlHandle { inner: this.inner.clone() },
1498                            method_type: fidl::MethodType::OneWay,
1499                        })
1500                    }
1501                    _ if header
1502                        .dynamic_flags()
1503                        .contains(fidl::encoding::DynamicFlags::FLEXIBLE) =>
1504                    {
1505                        this.inner.send_framework_err(
1506                            fidl::encoding::FrameworkErr::UnknownMethod,
1507                            header.tx_id,
1508                            header.ordinal,
1509                            header.dynamic_flags(),
1510                            (bytes, handles),
1511                        )?;
1512                        Ok(DeviceRequest::_UnknownMethod {
1513                            ordinal: header.ordinal,
1514                            control_handle: DeviceControlHandle { inner: this.inner.clone() },
1515                            method_type: fidl::MethodType::TwoWay,
1516                        })
1517                    }
1518                    _ => Err(fidl::Error::UnknownOrdinal {
1519                        ordinal: header.ordinal,
1520                        protocol_name:
1521                            <DeviceMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME,
1522                    }),
1523                }))
1524            },
1525        )
1526    }
1527}
1528
1529/// Each instance of `Device` represents a target/secondary SPMI device on a SPMI bus.
1530/// To support multiple SPMI devices, multiple nodes must be instantiated.
1531#[derive(Debug)]
1532pub enum DeviceRequest {
1533    /// Issue register read commands to the SPMI device.
1534    /// The implementation may choose which SPMI variation (e.g. extended, long) to use.
1535    /// When successful, it returns `size_bytes` in `data` read contiguously starting from
1536    /// `address` in the device.
1537    RegisterRead { address: u16, size_bytes: u32, responder: DeviceRegisterReadResponder },
1538    /// Issue register write commands to the SPMI device.
1539    /// The implementation may choose which SPMI variation (e.g. extended, long) to use.
1540    /// When this command is successful, `data` will be written contiguously starting from
1541    /// `address` in the device.
1542    RegisterWrite { address: u16, data: Vec<u8>, responder: DeviceRegisterWriteResponder },
1543    /// Get the properties of the SPMI device.
1544    GetProperties { responder: DeviceGetPropertiesResponder },
1545    /// Hanging-get method to receive controller write commands from the device. `address` and
1546    /// `size` specify the register range to monitor for commands. Multiple overlapping calls to
1547    /// this method are not allowed.
1548    /// Returns `INVALID_ARGS` if `address` or `size` are invalid, or `BAD_STATE` if another call
1549    /// is pending for this register range. Returns `CANCELED` if
1550    /// `CancelWatchControllerWriteCommands()` was called for this register range.
1551    ///
1552    /// If this method is meant to keep the system awake (prevents suspension) while watch is setup,
1553    /// use the passed-in `setup_wake_lease` `LeaseToken`. Then, when the watch is triggered this
1554    /// method will return a second `wake_lease` `LeaseToken` to prevent suspension.
1555    ///
1556    /// These keep alive wake lease tokens are provided by the Power Framework's System Activity
1557    /// Governor. A driver supporting keep alive must be able to get `wake_lease` from System
1558    /// Activity Governor.
1559    ///
1560    /// When `wake_lease` is closed, then the created wake lease keeping the system from suspending
1561    /// at the time of watch triggering is dropped. Hence, to guarantee that the system is not
1562    /// suspended by the Power Framework a client must either keep this `wake_lease` for as long as
1563    /// the system needs to stay awake, or a client must get its own wake lease from the Power
1564    /// Framework before it drops `wake_lease` to prevent suspension.
1565    WatchControllerWriteCommands {
1566        address: u8,
1567        size: u16,
1568        setup_wake_lease: Option<fidl::EventPair>,
1569        responder: DeviceWatchControllerWriteCommandsResponder,
1570    },
1571    /// Cancels an pending call to `WatchControllerWriteCommands`. `address` and `size` must
1572    /// exactly match a previous call to `WatchControllerWriteCommands()`, otherwise `NOT_FOUND`
1573    /// is returned.
1574    CancelWatchControllerWriteCommands {
1575        address: u8,
1576        size: u16,
1577        responder: DeviceCancelWatchControllerWriteCommandsResponder,
1578    },
1579    /// An interaction was received which does not match any known method.
1580    #[non_exhaustive]
1581    _UnknownMethod {
1582        /// Ordinal of the method that was called.
1583        ordinal: u64,
1584        control_handle: DeviceControlHandle,
1585        method_type: fidl::MethodType,
1586    },
1587}
1588
1589impl DeviceRequest {
1590    #[allow(irrefutable_let_patterns)]
1591    pub fn into_register_read(self) -> Option<(u16, u32, DeviceRegisterReadResponder)> {
1592        if let DeviceRequest::RegisterRead { address, size_bytes, responder } = self {
1593            Some((address, size_bytes, responder))
1594        } else {
1595            None
1596        }
1597    }
1598
1599    #[allow(irrefutable_let_patterns)]
1600    pub fn into_register_write(self) -> Option<(u16, Vec<u8>, DeviceRegisterWriteResponder)> {
1601        if let DeviceRequest::RegisterWrite { address, data, responder } = self {
1602            Some((address, data, responder))
1603        } else {
1604            None
1605        }
1606    }
1607
1608    #[allow(irrefutable_let_patterns)]
1609    pub fn into_get_properties(self) -> Option<(DeviceGetPropertiesResponder)> {
1610        if let DeviceRequest::GetProperties { responder } = self { Some((responder)) } else { None }
1611    }
1612
1613    #[allow(irrefutable_let_patterns)]
1614    pub fn into_watch_controller_write_commands(
1615        self,
1616    ) -> Option<(u8, u16, Option<fidl::EventPair>, DeviceWatchControllerWriteCommandsResponder)>
1617    {
1618        if let DeviceRequest::WatchControllerWriteCommands {
1619            address,
1620            size,
1621            setup_wake_lease,
1622            responder,
1623        } = self
1624        {
1625            Some((address, size, setup_wake_lease, responder))
1626        } else {
1627            None
1628        }
1629    }
1630
1631    #[allow(irrefutable_let_patterns)]
1632    pub fn into_cancel_watch_controller_write_commands(
1633        self,
1634    ) -> Option<(u8, u16, DeviceCancelWatchControllerWriteCommandsResponder)> {
1635        if let DeviceRequest::CancelWatchControllerWriteCommands { address, size, responder } = self
1636        {
1637            Some((address, size, responder))
1638        } else {
1639            None
1640        }
1641    }
1642
1643    /// Name of the method defined in FIDL
1644    pub fn method_name(&self) -> &'static str {
1645        match *self {
1646            DeviceRequest::RegisterRead { .. } => "register_read",
1647            DeviceRequest::RegisterWrite { .. } => "register_write",
1648            DeviceRequest::GetProperties { .. } => "get_properties",
1649            DeviceRequest::WatchControllerWriteCommands { .. } => "watch_controller_write_commands",
1650            DeviceRequest::CancelWatchControllerWriteCommands { .. } => {
1651                "cancel_watch_controller_write_commands"
1652            }
1653            DeviceRequest::_UnknownMethod { method_type: fidl::MethodType::OneWay, .. } => {
1654                "unknown one-way method"
1655            }
1656            DeviceRequest::_UnknownMethod { method_type: fidl::MethodType::TwoWay, .. } => {
1657                "unknown two-way method"
1658            }
1659        }
1660    }
1661}
1662
1663#[derive(Debug, Clone)]
1664pub struct DeviceControlHandle {
1665    inner: std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>,
1666}
1667
1668impl DeviceControlHandle {
1669    pub fn shutdown_with_epitaph(&self, status: impl Into<fidl::Epitaph>) {
1670        self.inner.shutdown_with_epitaph(status.into())
1671    }
1672}
1673
1674impl fidl::endpoints::ControlHandle for DeviceControlHandle {
1675    fn shutdown(&self) {
1676        self.inner.shutdown()
1677    }
1678
1679    fn shutdown_with_epitaph(&self, status: fidl::Epitaph) {
1680        self.inner.shutdown_with_epitaph(status)
1681    }
1682
1683    fn is_closed(&self) -> bool {
1684        self.inner.channel().is_closed()
1685    }
1686    fn on_closed(&self) -> fidl::OnSignalsRef<'_> {
1687        self.inner.channel().on_closed()
1688    }
1689
1690    #[cfg(target_os = "fuchsia")]
1691    fn signal_peer(
1692        &self,
1693        clear_mask: zx::Signals,
1694        set_mask: zx::Signals,
1695    ) -> Result<(), zx_status::Status> {
1696        use fidl::Peered;
1697        self.inner.channel().signal_peer(clear_mask, set_mask)
1698    }
1699}
1700
1701impl DeviceControlHandle {}
1702
1703#[must_use = "FIDL methods require a response to be sent"]
1704#[derive(Debug)]
1705pub struct DeviceRegisterReadResponder {
1706    control_handle: std::mem::ManuallyDrop<DeviceControlHandle>,
1707    tx_id: u32,
1708}
1709
1710/// Set the the channel to be shutdown (see [`DeviceControlHandle::shutdown`])
1711/// if the responder is dropped without sending a response, so that the client
1712/// doesn't hang. To prevent this behavior, call `drop_without_shutdown`.
1713impl std::ops::Drop for DeviceRegisterReadResponder {
1714    fn drop(&mut self) {
1715        self.control_handle.shutdown();
1716        // Safety: drops once, never accessed again
1717        unsafe { std::mem::ManuallyDrop::drop(&mut self.control_handle) };
1718    }
1719}
1720
1721impl fidl::endpoints::Responder for DeviceRegisterReadResponder {
1722    type ControlHandle = DeviceControlHandle;
1723
1724    fn control_handle(&self) -> &DeviceControlHandle {
1725        &self.control_handle
1726    }
1727
1728    fn drop_without_shutdown(mut self) {
1729        // Safety: drops once, never accessed again due to mem::forget
1730        unsafe { std::mem::ManuallyDrop::drop(&mut self.control_handle) };
1731        // Prevent Drop from running (which would shut down the channel)
1732        std::mem::forget(self);
1733    }
1734}
1735
1736impl DeviceRegisterReadResponder {
1737    /// Sends a response to the FIDL transaction.
1738    ///
1739    /// Sets the channel to shutdown if an error occurs.
1740    pub fn send(self, mut result: Result<&[u8], DriverError>) -> Result<(), fidl::Error> {
1741        let _result = self.send_raw(result);
1742        if _result.is_err() {
1743            self.control_handle.shutdown();
1744        }
1745        self.drop_without_shutdown();
1746        _result
1747    }
1748
1749    /// Similar to "send" but does not shutdown the channel if an error occurs.
1750    pub fn send_no_shutdown_on_err(
1751        self,
1752        mut result: Result<&[u8], DriverError>,
1753    ) -> Result<(), fidl::Error> {
1754        let _result = self.send_raw(result);
1755        self.drop_without_shutdown();
1756        _result
1757    }
1758
1759    fn send_raw(&self, mut result: Result<&[u8], DriverError>) -> Result<(), fidl::Error> {
1760        self.control_handle.inner.send::<fidl::encoding::FlexibleResultType<
1761            DeviceRegisterReadResponse,
1762            DriverError,
1763        >>(
1764            fidl::encoding::FlexibleResult::new(result.map(|data| (data,))),
1765            self.tx_id,
1766            0x1b0f6eff7638b5,
1767            fidl::encoding::DynamicFlags::FLEXIBLE,
1768        )
1769    }
1770}
1771
1772#[must_use = "FIDL methods require a response to be sent"]
1773#[derive(Debug)]
1774pub struct DeviceRegisterWriteResponder {
1775    control_handle: std::mem::ManuallyDrop<DeviceControlHandle>,
1776    tx_id: u32,
1777}
1778
1779/// Set the the channel to be shutdown (see [`DeviceControlHandle::shutdown`])
1780/// if the responder is dropped without sending a response, so that the client
1781/// doesn't hang. To prevent this behavior, call `drop_without_shutdown`.
1782impl std::ops::Drop for DeviceRegisterWriteResponder {
1783    fn drop(&mut self) {
1784        self.control_handle.shutdown();
1785        // Safety: drops once, never accessed again
1786        unsafe { std::mem::ManuallyDrop::drop(&mut self.control_handle) };
1787    }
1788}
1789
1790impl fidl::endpoints::Responder for DeviceRegisterWriteResponder {
1791    type ControlHandle = DeviceControlHandle;
1792
1793    fn control_handle(&self) -> &DeviceControlHandle {
1794        &self.control_handle
1795    }
1796
1797    fn drop_without_shutdown(mut self) {
1798        // Safety: drops once, never accessed again due to mem::forget
1799        unsafe { std::mem::ManuallyDrop::drop(&mut self.control_handle) };
1800        // Prevent Drop from running (which would shut down the channel)
1801        std::mem::forget(self);
1802    }
1803}
1804
1805impl DeviceRegisterWriteResponder {
1806    /// Sends a response to the FIDL transaction.
1807    ///
1808    /// Sets the channel to shutdown if an error occurs.
1809    pub fn send(self, mut result: Result<(), DriverError>) -> Result<(), fidl::Error> {
1810        let _result = self.send_raw(result);
1811        if _result.is_err() {
1812            self.control_handle.shutdown();
1813        }
1814        self.drop_without_shutdown();
1815        _result
1816    }
1817
1818    /// Similar to "send" but does not shutdown the channel if an error occurs.
1819    pub fn send_no_shutdown_on_err(
1820        self,
1821        mut result: Result<(), DriverError>,
1822    ) -> Result<(), fidl::Error> {
1823        let _result = self.send_raw(result);
1824        self.drop_without_shutdown();
1825        _result
1826    }
1827
1828    fn send_raw(&self, mut result: Result<(), DriverError>) -> Result<(), fidl::Error> {
1829        self.control_handle.inner.send::<fidl::encoding::FlexibleResultType<
1830            fidl::encoding::EmptyStruct,
1831            DriverError,
1832        >>(
1833            fidl::encoding::FlexibleResult::new(result),
1834            self.tx_id,
1835            0xe7f4ed59770bb2b,
1836            fidl::encoding::DynamicFlags::FLEXIBLE,
1837        )
1838    }
1839}
1840
1841#[must_use = "FIDL methods require a response to be sent"]
1842#[derive(Debug)]
1843pub struct DeviceGetPropertiesResponder {
1844    control_handle: std::mem::ManuallyDrop<DeviceControlHandle>,
1845    tx_id: u32,
1846}
1847
1848/// Set the the channel to be shutdown (see [`DeviceControlHandle::shutdown`])
1849/// if the responder is dropped without sending a response, so that the client
1850/// doesn't hang. To prevent this behavior, call `drop_without_shutdown`.
1851impl std::ops::Drop for DeviceGetPropertiesResponder {
1852    fn drop(&mut self) {
1853        self.control_handle.shutdown();
1854        // Safety: drops once, never accessed again
1855        unsafe { std::mem::ManuallyDrop::drop(&mut self.control_handle) };
1856    }
1857}
1858
1859impl fidl::endpoints::Responder for DeviceGetPropertiesResponder {
1860    type ControlHandle = DeviceControlHandle;
1861
1862    fn control_handle(&self) -> &DeviceControlHandle {
1863        &self.control_handle
1864    }
1865
1866    fn drop_without_shutdown(mut self) {
1867        // Safety: drops once, never accessed again due to mem::forget
1868        unsafe { std::mem::ManuallyDrop::drop(&mut self.control_handle) };
1869        // Prevent Drop from running (which would shut down the channel)
1870        std::mem::forget(self);
1871    }
1872}
1873
1874impl DeviceGetPropertiesResponder {
1875    /// Sends a response to the FIDL transaction.
1876    ///
1877    /// Sets the channel to shutdown if an error occurs.
1878    pub fn send(self, mut payload: &DeviceGetPropertiesResponse) -> Result<(), fidl::Error> {
1879        let _result = self.send_raw(payload);
1880        if _result.is_err() {
1881            self.control_handle.shutdown();
1882        }
1883        self.drop_without_shutdown();
1884        _result
1885    }
1886
1887    /// Similar to "send" but does not shutdown the channel if an error occurs.
1888    pub fn send_no_shutdown_on_err(
1889        self,
1890        mut payload: &DeviceGetPropertiesResponse,
1891    ) -> Result<(), fidl::Error> {
1892        let _result = self.send_raw(payload);
1893        self.drop_without_shutdown();
1894        _result
1895    }
1896
1897    fn send_raw(&self, mut payload: &DeviceGetPropertiesResponse) -> Result<(), fidl::Error> {
1898        self.control_handle.inner.send::<fidl::encoding::FlexibleType<DeviceGetPropertiesResponse>>(
1899            fidl::encoding::Flexible::new(payload),
1900            self.tx_id,
1901            0x1e946ec04006ffbb,
1902            fidl::encoding::DynamicFlags::FLEXIBLE,
1903        )
1904    }
1905}
1906
1907#[must_use = "FIDL methods require a response to be sent"]
1908#[derive(Debug)]
1909pub struct DeviceWatchControllerWriteCommandsResponder {
1910    control_handle: std::mem::ManuallyDrop<DeviceControlHandle>,
1911    tx_id: u32,
1912}
1913
1914/// Set the the channel to be shutdown (see [`DeviceControlHandle::shutdown`])
1915/// if the responder is dropped without sending a response, so that the client
1916/// doesn't hang. To prevent this behavior, call `drop_without_shutdown`.
1917impl std::ops::Drop for DeviceWatchControllerWriteCommandsResponder {
1918    fn drop(&mut self) {
1919        self.control_handle.shutdown();
1920        // Safety: drops once, never accessed again
1921        unsafe { std::mem::ManuallyDrop::drop(&mut self.control_handle) };
1922    }
1923}
1924
1925impl fidl::endpoints::Responder for DeviceWatchControllerWriteCommandsResponder {
1926    type ControlHandle = DeviceControlHandle;
1927
1928    fn control_handle(&self) -> &DeviceControlHandle {
1929        &self.control_handle
1930    }
1931
1932    fn drop_without_shutdown(mut self) {
1933        // Safety: drops once, never accessed again due to mem::forget
1934        unsafe { std::mem::ManuallyDrop::drop(&mut self.control_handle) };
1935        // Prevent Drop from running (which would shut down the channel)
1936        std::mem::forget(self);
1937    }
1938}
1939
1940impl DeviceWatchControllerWriteCommandsResponder {
1941    /// Sends a response to the FIDL transaction.
1942    ///
1943    /// Sets the channel to shutdown if an error occurs.
1944    pub fn send(
1945        self,
1946        mut result: Result<(&[Register8], Option<fidl::EventPair>), DriverError>,
1947    ) -> Result<(), fidl::Error> {
1948        let _result = self.send_raw(result);
1949        if _result.is_err() {
1950            self.control_handle.shutdown();
1951        }
1952        self.drop_without_shutdown();
1953        _result
1954    }
1955
1956    /// Similar to "send" but does not shutdown the channel if an error occurs.
1957    pub fn send_no_shutdown_on_err(
1958        self,
1959        mut result: Result<(&[Register8], Option<fidl::EventPair>), DriverError>,
1960    ) -> Result<(), fidl::Error> {
1961        let _result = self.send_raw(result);
1962        self.drop_without_shutdown();
1963        _result
1964    }
1965
1966    fn send_raw(
1967        &self,
1968        mut result: Result<(&[Register8], Option<fidl::EventPair>), DriverError>,
1969    ) -> Result<(), fidl::Error> {
1970        self.control_handle.inner.send::<fidl::encoding::FlexibleResultType<
1971            DeviceWatchControllerWriteCommandsResponse,
1972            DriverError,
1973        >>(
1974            fidl::encoding::FlexibleResult::new(result),
1975            self.tx_id,
1976            0x41674c1eba4d05ac,
1977            fidl::encoding::DynamicFlags::FLEXIBLE,
1978        )
1979    }
1980}
1981
1982#[must_use = "FIDL methods require a response to be sent"]
1983#[derive(Debug)]
1984pub struct DeviceCancelWatchControllerWriteCommandsResponder {
1985    control_handle: std::mem::ManuallyDrop<DeviceControlHandle>,
1986    tx_id: u32,
1987}
1988
1989/// Set the the channel to be shutdown (see [`DeviceControlHandle::shutdown`])
1990/// if the responder is dropped without sending a response, so that the client
1991/// doesn't hang. To prevent this behavior, call `drop_without_shutdown`.
1992impl std::ops::Drop for DeviceCancelWatchControllerWriteCommandsResponder {
1993    fn drop(&mut self) {
1994        self.control_handle.shutdown();
1995        // Safety: drops once, never accessed again
1996        unsafe { std::mem::ManuallyDrop::drop(&mut self.control_handle) };
1997    }
1998}
1999
2000impl fidl::endpoints::Responder for DeviceCancelWatchControllerWriteCommandsResponder {
2001    type ControlHandle = DeviceControlHandle;
2002
2003    fn control_handle(&self) -> &DeviceControlHandle {
2004        &self.control_handle
2005    }
2006
2007    fn drop_without_shutdown(mut self) {
2008        // Safety: drops once, never accessed again due to mem::forget
2009        unsafe { std::mem::ManuallyDrop::drop(&mut self.control_handle) };
2010        // Prevent Drop from running (which would shut down the channel)
2011        std::mem::forget(self);
2012    }
2013}
2014
2015impl DeviceCancelWatchControllerWriteCommandsResponder {
2016    /// Sends a response to the FIDL transaction.
2017    ///
2018    /// Sets the channel to shutdown if an error occurs.
2019    pub fn send(self, mut result: Result<(), DriverError>) -> Result<(), fidl::Error> {
2020        let _result = self.send_raw(result);
2021        if _result.is_err() {
2022            self.control_handle.shutdown();
2023        }
2024        self.drop_without_shutdown();
2025        _result
2026    }
2027
2028    /// Similar to "send" but does not shutdown the channel if an error occurs.
2029    pub fn send_no_shutdown_on_err(
2030        self,
2031        mut result: Result<(), DriverError>,
2032    ) -> Result<(), fidl::Error> {
2033        let _result = self.send_raw(result);
2034        self.drop_without_shutdown();
2035        _result
2036    }
2037
2038    fn send_raw(&self, mut result: Result<(), DriverError>) -> Result<(), fidl::Error> {
2039        self.control_handle.inner.send::<fidl::encoding::FlexibleResultType<
2040            fidl::encoding::EmptyStruct,
2041            DriverError,
2042        >>(
2043            fidl::encoding::FlexibleResult::new(result),
2044            self.tx_id,
2045            0x5057c280e6f0d420,
2046            fidl::encoding::DynamicFlags::FLEXIBLE,
2047        )
2048    }
2049}
2050
2051#[derive(Debug, Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Hash)]
2052pub struct DebugServiceMarker;
2053
2054#[cfg(target_os = "fuchsia")]
2055impl fidl::endpoints::ServiceMarker for DebugServiceMarker {
2056    type Proxy = DebugServiceProxy;
2057    type Request = DebugServiceRequest;
2058    const SERVICE_NAME: &'static str = "fuchsia.hardware.spmi.DebugService";
2059}
2060
2061/// A request for one of the member protocols of DebugService.
2062///
2063/// This service can be used by command-line utilities and tests to connect to any target device on
2064/// the SPMI bus. It is not exposed to drivers.
2065#[cfg(target_os = "fuchsia")]
2066pub enum DebugServiceRequest {
2067    Device(DebugRequestStream),
2068}
2069
2070#[cfg(target_os = "fuchsia")]
2071impl fidl::endpoints::ServiceRequest for DebugServiceRequest {
2072    type Service = DebugServiceMarker;
2073
2074    fn dispatch(name: &str, _channel: fidl::AsyncChannel) -> Self {
2075        match name {
2076            "device" => Self::Device(
2077                <DebugRequestStream as fidl::endpoints::RequestStream>::from_channel(_channel),
2078            ),
2079            _ => panic!("no such member protocol name for service DebugService"),
2080        }
2081    }
2082
2083    fn member_names() -> &'static [&'static str] {
2084        &["device"]
2085    }
2086}
2087/// This service can be used by command-line utilities and tests to connect to any target device on
2088/// the SPMI bus. It is not exposed to drivers.
2089#[cfg(target_os = "fuchsia")]
2090pub struct DebugServiceProxy(#[allow(dead_code)] Box<dyn fidl::endpoints::MemberOpener>);
2091
2092#[cfg(target_os = "fuchsia")]
2093impl fidl::endpoints::ServiceProxy for DebugServiceProxy {
2094    type Service = DebugServiceMarker;
2095
2096    fn from_member_opener(opener: Box<dyn fidl::endpoints::MemberOpener>) -> Self {
2097        Self(opener)
2098    }
2099}
2100
2101#[cfg(target_os = "fuchsia")]
2102impl DebugServiceProxy {
2103    pub fn connect_to_device(&self) -> Result<DebugProxy, fidl::Error> {
2104        let (proxy, server_end) = fidl::endpoints::create_proxy::<DebugMarker>();
2105        self.connect_channel_to_device(server_end)?;
2106        Ok(proxy)
2107    }
2108
2109    /// Like `connect_to_device`, but returns a sync proxy.
2110    /// See [`Self::connect_to_device`] for more details.
2111    pub fn connect_to_device_sync(&self) -> Result<DebugSynchronousProxy, fidl::Error> {
2112        let (proxy, server_end) = fidl::endpoints::create_sync_proxy::<DebugMarker>();
2113        self.connect_channel_to_device(server_end)?;
2114        Ok(proxy)
2115    }
2116
2117    /// Like `connect_to_device`, but accepts a server end.
2118    /// See [`Self::connect_to_device`] for more details.
2119    pub fn connect_channel_to_device(
2120        &self,
2121        server_end: fidl::endpoints::ServerEnd<DebugMarker>,
2122    ) -> Result<(), fidl::Error> {
2123        self.0.open_member("device", server_end.into_channel())
2124    }
2125
2126    pub fn instance_name(&self) -> &str {
2127        self.0.instance_name()
2128    }
2129}
2130
2131#[derive(Debug, Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Hash)]
2132pub struct SubTargetServiceMarker;
2133
2134#[cfg(target_os = "fuchsia")]
2135impl fidl::endpoints::ServiceMarker for SubTargetServiceMarker {
2136    type Proxy = SubTargetServiceProxy;
2137    type Request = SubTargetServiceRequest;
2138    const SERVICE_NAME: &'static str = "fuchsia.hardware.spmi.SubTargetService";
2139}
2140
2141/// A request for one of the member protocols of SubTargetService.
2142///
2143/// This service represents a sub-target device within an SPMI target. Clients have access to a
2144/// subset of the SPMI register range as determined by the controller driver.
2145#[cfg(target_os = "fuchsia")]
2146pub enum SubTargetServiceRequest {
2147    Device(DeviceRequestStream),
2148}
2149
2150#[cfg(target_os = "fuchsia")]
2151impl fidl::endpoints::ServiceRequest for SubTargetServiceRequest {
2152    type Service = SubTargetServiceMarker;
2153
2154    fn dispatch(name: &str, _channel: fidl::AsyncChannel) -> Self {
2155        match name {
2156            "device" => Self::Device(
2157                <DeviceRequestStream as fidl::endpoints::RequestStream>::from_channel(_channel),
2158            ),
2159            _ => panic!("no such member protocol name for service SubTargetService"),
2160        }
2161    }
2162
2163    fn member_names() -> &'static [&'static str] {
2164        &["device"]
2165    }
2166}
2167/// This service represents a sub-target device within an SPMI target. Clients have access to a
2168/// subset of the SPMI register range as determined by the controller driver.
2169#[cfg(target_os = "fuchsia")]
2170pub struct SubTargetServiceProxy(#[allow(dead_code)] Box<dyn fidl::endpoints::MemberOpener>);
2171
2172#[cfg(target_os = "fuchsia")]
2173impl fidl::endpoints::ServiceProxy for SubTargetServiceProxy {
2174    type Service = SubTargetServiceMarker;
2175
2176    fn from_member_opener(opener: Box<dyn fidl::endpoints::MemberOpener>) -> Self {
2177        Self(opener)
2178    }
2179}
2180
2181#[cfg(target_os = "fuchsia")]
2182impl SubTargetServiceProxy {
2183    pub fn connect_to_device(&self) -> Result<DeviceProxy, fidl::Error> {
2184        let (proxy, server_end) = fidl::endpoints::create_proxy::<DeviceMarker>();
2185        self.connect_channel_to_device(server_end)?;
2186        Ok(proxy)
2187    }
2188
2189    /// Like `connect_to_device`, but returns a sync proxy.
2190    /// See [`Self::connect_to_device`] for more details.
2191    pub fn connect_to_device_sync(&self) -> Result<DeviceSynchronousProxy, fidl::Error> {
2192        let (proxy, server_end) = fidl::endpoints::create_sync_proxy::<DeviceMarker>();
2193        self.connect_channel_to_device(server_end)?;
2194        Ok(proxy)
2195    }
2196
2197    /// Like `connect_to_device`, but accepts a server end.
2198    /// See [`Self::connect_to_device`] for more details.
2199    pub fn connect_channel_to_device(
2200        &self,
2201        server_end: fidl::endpoints::ServerEnd<DeviceMarker>,
2202    ) -> Result<(), fidl::Error> {
2203        self.0.open_member("device", server_end.into_channel())
2204    }
2205
2206    pub fn instance_name(&self) -> &str {
2207        self.0.instance_name()
2208    }
2209}
2210
2211#[derive(Debug, Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Hash)]
2212pub struct TargetServiceMarker;
2213
2214#[cfg(target_os = "fuchsia")]
2215impl fidl::endpoints::ServiceMarker for TargetServiceMarker {
2216    type Proxy = TargetServiceProxy;
2217    type Request = TargetServiceRequest;
2218    const SERVICE_NAME: &'static str = "fuchsia.hardware.spmi.TargetService";
2219}
2220
2221/// A request for one of the member protocols of TargetService.
2222///
2223/// This service represents an SPMI target device. Clients have access to the entire SPMI register
2224/// range.
2225#[cfg(target_os = "fuchsia")]
2226pub enum TargetServiceRequest {
2227    Device(DeviceRequestStream),
2228}
2229
2230#[cfg(target_os = "fuchsia")]
2231impl fidl::endpoints::ServiceRequest for TargetServiceRequest {
2232    type Service = TargetServiceMarker;
2233
2234    fn dispatch(name: &str, _channel: fidl::AsyncChannel) -> Self {
2235        match name {
2236            "device" => Self::Device(
2237                <DeviceRequestStream as fidl::endpoints::RequestStream>::from_channel(_channel),
2238            ),
2239            _ => panic!("no such member protocol name for service TargetService"),
2240        }
2241    }
2242
2243    fn member_names() -> &'static [&'static str] {
2244        &["device"]
2245    }
2246}
2247/// This service represents an SPMI target device. Clients have access to the entire SPMI register
2248/// range.
2249#[cfg(target_os = "fuchsia")]
2250pub struct TargetServiceProxy(#[allow(dead_code)] Box<dyn fidl::endpoints::MemberOpener>);
2251
2252#[cfg(target_os = "fuchsia")]
2253impl fidl::endpoints::ServiceProxy for TargetServiceProxy {
2254    type Service = TargetServiceMarker;
2255
2256    fn from_member_opener(opener: Box<dyn fidl::endpoints::MemberOpener>) -> Self {
2257        Self(opener)
2258    }
2259}
2260
2261#[cfg(target_os = "fuchsia")]
2262impl TargetServiceProxy {
2263    pub fn connect_to_device(&self) -> Result<DeviceProxy, fidl::Error> {
2264        let (proxy, server_end) = fidl::endpoints::create_proxy::<DeviceMarker>();
2265        self.connect_channel_to_device(server_end)?;
2266        Ok(proxy)
2267    }
2268
2269    /// Like `connect_to_device`, but returns a sync proxy.
2270    /// See [`Self::connect_to_device`] for more details.
2271    pub fn connect_to_device_sync(&self) -> Result<DeviceSynchronousProxy, fidl::Error> {
2272        let (proxy, server_end) = fidl::endpoints::create_sync_proxy::<DeviceMarker>();
2273        self.connect_channel_to_device(server_end)?;
2274        Ok(proxy)
2275    }
2276
2277    /// Like `connect_to_device`, but accepts a server end.
2278    /// See [`Self::connect_to_device`] for more details.
2279    pub fn connect_channel_to_device(
2280        &self,
2281        server_end: fidl::endpoints::ServerEnd<DeviceMarker>,
2282    ) -> Result<(), fidl::Error> {
2283        self.0.open_member("device", server_end.into_channel())
2284    }
2285
2286    pub fn instance_name(&self) -> &str {
2287        self.0.instance_name()
2288    }
2289}
2290
2291mod internal {
2292    use super::*;
2293
2294    impl fidl::encoding::ResourceTypeMarker for DebugConnectTargetRequest {
2295        type Borrowed<'a> = &'a mut Self;
2296        fn take_or_borrow<'a>(
2297            value: &'a mut <Self as fidl::encoding::TypeMarker>::Owned,
2298        ) -> Self::Borrowed<'a> {
2299            value
2300        }
2301    }
2302
2303    unsafe impl fidl::encoding::TypeMarker for DebugConnectTargetRequest {
2304        type Owned = Self;
2305
2306        #[inline(always)]
2307        fn inline_align(_context: fidl::encoding::Context) -> usize {
2308            4
2309        }
2310
2311        #[inline(always)]
2312        fn inline_size(_context: fidl::encoding::Context) -> usize {
2313            8
2314        }
2315    }
2316
2317    unsafe impl
2318        fidl::encoding::Encode<
2319            DebugConnectTargetRequest,
2320            fidl::encoding::DefaultFuchsiaResourceDialect,
2321        > for &mut DebugConnectTargetRequest
2322    {
2323        #[inline]
2324        unsafe fn encode(
2325            self,
2326            encoder: &mut fidl::encoding::Encoder<
2327                '_,
2328                fidl::encoding::DefaultFuchsiaResourceDialect,
2329            >,
2330            offset: usize,
2331            _depth: fidl::encoding::Depth,
2332        ) -> fidl::Result<()> {
2333            encoder.debug_check_bounds::<DebugConnectTargetRequest>(offset);
2334            // Delegate to tuple encoding.
2335            fidl::encoding::Encode::<DebugConnectTargetRequest, fidl::encoding::DefaultFuchsiaResourceDialect>::encode(
2336                (
2337                    <u8 as fidl::encoding::ValueTypeMarker>::borrow(&self.target_id),
2338                    <fidl::encoding::Endpoint<fidl::endpoints::ServerEnd<DeviceMarker>> as fidl::encoding::ResourceTypeMarker>::take_or_borrow(&mut self.server),
2339                ),
2340                encoder, offset, _depth
2341            )
2342        }
2343    }
2344    unsafe impl<
2345        T0: fidl::encoding::Encode<u8, fidl::encoding::DefaultFuchsiaResourceDialect>,
2346        T1: fidl::encoding::Encode<
2347                fidl::encoding::Endpoint<fidl::endpoints::ServerEnd<DeviceMarker>>,
2348                fidl::encoding::DefaultFuchsiaResourceDialect,
2349            >,
2350    >
2351        fidl::encoding::Encode<
2352            DebugConnectTargetRequest,
2353            fidl::encoding::DefaultFuchsiaResourceDialect,
2354        > for (T0, T1)
2355    {
2356        #[inline]
2357        unsafe fn encode(
2358            self,
2359            encoder: &mut fidl::encoding::Encoder<
2360                '_,
2361                fidl::encoding::DefaultFuchsiaResourceDialect,
2362            >,
2363            offset: usize,
2364            depth: fidl::encoding::Depth,
2365        ) -> fidl::Result<()> {
2366            encoder.debug_check_bounds::<DebugConnectTargetRequest>(offset);
2367            // Zero out padding regions. There's no need to apply masks
2368            // because the unmasked parts will be overwritten by fields.
2369            unsafe {
2370                let ptr = encoder.buf.as_mut_ptr().add(offset).offset(0);
2371                (ptr as *mut u32).write_unaligned(0);
2372            }
2373            // Write the fields.
2374            self.0.encode(encoder, offset + 0, depth)?;
2375            self.1.encode(encoder, offset + 4, depth)?;
2376            Ok(())
2377        }
2378    }
2379
2380    impl fidl::encoding::Decode<Self, fidl::encoding::DefaultFuchsiaResourceDialect>
2381        for DebugConnectTargetRequest
2382    {
2383        #[inline(always)]
2384        fn new_empty() -> Self {
2385            Self {
2386                target_id: fidl::new_empty!(u8, fidl::encoding::DefaultFuchsiaResourceDialect),
2387                server: fidl::new_empty!(
2388                    fidl::encoding::Endpoint<fidl::endpoints::ServerEnd<DeviceMarker>>,
2389                    fidl::encoding::DefaultFuchsiaResourceDialect
2390                ),
2391            }
2392        }
2393
2394        #[inline]
2395        unsafe fn decode(
2396            &mut self,
2397            decoder: &mut fidl::encoding::Decoder<
2398                '_,
2399                fidl::encoding::DefaultFuchsiaResourceDialect,
2400            >,
2401            offset: usize,
2402            _depth: fidl::encoding::Depth,
2403        ) -> fidl::Result<()> {
2404            decoder.debug_check_bounds::<Self>(offset);
2405            // Verify that padding bytes are zero.
2406            let ptr = unsafe { decoder.buf.as_ptr().add(offset).offset(0) };
2407            let padval = unsafe { (ptr as *const u32).read_unaligned() };
2408            let mask = 0xffffff00u32;
2409            let maskedval = padval & mask;
2410            if maskedval != 0 {
2411                return Err(fidl::Error::NonZeroPadding {
2412                    padding_start: offset + 0 + ((mask as u64).trailing_zeros() / 8) as usize,
2413                });
2414            }
2415            fidl::decode!(
2416                u8,
2417                fidl::encoding::DefaultFuchsiaResourceDialect,
2418                &mut self.target_id,
2419                decoder,
2420                offset + 0,
2421                _depth
2422            )?;
2423            fidl::decode!(
2424                fidl::encoding::Endpoint<fidl::endpoints::ServerEnd<DeviceMarker>>,
2425                fidl::encoding::DefaultFuchsiaResourceDialect,
2426                &mut self.server,
2427                decoder,
2428                offset + 4,
2429                _depth
2430            )?;
2431            Ok(())
2432        }
2433    }
2434
2435    impl fidl::encoding::ResourceTypeMarker for DeviceWatchControllerWriteCommandsRequest {
2436        type Borrowed<'a> = &'a mut Self;
2437        fn take_or_borrow<'a>(
2438            value: &'a mut <Self as fidl::encoding::TypeMarker>::Owned,
2439        ) -> Self::Borrowed<'a> {
2440            value
2441        }
2442    }
2443
2444    unsafe impl fidl::encoding::TypeMarker for DeviceWatchControllerWriteCommandsRequest {
2445        type Owned = Self;
2446
2447        #[inline(always)]
2448        fn inline_align(_context: fidl::encoding::Context) -> usize {
2449            4
2450        }
2451
2452        #[inline(always)]
2453        fn inline_size(_context: fidl::encoding::Context) -> usize {
2454            8
2455        }
2456    }
2457
2458    unsafe impl
2459        fidl::encoding::Encode<
2460            DeviceWatchControllerWriteCommandsRequest,
2461            fidl::encoding::DefaultFuchsiaResourceDialect,
2462        > for &mut DeviceWatchControllerWriteCommandsRequest
2463    {
2464        #[inline]
2465        unsafe fn encode(
2466            self,
2467            encoder: &mut fidl::encoding::Encoder<
2468                '_,
2469                fidl::encoding::DefaultFuchsiaResourceDialect,
2470            >,
2471            offset: usize,
2472            _depth: fidl::encoding::Depth,
2473        ) -> fidl::Result<()> {
2474            encoder.debug_check_bounds::<DeviceWatchControllerWriteCommandsRequest>(offset);
2475            // Delegate to tuple encoding.
2476            fidl::encoding::Encode::<
2477                DeviceWatchControllerWriteCommandsRequest,
2478                fidl::encoding::DefaultFuchsiaResourceDialect,
2479            >::encode(
2480                (
2481                    <u8 as fidl::encoding::ValueTypeMarker>::borrow(&self.address),
2482                    <u16 as fidl::encoding::ValueTypeMarker>::borrow(&self.size),
2483                    <fidl::encoding::Optional<
2484                        fidl::encoding::HandleType<
2485                            fidl::EventPair,
2486                            { fidl::ObjectType::EVENTPAIR.into_raw() },
2487                            16387,
2488                        >,
2489                    > as fidl::encoding::ResourceTypeMarker>::take_or_borrow(
2490                        &mut self.setup_wake_lease,
2491                    ),
2492                ),
2493                encoder,
2494                offset,
2495                _depth,
2496            )
2497        }
2498    }
2499    unsafe impl<
2500        T0: fidl::encoding::Encode<u8, fidl::encoding::DefaultFuchsiaResourceDialect>,
2501        T1: fidl::encoding::Encode<u16, fidl::encoding::DefaultFuchsiaResourceDialect>,
2502        T2: fidl::encoding::Encode<
2503                fidl::encoding::Optional<
2504                    fidl::encoding::HandleType<
2505                        fidl::EventPair,
2506                        { fidl::ObjectType::EVENTPAIR.into_raw() },
2507                        16387,
2508                    >,
2509                >,
2510                fidl::encoding::DefaultFuchsiaResourceDialect,
2511            >,
2512    >
2513        fidl::encoding::Encode<
2514            DeviceWatchControllerWriteCommandsRequest,
2515            fidl::encoding::DefaultFuchsiaResourceDialect,
2516        > for (T0, T1, T2)
2517    {
2518        #[inline]
2519        unsafe fn encode(
2520            self,
2521            encoder: &mut fidl::encoding::Encoder<
2522                '_,
2523                fidl::encoding::DefaultFuchsiaResourceDialect,
2524            >,
2525            offset: usize,
2526            depth: fidl::encoding::Depth,
2527        ) -> fidl::Result<()> {
2528            encoder.debug_check_bounds::<DeviceWatchControllerWriteCommandsRequest>(offset);
2529            // Zero out padding regions. There's no need to apply masks
2530            // because the unmasked parts will be overwritten by fields.
2531            unsafe {
2532                let ptr = encoder.buf.as_mut_ptr().add(offset).offset(0);
2533                (ptr as *mut u32).write_unaligned(0);
2534            }
2535            // Write the fields.
2536            self.0.encode(encoder, offset + 0, depth)?;
2537            self.1.encode(encoder, offset + 2, depth)?;
2538            self.2.encode(encoder, offset + 4, depth)?;
2539            Ok(())
2540        }
2541    }
2542
2543    impl fidl::encoding::Decode<Self, fidl::encoding::DefaultFuchsiaResourceDialect>
2544        for DeviceWatchControllerWriteCommandsRequest
2545    {
2546        #[inline(always)]
2547        fn new_empty() -> Self {
2548            Self {
2549                address: fidl::new_empty!(u8, fidl::encoding::DefaultFuchsiaResourceDialect),
2550                size: fidl::new_empty!(u16, fidl::encoding::DefaultFuchsiaResourceDialect),
2551                setup_wake_lease: fidl::new_empty!(
2552                    fidl::encoding::Optional<
2553                        fidl::encoding::HandleType<
2554                            fidl::EventPair,
2555                            { fidl::ObjectType::EVENTPAIR.into_raw() },
2556                            16387,
2557                        >,
2558                    >,
2559                    fidl::encoding::DefaultFuchsiaResourceDialect
2560                ),
2561            }
2562        }
2563
2564        #[inline]
2565        unsafe fn decode(
2566            &mut self,
2567            decoder: &mut fidl::encoding::Decoder<
2568                '_,
2569                fidl::encoding::DefaultFuchsiaResourceDialect,
2570            >,
2571            offset: usize,
2572            _depth: fidl::encoding::Depth,
2573        ) -> fidl::Result<()> {
2574            decoder.debug_check_bounds::<Self>(offset);
2575            // Verify that padding bytes are zero.
2576            let ptr = unsafe { decoder.buf.as_ptr().add(offset).offset(0) };
2577            let padval = unsafe { (ptr as *const u32).read_unaligned() };
2578            let mask = 0xff00u32;
2579            let maskedval = padval & mask;
2580            if maskedval != 0 {
2581                return Err(fidl::Error::NonZeroPadding {
2582                    padding_start: offset + 0 + ((mask as u64).trailing_zeros() / 8) as usize,
2583                });
2584            }
2585            fidl::decode!(
2586                u8,
2587                fidl::encoding::DefaultFuchsiaResourceDialect,
2588                &mut self.address,
2589                decoder,
2590                offset + 0,
2591                _depth
2592            )?;
2593            fidl::decode!(
2594                u16,
2595                fidl::encoding::DefaultFuchsiaResourceDialect,
2596                &mut self.size,
2597                decoder,
2598                offset + 2,
2599                _depth
2600            )?;
2601            fidl::decode!(
2602                fidl::encoding::Optional<
2603                    fidl::encoding::HandleType<
2604                        fidl::EventPair,
2605                        { fidl::ObjectType::EVENTPAIR.into_raw() },
2606                        16387,
2607                    >,
2608                >,
2609                fidl::encoding::DefaultFuchsiaResourceDialect,
2610                &mut self.setup_wake_lease,
2611                decoder,
2612                offset + 4,
2613                _depth
2614            )?;
2615            Ok(())
2616        }
2617    }
2618
2619    impl fidl::encoding::ResourceTypeMarker for DeviceWatchControllerWriteCommandsResponse {
2620        type Borrowed<'a> = &'a mut Self;
2621        fn take_or_borrow<'a>(
2622            value: &'a mut <Self as fidl::encoding::TypeMarker>::Owned,
2623        ) -> Self::Borrowed<'a> {
2624            value
2625        }
2626    }
2627
2628    unsafe impl fidl::encoding::TypeMarker for DeviceWatchControllerWriteCommandsResponse {
2629        type Owned = Self;
2630
2631        #[inline(always)]
2632        fn inline_align(_context: fidl::encoding::Context) -> usize {
2633            8
2634        }
2635
2636        #[inline(always)]
2637        fn inline_size(_context: fidl::encoding::Context) -> usize {
2638            24
2639        }
2640    }
2641
2642    unsafe impl
2643        fidl::encoding::Encode<
2644            DeviceWatchControllerWriteCommandsResponse,
2645            fidl::encoding::DefaultFuchsiaResourceDialect,
2646        > for &mut DeviceWatchControllerWriteCommandsResponse
2647    {
2648        #[inline]
2649        unsafe fn encode(
2650            self,
2651            encoder: &mut fidl::encoding::Encoder<
2652                '_,
2653                fidl::encoding::DefaultFuchsiaResourceDialect,
2654            >,
2655            offset: usize,
2656            _depth: fidl::encoding::Depth,
2657        ) -> fidl::Result<()> {
2658            encoder.debug_check_bounds::<DeviceWatchControllerWriteCommandsResponse>(offset);
2659            // Delegate to tuple encoding.
2660            fidl::encoding::Encode::<DeviceWatchControllerWriteCommandsResponse, fidl::encoding::DefaultFuchsiaResourceDialect>::encode(
2661                (
2662                    <fidl::encoding::Vector<Register8, 256> as fidl::encoding::ValueTypeMarker>::borrow(&self.writes),
2663                    <fidl::encoding::Optional<fidl::encoding::HandleType<fidl::EventPair, { fidl::ObjectType::EVENTPAIR.into_raw() }, 16387>> as fidl::encoding::ResourceTypeMarker>::take_or_borrow(&mut self.wake_lease),
2664                ),
2665                encoder, offset, _depth
2666            )
2667        }
2668    }
2669    unsafe impl<
2670        T0: fidl::encoding::Encode<
2671                fidl::encoding::Vector<Register8, 256>,
2672                fidl::encoding::DefaultFuchsiaResourceDialect,
2673            >,
2674        T1: fidl::encoding::Encode<
2675                fidl::encoding::Optional<
2676                    fidl::encoding::HandleType<
2677                        fidl::EventPair,
2678                        { fidl::ObjectType::EVENTPAIR.into_raw() },
2679                        16387,
2680                    >,
2681                >,
2682                fidl::encoding::DefaultFuchsiaResourceDialect,
2683            >,
2684    >
2685        fidl::encoding::Encode<
2686            DeviceWatchControllerWriteCommandsResponse,
2687            fidl::encoding::DefaultFuchsiaResourceDialect,
2688        > for (T0, T1)
2689    {
2690        #[inline]
2691        unsafe fn encode(
2692            self,
2693            encoder: &mut fidl::encoding::Encoder<
2694                '_,
2695                fidl::encoding::DefaultFuchsiaResourceDialect,
2696            >,
2697            offset: usize,
2698            depth: fidl::encoding::Depth,
2699        ) -> fidl::Result<()> {
2700            encoder.debug_check_bounds::<DeviceWatchControllerWriteCommandsResponse>(offset);
2701            // Zero out padding regions. There's no need to apply masks
2702            // because the unmasked parts will be overwritten by fields.
2703            unsafe {
2704                let ptr = encoder.buf.as_mut_ptr().add(offset).offset(16);
2705                (ptr as *mut u64).write_unaligned(0);
2706            }
2707            // Write the fields.
2708            self.0.encode(encoder, offset + 0, depth)?;
2709            self.1.encode(encoder, offset + 16, depth)?;
2710            Ok(())
2711        }
2712    }
2713
2714    impl fidl::encoding::Decode<Self, fidl::encoding::DefaultFuchsiaResourceDialect>
2715        for DeviceWatchControllerWriteCommandsResponse
2716    {
2717        #[inline(always)]
2718        fn new_empty() -> Self {
2719            Self {
2720                writes: fidl::new_empty!(fidl::encoding::Vector<Register8, 256>, fidl::encoding::DefaultFuchsiaResourceDialect),
2721                wake_lease: fidl::new_empty!(
2722                    fidl::encoding::Optional<
2723                        fidl::encoding::HandleType<
2724                            fidl::EventPair,
2725                            { fidl::ObjectType::EVENTPAIR.into_raw() },
2726                            16387,
2727                        >,
2728                    >,
2729                    fidl::encoding::DefaultFuchsiaResourceDialect
2730                ),
2731            }
2732        }
2733
2734        #[inline]
2735        unsafe fn decode(
2736            &mut self,
2737            decoder: &mut fidl::encoding::Decoder<
2738                '_,
2739                fidl::encoding::DefaultFuchsiaResourceDialect,
2740            >,
2741            offset: usize,
2742            _depth: fidl::encoding::Depth,
2743        ) -> fidl::Result<()> {
2744            decoder.debug_check_bounds::<Self>(offset);
2745            // Verify that padding bytes are zero.
2746            let ptr = unsafe { decoder.buf.as_ptr().add(offset).offset(16) };
2747            let padval = unsafe { (ptr as *const u64).read_unaligned() };
2748            let mask = 0xffffffff00000000u64;
2749            let maskedval = padval & mask;
2750            if maskedval != 0 {
2751                return Err(fidl::Error::NonZeroPadding {
2752                    padding_start: offset + 16 + ((mask as u64).trailing_zeros() / 8) as usize,
2753                });
2754            }
2755            fidl::decode!(fidl::encoding::Vector<Register8, 256>, fidl::encoding::DefaultFuchsiaResourceDialect, &mut self.writes, decoder, offset + 0, _depth)?;
2756            fidl::decode!(
2757                fidl::encoding::Optional<
2758                    fidl::encoding::HandleType<
2759                        fidl::EventPair,
2760                        { fidl::ObjectType::EVENTPAIR.into_raw() },
2761                        16387,
2762                    >,
2763                >,
2764                fidl::encoding::DefaultFuchsiaResourceDialect,
2765                &mut self.wake_lease,
2766                decoder,
2767                offset + 16,
2768                _depth
2769            )?;
2770            Ok(())
2771        }
2772    }
2773}