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 BatteryControlHandle {
643    pub fn shutdown_with_epitaph(&self, status: impl Into<fidl::Epitaph>) {
644        self.inner.shutdown_with_epitaph(status.into())
645    }
646}
647
648impl fidl::endpoints::ControlHandle for BatteryControlHandle {
649    fn shutdown(&self) {
650        self.inner.shutdown()
651    }
652
653    fn shutdown_with_epitaph(&self, status: fidl::Epitaph) {
654        self.inner.shutdown_with_epitaph(status)
655    }
656
657    fn is_closed(&self) -> bool {
658        self.inner.channel().is_closed()
659    }
660    fn on_closed(&self) -> fidl::OnSignalsRef<'_> {
661        self.inner.channel().on_closed()
662    }
663
664    #[cfg(target_os = "fuchsia")]
665    fn signal_peer(
666        &self,
667        clear_mask: zx::Signals,
668        set_mask: zx::Signals,
669    ) -> Result<(), zx_status::Status> {
670        use fidl::Peered;
671        self.inner.channel().signal_peer(clear_mask, set_mask)
672    }
673}
674
675impl BatteryControlHandle {}
676
677#[must_use = "FIDL methods require a response to be sent"]
678#[derive(Debug)]
679pub struct BatteryGetSpecResponder {
680    control_handle: std::mem::ManuallyDrop<BatteryControlHandle>,
681    tx_id: u32,
682}
683
684/// Set the the channel to be shutdown (see [`BatteryControlHandle::shutdown`])
685/// if the responder is dropped without sending a response, so that the client
686/// doesn't hang. To prevent this behavior, call `drop_without_shutdown`.
687impl std::ops::Drop for BatteryGetSpecResponder {
688    fn drop(&mut self) {
689        self.control_handle.shutdown();
690        // Safety: drops once, never accessed again
691        unsafe { std::mem::ManuallyDrop::drop(&mut self.control_handle) };
692    }
693}
694
695impl fidl::endpoints::Responder for BatteryGetSpecResponder {
696    type ControlHandle = BatteryControlHandle;
697
698    fn control_handle(&self) -> &BatteryControlHandle {
699        &self.control_handle
700    }
701
702    fn drop_without_shutdown(mut self) {
703        // Safety: drops once, never accessed again due to mem::forget
704        unsafe { std::mem::ManuallyDrop::drop(&mut self.control_handle) };
705        // Prevent Drop from running (which would shut down the channel)
706        std::mem::forget(self);
707    }
708}
709
710impl BatteryGetSpecResponder {
711    /// Sends a response to the FIDL transaction.
712    ///
713    /// Sets the channel to shutdown if an error occurs.
714    pub fn send(
715        self,
716        mut result: Result<&Spec, fidl_fuchsia_hardware_power_source::Error>,
717    ) -> Result<(), fidl::Error> {
718        let _result = self.send_raw(result);
719        if _result.is_err() {
720            self.control_handle.shutdown();
721        }
722        self.drop_without_shutdown();
723        _result
724    }
725
726    /// Similar to "send" but does not shutdown the channel if an error occurs.
727    pub fn send_no_shutdown_on_err(
728        self,
729        mut result: Result<&Spec, fidl_fuchsia_hardware_power_source::Error>,
730    ) -> Result<(), fidl::Error> {
731        let _result = self.send_raw(result);
732        self.drop_without_shutdown();
733        _result
734    }
735
736    fn send_raw(
737        &self,
738        mut result: Result<&Spec, fidl_fuchsia_hardware_power_source::Error>,
739    ) -> Result<(), fidl::Error> {
740        self.control_handle.inner.send::<fidl::encoding::FlexibleResultType<
741            BatteryGetSpecResponse,
742            fidl_fuchsia_hardware_power_source::Error,
743        >>(
744            fidl::encoding::FlexibleResult::new(result.map(|spec| (spec,))),
745            self.tx_id,
746            0x235609229653654f,
747            fidl::encoding::DynamicFlags::FLEXIBLE,
748        )
749    }
750}
751
752#[must_use = "FIDL methods require a response to be sent"]
753#[derive(Debug)]
754pub struct BatteryGetStatusResponder {
755    control_handle: std::mem::ManuallyDrop<BatteryControlHandle>,
756    tx_id: u32,
757}
758
759/// Set the the channel to be shutdown (see [`BatteryControlHandle::shutdown`])
760/// if the responder is dropped without sending a response, so that the client
761/// doesn't hang. To prevent this behavior, call `drop_without_shutdown`.
762impl std::ops::Drop for BatteryGetStatusResponder {
763    fn drop(&mut self) {
764        self.control_handle.shutdown();
765        // Safety: drops once, never accessed again
766        unsafe { std::mem::ManuallyDrop::drop(&mut self.control_handle) };
767    }
768}
769
770impl fidl::endpoints::Responder for BatteryGetStatusResponder {
771    type ControlHandle = BatteryControlHandle;
772
773    fn control_handle(&self) -> &BatteryControlHandle {
774        &self.control_handle
775    }
776
777    fn drop_without_shutdown(mut self) {
778        // Safety: drops once, never accessed again due to mem::forget
779        unsafe { std::mem::ManuallyDrop::drop(&mut self.control_handle) };
780        // Prevent Drop from running (which would shut down the channel)
781        std::mem::forget(self);
782    }
783}
784
785impl BatteryGetStatusResponder {
786    /// Sends a response to the FIDL transaction.
787    ///
788    /// Sets the channel to shutdown if an error occurs.
789    pub fn send(
790        self,
791        mut result: Result<&Status, fidl_fuchsia_hardware_power_source::Error>,
792    ) -> Result<(), fidl::Error> {
793        let _result = self.send_raw(result);
794        if _result.is_err() {
795            self.control_handle.shutdown();
796        }
797        self.drop_without_shutdown();
798        _result
799    }
800
801    /// Similar to "send" but does not shutdown the channel if an error occurs.
802    pub fn send_no_shutdown_on_err(
803        self,
804        mut result: Result<&Status, fidl_fuchsia_hardware_power_source::Error>,
805    ) -> Result<(), fidl::Error> {
806        let _result = self.send_raw(result);
807        self.drop_without_shutdown();
808        _result
809    }
810
811    fn send_raw(
812        &self,
813        mut result: Result<&Status, fidl_fuchsia_hardware_power_source::Error>,
814    ) -> Result<(), fidl::Error> {
815        self.control_handle.inner.send::<fidl::encoding::FlexibleResultType<
816            BatteryGetStatusResponse,
817            fidl_fuchsia_hardware_power_source::Error,
818        >>(
819            fidl::encoding::FlexibleResult::new(result.map(|status| (status,))),
820            self.tx_id,
821            0x2e0c03524d47095a,
822            fidl::encoding::DynamicFlags::FLEXIBLE,
823        )
824    }
825}
826
827#[must_use = "FIDL methods require a response to be sent"]
828#[derive(Debug)]
829pub struct BatteryWatchResponder {
830    control_handle: std::mem::ManuallyDrop<BatteryControlHandle>,
831    tx_id: u32,
832}
833
834/// Set the the channel to be shutdown (see [`BatteryControlHandle::shutdown`])
835/// if the responder is dropped without sending a response, so that the client
836/// doesn't hang. To prevent this behavior, call `drop_without_shutdown`.
837impl std::ops::Drop for BatteryWatchResponder {
838    fn drop(&mut self) {
839        self.control_handle.shutdown();
840        // Safety: drops once, never accessed again
841        unsafe { std::mem::ManuallyDrop::drop(&mut self.control_handle) };
842    }
843}
844
845impl fidl::endpoints::Responder for BatteryWatchResponder {
846    type ControlHandle = BatteryControlHandle;
847
848    fn control_handle(&self) -> &BatteryControlHandle {
849        &self.control_handle
850    }
851
852    fn drop_without_shutdown(mut self) {
853        // Safety: drops once, never accessed again due to mem::forget
854        unsafe { std::mem::ManuallyDrop::drop(&mut self.control_handle) };
855        // Prevent Drop from running (which would shut down the channel)
856        std::mem::forget(self);
857    }
858}
859
860impl BatteryWatchResponder {
861    /// Sends a response to the FIDL transaction.
862    ///
863    /// Sets the channel to shutdown if an error occurs.
864    pub fn send(
865        self,
866        mut status: &Status,
867        mut wake_lease: Option<fidl::EventPair>,
868    ) -> Result<(), fidl::Error> {
869        let _result = self.send_raw(status, wake_lease);
870        if _result.is_err() {
871            self.control_handle.shutdown();
872        }
873        self.drop_without_shutdown();
874        _result
875    }
876
877    /// Similar to "send" but does not shutdown the channel if an error occurs.
878    pub fn send_no_shutdown_on_err(
879        self,
880        mut status: &Status,
881        mut wake_lease: Option<fidl::EventPair>,
882    ) -> Result<(), fidl::Error> {
883        let _result = self.send_raw(status, wake_lease);
884        self.drop_without_shutdown();
885        _result
886    }
887
888    fn send_raw(
889        &self,
890        mut status: &Status,
891        mut wake_lease: Option<fidl::EventPair>,
892    ) -> Result<(), fidl::Error> {
893        self.control_handle.inner.send::<fidl::encoding::FlexibleType<BatteryWatchResponse>>(
894            fidl::encoding::Flexible::new((status, wake_lease)),
895            self.tx_id,
896            0x7386830cdd9e3390,
897            fidl::encoding::DynamicFlags::FLEXIBLE,
898        )
899    }
900}
901
902#[derive(Debug, Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Hash)]
903pub struct ServiceMarker;
904
905#[cfg(target_os = "fuchsia")]
906impl fidl::endpoints::ServiceMarker for ServiceMarker {
907    type Proxy = ServiceProxy;
908    type Request = ServiceRequest;
909    const SERVICE_NAME: &'static str = "fuchsia.hardware.power.battery.Service";
910}
911
912/// A request for one of the member protocols of Service.
913///
914#[cfg(target_os = "fuchsia")]
915pub enum ServiceRequest {
916    Battery(BatteryRequestStream),
917    PowerSource(fidl_fuchsia_hardware_power_source::SourceRequestStream),
918}
919
920#[cfg(target_os = "fuchsia")]
921impl fidl::endpoints::ServiceRequest for ServiceRequest {
922    type Service = ServiceMarker;
923
924    fn dispatch(name: &str, _channel: fidl::AsyncChannel) -> Self {
925        match name {
926            "battery" => Self::Battery(
927                <BatteryRequestStream as fidl::endpoints::RequestStream>::from_channel(_channel),
928            ),
929            "power_source" => Self::PowerSource(
930                <fidl_fuchsia_hardware_power_source::SourceRequestStream as fidl::endpoints::RequestStream>::from_channel(_channel),
931            ),
932            _ => panic!("no such member protocol name for service Service"),
933        }
934    }
935
936    fn member_names() -> &'static [&'static str] {
937        &["battery", "power_source"]
938    }
939}
940#[cfg(target_os = "fuchsia")]
941pub struct ServiceProxy(#[allow(dead_code)] Box<dyn fidl::endpoints::MemberOpener>);
942
943#[cfg(target_os = "fuchsia")]
944impl fidl::endpoints::ServiceProxy for ServiceProxy {
945    type Service = ServiceMarker;
946
947    fn from_member_opener(opener: Box<dyn fidl::endpoints::MemberOpener>) -> Self {
948        Self(opener)
949    }
950}
951
952#[cfg(target_os = "fuchsia")]
953impl ServiceProxy {
954    pub fn connect_to_battery(&self) -> Result<BatteryProxy, fidl::Error> {
955        let (proxy, server_end) = fidl::endpoints::create_proxy::<BatteryMarker>();
956        self.connect_channel_to_battery(server_end)?;
957        Ok(proxy)
958    }
959
960    /// Like `connect_to_battery`, but returns a sync proxy.
961    /// See [`Self::connect_to_battery`] for more details.
962    pub fn connect_to_battery_sync(&self) -> Result<BatterySynchronousProxy, fidl::Error> {
963        let (proxy, server_end) = fidl::endpoints::create_sync_proxy::<BatteryMarker>();
964        self.connect_channel_to_battery(server_end)?;
965        Ok(proxy)
966    }
967
968    /// Like `connect_to_battery`, but accepts a server end.
969    /// See [`Self::connect_to_battery`] for more details.
970    pub fn connect_channel_to_battery(
971        &self,
972        server_end: fidl::endpoints::ServerEnd<BatteryMarker>,
973    ) -> Result<(), fidl::Error> {
974        self.0.open_member("battery", server_end.into_channel())
975    }
976    pub fn connect_to_power_source(
977        &self,
978    ) -> Result<fidl_fuchsia_hardware_power_source::SourceProxy, fidl::Error> {
979        let (proxy, server_end) =
980            fidl::endpoints::create_proxy::<fidl_fuchsia_hardware_power_source::SourceMarker>();
981        self.connect_channel_to_power_source(server_end)?;
982        Ok(proxy)
983    }
984
985    /// Like `connect_to_power_source`, but returns a sync proxy.
986    /// See [`Self::connect_to_power_source`] for more details.
987    pub fn connect_to_power_source_sync(
988        &self,
989    ) -> Result<fidl_fuchsia_hardware_power_source::SourceSynchronousProxy, fidl::Error> {
990        let (proxy, server_end) = fidl::endpoints::create_sync_proxy::<
991            fidl_fuchsia_hardware_power_source::SourceMarker,
992        >();
993        self.connect_channel_to_power_source(server_end)?;
994        Ok(proxy)
995    }
996
997    /// Like `connect_to_power_source`, but accepts a server end.
998    /// See [`Self::connect_to_power_source`] for more details.
999    pub fn connect_channel_to_power_source(
1000        &self,
1001        server_end: fidl::endpoints::ServerEnd<fidl_fuchsia_hardware_power_source::SourceMarker>,
1002    ) -> Result<(), fidl::Error> {
1003        self.0.open_member("power_source", server_end.into_channel())
1004    }
1005
1006    pub fn instance_name(&self) -> &str {
1007        self.0.instance_name()
1008    }
1009}
1010
1011mod internal {
1012    use super::*;
1013
1014    impl fidl::encoding::ResourceTypeMarker for BatteryWatchRequest {
1015        type Borrowed<'a> = &'a mut Self;
1016        fn take_or_borrow<'a>(
1017            value: &'a mut <Self as fidl::encoding::TypeMarker>::Owned,
1018        ) -> Self::Borrowed<'a> {
1019            value
1020        }
1021    }
1022
1023    unsafe impl fidl::encoding::TypeMarker for BatteryWatchRequest {
1024        type Owned = Self;
1025
1026        #[inline(always)]
1027        fn inline_align(_context: fidl::encoding::Context) -> usize {
1028            8
1029        }
1030
1031        #[inline(always)]
1032        fn inline_size(_context: fidl::encoding::Context) -> usize {
1033            40
1034        }
1035    }
1036
1037    unsafe impl
1038        fidl::encoding::Encode<BatteryWatchRequest, fidl::encoding::DefaultFuchsiaResourceDialect>
1039        for &mut BatteryWatchRequest
1040    {
1041        #[inline]
1042        unsafe fn encode(
1043            self,
1044            encoder: &mut fidl::encoding::Encoder<
1045                '_,
1046                fidl::encoding::DefaultFuchsiaResourceDialect,
1047            >,
1048            offset: usize,
1049            _depth: fidl::encoding::Depth,
1050        ) -> fidl::Result<()> {
1051            encoder.debug_check_bounds::<BatteryWatchRequest>(offset);
1052            // Delegate to tuple encoding.
1053            fidl::encoding::Encode::<
1054                BatteryWatchRequest,
1055                fidl::encoding::DefaultFuchsiaResourceDialect,
1056            >::encode(
1057                (
1058                    <Status as fidl::encoding::ValueTypeMarker>::borrow(&self.interest),
1059                    <Status as fidl::encoding::ValueTypeMarker>::borrow(&self.wake_on),
1060                    <fidl::encoding::Optional<
1061                        fidl::encoding::HandleType<
1062                            fidl::EventPair,
1063                            { fidl::ObjectType::EVENTPAIR.into_raw() },
1064                            16387,
1065                        >,
1066                    > as fidl::encoding::ResourceTypeMarker>::take_or_borrow(
1067                        &mut self.lease
1068                    ),
1069                ),
1070                encoder,
1071                offset,
1072                _depth,
1073            )
1074        }
1075    }
1076    unsafe impl<
1077        T0: fidl::encoding::Encode<Status, fidl::encoding::DefaultFuchsiaResourceDialect>,
1078        T1: fidl::encoding::Encode<Status, fidl::encoding::DefaultFuchsiaResourceDialect>,
1079        T2: fidl::encoding::Encode<
1080                fidl::encoding::Optional<
1081                    fidl::encoding::HandleType<
1082                        fidl::EventPair,
1083                        { fidl::ObjectType::EVENTPAIR.into_raw() },
1084                        16387,
1085                    >,
1086                >,
1087                fidl::encoding::DefaultFuchsiaResourceDialect,
1088            >,
1089    > fidl::encoding::Encode<BatteryWatchRequest, fidl::encoding::DefaultFuchsiaResourceDialect>
1090        for (T0, T1, T2)
1091    {
1092        #[inline]
1093        unsafe fn encode(
1094            self,
1095            encoder: &mut fidl::encoding::Encoder<
1096                '_,
1097                fidl::encoding::DefaultFuchsiaResourceDialect,
1098            >,
1099            offset: usize,
1100            depth: fidl::encoding::Depth,
1101        ) -> fidl::Result<()> {
1102            encoder.debug_check_bounds::<BatteryWatchRequest>(offset);
1103            // Zero out padding regions. There's no need to apply masks
1104            // because the unmasked parts will be overwritten by fields.
1105            unsafe {
1106                let ptr = encoder.buf.as_mut_ptr().add(offset).offset(32);
1107                (ptr as *mut u64).write_unaligned(0);
1108            }
1109            // Write the fields.
1110            self.0.encode(encoder, offset + 0, depth)?;
1111            self.1.encode(encoder, offset + 16, depth)?;
1112            self.2.encode(encoder, offset + 32, depth)?;
1113            Ok(())
1114        }
1115    }
1116
1117    impl fidl::encoding::Decode<Self, fidl::encoding::DefaultFuchsiaResourceDialect>
1118        for BatteryWatchRequest
1119    {
1120        #[inline(always)]
1121        fn new_empty() -> Self {
1122            Self {
1123                interest: fidl::new_empty!(Status, fidl::encoding::DefaultFuchsiaResourceDialect),
1124                wake_on: fidl::new_empty!(Status, fidl::encoding::DefaultFuchsiaResourceDialect),
1125                lease: fidl::new_empty!(
1126                    fidl::encoding::Optional<
1127                        fidl::encoding::HandleType<
1128                            fidl::EventPair,
1129                            { fidl::ObjectType::EVENTPAIR.into_raw() },
1130                            16387,
1131                        >,
1132                    >,
1133                    fidl::encoding::DefaultFuchsiaResourceDialect
1134                ),
1135            }
1136        }
1137
1138        #[inline]
1139        unsafe fn decode(
1140            &mut self,
1141            decoder: &mut fidl::encoding::Decoder<
1142                '_,
1143                fidl::encoding::DefaultFuchsiaResourceDialect,
1144            >,
1145            offset: usize,
1146            _depth: fidl::encoding::Depth,
1147        ) -> fidl::Result<()> {
1148            decoder.debug_check_bounds::<Self>(offset);
1149            // Verify that padding bytes are zero.
1150            let ptr = unsafe { decoder.buf.as_ptr().add(offset).offset(32) };
1151            let padval = unsafe { (ptr as *const u64).read_unaligned() };
1152            let mask = 0xffffffff00000000u64;
1153            let maskedval = padval & mask;
1154            if maskedval != 0 {
1155                return Err(fidl::Error::NonZeroPadding {
1156                    padding_start: offset + 32 + ((mask as u64).trailing_zeros() / 8) as usize,
1157                });
1158            }
1159            fidl::decode!(
1160                Status,
1161                fidl::encoding::DefaultFuchsiaResourceDialect,
1162                &mut self.interest,
1163                decoder,
1164                offset + 0,
1165                _depth
1166            )?;
1167            fidl::decode!(
1168                Status,
1169                fidl::encoding::DefaultFuchsiaResourceDialect,
1170                &mut self.wake_on,
1171                decoder,
1172                offset + 16,
1173                _depth
1174            )?;
1175            fidl::decode!(
1176                fidl::encoding::Optional<
1177                    fidl::encoding::HandleType<
1178                        fidl::EventPair,
1179                        { fidl::ObjectType::EVENTPAIR.into_raw() },
1180                        16387,
1181                    >,
1182                >,
1183                fidl::encoding::DefaultFuchsiaResourceDialect,
1184                &mut self.lease,
1185                decoder,
1186                offset + 32,
1187                _depth
1188            )?;
1189            Ok(())
1190        }
1191    }
1192
1193    impl fidl::encoding::ResourceTypeMarker for BatteryWatchResponse {
1194        type Borrowed<'a> = &'a mut Self;
1195        fn take_or_borrow<'a>(
1196            value: &'a mut <Self as fidl::encoding::TypeMarker>::Owned,
1197        ) -> Self::Borrowed<'a> {
1198            value
1199        }
1200    }
1201
1202    unsafe impl fidl::encoding::TypeMarker for BatteryWatchResponse {
1203        type Owned = Self;
1204
1205        #[inline(always)]
1206        fn inline_align(_context: fidl::encoding::Context) -> usize {
1207            8
1208        }
1209
1210        #[inline(always)]
1211        fn inline_size(_context: fidl::encoding::Context) -> usize {
1212            24
1213        }
1214    }
1215
1216    unsafe impl
1217        fidl::encoding::Encode<BatteryWatchResponse, fidl::encoding::DefaultFuchsiaResourceDialect>
1218        for &mut BatteryWatchResponse
1219    {
1220        #[inline]
1221        unsafe fn encode(
1222            self,
1223            encoder: &mut fidl::encoding::Encoder<
1224                '_,
1225                fidl::encoding::DefaultFuchsiaResourceDialect,
1226            >,
1227            offset: usize,
1228            _depth: fidl::encoding::Depth,
1229        ) -> fidl::Result<()> {
1230            encoder.debug_check_bounds::<BatteryWatchResponse>(offset);
1231            // Delegate to tuple encoding.
1232            fidl::encoding::Encode::<
1233                BatteryWatchResponse,
1234                fidl::encoding::DefaultFuchsiaResourceDialect,
1235            >::encode(
1236                (
1237                    <Status as fidl::encoding::ValueTypeMarker>::borrow(&self.status),
1238                    <fidl::encoding::Optional<
1239                        fidl::encoding::HandleType<
1240                            fidl::EventPair,
1241                            { fidl::ObjectType::EVENTPAIR.into_raw() },
1242                            16387,
1243                        >,
1244                    > as fidl::encoding::ResourceTypeMarker>::take_or_borrow(
1245                        &mut self.wake_lease
1246                    ),
1247                ),
1248                encoder,
1249                offset,
1250                _depth,
1251            )
1252        }
1253    }
1254    unsafe impl<
1255        T0: fidl::encoding::Encode<Status, fidl::encoding::DefaultFuchsiaResourceDialect>,
1256        T1: fidl::encoding::Encode<
1257                fidl::encoding::Optional<
1258                    fidl::encoding::HandleType<
1259                        fidl::EventPair,
1260                        { fidl::ObjectType::EVENTPAIR.into_raw() },
1261                        16387,
1262                    >,
1263                >,
1264                fidl::encoding::DefaultFuchsiaResourceDialect,
1265            >,
1266    >
1267        fidl::encoding::Encode<BatteryWatchResponse, fidl::encoding::DefaultFuchsiaResourceDialect>
1268        for (T0, T1)
1269    {
1270        #[inline]
1271        unsafe fn encode(
1272            self,
1273            encoder: &mut fidl::encoding::Encoder<
1274                '_,
1275                fidl::encoding::DefaultFuchsiaResourceDialect,
1276            >,
1277            offset: usize,
1278            depth: fidl::encoding::Depth,
1279        ) -> fidl::Result<()> {
1280            encoder.debug_check_bounds::<BatteryWatchResponse>(offset);
1281            // Zero out padding regions. There's no need to apply masks
1282            // because the unmasked parts will be overwritten by fields.
1283            unsafe {
1284                let ptr = encoder.buf.as_mut_ptr().add(offset).offset(16);
1285                (ptr as *mut u64).write_unaligned(0);
1286            }
1287            // Write the fields.
1288            self.0.encode(encoder, offset + 0, depth)?;
1289            self.1.encode(encoder, offset + 16, depth)?;
1290            Ok(())
1291        }
1292    }
1293
1294    impl fidl::encoding::Decode<Self, fidl::encoding::DefaultFuchsiaResourceDialect>
1295        for BatteryWatchResponse
1296    {
1297        #[inline(always)]
1298        fn new_empty() -> Self {
1299            Self {
1300                status: fidl::new_empty!(Status, fidl::encoding::DefaultFuchsiaResourceDialect),
1301                wake_lease: fidl::new_empty!(
1302                    fidl::encoding::Optional<
1303                        fidl::encoding::HandleType<
1304                            fidl::EventPair,
1305                            { fidl::ObjectType::EVENTPAIR.into_raw() },
1306                            16387,
1307                        >,
1308                    >,
1309                    fidl::encoding::DefaultFuchsiaResourceDialect
1310                ),
1311            }
1312        }
1313
1314        #[inline]
1315        unsafe fn decode(
1316            &mut self,
1317            decoder: &mut fidl::encoding::Decoder<
1318                '_,
1319                fidl::encoding::DefaultFuchsiaResourceDialect,
1320            >,
1321            offset: usize,
1322            _depth: fidl::encoding::Depth,
1323        ) -> fidl::Result<()> {
1324            decoder.debug_check_bounds::<Self>(offset);
1325            // Verify that padding bytes are zero.
1326            let ptr = unsafe { decoder.buf.as_ptr().add(offset).offset(16) };
1327            let padval = unsafe { (ptr as *const u64).read_unaligned() };
1328            let mask = 0xffffffff00000000u64;
1329            let maskedval = padval & mask;
1330            if maskedval != 0 {
1331                return Err(fidl::Error::NonZeroPadding {
1332                    padding_start: offset + 16 + ((mask as u64).trailing_zeros() / 8) as usize,
1333                });
1334            }
1335            fidl::decode!(
1336                Status,
1337                fidl::encoding::DefaultFuchsiaResourceDialect,
1338                &mut self.status,
1339                decoder,
1340                offset + 0,
1341                _depth
1342            )?;
1343            fidl::decode!(
1344                fidl::encoding::Optional<
1345                    fidl::encoding::HandleType<
1346                        fidl::EventPair,
1347                        { fidl::ObjectType::EVENTPAIR.into_raw() },
1348                        16387,
1349                    >,
1350                >,
1351                fidl::encoding::DefaultFuchsiaResourceDialect,
1352                &mut self.wake_lease,
1353                decoder,
1354                offset + 16,
1355                _depth
1356            )?;
1357            Ok(())
1358        }
1359    }
1360}