fidl_fuchsia_bluetooth_le/
fidl_fuchsia_bluetooth_le.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_bluetooth_le_common::*;
11use futures::future::{self, MaybeDone, TryFutureExt};
12use zx_status;
13
14#[derive(Debug, PartialEq)]
15pub struct AdvertisedPeripheralOnConnectedRequest {
16    pub peer: Peer,
17    pub connection: fidl::endpoints::ClientEnd<ConnectionMarker>,
18}
19
20impl fidl::Standalone<fidl::encoding::DefaultFuchsiaResourceDialect>
21    for AdvertisedPeripheralOnConnectedRequest
22{
23}
24
25#[derive(Debug, PartialEq)]
26pub struct CentralConnectPeripheralRequest {
27    pub identifier: String,
28    pub options: ConnectionOptions,
29    pub gatt_client: fidl::endpoints::ServerEnd<fidl_fuchsia_bluetooth_gatt::ClientMarker>,
30}
31
32impl fidl::Standalone<fidl::encoding::DefaultFuchsiaResourceDialect>
33    for CentralConnectPeripheralRequest
34{
35}
36
37#[derive(Debug, PartialEq)]
38pub struct CentralConnectRequest {
39    pub id: fidl_fuchsia_bluetooth::PeerId,
40    pub options: ConnectionOptions,
41    pub handle: fidl::endpoints::ServerEnd<ConnectionMarker>,
42}
43
44impl fidl::Standalone<fidl::encoding::DefaultFuchsiaResourceDialect> for CentralConnectRequest {}
45
46#[derive(Debug, PartialEq)]
47pub struct CentralScanRequest {
48    pub options: ScanOptions,
49    pub result_watcher: fidl::endpoints::ServerEnd<ScanResultWatcherMarker>,
50}
51
52impl fidl::Standalone<fidl::encoding::DefaultFuchsiaResourceDialect> for CentralScanRequest {}
53
54#[derive(Debug, Eq, Hash, Ord, PartialEq, PartialOrd)]
55pub struct ChannelListenerAcceptRequest {
56    pub channel: fidl::endpoints::ClientEnd<fidl_fuchsia_bluetooth::ChannelMarker>,
57}
58
59impl fidl::Standalone<fidl::encoding::DefaultFuchsiaResourceDialect>
60    for ChannelListenerAcceptRequest
61{
62}
63
64#[derive(Debug, Eq, Hash, Ord, PartialEq, PartialOrd)]
65pub struct ConnectionRequestGattClientRequest {
66    pub client: fidl::endpoints::ServerEnd<fidl_fuchsia_bluetooth_gatt2::ClientMarker>,
67}
68
69impl fidl::Standalone<fidl::encoding::DefaultFuchsiaResourceDialect>
70    for ConnectionRequestGattClientRequest
71{
72}
73
74#[derive(Debug, PartialEq)]
75pub struct PeripheralAdvertiseRequest {
76    pub parameters: AdvertisingParameters,
77    pub advertised_peripheral: fidl::endpoints::ClientEnd<AdvertisedPeripheralMarker>,
78}
79
80impl fidl::Standalone<fidl::encoding::DefaultFuchsiaResourceDialect>
81    for PeripheralAdvertiseRequest
82{
83}
84
85#[derive(Debug, PartialEq)]
86pub struct PeripheralOnPeerConnectedRequest {
87    pub peer: Peer,
88    pub connection: fidl::endpoints::ClientEnd<ConnectionMarker>,
89}
90
91impl fidl::Standalone<fidl::encoding::DefaultFuchsiaResourceDialect>
92    for PeripheralOnPeerConnectedRequest
93{
94}
95
96#[derive(Debug, PartialEq)]
97pub struct PeripheralStartAdvertisingRequest {
98    pub parameters: AdvertisingParameters,
99    pub handle: fidl::endpoints::ServerEnd<AdvertisingHandleMarker>,
100}
101
102impl fidl::Standalone<fidl::encoding::DefaultFuchsiaResourceDialect>
103    for PeripheralStartAdvertisingRequest
104{
105}
106
107#[derive(Debug, Default, PartialEq)]
108pub struct ChannelListenerRegistryListenL2capRequest {
109    /// Accepted parameters for the local side of the channel.
110    pub parameters: Option<AcceptedChannelParameters>,
111    /// The channel listener protocol to open.
112    pub listener: Option<fidl::endpoints::ClientEnd<ChannelListenerMarker>>,
113    #[doc(hidden)]
114    pub __source_breaking: fidl::marker::SourceBreaking,
115}
116
117impl fidl::Standalone<fidl::encoding::DefaultFuchsiaResourceDialect>
118    for ChannelListenerRegistryListenL2capRequest
119{
120}
121
122#[derive(Debug, Default, PartialEq)]
123pub struct ConnectionAcceptCisRequest {
124    /// Identifier of the CIG that contains the requested CIS. Required.
125    pub cig_id: Option<u8>,
126    /// Identifier of the requested CIS. Required.
127    pub cis_id: Option<u8>,
128    /// When the stream is established, the server will invoke
129    /// IsochronousStream::OnCisEstablished() on this channel. Required.
130    ///
131    /// If the client end of this channel is closed, requests of the corresponding CIG/CIS
132    /// combination will be rejected until/unless another call is made to AcceptCis() with
133    /// the same CIG/CIS parameters.
134    pub connection_stream: Option<fidl::endpoints::ServerEnd<IsochronousStreamMarker>>,
135    #[doc(hidden)]
136    pub __source_breaking: fidl::marker::SourceBreaking,
137}
138
139impl fidl::Standalone<fidl::encoding::DefaultFuchsiaResourceDialect>
140    for ConnectionAcceptCisRequest
141{
142}
143
144#[derive(Debug, Default, PartialEq)]
145pub struct ConnectionConnectL2capRequest {
146    /// Parameters for the local side of the channel.
147    pub parameters: Option<fidl_fuchsia_bluetooth::ChannelParameters>,
148    /// The channel protocol to open.
149    pub channel: Option<fidl::endpoints::ServerEnd<fidl_fuchsia_bluetooth::ChannelMarker>>,
150    /// The PSM of the remote side to connect to.
151    pub psm: Option<u16>,
152    #[doc(hidden)]
153    pub __source_breaking: fidl::marker::SourceBreaking,
154}
155
156impl fidl::Standalone<fidl::encoding::DefaultFuchsiaResourceDialect>
157    for ConnectionConnectL2capRequest
158{
159}
160
161#[derive(Debug, Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Hash)]
162pub struct AdvertisedPeripheralMarker;
163
164impl fidl::endpoints::ProtocolMarker for AdvertisedPeripheralMarker {
165    type Proxy = AdvertisedPeripheralProxy;
166    type RequestStream = AdvertisedPeripheralRequestStream;
167    #[cfg(target_os = "fuchsia")]
168    type SynchronousProxy = AdvertisedPeripheralSynchronousProxy;
169
170    const DEBUG_NAME: &'static str = "(anonymous) AdvertisedPeripheral";
171}
172
173pub trait AdvertisedPeripheralProxyInterface: Send + Sync {
174    type OnConnectedResponseFut: std::future::Future<Output = Result<(), fidl::Error>> + Send;
175    fn r#on_connected(
176        &self,
177        peer: &Peer,
178        connection: fidl::endpoints::ClientEnd<ConnectionMarker>,
179    ) -> Self::OnConnectedResponseFut;
180}
181#[derive(Debug)]
182#[cfg(target_os = "fuchsia")]
183pub struct AdvertisedPeripheralSynchronousProxy {
184    client: fidl::client::sync::Client,
185}
186
187#[cfg(target_os = "fuchsia")]
188impl fidl::endpoints::SynchronousProxy for AdvertisedPeripheralSynchronousProxy {
189    type Proxy = AdvertisedPeripheralProxy;
190    type Protocol = AdvertisedPeripheralMarker;
191
192    fn from_channel(inner: fidl::Channel) -> Self {
193        Self::new(inner)
194    }
195
196    fn into_channel(self) -> fidl::Channel {
197        self.client.into_channel()
198    }
199
200    fn as_channel(&self) -> &fidl::Channel {
201        self.client.as_channel()
202    }
203}
204
205#[cfg(target_os = "fuchsia")]
206impl AdvertisedPeripheralSynchronousProxy {
207    pub fn new(channel: fidl::Channel) -> Self {
208        let protocol_name =
209            <AdvertisedPeripheralMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME;
210        Self { client: fidl::client::sync::Client::new(channel, protocol_name) }
211    }
212
213    pub fn into_channel(self) -> fidl::Channel {
214        self.client.into_channel()
215    }
216
217    /// Waits until an event arrives and returns it. It is safe for other
218    /// threads to make concurrent requests while waiting for an event.
219    pub fn wait_for_event(
220        &self,
221        deadline: zx::MonotonicInstant,
222    ) -> Result<AdvertisedPeripheralEvent, fidl::Error> {
223        AdvertisedPeripheralEvent::decode(self.client.wait_for_event(deadline)?)
224    }
225
226    /// Called when a remote LE central connects to this peripheral when
227    /// connectable advertising is enabled via
228    /// [`fuchsia.bluetooth.le/Peripheral.Advertise`]. When this call is made,
229    /// the system has paused advertising, and will not continue until it
230    /// receives a response.
231    ///
232    /// The returned [`fuchsia.bluetooth.le/Connection`] protocol can be used to
233    /// interact with the peer. It also represents a peripheral's ownership over
234    /// the connection: the client can drop the protocol to request a
235    /// disconnection. Similarly, the protocol is closed by the system to
236    /// indicate that the connection to the peer has been lost.
237    ///
238    /// + request `peer` Information about the central that initiated the
239    ///   connection.
240    /// + request `connection` Represents the connection.
241    /// - response An empty response should be sent to acknowledge the
242    ///   connection and resume advertising (for flow control).
243    pub fn r#on_connected(
244        &self,
245        mut peer: &Peer,
246        mut connection: fidl::endpoints::ClientEnd<ConnectionMarker>,
247        ___deadline: zx::MonotonicInstant,
248    ) -> Result<(), fidl::Error> {
249        let _response = self
250            .client
251            .send_query::<AdvertisedPeripheralOnConnectedRequest, fidl::encoding::EmptyPayload>(
252                (peer, connection),
253                0x607b7716457eb178,
254                fidl::encoding::DynamicFlags::empty(),
255                ___deadline,
256            )?;
257        Ok(_response)
258    }
259}
260
261#[cfg(target_os = "fuchsia")]
262impl From<AdvertisedPeripheralSynchronousProxy> for zx::Handle {
263    fn from(value: AdvertisedPeripheralSynchronousProxy) -> Self {
264        value.into_channel().into()
265    }
266}
267
268#[cfg(target_os = "fuchsia")]
269impl From<fidl::Channel> for AdvertisedPeripheralSynchronousProxy {
270    fn from(value: fidl::Channel) -> Self {
271        Self::new(value)
272    }
273}
274
275#[derive(Debug, Clone)]
276pub struct AdvertisedPeripheralProxy {
277    client: fidl::client::Client<fidl::encoding::DefaultFuchsiaResourceDialect>,
278}
279
280impl fidl::endpoints::Proxy for AdvertisedPeripheralProxy {
281    type Protocol = AdvertisedPeripheralMarker;
282
283    fn from_channel(inner: ::fidl::AsyncChannel) -> Self {
284        Self::new(inner)
285    }
286
287    fn into_channel(self) -> Result<::fidl::AsyncChannel, Self> {
288        self.client.into_channel().map_err(|client| Self { client })
289    }
290
291    fn as_channel(&self) -> &::fidl::AsyncChannel {
292        self.client.as_channel()
293    }
294}
295
296impl AdvertisedPeripheralProxy {
297    /// Create a new Proxy for fuchsia.bluetooth.le/AdvertisedPeripheral.
298    pub fn new(channel: ::fidl::AsyncChannel) -> Self {
299        let protocol_name =
300            <AdvertisedPeripheralMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME;
301        Self { client: fidl::client::Client::new(channel, protocol_name) }
302    }
303
304    /// Get a Stream of events from the remote end of the protocol.
305    ///
306    /// # Panics
307    ///
308    /// Panics if the event stream was already taken.
309    pub fn take_event_stream(&self) -> AdvertisedPeripheralEventStream {
310        AdvertisedPeripheralEventStream { event_receiver: self.client.take_event_receiver() }
311    }
312
313    /// Called when a remote LE central connects to this peripheral when
314    /// connectable advertising is enabled via
315    /// [`fuchsia.bluetooth.le/Peripheral.Advertise`]. When this call is made,
316    /// the system has paused advertising, and will not continue until it
317    /// receives a response.
318    ///
319    /// The returned [`fuchsia.bluetooth.le/Connection`] protocol can be used to
320    /// interact with the peer. It also represents a peripheral's ownership over
321    /// the connection: the client can drop the protocol to request a
322    /// disconnection. Similarly, the protocol is closed by the system to
323    /// indicate that the connection to the peer has been lost.
324    ///
325    /// + request `peer` Information about the central that initiated the
326    ///   connection.
327    /// + request `connection` Represents the connection.
328    /// - response An empty response should be sent to acknowledge the
329    ///   connection and resume advertising (for flow control).
330    pub fn r#on_connected(
331        &self,
332        mut peer: &Peer,
333        mut connection: fidl::endpoints::ClientEnd<ConnectionMarker>,
334    ) -> fidl::client::QueryResponseFut<(), fidl::encoding::DefaultFuchsiaResourceDialect> {
335        AdvertisedPeripheralProxyInterface::r#on_connected(self, peer, connection)
336    }
337}
338
339impl AdvertisedPeripheralProxyInterface for AdvertisedPeripheralProxy {
340    type OnConnectedResponseFut =
341        fidl::client::QueryResponseFut<(), fidl::encoding::DefaultFuchsiaResourceDialect>;
342    fn r#on_connected(
343        &self,
344        mut peer: &Peer,
345        mut connection: fidl::endpoints::ClientEnd<ConnectionMarker>,
346    ) -> Self::OnConnectedResponseFut {
347        fn _decode(
348            mut _buf: Result<<fidl::encoding::DefaultFuchsiaResourceDialect as fidl::encoding::ResourceDialect>::MessageBufEtc, fidl::Error>,
349        ) -> Result<(), fidl::Error> {
350            let _response = fidl::client::decode_transaction_body::<
351                fidl::encoding::EmptyPayload,
352                fidl::encoding::DefaultFuchsiaResourceDialect,
353                0x607b7716457eb178,
354            >(_buf?)?;
355            Ok(_response)
356        }
357        self.client.send_query_and_decode::<AdvertisedPeripheralOnConnectedRequest, ()>(
358            (peer, connection),
359            0x607b7716457eb178,
360            fidl::encoding::DynamicFlags::empty(),
361            _decode,
362        )
363    }
364}
365
366pub struct AdvertisedPeripheralEventStream {
367    event_receiver: fidl::client::EventReceiver<fidl::encoding::DefaultFuchsiaResourceDialect>,
368}
369
370impl std::marker::Unpin for AdvertisedPeripheralEventStream {}
371
372impl futures::stream::FusedStream for AdvertisedPeripheralEventStream {
373    fn is_terminated(&self) -> bool {
374        self.event_receiver.is_terminated()
375    }
376}
377
378impl futures::Stream for AdvertisedPeripheralEventStream {
379    type Item = Result<AdvertisedPeripheralEvent, fidl::Error>;
380
381    fn poll_next(
382        mut self: std::pin::Pin<&mut Self>,
383        cx: &mut std::task::Context<'_>,
384    ) -> std::task::Poll<Option<Self::Item>> {
385        match futures::ready!(futures::stream::StreamExt::poll_next_unpin(
386            &mut self.event_receiver,
387            cx
388        )?) {
389            Some(buf) => std::task::Poll::Ready(Some(AdvertisedPeripheralEvent::decode(buf))),
390            None => std::task::Poll::Ready(None),
391        }
392    }
393}
394
395#[derive(Debug)]
396pub enum AdvertisedPeripheralEvent {}
397
398impl AdvertisedPeripheralEvent {
399    /// Decodes a message buffer as a [`AdvertisedPeripheralEvent`].
400    fn decode(
401        mut buf: <fidl::encoding::DefaultFuchsiaResourceDialect as fidl::encoding::ResourceDialect>::MessageBufEtc,
402    ) -> Result<AdvertisedPeripheralEvent, fidl::Error> {
403        let (bytes, _handles) = buf.split_mut();
404        let (tx_header, _body_bytes) = fidl::encoding::decode_transaction_header(bytes)?;
405        debug_assert_eq!(tx_header.tx_id, 0);
406        match tx_header.ordinal {
407            _ => Err(fidl::Error::UnknownOrdinal {
408                ordinal: tx_header.ordinal,
409                protocol_name:
410                    <AdvertisedPeripheralMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME,
411            }),
412        }
413    }
414}
415
416/// A Stream of incoming requests for fuchsia.bluetooth.le/AdvertisedPeripheral.
417pub struct AdvertisedPeripheralRequestStream {
418    inner: std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>,
419    is_terminated: bool,
420}
421
422impl std::marker::Unpin for AdvertisedPeripheralRequestStream {}
423
424impl futures::stream::FusedStream for AdvertisedPeripheralRequestStream {
425    fn is_terminated(&self) -> bool {
426        self.is_terminated
427    }
428}
429
430impl fidl::endpoints::RequestStream for AdvertisedPeripheralRequestStream {
431    type Protocol = AdvertisedPeripheralMarker;
432    type ControlHandle = AdvertisedPeripheralControlHandle;
433
434    fn from_channel(channel: ::fidl::AsyncChannel) -> Self {
435        Self { inner: std::sync::Arc::new(fidl::ServeInner::new(channel)), is_terminated: false }
436    }
437
438    fn control_handle(&self) -> Self::ControlHandle {
439        AdvertisedPeripheralControlHandle { inner: self.inner.clone() }
440    }
441
442    fn into_inner(
443        self,
444    ) -> (::std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>, bool)
445    {
446        (self.inner, self.is_terminated)
447    }
448
449    fn from_inner(
450        inner: std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>,
451        is_terminated: bool,
452    ) -> Self {
453        Self { inner, is_terminated }
454    }
455}
456
457impl futures::Stream for AdvertisedPeripheralRequestStream {
458    type Item = Result<AdvertisedPeripheralRequest, fidl::Error>;
459
460    fn poll_next(
461        mut self: std::pin::Pin<&mut Self>,
462        cx: &mut std::task::Context<'_>,
463    ) -> std::task::Poll<Option<Self::Item>> {
464        let this = &mut *self;
465        if this.inner.check_shutdown(cx) {
466            this.is_terminated = true;
467            return std::task::Poll::Ready(None);
468        }
469        if this.is_terminated {
470            panic!("polled AdvertisedPeripheralRequestStream after completion");
471        }
472        fidl::encoding::with_tls_decode_buf::<_, fidl::encoding::DefaultFuchsiaResourceDialect>(
473            |bytes, handles| {
474                match this.inner.channel().read_etc(cx, bytes, handles) {
475                    std::task::Poll::Ready(Ok(())) => {}
476                    std::task::Poll::Pending => return std::task::Poll::Pending,
477                    std::task::Poll::Ready(Err(zx_status::Status::PEER_CLOSED)) => {
478                        this.is_terminated = true;
479                        return std::task::Poll::Ready(None);
480                    }
481                    std::task::Poll::Ready(Err(e)) => {
482                        return std::task::Poll::Ready(Some(Err(fidl::Error::ServerRequestRead(
483                            e.into(),
484                        ))))
485                    }
486                }
487
488                // A message has been received from the channel
489                let (header, _body_bytes) = fidl::encoding::decode_transaction_header(bytes)?;
490
491                std::task::Poll::Ready(Some(match header.ordinal {
492                0x607b7716457eb178 => {
493                    header.validate_request_tx_id(fidl::MethodType::TwoWay)?;
494                    let mut req = fidl::new_empty!(AdvertisedPeripheralOnConnectedRequest, fidl::encoding::DefaultFuchsiaResourceDialect);
495                    fidl::encoding::Decoder::<fidl::encoding::DefaultFuchsiaResourceDialect>::decode_into::<AdvertisedPeripheralOnConnectedRequest>(&header, _body_bytes, handles, &mut req)?;
496                    let control_handle = AdvertisedPeripheralControlHandle {
497                        inner: this.inner.clone(),
498                    };
499                    Ok(AdvertisedPeripheralRequest::OnConnected {peer: req.peer,
500connection: req.connection,
501
502                        responder: AdvertisedPeripheralOnConnectedResponder {
503                            control_handle: std::mem::ManuallyDrop::new(control_handle),
504                            tx_id: header.tx_id,
505                        },
506                    })
507                }
508                _ => Err(fidl::Error::UnknownOrdinal {
509                    ordinal: header.ordinal,
510                    protocol_name: <AdvertisedPeripheralMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME,
511                }),
512            }))
513            },
514        )
515    }
516}
517
518/// Protocol that is valid for the duration of advertising. The caller can close
519/// the protocol to stop advertising. If the system internally stops advertising
520/// for any reason, the protocol will be closed to communicate this to the
521/// client.
522#[derive(Debug)]
523pub enum AdvertisedPeripheralRequest {
524    /// Called when a remote LE central connects to this peripheral when
525    /// connectable advertising is enabled via
526    /// [`fuchsia.bluetooth.le/Peripheral.Advertise`]. When this call is made,
527    /// the system has paused advertising, and will not continue until it
528    /// receives a response.
529    ///
530    /// The returned [`fuchsia.bluetooth.le/Connection`] protocol can be used to
531    /// interact with the peer. It also represents a peripheral's ownership over
532    /// the connection: the client can drop the protocol to request a
533    /// disconnection. Similarly, the protocol is closed by the system to
534    /// indicate that the connection to the peer has been lost.
535    ///
536    /// + request `peer` Information about the central that initiated the
537    ///   connection.
538    /// + request `connection` Represents the connection.
539    /// - response An empty response should be sent to acknowledge the
540    ///   connection and resume advertising (for flow control).
541    OnConnected {
542        peer: Peer,
543        connection: fidl::endpoints::ClientEnd<ConnectionMarker>,
544        responder: AdvertisedPeripheralOnConnectedResponder,
545    },
546}
547
548impl AdvertisedPeripheralRequest {
549    #[allow(irrefutable_let_patterns)]
550    pub fn into_on_connected(
551        self,
552    ) -> Option<(
553        Peer,
554        fidl::endpoints::ClientEnd<ConnectionMarker>,
555        AdvertisedPeripheralOnConnectedResponder,
556    )> {
557        if let AdvertisedPeripheralRequest::OnConnected { peer, connection, responder } = self {
558            Some((peer, connection, responder))
559        } else {
560            None
561        }
562    }
563
564    /// Name of the method defined in FIDL
565    pub fn method_name(&self) -> &'static str {
566        match *self {
567            AdvertisedPeripheralRequest::OnConnected { .. } => "on_connected",
568        }
569    }
570}
571
572#[derive(Debug, Clone)]
573pub struct AdvertisedPeripheralControlHandle {
574    inner: std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>,
575}
576
577impl fidl::endpoints::ControlHandle for AdvertisedPeripheralControlHandle {
578    fn shutdown(&self) {
579        self.inner.shutdown()
580    }
581    fn shutdown_with_epitaph(&self, status: zx_status::Status) {
582        self.inner.shutdown_with_epitaph(status)
583    }
584
585    fn is_closed(&self) -> bool {
586        self.inner.channel().is_closed()
587    }
588    fn on_closed(&self) -> fidl::OnSignalsRef<'_> {
589        self.inner.channel().on_closed()
590    }
591
592    #[cfg(target_os = "fuchsia")]
593    fn signal_peer(
594        &self,
595        clear_mask: zx::Signals,
596        set_mask: zx::Signals,
597    ) -> Result<(), zx_status::Status> {
598        use fidl::Peered;
599        self.inner.channel().signal_peer(clear_mask, set_mask)
600    }
601}
602
603impl AdvertisedPeripheralControlHandle {}
604
605#[must_use = "FIDL methods require a response to be sent"]
606#[derive(Debug)]
607pub struct AdvertisedPeripheralOnConnectedResponder {
608    control_handle: std::mem::ManuallyDrop<AdvertisedPeripheralControlHandle>,
609    tx_id: u32,
610}
611
612/// Set the the channel to be shutdown (see [`AdvertisedPeripheralControlHandle::shutdown`])
613/// if the responder is dropped without sending a response, so that the client
614/// doesn't hang. To prevent this behavior, call `drop_without_shutdown`.
615impl std::ops::Drop for AdvertisedPeripheralOnConnectedResponder {
616    fn drop(&mut self) {
617        self.control_handle.shutdown();
618        // Safety: drops once, never accessed again
619        unsafe { std::mem::ManuallyDrop::drop(&mut self.control_handle) };
620    }
621}
622
623impl fidl::endpoints::Responder for AdvertisedPeripheralOnConnectedResponder {
624    type ControlHandle = AdvertisedPeripheralControlHandle;
625
626    fn control_handle(&self) -> &AdvertisedPeripheralControlHandle {
627        &self.control_handle
628    }
629
630    fn drop_without_shutdown(mut self) {
631        // Safety: drops once, never accessed again due to mem::forget
632        unsafe { std::mem::ManuallyDrop::drop(&mut self.control_handle) };
633        // Prevent Drop from running (which would shut down the channel)
634        std::mem::forget(self);
635    }
636}
637
638impl AdvertisedPeripheralOnConnectedResponder {
639    /// Sends a response to the FIDL transaction.
640    ///
641    /// Sets the channel to shutdown if an error occurs.
642    pub fn send(self) -> Result<(), fidl::Error> {
643        let _result = self.send_raw();
644        if _result.is_err() {
645            self.control_handle.shutdown();
646        }
647        self.drop_without_shutdown();
648        _result
649    }
650
651    /// Similar to "send" but does not shutdown the channel if an error occurs.
652    pub fn send_no_shutdown_on_err(self) -> Result<(), fidl::Error> {
653        let _result = self.send_raw();
654        self.drop_without_shutdown();
655        _result
656    }
657
658    fn send_raw(&self) -> Result<(), fidl::Error> {
659        self.control_handle.inner.send::<fidl::encoding::EmptyPayload>(
660            (),
661            self.tx_id,
662            0x607b7716457eb178,
663            fidl::encoding::DynamicFlags::empty(),
664        )
665    }
666}
667
668#[derive(Debug, Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Hash)]
669pub struct AdvertisingHandleMarker;
670
671impl fidl::endpoints::ProtocolMarker for AdvertisingHandleMarker {
672    type Proxy = AdvertisingHandleProxy;
673    type RequestStream = AdvertisingHandleRequestStream;
674    #[cfg(target_os = "fuchsia")]
675    type SynchronousProxy = AdvertisingHandleSynchronousProxy;
676
677    const DEBUG_NAME: &'static str = "(anonymous) AdvertisingHandle";
678}
679
680pub trait AdvertisingHandleProxyInterface: Send + Sync {}
681#[derive(Debug)]
682#[cfg(target_os = "fuchsia")]
683pub struct AdvertisingHandleSynchronousProxy {
684    client: fidl::client::sync::Client,
685}
686
687#[cfg(target_os = "fuchsia")]
688impl fidl::endpoints::SynchronousProxy for AdvertisingHandleSynchronousProxy {
689    type Proxy = AdvertisingHandleProxy;
690    type Protocol = AdvertisingHandleMarker;
691
692    fn from_channel(inner: fidl::Channel) -> Self {
693        Self::new(inner)
694    }
695
696    fn into_channel(self) -> fidl::Channel {
697        self.client.into_channel()
698    }
699
700    fn as_channel(&self) -> &fidl::Channel {
701        self.client.as_channel()
702    }
703}
704
705#[cfg(target_os = "fuchsia")]
706impl AdvertisingHandleSynchronousProxy {
707    pub fn new(channel: fidl::Channel) -> Self {
708        let protocol_name =
709            <AdvertisingHandleMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME;
710        Self { client: fidl::client::sync::Client::new(channel, protocol_name) }
711    }
712
713    pub fn into_channel(self) -> fidl::Channel {
714        self.client.into_channel()
715    }
716
717    /// Waits until an event arrives and returns it. It is safe for other
718    /// threads to make concurrent requests while waiting for an event.
719    pub fn wait_for_event(
720        &self,
721        deadline: zx::MonotonicInstant,
722    ) -> Result<AdvertisingHandleEvent, fidl::Error> {
723        AdvertisingHandleEvent::decode(self.client.wait_for_event(deadline)?)
724    }
725}
726
727#[cfg(target_os = "fuchsia")]
728impl From<AdvertisingHandleSynchronousProxy> for zx::Handle {
729    fn from(value: AdvertisingHandleSynchronousProxy) -> Self {
730        value.into_channel().into()
731    }
732}
733
734#[cfg(target_os = "fuchsia")]
735impl From<fidl::Channel> for AdvertisingHandleSynchronousProxy {
736    fn from(value: fidl::Channel) -> Self {
737        Self::new(value)
738    }
739}
740
741#[derive(Debug, Clone)]
742pub struct AdvertisingHandleProxy {
743    client: fidl::client::Client<fidl::encoding::DefaultFuchsiaResourceDialect>,
744}
745
746impl fidl::endpoints::Proxy for AdvertisingHandleProxy {
747    type Protocol = AdvertisingHandleMarker;
748
749    fn from_channel(inner: ::fidl::AsyncChannel) -> Self {
750        Self::new(inner)
751    }
752
753    fn into_channel(self) -> Result<::fidl::AsyncChannel, Self> {
754        self.client.into_channel().map_err(|client| Self { client })
755    }
756
757    fn as_channel(&self) -> &::fidl::AsyncChannel {
758        self.client.as_channel()
759    }
760}
761
762impl AdvertisingHandleProxy {
763    /// Create a new Proxy for fuchsia.bluetooth.le/AdvertisingHandle.
764    pub fn new(channel: ::fidl::AsyncChannel) -> Self {
765        let protocol_name =
766            <AdvertisingHandleMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME;
767        Self { client: fidl::client::Client::new(channel, protocol_name) }
768    }
769
770    /// Get a Stream of events from the remote end of the protocol.
771    ///
772    /// # Panics
773    ///
774    /// Panics if the event stream was already taken.
775    pub fn take_event_stream(&self) -> AdvertisingHandleEventStream {
776        AdvertisingHandleEventStream { event_receiver: self.client.take_event_receiver() }
777    }
778}
779
780impl AdvertisingHandleProxyInterface for AdvertisingHandleProxy {}
781
782pub struct AdvertisingHandleEventStream {
783    event_receiver: fidl::client::EventReceiver<fidl::encoding::DefaultFuchsiaResourceDialect>,
784}
785
786impl std::marker::Unpin for AdvertisingHandleEventStream {}
787
788impl futures::stream::FusedStream for AdvertisingHandleEventStream {
789    fn is_terminated(&self) -> bool {
790        self.event_receiver.is_terminated()
791    }
792}
793
794impl futures::Stream for AdvertisingHandleEventStream {
795    type Item = Result<AdvertisingHandleEvent, fidl::Error>;
796
797    fn poll_next(
798        mut self: std::pin::Pin<&mut Self>,
799        cx: &mut std::task::Context<'_>,
800    ) -> std::task::Poll<Option<Self::Item>> {
801        match futures::ready!(futures::stream::StreamExt::poll_next_unpin(
802            &mut self.event_receiver,
803            cx
804        )?) {
805            Some(buf) => std::task::Poll::Ready(Some(AdvertisingHandleEvent::decode(buf))),
806            None => std::task::Poll::Ready(None),
807        }
808    }
809}
810
811#[derive(Debug)]
812pub enum AdvertisingHandleEvent {}
813
814impl AdvertisingHandleEvent {
815    /// Decodes a message buffer as a [`AdvertisingHandleEvent`].
816    fn decode(
817        mut buf: <fidl::encoding::DefaultFuchsiaResourceDialect as fidl::encoding::ResourceDialect>::MessageBufEtc,
818    ) -> Result<AdvertisingHandleEvent, fidl::Error> {
819        let (bytes, _handles) = buf.split_mut();
820        let (tx_header, _body_bytes) = fidl::encoding::decode_transaction_header(bytes)?;
821        debug_assert_eq!(tx_header.tx_id, 0);
822        match tx_header.ordinal {
823            _ => Err(fidl::Error::UnknownOrdinal {
824                ordinal: tx_header.ordinal,
825                protocol_name:
826                    <AdvertisingHandleMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME,
827            }),
828        }
829    }
830}
831
832/// A Stream of incoming requests for fuchsia.bluetooth.le/AdvertisingHandle.
833pub struct AdvertisingHandleRequestStream {
834    inner: std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>,
835    is_terminated: bool,
836}
837
838impl std::marker::Unpin for AdvertisingHandleRequestStream {}
839
840impl futures::stream::FusedStream for AdvertisingHandleRequestStream {
841    fn is_terminated(&self) -> bool {
842        self.is_terminated
843    }
844}
845
846impl fidl::endpoints::RequestStream for AdvertisingHandleRequestStream {
847    type Protocol = AdvertisingHandleMarker;
848    type ControlHandle = AdvertisingHandleControlHandle;
849
850    fn from_channel(channel: ::fidl::AsyncChannel) -> Self {
851        Self { inner: std::sync::Arc::new(fidl::ServeInner::new(channel)), is_terminated: false }
852    }
853
854    fn control_handle(&self) -> Self::ControlHandle {
855        AdvertisingHandleControlHandle { inner: self.inner.clone() }
856    }
857
858    fn into_inner(
859        self,
860    ) -> (::std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>, bool)
861    {
862        (self.inner, self.is_terminated)
863    }
864
865    fn from_inner(
866        inner: std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>,
867        is_terminated: bool,
868    ) -> Self {
869        Self { inner, is_terminated }
870    }
871}
872
873impl futures::Stream for AdvertisingHandleRequestStream {
874    type Item = Result<AdvertisingHandleRequest, fidl::Error>;
875
876    fn poll_next(
877        mut self: std::pin::Pin<&mut Self>,
878        cx: &mut std::task::Context<'_>,
879    ) -> std::task::Poll<Option<Self::Item>> {
880        let this = &mut *self;
881        if this.inner.check_shutdown(cx) {
882            this.is_terminated = true;
883            return std::task::Poll::Ready(None);
884        }
885        if this.is_terminated {
886            panic!("polled AdvertisingHandleRequestStream after completion");
887        }
888        fidl::encoding::with_tls_decode_buf::<_, fidl::encoding::DefaultFuchsiaResourceDialect>(
889            |bytes, handles| {
890                match this.inner.channel().read_etc(cx, bytes, handles) {
891                    std::task::Poll::Ready(Ok(())) => {}
892                    std::task::Poll::Pending => return std::task::Poll::Pending,
893                    std::task::Poll::Ready(Err(zx_status::Status::PEER_CLOSED)) => {
894                        this.is_terminated = true;
895                        return std::task::Poll::Ready(None);
896                    }
897                    std::task::Poll::Ready(Err(e)) => {
898                        return std::task::Poll::Ready(Some(Err(fidl::Error::ServerRequestRead(
899                            e.into(),
900                        ))))
901                    }
902                }
903
904                // A message has been received from the channel
905                let (header, _body_bytes) = fidl::encoding::decode_transaction_header(bytes)?;
906
907                std::task::Poll::Ready(Some(match header.ordinal {
908                    _ => Err(fidl::Error::UnknownOrdinal {
909                        ordinal: header.ordinal,
910                        protocol_name:
911                            <AdvertisingHandleMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME,
912                    }),
913                }))
914            },
915        )
916    }
917}
918
919/// Capability that is valid for the duration of advertising. The caller can close the handle to
920/// stop advertising. If the system internally stops advertising for any reason, the handle will be
921/// closed to communicate this to the client.
922#[derive(Debug)]
923pub enum AdvertisingHandleRequest {}
924
925impl AdvertisingHandleRequest {
926    /// Name of the method defined in FIDL
927    pub fn method_name(&self) -> &'static str {
928        match *self {}
929    }
930}
931
932#[derive(Debug, Clone)]
933pub struct AdvertisingHandleControlHandle {
934    inner: std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>,
935}
936
937impl fidl::endpoints::ControlHandle for AdvertisingHandleControlHandle {
938    fn shutdown(&self) {
939        self.inner.shutdown()
940    }
941    fn shutdown_with_epitaph(&self, status: zx_status::Status) {
942        self.inner.shutdown_with_epitaph(status)
943    }
944
945    fn is_closed(&self) -> bool {
946        self.inner.channel().is_closed()
947    }
948    fn on_closed(&self) -> fidl::OnSignalsRef<'_> {
949        self.inner.channel().on_closed()
950    }
951
952    #[cfg(target_os = "fuchsia")]
953    fn signal_peer(
954        &self,
955        clear_mask: zx::Signals,
956        set_mask: zx::Signals,
957    ) -> Result<(), zx_status::Status> {
958        use fidl::Peered;
959        self.inner.channel().signal_peer(clear_mask, set_mask)
960    }
961}
962
963impl AdvertisingHandleControlHandle {}
964
965#[derive(Debug, Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Hash)]
966pub struct CentralMarker;
967
968impl fidl::endpoints::ProtocolMarker for CentralMarker {
969    type Proxy = CentralProxy;
970    type RequestStream = CentralRequestStream;
971    #[cfg(target_os = "fuchsia")]
972    type SynchronousProxy = CentralSynchronousProxy;
973
974    const DEBUG_NAME: &'static str = "fuchsia.bluetooth.le.Central";
975}
976impl fidl::endpoints::DiscoverableProtocolMarker for CentralMarker {}
977
978pub trait CentralProxyInterface: Send + Sync {
979    type ListenL2capResponseFut: std::future::Future<Output = Result<ChannelListenerRegistryListenL2capResult, fidl::Error>>
980        + Send;
981    fn r#listen_l2cap(
982        &self,
983        payload: ChannelListenerRegistryListenL2capRequest,
984    ) -> Self::ListenL2capResponseFut;
985    type ScanResponseFut: std::future::Future<Output = Result<(), fidl::Error>> + Send;
986    fn r#scan(
987        &self,
988        options: &ScanOptions,
989        result_watcher: fidl::endpoints::ServerEnd<ScanResultWatcherMarker>,
990    ) -> Self::ScanResponseFut;
991    fn r#connect(
992        &self,
993        id: &fidl_fuchsia_bluetooth::PeerId,
994        options: &ConnectionOptions,
995        handle: fidl::endpoints::ServerEnd<ConnectionMarker>,
996    ) -> Result<(), fidl::Error>;
997    type GetPeripheralsResponseFut: std::future::Future<Output = Result<Vec<RemoteDevice>, fidl::Error>>
998        + Send;
999    fn r#get_peripherals(
1000        &self,
1001        service_uuids: Option<&[String]>,
1002    ) -> Self::GetPeripheralsResponseFut;
1003    type GetPeripheralResponseFut: std::future::Future<Output = Result<Option<Box<RemoteDevice>>, fidl::Error>>
1004        + Send;
1005    fn r#get_peripheral(&self, identifier: &str) -> Self::GetPeripheralResponseFut;
1006    type StartScanResponseFut: std::future::Future<Output = Result<fidl_fuchsia_bluetooth::Status, fidl::Error>>
1007        + Send;
1008    fn r#start_scan(&self, filter: Option<&ScanFilter>) -> Self::StartScanResponseFut;
1009    fn r#stop_scan(&self) -> Result<(), fidl::Error>;
1010    type ConnectPeripheralResponseFut: std::future::Future<Output = Result<fidl_fuchsia_bluetooth::Status, fidl::Error>>
1011        + Send;
1012    fn r#connect_peripheral(
1013        &self,
1014        identifier: &str,
1015        options: &ConnectionOptions,
1016        gatt_client: fidl::endpoints::ServerEnd<fidl_fuchsia_bluetooth_gatt::ClientMarker>,
1017    ) -> Self::ConnectPeripheralResponseFut;
1018    type DisconnectPeripheralResponseFut: std::future::Future<Output = Result<fidl_fuchsia_bluetooth::Status, fidl::Error>>
1019        + Send;
1020    fn r#disconnect_peripheral(&self, identifier: &str) -> Self::DisconnectPeripheralResponseFut;
1021}
1022#[derive(Debug)]
1023#[cfg(target_os = "fuchsia")]
1024pub struct CentralSynchronousProxy {
1025    client: fidl::client::sync::Client,
1026}
1027
1028#[cfg(target_os = "fuchsia")]
1029impl fidl::endpoints::SynchronousProxy for CentralSynchronousProxy {
1030    type Proxy = CentralProxy;
1031    type Protocol = CentralMarker;
1032
1033    fn from_channel(inner: fidl::Channel) -> Self {
1034        Self::new(inner)
1035    }
1036
1037    fn into_channel(self) -> fidl::Channel {
1038        self.client.into_channel()
1039    }
1040
1041    fn as_channel(&self) -> &fidl::Channel {
1042        self.client.as_channel()
1043    }
1044}
1045
1046#[cfg(target_os = "fuchsia")]
1047impl CentralSynchronousProxy {
1048    pub fn new(channel: fidl::Channel) -> Self {
1049        let protocol_name = <CentralMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME;
1050        Self { client: fidl::client::sync::Client::new(channel, protocol_name) }
1051    }
1052
1053    pub fn into_channel(self) -> fidl::Channel {
1054        self.client.into_channel()
1055    }
1056
1057    /// Waits until an event arrives and returns it. It is safe for other
1058    /// threads to make concurrent requests while waiting for an event.
1059    pub fn wait_for_event(
1060        &self,
1061        deadline: zx::MonotonicInstant,
1062    ) -> Result<CentralEvent, fidl::Error> {
1063        CentralEvent::decode(self.client.wait_for_event(deadline)?)
1064    }
1065
1066    /// Register a listener for incoming channels. The registry will assign a
1067    /// PSM value that is unique for the local device, as well as open a
1068    /// [`ChannelListener`] for accepting incoming channels. In the unlikely
1069    /// event that all PSMs have been assigned, this call will fail with
1070    /// `ZX_ERR_NO_RESOURCES`.
1071    ///
1072    /// Note that the method of service discovery or advertising is defined by
1073    /// the service or protocol, so it is the responsibility of the caller to
1074    /// communicate the assigned PSM to any clients.
1075    pub fn r#listen_l2cap(
1076        &self,
1077        mut payload: ChannelListenerRegistryListenL2capRequest,
1078        ___deadline: zx::MonotonicInstant,
1079    ) -> Result<ChannelListenerRegistryListenL2capResult, fidl::Error> {
1080        let _response = self.client.send_query::<
1081            ChannelListenerRegistryListenL2capRequest,
1082            fidl::encoding::ResultType<ChannelListenerRegistryListenL2capResponse, i32>,
1083        >(
1084            &mut payload,
1085            0x39c6e9001d102338,
1086            fidl::encoding::DynamicFlags::empty(),
1087            ___deadline,
1088        )?;
1089        Ok(_response.map(|x| x))
1090    }
1091
1092    /// Scans for nearby LE peripherals and broadcasters. If the scan cannot be
1093    /// initiated, then `result_watcher` will be closed with an epitaph.
1094    ///
1095    /// A Central client is allowed to have only one active scan at a time.
1096    /// Accordingly, only one Scan request can be outstanding at a time.
1097    /// Additional calls to Scan will fail.
1098    ///
1099    /// The lifetime of the scan session is tied to the `result_watcher`
1100    /// protocol provided. The scan will be stopped if the channel is closed.
1101    ///
1102    /// Once a scan is started, the [`fuchsia.bluetooth.le/ScanResultWatcher`]
1103    /// can be used to watch for scan results.
1104    ///
1105    /// + request `options` Options used to configure the scan session.
1106    /// + request `result_watcher` Protocol that remains valid for the duration
1107    ///   of this scan session.
1108    /// - response An empty response will be sent to acknowledge the scan has
1109    ///   stopped.
1110    ///
1111    /// The following epitaphs may be sent by the server on error:
1112    /// * error `ALREADY_EXISTS`: A scan is already in progress. Each `Central`
1113    ///   protocol is only allowed 1 active scan.
1114    /// * error `INVALID_ARGS`: Some of the scan `options` are invalid. See the
1115    ///   `ScanOptions` documentation.
1116    /// * error `INTERNAL`: An internal error occurred and a scan could not be
1117    ///   started.
1118    pub fn r#scan(
1119        &self,
1120        mut options: &ScanOptions,
1121        mut result_watcher: fidl::endpoints::ServerEnd<ScanResultWatcherMarker>,
1122        ___deadline: zx::MonotonicInstant,
1123    ) -> Result<(), fidl::Error> {
1124        let _response =
1125            self.client.send_query::<CentralScanRequest, fidl::encoding::EmptyPayload>(
1126                (options, result_watcher),
1127                0x41f7121798dfe15f,
1128                fidl::encoding::DynamicFlags::empty(),
1129                ___deadline,
1130            )?;
1131        Ok(_response)
1132    }
1133
1134    /// Connect to the peer with the given identifier.
1135    ///
1136    /// The requested [`fuchsia.bluetooth.le/Connection`] represents the
1137    /// client's interest on the LE connection to the peer. Closing the channel
1138    /// removes interest, but may not result in disconnection if another client
1139    /// holds a valid [`fuchsia.bluetooth.le/Connection`] to the same peer.
1140    ///
1141    /// The [`fuchsia.bluetooth.le/Connection`] `handle` will be closed by the
1142    /// system if the connection to the peer is lost or an error occurs.
1143    ///
1144    /// The following epitaphs may be sent by the server on error:
1145    /// + `INVALID_ARGS`: Some of the parameters are invalid.
1146    /// + `ALREADY_BOUND`: A Connection to the peer already exists for this Central. The existing
1147    ///                    Connection should be used.
1148    /// + `NOT_CONNECTED`: A connection could not be established.
1149    /// + `CONNECTION_RESET`: The peer disconnected.
1150    ///
1151    /// + request `id` Identifier of the peer to initiate a connection to.
1152    /// + request `options` Options used to configure the connection.
1153    /// + request `handle` Handle that remains valid for the duration of this
1154    ///   connection.
1155    pub fn r#connect(
1156        &self,
1157        mut id: &fidl_fuchsia_bluetooth::PeerId,
1158        mut options: &ConnectionOptions,
1159        mut handle: fidl::endpoints::ServerEnd<ConnectionMarker>,
1160    ) -> Result<(), fidl::Error> {
1161        self.client.send::<CentralConnectRequest>(
1162            (id, options, handle),
1163            0x31a3065f2a6913c4,
1164            fidl::encoding::DynamicFlags::empty(),
1165        )
1166    }
1167
1168    /// Returns the list of peripherals that are known to the system from previous scan, connection,
1169    /// and/or bonding procedures. The results can be filtered based on service UUIDs that are known to
1170    /// be present on the peripheral.
1171    ///
1172    /// This method only returns peripherals (i.e. connectable devices).
1173    pub fn r#get_peripherals(
1174        &self,
1175        mut service_uuids: Option<&[String]>,
1176        ___deadline: zx::MonotonicInstant,
1177    ) -> Result<Vec<RemoteDevice>, fidl::Error> {
1178        let _response =
1179            self.client.send_query::<CentralGetPeripheralsRequest, CentralGetPeripheralsResponse>(
1180                (service_uuids,),
1181                0x37ba777499c683a8,
1182                fidl::encoding::DynamicFlags::empty(),
1183                ___deadline,
1184            )?;
1185        Ok(_response.peripherals)
1186    }
1187
1188    /// **This method is not implemented by the Fuchsia core stack- TODO(https://fxbug.dev/42087303)**
1189    ///
1190    /// Returns information about a single peripheral that is known to the system from previous scan,
1191    /// connection, and/or bonding procedures based on its unique identifier. Returns null if
1192    /// `identifier` is not recognized.
1193    pub fn r#get_peripheral(
1194        &self,
1195        mut identifier: &str,
1196        ___deadline: zx::MonotonicInstant,
1197    ) -> Result<Option<Box<RemoteDevice>>, fidl::Error> {
1198        let _response =
1199            self.client.send_query::<CentralGetPeripheralRequest, CentralGetPeripheralResponse>(
1200                (identifier,),
1201                0x97f5a2f2d9c13da,
1202                fidl::encoding::DynamicFlags::empty(),
1203                ___deadline,
1204            )?;
1205        Ok(_response.peripheral)
1206    }
1207
1208    /// Initiates a scan session for nearby peripherals and broadcasters. Discovered devices will be
1209    /// reported via CentralDelegate.OnDeviceDiscovered(). If a scan session is already in progress,
1210    /// `filter` will replace the existing session's filter.
1211    ///
1212    /// If `filter` is null or empty (i.e. none of its fields has been populated) then the delegate
1213    /// will be notified for all discoverable devices that are found. This is not recommended; clients
1214    /// should generally filter results by at least one of `filter.service_uuids`,
1215    /// `filter.service_data`, and/or `filter.manufacturer_identifier`.
1216    pub fn r#start_scan(
1217        &self,
1218        mut filter: Option<&ScanFilter>,
1219        ___deadline: zx::MonotonicInstant,
1220    ) -> Result<fidl_fuchsia_bluetooth::Status, fidl::Error> {
1221        let _response =
1222            self.client.send_query::<CentralStartScanRequest, CentralStartScanResponse>(
1223                (filter,),
1224                0xeb4cf0cd0e1132b,
1225                fidl::encoding::DynamicFlags::empty(),
1226                ___deadline,
1227            )?;
1228        Ok(_response.status)
1229    }
1230
1231    /// Terminate a previously started scan session.
1232    pub fn r#stop_scan(&self) -> Result<(), fidl::Error> {
1233        self.client.send::<fidl::encoding::EmptyPayload>(
1234            (),
1235            0x5f79ee6a0bb037a0,
1236            fidl::encoding::DynamicFlags::empty(),
1237        )
1238    }
1239
1240    /// Creates a connection to the peripheral device with the given identifier.
1241    /// Returns the status of the operation in `status`.
1242    ///
1243    /// On success, `gatt_client` will be bound and can be used for GATT client
1244    /// role procedures. On failure, `gatt_client` will be closed and `status` will
1245    /// indicate an error.
1246    pub fn r#connect_peripheral(
1247        &self,
1248        mut identifier: &str,
1249        mut options: &ConnectionOptions,
1250        mut gatt_client: fidl::endpoints::ServerEnd<fidl_fuchsia_bluetooth_gatt::ClientMarker>,
1251        ___deadline: zx::MonotonicInstant,
1252    ) -> Result<fidl_fuchsia_bluetooth::Status, fidl::Error> {
1253        let _response = self
1254            .client
1255            .send_query::<CentralConnectPeripheralRequest, CentralConnectPeripheralResponse>(
1256                (identifier, options, gatt_client),
1257                0x714d6c32d066d75a,
1258                fidl::encoding::DynamicFlags::empty(),
1259                ___deadline,
1260            )?;
1261        Ok(_response.status)
1262    }
1263
1264    /// Disconnects this Central's connection to the peripheral with the given identifier.
1265    pub fn r#disconnect_peripheral(
1266        &self,
1267        mut identifier: &str,
1268        ___deadline: zx::MonotonicInstant,
1269    ) -> Result<fidl_fuchsia_bluetooth::Status, fidl::Error> {
1270        let _response = self
1271            .client
1272            .send_query::<CentralDisconnectPeripheralRequest, CentralDisconnectPeripheralResponse>(
1273                (identifier,),
1274                0xa9430da197362fd,
1275                fidl::encoding::DynamicFlags::empty(),
1276                ___deadline,
1277            )?;
1278        Ok(_response.status)
1279    }
1280}
1281
1282#[cfg(target_os = "fuchsia")]
1283impl From<CentralSynchronousProxy> for zx::Handle {
1284    fn from(value: CentralSynchronousProxy) -> Self {
1285        value.into_channel().into()
1286    }
1287}
1288
1289#[cfg(target_os = "fuchsia")]
1290impl From<fidl::Channel> for CentralSynchronousProxy {
1291    fn from(value: fidl::Channel) -> Self {
1292        Self::new(value)
1293    }
1294}
1295
1296#[derive(Debug, Clone)]
1297pub struct CentralProxy {
1298    client: fidl::client::Client<fidl::encoding::DefaultFuchsiaResourceDialect>,
1299}
1300
1301impl fidl::endpoints::Proxy for CentralProxy {
1302    type Protocol = CentralMarker;
1303
1304    fn from_channel(inner: ::fidl::AsyncChannel) -> Self {
1305        Self::new(inner)
1306    }
1307
1308    fn into_channel(self) -> Result<::fidl::AsyncChannel, Self> {
1309        self.client.into_channel().map_err(|client| Self { client })
1310    }
1311
1312    fn as_channel(&self) -> &::fidl::AsyncChannel {
1313        self.client.as_channel()
1314    }
1315}
1316
1317impl CentralProxy {
1318    /// Create a new Proxy for fuchsia.bluetooth.le/Central.
1319    pub fn new(channel: ::fidl::AsyncChannel) -> Self {
1320        let protocol_name = <CentralMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME;
1321        Self { client: fidl::client::Client::new(channel, protocol_name) }
1322    }
1323
1324    /// Get a Stream of events from the remote end of the protocol.
1325    ///
1326    /// # Panics
1327    ///
1328    /// Panics if the event stream was already taken.
1329    pub fn take_event_stream(&self) -> CentralEventStream {
1330        CentralEventStream { event_receiver: self.client.take_event_receiver() }
1331    }
1332
1333    /// Register a listener for incoming channels. The registry will assign a
1334    /// PSM value that is unique for the local device, as well as open a
1335    /// [`ChannelListener`] for accepting incoming channels. In the unlikely
1336    /// event that all PSMs have been assigned, this call will fail with
1337    /// `ZX_ERR_NO_RESOURCES`.
1338    ///
1339    /// Note that the method of service discovery or advertising is defined by
1340    /// the service or protocol, so it is the responsibility of the caller to
1341    /// communicate the assigned PSM to any clients.
1342    pub fn r#listen_l2cap(
1343        &self,
1344        mut payload: ChannelListenerRegistryListenL2capRequest,
1345    ) -> fidl::client::QueryResponseFut<
1346        ChannelListenerRegistryListenL2capResult,
1347        fidl::encoding::DefaultFuchsiaResourceDialect,
1348    > {
1349        CentralProxyInterface::r#listen_l2cap(self, payload)
1350    }
1351
1352    /// Scans for nearby LE peripherals and broadcasters. If the scan cannot be
1353    /// initiated, then `result_watcher` will be closed with an epitaph.
1354    ///
1355    /// A Central client is allowed to have only one active scan at a time.
1356    /// Accordingly, only one Scan request can be outstanding at a time.
1357    /// Additional calls to Scan will fail.
1358    ///
1359    /// The lifetime of the scan session is tied to the `result_watcher`
1360    /// protocol provided. The scan will be stopped if the channel is closed.
1361    ///
1362    /// Once a scan is started, the [`fuchsia.bluetooth.le/ScanResultWatcher`]
1363    /// can be used to watch for scan results.
1364    ///
1365    /// + request `options` Options used to configure the scan session.
1366    /// + request `result_watcher` Protocol that remains valid for the duration
1367    ///   of this scan session.
1368    /// - response An empty response will be sent to acknowledge the scan has
1369    ///   stopped.
1370    ///
1371    /// The following epitaphs may be sent by the server on error:
1372    /// * error `ALREADY_EXISTS`: A scan is already in progress. Each `Central`
1373    ///   protocol is only allowed 1 active scan.
1374    /// * error `INVALID_ARGS`: Some of the scan `options` are invalid. See the
1375    ///   `ScanOptions` documentation.
1376    /// * error `INTERNAL`: An internal error occurred and a scan could not be
1377    ///   started.
1378    pub fn r#scan(
1379        &self,
1380        mut options: &ScanOptions,
1381        mut result_watcher: fidl::endpoints::ServerEnd<ScanResultWatcherMarker>,
1382    ) -> fidl::client::QueryResponseFut<(), fidl::encoding::DefaultFuchsiaResourceDialect> {
1383        CentralProxyInterface::r#scan(self, options, result_watcher)
1384    }
1385
1386    /// Connect to the peer with the given identifier.
1387    ///
1388    /// The requested [`fuchsia.bluetooth.le/Connection`] represents the
1389    /// client's interest on the LE connection to the peer. Closing the channel
1390    /// removes interest, but may not result in disconnection if another client
1391    /// holds a valid [`fuchsia.bluetooth.le/Connection`] to the same peer.
1392    ///
1393    /// The [`fuchsia.bluetooth.le/Connection`] `handle` will be closed by the
1394    /// system if the connection to the peer is lost or an error occurs.
1395    ///
1396    /// The following epitaphs may be sent by the server on error:
1397    /// + `INVALID_ARGS`: Some of the parameters are invalid.
1398    /// + `ALREADY_BOUND`: A Connection to the peer already exists for this Central. The existing
1399    ///                    Connection should be used.
1400    /// + `NOT_CONNECTED`: A connection could not be established.
1401    /// + `CONNECTION_RESET`: The peer disconnected.
1402    ///
1403    /// + request `id` Identifier of the peer to initiate a connection to.
1404    /// + request `options` Options used to configure the connection.
1405    /// + request `handle` Handle that remains valid for the duration of this
1406    ///   connection.
1407    pub fn r#connect(
1408        &self,
1409        mut id: &fidl_fuchsia_bluetooth::PeerId,
1410        mut options: &ConnectionOptions,
1411        mut handle: fidl::endpoints::ServerEnd<ConnectionMarker>,
1412    ) -> Result<(), fidl::Error> {
1413        CentralProxyInterface::r#connect(self, id, options, handle)
1414    }
1415
1416    /// Returns the list of peripherals that are known to the system from previous scan, connection,
1417    /// and/or bonding procedures. The results can be filtered based on service UUIDs that are known to
1418    /// be present on the peripheral.
1419    ///
1420    /// This method only returns peripherals (i.e. connectable devices).
1421    pub fn r#get_peripherals(
1422        &self,
1423        mut service_uuids: Option<&[String]>,
1424    ) -> fidl::client::QueryResponseFut<
1425        Vec<RemoteDevice>,
1426        fidl::encoding::DefaultFuchsiaResourceDialect,
1427    > {
1428        CentralProxyInterface::r#get_peripherals(self, service_uuids)
1429    }
1430
1431    /// **This method is not implemented by the Fuchsia core stack- TODO(https://fxbug.dev/42087303)**
1432    ///
1433    /// Returns information about a single peripheral that is known to the system from previous scan,
1434    /// connection, and/or bonding procedures based on its unique identifier. Returns null if
1435    /// `identifier` is not recognized.
1436    pub fn r#get_peripheral(
1437        &self,
1438        mut identifier: &str,
1439    ) -> fidl::client::QueryResponseFut<
1440        Option<Box<RemoteDevice>>,
1441        fidl::encoding::DefaultFuchsiaResourceDialect,
1442    > {
1443        CentralProxyInterface::r#get_peripheral(self, identifier)
1444    }
1445
1446    /// Initiates a scan session for nearby peripherals and broadcasters. Discovered devices will be
1447    /// reported via CentralDelegate.OnDeviceDiscovered(). If a scan session is already in progress,
1448    /// `filter` will replace the existing session's filter.
1449    ///
1450    /// If `filter` is null or empty (i.e. none of its fields has been populated) then the delegate
1451    /// will be notified for all discoverable devices that are found. This is not recommended; clients
1452    /// should generally filter results by at least one of `filter.service_uuids`,
1453    /// `filter.service_data`, and/or `filter.manufacturer_identifier`.
1454    pub fn r#start_scan(
1455        &self,
1456        mut filter: Option<&ScanFilter>,
1457    ) -> fidl::client::QueryResponseFut<
1458        fidl_fuchsia_bluetooth::Status,
1459        fidl::encoding::DefaultFuchsiaResourceDialect,
1460    > {
1461        CentralProxyInterface::r#start_scan(self, filter)
1462    }
1463
1464    /// Terminate a previously started scan session.
1465    pub fn r#stop_scan(&self) -> Result<(), fidl::Error> {
1466        CentralProxyInterface::r#stop_scan(self)
1467    }
1468
1469    /// Creates a connection to the peripheral device with the given identifier.
1470    /// Returns the status of the operation in `status`.
1471    ///
1472    /// On success, `gatt_client` will be bound and can be used for GATT client
1473    /// role procedures. On failure, `gatt_client` will be closed and `status` will
1474    /// indicate an error.
1475    pub fn r#connect_peripheral(
1476        &self,
1477        mut identifier: &str,
1478        mut options: &ConnectionOptions,
1479        mut gatt_client: fidl::endpoints::ServerEnd<fidl_fuchsia_bluetooth_gatt::ClientMarker>,
1480    ) -> fidl::client::QueryResponseFut<
1481        fidl_fuchsia_bluetooth::Status,
1482        fidl::encoding::DefaultFuchsiaResourceDialect,
1483    > {
1484        CentralProxyInterface::r#connect_peripheral(self, identifier, options, gatt_client)
1485    }
1486
1487    /// Disconnects this Central's connection to the peripheral with the given identifier.
1488    pub fn r#disconnect_peripheral(
1489        &self,
1490        mut identifier: &str,
1491    ) -> fidl::client::QueryResponseFut<
1492        fidl_fuchsia_bluetooth::Status,
1493        fidl::encoding::DefaultFuchsiaResourceDialect,
1494    > {
1495        CentralProxyInterface::r#disconnect_peripheral(self, identifier)
1496    }
1497}
1498
1499impl CentralProxyInterface for CentralProxy {
1500    type ListenL2capResponseFut = fidl::client::QueryResponseFut<
1501        ChannelListenerRegistryListenL2capResult,
1502        fidl::encoding::DefaultFuchsiaResourceDialect,
1503    >;
1504    fn r#listen_l2cap(
1505        &self,
1506        mut payload: ChannelListenerRegistryListenL2capRequest,
1507    ) -> Self::ListenL2capResponseFut {
1508        fn _decode(
1509            mut _buf: Result<<fidl::encoding::DefaultFuchsiaResourceDialect as fidl::encoding::ResourceDialect>::MessageBufEtc, fidl::Error>,
1510        ) -> Result<ChannelListenerRegistryListenL2capResult, fidl::Error> {
1511            let _response = fidl::client::decode_transaction_body::<
1512                fidl::encoding::ResultType<ChannelListenerRegistryListenL2capResponse, i32>,
1513                fidl::encoding::DefaultFuchsiaResourceDialect,
1514                0x39c6e9001d102338,
1515            >(_buf?)?;
1516            Ok(_response.map(|x| x))
1517        }
1518        self.client.send_query_and_decode::<
1519            ChannelListenerRegistryListenL2capRequest,
1520            ChannelListenerRegistryListenL2capResult,
1521        >(
1522            &mut payload,
1523            0x39c6e9001d102338,
1524            fidl::encoding::DynamicFlags::empty(),
1525            _decode,
1526        )
1527    }
1528
1529    type ScanResponseFut =
1530        fidl::client::QueryResponseFut<(), fidl::encoding::DefaultFuchsiaResourceDialect>;
1531    fn r#scan(
1532        &self,
1533        mut options: &ScanOptions,
1534        mut result_watcher: fidl::endpoints::ServerEnd<ScanResultWatcherMarker>,
1535    ) -> Self::ScanResponseFut {
1536        fn _decode(
1537            mut _buf: Result<<fidl::encoding::DefaultFuchsiaResourceDialect as fidl::encoding::ResourceDialect>::MessageBufEtc, fidl::Error>,
1538        ) -> Result<(), fidl::Error> {
1539            let _response = fidl::client::decode_transaction_body::<
1540                fidl::encoding::EmptyPayload,
1541                fidl::encoding::DefaultFuchsiaResourceDialect,
1542                0x41f7121798dfe15f,
1543            >(_buf?)?;
1544            Ok(_response)
1545        }
1546        self.client.send_query_and_decode::<CentralScanRequest, ()>(
1547            (options, result_watcher),
1548            0x41f7121798dfe15f,
1549            fidl::encoding::DynamicFlags::empty(),
1550            _decode,
1551        )
1552    }
1553
1554    fn r#connect(
1555        &self,
1556        mut id: &fidl_fuchsia_bluetooth::PeerId,
1557        mut options: &ConnectionOptions,
1558        mut handle: fidl::endpoints::ServerEnd<ConnectionMarker>,
1559    ) -> Result<(), fidl::Error> {
1560        self.client.send::<CentralConnectRequest>(
1561            (id, options, handle),
1562            0x31a3065f2a6913c4,
1563            fidl::encoding::DynamicFlags::empty(),
1564        )
1565    }
1566
1567    type GetPeripheralsResponseFut = fidl::client::QueryResponseFut<
1568        Vec<RemoteDevice>,
1569        fidl::encoding::DefaultFuchsiaResourceDialect,
1570    >;
1571    fn r#get_peripherals(
1572        &self,
1573        mut service_uuids: Option<&[String]>,
1574    ) -> Self::GetPeripheralsResponseFut {
1575        fn _decode(
1576            mut _buf: Result<<fidl::encoding::DefaultFuchsiaResourceDialect as fidl::encoding::ResourceDialect>::MessageBufEtc, fidl::Error>,
1577        ) -> Result<Vec<RemoteDevice>, fidl::Error> {
1578            let _response = fidl::client::decode_transaction_body::<
1579                CentralGetPeripheralsResponse,
1580                fidl::encoding::DefaultFuchsiaResourceDialect,
1581                0x37ba777499c683a8,
1582            >(_buf?)?;
1583            Ok(_response.peripherals)
1584        }
1585        self.client.send_query_and_decode::<CentralGetPeripheralsRequest, Vec<RemoteDevice>>(
1586            (service_uuids,),
1587            0x37ba777499c683a8,
1588            fidl::encoding::DynamicFlags::empty(),
1589            _decode,
1590        )
1591    }
1592
1593    type GetPeripheralResponseFut = fidl::client::QueryResponseFut<
1594        Option<Box<RemoteDevice>>,
1595        fidl::encoding::DefaultFuchsiaResourceDialect,
1596    >;
1597    fn r#get_peripheral(&self, mut identifier: &str) -> Self::GetPeripheralResponseFut {
1598        fn _decode(
1599            mut _buf: Result<<fidl::encoding::DefaultFuchsiaResourceDialect as fidl::encoding::ResourceDialect>::MessageBufEtc, fidl::Error>,
1600        ) -> Result<Option<Box<RemoteDevice>>, fidl::Error> {
1601            let _response = fidl::client::decode_transaction_body::<
1602                CentralGetPeripheralResponse,
1603                fidl::encoding::DefaultFuchsiaResourceDialect,
1604                0x97f5a2f2d9c13da,
1605            >(_buf?)?;
1606            Ok(_response.peripheral)
1607        }
1608        self.client.send_query_and_decode::<CentralGetPeripheralRequest, Option<Box<RemoteDevice>>>(
1609            (identifier,),
1610            0x97f5a2f2d9c13da,
1611            fidl::encoding::DynamicFlags::empty(),
1612            _decode,
1613        )
1614    }
1615
1616    type StartScanResponseFut = fidl::client::QueryResponseFut<
1617        fidl_fuchsia_bluetooth::Status,
1618        fidl::encoding::DefaultFuchsiaResourceDialect,
1619    >;
1620    fn r#start_scan(&self, mut filter: Option<&ScanFilter>) -> Self::StartScanResponseFut {
1621        fn _decode(
1622            mut _buf: Result<<fidl::encoding::DefaultFuchsiaResourceDialect as fidl::encoding::ResourceDialect>::MessageBufEtc, fidl::Error>,
1623        ) -> Result<fidl_fuchsia_bluetooth::Status, fidl::Error> {
1624            let _response = fidl::client::decode_transaction_body::<
1625                CentralStartScanResponse,
1626                fidl::encoding::DefaultFuchsiaResourceDialect,
1627                0xeb4cf0cd0e1132b,
1628            >(_buf?)?;
1629            Ok(_response.status)
1630        }
1631        self.client
1632            .send_query_and_decode::<CentralStartScanRequest, fidl_fuchsia_bluetooth::Status>(
1633                (filter,),
1634                0xeb4cf0cd0e1132b,
1635                fidl::encoding::DynamicFlags::empty(),
1636                _decode,
1637            )
1638    }
1639
1640    fn r#stop_scan(&self) -> Result<(), fidl::Error> {
1641        self.client.send::<fidl::encoding::EmptyPayload>(
1642            (),
1643            0x5f79ee6a0bb037a0,
1644            fidl::encoding::DynamicFlags::empty(),
1645        )
1646    }
1647
1648    type ConnectPeripheralResponseFut = fidl::client::QueryResponseFut<
1649        fidl_fuchsia_bluetooth::Status,
1650        fidl::encoding::DefaultFuchsiaResourceDialect,
1651    >;
1652    fn r#connect_peripheral(
1653        &self,
1654        mut identifier: &str,
1655        mut options: &ConnectionOptions,
1656        mut gatt_client: fidl::endpoints::ServerEnd<fidl_fuchsia_bluetooth_gatt::ClientMarker>,
1657    ) -> Self::ConnectPeripheralResponseFut {
1658        fn _decode(
1659            mut _buf: Result<<fidl::encoding::DefaultFuchsiaResourceDialect as fidl::encoding::ResourceDialect>::MessageBufEtc, fidl::Error>,
1660        ) -> Result<fidl_fuchsia_bluetooth::Status, fidl::Error> {
1661            let _response = fidl::client::decode_transaction_body::<
1662                CentralConnectPeripheralResponse,
1663                fidl::encoding::DefaultFuchsiaResourceDialect,
1664                0x714d6c32d066d75a,
1665            >(_buf?)?;
1666            Ok(_response.status)
1667        }
1668        self.client.send_query_and_decode::<
1669            CentralConnectPeripheralRequest,
1670            fidl_fuchsia_bluetooth::Status,
1671        >(
1672            (identifier, options, gatt_client,),
1673            0x714d6c32d066d75a,
1674            fidl::encoding::DynamicFlags::empty(),
1675            _decode,
1676        )
1677    }
1678
1679    type DisconnectPeripheralResponseFut = fidl::client::QueryResponseFut<
1680        fidl_fuchsia_bluetooth::Status,
1681        fidl::encoding::DefaultFuchsiaResourceDialect,
1682    >;
1683    fn r#disconnect_peripheral(
1684        &self,
1685        mut identifier: &str,
1686    ) -> Self::DisconnectPeripheralResponseFut {
1687        fn _decode(
1688            mut _buf: Result<<fidl::encoding::DefaultFuchsiaResourceDialect as fidl::encoding::ResourceDialect>::MessageBufEtc, fidl::Error>,
1689        ) -> Result<fidl_fuchsia_bluetooth::Status, fidl::Error> {
1690            let _response = fidl::client::decode_transaction_body::<
1691                CentralDisconnectPeripheralResponse,
1692                fidl::encoding::DefaultFuchsiaResourceDialect,
1693                0xa9430da197362fd,
1694            >(_buf?)?;
1695            Ok(_response.status)
1696        }
1697        self.client.send_query_and_decode::<
1698            CentralDisconnectPeripheralRequest,
1699            fidl_fuchsia_bluetooth::Status,
1700        >(
1701            (identifier,),
1702            0xa9430da197362fd,
1703            fidl::encoding::DynamicFlags::empty(),
1704            _decode,
1705        )
1706    }
1707}
1708
1709pub struct CentralEventStream {
1710    event_receiver: fidl::client::EventReceiver<fidl::encoding::DefaultFuchsiaResourceDialect>,
1711}
1712
1713impl std::marker::Unpin for CentralEventStream {}
1714
1715impl futures::stream::FusedStream for CentralEventStream {
1716    fn is_terminated(&self) -> bool {
1717        self.event_receiver.is_terminated()
1718    }
1719}
1720
1721impl futures::Stream for CentralEventStream {
1722    type Item = Result<CentralEvent, fidl::Error>;
1723
1724    fn poll_next(
1725        mut self: std::pin::Pin<&mut Self>,
1726        cx: &mut std::task::Context<'_>,
1727    ) -> std::task::Poll<Option<Self::Item>> {
1728        match futures::ready!(futures::stream::StreamExt::poll_next_unpin(
1729            &mut self.event_receiver,
1730            cx
1731        )?) {
1732            Some(buf) => std::task::Poll::Ready(Some(CentralEvent::decode(buf))),
1733            None => std::task::Poll::Ready(None),
1734        }
1735    }
1736}
1737
1738#[derive(Debug)]
1739pub enum CentralEvent {
1740    OnScanStateChanged { scanning: bool },
1741    OnDeviceDiscovered { device: RemoteDevice },
1742    OnPeripheralDisconnected { identifier: String },
1743}
1744
1745impl CentralEvent {
1746    #[allow(irrefutable_let_patterns)]
1747    pub fn into_on_scan_state_changed(self) -> Option<bool> {
1748        if let CentralEvent::OnScanStateChanged { scanning } = self {
1749            Some((scanning))
1750        } else {
1751            None
1752        }
1753    }
1754    #[allow(irrefutable_let_patterns)]
1755    pub fn into_on_device_discovered(self) -> Option<RemoteDevice> {
1756        if let CentralEvent::OnDeviceDiscovered { device } = self {
1757            Some((device))
1758        } else {
1759            None
1760        }
1761    }
1762    #[allow(irrefutable_let_patterns)]
1763    pub fn into_on_peripheral_disconnected(self) -> Option<String> {
1764        if let CentralEvent::OnPeripheralDisconnected { identifier } = self {
1765            Some((identifier))
1766        } else {
1767            None
1768        }
1769    }
1770
1771    /// Decodes a message buffer as a [`CentralEvent`].
1772    fn decode(
1773        mut buf: <fidl::encoding::DefaultFuchsiaResourceDialect as fidl::encoding::ResourceDialect>::MessageBufEtc,
1774    ) -> Result<CentralEvent, fidl::Error> {
1775        let (bytes, _handles) = buf.split_mut();
1776        let (tx_header, _body_bytes) = fidl::encoding::decode_transaction_header(bytes)?;
1777        debug_assert_eq!(tx_header.tx_id, 0);
1778        match tx_header.ordinal {
1779            0x5f8edc23cad04d3f => {
1780                let mut out = fidl::new_empty!(
1781                    CentralOnScanStateChangedRequest,
1782                    fidl::encoding::DefaultFuchsiaResourceDialect
1783                );
1784                fidl::encoding::Decoder::<fidl::encoding::DefaultFuchsiaResourceDialect>::decode_into::<CentralOnScanStateChangedRequest>(&tx_header, _body_bytes, _handles, &mut out)?;
1785                Ok((CentralEvent::OnScanStateChanged { scanning: out.scanning }))
1786            }
1787            0x708dadf20d66db6 => {
1788                let mut out = fidl::new_empty!(
1789                    CentralOnDeviceDiscoveredRequest,
1790                    fidl::encoding::DefaultFuchsiaResourceDialect
1791                );
1792                fidl::encoding::Decoder::<fidl::encoding::DefaultFuchsiaResourceDialect>::decode_into::<CentralOnDeviceDiscoveredRequest>(&tx_header, _body_bytes, _handles, &mut out)?;
1793                Ok((CentralEvent::OnDeviceDiscovered { device: out.device }))
1794            }
1795            0x4e4c6b979b2126df => {
1796                let mut out = fidl::new_empty!(
1797                    CentralOnPeripheralDisconnectedRequest,
1798                    fidl::encoding::DefaultFuchsiaResourceDialect
1799                );
1800                fidl::encoding::Decoder::<fidl::encoding::DefaultFuchsiaResourceDialect>::decode_into::<CentralOnPeripheralDisconnectedRequest>(&tx_header, _body_bytes, _handles, &mut out)?;
1801                Ok((CentralEvent::OnPeripheralDisconnected { identifier: out.identifier }))
1802            }
1803            _ => Err(fidl::Error::UnknownOrdinal {
1804                ordinal: tx_header.ordinal,
1805                protocol_name: <CentralMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME,
1806            }),
1807        }
1808    }
1809}
1810
1811/// A Stream of incoming requests for fuchsia.bluetooth.le/Central.
1812pub struct CentralRequestStream {
1813    inner: std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>,
1814    is_terminated: bool,
1815}
1816
1817impl std::marker::Unpin for CentralRequestStream {}
1818
1819impl futures::stream::FusedStream for CentralRequestStream {
1820    fn is_terminated(&self) -> bool {
1821        self.is_terminated
1822    }
1823}
1824
1825impl fidl::endpoints::RequestStream for CentralRequestStream {
1826    type Protocol = CentralMarker;
1827    type ControlHandle = CentralControlHandle;
1828
1829    fn from_channel(channel: ::fidl::AsyncChannel) -> Self {
1830        Self { inner: std::sync::Arc::new(fidl::ServeInner::new(channel)), is_terminated: false }
1831    }
1832
1833    fn control_handle(&self) -> Self::ControlHandle {
1834        CentralControlHandle { inner: self.inner.clone() }
1835    }
1836
1837    fn into_inner(
1838        self,
1839    ) -> (::std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>, bool)
1840    {
1841        (self.inner, self.is_terminated)
1842    }
1843
1844    fn from_inner(
1845        inner: std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>,
1846        is_terminated: bool,
1847    ) -> Self {
1848        Self { inner, is_terminated }
1849    }
1850}
1851
1852impl futures::Stream for CentralRequestStream {
1853    type Item = Result<CentralRequest, fidl::Error>;
1854
1855    fn poll_next(
1856        mut self: std::pin::Pin<&mut Self>,
1857        cx: &mut std::task::Context<'_>,
1858    ) -> std::task::Poll<Option<Self::Item>> {
1859        let this = &mut *self;
1860        if this.inner.check_shutdown(cx) {
1861            this.is_terminated = true;
1862            return std::task::Poll::Ready(None);
1863        }
1864        if this.is_terminated {
1865            panic!("polled CentralRequestStream after completion");
1866        }
1867        fidl::encoding::with_tls_decode_buf::<_, fidl::encoding::DefaultFuchsiaResourceDialect>(
1868            |bytes, handles| {
1869                match this.inner.channel().read_etc(cx, bytes, handles) {
1870                    std::task::Poll::Ready(Ok(())) => {}
1871                    std::task::Poll::Pending => return std::task::Poll::Pending,
1872                    std::task::Poll::Ready(Err(zx_status::Status::PEER_CLOSED)) => {
1873                        this.is_terminated = true;
1874                        return std::task::Poll::Ready(None);
1875                    }
1876                    std::task::Poll::Ready(Err(e)) => {
1877                        return std::task::Poll::Ready(Some(Err(fidl::Error::ServerRequestRead(
1878                            e.into(),
1879                        ))))
1880                    }
1881                }
1882
1883                // A message has been received from the channel
1884                let (header, _body_bytes) = fidl::encoding::decode_transaction_header(bytes)?;
1885
1886                std::task::Poll::Ready(Some(match header.ordinal {
1887                    0x39c6e9001d102338 => {
1888                        header.validate_request_tx_id(fidl::MethodType::TwoWay)?;
1889                        let mut req = fidl::new_empty!(
1890                            ChannelListenerRegistryListenL2capRequest,
1891                            fidl::encoding::DefaultFuchsiaResourceDialect
1892                        );
1893                        fidl::encoding::Decoder::<fidl::encoding::DefaultFuchsiaResourceDialect>::decode_into::<ChannelListenerRegistryListenL2capRequest>(&header, _body_bytes, handles, &mut req)?;
1894                        let control_handle = CentralControlHandle { inner: this.inner.clone() };
1895                        Ok(CentralRequest::ListenL2cap {
1896                            payload: req,
1897                            responder: CentralListenL2capResponder {
1898                                control_handle: std::mem::ManuallyDrop::new(control_handle),
1899                                tx_id: header.tx_id,
1900                            },
1901                        })
1902                    }
1903                    0x41f7121798dfe15f => {
1904                        header.validate_request_tx_id(fidl::MethodType::TwoWay)?;
1905                        let mut req = fidl::new_empty!(
1906                            CentralScanRequest,
1907                            fidl::encoding::DefaultFuchsiaResourceDialect
1908                        );
1909                        fidl::encoding::Decoder::<fidl::encoding::DefaultFuchsiaResourceDialect>::decode_into::<CentralScanRequest>(&header, _body_bytes, handles, &mut req)?;
1910                        let control_handle = CentralControlHandle { inner: this.inner.clone() };
1911                        Ok(CentralRequest::Scan {
1912                            options: req.options,
1913                            result_watcher: req.result_watcher,
1914
1915                            responder: CentralScanResponder {
1916                                control_handle: std::mem::ManuallyDrop::new(control_handle),
1917                                tx_id: header.tx_id,
1918                            },
1919                        })
1920                    }
1921                    0x31a3065f2a6913c4 => {
1922                        header.validate_request_tx_id(fidl::MethodType::OneWay)?;
1923                        let mut req = fidl::new_empty!(
1924                            CentralConnectRequest,
1925                            fidl::encoding::DefaultFuchsiaResourceDialect
1926                        );
1927                        fidl::encoding::Decoder::<fidl::encoding::DefaultFuchsiaResourceDialect>::decode_into::<CentralConnectRequest>(&header, _body_bytes, handles, &mut req)?;
1928                        let control_handle = CentralControlHandle { inner: this.inner.clone() };
1929                        Ok(CentralRequest::Connect {
1930                            id: req.id,
1931                            options: req.options,
1932                            handle: req.handle,
1933
1934                            control_handle,
1935                        })
1936                    }
1937                    0x37ba777499c683a8 => {
1938                        header.validate_request_tx_id(fidl::MethodType::TwoWay)?;
1939                        let mut req = fidl::new_empty!(
1940                            CentralGetPeripheralsRequest,
1941                            fidl::encoding::DefaultFuchsiaResourceDialect
1942                        );
1943                        fidl::encoding::Decoder::<fidl::encoding::DefaultFuchsiaResourceDialect>::decode_into::<CentralGetPeripheralsRequest>(&header, _body_bytes, handles, &mut req)?;
1944                        let control_handle = CentralControlHandle { inner: this.inner.clone() };
1945                        Ok(CentralRequest::GetPeripherals {
1946                            service_uuids: req.service_uuids,
1947
1948                            responder: CentralGetPeripheralsResponder {
1949                                control_handle: std::mem::ManuallyDrop::new(control_handle),
1950                                tx_id: header.tx_id,
1951                            },
1952                        })
1953                    }
1954                    0x97f5a2f2d9c13da => {
1955                        header.validate_request_tx_id(fidl::MethodType::TwoWay)?;
1956                        let mut req = fidl::new_empty!(
1957                            CentralGetPeripheralRequest,
1958                            fidl::encoding::DefaultFuchsiaResourceDialect
1959                        );
1960                        fidl::encoding::Decoder::<fidl::encoding::DefaultFuchsiaResourceDialect>::decode_into::<CentralGetPeripheralRequest>(&header, _body_bytes, handles, &mut req)?;
1961                        let control_handle = CentralControlHandle { inner: this.inner.clone() };
1962                        Ok(CentralRequest::GetPeripheral {
1963                            identifier: req.identifier,
1964
1965                            responder: CentralGetPeripheralResponder {
1966                                control_handle: std::mem::ManuallyDrop::new(control_handle),
1967                                tx_id: header.tx_id,
1968                            },
1969                        })
1970                    }
1971                    0xeb4cf0cd0e1132b => {
1972                        header.validate_request_tx_id(fidl::MethodType::TwoWay)?;
1973                        let mut req = fidl::new_empty!(
1974                            CentralStartScanRequest,
1975                            fidl::encoding::DefaultFuchsiaResourceDialect
1976                        );
1977                        fidl::encoding::Decoder::<fidl::encoding::DefaultFuchsiaResourceDialect>::decode_into::<CentralStartScanRequest>(&header, _body_bytes, handles, &mut req)?;
1978                        let control_handle = CentralControlHandle { inner: this.inner.clone() };
1979                        Ok(CentralRequest::StartScan {
1980                            filter: req.filter,
1981
1982                            responder: CentralStartScanResponder {
1983                                control_handle: std::mem::ManuallyDrop::new(control_handle),
1984                                tx_id: header.tx_id,
1985                            },
1986                        })
1987                    }
1988                    0x5f79ee6a0bb037a0 => {
1989                        header.validate_request_tx_id(fidl::MethodType::OneWay)?;
1990                        let mut req = fidl::new_empty!(
1991                            fidl::encoding::EmptyPayload,
1992                            fidl::encoding::DefaultFuchsiaResourceDialect
1993                        );
1994                        fidl::encoding::Decoder::<fidl::encoding::DefaultFuchsiaResourceDialect>::decode_into::<fidl::encoding::EmptyPayload>(&header, _body_bytes, handles, &mut req)?;
1995                        let control_handle = CentralControlHandle { inner: this.inner.clone() };
1996                        Ok(CentralRequest::StopScan { control_handle })
1997                    }
1998                    0x714d6c32d066d75a => {
1999                        header.validate_request_tx_id(fidl::MethodType::TwoWay)?;
2000                        let mut req = fidl::new_empty!(
2001                            CentralConnectPeripheralRequest,
2002                            fidl::encoding::DefaultFuchsiaResourceDialect
2003                        );
2004                        fidl::encoding::Decoder::<fidl::encoding::DefaultFuchsiaResourceDialect>::decode_into::<CentralConnectPeripheralRequest>(&header, _body_bytes, handles, &mut req)?;
2005                        let control_handle = CentralControlHandle { inner: this.inner.clone() };
2006                        Ok(CentralRequest::ConnectPeripheral {
2007                            identifier: req.identifier,
2008                            options: req.options,
2009                            gatt_client: req.gatt_client,
2010
2011                            responder: CentralConnectPeripheralResponder {
2012                                control_handle: std::mem::ManuallyDrop::new(control_handle),
2013                                tx_id: header.tx_id,
2014                            },
2015                        })
2016                    }
2017                    0xa9430da197362fd => {
2018                        header.validate_request_tx_id(fidl::MethodType::TwoWay)?;
2019                        let mut req = fidl::new_empty!(
2020                            CentralDisconnectPeripheralRequest,
2021                            fidl::encoding::DefaultFuchsiaResourceDialect
2022                        );
2023                        fidl::encoding::Decoder::<fidl::encoding::DefaultFuchsiaResourceDialect>::decode_into::<CentralDisconnectPeripheralRequest>(&header, _body_bytes, handles, &mut req)?;
2024                        let control_handle = CentralControlHandle { inner: this.inner.clone() };
2025                        Ok(CentralRequest::DisconnectPeripheral {
2026                            identifier: req.identifier,
2027
2028                            responder: CentralDisconnectPeripheralResponder {
2029                                control_handle: std::mem::ManuallyDrop::new(control_handle),
2030                                tx_id: header.tx_id,
2031                            },
2032                        })
2033                    }
2034                    _ => Err(fidl::Error::UnknownOrdinal {
2035                        ordinal: header.ordinal,
2036                        protocol_name:
2037                            <CentralMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME,
2038                    }),
2039                }))
2040            },
2041        )
2042    }
2043}
2044
2045#[derive(Debug)]
2046pub enum CentralRequest {
2047    /// Register a listener for incoming channels. The registry will assign a
2048    /// PSM value that is unique for the local device, as well as open a
2049    /// [`ChannelListener`] for accepting incoming channels. In the unlikely
2050    /// event that all PSMs have been assigned, this call will fail with
2051    /// `ZX_ERR_NO_RESOURCES`.
2052    ///
2053    /// Note that the method of service discovery or advertising is defined by
2054    /// the service or protocol, so it is the responsibility of the caller to
2055    /// communicate the assigned PSM to any clients.
2056    ListenL2cap {
2057        payload: ChannelListenerRegistryListenL2capRequest,
2058        responder: CentralListenL2capResponder,
2059    },
2060    /// Scans for nearby LE peripherals and broadcasters. If the scan cannot be
2061    /// initiated, then `result_watcher` will be closed with an epitaph.
2062    ///
2063    /// A Central client is allowed to have only one active scan at a time.
2064    /// Accordingly, only one Scan request can be outstanding at a time.
2065    /// Additional calls to Scan will fail.
2066    ///
2067    /// The lifetime of the scan session is tied to the `result_watcher`
2068    /// protocol provided. The scan will be stopped if the channel is closed.
2069    ///
2070    /// Once a scan is started, the [`fuchsia.bluetooth.le/ScanResultWatcher`]
2071    /// can be used to watch for scan results.
2072    ///
2073    /// + request `options` Options used to configure the scan session.
2074    /// + request `result_watcher` Protocol that remains valid for the duration
2075    ///   of this scan session.
2076    /// - response An empty response will be sent to acknowledge the scan has
2077    ///   stopped.
2078    ///
2079    /// The following epitaphs may be sent by the server on error:
2080    /// * error `ALREADY_EXISTS`: A scan is already in progress. Each `Central`
2081    ///   protocol is only allowed 1 active scan.
2082    /// * error `INVALID_ARGS`: Some of the scan `options` are invalid. See the
2083    ///   `ScanOptions` documentation.
2084    /// * error `INTERNAL`: An internal error occurred and a scan could not be
2085    ///   started.
2086    Scan {
2087        options: ScanOptions,
2088        result_watcher: fidl::endpoints::ServerEnd<ScanResultWatcherMarker>,
2089        responder: CentralScanResponder,
2090    },
2091    /// Connect to the peer with the given identifier.
2092    ///
2093    /// The requested [`fuchsia.bluetooth.le/Connection`] represents the
2094    /// client's interest on the LE connection to the peer. Closing the channel
2095    /// removes interest, but may not result in disconnection if another client
2096    /// holds a valid [`fuchsia.bluetooth.le/Connection`] to the same peer.
2097    ///
2098    /// The [`fuchsia.bluetooth.le/Connection`] `handle` will be closed by the
2099    /// system if the connection to the peer is lost or an error occurs.
2100    ///
2101    /// The following epitaphs may be sent by the server on error:
2102    /// + `INVALID_ARGS`: Some of the parameters are invalid.
2103    /// + `ALREADY_BOUND`: A Connection to the peer already exists for this Central. The existing
2104    ///                    Connection should be used.
2105    /// + `NOT_CONNECTED`: A connection could not be established.
2106    /// + `CONNECTION_RESET`: The peer disconnected.
2107    ///
2108    /// + request `id` Identifier of the peer to initiate a connection to.
2109    /// + request `options` Options used to configure the connection.
2110    /// + request `handle` Handle that remains valid for the duration of this
2111    ///   connection.
2112    Connect {
2113        id: fidl_fuchsia_bluetooth::PeerId,
2114        options: ConnectionOptions,
2115        handle: fidl::endpoints::ServerEnd<ConnectionMarker>,
2116        control_handle: CentralControlHandle,
2117    },
2118    /// Returns the list of peripherals that are known to the system from previous scan, connection,
2119    /// and/or bonding procedures. The results can be filtered based on service UUIDs that are known to
2120    /// be present on the peripheral.
2121    ///
2122    /// This method only returns peripherals (i.e. connectable devices).
2123    GetPeripherals { service_uuids: Option<Vec<String>>, responder: CentralGetPeripheralsResponder },
2124    /// **This method is not implemented by the Fuchsia core stack- TODO(https://fxbug.dev/42087303)**
2125    ///
2126    /// Returns information about a single peripheral that is known to the system from previous scan,
2127    /// connection, and/or bonding procedures based on its unique identifier. Returns null if
2128    /// `identifier` is not recognized.
2129    GetPeripheral { identifier: String, responder: CentralGetPeripheralResponder },
2130    /// Initiates a scan session for nearby peripherals and broadcasters. Discovered devices will be
2131    /// reported via CentralDelegate.OnDeviceDiscovered(). If a scan session is already in progress,
2132    /// `filter` will replace the existing session's filter.
2133    ///
2134    /// If `filter` is null or empty (i.e. none of its fields has been populated) then the delegate
2135    /// will be notified for all discoverable devices that are found. This is not recommended; clients
2136    /// should generally filter results by at least one of `filter.service_uuids`,
2137    /// `filter.service_data`, and/or `filter.manufacturer_identifier`.
2138    StartScan { filter: Option<Box<ScanFilter>>, responder: CentralStartScanResponder },
2139    /// Terminate a previously started scan session.
2140    StopScan { control_handle: CentralControlHandle },
2141    /// Creates a connection to the peripheral device with the given identifier.
2142    /// Returns the status of the operation in `status`.
2143    ///
2144    /// On success, `gatt_client` will be bound and can be used for GATT client
2145    /// role procedures. On failure, `gatt_client` will be closed and `status` will
2146    /// indicate an error.
2147    ConnectPeripheral {
2148        identifier: String,
2149        options: ConnectionOptions,
2150        gatt_client: fidl::endpoints::ServerEnd<fidl_fuchsia_bluetooth_gatt::ClientMarker>,
2151        responder: CentralConnectPeripheralResponder,
2152    },
2153    /// Disconnects this Central's connection to the peripheral with the given identifier.
2154    DisconnectPeripheral { identifier: String, responder: CentralDisconnectPeripheralResponder },
2155}
2156
2157impl CentralRequest {
2158    #[allow(irrefutable_let_patterns)]
2159    pub fn into_listen_l2cap(
2160        self,
2161    ) -> Option<(ChannelListenerRegistryListenL2capRequest, CentralListenL2capResponder)> {
2162        if let CentralRequest::ListenL2cap { payload, responder } = self {
2163            Some((payload, responder))
2164        } else {
2165            None
2166        }
2167    }
2168
2169    #[allow(irrefutable_let_patterns)]
2170    pub fn into_scan(
2171        self,
2172    ) -> Option<(
2173        ScanOptions,
2174        fidl::endpoints::ServerEnd<ScanResultWatcherMarker>,
2175        CentralScanResponder,
2176    )> {
2177        if let CentralRequest::Scan { options, result_watcher, responder } = self {
2178            Some((options, result_watcher, responder))
2179        } else {
2180            None
2181        }
2182    }
2183
2184    #[allow(irrefutable_let_patterns)]
2185    pub fn into_connect(
2186        self,
2187    ) -> Option<(
2188        fidl_fuchsia_bluetooth::PeerId,
2189        ConnectionOptions,
2190        fidl::endpoints::ServerEnd<ConnectionMarker>,
2191        CentralControlHandle,
2192    )> {
2193        if let CentralRequest::Connect { id, options, handle, control_handle } = self {
2194            Some((id, options, handle, control_handle))
2195        } else {
2196            None
2197        }
2198    }
2199
2200    #[allow(irrefutable_let_patterns)]
2201    pub fn into_get_peripherals(
2202        self,
2203    ) -> Option<(Option<Vec<String>>, CentralGetPeripheralsResponder)> {
2204        if let CentralRequest::GetPeripherals { service_uuids, responder } = self {
2205            Some((service_uuids, responder))
2206        } else {
2207            None
2208        }
2209    }
2210
2211    #[allow(irrefutable_let_patterns)]
2212    pub fn into_get_peripheral(self) -> Option<(String, CentralGetPeripheralResponder)> {
2213        if let CentralRequest::GetPeripheral { identifier, responder } = self {
2214            Some((identifier, responder))
2215        } else {
2216            None
2217        }
2218    }
2219
2220    #[allow(irrefutable_let_patterns)]
2221    pub fn into_start_scan(self) -> Option<(Option<Box<ScanFilter>>, CentralStartScanResponder)> {
2222        if let CentralRequest::StartScan { filter, responder } = self {
2223            Some((filter, responder))
2224        } else {
2225            None
2226        }
2227    }
2228
2229    #[allow(irrefutable_let_patterns)]
2230    pub fn into_stop_scan(self) -> Option<(CentralControlHandle)> {
2231        if let CentralRequest::StopScan { control_handle } = self {
2232            Some((control_handle))
2233        } else {
2234            None
2235        }
2236    }
2237
2238    #[allow(irrefutable_let_patterns)]
2239    pub fn into_connect_peripheral(
2240        self,
2241    ) -> Option<(
2242        String,
2243        ConnectionOptions,
2244        fidl::endpoints::ServerEnd<fidl_fuchsia_bluetooth_gatt::ClientMarker>,
2245        CentralConnectPeripheralResponder,
2246    )> {
2247        if let CentralRequest::ConnectPeripheral { identifier, options, gatt_client, responder } =
2248            self
2249        {
2250            Some((identifier, options, gatt_client, responder))
2251        } else {
2252            None
2253        }
2254    }
2255
2256    #[allow(irrefutable_let_patterns)]
2257    pub fn into_disconnect_peripheral(
2258        self,
2259    ) -> Option<(String, CentralDisconnectPeripheralResponder)> {
2260        if let CentralRequest::DisconnectPeripheral { identifier, responder } = self {
2261            Some((identifier, responder))
2262        } else {
2263            None
2264        }
2265    }
2266
2267    /// Name of the method defined in FIDL
2268    pub fn method_name(&self) -> &'static str {
2269        match *self {
2270            CentralRequest::ListenL2cap { .. } => "listen_l2cap",
2271            CentralRequest::Scan { .. } => "scan",
2272            CentralRequest::Connect { .. } => "connect",
2273            CentralRequest::GetPeripherals { .. } => "get_peripherals",
2274            CentralRequest::GetPeripheral { .. } => "get_peripheral",
2275            CentralRequest::StartScan { .. } => "start_scan",
2276            CentralRequest::StopScan { .. } => "stop_scan",
2277            CentralRequest::ConnectPeripheral { .. } => "connect_peripheral",
2278            CentralRequest::DisconnectPeripheral { .. } => "disconnect_peripheral",
2279        }
2280    }
2281}
2282
2283#[derive(Debug, Clone)]
2284pub struct CentralControlHandle {
2285    inner: std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>,
2286}
2287
2288impl fidl::endpoints::ControlHandle for CentralControlHandle {
2289    fn shutdown(&self) {
2290        self.inner.shutdown()
2291    }
2292    fn shutdown_with_epitaph(&self, status: zx_status::Status) {
2293        self.inner.shutdown_with_epitaph(status)
2294    }
2295
2296    fn is_closed(&self) -> bool {
2297        self.inner.channel().is_closed()
2298    }
2299    fn on_closed(&self) -> fidl::OnSignalsRef<'_> {
2300        self.inner.channel().on_closed()
2301    }
2302
2303    #[cfg(target_os = "fuchsia")]
2304    fn signal_peer(
2305        &self,
2306        clear_mask: zx::Signals,
2307        set_mask: zx::Signals,
2308    ) -> Result<(), zx_status::Status> {
2309        use fidl::Peered;
2310        self.inner.channel().signal_peer(clear_mask, set_mask)
2311    }
2312}
2313
2314impl CentralControlHandle {
2315    pub fn send_on_scan_state_changed(&self, mut scanning: bool) -> Result<(), fidl::Error> {
2316        self.inner.send::<CentralOnScanStateChangedRequest>(
2317            (scanning,),
2318            0,
2319            0x5f8edc23cad04d3f,
2320            fidl::encoding::DynamicFlags::empty(),
2321        )
2322    }
2323
2324    pub fn send_on_device_discovered(&self, mut device: &RemoteDevice) -> Result<(), fidl::Error> {
2325        self.inner.send::<CentralOnDeviceDiscoveredRequest>(
2326            (device,),
2327            0,
2328            0x708dadf20d66db6,
2329            fidl::encoding::DynamicFlags::empty(),
2330        )
2331    }
2332
2333    pub fn send_on_peripheral_disconnected(&self, mut identifier: &str) -> Result<(), fidl::Error> {
2334        self.inner.send::<CentralOnPeripheralDisconnectedRequest>(
2335            (identifier,),
2336            0,
2337            0x4e4c6b979b2126df,
2338            fidl::encoding::DynamicFlags::empty(),
2339        )
2340    }
2341}
2342
2343#[must_use = "FIDL methods require a response to be sent"]
2344#[derive(Debug)]
2345pub struct CentralListenL2capResponder {
2346    control_handle: std::mem::ManuallyDrop<CentralControlHandle>,
2347    tx_id: u32,
2348}
2349
2350/// Set the the channel to be shutdown (see [`CentralControlHandle::shutdown`])
2351/// if the responder is dropped without sending a response, so that the client
2352/// doesn't hang. To prevent this behavior, call `drop_without_shutdown`.
2353impl std::ops::Drop for CentralListenL2capResponder {
2354    fn drop(&mut self) {
2355        self.control_handle.shutdown();
2356        // Safety: drops once, never accessed again
2357        unsafe { std::mem::ManuallyDrop::drop(&mut self.control_handle) };
2358    }
2359}
2360
2361impl fidl::endpoints::Responder for CentralListenL2capResponder {
2362    type ControlHandle = CentralControlHandle;
2363
2364    fn control_handle(&self) -> &CentralControlHandle {
2365        &self.control_handle
2366    }
2367
2368    fn drop_without_shutdown(mut self) {
2369        // Safety: drops once, never accessed again due to mem::forget
2370        unsafe { std::mem::ManuallyDrop::drop(&mut self.control_handle) };
2371        // Prevent Drop from running (which would shut down the channel)
2372        std::mem::forget(self);
2373    }
2374}
2375
2376impl CentralListenL2capResponder {
2377    /// Sends a response to the FIDL transaction.
2378    ///
2379    /// Sets the channel to shutdown if an error occurs.
2380    pub fn send(
2381        self,
2382        mut result: Result<&ChannelListenerRegistryListenL2capResponse, i32>,
2383    ) -> Result<(), fidl::Error> {
2384        let _result = self.send_raw(result);
2385        if _result.is_err() {
2386            self.control_handle.shutdown();
2387        }
2388        self.drop_without_shutdown();
2389        _result
2390    }
2391
2392    /// Similar to "send" but does not shutdown the channel if an error occurs.
2393    pub fn send_no_shutdown_on_err(
2394        self,
2395        mut result: Result<&ChannelListenerRegistryListenL2capResponse, i32>,
2396    ) -> Result<(), fidl::Error> {
2397        let _result = self.send_raw(result);
2398        self.drop_without_shutdown();
2399        _result
2400    }
2401
2402    fn send_raw(
2403        &self,
2404        mut result: Result<&ChannelListenerRegistryListenL2capResponse, i32>,
2405    ) -> Result<(), fidl::Error> {
2406        self.control_handle.inner.send::<fidl::encoding::ResultType<
2407            ChannelListenerRegistryListenL2capResponse,
2408            i32,
2409        >>(
2410            result,
2411            self.tx_id,
2412            0x39c6e9001d102338,
2413            fidl::encoding::DynamicFlags::empty(),
2414        )
2415    }
2416}
2417
2418#[must_use = "FIDL methods require a response to be sent"]
2419#[derive(Debug)]
2420pub struct CentralScanResponder {
2421    control_handle: std::mem::ManuallyDrop<CentralControlHandle>,
2422    tx_id: u32,
2423}
2424
2425/// Set the the channel to be shutdown (see [`CentralControlHandle::shutdown`])
2426/// if the responder is dropped without sending a response, so that the client
2427/// doesn't hang. To prevent this behavior, call `drop_without_shutdown`.
2428impl std::ops::Drop for CentralScanResponder {
2429    fn drop(&mut self) {
2430        self.control_handle.shutdown();
2431        // Safety: drops once, never accessed again
2432        unsafe { std::mem::ManuallyDrop::drop(&mut self.control_handle) };
2433    }
2434}
2435
2436impl fidl::endpoints::Responder for CentralScanResponder {
2437    type ControlHandle = CentralControlHandle;
2438
2439    fn control_handle(&self) -> &CentralControlHandle {
2440        &self.control_handle
2441    }
2442
2443    fn drop_without_shutdown(mut self) {
2444        // Safety: drops once, never accessed again due to mem::forget
2445        unsafe { std::mem::ManuallyDrop::drop(&mut self.control_handle) };
2446        // Prevent Drop from running (which would shut down the channel)
2447        std::mem::forget(self);
2448    }
2449}
2450
2451impl CentralScanResponder {
2452    /// Sends a response to the FIDL transaction.
2453    ///
2454    /// Sets the channel to shutdown if an error occurs.
2455    pub fn send(self) -> Result<(), fidl::Error> {
2456        let _result = self.send_raw();
2457        if _result.is_err() {
2458            self.control_handle.shutdown();
2459        }
2460        self.drop_without_shutdown();
2461        _result
2462    }
2463
2464    /// Similar to "send" but does not shutdown the channel if an error occurs.
2465    pub fn send_no_shutdown_on_err(self) -> Result<(), fidl::Error> {
2466        let _result = self.send_raw();
2467        self.drop_without_shutdown();
2468        _result
2469    }
2470
2471    fn send_raw(&self) -> Result<(), fidl::Error> {
2472        self.control_handle.inner.send::<fidl::encoding::EmptyPayload>(
2473            (),
2474            self.tx_id,
2475            0x41f7121798dfe15f,
2476            fidl::encoding::DynamicFlags::empty(),
2477        )
2478    }
2479}
2480
2481#[must_use = "FIDL methods require a response to be sent"]
2482#[derive(Debug)]
2483pub struct CentralGetPeripheralsResponder {
2484    control_handle: std::mem::ManuallyDrop<CentralControlHandle>,
2485    tx_id: u32,
2486}
2487
2488/// Set the the channel to be shutdown (see [`CentralControlHandle::shutdown`])
2489/// if the responder is dropped without sending a response, so that the client
2490/// doesn't hang. To prevent this behavior, call `drop_without_shutdown`.
2491impl std::ops::Drop for CentralGetPeripheralsResponder {
2492    fn drop(&mut self) {
2493        self.control_handle.shutdown();
2494        // Safety: drops once, never accessed again
2495        unsafe { std::mem::ManuallyDrop::drop(&mut self.control_handle) };
2496    }
2497}
2498
2499impl fidl::endpoints::Responder for CentralGetPeripheralsResponder {
2500    type ControlHandle = CentralControlHandle;
2501
2502    fn control_handle(&self) -> &CentralControlHandle {
2503        &self.control_handle
2504    }
2505
2506    fn drop_without_shutdown(mut self) {
2507        // Safety: drops once, never accessed again due to mem::forget
2508        unsafe { std::mem::ManuallyDrop::drop(&mut self.control_handle) };
2509        // Prevent Drop from running (which would shut down the channel)
2510        std::mem::forget(self);
2511    }
2512}
2513
2514impl CentralGetPeripheralsResponder {
2515    /// Sends a response to the FIDL transaction.
2516    ///
2517    /// Sets the channel to shutdown if an error occurs.
2518    pub fn send(self, mut peripherals: &[RemoteDevice]) -> Result<(), fidl::Error> {
2519        let _result = self.send_raw(peripherals);
2520        if _result.is_err() {
2521            self.control_handle.shutdown();
2522        }
2523        self.drop_without_shutdown();
2524        _result
2525    }
2526
2527    /// Similar to "send" but does not shutdown the channel if an error occurs.
2528    pub fn send_no_shutdown_on_err(
2529        self,
2530        mut peripherals: &[RemoteDevice],
2531    ) -> Result<(), fidl::Error> {
2532        let _result = self.send_raw(peripherals);
2533        self.drop_without_shutdown();
2534        _result
2535    }
2536
2537    fn send_raw(&self, mut peripherals: &[RemoteDevice]) -> Result<(), fidl::Error> {
2538        self.control_handle.inner.send::<CentralGetPeripheralsResponse>(
2539            (peripherals,),
2540            self.tx_id,
2541            0x37ba777499c683a8,
2542            fidl::encoding::DynamicFlags::empty(),
2543        )
2544    }
2545}
2546
2547#[must_use = "FIDL methods require a response to be sent"]
2548#[derive(Debug)]
2549pub struct CentralGetPeripheralResponder {
2550    control_handle: std::mem::ManuallyDrop<CentralControlHandle>,
2551    tx_id: u32,
2552}
2553
2554/// Set the the channel to be shutdown (see [`CentralControlHandle::shutdown`])
2555/// if the responder is dropped without sending a response, so that the client
2556/// doesn't hang. To prevent this behavior, call `drop_without_shutdown`.
2557impl std::ops::Drop for CentralGetPeripheralResponder {
2558    fn drop(&mut self) {
2559        self.control_handle.shutdown();
2560        // Safety: drops once, never accessed again
2561        unsafe { std::mem::ManuallyDrop::drop(&mut self.control_handle) };
2562    }
2563}
2564
2565impl fidl::endpoints::Responder for CentralGetPeripheralResponder {
2566    type ControlHandle = CentralControlHandle;
2567
2568    fn control_handle(&self) -> &CentralControlHandle {
2569        &self.control_handle
2570    }
2571
2572    fn drop_without_shutdown(mut self) {
2573        // Safety: drops once, never accessed again due to mem::forget
2574        unsafe { std::mem::ManuallyDrop::drop(&mut self.control_handle) };
2575        // Prevent Drop from running (which would shut down the channel)
2576        std::mem::forget(self);
2577    }
2578}
2579
2580impl CentralGetPeripheralResponder {
2581    /// Sends a response to the FIDL transaction.
2582    ///
2583    /// Sets the channel to shutdown if an error occurs.
2584    pub fn send(self, mut peripheral: Option<&RemoteDevice>) -> Result<(), fidl::Error> {
2585        let _result = self.send_raw(peripheral);
2586        if _result.is_err() {
2587            self.control_handle.shutdown();
2588        }
2589        self.drop_without_shutdown();
2590        _result
2591    }
2592
2593    /// Similar to "send" but does not shutdown the channel if an error occurs.
2594    pub fn send_no_shutdown_on_err(
2595        self,
2596        mut peripheral: Option<&RemoteDevice>,
2597    ) -> Result<(), fidl::Error> {
2598        let _result = self.send_raw(peripheral);
2599        self.drop_without_shutdown();
2600        _result
2601    }
2602
2603    fn send_raw(&self, mut peripheral: Option<&RemoteDevice>) -> Result<(), fidl::Error> {
2604        self.control_handle.inner.send::<CentralGetPeripheralResponse>(
2605            (peripheral,),
2606            self.tx_id,
2607            0x97f5a2f2d9c13da,
2608            fidl::encoding::DynamicFlags::empty(),
2609        )
2610    }
2611}
2612
2613#[must_use = "FIDL methods require a response to be sent"]
2614#[derive(Debug)]
2615pub struct CentralStartScanResponder {
2616    control_handle: std::mem::ManuallyDrop<CentralControlHandle>,
2617    tx_id: u32,
2618}
2619
2620/// Set the the channel to be shutdown (see [`CentralControlHandle::shutdown`])
2621/// if the responder is dropped without sending a response, so that the client
2622/// doesn't hang. To prevent this behavior, call `drop_without_shutdown`.
2623impl std::ops::Drop for CentralStartScanResponder {
2624    fn drop(&mut self) {
2625        self.control_handle.shutdown();
2626        // Safety: drops once, never accessed again
2627        unsafe { std::mem::ManuallyDrop::drop(&mut self.control_handle) };
2628    }
2629}
2630
2631impl fidl::endpoints::Responder for CentralStartScanResponder {
2632    type ControlHandle = CentralControlHandle;
2633
2634    fn control_handle(&self) -> &CentralControlHandle {
2635        &self.control_handle
2636    }
2637
2638    fn drop_without_shutdown(mut self) {
2639        // Safety: drops once, never accessed again due to mem::forget
2640        unsafe { std::mem::ManuallyDrop::drop(&mut self.control_handle) };
2641        // Prevent Drop from running (which would shut down the channel)
2642        std::mem::forget(self);
2643    }
2644}
2645
2646impl CentralStartScanResponder {
2647    /// Sends a response to the FIDL transaction.
2648    ///
2649    /// Sets the channel to shutdown if an error occurs.
2650    pub fn send(self, mut status: &fidl_fuchsia_bluetooth::Status) -> Result<(), fidl::Error> {
2651        let _result = self.send_raw(status);
2652        if _result.is_err() {
2653            self.control_handle.shutdown();
2654        }
2655        self.drop_without_shutdown();
2656        _result
2657    }
2658
2659    /// Similar to "send" but does not shutdown the channel if an error occurs.
2660    pub fn send_no_shutdown_on_err(
2661        self,
2662        mut status: &fidl_fuchsia_bluetooth::Status,
2663    ) -> Result<(), fidl::Error> {
2664        let _result = self.send_raw(status);
2665        self.drop_without_shutdown();
2666        _result
2667    }
2668
2669    fn send_raw(&self, mut status: &fidl_fuchsia_bluetooth::Status) -> Result<(), fidl::Error> {
2670        self.control_handle.inner.send::<CentralStartScanResponse>(
2671            (status,),
2672            self.tx_id,
2673            0xeb4cf0cd0e1132b,
2674            fidl::encoding::DynamicFlags::empty(),
2675        )
2676    }
2677}
2678
2679#[must_use = "FIDL methods require a response to be sent"]
2680#[derive(Debug)]
2681pub struct CentralConnectPeripheralResponder {
2682    control_handle: std::mem::ManuallyDrop<CentralControlHandle>,
2683    tx_id: u32,
2684}
2685
2686/// Set the the channel to be shutdown (see [`CentralControlHandle::shutdown`])
2687/// if the responder is dropped without sending a response, so that the client
2688/// doesn't hang. To prevent this behavior, call `drop_without_shutdown`.
2689impl std::ops::Drop for CentralConnectPeripheralResponder {
2690    fn drop(&mut self) {
2691        self.control_handle.shutdown();
2692        // Safety: drops once, never accessed again
2693        unsafe { std::mem::ManuallyDrop::drop(&mut self.control_handle) };
2694    }
2695}
2696
2697impl fidl::endpoints::Responder for CentralConnectPeripheralResponder {
2698    type ControlHandle = CentralControlHandle;
2699
2700    fn control_handle(&self) -> &CentralControlHandle {
2701        &self.control_handle
2702    }
2703
2704    fn drop_without_shutdown(mut self) {
2705        // Safety: drops once, never accessed again due to mem::forget
2706        unsafe { std::mem::ManuallyDrop::drop(&mut self.control_handle) };
2707        // Prevent Drop from running (which would shut down the channel)
2708        std::mem::forget(self);
2709    }
2710}
2711
2712impl CentralConnectPeripheralResponder {
2713    /// Sends a response to the FIDL transaction.
2714    ///
2715    /// Sets the channel to shutdown if an error occurs.
2716    pub fn send(self, mut status: &fidl_fuchsia_bluetooth::Status) -> Result<(), fidl::Error> {
2717        let _result = self.send_raw(status);
2718        if _result.is_err() {
2719            self.control_handle.shutdown();
2720        }
2721        self.drop_without_shutdown();
2722        _result
2723    }
2724
2725    /// Similar to "send" but does not shutdown the channel if an error occurs.
2726    pub fn send_no_shutdown_on_err(
2727        self,
2728        mut status: &fidl_fuchsia_bluetooth::Status,
2729    ) -> Result<(), fidl::Error> {
2730        let _result = self.send_raw(status);
2731        self.drop_without_shutdown();
2732        _result
2733    }
2734
2735    fn send_raw(&self, mut status: &fidl_fuchsia_bluetooth::Status) -> Result<(), fidl::Error> {
2736        self.control_handle.inner.send::<CentralConnectPeripheralResponse>(
2737            (status,),
2738            self.tx_id,
2739            0x714d6c32d066d75a,
2740            fidl::encoding::DynamicFlags::empty(),
2741        )
2742    }
2743}
2744
2745#[must_use = "FIDL methods require a response to be sent"]
2746#[derive(Debug)]
2747pub struct CentralDisconnectPeripheralResponder {
2748    control_handle: std::mem::ManuallyDrop<CentralControlHandle>,
2749    tx_id: u32,
2750}
2751
2752/// Set the the channel to be shutdown (see [`CentralControlHandle::shutdown`])
2753/// if the responder is dropped without sending a response, so that the client
2754/// doesn't hang. To prevent this behavior, call `drop_without_shutdown`.
2755impl std::ops::Drop for CentralDisconnectPeripheralResponder {
2756    fn drop(&mut self) {
2757        self.control_handle.shutdown();
2758        // Safety: drops once, never accessed again
2759        unsafe { std::mem::ManuallyDrop::drop(&mut self.control_handle) };
2760    }
2761}
2762
2763impl fidl::endpoints::Responder for CentralDisconnectPeripheralResponder {
2764    type ControlHandle = CentralControlHandle;
2765
2766    fn control_handle(&self) -> &CentralControlHandle {
2767        &self.control_handle
2768    }
2769
2770    fn drop_without_shutdown(mut self) {
2771        // Safety: drops once, never accessed again due to mem::forget
2772        unsafe { std::mem::ManuallyDrop::drop(&mut self.control_handle) };
2773        // Prevent Drop from running (which would shut down the channel)
2774        std::mem::forget(self);
2775    }
2776}
2777
2778impl CentralDisconnectPeripheralResponder {
2779    /// Sends a response to the FIDL transaction.
2780    ///
2781    /// Sets the channel to shutdown if an error occurs.
2782    pub fn send(self, mut status: &fidl_fuchsia_bluetooth::Status) -> Result<(), fidl::Error> {
2783        let _result = self.send_raw(status);
2784        if _result.is_err() {
2785            self.control_handle.shutdown();
2786        }
2787        self.drop_without_shutdown();
2788        _result
2789    }
2790
2791    /// Similar to "send" but does not shutdown the channel if an error occurs.
2792    pub fn send_no_shutdown_on_err(
2793        self,
2794        mut status: &fidl_fuchsia_bluetooth::Status,
2795    ) -> Result<(), fidl::Error> {
2796        let _result = self.send_raw(status);
2797        self.drop_without_shutdown();
2798        _result
2799    }
2800
2801    fn send_raw(&self, mut status: &fidl_fuchsia_bluetooth::Status) -> Result<(), fidl::Error> {
2802        self.control_handle.inner.send::<CentralDisconnectPeripheralResponse>(
2803            (status,),
2804            self.tx_id,
2805            0xa9430da197362fd,
2806            fidl::encoding::DynamicFlags::empty(),
2807        )
2808    }
2809}
2810
2811#[derive(Debug, Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Hash)]
2812pub struct ChannelListenerMarker;
2813
2814impl fidl::endpoints::ProtocolMarker for ChannelListenerMarker {
2815    type Proxy = ChannelListenerProxy;
2816    type RequestStream = ChannelListenerRequestStream;
2817    #[cfg(target_os = "fuchsia")]
2818    type SynchronousProxy = ChannelListenerSynchronousProxy;
2819
2820    const DEBUG_NAME: &'static str = "(anonymous) ChannelListener";
2821}
2822
2823pub trait ChannelListenerProxyInterface: Send + Sync {
2824    type AcceptResponseFut: std::future::Future<Output = Result<(), fidl::Error>> + Send;
2825    fn r#accept(
2826        &self,
2827        channel: fidl::endpoints::ClientEnd<fidl_fuchsia_bluetooth::ChannelMarker>,
2828    ) -> Self::AcceptResponseFut;
2829}
2830#[derive(Debug)]
2831#[cfg(target_os = "fuchsia")]
2832pub struct ChannelListenerSynchronousProxy {
2833    client: fidl::client::sync::Client,
2834}
2835
2836#[cfg(target_os = "fuchsia")]
2837impl fidl::endpoints::SynchronousProxy for ChannelListenerSynchronousProxy {
2838    type Proxy = ChannelListenerProxy;
2839    type Protocol = ChannelListenerMarker;
2840
2841    fn from_channel(inner: fidl::Channel) -> Self {
2842        Self::new(inner)
2843    }
2844
2845    fn into_channel(self) -> fidl::Channel {
2846        self.client.into_channel()
2847    }
2848
2849    fn as_channel(&self) -> &fidl::Channel {
2850        self.client.as_channel()
2851    }
2852}
2853
2854#[cfg(target_os = "fuchsia")]
2855impl ChannelListenerSynchronousProxy {
2856    pub fn new(channel: fidl::Channel) -> Self {
2857        let protocol_name = <ChannelListenerMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME;
2858        Self { client: fidl::client::sync::Client::new(channel, protocol_name) }
2859    }
2860
2861    pub fn into_channel(self) -> fidl::Channel {
2862        self.client.into_channel()
2863    }
2864
2865    /// Waits until an event arrives and returns it. It is safe for other
2866    /// threads to make concurrent requests while waiting for an event.
2867    pub fn wait_for_event(
2868        &self,
2869        deadline: zx::MonotonicInstant,
2870    ) -> Result<ChannelListenerEvent, fidl::Error> {
2871        ChannelListenerEvent::decode(self.client.wait_for_event(deadline)?)
2872    }
2873
2874    pub fn r#accept(
2875        &self,
2876        mut channel: fidl::endpoints::ClientEnd<fidl_fuchsia_bluetooth::ChannelMarker>,
2877        ___deadline: zx::MonotonicInstant,
2878    ) -> Result<(), fidl::Error> {
2879        let _response = self.client.send_query::<
2880            ChannelListenerAcceptRequest,
2881            fidl::encoding::FlexibleType<fidl::encoding::EmptyStruct>,
2882        >(
2883            (channel,),
2884            0x6f535bd36b20fc7b,
2885            fidl::encoding::DynamicFlags::FLEXIBLE,
2886            ___deadline,
2887        )?
2888        .into_result::<ChannelListenerMarker>("accept")?;
2889        Ok(_response)
2890    }
2891}
2892
2893#[cfg(target_os = "fuchsia")]
2894impl From<ChannelListenerSynchronousProxy> for zx::Handle {
2895    fn from(value: ChannelListenerSynchronousProxy) -> Self {
2896        value.into_channel().into()
2897    }
2898}
2899
2900#[cfg(target_os = "fuchsia")]
2901impl From<fidl::Channel> for ChannelListenerSynchronousProxy {
2902    fn from(value: fidl::Channel) -> Self {
2903        Self::new(value)
2904    }
2905}
2906
2907#[derive(Debug, Clone)]
2908pub struct ChannelListenerProxy {
2909    client: fidl::client::Client<fidl::encoding::DefaultFuchsiaResourceDialect>,
2910}
2911
2912impl fidl::endpoints::Proxy for ChannelListenerProxy {
2913    type Protocol = ChannelListenerMarker;
2914
2915    fn from_channel(inner: ::fidl::AsyncChannel) -> Self {
2916        Self::new(inner)
2917    }
2918
2919    fn into_channel(self) -> Result<::fidl::AsyncChannel, Self> {
2920        self.client.into_channel().map_err(|client| Self { client })
2921    }
2922
2923    fn as_channel(&self) -> &::fidl::AsyncChannel {
2924        self.client.as_channel()
2925    }
2926}
2927
2928impl ChannelListenerProxy {
2929    /// Create a new Proxy for fuchsia.bluetooth.le/ChannelListener.
2930    pub fn new(channel: ::fidl::AsyncChannel) -> Self {
2931        let protocol_name = <ChannelListenerMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME;
2932        Self { client: fidl::client::Client::new(channel, protocol_name) }
2933    }
2934
2935    /// Get a Stream of events from the remote end of the protocol.
2936    ///
2937    /// # Panics
2938    ///
2939    /// Panics if the event stream was already taken.
2940    pub fn take_event_stream(&self) -> ChannelListenerEventStream {
2941        ChannelListenerEventStream { event_receiver: self.client.take_event_receiver() }
2942    }
2943
2944    pub fn r#accept(
2945        &self,
2946        mut channel: fidl::endpoints::ClientEnd<fidl_fuchsia_bluetooth::ChannelMarker>,
2947    ) -> fidl::client::QueryResponseFut<(), fidl::encoding::DefaultFuchsiaResourceDialect> {
2948        ChannelListenerProxyInterface::r#accept(self, channel)
2949    }
2950}
2951
2952impl ChannelListenerProxyInterface for ChannelListenerProxy {
2953    type AcceptResponseFut =
2954        fidl::client::QueryResponseFut<(), fidl::encoding::DefaultFuchsiaResourceDialect>;
2955    fn r#accept(
2956        &self,
2957        mut channel: fidl::endpoints::ClientEnd<fidl_fuchsia_bluetooth::ChannelMarker>,
2958    ) -> Self::AcceptResponseFut {
2959        fn _decode(
2960            mut _buf: Result<<fidl::encoding::DefaultFuchsiaResourceDialect as fidl::encoding::ResourceDialect>::MessageBufEtc, fidl::Error>,
2961        ) -> Result<(), fidl::Error> {
2962            let _response = fidl::client::decode_transaction_body::<
2963                fidl::encoding::FlexibleType<fidl::encoding::EmptyStruct>,
2964                fidl::encoding::DefaultFuchsiaResourceDialect,
2965                0x6f535bd36b20fc7b,
2966            >(_buf?)?
2967            .into_result::<ChannelListenerMarker>("accept")?;
2968            Ok(_response)
2969        }
2970        self.client.send_query_and_decode::<ChannelListenerAcceptRequest, ()>(
2971            (channel,),
2972            0x6f535bd36b20fc7b,
2973            fidl::encoding::DynamicFlags::FLEXIBLE,
2974            _decode,
2975        )
2976    }
2977}
2978
2979pub struct ChannelListenerEventStream {
2980    event_receiver: fidl::client::EventReceiver<fidl::encoding::DefaultFuchsiaResourceDialect>,
2981}
2982
2983impl std::marker::Unpin for ChannelListenerEventStream {}
2984
2985impl futures::stream::FusedStream for ChannelListenerEventStream {
2986    fn is_terminated(&self) -> bool {
2987        self.event_receiver.is_terminated()
2988    }
2989}
2990
2991impl futures::Stream for ChannelListenerEventStream {
2992    type Item = Result<ChannelListenerEvent, fidl::Error>;
2993
2994    fn poll_next(
2995        mut self: std::pin::Pin<&mut Self>,
2996        cx: &mut std::task::Context<'_>,
2997    ) -> std::task::Poll<Option<Self::Item>> {
2998        match futures::ready!(futures::stream::StreamExt::poll_next_unpin(
2999            &mut self.event_receiver,
3000            cx
3001        )?) {
3002            Some(buf) => std::task::Poll::Ready(Some(ChannelListenerEvent::decode(buf))),
3003            None => std::task::Poll::Ready(None),
3004        }
3005    }
3006}
3007
3008#[derive(Debug)]
3009pub enum ChannelListenerEvent {
3010    #[non_exhaustive]
3011    _UnknownEvent {
3012        /// Ordinal of the event that was sent.
3013        ordinal: u64,
3014    },
3015}
3016
3017impl ChannelListenerEvent {
3018    /// Decodes a message buffer as a [`ChannelListenerEvent`].
3019    fn decode(
3020        mut buf: <fidl::encoding::DefaultFuchsiaResourceDialect as fidl::encoding::ResourceDialect>::MessageBufEtc,
3021    ) -> Result<ChannelListenerEvent, fidl::Error> {
3022        let (bytes, _handles) = buf.split_mut();
3023        let (tx_header, _body_bytes) = fidl::encoding::decode_transaction_header(bytes)?;
3024        debug_assert_eq!(tx_header.tx_id, 0);
3025        match tx_header.ordinal {
3026            _ if tx_header.dynamic_flags().contains(fidl::encoding::DynamicFlags::FLEXIBLE) => {
3027                Ok(ChannelListenerEvent::_UnknownEvent { ordinal: tx_header.ordinal })
3028            }
3029            _ => Err(fidl::Error::UnknownOrdinal {
3030                ordinal: tx_header.ordinal,
3031                protocol_name:
3032                    <ChannelListenerMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME,
3033            }),
3034        }
3035    }
3036}
3037
3038/// A Stream of incoming requests for fuchsia.bluetooth.le/ChannelListener.
3039pub struct ChannelListenerRequestStream {
3040    inner: std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>,
3041    is_terminated: bool,
3042}
3043
3044impl std::marker::Unpin for ChannelListenerRequestStream {}
3045
3046impl futures::stream::FusedStream for ChannelListenerRequestStream {
3047    fn is_terminated(&self) -> bool {
3048        self.is_terminated
3049    }
3050}
3051
3052impl fidl::endpoints::RequestStream for ChannelListenerRequestStream {
3053    type Protocol = ChannelListenerMarker;
3054    type ControlHandle = ChannelListenerControlHandle;
3055
3056    fn from_channel(channel: ::fidl::AsyncChannel) -> Self {
3057        Self { inner: std::sync::Arc::new(fidl::ServeInner::new(channel)), is_terminated: false }
3058    }
3059
3060    fn control_handle(&self) -> Self::ControlHandle {
3061        ChannelListenerControlHandle { inner: self.inner.clone() }
3062    }
3063
3064    fn into_inner(
3065        self,
3066    ) -> (::std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>, bool)
3067    {
3068        (self.inner, self.is_terminated)
3069    }
3070
3071    fn from_inner(
3072        inner: std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>,
3073        is_terminated: bool,
3074    ) -> Self {
3075        Self { inner, is_terminated }
3076    }
3077}
3078
3079impl futures::Stream for ChannelListenerRequestStream {
3080    type Item = Result<ChannelListenerRequest, fidl::Error>;
3081
3082    fn poll_next(
3083        mut self: std::pin::Pin<&mut Self>,
3084        cx: &mut std::task::Context<'_>,
3085    ) -> std::task::Poll<Option<Self::Item>> {
3086        let this = &mut *self;
3087        if this.inner.check_shutdown(cx) {
3088            this.is_terminated = true;
3089            return std::task::Poll::Ready(None);
3090        }
3091        if this.is_terminated {
3092            panic!("polled ChannelListenerRequestStream after completion");
3093        }
3094        fidl::encoding::with_tls_decode_buf::<_, fidl::encoding::DefaultFuchsiaResourceDialect>(
3095            |bytes, handles| {
3096                match this.inner.channel().read_etc(cx, bytes, handles) {
3097                    std::task::Poll::Ready(Ok(())) => {}
3098                    std::task::Poll::Pending => return std::task::Poll::Pending,
3099                    std::task::Poll::Ready(Err(zx_status::Status::PEER_CLOSED)) => {
3100                        this.is_terminated = true;
3101                        return std::task::Poll::Ready(None);
3102                    }
3103                    std::task::Poll::Ready(Err(e)) => {
3104                        return std::task::Poll::Ready(Some(Err(fidl::Error::ServerRequestRead(
3105                            e.into(),
3106                        ))))
3107                    }
3108                }
3109
3110                // A message has been received from the channel
3111                let (header, _body_bytes) = fidl::encoding::decode_transaction_header(bytes)?;
3112
3113                std::task::Poll::Ready(Some(match header.ordinal {
3114                    0x6f535bd36b20fc7b => {
3115                        header.validate_request_tx_id(fidl::MethodType::TwoWay)?;
3116                        let mut req = fidl::new_empty!(
3117                            ChannelListenerAcceptRequest,
3118                            fidl::encoding::DefaultFuchsiaResourceDialect
3119                        );
3120                        fidl::encoding::Decoder::<fidl::encoding::DefaultFuchsiaResourceDialect>::decode_into::<ChannelListenerAcceptRequest>(&header, _body_bytes, handles, &mut req)?;
3121                        let control_handle =
3122                            ChannelListenerControlHandle { inner: this.inner.clone() };
3123                        Ok(ChannelListenerRequest::Accept {
3124                            channel: req.channel,
3125
3126                            responder: ChannelListenerAcceptResponder {
3127                                control_handle: std::mem::ManuallyDrop::new(control_handle),
3128                                tx_id: header.tx_id,
3129                            },
3130                        })
3131                    }
3132                    _ if header.tx_id == 0
3133                        && header
3134                            .dynamic_flags()
3135                            .contains(fidl::encoding::DynamicFlags::FLEXIBLE) =>
3136                    {
3137                        Ok(ChannelListenerRequest::_UnknownMethod {
3138                            ordinal: header.ordinal,
3139                            control_handle: ChannelListenerControlHandle {
3140                                inner: this.inner.clone(),
3141                            },
3142                            method_type: fidl::MethodType::OneWay,
3143                        })
3144                    }
3145                    _ if header
3146                        .dynamic_flags()
3147                        .contains(fidl::encoding::DynamicFlags::FLEXIBLE) =>
3148                    {
3149                        this.inner.send_framework_err(
3150                            fidl::encoding::FrameworkErr::UnknownMethod,
3151                            header.tx_id,
3152                            header.ordinal,
3153                            header.dynamic_flags(),
3154                            (bytes, handles),
3155                        )?;
3156                        Ok(ChannelListenerRequest::_UnknownMethod {
3157                            ordinal: header.ordinal,
3158                            control_handle: ChannelListenerControlHandle {
3159                                inner: this.inner.clone(),
3160                            },
3161                            method_type: fidl::MethodType::TwoWay,
3162                        })
3163                    }
3164                    _ => Err(fidl::Error::UnknownOrdinal {
3165                        ordinal: header.ordinal,
3166                        protocol_name:
3167                            <ChannelListenerMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME,
3168                    }),
3169                }))
3170            },
3171        )
3172    }
3173}
3174
3175/// Represents a service or protocol that accepts incoming channel requests.
3176/// Incoming channel requests for the associated PSM will be connected via this
3177/// protocol. Closing this protocol will also cease accepting any incoming
3178/// channel requests, but existing established channels will not be affected.
3179/// Additionally, once this protocol is closed the implementation is free to
3180/// reuse the PSM that was previously assigned for this instance.
3181#[derive(Debug)]
3182pub enum ChannelListenerRequest {
3183    Accept {
3184        channel: fidl::endpoints::ClientEnd<fidl_fuchsia_bluetooth::ChannelMarker>,
3185        responder: ChannelListenerAcceptResponder,
3186    },
3187    /// An interaction was received which does not match any known method.
3188    #[non_exhaustive]
3189    _UnknownMethod {
3190        /// Ordinal of the method that was called.
3191        ordinal: u64,
3192        control_handle: ChannelListenerControlHandle,
3193        method_type: fidl::MethodType,
3194    },
3195}
3196
3197impl ChannelListenerRequest {
3198    #[allow(irrefutable_let_patterns)]
3199    pub fn into_accept(
3200        self,
3201    ) -> Option<(
3202        fidl::endpoints::ClientEnd<fidl_fuchsia_bluetooth::ChannelMarker>,
3203        ChannelListenerAcceptResponder,
3204    )> {
3205        if let ChannelListenerRequest::Accept { channel, responder } = self {
3206            Some((channel, responder))
3207        } else {
3208            None
3209        }
3210    }
3211
3212    /// Name of the method defined in FIDL
3213    pub fn method_name(&self) -> &'static str {
3214        match *self {
3215            ChannelListenerRequest::Accept { .. } => "accept",
3216            ChannelListenerRequest::_UnknownMethod {
3217                method_type: fidl::MethodType::OneWay,
3218                ..
3219            } => "unknown one-way method",
3220            ChannelListenerRequest::_UnknownMethod {
3221                method_type: fidl::MethodType::TwoWay,
3222                ..
3223            } => "unknown two-way method",
3224        }
3225    }
3226}
3227
3228#[derive(Debug, Clone)]
3229pub struct ChannelListenerControlHandle {
3230    inner: std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>,
3231}
3232
3233impl fidl::endpoints::ControlHandle for ChannelListenerControlHandle {
3234    fn shutdown(&self) {
3235        self.inner.shutdown()
3236    }
3237    fn shutdown_with_epitaph(&self, status: zx_status::Status) {
3238        self.inner.shutdown_with_epitaph(status)
3239    }
3240
3241    fn is_closed(&self) -> bool {
3242        self.inner.channel().is_closed()
3243    }
3244    fn on_closed(&self) -> fidl::OnSignalsRef<'_> {
3245        self.inner.channel().on_closed()
3246    }
3247
3248    #[cfg(target_os = "fuchsia")]
3249    fn signal_peer(
3250        &self,
3251        clear_mask: zx::Signals,
3252        set_mask: zx::Signals,
3253    ) -> Result<(), zx_status::Status> {
3254        use fidl::Peered;
3255        self.inner.channel().signal_peer(clear_mask, set_mask)
3256    }
3257}
3258
3259impl ChannelListenerControlHandle {}
3260
3261#[must_use = "FIDL methods require a response to be sent"]
3262#[derive(Debug)]
3263pub struct ChannelListenerAcceptResponder {
3264    control_handle: std::mem::ManuallyDrop<ChannelListenerControlHandle>,
3265    tx_id: u32,
3266}
3267
3268/// Set the the channel to be shutdown (see [`ChannelListenerControlHandle::shutdown`])
3269/// if the responder is dropped without sending a response, so that the client
3270/// doesn't hang. To prevent this behavior, call `drop_without_shutdown`.
3271impl std::ops::Drop for ChannelListenerAcceptResponder {
3272    fn drop(&mut self) {
3273        self.control_handle.shutdown();
3274        // Safety: drops once, never accessed again
3275        unsafe { std::mem::ManuallyDrop::drop(&mut self.control_handle) };
3276    }
3277}
3278
3279impl fidl::endpoints::Responder for ChannelListenerAcceptResponder {
3280    type ControlHandle = ChannelListenerControlHandle;
3281
3282    fn control_handle(&self) -> &ChannelListenerControlHandle {
3283        &self.control_handle
3284    }
3285
3286    fn drop_without_shutdown(mut self) {
3287        // Safety: drops once, never accessed again due to mem::forget
3288        unsafe { std::mem::ManuallyDrop::drop(&mut self.control_handle) };
3289        // Prevent Drop from running (which would shut down the channel)
3290        std::mem::forget(self);
3291    }
3292}
3293
3294impl ChannelListenerAcceptResponder {
3295    /// Sends a response to the FIDL transaction.
3296    ///
3297    /// Sets the channel to shutdown if an error occurs.
3298    pub fn send(self) -> Result<(), fidl::Error> {
3299        let _result = self.send_raw();
3300        if _result.is_err() {
3301            self.control_handle.shutdown();
3302        }
3303        self.drop_without_shutdown();
3304        _result
3305    }
3306
3307    /// Similar to "send" but does not shutdown the channel if an error occurs.
3308    pub fn send_no_shutdown_on_err(self) -> Result<(), fidl::Error> {
3309        let _result = self.send_raw();
3310        self.drop_without_shutdown();
3311        _result
3312    }
3313
3314    fn send_raw(&self) -> Result<(), fidl::Error> {
3315        self.control_handle.inner.send::<fidl::encoding::FlexibleType<fidl::encoding::EmptyStruct>>(
3316            fidl::encoding::Flexible::new(()),
3317            self.tx_id,
3318            0x6f535bd36b20fc7b,
3319            fidl::encoding::DynamicFlags::FLEXIBLE,
3320        )
3321    }
3322}
3323
3324#[derive(Debug, Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Hash)]
3325pub struct ChannelListenerRegistryMarker;
3326
3327impl fidl::endpoints::ProtocolMarker for ChannelListenerRegistryMarker {
3328    type Proxy = ChannelListenerRegistryProxy;
3329    type RequestStream = ChannelListenerRegistryRequestStream;
3330    #[cfg(target_os = "fuchsia")]
3331    type SynchronousProxy = ChannelListenerRegistrySynchronousProxy;
3332
3333    const DEBUG_NAME: &'static str = "(anonymous) ChannelListenerRegistry";
3334}
3335pub type ChannelListenerRegistryListenL2capResult =
3336    Result<ChannelListenerRegistryListenL2capResponse, i32>;
3337
3338pub trait ChannelListenerRegistryProxyInterface: Send + Sync {
3339    type ListenL2capResponseFut: std::future::Future<Output = Result<ChannelListenerRegistryListenL2capResult, fidl::Error>>
3340        + Send;
3341    fn r#listen_l2cap(
3342        &self,
3343        payload: ChannelListenerRegistryListenL2capRequest,
3344    ) -> Self::ListenL2capResponseFut;
3345}
3346#[derive(Debug)]
3347#[cfg(target_os = "fuchsia")]
3348pub struct ChannelListenerRegistrySynchronousProxy {
3349    client: fidl::client::sync::Client,
3350}
3351
3352#[cfg(target_os = "fuchsia")]
3353impl fidl::endpoints::SynchronousProxy for ChannelListenerRegistrySynchronousProxy {
3354    type Proxy = ChannelListenerRegistryProxy;
3355    type Protocol = ChannelListenerRegistryMarker;
3356
3357    fn from_channel(inner: fidl::Channel) -> Self {
3358        Self::new(inner)
3359    }
3360
3361    fn into_channel(self) -> fidl::Channel {
3362        self.client.into_channel()
3363    }
3364
3365    fn as_channel(&self) -> &fidl::Channel {
3366        self.client.as_channel()
3367    }
3368}
3369
3370#[cfg(target_os = "fuchsia")]
3371impl ChannelListenerRegistrySynchronousProxy {
3372    pub fn new(channel: fidl::Channel) -> Self {
3373        let protocol_name =
3374            <ChannelListenerRegistryMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME;
3375        Self { client: fidl::client::sync::Client::new(channel, protocol_name) }
3376    }
3377
3378    pub fn into_channel(self) -> fidl::Channel {
3379        self.client.into_channel()
3380    }
3381
3382    /// Waits until an event arrives and returns it. It is safe for other
3383    /// threads to make concurrent requests while waiting for an event.
3384    pub fn wait_for_event(
3385        &self,
3386        deadline: zx::MonotonicInstant,
3387    ) -> Result<ChannelListenerRegistryEvent, fidl::Error> {
3388        ChannelListenerRegistryEvent::decode(self.client.wait_for_event(deadline)?)
3389    }
3390
3391    /// Register a listener for incoming channels. The registry will assign a
3392    /// PSM value that is unique for the local device, as well as open a
3393    /// [`ChannelListener`] for accepting incoming channels. In the unlikely
3394    /// event that all PSMs have been assigned, this call will fail with
3395    /// `ZX_ERR_NO_RESOURCES`.
3396    ///
3397    /// Note that the method of service discovery or advertising is defined by
3398    /// the service or protocol, so it is the responsibility of the caller to
3399    /// communicate the assigned PSM to any clients.
3400    pub fn r#listen_l2cap(
3401        &self,
3402        mut payload: ChannelListenerRegistryListenL2capRequest,
3403        ___deadline: zx::MonotonicInstant,
3404    ) -> Result<ChannelListenerRegistryListenL2capResult, fidl::Error> {
3405        let _response = self.client.send_query::<
3406            ChannelListenerRegistryListenL2capRequest,
3407            fidl::encoding::ResultType<ChannelListenerRegistryListenL2capResponse, i32>,
3408        >(
3409            &mut payload,
3410            0x39c6e9001d102338,
3411            fidl::encoding::DynamicFlags::empty(),
3412            ___deadline,
3413        )?;
3414        Ok(_response.map(|x| x))
3415    }
3416}
3417
3418#[cfg(target_os = "fuchsia")]
3419impl From<ChannelListenerRegistrySynchronousProxy> for zx::Handle {
3420    fn from(value: ChannelListenerRegistrySynchronousProxy) -> Self {
3421        value.into_channel().into()
3422    }
3423}
3424
3425#[cfg(target_os = "fuchsia")]
3426impl From<fidl::Channel> for ChannelListenerRegistrySynchronousProxy {
3427    fn from(value: fidl::Channel) -> Self {
3428        Self::new(value)
3429    }
3430}
3431
3432#[derive(Debug, Clone)]
3433pub struct ChannelListenerRegistryProxy {
3434    client: fidl::client::Client<fidl::encoding::DefaultFuchsiaResourceDialect>,
3435}
3436
3437impl fidl::endpoints::Proxy for ChannelListenerRegistryProxy {
3438    type Protocol = ChannelListenerRegistryMarker;
3439
3440    fn from_channel(inner: ::fidl::AsyncChannel) -> Self {
3441        Self::new(inner)
3442    }
3443
3444    fn into_channel(self) -> Result<::fidl::AsyncChannel, Self> {
3445        self.client.into_channel().map_err(|client| Self { client })
3446    }
3447
3448    fn as_channel(&self) -> &::fidl::AsyncChannel {
3449        self.client.as_channel()
3450    }
3451}
3452
3453impl ChannelListenerRegistryProxy {
3454    /// Create a new Proxy for fuchsia.bluetooth.le/ChannelListenerRegistry.
3455    pub fn new(channel: ::fidl::AsyncChannel) -> Self {
3456        let protocol_name =
3457            <ChannelListenerRegistryMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME;
3458        Self { client: fidl::client::Client::new(channel, protocol_name) }
3459    }
3460
3461    /// Get a Stream of events from the remote end of the protocol.
3462    ///
3463    /// # Panics
3464    ///
3465    /// Panics if the event stream was already taken.
3466    pub fn take_event_stream(&self) -> ChannelListenerRegistryEventStream {
3467        ChannelListenerRegistryEventStream { event_receiver: self.client.take_event_receiver() }
3468    }
3469
3470    /// Register a listener for incoming channels. The registry will assign a
3471    /// PSM value that is unique for the local device, as well as open a
3472    /// [`ChannelListener`] for accepting incoming channels. In the unlikely
3473    /// event that all PSMs have been assigned, this call will fail with
3474    /// `ZX_ERR_NO_RESOURCES`.
3475    ///
3476    /// Note that the method of service discovery or advertising is defined by
3477    /// the service or protocol, so it is the responsibility of the caller to
3478    /// communicate the assigned PSM to any clients.
3479    pub fn r#listen_l2cap(
3480        &self,
3481        mut payload: ChannelListenerRegistryListenL2capRequest,
3482    ) -> fidl::client::QueryResponseFut<
3483        ChannelListenerRegistryListenL2capResult,
3484        fidl::encoding::DefaultFuchsiaResourceDialect,
3485    > {
3486        ChannelListenerRegistryProxyInterface::r#listen_l2cap(self, payload)
3487    }
3488}
3489
3490impl ChannelListenerRegistryProxyInterface for ChannelListenerRegistryProxy {
3491    type ListenL2capResponseFut = fidl::client::QueryResponseFut<
3492        ChannelListenerRegistryListenL2capResult,
3493        fidl::encoding::DefaultFuchsiaResourceDialect,
3494    >;
3495    fn r#listen_l2cap(
3496        &self,
3497        mut payload: ChannelListenerRegistryListenL2capRequest,
3498    ) -> Self::ListenL2capResponseFut {
3499        fn _decode(
3500            mut _buf: Result<<fidl::encoding::DefaultFuchsiaResourceDialect as fidl::encoding::ResourceDialect>::MessageBufEtc, fidl::Error>,
3501        ) -> Result<ChannelListenerRegistryListenL2capResult, fidl::Error> {
3502            let _response = fidl::client::decode_transaction_body::<
3503                fidl::encoding::ResultType<ChannelListenerRegistryListenL2capResponse, i32>,
3504                fidl::encoding::DefaultFuchsiaResourceDialect,
3505                0x39c6e9001d102338,
3506            >(_buf?)?;
3507            Ok(_response.map(|x| x))
3508        }
3509        self.client.send_query_and_decode::<
3510            ChannelListenerRegistryListenL2capRequest,
3511            ChannelListenerRegistryListenL2capResult,
3512        >(
3513            &mut payload,
3514            0x39c6e9001d102338,
3515            fidl::encoding::DynamicFlags::empty(),
3516            _decode,
3517        )
3518    }
3519}
3520
3521pub struct ChannelListenerRegistryEventStream {
3522    event_receiver: fidl::client::EventReceiver<fidl::encoding::DefaultFuchsiaResourceDialect>,
3523}
3524
3525impl std::marker::Unpin for ChannelListenerRegistryEventStream {}
3526
3527impl futures::stream::FusedStream for ChannelListenerRegistryEventStream {
3528    fn is_terminated(&self) -> bool {
3529        self.event_receiver.is_terminated()
3530    }
3531}
3532
3533impl futures::Stream for ChannelListenerRegistryEventStream {
3534    type Item = Result<ChannelListenerRegistryEvent, fidl::Error>;
3535
3536    fn poll_next(
3537        mut self: std::pin::Pin<&mut Self>,
3538        cx: &mut std::task::Context<'_>,
3539    ) -> std::task::Poll<Option<Self::Item>> {
3540        match futures::ready!(futures::stream::StreamExt::poll_next_unpin(
3541            &mut self.event_receiver,
3542            cx
3543        )?) {
3544            Some(buf) => std::task::Poll::Ready(Some(ChannelListenerRegistryEvent::decode(buf))),
3545            None => std::task::Poll::Ready(None),
3546        }
3547    }
3548}
3549
3550#[derive(Debug)]
3551pub enum ChannelListenerRegistryEvent {}
3552
3553impl ChannelListenerRegistryEvent {
3554    /// Decodes a message buffer as a [`ChannelListenerRegistryEvent`].
3555    fn decode(
3556        mut buf: <fidl::encoding::DefaultFuchsiaResourceDialect as fidl::encoding::ResourceDialect>::MessageBufEtc,
3557    ) -> Result<ChannelListenerRegistryEvent, fidl::Error> {
3558        let (bytes, _handles) = buf.split_mut();
3559        let (tx_header, _body_bytes) = fidl::encoding::decode_transaction_header(bytes)?;
3560        debug_assert_eq!(tx_header.tx_id, 0);
3561        match tx_header.ordinal {
3562            _ => Err(fidl::Error::UnknownOrdinal {
3563                ordinal: tx_header.ordinal,
3564                protocol_name:
3565                    <ChannelListenerRegistryMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME,
3566            }),
3567        }
3568    }
3569}
3570
3571/// A Stream of incoming requests for fuchsia.bluetooth.le/ChannelListenerRegistry.
3572pub struct ChannelListenerRegistryRequestStream {
3573    inner: std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>,
3574    is_terminated: bool,
3575}
3576
3577impl std::marker::Unpin for ChannelListenerRegistryRequestStream {}
3578
3579impl futures::stream::FusedStream for ChannelListenerRegistryRequestStream {
3580    fn is_terminated(&self) -> bool {
3581        self.is_terminated
3582    }
3583}
3584
3585impl fidl::endpoints::RequestStream for ChannelListenerRegistryRequestStream {
3586    type Protocol = ChannelListenerRegistryMarker;
3587    type ControlHandle = ChannelListenerRegistryControlHandle;
3588
3589    fn from_channel(channel: ::fidl::AsyncChannel) -> Self {
3590        Self { inner: std::sync::Arc::new(fidl::ServeInner::new(channel)), is_terminated: false }
3591    }
3592
3593    fn control_handle(&self) -> Self::ControlHandle {
3594        ChannelListenerRegistryControlHandle { inner: self.inner.clone() }
3595    }
3596
3597    fn into_inner(
3598        self,
3599    ) -> (::std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>, bool)
3600    {
3601        (self.inner, self.is_terminated)
3602    }
3603
3604    fn from_inner(
3605        inner: std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>,
3606        is_terminated: bool,
3607    ) -> Self {
3608        Self { inner, is_terminated }
3609    }
3610}
3611
3612impl futures::Stream for ChannelListenerRegistryRequestStream {
3613    type Item = Result<ChannelListenerRegistryRequest, fidl::Error>;
3614
3615    fn poll_next(
3616        mut self: std::pin::Pin<&mut Self>,
3617        cx: &mut std::task::Context<'_>,
3618    ) -> std::task::Poll<Option<Self::Item>> {
3619        let this = &mut *self;
3620        if this.inner.check_shutdown(cx) {
3621            this.is_terminated = true;
3622            return std::task::Poll::Ready(None);
3623        }
3624        if this.is_terminated {
3625            panic!("polled ChannelListenerRegistryRequestStream after completion");
3626        }
3627        fidl::encoding::with_tls_decode_buf::<_, fidl::encoding::DefaultFuchsiaResourceDialect>(
3628            |bytes, handles| {
3629                match this.inner.channel().read_etc(cx, bytes, handles) {
3630                    std::task::Poll::Ready(Ok(())) => {}
3631                    std::task::Poll::Pending => return std::task::Poll::Pending,
3632                    std::task::Poll::Ready(Err(zx_status::Status::PEER_CLOSED)) => {
3633                        this.is_terminated = true;
3634                        return std::task::Poll::Ready(None);
3635                    }
3636                    std::task::Poll::Ready(Err(e)) => {
3637                        return std::task::Poll::Ready(Some(Err(fidl::Error::ServerRequestRead(
3638                            e.into(),
3639                        ))))
3640                    }
3641                }
3642
3643                // A message has been received from the channel
3644                let (header, _body_bytes) = fidl::encoding::decode_transaction_header(bytes)?;
3645
3646                std::task::Poll::Ready(Some(match header.ordinal {
3647                0x39c6e9001d102338 => {
3648                    header.validate_request_tx_id(fidl::MethodType::TwoWay)?;
3649                    let mut req = fidl::new_empty!(ChannelListenerRegistryListenL2capRequest, fidl::encoding::DefaultFuchsiaResourceDialect);
3650                    fidl::encoding::Decoder::<fidl::encoding::DefaultFuchsiaResourceDialect>::decode_into::<ChannelListenerRegistryListenL2capRequest>(&header, _body_bytes, handles, &mut req)?;
3651                    let control_handle = ChannelListenerRegistryControlHandle {
3652                        inner: this.inner.clone(),
3653                    };
3654                    Ok(ChannelListenerRegistryRequest::ListenL2cap {payload: req,
3655                        responder: ChannelListenerRegistryListenL2capResponder {
3656                            control_handle: std::mem::ManuallyDrop::new(control_handle),
3657                            tx_id: header.tx_id,
3658                        },
3659                    })
3660                }
3661                _ => Err(fidl::Error::UnknownOrdinal {
3662                    ordinal: header.ordinal,
3663                    protocol_name: <ChannelListenerRegistryMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME,
3664                }),
3665            }))
3666            },
3667        )
3668    }
3669}
3670
3671/// Represents the ability to register and accept incoming connections on
3672/// connection oriented channels.
3673#[derive(Debug)]
3674pub enum ChannelListenerRegistryRequest {
3675    /// Register a listener for incoming channels. The registry will assign a
3676    /// PSM value that is unique for the local device, as well as open a
3677    /// [`ChannelListener`] for accepting incoming channels. In the unlikely
3678    /// event that all PSMs have been assigned, this call will fail with
3679    /// `ZX_ERR_NO_RESOURCES`.
3680    ///
3681    /// Note that the method of service discovery or advertising is defined by
3682    /// the service or protocol, so it is the responsibility of the caller to
3683    /// communicate the assigned PSM to any clients.
3684    ListenL2cap {
3685        payload: ChannelListenerRegistryListenL2capRequest,
3686        responder: ChannelListenerRegistryListenL2capResponder,
3687    },
3688}
3689
3690impl ChannelListenerRegistryRequest {
3691    #[allow(irrefutable_let_patterns)]
3692    pub fn into_listen_l2cap(
3693        self,
3694    ) -> Option<(
3695        ChannelListenerRegistryListenL2capRequest,
3696        ChannelListenerRegistryListenL2capResponder,
3697    )> {
3698        if let ChannelListenerRegistryRequest::ListenL2cap { payload, responder } = self {
3699            Some((payload, responder))
3700        } else {
3701            None
3702        }
3703    }
3704
3705    /// Name of the method defined in FIDL
3706    pub fn method_name(&self) -> &'static str {
3707        match *self {
3708            ChannelListenerRegistryRequest::ListenL2cap { .. } => "listen_l2cap",
3709        }
3710    }
3711}
3712
3713#[derive(Debug, Clone)]
3714pub struct ChannelListenerRegistryControlHandle {
3715    inner: std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>,
3716}
3717
3718impl fidl::endpoints::ControlHandle for ChannelListenerRegistryControlHandle {
3719    fn shutdown(&self) {
3720        self.inner.shutdown()
3721    }
3722    fn shutdown_with_epitaph(&self, status: zx_status::Status) {
3723        self.inner.shutdown_with_epitaph(status)
3724    }
3725
3726    fn is_closed(&self) -> bool {
3727        self.inner.channel().is_closed()
3728    }
3729    fn on_closed(&self) -> fidl::OnSignalsRef<'_> {
3730        self.inner.channel().on_closed()
3731    }
3732
3733    #[cfg(target_os = "fuchsia")]
3734    fn signal_peer(
3735        &self,
3736        clear_mask: zx::Signals,
3737        set_mask: zx::Signals,
3738    ) -> Result<(), zx_status::Status> {
3739        use fidl::Peered;
3740        self.inner.channel().signal_peer(clear_mask, set_mask)
3741    }
3742}
3743
3744impl ChannelListenerRegistryControlHandle {}
3745
3746#[must_use = "FIDL methods require a response to be sent"]
3747#[derive(Debug)]
3748pub struct ChannelListenerRegistryListenL2capResponder {
3749    control_handle: std::mem::ManuallyDrop<ChannelListenerRegistryControlHandle>,
3750    tx_id: u32,
3751}
3752
3753/// Set the the channel to be shutdown (see [`ChannelListenerRegistryControlHandle::shutdown`])
3754/// if the responder is dropped without sending a response, so that the client
3755/// doesn't hang. To prevent this behavior, call `drop_without_shutdown`.
3756impl std::ops::Drop for ChannelListenerRegistryListenL2capResponder {
3757    fn drop(&mut self) {
3758        self.control_handle.shutdown();
3759        // Safety: drops once, never accessed again
3760        unsafe { std::mem::ManuallyDrop::drop(&mut self.control_handle) };
3761    }
3762}
3763
3764impl fidl::endpoints::Responder for ChannelListenerRegistryListenL2capResponder {
3765    type ControlHandle = ChannelListenerRegistryControlHandle;
3766
3767    fn control_handle(&self) -> &ChannelListenerRegistryControlHandle {
3768        &self.control_handle
3769    }
3770
3771    fn drop_without_shutdown(mut self) {
3772        // Safety: drops once, never accessed again due to mem::forget
3773        unsafe { std::mem::ManuallyDrop::drop(&mut self.control_handle) };
3774        // Prevent Drop from running (which would shut down the channel)
3775        std::mem::forget(self);
3776    }
3777}
3778
3779impl ChannelListenerRegistryListenL2capResponder {
3780    /// Sends a response to the FIDL transaction.
3781    ///
3782    /// Sets the channel to shutdown if an error occurs.
3783    pub fn send(
3784        self,
3785        mut result: Result<&ChannelListenerRegistryListenL2capResponse, i32>,
3786    ) -> Result<(), fidl::Error> {
3787        let _result = self.send_raw(result);
3788        if _result.is_err() {
3789            self.control_handle.shutdown();
3790        }
3791        self.drop_without_shutdown();
3792        _result
3793    }
3794
3795    /// Similar to "send" but does not shutdown the channel if an error occurs.
3796    pub fn send_no_shutdown_on_err(
3797        self,
3798        mut result: Result<&ChannelListenerRegistryListenL2capResponse, i32>,
3799    ) -> Result<(), fidl::Error> {
3800        let _result = self.send_raw(result);
3801        self.drop_without_shutdown();
3802        _result
3803    }
3804
3805    fn send_raw(
3806        &self,
3807        mut result: Result<&ChannelListenerRegistryListenL2capResponse, i32>,
3808    ) -> Result<(), fidl::Error> {
3809        self.control_handle.inner.send::<fidl::encoding::ResultType<
3810            ChannelListenerRegistryListenL2capResponse,
3811            i32,
3812        >>(
3813            result,
3814            self.tx_id,
3815            0x39c6e9001d102338,
3816            fidl::encoding::DynamicFlags::empty(),
3817        )
3818    }
3819}
3820
3821#[derive(Debug, Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Hash)]
3822pub struct CodecDelayMarker;
3823
3824impl fidl::endpoints::ProtocolMarker for CodecDelayMarker {
3825    type Proxy = CodecDelayProxy;
3826    type RequestStream = CodecDelayRequestStream;
3827    #[cfg(target_os = "fuchsia")]
3828    type SynchronousProxy = CodecDelaySynchronousProxy;
3829
3830    const DEBUG_NAME: &'static str = "(anonymous) CodecDelay";
3831}
3832pub type CodecDelayGetCodecLocalDelayRangeResult =
3833    Result<CodecDelayGetCodecLocalDelayRangeResponse, i32>;
3834
3835pub trait CodecDelayProxyInterface: Send + Sync {
3836    type GetCodecLocalDelayRangeResponseFut: std::future::Future<Output = Result<CodecDelayGetCodecLocalDelayRangeResult, fidl::Error>>
3837        + Send;
3838    fn r#get_codec_local_delay_range(
3839        &self,
3840        payload: &CodecDelayGetCodecLocalDelayRangeRequest,
3841    ) -> Self::GetCodecLocalDelayRangeResponseFut;
3842}
3843#[derive(Debug)]
3844#[cfg(target_os = "fuchsia")]
3845pub struct CodecDelaySynchronousProxy {
3846    client: fidl::client::sync::Client,
3847}
3848
3849#[cfg(target_os = "fuchsia")]
3850impl fidl::endpoints::SynchronousProxy for CodecDelaySynchronousProxy {
3851    type Proxy = CodecDelayProxy;
3852    type Protocol = CodecDelayMarker;
3853
3854    fn from_channel(inner: fidl::Channel) -> Self {
3855        Self::new(inner)
3856    }
3857
3858    fn into_channel(self) -> fidl::Channel {
3859        self.client.into_channel()
3860    }
3861
3862    fn as_channel(&self) -> &fidl::Channel {
3863        self.client.as_channel()
3864    }
3865}
3866
3867#[cfg(target_os = "fuchsia")]
3868impl CodecDelaySynchronousProxy {
3869    pub fn new(channel: fidl::Channel) -> Self {
3870        let protocol_name = <CodecDelayMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME;
3871        Self { client: fidl::client::sync::Client::new(channel, protocol_name) }
3872    }
3873
3874    pub fn into_channel(self) -> fidl::Channel {
3875        self.client.into_channel()
3876    }
3877
3878    /// Waits until an event arrives and returns it. It is safe for other
3879    /// threads to make concurrent requests while waiting for an event.
3880    pub fn wait_for_event(
3881        &self,
3882        deadline: zx::MonotonicInstant,
3883    ) -> Result<CodecDelayEvent, fidl::Error> {
3884        CodecDelayEvent::decode(self.client.wait_for_event(deadline)?)
3885    }
3886
3887    /// Retrieve the range of controller delay for the codec specified with the provided stream
3888    /// attributes.
3889    ///
3890    /// On success, returns the minimum and maximum allowed delay.
3891    ///
3892    /// Returns ZX_ERR_NOT_SUPPORTED if reading the delay is not supported.
3893    /// Returns ZX_ERR_INTERNAL for all other failures.
3894    pub fn r#get_codec_local_delay_range(
3895        &self,
3896        mut payload: &CodecDelayGetCodecLocalDelayRangeRequest,
3897        ___deadline: zx::MonotonicInstant,
3898    ) -> Result<CodecDelayGetCodecLocalDelayRangeResult, fidl::Error> {
3899        let _response = self.client.send_query::<
3900            CodecDelayGetCodecLocalDelayRangeRequest,
3901            fidl::encoding::ResultType<CodecDelayGetCodecLocalDelayRangeResponse, i32>,
3902        >(
3903            payload,
3904            0x1cf34fdeed80b4d,
3905            fidl::encoding::DynamicFlags::empty(),
3906            ___deadline,
3907        )?;
3908        Ok(_response.map(|x| x))
3909    }
3910}
3911
3912#[cfg(target_os = "fuchsia")]
3913impl From<CodecDelaySynchronousProxy> for zx::Handle {
3914    fn from(value: CodecDelaySynchronousProxy) -> Self {
3915        value.into_channel().into()
3916    }
3917}
3918
3919#[cfg(target_os = "fuchsia")]
3920impl From<fidl::Channel> for CodecDelaySynchronousProxy {
3921    fn from(value: fidl::Channel) -> Self {
3922        Self::new(value)
3923    }
3924}
3925
3926#[derive(Debug, Clone)]
3927pub struct CodecDelayProxy {
3928    client: fidl::client::Client<fidl::encoding::DefaultFuchsiaResourceDialect>,
3929}
3930
3931impl fidl::endpoints::Proxy for CodecDelayProxy {
3932    type Protocol = CodecDelayMarker;
3933
3934    fn from_channel(inner: ::fidl::AsyncChannel) -> Self {
3935        Self::new(inner)
3936    }
3937
3938    fn into_channel(self) -> Result<::fidl::AsyncChannel, Self> {
3939        self.client.into_channel().map_err(|client| Self { client })
3940    }
3941
3942    fn as_channel(&self) -> &::fidl::AsyncChannel {
3943        self.client.as_channel()
3944    }
3945}
3946
3947impl CodecDelayProxy {
3948    /// Create a new Proxy for fuchsia.bluetooth.le/CodecDelay.
3949    pub fn new(channel: ::fidl::AsyncChannel) -> Self {
3950        let protocol_name = <CodecDelayMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME;
3951        Self { client: fidl::client::Client::new(channel, protocol_name) }
3952    }
3953
3954    /// Get a Stream of events from the remote end of the protocol.
3955    ///
3956    /// # Panics
3957    ///
3958    /// Panics if the event stream was already taken.
3959    pub fn take_event_stream(&self) -> CodecDelayEventStream {
3960        CodecDelayEventStream { event_receiver: self.client.take_event_receiver() }
3961    }
3962
3963    /// Retrieve the range of controller delay for the codec specified with the provided stream
3964    /// attributes.
3965    ///
3966    /// On success, returns the minimum and maximum allowed delay.
3967    ///
3968    /// Returns ZX_ERR_NOT_SUPPORTED if reading the delay is not supported.
3969    /// Returns ZX_ERR_INTERNAL for all other failures.
3970    pub fn r#get_codec_local_delay_range(
3971        &self,
3972        mut payload: &CodecDelayGetCodecLocalDelayRangeRequest,
3973    ) -> fidl::client::QueryResponseFut<
3974        CodecDelayGetCodecLocalDelayRangeResult,
3975        fidl::encoding::DefaultFuchsiaResourceDialect,
3976    > {
3977        CodecDelayProxyInterface::r#get_codec_local_delay_range(self, payload)
3978    }
3979}
3980
3981impl CodecDelayProxyInterface for CodecDelayProxy {
3982    type GetCodecLocalDelayRangeResponseFut = fidl::client::QueryResponseFut<
3983        CodecDelayGetCodecLocalDelayRangeResult,
3984        fidl::encoding::DefaultFuchsiaResourceDialect,
3985    >;
3986    fn r#get_codec_local_delay_range(
3987        &self,
3988        mut payload: &CodecDelayGetCodecLocalDelayRangeRequest,
3989    ) -> Self::GetCodecLocalDelayRangeResponseFut {
3990        fn _decode(
3991            mut _buf: Result<<fidl::encoding::DefaultFuchsiaResourceDialect as fidl::encoding::ResourceDialect>::MessageBufEtc, fidl::Error>,
3992        ) -> Result<CodecDelayGetCodecLocalDelayRangeResult, fidl::Error> {
3993            let _response = fidl::client::decode_transaction_body::<
3994                fidl::encoding::ResultType<CodecDelayGetCodecLocalDelayRangeResponse, i32>,
3995                fidl::encoding::DefaultFuchsiaResourceDialect,
3996                0x1cf34fdeed80b4d,
3997            >(_buf?)?;
3998            Ok(_response.map(|x| x))
3999        }
4000        self.client.send_query_and_decode::<
4001            CodecDelayGetCodecLocalDelayRangeRequest,
4002            CodecDelayGetCodecLocalDelayRangeResult,
4003        >(
4004            payload,
4005            0x1cf34fdeed80b4d,
4006            fidl::encoding::DynamicFlags::empty(),
4007            _decode,
4008        )
4009    }
4010}
4011
4012pub struct CodecDelayEventStream {
4013    event_receiver: fidl::client::EventReceiver<fidl::encoding::DefaultFuchsiaResourceDialect>,
4014}
4015
4016impl std::marker::Unpin for CodecDelayEventStream {}
4017
4018impl futures::stream::FusedStream for CodecDelayEventStream {
4019    fn is_terminated(&self) -> bool {
4020        self.event_receiver.is_terminated()
4021    }
4022}
4023
4024impl futures::Stream for CodecDelayEventStream {
4025    type Item = Result<CodecDelayEvent, fidl::Error>;
4026
4027    fn poll_next(
4028        mut self: std::pin::Pin<&mut Self>,
4029        cx: &mut std::task::Context<'_>,
4030    ) -> std::task::Poll<Option<Self::Item>> {
4031        match futures::ready!(futures::stream::StreamExt::poll_next_unpin(
4032            &mut self.event_receiver,
4033            cx
4034        )?) {
4035            Some(buf) => std::task::Poll::Ready(Some(CodecDelayEvent::decode(buf))),
4036            None => std::task::Poll::Ready(None),
4037        }
4038    }
4039}
4040
4041#[derive(Debug)]
4042pub enum CodecDelayEvent {}
4043
4044impl CodecDelayEvent {
4045    /// Decodes a message buffer as a [`CodecDelayEvent`].
4046    fn decode(
4047        mut buf: <fidl::encoding::DefaultFuchsiaResourceDialect as fidl::encoding::ResourceDialect>::MessageBufEtc,
4048    ) -> Result<CodecDelayEvent, fidl::Error> {
4049        let (bytes, _handles) = buf.split_mut();
4050        let (tx_header, _body_bytes) = fidl::encoding::decode_transaction_header(bytes)?;
4051        debug_assert_eq!(tx_header.tx_id, 0);
4052        match tx_header.ordinal {
4053            _ => Err(fidl::Error::UnknownOrdinal {
4054                ordinal: tx_header.ordinal,
4055                protocol_name: <CodecDelayMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME,
4056            }),
4057        }
4058    }
4059}
4060
4061/// A Stream of incoming requests for fuchsia.bluetooth.le/CodecDelay.
4062pub struct CodecDelayRequestStream {
4063    inner: std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>,
4064    is_terminated: bool,
4065}
4066
4067impl std::marker::Unpin for CodecDelayRequestStream {}
4068
4069impl futures::stream::FusedStream for CodecDelayRequestStream {
4070    fn is_terminated(&self) -> bool {
4071        self.is_terminated
4072    }
4073}
4074
4075impl fidl::endpoints::RequestStream for CodecDelayRequestStream {
4076    type Protocol = CodecDelayMarker;
4077    type ControlHandle = CodecDelayControlHandle;
4078
4079    fn from_channel(channel: ::fidl::AsyncChannel) -> Self {
4080        Self { inner: std::sync::Arc::new(fidl::ServeInner::new(channel)), is_terminated: false }
4081    }
4082
4083    fn control_handle(&self) -> Self::ControlHandle {
4084        CodecDelayControlHandle { inner: self.inner.clone() }
4085    }
4086
4087    fn into_inner(
4088        self,
4089    ) -> (::std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>, bool)
4090    {
4091        (self.inner, self.is_terminated)
4092    }
4093
4094    fn from_inner(
4095        inner: std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>,
4096        is_terminated: bool,
4097    ) -> Self {
4098        Self { inner, is_terminated }
4099    }
4100}
4101
4102impl futures::Stream for CodecDelayRequestStream {
4103    type Item = Result<CodecDelayRequest, fidl::Error>;
4104
4105    fn poll_next(
4106        mut self: std::pin::Pin<&mut Self>,
4107        cx: &mut std::task::Context<'_>,
4108    ) -> std::task::Poll<Option<Self::Item>> {
4109        let this = &mut *self;
4110        if this.inner.check_shutdown(cx) {
4111            this.is_terminated = true;
4112            return std::task::Poll::Ready(None);
4113        }
4114        if this.is_terminated {
4115            panic!("polled CodecDelayRequestStream after completion");
4116        }
4117        fidl::encoding::with_tls_decode_buf::<_, fidl::encoding::DefaultFuchsiaResourceDialect>(
4118            |bytes, handles| {
4119                match this.inner.channel().read_etc(cx, bytes, handles) {
4120                    std::task::Poll::Ready(Ok(())) => {}
4121                    std::task::Poll::Pending => return std::task::Poll::Pending,
4122                    std::task::Poll::Ready(Err(zx_status::Status::PEER_CLOSED)) => {
4123                        this.is_terminated = true;
4124                        return std::task::Poll::Ready(None);
4125                    }
4126                    std::task::Poll::Ready(Err(e)) => {
4127                        return std::task::Poll::Ready(Some(Err(fidl::Error::ServerRequestRead(
4128                            e.into(),
4129                        ))))
4130                    }
4131                }
4132
4133                // A message has been received from the channel
4134                let (header, _body_bytes) = fidl::encoding::decode_transaction_header(bytes)?;
4135
4136                std::task::Poll::Ready(Some(match header.ordinal {
4137                    0x1cf34fdeed80b4d => {
4138                        header.validate_request_tx_id(fidl::MethodType::TwoWay)?;
4139                        let mut req = fidl::new_empty!(
4140                            CodecDelayGetCodecLocalDelayRangeRequest,
4141                            fidl::encoding::DefaultFuchsiaResourceDialect
4142                        );
4143                        fidl::encoding::Decoder::<fidl::encoding::DefaultFuchsiaResourceDialect>::decode_into::<CodecDelayGetCodecLocalDelayRangeRequest>(&header, _body_bytes, handles, &mut req)?;
4144                        let control_handle = CodecDelayControlHandle { inner: this.inner.clone() };
4145                        Ok(CodecDelayRequest::GetCodecLocalDelayRange {
4146                            payload: req,
4147                            responder: CodecDelayGetCodecLocalDelayRangeResponder {
4148                                control_handle: std::mem::ManuallyDrop::new(control_handle),
4149                                tx_id: header.tx_id,
4150                            },
4151                        })
4152                    }
4153                    _ => Err(fidl::Error::UnknownOrdinal {
4154                        ordinal: header.ordinal,
4155                        protocol_name:
4156                            <CodecDelayMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME,
4157                    }),
4158                }))
4159            },
4160        )
4161    }
4162}
4163
4164/// This protocol allows us to retrieve controller local delay values. It is not intended to be
4165/// used stand-alone, but to be composed into protocols that need access to this information.
4166#[derive(Debug)]
4167pub enum CodecDelayRequest {
4168    /// Retrieve the range of controller delay for the codec specified with the provided stream
4169    /// attributes.
4170    ///
4171    /// On success, returns the minimum and maximum allowed delay.
4172    ///
4173    /// Returns ZX_ERR_NOT_SUPPORTED if reading the delay is not supported.
4174    /// Returns ZX_ERR_INTERNAL for all other failures.
4175    GetCodecLocalDelayRange {
4176        payload: CodecDelayGetCodecLocalDelayRangeRequest,
4177        responder: CodecDelayGetCodecLocalDelayRangeResponder,
4178    },
4179}
4180
4181impl CodecDelayRequest {
4182    #[allow(irrefutable_let_patterns)]
4183    pub fn into_get_codec_local_delay_range(
4184        self,
4185    ) -> Option<(
4186        CodecDelayGetCodecLocalDelayRangeRequest,
4187        CodecDelayGetCodecLocalDelayRangeResponder,
4188    )> {
4189        if let CodecDelayRequest::GetCodecLocalDelayRange { payload, responder } = self {
4190            Some((payload, responder))
4191        } else {
4192            None
4193        }
4194    }
4195
4196    /// Name of the method defined in FIDL
4197    pub fn method_name(&self) -> &'static str {
4198        match *self {
4199            CodecDelayRequest::GetCodecLocalDelayRange { .. } => "get_codec_local_delay_range",
4200        }
4201    }
4202}
4203
4204#[derive(Debug, Clone)]
4205pub struct CodecDelayControlHandle {
4206    inner: std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>,
4207}
4208
4209impl fidl::endpoints::ControlHandle for CodecDelayControlHandle {
4210    fn shutdown(&self) {
4211        self.inner.shutdown()
4212    }
4213    fn shutdown_with_epitaph(&self, status: zx_status::Status) {
4214        self.inner.shutdown_with_epitaph(status)
4215    }
4216
4217    fn is_closed(&self) -> bool {
4218        self.inner.channel().is_closed()
4219    }
4220    fn on_closed(&self) -> fidl::OnSignalsRef<'_> {
4221        self.inner.channel().on_closed()
4222    }
4223
4224    #[cfg(target_os = "fuchsia")]
4225    fn signal_peer(
4226        &self,
4227        clear_mask: zx::Signals,
4228        set_mask: zx::Signals,
4229    ) -> Result<(), zx_status::Status> {
4230        use fidl::Peered;
4231        self.inner.channel().signal_peer(clear_mask, set_mask)
4232    }
4233}
4234
4235impl CodecDelayControlHandle {}
4236
4237#[must_use = "FIDL methods require a response to be sent"]
4238#[derive(Debug)]
4239pub struct CodecDelayGetCodecLocalDelayRangeResponder {
4240    control_handle: std::mem::ManuallyDrop<CodecDelayControlHandle>,
4241    tx_id: u32,
4242}
4243
4244/// Set the the channel to be shutdown (see [`CodecDelayControlHandle::shutdown`])
4245/// if the responder is dropped without sending a response, so that the client
4246/// doesn't hang. To prevent this behavior, call `drop_without_shutdown`.
4247impl std::ops::Drop for CodecDelayGetCodecLocalDelayRangeResponder {
4248    fn drop(&mut self) {
4249        self.control_handle.shutdown();
4250        // Safety: drops once, never accessed again
4251        unsafe { std::mem::ManuallyDrop::drop(&mut self.control_handle) };
4252    }
4253}
4254
4255impl fidl::endpoints::Responder for CodecDelayGetCodecLocalDelayRangeResponder {
4256    type ControlHandle = CodecDelayControlHandle;
4257
4258    fn control_handle(&self) -> &CodecDelayControlHandle {
4259        &self.control_handle
4260    }
4261
4262    fn drop_without_shutdown(mut self) {
4263        // Safety: drops once, never accessed again due to mem::forget
4264        unsafe { std::mem::ManuallyDrop::drop(&mut self.control_handle) };
4265        // Prevent Drop from running (which would shut down the channel)
4266        std::mem::forget(self);
4267    }
4268}
4269
4270impl CodecDelayGetCodecLocalDelayRangeResponder {
4271    /// Sends a response to the FIDL transaction.
4272    ///
4273    /// Sets the channel to shutdown if an error occurs.
4274    pub fn send(
4275        self,
4276        mut result: Result<&CodecDelayGetCodecLocalDelayRangeResponse, i32>,
4277    ) -> Result<(), fidl::Error> {
4278        let _result = self.send_raw(result);
4279        if _result.is_err() {
4280            self.control_handle.shutdown();
4281        }
4282        self.drop_without_shutdown();
4283        _result
4284    }
4285
4286    /// Similar to "send" but does not shutdown the channel if an error occurs.
4287    pub fn send_no_shutdown_on_err(
4288        self,
4289        mut result: Result<&CodecDelayGetCodecLocalDelayRangeResponse, i32>,
4290    ) -> Result<(), fidl::Error> {
4291        let _result = self.send_raw(result);
4292        self.drop_without_shutdown();
4293        _result
4294    }
4295
4296    fn send_raw(
4297        &self,
4298        mut result: Result<&CodecDelayGetCodecLocalDelayRangeResponse, i32>,
4299    ) -> Result<(), fidl::Error> {
4300        self.control_handle.inner.send::<fidl::encoding::ResultType<
4301            CodecDelayGetCodecLocalDelayRangeResponse,
4302            i32,
4303        >>(
4304            result,
4305            self.tx_id,
4306            0x1cf34fdeed80b4d,
4307            fidl::encoding::DynamicFlags::empty(),
4308        )
4309    }
4310}
4311
4312#[derive(Debug, Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Hash)]
4313pub struct ConnectionMarker;
4314
4315impl fidl::endpoints::ProtocolMarker for ConnectionMarker {
4316    type Proxy = ConnectionProxy;
4317    type RequestStream = ConnectionRequestStream;
4318    #[cfg(target_os = "fuchsia")]
4319    type SynchronousProxy = ConnectionSynchronousProxy;
4320
4321    const DEBUG_NAME: &'static str = "(anonymous) Connection";
4322}
4323
4324pub trait ConnectionProxyInterface: Send + Sync {
4325    type GetCodecLocalDelayRangeResponseFut: std::future::Future<Output = Result<CodecDelayGetCodecLocalDelayRangeResult, fidl::Error>>
4326        + Send;
4327    fn r#get_codec_local_delay_range(
4328        &self,
4329        payload: &CodecDelayGetCodecLocalDelayRangeRequest,
4330    ) -> Self::GetCodecLocalDelayRangeResponseFut;
4331    fn r#request_gatt_client(
4332        &self,
4333        client: fidl::endpoints::ServerEnd<fidl_fuchsia_bluetooth_gatt2::ClientMarker>,
4334    ) -> Result<(), fidl::Error>;
4335    fn r#accept_cis(&self, payload: ConnectionAcceptCisRequest) -> Result<(), fidl::Error>;
4336    fn r#connect_l2cap(&self, payload: ConnectionConnectL2capRequest) -> Result<(), fidl::Error>;
4337}
4338#[derive(Debug)]
4339#[cfg(target_os = "fuchsia")]
4340pub struct ConnectionSynchronousProxy {
4341    client: fidl::client::sync::Client,
4342}
4343
4344#[cfg(target_os = "fuchsia")]
4345impl fidl::endpoints::SynchronousProxy for ConnectionSynchronousProxy {
4346    type Proxy = ConnectionProxy;
4347    type Protocol = ConnectionMarker;
4348
4349    fn from_channel(inner: fidl::Channel) -> Self {
4350        Self::new(inner)
4351    }
4352
4353    fn into_channel(self) -> fidl::Channel {
4354        self.client.into_channel()
4355    }
4356
4357    fn as_channel(&self) -> &fidl::Channel {
4358        self.client.as_channel()
4359    }
4360}
4361
4362#[cfg(target_os = "fuchsia")]
4363impl ConnectionSynchronousProxy {
4364    pub fn new(channel: fidl::Channel) -> Self {
4365        let protocol_name = <ConnectionMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME;
4366        Self { client: fidl::client::sync::Client::new(channel, protocol_name) }
4367    }
4368
4369    pub fn into_channel(self) -> fidl::Channel {
4370        self.client.into_channel()
4371    }
4372
4373    /// Waits until an event arrives and returns it. It is safe for other
4374    /// threads to make concurrent requests while waiting for an event.
4375    pub fn wait_for_event(
4376        &self,
4377        deadline: zx::MonotonicInstant,
4378    ) -> Result<ConnectionEvent, fidl::Error> {
4379        ConnectionEvent::decode(self.client.wait_for_event(deadline)?)
4380    }
4381
4382    /// Retrieve the range of controller delay for the codec specified with the provided stream
4383    /// attributes.
4384    ///
4385    /// On success, returns the minimum and maximum allowed delay.
4386    ///
4387    /// Returns ZX_ERR_NOT_SUPPORTED if reading the delay is not supported.
4388    /// Returns ZX_ERR_INTERNAL for all other failures.
4389    pub fn r#get_codec_local_delay_range(
4390        &self,
4391        mut payload: &CodecDelayGetCodecLocalDelayRangeRequest,
4392        ___deadline: zx::MonotonicInstant,
4393    ) -> Result<CodecDelayGetCodecLocalDelayRangeResult, fidl::Error> {
4394        let _response = self.client.send_query::<
4395            CodecDelayGetCodecLocalDelayRangeRequest,
4396            fidl::encoding::ResultType<CodecDelayGetCodecLocalDelayRangeResponse, i32>,
4397        >(
4398            payload,
4399            0x1cf34fdeed80b4d,
4400            fidl::encoding::DynamicFlags::empty(),
4401            ___deadline,
4402        )?;
4403        Ok(_response.map(|x| x))
4404    }
4405
4406    /// The following epitaphs may be sent by the server on error:
4407    /// + `ZX_ERR_ALREADY_BOUND`: A Client server has already been bound in this Connection
4408    ///                           protocol. The existing Client should be used.
4409    pub fn r#request_gatt_client(
4410        &self,
4411        mut client: fidl::endpoints::ServerEnd<fidl_fuchsia_bluetooth_gatt2::ClientMarker>,
4412    ) -> Result<(), fidl::Error> {
4413        self.client.send::<ConnectionRequestGattClientRequest>(
4414            (client,),
4415            0x2a670e0fec6ccc6b,
4416            fidl::encoding::DynamicFlags::empty(),
4417        )
4418    }
4419
4420    /// Accept a future CIS request from the peer with the specified CIG/CIS values. All
4421    /// CIS requests that have not explicitly been allowed will be rejected.
4422    ///
4423    /// The provided IsochronousStream will be used for future notification of established
4424    /// connections.
4425    ///
4426    /// The host may wait for multiple incoming connections simultaneously, although each
4427    /// must have a combination of CIG/CIS values that is unique to this connection.
4428    ///
4429    /// If we are not operating in the peripheral role in this connection, connection_stream
4430    /// will be closed with a ZX_ERR_NOT_SUPPORTED epitaph.
4431    ///
4432    /// If we are already waiting for another connection with the same combination of CIG/CIS
4433    /// values, connection_stream will be closed with a ZX_ERR_INVALID_ARGS epitaph.
4434    pub fn r#accept_cis(&self, mut payload: ConnectionAcceptCisRequest) -> Result<(), fidl::Error> {
4435        self.client.send::<ConnectionAcceptCisRequest>(
4436            &mut payload,
4437            0x7e6338c237088144,
4438            fidl::encoding::DynamicFlags::empty(),
4439        )
4440    }
4441
4442    /// Connect to an L2CAP LE connection-oriented channel.
4443    pub fn r#connect_l2cap(
4444        &self,
4445        mut payload: ConnectionConnectL2capRequest,
4446    ) -> Result<(), fidl::Error> {
4447        self.client.send::<ConnectionConnectL2capRequest>(
4448            &mut payload,
4449            0x12351316feaebce9,
4450            fidl::encoding::DynamicFlags::empty(),
4451        )
4452    }
4453}
4454
4455#[cfg(target_os = "fuchsia")]
4456impl From<ConnectionSynchronousProxy> for zx::Handle {
4457    fn from(value: ConnectionSynchronousProxy) -> Self {
4458        value.into_channel().into()
4459    }
4460}
4461
4462#[cfg(target_os = "fuchsia")]
4463impl From<fidl::Channel> for ConnectionSynchronousProxy {
4464    fn from(value: fidl::Channel) -> Self {
4465        Self::new(value)
4466    }
4467}
4468
4469#[derive(Debug, Clone)]
4470pub struct ConnectionProxy {
4471    client: fidl::client::Client<fidl::encoding::DefaultFuchsiaResourceDialect>,
4472}
4473
4474impl fidl::endpoints::Proxy for ConnectionProxy {
4475    type Protocol = ConnectionMarker;
4476
4477    fn from_channel(inner: ::fidl::AsyncChannel) -> Self {
4478        Self::new(inner)
4479    }
4480
4481    fn into_channel(self) -> Result<::fidl::AsyncChannel, Self> {
4482        self.client.into_channel().map_err(|client| Self { client })
4483    }
4484
4485    fn as_channel(&self) -> &::fidl::AsyncChannel {
4486        self.client.as_channel()
4487    }
4488}
4489
4490impl ConnectionProxy {
4491    /// Create a new Proxy for fuchsia.bluetooth.le/Connection.
4492    pub fn new(channel: ::fidl::AsyncChannel) -> Self {
4493        let protocol_name = <ConnectionMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME;
4494        Self { client: fidl::client::Client::new(channel, protocol_name) }
4495    }
4496
4497    /// Get a Stream of events from the remote end of the protocol.
4498    ///
4499    /// # Panics
4500    ///
4501    /// Panics if the event stream was already taken.
4502    pub fn take_event_stream(&self) -> ConnectionEventStream {
4503        ConnectionEventStream { event_receiver: self.client.take_event_receiver() }
4504    }
4505
4506    /// Retrieve the range of controller delay for the codec specified with the provided stream
4507    /// attributes.
4508    ///
4509    /// On success, returns the minimum and maximum allowed delay.
4510    ///
4511    /// Returns ZX_ERR_NOT_SUPPORTED if reading the delay is not supported.
4512    /// Returns ZX_ERR_INTERNAL for all other failures.
4513    pub fn r#get_codec_local_delay_range(
4514        &self,
4515        mut payload: &CodecDelayGetCodecLocalDelayRangeRequest,
4516    ) -> fidl::client::QueryResponseFut<
4517        CodecDelayGetCodecLocalDelayRangeResult,
4518        fidl::encoding::DefaultFuchsiaResourceDialect,
4519    > {
4520        ConnectionProxyInterface::r#get_codec_local_delay_range(self, payload)
4521    }
4522
4523    /// The following epitaphs may be sent by the server on error:
4524    /// + `ZX_ERR_ALREADY_BOUND`: A Client server has already been bound in this Connection
4525    ///                           protocol. The existing Client should be used.
4526    pub fn r#request_gatt_client(
4527        &self,
4528        mut client: fidl::endpoints::ServerEnd<fidl_fuchsia_bluetooth_gatt2::ClientMarker>,
4529    ) -> Result<(), fidl::Error> {
4530        ConnectionProxyInterface::r#request_gatt_client(self, client)
4531    }
4532
4533    /// Accept a future CIS request from the peer with the specified CIG/CIS values. All
4534    /// CIS requests that have not explicitly been allowed will be rejected.
4535    ///
4536    /// The provided IsochronousStream will be used for future notification of established
4537    /// connections.
4538    ///
4539    /// The host may wait for multiple incoming connections simultaneously, although each
4540    /// must have a combination of CIG/CIS values that is unique to this connection.
4541    ///
4542    /// If we are not operating in the peripheral role in this connection, connection_stream
4543    /// will be closed with a ZX_ERR_NOT_SUPPORTED epitaph.
4544    ///
4545    /// If we are already waiting for another connection with the same combination of CIG/CIS
4546    /// values, connection_stream will be closed with a ZX_ERR_INVALID_ARGS epitaph.
4547    pub fn r#accept_cis(&self, mut payload: ConnectionAcceptCisRequest) -> Result<(), fidl::Error> {
4548        ConnectionProxyInterface::r#accept_cis(self, payload)
4549    }
4550
4551    /// Connect to an L2CAP LE connection-oriented channel.
4552    pub fn r#connect_l2cap(
4553        &self,
4554        mut payload: ConnectionConnectL2capRequest,
4555    ) -> Result<(), fidl::Error> {
4556        ConnectionProxyInterface::r#connect_l2cap(self, payload)
4557    }
4558}
4559
4560impl ConnectionProxyInterface for ConnectionProxy {
4561    type GetCodecLocalDelayRangeResponseFut = fidl::client::QueryResponseFut<
4562        CodecDelayGetCodecLocalDelayRangeResult,
4563        fidl::encoding::DefaultFuchsiaResourceDialect,
4564    >;
4565    fn r#get_codec_local_delay_range(
4566        &self,
4567        mut payload: &CodecDelayGetCodecLocalDelayRangeRequest,
4568    ) -> Self::GetCodecLocalDelayRangeResponseFut {
4569        fn _decode(
4570            mut _buf: Result<<fidl::encoding::DefaultFuchsiaResourceDialect as fidl::encoding::ResourceDialect>::MessageBufEtc, fidl::Error>,
4571        ) -> Result<CodecDelayGetCodecLocalDelayRangeResult, fidl::Error> {
4572            let _response = fidl::client::decode_transaction_body::<
4573                fidl::encoding::ResultType<CodecDelayGetCodecLocalDelayRangeResponse, i32>,
4574                fidl::encoding::DefaultFuchsiaResourceDialect,
4575                0x1cf34fdeed80b4d,
4576            >(_buf?)?;
4577            Ok(_response.map(|x| x))
4578        }
4579        self.client.send_query_and_decode::<
4580            CodecDelayGetCodecLocalDelayRangeRequest,
4581            CodecDelayGetCodecLocalDelayRangeResult,
4582        >(
4583            payload,
4584            0x1cf34fdeed80b4d,
4585            fidl::encoding::DynamicFlags::empty(),
4586            _decode,
4587        )
4588    }
4589
4590    fn r#request_gatt_client(
4591        &self,
4592        mut client: fidl::endpoints::ServerEnd<fidl_fuchsia_bluetooth_gatt2::ClientMarker>,
4593    ) -> Result<(), fidl::Error> {
4594        self.client.send::<ConnectionRequestGattClientRequest>(
4595            (client,),
4596            0x2a670e0fec6ccc6b,
4597            fidl::encoding::DynamicFlags::empty(),
4598        )
4599    }
4600
4601    fn r#accept_cis(&self, mut payload: ConnectionAcceptCisRequest) -> Result<(), fidl::Error> {
4602        self.client.send::<ConnectionAcceptCisRequest>(
4603            &mut payload,
4604            0x7e6338c237088144,
4605            fidl::encoding::DynamicFlags::empty(),
4606        )
4607    }
4608
4609    fn r#connect_l2cap(
4610        &self,
4611        mut payload: ConnectionConnectL2capRequest,
4612    ) -> Result<(), fidl::Error> {
4613        self.client.send::<ConnectionConnectL2capRequest>(
4614            &mut payload,
4615            0x12351316feaebce9,
4616            fidl::encoding::DynamicFlags::empty(),
4617        )
4618    }
4619}
4620
4621pub struct ConnectionEventStream {
4622    event_receiver: fidl::client::EventReceiver<fidl::encoding::DefaultFuchsiaResourceDialect>,
4623}
4624
4625impl std::marker::Unpin for ConnectionEventStream {}
4626
4627impl futures::stream::FusedStream for ConnectionEventStream {
4628    fn is_terminated(&self) -> bool {
4629        self.event_receiver.is_terminated()
4630    }
4631}
4632
4633impl futures::Stream for ConnectionEventStream {
4634    type Item = Result<ConnectionEvent, fidl::Error>;
4635
4636    fn poll_next(
4637        mut self: std::pin::Pin<&mut Self>,
4638        cx: &mut std::task::Context<'_>,
4639    ) -> std::task::Poll<Option<Self::Item>> {
4640        match futures::ready!(futures::stream::StreamExt::poll_next_unpin(
4641            &mut self.event_receiver,
4642            cx
4643        )?) {
4644            Some(buf) => std::task::Poll::Ready(Some(ConnectionEvent::decode(buf))),
4645            None => std::task::Poll::Ready(None),
4646        }
4647    }
4648}
4649
4650#[derive(Debug)]
4651pub enum ConnectionEvent {}
4652
4653impl ConnectionEvent {
4654    /// Decodes a message buffer as a [`ConnectionEvent`].
4655    fn decode(
4656        mut buf: <fidl::encoding::DefaultFuchsiaResourceDialect as fidl::encoding::ResourceDialect>::MessageBufEtc,
4657    ) -> Result<ConnectionEvent, fidl::Error> {
4658        let (bytes, _handles) = buf.split_mut();
4659        let (tx_header, _body_bytes) = fidl::encoding::decode_transaction_header(bytes)?;
4660        debug_assert_eq!(tx_header.tx_id, 0);
4661        match tx_header.ordinal {
4662            _ => Err(fidl::Error::UnknownOrdinal {
4663                ordinal: tx_header.ordinal,
4664                protocol_name: <ConnectionMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME,
4665            }),
4666        }
4667    }
4668}
4669
4670/// A Stream of incoming requests for fuchsia.bluetooth.le/Connection.
4671pub struct ConnectionRequestStream {
4672    inner: std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>,
4673    is_terminated: bool,
4674}
4675
4676impl std::marker::Unpin for ConnectionRequestStream {}
4677
4678impl futures::stream::FusedStream for ConnectionRequestStream {
4679    fn is_terminated(&self) -> bool {
4680        self.is_terminated
4681    }
4682}
4683
4684impl fidl::endpoints::RequestStream for ConnectionRequestStream {
4685    type Protocol = ConnectionMarker;
4686    type ControlHandle = ConnectionControlHandle;
4687
4688    fn from_channel(channel: ::fidl::AsyncChannel) -> Self {
4689        Self { inner: std::sync::Arc::new(fidl::ServeInner::new(channel)), is_terminated: false }
4690    }
4691
4692    fn control_handle(&self) -> Self::ControlHandle {
4693        ConnectionControlHandle { inner: self.inner.clone() }
4694    }
4695
4696    fn into_inner(
4697        self,
4698    ) -> (::std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>, bool)
4699    {
4700        (self.inner, self.is_terminated)
4701    }
4702
4703    fn from_inner(
4704        inner: std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>,
4705        is_terminated: bool,
4706    ) -> Self {
4707        Self { inner, is_terminated }
4708    }
4709}
4710
4711impl futures::Stream for ConnectionRequestStream {
4712    type Item = Result<ConnectionRequest, fidl::Error>;
4713
4714    fn poll_next(
4715        mut self: std::pin::Pin<&mut Self>,
4716        cx: &mut std::task::Context<'_>,
4717    ) -> std::task::Poll<Option<Self::Item>> {
4718        let this = &mut *self;
4719        if this.inner.check_shutdown(cx) {
4720            this.is_terminated = true;
4721            return std::task::Poll::Ready(None);
4722        }
4723        if this.is_terminated {
4724            panic!("polled ConnectionRequestStream after completion");
4725        }
4726        fidl::encoding::with_tls_decode_buf::<_, fidl::encoding::DefaultFuchsiaResourceDialect>(
4727            |bytes, handles| {
4728                match this.inner.channel().read_etc(cx, bytes, handles) {
4729                    std::task::Poll::Ready(Ok(())) => {}
4730                    std::task::Poll::Pending => return std::task::Poll::Pending,
4731                    std::task::Poll::Ready(Err(zx_status::Status::PEER_CLOSED)) => {
4732                        this.is_terminated = true;
4733                        return std::task::Poll::Ready(None);
4734                    }
4735                    std::task::Poll::Ready(Err(e)) => {
4736                        return std::task::Poll::Ready(Some(Err(fidl::Error::ServerRequestRead(
4737                            e.into(),
4738                        ))))
4739                    }
4740                }
4741
4742                // A message has been received from the channel
4743                let (header, _body_bytes) = fidl::encoding::decode_transaction_header(bytes)?;
4744
4745                std::task::Poll::Ready(Some(match header.ordinal {
4746                    0x1cf34fdeed80b4d => {
4747                        header.validate_request_tx_id(fidl::MethodType::TwoWay)?;
4748                        let mut req = fidl::new_empty!(
4749                            CodecDelayGetCodecLocalDelayRangeRequest,
4750                            fidl::encoding::DefaultFuchsiaResourceDialect
4751                        );
4752                        fidl::encoding::Decoder::<fidl::encoding::DefaultFuchsiaResourceDialect>::decode_into::<CodecDelayGetCodecLocalDelayRangeRequest>(&header, _body_bytes, handles, &mut req)?;
4753                        let control_handle = ConnectionControlHandle { inner: this.inner.clone() };
4754                        Ok(ConnectionRequest::GetCodecLocalDelayRange {
4755                            payload: req,
4756                            responder: ConnectionGetCodecLocalDelayRangeResponder {
4757                                control_handle: std::mem::ManuallyDrop::new(control_handle),
4758                                tx_id: header.tx_id,
4759                            },
4760                        })
4761                    }
4762                    0x2a670e0fec6ccc6b => {
4763                        header.validate_request_tx_id(fidl::MethodType::OneWay)?;
4764                        let mut req = fidl::new_empty!(
4765                            ConnectionRequestGattClientRequest,
4766                            fidl::encoding::DefaultFuchsiaResourceDialect
4767                        );
4768                        fidl::encoding::Decoder::<fidl::encoding::DefaultFuchsiaResourceDialect>::decode_into::<ConnectionRequestGattClientRequest>(&header, _body_bytes, handles, &mut req)?;
4769                        let control_handle = ConnectionControlHandle { inner: this.inner.clone() };
4770                        Ok(ConnectionRequest::RequestGattClient {
4771                            client: req.client,
4772
4773                            control_handle,
4774                        })
4775                    }
4776                    0x7e6338c237088144 => {
4777                        header.validate_request_tx_id(fidl::MethodType::OneWay)?;
4778                        let mut req = fidl::new_empty!(
4779                            ConnectionAcceptCisRequest,
4780                            fidl::encoding::DefaultFuchsiaResourceDialect
4781                        );
4782                        fidl::encoding::Decoder::<fidl::encoding::DefaultFuchsiaResourceDialect>::decode_into::<ConnectionAcceptCisRequest>(&header, _body_bytes, handles, &mut req)?;
4783                        let control_handle = ConnectionControlHandle { inner: this.inner.clone() };
4784                        Ok(ConnectionRequest::AcceptCis { payload: req, control_handle })
4785                    }
4786                    0x12351316feaebce9 => {
4787                        header.validate_request_tx_id(fidl::MethodType::OneWay)?;
4788                        let mut req = fidl::new_empty!(
4789                            ConnectionConnectL2capRequest,
4790                            fidl::encoding::DefaultFuchsiaResourceDialect
4791                        );
4792                        fidl::encoding::Decoder::<fidl::encoding::DefaultFuchsiaResourceDialect>::decode_into::<ConnectionConnectL2capRequest>(&header, _body_bytes, handles, &mut req)?;
4793                        let control_handle = ConnectionControlHandle { inner: this.inner.clone() };
4794                        Ok(ConnectionRequest::ConnectL2cap { payload: req, control_handle })
4795                    }
4796                    _ => Err(fidl::Error::UnknownOrdinal {
4797                        ordinal: header.ordinal,
4798                        protocol_name:
4799                            <ConnectionMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME,
4800                    }),
4801                }))
4802            },
4803        )
4804    }
4805}
4806
4807/// Protocol that represents the connection to a peer. This can be used to interact with GATT
4808/// services and establish L2CAP channels.
4809///
4810/// This lifetime of this capability is tied to that of the LE connection it represents. Closing the
4811/// channel results in a disconnection if no other clients hold a Connection to the same peer.
4812#[derive(Debug)]
4813pub enum ConnectionRequest {
4814    /// Retrieve the range of controller delay for the codec specified with the provided stream
4815    /// attributes.
4816    ///
4817    /// On success, returns the minimum and maximum allowed delay.
4818    ///
4819    /// Returns ZX_ERR_NOT_SUPPORTED if reading the delay is not supported.
4820    /// Returns ZX_ERR_INTERNAL for all other failures.
4821    GetCodecLocalDelayRange {
4822        payload: CodecDelayGetCodecLocalDelayRangeRequest,
4823        responder: ConnectionGetCodecLocalDelayRangeResponder,
4824    },
4825    /// The following epitaphs may be sent by the server on error:
4826    /// + `ZX_ERR_ALREADY_BOUND`: A Client server has already been bound in this Connection
4827    ///                           protocol. The existing Client should be used.
4828    RequestGattClient {
4829        client: fidl::endpoints::ServerEnd<fidl_fuchsia_bluetooth_gatt2::ClientMarker>,
4830        control_handle: ConnectionControlHandle,
4831    },
4832    /// Accept a future CIS request from the peer with the specified CIG/CIS values. All
4833    /// CIS requests that have not explicitly been allowed will be rejected.
4834    ///
4835    /// The provided IsochronousStream will be used for future notification of established
4836    /// connections.
4837    ///
4838    /// The host may wait for multiple incoming connections simultaneously, although each
4839    /// must have a combination of CIG/CIS values that is unique to this connection.
4840    ///
4841    /// If we are not operating in the peripheral role in this connection, connection_stream
4842    /// will be closed with a ZX_ERR_NOT_SUPPORTED epitaph.
4843    ///
4844    /// If we are already waiting for another connection with the same combination of CIG/CIS
4845    /// values, connection_stream will be closed with a ZX_ERR_INVALID_ARGS epitaph.
4846    AcceptCis { payload: ConnectionAcceptCisRequest, control_handle: ConnectionControlHandle },
4847    /// Connect to an L2CAP LE connection-oriented channel.
4848    ConnectL2cap { payload: ConnectionConnectL2capRequest, control_handle: ConnectionControlHandle },
4849}
4850
4851impl ConnectionRequest {
4852    #[allow(irrefutable_let_patterns)]
4853    pub fn into_get_codec_local_delay_range(
4854        self,
4855    ) -> Option<(
4856        CodecDelayGetCodecLocalDelayRangeRequest,
4857        ConnectionGetCodecLocalDelayRangeResponder,
4858    )> {
4859        if let ConnectionRequest::GetCodecLocalDelayRange { payload, responder } = self {
4860            Some((payload, responder))
4861        } else {
4862            None
4863        }
4864    }
4865
4866    #[allow(irrefutable_let_patterns)]
4867    pub fn into_request_gatt_client(
4868        self,
4869    ) -> Option<(
4870        fidl::endpoints::ServerEnd<fidl_fuchsia_bluetooth_gatt2::ClientMarker>,
4871        ConnectionControlHandle,
4872    )> {
4873        if let ConnectionRequest::RequestGattClient { client, control_handle } = self {
4874            Some((client, control_handle))
4875        } else {
4876            None
4877        }
4878    }
4879
4880    #[allow(irrefutable_let_patterns)]
4881    pub fn into_accept_cis(self) -> Option<(ConnectionAcceptCisRequest, ConnectionControlHandle)> {
4882        if let ConnectionRequest::AcceptCis { payload, control_handle } = self {
4883            Some((payload, control_handle))
4884        } else {
4885            None
4886        }
4887    }
4888
4889    #[allow(irrefutable_let_patterns)]
4890    pub fn into_connect_l2cap(
4891        self,
4892    ) -> Option<(ConnectionConnectL2capRequest, ConnectionControlHandle)> {
4893        if let ConnectionRequest::ConnectL2cap { payload, control_handle } = self {
4894            Some((payload, control_handle))
4895        } else {
4896            None
4897        }
4898    }
4899
4900    /// Name of the method defined in FIDL
4901    pub fn method_name(&self) -> &'static str {
4902        match *self {
4903            ConnectionRequest::GetCodecLocalDelayRange { .. } => "get_codec_local_delay_range",
4904            ConnectionRequest::RequestGattClient { .. } => "request_gatt_client",
4905            ConnectionRequest::AcceptCis { .. } => "accept_cis",
4906            ConnectionRequest::ConnectL2cap { .. } => "connect_l2cap",
4907        }
4908    }
4909}
4910
4911#[derive(Debug, Clone)]
4912pub struct ConnectionControlHandle {
4913    inner: std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>,
4914}
4915
4916impl fidl::endpoints::ControlHandle for ConnectionControlHandle {
4917    fn shutdown(&self) {
4918        self.inner.shutdown()
4919    }
4920    fn shutdown_with_epitaph(&self, status: zx_status::Status) {
4921        self.inner.shutdown_with_epitaph(status)
4922    }
4923
4924    fn is_closed(&self) -> bool {
4925        self.inner.channel().is_closed()
4926    }
4927    fn on_closed(&self) -> fidl::OnSignalsRef<'_> {
4928        self.inner.channel().on_closed()
4929    }
4930
4931    #[cfg(target_os = "fuchsia")]
4932    fn signal_peer(
4933        &self,
4934        clear_mask: zx::Signals,
4935        set_mask: zx::Signals,
4936    ) -> Result<(), zx_status::Status> {
4937        use fidl::Peered;
4938        self.inner.channel().signal_peer(clear_mask, set_mask)
4939    }
4940}
4941
4942impl ConnectionControlHandle {}
4943
4944#[must_use = "FIDL methods require a response to be sent"]
4945#[derive(Debug)]
4946pub struct ConnectionGetCodecLocalDelayRangeResponder {
4947    control_handle: std::mem::ManuallyDrop<ConnectionControlHandle>,
4948    tx_id: u32,
4949}
4950
4951/// Set the the channel to be shutdown (see [`ConnectionControlHandle::shutdown`])
4952/// if the responder is dropped without sending a response, so that the client
4953/// doesn't hang. To prevent this behavior, call `drop_without_shutdown`.
4954impl std::ops::Drop for ConnectionGetCodecLocalDelayRangeResponder {
4955    fn drop(&mut self) {
4956        self.control_handle.shutdown();
4957        // Safety: drops once, never accessed again
4958        unsafe { std::mem::ManuallyDrop::drop(&mut self.control_handle) };
4959    }
4960}
4961
4962impl fidl::endpoints::Responder for ConnectionGetCodecLocalDelayRangeResponder {
4963    type ControlHandle = ConnectionControlHandle;
4964
4965    fn control_handle(&self) -> &ConnectionControlHandle {
4966        &self.control_handle
4967    }
4968
4969    fn drop_without_shutdown(mut self) {
4970        // Safety: drops once, never accessed again due to mem::forget
4971        unsafe { std::mem::ManuallyDrop::drop(&mut self.control_handle) };
4972        // Prevent Drop from running (which would shut down the channel)
4973        std::mem::forget(self);
4974    }
4975}
4976
4977impl ConnectionGetCodecLocalDelayRangeResponder {
4978    /// Sends a response to the FIDL transaction.
4979    ///
4980    /// Sets the channel to shutdown if an error occurs.
4981    pub fn send(
4982        self,
4983        mut result: Result<&CodecDelayGetCodecLocalDelayRangeResponse, i32>,
4984    ) -> Result<(), fidl::Error> {
4985        let _result = self.send_raw(result);
4986        if _result.is_err() {
4987            self.control_handle.shutdown();
4988        }
4989        self.drop_without_shutdown();
4990        _result
4991    }
4992
4993    /// Similar to "send" but does not shutdown the channel if an error occurs.
4994    pub fn send_no_shutdown_on_err(
4995        self,
4996        mut result: Result<&CodecDelayGetCodecLocalDelayRangeResponse, i32>,
4997    ) -> Result<(), fidl::Error> {
4998        let _result = self.send_raw(result);
4999        self.drop_without_shutdown();
5000        _result
5001    }
5002
5003    fn send_raw(
5004        &self,
5005        mut result: Result<&CodecDelayGetCodecLocalDelayRangeResponse, i32>,
5006    ) -> Result<(), fidl::Error> {
5007        self.control_handle.inner.send::<fidl::encoding::ResultType<
5008            CodecDelayGetCodecLocalDelayRangeResponse,
5009            i32,
5010        >>(
5011            result,
5012            self.tx_id,
5013            0x1cf34fdeed80b4d,
5014            fidl::encoding::DynamicFlags::empty(),
5015        )
5016    }
5017}
5018
5019#[derive(Debug, Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Hash)]
5020pub struct IsochronousStreamMarker;
5021
5022impl fidl::endpoints::ProtocolMarker for IsochronousStreamMarker {
5023    type Proxy = IsochronousStreamProxy;
5024    type RequestStream = IsochronousStreamRequestStream;
5025    #[cfg(target_os = "fuchsia")]
5026    type SynchronousProxy = IsochronousStreamSynchronousProxy;
5027
5028    const DEBUG_NAME: &'static str = "(anonymous) IsochronousStream";
5029}
5030pub type IsochronousStreamSetupDataPathResult = Result<(), i32>;
5031pub type IsochronousStreamWriteResult = Result<(), i32>;
5032
5033pub trait IsochronousStreamProxyInterface: Send + Sync {
5034    type SetupDataPathResponseFut: std::future::Future<Output = Result<IsochronousStreamSetupDataPathResult, fidl::Error>>
5035        + Send;
5036    fn r#setup_data_path(
5037        &self,
5038        payload: &IsochronousStreamSetupDataPathRequest,
5039    ) -> Self::SetupDataPathResponseFut;
5040    type ReadResponseFut: std::future::Future<Output = Result<IsochronousStreamReadResponse, fidl::Error>>
5041        + Send;
5042    fn r#read(&self) -> Self::ReadResponseFut;
5043    type WriteResponseFut: std::future::Future<Output = Result<IsochronousStreamWriteResult, fidl::Error>>
5044        + Send;
5045    fn r#write(&self, payload: &IsochronousStreamWriteRequest) -> Self::WriteResponseFut;
5046}
5047#[derive(Debug)]
5048#[cfg(target_os = "fuchsia")]
5049pub struct IsochronousStreamSynchronousProxy {
5050    client: fidl::client::sync::Client,
5051}
5052
5053#[cfg(target_os = "fuchsia")]
5054impl fidl::endpoints::SynchronousProxy for IsochronousStreamSynchronousProxy {
5055    type Proxy = IsochronousStreamProxy;
5056    type Protocol = IsochronousStreamMarker;
5057
5058    fn from_channel(inner: fidl::Channel) -> Self {
5059        Self::new(inner)
5060    }
5061
5062    fn into_channel(self) -> fidl::Channel {
5063        self.client.into_channel()
5064    }
5065
5066    fn as_channel(&self) -> &fidl::Channel {
5067        self.client.as_channel()
5068    }
5069}
5070
5071#[cfg(target_os = "fuchsia")]
5072impl IsochronousStreamSynchronousProxy {
5073    pub fn new(channel: fidl::Channel) -> Self {
5074        let protocol_name =
5075            <IsochronousStreamMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME;
5076        Self { client: fidl::client::sync::Client::new(channel, protocol_name) }
5077    }
5078
5079    pub fn into_channel(self) -> fidl::Channel {
5080        self.client.into_channel()
5081    }
5082
5083    /// Waits until an event arrives and returns it. It is safe for other
5084    /// threads to make concurrent requests while waiting for an event.
5085    pub fn wait_for_event(
5086        &self,
5087        deadline: zx::MonotonicInstant,
5088    ) -> Result<IsochronousStreamEvent, fidl::Error> {
5089        IsochronousStreamEvent::decode(self.client.wait_for_event(deadline)?)
5090    }
5091
5092    /// Create an isochronous data path with the specified parameters. Only in-band (HCI) ISO
5093    /// transport is currently supported.
5094    ///
5095    /// Returns ZX_ERR_ALREADY_EXISTS if a ISO stream has already been created for this
5096    /// direction.
5097    ///
5098    /// Returns ZX_ERR_BAD_STATE if issued on a peripheral before a CIS request has been
5099    /// accepted.
5100    ///
5101    /// Returns ZX_ERR_INVALID_ARGS if the codec arguments are invalid or outside of the
5102    /// controller's supported range.
5103    pub fn r#setup_data_path(
5104        &self,
5105        mut payload: &IsochronousStreamSetupDataPathRequest,
5106        ___deadline: zx::MonotonicInstant,
5107    ) -> Result<IsochronousStreamSetupDataPathResult, fidl::Error> {
5108        let _response = self.client.send_query::<
5109            IsochronousStreamSetupDataPathRequest,
5110            fidl::encoding::FlexibleResultType<fidl::encoding::EmptyStruct, i32>,
5111        >(
5112            payload,
5113            0x7ec1e2b9cc6d2fbe,
5114            fidl::encoding::DynamicFlags::FLEXIBLE,
5115            ___deadline,
5116        )?
5117        .into_result::<IsochronousStreamMarker>("setup_data_path")?;
5118        Ok(_response.map(|x| x))
5119    }
5120
5121    /// Receive data from an output (controller => host) ISO stream that has been established and
5122    /// set up. Designed to be used with a hanging get pattern.
5123    ///
5124    /// Can be invoked before the ISO data stream has been established and set up, but will not
5125    /// return until after it has been set up and data has been received.
5126    pub fn r#read(
5127        &self,
5128        ___deadline: zx::MonotonicInstant,
5129    ) -> Result<IsochronousStreamReadResponse, fidl::Error> {
5130        let _response = self.client.send_query::<
5131            fidl::encoding::EmptyPayload,
5132            fidl::encoding::FlexibleType<IsochronousStreamReadResponse>,
5133        >(
5134            (),
5135            0x6d7d8b4950ed3a32,
5136            fidl::encoding::DynamicFlags::FLEXIBLE,
5137            ___deadline,
5138        )?
5139        .into_result::<IsochronousStreamMarker>("read")?;
5140        Ok(_response)
5141    }
5142
5143    /// Send data to an established ISO stream (host => controller).
5144    ///
5145    /// Returns ZX_ERR_INTERNAL for any errors encountered.
5146    pub fn r#write(
5147        &self,
5148        mut payload: &IsochronousStreamWriteRequest,
5149        ___deadline: zx::MonotonicInstant,
5150    ) -> Result<IsochronousStreamWriteResult, fidl::Error> {
5151        let _response = self.client.send_query::<
5152            IsochronousStreamWriteRequest,
5153            fidl::encoding::FlexibleResultType<fidl::encoding::EmptyStruct, i32>,
5154        >(
5155            payload,
5156            0x5282e90b667d0d43,
5157            fidl::encoding::DynamicFlags::FLEXIBLE,
5158            ___deadline,
5159        )?
5160        .into_result::<IsochronousStreamMarker>("write")?;
5161        Ok(_response.map(|x| x))
5162    }
5163}
5164
5165#[cfg(target_os = "fuchsia")]
5166impl From<IsochronousStreamSynchronousProxy> for zx::Handle {
5167    fn from(value: IsochronousStreamSynchronousProxy) -> Self {
5168        value.into_channel().into()
5169    }
5170}
5171
5172#[cfg(target_os = "fuchsia")]
5173impl From<fidl::Channel> for IsochronousStreamSynchronousProxy {
5174    fn from(value: fidl::Channel) -> Self {
5175        Self::new(value)
5176    }
5177}
5178
5179#[derive(Debug, Clone)]
5180pub struct IsochronousStreamProxy {
5181    client: fidl::client::Client<fidl::encoding::DefaultFuchsiaResourceDialect>,
5182}
5183
5184impl fidl::endpoints::Proxy for IsochronousStreamProxy {
5185    type Protocol = IsochronousStreamMarker;
5186
5187    fn from_channel(inner: ::fidl::AsyncChannel) -> Self {
5188        Self::new(inner)
5189    }
5190
5191    fn into_channel(self) -> Result<::fidl::AsyncChannel, Self> {
5192        self.client.into_channel().map_err(|client| Self { client })
5193    }
5194
5195    fn as_channel(&self) -> &::fidl::AsyncChannel {
5196        self.client.as_channel()
5197    }
5198}
5199
5200impl IsochronousStreamProxy {
5201    /// Create a new Proxy for fuchsia.bluetooth.le/IsochronousStream.
5202    pub fn new(channel: ::fidl::AsyncChannel) -> Self {
5203        let protocol_name =
5204            <IsochronousStreamMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME;
5205        Self { client: fidl::client::Client::new(channel, protocol_name) }
5206    }
5207
5208    /// Get a Stream of events from the remote end of the protocol.
5209    ///
5210    /// # Panics
5211    ///
5212    /// Panics if the event stream was already taken.
5213    pub fn take_event_stream(&self) -> IsochronousStreamEventStream {
5214        IsochronousStreamEventStream { event_receiver: self.client.take_event_receiver() }
5215    }
5216
5217    /// Create an isochronous data path with the specified parameters. Only in-band (HCI) ISO
5218    /// transport is currently supported.
5219    ///
5220    /// Returns ZX_ERR_ALREADY_EXISTS if a ISO stream has already been created for this
5221    /// direction.
5222    ///
5223    /// Returns ZX_ERR_BAD_STATE if issued on a peripheral before a CIS request has been
5224    /// accepted.
5225    ///
5226    /// Returns ZX_ERR_INVALID_ARGS if the codec arguments are invalid or outside of the
5227    /// controller's supported range.
5228    pub fn r#setup_data_path(
5229        &self,
5230        mut payload: &IsochronousStreamSetupDataPathRequest,
5231    ) -> fidl::client::QueryResponseFut<
5232        IsochronousStreamSetupDataPathResult,
5233        fidl::encoding::DefaultFuchsiaResourceDialect,
5234    > {
5235        IsochronousStreamProxyInterface::r#setup_data_path(self, payload)
5236    }
5237
5238    /// Receive data from an output (controller => host) ISO stream that has been established and
5239    /// set up. Designed to be used with a hanging get pattern.
5240    ///
5241    /// Can be invoked before the ISO data stream has been established and set up, but will not
5242    /// return until after it has been set up and data has been received.
5243    pub fn r#read(
5244        &self,
5245    ) -> fidl::client::QueryResponseFut<
5246        IsochronousStreamReadResponse,
5247        fidl::encoding::DefaultFuchsiaResourceDialect,
5248    > {
5249        IsochronousStreamProxyInterface::r#read(self)
5250    }
5251
5252    /// Send data to an established ISO stream (host => controller).
5253    ///
5254    /// Returns ZX_ERR_INTERNAL for any errors encountered.
5255    pub fn r#write(
5256        &self,
5257        mut payload: &IsochronousStreamWriteRequest,
5258    ) -> fidl::client::QueryResponseFut<
5259        IsochronousStreamWriteResult,
5260        fidl::encoding::DefaultFuchsiaResourceDialect,
5261    > {
5262        IsochronousStreamProxyInterface::r#write(self, payload)
5263    }
5264}
5265
5266impl IsochronousStreamProxyInterface for IsochronousStreamProxy {
5267    type SetupDataPathResponseFut = fidl::client::QueryResponseFut<
5268        IsochronousStreamSetupDataPathResult,
5269        fidl::encoding::DefaultFuchsiaResourceDialect,
5270    >;
5271    fn r#setup_data_path(
5272        &self,
5273        mut payload: &IsochronousStreamSetupDataPathRequest,
5274    ) -> Self::SetupDataPathResponseFut {
5275        fn _decode(
5276            mut _buf: Result<<fidl::encoding::DefaultFuchsiaResourceDialect as fidl::encoding::ResourceDialect>::MessageBufEtc, fidl::Error>,
5277        ) -> Result<IsochronousStreamSetupDataPathResult, fidl::Error> {
5278            let _response = fidl::client::decode_transaction_body::<
5279                fidl::encoding::FlexibleResultType<fidl::encoding::EmptyStruct, i32>,
5280                fidl::encoding::DefaultFuchsiaResourceDialect,
5281                0x7ec1e2b9cc6d2fbe,
5282            >(_buf?)?
5283            .into_result::<IsochronousStreamMarker>("setup_data_path")?;
5284            Ok(_response.map(|x| x))
5285        }
5286        self.client.send_query_and_decode::<
5287            IsochronousStreamSetupDataPathRequest,
5288            IsochronousStreamSetupDataPathResult,
5289        >(
5290            payload,
5291            0x7ec1e2b9cc6d2fbe,
5292            fidl::encoding::DynamicFlags::FLEXIBLE,
5293            _decode,
5294        )
5295    }
5296
5297    type ReadResponseFut = fidl::client::QueryResponseFut<
5298        IsochronousStreamReadResponse,
5299        fidl::encoding::DefaultFuchsiaResourceDialect,
5300    >;
5301    fn r#read(&self) -> Self::ReadResponseFut {
5302        fn _decode(
5303            mut _buf: Result<<fidl::encoding::DefaultFuchsiaResourceDialect as fidl::encoding::ResourceDialect>::MessageBufEtc, fidl::Error>,
5304        ) -> Result<IsochronousStreamReadResponse, fidl::Error> {
5305            let _response = fidl::client::decode_transaction_body::<
5306                fidl::encoding::FlexibleType<IsochronousStreamReadResponse>,
5307                fidl::encoding::DefaultFuchsiaResourceDialect,
5308                0x6d7d8b4950ed3a32,
5309            >(_buf?)?
5310            .into_result::<IsochronousStreamMarker>("read")?;
5311            Ok(_response)
5312        }
5313        self.client
5314            .send_query_and_decode::<fidl::encoding::EmptyPayload, IsochronousStreamReadResponse>(
5315                (),
5316                0x6d7d8b4950ed3a32,
5317                fidl::encoding::DynamicFlags::FLEXIBLE,
5318                _decode,
5319            )
5320    }
5321
5322    type WriteResponseFut = fidl::client::QueryResponseFut<
5323        IsochronousStreamWriteResult,
5324        fidl::encoding::DefaultFuchsiaResourceDialect,
5325    >;
5326    fn r#write(&self, mut payload: &IsochronousStreamWriteRequest) -> Self::WriteResponseFut {
5327        fn _decode(
5328            mut _buf: Result<<fidl::encoding::DefaultFuchsiaResourceDialect as fidl::encoding::ResourceDialect>::MessageBufEtc, fidl::Error>,
5329        ) -> Result<IsochronousStreamWriteResult, fidl::Error> {
5330            let _response = fidl::client::decode_transaction_body::<
5331                fidl::encoding::FlexibleResultType<fidl::encoding::EmptyStruct, i32>,
5332                fidl::encoding::DefaultFuchsiaResourceDialect,
5333                0x5282e90b667d0d43,
5334            >(_buf?)?
5335            .into_result::<IsochronousStreamMarker>("write")?;
5336            Ok(_response.map(|x| x))
5337        }
5338        self.client
5339            .send_query_and_decode::<IsochronousStreamWriteRequest, IsochronousStreamWriteResult>(
5340                payload,
5341                0x5282e90b667d0d43,
5342                fidl::encoding::DynamicFlags::FLEXIBLE,
5343                _decode,
5344            )
5345    }
5346}
5347
5348pub struct IsochronousStreamEventStream {
5349    event_receiver: fidl::client::EventReceiver<fidl::encoding::DefaultFuchsiaResourceDialect>,
5350}
5351
5352impl std::marker::Unpin for IsochronousStreamEventStream {}
5353
5354impl futures::stream::FusedStream for IsochronousStreamEventStream {
5355    fn is_terminated(&self) -> bool {
5356        self.event_receiver.is_terminated()
5357    }
5358}
5359
5360impl futures::Stream for IsochronousStreamEventStream {
5361    type Item = Result<IsochronousStreamEvent, fidl::Error>;
5362
5363    fn poll_next(
5364        mut self: std::pin::Pin<&mut Self>,
5365        cx: &mut std::task::Context<'_>,
5366    ) -> std::task::Poll<Option<Self::Item>> {
5367        match futures::ready!(futures::stream::StreamExt::poll_next_unpin(
5368            &mut self.event_receiver,
5369            cx
5370        )?) {
5371            Some(buf) => std::task::Poll::Ready(Some(IsochronousStreamEvent::decode(buf))),
5372            None => std::task::Poll::Ready(None),
5373        }
5374    }
5375}
5376
5377#[derive(Debug)]
5378pub enum IsochronousStreamEvent {
5379    OnEstablished {
5380        payload: IsochronousStreamOnEstablishedRequest,
5381    },
5382    #[non_exhaustive]
5383    _UnknownEvent {
5384        /// Ordinal of the event that was sent.
5385        ordinal: u64,
5386    },
5387}
5388
5389impl IsochronousStreamEvent {
5390    #[allow(irrefutable_let_patterns)]
5391    pub fn into_on_established(self) -> Option<IsochronousStreamOnEstablishedRequest> {
5392        if let IsochronousStreamEvent::OnEstablished { payload } = self {
5393            Some((payload))
5394        } else {
5395            None
5396        }
5397    }
5398
5399    /// Decodes a message buffer as a [`IsochronousStreamEvent`].
5400    fn decode(
5401        mut buf: <fidl::encoding::DefaultFuchsiaResourceDialect as fidl::encoding::ResourceDialect>::MessageBufEtc,
5402    ) -> Result<IsochronousStreamEvent, fidl::Error> {
5403        let (bytes, _handles) = buf.split_mut();
5404        let (tx_header, _body_bytes) = fidl::encoding::decode_transaction_header(bytes)?;
5405        debug_assert_eq!(tx_header.tx_id, 0);
5406        match tx_header.ordinal {
5407            0x341c50e9d10f3421 => {
5408                let mut out = fidl::new_empty!(
5409                    IsochronousStreamOnEstablishedRequest,
5410                    fidl::encoding::DefaultFuchsiaResourceDialect
5411                );
5412                fidl::encoding::Decoder::<fidl::encoding::DefaultFuchsiaResourceDialect>::decode_into::<IsochronousStreamOnEstablishedRequest>(&tx_header, _body_bytes, _handles, &mut out)?;
5413                Ok((IsochronousStreamEvent::OnEstablished { payload: out }))
5414            }
5415            _ if tx_header.dynamic_flags().contains(fidl::encoding::DynamicFlags::FLEXIBLE) => {
5416                Ok(IsochronousStreamEvent::_UnknownEvent { ordinal: tx_header.ordinal })
5417            }
5418            _ => Err(fidl::Error::UnknownOrdinal {
5419                ordinal: tx_header.ordinal,
5420                protocol_name:
5421                    <IsochronousStreamMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME,
5422            }),
5423        }
5424    }
5425}
5426
5427/// A Stream of incoming requests for fuchsia.bluetooth.le/IsochronousStream.
5428pub struct IsochronousStreamRequestStream {
5429    inner: std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>,
5430    is_terminated: bool,
5431}
5432
5433impl std::marker::Unpin for IsochronousStreamRequestStream {}
5434
5435impl futures::stream::FusedStream for IsochronousStreamRequestStream {
5436    fn is_terminated(&self) -> bool {
5437        self.is_terminated
5438    }
5439}
5440
5441impl fidl::endpoints::RequestStream for IsochronousStreamRequestStream {
5442    type Protocol = IsochronousStreamMarker;
5443    type ControlHandle = IsochronousStreamControlHandle;
5444
5445    fn from_channel(channel: ::fidl::AsyncChannel) -> Self {
5446        Self { inner: std::sync::Arc::new(fidl::ServeInner::new(channel)), is_terminated: false }
5447    }
5448
5449    fn control_handle(&self) -> Self::ControlHandle {
5450        IsochronousStreamControlHandle { inner: self.inner.clone() }
5451    }
5452
5453    fn into_inner(
5454        self,
5455    ) -> (::std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>, bool)
5456    {
5457        (self.inner, self.is_terminated)
5458    }
5459
5460    fn from_inner(
5461        inner: std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>,
5462        is_terminated: bool,
5463    ) -> Self {
5464        Self { inner, is_terminated }
5465    }
5466}
5467
5468impl futures::Stream for IsochronousStreamRequestStream {
5469    type Item = Result<IsochronousStreamRequest, fidl::Error>;
5470
5471    fn poll_next(
5472        mut self: std::pin::Pin<&mut Self>,
5473        cx: &mut std::task::Context<'_>,
5474    ) -> std::task::Poll<Option<Self::Item>> {
5475        let this = &mut *self;
5476        if this.inner.check_shutdown(cx) {
5477            this.is_terminated = true;
5478            return std::task::Poll::Ready(None);
5479        }
5480        if this.is_terminated {
5481            panic!("polled IsochronousStreamRequestStream after completion");
5482        }
5483        fidl::encoding::with_tls_decode_buf::<_, fidl::encoding::DefaultFuchsiaResourceDialect>(
5484            |bytes, handles| {
5485                match this.inner.channel().read_etc(cx, bytes, handles) {
5486                    std::task::Poll::Ready(Ok(())) => {}
5487                    std::task::Poll::Pending => return std::task::Poll::Pending,
5488                    std::task::Poll::Ready(Err(zx_status::Status::PEER_CLOSED)) => {
5489                        this.is_terminated = true;
5490                        return std::task::Poll::Ready(None);
5491                    }
5492                    std::task::Poll::Ready(Err(e)) => {
5493                        return std::task::Poll::Ready(Some(Err(fidl::Error::ServerRequestRead(
5494                            e.into(),
5495                        ))))
5496                    }
5497                }
5498
5499                // A message has been received from the channel
5500                let (header, _body_bytes) = fidl::encoding::decode_transaction_header(bytes)?;
5501
5502                std::task::Poll::Ready(Some(match header.ordinal {
5503                    0x7ec1e2b9cc6d2fbe => {
5504                        header.validate_request_tx_id(fidl::MethodType::TwoWay)?;
5505                        let mut req = fidl::new_empty!(
5506                            IsochronousStreamSetupDataPathRequest,
5507                            fidl::encoding::DefaultFuchsiaResourceDialect
5508                        );
5509                        fidl::encoding::Decoder::<fidl::encoding::DefaultFuchsiaResourceDialect>::decode_into::<IsochronousStreamSetupDataPathRequest>(&header, _body_bytes, handles, &mut req)?;
5510                        let control_handle =
5511                            IsochronousStreamControlHandle { inner: this.inner.clone() };
5512                        Ok(IsochronousStreamRequest::SetupDataPath {
5513                            payload: req,
5514                            responder: IsochronousStreamSetupDataPathResponder {
5515                                control_handle: std::mem::ManuallyDrop::new(control_handle),
5516                                tx_id: header.tx_id,
5517                            },
5518                        })
5519                    }
5520                    0x6d7d8b4950ed3a32 => {
5521                        header.validate_request_tx_id(fidl::MethodType::TwoWay)?;
5522                        let mut req = fidl::new_empty!(
5523                            fidl::encoding::EmptyPayload,
5524                            fidl::encoding::DefaultFuchsiaResourceDialect
5525                        );
5526                        fidl::encoding::Decoder::<fidl::encoding::DefaultFuchsiaResourceDialect>::decode_into::<fidl::encoding::EmptyPayload>(&header, _body_bytes, handles, &mut req)?;
5527                        let control_handle =
5528                            IsochronousStreamControlHandle { inner: this.inner.clone() };
5529                        Ok(IsochronousStreamRequest::Read {
5530                            responder: IsochronousStreamReadResponder {
5531                                control_handle: std::mem::ManuallyDrop::new(control_handle),
5532                                tx_id: header.tx_id,
5533                            },
5534                        })
5535                    }
5536                    0x5282e90b667d0d43 => {
5537                        header.validate_request_tx_id(fidl::MethodType::TwoWay)?;
5538                        let mut req = fidl::new_empty!(
5539                            IsochronousStreamWriteRequest,
5540                            fidl::encoding::DefaultFuchsiaResourceDialect
5541                        );
5542                        fidl::encoding::Decoder::<fidl::encoding::DefaultFuchsiaResourceDialect>::decode_into::<IsochronousStreamWriteRequest>(&header, _body_bytes, handles, &mut req)?;
5543                        let control_handle =
5544                            IsochronousStreamControlHandle { inner: this.inner.clone() };
5545                        Ok(IsochronousStreamRequest::Write {
5546                            payload: req,
5547                            responder: IsochronousStreamWriteResponder {
5548                                control_handle: std::mem::ManuallyDrop::new(control_handle),
5549                                tx_id: header.tx_id,
5550                            },
5551                        })
5552                    }
5553                    _ if header.tx_id == 0
5554                        && header
5555                            .dynamic_flags()
5556                            .contains(fidl::encoding::DynamicFlags::FLEXIBLE) =>
5557                    {
5558                        Ok(IsochronousStreamRequest::_UnknownMethod {
5559                            ordinal: header.ordinal,
5560                            control_handle: IsochronousStreamControlHandle {
5561                                inner: this.inner.clone(),
5562                            },
5563                            method_type: fidl::MethodType::OneWay,
5564                        })
5565                    }
5566                    _ if header
5567                        .dynamic_flags()
5568                        .contains(fidl::encoding::DynamicFlags::FLEXIBLE) =>
5569                    {
5570                        this.inner.send_framework_err(
5571                            fidl::encoding::FrameworkErr::UnknownMethod,
5572                            header.tx_id,
5573                            header.ordinal,
5574                            header.dynamic_flags(),
5575                            (bytes, handles),
5576                        )?;
5577                        Ok(IsochronousStreamRequest::_UnknownMethod {
5578                            ordinal: header.ordinal,
5579                            control_handle: IsochronousStreamControlHandle {
5580                                inner: this.inner.clone(),
5581                            },
5582                            method_type: fidl::MethodType::TwoWay,
5583                        })
5584                    }
5585                    _ => Err(fidl::Error::UnknownOrdinal {
5586                        ordinal: header.ordinal,
5587                        protocol_name:
5588                            <IsochronousStreamMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME,
5589                    }),
5590                }))
5591            },
5592        )
5593    }
5594}
5595
5596#[derive(Debug)]
5597pub enum IsochronousStreamRequest {
5598    /// Create an isochronous data path with the specified parameters. Only in-band (HCI) ISO
5599    /// transport is currently supported.
5600    ///
5601    /// Returns ZX_ERR_ALREADY_EXISTS if a ISO stream has already been created for this
5602    /// direction.
5603    ///
5604    /// Returns ZX_ERR_BAD_STATE if issued on a peripheral before a CIS request has been
5605    /// accepted.
5606    ///
5607    /// Returns ZX_ERR_INVALID_ARGS if the codec arguments are invalid or outside of the
5608    /// controller's supported range.
5609    SetupDataPath {
5610        payload: IsochronousStreamSetupDataPathRequest,
5611        responder: IsochronousStreamSetupDataPathResponder,
5612    },
5613    /// Receive data from an output (controller => host) ISO stream that has been established and
5614    /// set up. Designed to be used with a hanging get pattern.
5615    ///
5616    /// Can be invoked before the ISO data stream has been established and set up, but will not
5617    /// return until after it has been set up and data has been received.
5618    Read { responder: IsochronousStreamReadResponder },
5619    /// Send data to an established ISO stream (host => controller).
5620    ///
5621    /// Returns ZX_ERR_INTERNAL for any errors encountered.
5622    Write { payload: IsochronousStreamWriteRequest, responder: IsochronousStreamWriteResponder },
5623    /// An interaction was received which does not match any known method.
5624    #[non_exhaustive]
5625    _UnknownMethod {
5626        /// Ordinal of the method that was called.
5627        ordinal: u64,
5628        control_handle: IsochronousStreamControlHandle,
5629        method_type: fidl::MethodType,
5630    },
5631}
5632
5633impl IsochronousStreamRequest {
5634    #[allow(irrefutable_let_patterns)]
5635    pub fn into_setup_data_path(
5636        self,
5637    ) -> Option<(IsochronousStreamSetupDataPathRequest, IsochronousStreamSetupDataPathResponder)>
5638    {
5639        if let IsochronousStreamRequest::SetupDataPath { payload, responder } = self {
5640            Some((payload, responder))
5641        } else {
5642            None
5643        }
5644    }
5645
5646    #[allow(irrefutable_let_patterns)]
5647    pub fn into_read(self) -> Option<(IsochronousStreamReadResponder)> {
5648        if let IsochronousStreamRequest::Read { responder } = self {
5649            Some((responder))
5650        } else {
5651            None
5652        }
5653    }
5654
5655    #[allow(irrefutable_let_patterns)]
5656    pub fn into_write(
5657        self,
5658    ) -> Option<(IsochronousStreamWriteRequest, IsochronousStreamWriteResponder)> {
5659        if let IsochronousStreamRequest::Write { payload, responder } = self {
5660            Some((payload, responder))
5661        } else {
5662            None
5663        }
5664    }
5665
5666    /// Name of the method defined in FIDL
5667    pub fn method_name(&self) -> &'static str {
5668        match *self {
5669            IsochronousStreamRequest::SetupDataPath { .. } => "setup_data_path",
5670            IsochronousStreamRequest::Read { .. } => "read",
5671            IsochronousStreamRequest::Write { .. } => "write",
5672            IsochronousStreamRequest::_UnknownMethod {
5673                method_type: fidl::MethodType::OneWay,
5674                ..
5675            } => "unknown one-way method",
5676            IsochronousStreamRequest::_UnknownMethod {
5677                method_type: fidl::MethodType::TwoWay,
5678                ..
5679            } => "unknown two-way method",
5680        }
5681    }
5682}
5683
5684#[derive(Debug, Clone)]
5685pub struct IsochronousStreamControlHandle {
5686    inner: std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>,
5687}
5688
5689impl fidl::endpoints::ControlHandle for IsochronousStreamControlHandle {
5690    fn shutdown(&self) {
5691        self.inner.shutdown()
5692    }
5693    fn shutdown_with_epitaph(&self, status: zx_status::Status) {
5694        self.inner.shutdown_with_epitaph(status)
5695    }
5696
5697    fn is_closed(&self) -> bool {
5698        self.inner.channel().is_closed()
5699    }
5700    fn on_closed(&self) -> fidl::OnSignalsRef<'_> {
5701        self.inner.channel().on_closed()
5702    }
5703
5704    #[cfg(target_os = "fuchsia")]
5705    fn signal_peer(
5706        &self,
5707        clear_mask: zx::Signals,
5708        set_mask: zx::Signals,
5709    ) -> Result<(), zx_status::Status> {
5710        use fidl::Peered;
5711        self.inner.channel().signal_peer(clear_mask, set_mask)
5712    }
5713}
5714
5715impl IsochronousStreamControlHandle {
5716    pub fn send_on_established(
5717        &self,
5718        mut payload: &IsochronousStreamOnEstablishedRequest,
5719    ) -> Result<(), fidl::Error> {
5720        self.inner.send::<IsochronousStreamOnEstablishedRequest>(
5721            payload,
5722            0,
5723            0x341c50e9d10f3421,
5724            fidl::encoding::DynamicFlags::FLEXIBLE,
5725        )
5726    }
5727}
5728
5729#[must_use = "FIDL methods require a response to be sent"]
5730#[derive(Debug)]
5731pub struct IsochronousStreamSetupDataPathResponder {
5732    control_handle: std::mem::ManuallyDrop<IsochronousStreamControlHandle>,
5733    tx_id: u32,
5734}
5735
5736/// Set the the channel to be shutdown (see [`IsochronousStreamControlHandle::shutdown`])
5737/// if the responder is dropped without sending a response, so that the client
5738/// doesn't hang. To prevent this behavior, call `drop_without_shutdown`.
5739impl std::ops::Drop for IsochronousStreamSetupDataPathResponder {
5740    fn drop(&mut self) {
5741        self.control_handle.shutdown();
5742        // Safety: drops once, never accessed again
5743        unsafe { std::mem::ManuallyDrop::drop(&mut self.control_handle) };
5744    }
5745}
5746
5747impl fidl::endpoints::Responder for IsochronousStreamSetupDataPathResponder {
5748    type ControlHandle = IsochronousStreamControlHandle;
5749
5750    fn control_handle(&self) -> &IsochronousStreamControlHandle {
5751        &self.control_handle
5752    }
5753
5754    fn drop_without_shutdown(mut self) {
5755        // Safety: drops once, never accessed again due to mem::forget
5756        unsafe { std::mem::ManuallyDrop::drop(&mut self.control_handle) };
5757        // Prevent Drop from running (which would shut down the channel)
5758        std::mem::forget(self);
5759    }
5760}
5761
5762impl IsochronousStreamSetupDataPathResponder {
5763    /// Sends a response to the FIDL transaction.
5764    ///
5765    /// Sets the channel to shutdown if an error occurs.
5766    pub fn send(self, mut result: Result<(), i32>) -> Result<(), fidl::Error> {
5767        let _result = self.send_raw(result);
5768        if _result.is_err() {
5769            self.control_handle.shutdown();
5770        }
5771        self.drop_without_shutdown();
5772        _result
5773    }
5774
5775    /// Similar to "send" but does not shutdown the channel if an error occurs.
5776    pub fn send_no_shutdown_on_err(self, mut result: Result<(), i32>) -> Result<(), fidl::Error> {
5777        let _result = self.send_raw(result);
5778        self.drop_without_shutdown();
5779        _result
5780    }
5781
5782    fn send_raw(&self, mut result: Result<(), i32>) -> Result<(), fidl::Error> {
5783        self.control_handle.inner.send::<fidl::encoding::FlexibleResultType<
5784            fidl::encoding::EmptyStruct,
5785            i32,
5786        >>(
5787            fidl::encoding::FlexibleResult::new(result),
5788            self.tx_id,
5789            0x7ec1e2b9cc6d2fbe,
5790            fidl::encoding::DynamicFlags::FLEXIBLE,
5791        )
5792    }
5793}
5794
5795#[must_use = "FIDL methods require a response to be sent"]
5796#[derive(Debug)]
5797pub struct IsochronousStreamReadResponder {
5798    control_handle: std::mem::ManuallyDrop<IsochronousStreamControlHandle>,
5799    tx_id: u32,
5800}
5801
5802/// Set the the channel to be shutdown (see [`IsochronousStreamControlHandle::shutdown`])
5803/// if the responder is dropped without sending a response, so that the client
5804/// doesn't hang. To prevent this behavior, call `drop_without_shutdown`.
5805impl std::ops::Drop for IsochronousStreamReadResponder {
5806    fn drop(&mut self) {
5807        self.control_handle.shutdown();
5808        // Safety: drops once, never accessed again
5809        unsafe { std::mem::ManuallyDrop::drop(&mut self.control_handle) };
5810    }
5811}
5812
5813impl fidl::endpoints::Responder for IsochronousStreamReadResponder {
5814    type ControlHandle = IsochronousStreamControlHandle;
5815
5816    fn control_handle(&self) -> &IsochronousStreamControlHandle {
5817        &self.control_handle
5818    }
5819
5820    fn drop_without_shutdown(mut self) {
5821        // Safety: drops once, never accessed again due to mem::forget
5822        unsafe { std::mem::ManuallyDrop::drop(&mut self.control_handle) };
5823        // Prevent Drop from running (which would shut down the channel)
5824        std::mem::forget(self);
5825    }
5826}
5827
5828impl IsochronousStreamReadResponder {
5829    /// Sends a response to the FIDL transaction.
5830    ///
5831    /// Sets the channel to shutdown if an error occurs.
5832    pub fn send(self, mut payload: &IsochronousStreamReadResponse) -> Result<(), fidl::Error> {
5833        let _result = self.send_raw(payload);
5834        if _result.is_err() {
5835            self.control_handle.shutdown();
5836        }
5837        self.drop_without_shutdown();
5838        _result
5839    }
5840
5841    /// Similar to "send" but does not shutdown the channel if an error occurs.
5842    pub fn send_no_shutdown_on_err(
5843        self,
5844        mut payload: &IsochronousStreamReadResponse,
5845    ) -> Result<(), fidl::Error> {
5846        let _result = self.send_raw(payload);
5847        self.drop_without_shutdown();
5848        _result
5849    }
5850
5851    fn send_raw(&self, mut payload: &IsochronousStreamReadResponse) -> Result<(), fidl::Error> {
5852        self.control_handle
5853            .inner
5854            .send::<fidl::encoding::FlexibleType<IsochronousStreamReadResponse>>(
5855                fidl::encoding::Flexible::new(payload),
5856                self.tx_id,
5857                0x6d7d8b4950ed3a32,
5858                fidl::encoding::DynamicFlags::FLEXIBLE,
5859            )
5860    }
5861}
5862
5863#[must_use = "FIDL methods require a response to be sent"]
5864#[derive(Debug)]
5865pub struct IsochronousStreamWriteResponder {
5866    control_handle: std::mem::ManuallyDrop<IsochronousStreamControlHandle>,
5867    tx_id: u32,
5868}
5869
5870/// Set the the channel to be shutdown (see [`IsochronousStreamControlHandle::shutdown`])
5871/// if the responder is dropped without sending a response, so that the client
5872/// doesn't hang. To prevent this behavior, call `drop_without_shutdown`.
5873impl std::ops::Drop for IsochronousStreamWriteResponder {
5874    fn drop(&mut self) {
5875        self.control_handle.shutdown();
5876        // Safety: drops once, never accessed again
5877        unsafe { std::mem::ManuallyDrop::drop(&mut self.control_handle) };
5878    }
5879}
5880
5881impl fidl::endpoints::Responder for IsochronousStreamWriteResponder {
5882    type ControlHandle = IsochronousStreamControlHandle;
5883
5884    fn control_handle(&self) -> &IsochronousStreamControlHandle {
5885        &self.control_handle
5886    }
5887
5888    fn drop_without_shutdown(mut self) {
5889        // Safety: drops once, never accessed again due to mem::forget
5890        unsafe { std::mem::ManuallyDrop::drop(&mut self.control_handle) };
5891        // Prevent Drop from running (which would shut down the channel)
5892        std::mem::forget(self);
5893    }
5894}
5895
5896impl IsochronousStreamWriteResponder {
5897    /// Sends a response to the FIDL transaction.
5898    ///
5899    /// Sets the channel to shutdown if an error occurs.
5900    pub fn send(self, mut result: Result<(), i32>) -> Result<(), fidl::Error> {
5901        let _result = self.send_raw(result);
5902        if _result.is_err() {
5903            self.control_handle.shutdown();
5904        }
5905        self.drop_without_shutdown();
5906        _result
5907    }
5908
5909    /// Similar to "send" but does not shutdown the channel if an error occurs.
5910    pub fn send_no_shutdown_on_err(self, mut result: Result<(), i32>) -> Result<(), fidl::Error> {
5911        let _result = self.send_raw(result);
5912        self.drop_without_shutdown();
5913        _result
5914    }
5915
5916    fn send_raw(&self, mut result: Result<(), i32>) -> Result<(), fidl::Error> {
5917        self.control_handle.inner.send::<fidl::encoding::FlexibleResultType<
5918            fidl::encoding::EmptyStruct,
5919            i32,
5920        >>(
5921            fidl::encoding::FlexibleResult::new(result),
5922            self.tx_id,
5923            0x5282e90b667d0d43,
5924            fidl::encoding::DynamicFlags::FLEXIBLE,
5925        )
5926    }
5927}
5928
5929#[derive(Debug, Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Hash)]
5930pub struct PeripheralMarker;
5931
5932impl fidl::endpoints::ProtocolMarker for PeripheralMarker {
5933    type Proxy = PeripheralProxy;
5934    type RequestStream = PeripheralRequestStream;
5935    #[cfg(target_os = "fuchsia")]
5936    type SynchronousProxy = PeripheralSynchronousProxy;
5937
5938    const DEBUG_NAME: &'static str = "fuchsia.bluetooth.le.Peripheral";
5939}
5940impl fidl::endpoints::DiscoverableProtocolMarker for PeripheralMarker {}
5941pub type PeripheralAdvertiseResult = Result<(), PeripheralError>;
5942pub type PeripheralStartAdvertisingResult = Result<(), PeripheralError>;
5943
5944pub trait PeripheralProxyInterface: Send + Sync {
5945    type ListenL2capResponseFut: std::future::Future<Output = Result<ChannelListenerRegistryListenL2capResult, fidl::Error>>
5946        + Send;
5947    fn r#listen_l2cap(
5948        &self,
5949        payload: ChannelListenerRegistryListenL2capRequest,
5950    ) -> Self::ListenL2capResponseFut;
5951    type AdvertiseResponseFut: std::future::Future<Output = Result<PeripheralAdvertiseResult, fidl::Error>>
5952        + Send;
5953    fn r#advertise(
5954        &self,
5955        parameters: &AdvertisingParameters,
5956        advertised_peripheral: fidl::endpoints::ClientEnd<AdvertisedPeripheralMarker>,
5957    ) -> Self::AdvertiseResponseFut;
5958    type StartAdvertisingResponseFut: std::future::Future<Output = Result<PeripheralStartAdvertisingResult, fidl::Error>>
5959        + Send;
5960    fn r#start_advertising(
5961        &self,
5962        parameters: &AdvertisingParameters,
5963        handle: fidl::endpoints::ServerEnd<AdvertisingHandleMarker>,
5964    ) -> Self::StartAdvertisingResponseFut;
5965}
5966#[derive(Debug)]
5967#[cfg(target_os = "fuchsia")]
5968pub struct PeripheralSynchronousProxy {
5969    client: fidl::client::sync::Client,
5970}
5971
5972#[cfg(target_os = "fuchsia")]
5973impl fidl::endpoints::SynchronousProxy for PeripheralSynchronousProxy {
5974    type Proxy = PeripheralProxy;
5975    type Protocol = PeripheralMarker;
5976
5977    fn from_channel(inner: fidl::Channel) -> Self {
5978        Self::new(inner)
5979    }
5980
5981    fn into_channel(self) -> fidl::Channel {
5982        self.client.into_channel()
5983    }
5984
5985    fn as_channel(&self) -> &fidl::Channel {
5986        self.client.as_channel()
5987    }
5988}
5989
5990#[cfg(target_os = "fuchsia")]
5991impl PeripheralSynchronousProxy {
5992    pub fn new(channel: fidl::Channel) -> Self {
5993        let protocol_name = <PeripheralMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME;
5994        Self { client: fidl::client::sync::Client::new(channel, protocol_name) }
5995    }
5996
5997    pub fn into_channel(self) -> fidl::Channel {
5998        self.client.into_channel()
5999    }
6000
6001    /// Waits until an event arrives and returns it. It is safe for other
6002    /// threads to make concurrent requests while waiting for an event.
6003    pub fn wait_for_event(
6004        &self,
6005        deadline: zx::MonotonicInstant,
6006    ) -> Result<PeripheralEvent, fidl::Error> {
6007        PeripheralEvent::decode(self.client.wait_for_event(deadline)?)
6008    }
6009
6010    /// Register a listener for incoming channels. The registry will assign a
6011    /// PSM value that is unique for the local device, as well as open a
6012    /// [`ChannelListener`] for accepting incoming channels. In the unlikely
6013    /// event that all PSMs have been assigned, this call will fail with
6014    /// `ZX_ERR_NO_RESOURCES`.
6015    ///
6016    /// Note that the method of service discovery or advertising is defined by
6017    /// the service or protocol, so it is the responsibility of the caller to
6018    /// communicate the assigned PSM to any clients.
6019    pub fn r#listen_l2cap(
6020        &self,
6021        mut payload: ChannelListenerRegistryListenL2capRequest,
6022        ___deadline: zx::MonotonicInstant,
6023    ) -> Result<ChannelListenerRegistryListenL2capResult, fidl::Error> {
6024        let _response = self.client.send_query::<
6025            ChannelListenerRegistryListenL2capRequest,
6026            fidl::encoding::ResultType<ChannelListenerRegistryListenL2capResponse, i32>,
6027        >(
6028            &mut payload,
6029            0x39c6e9001d102338,
6030            fidl::encoding::DynamicFlags::empty(),
6031            ___deadline,
6032        )?;
6033        Ok(_response.map(|x| x))
6034    }
6035
6036    /// Start advertising continuously as a LE peripheral. If advertising cannot
6037    /// be initiated then `advertised_peripheral` will be closed and an error
6038    /// will be returned.
6039    ///
6040    /// This method may be called any number of times. To reconfigure an
6041    /// advertisement, first close the original advertisement and then initiate
6042    /// a new advertisement after an empty response is returned.
6043    ///
6044    /// If the client closes its end of the
6045    /// [`fuchsia.bluetooth.le/AdvertisedPeripheral`] channel,
6046    /// advertising will be stopped. If the handle is closed before the request
6047    /// is fulfilled, advertising may be briefly enabled before it is
6048    /// terminated. AdvertisedPeripheral lifetime is bounded by the lifetime of
6049    /// the Peripheral protocol, but this may be changed in the future
6050    /// (https://fxbug.dev/42157682).
6051    ///
6052    /// + request `parameters` Parameters used while configuring the advertising
6053    ///   instance.
6054    /// + request `advertised_peripheral` Protocol that remains valid for the
6055    ///   duration of this advertising session.
6056    /// - response An empty response will be sent when the advertisement is
6057    ///   successfully stopped (due to release of the `advertised_peripheral`
6058    ///   protocol). To prevent overlapping similar advertisements and transient
6059    ///   errors with limited advertising resources, waiting for a response is
6060    ///   recommended before calling `Advertise` again.
6061    /// * error If an error occurs, `advertised_peripheral` will be closed and a
6062    ///   `PeripheralError` will be returned.
6063    pub fn r#advertise(
6064        &self,
6065        mut parameters: &AdvertisingParameters,
6066        mut advertised_peripheral: fidl::endpoints::ClientEnd<AdvertisedPeripheralMarker>,
6067        ___deadline: zx::MonotonicInstant,
6068    ) -> Result<PeripheralAdvertiseResult, fidl::Error> {
6069        let _response = self.client.send_query::<
6070            PeripheralAdvertiseRequest,
6071            fidl::encoding::ResultType<fidl::encoding::EmptyStruct, PeripheralError>,
6072        >(
6073            (parameters, advertised_peripheral,),
6074            0x2d9ec9260c32c17f,
6075            fidl::encoding::DynamicFlags::empty(),
6076            ___deadline,
6077        )?;
6078        Ok(_response.map(|x| x))
6079    }
6080
6081    /// Start advertising as a LE peripheral. An empty response is sent to indicate when advertising
6082    /// has successfully initiated. If advertising cannot be initiated, then the response will
6083    /// contain a [`fuchsia.bluetooth.le/PeripheralError`].
6084    ///
6085    /// This method can get called any number of times and successive calls can be made to
6086    /// reconfigure the advertising parameters. However only the most recent
6087    /// [`fuchsia.bluetooth.le/AdvertisingHandle`] will remain valid.
6088    ///
6089    /// An instance of [`fuchsia.bluetooth.le/Peripheral`] can only have one active advertisement at
6090    /// a time. Clients must obtain multiple Peripheral instances for multiple simultaneous
6091    /// advertisements.
6092    ///
6093    /// If the client closes its end of the [`fuchsia.bluetooth.le/AdvertisingHandle`] channel,
6094    /// advertising will be stopped. If the handle is closed before the request is fulfilled,
6095    /// advertising will be briefly enabled before it is terminated.
6096    ///
6097    /// + request `parameters` Parameters used while configuring the advertising instance.
6098    /// + request `handle` Handle that remains valid for the duration of this advertising session.
6099    /// * error Returns a [`fuchsia.bluetooth.le/PeripheralError`] if advertising cannot be
6100    ///         initiated. In this case the `handle` will be closed.
6101    pub fn r#start_advertising(
6102        &self,
6103        mut parameters: &AdvertisingParameters,
6104        mut handle: fidl::endpoints::ServerEnd<AdvertisingHandleMarker>,
6105        ___deadline: zx::MonotonicInstant,
6106    ) -> Result<PeripheralStartAdvertisingResult, fidl::Error> {
6107        let _response = self.client.send_query::<
6108            PeripheralStartAdvertisingRequest,
6109            fidl::encoding::ResultType<fidl::encoding::EmptyStruct, PeripheralError>,
6110        >(
6111            (parameters, handle,),
6112            0x5875c1c575f00f7d,
6113            fidl::encoding::DynamicFlags::empty(),
6114            ___deadline,
6115        )?;
6116        Ok(_response.map(|x| x))
6117    }
6118}
6119
6120#[cfg(target_os = "fuchsia")]
6121impl From<PeripheralSynchronousProxy> for zx::Handle {
6122    fn from(value: PeripheralSynchronousProxy) -> Self {
6123        value.into_channel().into()
6124    }
6125}
6126
6127#[cfg(target_os = "fuchsia")]
6128impl From<fidl::Channel> for PeripheralSynchronousProxy {
6129    fn from(value: fidl::Channel) -> Self {
6130        Self::new(value)
6131    }
6132}
6133
6134#[derive(Debug, Clone)]
6135pub struct PeripheralProxy {
6136    client: fidl::client::Client<fidl::encoding::DefaultFuchsiaResourceDialect>,
6137}
6138
6139impl fidl::endpoints::Proxy for PeripheralProxy {
6140    type Protocol = PeripheralMarker;
6141
6142    fn from_channel(inner: ::fidl::AsyncChannel) -> Self {
6143        Self::new(inner)
6144    }
6145
6146    fn into_channel(self) -> Result<::fidl::AsyncChannel, Self> {
6147        self.client.into_channel().map_err(|client| Self { client })
6148    }
6149
6150    fn as_channel(&self) -> &::fidl::AsyncChannel {
6151        self.client.as_channel()
6152    }
6153}
6154
6155impl PeripheralProxy {
6156    /// Create a new Proxy for fuchsia.bluetooth.le/Peripheral.
6157    pub fn new(channel: ::fidl::AsyncChannel) -> Self {
6158        let protocol_name = <PeripheralMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME;
6159        Self { client: fidl::client::Client::new(channel, protocol_name) }
6160    }
6161
6162    /// Get a Stream of events from the remote end of the protocol.
6163    ///
6164    /// # Panics
6165    ///
6166    /// Panics if the event stream was already taken.
6167    pub fn take_event_stream(&self) -> PeripheralEventStream {
6168        PeripheralEventStream { event_receiver: self.client.take_event_receiver() }
6169    }
6170
6171    /// Register a listener for incoming channels. The registry will assign a
6172    /// PSM value that is unique for the local device, as well as open a
6173    /// [`ChannelListener`] for accepting incoming channels. In the unlikely
6174    /// event that all PSMs have been assigned, this call will fail with
6175    /// `ZX_ERR_NO_RESOURCES`.
6176    ///
6177    /// Note that the method of service discovery or advertising is defined by
6178    /// the service or protocol, so it is the responsibility of the caller to
6179    /// communicate the assigned PSM to any clients.
6180    pub fn r#listen_l2cap(
6181        &self,
6182        mut payload: ChannelListenerRegistryListenL2capRequest,
6183    ) -> fidl::client::QueryResponseFut<
6184        ChannelListenerRegistryListenL2capResult,
6185        fidl::encoding::DefaultFuchsiaResourceDialect,
6186    > {
6187        PeripheralProxyInterface::r#listen_l2cap(self, payload)
6188    }
6189
6190    /// Start advertising continuously as a LE peripheral. If advertising cannot
6191    /// be initiated then `advertised_peripheral` will be closed and an error
6192    /// will be returned.
6193    ///
6194    /// This method may be called any number of times. To reconfigure an
6195    /// advertisement, first close the original advertisement and then initiate
6196    /// a new advertisement after an empty response is returned.
6197    ///
6198    /// If the client closes its end of the
6199    /// [`fuchsia.bluetooth.le/AdvertisedPeripheral`] channel,
6200    /// advertising will be stopped. If the handle is closed before the request
6201    /// is fulfilled, advertising may be briefly enabled before it is
6202    /// terminated. AdvertisedPeripheral lifetime is bounded by the lifetime of
6203    /// the Peripheral protocol, but this may be changed in the future
6204    /// (https://fxbug.dev/42157682).
6205    ///
6206    /// + request `parameters` Parameters used while configuring the advertising
6207    ///   instance.
6208    /// + request `advertised_peripheral` Protocol that remains valid for the
6209    ///   duration of this advertising session.
6210    /// - response An empty response will be sent when the advertisement is
6211    ///   successfully stopped (due to release of the `advertised_peripheral`
6212    ///   protocol). To prevent overlapping similar advertisements and transient
6213    ///   errors with limited advertising resources, waiting for a response is
6214    ///   recommended before calling `Advertise` again.
6215    /// * error If an error occurs, `advertised_peripheral` will be closed and a
6216    ///   `PeripheralError` will be returned.
6217    pub fn r#advertise(
6218        &self,
6219        mut parameters: &AdvertisingParameters,
6220        mut advertised_peripheral: fidl::endpoints::ClientEnd<AdvertisedPeripheralMarker>,
6221    ) -> fidl::client::QueryResponseFut<
6222        PeripheralAdvertiseResult,
6223        fidl::encoding::DefaultFuchsiaResourceDialect,
6224    > {
6225        PeripheralProxyInterface::r#advertise(self, parameters, advertised_peripheral)
6226    }
6227
6228    /// Start advertising as a LE peripheral. An empty response is sent to indicate when advertising
6229    /// has successfully initiated. If advertising cannot be initiated, then the response will
6230    /// contain a [`fuchsia.bluetooth.le/PeripheralError`].
6231    ///
6232    /// This method can get called any number of times and successive calls can be made to
6233    /// reconfigure the advertising parameters. However only the most recent
6234    /// [`fuchsia.bluetooth.le/AdvertisingHandle`] will remain valid.
6235    ///
6236    /// An instance of [`fuchsia.bluetooth.le/Peripheral`] can only have one active advertisement at
6237    /// a time. Clients must obtain multiple Peripheral instances for multiple simultaneous
6238    /// advertisements.
6239    ///
6240    /// If the client closes its end of the [`fuchsia.bluetooth.le/AdvertisingHandle`] channel,
6241    /// advertising will be stopped. If the handle is closed before the request is fulfilled,
6242    /// advertising will be briefly enabled before it is terminated.
6243    ///
6244    /// + request `parameters` Parameters used while configuring the advertising instance.
6245    /// + request `handle` Handle that remains valid for the duration of this advertising session.
6246    /// * error Returns a [`fuchsia.bluetooth.le/PeripheralError`] if advertising cannot be
6247    ///         initiated. In this case the `handle` will be closed.
6248    pub fn r#start_advertising(
6249        &self,
6250        mut parameters: &AdvertisingParameters,
6251        mut handle: fidl::endpoints::ServerEnd<AdvertisingHandleMarker>,
6252    ) -> fidl::client::QueryResponseFut<
6253        PeripheralStartAdvertisingResult,
6254        fidl::encoding::DefaultFuchsiaResourceDialect,
6255    > {
6256        PeripheralProxyInterface::r#start_advertising(self, parameters, handle)
6257    }
6258}
6259
6260impl PeripheralProxyInterface for PeripheralProxy {
6261    type ListenL2capResponseFut = fidl::client::QueryResponseFut<
6262        ChannelListenerRegistryListenL2capResult,
6263        fidl::encoding::DefaultFuchsiaResourceDialect,
6264    >;
6265    fn r#listen_l2cap(
6266        &self,
6267        mut payload: ChannelListenerRegistryListenL2capRequest,
6268    ) -> Self::ListenL2capResponseFut {
6269        fn _decode(
6270            mut _buf: Result<<fidl::encoding::DefaultFuchsiaResourceDialect as fidl::encoding::ResourceDialect>::MessageBufEtc, fidl::Error>,
6271        ) -> Result<ChannelListenerRegistryListenL2capResult, fidl::Error> {
6272            let _response = fidl::client::decode_transaction_body::<
6273                fidl::encoding::ResultType<ChannelListenerRegistryListenL2capResponse, i32>,
6274                fidl::encoding::DefaultFuchsiaResourceDialect,
6275                0x39c6e9001d102338,
6276            >(_buf?)?;
6277            Ok(_response.map(|x| x))
6278        }
6279        self.client.send_query_and_decode::<
6280            ChannelListenerRegistryListenL2capRequest,
6281            ChannelListenerRegistryListenL2capResult,
6282        >(
6283            &mut payload,
6284            0x39c6e9001d102338,
6285            fidl::encoding::DynamicFlags::empty(),
6286            _decode,
6287        )
6288    }
6289
6290    type AdvertiseResponseFut = fidl::client::QueryResponseFut<
6291        PeripheralAdvertiseResult,
6292        fidl::encoding::DefaultFuchsiaResourceDialect,
6293    >;
6294    fn r#advertise(
6295        &self,
6296        mut parameters: &AdvertisingParameters,
6297        mut advertised_peripheral: fidl::endpoints::ClientEnd<AdvertisedPeripheralMarker>,
6298    ) -> Self::AdvertiseResponseFut {
6299        fn _decode(
6300            mut _buf: Result<<fidl::encoding::DefaultFuchsiaResourceDialect as fidl::encoding::ResourceDialect>::MessageBufEtc, fidl::Error>,
6301        ) -> Result<PeripheralAdvertiseResult, fidl::Error> {
6302            let _response = fidl::client::decode_transaction_body::<
6303                fidl::encoding::ResultType<fidl::encoding::EmptyStruct, PeripheralError>,
6304                fidl::encoding::DefaultFuchsiaResourceDialect,
6305                0x2d9ec9260c32c17f,
6306            >(_buf?)?;
6307            Ok(_response.map(|x| x))
6308        }
6309        self.client.send_query_and_decode::<PeripheralAdvertiseRequest, PeripheralAdvertiseResult>(
6310            (parameters, advertised_peripheral),
6311            0x2d9ec9260c32c17f,
6312            fidl::encoding::DynamicFlags::empty(),
6313            _decode,
6314        )
6315    }
6316
6317    type StartAdvertisingResponseFut = fidl::client::QueryResponseFut<
6318        PeripheralStartAdvertisingResult,
6319        fidl::encoding::DefaultFuchsiaResourceDialect,
6320    >;
6321    fn r#start_advertising(
6322        &self,
6323        mut parameters: &AdvertisingParameters,
6324        mut handle: fidl::endpoints::ServerEnd<AdvertisingHandleMarker>,
6325    ) -> Self::StartAdvertisingResponseFut {
6326        fn _decode(
6327            mut _buf: Result<<fidl::encoding::DefaultFuchsiaResourceDialect as fidl::encoding::ResourceDialect>::MessageBufEtc, fidl::Error>,
6328        ) -> Result<PeripheralStartAdvertisingResult, fidl::Error> {
6329            let _response = fidl::client::decode_transaction_body::<
6330                fidl::encoding::ResultType<fidl::encoding::EmptyStruct, PeripheralError>,
6331                fidl::encoding::DefaultFuchsiaResourceDialect,
6332                0x5875c1c575f00f7d,
6333            >(_buf?)?;
6334            Ok(_response.map(|x| x))
6335        }
6336        self.client.send_query_and_decode::<
6337            PeripheralStartAdvertisingRequest,
6338            PeripheralStartAdvertisingResult,
6339        >(
6340            (parameters, handle,),
6341            0x5875c1c575f00f7d,
6342            fidl::encoding::DynamicFlags::empty(),
6343            _decode,
6344        )
6345    }
6346}
6347
6348pub struct PeripheralEventStream {
6349    event_receiver: fidl::client::EventReceiver<fidl::encoding::DefaultFuchsiaResourceDialect>,
6350}
6351
6352impl std::marker::Unpin for PeripheralEventStream {}
6353
6354impl futures::stream::FusedStream for PeripheralEventStream {
6355    fn is_terminated(&self) -> bool {
6356        self.event_receiver.is_terminated()
6357    }
6358}
6359
6360impl futures::Stream for PeripheralEventStream {
6361    type Item = Result<PeripheralEvent, fidl::Error>;
6362
6363    fn poll_next(
6364        mut self: std::pin::Pin<&mut Self>,
6365        cx: &mut std::task::Context<'_>,
6366    ) -> std::task::Poll<Option<Self::Item>> {
6367        match futures::ready!(futures::stream::StreamExt::poll_next_unpin(
6368            &mut self.event_receiver,
6369            cx
6370        )?) {
6371            Some(buf) => std::task::Poll::Ready(Some(PeripheralEvent::decode(buf))),
6372            None => std::task::Poll::Ready(None),
6373        }
6374    }
6375}
6376
6377#[derive(Debug)]
6378pub enum PeripheralEvent {
6379    OnPeerConnected { peer: Peer, connection: fidl::endpoints::ClientEnd<ConnectionMarker> },
6380}
6381
6382impl PeripheralEvent {
6383    #[allow(irrefutable_let_patterns)]
6384    pub fn into_on_peer_connected(
6385        self,
6386    ) -> Option<(Peer, fidl::endpoints::ClientEnd<ConnectionMarker>)> {
6387        if let PeripheralEvent::OnPeerConnected { peer, connection } = self {
6388            Some((peer, connection))
6389        } else {
6390            None
6391        }
6392    }
6393
6394    /// Decodes a message buffer as a [`PeripheralEvent`].
6395    fn decode(
6396        mut buf: <fidl::encoding::DefaultFuchsiaResourceDialect as fidl::encoding::ResourceDialect>::MessageBufEtc,
6397    ) -> Result<PeripheralEvent, fidl::Error> {
6398        let (bytes, _handles) = buf.split_mut();
6399        let (tx_header, _body_bytes) = fidl::encoding::decode_transaction_header(bytes)?;
6400        debug_assert_eq!(tx_header.tx_id, 0);
6401        match tx_header.ordinal {
6402            0x16135d464299e356 => {
6403                let mut out = fidl::new_empty!(
6404                    PeripheralOnPeerConnectedRequest,
6405                    fidl::encoding::DefaultFuchsiaResourceDialect
6406                );
6407                fidl::encoding::Decoder::<fidl::encoding::DefaultFuchsiaResourceDialect>::decode_into::<PeripheralOnPeerConnectedRequest>(&tx_header, _body_bytes, _handles, &mut out)?;
6408                Ok((PeripheralEvent::OnPeerConnected {
6409                    peer: out.peer,
6410                    connection: out.connection,
6411                }))
6412            }
6413            _ => Err(fidl::Error::UnknownOrdinal {
6414                ordinal: tx_header.ordinal,
6415                protocol_name: <PeripheralMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME,
6416            }),
6417        }
6418    }
6419}
6420
6421/// A Stream of incoming requests for fuchsia.bluetooth.le/Peripheral.
6422pub struct PeripheralRequestStream {
6423    inner: std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>,
6424    is_terminated: bool,
6425}
6426
6427impl std::marker::Unpin for PeripheralRequestStream {}
6428
6429impl futures::stream::FusedStream for PeripheralRequestStream {
6430    fn is_terminated(&self) -> bool {
6431        self.is_terminated
6432    }
6433}
6434
6435impl fidl::endpoints::RequestStream for PeripheralRequestStream {
6436    type Protocol = PeripheralMarker;
6437    type ControlHandle = PeripheralControlHandle;
6438
6439    fn from_channel(channel: ::fidl::AsyncChannel) -> Self {
6440        Self { inner: std::sync::Arc::new(fidl::ServeInner::new(channel)), is_terminated: false }
6441    }
6442
6443    fn control_handle(&self) -> Self::ControlHandle {
6444        PeripheralControlHandle { inner: self.inner.clone() }
6445    }
6446
6447    fn into_inner(
6448        self,
6449    ) -> (::std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>, bool)
6450    {
6451        (self.inner, self.is_terminated)
6452    }
6453
6454    fn from_inner(
6455        inner: std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>,
6456        is_terminated: bool,
6457    ) -> Self {
6458        Self { inner, is_terminated }
6459    }
6460}
6461
6462impl futures::Stream for PeripheralRequestStream {
6463    type Item = Result<PeripheralRequest, fidl::Error>;
6464
6465    fn poll_next(
6466        mut self: std::pin::Pin<&mut Self>,
6467        cx: &mut std::task::Context<'_>,
6468    ) -> std::task::Poll<Option<Self::Item>> {
6469        let this = &mut *self;
6470        if this.inner.check_shutdown(cx) {
6471            this.is_terminated = true;
6472            return std::task::Poll::Ready(None);
6473        }
6474        if this.is_terminated {
6475            panic!("polled PeripheralRequestStream after completion");
6476        }
6477        fidl::encoding::with_tls_decode_buf::<_, fidl::encoding::DefaultFuchsiaResourceDialect>(
6478            |bytes, handles| {
6479                match this.inner.channel().read_etc(cx, bytes, handles) {
6480                    std::task::Poll::Ready(Ok(())) => {}
6481                    std::task::Poll::Pending => return std::task::Poll::Pending,
6482                    std::task::Poll::Ready(Err(zx_status::Status::PEER_CLOSED)) => {
6483                        this.is_terminated = true;
6484                        return std::task::Poll::Ready(None);
6485                    }
6486                    std::task::Poll::Ready(Err(e)) => {
6487                        return std::task::Poll::Ready(Some(Err(fidl::Error::ServerRequestRead(
6488                            e.into(),
6489                        ))))
6490                    }
6491                }
6492
6493                // A message has been received from the channel
6494                let (header, _body_bytes) = fidl::encoding::decode_transaction_header(bytes)?;
6495
6496                std::task::Poll::Ready(Some(match header.ordinal {
6497                    0x39c6e9001d102338 => {
6498                        header.validate_request_tx_id(fidl::MethodType::TwoWay)?;
6499                        let mut req = fidl::new_empty!(
6500                            ChannelListenerRegistryListenL2capRequest,
6501                            fidl::encoding::DefaultFuchsiaResourceDialect
6502                        );
6503                        fidl::encoding::Decoder::<fidl::encoding::DefaultFuchsiaResourceDialect>::decode_into::<ChannelListenerRegistryListenL2capRequest>(&header, _body_bytes, handles, &mut req)?;
6504                        let control_handle = PeripheralControlHandle { inner: this.inner.clone() };
6505                        Ok(PeripheralRequest::ListenL2cap {
6506                            payload: req,
6507                            responder: PeripheralListenL2capResponder {
6508                                control_handle: std::mem::ManuallyDrop::new(control_handle),
6509                                tx_id: header.tx_id,
6510                            },
6511                        })
6512                    }
6513                    0x2d9ec9260c32c17f => {
6514                        header.validate_request_tx_id(fidl::MethodType::TwoWay)?;
6515                        let mut req = fidl::new_empty!(
6516                            PeripheralAdvertiseRequest,
6517                            fidl::encoding::DefaultFuchsiaResourceDialect
6518                        );
6519                        fidl::encoding::Decoder::<fidl::encoding::DefaultFuchsiaResourceDialect>::decode_into::<PeripheralAdvertiseRequest>(&header, _body_bytes, handles, &mut req)?;
6520                        let control_handle = PeripheralControlHandle { inner: this.inner.clone() };
6521                        Ok(PeripheralRequest::Advertise {
6522                            parameters: req.parameters,
6523                            advertised_peripheral: req.advertised_peripheral,
6524
6525                            responder: PeripheralAdvertiseResponder {
6526                                control_handle: std::mem::ManuallyDrop::new(control_handle),
6527                                tx_id: header.tx_id,
6528                            },
6529                        })
6530                    }
6531                    0x5875c1c575f00f7d => {
6532                        header.validate_request_tx_id(fidl::MethodType::TwoWay)?;
6533                        let mut req = fidl::new_empty!(
6534                            PeripheralStartAdvertisingRequest,
6535                            fidl::encoding::DefaultFuchsiaResourceDialect
6536                        );
6537                        fidl::encoding::Decoder::<fidl::encoding::DefaultFuchsiaResourceDialect>::decode_into::<PeripheralStartAdvertisingRequest>(&header, _body_bytes, handles, &mut req)?;
6538                        let control_handle = PeripheralControlHandle { inner: this.inner.clone() };
6539                        Ok(PeripheralRequest::StartAdvertising {
6540                            parameters: req.parameters,
6541                            handle: req.handle,
6542
6543                            responder: PeripheralStartAdvertisingResponder {
6544                                control_handle: std::mem::ManuallyDrop::new(control_handle),
6545                                tx_id: header.tx_id,
6546                            },
6547                        })
6548                    }
6549                    _ => Err(fidl::Error::UnknownOrdinal {
6550                        ordinal: header.ordinal,
6551                        protocol_name:
6552                            <PeripheralMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME,
6553                    }),
6554                }))
6555            },
6556        )
6557    }
6558}
6559
6560#[derive(Debug)]
6561pub enum PeripheralRequest {
6562    /// Register a listener for incoming channels. The registry will assign a
6563    /// PSM value that is unique for the local device, as well as open a
6564    /// [`ChannelListener`] for accepting incoming channels. In the unlikely
6565    /// event that all PSMs have been assigned, this call will fail with
6566    /// `ZX_ERR_NO_RESOURCES`.
6567    ///
6568    /// Note that the method of service discovery or advertising is defined by
6569    /// the service or protocol, so it is the responsibility of the caller to
6570    /// communicate the assigned PSM to any clients.
6571    ListenL2cap {
6572        payload: ChannelListenerRegistryListenL2capRequest,
6573        responder: PeripheralListenL2capResponder,
6574    },
6575    /// Start advertising continuously as a LE peripheral. If advertising cannot
6576    /// be initiated then `advertised_peripheral` will be closed and an error
6577    /// will be returned.
6578    ///
6579    /// This method may be called any number of times. To reconfigure an
6580    /// advertisement, first close the original advertisement and then initiate
6581    /// a new advertisement after an empty response is returned.
6582    ///
6583    /// If the client closes its end of the
6584    /// [`fuchsia.bluetooth.le/AdvertisedPeripheral`] channel,
6585    /// advertising will be stopped. If the handle is closed before the request
6586    /// is fulfilled, advertising may be briefly enabled before it is
6587    /// terminated. AdvertisedPeripheral lifetime is bounded by the lifetime of
6588    /// the Peripheral protocol, but this may be changed in the future
6589    /// (https://fxbug.dev/42157682).
6590    ///
6591    /// + request `parameters` Parameters used while configuring the advertising
6592    ///   instance.
6593    /// + request `advertised_peripheral` Protocol that remains valid for the
6594    ///   duration of this advertising session.
6595    /// - response An empty response will be sent when the advertisement is
6596    ///   successfully stopped (due to release of the `advertised_peripheral`
6597    ///   protocol). To prevent overlapping similar advertisements and transient
6598    ///   errors with limited advertising resources, waiting for a response is
6599    ///   recommended before calling `Advertise` again.
6600    /// * error If an error occurs, `advertised_peripheral` will be closed and a
6601    ///   `PeripheralError` will be returned.
6602    Advertise {
6603        parameters: AdvertisingParameters,
6604        advertised_peripheral: fidl::endpoints::ClientEnd<AdvertisedPeripheralMarker>,
6605        responder: PeripheralAdvertiseResponder,
6606    },
6607    /// Start advertising as a LE peripheral. An empty response is sent to indicate when advertising
6608    /// has successfully initiated. If advertising cannot be initiated, then the response will
6609    /// contain a [`fuchsia.bluetooth.le/PeripheralError`].
6610    ///
6611    /// This method can get called any number of times and successive calls can be made to
6612    /// reconfigure the advertising parameters. However only the most recent
6613    /// [`fuchsia.bluetooth.le/AdvertisingHandle`] will remain valid.
6614    ///
6615    /// An instance of [`fuchsia.bluetooth.le/Peripheral`] can only have one active advertisement at
6616    /// a time. Clients must obtain multiple Peripheral instances for multiple simultaneous
6617    /// advertisements.
6618    ///
6619    /// If the client closes its end of the [`fuchsia.bluetooth.le/AdvertisingHandle`] channel,
6620    /// advertising will be stopped. If the handle is closed before the request is fulfilled,
6621    /// advertising will be briefly enabled before it is terminated.
6622    ///
6623    /// + request `parameters` Parameters used while configuring the advertising instance.
6624    /// + request `handle` Handle that remains valid for the duration of this advertising session.
6625    /// * error Returns a [`fuchsia.bluetooth.le/PeripheralError`] if advertising cannot be
6626    ///         initiated. In this case the `handle` will be closed.
6627    StartAdvertising {
6628        parameters: AdvertisingParameters,
6629        handle: fidl::endpoints::ServerEnd<AdvertisingHandleMarker>,
6630        responder: PeripheralStartAdvertisingResponder,
6631    },
6632}
6633
6634impl PeripheralRequest {
6635    #[allow(irrefutable_let_patterns)]
6636    pub fn into_listen_l2cap(
6637        self,
6638    ) -> Option<(ChannelListenerRegistryListenL2capRequest, PeripheralListenL2capResponder)> {
6639        if let PeripheralRequest::ListenL2cap { payload, responder } = self {
6640            Some((payload, responder))
6641        } else {
6642            None
6643        }
6644    }
6645
6646    #[allow(irrefutable_let_patterns)]
6647    pub fn into_advertise(
6648        self,
6649    ) -> Option<(
6650        AdvertisingParameters,
6651        fidl::endpoints::ClientEnd<AdvertisedPeripheralMarker>,
6652        PeripheralAdvertiseResponder,
6653    )> {
6654        if let PeripheralRequest::Advertise { parameters, advertised_peripheral, responder } = self
6655        {
6656            Some((parameters, advertised_peripheral, responder))
6657        } else {
6658            None
6659        }
6660    }
6661
6662    #[allow(irrefutable_let_patterns)]
6663    pub fn into_start_advertising(
6664        self,
6665    ) -> Option<(
6666        AdvertisingParameters,
6667        fidl::endpoints::ServerEnd<AdvertisingHandleMarker>,
6668        PeripheralStartAdvertisingResponder,
6669    )> {
6670        if let PeripheralRequest::StartAdvertising { parameters, handle, responder } = self {
6671            Some((parameters, handle, responder))
6672        } else {
6673            None
6674        }
6675    }
6676
6677    /// Name of the method defined in FIDL
6678    pub fn method_name(&self) -> &'static str {
6679        match *self {
6680            PeripheralRequest::ListenL2cap { .. } => "listen_l2cap",
6681            PeripheralRequest::Advertise { .. } => "advertise",
6682            PeripheralRequest::StartAdvertising { .. } => "start_advertising",
6683        }
6684    }
6685}
6686
6687#[derive(Debug, Clone)]
6688pub struct PeripheralControlHandle {
6689    inner: std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>,
6690}
6691
6692impl fidl::endpoints::ControlHandle for PeripheralControlHandle {
6693    fn shutdown(&self) {
6694        self.inner.shutdown()
6695    }
6696    fn shutdown_with_epitaph(&self, status: zx_status::Status) {
6697        self.inner.shutdown_with_epitaph(status)
6698    }
6699
6700    fn is_closed(&self) -> bool {
6701        self.inner.channel().is_closed()
6702    }
6703    fn on_closed(&self) -> fidl::OnSignalsRef<'_> {
6704        self.inner.channel().on_closed()
6705    }
6706
6707    #[cfg(target_os = "fuchsia")]
6708    fn signal_peer(
6709        &self,
6710        clear_mask: zx::Signals,
6711        set_mask: zx::Signals,
6712    ) -> Result<(), zx_status::Status> {
6713        use fidl::Peered;
6714        self.inner.channel().signal_peer(clear_mask, set_mask)
6715    }
6716}
6717
6718impl PeripheralControlHandle {
6719    pub fn send_on_peer_connected(
6720        &self,
6721        mut peer: &Peer,
6722        mut connection: fidl::endpoints::ClientEnd<ConnectionMarker>,
6723    ) -> Result<(), fidl::Error> {
6724        self.inner.send::<PeripheralOnPeerConnectedRequest>(
6725            (peer, connection),
6726            0,
6727            0x16135d464299e356,
6728            fidl::encoding::DynamicFlags::empty(),
6729        )
6730    }
6731}
6732
6733#[must_use = "FIDL methods require a response to be sent"]
6734#[derive(Debug)]
6735pub struct PeripheralListenL2capResponder {
6736    control_handle: std::mem::ManuallyDrop<PeripheralControlHandle>,
6737    tx_id: u32,
6738}
6739
6740/// Set the the channel to be shutdown (see [`PeripheralControlHandle::shutdown`])
6741/// if the responder is dropped without sending a response, so that the client
6742/// doesn't hang. To prevent this behavior, call `drop_without_shutdown`.
6743impl std::ops::Drop for PeripheralListenL2capResponder {
6744    fn drop(&mut self) {
6745        self.control_handle.shutdown();
6746        // Safety: drops once, never accessed again
6747        unsafe { std::mem::ManuallyDrop::drop(&mut self.control_handle) };
6748    }
6749}
6750
6751impl fidl::endpoints::Responder for PeripheralListenL2capResponder {
6752    type ControlHandle = PeripheralControlHandle;
6753
6754    fn control_handle(&self) -> &PeripheralControlHandle {
6755        &self.control_handle
6756    }
6757
6758    fn drop_without_shutdown(mut self) {
6759        // Safety: drops once, never accessed again due to mem::forget
6760        unsafe { std::mem::ManuallyDrop::drop(&mut self.control_handle) };
6761        // Prevent Drop from running (which would shut down the channel)
6762        std::mem::forget(self);
6763    }
6764}
6765
6766impl PeripheralListenL2capResponder {
6767    /// Sends a response to the FIDL transaction.
6768    ///
6769    /// Sets the channel to shutdown if an error occurs.
6770    pub fn send(
6771        self,
6772        mut result: Result<&ChannelListenerRegistryListenL2capResponse, i32>,
6773    ) -> Result<(), fidl::Error> {
6774        let _result = self.send_raw(result);
6775        if _result.is_err() {
6776            self.control_handle.shutdown();
6777        }
6778        self.drop_without_shutdown();
6779        _result
6780    }
6781
6782    /// Similar to "send" but does not shutdown the channel if an error occurs.
6783    pub fn send_no_shutdown_on_err(
6784        self,
6785        mut result: Result<&ChannelListenerRegistryListenL2capResponse, i32>,
6786    ) -> Result<(), fidl::Error> {
6787        let _result = self.send_raw(result);
6788        self.drop_without_shutdown();
6789        _result
6790    }
6791
6792    fn send_raw(
6793        &self,
6794        mut result: Result<&ChannelListenerRegistryListenL2capResponse, i32>,
6795    ) -> Result<(), fidl::Error> {
6796        self.control_handle.inner.send::<fidl::encoding::ResultType<
6797            ChannelListenerRegistryListenL2capResponse,
6798            i32,
6799        >>(
6800            result,
6801            self.tx_id,
6802            0x39c6e9001d102338,
6803            fidl::encoding::DynamicFlags::empty(),
6804        )
6805    }
6806}
6807
6808#[must_use = "FIDL methods require a response to be sent"]
6809#[derive(Debug)]
6810pub struct PeripheralAdvertiseResponder {
6811    control_handle: std::mem::ManuallyDrop<PeripheralControlHandle>,
6812    tx_id: u32,
6813}
6814
6815/// Set the the channel to be shutdown (see [`PeripheralControlHandle::shutdown`])
6816/// if the responder is dropped without sending a response, so that the client
6817/// doesn't hang. To prevent this behavior, call `drop_without_shutdown`.
6818impl std::ops::Drop for PeripheralAdvertiseResponder {
6819    fn drop(&mut self) {
6820        self.control_handle.shutdown();
6821        // Safety: drops once, never accessed again
6822        unsafe { std::mem::ManuallyDrop::drop(&mut self.control_handle) };
6823    }
6824}
6825
6826impl fidl::endpoints::Responder for PeripheralAdvertiseResponder {
6827    type ControlHandle = PeripheralControlHandle;
6828
6829    fn control_handle(&self) -> &PeripheralControlHandle {
6830        &self.control_handle
6831    }
6832
6833    fn drop_without_shutdown(mut self) {
6834        // Safety: drops once, never accessed again due to mem::forget
6835        unsafe { std::mem::ManuallyDrop::drop(&mut self.control_handle) };
6836        // Prevent Drop from running (which would shut down the channel)
6837        std::mem::forget(self);
6838    }
6839}
6840
6841impl PeripheralAdvertiseResponder {
6842    /// Sends a response to the FIDL transaction.
6843    ///
6844    /// Sets the channel to shutdown if an error occurs.
6845    pub fn send(self, mut result: Result<(), PeripheralError>) -> Result<(), fidl::Error> {
6846        let _result = self.send_raw(result);
6847        if _result.is_err() {
6848            self.control_handle.shutdown();
6849        }
6850        self.drop_without_shutdown();
6851        _result
6852    }
6853
6854    /// Similar to "send" but does not shutdown the channel if an error occurs.
6855    pub fn send_no_shutdown_on_err(
6856        self,
6857        mut result: Result<(), PeripheralError>,
6858    ) -> Result<(), fidl::Error> {
6859        let _result = self.send_raw(result);
6860        self.drop_without_shutdown();
6861        _result
6862    }
6863
6864    fn send_raw(&self, mut result: Result<(), PeripheralError>) -> Result<(), fidl::Error> {
6865        self.control_handle.inner.send::<fidl::encoding::ResultType<
6866            fidl::encoding::EmptyStruct,
6867            PeripheralError,
6868        >>(
6869            result,
6870            self.tx_id,
6871            0x2d9ec9260c32c17f,
6872            fidl::encoding::DynamicFlags::empty(),
6873        )
6874    }
6875}
6876
6877#[must_use = "FIDL methods require a response to be sent"]
6878#[derive(Debug)]
6879pub struct PeripheralStartAdvertisingResponder {
6880    control_handle: std::mem::ManuallyDrop<PeripheralControlHandle>,
6881    tx_id: u32,
6882}
6883
6884/// Set the the channel to be shutdown (see [`PeripheralControlHandle::shutdown`])
6885/// if the responder is dropped without sending a response, so that the client
6886/// doesn't hang. To prevent this behavior, call `drop_without_shutdown`.
6887impl std::ops::Drop for PeripheralStartAdvertisingResponder {
6888    fn drop(&mut self) {
6889        self.control_handle.shutdown();
6890        // Safety: drops once, never accessed again
6891        unsafe { std::mem::ManuallyDrop::drop(&mut self.control_handle) };
6892    }
6893}
6894
6895impl fidl::endpoints::Responder for PeripheralStartAdvertisingResponder {
6896    type ControlHandle = PeripheralControlHandle;
6897
6898    fn control_handle(&self) -> &PeripheralControlHandle {
6899        &self.control_handle
6900    }
6901
6902    fn drop_without_shutdown(mut self) {
6903        // Safety: drops once, never accessed again due to mem::forget
6904        unsafe { std::mem::ManuallyDrop::drop(&mut self.control_handle) };
6905        // Prevent Drop from running (which would shut down the channel)
6906        std::mem::forget(self);
6907    }
6908}
6909
6910impl PeripheralStartAdvertisingResponder {
6911    /// Sends a response to the FIDL transaction.
6912    ///
6913    /// Sets the channel to shutdown if an error occurs.
6914    pub fn send(self, mut result: Result<(), PeripheralError>) -> Result<(), fidl::Error> {
6915        let _result = self.send_raw(result);
6916        if _result.is_err() {
6917            self.control_handle.shutdown();
6918        }
6919        self.drop_without_shutdown();
6920        _result
6921    }
6922
6923    /// Similar to "send" but does not shutdown the channel if an error occurs.
6924    pub fn send_no_shutdown_on_err(
6925        self,
6926        mut result: Result<(), PeripheralError>,
6927    ) -> Result<(), fidl::Error> {
6928        let _result = self.send_raw(result);
6929        self.drop_without_shutdown();
6930        _result
6931    }
6932
6933    fn send_raw(&self, mut result: Result<(), PeripheralError>) -> Result<(), fidl::Error> {
6934        self.control_handle.inner.send::<fidl::encoding::ResultType<
6935            fidl::encoding::EmptyStruct,
6936            PeripheralError,
6937        >>(
6938            result,
6939            self.tx_id,
6940            0x5875c1c575f00f7d,
6941            fidl::encoding::DynamicFlags::empty(),
6942        )
6943    }
6944}
6945
6946#[derive(Debug, Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Hash)]
6947pub struct PrivilegedPeripheralMarker;
6948
6949impl fidl::endpoints::ProtocolMarker for PrivilegedPeripheralMarker {
6950    type Proxy = PrivilegedPeripheralProxy;
6951    type RequestStream = PrivilegedPeripheralRequestStream;
6952    #[cfg(target_os = "fuchsia")]
6953    type SynchronousProxy = PrivilegedPeripheralSynchronousProxy;
6954
6955    const DEBUG_NAME: &'static str = "fuchsia.bluetooth.le.PrivilegedPeripheral";
6956}
6957impl fidl::endpoints::DiscoverableProtocolMarker for PrivilegedPeripheralMarker {}
6958
6959pub trait PrivilegedPeripheralProxyInterface: Send + Sync {
6960    type ListenL2capResponseFut: std::future::Future<Output = Result<ChannelListenerRegistryListenL2capResult, fidl::Error>>
6961        + Send;
6962    fn r#listen_l2cap(
6963        &self,
6964        payload: ChannelListenerRegistryListenL2capRequest,
6965    ) -> Self::ListenL2capResponseFut;
6966    type AdvertiseResponseFut: std::future::Future<Output = Result<PeripheralAdvertiseResult, fidl::Error>>
6967        + Send;
6968    fn r#advertise(
6969        &self,
6970        parameters: &AdvertisingParameters,
6971        advertised_peripheral: fidl::endpoints::ClientEnd<AdvertisedPeripheralMarker>,
6972    ) -> Self::AdvertiseResponseFut;
6973    type StartAdvertisingResponseFut: std::future::Future<Output = Result<PeripheralStartAdvertisingResult, fidl::Error>>
6974        + Send;
6975    fn r#start_advertising(
6976        &self,
6977        parameters: &AdvertisingParameters,
6978        handle: fidl::endpoints::ServerEnd<AdvertisingHandleMarker>,
6979    ) -> Self::StartAdvertisingResponseFut;
6980}
6981#[derive(Debug)]
6982#[cfg(target_os = "fuchsia")]
6983pub struct PrivilegedPeripheralSynchronousProxy {
6984    client: fidl::client::sync::Client,
6985}
6986
6987#[cfg(target_os = "fuchsia")]
6988impl fidl::endpoints::SynchronousProxy for PrivilegedPeripheralSynchronousProxy {
6989    type Proxy = PrivilegedPeripheralProxy;
6990    type Protocol = PrivilegedPeripheralMarker;
6991
6992    fn from_channel(inner: fidl::Channel) -> Self {
6993        Self::new(inner)
6994    }
6995
6996    fn into_channel(self) -> fidl::Channel {
6997        self.client.into_channel()
6998    }
6999
7000    fn as_channel(&self) -> &fidl::Channel {
7001        self.client.as_channel()
7002    }
7003}
7004
7005#[cfg(target_os = "fuchsia")]
7006impl PrivilegedPeripheralSynchronousProxy {
7007    pub fn new(channel: fidl::Channel) -> Self {
7008        let protocol_name =
7009            <PrivilegedPeripheralMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME;
7010        Self { client: fidl::client::sync::Client::new(channel, protocol_name) }
7011    }
7012
7013    pub fn into_channel(self) -> fidl::Channel {
7014        self.client.into_channel()
7015    }
7016
7017    /// Waits until an event arrives and returns it. It is safe for other
7018    /// threads to make concurrent requests while waiting for an event.
7019    pub fn wait_for_event(
7020        &self,
7021        deadline: zx::MonotonicInstant,
7022    ) -> Result<PrivilegedPeripheralEvent, fidl::Error> {
7023        PrivilegedPeripheralEvent::decode(self.client.wait_for_event(deadline)?)
7024    }
7025
7026    /// Register a listener for incoming channels. The registry will assign a
7027    /// PSM value that is unique for the local device, as well as open a
7028    /// [`ChannelListener`] for accepting incoming channels. In the unlikely
7029    /// event that all PSMs have been assigned, this call will fail with
7030    /// `ZX_ERR_NO_RESOURCES`.
7031    ///
7032    /// Note that the method of service discovery or advertising is defined by
7033    /// the service or protocol, so it is the responsibility of the caller to
7034    /// communicate the assigned PSM to any clients.
7035    pub fn r#listen_l2cap(
7036        &self,
7037        mut payload: ChannelListenerRegistryListenL2capRequest,
7038        ___deadline: zx::MonotonicInstant,
7039    ) -> Result<ChannelListenerRegistryListenL2capResult, fidl::Error> {
7040        let _response = self.client.send_query::<
7041            ChannelListenerRegistryListenL2capRequest,
7042            fidl::encoding::ResultType<ChannelListenerRegistryListenL2capResponse, i32>,
7043        >(
7044            &mut payload,
7045            0x39c6e9001d102338,
7046            fidl::encoding::DynamicFlags::empty(),
7047            ___deadline,
7048        )?;
7049        Ok(_response.map(|x| x))
7050    }
7051
7052    /// Start advertising continuously as a LE peripheral. If advertising cannot
7053    /// be initiated then `advertised_peripheral` will be closed and an error
7054    /// will be returned.
7055    ///
7056    /// This method may be called any number of times. To reconfigure an
7057    /// advertisement, first close the original advertisement and then initiate
7058    /// a new advertisement after an empty response is returned.
7059    ///
7060    /// If the client closes its end of the
7061    /// [`fuchsia.bluetooth.le/AdvertisedPeripheral`] channel,
7062    /// advertising will be stopped. If the handle is closed before the request
7063    /// is fulfilled, advertising may be briefly enabled before it is
7064    /// terminated. AdvertisedPeripheral lifetime is bounded by the lifetime of
7065    /// the Peripheral protocol, but this may be changed in the future
7066    /// (https://fxbug.dev/42157682).
7067    ///
7068    /// + request `parameters` Parameters used while configuring the advertising
7069    ///   instance.
7070    /// + request `advertised_peripheral` Protocol that remains valid for the
7071    ///   duration of this advertising session.
7072    /// - response An empty response will be sent when the advertisement is
7073    ///   successfully stopped (due to release of the `advertised_peripheral`
7074    ///   protocol). To prevent overlapping similar advertisements and transient
7075    ///   errors with limited advertising resources, waiting for a response is
7076    ///   recommended before calling `Advertise` again.
7077    /// * error If an error occurs, `advertised_peripheral` will be closed and a
7078    ///   `PeripheralError` will be returned.
7079    pub fn r#advertise(
7080        &self,
7081        mut parameters: &AdvertisingParameters,
7082        mut advertised_peripheral: fidl::endpoints::ClientEnd<AdvertisedPeripheralMarker>,
7083        ___deadline: zx::MonotonicInstant,
7084    ) -> Result<PeripheralAdvertiseResult, fidl::Error> {
7085        let _response = self.client.send_query::<
7086            PeripheralAdvertiseRequest,
7087            fidl::encoding::ResultType<fidl::encoding::EmptyStruct, PeripheralError>,
7088        >(
7089            (parameters, advertised_peripheral,),
7090            0x2d9ec9260c32c17f,
7091            fidl::encoding::DynamicFlags::empty(),
7092            ___deadline,
7093        )?;
7094        Ok(_response.map(|x| x))
7095    }
7096
7097    /// Start advertising as a LE peripheral. An empty response is sent to indicate when advertising
7098    /// has successfully initiated. If advertising cannot be initiated, then the response will
7099    /// contain a [`fuchsia.bluetooth.le/PeripheralError`].
7100    ///
7101    /// This method can get called any number of times and successive calls can be made to
7102    /// reconfigure the advertising parameters. However only the most recent
7103    /// [`fuchsia.bluetooth.le/AdvertisingHandle`] will remain valid.
7104    ///
7105    /// An instance of [`fuchsia.bluetooth.le/Peripheral`] can only have one active advertisement at
7106    /// a time. Clients must obtain multiple Peripheral instances for multiple simultaneous
7107    /// advertisements.
7108    ///
7109    /// If the client closes its end of the [`fuchsia.bluetooth.le/AdvertisingHandle`] channel,
7110    /// advertising will be stopped. If the handle is closed before the request is fulfilled,
7111    /// advertising will be briefly enabled before it is terminated.
7112    ///
7113    /// + request `parameters` Parameters used while configuring the advertising instance.
7114    /// + request `handle` Handle that remains valid for the duration of this advertising session.
7115    /// * error Returns a [`fuchsia.bluetooth.le/PeripheralError`] if advertising cannot be
7116    ///         initiated. In this case the `handle` will be closed.
7117    pub fn r#start_advertising(
7118        &self,
7119        mut parameters: &AdvertisingParameters,
7120        mut handle: fidl::endpoints::ServerEnd<AdvertisingHandleMarker>,
7121        ___deadline: zx::MonotonicInstant,
7122    ) -> Result<PeripheralStartAdvertisingResult, fidl::Error> {
7123        let _response = self.client.send_query::<
7124            PeripheralStartAdvertisingRequest,
7125            fidl::encoding::ResultType<fidl::encoding::EmptyStruct, PeripheralError>,
7126        >(
7127            (parameters, handle,),
7128            0x5875c1c575f00f7d,
7129            fidl::encoding::DynamicFlags::empty(),
7130            ___deadline,
7131        )?;
7132        Ok(_response.map(|x| x))
7133    }
7134}
7135
7136#[cfg(target_os = "fuchsia")]
7137impl From<PrivilegedPeripheralSynchronousProxy> for zx::Handle {
7138    fn from(value: PrivilegedPeripheralSynchronousProxy) -> Self {
7139        value.into_channel().into()
7140    }
7141}
7142
7143#[cfg(target_os = "fuchsia")]
7144impl From<fidl::Channel> for PrivilegedPeripheralSynchronousProxy {
7145    fn from(value: fidl::Channel) -> Self {
7146        Self::new(value)
7147    }
7148}
7149
7150#[derive(Debug, Clone)]
7151pub struct PrivilegedPeripheralProxy {
7152    client: fidl::client::Client<fidl::encoding::DefaultFuchsiaResourceDialect>,
7153}
7154
7155impl fidl::endpoints::Proxy for PrivilegedPeripheralProxy {
7156    type Protocol = PrivilegedPeripheralMarker;
7157
7158    fn from_channel(inner: ::fidl::AsyncChannel) -> Self {
7159        Self::new(inner)
7160    }
7161
7162    fn into_channel(self) -> Result<::fidl::AsyncChannel, Self> {
7163        self.client.into_channel().map_err(|client| Self { client })
7164    }
7165
7166    fn as_channel(&self) -> &::fidl::AsyncChannel {
7167        self.client.as_channel()
7168    }
7169}
7170
7171impl PrivilegedPeripheralProxy {
7172    /// Create a new Proxy for fuchsia.bluetooth.le/PrivilegedPeripheral.
7173    pub fn new(channel: ::fidl::AsyncChannel) -> Self {
7174        let protocol_name =
7175            <PrivilegedPeripheralMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME;
7176        Self { client: fidl::client::Client::new(channel, protocol_name) }
7177    }
7178
7179    /// Get a Stream of events from the remote end of the protocol.
7180    ///
7181    /// # Panics
7182    ///
7183    /// Panics if the event stream was already taken.
7184    pub fn take_event_stream(&self) -> PrivilegedPeripheralEventStream {
7185        PrivilegedPeripheralEventStream { event_receiver: self.client.take_event_receiver() }
7186    }
7187
7188    /// Register a listener for incoming channels. The registry will assign a
7189    /// PSM value that is unique for the local device, as well as open a
7190    /// [`ChannelListener`] for accepting incoming channels. In the unlikely
7191    /// event that all PSMs have been assigned, this call will fail with
7192    /// `ZX_ERR_NO_RESOURCES`.
7193    ///
7194    /// Note that the method of service discovery or advertising is defined by
7195    /// the service or protocol, so it is the responsibility of the caller to
7196    /// communicate the assigned PSM to any clients.
7197    pub fn r#listen_l2cap(
7198        &self,
7199        mut payload: ChannelListenerRegistryListenL2capRequest,
7200    ) -> fidl::client::QueryResponseFut<
7201        ChannelListenerRegistryListenL2capResult,
7202        fidl::encoding::DefaultFuchsiaResourceDialect,
7203    > {
7204        PrivilegedPeripheralProxyInterface::r#listen_l2cap(self, payload)
7205    }
7206
7207    /// Start advertising continuously as a LE peripheral. If advertising cannot
7208    /// be initiated then `advertised_peripheral` will be closed and an error
7209    /// will be returned.
7210    ///
7211    /// This method may be called any number of times. To reconfigure an
7212    /// advertisement, first close the original advertisement and then initiate
7213    /// a new advertisement after an empty response is returned.
7214    ///
7215    /// If the client closes its end of the
7216    /// [`fuchsia.bluetooth.le/AdvertisedPeripheral`] channel,
7217    /// advertising will be stopped. If the handle is closed before the request
7218    /// is fulfilled, advertising may be briefly enabled before it is
7219    /// terminated. AdvertisedPeripheral lifetime is bounded by the lifetime of
7220    /// the Peripheral protocol, but this may be changed in the future
7221    /// (https://fxbug.dev/42157682).
7222    ///
7223    /// + request `parameters` Parameters used while configuring the advertising
7224    ///   instance.
7225    /// + request `advertised_peripheral` Protocol that remains valid for the
7226    ///   duration of this advertising session.
7227    /// - response An empty response will be sent when the advertisement is
7228    ///   successfully stopped (due to release of the `advertised_peripheral`
7229    ///   protocol). To prevent overlapping similar advertisements and transient
7230    ///   errors with limited advertising resources, waiting for a response is
7231    ///   recommended before calling `Advertise` again.
7232    /// * error If an error occurs, `advertised_peripheral` will be closed and a
7233    ///   `PeripheralError` will be returned.
7234    pub fn r#advertise(
7235        &self,
7236        mut parameters: &AdvertisingParameters,
7237        mut advertised_peripheral: fidl::endpoints::ClientEnd<AdvertisedPeripheralMarker>,
7238    ) -> fidl::client::QueryResponseFut<
7239        PeripheralAdvertiseResult,
7240        fidl::encoding::DefaultFuchsiaResourceDialect,
7241    > {
7242        PrivilegedPeripheralProxyInterface::r#advertise(self, parameters, advertised_peripheral)
7243    }
7244
7245    /// Start advertising as a LE peripheral. An empty response is sent to indicate when advertising
7246    /// has successfully initiated. If advertising cannot be initiated, then the response will
7247    /// contain a [`fuchsia.bluetooth.le/PeripheralError`].
7248    ///
7249    /// This method can get called any number of times and successive calls can be made to
7250    /// reconfigure the advertising parameters. However only the most recent
7251    /// [`fuchsia.bluetooth.le/AdvertisingHandle`] will remain valid.
7252    ///
7253    /// An instance of [`fuchsia.bluetooth.le/Peripheral`] can only have one active advertisement at
7254    /// a time. Clients must obtain multiple Peripheral instances for multiple simultaneous
7255    /// advertisements.
7256    ///
7257    /// If the client closes its end of the [`fuchsia.bluetooth.le/AdvertisingHandle`] channel,
7258    /// advertising will be stopped. If the handle is closed before the request is fulfilled,
7259    /// advertising will be briefly enabled before it is terminated.
7260    ///
7261    /// + request `parameters` Parameters used while configuring the advertising instance.
7262    /// + request `handle` Handle that remains valid for the duration of this advertising session.
7263    /// * error Returns a [`fuchsia.bluetooth.le/PeripheralError`] if advertising cannot be
7264    ///         initiated. In this case the `handle` will be closed.
7265    pub fn r#start_advertising(
7266        &self,
7267        mut parameters: &AdvertisingParameters,
7268        mut handle: fidl::endpoints::ServerEnd<AdvertisingHandleMarker>,
7269    ) -> fidl::client::QueryResponseFut<
7270        PeripheralStartAdvertisingResult,
7271        fidl::encoding::DefaultFuchsiaResourceDialect,
7272    > {
7273        PrivilegedPeripheralProxyInterface::r#start_advertising(self, parameters, handle)
7274    }
7275}
7276
7277impl PrivilegedPeripheralProxyInterface for PrivilegedPeripheralProxy {
7278    type ListenL2capResponseFut = fidl::client::QueryResponseFut<
7279        ChannelListenerRegistryListenL2capResult,
7280        fidl::encoding::DefaultFuchsiaResourceDialect,
7281    >;
7282    fn r#listen_l2cap(
7283        &self,
7284        mut payload: ChannelListenerRegistryListenL2capRequest,
7285    ) -> Self::ListenL2capResponseFut {
7286        fn _decode(
7287            mut _buf: Result<<fidl::encoding::DefaultFuchsiaResourceDialect as fidl::encoding::ResourceDialect>::MessageBufEtc, fidl::Error>,
7288        ) -> Result<ChannelListenerRegistryListenL2capResult, fidl::Error> {
7289            let _response = fidl::client::decode_transaction_body::<
7290                fidl::encoding::ResultType<ChannelListenerRegistryListenL2capResponse, i32>,
7291                fidl::encoding::DefaultFuchsiaResourceDialect,
7292                0x39c6e9001d102338,
7293            >(_buf?)?;
7294            Ok(_response.map(|x| x))
7295        }
7296        self.client.send_query_and_decode::<
7297            ChannelListenerRegistryListenL2capRequest,
7298            ChannelListenerRegistryListenL2capResult,
7299        >(
7300            &mut payload,
7301            0x39c6e9001d102338,
7302            fidl::encoding::DynamicFlags::empty(),
7303            _decode,
7304        )
7305    }
7306
7307    type AdvertiseResponseFut = fidl::client::QueryResponseFut<
7308        PeripheralAdvertiseResult,
7309        fidl::encoding::DefaultFuchsiaResourceDialect,
7310    >;
7311    fn r#advertise(
7312        &self,
7313        mut parameters: &AdvertisingParameters,
7314        mut advertised_peripheral: fidl::endpoints::ClientEnd<AdvertisedPeripheralMarker>,
7315    ) -> Self::AdvertiseResponseFut {
7316        fn _decode(
7317            mut _buf: Result<<fidl::encoding::DefaultFuchsiaResourceDialect as fidl::encoding::ResourceDialect>::MessageBufEtc, fidl::Error>,
7318        ) -> Result<PeripheralAdvertiseResult, fidl::Error> {
7319            let _response = fidl::client::decode_transaction_body::<
7320                fidl::encoding::ResultType<fidl::encoding::EmptyStruct, PeripheralError>,
7321                fidl::encoding::DefaultFuchsiaResourceDialect,
7322                0x2d9ec9260c32c17f,
7323            >(_buf?)?;
7324            Ok(_response.map(|x| x))
7325        }
7326        self.client.send_query_and_decode::<PeripheralAdvertiseRequest, PeripheralAdvertiseResult>(
7327            (parameters, advertised_peripheral),
7328            0x2d9ec9260c32c17f,
7329            fidl::encoding::DynamicFlags::empty(),
7330            _decode,
7331        )
7332    }
7333
7334    type StartAdvertisingResponseFut = fidl::client::QueryResponseFut<
7335        PeripheralStartAdvertisingResult,
7336        fidl::encoding::DefaultFuchsiaResourceDialect,
7337    >;
7338    fn r#start_advertising(
7339        &self,
7340        mut parameters: &AdvertisingParameters,
7341        mut handle: fidl::endpoints::ServerEnd<AdvertisingHandleMarker>,
7342    ) -> Self::StartAdvertisingResponseFut {
7343        fn _decode(
7344            mut _buf: Result<<fidl::encoding::DefaultFuchsiaResourceDialect as fidl::encoding::ResourceDialect>::MessageBufEtc, fidl::Error>,
7345        ) -> Result<PeripheralStartAdvertisingResult, fidl::Error> {
7346            let _response = fidl::client::decode_transaction_body::<
7347                fidl::encoding::ResultType<fidl::encoding::EmptyStruct, PeripheralError>,
7348                fidl::encoding::DefaultFuchsiaResourceDialect,
7349                0x5875c1c575f00f7d,
7350            >(_buf?)?;
7351            Ok(_response.map(|x| x))
7352        }
7353        self.client.send_query_and_decode::<
7354            PeripheralStartAdvertisingRequest,
7355            PeripheralStartAdvertisingResult,
7356        >(
7357            (parameters, handle,),
7358            0x5875c1c575f00f7d,
7359            fidl::encoding::DynamicFlags::empty(),
7360            _decode,
7361        )
7362    }
7363}
7364
7365pub struct PrivilegedPeripheralEventStream {
7366    event_receiver: fidl::client::EventReceiver<fidl::encoding::DefaultFuchsiaResourceDialect>,
7367}
7368
7369impl std::marker::Unpin for PrivilegedPeripheralEventStream {}
7370
7371impl futures::stream::FusedStream for PrivilegedPeripheralEventStream {
7372    fn is_terminated(&self) -> bool {
7373        self.event_receiver.is_terminated()
7374    }
7375}
7376
7377impl futures::Stream for PrivilegedPeripheralEventStream {
7378    type Item = Result<PrivilegedPeripheralEvent, fidl::Error>;
7379
7380    fn poll_next(
7381        mut self: std::pin::Pin<&mut Self>,
7382        cx: &mut std::task::Context<'_>,
7383    ) -> std::task::Poll<Option<Self::Item>> {
7384        match futures::ready!(futures::stream::StreamExt::poll_next_unpin(
7385            &mut self.event_receiver,
7386            cx
7387        )?) {
7388            Some(buf) => std::task::Poll::Ready(Some(PrivilegedPeripheralEvent::decode(buf))),
7389            None => std::task::Poll::Ready(None),
7390        }
7391    }
7392}
7393
7394#[derive(Debug)]
7395pub enum PrivilegedPeripheralEvent {
7396    OnPeerConnected { peer: Peer, connection: fidl::endpoints::ClientEnd<ConnectionMarker> },
7397}
7398
7399impl PrivilegedPeripheralEvent {
7400    #[allow(irrefutable_let_patterns)]
7401    pub fn into_on_peer_connected(
7402        self,
7403    ) -> Option<(Peer, fidl::endpoints::ClientEnd<ConnectionMarker>)> {
7404        if let PrivilegedPeripheralEvent::OnPeerConnected { peer, connection } = self {
7405            Some((peer, connection))
7406        } else {
7407            None
7408        }
7409    }
7410
7411    /// Decodes a message buffer as a [`PrivilegedPeripheralEvent`].
7412    fn decode(
7413        mut buf: <fidl::encoding::DefaultFuchsiaResourceDialect as fidl::encoding::ResourceDialect>::MessageBufEtc,
7414    ) -> Result<PrivilegedPeripheralEvent, fidl::Error> {
7415        let (bytes, _handles) = buf.split_mut();
7416        let (tx_header, _body_bytes) = fidl::encoding::decode_transaction_header(bytes)?;
7417        debug_assert_eq!(tx_header.tx_id, 0);
7418        match tx_header.ordinal {
7419            0x16135d464299e356 => {
7420                let mut out = fidl::new_empty!(
7421                    PeripheralOnPeerConnectedRequest,
7422                    fidl::encoding::DefaultFuchsiaResourceDialect
7423                );
7424                fidl::encoding::Decoder::<fidl::encoding::DefaultFuchsiaResourceDialect>::decode_into::<PeripheralOnPeerConnectedRequest>(&tx_header, _body_bytes, _handles, &mut out)?;
7425                Ok((PrivilegedPeripheralEvent::OnPeerConnected {
7426                    peer: out.peer,
7427                    connection: out.connection,
7428                }))
7429            }
7430            _ => Err(fidl::Error::UnknownOrdinal {
7431                ordinal: tx_header.ordinal,
7432                protocol_name:
7433                    <PrivilegedPeripheralMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME,
7434            }),
7435        }
7436    }
7437}
7438
7439/// A Stream of incoming requests for fuchsia.bluetooth.le/PrivilegedPeripheral.
7440pub struct PrivilegedPeripheralRequestStream {
7441    inner: std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>,
7442    is_terminated: bool,
7443}
7444
7445impl std::marker::Unpin for PrivilegedPeripheralRequestStream {}
7446
7447impl futures::stream::FusedStream for PrivilegedPeripheralRequestStream {
7448    fn is_terminated(&self) -> bool {
7449        self.is_terminated
7450    }
7451}
7452
7453impl fidl::endpoints::RequestStream for PrivilegedPeripheralRequestStream {
7454    type Protocol = PrivilegedPeripheralMarker;
7455    type ControlHandle = PrivilegedPeripheralControlHandle;
7456
7457    fn from_channel(channel: ::fidl::AsyncChannel) -> Self {
7458        Self { inner: std::sync::Arc::new(fidl::ServeInner::new(channel)), is_terminated: false }
7459    }
7460
7461    fn control_handle(&self) -> Self::ControlHandle {
7462        PrivilegedPeripheralControlHandle { inner: self.inner.clone() }
7463    }
7464
7465    fn into_inner(
7466        self,
7467    ) -> (::std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>, bool)
7468    {
7469        (self.inner, self.is_terminated)
7470    }
7471
7472    fn from_inner(
7473        inner: std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>,
7474        is_terminated: bool,
7475    ) -> Self {
7476        Self { inner, is_terminated }
7477    }
7478}
7479
7480impl futures::Stream for PrivilegedPeripheralRequestStream {
7481    type Item = Result<PrivilegedPeripheralRequest, fidl::Error>;
7482
7483    fn poll_next(
7484        mut self: std::pin::Pin<&mut Self>,
7485        cx: &mut std::task::Context<'_>,
7486    ) -> std::task::Poll<Option<Self::Item>> {
7487        let this = &mut *self;
7488        if this.inner.check_shutdown(cx) {
7489            this.is_terminated = true;
7490            return std::task::Poll::Ready(None);
7491        }
7492        if this.is_terminated {
7493            panic!("polled PrivilegedPeripheralRequestStream after completion");
7494        }
7495        fidl::encoding::with_tls_decode_buf::<_, fidl::encoding::DefaultFuchsiaResourceDialect>(
7496            |bytes, handles| {
7497                match this.inner.channel().read_etc(cx, bytes, handles) {
7498                    std::task::Poll::Ready(Ok(())) => {}
7499                    std::task::Poll::Pending => return std::task::Poll::Pending,
7500                    std::task::Poll::Ready(Err(zx_status::Status::PEER_CLOSED)) => {
7501                        this.is_terminated = true;
7502                        return std::task::Poll::Ready(None);
7503                    }
7504                    std::task::Poll::Ready(Err(e)) => {
7505                        return std::task::Poll::Ready(Some(Err(fidl::Error::ServerRequestRead(
7506                            e.into(),
7507                        ))))
7508                    }
7509                }
7510
7511                // A message has been received from the channel
7512                let (header, _body_bytes) = fidl::encoding::decode_transaction_header(bytes)?;
7513
7514                std::task::Poll::Ready(Some(match header.ordinal {
7515                0x39c6e9001d102338 => {
7516                    header.validate_request_tx_id(fidl::MethodType::TwoWay)?;
7517                    let mut req = fidl::new_empty!(ChannelListenerRegistryListenL2capRequest, fidl::encoding::DefaultFuchsiaResourceDialect);
7518                    fidl::encoding::Decoder::<fidl::encoding::DefaultFuchsiaResourceDialect>::decode_into::<ChannelListenerRegistryListenL2capRequest>(&header, _body_bytes, handles, &mut req)?;
7519                    let control_handle = PrivilegedPeripheralControlHandle {
7520                        inner: this.inner.clone(),
7521                    };
7522                    Ok(PrivilegedPeripheralRequest::ListenL2cap {payload: req,
7523                        responder: PrivilegedPeripheralListenL2capResponder {
7524                            control_handle: std::mem::ManuallyDrop::new(control_handle),
7525                            tx_id: header.tx_id,
7526                        },
7527                    })
7528                }
7529                0x2d9ec9260c32c17f => {
7530                    header.validate_request_tx_id(fidl::MethodType::TwoWay)?;
7531                    let mut req = fidl::new_empty!(PeripheralAdvertiseRequest, fidl::encoding::DefaultFuchsiaResourceDialect);
7532                    fidl::encoding::Decoder::<fidl::encoding::DefaultFuchsiaResourceDialect>::decode_into::<PeripheralAdvertiseRequest>(&header, _body_bytes, handles, &mut req)?;
7533                    let control_handle = PrivilegedPeripheralControlHandle {
7534                        inner: this.inner.clone(),
7535                    };
7536                    Ok(PrivilegedPeripheralRequest::Advertise {parameters: req.parameters,
7537advertised_peripheral: req.advertised_peripheral,
7538
7539                        responder: PrivilegedPeripheralAdvertiseResponder {
7540                            control_handle: std::mem::ManuallyDrop::new(control_handle),
7541                            tx_id: header.tx_id,
7542                        },
7543                    })
7544                }
7545                0x5875c1c575f00f7d => {
7546                    header.validate_request_tx_id(fidl::MethodType::TwoWay)?;
7547                    let mut req = fidl::new_empty!(PeripheralStartAdvertisingRequest, fidl::encoding::DefaultFuchsiaResourceDialect);
7548                    fidl::encoding::Decoder::<fidl::encoding::DefaultFuchsiaResourceDialect>::decode_into::<PeripheralStartAdvertisingRequest>(&header, _body_bytes, handles, &mut req)?;
7549                    let control_handle = PrivilegedPeripheralControlHandle {
7550                        inner: this.inner.clone(),
7551                    };
7552                    Ok(PrivilegedPeripheralRequest::StartAdvertising {parameters: req.parameters,
7553handle: req.handle,
7554
7555                        responder: PrivilegedPeripheralStartAdvertisingResponder {
7556                            control_handle: std::mem::ManuallyDrop::new(control_handle),
7557                            tx_id: header.tx_id,
7558                        },
7559                    })
7560                }
7561                _ => Err(fidl::Error::UnknownOrdinal {
7562                    ordinal: header.ordinal,
7563                    protocol_name: <PrivilegedPeripheralMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME,
7564                }),
7565            }))
7566            },
7567        )
7568    }
7569}
7570
7571/// Privileged version of the Peripheral protocol.
7572/// This protocol should only be routed to trusted and system components. Using this protocol will
7573/// enable the client to break normal privacy restrictions which could leak information about the
7574/// location or owner of the device.
7575///
7576/// Use cases which reveal information are noted in documentation and marked as only available
7577/// through PrivilegedPeripheral, and are an error if used through Peripheral.
7578#[derive(Debug)]
7579pub enum PrivilegedPeripheralRequest {
7580    /// Register a listener for incoming channels. The registry will assign a
7581    /// PSM value that is unique for the local device, as well as open a
7582    /// [`ChannelListener`] for accepting incoming channels. In the unlikely
7583    /// event that all PSMs have been assigned, this call will fail with
7584    /// `ZX_ERR_NO_RESOURCES`.
7585    ///
7586    /// Note that the method of service discovery or advertising is defined by
7587    /// the service or protocol, so it is the responsibility of the caller to
7588    /// communicate the assigned PSM to any clients.
7589    ListenL2cap {
7590        payload: ChannelListenerRegistryListenL2capRequest,
7591        responder: PrivilegedPeripheralListenL2capResponder,
7592    },
7593    /// Start advertising continuously as a LE peripheral. If advertising cannot
7594    /// be initiated then `advertised_peripheral` will be closed and an error
7595    /// will be returned.
7596    ///
7597    /// This method may be called any number of times. To reconfigure an
7598    /// advertisement, first close the original advertisement and then initiate
7599    /// a new advertisement after an empty response is returned.
7600    ///
7601    /// If the client closes its end of the
7602    /// [`fuchsia.bluetooth.le/AdvertisedPeripheral`] channel,
7603    /// advertising will be stopped. If the handle is closed before the request
7604    /// is fulfilled, advertising may be briefly enabled before it is
7605    /// terminated. AdvertisedPeripheral lifetime is bounded by the lifetime of
7606    /// the Peripheral protocol, but this may be changed in the future
7607    /// (https://fxbug.dev/42157682).
7608    ///
7609    /// + request `parameters` Parameters used while configuring the advertising
7610    ///   instance.
7611    /// + request `advertised_peripheral` Protocol that remains valid for the
7612    ///   duration of this advertising session.
7613    /// - response An empty response will be sent when the advertisement is
7614    ///   successfully stopped (due to release of the `advertised_peripheral`
7615    ///   protocol). To prevent overlapping similar advertisements and transient
7616    ///   errors with limited advertising resources, waiting for a response is
7617    ///   recommended before calling `Advertise` again.
7618    /// * error If an error occurs, `advertised_peripheral` will be closed and a
7619    ///   `PeripheralError` will be returned.
7620    Advertise {
7621        parameters: AdvertisingParameters,
7622        advertised_peripheral: fidl::endpoints::ClientEnd<AdvertisedPeripheralMarker>,
7623        responder: PrivilegedPeripheralAdvertiseResponder,
7624    },
7625    /// Start advertising as a LE peripheral. An empty response is sent to indicate when advertising
7626    /// has successfully initiated. If advertising cannot be initiated, then the response will
7627    /// contain a [`fuchsia.bluetooth.le/PeripheralError`].
7628    ///
7629    /// This method can get called any number of times and successive calls can be made to
7630    /// reconfigure the advertising parameters. However only the most recent
7631    /// [`fuchsia.bluetooth.le/AdvertisingHandle`] will remain valid.
7632    ///
7633    /// An instance of [`fuchsia.bluetooth.le/Peripheral`] can only have one active advertisement at
7634    /// a time. Clients must obtain multiple Peripheral instances for multiple simultaneous
7635    /// advertisements.
7636    ///
7637    /// If the client closes its end of the [`fuchsia.bluetooth.le/AdvertisingHandle`] channel,
7638    /// advertising will be stopped. If the handle is closed before the request is fulfilled,
7639    /// advertising will be briefly enabled before it is terminated.
7640    ///
7641    /// + request `parameters` Parameters used while configuring the advertising instance.
7642    /// + request `handle` Handle that remains valid for the duration of this advertising session.
7643    /// * error Returns a [`fuchsia.bluetooth.le/PeripheralError`] if advertising cannot be
7644    ///         initiated. In this case the `handle` will be closed.
7645    StartAdvertising {
7646        parameters: AdvertisingParameters,
7647        handle: fidl::endpoints::ServerEnd<AdvertisingHandleMarker>,
7648        responder: PrivilegedPeripheralStartAdvertisingResponder,
7649    },
7650}
7651
7652impl PrivilegedPeripheralRequest {
7653    #[allow(irrefutable_let_patterns)]
7654    pub fn into_listen_l2cap(
7655        self,
7656    ) -> Option<(ChannelListenerRegistryListenL2capRequest, PrivilegedPeripheralListenL2capResponder)>
7657    {
7658        if let PrivilegedPeripheralRequest::ListenL2cap { payload, responder } = self {
7659            Some((payload, responder))
7660        } else {
7661            None
7662        }
7663    }
7664
7665    #[allow(irrefutable_let_patterns)]
7666    pub fn into_advertise(
7667        self,
7668    ) -> Option<(
7669        AdvertisingParameters,
7670        fidl::endpoints::ClientEnd<AdvertisedPeripheralMarker>,
7671        PrivilegedPeripheralAdvertiseResponder,
7672    )> {
7673        if let PrivilegedPeripheralRequest::Advertise {
7674            parameters,
7675            advertised_peripheral,
7676            responder,
7677        } = self
7678        {
7679            Some((parameters, advertised_peripheral, responder))
7680        } else {
7681            None
7682        }
7683    }
7684
7685    #[allow(irrefutable_let_patterns)]
7686    pub fn into_start_advertising(
7687        self,
7688    ) -> Option<(
7689        AdvertisingParameters,
7690        fidl::endpoints::ServerEnd<AdvertisingHandleMarker>,
7691        PrivilegedPeripheralStartAdvertisingResponder,
7692    )> {
7693        if let PrivilegedPeripheralRequest::StartAdvertising { parameters, handle, responder } =
7694            self
7695        {
7696            Some((parameters, handle, responder))
7697        } else {
7698            None
7699        }
7700    }
7701
7702    /// Name of the method defined in FIDL
7703    pub fn method_name(&self) -> &'static str {
7704        match *self {
7705            PrivilegedPeripheralRequest::ListenL2cap { .. } => "listen_l2cap",
7706            PrivilegedPeripheralRequest::Advertise { .. } => "advertise",
7707            PrivilegedPeripheralRequest::StartAdvertising { .. } => "start_advertising",
7708        }
7709    }
7710}
7711
7712#[derive(Debug, Clone)]
7713pub struct PrivilegedPeripheralControlHandle {
7714    inner: std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>,
7715}
7716
7717impl fidl::endpoints::ControlHandle for PrivilegedPeripheralControlHandle {
7718    fn shutdown(&self) {
7719        self.inner.shutdown()
7720    }
7721    fn shutdown_with_epitaph(&self, status: zx_status::Status) {
7722        self.inner.shutdown_with_epitaph(status)
7723    }
7724
7725    fn is_closed(&self) -> bool {
7726        self.inner.channel().is_closed()
7727    }
7728    fn on_closed(&self) -> fidl::OnSignalsRef<'_> {
7729        self.inner.channel().on_closed()
7730    }
7731
7732    #[cfg(target_os = "fuchsia")]
7733    fn signal_peer(
7734        &self,
7735        clear_mask: zx::Signals,
7736        set_mask: zx::Signals,
7737    ) -> Result<(), zx_status::Status> {
7738        use fidl::Peered;
7739        self.inner.channel().signal_peer(clear_mask, set_mask)
7740    }
7741}
7742
7743impl PrivilegedPeripheralControlHandle {
7744    pub fn send_on_peer_connected(
7745        &self,
7746        mut peer: &Peer,
7747        mut connection: fidl::endpoints::ClientEnd<ConnectionMarker>,
7748    ) -> Result<(), fidl::Error> {
7749        self.inner.send::<PeripheralOnPeerConnectedRequest>(
7750            (peer, connection),
7751            0,
7752            0x16135d464299e356,
7753            fidl::encoding::DynamicFlags::empty(),
7754        )
7755    }
7756}
7757
7758#[must_use = "FIDL methods require a response to be sent"]
7759#[derive(Debug)]
7760pub struct PrivilegedPeripheralListenL2capResponder {
7761    control_handle: std::mem::ManuallyDrop<PrivilegedPeripheralControlHandle>,
7762    tx_id: u32,
7763}
7764
7765/// Set the the channel to be shutdown (see [`PrivilegedPeripheralControlHandle::shutdown`])
7766/// if the responder is dropped without sending a response, so that the client
7767/// doesn't hang. To prevent this behavior, call `drop_without_shutdown`.
7768impl std::ops::Drop for PrivilegedPeripheralListenL2capResponder {
7769    fn drop(&mut self) {
7770        self.control_handle.shutdown();
7771        // Safety: drops once, never accessed again
7772        unsafe { std::mem::ManuallyDrop::drop(&mut self.control_handle) };
7773    }
7774}
7775
7776impl fidl::endpoints::Responder for PrivilegedPeripheralListenL2capResponder {
7777    type ControlHandle = PrivilegedPeripheralControlHandle;
7778
7779    fn control_handle(&self) -> &PrivilegedPeripheralControlHandle {
7780        &self.control_handle
7781    }
7782
7783    fn drop_without_shutdown(mut self) {
7784        // Safety: drops once, never accessed again due to mem::forget
7785        unsafe { std::mem::ManuallyDrop::drop(&mut self.control_handle) };
7786        // Prevent Drop from running (which would shut down the channel)
7787        std::mem::forget(self);
7788    }
7789}
7790
7791impl PrivilegedPeripheralListenL2capResponder {
7792    /// Sends a response to the FIDL transaction.
7793    ///
7794    /// Sets the channel to shutdown if an error occurs.
7795    pub fn send(
7796        self,
7797        mut result: Result<&ChannelListenerRegistryListenL2capResponse, i32>,
7798    ) -> Result<(), fidl::Error> {
7799        let _result = self.send_raw(result);
7800        if _result.is_err() {
7801            self.control_handle.shutdown();
7802        }
7803        self.drop_without_shutdown();
7804        _result
7805    }
7806
7807    /// Similar to "send" but does not shutdown the channel if an error occurs.
7808    pub fn send_no_shutdown_on_err(
7809        self,
7810        mut result: Result<&ChannelListenerRegistryListenL2capResponse, i32>,
7811    ) -> Result<(), fidl::Error> {
7812        let _result = self.send_raw(result);
7813        self.drop_without_shutdown();
7814        _result
7815    }
7816
7817    fn send_raw(
7818        &self,
7819        mut result: Result<&ChannelListenerRegistryListenL2capResponse, i32>,
7820    ) -> Result<(), fidl::Error> {
7821        self.control_handle.inner.send::<fidl::encoding::ResultType<
7822            ChannelListenerRegistryListenL2capResponse,
7823            i32,
7824        >>(
7825            result,
7826            self.tx_id,
7827            0x39c6e9001d102338,
7828            fidl::encoding::DynamicFlags::empty(),
7829        )
7830    }
7831}
7832
7833#[must_use = "FIDL methods require a response to be sent"]
7834#[derive(Debug)]
7835pub struct PrivilegedPeripheralAdvertiseResponder {
7836    control_handle: std::mem::ManuallyDrop<PrivilegedPeripheralControlHandle>,
7837    tx_id: u32,
7838}
7839
7840/// Set the the channel to be shutdown (see [`PrivilegedPeripheralControlHandle::shutdown`])
7841/// if the responder is dropped without sending a response, so that the client
7842/// doesn't hang. To prevent this behavior, call `drop_without_shutdown`.
7843impl std::ops::Drop for PrivilegedPeripheralAdvertiseResponder {
7844    fn drop(&mut self) {
7845        self.control_handle.shutdown();
7846        // Safety: drops once, never accessed again
7847        unsafe { std::mem::ManuallyDrop::drop(&mut self.control_handle) };
7848    }
7849}
7850
7851impl fidl::endpoints::Responder for PrivilegedPeripheralAdvertiseResponder {
7852    type ControlHandle = PrivilegedPeripheralControlHandle;
7853
7854    fn control_handle(&self) -> &PrivilegedPeripheralControlHandle {
7855        &self.control_handle
7856    }
7857
7858    fn drop_without_shutdown(mut self) {
7859        // Safety: drops once, never accessed again due to mem::forget
7860        unsafe { std::mem::ManuallyDrop::drop(&mut self.control_handle) };
7861        // Prevent Drop from running (which would shut down the channel)
7862        std::mem::forget(self);
7863    }
7864}
7865
7866impl PrivilegedPeripheralAdvertiseResponder {
7867    /// Sends a response to the FIDL transaction.
7868    ///
7869    /// Sets the channel to shutdown if an error occurs.
7870    pub fn send(self, mut result: Result<(), PeripheralError>) -> Result<(), fidl::Error> {
7871        let _result = self.send_raw(result);
7872        if _result.is_err() {
7873            self.control_handle.shutdown();
7874        }
7875        self.drop_without_shutdown();
7876        _result
7877    }
7878
7879    /// Similar to "send" but does not shutdown the channel if an error occurs.
7880    pub fn send_no_shutdown_on_err(
7881        self,
7882        mut result: Result<(), PeripheralError>,
7883    ) -> Result<(), fidl::Error> {
7884        let _result = self.send_raw(result);
7885        self.drop_without_shutdown();
7886        _result
7887    }
7888
7889    fn send_raw(&self, mut result: Result<(), PeripheralError>) -> Result<(), fidl::Error> {
7890        self.control_handle.inner.send::<fidl::encoding::ResultType<
7891            fidl::encoding::EmptyStruct,
7892            PeripheralError,
7893        >>(
7894            result,
7895            self.tx_id,
7896            0x2d9ec9260c32c17f,
7897            fidl::encoding::DynamicFlags::empty(),
7898        )
7899    }
7900}
7901
7902#[must_use = "FIDL methods require a response to be sent"]
7903#[derive(Debug)]
7904pub struct PrivilegedPeripheralStartAdvertisingResponder {
7905    control_handle: std::mem::ManuallyDrop<PrivilegedPeripheralControlHandle>,
7906    tx_id: u32,
7907}
7908
7909/// Set the the channel to be shutdown (see [`PrivilegedPeripheralControlHandle::shutdown`])
7910/// if the responder is dropped without sending a response, so that the client
7911/// doesn't hang. To prevent this behavior, call `drop_without_shutdown`.
7912impl std::ops::Drop for PrivilegedPeripheralStartAdvertisingResponder {
7913    fn drop(&mut self) {
7914        self.control_handle.shutdown();
7915        // Safety: drops once, never accessed again
7916        unsafe { std::mem::ManuallyDrop::drop(&mut self.control_handle) };
7917    }
7918}
7919
7920impl fidl::endpoints::Responder for PrivilegedPeripheralStartAdvertisingResponder {
7921    type ControlHandle = PrivilegedPeripheralControlHandle;
7922
7923    fn control_handle(&self) -> &PrivilegedPeripheralControlHandle {
7924        &self.control_handle
7925    }
7926
7927    fn drop_without_shutdown(mut self) {
7928        // Safety: drops once, never accessed again due to mem::forget
7929        unsafe { std::mem::ManuallyDrop::drop(&mut self.control_handle) };
7930        // Prevent Drop from running (which would shut down the channel)
7931        std::mem::forget(self);
7932    }
7933}
7934
7935impl PrivilegedPeripheralStartAdvertisingResponder {
7936    /// Sends a response to the FIDL transaction.
7937    ///
7938    /// Sets the channel to shutdown if an error occurs.
7939    pub fn send(self, mut result: Result<(), PeripheralError>) -> Result<(), fidl::Error> {
7940        let _result = self.send_raw(result);
7941        if _result.is_err() {
7942            self.control_handle.shutdown();
7943        }
7944        self.drop_without_shutdown();
7945        _result
7946    }
7947
7948    /// Similar to "send" but does not shutdown the channel if an error occurs.
7949    pub fn send_no_shutdown_on_err(
7950        self,
7951        mut result: Result<(), PeripheralError>,
7952    ) -> Result<(), fidl::Error> {
7953        let _result = self.send_raw(result);
7954        self.drop_without_shutdown();
7955        _result
7956    }
7957
7958    fn send_raw(&self, mut result: Result<(), PeripheralError>) -> Result<(), fidl::Error> {
7959        self.control_handle.inner.send::<fidl::encoding::ResultType<
7960            fidl::encoding::EmptyStruct,
7961            PeripheralError,
7962        >>(
7963            result,
7964            self.tx_id,
7965            0x5875c1c575f00f7d,
7966            fidl::encoding::DynamicFlags::empty(),
7967        )
7968    }
7969}
7970
7971#[derive(Debug, Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Hash)]
7972pub struct ScanResultWatcherMarker;
7973
7974impl fidl::endpoints::ProtocolMarker for ScanResultWatcherMarker {
7975    type Proxy = ScanResultWatcherProxy;
7976    type RequestStream = ScanResultWatcherRequestStream;
7977    #[cfg(target_os = "fuchsia")]
7978    type SynchronousProxy = ScanResultWatcherSynchronousProxy;
7979
7980    const DEBUG_NAME: &'static str = "(anonymous) ScanResultWatcher";
7981}
7982
7983pub trait ScanResultWatcherProxyInterface: Send + Sync {
7984    type WatchResponseFut: std::future::Future<Output = Result<Vec<Peer>, fidl::Error>> + Send;
7985    fn r#watch(&self) -> Self::WatchResponseFut;
7986}
7987#[derive(Debug)]
7988#[cfg(target_os = "fuchsia")]
7989pub struct ScanResultWatcherSynchronousProxy {
7990    client: fidl::client::sync::Client,
7991}
7992
7993#[cfg(target_os = "fuchsia")]
7994impl fidl::endpoints::SynchronousProxy for ScanResultWatcherSynchronousProxy {
7995    type Proxy = ScanResultWatcherProxy;
7996    type Protocol = ScanResultWatcherMarker;
7997
7998    fn from_channel(inner: fidl::Channel) -> Self {
7999        Self::new(inner)
8000    }
8001
8002    fn into_channel(self) -> fidl::Channel {
8003        self.client.into_channel()
8004    }
8005
8006    fn as_channel(&self) -> &fidl::Channel {
8007        self.client.as_channel()
8008    }
8009}
8010
8011#[cfg(target_os = "fuchsia")]
8012impl ScanResultWatcherSynchronousProxy {
8013    pub fn new(channel: fidl::Channel) -> Self {
8014        let protocol_name =
8015            <ScanResultWatcherMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME;
8016        Self { client: fidl::client::sync::Client::new(channel, protocol_name) }
8017    }
8018
8019    pub fn into_channel(self) -> fidl::Channel {
8020        self.client.into_channel()
8021    }
8022
8023    /// Waits until an event arrives and returns it. It is safe for other
8024    /// threads to make concurrent requests while waiting for an event.
8025    pub fn wait_for_event(
8026        &self,
8027        deadline: zx::MonotonicInstant,
8028    ) -> Result<ScanResultWatcherEvent, fidl::Error> {
8029        ScanResultWatcherEvent::decode(self.client.wait_for_event(deadline)?)
8030    }
8031
8032    /// Returns a list of all LE peers that satisfy the filters indicated in
8033    /// `ScanOptions`. The first response(s) will return matching discovered
8034    /// peers immediately. Subsequent calls receive a response only when peers
8035    /// have been scanned or updated since the last call. If a second call to
8036    /// `Watch` is erronously sent while one call is already pending, the scan
8037    /// will be canceled and the protocol will be closed.
8038    ///
8039    /// - response `updated` Peers that were added or updated since the last
8040    ///   call to Watch().
8041    pub fn r#watch(&self, ___deadline: zx::MonotonicInstant) -> Result<Vec<Peer>, fidl::Error> {
8042        let _response = self
8043            .client
8044            .send_query::<fidl::encoding::EmptyPayload, ScanResultWatcherWatchResponse>(
8045                (),
8046                0x713a122e949f301a,
8047                fidl::encoding::DynamicFlags::empty(),
8048                ___deadline,
8049            )?;
8050        Ok(_response.updated)
8051    }
8052}
8053
8054#[cfg(target_os = "fuchsia")]
8055impl From<ScanResultWatcherSynchronousProxy> for zx::Handle {
8056    fn from(value: ScanResultWatcherSynchronousProxy) -> Self {
8057        value.into_channel().into()
8058    }
8059}
8060
8061#[cfg(target_os = "fuchsia")]
8062impl From<fidl::Channel> for ScanResultWatcherSynchronousProxy {
8063    fn from(value: fidl::Channel) -> Self {
8064        Self::new(value)
8065    }
8066}
8067
8068#[derive(Debug, Clone)]
8069pub struct ScanResultWatcherProxy {
8070    client: fidl::client::Client<fidl::encoding::DefaultFuchsiaResourceDialect>,
8071}
8072
8073impl fidl::endpoints::Proxy for ScanResultWatcherProxy {
8074    type Protocol = ScanResultWatcherMarker;
8075
8076    fn from_channel(inner: ::fidl::AsyncChannel) -> Self {
8077        Self::new(inner)
8078    }
8079
8080    fn into_channel(self) -> Result<::fidl::AsyncChannel, Self> {
8081        self.client.into_channel().map_err(|client| Self { client })
8082    }
8083
8084    fn as_channel(&self) -> &::fidl::AsyncChannel {
8085        self.client.as_channel()
8086    }
8087}
8088
8089impl ScanResultWatcherProxy {
8090    /// Create a new Proxy for fuchsia.bluetooth.le/ScanResultWatcher.
8091    pub fn new(channel: ::fidl::AsyncChannel) -> Self {
8092        let protocol_name =
8093            <ScanResultWatcherMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME;
8094        Self { client: fidl::client::Client::new(channel, protocol_name) }
8095    }
8096
8097    /// Get a Stream of events from the remote end of the protocol.
8098    ///
8099    /// # Panics
8100    ///
8101    /// Panics if the event stream was already taken.
8102    pub fn take_event_stream(&self) -> ScanResultWatcherEventStream {
8103        ScanResultWatcherEventStream { event_receiver: self.client.take_event_receiver() }
8104    }
8105
8106    /// Returns a list of all LE peers that satisfy the filters indicated in
8107    /// `ScanOptions`. The first response(s) will return matching discovered
8108    /// peers immediately. Subsequent calls receive a response only when peers
8109    /// have been scanned or updated since the last call. If a second call to
8110    /// `Watch` is erronously sent while one call is already pending, the scan
8111    /// will be canceled and the protocol will be closed.
8112    ///
8113    /// - response `updated` Peers that were added or updated since the last
8114    ///   call to Watch().
8115    pub fn r#watch(
8116        &self,
8117    ) -> fidl::client::QueryResponseFut<Vec<Peer>, fidl::encoding::DefaultFuchsiaResourceDialect>
8118    {
8119        ScanResultWatcherProxyInterface::r#watch(self)
8120    }
8121}
8122
8123impl ScanResultWatcherProxyInterface for ScanResultWatcherProxy {
8124    type WatchResponseFut =
8125        fidl::client::QueryResponseFut<Vec<Peer>, fidl::encoding::DefaultFuchsiaResourceDialect>;
8126    fn r#watch(&self) -> Self::WatchResponseFut {
8127        fn _decode(
8128            mut _buf: Result<<fidl::encoding::DefaultFuchsiaResourceDialect as fidl::encoding::ResourceDialect>::MessageBufEtc, fidl::Error>,
8129        ) -> Result<Vec<Peer>, fidl::Error> {
8130            let _response = fidl::client::decode_transaction_body::<
8131                ScanResultWatcherWatchResponse,
8132                fidl::encoding::DefaultFuchsiaResourceDialect,
8133                0x713a122e949f301a,
8134            >(_buf?)?;
8135            Ok(_response.updated)
8136        }
8137        self.client.send_query_and_decode::<fidl::encoding::EmptyPayload, Vec<Peer>>(
8138            (),
8139            0x713a122e949f301a,
8140            fidl::encoding::DynamicFlags::empty(),
8141            _decode,
8142        )
8143    }
8144}
8145
8146pub struct ScanResultWatcherEventStream {
8147    event_receiver: fidl::client::EventReceiver<fidl::encoding::DefaultFuchsiaResourceDialect>,
8148}
8149
8150impl std::marker::Unpin for ScanResultWatcherEventStream {}
8151
8152impl futures::stream::FusedStream for ScanResultWatcherEventStream {
8153    fn is_terminated(&self) -> bool {
8154        self.event_receiver.is_terminated()
8155    }
8156}
8157
8158impl futures::Stream for ScanResultWatcherEventStream {
8159    type Item = Result<ScanResultWatcherEvent, fidl::Error>;
8160
8161    fn poll_next(
8162        mut self: std::pin::Pin<&mut Self>,
8163        cx: &mut std::task::Context<'_>,
8164    ) -> std::task::Poll<Option<Self::Item>> {
8165        match futures::ready!(futures::stream::StreamExt::poll_next_unpin(
8166            &mut self.event_receiver,
8167            cx
8168        )?) {
8169            Some(buf) => std::task::Poll::Ready(Some(ScanResultWatcherEvent::decode(buf))),
8170            None => std::task::Poll::Ready(None),
8171        }
8172    }
8173}
8174
8175#[derive(Debug)]
8176pub enum ScanResultWatcherEvent {}
8177
8178impl ScanResultWatcherEvent {
8179    /// Decodes a message buffer as a [`ScanResultWatcherEvent`].
8180    fn decode(
8181        mut buf: <fidl::encoding::DefaultFuchsiaResourceDialect as fidl::encoding::ResourceDialect>::MessageBufEtc,
8182    ) -> Result<ScanResultWatcherEvent, fidl::Error> {
8183        let (bytes, _handles) = buf.split_mut();
8184        let (tx_header, _body_bytes) = fidl::encoding::decode_transaction_header(bytes)?;
8185        debug_assert_eq!(tx_header.tx_id, 0);
8186        match tx_header.ordinal {
8187            _ => Err(fidl::Error::UnknownOrdinal {
8188                ordinal: tx_header.ordinal,
8189                protocol_name:
8190                    <ScanResultWatcherMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME,
8191            }),
8192        }
8193    }
8194}
8195
8196/// A Stream of incoming requests for fuchsia.bluetooth.le/ScanResultWatcher.
8197pub struct ScanResultWatcherRequestStream {
8198    inner: std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>,
8199    is_terminated: bool,
8200}
8201
8202impl std::marker::Unpin for ScanResultWatcherRequestStream {}
8203
8204impl futures::stream::FusedStream for ScanResultWatcherRequestStream {
8205    fn is_terminated(&self) -> bool {
8206        self.is_terminated
8207    }
8208}
8209
8210impl fidl::endpoints::RequestStream for ScanResultWatcherRequestStream {
8211    type Protocol = ScanResultWatcherMarker;
8212    type ControlHandle = ScanResultWatcherControlHandle;
8213
8214    fn from_channel(channel: ::fidl::AsyncChannel) -> Self {
8215        Self { inner: std::sync::Arc::new(fidl::ServeInner::new(channel)), is_terminated: false }
8216    }
8217
8218    fn control_handle(&self) -> Self::ControlHandle {
8219        ScanResultWatcherControlHandle { inner: self.inner.clone() }
8220    }
8221
8222    fn into_inner(
8223        self,
8224    ) -> (::std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>, bool)
8225    {
8226        (self.inner, self.is_terminated)
8227    }
8228
8229    fn from_inner(
8230        inner: std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>,
8231        is_terminated: bool,
8232    ) -> Self {
8233        Self { inner, is_terminated }
8234    }
8235}
8236
8237impl futures::Stream for ScanResultWatcherRequestStream {
8238    type Item = Result<ScanResultWatcherRequest, fidl::Error>;
8239
8240    fn poll_next(
8241        mut self: std::pin::Pin<&mut Self>,
8242        cx: &mut std::task::Context<'_>,
8243    ) -> std::task::Poll<Option<Self::Item>> {
8244        let this = &mut *self;
8245        if this.inner.check_shutdown(cx) {
8246            this.is_terminated = true;
8247            return std::task::Poll::Ready(None);
8248        }
8249        if this.is_terminated {
8250            panic!("polled ScanResultWatcherRequestStream after completion");
8251        }
8252        fidl::encoding::with_tls_decode_buf::<_, fidl::encoding::DefaultFuchsiaResourceDialect>(
8253            |bytes, handles| {
8254                match this.inner.channel().read_etc(cx, bytes, handles) {
8255                    std::task::Poll::Ready(Ok(())) => {}
8256                    std::task::Poll::Pending => return std::task::Poll::Pending,
8257                    std::task::Poll::Ready(Err(zx_status::Status::PEER_CLOSED)) => {
8258                        this.is_terminated = true;
8259                        return std::task::Poll::Ready(None);
8260                    }
8261                    std::task::Poll::Ready(Err(e)) => {
8262                        return std::task::Poll::Ready(Some(Err(fidl::Error::ServerRequestRead(
8263                            e.into(),
8264                        ))))
8265                    }
8266                }
8267
8268                // A message has been received from the channel
8269                let (header, _body_bytes) = fidl::encoding::decode_transaction_header(bytes)?;
8270
8271                std::task::Poll::Ready(Some(match header.ordinal {
8272                    0x713a122e949f301a => {
8273                        header.validate_request_tx_id(fidl::MethodType::TwoWay)?;
8274                        let mut req = fidl::new_empty!(
8275                            fidl::encoding::EmptyPayload,
8276                            fidl::encoding::DefaultFuchsiaResourceDialect
8277                        );
8278                        fidl::encoding::Decoder::<fidl::encoding::DefaultFuchsiaResourceDialect>::decode_into::<fidl::encoding::EmptyPayload>(&header, _body_bytes, handles, &mut req)?;
8279                        let control_handle =
8280                            ScanResultWatcherControlHandle { inner: this.inner.clone() };
8281                        Ok(ScanResultWatcherRequest::Watch {
8282                            responder: ScanResultWatcherWatchResponder {
8283                                control_handle: std::mem::ManuallyDrop::new(control_handle),
8284                                tx_id: header.tx_id,
8285                            },
8286                        })
8287                    }
8288                    _ => Err(fidl::Error::UnknownOrdinal {
8289                        ordinal: header.ordinal,
8290                        protocol_name:
8291                            <ScanResultWatcherMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME,
8292                    }),
8293                }))
8294            },
8295        )
8296    }
8297}
8298
8299/// Represents an active scan procedure. This protocol remains valid for the
8300/// duration of a scan and can be used to obtain scan results. The client can
8301/// close the protocol to stop scanning. If a scan is stopped by the system, the
8302/// protocol will be closed with the epitaph `CANCELED` to communicate this to
8303/// the client.
8304#[derive(Debug)]
8305pub enum ScanResultWatcherRequest {
8306    /// Returns a list of all LE peers that satisfy the filters indicated in
8307    /// `ScanOptions`. The first response(s) will return matching discovered
8308    /// peers immediately. Subsequent calls receive a response only when peers
8309    /// have been scanned or updated since the last call. If a second call to
8310    /// `Watch` is erronously sent while one call is already pending, the scan
8311    /// will be canceled and the protocol will be closed.
8312    ///
8313    /// - response `updated` Peers that were added or updated since the last
8314    ///   call to Watch().
8315    Watch { responder: ScanResultWatcherWatchResponder },
8316}
8317
8318impl ScanResultWatcherRequest {
8319    #[allow(irrefutable_let_patterns)]
8320    pub fn into_watch(self) -> Option<(ScanResultWatcherWatchResponder)> {
8321        if let ScanResultWatcherRequest::Watch { responder } = self {
8322            Some((responder))
8323        } else {
8324            None
8325        }
8326    }
8327
8328    /// Name of the method defined in FIDL
8329    pub fn method_name(&self) -> &'static str {
8330        match *self {
8331            ScanResultWatcherRequest::Watch { .. } => "watch",
8332        }
8333    }
8334}
8335
8336#[derive(Debug, Clone)]
8337pub struct ScanResultWatcherControlHandle {
8338    inner: std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>,
8339}
8340
8341impl fidl::endpoints::ControlHandle for ScanResultWatcherControlHandle {
8342    fn shutdown(&self) {
8343        self.inner.shutdown()
8344    }
8345    fn shutdown_with_epitaph(&self, status: zx_status::Status) {
8346        self.inner.shutdown_with_epitaph(status)
8347    }
8348
8349    fn is_closed(&self) -> bool {
8350        self.inner.channel().is_closed()
8351    }
8352    fn on_closed(&self) -> fidl::OnSignalsRef<'_> {
8353        self.inner.channel().on_closed()
8354    }
8355
8356    #[cfg(target_os = "fuchsia")]
8357    fn signal_peer(
8358        &self,
8359        clear_mask: zx::Signals,
8360        set_mask: zx::Signals,
8361    ) -> Result<(), zx_status::Status> {
8362        use fidl::Peered;
8363        self.inner.channel().signal_peer(clear_mask, set_mask)
8364    }
8365}
8366
8367impl ScanResultWatcherControlHandle {}
8368
8369#[must_use = "FIDL methods require a response to be sent"]
8370#[derive(Debug)]
8371pub struct ScanResultWatcherWatchResponder {
8372    control_handle: std::mem::ManuallyDrop<ScanResultWatcherControlHandle>,
8373    tx_id: u32,
8374}
8375
8376/// Set the the channel to be shutdown (see [`ScanResultWatcherControlHandle::shutdown`])
8377/// if the responder is dropped without sending a response, so that the client
8378/// doesn't hang. To prevent this behavior, call `drop_without_shutdown`.
8379impl std::ops::Drop for ScanResultWatcherWatchResponder {
8380    fn drop(&mut self) {
8381        self.control_handle.shutdown();
8382        // Safety: drops once, never accessed again
8383        unsafe { std::mem::ManuallyDrop::drop(&mut self.control_handle) };
8384    }
8385}
8386
8387impl fidl::endpoints::Responder for ScanResultWatcherWatchResponder {
8388    type ControlHandle = ScanResultWatcherControlHandle;
8389
8390    fn control_handle(&self) -> &ScanResultWatcherControlHandle {
8391        &self.control_handle
8392    }
8393
8394    fn drop_without_shutdown(mut self) {
8395        // Safety: drops once, never accessed again due to mem::forget
8396        unsafe { std::mem::ManuallyDrop::drop(&mut self.control_handle) };
8397        // Prevent Drop from running (which would shut down the channel)
8398        std::mem::forget(self);
8399    }
8400}
8401
8402impl ScanResultWatcherWatchResponder {
8403    /// Sends a response to the FIDL transaction.
8404    ///
8405    /// Sets the channel to shutdown if an error occurs.
8406    pub fn send(self, mut updated: &[Peer]) -> Result<(), fidl::Error> {
8407        let _result = self.send_raw(updated);
8408        if _result.is_err() {
8409            self.control_handle.shutdown();
8410        }
8411        self.drop_without_shutdown();
8412        _result
8413    }
8414
8415    /// Similar to "send" but does not shutdown the channel if an error occurs.
8416    pub fn send_no_shutdown_on_err(self, mut updated: &[Peer]) -> Result<(), fidl::Error> {
8417        let _result = self.send_raw(updated);
8418        self.drop_without_shutdown();
8419        _result
8420    }
8421
8422    fn send_raw(&self, mut updated: &[Peer]) -> Result<(), fidl::Error> {
8423        self.control_handle.inner.send::<ScanResultWatcherWatchResponse>(
8424            (updated,),
8425            self.tx_id,
8426            0x713a122e949f301a,
8427            fidl::encoding::DynamicFlags::empty(),
8428        )
8429    }
8430}
8431
8432mod internal {
8433    use super::*;
8434
8435    impl fidl::encoding::ResourceTypeMarker for AdvertisedPeripheralOnConnectedRequest {
8436        type Borrowed<'a> = &'a mut Self;
8437        fn take_or_borrow<'a>(
8438            value: &'a mut <Self as fidl::encoding::TypeMarker>::Owned,
8439        ) -> Self::Borrowed<'a> {
8440            value
8441        }
8442    }
8443
8444    unsafe impl fidl::encoding::TypeMarker for AdvertisedPeripheralOnConnectedRequest {
8445        type Owned = Self;
8446
8447        #[inline(always)]
8448        fn inline_align(_context: fidl::encoding::Context) -> usize {
8449            8
8450        }
8451
8452        #[inline(always)]
8453        fn inline_size(_context: fidl::encoding::Context) -> usize {
8454            24
8455        }
8456    }
8457
8458    unsafe impl
8459        fidl::encoding::Encode<
8460            AdvertisedPeripheralOnConnectedRequest,
8461            fidl::encoding::DefaultFuchsiaResourceDialect,
8462        > for &mut AdvertisedPeripheralOnConnectedRequest
8463    {
8464        #[inline]
8465        unsafe fn encode(
8466            self,
8467            encoder: &mut fidl::encoding::Encoder<
8468                '_,
8469                fidl::encoding::DefaultFuchsiaResourceDialect,
8470            >,
8471            offset: usize,
8472            _depth: fidl::encoding::Depth,
8473        ) -> fidl::Result<()> {
8474            encoder.debug_check_bounds::<AdvertisedPeripheralOnConnectedRequest>(offset);
8475            // Delegate to tuple encoding.
8476            fidl::encoding::Encode::<AdvertisedPeripheralOnConnectedRequest, fidl::encoding::DefaultFuchsiaResourceDialect>::encode(
8477                (
8478                    <Peer as fidl::encoding::ValueTypeMarker>::borrow(&self.peer),
8479                    <fidl::encoding::Endpoint<fidl::endpoints::ClientEnd<ConnectionMarker>> as fidl::encoding::ResourceTypeMarker>::take_or_borrow(&mut self.connection),
8480                ),
8481                encoder, offset, _depth
8482            )
8483        }
8484    }
8485    unsafe impl<
8486            T0: fidl::encoding::Encode<Peer, fidl::encoding::DefaultFuchsiaResourceDialect>,
8487            T1: fidl::encoding::Encode<
8488                fidl::encoding::Endpoint<fidl::endpoints::ClientEnd<ConnectionMarker>>,
8489                fidl::encoding::DefaultFuchsiaResourceDialect,
8490            >,
8491        >
8492        fidl::encoding::Encode<
8493            AdvertisedPeripheralOnConnectedRequest,
8494            fidl::encoding::DefaultFuchsiaResourceDialect,
8495        > for (T0, T1)
8496    {
8497        #[inline]
8498        unsafe fn encode(
8499            self,
8500            encoder: &mut fidl::encoding::Encoder<
8501                '_,
8502                fidl::encoding::DefaultFuchsiaResourceDialect,
8503            >,
8504            offset: usize,
8505            depth: fidl::encoding::Depth,
8506        ) -> fidl::Result<()> {
8507            encoder.debug_check_bounds::<AdvertisedPeripheralOnConnectedRequest>(offset);
8508            // Zero out padding regions. There's no need to apply masks
8509            // because the unmasked parts will be overwritten by fields.
8510            unsafe {
8511                let ptr = encoder.buf.as_mut_ptr().add(offset).offset(16);
8512                (ptr as *mut u64).write_unaligned(0);
8513            }
8514            // Write the fields.
8515            self.0.encode(encoder, offset + 0, depth)?;
8516            self.1.encode(encoder, offset + 16, depth)?;
8517            Ok(())
8518        }
8519    }
8520
8521    impl fidl::encoding::Decode<Self, fidl::encoding::DefaultFuchsiaResourceDialect>
8522        for AdvertisedPeripheralOnConnectedRequest
8523    {
8524        #[inline(always)]
8525        fn new_empty() -> Self {
8526            Self {
8527                peer: fidl::new_empty!(Peer, fidl::encoding::DefaultFuchsiaResourceDialect),
8528                connection: fidl::new_empty!(
8529                    fidl::encoding::Endpoint<fidl::endpoints::ClientEnd<ConnectionMarker>>,
8530                    fidl::encoding::DefaultFuchsiaResourceDialect
8531                ),
8532            }
8533        }
8534
8535        #[inline]
8536        unsafe fn decode(
8537            &mut self,
8538            decoder: &mut fidl::encoding::Decoder<
8539                '_,
8540                fidl::encoding::DefaultFuchsiaResourceDialect,
8541            >,
8542            offset: usize,
8543            _depth: fidl::encoding::Depth,
8544        ) -> fidl::Result<()> {
8545            decoder.debug_check_bounds::<Self>(offset);
8546            // Verify that padding bytes are zero.
8547            let ptr = unsafe { decoder.buf.as_ptr().add(offset).offset(16) };
8548            let padval = unsafe { (ptr as *const u64).read_unaligned() };
8549            let mask = 0xffffffff00000000u64;
8550            let maskedval = padval & mask;
8551            if maskedval != 0 {
8552                return Err(fidl::Error::NonZeroPadding {
8553                    padding_start: offset + 16 + ((mask as u64).trailing_zeros() / 8) as usize,
8554                });
8555            }
8556            fidl::decode!(
8557                Peer,
8558                fidl::encoding::DefaultFuchsiaResourceDialect,
8559                &mut self.peer,
8560                decoder,
8561                offset + 0,
8562                _depth
8563            )?;
8564            fidl::decode!(
8565                fidl::encoding::Endpoint<fidl::endpoints::ClientEnd<ConnectionMarker>>,
8566                fidl::encoding::DefaultFuchsiaResourceDialect,
8567                &mut self.connection,
8568                decoder,
8569                offset + 16,
8570                _depth
8571            )?;
8572            Ok(())
8573        }
8574    }
8575
8576    impl fidl::encoding::ResourceTypeMarker for CentralConnectPeripheralRequest {
8577        type Borrowed<'a> = &'a mut Self;
8578        fn take_or_borrow<'a>(
8579            value: &'a mut <Self as fidl::encoding::TypeMarker>::Owned,
8580        ) -> Self::Borrowed<'a> {
8581            value
8582        }
8583    }
8584
8585    unsafe impl fidl::encoding::TypeMarker for CentralConnectPeripheralRequest {
8586        type Owned = Self;
8587
8588        #[inline(always)]
8589        fn inline_align(_context: fidl::encoding::Context) -> usize {
8590            8
8591        }
8592
8593        #[inline(always)]
8594        fn inline_size(_context: fidl::encoding::Context) -> usize {
8595            40
8596        }
8597    }
8598
8599    unsafe impl
8600        fidl::encoding::Encode<
8601            CentralConnectPeripheralRequest,
8602            fidl::encoding::DefaultFuchsiaResourceDialect,
8603        > for &mut CentralConnectPeripheralRequest
8604    {
8605        #[inline]
8606        unsafe fn encode(
8607            self,
8608            encoder: &mut fidl::encoding::Encoder<
8609                '_,
8610                fidl::encoding::DefaultFuchsiaResourceDialect,
8611            >,
8612            offset: usize,
8613            _depth: fidl::encoding::Depth,
8614        ) -> fidl::Result<()> {
8615            encoder.debug_check_bounds::<CentralConnectPeripheralRequest>(offset);
8616            // Delegate to tuple encoding.
8617            fidl::encoding::Encode::<
8618                CentralConnectPeripheralRequest,
8619                fidl::encoding::DefaultFuchsiaResourceDialect,
8620            >::encode(
8621                (
8622                    <fidl::encoding::BoundedString<16> as fidl::encoding::ValueTypeMarker>::borrow(
8623                        &self.identifier,
8624                    ),
8625                    <ConnectionOptions as fidl::encoding::ValueTypeMarker>::borrow(&self.options),
8626                    <fidl::encoding::Endpoint<
8627                        fidl::endpoints::ServerEnd<fidl_fuchsia_bluetooth_gatt::ClientMarker>,
8628                    > as fidl::encoding::ResourceTypeMarker>::take_or_borrow(
8629                        &mut self.gatt_client
8630                    ),
8631                ),
8632                encoder,
8633                offset,
8634                _depth,
8635            )
8636        }
8637    }
8638    unsafe impl<
8639            T0: fidl::encoding::Encode<
8640                fidl::encoding::BoundedString<16>,
8641                fidl::encoding::DefaultFuchsiaResourceDialect,
8642            >,
8643            T1: fidl::encoding::Encode<
8644                ConnectionOptions,
8645                fidl::encoding::DefaultFuchsiaResourceDialect,
8646            >,
8647            T2: fidl::encoding::Encode<
8648                fidl::encoding::Endpoint<
8649                    fidl::endpoints::ServerEnd<fidl_fuchsia_bluetooth_gatt::ClientMarker>,
8650                >,
8651                fidl::encoding::DefaultFuchsiaResourceDialect,
8652            >,
8653        >
8654        fidl::encoding::Encode<
8655            CentralConnectPeripheralRequest,
8656            fidl::encoding::DefaultFuchsiaResourceDialect,
8657        > for (T0, T1, T2)
8658    {
8659        #[inline]
8660        unsafe fn encode(
8661            self,
8662            encoder: &mut fidl::encoding::Encoder<
8663                '_,
8664                fidl::encoding::DefaultFuchsiaResourceDialect,
8665            >,
8666            offset: usize,
8667            depth: fidl::encoding::Depth,
8668        ) -> fidl::Result<()> {
8669            encoder.debug_check_bounds::<CentralConnectPeripheralRequest>(offset);
8670            // Zero out padding regions. There's no need to apply masks
8671            // because the unmasked parts will be overwritten by fields.
8672            unsafe {
8673                let ptr = encoder.buf.as_mut_ptr().add(offset).offset(32);
8674                (ptr as *mut u64).write_unaligned(0);
8675            }
8676            // Write the fields.
8677            self.0.encode(encoder, offset + 0, depth)?;
8678            self.1.encode(encoder, offset + 16, depth)?;
8679            self.2.encode(encoder, offset + 32, depth)?;
8680            Ok(())
8681        }
8682    }
8683
8684    impl fidl::encoding::Decode<Self, fidl::encoding::DefaultFuchsiaResourceDialect>
8685        for CentralConnectPeripheralRequest
8686    {
8687        #[inline(always)]
8688        fn new_empty() -> Self {
8689            Self {
8690                identifier: fidl::new_empty!(
8691                    fidl::encoding::BoundedString<16>,
8692                    fidl::encoding::DefaultFuchsiaResourceDialect
8693                ),
8694                options: fidl::new_empty!(
8695                    ConnectionOptions,
8696                    fidl::encoding::DefaultFuchsiaResourceDialect
8697                ),
8698                gatt_client: fidl::new_empty!(
8699                    fidl::encoding::Endpoint<
8700                        fidl::endpoints::ServerEnd<fidl_fuchsia_bluetooth_gatt::ClientMarker>,
8701                    >,
8702                    fidl::encoding::DefaultFuchsiaResourceDialect
8703                ),
8704            }
8705        }
8706
8707        #[inline]
8708        unsafe fn decode(
8709            &mut self,
8710            decoder: &mut fidl::encoding::Decoder<
8711                '_,
8712                fidl::encoding::DefaultFuchsiaResourceDialect,
8713            >,
8714            offset: usize,
8715            _depth: fidl::encoding::Depth,
8716        ) -> fidl::Result<()> {
8717            decoder.debug_check_bounds::<Self>(offset);
8718            // Verify that padding bytes are zero.
8719            let ptr = unsafe { decoder.buf.as_ptr().add(offset).offset(32) };
8720            let padval = unsafe { (ptr as *const u64).read_unaligned() };
8721            let mask = 0xffffffff00000000u64;
8722            let maskedval = padval & mask;
8723            if maskedval != 0 {
8724                return Err(fidl::Error::NonZeroPadding {
8725                    padding_start: offset + 32 + ((mask as u64).trailing_zeros() / 8) as usize,
8726                });
8727            }
8728            fidl::decode!(
8729                fidl::encoding::BoundedString<16>,
8730                fidl::encoding::DefaultFuchsiaResourceDialect,
8731                &mut self.identifier,
8732                decoder,
8733                offset + 0,
8734                _depth
8735            )?;
8736            fidl::decode!(
8737                ConnectionOptions,
8738                fidl::encoding::DefaultFuchsiaResourceDialect,
8739                &mut self.options,
8740                decoder,
8741                offset + 16,
8742                _depth
8743            )?;
8744            fidl::decode!(
8745                fidl::encoding::Endpoint<
8746                    fidl::endpoints::ServerEnd<fidl_fuchsia_bluetooth_gatt::ClientMarker>,
8747                >,
8748                fidl::encoding::DefaultFuchsiaResourceDialect,
8749                &mut self.gatt_client,
8750                decoder,
8751                offset + 32,
8752                _depth
8753            )?;
8754            Ok(())
8755        }
8756    }
8757
8758    impl fidl::encoding::ResourceTypeMarker for CentralConnectRequest {
8759        type Borrowed<'a> = &'a mut Self;
8760        fn take_or_borrow<'a>(
8761            value: &'a mut <Self as fidl::encoding::TypeMarker>::Owned,
8762        ) -> Self::Borrowed<'a> {
8763            value
8764        }
8765    }
8766
8767    unsafe impl fidl::encoding::TypeMarker for CentralConnectRequest {
8768        type Owned = Self;
8769
8770        #[inline(always)]
8771        fn inline_align(_context: fidl::encoding::Context) -> usize {
8772            8
8773        }
8774
8775        #[inline(always)]
8776        fn inline_size(_context: fidl::encoding::Context) -> usize {
8777            32
8778        }
8779    }
8780
8781    unsafe impl
8782        fidl::encoding::Encode<CentralConnectRequest, fidl::encoding::DefaultFuchsiaResourceDialect>
8783        for &mut CentralConnectRequest
8784    {
8785        #[inline]
8786        unsafe fn encode(
8787            self,
8788            encoder: &mut fidl::encoding::Encoder<
8789                '_,
8790                fidl::encoding::DefaultFuchsiaResourceDialect,
8791            >,
8792            offset: usize,
8793            _depth: fidl::encoding::Depth,
8794        ) -> fidl::Result<()> {
8795            encoder.debug_check_bounds::<CentralConnectRequest>(offset);
8796            // Delegate to tuple encoding.
8797            fidl::encoding::Encode::<CentralConnectRequest, fidl::encoding::DefaultFuchsiaResourceDialect>::encode(
8798                (
8799                    <fidl_fuchsia_bluetooth::PeerId as fidl::encoding::ValueTypeMarker>::borrow(&self.id),
8800                    <ConnectionOptions as fidl::encoding::ValueTypeMarker>::borrow(&self.options),
8801                    <fidl::encoding::Endpoint<fidl::endpoints::ServerEnd<ConnectionMarker>> as fidl::encoding::ResourceTypeMarker>::take_or_borrow(&mut self.handle),
8802                ),
8803                encoder, offset, _depth
8804            )
8805        }
8806    }
8807    unsafe impl<
8808            T0: fidl::encoding::Encode<
8809                fidl_fuchsia_bluetooth::PeerId,
8810                fidl::encoding::DefaultFuchsiaResourceDialect,
8811            >,
8812            T1: fidl::encoding::Encode<
8813                ConnectionOptions,
8814                fidl::encoding::DefaultFuchsiaResourceDialect,
8815            >,
8816            T2: fidl::encoding::Encode<
8817                fidl::encoding::Endpoint<fidl::endpoints::ServerEnd<ConnectionMarker>>,
8818                fidl::encoding::DefaultFuchsiaResourceDialect,
8819            >,
8820        >
8821        fidl::encoding::Encode<CentralConnectRequest, fidl::encoding::DefaultFuchsiaResourceDialect>
8822        for (T0, T1, T2)
8823    {
8824        #[inline]
8825        unsafe fn encode(
8826            self,
8827            encoder: &mut fidl::encoding::Encoder<
8828                '_,
8829                fidl::encoding::DefaultFuchsiaResourceDialect,
8830            >,
8831            offset: usize,
8832            depth: fidl::encoding::Depth,
8833        ) -> fidl::Result<()> {
8834            encoder.debug_check_bounds::<CentralConnectRequest>(offset);
8835            // Zero out padding regions. There's no need to apply masks
8836            // because the unmasked parts will be overwritten by fields.
8837            unsafe {
8838                let ptr = encoder.buf.as_mut_ptr().add(offset).offset(24);
8839                (ptr as *mut u64).write_unaligned(0);
8840            }
8841            // Write the fields.
8842            self.0.encode(encoder, offset + 0, depth)?;
8843            self.1.encode(encoder, offset + 8, depth)?;
8844            self.2.encode(encoder, offset + 24, depth)?;
8845            Ok(())
8846        }
8847    }
8848
8849    impl fidl::encoding::Decode<Self, fidl::encoding::DefaultFuchsiaResourceDialect>
8850        for CentralConnectRequest
8851    {
8852        #[inline(always)]
8853        fn new_empty() -> Self {
8854            Self {
8855                id: fidl::new_empty!(
8856                    fidl_fuchsia_bluetooth::PeerId,
8857                    fidl::encoding::DefaultFuchsiaResourceDialect
8858                ),
8859                options: fidl::new_empty!(
8860                    ConnectionOptions,
8861                    fidl::encoding::DefaultFuchsiaResourceDialect
8862                ),
8863                handle: fidl::new_empty!(
8864                    fidl::encoding::Endpoint<fidl::endpoints::ServerEnd<ConnectionMarker>>,
8865                    fidl::encoding::DefaultFuchsiaResourceDialect
8866                ),
8867            }
8868        }
8869
8870        #[inline]
8871        unsafe fn decode(
8872            &mut self,
8873            decoder: &mut fidl::encoding::Decoder<
8874                '_,
8875                fidl::encoding::DefaultFuchsiaResourceDialect,
8876            >,
8877            offset: usize,
8878            _depth: fidl::encoding::Depth,
8879        ) -> fidl::Result<()> {
8880            decoder.debug_check_bounds::<Self>(offset);
8881            // Verify that padding bytes are zero.
8882            let ptr = unsafe { decoder.buf.as_ptr().add(offset).offset(24) };
8883            let padval = unsafe { (ptr as *const u64).read_unaligned() };
8884            let mask = 0xffffffff00000000u64;
8885            let maskedval = padval & mask;
8886            if maskedval != 0 {
8887                return Err(fidl::Error::NonZeroPadding {
8888                    padding_start: offset + 24 + ((mask as u64).trailing_zeros() / 8) as usize,
8889                });
8890            }
8891            fidl::decode!(
8892                fidl_fuchsia_bluetooth::PeerId,
8893                fidl::encoding::DefaultFuchsiaResourceDialect,
8894                &mut self.id,
8895                decoder,
8896                offset + 0,
8897                _depth
8898            )?;
8899            fidl::decode!(
8900                ConnectionOptions,
8901                fidl::encoding::DefaultFuchsiaResourceDialect,
8902                &mut self.options,
8903                decoder,
8904                offset + 8,
8905                _depth
8906            )?;
8907            fidl::decode!(
8908                fidl::encoding::Endpoint<fidl::endpoints::ServerEnd<ConnectionMarker>>,
8909                fidl::encoding::DefaultFuchsiaResourceDialect,
8910                &mut self.handle,
8911                decoder,
8912                offset + 24,
8913                _depth
8914            )?;
8915            Ok(())
8916        }
8917    }
8918
8919    impl fidl::encoding::ResourceTypeMarker for CentralScanRequest {
8920        type Borrowed<'a> = &'a mut Self;
8921        fn take_or_borrow<'a>(
8922            value: &'a mut <Self as fidl::encoding::TypeMarker>::Owned,
8923        ) -> Self::Borrowed<'a> {
8924            value
8925        }
8926    }
8927
8928    unsafe impl fidl::encoding::TypeMarker for CentralScanRequest {
8929        type Owned = Self;
8930
8931        #[inline(always)]
8932        fn inline_align(_context: fidl::encoding::Context) -> usize {
8933            8
8934        }
8935
8936        #[inline(always)]
8937        fn inline_size(_context: fidl::encoding::Context) -> usize {
8938            24
8939        }
8940    }
8941
8942    unsafe impl
8943        fidl::encoding::Encode<CentralScanRequest, fidl::encoding::DefaultFuchsiaResourceDialect>
8944        for &mut CentralScanRequest
8945    {
8946        #[inline]
8947        unsafe fn encode(
8948            self,
8949            encoder: &mut fidl::encoding::Encoder<
8950                '_,
8951                fidl::encoding::DefaultFuchsiaResourceDialect,
8952            >,
8953            offset: usize,
8954            _depth: fidl::encoding::Depth,
8955        ) -> fidl::Result<()> {
8956            encoder.debug_check_bounds::<CentralScanRequest>(offset);
8957            // Delegate to tuple encoding.
8958            fidl::encoding::Encode::<CentralScanRequest, fidl::encoding::DefaultFuchsiaResourceDialect>::encode(
8959                (
8960                    <ScanOptions as fidl::encoding::ValueTypeMarker>::borrow(&self.options),
8961                    <fidl::encoding::Endpoint<fidl::endpoints::ServerEnd<ScanResultWatcherMarker>> as fidl::encoding::ResourceTypeMarker>::take_or_borrow(&mut self.result_watcher),
8962                ),
8963                encoder, offset, _depth
8964            )
8965        }
8966    }
8967    unsafe impl<
8968            T0: fidl::encoding::Encode<ScanOptions, fidl::encoding::DefaultFuchsiaResourceDialect>,
8969            T1: fidl::encoding::Encode<
8970                fidl::encoding::Endpoint<fidl::endpoints::ServerEnd<ScanResultWatcherMarker>>,
8971                fidl::encoding::DefaultFuchsiaResourceDialect,
8972            >,
8973        >
8974        fidl::encoding::Encode<CentralScanRequest, fidl::encoding::DefaultFuchsiaResourceDialect>
8975        for (T0, T1)
8976    {
8977        #[inline]
8978        unsafe fn encode(
8979            self,
8980            encoder: &mut fidl::encoding::Encoder<
8981                '_,
8982                fidl::encoding::DefaultFuchsiaResourceDialect,
8983            >,
8984            offset: usize,
8985            depth: fidl::encoding::Depth,
8986        ) -> fidl::Result<()> {
8987            encoder.debug_check_bounds::<CentralScanRequest>(offset);
8988            // Zero out padding regions. There's no need to apply masks
8989            // because the unmasked parts will be overwritten by fields.
8990            unsafe {
8991                let ptr = encoder.buf.as_mut_ptr().add(offset).offset(16);
8992                (ptr as *mut u64).write_unaligned(0);
8993            }
8994            // Write the fields.
8995            self.0.encode(encoder, offset + 0, depth)?;
8996            self.1.encode(encoder, offset + 16, depth)?;
8997            Ok(())
8998        }
8999    }
9000
9001    impl fidl::encoding::Decode<Self, fidl::encoding::DefaultFuchsiaResourceDialect>
9002        for CentralScanRequest
9003    {
9004        #[inline(always)]
9005        fn new_empty() -> Self {
9006            Self {
9007                options: fidl::new_empty!(
9008                    ScanOptions,
9009                    fidl::encoding::DefaultFuchsiaResourceDialect
9010                ),
9011                result_watcher: fidl::new_empty!(
9012                    fidl::encoding::Endpoint<fidl::endpoints::ServerEnd<ScanResultWatcherMarker>>,
9013                    fidl::encoding::DefaultFuchsiaResourceDialect
9014                ),
9015            }
9016        }
9017
9018        #[inline]
9019        unsafe fn decode(
9020            &mut self,
9021            decoder: &mut fidl::encoding::Decoder<
9022                '_,
9023                fidl::encoding::DefaultFuchsiaResourceDialect,
9024            >,
9025            offset: usize,
9026            _depth: fidl::encoding::Depth,
9027        ) -> fidl::Result<()> {
9028            decoder.debug_check_bounds::<Self>(offset);
9029            // Verify that padding bytes are zero.
9030            let ptr = unsafe { decoder.buf.as_ptr().add(offset).offset(16) };
9031            let padval = unsafe { (ptr as *const u64).read_unaligned() };
9032            let mask = 0xffffffff00000000u64;
9033            let maskedval = padval & mask;
9034            if maskedval != 0 {
9035                return Err(fidl::Error::NonZeroPadding {
9036                    padding_start: offset + 16 + ((mask as u64).trailing_zeros() / 8) as usize,
9037                });
9038            }
9039            fidl::decode!(
9040                ScanOptions,
9041                fidl::encoding::DefaultFuchsiaResourceDialect,
9042                &mut self.options,
9043                decoder,
9044                offset + 0,
9045                _depth
9046            )?;
9047            fidl::decode!(
9048                fidl::encoding::Endpoint<fidl::endpoints::ServerEnd<ScanResultWatcherMarker>>,
9049                fidl::encoding::DefaultFuchsiaResourceDialect,
9050                &mut self.result_watcher,
9051                decoder,
9052                offset + 16,
9053                _depth
9054            )?;
9055            Ok(())
9056        }
9057    }
9058
9059    impl fidl::encoding::ResourceTypeMarker for ChannelListenerAcceptRequest {
9060        type Borrowed<'a> = &'a mut Self;
9061        fn take_or_borrow<'a>(
9062            value: &'a mut <Self as fidl::encoding::TypeMarker>::Owned,
9063        ) -> Self::Borrowed<'a> {
9064            value
9065        }
9066    }
9067
9068    unsafe impl fidl::encoding::TypeMarker for ChannelListenerAcceptRequest {
9069        type Owned = Self;
9070
9071        #[inline(always)]
9072        fn inline_align(_context: fidl::encoding::Context) -> usize {
9073            4
9074        }
9075
9076        #[inline(always)]
9077        fn inline_size(_context: fidl::encoding::Context) -> usize {
9078            4
9079        }
9080    }
9081
9082    unsafe impl
9083        fidl::encoding::Encode<
9084            ChannelListenerAcceptRequest,
9085            fidl::encoding::DefaultFuchsiaResourceDialect,
9086        > for &mut ChannelListenerAcceptRequest
9087    {
9088        #[inline]
9089        unsafe fn encode(
9090            self,
9091            encoder: &mut fidl::encoding::Encoder<
9092                '_,
9093                fidl::encoding::DefaultFuchsiaResourceDialect,
9094            >,
9095            offset: usize,
9096            _depth: fidl::encoding::Depth,
9097        ) -> fidl::Result<()> {
9098            encoder.debug_check_bounds::<ChannelListenerAcceptRequest>(offset);
9099            // Delegate to tuple encoding.
9100            fidl::encoding::Encode::<
9101                ChannelListenerAcceptRequest,
9102                fidl::encoding::DefaultFuchsiaResourceDialect,
9103            >::encode(
9104                (<fidl::encoding::Endpoint<
9105                    fidl::endpoints::ClientEnd<fidl_fuchsia_bluetooth::ChannelMarker>,
9106                > as fidl::encoding::ResourceTypeMarker>::take_or_borrow(
9107                    &mut self.channel
9108                ),),
9109                encoder,
9110                offset,
9111                _depth,
9112            )
9113        }
9114    }
9115    unsafe impl<
9116            T0: fidl::encoding::Encode<
9117                fidl::encoding::Endpoint<
9118                    fidl::endpoints::ClientEnd<fidl_fuchsia_bluetooth::ChannelMarker>,
9119                >,
9120                fidl::encoding::DefaultFuchsiaResourceDialect,
9121            >,
9122        >
9123        fidl::encoding::Encode<
9124            ChannelListenerAcceptRequest,
9125            fidl::encoding::DefaultFuchsiaResourceDialect,
9126        > for (T0,)
9127    {
9128        #[inline]
9129        unsafe fn encode(
9130            self,
9131            encoder: &mut fidl::encoding::Encoder<
9132                '_,
9133                fidl::encoding::DefaultFuchsiaResourceDialect,
9134            >,
9135            offset: usize,
9136            depth: fidl::encoding::Depth,
9137        ) -> fidl::Result<()> {
9138            encoder.debug_check_bounds::<ChannelListenerAcceptRequest>(offset);
9139            // Zero out padding regions. There's no need to apply masks
9140            // because the unmasked parts will be overwritten by fields.
9141            // Write the fields.
9142            self.0.encode(encoder, offset + 0, depth)?;
9143            Ok(())
9144        }
9145    }
9146
9147    impl fidl::encoding::Decode<Self, fidl::encoding::DefaultFuchsiaResourceDialect>
9148        for ChannelListenerAcceptRequest
9149    {
9150        #[inline(always)]
9151        fn new_empty() -> Self {
9152            Self {
9153                channel: fidl::new_empty!(
9154                    fidl::encoding::Endpoint<
9155                        fidl::endpoints::ClientEnd<fidl_fuchsia_bluetooth::ChannelMarker>,
9156                    >,
9157                    fidl::encoding::DefaultFuchsiaResourceDialect
9158                ),
9159            }
9160        }
9161
9162        #[inline]
9163        unsafe fn decode(
9164            &mut self,
9165            decoder: &mut fidl::encoding::Decoder<
9166                '_,
9167                fidl::encoding::DefaultFuchsiaResourceDialect,
9168            >,
9169            offset: usize,
9170            _depth: fidl::encoding::Depth,
9171        ) -> fidl::Result<()> {
9172            decoder.debug_check_bounds::<Self>(offset);
9173            // Verify that padding bytes are zero.
9174            fidl::decode!(
9175                fidl::encoding::Endpoint<
9176                    fidl::endpoints::ClientEnd<fidl_fuchsia_bluetooth::ChannelMarker>,
9177                >,
9178                fidl::encoding::DefaultFuchsiaResourceDialect,
9179                &mut self.channel,
9180                decoder,
9181                offset + 0,
9182                _depth
9183            )?;
9184            Ok(())
9185        }
9186    }
9187
9188    impl fidl::encoding::ResourceTypeMarker for ConnectionRequestGattClientRequest {
9189        type Borrowed<'a> = &'a mut Self;
9190        fn take_or_borrow<'a>(
9191            value: &'a mut <Self as fidl::encoding::TypeMarker>::Owned,
9192        ) -> Self::Borrowed<'a> {
9193            value
9194        }
9195    }
9196
9197    unsafe impl fidl::encoding::TypeMarker for ConnectionRequestGattClientRequest {
9198        type Owned = Self;
9199
9200        #[inline(always)]
9201        fn inline_align(_context: fidl::encoding::Context) -> usize {
9202            4
9203        }
9204
9205        #[inline(always)]
9206        fn inline_size(_context: fidl::encoding::Context) -> usize {
9207            4
9208        }
9209    }
9210
9211    unsafe impl
9212        fidl::encoding::Encode<
9213            ConnectionRequestGattClientRequest,
9214            fidl::encoding::DefaultFuchsiaResourceDialect,
9215        > for &mut ConnectionRequestGattClientRequest
9216    {
9217        #[inline]
9218        unsafe fn encode(
9219            self,
9220            encoder: &mut fidl::encoding::Encoder<
9221                '_,
9222                fidl::encoding::DefaultFuchsiaResourceDialect,
9223            >,
9224            offset: usize,
9225            _depth: fidl::encoding::Depth,
9226        ) -> fidl::Result<()> {
9227            encoder.debug_check_bounds::<ConnectionRequestGattClientRequest>(offset);
9228            // Delegate to tuple encoding.
9229            fidl::encoding::Encode::<
9230                ConnectionRequestGattClientRequest,
9231                fidl::encoding::DefaultFuchsiaResourceDialect,
9232            >::encode(
9233                (<fidl::encoding::Endpoint<
9234                    fidl::endpoints::ServerEnd<fidl_fuchsia_bluetooth_gatt2::ClientMarker>,
9235                > as fidl::encoding::ResourceTypeMarker>::take_or_borrow(
9236                    &mut self.client
9237                ),),
9238                encoder,
9239                offset,
9240                _depth,
9241            )
9242        }
9243    }
9244    unsafe impl<
9245            T0: fidl::encoding::Encode<
9246                fidl::encoding::Endpoint<
9247                    fidl::endpoints::ServerEnd<fidl_fuchsia_bluetooth_gatt2::ClientMarker>,
9248                >,
9249                fidl::encoding::DefaultFuchsiaResourceDialect,
9250            >,
9251        >
9252        fidl::encoding::Encode<
9253            ConnectionRequestGattClientRequest,
9254            fidl::encoding::DefaultFuchsiaResourceDialect,
9255        > for (T0,)
9256    {
9257        #[inline]
9258        unsafe fn encode(
9259            self,
9260            encoder: &mut fidl::encoding::Encoder<
9261                '_,
9262                fidl::encoding::DefaultFuchsiaResourceDialect,
9263            >,
9264            offset: usize,
9265            depth: fidl::encoding::Depth,
9266        ) -> fidl::Result<()> {
9267            encoder.debug_check_bounds::<ConnectionRequestGattClientRequest>(offset);
9268            // Zero out padding regions. There's no need to apply masks
9269            // because the unmasked parts will be overwritten by fields.
9270            // Write the fields.
9271            self.0.encode(encoder, offset + 0, depth)?;
9272            Ok(())
9273        }
9274    }
9275
9276    impl fidl::encoding::Decode<Self, fidl::encoding::DefaultFuchsiaResourceDialect>
9277        for ConnectionRequestGattClientRequest
9278    {
9279        #[inline(always)]
9280        fn new_empty() -> Self {
9281            Self {
9282                client: fidl::new_empty!(
9283                    fidl::encoding::Endpoint<
9284                        fidl::endpoints::ServerEnd<fidl_fuchsia_bluetooth_gatt2::ClientMarker>,
9285                    >,
9286                    fidl::encoding::DefaultFuchsiaResourceDialect
9287                ),
9288            }
9289        }
9290
9291        #[inline]
9292        unsafe fn decode(
9293            &mut self,
9294            decoder: &mut fidl::encoding::Decoder<
9295                '_,
9296                fidl::encoding::DefaultFuchsiaResourceDialect,
9297            >,
9298            offset: usize,
9299            _depth: fidl::encoding::Depth,
9300        ) -> fidl::Result<()> {
9301            decoder.debug_check_bounds::<Self>(offset);
9302            // Verify that padding bytes are zero.
9303            fidl::decode!(
9304                fidl::encoding::Endpoint<
9305                    fidl::endpoints::ServerEnd<fidl_fuchsia_bluetooth_gatt2::ClientMarker>,
9306                >,
9307                fidl::encoding::DefaultFuchsiaResourceDialect,
9308                &mut self.client,
9309                decoder,
9310                offset + 0,
9311                _depth
9312            )?;
9313            Ok(())
9314        }
9315    }
9316
9317    impl fidl::encoding::ResourceTypeMarker for PeripheralAdvertiseRequest {
9318        type Borrowed<'a> = &'a mut Self;
9319        fn take_or_borrow<'a>(
9320            value: &'a mut <Self as fidl::encoding::TypeMarker>::Owned,
9321        ) -> Self::Borrowed<'a> {
9322            value
9323        }
9324    }
9325
9326    unsafe impl fidl::encoding::TypeMarker for PeripheralAdvertiseRequest {
9327        type Owned = Self;
9328
9329        #[inline(always)]
9330        fn inline_align(_context: fidl::encoding::Context) -> usize {
9331            8
9332        }
9333
9334        #[inline(always)]
9335        fn inline_size(_context: fidl::encoding::Context) -> usize {
9336            24
9337        }
9338    }
9339
9340    unsafe impl
9341        fidl::encoding::Encode<
9342            PeripheralAdvertiseRequest,
9343            fidl::encoding::DefaultFuchsiaResourceDialect,
9344        > for &mut PeripheralAdvertiseRequest
9345    {
9346        #[inline]
9347        unsafe fn encode(
9348            self,
9349            encoder: &mut fidl::encoding::Encoder<
9350                '_,
9351                fidl::encoding::DefaultFuchsiaResourceDialect,
9352            >,
9353            offset: usize,
9354            _depth: fidl::encoding::Depth,
9355        ) -> fidl::Result<()> {
9356            encoder.debug_check_bounds::<PeripheralAdvertiseRequest>(offset);
9357            // Delegate to tuple encoding.
9358            fidl::encoding::Encode::<
9359                PeripheralAdvertiseRequest,
9360                fidl::encoding::DefaultFuchsiaResourceDialect,
9361            >::encode(
9362                (
9363                    <AdvertisingParameters as fidl::encoding::ValueTypeMarker>::borrow(
9364                        &self.parameters,
9365                    ),
9366                    <fidl::encoding::Endpoint<
9367                        fidl::endpoints::ClientEnd<AdvertisedPeripheralMarker>,
9368                    > as fidl::encoding::ResourceTypeMarker>::take_or_borrow(
9369                        &mut self.advertised_peripheral,
9370                    ),
9371                ),
9372                encoder,
9373                offset,
9374                _depth,
9375            )
9376        }
9377    }
9378    unsafe impl<
9379            T0: fidl::encoding::Encode<
9380                AdvertisingParameters,
9381                fidl::encoding::DefaultFuchsiaResourceDialect,
9382            >,
9383            T1: fidl::encoding::Encode<
9384                fidl::encoding::Endpoint<fidl::endpoints::ClientEnd<AdvertisedPeripheralMarker>>,
9385                fidl::encoding::DefaultFuchsiaResourceDialect,
9386            >,
9387        >
9388        fidl::encoding::Encode<
9389            PeripheralAdvertiseRequest,
9390            fidl::encoding::DefaultFuchsiaResourceDialect,
9391        > for (T0, T1)
9392    {
9393        #[inline]
9394        unsafe fn encode(
9395            self,
9396            encoder: &mut fidl::encoding::Encoder<
9397                '_,
9398                fidl::encoding::DefaultFuchsiaResourceDialect,
9399            >,
9400            offset: usize,
9401            depth: fidl::encoding::Depth,
9402        ) -> fidl::Result<()> {
9403            encoder.debug_check_bounds::<PeripheralAdvertiseRequest>(offset);
9404            // Zero out padding regions. There's no need to apply masks
9405            // because the unmasked parts will be overwritten by fields.
9406            unsafe {
9407                let ptr = encoder.buf.as_mut_ptr().add(offset).offset(16);
9408                (ptr as *mut u64).write_unaligned(0);
9409            }
9410            // Write the fields.
9411            self.0.encode(encoder, offset + 0, depth)?;
9412            self.1.encode(encoder, offset + 16, depth)?;
9413            Ok(())
9414        }
9415    }
9416
9417    impl fidl::encoding::Decode<Self, fidl::encoding::DefaultFuchsiaResourceDialect>
9418        for PeripheralAdvertiseRequest
9419    {
9420        #[inline(always)]
9421        fn new_empty() -> Self {
9422            Self {
9423                parameters: fidl::new_empty!(
9424                    AdvertisingParameters,
9425                    fidl::encoding::DefaultFuchsiaResourceDialect
9426                ),
9427                advertised_peripheral: fidl::new_empty!(
9428                    fidl::encoding::Endpoint<
9429                        fidl::endpoints::ClientEnd<AdvertisedPeripheralMarker>,
9430                    >,
9431                    fidl::encoding::DefaultFuchsiaResourceDialect
9432                ),
9433            }
9434        }
9435
9436        #[inline]
9437        unsafe fn decode(
9438            &mut self,
9439            decoder: &mut fidl::encoding::Decoder<
9440                '_,
9441                fidl::encoding::DefaultFuchsiaResourceDialect,
9442            >,
9443            offset: usize,
9444            _depth: fidl::encoding::Depth,
9445        ) -> fidl::Result<()> {
9446            decoder.debug_check_bounds::<Self>(offset);
9447            // Verify that padding bytes are zero.
9448            let ptr = unsafe { decoder.buf.as_ptr().add(offset).offset(16) };
9449            let padval = unsafe { (ptr as *const u64).read_unaligned() };
9450            let mask = 0xffffffff00000000u64;
9451            let maskedval = padval & mask;
9452            if maskedval != 0 {
9453                return Err(fidl::Error::NonZeroPadding {
9454                    padding_start: offset + 16 + ((mask as u64).trailing_zeros() / 8) as usize,
9455                });
9456            }
9457            fidl::decode!(
9458                AdvertisingParameters,
9459                fidl::encoding::DefaultFuchsiaResourceDialect,
9460                &mut self.parameters,
9461                decoder,
9462                offset + 0,
9463                _depth
9464            )?;
9465            fidl::decode!(
9466                fidl::encoding::Endpoint<fidl::endpoints::ClientEnd<AdvertisedPeripheralMarker>>,
9467                fidl::encoding::DefaultFuchsiaResourceDialect,
9468                &mut self.advertised_peripheral,
9469                decoder,
9470                offset + 16,
9471                _depth
9472            )?;
9473            Ok(())
9474        }
9475    }
9476
9477    impl fidl::encoding::ResourceTypeMarker for PeripheralOnPeerConnectedRequest {
9478        type Borrowed<'a> = &'a mut Self;
9479        fn take_or_borrow<'a>(
9480            value: &'a mut <Self as fidl::encoding::TypeMarker>::Owned,
9481        ) -> Self::Borrowed<'a> {
9482            value
9483        }
9484    }
9485
9486    unsafe impl fidl::encoding::TypeMarker for PeripheralOnPeerConnectedRequest {
9487        type Owned = Self;
9488
9489        #[inline(always)]
9490        fn inline_align(_context: fidl::encoding::Context) -> usize {
9491            8
9492        }
9493
9494        #[inline(always)]
9495        fn inline_size(_context: fidl::encoding::Context) -> usize {
9496            24
9497        }
9498    }
9499
9500    unsafe impl
9501        fidl::encoding::Encode<
9502            PeripheralOnPeerConnectedRequest,
9503            fidl::encoding::DefaultFuchsiaResourceDialect,
9504        > for &mut PeripheralOnPeerConnectedRequest
9505    {
9506        #[inline]
9507        unsafe fn encode(
9508            self,
9509            encoder: &mut fidl::encoding::Encoder<
9510                '_,
9511                fidl::encoding::DefaultFuchsiaResourceDialect,
9512            >,
9513            offset: usize,
9514            _depth: fidl::encoding::Depth,
9515        ) -> fidl::Result<()> {
9516            encoder.debug_check_bounds::<PeripheralOnPeerConnectedRequest>(offset);
9517            // Delegate to tuple encoding.
9518            fidl::encoding::Encode::<PeripheralOnPeerConnectedRequest, fidl::encoding::DefaultFuchsiaResourceDialect>::encode(
9519                (
9520                    <Peer as fidl::encoding::ValueTypeMarker>::borrow(&self.peer),
9521                    <fidl::encoding::Endpoint<fidl::endpoints::ClientEnd<ConnectionMarker>> as fidl::encoding::ResourceTypeMarker>::take_or_borrow(&mut self.connection),
9522                ),
9523                encoder, offset, _depth
9524            )
9525        }
9526    }
9527    unsafe impl<
9528            T0: fidl::encoding::Encode<Peer, fidl::encoding::DefaultFuchsiaResourceDialect>,
9529            T1: fidl::encoding::Encode<
9530                fidl::encoding::Endpoint<fidl::endpoints::ClientEnd<ConnectionMarker>>,
9531                fidl::encoding::DefaultFuchsiaResourceDialect,
9532            >,
9533        >
9534        fidl::encoding::Encode<
9535            PeripheralOnPeerConnectedRequest,
9536            fidl::encoding::DefaultFuchsiaResourceDialect,
9537        > for (T0, T1)
9538    {
9539        #[inline]
9540        unsafe fn encode(
9541            self,
9542            encoder: &mut fidl::encoding::Encoder<
9543                '_,
9544                fidl::encoding::DefaultFuchsiaResourceDialect,
9545            >,
9546            offset: usize,
9547            depth: fidl::encoding::Depth,
9548        ) -> fidl::Result<()> {
9549            encoder.debug_check_bounds::<PeripheralOnPeerConnectedRequest>(offset);
9550            // Zero out padding regions. There's no need to apply masks
9551            // because the unmasked parts will be overwritten by fields.
9552            unsafe {
9553                let ptr = encoder.buf.as_mut_ptr().add(offset).offset(16);
9554                (ptr as *mut u64).write_unaligned(0);
9555            }
9556            // Write the fields.
9557            self.0.encode(encoder, offset + 0, depth)?;
9558            self.1.encode(encoder, offset + 16, depth)?;
9559            Ok(())
9560        }
9561    }
9562
9563    impl fidl::encoding::Decode<Self, fidl::encoding::DefaultFuchsiaResourceDialect>
9564        for PeripheralOnPeerConnectedRequest
9565    {
9566        #[inline(always)]
9567        fn new_empty() -> Self {
9568            Self {
9569                peer: fidl::new_empty!(Peer, fidl::encoding::DefaultFuchsiaResourceDialect),
9570                connection: fidl::new_empty!(
9571                    fidl::encoding::Endpoint<fidl::endpoints::ClientEnd<ConnectionMarker>>,
9572                    fidl::encoding::DefaultFuchsiaResourceDialect
9573                ),
9574            }
9575        }
9576
9577        #[inline]
9578        unsafe fn decode(
9579            &mut self,
9580            decoder: &mut fidl::encoding::Decoder<
9581                '_,
9582                fidl::encoding::DefaultFuchsiaResourceDialect,
9583            >,
9584            offset: usize,
9585            _depth: fidl::encoding::Depth,
9586        ) -> fidl::Result<()> {
9587            decoder.debug_check_bounds::<Self>(offset);
9588            // Verify that padding bytes are zero.
9589            let ptr = unsafe { decoder.buf.as_ptr().add(offset).offset(16) };
9590            let padval = unsafe { (ptr as *const u64).read_unaligned() };
9591            let mask = 0xffffffff00000000u64;
9592            let maskedval = padval & mask;
9593            if maskedval != 0 {
9594                return Err(fidl::Error::NonZeroPadding {
9595                    padding_start: offset + 16 + ((mask as u64).trailing_zeros() / 8) as usize,
9596                });
9597            }
9598            fidl::decode!(
9599                Peer,
9600                fidl::encoding::DefaultFuchsiaResourceDialect,
9601                &mut self.peer,
9602                decoder,
9603                offset + 0,
9604                _depth
9605            )?;
9606            fidl::decode!(
9607                fidl::encoding::Endpoint<fidl::endpoints::ClientEnd<ConnectionMarker>>,
9608                fidl::encoding::DefaultFuchsiaResourceDialect,
9609                &mut self.connection,
9610                decoder,
9611                offset + 16,
9612                _depth
9613            )?;
9614            Ok(())
9615        }
9616    }
9617
9618    impl fidl::encoding::ResourceTypeMarker for PeripheralStartAdvertisingRequest {
9619        type Borrowed<'a> = &'a mut Self;
9620        fn take_or_borrow<'a>(
9621            value: &'a mut <Self as fidl::encoding::TypeMarker>::Owned,
9622        ) -> Self::Borrowed<'a> {
9623            value
9624        }
9625    }
9626
9627    unsafe impl fidl::encoding::TypeMarker for PeripheralStartAdvertisingRequest {
9628        type Owned = Self;
9629
9630        #[inline(always)]
9631        fn inline_align(_context: fidl::encoding::Context) -> usize {
9632            8
9633        }
9634
9635        #[inline(always)]
9636        fn inline_size(_context: fidl::encoding::Context) -> usize {
9637            24
9638        }
9639    }
9640
9641    unsafe impl
9642        fidl::encoding::Encode<
9643            PeripheralStartAdvertisingRequest,
9644            fidl::encoding::DefaultFuchsiaResourceDialect,
9645        > for &mut PeripheralStartAdvertisingRequest
9646    {
9647        #[inline]
9648        unsafe fn encode(
9649            self,
9650            encoder: &mut fidl::encoding::Encoder<
9651                '_,
9652                fidl::encoding::DefaultFuchsiaResourceDialect,
9653            >,
9654            offset: usize,
9655            _depth: fidl::encoding::Depth,
9656        ) -> fidl::Result<()> {
9657            encoder.debug_check_bounds::<PeripheralStartAdvertisingRequest>(offset);
9658            // Delegate to tuple encoding.
9659            fidl::encoding::Encode::<PeripheralStartAdvertisingRequest, fidl::encoding::DefaultFuchsiaResourceDialect>::encode(
9660                (
9661                    <AdvertisingParameters as fidl::encoding::ValueTypeMarker>::borrow(&self.parameters),
9662                    <fidl::encoding::Endpoint<fidl::endpoints::ServerEnd<AdvertisingHandleMarker>> as fidl::encoding::ResourceTypeMarker>::take_or_borrow(&mut self.handle),
9663                ),
9664                encoder, offset, _depth
9665            )
9666        }
9667    }
9668    unsafe impl<
9669            T0: fidl::encoding::Encode<
9670                AdvertisingParameters,
9671                fidl::encoding::DefaultFuchsiaResourceDialect,
9672            >,
9673            T1: fidl::encoding::Encode<
9674                fidl::encoding::Endpoint<fidl::endpoints::ServerEnd<AdvertisingHandleMarker>>,
9675                fidl::encoding::DefaultFuchsiaResourceDialect,
9676            >,
9677        >
9678        fidl::encoding::Encode<
9679            PeripheralStartAdvertisingRequest,
9680            fidl::encoding::DefaultFuchsiaResourceDialect,
9681        > for (T0, T1)
9682    {
9683        #[inline]
9684        unsafe fn encode(
9685            self,
9686            encoder: &mut fidl::encoding::Encoder<
9687                '_,
9688                fidl::encoding::DefaultFuchsiaResourceDialect,
9689            >,
9690            offset: usize,
9691            depth: fidl::encoding::Depth,
9692        ) -> fidl::Result<()> {
9693            encoder.debug_check_bounds::<PeripheralStartAdvertisingRequest>(offset);
9694            // Zero out padding regions. There's no need to apply masks
9695            // because the unmasked parts will be overwritten by fields.
9696            unsafe {
9697                let ptr = encoder.buf.as_mut_ptr().add(offset).offset(16);
9698                (ptr as *mut u64).write_unaligned(0);
9699            }
9700            // Write the fields.
9701            self.0.encode(encoder, offset + 0, depth)?;
9702            self.1.encode(encoder, offset + 16, depth)?;
9703            Ok(())
9704        }
9705    }
9706
9707    impl fidl::encoding::Decode<Self, fidl::encoding::DefaultFuchsiaResourceDialect>
9708        for PeripheralStartAdvertisingRequest
9709    {
9710        #[inline(always)]
9711        fn new_empty() -> Self {
9712            Self {
9713                parameters: fidl::new_empty!(
9714                    AdvertisingParameters,
9715                    fidl::encoding::DefaultFuchsiaResourceDialect
9716                ),
9717                handle: fidl::new_empty!(
9718                    fidl::encoding::Endpoint<fidl::endpoints::ServerEnd<AdvertisingHandleMarker>>,
9719                    fidl::encoding::DefaultFuchsiaResourceDialect
9720                ),
9721            }
9722        }
9723
9724        #[inline]
9725        unsafe fn decode(
9726            &mut self,
9727            decoder: &mut fidl::encoding::Decoder<
9728                '_,
9729                fidl::encoding::DefaultFuchsiaResourceDialect,
9730            >,
9731            offset: usize,
9732            _depth: fidl::encoding::Depth,
9733        ) -> fidl::Result<()> {
9734            decoder.debug_check_bounds::<Self>(offset);
9735            // Verify that padding bytes are zero.
9736            let ptr = unsafe { decoder.buf.as_ptr().add(offset).offset(16) };
9737            let padval = unsafe { (ptr as *const u64).read_unaligned() };
9738            let mask = 0xffffffff00000000u64;
9739            let maskedval = padval & mask;
9740            if maskedval != 0 {
9741                return Err(fidl::Error::NonZeroPadding {
9742                    padding_start: offset + 16 + ((mask as u64).trailing_zeros() / 8) as usize,
9743                });
9744            }
9745            fidl::decode!(
9746                AdvertisingParameters,
9747                fidl::encoding::DefaultFuchsiaResourceDialect,
9748                &mut self.parameters,
9749                decoder,
9750                offset + 0,
9751                _depth
9752            )?;
9753            fidl::decode!(
9754                fidl::encoding::Endpoint<fidl::endpoints::ServerEnd<AdvertisingHandleMarker>>,
9755                fidl::encoding::DefaultFuchsiaResourceDialect,
9756                &mut self.handle,
9757                decoder,
9758                offset + 16,
9759                _depth
9760            )?;
9761            Ok(())
9762        }
9763    }
9764
9765    impl ChannelListenerRegistryListenL2capRequest {
9766        #[inline(always)]
9767        fn max_ordinal_present(&self) -> u64 {
9768            if let Some(_) = self.listener {
9769                return 2;
9770            }
9771            if let Some(_) = self.parameters {
9772                return 1;
9773            }
9774            0
9775        }
9776    }
9777
9778    impl fidl::encoding::ResourceTypeMarker for ChannelListenerRegistryListenL2capRequest {
9779        type Borrowed<'a> = &'a mut Self;
9780        fn take_or_borrow<'a>(
9781            value: &'a mut <Self as fidl::encoding::TypeMarker>::Owned,
9782        ) -> Self::Borrowed<'a> {
9783            value
9784        }
9785    }
9786
9787    unsafe impl fidl::encoding::TypeMarker for ChannelListenerRegistryListenL2capRequest {
9788        type Owned = Self;
9789
9790        #[inline(always)]
9791        fn inline_align(_context: fidl::encoding::Context) -> usize {
9792            8
9793        }
9794
9795        #[inline(always)]
9796        fn inline_size(_context: fidl::encoding::Context) -> usize {
9797            16
9798        }
9799    }
9800
9801    unsafe impl
9802        fidl::encoding::Encode<
9803            ChannelListenerRegistryListenL2capRequest,
9804            fidl::encoding::DefaultFuchsiaResourceDialect,
9805        > for &mut ChannelListenerRegistryListenL2capRequest
9806    {
9807        unsafe fn encode(
9808            self,
9809            encoder: &mut fidl::encoding::Encoder<
9810                '_,
9811                fidl::encoding::DefaultFuchsiaResourceDialect,
9812            >,
9813            offset: usize,
9814            mut depth: fidl::encoding::Depth,
9815        ) -> fidl::Result<()> {
9816            encoder.debug_check_bounds::<ChannelListenerRegistryListenL2capRequest>(offset);
9817            // Vector header
9818            let max_ordinal: u64 = self.max_ordinal_present();
9819            encoder.write_num(max_ordinal, offset);
9820            encoder.write_num(fidl::encoding::ALLOC_PRESENT_U64, offset + 8);
9821            // Calling encoder.out_of_line_offset(0) is not allowed.
9822            if max_ordinal == 0 {
9823                return Ok(());
9824            }
9825            depth.increment()?;
9826            let envelope_size = 8;
9827            let bytes_len = max_ordinal as usize * envelope_size;
9828            #[allow(unused_variables)]
9829            let offset = encoder.out_of_line_offset(bytes_len);
9830            let mut _prev_end_offset: usize = 0;
9831            if 1 > max_ordinal {
9832                return Ok(());
9833            }
9834
9835            // Write at offset+(ordinal-1)*envelope_size, since ordinals are one-based and envelopes
9836            // are envelope_size bytes.
9837            let cur_offset: usize = (1 - 1) * envelope_size;
9838
9839            // Zero reserved fields.
9840            encoder.padding(offset + _prev_end_offset, cur_offset - _prev_end_offset);
9841
9842            // Safety:
9843            // - bytes_len is calculated to fit envelope_size*max(member.ordinal).
9844            // - Since cur_offset is envelope_size*(member.ordinal - 1) and the envelope takes
9845            //   envelope_size bytes, there is always sufficient room.
9846            fidl::encoding::encode_in_envelope_optional::<
9847                AcceptedChannelParameters,
9848                fidl::encoding::DefaultFuchsiaResourceDialect,
9849            >(
9850                self.parameters
9851                    .as_ref()
9852                    .map(<AcceptedChannelParameters as fidl::encoding::ValueTypeMarker>::borrow),
9853                encoder,
9854                offset + cur_offset,
9855                depth,
9856            )?;
9857
9858            _prev_end_offset = cur_offset + envelope_size;
9859            if 2 > max_ordinal {
9860                return Ok(());
9861            }
9862
9863            // Write at offset+(ordinal-1)*envelope_size, since ordinals are one-based and envelopes
9864            // are envelope_size bytes.
9865            let cur_offset: usize = (2 - 1) * envelope_size;
9866
9867            // Zero reserved fields.
9868            encoder.padding(offset + _prev_end_offset, cur_offset - _prev_end_offset);
9869
9870            // Safety:
9871            // - bytes_len is calculated to fit envelope_size*max(member.ordinal).
9872            // - Since cur_offset is envelope_size*(member.ordinal - 1) and the envelope takes
9873            //   envelope_size bytes, there is always sufficient room.
9874            fidl::encoding::encode_in_envelope_optional::<fidl::encoding::Endpoint<fidl::endpoints::ClientEnd<ChannelListenerMarker>>, fidl::encoding::DefaultFuchsiaResourceDialect>(
9875            self.listener.as_mut().map(<fidl::encoding::Endpoint<fidl::endpoints::ClientEnd<ChannelListenerMarker>> as fidl::encoding::ResourceTypeMarker>::take_or_borrow),
9876            encoder, offset + cur_offset, depth
9877        )?;
9878
9879            _prev_end_offset = cur_offset + envelope_size;
9880
9881            Ok(())
9882        }
9883    }
9884
9885    impl fidl::encoding::Decode<Self, fidl::encoding::DefaultFuchsiaResourceDialect>
9886        for ChannelListenerRegistryListenL2capRequest
9887    {
9888        #[inline(always)]
9889        fn new_empty() -> Self {
9890            Self::default()
9891        }
9892
9893        unsafe fn decode(
9894            &mut self,
9895            decoder: &mut fidl::encoding::Decoder<
9896                '_,
9897                fidl::encoding::DefaultFuchsiaResourceDialect,
9898            >,
9899            offset: usize,
9900            mut depth: fidl::encoding::Depth,
9901        ) -> fidl::Result<()> {
9902            decoder.debug_check_bounds::<Self>(offset);
9903            let len = match fidl::encoding::decode_vector_header(decoder, offset)? {
9904                None => return Err(fidl::Error::NotNullable),
9905                Some(len) => len,
9906            };
9907            // Calling decoder.out_of_line_offset(0) is not allowed.
9908            if len == 0 {
9909                return Ok(());
9910            };
9911            depth.increment()?;
9912            let envelope_size = 8;
9913            let bytes_len = len * envelope_size;
9914            let offset = decoder.out_of_line_offset(bytes_len)?;
9915            // Decode the envelope for each type.
9916            let mut _next_ordinal_to_read = 0;
9917            let mut next_offset = offset;
9918            let end_offset = offset + bytes_len;
9919            _next_ordinal_to_read += 1;
9920            if next_offset >= end_offset {
9921                return Ok(());
9922            }
9923
9924            // Decode unknown envelopes for gaps in ordinals.
9925            while _next_ordinal_to_read < 1 {
9926                fidl::encoding::decode_unknown_envelope(decoder, next_offset, depth)?;
9927                _next_ordinal_to_read += 1;
9928                next_offset += envelope_size;
9929            }
9930
9931            let next_out_of_line = decoder.next_out_of_line();
9932            let handles_before = decoder.remaining_handles();
9933            if let Some((inlined, num_bytes, num_handles)) =
9934                fidl::encoding::decode_envelope_header(decoder, next_offset)?
9935            {
9936                let member_inline_size =
9937                    <AcceptedChannelParameters as fidl::encoding::TypeMarker>::inline_size(
9938                        decoder.context,
9939                    );
9940                if inlined != (member_inline_size <= 4) {
9941                    return Err(fidl::Error::InvalidInlineBitInEnvelope);
9942                }
9943                let inner_offset;
9944                let mut inner_depth = depth.clone();
9945                if inlined {
9946                    decoder.check_inline_envelope_padding(next_offset, member_inline_size)?;
9947                    inner_offset = next_offset;
9948                } else {
9949                    inner_offset = decoder.out_of_line_offset(member_inline_size)?;
9950                    inner_depth.increment()?;
9951                }
9952                let val_ref = self.parameters.get_or_insert_with(|| {
9953                    fidl::new_empty!(
9954                        AcceptedChannelParameters,
9955                        fidl::encoding::DefaultFuchsiaResourceDialect
9956                    )
9957                });
9958                fidl::decode!(
9959                    AcceptedChannelParameters,
9960                    fidl::encoding::DefaultFuchsiaResourceDialect,
9961                    val_ref,
9962                    decoder,
9963                    inner_offset,
9964                    inner_depth
9965                )?;
9966                if !inlined && decoder.next_out_of_line() != next_out_of_line + (num_bytes as usize)
9967                {
9968                    return Err(fidl::Error::InvalidNumBytesInEnvelope);
9969                }
9970                if handles_before != decoder.remaining_handles() + (num_handles as usize) {
9971                    return Err(fidl::Error::InvalidNumHandlesInEnvelope);
9972                }
9973            }
9974
9975            next_offset += envelope_size;
9976            _next_ordinal_to_read += 1;
9977            if next_offset >= end_offset {
9978                return Ok(());
9979            }
9980
9981            // Decode unknown envelopes for gaps in ordinals.
9982            while _next_ordinal_to_read < 2 {
9983                fidl::encoding::decode_unknown_envelope(decoder, next_offset, depth)?;
9984                _next_ordinal_to_read += 1;
9985                next_offset += envelope_size;
9986            }
9987
9988            let next_out_of_line = decoder.next_out_of_line();
9989            let handles_before = decoder.remaining_handles();
9990            if let Some((inlined, num_bytes, num_handles)) =
9991                fidl::encoding::decode_envelope_header(decoder, next_offset)?
9992            {
9993                let member_inline_size = <fidl::encoding::Endpoint<
9994                    fidl::endpoints::ClientEnd<ChannelListenerMarker>,
9995                > as fidl::encoding::TypeMarker>::inline_size(
9996                    decoder.context
9997                );
9998                if inlined != (member_inline_size <= 4) {
9999                    return Err(fidl::Error::InvalidInlineBitInEnvelope);
10000                }
10001                let inner_offset;
10002                let mut inner_depth = depth.clone();
10003                if inlined {
10004                    decoder.check_inline_envelope_padding(next_offset, member_inline_size)?;
10005                    inner_offset = next_offset;
10006                } else {
10007                    inner_offset = decoder.out_of_line_offset(member_inline_size)?;
10008                    inner_depth.increment()?;
10009                }
10010                let val_ref = self.listener.get_or_insert_with(|| {
10011                    fidl::new_empty!(
10012                        fidl::encoding::Endpoint<fidl::endpoints::ClientEnd<ChannelListenerMarker>>,
10013                        fidl::encoding::DefaultFuchsiaResourceDialect
10014                    )
10015                });
10016                fidl::decode!(
10017                    fidl::encoding::Endpoint<fidl::endpoints::ClientEnd<ChannelListenerMarker>>,
10018                    fidl::encoding::DefaultFuchsiaResourceDialect,
10019                    val_ref,
10020                    decoder,
10021                    inner_offset,
10022                    inner_depth
10023                )?;
10024                if !inlined && decoder.next_out_of_line() != next_out_of_line + (num_bytes as usize)
10025                {
10026                    return Err(fidl::Error::InvalidNumBytesInEnvelope);
10027                }
10028                if handles_before != decoder.remaining_handles() + (num_handles as usize) {
10029                    return Err(fidl::Error::InvalidNumHandlesInEnvelope);
10030                }
10031            }
10032
10033            next_offset += envelope_size;
10034
10035            // Decode the remaining unknown envelopes.
10036            while next_offset < end_offset {
10037                _next_ordinal_to_read += 1;
10038                fidl::encoding::decode_unknown_envelope(decoder, next_offset, depth)?;
10039                next_offset += envelope_size;
10040            }
10041
10042            Ok(())
10043        }
10044    }
10045
10046    impl ConnectionAcceptCisRequest {
10047        #[inline(always)]
10048        fn max_ordinal_present(&self) -> u64 {
10049            if let Some(_) = self.connection_stream {
10050                return 3;
10051            }
10052            if let Some(_) = self.cis_id {
10053                return 2;
10054            }
10055            if let Some(_) = self.cig_id {
10056                return 1;
10057            }
10058            0
10059        }
10060    }
10061
10062    impl fidl::encoding::ResourceTypeMarker for ConnectionAcceptCisRequest {
10063        type Borrowed<'a> = &'a mut Self;
10064        fn take_or_borrow<'a>(
10065            value: &'a mut <Self as fidl::encoding::TypeMarker>::Owned,
10066        ) -> Self::Borrowed<'a> {
10067            value
10068        }
10069    }
10070
10071    unsafe impl fidl::encoding::TypeMarker for ConnectionAcceptCisRequest {
10072        type Owned = Self;
10073
10074        #[inline(always)]
10075        fn inline_align(_context: fidl::encoding::Context) -> usize {
10076            8
10077        }
10078
10079        #[inline(always)]
10080        fn inline_size(_context: fidl::encoding::Context) -> usize {
10081            16
10082        }
10083    }
10084
10085    unsafe impl
10086        fidl::encoding::Encode<
10087            ConnectionAcceptCisRequest,
10088            fidl::encoding::DefaultFuchsiaResourceDialect,
10089        > for &mut ConnectionAcceptCisRequest
10090    {
10091        unsafe fn encode(
10092            self,
10093            encoder: &mut fidl::encoding::Encoder<
10094                '_,
10095                fidl::encoding::DefaultFuchsiaResourceDialect,
10096            >,
10097            offset: usize,
10098            mut depth: fidl::encoding::Depth,
10099        ) -> fidl::Result<()> {
10100            encoder.debug_check_bounds::<ConnectionAcceptCisRequest>(offset);
10101            // Vector header
10102            let max_ordinal: u64 = self.max_ordinal_present();
10103            encoder.write_num(max_ordinal, offset);
10104            encoder.write_num(fidl::encoding::ALLOC_PRESENT_U64, offset + 8);
10105            // Calling encoder.out_of_line_offset(0) is not allowed.
10106            if max_ordinal == 0 {
10107                return Ok(());
10108            }
10109            depth.increment()?;
10110            let envelope_size = 8;
10111            let bytes_len = max_ordinal as usize * envelope_size;
10112            #[allow(unused_variables)]
10113            let offset = encoder.out_of_line_offset(bytes_len);
10114            let mut _prev_end_offset: usize = 0;
10115            if 1 > max_ordinal {
10116                return Ok(());
10117            }
10118
10119            // Write at offset+(ordinal-1)*envelope_size, since ordinals are one-based and envelopes
10120            // are envelope_size bytes.
10121            let cur_offset: usize = (1 - 1) * envelope_size;
10122
10123            // Zero reserved fields.
10124            encoder.padding(offset + _prev_end_offset, cur_offset - _prev_end_offset);
10125
10126            // Safety:
10127            // - bytes_len is calculated to fit envelope_size*max(member.ordinal).
10128            // - Since cur_offset is envelope_size*(member.ordinal - 1) and the envelope takes
10129            //   envelope_size bytes, there is always sufficient room.
10130            fidl::encoding::encode_in_envelope_optional::<
10131                u8,
10132                fidl::encoding::DefaultFuchsiaResourceDialect,
10133            >(
10134                self.cig_id.as_ref().map(<u8 as fidl::encoding::ValueTypeMarker>::borrow),
10135                encoder,
10136                offset + cur_offset,
10137                depth,
10138            )?;
10139
10140            _prev_end_offset = cur_offset + envelope_size;
10141            if 2 > max_ordinal {
10142                return Ok(());
10143            }
10144
10145            // Write at offset+(ordinal-1)*envelope_size, since ordinals are one-based and envelopes
10146            // are envelope_size bytes.
10147            let cur_offset: usize = (2 - 1) * envelope_size;
10148
10149            // Zero reserved fields.
10150            encoder.padding(offset + _prev_end_offset, cur_offset - _prev_end_offset);
10151
10152            // Safety:
10153            // - bytes_len is calculated to fit envelope_size*max(member.ordinal).
10154            // - Since cur_offset is envelope_size*(member.ordinal - 1) and the envelope takes
10155            //   envelope_size bytes, there is always sufficient room.
10156            fidl::encoding::encode_in_envelope_optional::<
10157                u8,
10158                fidl::encoding::DefaultFuchsiaResourceDialect,
10159            >(
10160                self.cis_id.as_ref().map(<u8 as fidl::encoding::ValueTypeMarker>::borrow),
10161                encoder,
10162                offset + cur_offset,
10163                depth,
10164            )?;
10165
10166            _prev_end_offset = cur_offset + envelope_size;
10167            if 3 > max_ordinal {
10168                return Ok(());
10169            }
10170
10171            // Write at offset+(ordinal-1)*envelope_size, since ordinals are one-based and envelopes
10172            // are envelope_size bytes.
10173            let cur_offset: usize = (3 - 1) * envelope_size;
10174
10175            // Zero reserved fields.
10176            encoder.padding(offset + _prev_end_offset, cur_offset - _prev_end_offset);
10177
10178            // Safety:
10179            // - bytes_len is calculated to fit envelope_size*max(member.ordinal).
10180            // - Since cur_offset is envelope_size*(member.ordinal - 1) and the envelope takes
10181            //   envelope_size bytes, there is always sufficient room.
10182            fidl::encoding::encode_in_envelope_optional::<fidl::encoding::Endpoint<fidl::endpoints::ServerEnd<IsochronousStreamMarker>>, fidl::encoding::DefaultFuchsiaResourceDialect>(
10183            self.connection_stream.as_mut().map(<fidl::encoding::Endpoint<fidl::endpoints::ServerEnd<IsochronousStreamMarker>> as fidl::encoding::ResourceTypeMarker>::take_or_borrow),
10184            encoder, offset + cur_offset, depth
10185        )?;
10186
10187            _prev_end_offset = cur_offset + envelope_size;
10188
10189            Ok(())
10190        }
10191    }
10192
10193    impl fidl::encoding::Decode<Self, fidl::encoding::DefaultFuchsiaResourceDialect>
10194        for ConnectionAcceptCisRequest
10195    {
10196        #[inline(always)]
10197        fn new_empty() -> Self {
10198            Self::default()
10199        }
10200
10201        unsafe fn decode(
10202            &mut self,
10203            decoder: &mut fidl::encoding::Decoder<
10204                '_,
10205                fidl::encoding::DefaultFuchsiaResourceDialect,
10206            >,
10207            offset: usize,
10208            mut depth: fidl::encoding::Depth,
10209        ) -> fidl::Result<()> {
10210            decoder.debug_check_bounds::<Self>(offset);
10211            let len = match fidl::encoding::decode_vector_header(decoder, offset)? {
10212                None => return Err(fidl::Error::NotNullable),
10213                Some(len) => len,
10214            };
10215            // Calling decoder.out_of_line_offset(0) is not allowed.
10216            if len == 0 {
10217                return Ok(());
10218            };
10219            depth.increment()?;
10220            let envelope_size = 8;
10221            let bytes_len = len * envelope_size;
10222            let offset = decoder.out_of_line_offset(bytes_len)?;
10223            // Decode the envelope for each type.
10224            let mut _next_ordinal_to_read = 0;
10225            let mut next_offset = offset;
10226            let end_offset = offset + bytes_len;
10227            _next_ordinal_to_read += 1;
10228            if next_offset >= end_offset {
10229                return Ok(());
10230            }
10231
10232            // Decode unknown envelopes for gaps in ordinals.
10233            while _next_ordinal_to_read < 1 {
10234                fidl::encoding::decode_unknown_envelope(decoder, next_offset, depth)?;
10235                _next_ordinal_to_read += 1;
10236                next_offset += envelope_size;
10237            }
10238
10239            let next_out_of_line = decoder.next_out_of_line();
10240            let handles_before = decoder.remaining_handles();
10241            if let Some((inlined, num_bytes, num_handles)) =
10242                fidl::encoding::decode_envelope_header(decoder, next_offset)?
10243            {
10244                let member_inline_size =
10245                    <u8 as fidl::encoding::TypeMarker>::inline_size(decoder.context);
10246                if inlined != (member_inline_size <= 4) {
10247                    return Err(fidl::Error::InvalidInlineBitInEnvelope);
10248                }
10249                let inner_offset;
10250                let mut inner_depth = depth.clone();
10251                if inlined {
10252                    decoder.check_inline_envelope_padding(next_offset, member_inline_size)?;
10253                    inner_offset = next_offset;
10254                } else {
10255                    inner_offset = decoder.out_of_line_offset(member_inline_size)?;
10256                    inner_depth.increment()?;
10257                }
10258                let val_ref = self.cig_id.get_or_insert_with(|| {
10259                    fidl::new_empty!(u8, fidl::encoding::DefaultFuchsiaResourceDialect)
10260                });
10261                fidl::decode!(
10262                    u8,
10263                    fidl::encoding::DefaultFuchsiaResourceDialect,
10264                    val_ref,
10265                    decoder,
10266                    inner_offset,
10267                    inner_depth
10268                )?;
10269                if !inlined && decoder.next_out_of_line() != next_out_of_line + (num_bytes as usize)
10270                {
10271                    return Err(fidl::Error::InvalidNumBytesInEnvelope);
10272                }
10273                if handles_before != decoder.remaining_handles() + (num_handles as usize) {
10274                    return Err(fidl::Error::InvalidNumHandlesInEnvelope);
10275                }
10276            }
10277
10278            next_offset += envelope_size;
10279            _next_ordinal_to_read += 1;
10280            if next_offset >= end_offset {
10281                return Ok(());
10282            }
10283
10284            // Decode unknown envelopes for gaps in ordinals.
10285            while _next_ordinal_to_read < 2 {
10286                fidl::encoding::decode_unknown_envelope(decoder, next_offset, depth)?;
10287                _next_ordinal_to_read += 1;
10288                next_offset += envelope_size;
10289            }
10290
10291            let next_out_of_line = decoder.next_out_of_line();
10292            let handles_before = decoder.remaining_handles();
10293            if let Some((inlined, num_bytes, num_handles)) =
10294                fidl::encoding::decode_envelope_header(decoder, next_offset)?
10295            {
10296                let member_inline_size =
10297                    <u8 as fidl::encoding::TypeMarker>::inline_size(decoder.context);
10298                if inlined != (member_inline_size <= 4) {
10299                    return Err(fidl::Error::InvalidInlineBitInEnvelope);
10300                }
10301                let inner_offset;
10302                let mut inner_depth = depth.clone();
10303                if inlined {
10304                    decoder.check_inline_envelope_padding(next_offset, member_inline_size)?;
10305                    inner_offset = next_offset;
10306                } else {
10307                    inner_offset = decoder.out_of_line_offset(member_inline_size)?;
10308                    inner_depth.increment()?;
10309                }
10310                let val_ref = self.cis_id.get_or_insert_with(|| {
10311                    fidl::new_empty!(u8, fidl::encoding::DefaultFuchsiaResourceDialect)
10312                });
10313                fidl::decode!(
10314                    u8,
10315                    fidl::encoding::DefaultFuchsiaResourceDialect,
10316                    val_ref,
10317                    decoder,
10318                    inner_offset,
10319                    inner_depth
10320                )?;
10321                if !inlined && decoder.next_out_of_line() != next_out_of_line + (num_bytes as usize)
10322                {
10323                    return Err(fidl::Error::InvalidNumBytesInEnvelope);
10324                }
10325                if handles_before != decoder.remaining_handles() + (num_handles as usize) {
10326                    return Err(fidl::Error::InvalidNumHandlesInEnvelope);
10327                }
10328            }
10329
10330            next_offset += envelope_size;
10331            _next_ordinal_to_read += 1;
10332            if next_offset >= end_offset {
10333                return Ok(());
10334            }
10335
10336            // Decode unknown envelopes for gaps in ordinals.
10337            while _next_ordinal_to_read < 3 {
10338                fidl::encoding::decode_unknown_envelope(decoder, next_offset, depth)?;
10339                _next_ordinal_to_read += 1;
10340                next_offset += envelope_size;
10341            }
10342
10343            let next_out_of_line = decoder.next_out_of_line();
10344            let handles_before = decoder.remaining_handles();
10345            if let Some((inlined, num_bytes, num_handles)) =
10346                fidl::encoding::decode_envelope_header(decoder, next_offset)?
10347            {
10348                let member_inline_size = <fidl::encoding::Endpoint<
10349                    fidl::endpoints::ServerEnd<IsochronousStreamMarker>,
10350                > as fidl::encoding::TypeMarker>::inline_size(
10351                    decoder.context
10352                );
10353                if inlined != (member_inline_size <= 4) {
10354                    return Err(fidl::Error::InvalidInlineBitInEnvelope);
10355                }
10356                let inner_offset;
10357                let mut inner_depth = depth.clone();
10358                if inlined {
10359                    decoder.check_inline_envelope_padding(next_offset, member_inline_size)?;
10360                    inner_offset = next_offset;
10361                } else {
10362                    inner_offset = decoder.out_of_line_offset(member_inline_size)?;
10363                    inner_depth.increment()?;
10364                }
10365                let val_ref = self.connection_stream.get_or_insert_with(|| {
10366                    fidl::new_empty!(
10367                        fidl::encoding::Endpoint<
10368                            fidl::endpoints::ServerEnd<IsochronousStreamMarker>,
10369                        >,
10370                        fidl::encoding::DefaultFuchsiaResourceDialect
10371                    )
10372                });
10373                fidl::decode!(
10374                    fidl::encoding::Endpoint<fidl::endpoints::ServerEnd<IsochronousStreamMarker>>,
10375                    fidl::encoding::DefaultFuchsiaResourceDialect,
10376                    val_ref,
10377                    decoder,
10378                    inner_offset,
10379                    inner_depth
10380                )?;
10381                if !inlined && decoder.next_out_of_line() != next_out_of_line + (num_bytes as usize)
10382                {
10383                    return Err(fidl::Error::InvalidNumBytesInEnvelope);
10384                }
10385                if handles_before != decoder.remaining_handles() + (num_handles as usize) {
10386                    return Err(fidl::Error::InvalidNumHandlesInEnvelope);
10387                }
10388            }
10389
10390            next_offset += envelope_size;
10391
10392            // Decode the remaining unknown envelopes.
10393            while next_offset < end_offset {
10394                _next_ordinal_to_read += 1;
10395                fidl::encoding::decode_unknown_envelope(decoder, next_offset, depth)?;
10396                next_offset += envelope_size;
10397            }
10398
10399            Ok(())
10400        }
10401    }
10402
10403    impl ConnectionConnectL2capRequest {
10404        #[inline(always)]
10405        fn max_ordinal_present(&self) -> u64 {
10406            if let Some(_) = self.psm {
10407                return 3;
10408            }
10409            if let Some(_) = self.channel {
10410                return 2;
10411            }
10412            if let Some(_) = self.parameters {
10413                return 1;
10414            }
10415            0
10416        }
10417    }
10418
10419    impl fidl::encoding::ResourceTypeMarker for ConnectionConnectL2capRequest {
10420        type Borrowed<'a> = &'a mut Self;
10421        fn take_or_borrow<'a>(
10422            value: &'a mut <Self as fidl::encoding::TypeMarker>::Owned,
10423        ) -> Self::Borrowed<'a> {
10424            value
10425        }
10426    }
10427
10428    unsafe impl fidl::encoding::TypeMarker for ConnectionConnectL2capRequest {
10429        type Owned = Self;
10430
10431        #[inline(always)]
10432        fn inline_align(_context: fidl::encoding::Context) -> usize {
10433            8
10434        }
10435
10436        #[inline(always)]
10437        fn inline_size(_context: fidl::encoding::Context) -> usize {
10438            16
10439        }
10440    }
10441
10442    unsafe impl
10443        fidl::encoding::Encode<
10444            ConnectionConnectL2capRequest,
10445            fidl::encoding::DefaultFuchsiaResourceDialect,
10446        > for &mut ConnectionConnectL2capRequest
10447    {
10448        unsafe fn encode(
10449            self,
10450            encoder: &mut fidl::encoding::Encoder<
10451                '_,
10452                fidl::encoding::DefaultFuchsiaResourceDialect,
10453            >,
10454            offset: usize,
10455            mut depth: fidl::encoding::Depth,
10456        ) -> fidl::Result<()> {
10457            encoder.debug_check_bounds::<ConnectionConnectL2capRequest>(offset);
10458            // Vector header
10459            let max_ordinal: u64 = self.max_ordinal_present();
10460            encoder.write_num(max_ordinal, offset);
10461            encoder.write_num(fidl::encoding::ALLOC_PRESENT_U64, offset + 8);
10462            // Calling encoder.out_of_line_offset(0) is not allowed.
10463            if max_ordinal == 0 {
10464                return Ok(());
10465            }
10466            depth.increment()?;
10467            let envelope_size = 8;
10468            let bytes_len = max_ordinal as usize * envelope_size;
10469            #[allow(unused_variables)]
10470            let offset = encoder.out_of_line_offset(bytes_len);
10471            let mut _prev_end_offset: usize = 0;
10472            if 1 > max_ordinal {
10473                return Ok(());
10474            }
10475
10476            // Write at offset+(ordinal-1)*envelope_size, since ordinals are one-based and envelopes
10477            // are envelope_size bytes.
10478            let cur_offset: usize = (1 - 1) * envelope_size;
10479
10480            // Zero reserved fields.
10481            encoder.padding(offset + _prev_end_offset, cur_offset - _prev_end_offset);
10482
10483            // Safety:
10484            // - bytes_len is calculated to fit envelope_size*max(member.ordinal).
10485            // - Since cur_offset is envelope_size*(member.ordinal - 1) and the envelope takes
10486            //   envelope_size bytes, there is always sufficient room.
10487            fidl::encoding::encode_in_envelope_optional::<fidl_fuchsia_bluetooth::ChannelParameters, fidl::encoding::DefaultFuchsiaResourceDialect>(
10488            self.parameters.as_ref().map(<fidl_fuchsia_bluetooth::ChannelParameters as fidl::encoding::ValueTypeMarker>::borrow),
10489            encoder, offset + cur_offset, depth
10490        )?;
10491
10492            _prev_end_offset = cur_offset + envelope_size;
10493            if 2 > max_ordinal {
10494                return Ok(());
10495            }
10496
10497            // Write at offset+(ordinal-1)*envelope_size, since ordinals are one-based and envelopes
10498            // are envelope_size bytes.
10499            let cur_offset: usize = (2 - 1) * envelope_size;
10500
10501            // Zero reserved fields.
10502            encoder.padding(offset + _prev_end_offset, cur_offset - _prev_end_offset);
10503
10504            // Safety:
10505            // - bytes_len is calculated to fit envelope_size*max(member.ordinal).
10506            // - Since cur_offset is envelope_size*(member.ordinal - 1) and the envelope takes
10507            //   envelope_size bytes, there is always sufficient room.
10508            fidl::encoding::encode_in_envelope_optional::<
10509                fidl::encoding::Endpoint<
10510                    fidl::endpoints::ServerEnd<fidl_fuchsia_bluetooth::ChannelMarker>,
10511                >,
10512                fidl::encoding::DefaultFuchsiaResourceDialect,
10513            >(
10514                self.channel.as_mut().map(
10515                    <fidl::encoding::Endpoint<
10516                        fidl::endpoints::ServerEnd<fidl_fuchsia_bluetooth::ChannelMarker>,
10517                    > as fidl::encoding::ResourceTypeMarker>::take_or_borrow,
10518                ),
10519                encoder,
10520                offset + cur_offset,
10521                depth,
10522            )?;
10523
10524            _prev_end_offset = cur_offset + envelope_size;
10525            if 3 > max_ordinal {
10526                return Ok(());
10527            }
10528
10529            // Write at offset+(ordinal-1)*envelope_size, since ordinals are one-based and envelopes
10530            // are envelope_size bytes.
10531            let cur_offset: usize = (3 - 1) * envelope_size;
10532
10533            // Zero reserved fields.
10534            encoder.padding(offset + _prev_end_offset, cur_offset - _prev_end_offset);
10535
10536            // Safety:
10537            // - bytes_len is calculated to fit envelope_size*max(member.ordinal).
10538            // - Since cur_offset is envelope_size*(member.ordinal - 1) and the envelope takes
10539            //   envelope_size bytes, there is always sufficient room.
10540            fidl::encoding::encode_in_envelope_optional::<
10541                u16,
10542                fidl::encoding::DefaultFuchsiaResourceDialect,
10543            >(
10544                self.psm.as_ref().map(<u16 as fidl::encoding::ValueTypeMarker>::borrow),
10545                encoder,
10546                offset + cur_offset,
10547                depth,
10548            )?;
10549
10550            _prev_end_offset = cur_offset + envelope_size;
10551
10552            Ok(())
10553        }
10554    }
10555
10556    impl fidl::encoding::Decode<Self, fidl::encoding::DefaultFuchsiaResourceDialect>
10557        for ConnectionConnectL2capRequest
10558    {
10559        #[inline(always)]
10560        fn new_empty() -> Self {
10561            Self::default()
10562        }
10563
10564        unsafe fn decode(
10565            &mut self,
10566            decoder: &mut fidl::encoding::Decoder<
10567                '_,
10568                fidl::encoding::DefaultFuchsiaResourceDialect,
10569            >,
10570            offset: usize,
10571            mut depth: fidl::encoding::Depth,
10572        ) -> fidl::Result<()> {
10573            decoder.debug_check_bounds::<Self>(offset);
10574            let len = match fidl::encoding::decode_vector_header(decoder, offset)? {
10575                None => return Err(fidl::Error::NotNullable),
10576                Some(len) => len,
10577            };
10578            // Calling decoder.out_of_line_offset(0) is not allowed.
10579            if len == 0 {
10580                return Ok(());
10581            };
10582            depth.increment()?;
10583            let envelope_size = 8;
10584            let bytes_len = len * envelope_size;
10585            let offset = decoder.out_of_line_offset(bytes_len)?;
10586            // Decode the envelope for each type.
10587            let mut _next_ordinal_to_read = 0;
10588            let mut next_offset = offset;
10589            let end_offset = offset + bytes_len;
10590            _next_ordinal_to_read += 1;
10591            if next_offset >= end_offset {
10592                return Ok(());
10593            }
10594
10595            // Decode unknown envelopes for gaps in ordinals.
10596            while _next_ordinal_to_read < 1 {
10597                fidl::encoding::decode_unknown_envelope(decoder, next_offset, depth)?;
10598                _next_ordinal_to_read += 1;
10599                next_offset += envelope_size;
10600            }
10601
10602            let next_out_of_line = decoder.next_out_of_line();
10603            let handles_before = decoder.remaining_handles();
10604            if let Some((inlined, num_bytes, num_handles)) =
10605                fidl::encoding::decode_envelope_header(decoder, next_offset)?
10606            {
10607                let member_inline_size = <fidl_fuchsia_bluetooth::ChannelParameters as fidl::encoding::TypeMarker>::inline_size(decoder.context);
10608                if inlined != (member_inline_size <= 4) {
10609                    return Err(fidl::Error::InvalidInlineBitInEnvelope);
10610                }
10611                let inner_offset;
10612                let mut inner_depth = depth.clone();
10613                if inlined {
10614                    decoder.check_inline_envelope_padding(next_offset, member_inline_size)?;
10615                    inner_offset = next_offset;
10616                } else {
10617                    inner_offset = decoder.out_of_line_offset(member_inline_size)?;
10618                    inner_depth.increment()?;
10619                }
10620                let val_ref = self.parameters.get_or_insert_with(|| {
10621                    fidl::new_empty!(
10622                        fidl_fuchsia_bluetooth::ChannelParameters,
10623                        fidl::encoding::DefaultFuchsiaResourceDialect
10624                    )
10625                });
10626                fidl::decode!(
10627                    fidl_fuchsia_bluetooth::ChannelParameters,
10628                    fidl::encoding::DefaultFuchsiaResourceDialect,
10629                    val_ref,
10630                    decoder,
10631                    inner_offset,
10632                    inner_depth
10633                )?;
10634                if !inlined && decoder.next_out_of_line() != next_out_of_line + (num_bytes as usize)
10635                {
10636                    return Err(fidl::Error::InvalidNumBytesInEnvelope);
10637                }
10638                if handles_before != decoder.remaining_handles() + (num_handles as usize) {
10639                    return Err(fidl::Error::InvalidNumHandlesInEnvelope);
10640                }
10641            }
10642
10643            next_offset += envelope_size;
10644            _next_ordinal_to_read += 1;
10645            if next_offset >= end_offset {
10646                return Ok(());
10647            }
10648
10649            // Decode unknown envelopes for gaps in ordinals.
10650            while _next_ordinal_to_read < 2 {
10651                fidl::encoding::decode_unknown_envelope(decoder, next_offset, depth)?;
10652                _next_ordinal_to_read += 1;
10653                next_offset += envelope_size;
10654            }
10655
10656            let next_out_of_line = decoder.next_out_of_line();
10657            let handles_before = decoder.remaining_handles();
10658            if let Some((inlined, num_bytes, num_handles)) =
10659                fidl::encoding::decode_envelope_header(decoder, next_offset)?
10660            {
10661                let member_inline_size = <fidl::encoding::Endpoint<
10662                    fidl::endpoints::ServerEnd<fidl_fuchsia_bluetooth::ChannelMarker>,
10663                > as fidl::encoding::TypeMarker>::inline_size(
10664                    decoder.context
10665                );
10666                if inlined != (member_inline_size <= 4) {
10667                    return Err(fidl::Error::InvalidInlineBitInEnvelope);
10668                }
10669                let inner_offset;
10670                let mut inner_depth = depth.clone();
10671                if inlined {
10672                    decoder.check_inline_envelope_padding(next_offset, member_inline_size)?;
10673                    inner_offset = next_offset;
10674                } else {
10675                    inner_offset = decoder.out_of_line_offset(member_inline_size)?;
10676                    inner_depth.increment()?;
10677                }
10678                let val_ref = self.channel.get_or_insert_with(|| {
10679                    fidl::new_empty!(
10680                        fidl::encoding::Endpoint<
10681                            fidl::endpoints::ServerEnd<fidl_fuchsia_bluetooth::ChannelMarker>,
10682                        >,
10683                        fidl::encoding::DefaultFuchsiaResourceDialect
10684                    )
10685                });
10686                fidl::decode!(
10687                    fidl::encoding::Endpoint<
10688                        fidl::endpoints::ServerEnd<fidl_fuchsia_bluetooth::ChannelMarker>,
10689                    >,
10690                    fidl::encoding::DefaultFuchsiaResourceDialect,
10691                    val_ref,
10692                    decoder,
10693                    inner_offset,
10694                    inner_depth
10695                )?;
10696                if !inlined && decoder.next_out_of_line() != next_out_of_line + (num_bytes as usize)
10697                {
10698                    return Err(fidl::Error::InvalidNumBytesInEnvelope);
10699                }
10700                if handles_before != decoder.remaining_handles() + (num_handles as usize) {
10701                    return Err(fidl::Error::InvalidNumHandlesInEnvelope);
10702                }
10703            }
10704
10705            next_offset += envelope_size;
10706            _next_ordinal_to_read += 1;
10707            if next_offset >= end_offset {
10708                return Ok(());
10709            }
10710
10711            // Decode unknown envelopes for gaps in ordinals.
10712            while _next_ordinal_to_read < 3 {
10713                fidl::encoding::decode_unknown_envelope(decoder, next_offset, depth)?;
10714                _next_ordinal_to_read += 1;
10715                next_offset += envelope_size;
10716            }
10717
10718            let next_out_of_line = decoder.next_out_of_line();
10719            let handles_before = decoder.remaining_handles();
10720            if let Some((inlined, num_bytes, num_handles)) =
10721                fidl::encoding::decode_envelope_header(decoder, next_offset)?
10722            {
10723                let member_inline_size =
10724                    <u16 as fidl::encoding::TypeMarker>::inline_size(decoder.context);
10725                if inlined != (member_inline_size <= 4) {
10726                    return Err(fidl::Error::InvalidInlineBitInEnvelope);
10727                }
10728                let inner_offset;
10729                let mut inner_depth = depth.clone();
10730                if inlined {
10731                    decoder.check_inline_envelope_padding(next_offset, member_inline_size)?;
10732                    inner_offset = next_offset;
10733                } else {
10734                    inner_offset = decoder.out_of_line_offset(member_inline_size)?;
10735                    inner_depth.increment()?;
10736                }
10737                let val_ref = self.psm.get_or_insert_with(|| {
10738                    fidl::new_empty!(u16, fidl::encoding::DefaultFuchsiaResourceDialect)
10739                });
10740                fidl::decode!(
10741                    u16,
10742                    fidl::encoding::DefaultFuchsiaResourceDialect,
10743                    val_ref,
10744                    decoder,
10745                    inner_offset,
10746                    inner_depth
10747                )?;
10748                if !inlined && decoder.next_out_of_line() != next_out_of_line + (num_bytes as usize)
10749                {
10750                    return Err(fidl::Error::InvalidNumBytesInEnvelope);
10751                }
10752                if handles_before != decoder.remaining_handles() + (num_handles as usize) {
10753                    return Err(fidl::Error::InvalidNumHandlesInEnvelope);
10754                }
10755            }
10756
10757            next_offset += envelope_size;
10758
10759            // Decode the remaining unknown envelopes.
10760            while next_offset < end_offset {
10761                _next_ordinal_to_read += 1;
10762                fidl::encoding::decode_unknown_envelope(decoder, next_offset, depth)?;
10763                next_offset += envelope_size;
10764            }
10765
10766            Ok(())
10767        }
10768    }
10769}