Skip to main content

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