fidl_fuchsia_lowpan_spinel/
fidl_fuchsia_lowpan_spinel.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_lowpan_spinel_common::*;
11use futures::future::{self, MaybeDone, TryFutureExt};
12use zx_status;
13
14#[derive(Debug, Eq, Hash, Ord, PartialEq, PartialOrd)]
15pub struct DeviceSetupSetChannelRequest {
16    pub req: fidl::endpoints::ServerEnd<DeviceMarker>,
17}
18
19impl fidl::Standalone<fidl::encoding::DefaultFuchsiaResourceDialect>
20    for DeviceSetupSetChannelRequest
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 = "fuchsia.lowpan.spinel.Device";
34}
35impl fidl::endpoints::DiscoverableProtocolMarker for DeviceMarker {}
36pub type DeviceOpenResult = Result<(), Error>;
37pub type DeviceCloseResult = Result<(), Error>;
38
39pub trait DeviceProxyInterface: Send + Sync {
40    type OpenResponseFut: std::future::Future<Output = Result<DeviceOpenResult, fidl::Error>> + Send;
41    fn r#open(&self) -> Self::OpenResponseFut;
42    type CloseResponseFut: std::future::Future<Output = Result<DeviceCloseResult, fidl::Error>>
43        + Send;
44    fn r#close(&self) -> Self::CloseResponseFut;
45    type GetMaxFrameSizeResponseFut: std::future::Future<Output = Result<u32, fidl::Error>> + Send;
46    fn r#get_max_frame_size(&self) -> Self::GetMaxFrameSizeResponseFut;
47    fn r#send_frame(&self, data: &[u8]) -> Result<(), fidl::Error>;
48    fn r#ready_to_receive_frames(&self, number_of_frames: u32) -> Result<(), fidl::Error>;
49}
50#[derive(Debug)]
51#[cfg(target_os = "fuchsia")]
52pub struct DeviceSynchronousProxy {
53    client: fidl::client::sync::Client,
54}
55
56#[cfg(target_os = "fuchsia")]
57impl fidl::endpoints::SynchronousProxy for DeviceSynchronousProxy {
58    type Proxy = DeviceProxy;
59    type Protocol = DeviceMarker;
60
61    fn from_channel(inner: fidl::Channel) -> Self {
62        Self::new(inner)
63    }
64
65    fn into_channel(self) -> fidl::Channel {
66        self.client.into_channel()
67    }
68
69    fn as_channel(&self) -> &fidl::Channel {
70        self.client.as_channel()
71    }
72}
73
74#[cfg(target_os = "fuchsia")]
75impl DeviceSynchronousProxy {
76    pub fn new(channel: fidl::Channel) -> Self {
77        let protocol_name = <DeviceMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME;
78        Self { client: fidl::client::sync::Client::new(channel, protocol_name) }
79    }
80
81    pub fn into_channel(self) -> fidl::Channel {
82        self.client.into_channel()
83    }
84
85    /// Waits until an event arrives and returns it. It is safe for other
86    /// threads to make concurrent requests while waiting for an event.
87    pub fn wait_for_event(
88        &self,
89        deadline: zx::MonotonicInstant,
90    ) -> Result<DeviceEvent, fidl::Error> {
91        DeviceEvent::decode(self.client.wait_for_event(deadline)?)
92    }
93
94    /// Opens the Spinel connection and performs initialization.
95    ///
96    /// This method will block until the Device is ready to use or
97    /// an error has been encountered. If an error is indicated,
98    /// the device is still considered closed.
99    ///
100    /// Calling this method will typically induce reset if
101    /// supported by the underlying hardware. It may be called
102    /// while the device is already open in order to trigger a
103    /// reset.
104    ///
105    /// Possible error codes:
106    ///
107    /// * `Error::IO_ERROR`: An IO error occurred.
108    /// * `Error::UNSPECIFIED`: An unspecified error occurred.
109    ///                         See logs for more details.
110    pub fn r#open(
111        &self,
112        ___deadline: zx::MonotonicInstant,
113    ) -> Result<DeviceOpenResult, fidl::Error> {
114        let _response = self.client.send_query::<
115            fidl::encoding::EmptyPayload,
116            fidl::encoding::ResultType<fidl::encoding::EmptyStruct, Error>,
117        >(
118            (),
119            0x508cecb73a776ef7,
120            fidl::encoding::DynamicFlags::empty(),
121            ___deadline,
122        )?;
123        Ok(_response.map(|x| x))
124    }
125
126    /// Close the Spinel connection.
127    ///
128    /// This method will block until the Device has successfully
129    /// been put into a closed (preferably low-power) state. An
130    /// error may be indicated if a problem was encountered that
131    /// may indicate the device did not close cleanly.
132    ///
133    /// Calling this method will always cause this interface to be
134    /// closed, even if an error is reported. Thus, the error may
135    /// be simply ignored or logged.
136    ///
137    /// Calling this method when the device is already closed
138    /// will do nothing.
139    ///
140    /// Possible error codes:
141    ///
142    /// * `Error::IO_ERROR`: An IO error occurred.
143    /// * `Error::UNSPECIFIED`: An unspecified error occurred.
144    ///                         See logs for more details.
145    pub fn r#close(
146        &self,
147        ___deadline: zx::MonotonicInstant,
148    ) -> Result<DeviceCloseResult, fidl::Error> {
149        let _response = self.client.send_query::<
150            fidl::encoding::EmptyPayload,
151            fidl::encoding::ResultType<fidl::encoding::EmptyStruct, Error>,
152        >(
153            (),
154            0x621a0f31b867781a,
155            fidl::encoding::DynamicFlags::empty(),
156            ___deadline,
157        )?;
158        Ok(_response.map(|x| x))
159    }
160
161    /// Fetch the max frame size.
162    ///
163    /// This method may be called at any time. The returned
164    /// value is an implementation-specific constant.
165    ///
166    /// @return The size of the largest frame that this implementation
167    /// supports being passed into `SendFrame()`.
168    pub fn r#get_max_frame_size(
169        &self,
170        ___deadline: zx::MonotonicInstant,
171    ) -> Result<u32, fidl::Error> {
172        let _response =
173            self.client.send_query::<fidl::encoding::EmptyPayload, DeviceGetMaxFrameSizeResponse>(
174                (),
175                0x1d2d652e8b06d463,
176                fidl::encoding::DynamicFlags::empty(),
177                ___deadline,
178            )?;
179        Ok(_response.size)
180    }
181
182    /// Sends a Spinel-formatted frame to the device.
183    ///
184    /// Calling this method while the device is closed will cause
185    /// the frame to be dropped and `->OnError()` to emit `Error::CLOSED`.
186    ///
187    /// See `->OnReadyForSendFrames()` for flow-control considerations.
188    pub fn r#send_frame(&self, mut data: &[u8]) -> Result<(), fidl::Error> {
189        self.client.send::<DeviceSendFrameRequest>(
190            (data,),
191            0x634f2957b35c5944,
192            fidl::encoding::DynamicFlags::empty(),
193        )
194    }
195
196    /// Increases the number of additional frames that the caller is
197    /// currently ready to receive, as a method of inbound flow-control.
198    ///
199    /// The caller can use this method to regulate the speed at which
200    /// inbound frames are handled. This method should be called periodically
201    /// to ensure low-latency frame delivery.
202    ///
203    /// Calling this method with a non-zero value indicates to the
204    /// receiver that the caller is ready to receive the specified
205    /// additional number of frames.
206    ///
207    /// This method SHOULD NOT be called with a value of zero. If the
208    /// receiver gets this call with a value of zero, it MUST be ignored.
209    ///
210    /// Frames will not be received until this method is first called
211    /// with a non-zero value. Once received, the receiver will limit
212    /// the number of subsequent frames emitted via `->OnReceiveFrame()`
213    /// to the given number of frames.
214    ///
215    /// Calling this method while the device is closed will do nothing.
216    ///
217    /// A reasonable usage pattern would be to first call this method
218    /// with a value of 4, calling it again with a value of 2 after
219    /// every second received inbound frame.
220    ///
221    /// Outbound flow control is similarly accomplished via `->OnReadyForSendFrames()`.
222    pub fn r#ready_to_receive_frames(&self, mut number_of_frames: u32) -> Result<(), fidl::Error> {
223        self.client.send::<DeviceReadyToReceiveFramesRequest>(
224            (number_of_frames,),
225            0x3147df23fdd53b87,
226            fidl::encoding::DynamicFlags::empty(),
227        )
228    }
229}
230
231#[cfg(target_os = "fuchsia")]
232impl From<DeviceSynchronousProxy> for zx::Handle {
233    fn from(value: DeviceSynchronousProxy) -> Self {
234        value.into_channel().into()
235    }
236}
237
238#[cfg(target_os = "fuchsia")]
239impl From<fidl::Channel> for DeviceSynchronousProxy {
240    fn from(value: fidl::Channel) -> Self {
241        Self::new(value)
242    }
243}
244
245#[derive(Debug, Clone)]
246pub struct DeviceProxy {
247    client: fidl::client::Client<fidl::encoding::DefaultFuchsiaResourceDialect>,
248}
249
250impl fidl::endpoints::Proxy for DeviceProxy {
251    type Protocol = DeviceMarker;
252
253    fn from_channel(inner: ::fidl::AsyncChannel) -> Self {
254        Self::new(inner)
255    }
256
257    fn into_channel(self) -> Result<::fidl::AsyncChannel, Self> {
258        self.client.into_channel().map_err(|client| Self { client })
259    }
260
261    fn as_channel(&self) -> &::fidl::AsyncChannel {
262        self.client.as_channel()
263    }
264}
265
266impl DeviceProxy {
267    /// Create a new Proxy for fuchsia.lowpan.spinel/Device.
268    pub fn new(channel: ::fidl::AsyncChannel) -> Self {
269        let protocol_name = <DeviceMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME;
270        Self { client: fidl::client::Client::new(channel, protocol_name) }
271    }
272
273    /// Get a Stream of events from the remote end of the protocol.
274    ///
275    /// # Panics
276    ///
277    /// Panics if the event stream was already taken.
278    pub fn take_event_stream(&self) -> DeviceEventStream {
279        DeviceEventStream { event_receiver: self.client.take_event_receiver() }
280    }
281
282    /// Opens the Spinel connection and performs initialization.
283    ///
284    /// This method will block until the Device is ready to use or
285    /// an error has been encountered. If an error is indicated,
286    /// the device is still considered closed.
287    ///
288    /// Calling this method will typically induce reset if
289    /// supported by the underlying hardware. It may be called
290    /// while the device is already open in order to trigger a
291    /// reset.
292    ///
293    /// Possible error codes:
294    ///
295    /// * `Error::IO_ERROR`: An IO error occurred.
296    /// * `Error::UNSPECIFIED`: An unspecified error occurred.
297    ///                         See logs for more details.
298    pub fn r#open(
299        &self,
300    ) -> fidl::client::QueryResponseFut<
301        DeviceOpenResult,
302        fidl::encoding::DefaultFuchsiaResourceDialect,
303    > {
304        DeviceProxyInterface::r#open(self)
305    }
306
307    /// Close the Spinel connection.
308    ///
309    /// This method will block until the Device has successfully
310    /// been put into a closed (preferably low-power) state. An
311    /// error may be indicated if a problem was encountered that
312    /// may indicate the device did not close cleanly.
313    ///
314    /// Calling this method will always cause this interface to be
315    /// closed, even if an error is reported. Thus, the error may
316    /// be simply ignored or logged.
317    ///
318    /// Calling this method when the device is already closed
319    /// will do nothing.
320    ///
321    /// Possible error codes:
322    ///
323    /// * `Error::IO_ERROR`: An IO error occurred.
324    /// * `Error::UNSPECIFIED`: An unspecified error occurred.
325    ///                         See logs for more details.
326    pub fn r#close(
327        &self,
328    ) -> fidl::client::QueryResponseFut<
329        DeviceCloseResult,
330        fidl::encoding::DefaultFuchsiaResourceDialect,
331    > {
332        DeviceProxyInterface::r#close(self)
333    }
334
335    /// Fetch the max frame size.
336    ///
337    /// This method may be called at any time. The returned
338    /// value is an implementation-specific constant.
339    ///
340    /// @return The size of the largest frame that this implementation
341    /// supports being passed into `SendFrame()`.
342    pub fn r#get_max_frame_size(
343        &self,
344    ) -> fidl::client::QueryResponseFut<u32, fidl::encoding::DefaultFuchsiaResourceDialect> {
345        DeviceProxyInterface::r#get_max_frame_size(self)
346    }
347
348    /// Sends a Spinel-formatted frame to the device.
349    ///
350    /// Calling this method while the device is closed will cause
351    /// the frame to be dropped and `->OnError()` to emit `Error::CLOSED`.
352    ///
353    /// See `->OnReadyForSendFrames()` for flow-control considerations.
354    pub fn r#send_frame(&self, mut data: &[u8]) -> Result<(), fidl::Error> {
355        DeviceProxyInterface::r#send_frame(self, data)
356    }
357
358    /// Increases the number of additional frames that the caller is
359    /// currently ready to receive, as a method of inbound flow-control.
360    ///
361    /// The caller can use this method to regulate the speed at which
362    /// inbound frames are handled. This method should be called periodically
363    /// to ensure low-latency frame delivery.
364    ///
365    /// Calling this method with a non-zero value indicates to the
366    /// receiver that the caller is ready to receive the specified
367    /// additional number of frames.
368    ///
369    /// This method SHOULD NOT be called with a value of zero. If the
370    /// receiver gets this call with a value of zero, it MUST be ignored.
371    ///
372    /// Frames will not be received until this method is first called
373    /// with a non-zero value. Once received, the receiver will limit
374    /// the number of subsequent frames emitted via `->OnReceiveFrame()`
375    /// to the given number of frames.
376    ///
377    /// Calling this method while the device is closed will do nothing.
378    ///
379    /// A reasonable usage pattern would be to first call this method
380    /// with a value of 4, calling it again with a value of 2 after
381    /// every second received inbound frame.
382    ///
383    /// Outbound flow control is similarly accomplished via `->OnReadyForSendFrames()`.
384    pub fn r#ready_to_receive_frames(&self, mut number_of_frames: u32) -> Result<(), fidl::Error> {
385        DeviceProxyInterface::r#ready_to_receive_frames(self, number_of_frames)
386    }
387}
388
389impl DeviceProxyInterface for DeviceProxy {
390    type OpenResponseFut = fidl::client::QueryResponseFut<
391        DeviceOpenResult,
392        fidl::encoding::DefaultFuchsiaResourceDialect,
393    >;
394    fn r#open(&self) -> Self::OpenResponseFut {
395        fn _decode(
396            mut _buf: Result<<fidl::encoding::DefaultFuchsiaResourceDialect as fidl::encoding::ResourceDialect>::MessageBufEtc, fidl::Error>,
397        ) -> Result<DeviceOpenResult, fidl::Error> {
398            let _response = fidl::client::decode_transaction_body::<
399                fidl::encoding::ResultType<fidl::encoding::EmptyStruct, Error>,
400                fidl::encoding::DefaultFuchsiaResourceDialect,
401                0x508cecb73a776ef7,
402            >(_buf?)?;
403            Ok(_response.map(|x| x))
404        }
405        self.client.send_query_and_decode::<fidl::encoding::EmptyPayload, DeviceOpenResult>(
406            (),
407            0x508cecb73a776ef7,
408            fidl::encoding::DynamicFlags::empty(),
409            _decode,
410        )
411    }
412
413    type CloseResponseFut = fidl::client::QueryResponseFut<
414        DeviceCloseResult,
415        fidl::encoding::DefaultFuchsiaResourceDialect,
416    >;
417    fn r#close(&self) -> Self::CloseResponseFut {
418        fn _decode(
419            mut _buf: Result<<fidl::encoding::DefaultFuchsiaResourceDialect as fidl::encoding::ResourceDialect>::MessageBufEtc, fidl::Error>,
420        ) -> Result<DeviceCloseResult, fidl::Error> {
421            let _response = fidl::client::decode_transaction_body::<
422                fidl::encoding::ResultType<fidl::encoding::EmptyStruct, Error>,
423                fidl::encoding::DefaultFuchsiaResourceDialect,
424                0x621a0f31b867781a,
425            >(_buf?)?;
426            Ok(_response.map(|x| x))
427        }
428        self.client.send_query_and_decode::<fidl::encoding::EmptyPayload, DeviceCloseResult>(
429            (),
430            0x621a0f31b867781a,
431            fidl::encoding::DynamicFlags::empty(),
432            _decode,
433        )
434    }
435
436    type GetMaxFrameSizeResponseFut =
437        fidl::client::QueryResponseFut<u32, fidl::encoding::DefaultFuchsiaResourceDialect>;
438    fn r#get_max_frame_size(&self) -> Self::GetMaxFrameSizeResponseFut {
439        fn _decode(
440            mut _buf: Result<<fidl::encoding::DefaultFuchsiaResourceDialect as fidl::encoding::ResourceDialect>::MessageBufEtc, fidl::Error>,
441        ) -> Result<u32, fidl::Error> {
442            let _response = fidl::client::decode_transaction_body::<
443                DeviceGetMaxFrameSizeResponse,
444                fidl::encoding::DefaultFuchsiaResourceDialect,
445                0x1d2d652e8b06d463,
446            >(_buf?)?;
447            Ok(_response.size)
448        }
449        self.client.send_query_and_decode::<fidl::encoding::EmptyPayload, u32>(
450            (),
451            0x1d2d652e8b06d463,
452            fidl::encoding::DynamicFlags::empty(),
453            _decode,
454        )
455    }
456
457    fn r#send_frame(&self, mut data: &[u8]) -> Result<(), fidl::Error> {
458        self.client.send::<DeviceSendFrameRequest>(
459            (data,),
460            0x634f2957b35c5944,
461            fidl::encoding::DynamicFlags::empty(),
462        )
463    }
464
465    fn r#ready_to_receive_frames(&self, mut number_of_frames: u32) -> Result<(), fidl::Error> {
466        self.client.send::<DeviceReadyToReceiveFramesRequest>(
467            (number_of_frames,),
468            0x3147df23fdd53b87,
469            fidl::encoding::DynamicFlags::empty(),
470        )
471    }
472}
473
474pub struct DeviceEventStream {
475    event_receiver: fidl::client::EventReceiver<fidl::encoding::DefaultFuchsiaResourceDialect>,
476}
477
478impl std::marker::Unpin for DeviceEventStream {}
479
480impl futures::stream::FusedStream for DeviceEventStream {
481    fn is_terminated(&self) -> bool {
482        self.event_receiver.is_terminated()
483    }
484}
485
486impl futures::Stream for DeviceEventStream {
487    type Item = Result<DeviceEvent, fidl::Error>;
488
489    fn poll_next(
490        mut self: std::pin::Pin<&mut Self>,
491        cx: &mut std::task::Context<'_>,
492    ) -> std::task::Poll<Option<Self::Item>> {
493        match futures::ready!(futures::stream::StreamExt::poll_next_unpin(
494            &mut self.event_receiver,
495            cx
496        )?) {
497            Some(buf) => std::task::Poll::Ready(Some(DeviceEvent::decode(buf))),
498            None => std::task::Poll::Ready(None),
499        }
500    }
501}
502
503#[derive(Debug)]
504pub enum DeviceEvent {
505    OnReadyForSendFrames { number_of_frames: u32 },
506    OnReceiveFrame { data: Vec<u8> },
507    OnError { error: Error, did_close: bool },
508}
509
510impl DeviceEvent {
511    #[allow(irrefutable_let_patterns)]
512    pub fn into_on_ready_for_send_frames(self) -> Option<u32> {
513        if let DeviceEvent::OnReadyForSendFrames { number_of_frames } = self {
514            Some((number_of_frames))
515        } else {
516            None
517        }
518    }
519    #[allow(irrefutable_let_patterns)]
520    pub fn into_on_receive_frame(self) -> Option<Vec<u8>> {
521        if let DeviceEvent::OnReceiveFrame { data } = self {
522            Some((data))
523        } else {
524            None
525        }
526    }
527    #[allow(irrefutable_let_patterns)]
528    pub fn into_on_error(self) -> Option<(Error, bool)> {
529        if let DeviceEvent::OnError { error, did_close } = self {
530            Some((error, did_close))
531        } else {
532            None
533        }
534    }
535
536    /// Decodes a message buffer as a [`DeviceEvent`].
537    fn decode(
538        mut buf: <fidl::encoding::DefaultFuchsiaResourceDialect as fidl::encoding::ResourceDialect>::MessageBufEtc,
539    ) -> Result<DeviceEvent, fidl::Error> {
540        let (bytes, _handles) = buf.split_mut();
541        let (tx_header, _body_bytes) = fidl::encoding::decode_transaction_header(bytes)?;
542        debug_assert_eq!(tx_header.tx_id, 0);
543        match tx_header.ordinal {
544            0x2b1d5b28c5811b53 => {
545                let mut out = fidl::new_empty!(
546                    DeviceOnReadyForSendFramesRequest,
547                    fidl::encoding::DefaultFuchsiaResourceDialect
548                );
549                fidl::encoding::Decoder::<fidl::encoding::DefaultFuchsiaResourceDialect>::decode_into::<DeviceOnReadyForSendFramesRequest>(&tx_header, _body_bytes, _handles, &mut out)?;
550                Ok((DeviceEvent::OnReadyForSendFrames { number_of_frames: out.number_of_frames }))
551            }
552            0x61937a45670aabb0 => {
553                let mut out = fidl::new_empty!(
554                    DeviceOnReceiveFrameRequest,
555                    fidl::encoding::DefaultFuchsiaResourceDialect
556                );
557                fidl::encoding::Decoder::<fidl::encoding::DefaultFuchsiaResourceDialect>::decode_into::<DeviceOnReceiveFrameRequest>(&tx_header, _body_bytes, _handles, &mut out)?;
558                Ok((DeviceEvent::OnReceiveFrame { data: out.data }))
559            }
560            0x4d20e65a9d2625e1 => {
561                let mut out = fidl::new_empty!(
562                    DeviceOnErrorRequest,
563                    fidl::encoding::DefaultFuchsiaResourceDialect
564                );
565                fidl::encoding::Decoder::<fidl::encoding::DefaultFuchsiaResourceDialect>::decode_into::<DeviceOnErrorRequest>(&tx_header, _body_bytes, _handles, &mut out)?;
566                Ok((DeviceEvent::OnError { error: out.error, did_close: out.did_close }))
567            }
568            _ => Err(fidl::Error::UnknownOrdinal {
569                ordinal: tx_header.ordinal,
570                protocol_name: <DeviceMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME,
571            }),
572        }
573    }
574}
575
576/// A Stream of incoming requests for fuchsia.lowpan.spinel/Device.
577pub struct DeviceRequestStream {
578    inner: std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>,
579    is_terminated: bool,
580}
581
582impl std::marker::Unpin for DeviceRequestStream {}
583
584impl futures::stream::FusedStream for DeviceRequestStream {
585    fn is_terminated(&self) -> bool {
586        self.is_terminated
587    }
588}
589
590impl fidl::endpoints::RequestStream for DeviceRequestStream {
591    type Protocol = DeviceMarker;
592    type ControlHandle = DeviceControlHandle;
593
594    fn from_channel(channel: ::fidl::AsyncChannel) -> Self {
595        Self { inner: std::sync::Arc::new(fidl::ServeInner::new(channel)), is_terminated: false }
596    }
597
598    fn control_handle(&self) -> Self::ControlHandle {
599        DeviceControlHandle { inner: self.inner.clone() }
600    }
601
602    fn into_inner(
603        self,
604    ) -> (::std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>, bool)
605    {
606        (self.inner, self.is_terminated)
607    }
608
609    fn from_inner(
610        inner: std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>,
611        is_terminated: bool,
612    ) -> Self {
613        Self { inner, is_terminated }
614    }
615}
616
617impl futures::Stream for DeviceRequestStream {
618    type Item = Result<DeviceRequest, fidl::Error>;
619
620    fn poll_next(
621        mut self: std::pin::Pin<&mut Self>,
622        cx: &mut std::task::Context<'_>,
623    ) -> std::task::Poll<Option<Self::Item>> {
624        let this = &mut *self;
625        if this.inner.check_shutdown(cx) {
626            this.is_terminated = true;
627            return std::task::Poll::Ready(None);
628        }
629        if this.is_terminated {
630            panic!("polled DeviceRequestStream after completion");
631        }
632        fidl::encoding::with_tls_decode_buf::<_, fidl::encoding::DefaultFuchsiaResourceDialect>(
633            |bytes, handles| {
634                match this.inner.channel().read_etc(cx, bytes, handles) {
635                    std::task::Poll::Ready(Ok(())) => {}
636                    std::task::Poll::Pending => return std::task::Poll::Pending,
637                    std::task::Poll::Ready(Err(zx_status::Status::PEER_CLOSED)) => {
638                        this.is_terminated = true;
639                        return std::task::Poll::Ready(None);
640                    }
641                    std::task::Poll::Ready(Err(e)) => {
642                        return std::task::Poll::Ready(Some(Err(fidl::Error::ServerRequestRead(
643                            e.into(),
644                        ))))
645                    }
646                }
647
648                // A message has been received from the channel
649                let (header, _body_bytes) = fidl::encoding::decode_transaction_header(bytes)?;
650
651                std::task::Poll::Ready(Some(match header.ordinal {
652                    0x508cecb73a776ef7 => {
653                        header.validate_request_tx_id(fidl::MethodType::TwoWay)?;
654                        let mut req = fidl::new_empty!(
655                            fidl::encoding::EmptyPayload,
656                            fidl::encoding::DefaultFuchsiaResourceDialect
657                        );
658                        fidl::encoding::Decoder::<fidl::encoding::DefaultFuchsiaResourceDialect>::decode_into::<fidl::encoding::EmptyPayload>(&header, _body_bytes, handles, &mut req)?;
659                        let control_handle = DeviceControlHandle { inner: this.inner.clone() };
660                        Ok(DeviceRequest::Open {
661                            responder: DeviceOpenResponder {
662                                control_handle: std::mem::ManuallyDrop::new(control_handle),
663                                tx_id: header.tx_id,
664                            },
665                        })
666                    }
667                    0x621a0f31b867781a => {
668                        header.validate_request_tx_id(fidl::MethodType::TwoWay)?;
669                        let mut req = fidl::new_empty!(
670                            fidl::encoding::EmptyPayload,
671                            fidl::encoding::DefaultFuchsiaResourceDialect
672                        );
673                        fidl::encoding::Decoder::<fidl::encoding::DefaultFuchsiaResourceDialect>::decode_into::<fidl::encoding::EmptyPayload>(&header, _body_bytes, handles, &mut req)?;
674                        let control_handle = DeviceControlHandle { inner: this.inner.clone() };
675                        Ok(DeviceRequest::Close {
676                            responder: DeviceCloseResponder {
677                                control_handle: std::mem::ManuallyDrop::new(control_handle),
678                                tx_id: header.tx_id,
679                            },
680                        })
681                    }
682                    0x1d2d652e8b06d463 => {
683                        header.validate_request_tx_id(fidl::MethodType::TwoWay)?;
684                        let mut req = fidl::new_empty!(
685                            fidl::encoding::EmptyPayload,
686                            fidl::encoding::DefaultFuchsiaResourceDialect
687                        );
688                        fidl::encoding::Decoder::<fidl::encoding::DefaultFuchsiaResourceDialect>::decode_into::<fidl::encoding::EmptyPayload>(&header, _body_bytes, handles, &mut req)?;
689                        let control_handle = DeviceControlHandle { inner: this.inner.clone() };
690                        Ok(DeviceRequest::GetMaxFrameSize {
691                            responder: DeviceGetMaxFrameSizeResponder {
692                                control_handle: std::mem::ManuallyDrop::new(control_handle),
693                                tx_id: header.tx_id,
694                            },
695                        })
696                    }
697                    0x634f2957b35c5944 => {
698                        header.validate_request_tx_id(fidl::MethodType::OneWay)?;
699                        let mut req = fidl::new_empty!(
700                            DeviceSendFrameRequest,
701                            fidl::encoding::DefaultFuchsiaResourceDialect
702                        );
703                        fidl::encoding::Decoder::<fidl::encoding::DefaultFuchsiaResourceDialect>::decode_into::<DeviceSendFrameRequest>(&header, _body_bytes, handles, &mut req)?;
704                        let control_handle = DeviceControlHandle { inner: this.inner.clone() };
705                        Ok(DeviceRequest::SendFrame { data: req.data, control_handle })
706                    }
707                    0x3147df23fdd53b87 => {
708                        header.validate_request_tx_id(fidl::MethodType::OneWay)?;
709                        let mut req = fidl::new_empty!(
710                            DeviceReadyToReceiveFramesRequest,
711                            fidl::encoding::DefaultFuchsiaResourceDialect
712                        );
713                        fidl::encoding::Decoder::<fidl::encoding::DefaultFuchsiaResourceDialect>::decode_into::<DeviceReadyToReceiveFramesRequest>(&header, _body_bytes, handles, &mut req)?;
714                        let control_handle = DeviceControlHandle { inner: this.inner.clone() };
715                        Ok(DeviceRequest::ReadyToReceiveFrames {
716                            number_of_frames: req.number_of_frames,
717
718                            control_handle,
719                        })
720                    }
721                    _ => Err(fidl::Error::UnknownOrdinal {
722                        ordinal: header.ordinal,
723                        protocol_name:
724                            <DeviceMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME,
725                    }),
726                }))
727            },
728        )
729    }
730}
731
732#[derive(Debug)]
733pub enum DeviceRequest {
734    /// Opens the Spinel connection and performs initialization.
735    ///
736    /// This method will block until the Device is ready to use or
737    /// an error has been encountered. If an error is indicated,
738    /// the device is still considered closed.
739    ///
740    /// Calling this method will typically induce reset if
741    /// supported by the underlying hardware. It may be called
742    /// while the device is already open in order to trigger a
743    /// reset.
744    ///
745    /// Possible error codes:
746    ///
747    /// * `Error::IO_ERROR`: An IO error occurred.
748    /// * `Error::UNSPECIFIED`: An unspecified error occurred.
749    ///                         See logs for more details.
750    Open { responder: DeviceOpenResponder },
751    /// Close the Spinel connection.
752    ///
753    /// This method will block until the Device has successfully
754    /// been put into a closed (preferably low-power) state. An
755    /// error may be indicated if a problem was encountered that
756    /// may indicate the device did not close cleanly.
757    ///
758    /// Calling this method will always cause this interface to be
759    /// closed, even if an error is reported. Thus, the error may
760    /// be simply ignored or logged.
761    ///
762    /// Calling this method when the device is already closed
763    /// will do nothing.
764    ///
765    /// Possible error codes:
766    ///
767    /// * `Error::IO_ERROR`: An IO error occurred.
768    /// * `Error::UNSPECIFIED`: An unspecified error occurred.
769    ///                         See logs for more details.
770    Close { responder: DeviceCloseResponder },
771    /// Fetch the max frame size.
772    ///
773    /// This method may be called at any time. The returned
774    /// value is an implementation-specific constant.
775    ///
776    /// @return The size of the largest frame that this implementation
777    /// supports being passed into `SendFrame()`.
778    GetMaxFrameSize { responder: DeviceGetMaxFrameSizeResponder },
779    /// Sends a Spinel-formatted frame to the device.
780    ///
781    /// Calling this method while the device is closed will cause
782    /// the frame to be dropped and `->OnError()` to emit `Error::CLOSED`.
783    ///
784    /// See `->OnReadyForSendFrames()` for flow-control considerations.
785    SendFrame { data: Vec<u8>, control_handle: DeviceControlHandle },
786    /// Increases the number of additional frames that the caller is
787    /// currently ready to receive, as a method of inbound flow-control.
788    ///
789    /// The caller can use this method to regulate the speed at which
790    /// inbound frames are handled. This method should be called periodically
791    /// to ensure low-latency frame delivery.
792    ///
793    /// Calling this method with a non-zero value indicates to the
794    /// receiver that the caller is ready to receive the specified
795    /// additional number of frames.
796    ///
797    /// This method SHOULD NOT be called with a value of zero. If the
798    /// receiver gets this call with a value of zero, it MUST be ignored.
799    ///
800    /// Frames will not be received until this method is first called
801    /// with a non-zero value. Once received, the receiver will limit
802    /// the number of subsequent frames emitted via `->OnReceiveFrame()`
803    /// to the given number of frames.
804    ///
805    /// Calling this method while the device is closed will do nothing.
806    ///
807    /// A reasonable usage pattern would be to first call this method
808    /// with a value of 4, calling it again with a value of 2 after
809    /// every second received inbound frame.
810    ///
811    /// Outbound flow control is similarly accomplished via `->OnReadyForSendFrames()`.
812    ReadyToReceiveFrames { number_of_frames: u32, control_handle: DeviceControlHandle },
813}
814
815impl DeviceRequest {
816    #[allow(irrefutable_let_patterns)]
817    pub fn into_open(self) -> Option<(DeviceOpenResponder)> {
818        if let DeviceRequest::Open { responder } = self {
819            Some((responder))
820        } else {
821            None
822        }
823    }
824
825    #[allow(irrefutable_let_patterns)]
826    pub fn into_close(self) -> Option<(DeviceCloseResponder)> {
827        if let DeviceRequest::Close { responder } = self {
828            Some((responder))
829        } else {
830            None
831        }
832    }
833
834    #[allow(irrefutable_let_patterns)]
835    pub fn into_get_max_frame_size(self) -> Option<(DeviceGetMaxFrameSizeResponder)> {
836        if let DeviceRequest::GetMaxFrameSize { responder } = self {
837            Some((responder))
838        } else {
839            None
840        }
841    }
842
843    #[allow(irrefutable_let_patterns)]
844    pub fn into_send_frame(self) -> Option<(Vec<u8>, DeviceControlHandle)> {
845        if let DeviceRequest::SendFrame { data, control_handle } = self {
846            Some((data, control_handle))
847        } else {
848            None
849        }
850    }
851
852    #[allow(irrefutable_let_patterns)]
853    pub fn into_ready_to_receive_frames(self) -> Option<(u32, DeviceControlHandle)> {
854        if let DeviceRequest::ReadyToReceiveFrames { number_of_frames, control_handle } = self {
855            Some((number_of_frames, control_handle))
856        } else {
857            None
858        }
859    }
860
861    /// Name of the method defined in FIDL
862    pub fn method_name(&self) -> &'static str {
863        match *self {
864            DeviceRequest::Open { .. } => "open",
865            DeviceRequest::Close { .. } => "close",
866            DeviceRequest::GetMaxFrameSize { .. } => "get_max_frame_size",
867            DeviceRequest::SendFrame { .. } => "send_frame",
868            DeviceRequest::ReadyToReceiveFrames { .. } => "ready_to_receive_frames",
869        }
870    }
871}
872
873#[derive(Debug, Clone)]
874pub struct DeviceControlHandle {
875    inner: std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>,
876}
877
878impl fidl::endpoints::ControlHandle for DeviceControlHandle {
879    fn shutdown(&self) {
880        self.inner.shutdown()
881    }
882    fn shutdown_with_epitaph(&self, status: zx_status::Status) {
883        self.inner.shutdown_with_epitaph(status)
884    }
885
886    fn is_closed(&self) -> bool {
887        self.inner.channel().is_closed()
888    }
889    fn on_closed(&self) -> fidl::OnSignalsRef<'_> {
890        self.inner.channel().on_closed()
891    }
892
893    #[cfg(target_os = "fuchsia")]
894    fn signal_peer(
895        &self,
896        clear_mask: zx::Signals,
897        set_mask: zx::Signals,
898    ) -> Result<(), zx_status::Status> {
899        use fidl::Peered;
900        self.inner.channel().signal_peer(clear_mask, set_mask)
901    }
902}
903
904impl DeviceControlHandle {
905    pub fn send_on_ready_for_send_frames(
906        &self,
907        mut number_of_frames: u32,
908    ) -> Result<(), fidl::Error> {
909        self.inner.send::<DeviceOnReadyForSendFramesRequest>(
910            (number_of_frames,),
911            0,
912            0x2b1d5b28c5811b53,
913            fidl::encoding::DynamicFlags::empty(),
914        )
915    }
916
917    pub fn send_on_receive_frame(&self, mut data: &[u8]) -> Result<(), fidl::Error> {
918        self.inner.send::<DeviceOnReceiveFrameRequest>(
919            (data,),
920            0,
921            0x61937a45670aabb0,
922            fidl::encoding::DynamicFlags::empty(),
923        )
924    }
925
926    pub fn send_on_error(&self, mut error: Error, mut did_close: bool) -> Result<(), fidl::Error> {
927        self.inner.send::<DeviceOnErrorRequest>(
928            (error, did_close),
929            0,
930            0x4d20e65a9d2625e1,
931            fidl::encoding::DynamicFlags::empty(),
932        )
933    }
934}
935
936#[must_use = "FIDL methods require a response to be sent"]
937#[derive(Debug)]
938pub struct DeviceOpenResponder {
939    control_handle: std::mem::ManuallyDrop<DeviceControlHandle>,
940    tx_id: u32,
941}
942
943/// Set the the channel to be shutdown (see [`DeviceControlHandle::shutdown`])
944/// if the responder is dropped without sending a response, so that the client
945/// doesn't hang. To prevent this behavior, call `drop_without_shutdown`.
946impl std::ops::Drop for DeviceOpenResponder {
947    fn drop(&mut self) {
948        self.control_handle.shutdown();
949        // Safety: drops once, never accessed again
950        unsafe { std::mem::ManuallyDrop::drop(&mut self.control_handle) };
951    }
952}
953
954impl fidl::endpoints::Responder for DeviceOpenResponder {
955    type ControlHandle = DeviceControlHandle;
956
957    fn control_handle(&self) -> &DeviceControlHandle {
958        &self.control_handle
959    }
960
961    fn drop_without_shutdown(mut self) {
962        // Safety: drops once, never accessed again due to mem::forget
963        unsafe { std::mem::ManuallyDrop::drop(&mut self.control_handle) };
964        // Prevent Drop from running (which would shut down the channel)
965        std::mem::forget(self);
966    }
967}
968
969impl DeviceOpenResponder {
970    /// Sends a response to the FIDL transaction.
971    ///
972    /// Sets the channel to shutdown if an error occurs.
973    pub fn send(self, mut result: Result<(), Error>) -> Result<(), fidl::Error> {
974        let _result = self.send_raw(result);
975        if _result.is_err() {
976            self.control_handle.shutdown();
977        }
978        self.drop_without_shutdown();
979        _result
980    }
981
982    /// Similar to "send" but does not shutdown the channel if an error occurs.
983    pub fn send_no_shutdown_on_err(self, mut result: Result<(), Error>) -> Result<(), fidl::Error> {
984        let _result = self.send_raw(result);
985        self.drop_without_shutdown();
986        _result
987    }
988
989    fn send_raw(&self, mut result: Result<(), Error>) -> Result<(), fidl::Error> {
990        self.control_handle
991            .inner
992            .send::<fidl::encoding::ResultType<fidl::encoding::EmptyStruct, Error>>(
993                result,
994                self.tx_id,
995                0x508cecb73a776ef7,
996                fidl::encoding::DynamicFlags::empty(),
997            )
998    }
999}
1000
1001#[must_use = "FIDL methods require a response to be sent"]
1002#[derive(Debug)]
1003pub struct DeviceCloseResponder {
1004    control_handle: std::mem::ManuallyDrop<DeviceControlHandle>,
1005    tx_id: u32,
1006}
1007
1008/// Set the the channel to be shutdown (see [`DeviceControlHandle::shutdown`])
1009/// if the responder is dropped without sending a response, so that the client
1010/// doesn't hang. To prevent this behavior, call `drop_without_shutdown`.
1011impl std::ops::Drop for DeviceCloseResponder {
1012    fn drop(&mut self) {
1013        self.control_handle.shutdown();
1014        // Safety: drops once, never accessed again
1015        unsafe { std::mem::ManuallyDrop::drop(&mut self.control_handle) };
1016    }
1017}
1018
1019impl fidl::endpoints::Responder for DeviceCloseResponder {
1020    type ControlHandle = DeviceControlHandle;
1021
1022    fn control_handle(&self) -> &DeviceControlHandle {
1023        &self.control_handle
1024    }
1025
1026    fn drop_without_shutdown(mut self) {
1027        // Safety: drops once, never accessed again due to mem::forget
1028        unsafe { std::mem::ManuallyDrop::drop(&mut self.control_handle) };
1029        // Prevent Drop from running (which would shut down the channel)
1030        std::mem::forget(self);
1031    }
1032}
1033
1034impl DeviceCloseResponder {
1035    /// Sends a response to the FIDL transaction.
1036    ///
1037    /// Sets the channel to shutdown if an error occurs.
1038    pub fn send(self, mut result: Result<(), Error>) -> Result<(), fidl::Error> {
1039        let _result = self.send_raw(result);
1040        if _result.is_err() {
1041            self.control_handle.shutdown();
1042        }
1043        self.drop_without_shutdown();
1044        _result
1045    }
1046
1047    /// Similar to "send" but does not shutdown the channel if an error occurs.
1048    pub fn send_no_shutdown_on_err(self, mut result: Result<(), Error>) -> Result<(), fidl::Error> {
1049        let _result = self.send_raw(result);
1050        self.drop_without_shutdown();
1051        _result
1052    }
1053
1054    fn send_raw(&self, mut result: Result<(), Error>) -> Result<(), fidl::Error> {
1055        self.control_handle
1056            .inner
1057            .send::<fidl::encoding::ResultType<fidl::encoding::EmptyStruct, Error>>(
1058                result,
1059                self.tx_id,
1060                0x621a0f31b867781a,
1061                fidl::encoding::DynamicFlags::empty(),
1062            )
1063    }
1064}
1065
1066#[must_use = "FIDL methods require a response to be sent"]
1067#[derive(Debug)]
1068pub struct DeviceGetMaxFrameSizeResponder {
1069    control_handle: std::mem::ManuallyDrop<DeviceControlHandle>,
1070    tx_id: u32,
1071}
1072
1073/// Set the the channel to be shutdown (see [`DeviceControlHandle::shutdown`])
1074/// if the responder is dropped without sending a response, so that the client
1075/// doesn't hang. To prevent this behavior, call `drop_without_shutdown`.
1076impl std::ops::Drop for DeviceGetMaxFrameSizeResponder {
1077    fn drop(&mut self) {
1078        self.control_handle.shutdown();
1079        // Safety: drops once, never accessed again
1080        unsafe { std::mem::ManuallyDrop::drop(&mut self.control_handle) };
1081    }
1082}
1083
1084impl fidl::endpoints::Responder for DeviceGetMaxFrameSizeResponder {
1085    type ControlHandle = DeviceControlHandle;
1086
1087    fn control_handle(&self) -> &DeviceControlHandle {
1088        &self.control_handle
1089    }
1090
1091    fn drop_without_shutdown(mut self) {
1092        // Safety: drops once, never accessed again due to mem::forget
1093        unsafe { std::mem::ManuallyDrop::drop(&mut self.control_handle) };
1094        // Prevent Drop from running (which would shut down the channel)
1095        std::mem::forget(self);
1096    }
1097}
1098
1099impl DeviceGetMaxFrameSizeResponder {
1100    /// Sends a response to the FIDL transaction.
1101    ///
1102    /// Sets the channel to shutdown if an error occurs.
1103    pub fn send(self, mut size: u32) -> Result<(), fidl::Error> {
1104        let _result = self.send_raw(size);
1105        if _result.is_err() {
1106            self.control_handle.shutdown();
1107        }
1108        self.drop_without_shutdown();
1109        _result
1110    }
1111
1112    /// Similar to "send" but does not shutdown the channel if an error occurs.
1113    pub fn send_no_shutdown_on_err(self, mut size: u32) -> Result<(), fidl::Error> {
1114        let _result = self.send_raw(size);
1115        self.drop_without_shutdown();
1116        _result
1117    }
1118
1119    fn send_raw(&self, mut size: u32) -> Result<(), fidl::Error> {
1120        self.control_handle.inner.send::<DeviceGetMaxFrameSizeResponse>(
1121            (size,),
1122            self.tx_id,
1123            0x1d2d652e8b06d463,
1124            fidl::encoding::DynamicFlags::empty(),
1125        )
1126    }
1127}
1128
1129#[derive(Debug, Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Hash)]
1130pub struct DeviceSetupMarker;
1131
1132impl fidl::endpoints::ProtocolMarker for DeviceSetupMarker {
1133    type Proxy = DeviceSetupProxy;
1134    type RequestStream = DeviceSetupRequestStream;
1135    #[cfg(target_os = "fuchsia")]
1136    type SynchronousProxy = DeviceSetupSynchronousProxy;
1137
1138    const DEBUG_NAME: &'static str = "(anonymous) DeviceSetup";
1139}
1140pub type DeviceSetupSetChannelResult = Result<(), i32>;
1141
1142pub trait DeviceSetupProxyInterface: Send + Sync {
1143    type SetChannelResponseFut: std::future::Future<Output = Result<DeviceSetupSetChannelResult, fidl::Error>>
1144        + Send;
1145    fn r#set_channel(
1146        &self,
1147        req: fidl::endpoints::ServerEnd<DeviceMarker>,
1148    ) -> Self::SetChannelResponseFut;
1149}
1150#[derive(Debug)]
1151#[cfg(target_os = "fuchsia")]
1152pub struct DeviceSetupSynchronousProxy {
1153    client: fidl::client::sync::Client,
1154}
1155
1156#[cfg(target_os = "fuchsia")]
1157impl fidl::endpoints::SynchronousProxy for DeviceSetupSynchronousProxy {
1158    type Proxy = DeviceSetupProxy;
1159    type Protocol = DeviceSetupMarker;
1160
1161    fn from_channel(inner: fidl::Channel) -> Self {
1162        Self::new(inner)
1163    }
1164
1165    fn into_channel(self) -> fidl::Channel {
1166        self.client.into_channel()
1167    }
1168
1169    fn as_channel(&self) -> &fidl::Channel {
1170        self.client.as_channel()
1171    }
1172}
1173
1174#[cfg(target_os = "fuchsia")]
1175impl DeviceSetupSynchronousProxy {
1176    pub fn new(channel: fidl::Channel) -> Self {
1177        let protocol_name = <DeviceSetupMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME;
1178        Self { client: fidl::client::sync::Client::new(channel, protocol_name) }
1179    }
1180
1181    pub fn into_channel(self) -> fidl::Channel {
1182        self.client.into_channel()
1183    }
1184
1185    /// Waits until an event arrives and returns it. It is safe for other
1186    /// threads to make concurrent requests while waiting for an event.
1187    pub fn wait_for_event(
1188        &self,
1189        deadline: zx::MonotonicInstant,
1190    ) -> Result<DeviceSetupEvent, fidl::Error> {
1191        DeviceSetupEvent::decode(self.client.wait_for_event(deadline)?)
1192    }
1193
1194    pub fn r#set_channel(
1195        &self,
1196        mut req: fidl::endpoints::ServerEnd<DeviceMarker>,
1197        ___deadline: zx::MonotonicInstant,
1198    ) -> Result<DeviceSetupSetChannelResult, fidl::Error> {
1199        let _response = self.client.send_query::<
1200            DeviceSetupSetChannelRequest,
1201            fidl::encoding::ResultType<fidl::encoding::EmptyStruct, i32>,
1202        >(
1203            (req,),
1204            0x7f8e02c174ef02a5,
1205            fidl::encoding::DynamicFlags::empty(),
1206            ___deadline,
1207        )?;
1208        Ok(_response.map(|x| x))
1209    }
1210}
1211
1212#[cfg(target_os = "fuchsia")]
1213impl From<DeviceSetupSynchronousProxy> for zx::Handle {
1214    fn from(value: DeviceSetupSynchronousProxy) -> Self {
1215        value.into_channel().into()
1216    }
1217}
1218
1219#[cfg(target_os = "fuchsia")]
1220impl From<fidl::Channel> for DeviceSetupSynchronousProxy {
1221    fn from(value: fidl::Channel) -> Self {
1222        Self::new(value)
1223    }
1224}
1225
1226#[derive(Debug, Clone)]
1227pub struct DeviceSetupProxy {
1228    client: fidl::client::Client<fidl::encoding::DefaultFuchsiaResourceDialect>,
1229}
1230
1231impl fidl::endpoints::Proxy for DeviceSetupProxy {
1232    type Protocol = DeviceSetupMarker;
1233
1234    fn from_channel(inner: ::fidl::AsyncChannel) -> Self {
1235        Self::new(inner)
1236    }
1237
1238    fn into_channel(self) -> Result<::fidl::AsyncChannel, Self> {
1239        self.client.into_channel().map_err(|client| Self { client })
1240    }
1241
1242    fn as_channel(&self) -> &::fidl::AsyncChannel {
1243        self.client.as_channel()
1244    }
1245}
1246
1247impl DeviceSetupProxy {
1248    /// Create a new Proxy for fuchsia.lowpan.spinel/DeviceSetup.
1249    pub fn new(channel: ::fidl::AsyncChannel) -> Self {
1250        let protocol_name = <DeviceSetupMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME;
1251        Self { client: fidl::client::Client::new(channel, protocol_name) }
1252    }
1253
1254    /// Get a Stream of events from the remote end of the protocol.
1255    ///
1256    /// # Panics
1257    ///
1258    /// Panics if the event stream was already taken.
1259    pub fn take_event_stream(&self) -> DeviceSetupEventStream {
1260        DeviceSetupEventStream { event_receiver: self.client.take_event_receiver() }
1261    }
1262
1263    pub fn r#set_channel(
1264        &self,
1265        mut req: fidl::endpoints::ServerEnd<DeviceMarker>,
1266    ) -> fidl::client::QueryResponseFut<
1267        DeviceSetupSetChannelResult,
1268        fidl::encoding::DefaultFuchsiaResourceDialect,
1269    > {
1270        DeviceSetupProxyInterface::r#set_channel(self, req)
1271    }
1272}
1273
1274impl DeviceSetupProxyInterface for DeviceSetupProxy {
1275    type SetChannelResponseFut = fidl::client::QueryResponseFut<
1276        DeviceSetupSetChannelResult,
1277        fidl::encoding::DefaultFuchsiaResourceDialect,
1278    >;
1279    fn r#set_channel(
1280        &self,
1281        mut req: fidl::endpoints::ServerEnd<DeviceMarker>,
1282    ) -> Self::SetChannelResponseFut {
1283        fn _decode(
1284            mut _buf: Result<<fidl::encoding::DefaultFuchsiaResourceDialect as fidl::encoding::ResourceDialect>::MessageBufEtc, fidl::Error>,
1285        ) -> Result<DeviceSetupSetChannelResult, fidl::Error> {
1286            let _response = fidl::client::decode_transaction_body::<
1287                fidl::encoding::ResultType<fidl::encoding::EmptyStruct, i32>,
1288                fidl::encoding::DefaultFuchsiaResourceDialect,
1289                0x7f8e02c174ef02a5,
1290            >(_buf?)?;
1291            Ok(_response.map(|x| x))
1292        }
1293        self.client
1294            .send_query_and_decode::<DeviceSetupSetChannelRequest, DeviceSetupSetChannelResult>(
1295                (req,),
1296                0x7f8e02c174ef02a5,
1297                fidl::encoding::DynamicFlags::empty(),
1298                _decode,
1299            )
1300    }
1301}
1302
1303pub struct DeviceSetupEventStream {
1304    event_receiver: fidl::client::EventReceiver<fidl::encoding::DefaultFuchsiaResourceDialect>,
1305}
1306
1307impl std::marker::Unpin for DeviceSetupEventStream {}
1308
1309impl futures::stream::FusedStream for DeviceSetupEventStream {
1310    fn is_terminated(&self) -> bool {
1311        self.event_receiver.is_terminated()
1312    }
1313}
1314
1315impl futures::Stream for DeviceSetupEventStream {
1316    type Item = Result<DeviceSetupEvent, fidl::Error>;
1317
1318    fn poll_next(
1319        mut self: std::pin::Pin<&mut Self>,
1320        cx: &mut std::task::Context<'_>,
1321    ) -> std::task::Poll<Option<Self::Item>> {
1322        match futures::ready!(futures::stream::StreamExt::poll_next_unpin(
1323            &mut self.event_receiver,
1324            cx
1325        )?) {
1326            Some(buf) => std::task::Poll::Ready(Some(DeviceSetupEvent::decode(buf))),
1327            None => std::task::Poll::Ready(None),
1328        }
1329    }
1330}
1331
1332#[derive(Debug)]
1333pub enum DeviceSetupEvent {}
1334
1335impl DeviceSetupEvent {
1336    /// Decodes a message buffer as a [`DeviceSetupEvent`].
1337    fn decode(
1338        mut buf: <fidl::encoding::DefaultFuchsiaResourceDialect as fidl::encoding::ResourceDialect>::MessageBufEtc,
1339    ) -> Result<DeviceSetupEvent, fidl::Error> {
1340        let (bytes, _handles) = buf.split_mut();
1341        let (tx_header, _body_bytes) = fidl::encoding::decode_transaction_header(bytes)?;
1342        debug_assert_eq!(tx_header.tx_id, 0);
1343        match tx_header.ordinal {
1344            _ => Err(fidl::Error::UnknownOrdinal {
1345                ordinal: tx_header.ordinal,
1346                protocol_name: <DeviceSetupMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME,
1347            }),
1348        }
1349    }
1350}
1351
1352/// A Stream of incoming requests for fuchsia.lowpan.spinel/DeviceSetup.
1353pub struct DeviceSetupRequestStream {
1354    inner: std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>,
1355    is_terminated: bool,
1356}
1357
1358impl std::marker::Unpin for DeviceSetupRequestStream {}
1359
1360impl futures::stream::FusedStream for DeviceSetupRequestStream {
1361    fn is_terminated(&self) -> bool {
1362        self.is_terminated
1363    }
1364}
1365
1366impl fidl::endpoints::RequestStream for DeviceSetupRequestStream {
1367    type Protocol = DeviceSetupMarker;
1368    type ControlHandle = DeviceSetupControlHandle;
1369
1370    fn from_channel(channel: ::fidl::AsyncChannel) -> Self {
1371        Self { inner: std::sync::Arc::new(fidl::ServeInner::new(channel)), is_terminated: false }
1372    }
1373
1374    fn control_handle(&self) -> Self::ControlHandle {
1375        DeviceSetupControlHandle { inner: self.inner.clone() }
1376    }
1377
1378    fn into_inner(
1379        self,
1380    ) -> (::std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>, bool)
1381    {
1382        (self.inner, self.is_terminated)
1383    }
1384
1385    fn from_inner(
1386        inner: std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>,
1387        is_terminated: bool,
1388    ) -> Self {
1389        Self { inner, is_terminated }
1390    }
1391}
1392
1393impl futures::Stream for DeviceSetupRequestStream {
1394    type Item = Result<DeviceSetupRequest, fidl::Error>;
1395
1396    fn poll_next(
1397        mut self: std::pin::Pin<&mut Self>,
1398        cx: &mut std::task::Context<'_>,
1399    ) -> std::task::Poll<Option<Self::Item>> {
1400        let this = &mut *self;
1401        if this.inner.check_shutdown(cx) {
1402            this.is_terminated = true;
1403            return std::task::Poll::Ready(None);
1404        }
1405        if this.is_terminated {
1406            panic!("polled DeviceSetupRequestStream after completion");
1407        }
1408        fidl::encoding::with_tls_decode_buf::<_, fidl::encoding::DefaultFuchsiaResourceDialect>(
1409            |bytes, handles| {
1410                match this.inner.channel().read_etc(cx, bytes, handles) {
1411                    std::task::Poll::Ready(Ok(())) => {}
1412                    std::task::Poll::Pending => return std::task::Poll::Pending,
1413                    std::task::Poll::Ready(Err(zx_status::Status::PEER_CLOSED)) => {
1414                        this.is_terminated = true;
1415                        return std::task::Poll::Ready(None);
1416                    }
1417                    std::task::Poll::Ready(Err(e)) => {
1418                        return std::task::Poll::Ready(Some(Err(fidl::Error::ServerRequestRead(
1419                            e.into(),
1420                        ))))
1421                    }
1422                }
1423
1424                // A message has been received from the channel
1425                let (header, _body_bytes) = fidl::encoding::decode_transaction_header(bytes)?;
1426
1427                std::task::Poll::Ready(Some(match header.ordinal {
1428                    0x7f8e02c174ef02a5 => {
1429                        header.validate_request_tx_id(fidl::MethodType::TwoWay)?;
1430                        let mut req = fidl::new_empty!(
1431                            DeviceSetupSetChannelRequest,
1432                            fidl::encoding::DefaultFuchsiaResourceDialect
1433                        );
1434                        fidl::encoding::Decoder::<fidl::encoding::DefaultFuchsiaResourceDialect>::decode_into::<DeviceSetupSetChannelRequest>(&header, _body_bytes, handles, &mut req)?;
1435                        let control_handle = DeviceSetupControlHandle { inner: this.inner.clone() };
1436                        Ok(DeviceSetupRequest::SetChannel {
1437                            req: req.req,
1438
1439                            responder: DeviceSetupSetChannelResponder {
1440                                control_handle: std::mem::ManuallyDrop::new(control_handle),
1441                                tx_id: header.tx_id,
1442                            },
1443                        })
1444                    }
1445                    _ => Err(fidl::Error::UnknownOrdinal {
1446                        ordinal: header.ordinal,
1447                        protocol_name:
1448                            <DeviceSetupMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME,
1449                    }),
1450                }))
1451            },
1452        )
1453    }
1454}
1455
1456#[derive(Debug)]
1457pub enum DeviceSetupRequest {
1458    SetChannel {
1459        req: fidl::endpoints::ServerEnd<DeviceMarker>,
1460        responder: DeviceSetupSetChannelResponder,
1461    },
1462}
1463
1464impl DeviceSetupRequest {
1465    #[allow(irrefutable_let_patterns)]
1466    pub fn into_set_channel(
1467        self,
1468    ) -> Option<(fidl::endpoints::ServerEnd<DeviceMarker>, DeviceSetupSetChannelResponder)> {
1469        if let DeviceSetupRequest::SetChannel { req, responder } = self {
1470            Some((req, responder))
1471        } else {
1472            None
1473        }
1474    }
1475
1476    /// Name of the method defined in FIDL
1477    pub fn method_name(&self) -> &'static str {
1478        match *self {
1479            DeviceSetupRequest::SetChannel { .. } => "set_channel",
1480        }
1481    }
1482}
1483
1484#[derive(Debug, Clone)]
1485pub struct DeviceSetupControlHandle {
1486    inner: std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>,
1487}
1488
1489impl fidl::endpoints::ControlHandle for DeviceSetupControlHandle {
1490    fn shutdown(&self) {
1491        self.inner.shutdown()
1492    }
1493    fn shutdown_with_epitaph(&self, status: zx_status::Status) {
1494        self.inner.shutdown_with_epitaph(status)
1495    }
1496
1497    fn is_closed(&self) -> bool {
1498        self.inner.channel().is_closed()
1499    }
1500    fn on_closed(&self) -> fidl::OnSignalsRef<'_> {
1501        self.inner.channel().on_closed()
1502    }
1503
1504    #[cfg(target_os = "fuchsia")]
1505    fn signal_peer(
1506        &self,
1507        clear_mask: zx::Signals,
1508        set_mask: zx::Signals,
1509    ) -> Result<(), zx_status::Status> {
1510        use fidl::Peered;
1511        self.inner.channel().signal_peer(clear_mask, set_mask)
1512    }
1513}
1514
1515impl DeviceSetupControlHandle {}
1516
1517#[must_use = "FIDL methods require a response to be sent"]
1518#[derive(Debug)]
1519pub struct DeviceSetupSetChannelResponder {
1520    control_handle: std::mem::ManuallyDrop<DeviceSetupControlHandle>,
1521    tx_id: u32,
1522}
1523
1524/// Set the the channel to be shutdown (see [`DeviceSetupControlHandle::shutdown`])
1525/// if the responder is dropped without sending a response, so that the client
1526/// doesn't hang. To prevent this behavior, call `drop_without_shutdown`.
1527impl std::ops::Drop for DeviceSetupSetChannelResponder {
1528    fn drop(&mut self) {
1529        self.control_handle.shutdown();
1530        // Safety: drops once, never accessed again
1531        unsafe { std::mem::ManuallyDrop::drop(&mut self.control_handle) };
1532    }
1533}
1534
1535impl fidl::endpoints::Responder for DeviceSetupSetChannelResponder {
1536    type ControlHandle = DeviceSetupControlHandle;
1537
1538    fn control_handle(&self) -> &DeviceSetupControlHandle {
1539        &self.control_handle
1540    }
1541
1542    fn drop_without_shutdown(mut self) {
1543        // Safety: drops once, never accessed again due to mem::forget
1544        unsafe { std::mem::ManuallyDrop::drop(&mut self.control_handle) };
1545        // Prevent Drop from running (which would shut down the channel)
1546        std::mem::forget(self);
1547    }
1548}
1549
1550impl DeviceSetupSetChannelResponder {
1551    /// Sends a response to the FIDL transaction.
1552    ///
1553    /// Sets the channel to shutdown if an error occurs.
1554    pub fn send(self, mut result: Result<(), i32>) -> Result<(), fidl::Error> {
1555        let _result = self.send_raw(result);
1556        if _result.is_err() {
1557            self.control_handle.shutdown();
1558        }
1559        self.drop_without_shutdown();
1560        _result
1561    }
1562
1563    /// Similar to "send" but does not shutdown the channel if an error occurs.
1564    pub fn send_no_shutdown_on_err(self, mut result: Result<(), i32>) -> Result<(), fidl::Error> {
1565        let _result = self.send_raw(result);
1566        self.drop_without_shutdown();
1567        _result
1568    }
1569
1570    fn send_raw(&self, mut result: Result<(), i32>) -> Result<(), fidl::Error> {
1571        self.control_handle
1572            .inner
1573            .send::<fidl::encoding::ResultType<fidl::encoding::EmptyStruct, i32>>(
1574                result,
1575                self.tx_id,
1576                0x7f8e02c174ef02a5,
1577                fidl::encoding::DynamicFlags::empty(),
1578            )
1579    }
1580}
1581
1582#[derive(Debug, Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Hash)]
1583pub struct ServiceMarker;
1584
1585#[cfg(target_os = "fuchsia")]
1586impl fidl::endpoints::ServiceMarker for ServiceMarker {
1587    type Proxy = ServiceProxy;
1588    type Request = ServiceRequest;
1589    const SERVICE_NAME: &'static str = "fuchsia.lowpan.spinel.Service";
1590}
1591
1592/// A request for one of the member protocols of Service.
1593///
1594#[cfg(target_os = "fuchsia")]
1595pub enum ServiceRequest {
1596    DeviceSetup(DeviceSetupRequestStream),
1597}
1598
1599#[cfg(target_os = "fuchsia")]
1600impl fidl::endpoints::ServiceRequest for ServiceRequest {
1601    type Service = ServiceMarker;
1602
1603    fn dispatch(name: &str, _channel: fidl::AsyncChannel) -> Self {
1604        match name {
1605            "device_setup" => Self::DeviceSetup(
1606                <DeviceSetupRequestStream as fidl::endpoints::RequestStream>::from_channel(
1607                    _channel,
1608                ),
1609            ),
1610            _ => panic!("no such member protocol name for service Service"),
1611        }
1612    }
1613
1614    fn member_names() -> &'static [&'static str] {
1615        &["device_setup"]
1616    }
1617}
1618#[cfg(target_os = "fuchsia")]
1619pub struct ServiceProxy(#[allow(dead_code)] Box<dyn fidl::endpoints::MemberOpener>);
1620
1621#[cfg(target_os = "fuchsia")]
1622impl fidl::endpoints::ServiceProxy for ServiceProxy {
1623    type Service = ServiceMarker;
1624
1625    fn from_member_opener(opener: Box<dyn fidl::endpoints::MemberOpener>) -> Self {
1626        Self(opener)
1627    }
1628}
1629
1630#[cfg(target_os = "fuchsia")]
1631impl ServiceProxy {
1632    pub fn connect_to_device_setup(&self) -> Result<DeviceSetupProxy, fidl::Error> {
1633        let (proxy, server_end) = fidl::endpoints::create_proxy::<DeviceSetupMarker>();
1634        self.connect_channel_to_device_setup(server_end)?;
1635        Ok(proxy)
1636    }
1637
1638    /// Like `connect_to_device_setup`, but returns a sync proxy.
1639    /// See [`Self::connect_to_device_setup`] for more details.
1640    pub fn connect_to_device_setup_sync(&self) -> Result<DeviceSetupSynchronousProxy, fidl::Error> {
1641        let (proxy, server_end) = fidl::endpoints::create_sync_proxy::<DeviceSetupMarker>();
1642        self.connect_channel_to_device_setup(server_end)?;
1643        Ok(proxy)
1644    }
1645
1646    /// Like `connect_to_device_setup`, but accepts a server end.
1647    /// See [`Self::connect_to_device_setup`] for more details.
1648    pub fn connect_channel_to_device_setup(
1649        &self,
1650        server_end: fidl::endpoints::ServerEnd<DeviceSetupMarker>,
1651    ) -> Result<(), fidl::Error> {
1652        self.0.open_member("device_setup", server_end.into_channel())
1653    }
1654
1655    pub fn instance_name(&self) -> &str {
1656        self.0.instance_name()
1657    }
1658}
1659
1660mod internal {
1661    use super::*;
1662
1663    impl fidl::encoding::ResourceTypeMarker for DeviceSetupSetChannelRequest {
1664        type Borrowed<'a> = &'a mut Self;
1665        fn take_or_borrow<'a>(
1666            value: &'a mut <Self as fidl::encoding::TypeMarker>::Owned,
1667        ) -> Self::Borrowed<'a> {
1668            value
1669        }
1670    }
1671
1672    unsafe impl fidl::encoding::TypeMarker for DeviceSetupSetChannelRequest {
1673        type Owned = Self;
1674
1675        #[inline(always)]
1676        fn inline_align(_context: fidl::encoding::Context) -> usize {
1677            4
1678        }
1679
1680        #[inline(always)]
1681        fn inline_size(_context: fidl::encoding::Context) -> usize {
1682            4
1683        }
1684    }
1685
1686    unsafe impl
1687        fidl::encoding::Encode<
1688            DeviceSetupSetChannelRequest,
1689            fidl::encoding::DefaultFuchsiaResourceDialect,
1690        > for &mut DeviceSetupSetChannelRequest
1691    {
1692        #[inline]
1693        unsafe fn encode(
1694            self,
1695            encoder: &mut fidl::encoding::Encoder<
1696                '_,
1697                fidl::encoding::DefaultFuchsiaResourceDialect,
1698            >,
1699            offset: usize,
1700            _depth: fidl::encoding::Depth,
1701        ) -> fidl::Result<()> {
1702            encoder.debug_check_bounds::<DeviceSetupSetChannelRequest>(offset);
1703            // Delegate to tuple encoding.
1704            fidl::encoding::Encode::<DeviceSetupSetChannelRequest, fidl::encoding::DefaultFuchsiaResourceDialect>::encode(
1705                (
1706                    <fidl::encoding::Endpoint<fidl::endpoints::ServerEnd<DeviceMarker>> as fidl::encoding::ResourceTypeMarker>::take_or_borrow(&mut self.req),
1707                ),
1708                encoder, offset, _depth
1709            )
1710        }
1711    }
1712    unsafe impl<
1713            T0: fidl::encoding::Encode<
1714                fidl::encoding::Endpoint<fidl::endpoints::ServerEnd<DeviceMarker>>,
1715                fidl::encoding::DefaultFuchsiaResourceDialect,
1716            >,
1717        >
1718        fidl::encoding::Encode<
1719            DeviceSetupSetChannelRequest,
1720            fidl::encoding::DefaultFuchsiaResourceDialect,
1721        > for (T0,)
1722    {
1723        #[inline]
1724        unsafe fn encode(
1725            self,
1726            encoder: &mut fidl::encoding::Encoder<
1727                '_,
1728                fidl::encoding::DefaultFuchsiaResourceDialect,
1729            >,
1730            offset: usize,
1731            depth: fidl::encoding::Depth,
1732        ) -> fidl::Result<()> {
1733            encoder.debug_check_bounds::<DeviceSetupSetChannelRequest>(offset);
1734            // Zero out padding regions. There's no need to apply masks
1735            // because the unmasked parts will be overwritten by fields.
1736            // Write the fields.
1737            self.0.encode(encoder, offset + 0, depth)?;
1738            Ok(())
1739        }
1740    }
1741
1742    impl fidl::encoding::Decode<Self, fidl::encoding::DefaultFuchsiaResourceDialect>
1743        for DeviceSetupSetChannelRequest
1744    {
1745        #[inline(always)]
1746        fn new_empty() -> Self {
1747            Self {
1748                req: fidl::new_empty!(
1749                    fidl::encoding::Endpoint<fidl::endpoints::ServerEnd<DeviceMarker>>,
1750                    fidl::encoding::DefaultFuchsiaResourceDialect
1751                ),
1752            }
1753        }
1754
1755        #[inline]
1756        unsafe fn decode(
1757            &mut self,
1758            decoder: &mut fidl::encoding::Decoder<
1759                '_,
1760                fidl::encoding::DefaultFuchsiaResourceDialect,
1761            >,
1762            offset: usize,
1763            _depth: fidl::encoding::Depth,
1764        ) -> fidl::Result<()> {
1765            decoder.debug_check_bounds::<Self>(offset);
1766            // Verify that padding bytes are zero.
1767            fidl::decode!(
1768                fidl::encoding::Endpoint<fidl::endpoints::ServerEnd<DeviceMarker>>,
1769                fidl::encoding::DefaultFuchsiaResourceDialect,
1770                &mut self.req,
1771                decoder,
1772                offset + 0,
1773                _depth
1774            )?;
1775            Ok(())
1776        }
1777    }
1778}