fidl_fuchsia_hardware_serial/
fidl_fuchsia_hardware_serial.rs

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