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