fidl_fuchsia_testing_proxy/
fidl_fuchsia_testing_proxy.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 _};
10use futures::future::{self, MaybeDone, TryFutureExt};
11use zx_status;
12
13#[derive(Debug, Eq, Hash, Ord, PartialEq, PartialOrd)]
14pub struct TcpProxyControlOpenProxyRequest {
15    pub target_port: u16,
16    pub proxy_port: u16,
17    pub tcp_proxy: fidl::endpoints::ServerEnd<TcpProxy_Marker>,
18}
19
20impl fidl::Standalone<fidl::encoding::DefaultFuchsiaResourceDialect>
21    for TcpProxyControlOpenProxyRequest
22{
23}
24
25#[derive(Clone, Copy, Debug, Eq, Hash, Ord, PartialEq, PartialOrd)]
26#[repr(C)]
27pub struct TcpProxyControlOpenProxyResponse {
28    pub open_port: u16,
29}
30
31impl fidl::Persistable for TcpProxyControlOpenProxyResponse {}
32
33#[derive(Debug, Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Hash)]
34pub struct TcpProxy_Marker;
35
36impl fidl::endpoints::ProtocolMarker for TcpProxy_Marker {
37    type Proxy = TcpProxy_Proxy;
38    type RequestStream = TcpProxy_RequestStream;
39    #[cfg(target_os = "fuchsia")]
40    type SynchronousProxy = TcpProxy_SynchronousProxy;
41
42    const DEBUG_NAME: &'static str = "(anonymous) TcpProxy_";
43}
44
45pub trait TcpProxy_ProxyInterface: Send + Sync {}
46#[derive(Debug)]
47#[cfg(target_os = "fuchsia")]
48pub struct TcpProxy_SynchronousProxy {
49    client: fidl::client::sync::Client,
50}
51
52#[cfg(target_os = "fuchsia")]
53impl fidl::endpoints::SynchronousProxy for TcpProxy_SynchronousProxy {
54    type Proxy = TcpProxy_Proxy;
55    type Protocol = TcpProxy_Marker;
56
57    fn from_channel(inner: fidl::Channel) -> Self {
58        Self::new(inner)
59    }
60
61    fn into_channel(self) -> fidl::Channel {
62        self.client.into_channel()
63    }
64
65    fn as_channel(&self) -> &fidl::Channel {
66        self.client.as_channel()
67    }
68}
69
70#[cfg(target_os = "fuchsia")]
71impl TcpProxy_SynchronousProxy {
72    pub fn new(channel: fidl::Channel) -> Self {
73        let protocol_name = <TcpProxy_Marker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME;
74        Self { client: fidl::client::sync::Client::new(channel, protocol_name) }
75    }
76
77    pub fn into_channel(self) -> fidl::Channel {
78        self.client.into_channel()
79    }
80
81    /// Waits until an event arrives and returns it. It is safe for other
82    /// threads to make concurrent requests while waiting for an event.
83    pub fn wait_for_event(
84        &self,
85        deadline: zx::MonotonicInstant,
86    ) -> Result<TcpProxy_Event, fidl::Error> {
87        TcpProxy_Event::decode(self.client.wait_for_event(deadline)?)
88    }
89}
90
91#[derive(Debug, Clone)]
92pub struct TcpProxy_Proxy {
93    client: fidl::client::Client<fidl::encoding::DefaultFuchsiaResourceDialect>,
94}
95
96impl fidl::endpoints::Proxy for TcpProxy_Proxy {
97    type Protocol = TcpProxy_Marker;
98
99    fn from_channel(inner: ::fidl::AsyncChannel) -> Self {
100        Self::new(inner)
101    }
102
103    fn into_channel(self) -> Result<::fidl::AsyncChannel, Self> {
104        self.client.into_channel().map_err(|client| Self { client })
105    }
106
107    fn as_channel(&self) -> &::fidl::AsyncChannel {
108        self.client.as_channel()
109    }
110}
111
112impl TcpProxy_Proxy {
113    /// Create a new Proxy for fuchsia.testing.proxy/TcpProxy.
114    pub fn new(channel: ::fidl::AsyncChannel) -> Self {
115        let protocol_name = <TcpProxy_Marker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME;
116        Self { client: fidl::client::Client::new(channel, protocol_name) }
117    }
118
119    /// Get a Stream of events from the remote end of the protocol.
120    ///
121    /// # Panics
122    ///
123    /// Panics if the event stream was already taken.
124    pub fn take_event_stream(&self) -> TcpProxy_EventStream {
125        TcpProxy_EventStream { event_receiver: self.client.take_event_receiver() }
126    }
127}
128
129impl TcpProxy_ProxyInterface for TcpProxy_Proxy {}
130
131pub struct TcpProxy_EventStream {
132    event_receiver: fidl::client::EventReceiver<fidl::encoding::DefaultFuchsiaResourceDialect>,
133}
134
135impl std::marker::Unpin for TcpProxy_EventStream {}
136
137impl futures::stream::FusedStream for TcpProxy_EventStream {
138    fn is_terminated(&self) -> bool {
139        self.event_receiver.is_terminated()
140    }
141}
142
143impl futures::Stream for TcpProxy_EventStream {
144    type Item = Result<TcpProxy_Event, fidl::Error>;
145
146    fn poll_next(
147        mut self: std::pin::Pin<&mut Self>,
148        cx: &mut std::task::Context<'_>,
149    ) -> std::task::Poll<Option<Self::Item>> {
150        match futures::ready!(futures::stream::StreamExt::poll_next_unpin(
151            &mut self.event_receiver,
152            cx
153        )?) {
154            Some(buf) => std::task::Poll::Ready(Some(TcpProxy_Event::decode(buf))),
155            None => std::task::Poll::Ready(None),
156        }
157    }
158}
159
160#[derive(Debug)]
161pub enum TcpProxy_Event {}
162
163impl TcpProxy_Event {
164    /// Decodes a message buffer as a [`TcpProxy_Event`].
165    fn decode(
166        mut buf: <fidl::encoding::DefaultFuchsiaResourceDialect as fidl::encoding::ResourceDialect>::MessageBufEtc,
167    ) -> Result<TcpProxy_Event, fidl::Error> {
168        let (bytes, _handles) = buf.split_mut();
169        let (tx_header, _body_bytes) = fidl::encoding::decode_transaction_header(bytes)?;
170        debug_assert_eq!(tx_header.tx_id, 0);
171        match tx_header.ordinal {
172            _ => Err(fidl::Error::UnknownOrdinal {
173                ordinal: tx_header.ordinal,
174                protocol_name: <TcpProxy_Marker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME,
175            }),
176        }
177    }
178}
179
180/// A Stream of incoming requests for fuchsia.testing.proxy/TcpProxy.
181pub struct TcpProxy_RequestStream {
182    inner: std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>,
183    is_terminated: bool,
184}
185
186impl std::marker::Unpin for TcpProxy_RequestStream {}
187
188impl futures::stream::FusedStream for TcpProxy_RequestStream {
189    fn is_terminated(&self) -> bool {
190        self.is_terminated
191    }
192}
193
194impl fidl::endpoints::RequestStream for TcpProxy_RequestStream {
195    type Protocol = TcpProxy_Marker;
196    type ControlHandle = TcpProxy_ControlHandle;
197
198    fn from_channel(channel: ::fidl::AsyncChannel) -> Self {
199        Self { inner: std::sync::Arc::new(fidl::ServeInner::new(channel)), is_terminated: false }
200    }
201
202    fn control_handle(&self) -> Self::ControlHandle {
203        TcpProxy_ControlHandle { inner: self.inner.clone() }
204    }
205
206    fn into_inner(
207        self,
208    ) -> (::std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>, bool)
209    {
210        (self.inner, self.is_terminated)
211    }
212
213    fn from_inner(
214        inner: std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>,
215        is_terminated: bool,
216    ) -> Self {
217        Self { inner, is_terminated }
218    }
219}
220
221impl futures::Stream for TcpProxy_RequestStream {
222    type Item = Result<TcpProxy_Request, fidl::Error>;
223
224    fn poll_next(
225        mut self: std::pin::Pin<&mut Self>,
226        cx: &mut std::task::Context<'_>,
227    ) -> std::task::Poll<Option<Self::Item>> {
228        let this = &mut *self;
229        if this.inner.check_shutdown(cx) {
230            this.is_terminated = true;
231            return std::task::Poll::Ready(None);
232        }
233        if this.is_terminated {
234            panic!("polled TcpProxy_RequestStream after completion");
235        }
236        fidl::encoding::with_tls_decode_buf::<_, fidl::encoding::DefaultFuchsiaResourceDialect>(
237            |bytes, handles| {
238                match this.inner.channel().read_etc(cx, bytes, handles) {
239                    std::task::Poll::Ready(Ok(())) => {}
240                    std::task::Poll::Pending => return std::task::Poll::Pending,
241                    std::task::Poll::Ready(Err(zx_status::Status::PEER_CLOSED)) => {
242                        this.is_terminated = true;
243                        return std::task::Poll::Ready(None);
244                    }
245                    std::task::Poll::Ready(Err(e)) => {
246                        return std::task::Poll::Ready(Some(Err(fidl::Error::ServerRequestRead(
247                            e.into(),
248                        ))))
249                    }
250                }
251
252                // A message has been received from the channel
253                let (header, _body_bytes) = fidl::encoding::decode_transaction_header(bytes)?;
254
255                std::task::Poll::Ready(Some(match header.ordinal {
256                    _ => Err(fidl::Error::UnknownOrdinal {
257                        ordinal: header.ordinal,
258                        protocol_name:
259                            <TcpProxy_Marker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME,
260                    }),
261                }))
262            },
263        )
264    }
265}
266
267/// An empty protocol which serves as a token for a proxy started with
268/// |TcpProxyControl.OpenProxy|. The proxy stays open as long as at least one
269/// |TcpProxy| channel corresponding to the proxy remains open. Note that the
270/// server may close the channel in the case an error is encountered.
271#[derive(Debug)]
272pub enum TcpProxy_Request {}
273
274impl TcpProxy_Request {
275    /// Name of the method defined in FIDL
276    pub fn method_name(&self) -> &'static str {
277        match *self {}
278    }
279}
280
281#[derive(Debug, Clone)]
282pub struct TcpProxy_ControlHandle {
283    inner: std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>,
284}
285
286impl fidl::endpoints::ControlHandle for TcpProxy_ControlHandle {
287    fn shutdown(&self) {
288        self.inner.shutdown()
289    }
290    fn shutdown_with_epitaph(&self, status: zx_status::Status) {
291        self.inner.shutdown_with_epitaph(status)
292    }
293
294    fn is_closed(&self) -> bool {
295        self.inner.channel().is_closed()
296    }
297    fn on_closed(&self) -> fidl::OnSignalsRef<'_> {
298        self.inner.channel().on_closed()
299    }
300
301    #[cfg(target_os = "fuchsia")]
302    fn signal_peer(
303        &self,
304        clear_mask: zx::Signals,
305        set_mask: zx::Signals,
306    ) -> Result<(), zx_status::Status> {
307        use fidl::Peered;
308        self.inner.channel().signal_peer(clear_mask, set_mask)
309    }
310}
311
312impl TcpProxy_ControlHandle {}
313
314#[derive(Debug, Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Hash)]
315pub struct TcpProxyControlMarker;
316
317impl fidl::endpoints::ProtocolMarker for TcpProxyControlMarker {
318    type Proxy = TcpProxyControlProxy;
319    type RequestStream = TcpProxyControlRequestStream;
320    #[cfg(target_os = "fuchsia")]
321    type SynchronousProxy = TcpProxyControlSynchronousProxy;
322
323    const DEBUG_NAME: &'static str = "fuchsia.testing.proxy.TcpProxyControl";
324}
325impl fidl::endpoints::DiscoverableProtocolMarker for TcpProxyControlMarker {}
326
327pub trait TcpProxyControlProxyInterface: Send + Sync {
328    type OpenProxy_ResponseFut: std::future::Future<Output = Result<u16, fidl::Error>> + Send;
329    fn r#open_proxy_(
330        &self,
331        target_port: u16,
332        proxy_port: u16,
333        tcp_proxy: fidl::endpoints::ServerEnd<TcpProxy_Marker>,
334    ) -> Self::OpenProxy_ResponseFut;
335}
336#[derive(Debug)]
337#[cfg(target_os = "fuchsia")]
338pub struct TcpProxyControlSynchronousProxy {
339    client: fidl::client::sync::Client,
340}
341
342#[cfg(target_os = "fuchsia")]
343impl fidl::endpoints::SynchronousProxy for TcpProxyControlSynchronousProxy {
344    type Proxy = TcpProxyControlProxy;
345    type Protocol = TcpProxyControlMarker;
346
347    fn from_channel(inner: fidl::Channel) -> Self {
348        Self::new(inner)
349    }
350
351    fn into_channel(self) -> fidl::Channel {
352        self.client.into_channel()
353    }
354
355    fn as_channel(&self) -> &fidl::Channel {
356        self.client.as_channel()
357    }
358}
359
360#[cfg(target_os = "fuchsia")]
361impl TcpProxyControlSynchronousProxy {
362    pub fn new(channel: fidl::Channel) -> Self {
363        let protocol_name = <TcpProxyControlMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME;
364        Self { client: fidl::client::sync::Client::new(channel, protocol_name) }
365    }
366
367    pub fn into_channel(self) -> fidl::Channel {
368        self.client.into_channel()
369    }
370
371    /// Waits until an event arrives and returns it. It is safe for other
372    /// threads to make concurrent requests while waiting for an event.
373    pub fn wait_for_event(
374        &self,
375        deadline: zx::MonotonicInstant,
376    ) -> Result<TcpProxyControlEvent, fidl::Error> {
377        TcpProxyControlEvent::decode(self.client.wait_for_event(deadline)?)
378    }
379
380    /// Opens a proxy to the given |target_port|. If a proxy is already open
381    /// for the specified |target_port|, the existing |open_port| is returned.
382    /// The proxy remains open as long as at least a single client keeps their
383    /// |proxy_token| handle for the specified |target_port|. Once all the
384    /// |proxy_token| handles are closed, the proxy is closed. |proxy_port| is
385    /// the source port where the proxy is opened. Except when the test running
386    /// on remote host needs to reach a local device, its value is 0. This is
387    /// only useful when the user has tunneled these ports to the local device
388    /// and specified that port number as |proxy_port|.
389    pub fn r#open_proxy_(
390        &self,
391        mut target_port: u16,
392        mut proxy_port: u16,
393        mut tcp_proxy: fidl::endpoints::ServerEnd<TcpProxy_Marker>,
394        ___deadline: zx::MonotonicInstant,
395    ) -> Result<u16, fidl::Error> {
396        let _response = self
397            .client
398            .send_query::<TcpProxyControlOpenProxyRequest, TcpProxyControlOpenProxyResponse>(
399                (target_port, proxy_port, tcp_proxy),
400                0x6e2c348c371061e2,
401                fidl::encoding::DynamicFlags::empty(),
402                ___deadline,
403            )?;
404        Ok(_response.open_port)
405    }
406}
407
408#[derive(Debug, Clone)]
409pub struct TcpProxyControlProxy {
410    client: fidl::client::Client<fidl::encoding::DefaultFuchsiaResourceDialect>,
411}
412
413impl fidl::endpoints::Proxy for TcpProxyControlProxy {
414    type Protocol = TcpProxyControlMarker;
415
416    fn from_channel(inner: ::fidl::AsyncChannel) -> Self {
417        Self::new(inner)
418    }
419
420    fn into_channel(self) -> Result<::fidl::AsyncChannel, Self> {
421        self.client.into_channel().map_err(|client| Self { client })
422    }
423
424    fn as_channel(&self) -> &::fidl::AsyncChannel {
425        self.client.as_channel()
426    }
427}
428
429impl TcpProxyControlProxy {
430    /// Create a new Proxy for fuchsia.testing.proxy/TcpProxyControl.
431    pub fn new(channel: ::fidl::AsyncChannel) -> Self {
432        let protocol_name = <TcpProxyControlMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME;
433        Self { client: fidl::client::Client::new(channel, protocol_name) }
434    }
435
436    /// Get a Stream of events from the remote end of the protocol.
437    ///
438    /// # Panics
439    ///
440    /// Panics if the event stream was already taken.
441    pub fn take_event_stream(&self) -> TcpProxyControlEventStream {
442        TcpProxyControlEventStream { event_receiver: self.client.take_event_receiver() }
443    }
444
445    /// Opens a proxy to the given |target_port|. If a proxy is already open
446    /// for the specified |target_port|, the existing |open_port| is returned.
447    /// The proxy remains open as long as at least a single client keeps their
448    /// |proxy_token| handle for the specified |target_port|. Once all the
449    /// |proxy_token| handles are closed, the proxy is closed. |proxy_port| is
450    /// the source port where the proxy is opened. Except when the test running
451    /// on remote host needs to reach a local device, its value is 0. This is
452    /// only useful when the user has tunneled these ports to the local device
453    /// and specified that port number as |proxy_port|.
454    pub fn r#open_proxy_(
455        &self,
456        mut target_port: u16,
457        mut proxy_port: u16,
458        mut tcp_proxy: fidl::endpoints::ServerEnd<TcpProxy_Marker>,
459    ) -> fidl::client::QueryResponseFut<u16, fidl::encoding::DefaultFuchsiaResourceDialect> {
460        TcpProxyControlProxyInterface::r#open_proxy_(self, target_port, proxy_port, tcp_proxy)
461    }
462}
463
464impl TcpProxyControlProxyInterface for TcpProxyControlProxy {
465    type OpenProxy_ResponseFut =
466        fidl::client::QueryResponseFut<u16, fidl::encoding::DefaultFuchsiaResourceDialect>;
467    fn r#open_proxy_(
468        &self,
469        mut target_port: u16,
470        mut proxy_port: u16,
471        mut tcp_proxy: fidl::endpoints::ServerEnd<TcpProxy_Marker>,
472    ) -> Self::OpenProxy_ResponseFut {
473        fn _decode(
474            mut _buf: Result<<fidl::encoding::DefaultFuchsiaResourceDialect as fidl::encoding::ResourceDialect>::MessageBufEtc, fidl::Error>,
475        ) -> Result<u16, fidl::Error> {
476            let _response = fidl::client::decode_transaction_body::<
477                TcpProxyControlOpenProxyResponse,
478                fidl::encoding::DefaultFuchsiaResourceDialect,
479                0x6e2c348c371061e2,
480            >(_buf?)?;
481            Ok(_response.open_port)
482        }
483        self.client.send_query_and_decode::<TcpProxyControlOpenProxyRequest, u16>(
484            (target_port, proxy_port, tcp_proxy),
485            0x6e2c348c371061e2,
486            fidl::encoding::DynamicFlags::empty(),
487            _decode,
488        )
489    }
490}
491
492pub struct TcpProxyControlEventStream {
493    event_receiver: fidl::client::EventReceiver<fidl::encoding::DefaultFuchsiaResourceDialect>,
494}
495
496impl std::marker::Unpin for TcpProxyControlEventStream {}
497
498impl futures::stream::FusedStream for TcpProxyControlEventStream {
499    fn is_terminated(&self) -> bool {
500        self.event_receiver.is_terminated()
501    }
502}
503
504impl futures::Stream for TcpProxyControlEventStream {
505    type Item = Result<TcpProxyControlEvent, fidl::Error>;
506
507    fn poll_next(
508        mut self: std::pin::Pin<&mut Self>,
509        cx: &mut std::task::Context<'_>,
510    ) -> std::task::Poll<Option<Self::Item>> {
511        match futures::ready!(futures::stream::StreamExt::poll_next_unpin(
512            &mut self.event_receiver,
513            cx
514        )?) {
515            Some(buf) => std::task::Poll::Ready(Some(TcpProxyControlEvent::decode(buf))),
516            None => std::task::Poll::Ready(None),
517        }
518    }
519}
520
521#[derive(Debug)]
522pub enum TcpProxyControlEvent {}
523
524impl TcpProxyControlEvent {
525    /// Decodes a message buffer as a [`TcpProxyControlEvent`].
526    fn decode(
527        mut buf: <fidl::encoding::DefaultFuchsiaResourceDialect as fidl::encoding::ResourceDialect>::MessageBufEtc,
528    ) -> Result<TcpProxyControlEvent, fidl::Error> {
529        let (bytes, _handles) = buf.split_mut();
530        let (tx_header, _body_bytes) = fidl::encoding::decode_transaction_header(bytes)?;
531        debug_assert_eq!(tx_header.tx_id, 0);
532        match tx_header.ordinal {
533            _ => Err(fidl::Error::UnknownOrdinal {
534                ordinal: tx_header.ordinal,
535                protocol_name:
536                    <TcpProxyControlMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME,
537            }),
538        }
539    }
540}
541
542/// A Stream of incoming requests for fuchsia.testing.proxy/TcpProxyControl.
543pub struct TcpProxyControlRequestStream {
544    inner: std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>,
545    is_terminated: bool,
546}
547
548impl std::marker::Unpin for TcpProxyControlRequestStream {}
549
550impl futures::stream::FusedStream for TcpProxyControlRequestStream {
551    fn is_terminated(&self) -> bool {
552        self.is_terminated
553    }
554}
555
556impl fidl::endpoints::RequestStream for TcpProxyControlRequestStream {
557    type Protocol = TcpProxyControlMarker;
558    type ControlHandle = TcpProxyControlControlHandle;
559
560    fn from_channel(channel: ::fidl::AsyncChannel) -> Self {
561        Self { inner: std::sync::Arc::new(fidl::ServeInner::new(channel)), is_terminated: false }
562    }
563
564    fn control_handle(&self) -> Self::ControlHandle {
565        TcpProxyControlControlHandle { inner: self.inner.clone() }
566    }
567
568    fn into_inner(
569        self,
570    ) -> (::std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>, bool)
571    {
572        (self.inner, self.is_terminated)
573    }
574
575    fn from_inner(
576        inner: std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>,
577        is_terminated: bool,
578    ) -> Self {
579        Self { inner, is_terminated }
580    }
581}
582
583impl futures::Stream for TcpProxyControlRequestStream {
584    type Item = Result<TcpProxyControlRequest, fidl::Error>;
585
586    fn poll_next(
587        mut self: std::pin::Pin<&mut Self>,
588        cx: &mut std::task::Context<'_>,
589    ) -> std::task::Poll<Option<Self::Item>> {
590        let this = &mut *self;
591        if this.inner.check_shutdown(cx) {
592            this.is_terminated = true;
593            return std::task::Poll::Ready(None);
594        }
595        if this.is_terminated {
596            panic!("polled TcpProxyControlRequestStream after completion");
597        }
598        fidl::encoding::with_tls_decode_buf::<_, fidl::encoding::DefaultFuchsiaResourceDialect>(
599            |bytes, handles| {
600                match this.inner.channel().read_etc(cx, bytes, handles) {
601                    std::task::Poll::Ready(Ok(())) => {}
602                    std::task::Poll::Pending => return std::task::Poll::Pending,
603                    std::task::Poll::Ready(Err(zx_status::Status::PEER_CLOSED)) => {
604                        this.is_terminated = true;
605                        return std::task::Poll::Ready(None);
606                    }
607                    std::task::Poll::Ready(Err(e)) => {
608                        return std::task::Poll::Ready(Some(Err(fidl::Error::ServerRequestRead(
609                            e.into(),
610                        ))))
611                    }
612                }
613
614                // A message has been received from the channel
615                let (header, _body_bytes) = fidl::encoding::decode_transaction_header(bytes)?;
616
617                std::task::Poll::Ready(Some(match header.ordinal {
618                    0x6e2c348c371061e2 => {
619                        header.validate_request_tx_id(fidl::MethodType::TwoWay)?;
620                        let mut req = fidl::new_empty!(
621                            TcpProxyControlOpenProxyRequest,
622                            fidl::encoding::DefaultFuchsiaResourceDialect
623                        );
624                        fidl::encoding::Decoder::<fidl::encoding::DefaultFuchsiaResourceDialect>::decode_into::<TcpProxyControlOpenProxyRequest>(&header, _body_bytes, handles, &mut req)?;
625                        let control_handle =
626                            TcpProxyControlControlHandle { inner: this.inner.clone() };
627                        Ok(TcpProxyControlRequest::OpenProxy_ {
628                            target_port: req.target_port,
629                            proxy_port: req.proxy_port,
630                            tcp_proxy: req.tcp_proxy,
631
632                            responder: TcpProxyControlOpenProxy_Responder {
633                                control_handle: std::mem::ManuallyDrop::new(control_handle),
634                                tx_id: header.tx_id,
635                            },
636                        })
637                    }
638                    _ => Err(fidl::Error::UnknownOrdinal {
639                        ordinal: header.ordinal,
640                        protocol_name:
641                            <TcpProxyControlMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME,
642                    }),
643                }))
644            },
645        )
646    }
647}
648
649/// A protocol that enables creating TCP proxies so that host tests may
650/// access debug services that normally accept only local connections.
651///
652/// For example, if web browser exposes a debug HTTP service listening on
653/// [::1]:9999, TcpProxyControl may listen on [::]:10000 and forward requests
654/// to port 9999. The host test then calls port 10000 to access the web browser's
655/// debug service.
656#[derive(Debug)]
657pub enum TcpProxyControlRequest {
658    /// Opens a proxy to the given |target_port|. If a proxy is already open
659    /// for the specified |target_port|, the existing |open_port| is returned.
660    /// The proxy remains open as long as at least a single client keeps their
661    /// |proxy_token| handle for the specified |target_port|. Once all the
662    /// |proxy_token| handles are closed, the proxy is closed. |proxy_port| is
663    /// the source port where the proxy is opened. Except when the test running
664    /// on remote host needs to reach a local device, its value is 0. This is
665    /// only useful when the user has tunneled these ports to the local device
666    /// and specified that port number as |proxy_port|.
667    OpenProxy_ {
668        target_port: u16,
669        proxy_port: u16,
670        tcp_proxy: fidl::endpoints::ServerEnd<TcpProxy_Marker>,
671        responder: TcpProxyControlOpenProxy_Responder,
672    },
673}
674
675impl TcpProxyControlRequest {
676    #[allow(irrefutable_let_patterns)]
677    pub fn into_open_proxy_(
678        self,
679    ) -> Option<(
680        u16,
681        u16,
682        fidl::endpoints::ServerEnd<TcpProxy_Marker>,
683        TcpProxyControlOpenProxy_Responder,
684    )> {
685        if let TcpProxyControlRequest::OpenProxy_ {
686            target_port,
687            proxy_port,
688            tcp_proxy,
689            responder,
690        } = self
691        {
692            Some((target_port, proxy_port, tcp_proxy, responder))
693        } else {
694            None
695        }
696    }
697
698    /// Name of the method defined in FIDL
699    pub fn method_name(&self) -> &'static str {
700        match *self {
701            TcpProxyControlRequest::OpenProxy_ { .. } => "open_proxy_",
702        }
703    }
704}
705
706#[derive(Debug, Clone)]
707pub struct TcpProxyControlControlHandle {
708    inner: std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>,
709}
710
711impl fidl::endpoints::ControlHandle for TcpProxyControlControlHandle {
712    fn shutdown(&self) {
713        self.inner.shutdown()
714    }
715    fn shutdown_with_epitaph(&self, status: zx_status::Status) {
716        self.inner.shutdown_with_epitaph(status)
717    }
718
719    fn is_closed(&self) -> bool {
720        self.inner.channel().is_closed()
721    }
722    fn on_closed(&self) -> fidl::OnSignalsRef<'_> {
723        self.inner.channel().on_closed()
724    }
725
726    #[cfg(target_os = "fuchsia")]
727    fn signal_peer(
728        &self,
729        clear_mask: zx::Signals,
730        set_mask: zx::Signals,
731    ) -> Result<(), zx_status::Status> {
732        use fidl::Peered;
733        self.inner.channel().signal_peer(clear_mask, set_mask)
734    }
735}
736
737impl TcpProxyControlControlHandle {}
738
739#[must_use = "FIDL methods require a response to be sent"]
740#[derive(Debug)]
741pub struct TcpProxyControlOpenProxy_Responder {
742    control_handle: std::mem::ManuallyDrop<TcpProxyControlControlHandle>,
743    tx_id: u32,
744}
745
746/// Set the the channel to be shutdown (see [`TcpProxyControlControlHandle::shutdown`])
747/// if the responder is dropped without sending a response, so that the client
748/// doesn't hang. To prevent this behavior, call `drop_without_shutdown`.
749impl std::ops::Drop for TcpProxyControlOpenProxy_Responder {
750    fn drop(&mut self) {
751        self.control_handle.shutdown();
752        // Safety: drops once, never accessed again
753        unsafe { std::mem::ManuallyDrop::drop(&mut self.control_handle) };
754    }
755}
756
757impl fidl::endpoints::Responder for TcpProxyControlOpenProxy_Responder {
758    type ControlHandle = TcpProxyControlControlHandle;
759
760    fn control_handle(&self) -> &TcpProxyControlControlHandle {
761        &self.control_handle
762    }
763
764    fn drop_without_shutdown(mut self) {
765        // Safety: drops once, never accessed again due to mem::forget
766        unsafe { std::mem::ManuallyDrop::drop(&mut self.control_handle) };
767        // Prevent Drop from running (which would shut down the channel)
768        std::mem::forget(self);
769    }
770}
771
772impl TcpProxyControlOpenProxy_Responder {
773    /// Sends a response to the FIDL transaction.
774    ///
775    /// Sets the channel to shutdown if an error occurs.
776    pub fn send(self, mut open_port: u16) -> Result<(), fidl::Error> {
777        let _result = self.send_raw(open_port);
778        if _result.is_err() {
779            self.control_handle.shutdown();
780        }
781        self.drop_without_shutdown();
782        _result
783    }
784
785    /// Similar to "send" but does not shutdown the channel if an error occurs.
786    pub fn send_no_shutdown_on_err(self, mut open_port: u16) -> Result<(), fidl::Error> {
787        let _result = self.send_raw(open_port);
788        self.drop_without_shutdown();
789        _result
790    }
791
792    fn send_raw(&self, mut open_port: u16) -> Result<(), fidl::Error> {
793        self.control_handle.inner.send::<TcpProxyControlOpenProxyResponse>(
794            (open_port,),
795            self.tx_id,
796            0x6e2c348c371061e2,
797            fidl::encoding::DynamicFlags::empty(),
798        )
799    }
800}
801
802mod internal {
803    use super::*;
804
805    impl fidl::encoding::ResourceTypeMarker for TcpProxyControlOpenProxyRequest {
806        type Borrowed<'a> = &'a mut Self;
807        fn take_or_borrow<'a>(
808            value: &'a mut <Self as fidl::encoding::TypeMarker>::Owned,
809        ) -> Self::Borrowed<'a> {
810            value
811        }
812    }
813
814    unsafe impl fidl::encoding::TypeMarker for TcpProxyControlOpenProxyRequest {
815        type Owned = Self;
816
817        #[inline(always)]
818        fn inline_align(_context: fidl::encoding::Context) -> usize {
819            4
820        }
821
822        #[inline(always)]
823        fn inline_size(_context: fidl::encoding::Context) -> usize {
824            8
825        }
826    }
827
828    unsafe impl
829        fidl::encoding::Encode<
830            TcpProxyControlOpenProxyRequest,
831            fidl::encoding::DefaultFuchsiaResourceDialect,
832        > for &mut TcpProxyControlOpenProxyRequest
833    {
834        #[inline]
835        unsafe fn encode(
836            self,
837            encoder: &mut fidl::encoding::Encoder<
838                '_,
839                fidl::encoding::DefaultFuchsiaResourceDialect,
840            >,
841            offset: usize,
842            _depth: fidl::encoding::Depth,
843        ) -> fidl::Result<()> {
844            encoder.debug_check_bounds::<TcpProxyControlOpenProxyRequest>(offset);
845            // Delegate to tuple encoding.
846            fidl::encoding::Encode::<TcpProxyControlOpenProxyRequest, fidl::encoding::DefaultFuchsiaResourceDialect>::encode(
847                (
848                    <u16 as fidl::encoding::ValueTypeMarker>::borrow(&self.target_port),
849                    <u16 as fidl::encoding::ValueTypeMarker>::borrow(&self.proxy_port),
850                    <fidl::encoding::Endpoint<fidl::endpoints::ServerEnd<TcpProxy_Marker>> as fidl::encoding::ResourceTypeMarker>::take_or_borrow(&mut self.tcp_proxy),
851                ),
852                encoder, offset, _depth
853            )
854        }
855    }
856    unsafe impl<
857            T0: fidl::encoding::Encode<u16, fidl::encoding::DefaultFuchsiaResourceDialect>,
858            T1: fidl::encoding::Encode<u16, fidl::encoding::DefaultFuchsiaResourceDialect>,
859            T2: fidl::encoding::Encode<
860                fidl::encoding::Endpoint<fidl::endpoints::ServerEnd<TcpProxy_Marker>>,
861                fidl::encoding::DefaultFuchsiaResourceDialect,
862            >,
863        >
864        fidl::encoding::Encode<
865            TcpProxyControlOpenProxyRequest,
866            fidl::encoding::DefaultFuchsiaResourceDialect,
867        > for (T0, T1, T2)
868    {
869        #[inline]
870        unsafe fn encode(
871            self,
872            encoder: &mut fidl::encoding::Encoder<
873                '_,
874                fidl::encoding::DefaultFuchsiaResourceDialect,
875            >,
876            offset: usize,
877            depth: fidl::encoding::Depth,
878        ) -> fidl::Result<()> {
879            encoder.debug_check_bounds::<TcpProxyControlOpenProxyRequest>(offset);
880            // Zero out padding regions. There's no need to apply masks
881            // because the unmasked parts will be overwritten by fields.
882            // Write the fields.
883            self.0.encode(encoder, offset + 0, depth)?;
884            self.1.encode(encoder, offset + 2, depth)?;
885            self.2.encode(encoder, offset + 4, depth)?;
886            Ok(())
887        }
888    }
889
890    impl fidl::encoding::Decode<Self, fidl::encoding::DefaultFuchsiaResourceDialect>
891        for TcpProxyControlOpenProxyRequest
892    {
893        #[inline(always)]
894        fn new_empty() -> Self {
895            Self {
896                target_port: fidl::new_empty!(u16, fidl::encoding::DefaultFuchsiaResourceDialect),
897                proxy_port: fidl::new_empty!(u16, fidl::encoding::DefaultFuchsiaResourceDialect),
898                tcp_proxy: fidl::new_empty!(
899                    fidl::encoding::Endpoint<fidl::endpoints::ServerEnd<TcpProxy_Marker>>,
900                    fidl::encoding::DefaultFuchsiaResourceDialect
901                ),
902            }
903        }
904
905        #[inline]
906        unsafe fn decode(
907            &mut self,
908            decoder: &mut fidl::encoding::Decoder<
909                '_,
910                fidl::encoding::DefaultFuchsiaResourceDialect,
911            >,
912            offset: usize,
913            _depth: fidl::encoding::Depth,
914        ) -> fidl::Result<()> {
915            decoder.debug_check_bounds::<Self>(offset);
916            // Verify that padding bytes are zero.
917            fidl::decode!(
918                u16,
919                fidl::encoding::DefaultFuchsiaResourceDialect,
920                &mut self.target_port,
921                decoder,
922                offset + 0,
923                _depth
924            )?;
925            fidl::decode!(
926                u16,
927                fidl::encoding::DefaultFuchsiaResourceDialect,
928                &mut self.proxy_port,
929                decoder,
930                offset + 2,
931                _depth
932            )?;
933            fidl::decode!(
934                fidl::encoding::Endpoint<fidl::endpoints::ServerEnd<TcpProxy_Marker>>,
935                fidl::encoding::DefaultFuchsiaResourceDialect,
936                &mut self.tcp_proxy,
937                decoder,
938                offset + 4,
939                _depth
940            )?;
941            Ok(())
942        }
943    }
944
945    impl fidl::encoding::ValueTypeMarker for TcpProxyControlOpenProxyResponse {
946        type Borrowed<'a> = &'a Self;
947        fn borrow(value: &<Self as fidl::encoding::TypeMarker>::Owned) -> Self::Borrowed<'_> {
948            value
949        }
950    }
951
952    unsafe impl fidl::encoding::TypeMarker for TcpProxyControlOpenProxyResponse {
953        type Owned = Self;
954
955        #[inline(always)]
956        fn inline_align(_context: fidl::encoding::Context) -> usize {
957            2
958        }
959
960        #[inline(always)]
961        fn inline_size(_context: fidl::encoding::Context) -> usize {
962            2
963        }
964        #[inline(always)]
965        fn encode_is_copy() -> bool {
966            true
967        }
968
969        #[inline(always)]
970        fn decode_is_copy() -> bool {
971            true
972        }
973    }
974
975    unsafe impl<D: fidl::encoding::ResourceDialect>
976        fidl::encoding::Encode<TcpProxyControlOpenProxyResponse, D>
977        for &TcpProxyControlOpenProxyResponse
978    {
979        #[inline]
980        unsafe fn encode(
981            self,
982            encoder: &mut fidl::encoding::Encoder<'_, D>,
983            offset: usize,
984            _depth: fidl::encoding::Depth,
985        ) -> fidl::Result<()> {
986            encoder.debug_check_bounds::<TcpProxyControlOpenProxyResponse>(offset);
987            unsafe {
988                // Copy the object into the buffer.
989                let buf_ptr = encoder.buf.as_mut_ptr().add(offset);
990                (buf_ptr as *mut TcpProxyControlOpenProxyResponse)
991                    .write_unaligned((self as *const TcpProxyControlOpenProxyResponse).read());
992                // Zero out padding regions. Unlike `fidl_struct_impl_noncopy!`, this must be
993                // done second because the memcpy will write garbage to these bytes.
994            }
995            Ok(())
996        }
997    }
998    unsafe impl<D: fidl::encoding::ResourceDialect, T0: fidl::encoding::Encode<u16, D>>
999        fidl::encoding::Encode<TcpProxyControlOpenProxyResponse, D> for (T0,)
1000    {
1001        #[inline]
1002        unsafe fn encode(
1003            self,
1004            encoder: &mut fidl::encoding::Encoder<'_, D>,
1005            offset: usize,
1006            depth: fidl::encoding::Depth,
1007        ) -> fidl::Result<()> {
1008            encoder.debug_check_bounds::<TcpProxyControlOpenProxyResponse>(offset);
1009            // Zero out padding regions. There's no need to apply masks
1010            // because the unmasked parts will be overwritten by fields.
1011            // Write the fields.
1012            self.0.encode(encoder, offset + 0, depth)?;
1013            Ok(())
1014        }
1015    }
1016
1017    impl<D: fidl::encoding::ResourceDialect> fidl::encoding::Decode<Self, D>
1018        for TcpProxyControlOpenProxyResponse
1019    {
1020        #[inline(always)]
1021        fn new_empty() -> Self {
1022            Self { open_port: fidl::new_empty!(u16, D) }
1023        }
1024
1025        #[inline]
1026        unsafe fn decode(
1027            &mut self,
1028            decoder: &mut fidl::encoding::Decoder<'_, D>,
1029            offset: usize,
1030            _depth: fidl::encoding::Depth,
1031        ) -> fidl::Result<()> {
1032            decoder.debug_check_bounds::<Self>(offset);
1033            let buf_ptr = unsafe { decoder.buf.as_ptr().add(offset) };
1034            // Verify that padding bytes are zero.
1035            // Copy from the buffer into the object.
1036            unsafe {
1037                std::ptr::copy_nonoverlapping(buf_ptr, self as *mut Self as *mut u8, 2);
1038            }
1039            Ok(())
1040        }
1041    }
1042}