fidl_fuchsia_time_alarms/
fidl_fuchsia_time_alarms.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_time_alarms__common::*;
11use futures::future::{self, MaybeDone, TryFutureExt};
12use zx_status;
13
14#[derive(Debug, Eq, Hash, Ord, PartialEq, PartialOrd)]
15pub struct ClientSideBatonManagementSetAndWaitResponse {
16    /// Used by the caller to ensure a minimum time slice for useful work,
17    /// before the system may suspend again.
18    pub keep_alive: fidl::EventPair,
19}
20
21impl fidl::Standalone<fidl::encoding::DefaultFuchsiaResourceDialect>
22    for ClientSideBatonManagementSetAndWaitResponse
23{
24}
25
26#[derive(Debug, PartialEq)]
27pub struct SetAndWaitArgs {
28    /// The deadline at which the timer is supposed to fire.
29    pub deadline: fidl::BootInstant,
30    /// Optional mode that allows the API to support a number of use cases.
31    pub mode: SetAndWaitMode,
32    /// Set to a nonempty value to identify the alarm. A unique value
33    /// of [AlarmId] must be picked per each unique alarm within a
34    /// single FIDL connection's scope.
35    ///
36    /// Supplying an alarm_id for an already scheduled alarm will reschedule
37    /// that alarm.
38    pub alarm_id: String,
39}
40
41impl fidl::Standalone<fidl::encoding::DefaultFuchsiaResourceDialect> for SetAndWaitArgs {}
42
43#[derive(Debug)]
44pub enum SetAndWaitMode {
45    /// This lease is dropped as immediately after the alarm is scheduled
46    /// (or an error occurs during scheduling), thus guaranteeing that the
47    /// alarm is scheduled before the system is suspended.
48    KeepAlive(fidl::EventPair),
49    /// The callee signals this event (with ZX_EVENT_SIGNALED) once the alarm
50    /// is scheduled. This indicates that the caller can drop any pending wake
51    /// leases related to this call.
52    NotifySetupDone(fidl::Event),
53    #[doc(hidden)]
54    __SourceBreaking { unknown_ordinal: u64 },
55}
56
57/// Pattern that matches an unknown `SetAndWaitMode` member.
58#[macro_export]
59macro_rules! SetAndWaitModeUnknown {
60    () => {
61        _
62    };
63}
64
65// Custom PartialEq so that unknown variants are not equal to themselves.
66impl PartialEq for SetAndWaitMode {
67    fn eq(&self, other: &Self) -> bool {
68        match (self, other) {
69            (Self::KeepAlive(x), Self::KeepAlive(y)) => *x == *y,
70            (Self::NotifySetupDone(x), Self::NotifySetupDone(y)) => *x == *y,
71            _ => false,
72        }
73    }
74}
75
76impl SetAndWaitMode {
77    #[inline]
78    pub fn ordinal(&self) -> u64 {
79        match *self {
80            Self::KeepAlive(_) => 1,
81            Self::NotifySetupDone(_) => 2,
82            Self::__SourceBreaking { unknown_ordinal } => unknown_ordinal,
83        }
84    }
85
86    #[inline]
87    pub fn unknown_variant_for_testing() -> Self {
88        Self::__SourceBreaking { unknown_ordinal: 0 }
89    }
90
91    #[inline]
92    pub fn is_unknown(&self) -> bool {
93        match self {
94            Self::__SourceBreaking { .. } => true,
95            _ => false,
96        }
97    }
98}
99
100impl fidl::Standalone<fidl::encoding::DefaultFuchsiaResourceDialect> for SetAndWaitMode {}
101
102#[derive(Debug, Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Hash)]
103pub struct ClientSideBatonManagementMarker;
104
105impl fidl::endpoints::ProtocolMarker for ClientSideBatonManagementMarker {
106    type Proxy = ClientSideBatonManagementProxy;
107    type RequestStream = ClientSideBatonManagementRequestStream;
108    #[cfg(target_os = "fuchsia")]
109    type SynchronousProxy = ClientSideBatonManagementSynchronousProxy;
110
111    const DEBUG_NAME: &'static str = "(anonymous) ClientSideBatonManagement";
112}
113pub type ClientSideBatonManagementSetAndWaitResult = Result<fidl::EventPair, WakeError>;
114
115pub trait ClientSideBatonManagementProxyInterface: Send + Sync {
116    type SetAndWaitResponseFut: std::future::Future<Output = Result<ClientSideBatonManagementSetAndWaitResult, fidl::Error>>
117        + Send;
118    fn r#set_and_wait(
119        &self,
120        deadline: fidl::BootInstant,
121        mode: SetAndWaitMode,
122        alarm_id: &str,
123    ) -> Self::SetAndWaitResponseFut;
124    fn r#cancel(&self, alarm_id: &str) -> Result<(), fidl::Error>;
125}
126#[derive(Debug)]
127#[cfg(target_os = "fuchsia")]
128pub struct ClientSideBatonManagementSynchronousProxy {
129    client: fidl::client::sync::Client,
130}
131
132#[cfg(target_os = "fuchsia")]
133impl fidl::endpoints::SynchronousProxy for ClientSideBatonManagementSynchronousProxy {
134    type Proxy = ClientSideBatonManagementProxy;
135    type Protocol = ClientSideBatonManagementMarker;
136
137    fn from_channel(inner: fidl::Channel) -> Self {
138        Self::new(inner)
139    }
140
141    fn into_channel(self) -> fidl::Channel {
142        self.client.into_channel()
143    }
144
145    fn as_channel(&self) -> &fidl::Channel {
146        self.client.as_channel()
147    }
148}
149
150#[cfg(target_os = "fuchsia")]
151impl ClientSideBatonManagementSynchronousProxy {
152    pub fn new(channel: fidl::Channel) -> Self {
153        let protocol_name =
154            <ClientSideBatonManagementMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME;
155        Self { client: fidl::client::sync::Client::new(channel, protocol_name) }
156    }
157
158    pub fn into_channel(self) -> fidl::Channel {
159        self.client.into_channel()
160    }
161
162    /// Waits until an event arrives and returns it. It is safe for other
163    /// threads to make concurrent requests while waiting for an event.
164    pub fn wait_for_event(
165        &self,
166        deadline: zx::MonotonicInstant,
167    ) -> Result<ClientSideBatonManagementEvent, fidl::Error> {
168        ClientSideBatonManagementEvent::decode(self.client.wait_for_event(deadline)?)
169    }
170
171    /// Sets a wake alarm with the provided parameters, and waits for the alarm
172    /// to fire.
173    ///
174    /// The caller MAY request multiple alarms open concurrently. However,
175    /// the callee is _not_ required to support any specific number of open
176    /// alarms.
177    ///
178    /// The call to SetAndWait will hang until the alarm fires, or an error
179    /// occurs.
180    ///
181    /// In the event that the caller requests more open alarms than the
182    /// callee is willing to provide, the callee SHOULD reject the new
183    /// request, but honor previous requests.
184    ///
185    /// ## Return value
186    ///
187    /// * `keep_alive`: a handle which prevents system suspend so long as
188    ///   it is held alive.
189    ///
190    /// This method will return when the alarm set in the call fires.
191    ///
192    /// ## Protocol Errors
193    ///
194    /// * [DROPPED] if the alarm has been canceled by using
195    ///   [Cancel].
196    /// * [UNSPECIFIED] a new error mode has occurred, please
197    ///   report this for investigatin.
198    /// * [INTERNAL] is a bug: an internal fallible call (which is expected
199    ///   to be unlikely to fail) has failed somehow. Please report this for
200    ///   investigation.
201    pub fn r#set_and_wait(
202        &self,
203        mut deadline: fidl::BootInstant,
204        mut mode: SetAndWaitMode,
205        mut alarm_id: &str,
206        ___deadline: zx::MonotonicInstant,
207    ) -> Result<ClientSideBatonManagementSetAndWaitResult, fidl::Error> {
208        let _response = self
209            .client
210            .send_query::<SetAndWaitArgs, fidl::encoding::FlexibleResultType<
211                ClientSideBatonManagementSetAndWaitResponse,
212                WakeError,
213            >>(
214                (deadline, &mut mode, alarm_id),
215                0x46ea462fcd0246c0,
216                fidl::encoding::DynamicFlags::FLEXIBLE,
217                ___deadline,
218            )?
219            .into_result::<ClientSideBatonManagementMarker>("set_and_wait")?;
220        Ok(_response.map(|x| x.keep_alive))
221    }
222
223    /// Cancels the alarm specified by `alarm_id`.
224    ///
225    /// Providing an `alarm_id` of an alarm that is not scheduled quietly
226    /// succeeds.
227    pub fn r#cancel(&self, mut alarm_id: &str) -> Result<(), fidl::Error> {
228        self.client.send::<ClientSideBatonManagementCancelRequest>(
229            (alarm_id,),
230            0x2d59ccae0bda24e3,
231            fidl::encoding::DynamicFlags::FLEXIBLE,
232        )
233    }
234}
235
236#[cfg(target_os = "fuchsia")]
237impl From<ClientSideBatonManagementSynchronousProxy> for zx::Handle {
238    fn from(value: ClientSideBatonManagementSynchronousProxy) -> Self {
239        value.into_channel().into()
240    }
241}
242
243#[cfg(target_os = "fuchsia")]
244impl From<fidl::Channel> for ClientSideBatonManagementSynchronousProxy {
245    fn from(value: fidl::Channel) -> Self {
246        Self::new(value)
247    }
248}
249
250#[cfg(target_os = "fuchsia")]
251impl fidl::endpoints::FromClient for ClientSideBatonManagementSynchronousProxy {
252    type Protocol = ClientSideBatonManagementMarker;
253
254    fn from_client(value: fidl::endpoints::ClientEnd<ClientSideBatonManagementMarker>) -> Self {
255        Self::new(value.into_channel())
256    }
257}
258
259#[derive(Debug, Clone)]
260pub struct ClientSideBatonManagementProxy {
261    client: fidl::client::Client<fidl::encoding::DefaultFuchsiaResourceDialect>,
262}
263
264impl fidl::endpoints::Proxy for ClientSideBatonManagementProxy {
265    type Protocol = ClientSideBatonManagementMarker;
266
267    fn from_channel(inner: ::fidl::AsyncChannel) -> Self {
268        Self::new(inner)
269    }
270
271    fn into_channel(self) -> Result<::fidl::AsyncChannel, Self> {
272        self.client.into_channel().map_err(|client| Self { client })
273    }
274
275    fn as_channel(&self) -> &::fidl::AsyncChannel {
276        self.client.as_channel()
277    }
278}
279
280impl ClientSideBatonManagementProxy {
281    /// Create a new Proxy for fuchsia.time.alarms/ClientSideBatonManagement.
282    pub fn new(channel: ::fidl::AsyncChannel) -> Self {
283        let protocol_name =
284            <ClientSideBatonManagementMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME;
285        Self { client: fidl::client::Client::new(channel, protocol_name) }
286    }
287
288    /// Get a Stream of events from the remote end of the protocol.
289    ///
290    /// # Panics
291    ///
292    /// Panics if the event stream was already taken.
293    pub fn take_event_stream(&self) -> ClientSideBatonManagementEventStream {
294        ClientSideBatonManagementEventStream { event_receiver: self.client.take_event_receiver() }
295    }
296
297    /// Sets a wake alarm with the provided parameters, and waits for the alarm
298    /// to fire.
299    ///
300    /// The caller MAY request multiple alarms open concurrently. However,
301    /// the callee is _not_ required to support any specific number of open
302    /// alarms.
303    ///
304    /// The call to SetAndWait will hang until the alarm fires, or an error
305    /// occurs.
306    ///
307    /// In the event that the caller requests more open alarms than the
308    /// callee is willing to provide, the callee SHOULD reject the new
309    /// request, but honor previous requests.
310    ///
311    /// ## Return value
312    ///
313    /// * `keep_alive`: a handle which prevents system suspend so long as
314    ///   it is held alive.
315    ///
316    /// This method will return when the alarm set in the call fires.
317    ///
318    /// ## Protocol Errors
319    ///
320    /// * [DROPPED] if the alarm has been canceled by using
321    ///   [Cancel].
322    /// * [UNSPECIFIED] a new error mode has occurred, please
323    ///   report this for investigatin.
324    /// * [INTERNAL] is a bug: an internal fallible call (which is expected
325    ///   to be unlikely to fail) has failed somehow. Please report this for
326    ///   investigation.
327    pub fn r#set_and_wait(
328        &self,
329        mut deadline: fidl::BootInstant,
330        mut mode: SetAndWaitMode,
331        mut alarm_id: &str,
332    ) -> fidl::client::QueryResponseFut<
333        ClientSideBatonManagementSetAndWaitResult,
334        fidl::encoding::DefaultFuchsiaResourceDialect,
335    > {
336        ClientSideBatonManagementProxyInterface::r#set_and_wait(self, deadline, mode, alarm_id)
337    }
338
339    /// Cancels the alarm specified by `alarm_id`.
340    ///
341    /// Providing an `alarm_id` of an alarm that is not scheduled quietly
342    /// succeeds.
343    pub fn r#cancel(&self, mut alarm_id: &str) -> Result<(), fidl::Error> {
344        ClientSideBatonManagementProxyInterface::r#cancel(self, alarm_id)
345    }
346}
347
348impl ClientSideBatonManagementProxyInterface for ClientSideBatonManagementProxy {
349    type SetAndWaitResponseFut = fidl::client::QueryResponseFut<
350        ClientSideBatonManagementSetAndWaitResult,
351        fidl::encoding::DefaultFuchsiaResourceDialect,
352    >;
353    fn r#set_and_wait(
354        &self,
355        mut deadline: fidl::BootInstant,
356        mut mode: SetAndWaitMode,
357        mut alarm_id: &str,
358    ) -> Self::SetAndWaitResponseFut {
359        fn _decode(
360            mut _buf: Result<<fidl::encoding::DefaultFuchsiaResourceDialect as fidl::encoding::ResourceDialect>::MessageBufEtc, fidl::Error>,
361        ) -> Result<ClientSideBatonManagementSetAndWaitResult, fidl::Error> {
362            let _response = fidl::client::decode_transaction_body::<
363                fidl::encoding::FlexibleResultType<
364                    ClientSideBatonManagementSetAndWaitResponse,
365                    WakeError,
366                >,
367                fidl::encoding::DefaultFuchsiaResourceDialect,
368                0x46ea462fcd0246c0,
369            >(_buf?)?
370            .into_result::<ClientSideBatonManagementMarker>("set_and_wait")?;
371            Ok(_response.map(|x| x.keep_alive))
372        }
373        self.client
374            .send_query_and_decode::<SetAndWaitArgs, ClientSideBatonManagementSetAndWaitResult>(
375                (deadline, &mut mode, alarm_id),
376                0x46ea462fcd0246c0,
377                fidl::encoding::DynamicFlags::FLEXIBLE,
378                _decode,
379            )
380    }
381
382    fn r#cancel(&self, mut alarm_id: &str) -> Result<(), fidl::Error> {
383        self.client.send::<ClientSideBatonManagementCancelRequest>(
384            (alarm_id,),
385            0x2d59ccae0bda24e3,
386            fidl::encoding::DynamicFlags::FLEXIBLE,
387        )
388    }
389}
390
391pub struct ClientSideBatonManagementEventStream {
392    event_receiver: fidl::client::EventReceiver<fidl::encoding::DefaultFuchsiaResourceDialect>,
393}
394
395impl std::marker::Unpin for ClientSideBatonManagementEventStream {}
396
397impl futures::stream::FusedStream for ClientSideBatonManagementEventStream {
398    fn is_terminated(&self) -> bool {
399        self.event_receiver.is_terminated()
400    }
401}
402
403impl futures::Stream for ClientSideBatonManagementEventStream {
404    type Item = Result<ClientSideBatonManagementEvent, fidl::Error>;
405
406    fn poll_next(
407        mut self: std::pin::Pin<&mut Self>,
408        cx: &mut std::task::Context<'_>,
409    ) -> std::task::Poll<Option<Self::Item>> {
410        match futures::ready!(futures::stream::StreamExt::poll_next_unpin(
411            &mut self.event_receiver,
412            cx
413        )?) {
414            Some(buf) => std::task::Poll::Ready(Some(ClientSideBatonManagementEvent::decode(buf))),
415            None => std::task::Poll::Ready(None),
416        }
417    }
418}
419
420#[derive(Debug)]
421pub enum ClientSideBatonManagementEvent {
422    #[non_exhaustive]
423    _UnknownEvent {
424        /// Ordinal of the event that was sent.
425        ordinal: u64,
426    },
427}
428
429impl ClientSideBatonManagementEvent {
430    /// Decodes a message buffer as a [`ClientSideBatonManagementEvent`].
431    fn decode(
432        mut buf: <fidl::encoding::DefaultFuchsiaResourceDialect as fidl::encoding::ResourceDialect>::MessageBufEtc,
433    ) -> Result<ClientSideBatonManagementEvent, fidl::Error> {
434        let (bytes, _handles) = buf.split_mut();
435        let (tx_header, _body_bytes) = fidl::encoding::decode_transaction_header(bytes)?;
436        debug_assert_eq!(tx_header.tx_id, 0);
437        match tx_header.ordinal {
438            _ if tx_header.dynamic_flags().contains(fidl::encoding::DynamicFlags::FLEXIBLE) => {
439                Ok(ClientSideBatonManagementEvent::_UnknownEvent { ordinal: tx_header.ordinal })
440            }
441            _ => Err(fidl::Error::UnknownOrdinal {
442                ordinal: tx_header.ordinal,
443                protocol_name:
444                    <ClientSideBatonManagementMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME,
445            }),
446        }
447    }
448}
449
450/// A Stream of incoming requests for fuchsia.time.alarms/ClientSideBatonManagement.
451pub struct ClientSideBatonManagementRequestStream {
452    inner: std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>,
453    is_terminated: bool,
454}
455
456impl std::marker::Unpin for ClientSideBatonManagementRequestStream {}
457
458impl futures::stream::FusedStream for ClientSideBatonManagementRequestStream {
459    fn is_terminated(&self) -> bool {
460        self.is_terminated
461    }
462}
463
464impl fidl::endpoints::RequestStream for ClientSideBatonManagementRequestStream {
465    type Protocol = ClientSideBatonManagementMarker;
466    type ControlHandle = ClientSideBatonManagementControlHandle;
467
468    fn from_channel(channel: ::fidl::AsyncChannel) -> Self {
469        Self { inner: std::sync::Arc::new(fidl::ServeInner::new(channel)), is_terminated: false }
470    }
471
472    fn control_handle(&self) -> Self::ControlHandle {
473        ClientSideBatonManagementControlHandle { inner: self.inner.clone() }
474    }
475
476    fn into_inner(
477        self,
478    ) -> (::std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>, bool)
479    {
480        (self.inner, self.is_terminated)
481    }
482
483    fn from_inner(
484        inner: std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>,
485        is_terminated: bool,
486    ) -> Self {
487        Self { inner, is_terminated }
488    }
489}
490
491impl futures::Stream for ClientSideBatonManagementRequestStream {
492    type Item = Result<ClientSideBatonManagementRequest, fidl::Error>;
493
494    fn poll_next(
495        mut self: std::pin::Pin<&mut Self>,
496        cx: &mut std::task::Context<'_>,
497    ) -> std::task::Poll<Option<Self::Item>> {
498        let this = &mut *self;
499        if this.inner.check_shutdown(cx) {
500            this.is_terminated = true;
501            return std::task::Poll::Ready(None);
502        }
503        if this.is_terminated {
504            panic!("polled ClientSideBatonManagementRequestStream after completion");
505        }
506        fidl::encoding::with_tls_decode_buf::<_, fidl::encoding::DefaultFuchsiaResourceDialect>(
507            |bytes, handles| {
508                match this.inner.channel().read_etc(cx, bytes, handles) {
509                    std::task::Poll::Ready(Ok(())) => {}
510                    std::task::Poll::Pending => return std::task::Poll::Pending,
511                    std::task::Poll::Ready(Err(zx_status::Status::PEER_CLOSED)) => {
512                        this.is_terminated = true;
513                        return std::task::Poll::Ready(None);
514                    }
515                    std::task::Poll::Ready(Err(e)) => {
516                        return std::task::Poll::Ready(Some(Err(fidl::Error::ServerRequestRead(
517                            e.into(),
518                        ))))
519                    }
520                }
521
522                // A message has been received from the channel
523                let (header, _body_bytes) = fidl::encoding::decode_transaction_header(bytes)?;
524
525                std::task::Poll::Ready(Some(match header.ordinal {
526                0x46ea462fcd0246c0 => {
527                    header.validate_request_tx_id(fidl::MethodType::TwoWay)?;
528                    let mut req = fidl::new_empty!(SetAndWaitArgs, fidl::encoding::DefaultFuchsiaResourceDialect);
529                    fidl::encoding::Decoder::<fidl::encoding::DefaultFuchsiaResourceDialect>::decode_into::<SetAndWaitArgs>(&header, _body_bytes, handles, &mut req)?;
530                    let control_handle = ClientSideBatonManagementControlHandle {
531                        inner: this.inner.clone(),
532                    };
533                    Ok(ClientSideBatonManagementRequest::SetAndWait {deadline: req.deadline,
534mode: req.mode,
535alarm_id: req.alarm_id,
536
537                        responder: ClientSideBatonManagementSetAndWaitResponder {
538                            control_handle: std::mem::ManuallyDrop::new(control_handle),
539                            tx_id: header.tx_id,
540                        },
541                    })
542                }
543                0x2d59ccae0bda24e3 => {
544                    header.validate_request_tx_id(fidl::MethodType::OneWay)?;
545                    let mut req = fidl::new_empty!(ClientSideBatonManagementCancelRequest, fidl::encoding::DefaultFuchsiaResourceDialect);
546                    fidl::encoding::Decoder::<fidl::encoding::DefaultFuchsiaResourceDialect>::decode_into::<ClientSideBatonManagementCancelRequest>(&header, _body_bytes, handles, &mut req)?;
547                    let control_handle = ClientSideBatonManagementControlHandle {
548                        inner: this.inner.clone(),
549                    };
550                    Ok(ClientSideBatonManagementRequest::Cancel {alarm_id: req.alarm_id,
551
552                        control_handle,
553                    })
554                }
555                _ if header.tx_id == 0 && header.dynamic_flags().contains(fidl::encoding::DynamicFlags::FLEXIBLE) => {
556                    Ok(ClientSideBatonManagementRequest::_UnknownMethod {
557                        ordinal: header.ordinal,
558                        control_handle: ClientSideBatonManagementControlHandle { inner: this.inner.clone() },
559                        method_type: fidl::MethodType::OneWay,
560                    })
561                }
562                _ if header.dynamic_flags().contains(fidl::encoding::DynamicFlags::FLEXIBLE) => {
563                    this.inner.send_framework_err(
564                        fidl::encoding::FrameworkErr::UnknownMethod,
565                        header.tx_id,
566                        header.ordinal,
567                        header.dynamic_flags(),
568                        (bytes, handles),
569                    )?;
570                    Ok(ClientSideBatonManagementRequest::_UnknownMethod {
571                        ordinal: header.ordinal,
572                        control_handle: ClientSideBatonManagementControlHandle { inner: this.inner.clone() },
573                        method_type: fidl::MethodType::TwoWay,
574                    })
575                }
576                _ => Err(fidl::Error::UnknownOrdinal {
577                    ordinal: header.ordinal,
578                    protocol_name: <ClientSideBatonManagementMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME,
579                }),
580            }))
581            },
582        )
583    }
584}
585
586#[derive(Debug)]
587pub enum ClientSideBatonManagementRequest {
588    /// Sets a wake alarm with the provided parameters, and waits for the alarm
589    /// to fire.
590    ///
591    /// The caller MAY request multiple alarms open concurrently. However,
592    /// the callee is _not_ required to support any specific number of open
593    /// alarms.
594    ///
595    /// The call to SetAndWait will hang until the alarm fires, or an error
596    /// occurs.
597    ///
598    /// In the event that the caller requests more open alarms than the
599    /// callee is willing to provide, the callee SHOULD reject the new
600    /// request, but honor previous requests.
601    ///
602    /// ## Return value
603    ///
604    /// * `keep_alive`: a handle which prevents system suspend so long as
605    ///   it is held alive.
606    ///
607    /// This method will return when the alarm set in the call fires.
608    ///
609    /// ## Protocol Errors
610    ///
611    /// * [DROPPED] if the alarm has been canceled by using
612    ///   [Cancel].
613    /// * [UNSPECIFIED] a new error mode has occurred, please
614    ///   report this for investigatin.
615    /// * [INTERNAL] is a bug: an internal fallible call (which is expected
616    ///   to be unlikely to fail) has failed somehow. Please report this for
617    ///   investigation.
618    SetAndWait {
619        deadline: fidl::BootInstant,
620        mode: SetAndWaitMode,
621        alarm_id: String,
622        responder: ClientSideBatonManagementSetAndWaitResponder,
623    },
624    /// Cancels the alarm specified by `alarm_id`.
625    ///
626    /// Providing an `alarm_id` of an alarm that is not scheduled quietly
627    /// succeeds.
628    Cancel { alarm_id: String, control_handle: ClientSideBatonManagementControlHandle },
629    /// An interaction was received which does not match any known method.
630    #[non_exhaustive]
631    _UnknownMethod {
632        /// Ordinal of the method that was called.
633        ordinal: u64,
634        control_handle: ClientSideBatonManagementControlHandle,
635        method_type: fidl::MethodType,
636    },
637}
638
639impl ClientSideBatonManagementRequest {
640    #[allow(irrefutable_let_patterns)]
641    pub fn into_set_and_wait(
642        self,
643    ) -> Option<(
644        fidl::BootInstant,
645        SetAndWaitMode,
646        String,
647        ClientSideBatonManagementSetAndWaitResponder,
648    )> {
649        if let ClientSideBatonManagementRequest::SetAndWait {
650            deadline,
651            mode,
652            alarm_id,
653            responder,
654        } = self
655        {
656            Some((deadline, mode, alarm_id, responder))
657        } else {
658            None
659        }
660    }
661
662    #[allow(irrefutable_let_patterns)]
663    pub fn into_cancel(self) -> Option<(String, ClientSideBatonManagementControlHandle)> {
664        if let ClientSideBatonManagementRequest::Cancel { alarm_id, control_handle } = self {
665            Some((alarm_id, control_handle))
666        } else {
667            None
668        }
669    }
670
671    /// Name of the method defined in FIDL
672    pub fn method_name(&self) -> &'static str {
673        match *self {
674            ClientSideBatonManagementRequest::SetAndWait { .. } => "set_and_wait",
675            ClientSideBatonManagementRequest::Cancel { .. } => "cancel",
676            ClientSideBatonManagementRequest::_UnknownMethod {
677                method_type: fidl::MethodType::OneWay,
678                ..
679            } => "unknown one-way method",
680            ClientSideBatonManagementRequest::_UnknownMethod {
681                method_type: fidl::MethodType::TwoWay,
682                ..
683            } => "unknown two-way method",
684        }
685    }
686}
687
688#[derive(Debug, Clone)]
689pub struct ClientSideBatonManagementControlHandle {
690    inner: std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>,
691}
692
693impl fidl::endpoints::ControlHandle for ClientSideBatonManagementControlHandle {
694    fn shutdown(&self) {
695        self.inner.shutdown()
696    }
697    fn shutdown_with_epitaph(&self, status: zx_status::Status) {
698        self.inner.shutdown_with_epitaph(status)
699    }
700
701    fn is_closed(&self) -> bool {
702        self.inner.channel().is_closed()
703    }
704    fn on_closed(&self) -> fidl::OnSignalsRef<'_> {
705        self.inner.channel().on_closed()
706    }
707
708    #[cfg(target_os = "fuchsia")]
709    fn signal_peer(
710        &self,
711        clear_mask: zx::Signals,
712        set_mask: zx::Signals,
713    ) -> Result<(), zx_status::Status> {
714        use fidl::Peered;
715        self.inner.channel().signal_peer(clear_mask, set_mask)
716    }
717}
718
719impl ClientSideBatonManagementControlHandle {}
720
721#[must_use = "FIDL methods require a response to be sent"]
722#[derive(Debug)]
723pub struct ClientSideBatonManagementSetAndWaitResponder {
724    control_handle: std::mem::ManuallyDrop<ClientSideBatonManagementControlHandle>,
725    tx_id: u32,
726}
727
728/// Set the the channel to be shutdown (see [`ClientSideBatonManagementControlHandle::shutdown`])
729/// if the responder is dropped without sending a response, so that the client
730/// doesn't hang. To prevent this behavior, call `drop_without_shutdown`.
731impl std::ops::Drop for ClientSideBatonManagementSetAndWaitResponder {
732    fn drop(&mut self) {
733        self.control_handle.shutdown();
734        // Safety: drops once, never accessed again
735        unsafe { std::mem::ManuallyDrop::drop(&mut self.control_handle) };
736    }
737}
738
739impl fidl::endpoints::Responder for ClientSideBatonManagementSetAndWaitResponder {
740    type ControlHandle = ClientSideBatonManagementControlHandle;
741
742    fn control_handle(&self) -> &ClientSideBatonManagementControlHandle {
743        &self.control_handle
744    }
745
746    fn drop_without_shutdown(mut self) {
747        // Safety: drops once, never accessed again due to mem::forget
748        unsafe { std::mem::ManuallyDrop::drop(&mut self.control_handle) };
749        // Prevent Drop from running (which would shut down the channel)
750        std::mem::forget(self);
751    }
752}
753
754impl ClientSideBatonManagementSetAndWaitResponder {
755    /// Sends a response to the FIDL transaction.
756    ///
757    /// Sets the channel to shutdown if an error occurs.
758    pub fn send(self, mut result: Result<fidl::EventPair, WakeError>) -> Result<(), fidl::Error> {
759        let _result = self.send_raw(result);
760        if _result.is_err() {
761            self.control_handle.shutdown();
762        }
763        self.drop_without_shutdown();
764        _result
765    }
766
767    /// Similar to "send" but does not shutdown the channel if an error occurs.
768    pub fn send_no_shutdown_on_err(
769        self,
770        mut result: Result<fidl::EventPair, WakeError>,
771    ) -> Result<(), fidl::Error> {
772        let _result = self.send_raw(result);
773        self.drop_without_shutdown();
774        _result
775    }
776
777    fn send_raw(&self, mut result: Result<fidl::EventPair, WakeError>) -> Result<(), fidl::Error> {
778        self.control_handle.inner.send::<fidl::encoding::FlexibleResultType<
779            ClientSideBatonManagementSetAndWaitResponse,
780            WakeError,
781        >>(
782            fidl::encoding::FlexibleResult::new(result.map(|keep_alive| (keep_alive,))),
783            self.tx_id,
784            0x46ea462fcd0246c0,
785            fidl::encoding::DynamicFlags::FLEXIBLE,
786        )
787    }
788}
789
790#[derive(Debug, Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Hash)]
791pub struct WakeMarker;
792
793impl fidl::endpoints::ProtocolMarker for WakeMarker {
794    type Proxy = WakeProxy;
795    type RequestStream = WakeRequestStream;
796    #[cfg(target_os = "fuchsia")]
797    type SynchronousProxy = WakeSynchronousProxy;
798
799    const DEBUG_NAME: &'static str = "fuchsia.time.alarms.Wake";
800}
801impl fidl::endpoints::DiscoverableProtocolMarker for WakeMarker {}
802
803pub trait WakeProxyInterface: Send + Sync {
804    type SetAndWaitResponseFut: std::future::Future<Output = Result<ClientSideBatonManagementSetAndWaitResult, fidl::Error>>
805        + Send;
806    fn r#set_and_wait(
807        &self,
808        deadline: fidl::BootInstant,
809        mode: SetAndWaitMode,
810        alarm_id: &str,
811    ) -> Self::SetAndWaitResponseFut;
812    fn r#cancel(&self, alarm_id: &str) -> Result<(), fidl::Error>;
813}
814#[derive(Debug)]
815#[cfg(target_os = "fuchsia")]
816pub struct WakeSynchronousProxy {
817    client: fidl::client::sync::Client,
818}
819
820#[cfg(target_os = "fuchsia")]
821impl fidl::endpoints::SynchronousProxy for WakeSynchronousProxy {
822    type Proxy = WakeProxy;
823    type Protocol = WakeMarker;
824
825    fn from_channel(inner: fidl::Channel) -> Self {
826        Self::new(inner)
827    }
828
829    fn into_channel(self) -> fidl::Channel {
830        self.client.into_channel()
831    }
832
833    fn as_channel(&self) -> &fidl::Channel {
834        self.client.as_channel()
835    }
836}
837
838#[cfg(target_os = "fuchsia")]
839impl WakeSynchronousProxy {
840    pub fn new(channel: fidl::Channel) -> Self {
841        let protocol_name = <WakeMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME;
842        Self { client: fidl::client::sync::Client::new(channel, protocol_name) }
843    }
844
845    pub fn into_channel(self) -> fidl::Channel {
846        self.client.into_channel()
847    }
848
849    /// Waits until an event arrives and returns it. It is safe for other
850    /// threads to make concurrent requests while waiting for an event.
851    pub fn wait_for_event(&self, deadline: zx::MonotonicInstant) -> Result<WakeEvent, fidl::Error> {
852        WakeEvent::decode(self.client.wait_for_event(deadline)?)
853    }
854
855    /// Sets a wake alarm with the provided parameters, and waits for the alarm
856    /// to fire.
857    ///
858    /// The caller MAY request multiple alarms open concurrently. However,
859    /// the callee is _not_ required to support any specific number of open
860    /// alarms.
861    ///
862    /// The call to SetAndWait will hang until the alarm fires, or an error
863    /// occurs.
864    ///
865    /// In the event that the caller requests more open alarms than the
866    /// callee is willing to provide, the callee SHOULD reject the new
867    /// request, but honor previous requests.
868    ///
869    /// ## Return value
870    ///
871    /// * `keep_alive`: a handle which prevents system suspend so long as
872    ///   it is held alive.
873    ///
874    /// This method will return when the alarm set in the call fires.
875    ///
876    /// ## Protocol Errors
877    ///
878    /// * [DROPPED] if the alarm has been canceled by using
879    ///   [Cancel].
880    /// * [UNSPECIFIED] a new error mode has occurred, please
881    ///   report this for investigatin.
882    /// * [INTERNAL] is a bug: an internal fallible call (which is expected
883    ///   to be unlikely to fail) has failed somehow. Please report this for
884    ///   investigation.
885    pub fn r#set_and_wait(
886        &self,
887        mut deadline: fidl::BootInstant,
888        mut mode: SetAndWaitMode,
889        mut alarm_id: &str,
890        ___deadline: zx::MonotonicInstant,
891    ) -> Result<ClientSideBatonManagementSetAndWaitResult, fidl::Error> {
892        let _response = self
893            .client
894            .send_query::<SetAndWaitArgs, fidl::encoding::FlexibleResultType<
895                ClientSideBatonManagementSetAndWaitResponse,
896                WakeError,
897            >>(
898                (deadline, &mut mode, alarm_id),
899                0x46ea462fcd0246c0,
900                fidl::encoding::DynamicFlags::FLEXIBLE,
901                ___deadline,
902            )?
903            .into_result::<WakeMarker>("set_and_wait")?;
904        Ok(_response.map(|x| x.keep_alive))
905    }
906
907    /// Cancels the alarm specified by `alarm_id`.
908    ///
909    /// Providing an `alarm_id` of an alarm that is not scheduled quietly
910    /// succeeds.
911    pub fn r#cancel(&self, mut alarm_id: &str) -> Result<(), fidl::Error> {
912        self.client.send::<ClientSideBatonManagementCancelRequest>(
913            (alarm_id,),
914            0x2d59ccae0bda24e3,
915            fidl::encoding::DynamicFlags::FLEXIBLE,
916        )
917    }
918}
919
920#[cfg(target_os = "fuchsia")]
921impl From<WakeSynchronousProxy> for zx::Handle {
922    fn from(value: WakeSynchronousProxy) -> Self {
923        value.into_channel().into()
924    }
925}
926
927#[cfg(target_os = "fuchsia")]
928impl From<fidl::Channel> for WakeSynchronousProxy {
929    fn from(value: fidl::Channel) -> Self {
930        Self::new(value)
931    }
932}
933
934#[cfg(target_os = "fuchsia")]
935impl fidl::endpoints::FromClient for WakeSynchronousProxy {
936    type Protocol = WakeMarker;
937
938    fn from_client(value: fidl::endpoints::ClientEnd<WakeMarker>) -> Self {
939        Self::new(value.into_channel())
940    }
941}
942
943#[derive(Debug, Clone)]
944pub struct WakeProxy {
945    client: fidl::client::Client<fidl::encoding::DefaultFuchsiaResourceDialect>,
946}
947
948impl fidl::endpoints::Proxy for WakeProxy {
949    type Protocol = WakeMarker;
950
951    fn from_channel(inner: ::fidl::AsyncChannel) -> Self {
952        Self::new(inner)
953    }
954
955    fn into_channel(self) -> Result<::fidl::AsyncChannel, Self> {
956        self.client.into_channel().map_err(|client| Self { client })
957    }
958
959    fn as_channel(&self) -> &::fidl::AsyncChannel {
960        self.client.as_channel()
961    }
962}
963
964impl WakeProxy {
965    /// Create a new Proxy for fuchsia.time.alarms/Wake.
966    pub fn new(channel: ::fidl::AsyncChannel) -> Self {
967        let protocol_name = <WakeMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME;
968        Self { client: fidl::client::Client::new(channel, protocol_name) }
969    }
970
971    /// Get a Stream of events from the remote end of the protocol.
972    ///
973    /// # Panics
974    ///
975    /// Panics if the event stream was already taken.
976    pub fn take_event_stream(&self) -> WakeEventStream {
977        WakeEventStream { event_receiver: self.client.take_event_receiver() }
978    }
979
980    /// Sets a wake alarm with the provided parameters, and waits for the alarm
981    /// to fire.
982    ///
983    /// The caller MAY request multiple alarms open concurrently. However,
984    /// the callee is _not_ required to support any specific number of open
985    /// alarms.
986    ///
987    /// The call to SetAndWait will hang until the alarm fires, or an error
988    /// occurs.
989    ///
990    /// In the event that the caller requests more open alarms than the
991    /// callee is willing to provide, the callee SHOULD reject the new
992    /// request, but honor previous requests.
993    ///
994    /// ## Return value
995    ///
996    /// * `keep_alive`: a handle which prevents system suspend so long as
997    ///   it is held alive.
998    ///
999    /// This method will return when the alarm set in the call fires.
1000    ///
1001    /// ## Protocol Errors
1002    ///
1003    /// * [DROPPED] if the alarm has been canceled by using
1004    ///   [Cancel].
1005    /// * [UNSPECIFIED] a new error mode has occurred, please
1006    ///   report this for investigatin.
1007    /// * [INTERNAL] is a bug: an internal fallible call (which is expected
1008    ///   to be unlikely to fail) has failed somehow. Please report this for
1009    ///   investigation.
1010    pub fn r#set_and_wait(
1011        &self,
1012        mut deadline: fidl::BootInstant,
1013        mut mode: SetAndWaitMode,
1014        mut alarm_id: &str,
1015    ) -> fidl::client::QueryResponseFut<
1016        ClientSideBatonManagementSetAndWaitResult,
1017        fidl::encoding::DefaultFuchsiaResourceDialect,
1018    > {
1019        WakeProxyInterface::r#set_and_wait(self, deadline, mode, alarm_id)
1020    }
1021
1022    /// Cancels the alarm specified by `alarm_id`.
1023    ///
1024    /// Providing an `alarm_id` of an alarm that is not scheduled quietly
1025    /// succeeds.
1026    pub fn r#cancel(&self, mut alarm_id: &str) -> Result<(), fidl::Error> {
1027        WakeProxyInterface::r#cancel(self, alarm_id)
1028    }
1029}
1030
1031impl WakeProxyInterface for WakeProxy {
1032    type SetAndWaitResponseFut = fidl::client::QueryResponseFut<
1033        ClientSideBatonManagementSetAndWaitResult,
1034        fidl::encoding::DefaultFuchsiaResourceDialect,
1035    >;
1036    fn r#set_and_wait(
1037        &self,
1038        mut deadline: fidl::BootInstant,
1039        mut mode: SetAndWaitMode,
1040        mut alarm_id: &str,
1041    ) -> Self::SetAndWaitResponseFut {
1042        fn _decode(
1043            mut _buf: Result<<fidl::encoding::DefaultFuchsiaResourceDialect as fidl::encoding::ResourceDialect>::MessageBufEtc, fidl::Error>,
1044        ) -> Result<ClientSideBatonManagementSetAndWaitResult, fidl::Error> {
1045            let _response = fidl::client::decode_transaction_body::<
1046                fidl::encoding::FlexibleResultType<
1047                    ClientSideBatonManagementSetAndWaitResponse,
1048                    WakeError,
1049                >,
1050                fidl::encoding::DefaultFuchsiaResourceDialect,
1051                0x46ea462fcd0246c0,
1052            >(_buf?)?
1053            .into_result::<WakeMarker>("set_and_wait")?;
1054            Ok(_response.map(|x| x.keep_alive))
1055        }
1056        self.client
1057            .send_query_and_decode::<SetAndWaitArgs, ClientSideBatonManagementSetAndWaitResult>(
1058                (deadline, &mut mode, alarm_id),
1059                0x46ea462fcd0246c0,
1060                fidl::encoding::DynamicFlags::FLEXIBLE,
1061                _decode,
1062            )
1063    }
1064
1065    fn r#cancel(&self, mut alarm_id: &str) -> Result<(), fidl::Error> {
1066        self.client.send::<ClientSideBatonManagementCancelRequest>(
1067            (alarm_id,),
1068            0x2d59ccae0bda24e3,
1069            fidl::encoding::DynamicFlags::FLEXIBLE,
1070        )
1071    }
1072}
1073
1074pub struct WakeEventStream {
1075    event_receiver: fidl::client::EventReceiver<fidl::encoding::DefaultFuchsiaResourceDialect>,
1076}
1077
1078impl std::marker::Unpin for WakeEventStream {}
1079
1080impl futures::stream::FusedStream for WakeEventStream {
1081    fn is_terminated(&self) -> bool {
1082        self.event_receiver.is_terminated()
1083    }
1084}
1085
1086impl futures::Stream for WakeEventStream {
1087    type Item = Result<WakeEvent, fidl::Error>;
1088
1089    fn poll_next(
1090        mut self: std::pin::Pin<&mut Self>,
1091        cx: &mut std::task::Context<'_>,
1092    ) -> std::task::Poll<Option<Self::Item>> {
1093        match futures::ready!(futures::stream::StreamExt::poll_next_unpin(
1094            &mut self.event_receiver,
1095            cx
1096        )?) {
1097            Some(buf) => std::task::Poll::Ready(Some(WakeEvent::decode(buf))),
1098            None => std::task::Poll::Ready(None),
1099        }
1100    }
1101}
1102
1103#[derive(Debug)]
1104pub enum WakeEvent {
1105    #[non_exhaustive]
1106    _UnknownEvent {
1107        /// Ordinal of the event that was sent.
1108        ordinal: u64,
1109    },
1110}
1111
1112impl WakeEvent {
1113    /// Decodes a message buffer as a [`WakeEvent`].
1114    fn decode(
1115        mut buf: <fidl::encoding::DefaultFuchsiaResourceDialect as fidl::encoding::ResourceDialect>::MessageBufEtc,
1116    ) -> Result<WakeEvent, fidl::Error> {
1117        let (bytes, _handles) = buf.split_mut();
1118        let (tx_header, _body_bytes) = fidl::encoding::decode_transaction_header(bytes)?;
1119        debug_assert_eq!(tx_header.tx_id, 0);
1120        match tx_header.ordinal {
1121            _ if tx_header.dynamic_flags().contains(fidl::encoding::DynamicFlags::FLEXIBLE) => {
1122                Ok(WakeEvent::_UnknownEvent { ordinal: tx_header.ordinal })
1123            }
1124            _ => Err(fidl::Error::UnknownOrdinal {
1125                ordinal: tx_header.ordinal,
1126                protocol_name: <WakeMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME,
1127            }),
1128        }
1129    }
1130}
1131
1132/// A Stream of incoming requests for fuchsia.time.alarms/Wake.
1133pub struct WakeRequestStream {
1134    inner: std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>,
1135    is_terminated: bool,
1136}
1137
1138impl std::marker::Unpin for WakeRequestStream {}
1139
1140impl futures::stream::FusedStream for WakeRequestStream {
1141    fn is_terminated(&self) -> bool {
1142        self.is_terminated
1143    }
1144}
1145
1146impl fidl::endpoints::RequestStream for WakeRequestStream {
1147    type Protocol = WakeMarker;
1148    type ControlHandle = WakeControlHandle;
1149
1150    fn from_channel(channel: ::fidl::AsyncChannel) -> Self {
1151        Self { inner: std::sync::Arc::new(fidl::ServeInner::new(channel)), is_terminated: false }
1152    }
1153
1154    fn control_handle(&self) -> Self::ControlHandle {
1155        WakeControlHandle { inner: self.inner.clone() }
1156    }
1157
1158    fn into_inner(
1159        self,
1160    ) -> (::std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>, bool)
1161    {
1162        (self.inner, self.is_terminated)
1163    }
1164
1165    fn from_inner(
1166        inner: std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>,
1167        is_terminated: bool,
1168    ) -> Self {
1169        Self { inner, is_terminated }
1170    }
1171}
1172
1173impl futures::Stream for WakeRequestStream {
1174    type Item = Result<WakeRequest, fidl::Error>;
1175
1176    fn poll_next(
1177        mut self: std::pin::Pin<&mut Self>,
1178        cx: &mut std::task::Context<'_>,
1179    ) -> std::task::Poll<Option<Self::Item>> {
1180        let this = &mut *self;
1181        if this.inner.check_shutdown(cx) {
1182            this.is_terminated = true;
1183            return std::task::Poll::Ready(None);
1184        }
1185        if this.is_terminated {
1186            panic!("polled WakeRequestStream after completion");
1187        }
1188        fidl::encoding::with_tls_decode_buf::<_, fidl::encoding::DefaultFuchsiaResourceDialect>(
1189            |bytes, handles| {
1190                match this.inner.channel().read_etc(cx, bytes, handles) {
1191                    std::task::Poll::Ready(Ok(())) => {}
1192                    std::task::Poll::Pending => return std::task::Poll::Pending,
1193                    std::task::Poll::Ready(Err(zx_status::Status::PEER_CLOSED)) => {
1194                        this.is_terminated = true;
1195                        return std::task::Poll::Ready(None);
1196                    }
1197                    std::task::Poll::Ready(Err(e)) => {
1198                        return std::task::Poll::Ready(Some(Err(fidl::Error::ServerRequestRead(
1199                            e.into(),
1200                        ))))
1201                    }
1202                }
1203
1204                // A message has been received from the channel
1205                let (header, _body_bytes) = fidl::encoding::decode_transaction_header(bytes)?;
1206
1207                std::task::Poll::Ready(Some(match header.ordinal {
1208                    0x46ea462fcd0246c0 => {
1209                        header.validate_request_tx_id(fidl::MethodType::TwoWay)?;
1210                        let mut req = fidl::new_empty!(
1211                            SetAndWaitArgs,
1212                            fidl::encoding::DefaultFuchsiaResourceDialect
1213                        );
1214                        fidl::encoding::Decoder::<fidl::encoding::DefaultFuchsiaResourceDialect>::decode_into::<SetAndWaitArgs>(&header, _body_bytes, handles, &mut req)?;
1215                        let control_handle = WakeControlHandle { inner: this.inner.clone() };
1216                        Ok(WakeRequest::SetAndWait {
1217                            deadline: req.deadline,
1218                            mode: req.mode,
1219                            alarm_id: req.alarm_id,
1220
1221                            responder: WakeSetAndWaitResponder {
1222                                control_handle: std::mem::ManuallyDrop::new(control_handle),
1223                                tx_id: header.tx_id,
1224                            },
1225                        })
1226                    }
1227                    0x2d59ccae0bda24e3 => {
1228                        header.validate_request_tx_id(fidl::MethodType::OneWay)?;
1229                        let mut req = fidl::new_empty!(
1230                            ClientSideBatonManagementCancelRequest,
1231                            fidl::encoding::DefaultFuchsiaResourceDialect
1232                        );
1233                        fidl::encoding::Decoder::<fidl::encoding::DefaultFuchsiaResourceDialect>::decode_into::<ClientSideBatonManagementCancelRequest>(&header, _body_bytes, handles, &mut req)?;
1234                        let control_handle = WakeControlHandle { inner: this.inner.clone() };
1235                        Ok(WakeRequest::Cancel { alarm_id: req.alarm_id, control_handle })
1236                    }
1237                    _ if header.tx_id == 0
1238                        && header
1239                            .dynamic_flags()
1240                            .contains(fidl::encoding::DynamicFlags::FLEXIBLE) =>
1241                    {
1242                        Ok(WakeRequest::_UnknownMethod {
1243                            ordinal: header.ordinal,
1244                            control_handle: WakeControlHandle { inner: this.inner.clone() },
1245                            method_type: fidl::MethodType::OneWay,
1246                        })
1247                    }
1248                    _ if header
1249                        .dynamic_flags()
1250                        .contains(fidl::encoding::DynamicFlags::FLEXIBLE) =>
1251                    {
1252                        this.inner.send_framework_err(
1253                            fidl::encoding::FrameworkErr::UnknownMethod,
1254                            header.tx_id,
1255                            header.ordinal,
1256                            header.dynamic_flags(),
1257                            (bytes, handles),
1258                        )?;
1259                        Ok(WakeRequest::_UnknownMethod {
1260                            ordinal: header.ordinal,
1261                            control_handle: WakeControlHandle { inner: this.inner.clone() },
1262                            method_type: fidl::MethodType::TwoWay,
1263                        })
1264                    }
1265                    _ => Err(fidl::Error::UnknownOrdinal {
1266                        ordinal: header.ordinal,
1267                        protocol_name: <WakeMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME,
1268                    }),
1269                }))
1270            },
1271        )
1272    }
1273}
1274
1275/// [Wake] provides setting up platform-wide wake alarms.
1276///
1277/// An alarm is a promise made by the system to the caller of the API to notify
1278/// the caller that AT LEAST a certain amount of time has expired. The alarm
1279/// may fire later than the requested amount of time at the discretion of the
1280/// server implementing this API.
1281///
1282/// When this notification happens, we say that the wake alarm has "fired".
1283///
1284/// A "wake" alarm firing also ensures that the system comes back from a reduced
1285/// power state if needed, so that it can notify the caller.
1286///
1287/// The general shape of a wake alarm API has three parts:
1288/// * A specification of when a wake alarm is supposed to fire,
1289/// * A way to notify the caller of an alarm that fired, and
1290/// * A way to keep the system awake until both the caller and the callee have
1291///   completed work associated with the alarm.
1292#[derive(Debug)]
1293pub enum WakeRequest {
1294    /// Sets a wake alarm with the provided parameters, and waits for the alarm
1295    /// to fire.
1296    ///
1297    /// The caller MAY request multiple alarms open concurrently. However,
1298    /// the callee is _not_ required to support any specific number of open
1299    /// alarms.
1300    ///
1301    /// The call to SetAndWait will hang until the alarm fires, or an error
1302    /// occurs.
1303    ///
1304    /// In the event that the caller requests more open alarms than the
1305    /// callee is willing to provide, the callee SHOULD reject the new
1306    /// request, but honor previous requests.
1307    ///
1308    /// ## Return value
1309    ///
1310    /// * `keep_alive`: a handle which prevents system suspend so long as
1311    ///   it is held alive.
1312    ///
1313    /// This method will return when the alarm set in the call fires.
1314    ///
1315    /// ## Protocol Errors
1316    ///
1317    /// * [DROPPED] if the alarm has been canceled by using
1318    ///   [Cancel].
1319    /// * [UNSPECIFIED] a new error mode has occurred, please
1320    ///   report this for investigatin.
1321    /// * [INTERNAL] is a bug: an internal fallible call (which is expected
1322    ///   to be unlikely to fail) has failed somehow. Please report this for
1323    ///   investigation.
1324    SetAndWait {
1325        deadline: fidl::BootInstant,
1326        mode: SetAndWaitMode,
1327        alarm_id: String,
1328        responder: WakeSetAndWaitResponder,
1329    },
1330    /// Cancels the alarm specified by `alarm_id`.
1331    ///
1332    /// Providing an `alarm_id` of an alarm that is not scheduled quietly
1333    /// succeeds.
1334    Cancel { alarm_id: String, control_handle: WakeControlHandle },
1335    /// An interaction was received which does not match any known method.
1336    #[non_exhaustive]
1337    _UnknownMethod {
1338        /// Ordinal of the method that was called.
1339        ordinal: u64,
1340        control_handle: WakeControlHandle,
1341        method_type: fidl::MethodType,
1342    },
1343}
1344
1345impl WakeRequest {
1346    #[allow(irrefutable_let_patterns)]
1347    pub fn into_set_and_wait(
1348        self,
1349    ) -> Option<(fidl::BootInstant, SetAndWaitMode, String, WakeSetAndWaitResponder)> {
1350        if let WakeRequest::SetAndWait { deadline, mode, alarm_id, responder } = self {
1351            Some((deadline, mode, alarm_id, responder))
1352        } else {
1353            None
1354        }
1355    }
1356
1357    #[allow(irrefutable_let_patterns)]
1358    pub fn into_cancel(self) -> Option<(String, WakeControlHandle)> {
1359        if let WakeRequest::Cancel { alarm_id, control_handle } = self {
1360            Some((alarm_id, control_handle))
1361        } else {
1362            None
1363        }
1364    }
1365
1366    /// Name of the method defined in FIDL
1367    pub fn method_name(&self) -> &'static str {
1368        match *self {
1369            WakeRequest::SetAndWait { .. } => "set_and_wait",
1370            WakeRequest::Cancel { .. } => "cancel",
1371            WakeRequest::_UnknownMethod { method_type: fidl::MethodType::OneWay, .. } => {
1372                "unknown one-way method"
1373            }
1374            WakeRequest::_UnknownMethod { method_type: fidl::MethodType::TwoWay, .. } => {
1375                "unknown two-way method"
1376            }
1377        }
1378    }
1379}
1380
1381#[derive(Debug, Clone)]
1382pub struct WakeControlHandle {
1383    inner: std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>,
1384}
1385
1386impl fidl::endpoints::ControlHandle for WakeControlHandle {
1387    fn shutdown(&self) {
1388        self.inner.shutdown()
1389    }
1390    fn shutdown_with_epitaph(&self, status: zx_status::Status) {
1391        self.inner.shutdown_with_epitaph(status)
1392    }
1393
1394    fn is_closed(&self) -> bool {
1395        self.inner.channel().is_closed()
1396    }
1397    fn on_closed(&self) -> fidl::OnSignalsRef<'_> {
1398        self.inner.channel().on_closed()
1399    }
1400
1401    #[cfg(target_os = "fuchsia")]
1402    fn signal_peer(
1403        &self,
1404        clear_mask: zx::Signals,
1405        set_mask: zx::Signals,
1406    ) -> Result<(), zx_status::Status> {
1407        use fidl::Peered;
1408        self.inner.channel().signal_peer(clear_mask, set_mask)
1409    }
1410}
1411
1412impl WakeControlHandle {}
1413
1414#[must_use = "FIDL methods require a response to be sent"]
1415#[derive(Debug)]
1416pub struct WakeSetAndWaitResponder {
1417    control_handle: std::mem::ManuallyDrop<WakeControlHandle>,
1418    tx_id: u32,
1419}
1420
1421/// Set the the channel to be shutdown (see [`WakeControlHandle::shutdown`])
1422/// if the responder is dropped without sending a response, so that the client
1423/// doesn't hang. To prevent this behavior, call `drop_without_shutdown`.
1424impl std::ops::Drop for WakeSetAndWaitResponder {
1425    fn drop(&mut self) {
1426        self.control_handle.shutdown();
1427        // Safety: drops once, never accessed again
1428        unsafe { std::mem::ManuallyDrop::drop(&mut self.control_handle) };
1429    }
1430}
1431
1432impl fidl::endpoints::Responder for WakeSetAndWaitResponder {
1433    type ControlHandle = WakeControlHandle;
1434
1435    fn control_handle(&self) -> &WakeControlHandle {
1436        &self.control_handle
1437    }
1438
1439    fn drop_without_shutdown(mut self) {
1440        // Safety: drops once, never accessed again due to mem::forget
1441        unsafe { std::mem::ManuallyDrop::drop(&mut self.control_handle) };
1442        // Prevent Drop from running (which would shut down the channel)
1443        std::mem::forget(self);
1444    }
1445}
1446
1447impl WakeSetAndWaitResponder {
1448    /// Sends a response to the FIDL transaction.
1449    ///
1450    /// Sets the channel to shutdown if an error occurs.
1451    pub fn send(self, mut result: Result<fidl::EventPair, WakeError>) -> Result<(), fidl::Error> {
1452        let _result = self.send_raw(result);
1453        if _result.is_err() {
1454            self.control_handle.shutdown();
1455        }
1456        self.drop_without_shutdown();
1457        _result
1458    }
1459
1460    /// Similar to "send" but does not shutdown the channel if an error occurs.
1461    pub fn send_no_shutdown_on_err(
1462        self,
1463        mut result: Result<fidl::EventPair, WakeError>,
1464    ) -> Result<(), fidl::Error> {
1465        let _result = self.send_raw(result);
1466        self.drop_without_shutdown();
1467        _result
1468    }
1469
1470    fn send_raw(&self, mut result: Result<fidl::EventPair, WakeError>) -> Result<(), fidl::Error> {
1471        self.control_handle.inner.send::<fidl::encoding::FlexibleResultType<
1472            ClientSideBatonManagementSetAndWaitResponse,
1473            WakeError,
1474        >>(
1475            fidl::encoding::FlexibleResult::new(result.map(|keep_alive| (keep_alive,))),
1476            self.tx_id,
1477            0x46ea462fcd0246c0,
1478            fidl::encoding::DynamicFlags::FLEXIBLE,
1479        )
1480    }
1481}
1482
1483mod internal {
1484    use super::*;
1485
1486    impl fidl::encoding::ResourceTypeMarker for ClientSideBatonManagementSetAndWaitResponse {
1487        type Borrowed<'a> = &'a mut Self;
1488        fn take_or_borrow<'a>(
1489            value: &'a mut <Self as fidl::encoding::TypeMarker>::Owned,
1490        ) -> Self::Borrowed<'a> {
1491            value
1492        }
1493    }
1494
1495    unsafe impl fidl::encoding::TypeMarker for ClientSideBatonManagementSetAndWaitResponse {
1496        type Owned = Self;
1497
1498        #[inline(always)]
1499        fn inline_align(_context: fidl::encoding::Context) -> usize {
1500            4
1501        }
1502
1503        #[inline(always)]
1504        fn inline_size(_context: fidl::encoding::Context) -> usize {
1505            4
1506        }
1507    }
1508
1509    unsafe impl
1510        fidl::encoding::Encode<
1511            ClientSideBatonManagementSetAndWaitResponse,
1512            fidl::encoding::DefaultFuchsiaResourceDialect,
1513        > for &mut ClientSideBatonManagementSetAndWaitResponse
1514    {
1515        #[inline]
1516        unsafe fn encode(
1517            self,
1518            encoder: &mut fidl::encoding::Encoder<
1519                '_,
1520                fidl::encoding::DefaultFuchsiaResourceDialect,
1521            >,
1522            offset: usize,
1523            _depth: fidl::encoding::Depth,
1524        ) -> fidl::Result<()> {
1525            encoder.debug_check_bounds::<ClientSideBatonManagementSetAndWaitResponse>(offset);
1526            // Delegate to tuple encoding.
1527            fidl::encoding::Encode::<
1528                ClientSideBatonManagementSetAndWaitResponse,
1529                fidl::encoding::DefaultFuchsiaResourceDialect,
1530            >::encode(
1531                (<fidl::encoding::HandleType<
1532                    fidl::EventPair,
1533                    { fidl::ObjectType::EVENTPAIR.into_raw() },
1534                    16387,
1535                > as fidl::encoding::ResourceTypeMarker>::take_or_borrow(
1536                    &mut self.keep_alive
1537                ),),
1538                encoder,
1539                offset,
1540                _depth,
1541            )
1542        }
1543    }
1544    unsafe impl<
1545            T0: fidl::encoding::Encode<
1546                fidl::encoding::HandleType<
1547                    fidl::EventPair,
1548                    { fidl::ObjectType::EVENTPAIR.into_raw() },
1549                    16387,
1550                >,
1551                fidl::encoding::DefaultFuchsiaResourceDialect,
1552            >,
1553        >
1554        fidl::encoding::Encode<
1555            ClientSideBatonManagementSetAndWaitResponse,
1556            fidl::encoding::DefaultFuchsiaResourceDialect,
1557        > for (T0,)
1558    {
1559        #[inline]
1560        unsafe fn encode(
1561            self,
1562            encoder: &mut fidl::encoding::Encoder<
1563                '_,
1564                fidl::encoding::DefaultFuchsiaResourceDialect,
1565            >,
1566            offset: usize,
1567            depth: fidl::encoding::Depth,
1568        ) -> fidl::Result<()> {
1569            encoder.debug_check_bounds::<ClientSideBatonManagementSetAndWaitResponse>(offset);
1570            // Zero out padding regions. There's no need to apply masks
1571            // because the unmasked parts will be overwritten by fields.
1572            // Write the fields.
1573            self.0.encode(encoder, offset + 0, depth)?;
1574            Ok(())
1575        }
1576    }
1577
1578    impl fidl::encoding::Decode<Self, fidl::encoding::DefaultFuchsiaResourceDialect>
1579        for ClientSideBatonManagementSetAndWaitResponse
1580    {
1581        #[inline(always)]
1582        fn new_empty() -> Self {
1583            Self {
1584                keep_alive: fidl::new_empty!(fidl::encoding::HandleType<fidl::EventPair, { fidl::ObjectType::EVENTPAIR.into_raw() }, 16387>, fidl::encoding::DefaultFuchsiaResourceDialect),
1585            }
1586        }
1587
1588        #[inline]
1589        unsafe fn decode(
1590            &mut self,
1591            decoder: &mut fidl::encoding::Decoder<
1592                '_,
1593                fidl::encoding::DefaultFuchsiaResourceDialect,
1594            >,
1595            offset: usize,
1596            _depth: fidl::encoding::Depth,
1597        ) -> fidl::Result<()> {
1598            decoder.debug_check_bounds::<Self>(offset);
1599            // Verify that padding bytes are zero.
1600            fidl::decode!(fidl::encoding::HandleType<fidl::EventPair, { fidl::ObjectType::EVENTPAIR.into_raw() }, 16387>, fidl::encoding::DefaultFuchsiaResourceDialect, &mut self.keep_alive, decoder, offset + 0, _depth)?;
1601            Ok(())
1602        }
1603    }
1604
1605    impl fidl::encoding::ResourceTypeMarker for SetAndWaitArgs {
1606        type Borrowed<'a> = &'a mut Self;
1607        fn take_or_borrow<'a>(
1608            value: &'a mut <Self as fidl::encoding::TypeMarker>::Owned,
1609        ) -> Self::Borrowed<'a> {
1610            value
1611        }
1612    }
1613
1614    unsafe impl fidl::encoding::TypeMarker for SetAndWaitArgs {
1615        type Owned = Self;
1616
1617        #[inline(always)]
1618        fn inline_align(_context: fidl::encoding::Context) -> usize {
1619            8
1620        }
1621
1622        #[inline(always)]
1623        fn inline_size(_context: fidl::encoding::Context) -> usize {
1624            40
1625        }
1626    }
1627
1628    unsafe impl
1629        fidl::encoding::Encode<SetAndWaitArgs, fidl::encoding::DefaultFuchsiaResourceDialect>
1630        for &mut SetAndWaitArgs
1631    {
1632        #[inline]
1633        unsafe fn encode(
1634            self,
1635            encoder: &mut fidl::encoding::Encoder<
1636                '_,
1637                fidl::encoding::DefaultFuchsiaResourceDialect,
1638            >,
1639            offset: usize,
1640            _depth: fidl::encoding::Depth,
1641        ) -> fidl::Result<()> {
1642            encoder.debug_check_bounds::<SetAndWaitArgs>(offset);
1643            // Delegate to tuple encoding.
1644            fidl::encoding::Encode::<SetAndWaitArgs, fidl::encoding::DefaultFuchsiaResourceDialect>::encode(
1645                (
1646                    <fidl::BootInstant as fidl::encoding::ValueTypeMarker>::borrow(&self.deadline),
1647                    <SetAndWaitMode as fidl::encoding::ResourceTypeMarker>::take_or_borrow(&mut self.mode),
1648                    <fidl::encoding::BoundedString<128> as fidl::encoding::ValueTypeMarker>::borrow(&self.alarm_id),
1649                ),
1650                encoder, offset, _depth
1651            )
1652        }
1653    }
1654    unsafe impl<
1655            T0: fidl::encoding::Encode<
1656                fidl::BootInstant,
1657                fidl::encoding::DefaultFuchsiaResourceDialect,
1658            >,
1659            T1: fidl::encoding::Encode<SetAndWaitMode, fidl::encoding::DefaultFuchsiaResourceDialect>,
1660            T2: fidl::encoding::Encode<
1661                fidl::encoding::BoundedString<128>,
1662                fidl::encoding::DefaultFuchsiaResourceDialect,
1663            >,
1664        > fidl::encoding::Encode<SetAndWaitArgs, fidl::encoding::DefaultFuchsiaResourceDialect>
1665        for (T0, T1, T2)
1666    {
1667        #[inline]
1668        unsafe fn encode(
1669            self,
1670            encoder: &mut fidl::encoding::Encoder<
1671                '_,
1672                fidl::encoding::DefaultFuchsiaResourceDialect,
1673            >,
1674            offset: usize,
1675            depth: fidl::encoding::Depth,
1676        ) -> fidl::Result<()> {
1677            encoder.debug_check_bounds::<SetAndWaitArgs>(offset);
1678            // Zero out padding regions. There's no need to apply masks
1679            // because the unmasked parts will be overwritten by fields.
1680            // Write the fields.
1681            self.0.encode(encoder, offset + 0, depth)?;
1682            self.1.encode(encoder, offset + 8, depth)?;
1683            self.2.encode(encoder, offset + 24, depth)?;
1684            Ok(())
1685        }
1686    }
1687
1688    impl fidl::encoding::Decode<Self, fidl::encoding::DefaultFuchsiaResourceDialect>
1689        for SetAndWaitArgs
1690    {
1691        #[inline(always)]
1692        fn new_empty() -> Self {
1693            Self {
1694                deadline: fidl::new_empty!(
1695                    fidl::BootInstant,
1696                    fidl::encoding::DefaultFuchsiaResourceDialect
1697                ),
1698                mode: fidl::new_empty!(
1699                    SetAndWaitMode,
1700                    fidl::encoding::DefaultFuchsiaResourceDialect
1701                ),
1702                alarm_id: fidl::new_empty!(
1703                    fidl::encoding::BoundedString<128>,
1704                    fidl::encoding::DefaultFuchsiaResourceDialect
1705                ),
1706            }
1707        }
1708
1709        #[inline]
1710        unsafe fn decode(
1711            &mut self,
1712            decoder: &mut fidl::encoding::Decoder<
1713                '_,
1714                fidl::encoding::DefaultFuchsiaResourceDialect,
1715            >,
1716            offset: usize,
1717            _depth: fidl::encoding::Depth,
1718        ) -> fidl::Result<()> {
1719            decoder.debug_check_bounds::<Self>(offset);
1720            // Verify that padding bytes are zero.
1721            fidl::decode!(
1722                fidl::BootInstant,
1723                fidl::encoding::DefaultFuchsiaResourceDialect,
1724                &mut self.deadline,
1725                decoder,
1726                offset + 0,
1727                _depth
1728            )?;
1729            fidl::decode!(
1730                SetAndWaitMode,
1731                fidl::encoding::DefaultFuchsiaResourceDialect,
1732                &mut self.mode,
1733                decoder,
1734                offset + 8,
1735                _depth
1736            )?;
1737            fidl::decode!(
1738                fidl::encoding::BoundedString<128>,
1739                fidl::encoding::DefaultFuchsiaResourceDialect,
1740                &mut self.alarm_id,
1741                decoder,
1742                offset + 24,
1743                _depth
1744            )?;
1745            Ok(())
1746        }
1747    }
1748
1749    impl fidl::encoding::ResourceTypeMarker for SetAndWaitMode {
1750        type Borrowed<'a> = &'a mut Self;
1751        fn take_or_borrow<'a>(
1752            value: &'a mut <Self as fidl::encoding::TypeMarker>::Owned,
1753        ) -> Self::Borrowed<'a> {
1754            value
1755        }
1756    }
1757
1758    unsafe impl fidl::encoding::TypeMarker for SetAndWaitMode {
1759        type Owned = Self;
1760
1761        #[inline(always)]
1762        fn inline_align(_context: fidl::encoding::Context) -> usize {
1763            8
1764        }
1765
1766        #[inline(always)]
1767        fn inline_size(_context: fidl::encoding::Context) -> usize {
1768            16
1769        }
1770    }
1771
1772    unsafe impl
1773        fidl::encoding::Encode<SetAndWaitMode, fidl::encoding::DefaultFuchsiaResourceDialect>
1774        for &mut SetAndWaitMode
1775    {
1776        #[inline]
1777        unsafe fn encode(
1778            self,
1779            encoder: &mut fidl::encoding::Encoder<
1780                '_,
1781                fidl::encoding::DefaultFuchsiaResourceDialect,
1782            >,
1783            offset: usize,
1784            _depth: fidl::encoding::Depth,
1785        ) -> fidl::Result<()> {
1786            encoder.debug_check_bounds::<SetAndWaitMode>(offset);
1787            encoder.write_num::<u64>(self.ordinal(), offset);
1788            match self {
1789                SetAndWaitMode::KeepAlive(ref mut val) => fidl::encoding::encode_in_envelope::<
1790                    fidl::encoding::HandleType<
1791                        fidl::EventPair,
1792                        { fidl::ObjectType::EVENTPAIR.into_raw() },
1793                        16387,
1794                    >,
1795                    fidl::encoding::DefaultFuchsiaResourceDialect,
1796                >(
1797                    <fidl::encoding::HandleType<
1798                        fidl::EventPair,
1799                        { fidl::ObjectType::EVENTPAIR.into_raw() },
1800                        16387,
1801                    > as fidl::encoding::ResourceTypeMarker>::take_or_borrow(
1802                        val
1803                    ),
1804                    encoder,
1805                    offset + 8,
1806                    _depth,
1807                ),
1808                SetAndWaitMode::NotifySetupDone(ref mut val) => {
1809                    fidl::encoding::encode_in_envelope::<
1810                        fidl::encoding::HandleType<
1811                            fidl::Event,
1812                            { fidl::ObjectType::EVENT.into_raw() },
1813                            2147483648,
1814                        >,
1815                        fidl::encoding::DefaultFuchsiaResourceDialect,
1816                    >(
1817                        <fidl::encoding::HandleType<
1818                            fidl::Event,
1819                            { fidl::ObjectType::EVENT.into_raw() },
1820                            2147483648,
1821                        > as fidl::encoding::ResourceTypeMarker>::take_or_borrow(
1822                            val
1823                        ),
1824                        encoder,
1825                        offset + 8,
1826                        _depth,
1827                    )
1828                }
1829                SetAndWaitMode::__SourceBreaking { .. } => Err(fidl::Error::UnknownUnionTag),
1830            }
1831        }
1832    }
1833
1834    impl fidl::encoding::Decode<Self, fidl::encoding::DefaultFuchsiaResourceDialect>
1835        for SetAndWaitMode
1836    {
1837        #[inline(always)]
1838        fn new_empty() -> Self {
1839            Self::__SourceBreaking { unknown_ordinal: 0 }
1840        }
1841
1842        #[inline]
1843        unsafe fn decode(
1844            &mut self,
1845            decoder: &mut fidl::encoding::Decoder<
1846                '_,
1847                fidl::encoding::DefaultFuchsiaResourceDialect,
1848            >,
1849            offset: usize,
1850            mut depth: fidl::encoding::Depth,
1851        ) -> fidl::Result<()> {
1852            decoder.debug_check_bounds::<Self>(offset);
1853            #[allow(unused_variables)]
1854            let next_out_of_line = decoder.next_out_of_line();
1855            let handles_before = decoder.remaining_handles();
1856            let (ordinal, inlined, num_bytes, num_handles) =
1857                fidl::encoding::decode_union_inline_portion(decoder, offset)?;
1858
1859            let member_inline_size = match ordinal {
1860                1 => <fidl::encoding::HandleType<
1861                    fidl::EventPair,
1862                    { fidl::ObjectType::EVENTPAIR.into_raw() },
1863                    16387,
1864                > as fidl::encoding::TypeMarker>::inline_size(decoder.context),
1865                2 => <fidl::encoding::HandleType<
1866                    fidl::Event,
1867                    { fidl::ObjectType::EVENT.into_raw() },
1868                    2147483648,
1869                > as fidl::encoding::TypeMarker>::inline_size(decoder.context),
1870                0 => return Err(fidl::Error::UnknownUnionTag),
1871                _ => num_bytes as usize,
1872            };
1873
1874            if inlined != (member_inline_size <= 4) {
1875                return Err(fidl::Error::InvalidInlineBitInEnvelope);
1876            }
1877            let _inner_offset;
1878            if inlined {
1879                decoder.check_inline_envelope_padding(offset + 8, member_inline_size)?;
1880                _inner_offset = offset + 8;
1881            } else {
1882                depth.increment()?;
1883                _inner_offset = decoder.out_of_line_offset(member_inline_size)?;
1884            }
1885            match ordinal {
1886                1 => {
1887                    #[allow(irrefutable_let_patterns)]
1888                    if let SetAndWaitMode::KeepAlive(_) = self {
1889                        // Do nothing, read the value into the object
1890                    } else {
1891                        // Initialize `self` to the right variant
1892                        *self = SetAndWaitMode::KeepAlive(
1893                            fidl::new_empty!(fidl::encoding::HandleType<fidl::EventPair, { fidl::ObjectType::EVENTPAIR.into_raw() }, 16387>, fidl::encoding::DefaultFuchsiaResourceDialect),
1894                        );
1895                    }
1896                    #[allow(irrefutable_let_patterns)]
1897                    if let SetAndWaitMode::KeepAlive(ref mut val) = self {
1898                        fidl::decode!(fidl::encoding::HandleType<fidl::EventPair, { fidl::ObjectType::EVENTPAIR.into_raw() }, 16387>, fidl::encoding::DefaultFuchsiaResourceDialect, val, decoder, _inner_offset, depth)?;
1899                    } else {
1900                        unreachable!()
1901                    }
1902                }
1903                2 => {
1904                    #[allow(irrefutable_let_patterns)]
1905                    if let SetAndWaitMode::NotifySetupDone(_) = self {
1906                        // Do nothing, read the value into the object
1907                    } else {
1908                        // Initialize `self` to the right variant
1909                        *self = SetAndWaitMode::NotifySetupDone(
1910                            fidl::new_empty!(fidl::encoding::HandleType<fidl::Event, { fidl::ObjectType::EVENT.into_raw() }, 2147483648>, fidl::encoding::DefaultFuchsiaResourceDialect),
1911                        );
1912                    }
1913                    #[allow(irrefutable_let_patterns)]
1914                    if let SetAndWaitMode::NotifySetupDone(ref mut val) = self {
1915                        fidl::decode!(fidl::encoding::HandleType<fidl::Event, { fidl::ObjectType::EVENT.into_raw() }, 2147483648>, fidl::encoding::DefaultFuchsiaResourceDialect, val, decoder, _inner_offset, depth)?;
1916                    } else {
1917                        unreachable!()
1918                    }
1919                }
1920                #[allow(deprecated)]
1921                ordinal => {
1922                    for _ in 0..num_handles {
1923                        decoder.drop_next_handle()?;
1924                    }
1925                    *self = SetAndWaitMode::__SourceBreaking { unknown_ordinal: ordinal };
1926                }
1927            }
1928            if !inlined && decoder.next_out_of_line() != next_out_of_line + (num_bytes as usize) {
1929                return Err(fidl::Error::InvalidNumBytesInEnvelope);
1930            }
1931            if handles_before != decoder.remaining_handles() + (num_handles as usize) {
1932                return Err(fidl::Error::InvalidNumHandlesInEnvelope);
1933            }
1934            Ok(())
1935        }
1936    }
1937}