fidl_fuchsia_services_test/
fidl_fuchsia_services_test.rs

1// WARNING: This file is machine generated by fidlgen.
2
3#![warn(clippy::all)]
4#![allow(unused_parens, unused_mut, unused_imports, nonstandard_style)]
5
6use bitflags::bitflags;
7use fidl::client::QueryResponseFut;
8use fidl::encoding::{MessageBufFor, ProxyChannelBox, ResourceDialect};
9use fidl::endpoints::{ControlHandle as _, Responder as _};
10use futures::future::{self, MaybeDone, TryFutureExt};
11use zx_status;
12
13#[derive(Debug, Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Hash)]
14pub struct ControlPlaneMarker;
15
16impl fidl::endpoints::ProtocolMarker for ControlPlaneMarker {
17    type Proxy = ControlPlaneProxy;
18    type RequestStream = ControlPlaneRequestStream;
19    #[cfg(target_os = "fuchsia")]
20    type SynchronousProxy = ControlPlaneSynchronousProxy;
21
22    const DEBUG_NAME: &'static str = "(anonymous) ControlPlane";
23}
24
25pub trait ControlPlaneProxyInterface: Send + Sync {
26    type ControlDoResponseFut: std::future::Future<Output = Result<(), fidl::Error>> + Send;
27    fn r#control_do(&self) -> Self::ControlDoResponseFut;
28}
29#[derive(Debug)]
30#[cfg(target_os = "fuchsia")]
31pub struct ControlPlaneSynchronousProxy {
32    client: fidl::client::sync::Client,
33}
34
35#[cfg(target_os = "fuchsia")]
36impl fidl::endpoints::SynchronousProxy for ControlPlaneSynchronousProxy {
37    type Proxy = ControlPlaneProxy;
38    type Protocol = ControlPlaneMarker;
39
40    fn from_channel(inner: fidl::Channel) -> Self {
41        Self::new(inner)
42    }
43
44    fn into_channel(self) -> fidl::Channel {
45        self.client.into_channel()
46    }
47
48    fn as_channel(&self) -> &fidl::Channel {
49        self.client.as_channel()
50    }
51}
52
53#[cfg(target_os = "fuchsia")]
54impl ControlPlaneSynchronousProxy {
55    pub fn new(channel: fidl::Channel) -> Self {
56        let protocol_name = <ControlPlaneMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME;
57        Self { client: fidl::client::sync::Client::new(channel, protocol_name) }
58    }
59
60    pub fn into_channel(self) -> fidl::Channel {
61        self.client.into_channel()
62    }
63
64    /// Waits until an event arrives and returns it. It is safe for other
65    /// threads to make concurrent requests while waiting for an event.
66    pub fn wait_for_event(
67        &self,
68        deadline: zx::MonotonicInstant,
69    ) -> Result<ControlPlaneEvent, fidl::Error> {
70        ControlPlaneEvent::decode(self.client.wait_for_event(deadline)?)
71    }
72
73    pub fn r#control_do(&self, ___deadline: zx::MonotonicInstant) -> Result<(), fidl::Error> {
74        let _response =
75            self.client.send_query::<fidl::encoding::EmptyPayload, fidl::encoding::EmptyPayload>(
76                (),
77                0x668f0515ba2e1ebc,
78                fidl::encoding::DynamicFlags::empty(),
79                ___deadline,
80            )?;
81        Ok(_response)
82    }
83}
84
85#[derive(Debug, Clone)]
86pub struct ControlPlaneProxy {
87    client: fidl::client::Client<fidl::encoding::DefaultFuchsiaResourceDialect>,
88}
89
90impl fidl::endpoints::Proxy for ControlPlaneProxy {
91    type Protocol = ControlPlaneMarker;
92
93    fn from_channel(inner: ::fidl::AsyncChannel) -> Self {
94        Self::new(inner)
95    }
96
97    fn into_channel(self) -> Result<::fidl::AsyncChannel, Self> {
98        self.client.into_channel().map_err(|client| Self { client })
99    }
100
101    fn as_channel(&self) -> &::fidl::AsyncChannel {
102        self.client.as_channel()
103    }
104}
105
106impl ControlPlaneProxy {
107    /// Create a new Proxy for fuchsia.services.test/ControlPlane.
108    pub fn new(channel: ::fidl::AsyncChannel) -> Self {
109        let protocol_name = <ControlPlaneMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME;
110        Self { client: fidl::client::Client::new(channel, protocol_name) }
111    }
112
113    /// Get a Stream of events from the remote end of the protocol.
114    ///
115    /// # Panics
116    ///
117    /// Panics if the event stream was already taken.
118    pub fn take_event_stream(&self) -> ControlPlaneEventStream {
119        ControlPlaneEventStream { event_receiver: self.client.take_event_receiver() }
120    }
121
122    pub fn r#control_do(
123        &self,
124    ) -> fidl::client::QueryResponseFut<(), fidl::encoding::DefaultFuchsiaResourceDialect> {
125        ControlPlaneProxyInterface::r#control_do(self)
126    }
127}
128
129impl ControlPlaneProxyInterface for ControlPlaneProxy {
130    type ControlDoResponseFut =
131        fidl::client::QueryResponseFut<(), fidl::encoding::DefaultFuchsiaResourceDialect>;
132    fn r#control_do(&self) -> Self::ControlDoResponseFut {
133        fn _decode(
134            mut _buf: Result<<fidl::encoding::DefaultFuchsiaResourceDialect as fidl::encoding::ResourceDialect>::MessageBufEtc, fidl::Error>,
135        ) -> Result<(), fidl::Error> {
136            let _response = fidl::client::decode_transaction_body::<
137                fidl::encoding::EmptyPayload,
138                fidl::encoding::DefaultFuchsiaResourceDialect,
139                0x668f0515ba2e1ebc,
140            >(_buf?)?;
141            Ok(_response)
142        }
143        self.client.send_query_and_decode::<fidl::encoding::EmptyPayload, ()>(
144            (),
145            0x668f0515ba2e1ebc,
146            fidl::encoding::DynamicFlags::empty(),
147            _decode,
148        )
149    }
150}
151
152pub struct ControlPlaneEventStream {
153    event_receiver: fidl::client::EventReceiver<fidl::encoding::DefaultFuchsiaResourceDialect>,
154}
155
156impl std::marker::Unpin for ControlPlaneEventStream {}
157
158impl futures::stream::FusedStream for ControlPlaneEventStream {
159    fn is_terminated(&self) -> bool {
160        self.event_receiver.is_terminated()
161    }
162}
163
164impl futures::Stream for ControlPlaneEventStream {
165    type Item = Result<ControlPlaneEvent, fidl::Error>;
166
167    fn poll_next(
168        mut self: std::pin::Pin<&mut Self>,
169        cx: &mut std::task::Context<'_>,
170    ) -> std::task::Poll<Option<Self::Item>> {
171        match futures::ready!(futures::stream::StreamExt::poll_next_unpin(
172            &mut self.event_receiver,
173            cx
174        )?) {
175            Some(buf) => std::task::Poll::Ready(Some(ControlPlaneEvent::decode(buf))),
176            None => std::task::Poll::Ready(None),
177        }
178    }
179}
180
181#[derive(Debug)]
182pub enum ControlPlaneEvent {}
183
184impl ControlPlaneEvent {
185    /// Decodes a message buffer as a [`ControlPlaneEvent`].
186    fn decode(
187        mut buf: <fidl::encoding::DefaultFuchsiaResourceDialect as fidl::encoding::ResourceDialect>::MessageBufEtc,
188    ) -> Result<ControlPlaneEvent, fidl::Error> {
189        let (bytes, _handles) = buf.split_mut();
190        let (tx_header, _body_bytes) = fidl::encoding::decode_transaction_header(bytes)?;
191        debug_assert_eq!(tx_header.tx_id, 0);
192        match tx_header.ordinal {
193            _ => Err(fidl::Error::UnknownOrdinal {
194                ordinal: tx_header.ordinal,
195                protocol_name: <ControlPlaneMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME,
196            }),
197        }
198    }
199}
200
201/// A Stream of incoming requests for fuchsia.services.test/ControlPlane.
202pub struct ControlPlaneRequestStream {
203    inner: std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>,
204    is_terminated: bool,
205}
206
207impl std::marker::Unpin for ControlPlaneRequestStream {}
208
209impl futures::stream::FusedStream for ControlPlaneRequestStream {
210    fn is_terminated(&self) -> bool {
211        self.is_terminated
212    }
213}
214
215impl fidl::endpoints::RequestStream for ControlPlaneRequestStream {
216    type Protocol = ControlPlaneMarker;
217    type ControlHandle = ControlPlaneControlHandle;
218
219    fn from_channel(channel: ::fidl::AsyncChannel) -> Self {
220        Self { inner: std::sync::Arc::new(fidl::ServeInner::new(channel)), is_terminated: false }
221    }
222
223    fn control_handle(&self) -> Self::ControlHandle {
224        ControlPlaneControlHandle { inner: self.inner.clone() }
225    }
226
227    fn into_inner(
228        self,
229    ) -> (::std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>, bool)
230    {
231        (self.inner, self.is_terminated)
232    }
233
234    fn from_inner(
235        inner: std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>,
236        is_terminated: bool,
237    ) -> Self {
238        Self { inner, is_terminated }
239    }
240}
241
242impl futures::Stream for ControlPlaneRequestStream {
243    type Item = Result<ControlPlaneRequest, fidl::Error>;
244
245    fn poll_next(
246        mut self: std::pin::Pin<&mut Self>,
247        cx: &mut std::task::Context<'_>,
248    ) -> std::task::Poll<Option<Self::Item>> {
249        let this = &mut *self;
250        if this.inner.check_shutdown(cx) {
251            this.is_terminated = true;
252            return std::task::Poll::Ready(None);
253        }
254        if this.is_terminated {
255            panic!("polled ControlPlaneRequestStream after completion");
256        }
257        fidl::encoding::with_tls_decode_buf::<_, fidl::encoding::DefaultFuchsiaResourceDialect>(
258            |bytes, handles| {
259                match this.inner.channel().read_etc(cx, bytes, handles) {
260                    std::task::Poll::Ready(Ok(())) => {}
261                    std::task::Poll::Pending => return std::task::Poll::Pending,
262                    std::task::Poll::Ready(Err(zx_status::Status::PEER_CLOSED)) => {
263                        this.is_terminated = true;
264                        return std::task::Poll::Ready(None);
265                    }
266                    std::task::Poll::Ready(Err(e)) => {
267                        return std::task::Poll::Ready(Some(Err(fidl::Error::ServerRequestRead(
268                            e.into(),
269                        ))))
270                    }
271                }
272
273                // A message has been received from the channel
274                let (header, _body_bytes) = fidl::encoding::decode_transaction_header(bytes)?;
275
276                std::task::Poll::Ready(Some(match header.ordinal {
277                    0x668f0515ba2e1ebc => {
278                        header.validate_request_tx_id(fidl::MethodType::TwoWay)?;
279                        let mut req = fidl::new_empty!(
280                            fidl::encoding::EmptyPayload,
281                            fidl::encoding::DefaultFuchsiaResourceDialect
282                        );
283                        fidl::encoding::Decoder::<fidl::encoding::DefaultFuchsiaResourceDialect>::decode_into::<fidl::encoding::EmptyPayload>(&header, _body_bytes, handles, &mut req)?;
284                        let control_handle =
285                            ControlPlaneControlHandle { inner: this.inner.clone() };
286                        Ok(ControlPlaneRequest::ControlDo {
287                            responder: ControlPlaneControlDoResponder {
288                                control_handle: std::mem::ManuallyDrop::new(control_handle),
289                                tx_id: header.tx_id,
290                            },
291                        })
292                    }
293                    _ => Err(fidl::Error::UnknownOrdinal {
294                        ordinal: header.ordinal,
295                        protocol_name:
296                            <ControlPlaneMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME,
297                    }),
298                }))
299            },
300        )
301    }
302}
303
304#[derive(Debug)]
305pub enum ControlPlaneRequest {
306    ControlDo { responder: ControlPlaneControlDoResponder },
307}
308
309impl ControlPlaneRequest {
310    #[allow(irrefutable_let_patterns)]
311    pub fn into_control_do(self) -> Option<(ControlPlaneControlDoResponder)> {
312        if let ControlPlaneRequest::ControlDo { responder } = self {
313            Some((responder))
314        } else {
315            None
316        }
317    }
318
319    /// Name of the method defined in FIDL
320    pub fn method_name(&self) -> &'static str {
321        match *self {
322            ControlPlaneRequest::ControlDo { .. } => "control_do",
323        }
324    }
325}
326
327#[derive(Debug, Clone)]
328pub struct ControlPlaneControlHandle {
329    inner: std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>,
330}
331
332impl fidl::endpoints::ControlHandle for ControlPlaneControlHandle {
333    fn shutdown(&self) {
334        self.inner.shutdown()
335    }
336    fn shutdown_with_epitaph(&self, status: zx_status::Status) {
337        self.inner.shutdown_with_epitaph(status)
338    }
339
340    fn is_closed(&self) -> bool {
341        self.inner.channel().is_closed()
342    }
343    fn on_closed(&self) -> fidl::OnSignalsRef<'_> {
344        self.inner.channel().on_closed()
345    }
346
347    #[cfg(target_os = "fuchsia")]
348    fn signal_peer(
349        &self,
350        clear_mask: zx::Signals,
351        set_mask: zx::Signals,
352    ) -> Result<(), zx_status::Status> {
353        use fidl::Peered;
354        self.inner.channel().signal_peer(clear_mask, set_mask)
355    }
356}
357
358impl ControlPlaneControlHandle {}
359
360#[must_use = "FIDL methods require a response to be sent"]
361#[derive(Debug)]
362pub struct ControlPlaneControlDoResponder {
363    control_handle: std::mem::ManuallyDrop<ControlPlaneControlHandle>,
364    tx_id: u32,
365}
366
367/// Set the the channel to be shutdown (see [`ControlPlaneControlHandle::shutdown`])
368/// if the responder is dropped without sending a response, so that the client
369/// doesn't hang. To prevent this behavior, call `drop_without_shutdown`.
370impl std::ops::Drop for ControlPlaneControlDoResponder {
371    fn drop(&mut self) {
372        self.control_handle.shutdown();
373        // Safety: drops once, never accessed again
374        unsafe { std::mem::ManuallyDrop::drop(&mut self.control_handle) };
375    }
376}
377
378impl fidl::endpoints::Responder for ControlPlaneControlDoResponder {
379    type ControlHandle = ControlPlaneControlHandle;
380
381    fn control_handle(&self) -> &ControlPlaneControlHandle {
382        &self.control_handle
383    }
384
385    fn drop_without_shutdown(mut self) {
386        // Safety: drops once, never accessed again due to mem::forget
387        unsafe { std::mem::ManuallyDrop::drop(&mut self.control_handle) };
388        // Prevent Drop from running (which would shut down the channel)
389        std::mem::forget(self);
390    }
391}
392
393impl ControlPlaneControlDoResponder {
394    /// Sends a response to the FIDL transaction.
395    ///
396    /// Sets the channel to shutdown if an error occurs.
397    pub fn send(self) -> Result<(), fidl::Error> {
398        let _result = self.send_raw();
399        if _result.is_err() {
400            self.control_handle.shutdown();
401        }
402        self.drop_without_shutdown();
403        _result
404    }
405
406    /// Similar to "send" but does not shutdown the channel if an error occurs.
407    pub fn send_no_shutdown_on_err(self) -> Result<(), fidl::Error> {
408        let _result = self.send_raw();
409        self.drop_without_shutdown();
410        _result
411    }
412
413    fn send_raw(&self) -> Result<(), fidl::Error> {
414        self.control_handle.inner.send::<fidl::encoding::EmptyPayload>(
415            (),
416            self.tx_id,
417            0x668f0515ba2e1ebc,
418            fidl::encoding::DynamicFlags::empty(),
419        )
420    }
421}
422
423#[derive(Debug, Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Hash)]
424pub struct DataPlaneMarker;
425
426impl fidl::endpoints::ProtocolMarker for DataPlaneMarker {
427    type Proxy = DataPlaneProxy;
428    type RequestStream = DataPlaneRequestStream;
429    #[cfg(target_os = "fuchsia")]
430    type SynchronousProxy = DataPlaneSynchronousProxy;
431
432    const DEBUG_NAME: &'static str = "(anonymous) DataPlane";
433}
434
435pub trait DataPlaneProxyInterface: Send + Sync {
436    type DataDoResponseFut: std::future::Future<Output = Result<(), fidl::Error>> + Send;
437    fn r#data_do(&self) -> Self::DataDoResponseFut;
438}
439#[derive(Debug)]
440#[cfg(target_os = "fuchsia")]
441pub struct DataPlaneSynchronousProxy {
442    client: fidl::client::sync::Client,
443}
444
445#[cfg(target_os = "fuchsia")]
446impl fidl::endpoints::SynchronousProxy for DataPlaneSynchronousProxy {
447    type Proxy = DataPlaneProxy;
448    type Protocol = DataPlaneMarker;
449
450    fn from_channel(inner: fidl::Channel) -> Self {
451        Self::new(inner)
452    }
453
454    fn into_channel(self) -> fidl::Channel {
455        self.client.into_channel()
456    }
457
458    fn as_channel(&self) -> &fidl::Channel {
459        self.client.as_channel()
460    }
461}
462
463#[cfg(target_os = "fuchsia")]
464impl DataPlaneSynchronousProxy {
465    pub fn new(channel: fidl::Channel) -> Self {
466        let protocol_name = <DataPlaneMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME;
467        Self { client: fidl::client::sync::Client::new(channel, protocol_name) }
468    }
469
470    pub fn into_channel(self) -> fidl::Channel {
471        self.client.into_channel()
472    }
473
474    /// Waits until an event arrives and returns it. It is safe for other
475    /// threads to make concurrent requests while waiting for an event.
476    pub fn wait_for_event(
477        &self,
478        deadline: zx::MonotonicInstant,
479    ) -> Result<DataPlaneEvent, fidl::Error> {
480        DataPlaneEvent::decode(self.client.wait_for_event(deadline)?)
481    }
482
483    pub fn r#data_do(&self, ___deadline: zx::MonotonicInstant) -> Result<(), fidl::Error> {
484        let _response =
485            self.client.send_query::<fidl::encoding::EmptyPayload, fidl::encoding::EmptyPayload>(
486                (),
487                0x1c8c82496b32e147,
488                fidl::encoding::DynamicFlags::empty(),
489                ___deadline,
490            )?;
491        Ok(_response)
492    }
493}
494
495#[derive(Debug, Clone)]
496pub struct DataPlaneProxy {
497    client: fidl::client::Client<fidl::encoding::DefaultFuchsiaResourceDialect>,
498}
499
500impl fidl::endpoints::Proxy for DataPlaneProxy {
501    type Protocol = DataPlaneMarker;
502
503    fn from_channel(inner: ::fidl::AsyncChannel) -> Self {
504        Self::new(inner)
505    }
506
507    fn into_channel(self) -> Result<::fidl::AsyncChannel, Self> {
508        self.client.into_channel().map_err(|client| Self { client })
509    }
510
511    fn as_channel(&self) -> &::fidl::AsyncChannel {
512        self.client.as_channel()
513    }
514}
515
516impl DataPlaneProxy {
517    /// Create a new Proxy for fuchsia.services.test/DataPlane.
518    pub fn new(channel: ::fidl::AsyncChannel) -> Self {
519        let protocol_name = <DataPlaneMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME;
520        Self { client: fidl::client::Client::new(channel, protocol_name) }
521    }
522
523    /// Get a Stream of events from the remote end of the protocol.
524    ///
525    /// # Panics
526    ///
527    /// Panics if the event stream was already taken.
528    pub fn take_event_stream(&self) -> DataPlaneEventStream {
529        DataPlaneEventStream { event_receiver: self.client.take_event_receiver() }
530    }
531
532    pub fn r#data_do(
533        &self,
534    ) -> fidl::client::QueryResponseFut<(), fidl::encoding::DefaultFuchsiaResourceDialect> {
535        DataPlaneProxyInterface::r#data_do(self)
536    }
537}
538
539impl DataPlaneProxyInterface for DataPlaneProxy {
540    type DataDoResponseFut =
541        fidl::client::QueryResponseFut<(), fidl::encoding::DefaultFuchsiaResourceDialect>;
542    fn r#data_do(&self) -> Self::DataDoResponseFut {
543        fn _decode(
544            mut _buf: Result<<fidl::encoding::DefaultFuchsiaResourceDialect as fidl::encoding::ResourceDialect>::MessageBufEtc, fidl::Error>,
545        ) -> Result<(), fidl::Error> {
546            let _response = fidl::client::decode_transaction_body::<
547                fidl::encoding::EmptyPayload,
548                fidl::encoding::DefaultFuchsiaResourceDialect,
549                0x1c8c82496b32e147,
550            >(_buf?)?;
551            Ok(_response)
552        }
553        self.client.send_query_and_decode::<fidl::encoding::EmptyPayload, ()>(
554            (),
555            0x1c8c82496b32e147,
556            fidl::encoding::DynamicFlags::empty(),
557            _decode,
558        )
559    }
560}
561
562pub struct DataPlaneEventStream {
563    event_receiver: fidl::client::EventReceiver<fidl::encoding::DefaultFuchsiaResourceDialect>,
564}
565
566impl std::marker::Unpin for DataPlaneEventStream {}
567
568impl futures::stream::FusedStream for DataPlaneEventStream {
569    fn is_terminated(&self) -> bool {
570        self.event_receiver.is_terminated()
571    }
572}
573
574impl futures::Stream for DataPlaneEventStream {
575    type Item = Result<DataPlaneEvent, fidl::Error>;
576
577    fn poll_next(
578        mut self: std::pin::Pin<&mut Self>,
579        cx: &mut std::task::Context<'_>,
580    ) -> std::task::Poll<Option<Self::Item>> {
581        match futures::ready!(futures::stream::StreamExt::poll_next_unpin(
582            &mut self.event_receiver,
583            cx
584        )?) {
585            Some(buf) => std::task::Poll::Ready(Some(DataPlaneEvent::decode(buf))),
586            None => std::task::Poll::Ready(None),
587        }
588    }
589}
590
591#[derive(Debug)]
592pub enum DataPlaneEvent {}
593
594impl DataPlaneEvent {
595    /// Decodes a message buffer as a [`DataPlaneEvent`].
596    fn decode(
597        mut buf: <fidl::encoding::DefaultFuchsiaResourceDialect as fidl::encoding::ResourceDialect>::MessageBufEtc,
598    ) -> Result<DataPlaneEvent, fidl::Error> {
599        let (bytes, _handles) = buf.split_mut();
600        let (tx_header, _body_bytes) = fidl::encoding::decode_transaction_header(bytes)?;
601        debug_assert_eq!(tx_header.tx_id, 0);
602        match tx_header.ordinal {
603            _ => Err(fidl::Error::UnknownOrdinal {
604                ordinal: tx_header.ordinal,
605                protocol_name: <DataPlaneMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME,
606            }),
607        }
608    }
609}
610
611/// A Stream of incoming requests for fuchsia.services.test/DataPlane.
612pub struct DataPlaneRequestStream {
613    inner: std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>,
614    is_terminated: bool,
615}
616
617impl std::marker::Unpin for DataPlaneRequestStream {}
618
619impl futures::stream::FusedStream for DataPlaneRequestStream {
620    fn is_terminated(&self) -> bool {
621        self.is_terminated
622    }
623}
624
625impl fidl::endpoints::RequestStream for DataPlaneRequestStream {
626    type Protocol = DataPlaneMarker;
627    type ControlHandle = DataPlaneControlHandle;
628
629    fn from_channel(channel: ::fidl::AsyncChannel) -> Self {
630        Self { inner: std::sync::Arc::new(fidl::ServeInner::new(channel)), is_terminated: false }
631    }
632
633    fn control_handle(&self) -> Self::ControlHandle {
634        DataPlaneControlHandle { inner: self.inner.clone() }
635    }
636
637    fn into_inner(
638        self,
639    ) -> (::std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>, bool)
640    {
641        (self.inner, self.is_terminated)
642    }
643
644    fn from_inner(
645        inner: std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>,
646        is_terminated: bool,
647    ) -> Self {
648        Self { inner, is_terminated }
649    }
650}
651
652impl futures::Stream for DataPlaneRequestStream {
653    type Item = Result<DataPlaneRequest, fidl::Error>;
654
655    fn poll_next(
656        mut self: std::pin::Pin<&mut Self>,
657        cx: &mut std::task::Context<'_>,
658    ) -> std::task::Poll<Option<Self::Item>> {
659        let this = &mut *self;
660        if this.inner.check_shutdown(cx) {
661            this.is_terminated = true;
662            return std::task::Poll::Ready(None);
663        }
664        if this.is_terminated {
665            panic!("polled DataPlaneRequestStream after completion");
666        }
667        fidl::encoding::with_tls_decode_buf::<_, fidl::encoding::DefaultFuchsiaResourceDialect>(
668            |bytes, handles| {
669                match this.inner.channel().read_etc(cx, bytes, handles) {
670                    std::task::Poll::Ready(Ok(())) => {}
671                    std::task::Poll::Pending => return std::task::Poll::Pending,
672                    std::task::Poll::Ready(Err(zx_status::Status::PEER_CLOSED)) => {
673                        this.is_terminated = true;
674                        return std::task::Poll::Ready(None);
675                    }
676                    std::task::Poll::Ready(Err(e)) => {
677                        return std::task::Poll::Ready(Some(Err(fidl::Error::ServerRequestRead(
678                            e.into(),
679                        ))))
680                    }
681                }
682
683                // A message has been received from the channel
684                let (header, _body_bytes) = fidl::encoding::decode_transaction_header(bytes)?;
685
686                std::task::Poll::Ready(Some(match header.ordinal {
687                    0x1c8c82496b32e147 => {
688                        header.validate_request_tx_id(fidl::MethodType::TwoWay)?;
689                        let mut req = fidl::new_empty!(
690                            fidl::encoding::EmptyPayload,
691                            fidl::encoding::DefaultFuchsiaResourceDialect
692                        );
693                        fidl::encoding::Decoder::<fidl::encoding::DefaultFuchsiaResourceDialect>::decode_into::<fidl::encoding::EmptyPayload>(&header, _body_bytes, handles, &mut req)?;
694                        let control_handle = DataPlaneControlHandle { inner: this.inner.clone() };
695                        Ok(DataPlaneRequest::DataDo {
696                            responder: DataPlaneDataDoResponder {
697                                control_handle: std::mem::ManuallyDrop::new(control_handle),
698                                tx_id: header.tx_id,
699                            },
700                        })
701                    }
702                    _ => Err(fidl::Error::UnknownOrdinal {
703                        ordinal: header.ordinal,
704                        protocol_name:
705                            <DataPlaneMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME,
706                    }),
707                }))
708            },
709        )
710    }
711}
712
713#[derive(Debug)]
714pub enum DataPlaneRequest {
715    DataDo { responder: DataPlaneDataDoResponder },
716}
717
718impl DataPlaneRequest {
719    #[allow(irrefutable_let_patterns)]
720    pub fn into_data_do(self) -> Option<(DataPlaneDataDoResponder)> {
721        if let DataPlaneRequest::DataDo { responder } = self {
722            Some((responder))
723        } else {
724            None
725        }
726    }
727
728    /// Name of the method defined in FIDL
729    pub fn method_name(&self) -> &'static str {
730        match *self {
731            DataPlaneRequest::DataDo { .. } => "data_do",
732        }
733    }
734}
735
736#[derive(Debug, Clone)]
737pub struct DataPlaneControlHandle {
738    inner: std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>,
739}
740
741impl fidl::endpoints::ControlHandle for DataPlaneControlHandle {
742    fn shutdown(&self) {
743        self.inner.shutdown()
744    }
745    fn shutdown_with_epitaph(&self, status: zx_status::Status) {
746        self.inner.shutdown_with_epitaph(status)
747    }
748
749    fn is_closed(&self) -> bool {
750        self.inner.channel().is_closed()
751    }
752    fn on_closed(&self) -> fidl::OnSignalsRef<'_> {
753        self.inner.channel().on_closed()
754    }
755
756    #[cfg(target_os = "fuchsia")]
757    fn signal_peer(
758        &self,
759        clear_mask: zx::Signals,
760        set_mask: zx::Signals,
761    ) -> Result<(), zx_status::Status> {
762        use fidl::Peered;
763        self.inner.channel().signal_peer(clear_mask, set_mask)
764    }
765}
766
767impl DataPlaneControlHandle {}
768
769#[must_use = "FIDL methods require a response to be sent"]
770#[derive(Debug)]
771pub struct DataPlaneDataDoResponder {
772    control_handle: std::mem::ManuallyDrop<DataPlaneControlHandle>,
773    tx_id: u32,
774}
775
776/// Set the the channel to be shutdown (see [`DataPlaneControlHandle::shutdown`])
777/// if the responder is dropped without sending a response, so that the client
778/// doesn't hang. To prevent this behavior, call `drop_without_shutdown`.
779impl std::ops::Drop for DataPlaneDataDoResponder {
780    fn drop(&mut self) {
781        self.control_handle.shutdown();
782        // Safety: drops once, never accessed again
783        unsafe { std::mem::ManuallyDrop::drop(&mut self.control_handle) };
784    }
785}
786
787impl fidl::endpoints::Responder for DataPlaneDataDoResponder {
788    type ControlHandle = DataPlaneControlHandle;
789
790    fn control_handle(&self) -> &DataPlaneControlHandle {
791        &self.control_handle
792    }
793
794    fn drop_without_shutdown(mut self) {
795        // Safety: drops once, never accessed again due to mem::forget
796        unsafe { std::mem::ManuallyDrop::drop(&mut self.control_handle) };
797        // Prevent Drop from running (which would shut down the channel)
798        std::mem::forget(self);
799    }
800}
801
802impl DataPlaneDataDoResponder {
803    /// Sends a response to the FIDL transaction.
804    ///
805    /// Sets the channel to shutdown if an error occurs.
806    pub fn send(self) -> Result<(), fidl::Error> {
807        let _result = self.send_raw();
808        if _result.is_err() {
809            self.control_handle.shutdown();
810        }
811        self.drop_without_shutdown();
812        _result
813    }
814
815    /// Similar to "send" but does not shutdown the channel if an error occurs.
816    pub fn send_no_shutdown_on_err(self) -> Result<(), fidl::Error> {
817        let _result = self.send_raw();
818        self.drop_without_shutdown();
819        _result
820    }
821
822    fn send_raw(&self) -> Result<(), fidl::Error> {
823        self.control_handle.inner.send::<fidl::encoding::EmptyPayload>(
824            (),
825            self.tx_id,
826            0x1c8c82496b32e147,
827            fidl::encoding::DynamicFlags::empty(),
828        )
829    }
830}
831
832#[derive(Debug, Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Hash)]
833pub struct DeviceMarker;
834
835#[cfg(target_os = "fuchsia")]
836impl fidl::endpoints::ServiceMarker for DeviceMarker {
837    type Proxy = DeviceProxy;
838    type Request = DeviceRequest;
839    const SERVICE_NAME: &'static str = "fuchsia.services.test.Device";
840}
841
842/// A request for one of the member protocols of Device.
843///
844#[cfg(target_os = "fuchsia")]
845pub enum DeviceRequest {
846    Control(ControlPlaneRequestStream),
847    Data(DataPlaneRequestStream),
848}
849
850#[cfg(target_os = "fuchsia")]
851impl fidl::endpoints::ServiceRequest for DeviceRequest {
852    type Service = DeviceMarker;
853
854    fn dispatch(name: &str, _channel: fidl::AsyncChannel) -> Self {
855        match name {
856            "control" => Self::Control(
857                <ControlPlaneRequestStream as fidl::endpoints::RequestStream>::from_channel(
858                    _channel,
859                ),
860            ),
861            "data" => Self::Data(
862                <DataPlaneRequestStream as fidl::endpoints::RequestStream>::from_channel(_channel),
863            ),
864            _ => panic!("no such member protocol name for service Device"),
865        }
866    }
867
868    fn member_names() -> &'static [&'static str] {
869        &["control", "data"]
870    }
871}
872#[cfg(target_os = "fuchsia")]
873pub struct DeviceProxy(#[allow(dead_code)] Box<dyn fidl::endpoints::MemberOpener>);
874
875#[cfg(target_os = "fuchsia")]
876impl fidl::endpoints::ServiceProxy for DeviceProxy {
877    type Service = DeviceMarker;
878
879    fn from_member_opener(opener: Box<dyn fidl::endpoints::MemberOpener>) -> Self {
880        Self(opener)
881    }
882}
883
884#[cfg(target_os = "fuchsia")]
885impl DeviceProxy {
886    pub fn connect_to_control(&self) -> Result<ControlPlaneProxy, fidl::Error> {
887        let (proxy, server_end) = fidl::endpoints::create_proxy::<ControlPlaneMarker>();
888        self.connect_channel_to_control(server_end)?;
889        Ok(proxy)
890    }
891
892    /// Like `connect_to_control`, but returns a sync proxy.
893    /// See [`Self::connect_to_control`] for more details.
894    pub fn connect_to_control_sync(&self) -> Result<ControlPlaneSynchronousProxy, fidl::Error> {
895        let (proxy, server_end) = fidl::endpoints::create_sync_proxy::<ControlPlaneMarker>();
896        self.connect_channel_to_control(server_end)?;
897        Ok(proxy)
898    }
899
900    /// Like `connect_to_control`, but accepts a server end.
901    /// See [`Self::connect_to_control`] for more details.
902    pub fn connect_channel_to_control(
903        &self,
904        server_end: fidl::endpoints::ServerEnd<ControlPlaneMarker>,
905    ) -> Result<(), fidl::Error> {
906        self.0.open_member("control", server_end.into_channel())
907    }
908    pub fn connect_to_data(&self) -> Result<DataPlaneProxy, fidl::Error> {
909        let (proxy, server_end) = fidl::endpoints::create_proxy::<DataPlaneMarker>();
910        self.connect_channel_to_data(server_end)?;
911        Ok(proxy)
912    }
913
914    /// Like `connect_to_data`, but returns a sync proxy.
915    /// See [`Self::connect_to_data`] for more details.
916    pub fn connect_to_data_sync(&self) -> Result<DataPlaneSynchronousProxy, fidl::Error> {
917        let (proxy, server_end) = fidl::endpoints::create_sync_proxy::<DataPlaneMarker>();
918        self.connect_channel_to_data(server_end)?;
919        Ok(proxy)
920    }
921
922    /// Like `connect_to_data`, but accepts a server end.
923    /// See [`Self::connect_to_data`] for more details.
924    pub fn connect_channel_to_data(
925        &self,
926        server_end: fidl::endpoints::ServerEnd<DataPlaneMarker>,
927    ) -> Result<(), fidl::Error> {
928        self.0.open_member("data", server_end.into_channel())
929    }
930
931    pub fn instance_name(&self) -> &str {
932        self.0.instance_name()
933    }
934}
935
936mod internal {
937    use super::*;
938}