Skip to main content

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