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