Skip to main content

fidl_fuchsia_hardware_power_battery/
fidl_fuchsia_hardware_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_hardware_power_battery_common::*;
11use futures::future::{self, MaybeDone, TryFutureExt};
12use zx_status;
13
14#[derive(Debug, PartialEq)]
15pub struct BatteryWatchRequest {
16    pub interest: Status,
17    pub wake_on: Status,
18    pub lease: Option<fidl::EventPair>,
19}
20
21impl fidl::Standalone<fidl::encoding::DefaultFuchsiaResourceDialect> for BatteryWatchRequest {}
22
23#[derive(Debug, PartialEq)]
24pub struct BatteryWatchResponse {
25    pub status: Status,
26    pub wake_lease: Option<fidl::EventPair>,
27}
28
29impl fidl::Standalone<fidl::encoding::DefaultFuchsiaResourceDialect> for BatteryWatchResponse {}
30
31#[derive(Debug, Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Hash)]
32pub struct BatteryMarker;
33
34impl fidl::endpoints::ProtocolMarker for BatteryMarker {
35    type Proxy = BatteryProxy;
36    type RequestStream = BatteryRequestStream;
37    #[cfg(target_os = "fuchsia")]
38    type SynchronousProxy = BatterySynchronousProxy;
39
40    const DEBUG_NAME: &'static str = "fuchsia.hardware.power.battery.Battery";
41}
42impl fidl::endpoints::DiscoverableProtocolMarker for BatteryMarker {}
43pub type BatteryGetSpecResult = Result<Spec, fidl_fuchsia_hardware_power_source::Error>;
44pub type BatteryGetStatusResult = Result<Status, fidl_fuchsia_hardware_power_source::Error>;
45
46pub trait BatteryProxyInterface: Send + Sync {
47    type GetSpecResponseFut: std::future::Future<Output = Result<BatteryGetSpecResult, fidl::Error>>
48        + Send;
49    fn r#get_spec(&self) -> Self::GetSpecResponseFut;
50    type GetStatusResponseFut: std::future::Future<Output = Result<BatteryGetStatusResult, fidl::Error>>
51        + Send;
52    fn r#get_status(&self) -> Self::GetStatusResponseFut;
53    type WatchResponseFut: std::future::Future<Output = Result<(Status, Option<fidl::EventPair>), fidl::Error>>
54        + Send;
55    fn r#watch(
56        &self,
57        interest: &Status,
58        wake_on: &Status,
59        lease: Option<fidl::EventPair>,
60    ) -> Self::WatchResponseFut;
61}
62#[derive(Debug)]
63#[cfg(target_os = "fuchsia")]
64pub struct BatterySynchronousProxy {
65    client: fidl::client::sync::Client,
66}
67
68#[cfg(target_os = "fuchsia")]
69impl fidl::endpoints::SynchronousProxy for BatterySynchronousProxy {
70    type Proxy = BatteryProxy;
71    type Protocol = BatteryMarker;
72
73    fn from_channel(inner: fidl::Channel) -> Self {
74        Self::new(inner)
75    }
76
77    fn into_channel(self) -> fidl::Channel {
78        self.client.into_channel()
79    }
80
81    fn as_channel(&self) -> &fidl::Channel {
82        self.client.as_channel()
83    }
84}
85
86#[cfg(target_os = "fuchsia")]
87impl BatterySynchronousProxy {
88    pub fn new(channel: fidl::Channel) -> Self {
89        Self { client: fidl::client::sync::Client::new(channel) }
90    }
91
92    pub fn into_channel(self) -> fidl::Channel {
93        self.client.into_channel()
94    }
95
96    /// Waits until an event arrives and returns it. It is safe for other
97    /// threads to make concurrent requests while waiting for an event.
98    pub fn wait_for_event(
99        &self,
100        deadline: zx::MonotonicInstant,
101    ) -> Result<BatteryEvent, fidl::Error> {
102        BatteryEvent::decode(self.client.wait_for_event::<BatteryMarker>(deadline)?)
103    }
104
105    /// Returns the spec immediately.
106    pub fn r#get_spec(
107        &self,
108        ___deadline: zx::MonotonicInstant,
109    ) -> Result<BatteryGetSpecResult, fidl::Error> {
110        let _response = self
111            .client
112            .send_query::<fidl::encoding::EmptyPayload, fidl::encoding::FlexibleResultType<
113                BatteryGetSpecResponse,
114                fidl_fuchsia_hardware_power_source::Error,
115            >, BatteryMarker>(
116                (),
117                0x235609229653654f,
118                fidl::encoding::DynamicFlags::FLEXIBLE,
119                ___deadline,
120            )?
121            .into_result::<BatteryMarker>("get_spec")?;
122        Ok(_response.map(|x| x.spec))
123    }
124
125    /// Returns the status immediately.
126    pub fn r#get_status(
127        &self,
128        ___deadline: zx::MonotonicInstant,
129    ) -> Result<BatteryGetStatusResult, fidl::Error> {
130        let _response = self
131            .client
132            .send_query::<fidl::encoding::EmptyPayload, fidl::encoding::FlexibleResultType<
133                BatteryGetStatusResponse,
134                fidl_fuchsia_hardware_power_source::Error,
135            >, BatteryMarker>(
136                (),
137                0x2e0c03524d47095a,
138                fidl::encoding::DynamicFlags::FLEXIBLE,
139                ___deadline,
140            )?
141            .into_result::<BatteryMarker>("get_status")?;
142        Ok(_response.map(|x| x.status))
143    }
144
145    /// Hanging get for status updates.
146    /// See [`fuchsia.hardware.power.source/Source.Watch`] for semantics.
147    pub fn r#watch(
148        &self,
149        mut interest: &Status,
150        mut wake_on: &Status,
151        mut lease: Option<fidl::EventPair>,
152        ___deadline: zx::MonotonicInstant,
153    ) -> Result<(Status, Option<fidl::EventPair>), fidl::Error> {
154        let _response = self.client.send_query::<
155            BatteryWatchRequest,
156            fidl::encoding::FlexibleType<BatteryWatchResponse>,
157            BatteryMarker,
158        >(
159            (interest, wake_on, lease,),
160            0x7386830cdd9e3390,
161            fidl::encoding::DynamicFlags::FLEXIBLE,
162            ___deadline,
163        )?
164        .into_result::<BatteryMarker>("watch")?;
165        Ok((_response.status, _response.wake_lease))
166    }
167}
168
169#[cfg(target_os = "fuchsia")]
170impl From<BatterySynchronousProxy> for zx::NullableHandle {
171    fn from(value: BatterySynchronousProxy) -> Self {
172        value.into_channel().into()
173    }
174}
175
176#[cfg(target_os = "fuchsia")]
177impl From<fidl::Channel> for BatterySynchronousProxy {
178    fn from(value: fidl::Channel) -> Self {
179        Self::new(value)
180    }
181}
182
183#[cfg(target_os = "fuchsia")]
184impl fidl::endpoints::FromClient for BatterySynchronousProxy {
185    type Protocol = BatteryMarker;
186
187    fn from_client(value: fidl::endpoints::ClientEnd<BatteryMarker>) -> Self {
188        Self::new(value.into_channel())
189    }
190}
191
192#[derive(Debug, Clone)]
193pub struct BatteryProxy {
194    client: fidl::client::Client<fidl::encoding::DefaultFuchsiaResourceDialect>,
195}
196
197impl fidl::endpoints::Proxy for BatteryProxy {
198    type Protocol = BatteryMarker;
199
200    fn from_channel(inner: ::fidl::AsyncChannel) -> Self {
201        Self::new(inner)
202    }
203
204    fn into_channel(self) -> Result<::fidl::AsyncChannel, Self> {
205        self.client.into_channel().map_err(|client| Self { client })
206    }
207
208    fn as_channel(&self) -> &::fidl::AsyncChannel {
209        self.client.as_channel()
210    }
211}
212
213impl BatteryProxy {
214    /// Create a new Proxy for fuchsia.hardware.power.battery/Battery.
215    pub fn new(channel: ::fidl::AsyncChannel) -> Self {
216        let protocol_name = <BatteryMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME;
217        Self { client: fidl::client::Client::new(channel, protocol_name) }
218    }
219
220    /// Get a Stream of events from the remote end of the protocol.
221    ///
222    /// # Panics
223    ///
224    /// Panics if the event stream was already taken.
225    pub fn take_event_stream(&self) -> BatteryEventStream {
226        BatteryEventStream { event_receiver: self.client.take_event_receiver() }
227    }
228
229    /// Returns the spec immediately.
230    pub fn r#get_spec(
231        &self,
232    ) -> fidl::client::QueryResponseFut<
233        BatteryGetSpecResult,
234        fidl::encoding::DefaultFuchsiaResourceDialect,
235    > {
236        BatteryProxyInterface::r#get_spec(self)
237    }
238
239    /// Returns the status immediately.
240    pub fn r#get_status(
241        &self,
242    ) -> fidl::client::QueryResponseFut<
243        BatteryGetStatusResult,
244        fidl::encoding::DefaultFuchsiaResourceDialect,
245    > {
246        BatteryProxyInterface::r#get_status(self)
247    }
248
249    /// Hanging get for status updates.
250    /// See [`fuchsia.hardware.power.source/Source.Watch`] for semantics.
251    pub fn r#watch(
252        &self,
253        mut interest: &Status,
254        mut wake_on: &Status,
255        mut lease: Option<fidl::EventPair>,
256    ) -> fidl::client::QueryResponseFut<
257        (Status, Option<fidl::EventPair>),
258        fidl::encoding::DefaultFuchsiaResourceDialect,
259    > {
260        BatteryProxyInterface::r#watch(self, interest, wake_on, lease)
261    }
262}
263
264impl BatteryProxyInterface for BatteryProxy {
265    type GetSpecResponseFut = fidl::client::QueryResponseFut<
266        BatteryGetSpecResult,
267        fidl::encoding::DefaultFuchsiaResourceDialect,
268    >;
269    fn r#get_spec(&self) -> Self::GetSpecResponseFut {
270        fn _decode(
271            mut _buf: Result<<fidl::encoding::DefaultFuchsiaResourceDialect as fidl::encoding::ResourceDialect>::MessageBufEtc, fidl::Error>,
272        ) -> Result<BatteryGetSpecResult, fidl::Error> {
273            let _response = fidl::client::decode_transaction_body::<
274                fidl::encoding::FlexibleResultType<
275                    BatteryGetSpecResponse,
276                    fidl_fuchsia_hardware_power_source::Error,
277                >,
278                fidl::encoding::DefaultFuchsiaResourceDialect,
279                0x235609229653654f,
280            >(_buf?)?
281            .into_result::<BatteryMarker>("get_spec")?;
282            Ok(_response.map(|x| x.spec))
283        }
284        self.client.send_query_and_decode::<fidl::encoding::EmptyPayload, BatteryGetSpecResult>(
285            (),
286            0x235609229653654f,
287            fidl::encoding::DynamicFlags::FLEXIBLE,
288            _decode,
289        )
290    }
291
292    type GetStatusResponseFut = fidl::client::QueryResponseFut<
293        BatteryGetStatusResult,
294        fidl::encoding::DefaultFuchsiaResourceDialect,
295    >;
296    fn r#get_status(&self) -> Self::GetStatusResponseFut {
297        fn _decode(
298            mut _buf: Result<<fidl::encoding::DefaultFuchsiaResourceDialect as fidl::encoding::ResourceDialect>::MessageBufEtc, fidl::Error>,
299        ) -> Result<BatteryGetStatusResult, fidl::Error> {
300            let _response = fidl::client::decode_transaction_body::<
301                fidl::encoding::FlexibleResultType<
302                    BatteryGetStatusResponse,
303                    fidl_fuchsia_hardware_power_source::Error,
304                >,
305                fidl::encoding::DefaultFuchsiaResourceDialect,
306                0x2e0c03524d47095a,
307            >(_buf?)?
308            .into_result::<BatteryMarker>("get_status")?;
309            Ok(_response.map(|x| x.status))
310        }
311        self.client.send_query_and_decode::<fidl::encoding::EmptyPayload, BatteryGetStatusResult>(
312            (),
313            0x2e0c03524d47095a,
314            fidl::encoding::DynamicFlags::FLEXIBLE,
315            _decode,
316        )
317    }
318
319    type WatchResponseFut = fidl::client::QueryResponseFut<
320        (Status, Option<fidl::EventPair>),
321        fidl::encoding::DefaultFuchsiaResourceDialect,
322    >;
323    fn r#watch(
324        &self,
325        mut interest: &Status,
326        mut wake_on: &Status,
327        mut lease: Option<fidl::EventPair>,
328    ) -> Self::WatchResponseFut {
329        fn _decode(
330            mut _buf: Result<<fidl::encoding::DefaultFuchsiaResourceDialect as fidl::encoding::ResourceDialect>::MessageBufEtc, fidl::Error>,
331        ) -> Result<(Status, Option<fidl::EventPair>), fidl::Error> {
332            let _response = fidl::client::decode_transaction_body::<
333                fidl::encoding::FlexibleType<BatteryWatchResponse>,
334                fidl::encoding::DefaultFuchsiaResourceDialect,
335                0x7386830cdd9e3390,
336            >(_buf?)?
337            .into_result::<BatteryMarker>("watch")?;
338            Ok((_response.status, _response.wake_lease))
339        }
340        self.client.send_query_and_decode::<BatteryWatchRequest, (Status, Option<fidl::EventPair>)>(
341            (interest, wake_on, lease),
342            0x7386830cdd9e3390,
343            fidl::encoding::DynamicFlags::FLEXIBLE,
344            _decode,
345        )
346    }
347}
348
349pub struct BatteryEventStream {
350    event_receiver: fidl::client::EventReceiver<fidl::encoding::DefaultFuchsiaResourceDialect>,
351}
352
353impl std::marker::Unpin for BatteryEventStream {}
354
355impl futures::stream::FusedStream for BatteryEventStream {
356    fn is_terminated(&self) -> bool {
357        self.event_receiver.is_terminated()
358    }
359}
360
361impl futures::Stream for BatteryEventStream {
362    type Item = Result<BatteryEvent, fidl::Error>;
363
364    fn poll_next(
365        mut self: std::pin::Pin<&mut Self>,
366        cx: &mut std::task::Context<'_>,
367    ) -> std::task::Poll<Option<Self::Item>> {
368        match futures::ready!(futures::stream::StreamExt::poll_next_unpin(
369            &mut self.event_receiver,
370            cx
371        )?) {
372            Some(buf) => std::task::Poll::Ready(Some(BatteryEvent::decode(buf))),
373            None => std::task::Poll::Ready(None),
374        }
375    }
376}
377
378#[derive(Debug)]
379pub enum BatteryEvent {
380    #[non_exhaustive]
381    _UnknownEvent {
382        /// Ordinal of the event that was sent.
383        ordinal: u64,
384    },
385}
386
387impl BatteryEvent {
388    /// Decodes a message buffer as a [`BatteryEvent`].
389    fn decode(
390        mut buf: <fidl::encoding::DefaultFuchsiaResourceDialect as fidl::encoding::ResourceDialect>::MessageBufEtc,
391    ) -> Result<BatteryEvent, fidl::Error> {
392        let (bytes, _handles) = buf.split_mut();
393        let (tx_header, _body_bytes) = fidl::encoding::decode_transaction_header(bytes)?;
394        debug_assert_eq!(tx_header.tx_id, 0);
395        match tx_header.ordinal {
396            _ if tx_header.dynamic_flags().contains(fidl::encoding::DynamicFlags::FLEXIBLE) => {
397                Ok(BatteryEvent::_UnknownEvent { ordinal: tx_header.ordinal })
398            }
399            _ => Err(fidl::Error::UnknownOrdinal {
400                ordinal: tx_header.ordinal,
401                protocol_name: <BatteryMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME,
402            }),
403        }
404    }
405}
406
407/// A Stream of incoming requests for fuchsia.hardware.power.battery/Battery.
408pub struct BatteryRequestStream {
409    inner: std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>,
410    is_terminated: bool,
411}
412
413impl std::marker::Unpin for BatteryRequestStream {}
414
415impl futures::stream::FusedStream for BatteryRequestStream {
416    fn is_terminated(&self) -> bool {
417        self.is_terminated
418    }
419}
420
421impl fidl::endpoints::RequestStream for BatteryRequestStream {
422    type Protocol = BatteryMarker;
423    type ControlHandle = BatteryControlHandle;
424
425    fn from_channel(channel: ::fidl::AsyncChannel) -> Self {
426        Self { inner: std::sync::Arc::new(fidl::ServeInner::new(channel)), is_terminated: false }
427    }
428
429    fn control_handle(&self) -> Self::ControlHandle {
430        BatteryControlHandle { inner: self.inner.clone() }
431    }
432
433    fn into_inner(
434        self,
435    ) -> (::std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>, bool)
436    {
437        (self.inner, self.is_terminated)
438    }
439
440    fn from_inner(
441        inner: std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>,
442        is_terminated: bool,
443    ) -> Self {
444        Self { inner, is_terminated }
445    }
446}
447
448impl futures::Stream for BatteryRequestStream {
449    type Item = Result<BatteryRequest, fidl::Error>;
450
451    fn poll_next(
452        mut self: std::pin::Pin<&mut Self>,
453        cx: &mut std::task::Context<'_>,
454    ) -> std::task::Poll<Option<Self::Item>> {
455        let this = &mut *self;
456        if this.inner.check_shutdown(cx) {
457            this.is_terminated = true;
458            return std::task::Poll::Ready(None);
459        }
460        if this.is_terminated {
461            panic!("polled BatteryRequestStream after completion");
462        }
463        fidl::encoding::with_tls_decode_buf::<_, fidl::encoding::DefaultFuchsiaResourceDialect>(
464            |bytes, handles| {
465                match this.inner.channel().read_etc(cx, bytes, handles) {
466                    std::task::Poll::Ready(Ok(())) => {}
467                    std::task::Poll::Pending => return std::task::Poll::Pending,
468                    std::task::Poll::Ready(Err(zx_status::Status::PEER_CLOSED)) => {
469                        this.is_terminated = true;
470                        return std::task::Poll::Ready(None);
471                    }
472                    std::task::Poll::Ready(Err(e)) => {
473                        return std::task::Poll::Ready(Some(Err(fidl::Error::ServerRequestRead(
474                            e.into(),
475                        ))));
476                    }
477                }
478
479                // A message has been received from the channel
480                let (header, _body_bytes) = fidl::encoding::decode_transaction_header(bytes)?;
481
482                std::task::Poll::Ready(Some(match header.ordinal {
483                    0x235609229653654f => {
484                        header.validate_request_tx_id(fidl::MethodType::TwoWay)?;
485                        let mut req = fidl::new_empty!(
486                            fidl::encoding::EmptyPayload,
487                            fidl::encoding::DefaultFuchsiaResourceDialect
488                        );
489                        fidl::encoding::Decoder::<fidl::encoding::DefaultFuchsiaResourceDialect>::decode_into::<fidl::encoding::EmptyPayload>(&header, _body_bytes, handles, &mut req)?;
490                        let control_handle = BatteryControlHandle { inner: this.inner.clone() };
491                        Ok(BatteryRequest::GetSpec {
492                            responder: BatteryGetSpecResponder {
493                                control_handle: std::mem::ManuallyDrop::new(control_handle),
494                                tx_id: header.tx_id,
495                            },
496                        })
497                    }
498                    0x2e0c03524d47095a => {
499                        header.validate_request_tx_id(fidl::MethodType::TwoWay)?;
500                        let mut req = fidl::new_empty!(
501                            fidl::encoding::EmptyPayload,
502                            fidl::encoding::DefaultFuchsiaResourceDialect
503                        );
504                        fidl::encoding::Decoder::<fidl::encoding::DefaultFuchsiaResourceDialect>::decode_into::<fidl::encoding::EmptyPayload>(&header, _body_bytes, handles, &mut req)?;
505                        let control_handle = BatteryControlHandle { inner: this.inner.clone() };
506                        Ok(BatteryRequest::GetStatus {
507                            responder: BatteryGetStatusResponder {
508                                control_handle: std::mem::ManuallyDrop::new(control_handle),
509                                tx_id: header.tx_id,
510                            },
511                        })
512                    }
513                    0x7386830cdd9e3390 => {
514                        header.validate_request_tx_id(fidl::MethodType::TwoWay)?;
515                        let mut req = fidl::new_empty!(
516                            BatteryWatchRequest,
517                            fidl::encoding::DefaultFuchsiaResourceDialect
518                        );
519                        fidl::encoding::Decoder::<fidl::encoding::DefaultFuchsiaResourceDialect>::decode_into::<BatteryWatchRequest>(&header, _body_bytes, handles, &mut req)?;
520                        let control_handle = BatteryControlHandle { inner: this.inner.clone() };
521                        Ok(BatteryRequest::Watch {
522                            interest: req.interest,
523                            wake_on: req.wake_on,
524                            lease: req.lease,
525
526                            responder: BatteryWatchResponder {
527                                control_handle: std::mem::ManuallyDrop::new(control_handle),
528                                tx_id: header.tx_id,
529                            },
530                        })
531                    }
532                    _ if header.tx_id == 0
533                        && header
534                            .dynamic_flags()
535                            .contains(fidl::encoding::DynamicFlags::FLEXIBLE) =>
536                    {
537                        Ok(BatteryRequest::_UnknownMethod {
538                            ordinal: header.ordinal,
539                            control_handle: BatteryControlHandle { inner: this.inner.clone() },
540                            method_type: fidl::MethodType::OneWay,
541                        })
542                    }
543                    _ if header
544                        .dynamic_flags()
545                        .contains(fidl::encoding::DynamicFlags::FLEXIBLE) =>
546                    {
547                        this.inner.send_framework_err(
548                            fidl::encoding::FrameworkErr::UnknownMethod,
549                            header.tx_id,
550                            header.ordinal,
551                            header.dynamic_flags(),
552                            (bytes, handles),
553                        )?;
554                        Ok(BatteryRequest::_UnknownMethod {
555                            ordinal: header.ordinal,
556                            control_handle: BatteryControlHandle { inner: this.inner.clone() },
557                            method_type: fidl::MethodType::TwoWay,
558                        })
559                    }
560                    _ => Err(fidl::Error::UnknownOrdinal {
561                        ordinal: header.ordinal,
562                        protocol_name:
563                            <BatteryMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME,
564                    }),
565                }))
566            },
567        )
568    }
569}
570
571/// Protocol representing the Battery (acting as the Fuel Gauge).
572///
573/// This protocol focuses on reading the chemical telemetry of the cell pack.
574/// Charging operations are managed separately via [`fuchsia.hardware.power.charger/Charger`].
575#[derive(Debug)]
576pub enum BatteryRequest {
577    /// Returns the spec immediately.
578    GetSpec { responder: BatteryGetSpecResponder },
579    /// Returns the status immediately.
580    GetStatus { responder: BatteryGetStatusResponder },
581    /// Hanging get for status updates.
582    /// See [`fuchsia.hardware.power.source/Source.Watch`] for semantics.
583    Watch {
584        interest: Status,
585        wake_on: Status,
586        lease: Option<fidl::EventPair>,
587        responder: BatteryWatchResponder,
588    },
589    /// An interaction was received which does not match any known method.
590    #[non_exhaustive]
591    _UnknownMethod {
592        /// Ordinal of the method that was called.
593        ordinal: u64,
594        control_handle: BatteryControlHandle,
595        method_type: fidl::MethodType,
596    },
597}
598
599impl BatteryRequest {
600    #[allow(irrefutable_let_patterns)]
601    pub fn into_get_spec(self) -> Option<(BatteryGetSpecResponder)> {
602        if let BatteryRequest::GetSpec { responder } = self { Some((responder)) } else { None }
603    }
604
605    #[allow(irrefutable_let_patterns)]
606    pub fn into_get_status(self) -> Option<(BatteryGetStatusResponder)> {
607        if let BatteryRequest::GetStatus { responder } = self { Some((responder)) } else { None }
608    }
609
610    #[allow(irrefutable_let_patterns)]
611    pub fn into_watch(
612        self,
613    ) -> Option<(Status, Status, Option<fidl::EventPair>, BatteryWatchResponder)> {
614        if let BatteryRequest::Watch { interest, wake_on, lease, responder } = self {
615            Some((interest, wake_on, lease, responder))
616        } else {
617            None
618        }
619    }
620
621    /// Name of the method defined in FIDL
622    pub fn method_name(&self) -> &'static str {
623        match *self {
624            BatteryRequest::GetSpec { .. } => "get_spec",
625            BatteryRequest::GetStatus { .. } => "get_status",
626            BatteryRequest::Watch { .. } => "watch",
627            BatteryRequest::_UnknownMethod { method_type: fidl::MethodType::OneWay, .. } => {
628                "unknown one-way method"
629            }
630            BatteryRequest::_UnknownMethod { method_type: fidl::MethodType::TwoWay, .. } => {
631                "unknown two-way method"
632            }
633        }
634    }
635}
636
637#[derive(Debug, Clone)]
638pub struct BatteryControlHandle {
639    inner: std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>,
640}
641
642impl fidl::endpoints::ControlHandle for BatteryControlHandle {
643    fn shutdown(&self) {
644        self.inner.shutdown()
645    }
646
647    fn shutdown_with_epitaph(&self, status: zx_status::Status) {
648        self.inner.shutdown_with_epitaph(status)
649    }
650
651    fn is_closed(&self) -> bool {
652        self.inner.channel().is_closed()
653    }
654    fn on_closed(&self) -> fidl::OnSignalsRef<'_> {
655        self.inner.channel().on_closed()
656    }
657
658    #[cfg(target_os = "fuchsia")]
659    fn signal_peer(
660        &self,
661        clear_mask: zx::Signals,
662        set_mask: zx::Signals,
663    ) -> Result<(), zx_status::Status> {
664        use fidl::Peered;
665        self.inner.channel().signal_peer(clear_mask, set_mask)
666    }
667}
668
669impl BatteryControlHandle {}
670
671#[must_use = "FIDL methods require a response to be sent"]
672#[derive(Debug)]
673pub struct BatteryGetSpecResponder {
674    control_handle: std::mem::ManuallyDrop<BatteryControlHandle>,
675    tx_id: u32,
676}
677
678/// Set the the channel to be shutdown (see [`BatteryControlHandle::shutdown`])
679/// if the responder is dropped without sending a response, so that the client
680/// doesn't hang. To prevent this behavior, call `drop_without_shutdown`.
681impl std::ops::Drop for BatteryGetSpecResponder {
682    fn drop(&mut self) {
683        self.control_handle.shutdown();
684        // Safety: drops once, never accessed again
685        unsafe { std::mem::ManuallyDrop::drop(&mut self.control_handle) };
686    }
687}
688
689impl fidl::endpoints::Responder for BatteryGetSpecResponder {
690    type ControlHandle = BatteryControlHandle;
691
692    fn control_handle(&self) -> &BatteryControlHandle {
693        &self.control_handle
694    }
695
696    fn drop_without_shutdown(mut self) {
697        // Safety: drops once, never accessed again due to mem::forget
698        unsafe { std::mem::ManuallyDrop::drop(&mut self.control_handle) };
699        // Prevent Drop from running (which would shut down the channel)
700        std::mem::forget(self);
701    }
702}
703
704impl BatteryGetSpecResponder {
705    /// Sends a response to the FIDL transaction.
706    ///
707    /// Sets the channel to shutdown if an error occurs.
708    pub fn send(
709        self,
710        mut result: Result<&Spec, fidl_fuchsia_hardware_power_source::Error>,
711    ) -> Result<(), fidl::Error> {
712        let _result = self.send_raw(result);
713        if _result.is_err() {
714            self.control_handle.shutdown();
715        }
716        self.drop_without_shutdown();
717        _result
718    }
719
720    /// Similar to "send" but does not shutdown the channel if an error occurs.
721    pub fn send_no_shutdown_on_err(
722        self,
723        mut result: Result<&Spec, fidl_fuchsia_hardware_power_source::Error>,
724    ) -> Result<(), fidl::Error> {
725        let _result = self.send_raw(result);
726        self.drop_without_shutdown();
727        _result
728    }
729
730    fn send_raw(
731        &self,
732        mut result: Result<&Spec, fidl_fuchsia_hardware_power_source::Error>,
733    ) -> Result<(), fidl::Error> {
734        self.control_handle.inner.send::<fidl::encoding::FlexibleResultType<
735            BatteryGetSpecResponse,
736            fidl_fuchsia_hardware_power_source::Error,
737        >>(
738            fidl::encoding::FlexibleResult::new(result.map(|spec| (spec,))),
739            self.tx_id,
740            0x235609229653654f,
741            fidl::encoding::DynamicFlags::FLEXIBLE,
742        )
743    }
744}
745
746#[must_use = "FIDL methods require a response to be sent"]
747#[derive(Debug)]
748pub struct BatteryGetStatusResponder {
749    control_handle: std::mem::ManuallyDrop<BatteryControlHandle>,
750    tx_id: u32,
751}
752
753/// Set the the channel to be shutdown (see [`BatteryControlHandle::shutdown`])
754/// if the responder is dropped without sending a response, so that the client
755/// doesn't hang. To prevent this behavior, call `drop_without_shutdown`.
756impl std::ops::Drop for BatteryGetStatusResponder {
757    fn drop(&mut self) {
758        self.control_handle.shutdown();
759        // Safety: drops once, never accessed again
760        unsafe { std::mem::ManuallyDrop::drop(&mut self.control_handle) };
761    }
762}
763
764impl fidl::endpoints::Responder for BatteryGetStatusResponder {
765    type ControlHandle = BatteryControlHandle;
766
767    fn control_handle(&self) -> &BatteryControlHandle {
768        &self.control_handle
769    }
770
771    fn drop_without_shutdown(mut self) {
772        // Safety: drops once, never accessed again due to mem::forget
773        unsafe { std::mem::ManuallyDrop::drop(&mut self.control_handle) };
774        // Prevent Drop from running (which would shut down the channel)
775        std::mem::forget(self);
776    }
777}
778
779impl BatteryGetStatusResponder {
780    /// Sends a response to the FIDL transaction.
781    ///
782    /// Sets the channel to shutdown if an error occurs.
783    pub fn send(
784        self,
785        mut result: Result<&Status, fidl_fuchsia_hardware_power_source::Error>,
786    ) -> Result<(), fidl::Error> {
787        let _result = self.send_raw(result);
788        if _result.is_err() {
789            self.control_handle.shutdown();
790        }
791        self.drop_without_shutdown();
792        _result
793    }
794
795    /// Similar to "send" but does not shutdown the channel if an error occurs.
796    pub fn send_no_shutdown_on_err(
797        self,
798        mut result: Result<&Status, fidl_fuchsia_hardware_power_source::Error>,
799    ) -> Result<(), fidl::Error> {
800        let _result = self.send_raw(result);
801        self.drop_without_shutdown();
802        _result
803    }
804
805    fn send_raw(
806        &self,
807        mut result: Result<&Status, fidl_fuchsia_hardware_power_source::Error>,
808    ) -> Result<(), fidl::Error> {
809        self.control_handle.inner.send::<fidl::encoding::FlexibleResultType<
810            BatteryGetStatusResponse,
811            fidl_fuchsia_hardware_power_source::Error,
812        >>(
813            fidl::encoding::FlexibleResult::new(result.map(|status| (status,))),
814            self.tx_id,
815            0x2e0c03524d47095a,
816            fidl::encoding::DynamicFlags::FLEXIBLE,
817        )
818    }
819}
820
821#[must_use = "FIDL methods require a response to be sent"]
822#[derive(Debug)]
823pub struct BatteryWatchResponder {
824    control_handle: std::mem::ManuallyDrop<BatteryControlHandle>,
825    tx_id: u32,
826}
827
828/// Set the the channel to be shutdown (see [`BatteryControlHandle::shutdown`])
829/// if the responder is dropped without sending a response, so that the client
830/// doesn't hang. To prevent this behavior, call `drop_without_shutdown`.
831impl std::ops::Drop for BatteryWatchResponder {
832    fn drop(&mut self) {
833        self.control_handle.shutdown();
834        // Safety: drops once, never accessed again
835        unsafe { std::mem::ManuallyDrop::drop(&mut self.control_handle) };
836    }
837}
838
839impl fidl::endpoints::Responder for BatteryWatchResponder {
840    type ControlHandle = BatteryControlHandle;
841
842    fn control_handle(&self) -> &BatteryControlHandle {
843        &self.control_handle
844    }
845
846    fn drop_without_shutdown(mut self) {
847        // Safety: drops once, never accessed again due to mem::forget
848        unsafe { std::mem::ManuallyDrop::drop(&mut self.control_handle) };
849        // Prevent Drop from running (which would shut down the channel)
850        std::mem::forget(self);
851    }
852}
853
854impl BatteryWatchResponder {
855    /// Sends a response to the FIDL transaction.
856    ///
857    /// Sets the channel to shutdown if an error occurs.
858    pub fn send(
859        self,
860        mut status: &Status,
861        mut wake_lease: Option<fidl::EventPair>,
862    ) -> Result<(), fidl::Error> {
863        let _result = self.send_raw(status, wake_lease);
864        if _result.is_err() {
865            self.control_handle.shutdown();
866        }
867        self.drop_without_shutdown();
868        _result
869    }
870
871    /// Similar to "send" but does not shutdown the channel if an error occurs.
872    pub fn send_no_shutdown_on_err(
873        self,
874        mut status: &Status,
875        mut wake_lease: Option<fidl::EventPair>,
876    ) -> Result<(), fidl::Error> {
877        let _result = self.send_raw(status, wake_lease);
878        self.drop_without_shutdown();
879        _result
880    }
881
882    fn send_raw(
883        &self,
884        mut status: &Status,
885        mut wake_lease: Option<fidl::EventPair>,
886    ) -> Result<(), fidl::Error> {
887        self.control_handle.inner.send::<fidl::encoding::FlexibleType<BatteryWatchResponse>>(
888            fidl::encoding::Flexible::new((status, wake_lease)),
889            self.tx_id,
890            0x7386830cdd9e3390,
891            fidl::encoding::DynamicFlags::FLEXIBLE,
892        )
893    }
894}
895
896#[derive(Debug, Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Hash)]
897pub struct ServiceMarker;
898
899#[cfg(target_os = "fuchsia")]
900impl fidl::endpoints::ServiceMarker for ServiceMarker {
901    type Proxy = ServiceProxy;
902    type Request = ServiceRequest;
903    const SERVICE_NAME: &'static str = "fuchsia.hardware.power.battery.Service";
904}
905
906/// A request for one of the member protocols of Service.
907///
908#[cfg(target_os = "fuchsia")]
909pub enum ServiceRequest {
910    Battery(BatteryRequestStream),
911    PowerSource(fidl_fuchsia_hardware_power_source::SourceRequestStream),
912}
913
914#[cfg(target_os = "fuchsia")]
915impl fidl::endpoints::ServiceRequest for ServiceRequest {
916    type Service = ServiceMarker;
917
918    fn dispatch(name: &str, _channel: fidl::AsyncChannel) -> Self {
919        match name {
920            "battery" => Self::Battery(
921                <BatteryRequestStream as fidl::endpoints::RequestStream>::from_channel(_channel),
922            ),
923            "power_source" => Self::PowerSource(
924                <fidl_fuchsia_hardware_power_source::SourceRequestStream as fidl::endpoints::RequestStream>::from_channel(_channel),
925            ),
926            _ => panic!("no such member protocol name for service Service"),
927        }
928    }
929
930    fn member_names() -> &'static [&'static str] {
931        &["battery", "power_source"]
932    }
933}
934#[cfg(target_os = "fuchsia")]
935pub struct ServiceProxy(#[allow(dead_code)] Box<dyn fidl::endpoints::MemberOpener>);
936
937#[cfg(target_os = "fuchsia")]
938impl fidl::endpoints::ServiceProxy for ServiceProxy {
939    type Service = ServiceMarker;
940
941    fn from_member_opener(opener: Box<dyn fidl::endpoints::MemberOpener>) -> Self {
942        Self(opener)
943    }
944}
945
946#[cfg(target_os = "fuchsia")]
947impl ServiceProxy {
948    pub fn connect_to_battery(&self) -> Result<BatteryProxy, fidl::Error> {
949        let (proxy, server_end) = fidl::endpoints::create_proxy::<BatteryMarker>();
950        self.connect_channel_to_battery(server_end)?;
951        Ok(proxy)
952    }
953
954    /// Like `connect_to_battery`, but returns a sync proxy.
955    /// See [`Self::connect_to_battery`] for more details.
956    pub fn connect_to_battery_sync(&self) -> Result<BatterySynchronousProxy, fidl::Error> {
957        let (proxy, server_end) = fidl::endpoints::create_sync_proxy::<BatteryMarker>();
958        self.connect_channel_to_battery(server_end)?;
959        Ok(proxy)
960    }
961
962    /// Like `connect_to_battery`, but accepts a server end.
963    /// See [`Self::connect_to_battery`] for more details.
964    pub fn connect_channel_to_battery(
965        &self,
966        server_end: fidl::endpoints::ServerEnd<BatteryMarker>,
967    ) -> Result<(), fidl::Error> {
968        self.0.open_member("battery", server_end.into_channel())
969    }
970    pub fn connect_to_power_source(
971        &self,
972    ) -> Result<fidl_fuchsia_hardware_power_source::SourceProxy, fidl::Error> {
973        let (proxy, server_end) =
974            fidl::endpoints::create_proxy::<fidl_fuchsia_hardware_power_source::SourceMarker>();
975        self.connect_channel_to_power_source(server_end)?;
976        Ok(proxy)
977    }
978
979    /// Like `connect_to_power_source`, but returns a sync proxy.
980    /// See [`Self::connect_to_power_source`] for more details.
981    pub fn connect_to_power_source_sync(
982        &self,
983    ) -> Result<fidl_fuchsia_hardware_power_source::SourceSynchronousProxy, fidl::Error> {
984        let (proxy, server_end) = fidl::endpoints::create_sync_proxy::<
985            fidl_fuchsia_hardware_power_source::SourceMarker,
986        >();
987        self.connect_channel_to_power_source(server_end)?;
988        Ok(proxy)
989    }
990
991    /// Like `connect_to_power_source`, but accepts a server end.
992    /// See [`Self::connect_to_power_source`] for more details.
993    pub fn connect_channel_to_power_source(
994        &self,
995        server_end: fidl::endpoints::ServerEnd<fidl_fuchsia_hardware_power_source::SourceMarker>,
996    ) -> Result<(), fidl::Error> {
997        self.0.open_member("power_source", server_end.into_channel())
998    }
999
1000    pub fn instance_name(&self) -> &str {
1001        self.0.instance_name()
1002    }
1003}
1004
1005mod internal {
1006    use super::*;
1007
1008    impl fidl::encoding::ResourceTypeMarker for BatteryWatchRequest {
1009        type Borrowed<'a> = &'a mut Self;
1010        fn take_or_borrow<'a>(
1011            value: &'a mut <Self as fidl::encoding::TypeMarker>::Owned,
1012        ) -> Self::Borrowed<'a> {
1013            value
1014        }
1015    }
1016
1017    unsafe impl fidl::encoding::TypeMarker for BatteryWatchRequest {
1018        type Owned = Self;
1019
1020        #[inline(always)]
1021        fn inline_align(_context: fidl::encoding::Context) -> usize {
1022            8
1023        }
1024
1025        #[inline(always)]
1026        fn inline_size(_context: fidl::encoding::Context) -> usize {
1027            40
1028        }
1029    }
1030
1031    unsafe impl
1032        fidl::encoding::Encode<BatteryWatchRequest, fidl::encoding::DefaultFuchsiaResourceDialect>
1033        for &mut BatteryWatchRequest
1034    {
1035        #[inline]
1036        unsafe fn encode(
1037            self,
1038            encoder: &mut fidl::encoding::Encoder<
1039                '_,
1040                fidl::encoding::DefaultFuchsiaResourceDialect,
1041            >,
1042            offset: usize,
1043            _depth: fidl::encoding::Depth,
1044        ) -> fidl::Result<()> {
1045            encoder.debug_check_bounds::<BatteryWatchRequest>(offset);
1046            // Delegate to tuple encoding.
1047            fidl::encoding::Encode::<
1048                BatteryWatchRequest,
1049                fidl::encoding::DefaultFuchsiaResourceDialect,
1050            >::encode(
1051                (
1052                    <Status as fidl::encoding::ValueTypeMarker>::borrow(&self.interest),
1053                    <Status as fidl::encoding::ValueTypeMarker>::borrow(&self.wake_on),
1054                    <fidl::encoding::Optional<
1055                        fidl::encoding::HandleType<
1056                            fidl::EventPair,
1057                            { fidl::ObjectType::EVENTPAIR.into_raw() },
1058                            16387,
1059                        >,
1060                    > as fidl::encoding::ResourceTypeMarker>::take_or_borrow(
1061                        &mut self.lease
1062                    ),
1063                ),
1064                encoder,
1065                offset,
1066                _depth,
1067            )
1068        }
1069    }
1070    unsafe impl<
1071        T0: fidl::encoding::Encode<Status, fidl::encoding::DefaultFuchsiaResourceDialect>,
1072        T1: fidl::encoding::Encode<Status, fidl::encoding::DefaultFuchsiaResourceDialect>,
1073        T2: fidl::encoding::Encode<
1074                fidl::encoding::Optional<
1075                    fidl::encoding::HandleType<
1076                        fidl::EventPair,
1077                        { fidl::ObjectType::EVENTPAIR.into_raw() },
1078                        16387,
1079                    >,
1080                >,
1081                fidl::encoding::DefaultFuchsiaResourceDialect,
1082            >,
1083    > fidl::encoding::Encode<BatteryWatchRequest, fidl::encoding::DefaultFuchsiaResourceDialect>
1084        for (T0, T1, T2)
1085    {
1086        #[inline]
1087        unsafe fn encode(
1088            self,
1089            encoder: &mut fidl::encoding::Encoder<
1090                '_,
1091                fidl::encoding::DefaultFuchsiaResourceDialect,
1092            >,
1093            offset: usize,
1094            depth: fidl::encoding::Depth,
1095        ) -> fidl::Result<()> {
1096            encoder.debug_check_bounds::<BatteryWatchRequest>(offset);
1097            // Zero out padding regions. There's no need to apply masks
1098            // because the unmasked parts will be overwritten by fields.
1099            unsafe {
1100                let ptr = encoder.buf.as_mut_ptr().add(offset).offset(32);
1101                (ptr as *mut u64).write_unaligned(0);
1102            }
1103            // Write the fields.
1104            self.0.encode(encoder, offset + 0, depth)?;
1105            self.1.encode(encoder, offset + 16, depth)?;
1106            self.2.encode(encoder, offset + 32, depth)?;
1107            Ok(())
1108        }
1109    }
1110
1111    impl fidl::encoding::Decode<Self, fidl::encoding::DefaultFuchsiaResourceDialect>
1112        for BatteryWatchRequest
1113    {
1114        #[inline(always)]
1115        fn new_empty() -> Self {
1116            Self {
1117                interest: fidl::new_empty!(Status, fidl::encoding::DefaultFuchsiaResourceDialect),
1118                wake_on: fidl::new_empty!(Status, fidl::encoding::DefaultFuchsiaResourceDialect),
1119                lease: fidl::new_empty!(
1120                    fidl::encoding::Optional<
1121                        fidl::encoding::HandleType<
1122                            fidl::EventPair,
1123                            { fidl::ObjectType::EVENTPAIR.into_raw() },
1124                            16387,
1125                        >,
1126                    >,
1127                    fidl::encoding::DefaultFuchsiaResourceDialect
1128                ),
1129            }
1130        }
1131
1132        #[inline]
1133        unsafe fn decode(
1134            &mut self,
1135            decoder: &mut fidl::encoding::Decoder<
1136                '_,
1137                fidl::encoding::DefaultFuchsiaResourceDialect,
1138            >,
1139            offset: usize,
1140            _depth: fidl::encoding::Depth,
1141        ) -> fidl::Result<()> {
1142            decoder.debug_check_bounds::<Self>(offset);
1143            // Verify that padding bytes are zero.
1144            let ptr = unsafe { decoder.buf.as_ptr().add(offset).offset(32) };
1145            let padval = unsafe { (ptr as *const u64).read_unaligned() };
1146            let mask = 0xffffffff00000000u64;
1147            let maskedval = padval & mask;
1148            if maskedval != 0 {
1149                return Err(fidl::Error::NonZeroPadding {
1150                    padding_start: offset + 32 + ((mask as u64).trailing_zeros() / 8) as usize,
1151                });
1152            }
1153            fidl::decode!(
1154                Status,
1155                fidl::encoding::DefaultFuchsiaResourceDialect,
1156                &mut self.interest,
1157                decoder,
1158                offset + 0,
1159                _depth
1160            )?;
1161            fidl::decode!(
1162                Status,
1163                fidl::encoding::DefaultFuchsiaResourceDialect,
1164                &mut self.wake_on,
1165                decoder,
1166                offset + 16,
1167                _depth
1168            )?;
1169            fidl::decode!(
1170                fidl::encoding::Optional<
1171                    fidl::encoding::HandleType<
1172                        fidl::EventPair,
1173                        { fidl::ObjectType::EVENTPAIR.into_raw() },
1174                        16387,
1175                    >,
1176                >,
1177                fidl::encoding::DefaultFuchsiaResourceDialect,
1178                &mut self.lease,
1179                decoder,
1180                offset + 32,
1181                _depth
1182            )?;
1183            Ok(())
1184        }
1185    }
1186
1187    impl fidl::encoding::ResourceTypeMarker for BatteryWatchResponse {
1188        type Borrowed<'a> = &'a mut Self;
1189        fn take_or_borrow<'a>(
1190            value: &'a mut <Self as fidl::encoding::TypeMarker>::Owned,
1191        ) -> Self::Borrowed<'a> {
1192            value
1193        }
1194    }
1195
1196    unsafe impl fidl::encoding::TypeMarker for BatteryWatchResponse {
1197        type Owned = Self;
1198
1199        #[inline(always)]
1200        fn inline_align(_context: fidl::encoding::Context) -> usize {
1201            8
1202        }
1203
1204        #[inline(always)]
1205        fn inline_size(_context: fidl::encoding::Context) -> usize {
1206            24
1207        }
1208    }
1209
1210    unsafe impl
1211        fidl::encoding::Encode<BatteryWatchResponse, fidl::encoding::DefaultFuchsiaResourceDialect>
1212        for &mut BatteryWatchResponse
1213    {
1214        #[inline]
1215        unsafe fn encode(
1216            self,
1217            encoder: &mut fidl::encoding::Encoder<
1218                '_,
1219                fidl::encoding::DefaultFuchsiaResourceDialect,
1220            >,
1221            offset: usize,
1222            _depth: fidl::encoding::Depth,
1223        ) -> fidl::Result<()> {
1224            encoder.debug_check_bounds::<BatteryWatchResponse>(offset);
1225            // Delegate to tuple encoding.
1226            fidl::encoding::Encode::<
1227                BatteryWatchResponse,
1228                fidl::encoding::DefaultFuchsiaResourceDialect,
1229            >::encode(
1230                (
1231                    <Status as fidl::encoding::ValueTypeMarker>::borrow(&self.status),
1232                    <fidl::encoding::Optional<
1233                        fidl::encoding::HandleType<
1234                            fidl::EventPair,
1235                            { fidl::ObjectType::EVENTPAIR.into_raw() },
1236                            16387,
1237                        >,
1238                    > as fidl::encoding::ResourceTypeMarker>::take_or_borrow(
1239                        &mut self.wake_lease
1240                    ),
1241                ),
1242                encoder,
1243                offset,
1244                _depth,
1245            )
1246        }
1247    }
1248    unsafe impl<
1249        T0: fidl::encoding::Encode<Status, fidl::encoding::DefaultFuchsiaResourceDialect>,
1250        T1: fidl::encoding::Encode<
1251                fidl::encoding::Optional<
1252                    fidl::encoding::HandleType<
1253                        fidl::EventPair,
1254                        { fidl::ObjectType::EVENTPAIR.into_raw() },
1255                        16387,
1256                    >,
1257                >,
1258                fidl::encoding::DefaultFuchsiaResourceDialect,
1259            >,
1260    >
1261        fidl::encoding::Encode<BatteryWatchResponse, fidl::encoding::DefaultFuchsiaResourceDialect>
1262        for (T0, T1)
1263    {
1264        #[inline]
1265        unsafe fn encode(
1266            self,
1267            encoder: &mut fidl::encoding::Encoder<
1268                '_,
1269                fidl::encoding::DefaultFuchsiaResourceDialect,
1270            >,
1271            offset: usize,
1272            depth: fidl::encoding::Depth,
1273        ) -> fidl::Result<()> {
1274            encoder.debug_check_bounds::<BatteryWatchResponse>(offset);
1275            // Zero out padding regions. There's no need to apply masks
1276            // because the unmasked parts will be overwritten by fields.
1277            unsafe {
1278                let ptr = encoder.buf.as_mut_ptr().add(offset).offset(16);
1279                (ptr as *mut u64).write_unaligned(0);
1280            }
1281            // Write the fields.
1282            self.0.encode(encoder, offset + 0, depth)?;
1283            self.1.encode(encoder, offset + 16, depth)?;
1284            Ok(())
1285        }
1286    }
1287
1288    impl fidl::encoding::Decode<Self, fidl::encoding::DefaultFuchsiaResourceDialect>
1289        for BatteryWatchResponse
1290    {
1291        #[inline(always)]
1292        fn new_empty() -> Self {
1293            Self {
1294                status: fidl::new_empty!(Status, fidl::encoding::DefaultFuchsiaResourceDialect),
1295                wake_lease: fidl::new_empty!(
1296                    fidl::encoding::Optional<
1297                        fidl::encoding::HandleType<
1298                            fidl::EventPair,
1299                            { fidl::ObjectType::EVENTPAIR.into_raw() },
1300                            16387,
1301                        >,
1302                    >,
1303                    fidl::encoding::DefaultFuchsiaResourceDialect
1304                ),
1305            }
1306        }
1307
1308        #[inline]
1309        unsafe fn decode(
1310            &mut self,
1311            decoder: &mut fidl::encoding::Decoder<
1312                '_,
1313                fidl::encoding::DefaultFuchsiaResourceDialect,
1314            >,
1315            offset: usize,
1316            _depth: fidl::encoding::Depth,
1317        ) -> fidl::Result<()> {
1318            decoder.debug_check_bounds::<Self>(offset);
1319            // Verify that padding bytes are zero.
1320            let ptr = unsafe { decoder.buf.as_ptr().add(offset).offset(16) };
1321            let padval = unsafe { (ptr as *const u64).read_unaligned() };
1322            let mask = 0xffffffff00000000u64;
1323            let maskedval = padval & mask;
1324            if maskedval != 0 {
1325                return Err(fidl::Error::NonZeroPadding {
1326                    padding_start: offset + 16 + ((mask as u64).trailing_zeros() / 8) as usize,
1327                });
1328            }
1329            fidl::decode!(
1330                Status,
1331                fidl::encoding::DefaultFuchsiaResourceDialect,
1332                &mut self.status,
1333                decoder,
1334                offset + 0,
1335                _depth
1336            )?;
1337            fidl::decode!(
1338                fidl::encoding::Optional<
1339                    fidl::encoding::HandleType<
1340                        fidl::EventPair,
1341                        { fidl::ObjectType::EVENTPAIR.into_raw() },
1342                        16387,
1343                    >,
1344                >,
1345                fidl::encoding::DefaultFuchsiaResourceDialect,
1346                &mut self.wake_lease,
1347                decoder,
1348                offset + 16,
1349                _depth
1350            )?;
1351            Ok(())
1352        }
1353    }
1354}