fidl_fuchsia_power_systemmode/
fidl_fuchsia_power_systemmode.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 _};
10use futures::future::{self, MaybeDone, TryFutureExt};
11use zx_status;
12
13/// Maximum number of [`ModeMatch`] entries that a [`ClientConfig`] may contain.
14///
15/// This value should be set equal to the number of [`SystemMode`] variants, as
16/// that is the number of entries required to support the "worst case" client
17/// configuration ("worst case" means a configuration where a mode match entry
18/// is needed for each of the supported power modes).
19pub const MAX_MODE_MATCHES_PER_CLIENT: u32 = 0;
20
21/// Possible error values returned by [`Requester.Request`].
22#[derive(Copy, Clone, Debug, Eq, PartialEq, Ord, PartialOrd, Hash)]
23pub enum ModeRequestError {
24    /// A generic error has occurred.
25    Generic,
26    #[doc(hidden)]
27    __SourceBreaking { unknown_ordinal: u32 },
28}
29
30/// Pattern that matches an unknown `ModeRequestError` member.
31#[macro_export]
32macro_rules! ModeRequestErrorUnknown {
33    () => {
34        _
35    };
36}
37
38impl ModeRequestError {
39    #[inline]
40    pub fn from_primitive(prim: u32) -> Option<Self> {
41        match prim {
42            1 => Some(Self::Generic),
43            _ => None,
44        }
45    }
46
47    #[inline]
48    pub fn from_primitive_allow_unknown(prim: u32) -> Self {
49        match prim {
50            1 => Self::Generic,
51            unknown_ordinal => Self::__SourceBreaking { unknown_ordinal },
52        }
53    }
54
55    #[inline]
56    pub fn unknown() -> Self {
57        Self::__SourceBreaking { unknown_ordinal: 0xffffffff }
58    }
59
60    #[inline]
61    pub const fn into_primitive(self) -> u32 {
62        match self {
63            Self::Generic => 1,
64            Self::__SourceBreaking { unknown_ordinal } => unknown_ordinal,
65        }
66    }
67
68    #[inline]
69    pub fn is_unknown(&self) -> bool {
70        match self {
71            Self::__SourceBreaking { unknown_ordinal: _ } => true,
72            _ => false,
73        }
74    }
75}
76
77/// Enumerates the supported system power modes.
78///
79/// Power modes in the system are non-exclusive -- more than one could be active
80/// at any given time. They typically define a system-wide low-power state or
81/// power goal, like "battery-saver mode". See the
82/// [README.md](/src/power/power-manager/system_power_mode_config/README.md) for
83/// more details.
84///
85/// Note when adding a new variant: update [`MAX_MODE_MATCHES_PER_CLIENT`] to be
86/// equal to the number of `SystemMode` variants to support the "worst case"
87/// client configuration.
88#[derive(Copy, Clone, Debug, Eq, PartialEq, Ord, PartialOrd, Hash)]
89pub enum SystemMode {
90    #[doc(hidden)]
91    __SourceBreaking { unknown_ordinal: u32 },
92}
93
94/// Pattern that matches an unknown `SystemMode` member.
95#[macro_export]
96macro_rules! SystemModeUnknown {
97    () => {
98        _
99    };
100}
101
102impl SystemMode {
103    #[inline]
104    pub fn from_primitive(prim: u32) -> Option<Self> {
105        match prim {
106            _ => None,
107        }
108    }
109
110    #[inline]
111    pub fn from_primitive_allow_unknown(prim: u32) -> Self {
112        match prim {
113            unknown_ordinal => Self::__SourceBreaking { unknown_ordinal },
114        }
115    }
116
117    #[inline]
118    pub fn unknown() -> Self {
119        Self::__SourceBreaking { unknown_ordinal: 0xffffffff }
120    }
121
122    #[inline]
123    pub const fn into_primitive(self) -> u32 {
124        match self {
125            Self::__SourceBreaking { unknown_ordinal } => unknown_ordinal,
126        }
127    }
128
129    #[inline]
130    pub fn is_unknown(&self) -> bool {
131        match self {
132            Self::__SourceBreaking { unknown_ordinal: _ } => true,
133        }
134    }
135}
136
137/// Defines the power configuration for a [`ClientType`].
138///
139/// For a client connected with a given [`ClientType`], the PowerManager will
140/// use the configured [`ClientConfig`] for that [`ClientType`] to choose the
141/// appropriate power level based on the currently active system power modes.
142/// The power level selection process is as follows for a given [`ClientType`]:
143///   1. Iterate through the [`ClientConfig.mode_matches`] entries. If the
144///   `mode` value specified by an entry is contained in the currently active
145///   system power modes, then the corresponding `power_level` from that entry
146///   will be selected as this client’s current power level, and iteration for
147///   this client will stop.
148///   2. If no entry in `mode_matches` was matched, then `default_level` will be
149///   selected as the client's current power level.
150#[derive(Clone, Debug, Eq, Hash, Ord, PartialEq, PartialOrd)]
151pub struct ClientConfig {
152    pub mode_matches: Vec<ModeMatch>,
153    pub default_level: u64,
154}
155
156impl fidl::Persistable for ClientConfig {}
157
158#[derive(Clone, Copy, Debug, Eq, Hash, Ord, PartialEq, PartialOrd)]
159pub struct ClientConfiguratorGetRequest {
160    pub client_type: fidl_fuchsia_power_clientlevel::ClientType,
161}
162
163impl fidl::Persistable for ClientConfiguratorGetRequest {}
164
165#[derive(Clone, Debug, Eq, Hash, Ord, PartialEq, PartialOrd)]
166pub struct ClientConfiguratorGetResponse {
167    pub config: Option<Box<ClientConfig>>,
168}
169
170impl fidl::Persistable for ClientConfiguratorGetResponse {}
171
172#[derive(Clone, Debug, Eq, Hash, Ord, PartialEq, PartialOrd)]
173pub struct ClientConfiguratorSetRequest {
174    pub client_type: fidl_fuchsia_power_clientlevel::ClientType,
175    pub config: ClientConfig,
176}
177
178impl fidl::Persistable for ClientConfiguratorSetRequest {}
179
180/// Defines the mode-based match criterion for selecting a power level.
181///
182/// The power configuration for a given [`ClientType`] is made up of a
183/// collection of these `ModeMatch` entries. If an entry's specified `mode` is
184/// contained in the currently active system power modes, then its `power_level`
185/// will be selected as the client's power level.
186#[derive(Clone, Copy, Debug, Eq, Hash, Ord, PartialEq, PartialOrd)]
187pub struct ModeMatch {
188    pub mode: SystemMode,
189    pub power_level: u64,
190}
191
192impl fidl::Persistable for ModeMatch {}
193
194#[derive(Clone, Copy, Debug, Eq, Hash, Ord, PartialEq, PartialOrd)]
195pub struct RequesterRequestRequest {
196    pub mode: SystemMode,
197    pub set: bool,
198}
199
200impl fidl::Persistable for RequesterRequestRequest {}
201
202#[derive(Debug, Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Hash)]
203pub struct ClientConfiguratorMarker;
204
205impl fidl::endpoints::ProtocolMarker for ClientConfiguratorMarker {
206    type Proxy = ClientConfiguratorProxy;
207    type RequestStream = ClientConfiguratorRequestStream;
208    #[cfg(target_os = "fuchsia")]
209    type SynchronousProxy = ClientConfiguratorSynchronousProxy;
210
211    const DEBUG_NAME: &'static str = "fuchsia.power.systemmode.ClientConfigurator";
212}
213impl fidl::endpoints::DiscoverableProtocolMarker for ClientConfiguratorMarker {}
214
215pub trait ClientConfiguratorProxyInterface: Send + Sync {
216    type GetResponseFut: std::future::Future<Output = Result<Option<Box<ClientConfig>>, fidl::Error>>
217        + Send;
218    fn r#get(
219        &self,
220        client_type: fidl_fuchsia_power_clientlevel::ClientType,
221    ) -> Self::GetResponseFut;
222    type SetResponseFut: std::future::Future<Output = Result<(), fidl::Error>> + Send;
223    fn r#set(
224        &self,
225        client_type: fidl_fuchsia_power_clientlevel::ClientType,
226        config: &ClientConfig,
227    ) -> Self::SetResponseFut;
228}
229#[derive(Debug)]
230#[cfg(target_os = "fuchsia")]
231pub struct ClientConfiguratorSynchronousProxy {
232    client: fidl::client::sync::Client,
233}
234
235#[cfg(target_os = "fuchsia")]
236impl fidl::endpoints::SynchronousProxy for ClientConfiguratorSynchronousProxy {
237    type Proxy = ClientConfiguratorProxy;
238    type Protocol = ClientConfiguratorMarker;
239
240    fn from_channel(inner: fidl::Channel) -> Self {
241        Self::new(inner)
242    }
243
244    fn into_channel(self) -> fidl::Channel {
245        self.client.into_channel()
246    }
247
248    fn as_channel(&self) -> &fidl::Channel {
249        self.client.as_channel()
250    }
251}
252
253#[cfg(target_os = "fuchsia")]
254impl ClientConfiguratorSynchronousProxy {
255    pub fn new(channel: fidl::Channel) -> Self {
256        let protocol_name =
257            <ClientConfiguratorMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME;
258        Self { client: fidl::client::sync::Client::new(channel, protocol_name) }
259    }
260
261    pub fn into_channel(self) -> fidl::Channel {
262        self.client.into_channel()
263    }
264
265    /// Waits until an event arrives and returns it. It is safe for other
266    /// threads to make concurrent requests while waiting for an event.
267    pub fn wait_for_event(
268        &self,
269        deadline: zx::MonotonicInstant,
270    ) -> Result<ClientConfiguratorEvent, fidl::Error> {
271        ClientConfiguratorEvent::decode(self.client.wait_for_event(deadline)?)
272    }
273
274    /// Gets the power configuration for the given [`ClientType`].
275    ///
276    /// If there is no power configuration for `client_type` then the returned
277    /// value will be absent.
278    ///
279    /// + `client_type` specifies which [`ClientType`] [`ClientConfig`] to get
280    /// - `config` is the returned client-specific configuration, or an absent
281    /// value if `client_type` does not have an existing configuration
282    pub fn r#get(
283        &self,
284        mut client_type: fidl_fuchsia_power_clientlevel::ClientType,
285        ___deadline: zx::MonotonicInstant,
286    ) -> Result<Option<Box<ClientConfig>>, fidl::Error> {
287        let _response =
288            self.client.send_query::<ClientConfiguratorGetRequest, ClientConfiguratorGetResponse>(
289                (client_type,),
290                0x1e37597b4d247d7b,
291                fidl::encoding::DynamicFlags::empty(),
292                ___deadline,
293            )?;
294        Ok(_response.config)
295    }
296
297    /// Sets the power configuration for the given [`ClientType`].
298    ///
299    /// This method should be used in tandem with [`GetConfig`] in order to
300    /// update the existing power configuration for a given [`ClientType`]
301    /// without fully overwriting it.
302    ///
303    /// When the power configuration for a given [`ClientType`] is changed, the
304    /// Power Manager will reevaluate current power level of that [`ClientType`]
305    /// according to the new configuration. This reevaluation may result in a
306    /// new power level being sent to the connected client.
307    ///
308    /// The call returns immediately after the new config has been received and
309    /// validated. Actual system changes to be applied as a result of changing a
310    /// client's configuration will occur after the call has returned.
311    /// Therefore, any errors that occur while updating clients according to the
312    /// new system power mode are not propagated back to the caller. Instead,
313    /// client updates are applied on a "best effort" basis.
314    ///
315    /// If the provided `config` is not valid, then no changes will be applied
316    /// and the channel will be closed. Validation will fail if a given
317    /// `SystemMode` is repeated across multiple `mode_match` entries contained
318    /// by the `ClientConfig`.
319    ///
320    /// + `client_type` specifies which [`ClientType`]'s [`ClientConfig`] to set
321    /// + `config` is the [`ClientConfig`] that will be set for [`client_type`]
322    pub fn r#set(
323        &self,
324        mut client_type: fidl_fuchsia_power_clientlevel::ClientType,
325        mut config: &ClientConfig,
326        ___deadline: zx::MonotonicInstant,
327    ) -> Result<(), fidl::Error> {
328        let _response =
329            self.client.send_query::<ClientConfiguratorSetRequest, fidl::encoding::EmptyPayload>(
330                (client_type, config),
331                0x2204fb91b32f6435,
332                fidl::encoding::DynamicFlags::empty(),
333                ___deadline,
334            )?;
335        Ok(_response)
336    }
337}
338
339#[derive(Debug, Clone)]
340pub struct ClientConfiguratorProxy {
341    client: fidl::client::Client<fidl::encoding::DefaultFuchsiaResourceDialect>,
342}
343
344impl fidl::endpoints::Proxy for ClientConfiguratorProxy {
345    type Protocol = ClientConfiguratorMarker;
346
347    fn from_channel(inner: ::fidl::AsyncChannel) -> Self {
348        Self::new(inner)
349    }
350
351    fn into_channel(self) -> Result<::fidl::AsyncChannel, Self> {
352        self.client.into_channel().map_err(|client| Self { client })
353    }
354
355    fn as_channel(&self) -> &::fidl::AsyncChannel {
356        self.client.as_channel()
357    }
358}
359
360impl ClientConfiguratorProxy {
361    /// Create a new Proxy for fuchsia.power.systemmode/ClientConfigurator.
362    pub fn new(channel: ::fidl::AsyncChannel) -> Self {
363        let protocol_name =
364            <ClientConfiguratorMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME;
365        Self { client: fidl::client::Client::new(channel, protocol_name) }
366    }
367
368    /// Get a Stream of events from the remote end of the protocol.
369    ///
370    /// # Panics
371    ///
372    /// Panics if the event stream was already taken.
373    pub fn take_event_stream(&self) -> ClientConfiguratorEventStream {
374        ClientConfiguratorEventStream { event_receiver: self.client.take_event_receiver() }
375    }
376
377    /// Gets the power configuration for the given [`ClientType`].
378    ///
379    /// If there is no power configuration for `client_type` then the returned
380    /// value will be absent.
381    ///
382    /// + `client_type` specifies which [`ClientType`] [`ClientConfig`] to get
383    /// - `config` is the returned client-specific configuration, or an absent
384    /// value if `client_type` does not have an existing configuration
385    pub fn r#get(
386        &self,
387        mut client_type: fidl_fuchsia_power_clientlevel::ClientType,
388    ) -> fidl::client::QueryResponseFut<
389        Option<Box<ClientConfig>>,
390        fidl::encoding::DefaultFuchsiaResourceDialect,
391    > {
392        ClientConfiguratorProxyInterface::r#get(self, client_type)
393    }
394
395    /// Sets the power configuration for the given [`ClientType`].
396    ///
397    /// This method should be used in tandem with [`GetConfig`] in order to
398    /// update the existing power configuration for a given [`ClientType`]
399    /// without fully overwriting it.
400    ///
401    /// When the power configuration for a given [`ClientType`] is changed, the
402    /// Power Manager will reevaluate current power level of that [`ClientType`]
403    /// according to the new configuration. This reevaluation may result in a
404    /// new power level being sent to the connected client.
405    ///
406    /// The call returns immediately after the new config has been received and
407    /// validated. Actual system changes to be applied as a result of changing a
408    /// client's configuration will occur after the call has returned.
409    /// Therefore, any errors that occur while updating clients according to the
410    /// new system power mode are not propagated back to the caller. Instead,
411    /// client updates are applied on a "best effort" basis.
412    ///
413    /// If the provided `config` is not valid, then no changes will be applied
414    /// and the channel will be closed. Validation will fail if a given
415    /// `SystemMode` is repeated across multiple `mode_match` entries contained
416    /// by the `ClientConfig`.
417    ///
418    /// + `client_type` specifies which [`ClientType`]'s [`ClientConfig`] to set
419    /// + `config` is the [`ClientConfig`] that will be set for [`client_type`]
420    pub fn r#set(
421        &self,
422        mut client_type: fidl_fuchsia_power_clientlevel::ClientType,
423        mut config: &ClientConfig,
424    ) -> fidl::client::QueryResponseFut<(), fidl::encoding::DefaultFuchsiaResourceDialect> {
425        ClientConfiguratorProxyInterface::r#set(self, client_type, config)
426    }
427}
428
429impl ClientConfiguratorProxyInterface for ClientConfiguratorProxy {
430    type GetResponseFut = fidl::client::QueryResponseFut<
431        Option<Box<ClientConfig>>,
432        fidl::encoding::DefaultFuchsiaResourceDialect,
433    >;
434    fn r#get(
435        &self,
436        mut client_type: fidl_fuchsia_power_clientlevel::ClientType,
437    ) -> Self::GetResponseFut {
438        fn _decode(
439            mut _buf: Result<<fidl::encoding::DefaultFuchsiaResourceDialect as fidl::encoding::ResourceDialect>::MessageBufEtc, fidl::Error>,
440        ) -> Result<Option<Box<ClientConfig>>, fidl::Error> {
441            let _response = fidl::client::decode_transaction_body::<
442                ClientConfiguratorGetResponse,
443                fidl::encoding::DefaultFuchsiaResourceDialect,
444                0x1e37597b4d247d7b,
445            >(_buf?)?;
446            Ok(_response.config)
447        }
448        self.client
449            .send_query_and_decode::<ClientConfiguratorGetRequest, Option<Box<ClientConfig>>>(
450                (client_type,),
451                0x1e37597b4d247d7b,
452                fidl::encoding::DynamicFlags::empty(),
453                _decode,
454            )
455    }
456
457    type SetResponseFut =
458        fidl::client::QueryResponseFut<(), fidl::encoding::DefaultFuchsiaResourceDialect>;
459    fn r#set(
460        &self,
461        mut client_type: fidl_fuchsia_power_clientlevel::ClientType,
462        mut config: &ClientConfig,
463    ) -> Self::SetResponseFut {
464        fn _decode(
465            mut _buf: Result<<fidl::encoding::DefaultFuchsiaResourceDialect as fidl::encoding::ResourceDialect>::MessageBufEtc, fidl::Error>,
466        ) -> Result<(), fidl::Error> {
467            let _response = fidl::client::decode_transaction_body::<
468                fidl::encoding::EmptyPayload,
469                fidl::encoding::DefaultFuchsiaResourceDialect,
470                0x2204fb91b32f6435,
471            >(_buf?)?;
472            Ok(_response)
473        }
474        self.client.send_query_and_decode::<ClientConfiguratorSetRequest, ()>(
475            (client_type, config),
476            0x2204fb91b32f6435,
477            fidl::encoding::DynamicFlags::empty(),
478            _decode,
479        )
480    }
481}
482
483pub struct ClientConfiguratorEventStream {
484    event_receiver: fidl::client::EventReceiver<fidl::encoding::DefaultFuchsiaResourceDialect>,
485}
486
487impl std::marker::Unpin for ClientConfiguratorEventStream {}
488
489impl futures::stream::FusedStream for ClientConfiguratorEventStream {
490    fn is_terminated(&self) -> bool {
491        self.event_receiver.is_terminated()
492    }
493}
494
495impl futures::Stream for ClientConfiguratorEventStream {
496    type Item = Result<ClientConfiguratorEvent, fidl::Error>;
497
498    fn poll_next(
499        mut self: std::pin::Pin<&mut Self>,
500        cx: &mut std::task::Context<'_>,
501    ) -> std::task::Poll<Option<Self::Item>> {
502        match futures::ready!(futures::stream::StreamExt::poll_next_unpin(
503            &mut self.event_receiver,
504            cx
505        )?) {
506            Some(buf) => std::task::Poll::Ready(Some(ClientConfiguratorEvent::decode(buf))),
507            None => std::task::Poll::Ready(None),
508        }
509    }
510}
511
512#[derive(Debug)]
513pub enum ClientConfiguratorEvent {}
514
515impl ClientConfiguratorEvent {
516    /// Decodes a message buffer as a [`ClientConfiguratorEvent`].
517    fn decode(
518        mut buf: <fidl::encoding::DefaultFuchsiaResourceDialect as fidl::encoding::ResourceDialect>::MessageBufEtc,
519    ) -> Result<ClientConfiguratorEvent, fidl::Error> {
520        let (bytes, _handles) = buf.split_mut();
521        let (tx_header, _body_bytes) = fidl::encoding::decode_transaction_header(bytes)?;
522        debug_assert_eq!(tx_header.tx_id, 0);
523        match tx_header.ordinal {
524            _ => Err(fidl::Error::UnknownOrdinal {
525                ordinal: tx_header.ordinal,
526                protocol_name:
527                    <ClientConfiguratorMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME,
528            }),
529        }
530    }
531}
532
533/// A Stream of incoming requests for fuchsia.power.systemmode/ClientConfigurator.
534pub struct ClientConfiguratorRequestStream {
535    inner: std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>,
536    is_terminated: bool,
537}
538
539impl std::marker::Unpin for ClientConfiguratorRequestStream {}
540
541impl futures::stream::FusedStream for ClientConfiguratorRequestStream {
542    fn is_terminated(&self) -> bool {
543        self.is_terminated
544    }
545}
546
547impl fidl::endpoints::RequestStream for ClientConfiguratorRequestStream {
548    type Protocol = ClientConfiguratorMarker;
549    type ControlHandle = ClientConfiguratorControlHandle;
550
551    fn from_channel(channel: ::fidl::AsyncChannel) -> Self {
552        Self { inner: std::sync::Arc::new(fidl::ServeInner::new(channel)), is_terminated: false }
553    }
554
555    fn control_handle(&self) -> Self::ControlHandle {
556        ClientConfiguratorControlHandle { inner: self.inner.clone() }
557    }
558
559    fn into_inner(
560        self,
561    ) -> (::std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>, bool)
562    {
563        (self.inner, self.is_terminated)
564    }
565
566    fn from_inner(
567        inner: std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>,
568        is_terminated: bool,
569    ) -> Self {
570        Self { inner, is_terminated }
571    }
572}
573
574impl futures::Stream for ClientConfiguratorRequestStream {
575    type Item = Result<ClientConfiguratorRequest, fidl::Error>;
576
577    fn poll_next(
578        mut self: std::pin::Pin<&mut Self>,
579        cx: &mut std::task::Context<'_>,
580    ) -> std::task::Poll<Option<Self::Item>> {
581        let this = &mut *self;
582        if this.inner.check_shutdown(cx) {
583            this.is_terminated = true;
584            return std::task::Poll::Ready(None);
585        }
586        if this.is_terminated {
587            panic!("polled ClientConfiguratorRequestStream after completion");
588        }
589        fidl::encoding::with_tls_decode_buf::<_, fidl::encoding::DefaultFuchsiaResourceDialect>(
590            |bytes, handles| {
591                match this.inner.channel().read_etc(cx, bytes, handles) {
592                    std::task::Poll::Ready(Ok(())) => {}
593                    std::task::Poll::Pending => return std::task::Poll::Pending,
594                    std::task::Poll::Ready(Err(zx_status::Status::PEER_CLOSED)) => {
595                        this.is_terminated = true;
596                        return std::task::Poll::Ready(None);
597                    }
598                    std::task::Poll::Ready(Err(e)) => {
599                        return std::task::Poll::Ready(Some(Err(fidl::Error::ServerRequestRead(
600                            e.into(),
601                        ))))
602                    }
603                }
604
605                // A message has been received from the channel
606                let (header, _body_bytes) = fidl::encoding::decode_transaction_header(bytes)?;
607
608                std::task::Poll::Ready(Some(match header.ordinal {
609                0x1e37597b4d247d7b => {
610                    header.validate_request_tx_id(fidl::MethodType::TwoWay)?;
611                    let mut req = fidl::new_empty!(ClientConfiguratorGetRequest, fidl::encoding::DefaultFuchsiaResourceDialect);
612                    fidl::encoding::Decoder::<fidl::encoding::DefaultFuchsiaResourceDialect>::decode_into::<ClientConfiguratorGetRequest>(&header, _body_bytes, handles, &mut req)?;
613                    let control_handle = ClientConfiguratorControlHandle {
614                        inner: this.inner.clone(),
615                    };
616                    Ok(ClientConfiguratorRequest::Get {client_type: req.client_type,
617
618                        responder: ClientConfiguratorGetResponder {
619                            control_handle: std::mem::ManuallyDrop::new(control_handle),
620                            tx_id: header.tx_id,
621                        },
622                    })
623                }
624                0x2204fb91b32f6435 => {
625                    header.validate_request_tx_id(fidl::MethodType::TwoWay)?;
626                    let mut req = fidl::new_empty!(ClientConfiguratorSetRequest, fidl::encoding::DefaultFuchsiaResourceDialect);
627                    fidl::encoding::Decoder::<fidl::encoding::DefaultFuchsiaResourceDialect>::decode_into::<ClientConfiguratorSetRequest>(&header, _body_bytes, handles, &mut req)?;
628                    let control_handle = ClientConfiguratorControlHandle {
629                        inner: this.inner.clone(),
630                    };
631                    Ok(ClientConfiguratorRequest::Set {client_type: req.client_type,
632config: req.config,
633
634                        responder: ClientConfiguratorSetResponder {
635                            control_handle: std::mem::ManuallyDrop::new(control_handle),
636                            tx_id: header.tx_id,
637                        },
638                    })
639                }
640                _ => Err(fidl::Error::UnknownOrdinal {
641                    ordinal: header.ordinal,
642                    protocol_name: <ClientConfiguratorMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME,
643                }),
644            }))
645            },
646        )
647    }
648}
649
650/// A protocol that can be used to update the power configuration for a given
651/// [`ClientType`].
652#[derive(Debug)]
653pub enum ClientConfiguratorRequest {
654    /// Gets the power configuration for the given [`ClientType`].
655    ///
656    /// If there is no power configuration for `client_type` then the returned
657    /// value will be absent.
658    ///
659    /// + `client_type` specifies which [`ClientType`] [`ClientConfig`] to get
660    /// - `config` is the returned client-specific configuration, or an absent
661    /// value if `client_type` does not have an existing configuration
662    Get {
663        client_type: fidl_fuchsia_power_clientlevel::ClientType,
664        responder: ClientConfiguratorGetResponder,
665    },
666    /// Sets the power configuration for the given [`ClientType`].
667    ///
668    /// This method should be used in tandem with [`GetConfig`] in order to
669    /// update the existing power configuration for a given [`ClientType`]
670    /// without fully overwriting it.
671    ///
672    /// When the power configuration for a given [`ClientType`] is changed, the
673    /// Power Manager will reevaluate current power level of that [`ClientType`]
674    /// according to the new configuration. This reevaluation may result in a
675    /// new power level being sent to the connected client.
676    ///
677    /// The call returns immediately after the new config has been received and
678    /// validated. Actual system changes to be applied as a result of changing a
679    /// client's configuration will occur after the call has returned.
680    /// Therefore, any errors that occur while updating clients according to the
681    /// new system power mode are not propagated back to the caller. Instead,
682    /// client updates are applied on a "best effort" basis.
683    ///
684    /// If the provided `config` is not valid, then no changes will be applied
685    /// and the channel will be closed. Validation will fail if a given
686    /// `SystemMode` is repeated across multiple `mode_match` entries contained
687    /// by the `ClientConfig`.
688    ///
689    /// + `client_type` specifies which [`ClientType`]'s [`ClientConfig`] to set
690    /// + `config` is the [`ClientConfig`] that will be set for [`client_type`]
691    Set {
692        client_type: fidl_fuchsia_power_clientlevel::ClientType,
693        config: ClientConfig,
694        responder: ClientConfiguratorSetResponder,
695    },
696}
697
698impl ClientConfiguratorRequest {
699    #[allow(irrefutable_let_patterns)]
700    pub fn into_get(
701        self,
702    ) -> Option<(fidl_fuchsia_power_clientlevel::ClientType, ClientConfiguratorGetResponder)> {
703        if let ClientConfiguratorRequest::Get { client_type, responder } = self {
704            Some((client_type, responder))
705        } else {
706            None
707        }
708    }
709
710    #[allow(irrefutable_let_patterns)]
711    pub fn into_set(
712        self,
713    ) -> Option<(
714        fidl_fuchsia_power_clientlevel::ClientType,
715        ClientConfig,
716        ClientConfiguratorSetResponder,
717    )> {
718        if let ClientConfiguratorRequest::Set { client_type, config, responder } = self {
719            Some((client_type, config, responder))
720        } else {
721            None
722        }
723    }
724
725    /// Name of the method defined in FIDL
726    pub fn method_name(&self) -> &'static str {
727        match *self {
728            ClientConfiguratorRequest::Get { .. } => "get",
729            ClientConfiguratorRequest::Set { .. } => "set",
730        }
731    }
732}
733
734#[derive(Debug, Clone)]
735pub struct ClientConfiguratorControlHandle {
736    inner: std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>,
737}
738
739impl fidl::endpoints::ControlHandle for ClientConfiguratorControlHandle {
740    fn shutdown(&self) {
741        self.inner.shutdown()
742    }
743    fn shutdown_with_epitaph(&self, status: zx_status::Status) {
744        self.inner.shutdown_with_epitaph(status)
745    }
746
747    fn is_closed(&self) -> bool {
748        self.inner.channel().is_closed()
749    }
750    fn on_closed(&self) -> fidl::OnSignalsRef<'_> {
751        self.inner.channel().on_closed()
752    }
753
754    #[cfg(target_os = "fuchsia")]
755    fn signal_peer(
756        &self,
757        clear_mask: zx::Signals,
758        set_mask: zx::Signals,
759    ) -> Result<(), zx_status::Status> {
760        use fidl::Peered;
761        self.inner.channel().signal_peer(clear_mask, set_mask)
762    }
763}
764
765impl ClientConfiguratorControlHandle {}
766
767#[must_use = "FIDL methods require a response to be sent"]
768#[derive(Debug)]
769pub struct ClientConfiguratorGetResponder {
770    control_handle: std::mem::ManuallyDrop<ClientConfiguratorControlHandle>,
771    tx_id: u32,
772}
773
774/// Set the the channel to be shutdown (see [`ClientConfiguratorControlHandle::shutdown`])
775/// if the responder is dropped without sending a response, so that the client
776/// doesn't hang. To prevent this behavior, call `drop_without_shutdown`.
777impl std::ops::Drop for ClientConfiguratorGetResponder {
778    fn drop(&mut self) {
779        self.control_handle.shutdown();
780        // Safety: drops once, never accessed again
781        unsafe { std::mem::ManuallyDrop::drop(&mut self.control_handle) };
782    }
783}
784
785impl fidl::endpoints::Responder for ClientConfiguratorGetResponder {
786    type ControlHandle = ClientConfiguratorControlHandle;
787
788    fn control_handle(&self) -> &ClientConfiguratorControlHandle {
789        &self.control_handle
790    }
791
792    fn drop_without_shutdown(mut self) {
793        // Safety: drops once, never accessed again due to mem::forget
794        unsafe { std::mem::ManuallyDrop::drop(&mut self.control_handle) };
795        // Prevent Drop from running (which would shut down the channel)
796        std::mem::forget(self);
797    }
798}
799
800impl ClientConfiguratorGetResponder {
801    /// Sends a response to the FIDL transaction.
802    ///
803    /// Sets the channel to shutdown if an error occurs.
804    pub fn send(self, mut config: Option<&ClientConfig>) -> Result<(), fidl::Error> {
805        let _result = self.send_raw(config);
806        if _result.is_err() {
807            self.control_handle.shutdown();
808        }
809        self.drop_without_shutdown();
810        _result
811    }
812
813    /// Similar to "send" but does not shutdown the channel if an error occurs.
814    pub fn send_no_shutdown_on_err(
815        self,
816        mut config: Option<&ClientConfig>,
817    ) -> Result<(), fidl::Error> {
818        let _result = self.send_raw(config);
819        self.drop_without_shutdown();
820        _result
821    }
822
823    fn send_raw(&self, mut config: Option<&ClientConfig>) -> Result<(), fidl::Error> {
824        self.control_handle.inner.send::<ClientConfiguratorGetResponse>(
825            (config,),
826            self.tx_id,
827            0x1e37597b4d247d7b,
828            fidl::encoding::DynamicFlags::empty(),
829        )
830    }
831}
832
833#[must_use = "FIDL methods require a response to be sent"]
834#[derive(Debug)]
835pub struct ClientConfiguratorSetResponder {
836    control_handle: std::mem::ManuallyDrop<ClientConfiguratorControlHandle>,
837    tx_id: u32,
838}
839
840/// Set the the channel to be shutdown (see [`ClientConfiguratorControlHandle::shutdown`])
841/// if the responder is dropped without sending a response, so that the client
842/// doesn't hang. To prevent this behavior, call `drop_without_shutdown`.
843impl std::ops::Drop for ClientConfiguratorSetResponder {
844    fn drop(&mut self) {
845        self.control_handle.shutdown();
846        // Safety: drops once, never accessed again
847        unsafe { std::mem::ManuallyDrop::drop(&mut self.control_handle) };
848    }
849}
850
851impl fidl::endpoints::Responder for ClientConfiguratorSetResponder {
852    type ControlHandle = ClientConfiguratorControlHandle;
853
854    fn control_handle(&self) -> &ClientConfiguratorControlHandle {
855        &self.control_handle
856    }
857
858    fn drop_without_shutdown(mut self) {
859        // Safety: drops once, never accessed again due to mem::forget
860        unsafe { std::mem::ManuallyDrop::drop(&mut self.control_handle) };
861        // Prevent Drop from running (which would shut down the channel)
862        std::mem::forget(self);
863    }
864}
865
866impl ClientConfiguratorSetResponder {
867    /// Sends a response to the FIDL transaction.
868    ///
869    /// Sets the channel to shutdown if an error occurs.
870    pub fn send(self) -> Result<(), fidl::Error> {
871        let _result = self.send_raw();
872        if _result.is_err() {
873            self.control_handle.shutdown();
874        }
875        self.drop_without_shutdown();
876        _result
877    }
878
879    /// Similar to "send" but does not shutdown the channel if an error occurs.
880    pub fn send_no_shutdown_on_err(self) -> Result<(), fidl::Error> {
881        let _result = self.send_raw();
882        self.drop_without_shutdown();
883        _result
884    }
885
886    fn send_raw(&self) -> Result<(), fidl::Error> {
887        self.control_handle.inner.send::<fidl::encoding::EmptyPayload>(
888            (),
889            self.tx_id,
890            0x2204fb91b32f6435,
891            fidl::encoding::DynamicFlags::empty(),
892        )
893    }
894}
895
896#[derive(Debug, Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Hash)]
897pub struct RequesterMarker;
898
899impl fidl::endpoints::ProtocolMarker for RequesterMarker {
900    type Proxy = RequesterProxy;
901    type RequestStream = RequesterRequestStream;
902    #[cfg(target_os = "fuchsia")]
903    type SynchronousProxy = RequesterSynchronousProxy;
904
905    const DEBUG_NAME: &'static str = "fuchsia.power.systemmode.Requester";
906}
907impl fidl::endpoints::DiscoverableProtocolMarker for RequesterMarker {}
908pub type RequesterRequestResult = Result<(), ModeRequestError>;
909
910pub trait RequesterProxyInterface: Send + Sync {
911    type RequestResponseFut: std::future::Future<Output = Result<RequesterRequestResult, fidl::Error>>
912        + Send;
913    fn r#request(&self, mode: SystemMode, set: bool) -> Self::RequestResponseFut;
914}
915#[derive(Debug)]
916#[cfg(target_os = "fuchsia")]
917pub struct RequesterSynchronousProxy {
918    client: fidl::client::sync::Client,
919}
920
921#[cfg(target_os = "fuchsia")]
922impl fidl::endpoints::SynchronousProxy for RequesterSynchronousProxy {
923    type Proxy = RequesterProxy;
924    type Protocol = RequesterMarker;
925
926    fn from_channel(inner: fidl::Channel) -> Self {
927        Self::new(inner)
928    }
929
930    fn into_channel(self) -> fidl::Channel {
931        self.client.into_channel()
932    }
933
934    fn as_channel(&self) -> &fidl::Channel {
935        self.client.as_channel()
936    }
937}
938
939#[cfg(target_os = "fuchsia")]
940impl RequesterSynchronousProxy {
941    pub fn new(channel: fidl::Channel) -> Self {
942        let protocol_name = <RequesterMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME;
943        Self { client: fidl::client::sync::Client::new(channel, protocol_name) }
944    }
945
946    pub fn into_channel(self) -> fidl::Channel {
947        self.client.into_channel()
948    }
949
950    /// Waits until an event arrives and returns it. It is safe for other
951    /// threads to make concurrent requests while waiting for an event.
952    pub fn wait_for_event(
953        &self,
954        deadline: zx::MonotonicInstant,
955    ) -> Result<RequesterEvent, fidl::Error> {
956        RequesterEvent::decode(self.client.wait_for_event(deadline)?)
957    }
958
959    /// Requests to set or clear a system power mode.
960    ///
961    /// The call returns immediately after the request has been received,
962    /// validated, and accepted. Actual system changes to be applied as a result
963    /// of this request will occur after the call has returned. Therefore, any
964    /// errors that occur while updating clients according to the new system
965    /// power mode are not propagated back to the caller. Instead, client
966    /// updates are applied on a "best effort" basis.
967    ///
968    /// An error returned by this method means the request itself is not valid
969    /// and was rejected. Details of the specific rejection reason are reflected
970    /// by the error value. In the event of an error, the channel will remain
971    /// open.
972    ///
973    /// A client can use this method to set or clear system power mode variants
974    /// independently. For example:
975    ///
976    ///   // battery is below the "low" threshold
977    ///   Request(LOW_BATTERY, true);
978    ///
979    ///   // device is now plugged into the wall
980    ///   Request(ON_AC_POWER, true);
981    ///
982    ///   // battery is now above the "low" threshold
983    ///   Request(LOW_BATTERY, false);
984    ///
985    /// + `mode` is the `SystemMode` to request to be set or cleared
986    /// + `set` should be true to request to set `mode`, or false to clear it
987    /// * error a [`ModeRequestError`] value indicating why the request was
988    /// rejected.
989    pub fn r#request(
990        &self,
991        mut mode: SystemMode,
992        mut set: bool,
993        ___deadline: zx::MonotonicInstant,
994    ) -> Result<RequesterRequestResult, fidl::Error> {
995        let _response = self.client.send_query::<
996            RequesterRequestRequest,
997            fidl::encoding::ResultType<fidl::encoding::EmptyStruct, ModeRequestError>,
998        >(
999            (mode, set,),
1000            0x5603afcd4421f425,
1001            fidl::encoding::DynamicFlags::empty(),
1002            ___deadline,
1003        )?;
1004        Ok(_response.map(|x| x))
1005    }
1006}
1007
1008#[derive(Debug, Clone)]
1009pub struct RequesterProxy {
1010    client: fidl::client::Client<fidl::encoding::DefaultFuchsiaResourceDialect>,
1011}
1012
1013impl fidl::endpoints::Proxy for RequesterProxy {
1014    type Protocol = RequesterMarker;
1015
1016    fn from_channel(inner: ::fidl::AsyncChannel) -> Self {
1017        Self::new(inner)
1018    }
1019
1020    fn into_channel(self) -> Result<::fidl::AsyncChannel, Self> {
1021        self.client.into_channel().map_err(|client| Self { client })
1022    }
1023
1024    fn as_channel(&self) -> &::fidl::AsyncChannel {
1025        self.client.as_channel()
1026    }
1027}
1028
1029impl RequesterProxy {
1030    /// Create a new Proxy for fuchsia.power.systemmode/Requester.
1031    pub fn new(channel: ::fidl::AsyncChannel) -> Self {
1032        let protocol_name = <RequesterMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME;
1033        Self { client: fidl::client::Client::new(channel, protocol_name) }
1034    }
1035
1036    /// Get a Stream of events from the remote end of the protocol.
1037    ///
1038    /// # Panics
1039    ///
1040    /// Panics if the event stream was already taken.
1041    pub fn take_event_stream(&self) -> RequesterEventStream {
1042        RequesterEventStream { event_receiver: self.client.take_event_receiver() }
1043    }
1044
1045    /// Requests to set or clear a system power mode.
1046    ///
1047    /// The call returns immediately after the request has been received,
1048    /// validated, and accepted. Actual system changes to be applied as a result
1049    /// of this request will occur after the call has returned. Therefore, any
1050    /// errors that occur while updating clients according to the new system
1051    /// power mode are not propagated back to the caller. Instead, client
1052    /// updates are applied on a "best effort" basis.
1053    ///
1054    /// An error returned by this method means the request itself is not valid
1055    /// and was rejected. Details of the specific rejection reason are reflected
1056    /// by the error value. In the event of an error, the channel will remain
1057    /// open.
1058    ///
1059    /// A client can use this method to set or clear system power mode variants
1060    /// independently. For example:
1061    ///
1062    ///   // battery is below the "low" threshold
1063    ///   Request(LOW_BATTERY, true);
1064    ///
1065    ///   // device is now plugged into the wall
1066    ///   Request(ON_AC_POWER, true);
1067    ///
1068    ///   // battery is now above the "low" threshold
1069    ///   Request(LOW_BATTERY, false);
1070    ///
1071    /// + `mode` is the `SystemMode` to request to be set or cleared
1072    /// + `set` should be true to request to set `mode`, or false to clear it
1073    /// * error a [`ModeRequestError`] value indicating why the request was
1074    /// rejected.
1075    pub fn r#request(
1076        &self,
1077        mut mode: SystemMode,
1078        mut set: bool,
1079    ) -> fidl::client::QueryResponseFut<
1080        RequesterRequestResult,
1081        fidl::encoding::DefaultFuchsiaResourceDialect,
1082    > {
1083        RequesterProxyInterface::r#request(self, mode, set)
1084    }
1085}
1086
1087impl RequesterProxyInterface for RequesterProxy {
1088    type RequestResponseFut = fidl::client::QueryResponseFut<
1089        RequesterRequestResult,
1090        fidl::encoding::DefaultFuchsiaResourceDialect,
1091    >;
1092    fn r#request(&self, mut mode: SystemMode, mut set: bool) -> Self::RequestResponseFut {
1093        fn _decode(
1094            mut _buf: Result<<fidl::encoding::DefaultFuchsiaResourceDialect as fidl::encoding::ResourceDialect>::MessageBufEtc, fidl::Error>,
1095        ) -> Result<RequesterRequestResult, fidl::Error> {
1096            let _response = fidl::client::decode_transaction_body::<
1097                fidl::encoding::ResultType<fidl::encoding::EmptyStruct, ModeRequestError>,
1098                fidl::encoding::DefaultFuchsiaResourceDialect,
1099                0x5603afcd4421f425,
1100            >(_buf?)?;
1101            Ok(_response.map(|x| x))
1102        }
1103        self.client.send_query_and_decode::<RequesterRequestRequest, RequesterRequestResult>(
1104            (mode, set),
1105            0x5603afcd4421f425,
1106            fidl::encoding::DynamicFlags::empty(),
1107            _decode,
1108        )
1109    }
1110}
1111
1112pub struct RequesterEventStream {
1113    event_receiver: fidl::client::EventReceiver<fidl::encoding::DefaultFuchsiaResourceDialect>,
1114}
1115
1116impl std::marker::Unpin for RequesterEventStream {}
1117
1118impl futures::stream::FusedStream for RequesterEventStream {
1119    fn is_terminated(&self) -> bool {
1120        self.event_receiver.is_terminated()
1121    }
1122}
1123
1124impl futures::Stream for RequesterEventStream {
1125    type Item = Result<RequesterEvent, fidl::Error>;
1126
1127    fn poll_next(
1128        mut self: std::pin::Pin<&mut Self>,
1129        cx: &mut std::task::Context<'_>,
1130    ) -> std::task::Poll<Option<Self::Item>> {
1131        match futures::ready!(futures::stream::StreamExt::poll_next_unpin(
1132            &mut self.event_receiver,
1133            cx
1134        )?) {
1135            Some(buf) => std::task::Poll::Ready(Some(RequesterEvent::decode(buf))),
1136            None => std::task::Poll::Ready(None),
1137        }
1138    }
1139}
1140
1141#[derive(Debug)]
1142pub enum RequesterEvent {}
1143
1144impl RequesterEvent {
1145    /// Decodes a message buffer as a [`RequesterEvent`].
1146    fn decode(
1147        mut buf: <fidl::encoding::DefaultFuchsiaResourceDialect as fidl::encoding::ResourceDialect>::MessageBufEtc,
1148    ) -> Result<RequesterEvent, fidl::Error> {
1149        let (bytes, _handles) = buf.split_mut();
1150        let (tx_header, _body_bytes) = fidl::encoding::decode_transaction_header(bytes)?;
1151        debug_assert_eq!(tx_header.tx_id, 0);
1152        match tx_header.ordinal {
1153            _ => Err(fidl::Error::UnknownOrdinal {
1154                ordinal: tx_header.ordinal,
1155                protocol_name: <RequesterMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME,
1156            }),
1157        }
1158    }
1159}
1160
1161/// A Stream of incoming requests for fuchsia.power.systemmode/Requester.
1162pub struct RequesterRequestStream {
1163    inner: std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>,
1164    is_terminated: bool,
1165}
1166
1167impl std::marker::Unpin for RequesterRequestStream {}
1168
1169impl futures::stream::FusedStream for RequesterRequestStream {
1170    fn is_terminated(&self) -> bool {
1171        self.is_terminated
1172    }
1173}
1174
1175impl fidl::endpoints::RequestStream for RequesterRequestStream {
1176    type Protocol = RequesterMarker;
1177    type ControlHandle = RequesterControlHandle;
1178
1179    fn from_channel(channel: ::fidl::AsyncChannel) -> Self {
1180        Self { inner: std::sync::Arc::new(fidl::ServeInner::new(channel)), is_terminated: false }
1181    }
1182
1183    fn control_handle(&self) -> Self::ControlHandle {
1184        RequesterControlHandle { inner: self.inner.clone() }
1185    }
1186
1187    fn into_inner(
1188        self,
1189    ) -> (::std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>, bool)
1190    {
1191        (self.inner, self.is_terminated)
1192    }
1193
1194    fn from_inner(
1195        inner: std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>,
1196        is_terminated: bool,
1197    ) -> Self {
1198        Self { inner, is_terminated }
1199    }
1200}
1201
1202impl futures::Stream for RequesterRequestStream {
1203    type Item = Result<RequesterRequest, fidl::Error>;
1204
1205    fn poll_next(
1206        mut self: std::pin::Pin<&mut Self>,
1207        cx: &mut std::task::Context<'_>,
1208    ) -> std::task::Poll<Option<Self::Item>> {
1209        let this = &mut *self;
1210        if this.inner.check_shutdown(cx) {
1211            this.is_terminated = true;
1212            return std::task::Poll::Ready(None);
1213        }
1214        if this.is_terminated {
1215            panic!("polled RequesterRequestStream after completion");
1216        }
1217        fidl::encoding::with_tls_decode_buf::<_, fidl::encoding::DefaultFuchsiaResourceDialect>(
1218            |bytes, handles| {
1219                match this.inner.channel().read_etc(cx, bytes, handles) {
1220                    std::task::Poll::Ready(Ok(())) => {}
1221                    std::task::Poll::Pending => return std::task::Poll::Pending,
1222                    std::task::Poll::Ready(Err(zx_status::Status::PEER_CLOSED)) => {
1223                        this.is_terminated = true;
1224                        return std::task::Poll::Ready(None);
1225                    }
1226                    std::task::Poll::Ready(Err(e)) => {
1227                        return std::task::Poll::Ready(Some(Err(fidl::Error::ServerRequestRead(
1228                            e.into(),
1229                        ))))
1230                    }
1231                }
1232
1233                // A message has been received from the channel
1234                let (header, _body_bytes) = fidl::encoding::decode_transaction_header(bytes)?;
1235
1236                std::task::Poll::Ready(Some(match header.ordinal {
1237                    0x5603afcd4421f425 => {
1238                        header.validate_request_tx_id(fidl::MethodType::TwoWay)?;
1239                        let mut req = fidl::new_empty!(
1240                            RequesterRequestRequest,
1241                            fidl::encoding::DefaultFuchsiaResourceDialect
1242                        );
1243                        fidl::encoding::Decoder::<fidl::encoding::DefaultFuchsiaResourceDialect>::decode_into::<RequesterRequestRequest>(&header, _body_bytes, handles, &mut req)?;
1244                        let control_handle = RequesterControlHandle { inner: this.inner.clone() };
1245                        Ok(RequesterRequest::Request {
1246                            mode: req.mode,
1247                            set: req.set,
1248
1249                            responder: RequesterRequestResponder {
1250                                control_handle: std::mem::ManuallyDrop::new(control_handle),
1251                                tx_id: header.tx_id,
1252                            },
1253                        })
1254                    }
1255                    _ => Err(fidl::Error::UnknownOrdinal {
1256                        ordinal: header.ordinal,
1257                        protocol_name:
1258                            <RequesterMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME,
1259                    }),
1260                }))
1261            },
1262        )
1263    }
1264}
1265
1266/// A protocol that can be used to request a change to the currently active
1267/// system power modes.
1268#[derive(Debug)]
1269pub enum RequesterRequest {
1270    /// Requests to set or clear a system power mode.
1271    ///
1272    /// The call returns immediately after the request has been received,
1273    /// validated, and accepted. Actual system changes to be applied as a result
1274    /// of this request will occur after the call has returned. Therefore, any
1275    /// errors that occur while updating clients according to the new system
1276    /// power mode are not propagated back to the caller. Instead, client
1277    /// updates are applied on a "best effort" basis.
1278    ///
1279    /// An error returned by this method means the request itself is not valid
1280    /// and was rejected. Details of the specific rejection reason are reflected
1281    /// by the error value. In the event of an error, the channel will remain
1282    /// open.
1283    ///
1284    /// A client can use this method to set or clear system power mode variants
1285    /// independently. For example:
1286    ///
1287    ///   // battery is below the "low" threshold
1288    ///   Request(LOW_BATTERY, true);
1289    ///
1290    ///   // device is now plugged into the wall
1291    ///   Request(ON_AC_POWER, true);
1292    ///
1293    ///   // battery is now above the "low" threshold
1294    ///   Request(LOW_BATTERY, false);
1295    ///
1296    /// + `mode` is the `SystemMode` to request to be set or cleared
1297    /// + `set` should be true to request to set `mode`, or false to clear it
1298    /// * error a [`ModeRequestError`] value indicating why the request was
1299    /// rejected.
1300    Request { mode: SystemMode, set: bool, responder: RequesterRequestResponder },
1301}
1302
1303impl RequesterRequest {
1304    #[allow(irrefutable_let_patterns)]
1305    pub fn into_request(self) -> Option<(SystemMode, bool, RequesterRequestResponder)> {
1306        if let RequesterRequest::Request { mode, set, responder } = self {
1307            Some((mode, set, responder))
1308        } else {
1309            None
1310        }
1311    }
1312
1313    /// Name of the method defined in FIDL
1314    pub fn method_name(&self) -> &'static str {
1315        match *self {
1316            RequesterRequest::Request { .. } => "request",
1317        }
1318    }
1319}
1320
1321#[derive(Debug, Clone)]
1322pub struct RequesterControlHandle {
1323    inner: std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>,
1324}
1325
1326impl fidl::endpoints::ControlHandle for RequesterControlHandle {
1327    fn shutdown(&self) {
1328        self.inner.shutdown()
1329    }
1330    fn shutdown_with_epitaph(&self, status: zx_status::Status) {
1331        self.inner.shutdown_with_epitaph(status)
1332    }
1333
1334    fn is_closed(&self) -> bool {
1335        self.inner.channel().is_closed()
1336    }
1337    fn on_closed(&self) -> fidl::OnSignalsRef<'_> {
1338        self.inner.channel().on_closed()
1339    }
1340
1341    #[cfg(target_os = "fuchsia")]
1342    fn signal_peer(
1343        &self,
1344        clear_mask: zx::Signals,
1345        set_mask: zx::Signals,
1346    ) -> Result<(), zx_status::Status> {
1347        use fidl::Peered;
1348        self.inner.channel().signal_peer(clear_mask, set_mask)
1349    }
1350}
1351
1352impl RequesterControlHandle {}
1353
1354#[must_use = "FIDL methods require a response to be sent"]
1355#[derive(Debug)]
1356pub struct RequesterRequestResponder {
1357    control_handle: std::mem::ManuallyDrop<RequesterControlHandle>,
1358    tx_id: u32,
1359}
1360
1361/// Set the the channel to be shutdown (see [`RequesterControlHandle::shutdown`])
1362/// if the responder is dropped without sending a response, so that the client
1363/// doesn't hang. To prevent this behavior, call `drop_without_shutdown`.
1364impl std::ops::Drop for RequesterRequestResponder {
1365    fn drop(&mut self) {
1366        self.control_handle.shutdown();
1367        // Safety: drops once, never accessed again
1368        unsafe { std::mem::ManuallyDrop::drop(&mut self.control_handle) };
1369    }
1370}
1371
1372impl fidl::endpoints::Responder for RequesterRequestResponder {
1373    type ControlHandle = RequesterControlHandle;
1374
1375    fn control_handle(&self) -> &RequesterControlHandle {
1376        &self.control_handle
1377    }
1378
1379    fn drop_without_shutdown(mut self) {
1380        // Safety: drops once, never accessed again due to mem::forget
1381        unsafe { std::mem::ManuallyDrop::drop(&mut self.control_handle) };
1382        // Prevent Drop from running (which would shut down the channel)
1383        std::mem::forget(self);
1384    }
1385}
1386
1387impl RequesterRequestResponder {
1388    /// Sends a response to the FIDL transaction.
1389    ///
1390    /// Sets the channel to shutdown if an error occurs.
1391    pub fn send(self, mut result: Result<(), ModeRequestError>) -> Result<(), fidl::Error> {
1392        let _result = self.send_raw(result);
1393        if _result.is_err() {
1394            self.control_handle.shutdown();
1395        }
1396        self.drop_without_shutdown();
1397        _result
1398    }
1399
1400    /// Similar to "send" but does not shutdown the channel if an error occurs.
1401    pub fn send_no_shutdown_on_err(
1402        self,
1403        mut result: Result<(), ModeRequestError>,
1404    ) -> Result<(), fidl::Error> {
1405        let _result = self.send_raw(result);
1406        self.drop_without_shutdown();
1407        _result
1408    }
1409
1410    fn send_raw(&self, mut result: Result<(), ModeRequestError>) -> Result<(), fidl::Error> {
1411        self.control_handle.inner.send::<fidl::encoding::ResultType<
1412            fidl::encoding::EmptyStruct,
1413            ModeRequestError,
1414        >>(
1415            result,
1416            self.tx_id,
1417            0x5603afcd4421f425,
1418            fidl::encoding::DynamicFlags::empty(),
1419        )
1420    }
1421}
1422
1423mod internal {
1424    use super::*;
1425    unsafe impl fidl::encoding::TypeMarker for ModeRequestError {
1426        type Owned = Self;
1427
1428        #[inline(always)]
1429        fn inline_align(_context: fidl::encoding::Context) -> usize {
1430            std::mem::align_of::<u32>()
1431        }
1432
1433        #[inline(always)]
1434        fn inline_size(_context: fidl::encoding::Context) -> usize {
1435            std::mem::size_of::<u32>()
1436        }
1437
1438        #[inline(always)]
1439        fn encode_is_copy() -> bool {
1440            false
1441        }
1442
1443        #[inline(always)]
1444        fn decode_is_copy() -> bool {
1445            false
1446        }
1447    }
1448
1449    impl fidl::encoding::ValueTypeMarker for ModeRequestError {
1450        type Borrowed<'a> = Self;
1451        #[inline(always)]
1452        fn borrow(value: &<Self as fidl::encoding::TypeMarker>::Owned) -> Self::Borrowed<'_> {
1453            *value
1454        }
1455    }
1456
1457    unsafe impl<D: fidl::encoding::ResourceDialect> fidl::encoding::Encode<Self, D>
1458        for ModeRequestError
1459    {
1460        #[inline]
1461        unsafe fn encode(
1462            self,
1463            encoder: &mut fidl::encoding::Encoder<'_, D>,
1464            offset: usize,
1465            _depth: fidl::encoding::Depth,
1466        ) -> fidl::Result<()> {
1467            encoder.debug_check_bounds::<Self>(offset);
1468            encoder.write_num(self.into_primitive(), offset);
1469            Ok(())
1470        }
1471    }
1472
1473    impl<D: fidl::encoding::ResourceDialect> fidl::encoding::Decode<Self, D> for ModeRequestError {
1474        #[inline(always)]
1475        fn new_empty() -> Self {
1476            Self::unknown()
1477        }
1478
1479        #[inline]
1480        unsafe fn decode(
1481            &mut self,
1482            decoder: &mut fidl::encoding::Decoder<'_, D>,
1483            offset: usize,
1484            _depth: fidl::encoding::Depth,
1485        ) -> fidl::Result<()> {
1486            decoder.debug_check_bounds::<Self>(offset);
1487            let prim = decoder.read_num::<u32>(offset);
1488
1489            *self = Self::from_primitive_allow_unknown(prim);
1490            Ok(())
1491        }
1492    }
1493    unsafe impl fidl::encoding::TypeMarker for SystemMode {
1494        type Owned = Self;
1495
1496        #[inline(always)]
1497        fn inline_align(_context: fidl::encoding::Context) -> usize {
1498            std::mem::align_of::<u32>()
1499        }
1500
1501        #[inline(always)]
1502        fn inline_size(_context: fidl::encoding::Context) -> usize {
1503            std::mem::size_of::<u32>()
1504        }
1505
1506        #[inline(always)]
1507        fn encode_is_copy() -> bool {
1508            false
1509        }
1510
1511        #[inline(always)]
1512        fn decode_is_copy() -> bool {
1513            false
1514        }
1515    }
1516
1517    impl fidl::encoding::ValueTypeMarker for SystemMode {
1518        type Borrowed<'a> = Self;
1519        #[inline(always)]
1520        fn borrow(value: &<Self as fidl::encoding::TypeMarker>::Owned) -> Self::Borrowed<'_> {
1521            *value
1522        }
1523    }
1524
1525    unsafe impl<D: fidl::encoding::ResourceDialect> fidl::encoding::Encode<Self, D> for SystemMode {
1526        #[inline]
1527        unsafe fn encode(
1528            self,
1529            encoder: &mut fidl::encoding::Encoder<'_, D>,
1530            offset: usize,
1531            _depth: fidl::encoding::Depth,
1532        ) -> fidl::Result<()> {
1533            encoder.debug_check_bounds::<Self>(offset);
1534            encoder.write_num(self.into_primitive(), offset);
1535            Ok(())
1536        }
1537    }
1538
1539    impl<D: fidl::encoding::ResourceDialect> fidl::encoding::Decode<Self, D> for SystemMode {
1540        #[inline(always)]
1541        fn new_empty() -> Self {
1542            Self::unknown()
1543        }
1544
1545        #[inline]
1546        unsafe fn decode(
1547            &mut self,
1548            decoder: &mut fidl::encoding::Decoder<'_, D>,
1549            offset: usize,
1550            _depth: fidl::encoding::Depth,
1551        ) -> fidl::Result<()> {
1552            decoder.debug_check_bounds::<Self>(offset);
1553            let prim = decoder.read_num::<u32>(offset);
1554
1555            *self = Self::from_primitive_allow_unknown(prim);
1556            Ok(())
1557        }
1558    }
1559
1560    impl fidl::encoding::ValueTypeMarker for ClientConfig {
1561        type Borrowed<'a> = &'a Self;
1562        fn borrow(value: &<Self as fidl::encoding::TypeMarker>::Owned) -> Self::Borrowed<'_> {
1563            value
1564        }
1565    }
1566
1567    unsafe impl fidl::encoding::TypeMarker for ClientConfig {
1568        type Owned = Self;
1569
1570        #[inline(always)]
1571        fn inline_align(_context: fidl::encoding::Context) -> usize {
1572            8
1573        }
1574
1575        #[inline(always)]
1576        fn inline_size(_context: fidl::encoding::Context) -> usize {
1577            24
1578        }
1579    }
1580
1581    unsafe impl<D: fidl::encoding::ResourceDialect> fidl::encoding::Encode<ClientConfig, D>
1582        for &ClientConfig
1583    {
1584        #[inline]
1585        unsafe fn encode(
1586            self,
1587            encoder: &mut fidl::encoding::Encoder<'_, D>,
1588            offset: usize,
1589            _depth: fidl::encoding::Depth,
1590        ) -> fidl::Result<()> {
1591            encoder.debug_check_bounds::<ClientConfig>(offset);
1592            // Delegate to tuple encoding.
1593            fidl::encoding::Encode::<ClientConfig, D>::encode(
1594                (
1595                    <fidl::encoding::Vector<ModeMatch, 0> as fidl::encoding::ValueTypeMarker>::borrow(&self.mode_matches),
1596                    <u64 as fidl::encoding::ValueTypeMarker>::borrow(&self.default_level),
1597                ),
1598                encoder, offset, _depth
1599            )
1600        }
1601    }
1602    unsafe impl<
1603            D: fidl::encoding::ResourceDialect,
1604            T0: fidl::encoding::Encode<fidl::encoding::Vector<ModeMatch, 0>, D>,
1605            T1: fidl::encoding::Encode<u64, D>,
1606        > fidl::encoding::Encode<ClientConfig, D> for (T0, T1)
1607    {
1608        #[inline]
1609        unsafe fn encode(
1610            self,
1611            encoder: &mut fidl::encoding::Encoder<'_, D>,
1612            offset: usize,
1613            depth: fidl::encoding::Depth,
1614        ) -> fidl::Result<()> {
1615            encoder.debug_check_bounds::<ClientConfig>(offset);
1616            // Zero out padding regions. There's no need to apply masks
1617            // because the unmasked parts will be overwritten by fields.
1618            // Write the fields.
1619            self.0.encode(encoder, offset + 0, depth)?;
1620            self.1.encode(encoder, offset + 16, depth)?;
1621            Ok(())
1622        }
1623    }
1624
1625    impl<D: fidl::encoding::ResourceDialect> fidl::encoding::Decode<Self, D> for ClientConfig {
1626        #[inline(always)]
1627        fn new_empty() -> Self {
1628            Self {
1629                mode_matches: fidl::new_empty!(fidl::encoding::Vector<ModeMatch, 0>, D),
1630                default_level: fidl::new_empty!(u64, D),
1631            }
1632        }
1633
1634        #[inline]
1635        unsafe fn decode(
1636            &mut self,
1637            decoder: &mut fidl::encoding::Decoder<'_, D>,
1638            offset: usize,
1639            _depth: fidl::encoding::Depth,
1640        ) -> fidl::Result<()> {
1641            decoder.debug_check_bounds::<Self>(offset);
1642            // Verify that padding bytes are zero.
1643            fidl::decode!(fidl::encoding::Vector<ModeMatch, 0>, D, &mut self.mode_matches, decoder, offset + 0, _depth)?;
1644            fidl::decode!(u64, D, &mut self.default_level, decoder, offset + 16, _depth)?;
1645            Ok(())
1646        }
1647    }
1648
1649    impl fidl::encoding::ValueTypeMarker for ClientConfiguratorGetRequest {
1650        type Borrowed<'a> = &'a Self;
1651        fn borrow(value: &<Self as fidl::encoding::TypeMarker>::Owned) -> Self::Borrowed<'_> {
1652            value
1653        }
1654    }
1655
1656    unsafe impl fidl::encoding::TypeMarker for ClientConfiguratorGetRequest {
1657        type Owned = Self;
1658
1659        #[inline(always)]
1660        fn inline_align(_context: fidl::encoding::Context) -> usize {
1661            4
1662        }
1663
1664        #[inline(always)]
1665        fn inline_size(_context: fidl::encoding::Context) -> usize {
1666            4
1667        }
1668    }
1669
1670    unsafe impl<D: fidl::encoding::ResourceDialect>
1671        fidl::encoding::Encode<ClientConfiguratorGetRequest, D> for &ClientConfiguratorGetRequest
1672    {
1673        #[inline]
1674        unsafe fn encode(
1675            self,
1676            encoder: &mut fidl::encoding::Encoder<'_, D>,
1677            offset: usize,
1678            _depth: fidl::encoding::Depth,
1679        ) -> fidl::Result<()> {
1680            encoder.debug_check_bounds::<ClientConfiguratorGetRequest>(offset);
1681            // Delegate to tuple encoding.
1682            fidl::encoding::Encode::<ClientConfiguratorGetRequest, D>::encode(
1683                (
1684                    <fidl_fuchsia_power_clientlevel::ClientType as fidl::encoding::ValueTypeMarker>::borrow(&self.client_type),
1685                ),
1686                encoder, offset, _depth
1687            )
1688        }
1689    }
1690    unsafe impl<
1691            D: fidl::encoding::ResourceDialect,
1692            T0: fidl::encoding::Encode<fidl_fuchsia_power_clientlevel::ClientType, D>,
1693        > fidl::encoding::Encode<ClientConfiguratorGetRequest, D> for (T0,)
1694    {
1695        #[inline]
1696        unsafe fn encode(
1697            self,
1698            encoder: &mut fidl::encoding::Encoder<'_, D>,
1699            offset: usize,
1700            depth: fidl::encoding::Depth,
1701        ) -> fidl::Result<()> {
1702            encoder.debug_check_bounds::<ClientConfiguratorGetRequest>(offset);
1703            // Zero out padding regions. There's no need to apply masks
1704            // because the unmasked parts will be overwritten by fields.
1705            // Write the fields.
1706            self.0.encode(encoder, offset + 0, depth)?;
1707            Ok(())
1708        }
1709    }
1710
1711    impl<D: fidl::encoding::ResourceDialect> fidl::encoding::Decode<Self, D>
1712        for ClientConfiguratorGetRequest
1713    {
1714        #[inline(always)]
1715        fn new_empty() -> Self {
1716            Self { client_type: fidl::new_empty!(fidl_fuchsia_power_clientlevel::ClientType, D) }
1717        }
1718
1719        #[inline]
1720        unsafe fn decode(
1721            &mut self,
1722            decoder: &mut fidl::encoding::Decoder<'_, D>,
1723            offset: usize,
1724            _depth: fidl::encoding::Depth,
1725        ) -> fidl::Result<()> {
1726            decoder.debug_check_bounds::<Self>(offset);
1727            // Verify that padding bytes are zero.
1728            fidl::decode!(
1729                fidl_fuchsia_power_clientlevel::ClientType,
1730                D,
1731                &mut self.client_type,
1732                decoder,
1733                offset + 0,
1734                _depth
1735            )?;
1736            Ok(())
1737        }
1738    }
1739
1740    impl fidl::encoding::ValueTypeMarker for ClientConfiguratorGetResponse {
1741        type Borrowed<'a> = &'a Self;
1742        fn borrow(value: &<Self as fidl::encoding::TypeMarker>::Owned) -> Self::Borrowed<'_> {
1743            value
1744        }
1745    }
1746
1747    unsafe impl fidl::encoding::TypeMarker for ClientConfiguratorGetResponse {
1748        type Owned = Self;
1749
1750        #[inline(always)]
1751        fn inline_align(_context: fidl::encoding::Context) -> usize {
1752            8
1753        }
1754
1755        #[inline(always)]
1756        fn inline_size(_context: fidl::encoding::Context) -> usize {
1757            8
1758        }
1759    }
1760
1761    unsafe impl<D: fidl::encoding::ResourceDialect>
1762        fidl::encoding::Encode<ClientConfiguratorGetResponse, D>
1763        for &ClientConfiguratorGetResponse
1764    {
1765        #[inline]
1766        unsafe fn encode(
1767            self,
1768            encoder: &mut fidl::encoding::Encoder<'_, D>,
1769            offset: usize,
1770            _depth: fidl::encoding::Depth,
1771        ) -> fidl::Result<()> {
1772            encoder.debug_check_bounds::<ClientConfiguratorGetResponse>(offset);
1773            // Delegate to tuple encoding.
1774            fidl::encoding::Encode::<ClientConfiguratorGetResponse, D>::encode(
1775                (<fidl::encoding::Boxed<ClientConfig> as fidl::encoding::ValueTypeMarker>::borrow(
1776                    &self.config,
1777                ),),
1778                encoder,
1779                offset,
1780                _depth,
1781            )
1782        }
1783    }
1784    unsafe impl<
1785            D: fidl::encoding::ResourceDialect,
1786            T0: fidl::encoding::Encode<fidl::encoding::Boxed<ClientConfig>, D>,
1787        > fidl::encoding::Encode<ClientConfiguratorGetResponse, D> for (T0,)
1788    {
1789        #[inline]
1790        unsafe fn encode(
1791            self,
1792            encoder: &mut fidl::encoding::Encoder<'_, D>,
1793            offset: usize,
1794            depth: fidl::encoding::Depth,
1795        ) -> fidl::Result<()> {
1796            encoder.debug_check_bounds::<ClientConfiguratorGetResponse>(offset);
1797            // Zero out padding regions. There's no need to apply masks
1798            // because the unmasked parts will be overwritten by fields.
1799            // Write the fields.
1800            self.0.encode(encoder, offset + 0, depth)?;
1801            Ok(())
1802        }
1803    }
1804
1805    impl<D: fidl::encoding::ResourceDialect> fidl::encoding::Decode<Self, D>
1806        for ClientConfiguratorGetResponse
1807    {
1808        #[inline(always)]
1809        fn new_empty() -> Self {
1810            Self { config: fidl::new_empty!(fidl::encoding::Boxed<ClientConfig>, D) }
1811        }
1812
1813        #[inline]
1814        unsafe fn decode(
1815            &mut self,
1816            decoder: &mut fidl::encoding::Decoder<'_, D>,
1817            offset: usize,
1818            _depth: fidl::encoding::Depth,
1819        ) -> fidl::Result<()> {
1820            decoder.debug_check_bounds::<Self>(offset);
1821            // Verify that padding bytes are zero.
1822            fidl::decode!(
1823                fidl::encoding::Boxed<ClientConfig>,
1824                D,
1825                &mut self.config,
1826                decoder,
1827                offset + 0,
1828                _depth
1829            )?;
1830            Ok(())
1831        }
1832    }
1833
1834    impl fidl::encoding::ValueTypeMarker for ClientConfiguratorSetRequest {
1835        type Borrowed<'a> = &'a Self;
1836        fn borrow(value: &<Self as fidl::encoding::TypeMarker>::Owned) -> Self::Borrowed<'_> {
1837            value
1838        }
1839    }
1840
1841    unsafe impl fidl::encoding::TypeMarker for ClientConfiguratorSetRequest {
1842        type Owned = Self;
1843
1844        #[inline(always)]
1845        fn inline_align(_context: fidl::encoding::Context) -> usize {
1846            8
1847        }
1848
1849        #[inline(always)]
1850        fn inline_size(_context: fidl::encoding::Context) -> usize {
1851            32
1852        }
1853    }
1854
1855    unsafe impl<D: fidl::encoding::ResourceDialect>
1856        fidl::encoding::Encode<ClientConfiguratorSetRequest, D> for &ClientConfiguratorSetRequest
1857    {
1858        #[inline]
1859        unsafe fn encode(
1860            self,
1861            encoder: &mut fidl::encoding::Encoder<'_, D>,
1862            offset: usize,
1863            _depth: fidl::encoding::Depth,
1864        ) -> fidl::Result<()> {
1865            encoder.debug_check_bounds::<ClientConfiguratorSetRequest>(offset);
1866            // Delegate to tuple encoding.
1867            fidl::encoding::Encode::<ClientConfiguratorSetRequest, D>::encode(
1868                (
1869                    <fidl_fuchsia_power_clientlevel::ClientType as fidl::encoding::ValueTypeMarker>::borrow(&self.client_type),
1870                    <ClientConfig as fidl::encoding::ValueTypeMarker>::borrow(&self.config),
1871                ),
1872                encoder, offset, _depth
1873            )
1874        }
1875    }
1876    unsafe impl<
1877            D: fidl::encoding::ResourceDialect,
1878            T0: fidl::encoding::Encode<fidl_fuchsia_power_clientlevel::ClientType, D>,
1879            T1: fidl::encoding::Encode<ClientConfig, D>,
1880        > fidl::encoding::Encode<ClientConfiguratorSetRequest, D> for (T0, T1)
1881    {
1882        #[inline]
1883        unsafe fn encode(
1884            self,
1885            encoder: &mut fidl::encoding::Encoder<'_, D>,
1886            offset: usize,
1887            depth: fidl::encoding::Depth,
1888        ) -> fidl::Result<()> {
1889            encoder.debug_check_bounds::<ClientConfiguratorSetRequest>(offset);
1890            // Zero out padding regions. There's no need to apply masks
1891            // because the unmasked parts will be overwritten by fields.
1892            unsafe {
1893                let ptr = encoder.buf.as_mut_ptr().add(offset).offset(0);
1894                (ptr as *mut u64).write_unaligned(0);
1895            }
1896            // Write the fields.
1897            self.0.encode(encoder, offset + 0, depth)?;
1898            self.1.encode(encoder, offset + 8, depth)?;
1899            Ok(())
1900        }
1901    }
1902
1903    impl<D: fidl::encoding::ResourceDialect> fidl::encoding::Decode<Self, D>
1904        for ClientConfiguratorSetRequest
1905    {
1906        #[inline(always)]
1907        fn new_empty() -> Self {
1908            Self {
1909                client_type: fidl::new_empty!(fidl_fuchsia_power_clientlevel::ClientType, D),
1910                config: fidl::new_empty!(ClientConfig, D),
1911            }
1912        }
1913
1914        #[inline]
1915        unsafe fn decode(
1916            &mut self,
1917            decoder: &mut fidl::encoding::Decoder<'_, D>,
1918            offset: usize,
1919            _depth: fidl::encoding::Depth,
1920        ) -> fidl::Result<()> {
1921            decoder.debug_check_bounds::<Self>(offset);
1922            // Verify that padding bytes are zero.
1923            let ptr = unsafe { decoder.buf.as_ptr().add(offset).offset(0) };
1924            let padval = unsafe { (ptr as *const u64).read_unaligned() };
1925            let mask = 0xffffffff00000000u64;
1926            let maskedval = padval & mask;
1927            if maskedval != 0 {
1928                return Err(fidl::Error::NonZeroPadding {
1929                    padding_start: offset + 0 + ((mask as u64).trailing_zeros() / 8) as usize,
1930                });
1931            }
1932            fidl::decode!(
1933                fidl_fuchsia_power_clientlevel::ClientType,
1934                D,
1935                &mut self.client_type,
1936                decoder,
1937                offset + 0,
1938                _depth
1939            )?;
1940            fidl::decode!(ClientConfig, D, &mut self.config, decoder, offset + 8, _depth)?;
1941            Ok(())
1942        }
1943    }
1944
1945    impl fidl::encoding::ValueTypeMarker for ModeMatch {
1946        type Borrowed<'a> = &'a Self;
1947        fn borrow(value: &<Self as fidl::encoding::TypeMarker>::Owned) -> Self::Borrowed<'_> {
1948            value
1949        }
1950    }
1951
1952    unsafe impl fidl::encoding::TypeMarker for ModeMatch {
1953        type Owned = Self;
1954
1955        #[inline(always)]
1956        fn inline_align(_context: fidl::encoding::Context) -> usize {
1957            8
1958        }
1959
1960        #[inline(always)]
1961        fn inline_size(_context: fidl::encoding::Context) -> usize {
1962            16
1963        }
1964    }
1965
1966    unsafe impl<D: fidl::encoding::ResourceDialect> fidl::encoding::Encode<ModeMatch, D>
1967        for &ModeMatch
1968    {
1969        #[inline]
1970        unsafe fn encode(
1971            self,
1972            encoder: &mut fidl::encoding::Encoder<'_, D>,
1973            offset: usize,
1974            _depth: fidl::encoding::Depth,
1975        ) -> fidl::Result<()> {
1976            encoder.debug_check_bounds::<ModeMatch>(offset);
1977            // Delegate to tuple encoding.
1978            fidl::encoding::Encode::<ModeMatch, D>::encode(
1979                (
1980                    <SystemMode as fidl::encoding::ValueTypeMarker>::borrow(&self.mode),
1981                    <u64 as fidl::encoding::ValueTypeMarker>::borrow(&self.power_level),
1982                ),
1983                encoder,
1984                offset,
1985                _depth,
1986            )
1987        }
1988    }
1989    unsafe impl<
1990            D: fidl::encoding::ResourceDialect,
1991            T0: fidl::encoding::Encode<SystemMode, D>,
1992            T1: fidl::encoding::Encode<u64, D>,
1993        > fidl::encoding::Encode<ModeMatch, D> for (T0, T1)
1994    {
1995        #[inline]
1996        unsafe fn encode(
1997            self,
1998            encoder: &mut fidl::encoding::Encoder<'_, D>,
1999            offset: usize,
2000            depth: fidl::encoding::Depth,
2001        ) -> fidl::Result<()> {
2002            encoder.debug_check_bounds::<ModeMatch>(offset);
2003            // Zero out padding regions. There's no need to apply masks
2004            // because the unmasked parts will be overwritten by fields.
2005            unsafe {
2006                let ptr = encoder.buf.as_mut_ptr().add(offset).offset(0);
2007                (ptr as *mut u64).write_unaligned(0);
2008            }
2009            // Write the fields.
2010            self.0.encode(encoder, offset + 0, depth)?;
2011            self.1.encode(encoder, offset + 8, depth)?;
2012            Ok(())
2013        }
2014    }
2015
2016    impl<D: fidl::encoding::ResourceDialect> fidl::encoding::Decode<Self, D> for ModeMatch {
2017        #[inline(always)]
2018        fn new_empty() -> Self {
2019            Self { mode: fidl::new_empty!(SystemMode, D), power_level: fidl::new_empty!(u64, D) }
2020        }
2021
2022        #[inline]
2023        unsafe fn decode(
2024            &mut self,
2025            decoder: &mut fidl::encoding::Decoder<'_, D>,
2026            offset: usize,
2027            _depth: fidl::encoding::Depth,
2028        ) -> fidl::Result<()> {
2029            decoder.debug_check_bounds::<Self>(offset);
2030            // Verify that padding bytes are zero.
2031            let ptr = unsafe { decoder.buf.as_ptr().add(offset).offset(0) };
2032            let padval = unsafe { (ptr as *const u64).read_unaligned() };
2033            let mask = 0xffffffff00000000u64;
2034            let maskedval = padval & mask;
2035            if maskedval != 0 {
2036                return Err(fidl::Error::NonZeroPadding {
2037                    padding_start: offset + 0 + ((mask as u64).trailing_zeros() / 8) as usize,
2038                });
2039            }
2040            fidl::decode!(SystemMode, D, &mut self.mode, decoder, offset + 0, _depth)?;
2041            fidl::decode!(u64, D, &mut self.power_level, decoder, offset + 8, _depth)?;
2042            Ok(())
2043        }
2044    }
2045
2046    impl fidl::encoding::ValueTypeMarker for RequesterRequestRequest {
2047        type Borrowed<'a> = &'a Self;
2048        fn borrow(value: &<Self as fidl::encoding::TypeMarker>::Owned) -> Self::Borrowed<'_> {
2049            value
2050        }
2051    }
2052
2053    unsafe impl fidl::encoding::TypeMarker for RequesterRequestRequest {
2054        type Owned = Self;
2055
2056        #[inline(always)]
2057        fn inline_align(_context: fidl::encoding::Context) -> usize {
2058            4
2059        }
2060
2061        #[inline(always)]
2062        fn inline_size(_context: fidl::encoding::Context) -> usize {
2063            8
2064        }
2065    }
2066
2067    unsafe impl<D: fidl::encoding::ResourceDialect>
2068        fidl::encoding::Encode<RequesterRequestRequest, D> for &RequesterRequestRequest
2069    {
2070        #[inline]
2071        unsafe fn encode(
2072            self,
2073            encoder: &mut fidl::encoding::Encoder<'_, D>,
2074            offset: usize,
2075            _depth: fidl::encoding::Depth,
2076        ) -> fidl::Result<()> {
2077            encoder.debug_check_bounds::<RequesterRequestRequest>(offset);
2078            // Delegate to tuple encoding.
2079            fidl::encoding::Encode::<RequesterRequestRequest, D>::encode(
2080                (
2081                    <SystemMode as fidl::encoding::ValueTypeMarker>::borrow(&self.mode),
2082                    <bool as fidl::encoding::ValueTypeMarker>::borrow(&self.set),
2083                ),
2084                encoder,
2085                offset,
2086                _depth,
2087            )
2088        }
2089    }
2090    unsafe impl<
2091            D: fidl::encoding::ResourceDialect,
2092            T0: fidl::encoding::Encode<SystemMode, D>,
2093            T1: fidl::encoding::Encode<bool, D>,
2094        > fidl::encoding::Encode<RequesterRequestRequest, D> for (T0, T1)
2095    {
2096        #[inline]
2097        unsafe fn encode(
2098            self,
2099            encoder: &mut fidl::encoding::Encoder<'_, D>,
2100            offset: usize,
2101            depth: fidl::encoding::Depth,
2102        ) -> fidl::Result<()> {
2103            encoder.debug_check_bounds::<RequesterRequestRequest>(offset);
2104            // Zero out padding regions. There's no need to apply masks
2105            // because the unmasked parts will be overwritten by fields.
2106            unsafe {
2107                let ptr = encoder.buf.as_mut_ptr().add(offset).offset(4);
2108                (ptr as *mut u32).write_unaligned(0);
2109            }
2110            // Write the fields.
2111            self.0.encode(encoder, offset + 0, depth)?;
2112            self.1.encode(encoder, offset + 4, depth)?;
2113            Ok(())
2114        }
2115    }
2116
2117    impl<D: fidl::encoding::ResourceDialect> fidl::encoding::Decode<Self, D>
2118        for RequesterRequestRequest
2119    {
2120        #[inline(always)]
2121        fn new_empty() -> Self {
2122            Self { mode: fidl::new_empty!(SystemMode, D), set: fidl::new_empty!(bool, D) }
2123        }
2124
2125        #[inline]
2126        unsafe fn decode(
2127            &mut self,
2128            decoder: &mut fidl::encoding::Decoder<'_, D>,
2129            offset: usize,
2130            _depth: fidl::encoding::Depth,
2131        ) -> fidl::Result<()> {
2132            decoder.debug_check_bounds::<Self>(offset);
2133            // Verify that padding bytes are zero.
2134            let ptr = unsafe { decoder.buf.as_ptr().add(offset).offset(4) };
2135            let padval = unsafe { (ptr as *const u32).read_unaligned() };
2136            let mask = 0xffffff00u32;
2137            let maskedval = padval & mask;
2138            if maskedval != 0 {
2139                return Err(fidl::Error::NonZeroPadding {
2140                    padding_start: offset + 4 + ((mask as u64).trailing_zeros() / 8) as usize,
2141                });
2142            }
2143            fidl::decode!(SystemMode, D, &mut self.mode, decoder, offset + 0, _depth)?;
2144            fidl::decode!(bool, D, &mut self.set, decoder, offset + 4, _depth)?;
2145            Ok(())
2146        }
2147    }
2148}