fidl_test_protocol_connector/
fidl_test_protocol_connector.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_test_protocol_connector_common::*;
11use futures::future::{self, MaybeDone, TryFutureExt};
12use zx_status;
13
14#[derive(Debug, Eq, Hash, Ord, PartialEq, PartialOrd)]
15pub struct ProtocolFactoryCreateProtocolRequest {
16    pub protocol: fidl::endpoints::ServerEnd<ProtocolMarker>,
17}
18
19impl fidl::Standalone<fidl::encoding::DefaultFuchsiaResourceDialect>
20    for ProtocolFactoryCreateProtocolRequest
21{
22}
23
24#[derive(Debug, Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Hash)]
25pub struct ProtocolMarker;
26
27impl fidl::endpoints::ProtocolMarker for ProtocolMarker {
28    type Proxy = ProtocolProxy;
29    type RequestStream = ProtocolRequestStream;
30    #[cfg(target_os = "fuchsia")]
31    type SynchronousProxy = ProtocolSynchronousProxy;
32
33    const DEBUG_NAME: &'static str = "(anonymous) Protocol";
34}
35pub type ProtocolDoActionResult = Result<(), Error>;
36
37pub trait ProtocolProxyInterface: Send + Sync {
38    type DoActionResponseFut: std::future::Future<Output = Result<ProtocolDoActionResult, fidl::Error>>
39        + Send;
40    fn r#do_action(&self) -> Self::DoActionResponseFut;
41}
42#[derive(Debug)]
43#[cfg(target_os = "fuchsia")]
44pub struct ProtocolSynchronousProxy {
45    client: fidl::client::sync::Client,
46}
47
48#[cfg(target_os = "fuchsia")]
49impl fidl::endpoints::SynchronousProxy for ProtocolSynchronousProxy {
50    type Proxy = ProtocolProxy;
51    type Protocol = ProtocolMarker;
52
53    fn from_channel(inner: fidl::Channel) -> Self {
54        Self::new(inner)
55    }
56
57    fn into_channel(self) -> fidl::Channel {
58        self.client.into_channel()
59    }
60
61    fn as_channel(&self) -> &fidl::Channel {
62        self.client.as_channel()
63    }
64}
65
66#[cfg(target_os = "fuchsia")]
67impl ProtocolSynchronousProxy {
68    pub fn new(channel: fidl::Channel) -> Self {
69        let protocol_name = <ProtocolMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME;
70        Self { client: fidl::client::sync::Client::new(channel, protocol_name) }
71    }
72
73    pub fn into_channel(self) -> fidl::Channel {
74        self.client.into_channel()
75    }
76
77    /// Waits until an event arrives and returns it. It is safe for other
78    /// threads to make concurrent requests while waiting for an event.
79    pub fn wait_for_event(
80        &self,
81        deadline: zx::MonotonicInstant,
82    ) -> Result<ProtocolEvent, fidl::Error> {
83        ProtocolEvent::decode(self.client.wait_for_event(deadline)?)
84    }
85
86    pub fn r#do_action(
87        &self,
88        ___deadline: zx::MonotonicInstant,
89    ) -> Result<ProtocolDoActionResult, fidl::Error> {
90        let _response = self.client.send_query::<
91            fidl::encoding::EmptyPayload,
92            fidl::encoding::ResultType<fidl::encoding::EmptyStruct, Error>,
93        >(
94            (),
95            0x8831ffac41f0c9f,
96            fidl::encoding::DynamicFlags::empty(),
97            ___deadline,
98        )?;
99        Ok(_response.map(|x| x))
100    }
101}
102
103#[cfg(target_os = "fuchsia")]
104impl From<ProtocolSynchronousProxy> for zx::Handle {
105    fn from(value: ProtocolSynchronousProxy) -> Self {
106        value.into_channel().into()
107    }
108}
109
110#[cfg(target_os = "fuchsia")]
111impl From<fidl::Channel> for ProtocolSynchronousProxy {
112    fn from(value: fidl::Channel) -> Self {
113        Self::new(value)
114    }
115}
116
117#[derive(Debug, Clone)]
118pub struct ProtocolProxy {
119    client: fidl::client::Client<fidl::encoding::DefaultFuchsiaResourceDialect>,
120}
121
122impl fidl::endpoints::Proxy for ProtocolProxy {
123    type Protocol = ProtocolMarker;
124
125    fn from_channel(inner: ::fidl::AsyncChannel) -> Self {
126        Self::new(inner)
127    }
128
129    fn into_channel(self) -> Result<::fidl::AsyncChannel, Self> {
130        self.client.into_channel().map_err(|client| Self { client })
131    }
132
133    fn as_channel(&self) -> &::fidl::AsyncChannel {
134        self.client.as_channel()
135    }
136}
137
138impl ProtocolProxy {
139    /// Create a new Proxy for test.protocol.connector/Protocol.
140    pub fn new(channel: ::fidl::AsyncChannel) -> Self {
141        let protocol_name = <ProtocolMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME;
142        Self { client: fidl::client::Client::new(channel, protocol_name) }
143    }
144
145    /// Get a Stream of events from the remote end of the protocol.
146    ///
147    /// # Panics
148    ///
149    /// Panics if the event stream was already taken.
150    pub fn take_event_stream(&self) -> ProtocolEventStream {
151        ProtocolEventStream { event_receiver: self.client.take_event_receiver() }
152    }
153
154    pub fn r#do_action(
155        &self,
156    ) -> fidl::client::QueryResponseFut<
157        ProtocolDoActionResult,
158        fidl::encoding::DefaultFuchsiaResourceDialect,
159    > {
160        ProtocolProxyInterface::r#do_action(self)
161    }
162}
163
164impl ProtocolProxyInterface for ProtocolProxy {
165    type DoActionResponseFut = fidl::client::QueryResponseFut<
166        ProtocolDoActionResult,
167        fidl::encoding::DefaultFuchsiaResourceDialect,
168    >;
169    fn r#do_action(&self) -> Self::DoActionResponseFut {
170        fn _decode(
171            mut _buf: Result<<fidl::encoding::DefaultFuchsiaResourceDialect as fidl::encoding::ResourceDialect>::MessageBufEtc, fidl::Error>,
172        ) -> Result<ProtocolDoActionResult, fidl::Error> {
173            let _response = fidl::client::decode_transaction_body::<
174                fidl::encoding::ResultType<fidl::encoding::EmptyStruct, Error>,
175                fidl::encoding::DefaultFuchsiaResourceDialect,
176                0x8831ffac41f0c9f,
177            >(_buf?)?;
178            Ok(_response.map(|x| x))
179        }
180        self.client.send_query_and_decode::<fidl::encoding::EmptyPayload, ProtocolDoActionResult>(
181            (),
182            0x8831ffac41f0c9f,
183            fidl::encoding::DynamicFlags::empty(),
184            _decode,
185        )
186    }
187}
188
189pub struct ProtocolEventStream {
190    event_receiver: fidl::client::EventReceiver<fidl::encoding::DefaultFuchsiaResourceDialect>,
191}
192
193impl std::marker::Unpin for ProtocolEventStream {}
194
195impl futures::stream::FusedStream for ProtocolEventStream {
196    fn is_terminated(&self) -> bool {
197        self.event_receiver.is_terminated()
198    }
199}
200
201impl futures::Stream for ProtocolEventStream {
202    type Item = Result<ProtocolEvent, fidl::Error>;
203
204    fn poll_next(
205        mut self: std::pin::Pin<&mut Self>,
206        cx: &mut std::task::Context<'_>,
207    ) -> std::task::Poll<Option<Self::Item>> {
208        match futures::ready!(futures::stream::StreamExt::poll_next_unpin(
209            &mut self.event_receiver,
210            cx
211        )?) {
212            Some(buf) => std::task::Poll::Ready(Some(ProtocolEvent::decode(buf))),
213            None => std::task::Poll::Ready(None),
214        }
215    }
216}
217
218#[derive(Debug)]
219pub enum ProtocolEvent {}
220
221impl ProtocolEvent {
222    /// Decodes a message buffer as a [`ProtocolEvent`].
223    fn decode(
224        mut buf: <fidl::encoding::DefaultFuchsiaResourceDialect as fidl::encoding::ResourceDialect>::MessageBufEtc,
225    ) -> Result<ProtocolEvent, fidl::Error> {
226        let (bytes, _handles) = buf.split_mut();
227        let (tx_header, _body_bytes) = fidl::encoding::decode_transaction_header(bytes)?;
228        debug_assert_eq!(tx_header.tx_id, 0);
229        match tx_header.ordinal {
230            _ => Err(fidl::Error::UnknownOrdinal {
231                ordinal: tx_header.ordinal,
232                protocol_name: <ProtocolMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME,
233            }),
234        }
235    }
236}
237
238/// A Stream of incoming requests for test.protocol.connector/Protocol.
239pub struct ProtocolRequestStream {
240    inner: std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>,
241    is_terminated: bool,
242}
243
244impl std::marker::Unpin for ProtocolRequestStream {}
245
246impl futures::stream::FusedStream for ProtocolRequestStream {
247    fn is_terminated(&self) -> bool {
248        self.is_terminated
249    }
250}
251
252impl fidl::endpoints::RequestStream for ProtocolRequestStream {
253    type Protocol = ProtocolMarker;
254    type ControlHandle = ProtocolControlHandle;
255
256    fn from_channel(channel: ::fidl::AsyncChannel) -> Self {
257        Self { inner: std::sync::Arc::new(fidl::ServeInner::new(channel)), is_terminated: false }
258    }
259
260    fn control_handle(&self) -> Self::ControlHandle {
261        ProtocolControlHandle { inner: self.inner.clone() }
262    }
263
264    fn into_inner(
265        self,
266    ) -> (::std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>, bool)
267    {
268        (self.inner, self.is_terminated)
269    }
270
271    fn from_inner(
272        inner: std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>,
273        is_terminated: bool,
274    ) -> Self {
275        Self { inner, is_terminated }
276    }
277}
278
279impl futures::Stream for ProtocolRequestStream {
280    type Item = Result<ProtocolRequest, fidl::Error>;
281
282    fn poll_next(
283        mut self: std::pin::Pin<&mut Self>,
284        cx: &mut std::task::Context<'_>,
285    ) -> std::task::Poll<Option<Self::Item>> {
286        let this = &mut *self;
287        if this.inner.check_shutdown(cx) {
288            this.is_terminated = true;
289            return std::task::Poll::Ready(None);
290        }
291        if this.is_terminated {
292            panic!("polled ProtocolRequestStream after completion");
293        }
294        fidl::encoding::with_tls_decode_buf::<_, fidl::encoding::DefaultFuchsiaResourceDialect>(
295            |bytes, handles| {
296                match this.inner.channel().read_etc(cx, bytes, handles) {
297                    std::task::Poll::Ready(Ok(())) => {}
298                    std::task::Poll::Pending => return std::task::Poll::Pending,
299                    std::task::Poll::Ready(Err(zx_status::Status::PEER_CLOSED)) => {
300                        this.is_terminated = true;
301                        return std::task::Poll::Ready(None);
302                    }
303                    std::task::Poll::Ready(Err(e)) => {
304                        return std::task::Poll::Ready(Some(Err(fidl::Error::ServerRequestRead(
305                            e.into(),
306                        ))))
307                    }
308                }
309
310                // A message has been received from the channel
311                let (header, _body_bytes) = fidl::encoding::decode_transaction_header(bytes)?;
312
313                std::task::Poll::Ready(Some(match header.ordinal {
314                    0x8831ffac41f0c9f => {
315                        header.validate_request_tx_id(fidl::MethodType::TwoWay)?;
316                        let mut req = fidl::new_empty!(
317                            fidl::encoding::EmptyPayload,
318                            fidl::encoding::DefaultFuchsiaResourceDialect
319                        );
320                        fidl::encoding::Decoder::<fidl::encoding::DefaultFuchsiaResourceDialect>::decode_into::<fidl::encoding::EmptyPayload>(&header, _body_bytes, handles, &mut req)?;
321                        let control_handle = ProtocolControlHandle { inner: this.inner.clone() };
322                        Ok(ProtocolRequest::DoAction {
323                            responder: ProtocolDoActionResponder {
324                                control_handle: std::mem::ManuallyDrop::new(control_handle),
325                                tx_id: header.tx_id,
326                            },
327                        })
328                    }
329                    _ => Err(fidl::Error::UnknownOrdinal {
330                        ordinal: header.ordinal,
331                        protocol_name:
332                            <ProtocolMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME,
333                    }),
334                }))
335            },
336        )
337    }
338}
339
340#[derive(Debug)]
341pub enum ProtocolRequest {
342    DoAction { responder: ProtocolDoActionResponder },
343}
344
345impl ProtocolRequest {
346    #[allow(irrefutable_let_patterns)]
347    pub fn into_do_action(self) -> Option<(ProtocolDoActionResponder)> {
348        if let ProtocolRequest::DoAction { responder } = self {
349            Some((responder))
350        } else {
351            None
352        }
353    }
354
355    /// Name of the method defined in FIDL
356    pub fn method_name(&self) -> &'static str {
357        match *self {
358            ProtocolRequest::DoAction { .. } => "do_action",
359        }
360    }
361}
362
363#[derive(Debug, Clone)]
364pub struct ProtocolControlHandle {
365    inner: std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>,
366}
367
368impl fidl::endpoints::ControlHandle for ProtocolControlHandle {
369    fn shutdown(&self) {
370        self.inner.shutdown()
371    }
372    fn shutdown_with_epitaph(&self, status: zx_status::Status) {
373        self.inner.shutdown_with_epitaph(status)
374    }
375
376    fn is_closed(&self) -> bool {
377        self.inner.channel().is_closed()
378    }
379    fn on_closed(&self) -> fidl::OnSignalsRef<'_> {
380        self.inner.channel().on_closed()
381    }
382
383    #[cfg(target_os = "fuchsia")]
384    fn signal_peer(
385        &self,
386        clear_mask: zx::Signals,
387        set_mask: zx::Signals,
388    ) -> Result<(), zx_status::Status> {
389        use fidl::Peered;
390        self.inner.channel().signal_peer(clear_mask, set_mask)
391    }
392}
393
394impl ProtocolControlHandle {}
395
396#[must_use = "FIDL methods require a response to be sent"]
397#[derive(Debug)]
398pub struct ProtocolDoActionResponder {
399    control_handle: std::mem::ManuallyDrop<ProtocolControlHandle>,
400    tx_id: u32,
401}
402
403/// Set the the channel to be shutdown (see [`ProtocolControlHandle::shutdown`])
404/// if the responder is dropped without sending a response, so that the client
405/// doesn't hang. To prevent this behavior, call `drop_without_shutdown`.
406impl std::ops::Drop for ProtocolDoActionResponder {
407    fn drop(&mut self) {
408        self.control_handle.shutdown();
409        // Safety: drops once, never accessed again
410        unsafe { std::mem::ManuallyDrop::drop(&mut self.control_handle) };
411    }
412}
413
414impl fidl::endpoints::Responder for ProtocolDoActionResponder {
415    type ControlHandle = ProtocolControlHandle;
416
417    fn control_handle(&self) -> &ProtocolControlHandle {
418        &self.control_handle
419    }
420
421    fn drop_without_shutdown(mut self) {
422        // Safety: drops once, never accessed again due to mem::forget
423        unsafe { std::mem::ManuallyDrop::drop(&mut self.control_handle) };
424        // Prevent Drop from running (which would shut down the channel)
425        std::mem::forget(self);
426    }
427}
428
429impl ProtocolDoActionResponder {
430    /// Sends a response to the FIDL transaction.
431    ///
432    /// Sets the channel to shutdown if an error occurs.
433    pub fn send(self, mut result: Result<(), Error>) -> Result<(), fidl::Error> {
434        let _result = self.send_raw(result);
435        if _result.is_err() {
436            self.control_handle.shutdown();
437        }
438        self.drop_without_shutdown();
439        _result
440    }
441
442    /// Similar to "send" but does not shutdown the channel if an error occurs.
443    pub fn send_no_shutdown_on_err(self, mut result: Result<(), Error>) -> Result<(), fidl::Error> {
444        let _result = self.send_raw(result);
445        self.drop_without_shutdown();
446        _result
447    }
448
449    fn send_raw(&self, mut result: Result<(), Error>) -> Result<(), fidl::Error> {
450        self.control_handle
451            .inner
452            .send::<fidl::encoding::ResultType<fidl::encoding::EmptyStruct, Error>>(
453                result,
454                self.tx_id,
455                0x8831ffac41f0c9f,
456                fidl::encoding::DynamicFlags::empty(),
457            )
458    }
459}
460
461#[derive(Debug, Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Hash)]
462pub struct ProtocolFactoryMarker;
463
464impl fidl::endpoints::ProtocolMarker for ProtocolFactoryMarker {
465    type Proxy = ProtocolFactoryProxy;
466    type RequestStream = ProtocolFactoryRequestStream;
467    #[cfg(target_os = "fuchsia")]
468    type SynchronousProxy = ProtocolFactorySynchronousProxy;
469
470    const DEBUG_NAME: &'static str = "test.protocol.connector.ProtocolFactory";
471}
472impl fidl::endpoints::DiscoverableProtocolMarker for ProtocolFactoryMarker {}
473pub type ProtocolFactoryCreateProtocolResult = Result<(), Error>;
474
475pub trait ProtocolFactoryProxyInterface: Send + Sync {
476    type CreateProtocolResponseFut: std::future::Future<Output = Result<ProtocolFactoryCreateProtocolResult, fidl::Error>>
477        + Send;
478    fn r#create_protocol(
479        &self,
480        protocol: fidl::endpoints::ServerEnd<ProtocolMarker>,
481    ) -> Self::CreateProtocolResponseFut;
482}
483#[derive(Debug)]
484#[cfg(target_os = "fuchsia")]
485pub struct ProtocolFactorySynchronousProxy {
486    client: fidl::client::sync::Client,
487}
488
489#[cfg(target_os = "fuchsia")]
490impl fidl::endpoints::SynchronousProxy for ProtocolFactorySynchronousProxy {
491    type Proxy = ProtocolFactoryProxy;
492    type Protocol = ProtocolFactoryMarker;
493
494    fn from_channel(inner: fidl::Channel) -> Self {
495        Self::new(inner)
496    }
497
498    fn into_channel(self) -> fidl::Channel {
499        self.client.into_channel()
500    }
501
502    fn as_channel(&self) -> &fidl::Channel {
503        self.client.as_channel()
504    }
505}
506
507#[cfg(target_os = "fuchsia")]
508impl ProtocolFactorySynchronousProxy {
509    pub fn new(channel: fidl::Channel) -> Self {
510        let protocol_name = <ProtocolFactoryMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME;
511        Self { client: fidl::client::sync::Client::new(channel, protocol_name) }
512    }
513
514    pub fn into_channel(self) -> fidl::Channel {
515        self.client.into_channel()
516    }
517
518    /// Waits until an event arrives and returns it. It is safe for other
519    /// threads to make concurrent requests while waiting for an event.
520    pub fn wait_for_event(
521        &self,
522        deadline: zx::MonotonicInstant,
523    ) -> Result<ProtocolFactoryEvent, fidl::Error> {
524        ProtocolFactoryEvent::decode(self.client.wait_for_event(deadline)?)
525    }
526
527    pub fn r#create_protocol(
528        &self,
529        mut protocol: fidl::endpoints::ServerEnd<ProtocolMarker>,
530        ___deadline: zx::MonotonicInstant,
531    ) -> Result<ProtocolFactoryCreateProtocolResult, fidl::Error> {
532        let _response = self.client.send_query::<
533            ProtocolFactoryCreateProtocolRequest,
534            fidl::encoding::ResultType<fidl::encoding::EmptyStruct, Error>,
535        >(
536            (protocol,),
537            0x57fac7669eddfb24,
538            fidl::encoding::DynamicFlags::empty(),
539            ___deadline,
540        )?;
541        Ok(_response.map(|x| x))
542    }
543}
544
545#[cfg(target_os = "fuchsia")]
546impl From<ProtocolFactorySynchronousProxy> for zx::Handle {
547    fn from(value: ProtocolFactorySynchronousProxy) -> Self {
548        value.into_channel().into()
549    }
550}
551
552#[cfg(target_os = "fuchsia")]
553impl From<fidl::Channel> for ProtocolFactorySynchronousProxy {
554    fn from(value: fidl::Channel) -> Self {
555        Self::new(value)
556    }
557}
558
559#[derive(Debug, Clone)]
560pub struct ProtocolFactoryProxy {
561    client: fidl::client::Client<fidl::encoding::DefaultFuchsiaResourceDialect>,
562}
563
564impl fidl::endpoints::Proxy for ProtocolFactoryProxy {
565    type Protocol = ProtocolFactoryMarker;
566
567    fn from_channel(inner: ::fidl::AsyncChannel) -> Self {
568        Self::new(inner)
569    }
570
571    fn into_channel(self) -> Result<::fidl::AsyncChannel, Self> {
572        self.client.into_channel().map_err(|client| Self { client })
573    }
574
575    fn as_channel(&self) -> &::fidl::AsyncChannel {
576        self.client.as_channel()
577    }
578}
579
580impl ProtocolFactoryProxy {
581    /// Create a new Proxy for test.protocol.connector/ProtocolFactory.
582    pub fn new(channel: ::fidl::AsyncChannel) -> Self {
583        let protocol_name = <ProtocolFactoryMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME;
584        Self { client: fidl::client::Client::new(channel, protocol_name) }
585    }
586
587    /// Get a Stream of events from the remote end of the protocol.
588    ///
589    /// # Panics
590    ///
591    /// Panics if the event stream was already taken.
592    pub fn take_event_stream(&self) -> ProtocolFactoryEventStream {
593        ProtocolFactoryEventStream { event_receiver: self.client.take_event_receiver() }
594    }
595
596    pub fn r#create_protocol(
597        &self,
598        mut protocol: fidl::endpoints::ServerEnd<ProtocolMarker>,
599    ) -> fidl::client::QueryResponseFut<
600        ProtocolFactoryCreateProtocolResult,
601        fidl::encoding::DefaultFuchsiaResourceDialect,
602    > {
603        ProtocolFactoryProxyInterface::r#create_protocol(self, protocol)
604    }
605}
606
607impl ProtocolFactoryProxyInterface for ProtocolFactoryProxy {
608    type CreateProtocolResponseFut = fidl::client::QueryResponseFut<
609        ProtocolFactoryCreateProtocolResult,
610        fidl::encoding::DefaultFuchsiaResourceDialect,
611    >;
612    fn r#create_protocol(
613        &self,
614        mut protocol: fidl::endpoints::ServerEnd<ProtocolMarker>,
615    ) -> Self::CreateProtocolResponseFut {
616        fn _decode(
617            mut _buf: Result<<fidl::encoding::DefaultFuchsiaResourceDialect as fidl::encoding::ResourceDialect>::MessageBufEtc, fidl::Error>,
618        ) -> Result<ProtocolFactoryCreateProtocolResult, fidl::Error> {
619            let _response = fidl::client::decode_transaction_body::<
620                fidl::encoding::ResultType<fidl::encoding::EmptyStruct, Error>,
621                fidl::encoding::DefaultFuchsiaResourceDialect,
622                0x57fac7669eddfb24,
623            >(_buf?)?;
624            Ok(_response.map(|x| x))
625        }
626        self.client.send_query_and_decode::<
627            ProtocolFactoryCreateProtocolRequest,
628            ProtocolFactoryCreateProtocolResult,
629        >(
630            (protocol,),
631            0x57fac7669eddfb24,
632            fidl::encoding::DynamicFlags::empty(),
633            _decode,
634        )
635    }
636}
637
638pub struct ProtocolFactoryEventStream {
639    event_receiver: fidl::client::EventReceiver<fidl::encoding::DefaultFuchsiaResourceDialect>,
640}
641
642impl std::marker::Unpin for ProtocolFactoryEventStream {}
643
644impl futures::stream::FusedStream for ProtocolFactoryEventStream {
645    fn is_terminated(&self) -> bool {
646        self.event_receiver.is_terminated()
647    }
648}
649
650impl futures::Stream for ProtocolFactoryEventStream {
651    type Item = Result<ProtocolFactoryEvent, fidl::Error>;
652
653    fn poll_next(
654        mut self: std::pin::Pin<&mut Self>,
655        cx: &mut std::task::Context<'_>,
656    ) -> std::task::Poll<Option<Self::Item>> {
657        match futures::ready!(futures::stream::StreamExt::poll_next_unpin(
658            &mut self.event_receiver,
659            cx
660        )?) {
661            Some(buf) => std::task::Poll::Ready(Some(ProtocolFactoryEvent::decode(buf))),
662            None => std::task::Poll::Ready(None),
663        }
664    }
665}
666
667#[derive(Debug)]
668pub enum ProtocolFactoryEvent {}
669
670impl ProtocolFactoryEvent {
671    /// Decodes a message buffer as a [`ProtocolFactoryEvent`].
672    fn decode(
673        mut buf: <fidl::encoding::DefaultFuchsiaResourceDialect as fidl::encoding::ResourceDialect>::MessageBufEtc,
674    ) -> Result<ProtocolFactoryEvent, fidl::Error> {
675        let (bytes, _handles) = buf.split_mut();
676        let (tx_header, _body_bytes) = fidl::encoding::decode_transaction_header(bytes)?;
677        debug_assert_eq!(tx_header.tx_id, 0);
678        match tx_header.ordinal {
679            _ => Err(fidl::Error::UnknownOrdinal {
680                ordinal: tx_header.ordinal,
681                protocol_name:
682                    <ProtocolFactoryMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME,
683            }),
684        }
685    }
686}
687
688/// A Stream of incoming requests for test.protocol.connector/ProtocolFactory.
689pub struct ProtocolFactoryRequestStream {
690    inner: std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>,
691    is_terminated: bool,
692}
693
694impl std::marker::Unpin for ProtocolFactoryRequestStream {}
695
696impl futures::stream::FusedStream for ProtocolFactoryRequestStream {
697    fn is_terminated(&self) -> bool {
698        self.is_terminated
699    }
700}
701
702impl fidl::endpoints::RequestStream for ProtocolFactoryRequestStream {
703    type Protocol = ProtocolFactoryMarker;
704    type ControlHandle = ProtocolFactoryControlHandle;
705
706    fn from_channel(channel: ::fidl::AsyncChannel) -> Self {
707        Self { inner: std::sync::Arc::new(fidl::ServeInner::new(channel)), is_terminated: false }
708    }
709
710    fn control_handle(&self) -> Self::ControlHandle {
711        ProtocolFactoryControlHandle { inner: self.inner.clone() }
712    }
713
714    fn into_inner(
715        self,
716    ) -> (::std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>, bool)
717    {
718        (self.inner, self.is_terminated)
719    }
720
721    fn from_inner(
722        inner: std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>,
723        is_terminated: bool,
724    ) -> Self {
725        Self { inner, is_terminated }
726    }
727}
728
729impl futures::Stream for ProtocolFactoryRequestStream {
730    type Item = Result<ProtocolFactoryRequest, fidl::Error>;
731
732    fn poll_next(
733        mut self: std::pin::Pin<&mut Self>,
734        cx: &mut std::task::Context<'_>,
735    ) -> std::task::Poll<Option<Self::Item>> {
736        let this = &mut *self;
737        if this.inner.check_shutdown(cx) {
738            this.is_terminated = true;
739            return std::task::Poll::Ready(None);
740        }
741        if this.is_terminated {
742            panic!("polled ProtocolFactoryRequestStream after completion");
743        }
744        fidl::encoding::with_tls_decode_buf::<_, fidl::encoding::DefaultFuchsiaResourceDialect>(
745            |bytes, handles| {
746                match this.inner.channel().read_etc(cx, bytes, handles) {
747                    std::task::Poll::Ready(Ok(())) => {}
748                    std::task::Poll::Pending => return std::task::Poll::Pending,
749                    std::task::Poll::Ready(Err(zx_status::Status::PEER_CLOSED)) => {
750                        this.is_terminated = true;
751                        return std::task::Poll::Ready(None);
752                    }
753                    std::task::Poll::Ready(Err(e)) => {
754                        return std::task::Poll::Ready(Some(Err(fidl::Error::ServerRequestRead(
755                            e.into(),
756                        ))))
757                    }
758                }
759
760                // A message has been received from the channel
761                let (header, _body_bytes) = fidl::encoding::decode_transaction_header(bytes)?;
762
763                std::task::Poll::Ready(Some(match header.ordinal {
764                    0x57fac7669eddfb24 => {
765                        header.validate_request_tx_id(fidl::MethodType::TwoWay)?;
766                        let mut req = fidl::new_empty!(
767                            ProtocolFactoryCreateProtocolRequest,
768                            fidl::encoding::DefaultFuchsiaResourceDialect
769                        );
770                        fidl::encoding::Decoder::<fidl::encoding::DefaultFuchsiaResourceDialect>::decode_into::<ProtocolFactoryCreateProtocolRequest>(&header, _body_bytes, handles, &mut req)?;
771                        let control_handle =
772                            ProtocolFactoryControlHandle { inner: this.inner.clone() };
773                        Ok(ProtocolFactoryRequest::CreateProtocol {
774                            protocol: req.protocol,
775
776                            responder: ProtocolFactoryCreateProtocolResponder {
777                                control_handle: std::mem::ManuallyDrop::new(control_handle),
778                                tx_id: header.tx_id,
779                            },
780                        })
781                    }
782                    _ => Err(fidl::Error::UnknownOrdinal {
783                        ordinal: header.ordinal,
784                        protocol_name:
785                            <ProtocolFactoryMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME,
786                    }),
787                }))
788            },
789        )
790    }
791}
792
793#[derive(Debug)]
794pub enum ProtocolFactoryRequest {
795    CreateProtocol {
796        protocol: fidl::endpoints::ServerEnd<ProtocolMarker>,
797        responder: ProtocolFactoryCreateProtocolResponder,
798    },
799}
800
801impl ProtocolFactoryRequest {
802    #[allow(irrefutable_let_patterns)]
803    pub fn into_create_protocol(
804        self,
805    ) -> Option<(fidl::endpoints::ServerEnd<ProtocolMarker>, ProtocolFactoryCreateProtocolResponder)>
806    {
807        if let ProtocolFactoryRequest::CreateProtocol { protocol, responder } = self {
808            Some((protocol, responder))
809        } else {
810            None
811        }
812    }
813
814    /// Name of the method defined in FIDL
815    pub fn method_name(&self) -> &'static str {
816        match *self {
817            ProtocolFactoryRequest::CreateProtocol { .. } => "create_protocol",
818        }
819    }
820}
821
822#[derive(Debug, Clone)]
823pub struct ProtocolFactoryControlHandle {
824    inner: std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>,
825}
826
827impl fidl::endpoints::ControlHandle for ProtocolFactoryControlHandle {
828    fn shutdown(&self) {
829        self.inner.shutdown()
830    }
831    fn shutdown_with_epitaph(&self, status: zx_status::Status) {
832        self.inner.shutdown_with_epitaph(status)
833    }
834
835    fn is_closed(&self) -> bool {
836        self.inner.channel().is_closed()
837    }
838    fn on_closed(&self) -> fidl::OnSignalsRef<'_> {
839        self.inner.channel().on_closed()
840    }
841
842    #[cfg(target_os = "fuchsia")]
843    fn signal_peer(
844        &self,
845        clear_mask: zx::Signals,
846        set_mask: zx::Signals,
847    ) -> Result<(), zx_status::Status> {
848        use fidl::Peered;
849        self.inner.channel().signal_peer(clear_mask, set_mask)
850    }
851}
852
853impl ProtocolFactoryControlHandle {}
854
855#[must_use = "FIDL methods require a response to be sent"]
856#[derive(Debug)]
857pub struct ProtocolFactoryCreateProtocolResponder {
858    control_handle: std::mem::ManuallyDrop<ProtocolFactoryControlHandle>,
859    tx_id: u32,
860}
861
862/// Set the the channel to be shutdown (see [`ProtocolFactoryControlHandle::shutdown`])
863/// if the responder is dropped without sending a response, so that the client
864/// doesn't hang. To prevent this behavior, call `drop_without_shutdown`.
865impl std::ops::Drop for ProtocolFactoryCreateProtocolResponder {
866    fn drop(&mut self) {
867        self.control_handle.shutdown();
868        // Safety: drops once, never accessed again
869        unsafe { std::mem::ManuallyDrop::drop(&mut self.control_handle) };
870    }
871}
872
873impl fidl::endpoints::Responder for ProtocolFactoryCreateProtocolResponder {
874    type ControlHandle = ProtocolFactoryControlHandle;
875
876    fn control_handle(&self) -> &ProtocolFactoryControlHandle {
877        &self.control_handle
878    }
879
880    fn drop_without_shutdown(mut self) {
881        // Safety: drops once, never accessed again due to mem::forget
882        unsafe { std::mem::ManuallyDrop::drop(&mut self.control_handle) };
883        // Prevent Drop from running (which would shut down the channel)
884        std::mem::forget(self);
885    }
886}
887
888impl ProtocolFactoryCreateProtocolResponder {
889    /// Sends a response to the FIDL transaction.
890    ///
891    /// Sets the channel to shutdown if an error occurs.
892    pub fn send(self, mut result: Result<(), Error>) -> Result<(), fidl::Error> {
893        let _result = self.send_raw(result);
894        if _result.is_err() {
895            self.control_handle.shutdown();
896        }
897        self.drop_without_shutdown();
898        _result
899    }
900
901    /// Similar to "send" but does not shutdown the channel if an error occurs.
902    pub fn send_no_shutdown_on_err(self, mut result: Result<(), Error>) -> Result<(), fidl::Error> {
903        let _result = self.send_raw(result);
904        self.drop_without_shutdown();
905        _result
906    }
907
908    fn send_raw(&self, mut result: Result<(), Error>) -> Result<(), fidl::Error> {
909        self.control_handle
910            .inner
911            .send::<fidl::encoding::ResultType<fidl::encoding::EmptyStruct, Error>>(
912                result,
913                self.tx_id,
914                0x57fac7669eddfb24,
915                fidl::encoding::DynamicFlags::empty(),
916            )
917    }
918}
919
920#[derive(Debug, Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Hash)]
921pub struct SimpleProtocolMarker;
922
923impl fidl::endpoints::ProtocolMarker for SimpleProtocolMarker {
924    type Proxy = SimpleProtocolProxy;
925    type RequestStream = SimpleProtocolRequestStream;
926    #[cfg(target_os = "fuchsia")]
927    type SynchronousProxy = SimpleProtocolSynchronousProxy;
928
929    const DEBUG_NAME: &'static str = "test.protocol.connector.SimpleProtocol";
930}
931impl fidl::endpoints::DiscoverableProtocolMarker for SimpleProtocolMarker {}
932pub type SimpleProtocolDoActionResult = Result<(), Error>;
933
934pub trait SimpleProtocolProxyInterface: Send + Sync {
935    type DoActionResponseFut: std::future::Future<Output = Result<SimpleProtocolDoActionResult, fidl::Error>>
936        + Send;
937    fn r#do_action(&self) -> Self::DoActionResponseFut;
938}
939#[derive(Debug)]
940#[cfg(target_os = "fuchsia")]
941pub struct SimpleProtocolSynchronousProxy {
942    client: fidl::client::sync::Client,
943}
944
945#[cfg(target_os = "fuchsia")]
946impl fidl::endpoints::SynchronousProxy for SimpleProtocolSynchronousProxy {
947    type Proxy = SimpleProtocolProxy;
948    type Protocol = SimpleProtocolMarker;
949
950    fn from_channel(inner: fidl::Channel) -> Self {
951        Self::new(inner)
952    }
953
954    fn into_channel(self) -> fidl::Channel {
955        self.client.into_channel()
956    }
957
958    fn as_channel(&self) -> &fidl::Channel {
959        self.client.as_channel()
960    }
961}
962
963#[cfg(target_os = "fuchsia")]
964impl SimpleProtocolSynchronousProxy {
965    pub fn new(channel: fidl::Channel) -> Self {
966        let protocol_name = <SimpleProtocolMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME;
967        Self { client: fidl::client::sync::Client::new(channel, protocol_name) }
968    }
969
970    pub fn into_channel(self) -> fidl::Channel {
971        self.client.into_channel()
972    }
973
974    /// Waits until an event arrives and returns it. It is safe for other
975    /// threads to make concurrent requests while waiting for an event.
976    pub fn wait_for_event(
977        &self,
978        deadline: zx::MonotonicInstant,
979    ) -> Result<SimpleProtocolEvent, fidl::Error> {
980        SimpleProtocolEvent::decode(self.client.wait_for_event(deadline)?)
981    }
982
983    pub fn r#do_action(
984        &self,
985        ___deadline: zx::MonotonicInstant,
986    ) -> Result<SimpleProtocolDoActionResult, fidl::Error> {
987        let _response = self.client.send_query::<
988            fidl::encoding::EmptyPayload,
989            fidl::encoding::ResultType<fidl::encoding::EmptyStruct, Error>,
990        >(
991            (),
992            0x482e3c82af55ef30,
993            fidl::encoding::DynamicFlags::empty(),
994            ___deadline,
995        )?;
996        Ok(_response.map(|x| x))
997    }
998}
999
1000#[cfg(target_os = "fuchsia")]
1001impl From<SimpleProtocolSynchronousProxy> for zx::Handle {
1002    fn from(value: SimpleProtocolSynchronousProxy) -> Self {
1003        value.into_channel().into()
1004    }
1005}
1006
1007#[cfg(target_os = "fuchsia")]
1008impl From<fidl::Channel> for SimpleProtocolSynchronousProxy {
1009    fn from(value: fidl::Channel) -> Self {
1010        Self::new(value)
1011    }
1012}
1013
1014#[derive(Debug, Clone)]
1015pub struct SimpleProtocolProxy {
1016    client: fidl::client::Client<fidl::encoding::DefaultFuchsiaResourceDialect>,
1017}
1018
1019impl fidl::endpoints::Proxy for SimpleProtocolProxy {
1020    type Protocol = SimpleProtocolMarker;
1021
1022    fn from_channel(inner: ::fidl::AsyncChannel) -> Self {
1023        Self::new(inner)
1024    }
1025
1026    fn into_channel(self) -> Result<::fidl::AsyncChannel, Self> {
1027        self.client.into_channel().map_err(|client| Self { client })
1028    }
1029
1030    fn as_channel(&self) -> &::fidl::AsyncChannel {
1031        self.client.as_channel()
1032    }
1033}
1034
1035impl SimpleProtocolProxy {
1036    /// Create a new Proxy for test.protocol.connector/SimpleProtocol.
1037    pub fn new(channel: ::fidl::AsyncChannel) -> Self {
1038        let protocol_name = <SimpleProtocolMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME;
1039        Self { client: fidl::client::Client::new(channel, protocol_name) }
1040    }
1041
1042    /// Get a Stream of events from the remote end of the protocol.
1043    ///
1044    /// # Panics
1045    ///
1046    /// Panics if the event stream was already taken.
1047    pub fn take_event_stream(&self) -> SimpleProtocolEventStream {
1048        SimpleProtocolEventStream { event_receiver: self.client.take_event_receiver() }
1049    }
1050
1051    pub fn r#do_action(
1052        &self,
1053    ) -> fidl::client::QueryResponseFut<
1054        SimpleProtocolDoActionResult,
1055        fidl::encoding::DefaultFuchsiaResourceDialect,
1056    > {
1057        SimpleProtocolProxyInterface::r#do_action(self)
1058    }
1059}
1060
1061impl SimpleProtocolProxyInterface for SimpleProtocolProxy {
1062    type DoActionResponseFut = fidl::client::QueryResponseFut<
1063        SimpleProtocolDoActionResult,
1064        fidl::encoding::DefaultFuchsiaResourceDialect,
1065    >;
1066    fn r#do_action(&self) -> Self::DoActionResponseFut {
1067        fn _decode(
1068            mut _buf: Result<<fidl::encoding::DefaultFuchsiaResourceDialect as fidl::encoding::ResourceDialect>::MessageBufEtc, fidl::Error>,
1069        ) -> Result<SimpleProtocolDoActionResult, fidl::Error> {
1070            let _response = fidl::client::decode_transaction_body::<
1071                fidl::encoding::ResultType<fidl::encoding::EmptyStruct, Error>,
1072                fidl::encoding::DefaultFuchsiaResourceDialect,
1073                0x482e3c82af55ef30,
1074            >(_buf?)?;
1075            Ok(_response.map(|x| x))
1076        }
1077        self.client
1078            .send_query_and_decode::<fidl::encoding::EmptyPayload, SimpleProtocolDoActionResult>(
1079                (),
1080                0x482e3c82af55ef30,
1081                fidl::encoding::DynamicFlags::empty(),
1082                _decode,
1083            )
1084    }
1085}
1086
1087pub struct SimpleProtocolEventStream {
1088    event_receiver: fidl::client::EventReceiver<fidl::encoding::DefaultFuchsiaResourceDialect>,
1089}
1090
1091impl std::marker::Unpin for SimpleProtocolEventStream {}
1092
1093impl futures::stream::FusedStream for SimpleProtocolEventStream {
1094    fn is_terminated(&self) -> bool {
1095        self.event_receiver.is_terminated()
1096    }
1097}
1098
1099impl futures::Stream for SimpleProtocolEventStream {
1100    type Item = Result<SimpleProtocolEvent, fidl::Error>;
1101
1102    fn poll_next(
1103        mut self: std::pin::Pin<&mut Self>,
1104        cx: &mut std::task::Context<'_>,
1105    ) -> std::task::Poll<Option<Self::Item>> {
1106        match futures::ready!(futures::stream::StreamExt::poll_next_unpin(
1107            &mut self.event_receiver,
1108            cx
1109        )?) {
1110            Some(buf) => std::task::Poll::Ready(Some(SimpleProtocolEvent::decode(buf))),
1111            None => std::task::Poll::Ready(None),
1112        }
1113    }
1114}
1115
1116#[derive(Debug)]
1117pub enum SimpleProtocolEvent {}
1118
1119impl SimpleProtocolEvent {
1120    /// Decodes a message buffer as a [`SimpleProtocolEvent`].
1121    fn decode(
1122        mut buf: <fidl::encoding::DefaultFuchsiaResourceDialect as fidl::encoding::ResourceDialect>::MessageBufEtc,
1123    ) -> Result<SimpleProtocolEvent, fidl::Error> {
1124        let (bytes, _handles) = buf.split_mut();
1125        let (tx_header, _body_bytes) = fidl::encoding::decode_transaction_header(bytes)?;
1126        debug_assert_eq!(tx_header.tx_id, 0);
1127        match tx_header.ordinal {
1128            _ => Err(fidl::Error::UnknownOrdinal {
1129                ordinal: tx_header.ordinal,
1130                protocol_name:
1131                    <SimpleProtocolMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME,
1132            }),
1133        }
1134    }
1135}
1136
1137/// A Stream of incoming requests for test.protocol.connector/SimpleProtocol.
1138pub struct SimpleProtocolRequestStream {
1139    inner: std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>,
1140    is_terminated: bool,
1141}
1142
1143impl std::marker::Unpin for SimpleProtocolRequestStream {}
1144
1145impl futures::stream::FusedStream for SimpleProtocolRequestStream {
1146    fn is_terminated(&self) -> bool {
1147        self.is_terminated
1148    }
1149}
1150
1151impl fidl::endpoints::RequestStream for SimpleProtocolRequestStream {
1152    type Protocol = SimpleProtocolMarker;
1153    type ControlHandle = SimpleProtocolControlHandle;
1154
1155    fn from_channel(channel: ::fidl::AsyncChannel) -> Self {
1156        Self { inner: std::sync::Arc::new(fidl::ServeInner::new(channel)), is_terminated: false }
1157    }
1158
1159    fn control_handle(&self) -> Self::ControlHandle {
1160        SimpleProtocolControlHandle { inner: self.inner.clone() }
1161    }
1162
1163    fn into_inner(
1164        self,
1165    ) -> (::std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>, bool)
1166    {
1167        (self.inner, self.is_terminated)
1168    }
1169
1170    fn from_inner(
1171        inner: std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>,
1172        is_terminated: bool,
1173    ) -> Self {
1174        Self { inner, is_terminated }
1175    }
1176}
1177
1178impl futures::Stream for SimpleProtocolRequestStream {
1179    type Item = Result<SimpleProtocolRequest, fidl::Error>;
1180
1181    fn poll_next(
1182        mut self: std::pin::Pin<&mut Self>,
1183        cx: &mut std::task::Context<'_>,
1184    ) -> std::task::Poll<Option<Self::Item>> {
1185        let this = &mut *self;
1186        if this.inner.check_shutdown(cx) {
1187            this.is_terminated = true;
1188            return std::task::Poll::Ready(None);
1189        }
1190        if this.is_terminated {
1191            panic!("polled SimpleProtocolRequestStream after completion");
1192        }
1193        fidl::encoding::with_tls_decode_buf::<_, fidl::encoding::DefaultFuchsiaResourceDialect>(
1194            |bytes, handles| {
1195                match this.inner.channel().read_etc(cx, bytes, handles) {
1196                    std::task::Poll::Ready(Ok(())) => {}
1197                    std::task::Poll::Pending => return std::task::Poll::Pending,
1198                    std::task::Poll::Ready(Err(zx_status::Status::PEER_CLOSED)) => {
1199                        this.is_terminated = true;
1200                        return std::task::Poll::Ready(None);
1201                    }
1202                    std::task::Poll::Ready(Err(e)) => {
1203                        return std::task::Poll::Ready(Some(Err(fidl::Error::ServerRequestRead(
1204                            e.into(),
1205                        ))))
1206                    }
1207                }
1208
1209                // A message has been received from the channel
1210                let (header, _body_bytes) = fidl::encoding::decode_transaction_header(bytes)?;
1211
1212                std::task::Poll::Ready(Some(match header.ordinal {
1213                    0x482e3c82af55ef30 => {
1214                        header.validate_request_tx_id(fidl::MethodType::TwoWay)?;
1215                        let mut req = fidl::new_empty!(
1216                            fidl::encoding::EmptyPayload,
1217                            fidl::encoding::DefaultFuchsiaResourceDialect
1218                        );
1219                        fidl::encoding::Decoder::<fidl::encoding::DefaultFuchsiaResourceDialect>::decode_into::<fidl::encoding::EmptyPayload>(&header, _body_bytes, handles, &mut req)?;
1220                        let control_handle =
1221                            SimpleProtocolControlHandle { inner: this.inner.clone() };
1222                        Ok(SimpleProtocolRequest::DoAction {
1223                            responder: SimpleProtocolDoActionResponder {
1224                                control_handle: std::mem::ManuallyDrop::new(control_handle),
1225                                tx_id: header.tx_id,
1226                            },
1227                        })
1228                    }
1229                    _ => Err(fidl::Error::UnknownOrdinal {
1230                        ordinal: header.ordinal,
1231                        protocol_name:
1232                            <SimpleProtocolMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME,
1233                    }),
1234                }))
1235            },
1236        )
1237    }
1238}
1239
1240#[derive(Debug)]
1241pub enum SimpleProtocolRequest {
1242    DoAction { responder: SimpleProtocolDoActionResponder },
1243}
1244
1245impl SimpleProtocolRequest {
1246    #[allow(irrefutable_let_patterns)]
1247    pub fn into_do_action(self) -> Option<(SimpleProtocolDoActionResponder)> {
1248        if let SimpleProtocolRequest::DoAction { responder } = self {
1249            Some((responder))
1250        } else {
1251            None
1252        }
1253    }
1254
1255    /// Name of the method defined in FIDL
1256    pub fn method_name(&self) -> &'static str {
1257        match *self {
1258            SimpleProtocolRequest::DoAction { .. } => "do_action",
1259        }
1260    }
1261}
1262
1263#[derive(Debug, Clone)]
1264pub struct SimpleProtocolControlHandle {
1265    inner: std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>,
1266}
1267
1268impl fidl::endpoints::ControlHandle for SimpleProtocolControlHandle {
1269    fn shutdown(&self) {
1270        self.inner.shutdown()
1271    }
1272    fn shutdown_with_epitaph(&self, status: zx_status::Status) {
1273        self.inner.shutdown_with_epitaph(status)
1274    }
1275
1276    fn is_closed(&self) -> bool {
1277        self.inner.channel().is_closed()
1278    }
1279    fn on_closed(&self) -> fidl::OnSignalsRef<'_> {
1280        self.inner.channel().on_closed()
1281    }
1282
1283    #[cfg(target_os = "fuchsia")]
1284    fn signal_peer(
1285        &self,
1286        clear_mask: zx::Signals,
1287        set_mask: zx::Signals,
1288    ) -> Result<(), zx_status::Status> {
1289        use fidl::Peered;
1290        self.inner.channel().signal_peer(clear_mask, set_mask)
1291    }
1292}
1293
1294impl SimpleProtocolControlHandle {}
1295
1296#[must_use = "FIDL methods require a response to be sent"]
1297#[derive(Debug)]
1298pub struct SimpleProtocolDoActionResponder {
1299    control_handle: std::mem::ManuallyDrop<SimpleProtocolControlHandle>,
1300    tx_id: u32,
1301}
1302
1303/// Set the the channel to be shutdown (see [`SimpleProtocolControlHandle::shutdown`])
1304/// if the responder is dropped without sending a response, so that the client
1305/// doesn't hang. To prevent this behavior, call `drop_without_shutdown`.
1306impl std::ops::Drop for SimpleProtocolDoActionResponder {
1307    fn drop(&mut self) {
1308        self.control_handle.shutdown();
1309        // Safety: drops once, never accessed again
1310        unsafe { std::mem::ManuallyDrop::drop(&mut self.control_handle) };
1311    }
1312}
1313
1314impl fidl::endpoints::Responder for SimpleProtocolDoActionResponder {
1315    type ControlHandle = SimpleProtocolControlHandle;
1316
1317    fn control_handle(&self) -> &SimpleProtocolControlHandle {
1318        &self.control_handle
1319    }
1320
1321    fn drop_without_shutdown(mut self) {
1322        // Safety: drops once, never accessed again due to mem::forget
1323        unsafe { std::mem::ManuallyDrop::drop(&mut self.control_handle) };
1324        // Prevent Drop from running (which would shut down the channel)
1325        std::mem::forget(self);
1326    }
1327}
1328
1329impl SimpleProtocolDoActionResponder {
1330    /// Sends a response to the FIDL transaction.
1331    ///
1332    /// Sets the channel to shutdown if an error occurs.
1333    pub fn send(self, mut result: Result<(), Error>) -> Result<(), fidl::Error> {
1334        let _result = self.send_raw(result);
1335        if _result.is_err() {
1336            self.control_handle.shutdown();
1337        }
1338        self.drop_without_shutdown();
1339        _result
1340    }
1341
1342    /// Similar to "send" but does not shutdown the channel if an error occurs.
1343    pub fn send_no_shutdown_on_err(self, mut result: Result<(), Error>) -> Result<(), fidl::Error> {
1344        let _result = self.send_raw(result);
1345        self.drop_without_shutdown();
1346        _result
1347    }
1348
1349    fn send_raw(&self, mut result: Result<(), Error>) -> Result<(), fidl::Error> {
1350        self.control_handle
1351            .inner
1352            .send::<fidl::encoding::ResultType<fidl::encoding::EmptyStruct, Error>>(
1353                result,
1354                self.tx_id,
1355                0x482e3c82af55ef30,
1356                fidl::encoding::DynamicFlags::empty(),
1357            )
1358    }
1359}
1360
1361mod internal {
1362    use super::*;
1363
1364    impl fidl::encoding::ResourceTypeMarker for ProtocolFactoryCreateProtocolRequest {
1365        type Borrowed<'a> = &'a mut Self;
1366        fn take_or_borrow<'a>(
1367            value: &'a mut <Self as fidl::encoding::TypeMarker>::Owned,
1368        ) -> Self::Borrowed<'a> {
1369            value
1370        }
1371    }
1372
1373    unsafe impl fidl::encoding::TypeMarker for ProtocolFactoryCreateProtocolRequest {
1374        type Owned = Self;
1375
1376        #[inline(always)]
1377        fn inline_align(_context: fidl::encoding::Context) -> usize {
1378            4
1379        }
1380
1381        #[inline(always)]
1382        fn inline_size(_context: fidl::encoding::Context) -> usize {
1383            4
1384        }
1385    }
1386
1387    unsafe impl
1388        fidl::encoding::Encode<
1389            ProtocolFactoryCreateProtocolRequest,
1390            fidl::encoding::DefaultFuchsiaResourceDialect,
1391        > for &mut ProtocolFactoryCreateProtocolRequest
1392    {
1393        #[inline]
1394        unsafe fn encode(
1395            self,
1396            encoder: &mut fidl::encoding::Encoder<
1397                '_,
1398                fidl::encoding::DefaultFuchsiaResourceDialect,
1399            >,
1400            offset: usize,
1401            _depth: fidl::encoding::Depth,
1402        ) -> fidl::Result<()> {
1403            encoder.debug_check_bounds::<ProtocolFactoryCreateProtocolRequest>(offset);
1404            // Delegate to tuple encoding.
1405            fidl::encoding::Encode::<ProtocolFactoryCreateProtocolRequest, fidl::encoding::DefaultFuchsiaResourceDialect>::encode(
1406                (
1407                    <fidl::encoding::Endpoint<fidl::endpoints::ServerEnd<ProtocolMarker>> as fidl::encoding::ResourceTypeMarker>::take_or_borrow(&mut self.protocol),
1408                ),
1409                encoder, offset, _depth
1410            )
1411        }
1412    }
1413    unsafe impl<
1414            T0: fidl::encoding::Encode<
1415                fidl::encoding::Endpoint<fidl::endpoints::ServerEnd<ProtocolMarker>>,
1416                fidl::encoding::DefaultFuchsiaResourceDialect,
1417            >,
1418        >
1419        fidl::encoding::Encode<
1420            ProtocolFactoryCreateProtocolRequest,
1421            fidl::encoding::DefaultFuchsiaResourceDialect,
1422        > for (T0,)
1423    {
1424        #[inline]
1425        unsafe fn encode(
1426            self,
1427            encoder: &mut fidl::encoding::Encoder<
1428                '_,
1429                fidl::encoding::DefaultFuchsiaResourceDialect,
1430            >,
1431            offset: usize,
1432            depth: fidl::encoding::Depth,
1433        ) -> fidl::Result<()> {
1434            encoder.debug_check_bounds::<ProtocolFactoryCreateProtocolRequest>(offset);
1435            // Zero out padding regions. There's no need to apply masks
1436            // because the unmasked parts will be overwritten by fields.
1437            // Write the fields.
1438            self.0.encode(encoder, offset + 0, depth)?;
1439            Ok(())
1440        }
1441    }
1442
1443    impl fidl::encoding::Decode<Self, fidl::encoding::DefaultFuchsiaResourceDialect>
1444        for ProtocolFactoryCreateProtocolRequest
1445    {
1446        #[inline(always)]
1447        fn new_empty() -> Self {
1448            Self {
1449                protocol: fidl::new_empty!(
1450                    fidl::encoding::Endpoint<fidl::endpoints::ServerEnd<ProtocolMarker>>,
1451                    fidl::encoding::DefaultFuchsiaResourceDialect
1452                ),
1453            }
1454        }
1455
1456        #[inline]
1457        unsafe fn decode(
1458            &mut self,
1459            decoder: &mut fidl::encoding::Decoder<
1460                '_,
1461                fidl::encoding::DefaultFuchsiaResourceDialect,
1462            >,
1463            offset: usize,
1464            _depth: fidl::encoding::Depth,
1465        ) -> fidl::Result<()> {
1466            decoder.debug_check_bounds::<Self>(offset);
1467            // Verify that padding bytes are zero.
1468            fidl::decode!(
1469                fidl::encoding::Endpoint<fidl::endpoints::ServerEnd<ProtocolMarker>>,
1470                fidl::encoding::DefaultFuchsiaResourceDialect,
1471                &mut self.protocol,
1472                decoder,
1473                offset + 0,
1474                _depth
1475            )?;
1476            Ok(())
1477        }
1478    }
1479}