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 fidl::endpoints::ControlHandle for DeviceControlHandle {
880    fn shutdown(&self) {
881        self.inner.shutdown()
882    }
883
884    fn shutdown_with_epitaph(&self, status: zx_status::Status) {
885        self.inner.shutdown_with_epitaph(status)
886    }
887
888    fn is_closed(&self) -> bool {
889        self.inner.channel().is_closed()
890    }
891    fn on_closed(&self) -> fidl::OnSignalsRef<'_> {
892        self.inner.channel().on_closed()
893    }
894
895    #[cfg(target_os = "fuchsia")]
896    fn signal_peer(
897        &self,
898        clear_mask: zx::Signals,
899        set_mask: zx::Signals,
900    ) -> Result<(), zx_status::Status> {
901        use fidl::Peered;
902        self.inner.channel().signal_peer(clear_mask, set_mask)
903    }
904}
905
906impl DeviceControlHandle {
907    pub fn send_on_ready_for_send_frames(
908        &self,
909        mut number_of_frames: u32,
910    ) -> Result<(), fidl::Error> {
911        self.inner.send::<DeviceOnReadyForSendFramesRequest>(
912            (number_of_frames,),
913            0,
914            0x2b1d5b28c5811b53,
915            fidl::encoding::DynamicFlags::empty(),
916        )
917    }
918
919    pub fn send_on_receive_frame(&self, mut data: &[u8]) -> Result<(), fidl::Error> {
920        self.inner.send::<DeviceOnReceiveFrameRequest>(
921            (data,),
922            0,
923            0x61937a45670aabb0,
924            fidl::encoding::DynamicFlags::empty(),
925        )
926    }
927
928    pub fn send_on_error(&self, mut error: Error, mut did_close: bool) -> Result<(), fidl::Error> {
929        self.inner.send::<DeviceOnErrorRequest>(
930            (error, did_close),
931            0,
932            0x4d20e65a9d2625e1,
933            fidl::encoding::DynamicFlags::empty(),
934        )
935    }
936}
937
938#[must_use = "FIDL methods require a response to be sent"]
939#[derive(Debug)]
940pub struct DeviceOpenResponder {
941    control_handle: std::mem::ManuallyDrop<DeviceControlHandle>,
942    tx_id: u32,
943}
944
945/// Set the the channel to be shutdown (see [`DeviceControlHandle::shutdown`])
946/// if the responder is dropped without sending a response, so that the client
947/// doesn't hang. To prevent this behavior, call `drop_without_shutdown`.
948impl std::ops::Drop for DeviceOpenResponder {
949    fn drop(&mut self) {
950        self.control_handle.shutdown();
951        // Safety: drops once, never accessed again
952        unsafe { std::mem::ManuallyDrop::drop(&mut self.control_handle) };
953    }
954}
955
956impl fidl::endpoints::Responder for DeviceOpenResponder {
957    type ControlHandle = DeviceControlHandle;
958
959    fn control_handle(&self) -> &DeviceControlHandle {
960        &self.control_handle
961    }
962
963    fn drop_without_shutdown(mut self) {
964        // Safety: drops once, never accessed again due to mem::forget
965        unsafe { std::mem::ManuallyDrop::drop(&mut self.control_handle) };
966        // Prevent Drop from running (which would shut down the channel)
967        std::mem::forget(self);
968    }
969}
970
971impl DeviceOpenResponder {
972    /// Sends a response to the FIDL transaction.
973    ///
974    /// Sets the channel to shutdown if an error occurs.
975    pub fn send(self, mut result: Result<(), Error>) -> Result<(), fidl::Error> {
976        let _result = self.send_raw(result);
977        if _result.is_err() {
978            self.control_handle.shutdown();
979        }
980        self.drop_without_shutdown();
981        _result
982    }
983
984    /// Similar to "send" but does not shutdown the channel if an error occurs.
985    pub fn send_no_shutdown_on_err(self, mut result: Result<(), Error>) -> Result<(), fidl::Error> {
986        let _result = self.send_raw(result);
987        self.drop_without_shutdown();
988        _result
989    }
990
991    fn send_raw(&self, mut result: Result<(), Error>) -> Result<(), fidl::Error> {
992        self.control_handle
993            .inner
994            .send::<fidl::encoding::ResultType<fidl::encoding::EmptyStruct, Error>>(
995                result,
996                self.tx_id,
997                0x508cecb73a776ef7,
998                fidl::encoding::DynamicFlags::empty(),
999            )
1000    }
1001}
1002
1003#[must_use = "FIDL methods require a response to be sent"]
1004#[derive(Debug)]
1005pub struct DeviceCloseResponder {
1006    control_handle: std::mem::ManuallyDrop<DeviceControlHandle>,
1007    tx_id: u32,
1008}
1009
1010/// Set the the channel to be shutdown (see [`DeviceControlHandle::shutdown`])
1011/// if the responder is dropped without sending a response, so that the client
1012/// doesn't hang. To prevent this behavior, call `drop_without_shutdown`.
1013impl std::ops::Drop for DeviceCloseResponder {
1014    fn drop(&mut self) {
1015        self.control_handle.shutdown();
1016        // Safety: drops once, never accessed again
1017        unsafe { std::mem::ManuallyDrop::drop(&mut self.control_handle) };
1018    }
1019}
1020
1021impl fidl::endpoints::Responder for DeviceCloseResponder {
1022    type ControlHandle = DeviceControlHandle;
1023
1024    fn control_handle(&self) -> &DeviceControlHandle {
1025        &self.control_handle
1026    }
1027
1028    fn drop_without_shutdown(mut self) {
1029        // Safety: drops once, never accessed again due to mem::forget
1030        unsafe { std::mem::ManuallyDrop::drop(&mut self.control_handle) };
1031        // Prevent Drop from running (which would shut down the channel)
1032        std::mem::forget(self);
1033    }
1034}
1035
1036impl DeviceCloseResponder {
1037    /// Sends a response to the FIDL transaction.
1038    ///
1039    /// Sets the channel to shutdown if an error occurs.
1040    pub fn send(self, mut result: Result<(), Error>) -> Result<(), fidl::Error> {
1041        let _result = self.send_raw(result);
1042        if _result.is_err() {
1043            self.control_handle.shutdown();
1044        }
1045        self.drop_without_shutdown();
1046        _result
1047    }
1048
1049    /// Similar to "send" but does not shutdown the channel if an error occurs.
1050    pub fn send_no_shutdown_on_err(self, mut result: Result<(), Error>) -> Result<(), fidl::Error> {
1051        let _result = self.send_raw(result);
1052        self.drop_without_shutdown();
1053        _result
1054    }
1055
1056    fn send_raw(&self, mut result: Result<(), Error>) -> Result<(), fidl::Error> {
1057        self.control_handle
1058            .inner
1059            .send::<fidl::encoding::ResultType<fidl::encoding::EmptyStruct, Error>>(
1060                result,
1061                self.tx_id,
1062                0x621a0f31b867781a,
1063                fidl::encoding::DynamicFlags::empty(),
1064            )
1065    }
1066}
1067
1068#[must_use = "FIDL methods require a response to be sent"]
1069#[derive(Debug)]
1070pub struct DeviceGetMaxFrameSizeResponder {
1071    control_handle: std::mem::ManuallyDrop<DeviceControlHandle>,
1072    tx_id: u32,
1073}
1074
1075/// Set the the channel to be shutdown (see [`DeviceControlHandle::shutdown`])
1076/// if the responder is dropped without sending a response, so that the client
1077/// doesn't hang. To prevent this behavior, call `drop_without_shutdown`.
1078impl std::ops::Drop for DeviceGetMaxFrameSizeResponder {
1079    fn drop(&mut self) {
1080        self.control_handle.shutdown();
1081        // Safety: drops once, never accessed again
1082        unsafe { std::mem::ManuallyDrop::drop(&mut self.control_handle) };
1083    }
1084}
1085
1086impl fidl::endpoints::Responder for DeviceGetMaxFrameSizeResponder {
1087    type ControlHandle = DeviceControlHandle;
1088
1089    fn control_handle(&self) -> &DeviceControlHandle {
1090        &self.control_handle
1091    }
1092
1093    fn drop_without_shutdown(mut self) {
1094        // Safety: drops once, never accessed again due to mem::forget
1095        unsafe { std::mem::ManuallyDrop::drop(&mut self.control_handle) };
1096        // Prevent Drop from running (which would shut down the channel)
1097        std::mem::forget(self);
1098    }
1099}
1100
1101impl DeviceGetMaxFrameSizeResponder {
1102    /// Sends a response to the FIDL transaction.
1103    ///
1104    /// Sets the channel to shutdown if an error occurs.
1105    pub fn send(self, mut size: u32) -> Result<(), fidl::Error> {
1106        let _result = self.send_raw(size);
1107        if _result.is_err() {
1108            self.control_handle.shutdown();
1109        }
1110        self.drop_without_shutdown();
1111        _result
1112    }
1113
1114    /// Similar to "send" but does not shutdown the channel if an error occurs.
1115    pub fn send_no_shutdown_on_err(self, mut size: u32) -> Result<(), fidl::Error> {
1116        let _result = self.send_raw(size);
1117        self.drop_without_shutdown();
1118        _result
1119    }
1120
1121    fn send_raw(&self, mut size: u32) -> Result<(), fidl::Error> {
1122        self.control_handle.inner.send::<DeviceGetMaxFrameSizeResponse>(
1123            (size,),
1124            self.tx_id,
1125            0x1d2d652e8b06d463,
1126            fidl::encoding::DynamicFlags::empty(),
1127        )
1128    }
1129}
1130
1131#[derive(Debug, Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Hash)]
1132pub struct DeviceSetupMarker;
1133
1134impl fidl::endpoints::ProtocolMarker for DeviceSetupMarker {
1135    type Proxy = DeviceSetupProxy;
1136    type RequestStream = DeviceSetupRequestStream;
1137    #[cfg(target_os = "fuchsia")]
1138    type SynchronousProxy = DeviceSetupSynchronousProxy;
1139
1140    const DEBUG_NAME: &'static str = "(anonymous) DeviceSetup";
1141}
1142pub type DeviceSetupSetChannelResult = Result<(), i32>;
1143
1144pub trait DeviceSetupProxyInterface: Send + Sync {
1145    type SetChannelResponseFut: std::future::Future<Output = Result<DeviceSetupSetChannelResult, fidl::Error>>
1146        + Send;
1147    fn r#set_channel(
1148        &self,
1149        req: fidl::endpoints::ServerEnd<DeviceMarker>,
1150    ) -> Self::SetChannelResponseFut;
1151}
1152#[derive(Debug)]
1153#[cfg(target_os = "fuchsia")]
1154pub struct DeviceSetupSynchronousProxy {
1155    client: fidl::client::sync::Client,
1156}
1157
1158#[cfg(target_os = "fuchsia")]
1159impl fidl::endpoints::SynchronousProxy for DeviceSetupSynchronousProxy {
1160    type Proxy = DeviceSetupProxy;
1161    type Protocol = DeviceSetupMarker;
1162
1163    fn from_channel(inner: fidl::Channel) -> Self {
1164        Self::new(inner)
1165    }
1166
1167    fn into_channel(self) -> fidl::Channel {
1168        self.client.into_channel()
1169    }
1170
1171    fn as_channel(&self) -> &fidl::Channel {
1172        self.client.as_channel()
1173    }
1174}
1175
1176#[cfg(target_os = "fuchsia")]
1177impl DeviceSetupSynchronousProxy {
1178    pub fn new(channel: fidl::Channel) -> Self {
1179        Self { client: fidl::client::sync::Client::new(channel) }
1180    }
1181
1182    pub fn into_channel(self) -> fidl::Channel {
1183        self.client.into_channel()
1184    }
1185
1186    /// Waits until an event arrives and returns it. It is safe for other
1187    /// threads to make concurrent requests while waiting for an event.
1188    pub fn wait_for_event(
1189        &self,
1190        deadline: zx::MonotonicInstant,
1191    ) -> Result<DeviceSetupEvent, fidl::Error> {
1192        DeviceSetupEvent::decode(self.client.wait_for_event::<DeviceSetupMarker>(deadline)?)
1193    }
1194
1195    pub fn r#set_channel(
1196        &self,
1197        mut req: fidl::endpoints::ServerEnd<DeviceMarker>,
1198        ___deadline: zx::MonotonicInstant,
1199    ) -> Result<DeviceSetupSetChannelResult, fidl::Error> {
1200        let _response = self.client.send_query::<
1201            DeviceSetupSetChannelRequest,
1202            fidl::encoding::ResultType<fidl::encoding::EmptyStruct, i32>,
1203            DeviceSetupMarker,
1204        >(
1205            (req,),
1206            0x7f8e02c174ef02a5,
1207            fidl::encoding::DynamicFlags::empty(),
1208            ___deadline,
1209        )?;
1210        Ok(_response.map(|x| x))
1211    }
1212}
1213
1214#[cfg(target_os = "fuchsia")]
1215impl From<DeviceSetupSynchronousProxy> for zx::NullableHandle {
1216    fn from(value: DeviceSetupSynchronousProxy) -> Self {
1217        value.into_channel().into()
1218    }
1219}
1220
1221#[cfg(target_os = "fuchsia")]
1222impl From<fidl::Channel> for DeviceSetupSynchronousProxy {
1223    fn from(value: fidl::Channel) -> Self {
1224        Self::new(value)
1225    }
1226}
1227
1228#[cfg(target_os = "fuchsia")]
1229impl fidl::endpoints::FromClient for DeviceSetupSynchronousProxy {
1230    type Protocol = DeviceSetupMarker;
1231
1232    fn from_client(value: fidl::endpoints::ClientEnd<DeviceSetupMarker>) -> Self {
1233        Self::new(value.into_channel())
1234    }
1235}
1236
1237#[derive(Debug, Clone)]
1238pub struct DeviceSetupProxy {
1239    client: fidl::client::Client<fidl::encoding::DefaultFuchsiaResourceDialect>,
1240}
1241
1242impl fidl::endpoints::Proxy for DeviceSetupProxy {
1243    type Protocol = DeviceSetupMarker;
1244
1245    fn from_channel(inner: ::fidl::AsyncChannel) -> Self {
1246        Self::new(inner)
1247    }
1248
1249    fn into_channel(self) -> Result<::fidl::AsyncChannel, Self> {
1250        self.client.into_channel().map_err(|client| Self { client })
1251    }
1252
1253    fn as_channel(&self) -> &::fidl::AsyncChannel {
1254        self.client.as_channel()
1255    }
1256}
1257
1258impl DeviceSetupProxy {
1259    /// Create a new Proxy for fuchsia.lowpan.spinel/DeviceSetup.
1260    pub fn new(channel: ::fidl::AsyncChannel) -> Self {
1261        let protocol_name = <DeviceSetupMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME;
1262        Self { client: fidl::client::Client::new(channel, protocol_name) }
1263    }
1264
1265    /// Get a Stream of events from the remote end of the protocol.
1266    ///
1267    /// # Panics
1268    ///
1269    /// Panics if the event stream was already taken.
1270    pub fn take_event_stream(&self) -> DeviceSetupEventStream {
1271        DeviceSetupEventStream { event_receiver: self.client.take_event_receiver() }
1272    }
1273
1274    pub fn r#set_channel(
1275        &self,
1276        mut req: fidl::endpoints::ServerEnd<DeviceMarker>,
1277    ) -> fidl::client::QueryResponseFut<
1278        DeviceSetupSetChannelResult,
1279        fidl::encoding::DefaultFuchsiaResourceDialect,
1280    > {
1281        DeviceSetupProxyInterface::r#set_channel(self, req)
1282    }
1283}
1284
1285impl DeviceSetupProxyInterface for DeviceSetupProxy {
1286    type SetChannelResponseFut = fidl::client::QueryResponseFut<
1287        DeviceSetupSetChannelResult,
1288        fidl::encoding::DefaultFuchsiaResourceDialect,
1289    >;
1290    fn r#set_channel(
1291        &self,
1292        mut req: fidl::endpoints::ServerEnd<DeviceMarker>,
1293    ) -> Self::SetChannelResponseFut {
1294        fn _decode(
1295            mut _buf: Result<<fidl::encoding::DefaultFuchsiaResourceDialect as fidl::encoding::ResourceDialect>::MessageBufEtc, fidl::Error>,
1296        ) -> Result<DeviceSetupSetChannelResult, fidl::Error> {
1297            let _response = fidl::client::decode_transaction_body::<
1298                fidl::encoding::ResultType<fidl::encoding::EmptyStruct, i32>,
1299                fidl::encoding::DefaultFuchsiaResourceDialect,
1300                0x7f8e02c174ef02a5,
1301            >(_buf?)?;
1302            Ok(_response.map(|x| x))
1303        }
1304        self.client
1305            .send_query_and_decode::<DeviceSetupSetChannelRequest, DeviceSetupSetChannelResult>(
1306                (req,),
1307                0x7f8e02c174ef02a5,
1308                fidl::encoding::DynamicFlags::empty(),
1309                _decode,
1310            )
1311    }
1312}
1313
1314pub struct DeviceSetupEventStream {
1315    event_receiver: fidl::client::EventReceiver<fidl::encoding::DefaultFuchsiaResourceDialect>,
1316}
1317
1318impl std::marker::Unpin for DeviceSetupEventStream {}
1319
1320impl futures::stream::FusedStream for DeviceSetupEventStream {
1321    fn is_terminated(&self) -> bool {
1322        self.event_receiver.is_terminated()
1323    }
1324}
1325
1326impl futures::Stream for DeviceSetupEventStream {
1327    type Item = Result<DeviceSetupEvent, fidl::Error>;
1328
1329    fn poll_next(
1330        mut self: std::pin::Pin<&mut Self>,
1331        cx: &mut std::task::Context<'_>,
1332    ) -> std::task::Poll<Option<Self::Item>> {
1333        match futures::ready!(futures::stream::StreamExt::poll_next_unpin(
1334            &mut self.event_receiver,
1335            cx
1336        )?) {
1337            Some(buf) => std::task::Poll::Ready(Some(DeviceSetupEvent::decode(buf))),
1338            None => std::task::Poll::Ready(None),
1339        }
1340    }
1341}
1342
1343#[derive(Debug)]
1344pub enum DeviceSetupEvent {}
1345
1346impl DeviceSetupEvent {
1347    /// Decodes a message buffer as a [`DeviceSetupEvent`].
1348    fn decode(
1349        mut buf: <fidl::encoding::DefaultFuchsiaResourceDialect as fidl::encoding::ResourceDialect>::MessageBufEtc,
1350    ) -> Result<DeviceSetupEvent, fidl::Error> {
1351        let (bytes, _handles) = buf.split_mut();
1352        let (tx_header, _body_bytes) = fidl::encoding::decode_transaction_header(bytes)?;
1353        debug_assert_eq!(tx_header.tx_id, 0);
1354        match tx_header.ordinal {
1355            _ => Err(fidl::Error::UnknownOrdinal {
1356                ordinal: tx_header.ordinal,
1357                protocol_name: <DeviceSetupMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME,
1358            }),
1359        }
1360    }
1361}
1362
1363/// A Stream of incoming requests for fuchsia.lowpan.spinel/DeviceSetup.
1364pub struct DeviceSetupRequestStream {
1365    inner: std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>,
1366    is_terminated: bool,
1367}
1368
1369impl std::marker::Unpin for DeviceSetupRequestStream {}
1370
1371impl futures::stream::FusedStream for DeviceSetupRequestStream {
1372    fn is_terminated(&self) -> bool {
1373        self.is_terminated
1374    }
1375}
1376
1377impl fidl::endpoints::RequestStream for DeviceSetupRequestStream {
1378    type Protocol = DeviceSetupMarker;
1379    type ControlHandle = DeviceSetupControlHandle;
1380
1381    fn from_channel(channel: ::fidl::AsyncChannel) -> Self {
1382        Self { inner: std::sync::Arc::new(fidl::ServeInner::new(channel)), is_terminated: false }
1383    }
1384
1385    fn control_handle(&self) -> Self::ControlHandle {
1386        DeviceSetupControlHandle { inner: self.inner.clone() }
1387    }
1388
1389    fn into_inner(
1390        self,
1391    ) -> (::std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>, bool)
1392    {
1393        (self.inner, self.is_terminated)
1394    }
1395
1396    fn from_inner(
1397        inner: std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>,
1398        is_terminated: bool,
1399    ) -> Self {
1400        Self { inner, is_terminated }
1401    }
1402}
1403
1404impl futures::Stream for DeviceSetupRequestStream {
1405    type Item = Result<DeviceSetupRequest, fidl::Error>;
1406
1407    fn poll_next(
1408        mut self: std::pin::Pin<&mut Self>,
1409        cx: &mut std::task::Context<'_>,
1410    ) -> std::task::Poll<Option<Self::Item>> {
1411        let this = &mut *self;
1412        if this.inner.check_shutdown(cx) {
1413            this.is_terminated = true;
1414            return std::task::Poll::Ready(None);
1415        }
1416        if this.is_terminated {
1417            panic!("polled DeviceSetupRequestStream after completion");
1418        }
1419        fidl::encoding::with_tls_decode_buf::<_, fidl::encoding::DefaultFuchsiaResourceDialect>(
1420            |bytes, handles| {
1421                match this.inner.channel().read_etc(cx, bytes, handles) {
1422                    std::task::Poll::Ready(Ok(())) => {}
1423                    std::task::Poll::Pending => return std::task::Poll::Pending,
1424                    std::task::Poll::Ready(Err(zx_status::Status::PEER_CLOSED)) => {
1425                        this.is_terminated = true;
1426                        return std::task::Poll::Ready(None);
1427                    }
1428                    std::task::Poll::Ready(Err(e)) => {
1429                        return std::task::Poll::Ready(Some(Err(fidl::Error::ServerRequestRead(
1430                            e.into(),
1431                        ))));
1432                    }
1433                }
1434
1435                // A message has been received from the channel
1436                let (header, _body_bytes) = fidl::encoding::decode_transaction_header(bytes)?;
1437
1438                std::task::Poll::Ready(Some(match header.ordinal {
1439                    0x7f8e02c174ef02a5 => {
1440                        header.validate_request_tx_id(fidl::MethodType::TwoWay)?;
1441                        let mut req = fidl::new_empty!(
1442                            DeviceSetupSetChannelRequest,
1443                            fidl::encoding::DefaultFuchsiaResourceDialect
1444                        );
1445                        fidl::encoding::Decoder::<fidl::encoding::DefaultFuchsiaResourceDialect>::decode_into::<DeviceSetupSetChannelRequest>(&header, _body_bytes, handles, &mut req)?;
1446                        let control_handle = DeviceSetupControlHandle { inner: this.inner.clone() };
1447                        Ok(DeviceSetupRequest::SetChannel {
1448                            req: req.req,
1449
1450                            responder: DeviceSetupSetChannelResponder {
1451                                control_handle: std::mem::ManuallyDrop::new(control_handle),
1452                                tx_id: header.tx_id,
1453                            },
1454                        })
1455                    }
1456                    _ => Err(fidl::Error::UnknownOrdinal {
1457                        ordinal: header.ordinal,
1458                        protocol_name:
1459                            <DeviceSetupMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME,
1460                    }),
1461                }))
1462            },
1463        )
1464    }
1465}
1466
1467#[derive(Debug)]
1468pub enum DeviceSetupRequest {
1469    SetChannel {
1470        req: fidl::endpoints::ServerEnd<DeviceMarker>,
1471        responder: DeviceSetupSetChannelResponder,
1472    },
1473}
1474
1475impl DeviceSetupRequest {
1476    #[allow(irrefutable_let_patterns)]
1477    pub fn into_set_channel(
1478        self,
1479    ) -> Option<(fidl::endpoints::ServerEnd<DeviceMarker>, DeviceSetupSetChannelResponder)> {
1480        if let DeviceSetupRequest::SetChannel { req, responder } = self {
1481            Some((req, responder))
1482        } else {
1483            None
1484        }
1485    }
1486
1487    /// Name of the method defined in FIDL
1488    pub fn method_name(&self) -> &'static str {
1489        match *self {
1490            DeviceSetupRequest::SetChannel { .. } => "set_channel",
1491        }
1492    }
1493}
1494
1495#[derive(Debug, Clone)]
1496pub struct DeviceSetupControlHandle {
1497    inner: std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>,
1498}
1499
1500impl fidl::endpoints::ControlHandle for DeviceSetupControlHandle {
1501    fn shutdown(&self) {
1502        self.inner.shutdown()
1503    }
1504
1505    fn shutdown_with_epitaph(&self, status: zx_status::Status) {
1506        self.inner.shutdown_with_epitaph(status)
1507    }
1508
1509    fn is_closed(&self) -> bool {
1510        self.inner.channel().is_closed()
1511    }
1512    fn on_closed(&self) -> fidl::OnSignalsRef<'_> {
1513        self.inner.channel().on_closed()
1514    }
1515
1516    #[cfg(target_os = "fuchsia")]
1517    fn signal_peer(
1518        &self,
1519        clear_mask: zx::Signals,
1520        set_mask: zx::Signals,
1521    ) -> Result<(), zx_status::Status> {
1522        use fidl::Peered;
1523        self.inner.channel().signal_peer(clear_mask, set_mask)
1524    }
1525}
1526
1527impl DeviceSetupControlHandle {}
1528
1529#[must_use = "FIDL methods require a response to be sent"]
1530#[derive(Debug)]
1531pub struct DeviceSetupSetChannelResponder {
1532    control_handle: std::mem::ManuallyDrop<DeviceSetupControlHandle>,
1533    tx_id: u32,
1534}
1535
1536/// Set the the channel to be shutdown (see [`DeviceSetupControlHandle::shutdown`])
1537/// if the responder is dropped without sending a response, so that the client
1538/// doesn't hang. To prevent this behavior, call `drop_without_shutdown`.
1539impl std::ops::Drop for DeviceSetupSetChannelResponder {
1540    fn drop(&mut self) {
1541        self.control_handle.shutdown();
1542        // Safety: drops once, never accessed again
1543        unsafe { std::mem::ManuallyDrop::drop(&mut self.control_handle) };
1544    }
1545}
1546
1547impl fidl::endpoints::Responder for DeviceSetupSetChannelResponder {
1548    type ControlHandle = DeviceSetupControlHandle;
1549
1550    fn control_handle(&self) -> &DeviceSetupControlHandle {
1551        &self.control_handle
1552    }
1553
1554    fn drop_without_shutdown(mut self) {
1555        // Safety: drops once, never accessed again due to mem::forget
1556        unsafe { std::mem::ManuallyDrop::drop(&mut self.control_handle) };
1557        // Prevent Drop from running (which would shut down the channel)
1558        std::mem::forget(self);
1559    }
1560}
1561
1562impl DeviceSetupSetChannelResponder {
1563    /// Sends a response to the FIDL transaction.
1564    ///
1565    /// Sets the channel to shutdown if an error occurs.
1566    pub fn send(self, mut result: Result<(), i32>) -> Result<(), fidl::Error> {
1567        let _result = self.send_raw(result);
1568        if _result.is_err() {
1569            self.control_handle.shutdown();
1570        }
1571        self.drop_without_shutdown();
1572        _result
1573    }
1574
1575    /// Similar to "send" but does not shutdown the channel if an error occurs.
1576    pub fn send_no_shutdown_on_err(self, mut result: Result<(), i32>) -> Result<(), fidl::Error> {
1577        let _result = self.send_raw(result);
1578        self.drop_without_shutdown();
1579        _result
1580    }
1581
1582    fn send_raw(&self, mut result: Result<(), i32>) -> Result<(), fidl::Error> {
1583        self.control_handle
1584            .inner
1585            .send::<fidl::encoding::ResultType<fidl::encoding::EmptyStruct, i32>>(
1586                result,
1587                self.tx_id,
1588                0x7f8e02c174ef02a5,
1589                fidl::encoding::DynamicFlags::empty(),
1590            )
1591    }
1592}
1593
1594#[derive(Debug, Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Hash)]
1595pub struct ServiceMarker;
1596
1597#[cfg(target_os = "fuchsia")]
1598impl fidl::endpoints::ServiceMarker for ServiceMarker {
1599    type Proxy = ServiceProxy;
1600    type Request = ServiceRequest;
1601    const SERVICE_NAME: &'static str = "fuchsia.lowpan.spinel.Service";
1602}
1603
1604/// A request for one of the member protocols of Service.
1605///
1606#[cfg(target_os = "fuchsia")]
1607pub enum ServiceRequest {
1608    DeviceSetup(DeviceSetupRequestStream),
1609}
1610
1611#[cfg(target_os = "fuchsia")]
1612impl fidl::endpoints::ServiceRequest for ServiceRequest {
1613    type Service = ServiceMarker;
1614
1615    fn dispatch(name: &str, _channel: fidl::AsyncChannel) -> Self {
1616        match name {
1617            "device_setup" => Self::DeviceSetup(
1618                <DeviceSetupRequestStream as fidl::endpoints::RequestStream>::from_channel(
1619                    _channel,
1620                ),
1621            ),
1622            _ => panic!("no such member protocol name for service Service"),
1623        }
1624    }
1625
1626    fn member_names() -> &'static [&'static str] {
1627        &["device_setup"]
1628    }
1629}
1630#[cfg(target_os = "fuchsia")]
1631pub struct ServiceProxy(#[allow(dead_code)] Box<dyn fidl::endpoints::MemberOpener>);
1632
1633#[cfg(target_os = "fuchsia")]
1634impl fidl::endpoints::ServiceProxy for ServiceProxy {
1635    type Service = ServiceMarker;
1636
1637    fn from_member_opener(opener: Box<dyn fidl::endpoints::MemberOpener>) -> Self {
1638        Self(opener)
1639    }
1640}
1641
1642#[cfg(target_os = "fuchsia")]
1643impl ServiceProxy {
1644    pub fn connect_to_device_setup(&self) -> Result<DeviceSetupProxy, fidl::Error> {
1645        let (proxy, server_end) = fidl::endpoints::create_proxy::<DeviceSetupMarker>();
1646        self.connect_channel_to_device_setup(server_end)?;
1647        Ok(proxy)
1648    }
1649
1650    /// Like `connect_to_device_setup`, but returns a sync proxy.
1651    /// See [`Self::connect_to_device_setup`] for more details.
1652    pub fn connect_to_device_setup_sync(&self) -> Result<DeviceSetupSynchronousProxy, fidl::Error> {
1653        let (proxy, server_end) = fidl::endpoints::create_sync_proxy::<DeviceSetupMarker>();
1654        self.connect_channel_to_device_setup(server_end)?;
1655        Ok(proxy)
1656    }
1657
1658    /// Like `connect_to_device_setup`, but accepts a server end.
1659    /// See [`Self::connect_to_device_setup`] for more details.
1660    pub fn connect_channel_to_device_setup(
1661        &self,
1662        server_end: fidl::endpoints::ServerEnd<DeviceSetupMarker>,
1663    ) -> Result<(), fidl::Error> {
1664        self.0.open_member("device_setup", server_end.into_channel())
1665    }
1666
1667    pub fn instance_name(&self) -> &str {
1668        self.0.instance_name()
1669    }
1670}
1671
1672mod internal {
1673    use super::*;
1674
1675    impl fidl::encoding::ResourceTypeMarker for DeviceSetupSetChannelRequest {
1676        type Borrowed<'a> = &'a mut Self;
1677        fn take_or_borrow<'a>(
1678            value: &'a mut <Self as fidl::encoding::TypeMarker>::Owned,
1679        ) -> Self::Borrowed<'a> {
1680            value
1681        }
1682    }
1683
1684    unsafe impl fidl::encoding::TypeMarker for DeviceSetupSetChannelRequest {
1685        type Owned = Self;
1686
1687        #[inline(always)]
1688        fn inline_align(_context: fidl::encoding::Context) -> usize {
1689            4
1690        }
1691
1692        #[inline(always)]
1693        fn inline_size(_context: fidl::encoding::Context) -> usize {
1694            4
1695        }
1696    }
1697
1698    unsafe impl
1699        fidl::encoding::Encode<
1700            DeviceSetupSetChannelRequest,
1701            fidl::encoding::DefaultFuchsiaResourceDialect,
1702        > for &mut DeviceSetupSetChannelRequest
1703    {
1704        #[inline]
1705        unsafe fn encode(
1706            self,
1707            encoder: &mut fidl::encoding::Encoder<
1708                '_,
1709                fidl::encoding::DefaultFuchsiaResourceDialect,
1710            >,
1711            offset: usize,
1712            _depth: fidl::encoding::Depth,
1713        ) -> fidl::Result<()> {
1714            encoder.debug_check_bounds::<DeviceSetupSetChannelRequest>(offset);
1715            // Delegate to tuple encoding.
1716            fidl::encoding::Encode::<DeviceSetupSetChannelRequest, fidl::encoding::DefaultFuchsiaResourceDialect>::encode(
1717                (
1718                    <fidl::encoding::Endpoint<fidl::endpoints::ServerEnd<DeviceMarker>> as fidl::encoding::ResourceTypeMarker>::take_or_borrow(&mut self.req),
1719                ),
1720                encoder, offset, _depth
1721            )
1722        }
1723    }
1724    unsafe impl<
1725        T0: fidl::encoding::Encode<
1726                fidl::encoding::Endpoint<fidl::endpoints::ServerEnd<DeviceMarker>>,
1727                fidl::encoding::DefaultFuchsiaResourceDialect,
1728            >,
1729    >
1730        fidl::encoding::Encode<
1731            DeviceSetupSetChannelRequest,
1732            fidl::encoding::DefaultFuchsiaResourceDialect,
1733        > for (T0,)
1734    {
1735        #[inline]
1736        unsafe fn encode(
1737            self,
1738            encoder: &mut fidl::encoding::Encoder<
1739                '_,
1740                fidl::encoding::DefaultFuchsiaResourceDialect,
1741            >,
1742            offset: usize,
1743            depth: fidl::encoding::Depth,
1744        ) -> fidl::Result<()> {
1745            encoder.debug_check_bounds::<DeviceSetupSetChannelRequest>(offset);
1746            // Zero out padding regions. There's no need to apply masks
1747            // because the unmasked parts will be overwritten by fields.
1748            // Write the fields.
1749            self.0.encode(encoder, offset + 0, depth)?;
1750            Ok(())
1751        }
1752    }
1753
1754    impl fidl::encoding::Decode<Self, fidl::encoding::DefaultFuchsiaResourceDialect>
1755        for DeviceSetupSetChannelRequest
1756    {
1757        #[inline(always)]
1758        fn new_empty() -> Self {
1759            Self {
1760                req: fidl::new_empty!(
1761                    fidl::encoding::Endpoint<fidl::endpoints::ServerEnd<DeviceMarker>>,
1762                    fidl::encoding::DefaultFuchsiaResourceDialect
1763                ),
1764            }
1765        }
1766
1767        #[inline]
1768        unsafe fn decode(
1769            &mut self,
1770            decoder: &mut fidl::encoding::Decoder<
1771                '_,
1772                fidl::encoding::DefaultFuchsiaResourceDialect,
1773            >,
1774            offset: usize,
1775            _depth: fidl::encoding::Depth,
1776        ) -> fidl::Result<()> {
1777            decoder.debug_check_bounds::<Self>(offset);
1778            // Verify that padding bytes are zero.
1779            fidl::decode!(
1780                fidl::encoding::Endpoint<fidl::endpoints::ServerEnd<DeviceMarker>>,
1781                fidl::encoding::DefaultFuchsiaResourceDialect,
1782                &mut self.req,
1783                decoder,
1784                offset + 0,
1785                _depth
1786            )?;
1787            Ok(())
1788        }
1789    }
1790}