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