Skip to main content

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