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