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