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