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::NullableHandle {
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
606    fn shutdown_with_epitaph(&self, status: zx_status::Status) {
607        self.inner.shutdown_with_epitaph(status)
608    }
609
610    fn is_closed(&self) -> bool {
611        self.inner.channel().is_closed()
612    }
613    fn on_closed(&self) -> fidl::OnSignalsRef<'_> {
614        self.inner.channel().on_closed()
615    }
616
617    #[cfg(target_os = "fuchsia")]
618    fn signal_peer(
619        &self,
620        clear_mask: zx::Signals,
621        set_mask: zx::Signals,
622    ) -> Result<(), zx_status::Status> {
623        use fidl::Peered;
624        self.inner.channel().signal_peer(clear_mask, set_mask)
625    }
626}
627
628impl DeviceControlHandle {}
629
630#[must_use = "FIDL methods require a response to be sent"]
631#[derive(Debug)]
632pub struct DeviceGetClassResponder {
633    control_handle: std::mem::ManuallyDrop<DeviceControlHandle>,
634    tx_id: u32,
635}
636
637/// Set the the channel to be shutdown (see [`DeviceControlHandle::shutdown`])
638/// if the responder is dropped without sending a response, so that the client
639/// doesn't hang. To prevent this behavior, call `drop_without_shutdown`.
640impl std::ops::Drop for DeviceGetClassResponder {
641    fn drop(&mut self) {
642        self.control_handle.shutdown();
643        // Safety: drops once, never accessed again
644        unsafe { std::mem::ManuallyDrop::drop(&mut self.control_handle) };
645    }
646}
647
648impl fidl::endpoints::Responder for DeviceGetClassResponder {
649    type ControlHandle = DeviceControlHandle;
650
651    fn control_handle(&self) -> &DeviceControlHandle {
652        &self.control_handle
653    }
654
655    fn drop_without_shutdown(mut self) {
656        // Safety: drops once, never accessed again due to mem::forget
657        unsafe { std::mem::ManuallyDrop::drop(&mut self.control_handle) };
658        // Prevent Drop from running (which would shut down the channel)
659        std::mem::forget(self);
660    }
661}
662
663impl DeviceGetClassResponder {
664    /// Sends a response to the FIDL transaction.
665    ///
666    /// Sets the channel to shutdown if an error occurs.
667    pub fn send(self, mut device_class: Class) -> Result<(), fidl::Error> {
668        let _result = self.send_raw(device_class);
669        if _result.is_err() {
670            self.control_handle.shutdown();
671        }
672        self.drop_without_shutdown();
673        _result
674    }
675
676    /// Similar to "send" but does not shutdown the channel if an error occurs.
677    pub fn send_no_shutdown_on_err(self, mut device_class: Class) -> Result<(), fidl::Error> {
678        let _result = self.send_raw(device_class);
679        self.drop_without_shutdown();
680        _result
681    }
682
683    fn send_raw(&self, mut device_class: Class) -> Result<(), fidl::Error> {
684        self.control_handle.inner.send::<DeviceGetClassResponse>(
685            (device_class,),
686            self.tx_id,
687            0x3d48bbcee248ab8b,
688            fidl::encoding::DynamicFlags::empty(),
689        )
690    }
691}
692
693#[must_use = "FIDL methods require a response to be sent"]
694#[derive(Debug)]
695pub struct DeviceSetConfigResponder {
696    control_handle: std::mem::ManuallyDrop<DeviceControlHandle>,
697    tx_id: u32,
698}
699
700/// Set the the channel to be shutdown (see [`DeviceControlHandle::shutdown`])
701/// if the responder is dropped without sending a response, so that the client
702/// doesn't hang. To prevent this behavior, call `drop_without_shutdown`.
703impl std::ops::Drop for DeviceSetConfigResponder {
704    fn drop(&mut self) {
705        self.control_handle.shutdown();
706        // Safety: drops once, never accessed again
707        unsafe { std::mem::ManuallyDrop::drop(&mut self.control_handle) };
708    }
709}
710
711impl fidl::endpoints::Responder for DeviceSetConfigResponder {
712    type ControlHandle = DeviceControlHandle;
713
714    fn control_handle(&self) -> &DeviceControlHandle {
715        &self.control_handle
716    }
717
718    fn drop_without_shutdown(mut self) {
719        // Safety: drops once, never accessed again due to mem::forget
720        unsafe { std::mem::ManuallyDrop::drop(&mut self.control_handle) };
721        // Prevent Drop from running (which would shut down the channel)
722        std::mem::forget(self);
723    }
724}
725
726impl DeviceSetConfigResponder {
727    /// Sends a response to the FIDL transaction.
728    ///
729    /// Sets the channel to shutdown if an error occurs.
730    pub fn send(self, mut s: i32) -> Result<(), fidl::Error> {
731        let _result = self.send_raw(s);
732        if _result.is_err() {
733            self.control_handle.shutdown();
734        }
735        self.drop_without_shutdown();
736        _result
737    }
738
739    /// Similar to "send" but does not shutdown the channel if an error occurs.
740    pub fn send_no_shutdown_on_err(self, mut s: i32) -> Result<(), fidl::Error> {
741        let _result = self.send_raw(s);
742        self.drop_without_shutdown();
743        _result
744    }
745
746    fn send_raw(&self, mut s: i32) -> Result<(), fidl::Error> {
747        self.control_handle.inner.send::<DeviceSetConfigResponse>(
748            (s,),
749            self.tx_id,
750            0x771a0946f6f87173,
751            fidl::encoding::DynamicFlags::empty(),
752        )
753    }
754}
755
756#[must_use = "FIDL methods require a response to be sent"]
757#[derive(Debug)]
758pub struct DeviceReadResponder {
759    control_handle: std::mem::ManuallyDrop<DeviceControlHandle>,
760    tx_id: u32,
761}
762
763/// Set the the channel to be shutdown (see [`DeviceControlHandle::shutdown`])
764/// if the responder is dropped without sending a response, so that the client
765/// doesn't hang. To prevent this behavior, call `drop_without_shutdown`.
766impl std::ops::Drop for DeviceReadResponder {
767    fn drop(&mut self) {
768        self.control_handle.shutdown();
769        // Safety: drops once, never accessed again
770        unsafe { std::mem::ManuallyDrop::drop(&mut self.control_handle) };
771    }
772}
773
774impl fidl::endpoints::Responder for DeviceReadResponder {
775    type ControlHandle = DeviceControlHandle;
776
777    fn control_handle(&self) -> &DeviceControlHandle {
778        &self.control_handle
779    }
780
781    fn drop_without_shutdown(mut self) {
782        // Safety: drops once, never accessed again due to mem::forget
783        unsafe { std::mem::ManuallyDrop::drop(&mut self.control_handle) };
784        // Prevent Drop from running (which would shut down the channel)
785        std::mem::forget(self);
786    }
787}
788
789impl DeviceReadResponder {
790    /// Sends a response to the FIDL transaction.
791    ///
792    /// Sets the channel to shutdown if an error occurs.
793    pub fn send(self, mut result: Result<&[u8], i32>) -> Result<(), fidl::Error> {
794        let _result = self.send_raw(result);
795        if _result.is_err() {
796            self.control_handle.shutdown();
797        }
798        self.drop_without_shutdown();
799        _result
800    }
801
802    /// Similar to "send" but does not shutdown the channel if an error occurs.
803    pub fn send_no_shutdown_on_err(
804        self,
805        mut result: Result<&[u8], i32>,
806    ) -> Result<(), fidl::Error> {
807        let _result = self.send_raw(result);
808        self.drop_without_shutdown();
809        _result
810    }
811
812    fn send_raw(&self, mut result: Result<&[u8], i32>) -> Result<(), fidl::Error> {
813        self.control_handle.inner.send::<fidl::encoding::ResultType<DeviceReadResponse, i32>>(
814            result.map(|data| (data,)),
815            self.tx_id,
816            0x63c41d3c053fadd8,
817            fidl::encoding::DynamicFlags::empty(),
818        )
819    }
820}
821
822#[must_use = "FIDL methods require a response to be sent"]
823#[derive(Debug)]
824pub struct DeviceWriteResponder {
825    control_handle: std::mem::ManuallyDrop<DeviceControlHandle>,
826    tx_id: u32,
827}
828
829/// Set the the channel to be shutdown (see [`DeviceControlHandle::shutdown`])
830/// if the responder is dropped without sending a response, so that the client
831/// doesn't hang. To prevent this behavior, call `drop_without_shutdown`.
832impl std::ops::Drop for DeviceWriteResponder {
833    fn drop(&mut self) {
834        self.control_handle.shutdown();
835        // Safety: drops once, never accessed again
836        unsafe { std::mem::ManuallyDrop::drop(&mut self.control_handle) };
837    }
838}
839
840impl fidl::endpoints::Responder for DeviceWriteResponder {
841    type ControlHandle = DeviceControlHandle;
842
843    fn control_handle(&self) -> &DeviceControlHandle {
844        &self.control_handle
845    }
846
847    fn drop_without_shutdown(mut self) {
848        // Safety: drops once, never accessed again due to mem::forget
849        unsafe { std::mem::ManuallyDrop::drop(&mut self.control_handle) };
850        // Prevent Drop from running (which would shut down the channel)
851        std::mem::forget(self);
852    }
853}
854
855impl DeviceWriteResponder {
856    /// Sends a response to the FIDL transaction.
857    ///
858    /// Sets the channel to shutdown if an error occurs.
859    pub fn send(self, mut result: Result<(), i32>) -> Result<(), fidl::Error> {
860        let _result = self.send_raw(result);
861        if _result.is_err() {
862            self.control_handle.shutdown();
863        }
864        self.drop_without_shutdown();
865        _result
866    }
867
868    /// Similar to "send" but does not shutdown the channel if an error occurs.
869    pub fn send_no_shutdown_on_err(self, mut result: Result<(), i32>) -> Result<(), fidl::Error> {
870        let _result = self.send_raw(result);
871        self.drop_without_shutdown();
872        _result
873    }
874
875    fn send_raw(&self, mut result: Result<(), i32>) -> Result<(), fidl::Error> {
876        self.control_handle
877            .inner
878            .send::<fidl::encoding::ResultType<fidl::encoding::EmptyStruct, i32>>(
879                result,
880                self.tx_id,
881                0x6aa7adae6841779c,
882                fidl::encoding::DynamicFlags::empty(),
883            )
884    }
885}
886
887#[derive(Debug, Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Hash)]
888pub struct DeviceProxy_Marker;
889
890impl fidl::endpoints::ProtocolMarker for DeviceProxy_Marker {
891    type Proxy = DeviceProxy_Proxy;
892    type RequestStream = DeviceProxy_RequestStream;
893    #[cfg(target_os = "fuchsia")]
894    type SynchronousProxy = DeviceProxy_SynchronousProxy;
895
896    const DEBUG_NAME: &'static str = "fuchsia.hardware.serial.DeviceProxy";
897}
898impl fidl::endpoints::DiscoverableProtocolMarker for DeviceProxy_Marker {}
899
900pub trait DeviceProxy_ProxyInterface: Send + Sync {
901    fn r#get_channel(
902        &self,
903        req: fidl::endpoints::ServerEnd<DeviceMarker>,
904    ) -> Result<(), fidl::Error>;
905}
906#[derive(Debug)]
907#[cfg(target_os = "fuchsia")]
908pub struct DeviceProxy_SynchronousProxy {
909    client: fidl::client::sync::Client,
910}
911
912#[cfg(target_os = "fuchsia")]
913impl fidl::endpoints::SynchronousProxy for DeviceProxy_SynchronousProxy {
914    type Proxy = DeviceProxy_Proxy;
915    type Protocol = DeviceProxy_Marker;
916
917    fn from_channel(inner: fidl::Channel) -> Self {
918        Self::new(inner)
919    }
920
921    fn into_channel(self) -> fidl::Channel {
922        self.client.into_channel()
923    }
924
925    fn as_channel(&self) -> &fidl::Channel {
926        self.client.as_channel()
927    }
928}
929
930#[cfg(target_os = "fuchsia")]
931impl DeviceProxy_SynchronousProxy {
932    pub fn new(channel: fidl::Channel) -> Self {
933        let protocol_name = <DeviceProxy_Marker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME;
934        Self { client: fidl::client::sync::Client::new(channel, protocol_name) }
935    }
936
937    pub fn into_channel(self) -> fidl::Channel {
938        self.client.into_channel()
939    }
940
941    /// Waits until an event arrives and returns it. It is safe for other
942    /// threads to make concurrent requests while waiting for an event.
943    pub fn wait_for_event(
944        &self,
945        deadline: zx::MonotonicInstant,
946    ) -> Result<DeviceProxy_Event, fidl::Error> {
947        DeviceProxy_Event::decode(self.client.wait_for_event(deadline)?)
948    }
949
950    pub fn r#get_channel(
951        &self,
952        mut req: fidl::endpoints::ServerEnd<DeviceMarker>,
953    ) -> Result<(), fidl::Error> {
954        self.client.send::<DeviceProxyGetChannelRequest>(
955            (req,),
956            0x580f1a3ef6c20fff,
957            fidl::encoding::DynamicFlags::empty(),
958        )
959    }
960}
961
962#[cfg(target_os = "fuchsia")]
963impl From<DeviceProxy_SynchronousProxy> for zx::NullableHandle {
964    fn from(value: DeviceProxy_SynchronousProxy) -> Self {
965        value.into_channel().into()
966    }
967}
968
969#[cfg(target_os = "fuchsia")]
970impl From<fidl::Channel> for DeviceProxy_SynchronousProxy {
971    fn from(value: fidl::Channel) -> Self {
972        Self::new(value)
973    }
974}
975
976#[cfg(target_os = "fuchsia")]
977impl fidl::endpoints::FromClient for DeviceProxy_SynchronousProxy {
978    type Protocol = DeviceProxy_Marker;
979
980    fn from_client(value: fidl::endpoints::ClientEnd<DeviceProxy_Marker>) -> Self {
981        Self::new(value.into_channel())
982    }
983}
984
985#[derive(Debug, Clone)]
986pub struct DeviceProxy_Proxy {
987    client: fidl::client::Client<fidl::encoding::DefaultFuchsiaResourceDialect>,
988}
989
990impl fidl::endpoints::Proxy for DeviceProxy_Proxy {
991    type Protocol = DeviceProxy_Marker;
992
993    fn from_channel(inner: ::fidl::AsyncChannel) -> Self {
994        Self::new(inner)
995    }
996
997    fn into_channel(self) -> Result<::fidl::AsyncChannel, Self> {
998        self.client.into_channel().map_err(|client| Self { client })
999    }
1000
1001    fn as_channel(&self) -> &::fidl::AsyncChannel {
1002        self.client.as_channel()
1003    }
1004}
1005
1006impl DeviceProxy_Proxy {
1007    /// Create a new Proxy for fuchsia.hardware.serial/DeviceProxy.
1008    pub fn new(channel: ::fidl::AsyncChannel) -> Self {
1009        let protocol_name = <DeviceProxy_Marker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME;
1010        Self { client: fidl::client::Client::new(channel, protocol_name) }
1011    }
1012
1013    /// Get a Stream of events from the remote end of the protocol.
1014    ///
1015    /// # Panics
1016    ///
1017    /// Panics if the event stream was already taken.
1018    pub fn take_event_stream(&self) -> DeviceProxy_EventStream {
1019        DeviceProxy_EventStream { event_receiver: self.client.take_event_receiver() }
1020    }
1021
1022    pub fn r#get_channel(
1023        &self,
1024        mut req: fidl::endpoints::ServerEnd<DeviceMarker>,
1025    ) -> Result<(), fidl::Error> {
1026        DeviceProxy_ProxyInterface::r#get_channel(self, req)
1027    }
1028}
1029
1030impl DeviceProxy_ProxyInterface for DeviceProxy_Proxy {
1031    fn r#get_channel(
1032        &self,
1033        mut req: fidl::endpoints::ServerEnd<DeviceMarker>,
1034    ) -> Result<(), fidl::Error> {
1035        self.client.send::<DeviceProxyGetChannelRequest>(
1036            (req,),
1037            0x580f1a3ef6c20fff,
1038            fidl::encoding::DynamicFlags::empty(),
1039        )
1040    }
1041}
1042
1043pub struct DeviceProxy_EventStream {
1044    event_receiver: fidl::client::EventReceiver<fidl::encoding::DefaultFuchsiaResourceDialect>,
1045}
1046
1047impl std::marker::Unpin for DeviceProxy_EventStream {}
1048
1049impl futures::stream::FusedStream for DeviceProxy_EventStream {
1050    fn is_terminated(&self) -> bool {
1051        self.event_receiver.is_terminated()
1052    }
1053}
1054
1055impl futures::Stream for DeviceProxy_EventStream {
1056    type Item = Result<DeviceProxy_Event, fidl::Error>;
1057
1058    fn poll_next(
1059        mut self: std::pin::Pin<&mut Self>,
1060        cx: &mut std::task::Context<'_>,
1061    ) -> std::task::Poll<Option<Self::Item>> {
1062        match futures::ready!(futures::stream::StreamExt::poll_next_unpin(
1063            &mut self.event_receiver,
1064            cx
1065        )?) {
1066            Some(buf) => std::task::Poll::Ready(Some(DeviceProxy_Event::decode(buf))),
1067            None => std::task::Poll::Ready(None),
1068        }
1069    }
1070}
1071
1072#[derive(Debug)]
1073pub enum DeviceProxy_Event {}
1074
1075impl DeviceProxy_Event {
1076    /// Decodes a message buffer as a [`DeviceProxy_Event`].
1077    fn decode(
1078        mut buf: <fidl::encoding::DefaultFuchsiaResourceDialect as fidl::encoding::ResourceDialect>::MessageBufEtc,
1079    ) -> Result<DeviceProxy_Event, fidl::Error> {
1080        let (bytes, _handles) = buf.split_mut();
1081        let (tx_header, _body_bytes) = fidl::encoding::decode_transaction_header(bytes)?;
1082        debug_assert_eq!(tx_header.tx_id, 0);
1083        match tx_header.ordinal {
1084            _ => Err(fidl::Error::UnknownOrdinal {
1085                ordinal: tx_header.ordinal,
1086                protocol_name: <DeviceProxy_Marker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME,
1087            }),
1088        }
1089    }
1090}
1091
1092/// A Stream of incoming requests for fuchsia.hardware.serial/DeviceProxy.
1093pub struct DeviceProxy_RequestStream {
1094    inner: std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>,
1095    is_terminated: bool,
1096}
1097
1098impl std::marker::Unpin for DeviceProxy_RequestStream {}
1099
1100impl futures::stream::FusedStream for DeviceProxy_RequestStream {
1101    fn is_terminated(&self) -> bool {
1102        self.is_terminated
1103    }
1104}
1105
1106impl fidl::endpoints::RequestStream for DeviceProxy_RequestStream {
1107    type Protocol = DeviceProxy_Marker;
1108    type ControlHandle = DeviceProxy_ControlHandle;
1109
1110    fn from_channel(channel: ::fidl::AsyncChannel) -> Self {
1111        Self { inner: std::sync::Arc::new(fidl::ServeInner::new(channel)), is_terminated: false }
1112    }
1113
1114    fn control_handle(&self) -> Self::ControlHandle {
1115        DeviceProxy_ControlHandle { inner: self.inner.clone() }
1116    }
1117
1118    fn into_inner(
1119        self,
1120    ) -> (::std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>, bool)
1121    {
1122        (self.inner, self.is_terminated)
1123    }
1124
1125    fn from_inner(
1126        inner: std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>,
1127        is_terminated: bool,
1128    ) -> Self {
1129        Self { inner, is_terminated }
1130    }
1131}
1132
1133impl futures::Stream for DeviceProxy_RequestStream {
1134    type Item = Result<DeviceProxy_Request, fidl::Error>;
1135
1136    fn poll_next(
1137        mut self: std::pin::Pin<&mut Self>,
1138        cx: &mut std::task::Context<'_>,
1139    ) -> std::task::Poll<Option<Self::Item>> {
1140        let this = &mut *self;
1141        if this.inner.check_shutdown(cx) {
1142            this.is_terminated = true;
1143            return std::task::Poll::Ready(None);
1144        }
1145        if this.is_terminated {
1146            panic!("polled DeviceProxy_RequestStream after completion");
1147        }
1148        fidl::encoding::with_tls_decode_buf::<_, fidl::encoding::DefaultFuchsiaResourceDialect>(
1149            |bytes, handles| {
1150                match this.inner.channel().read_etc(cx, bytes, handles) {
1151                    std::task::Poll::Ready(Ok(())) => {}
1152                    std::task::Poll::Pending => return std::task::Poll::Pending,
1153                    std::task::Poll::Ready(Err(zx_status::Status::PEER_CLOSED)) => {
1154                        this.is_terminated = true;
1155                        return std::task::Poll::Ready(None);
1156                    }
1157                    std::task::Poll::Ready(Err(e)) => {
1158                        return std::task::Poll::Ready(Some(Err(fidl::Error::ServerRequestRead(
1159                            e.into(),
1160                        ))));
1161                    }
1162                }
1163
1164                // A message has been received from the channel
1165                let (header, _body_bytes) = fidl::encoding::decode_transaction_header(bytes)?;
1166
1167                std::task::Poll::Ready(Some(match header.ordinal {
1168                    0x580f1a3ef6c20fff => {
1169                        header.validate_request_tx_id(fidl::MethodType::OneWay)?;
1170                        let mut req = fidl::new_empty!(
1171                            DeviceProxyGetChannelRequest,
1172                            fidl::encoding::DefaultFuchsiaResourceDialect
1173                        );
1174                        fidl::encoding::Decoder::<fidl::encoding::DefaultFuchsiaResourceDialect>::decode_into::<DeviceProxyGetChannelRequest>(&header, _body_bytes, handles, &mut req)?;
1175                        let control_handle =
1176                            DeviceProxy_ControlHandle { inner: this.inner.clone() };
1177                        Ok(DeviceProxy_Request::GetChannel { req: req.req, control_handle })
1178                    }
1179                    _ => Err(fidl::Error::UnknownOrdinal {
1180                        ordinal: header.ordinal,
1181                        protocol_name:
1182                            <DeviceProxy_Marker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME,
1183                    }),
1184                }))
1185            },
1186        )
1187    }
1188}
1189
1190#[derive(Debug)]
1191pub enum DeviceProxy_Request {
1192    GetChannel {
1193        req: fidl::endpoints::ServerEnd<DeviceMarker>,
1194        control_handle: DeviceProxy_ControlHandle,
1195    },
1196}
1197
1198impl DeviceProxy_Request {
1199    #[allow(irrefutable_let_patterns)]
1200    pub fn into_get_channel(
1201        self,
1202    ) -> Option<(fidl::endpoints::ServerEnd<DeviceMarker>, DeviceProxy_ControlHandle)> {
1203        if let DeviceProxy_Request::GetChannel { req, control_handle } = self {
1204            Some((req, control_handle))
1205        } else {
1206            None
1207        }
1208    }
1209
1210    /// Name of the method defined in FIDL
1211    pub fn method_name(&self) -> &'static str {
1212        match *self {
1213            DeviceProxy_Request::GetChannel { .. } => "get_channel",
1214        }
1215    }
1216}
1217
1218#[derive(Debug, Clone)]
1219pub struct DeviceProxy_ControlHandle {
1220    inner: std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>,
1221}
1222
1223impl fidl::endpoints::ControlHandle for DeviceProxy_ControlHandle {
1224    fn shutdown(&self) {
1225        self.inner.shutdown()
1226    }
1227
1228    fn shutdown_with_epitaph(&self, status: zx_status::Status) {
1229        self.inner.shutdown_with_epitaph(status)
1230    }
1231
1232    fn is_closed(&self) -> bool {
1233        self.inner.channel().is_closed()
1234    }
1235    fn on_closed(&self) -> fidl::OnSignalsRef<'_> {
1236        self.inner.channel().on_closed()
1237    }
1238
1239    #[cfg(target_os = "fuchsia")]
1240    fn signal_peer(
1241        &self,
1242        clear_mask: zx::Signals,
1243        set_mask: zx::Signals,
1244    ) -> Result<(), zx_status::Status> {
1245        use fidl::Peered;
1246        self.inner.channel().signal_peer(clear_mask, set_mask)
1247    }
1248}
1249
1250impl DeviceProxy_ControlHandle {}
1251
1252#[derive(Debug, Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Hash)]
1253pub struct ServiceMarker;
1254
1255#[cfg(target_os = "fuchsia")]
1256impl fidl::endpoints::ServiceMarker for ServiceMarker {
1257    type Proxy = ServiceProxy;
1258    type Request = ServiceRequest;
1259    const SERVICE_NAME: &'static str = "fuchsia.hardware.serial.Service";
1260}
1261
1262/// A request for one of the member protocols of Service.
1263///
1264#[cfg(target_os = "fuchsia")]
1265pub enum ServiceRequest {
1266    Device(DeviceRequestStream),
1267}
1268
1269#[cfg(target_os = "fuchsia")]
1270impl fidl::endpoints::ServiceRequest for ServiceRequest {
1271    type Service = ServiceMarker;
1272
1273    fn dispatch(name: &str, _channel: fidl::AsyncChannel) -> Self {
1274        match name {
1275            "device" => Self::Device(
1276                <DeviceRequestStream as fidl::endpoints::RequestStream>::from_channel(_channel),
1277            ),
1278            _ => panic!("no such member protocol name for service Service"),
1279        }
1280    }
1281
1282    fn member_names() -> &'static [&'static str] {
1283        &["device"]
1284    }
1285}
1286#[cfg(target_os = "fuchsia")]
1287pub struct ServiceProxy(#[allow(dead_code)] Box<dyn fidl::endpoints::MemberOpener>);
1288
1289#[cfg(target_os = "fuchsia")]
1290impl fidl::endpoints::ServiceProxy for ServiceProxy {
1291    type Service = ServiceMarker;
1292
1293    fn from_member_opener(opener: Box<dyn fidl::endpoints::MemberOpener>) -> Self {
1294        Self(opener)
1295    }
1296}
1297
1298#[cfg(target_os = "fuchsia")]
1299impl ServiceProxy {
1300    pub fn connect_to_device(&self) -> Result<DeviceProxy, fidl::Error> {
1301        let (proxy, server_end) = fidl::endpoints::create_proxy::<DeviceMarker>();
1302        self.connect_channel_to_device(server_end)?;
1303        Ok(proxy)
1304    }
1305
1306    /// Like `connect_to_device`, but returns a sync proxy.
1307    /// See [`Self::connect_to_device`] for more details.
1308    pub fn connect_to_device_sync(&self) -> Result<DeviceSynchronousProxy, fidl::Error> {
1309        let (proxy, server_end) = fidl::endpoints::create_sync_proxy::<DeviceMarker>();
1310        self.connect_channel_to_device(server_end)?;
1311        Ok(proxy)
1312    }
1313
1314    /// Like `connect_to_device`, but accepts a server end.
1315    /// See [`Self::connect_to_device`] for more details.
1316    pub fn connect_channel_to_device(
1317        &self,
1318        server_end: fidl::endpoints::ServerEnd<DeviceMarker>,
1319    ) -> Result<(), fidl::Error> {
1320        self.0.open_member("device", server_end.into_channel())
1321    }
1322
1323    pub fn instance_name(&self) -> &str {
1324        self.0.instance_name()
1325    }
1326}
1327
1328mod internal {
1329    use super::*;
1330
1331    impl fidl::encoding::ResourceTypeMarker for DeviceProxyGetChannelRequest {
1332        type Borrowed<'a> = &'a mut Self;
1333        fn take_or_borrow<'a>(
1334            value: &'a mut <Self as fidl::encoding::TypeMarker>::Owned,
1335        ) -> Self::Borrowed<'a> {
1336            value
1337        }
1338    }
1339
1340    unsafe impl fidl::encoding::TypeMarker for DeviceProxyGetChannelRequest {
1341        type Owned = Self;
1342
1343        #[inline(always)]
1344        fn inline_align(_context: fidl::encoding::Context) -> usize {
1345            4
1346        }
1347
1348        #[inline(always)]
1349        fn inline_size(_context: fidl::encoding::Context) -> usize {
1350            4
1351        }
1352    }
1353
1354    unsafe impl
1355        fidl::encoding::Encode<
1356            DeviceProxyGetChannelRequest,
1357            fidl::encoding::DefaultFuchsiaResourceDialect,
1358        > for &mut DeviceProxyGetChannelRequest
1359    {
1360        #[inline]
1361        unsafe fn encode(
1362            self,
1363            encoder: &mut fidl::encoding::Encoder<
1364                '_,
1365                fidl::encoding::DefaultFuchsiaResourceDialect,
1366            >,
1367            offset: usize,
1368            _depth: fidl::encoding::Depth,
1369        ) -> fidl::Result<()> {
1370            encoder.debug_check_bounds::<DeviceProxyGetChannelRequest>(offset);
1371            // Delegate to tuple encoding.
1372            fidl::encoding::Encode::<DeviceProxyGetChannelRequest, fidl::encoding::DefaultFuchsiaResourceDialect>::encode(
1373                (
1374                    <fidl::encoding::Endpoint<fidl::endpoints::ServerEnd<DeviceMarker>> as fidl::encoding::ResourceTypeMarker>::take_or_borrow(&mut self.req),
1375                ),
1376                encoder, offset, _depth
1377            )
1378        }
1379    }
1380    unsafe impl<
1381        T0: fidl::encoding::Encode<
1382                fidl::encoding::Endpoint<fidl::endpoints::ServerEnd<DeviceMarker>>,
1383                fidl::encoding::DefaultFuchsiaResourceDialect,
1384            >,
1385    >
1386        fidl::encoding::Encode<
1387            DeviceProxyGetChannelRequest,
1388            fidl::encoding::DefaultFuchsiaResourceDialect,
1389        > for (T0,)
1390    {
1391        #[inline]
1392        unsafe fn encode(
1393            self,
1394            encoder: &mut fidl::encoding::Encoder<
1395                '_,
1396                fidl::encoding::DefaultFuchsiaResourceDialect,
1397            >,
1398            offset: usize,
1399            depth: fidl::encoding::Depth,
1400        ) -> fidl::Result<()> {
1401            encoder.debug_check_bounds::<DeviceProxyGetChannelRequest>(offset);
1402            // Zero out padding regions. There's no need to apply masks
1403            // because the unmasked parts will be overwritten by fields.
1404            // Write the fields.
1405            self.0.encode(encoder, offset + 0, depth)?;
1406            Ok(())
1407        }
1408    }
1409
1410    impl fidl::encoding::Decode<Self, fidl::encoding::DefaultFuchsiaResourceDialect>
1411        for DeviceProxyGetChannelRequest
1412    {
1413        #[inline(always)]
1414        fn new_empty() -> Self {
1415            Self {
1416                req: fidl::new_empty!(
1417                    fidl::encoding::Endpoint<fidl::endpoints::ServerEnd<DeviceMarker>>,
1418                    fidl::encoding::DefaultFuchsiaResourceDialect
1419                ),
1420            }
1421        }
1422
1423        #[inline]
1424        unsafe fn decode(
1425            &mut self,
1426            decoder: &mut fidl::encoding::Decoder<
1427                '_,
1428                fidl::encoding::DefaultFuchsiaResourceDialect,
1429            >,
1430            offset: usize,
1431            _depth: fidl::encoding::Depth,
1432        ) -> fidl::Result<()> {
1433            decoder.debug_check_bounds::<Self>(offset);
1434            // Verify that padding bytes are zero.
1435            fidl::decode!(
1436                fidl::encoding::Endpoint<fidl::endpoints::ServerEnd<DeviceMarker>>,
1437                fidl::encoding::DefaultFuchsiaResourceDialect,
1438                &mut self.req,
1439                decoder,
1440                offset + 0,
1441                _depth
1442            )?;
1443            Ok(())
1444        }
1445    }
1446}