Skip to main content

fidl_fuchsia_bluetooth_bredr_test/
fidl_fuchsia_bluetooth_bredr_test.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_bredr_test_common::*;
11use futures::future::{self, MaybeDone, TryFutureExt};
12use zx_status;
13
14#[derive(Debug, Eq, Hash, Ord, PartialEq, PartialOrd)]
15pub struct MockPeerConnectProxyRequest {
16    pub interface: fidl::endpoints::ServerEnd<fidl_fuchsia_bluetooth_bredr::ProfileMarker>,
17}
18
19impl fidl::Standalone<fidl::encoding::DefaultFuchsiaResourceDialect>
20    for MockPeerConnectProxyRequest
21{
22}
23
24#[derive(Debug, PartialEq)]
25pub struct ProfileTestRegisterPeerRequest {
26    pub peer_id: fidl_fuchsia_bluetooth::PeerId,
27    pub peer: fidl::endpoints::ServerEnd<MockPeerMarker>,
28    pub observer: fidl::endpoints::ClientEnd<PeerObserverMarker>,
29}
30
31impl fidl::Standalone<fidl::encoding::DefaultFuchsiaResourceDialect>
32    for ProfileTestRegisterPeerRequest
33{
34}
35
36#[derive(Debug, Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Hash)]
37pub struct MockPeerMarker;
38
39impl fidl::endpoints::ProtocolMarker for MockPeerMarker {
40    type Proxy = MockPeerProxy;
41    type RequestStream = MockPeerRequestStream;
42    #[cfg(target_os = "fuchsia")]
43    type SynchronousProxy = MockPeerSynchronousProxy;
44
45    const DEBUG_NAME: &'static str = "(anonymous) MockPeer";
46}
47
48pub trait MockPeerProxyInterface: Send + Sync {
49    type ConnectProxy_ResponseFut: std::future::Future<Output = Result<(), fidl::Error>> + Send;
50    fn r#connect_proxy_(
51        &self,
52        interface: fidl::endpoints::ServerEnd<fidl_fuchsia_bluetooth_bredr::ProfileMarker>,
53    ) -> Self::ConnectProxy_ResponseFut;
54}
55#[derive(Debug)]
56#[cfg(target_os = "fuchsia")]
57pub struct MockPeerSynchronousProxy {
58    client: fidl::client::sync::Client,
59}
60
61#[cfg(target_os = "fuchsia")]
62impl fidl::endpoints::SynchronousProxy for MockPeerSynchronousProxy {
63    type Proxy = MockPeerProxy;
64    type Protocol = MockPeerMarker;
65
66    fn from_channel(inner: fidl::Channel) -> Self {
67        Self::new(inner)
68    }
69
70    fn into_channel(self) -> fidl::Channel {
71        self.client.into_channel()
72    }
73
74    fn as_channel(&self) -> &fidl::Channel {
75        self.client.as_channel()
76    }
77}
78
79#[cfg(target_os = "fuchsia")]
80impl MockPeerSynchronousProxy {
81    pub fn new(channel: fidl::Channel) -> Self {
82        Self { client: fidl::client::sync::Client::new(channel) }
83    }
84
85    pub fn into_channel(self) -> fidl::Channel {
86        self.client.into_channel()
87    }
88
89    /// Waits until an event arrives and returns it. It is safe for other
90    /// threads to make concurrent requests while waiting for an event.
91    pub fn wait_for_event(
92        &self,
93        deadline: zx::MonotonicInstant,
94    ) -> Result<MockPeerEvent, fidl::Error> {
95        MockPeerEvent::decode(self.client.wait_for_event::<MockPeerMarker>(deadline)?)
96    }
97
98    /// Connect a channel to the [`fuchsia.bluetooth.bredr.Profile`] protocol for
99    /// manipulation of the mock peer.
100    ///
101    /// It is valid to connect multiple proxies to a `MockPeer`.
102    ///
103    /// This parallels the current behavior of the bluetooth profile components.
104    /// Specifically, profiles internally use the [`fuchsia.bluetooth.bredr.Profile`]
105    /// service to register, search, and connect services. `ConnectProxy` provides a way
106    /// for the test client to do the same for a given mock peer.
107    ///
108    /// If the `interface` is not connectable, it will be dropped with an epitaph
109    /// signaling the failure.
110    ///
111    /// + request `interface` Interface to drive mock peer behavior.
112    pub fn r#connect_proxy_(
113        &self,
114        mut interface: fidl::endpoints::ServerEnd<fidl_fuchsia_bluetooth_bredr::ProfileMarker>,
115        ___deadline: zx::MonotonicInstant,
116    ) -> Result<(), fidl::Error> {
117        let _response = self.client.send_query::<
118            MockPeerConnectProxyRequest,
119            fidl::encoding::EmptyPayload,
120            MockPeerMarker,
121        >(
122            (interface,),
123            0x578ee1f7ee6dd9d8,
124            fidl::encoding::DynamicFlags::empty(),
125            ___deadline,
126        )?;
127        Ok(_response)
128    }
129}
130
131#[cfg(target_os = "fuchsia")]
132impl From<MockPeerSynchronousProxy> for zx::NullableHandle {
133    fn from(value: MockPeerSynchronousProxy) -> Self {
134        value.into_channel().into()
135    }
136}
137
138#[cfg(target_os = "fuchsia")]
139impl From<fidl::Channel> for MockPeerSynchronousProxy {
140    fn from(value: fidl::Channel) -> Self {
141        Self::new(value)
142    }
143}
144
145#[cfg(target_os = "fuchsia")]
146impl fidl::endpoints::FromClient for MockPeerSynchronousProxy {
147    type Protocol = MockPeerMarker;
148
149    fn from_client(value: fidl::endpoints::ClientEnd<MockPeerMarker>) -> Self {
150        Self::new(value.into_channel())
151    }
152}
153
154#[derive(Debug, Clone)]
155pub struct MockPeerProxy {
156    client: fidl::client::Client<fidl::encoding::DefaultFuchsiaResourceDialect>,
157}
158
159impl fidl::endpoints::Proxy for MockPeerProxy {
160    type Protocol = MockPeerMarker;
161
162    fn from_channel(inner: ::fidl::AsyncChannel) -> Self {
163        Self::new(inner)
164    }
165
166    fn into_channel(self) -> Result<::fidl::AsyncChannel, Self> {
167        self.client.into_channel().map_err(|client| Self { client })
168    }
169
170    fn as_channel(&self) -> &::fidl::AsyncChannel {
171        self.client.as_channel()
172    }
173}
174
175impl MockPeerProxy {
176    /// Create a new Proxy for fuchsia.bluetooth.bredr.test/MockPeer.
177    pub fn new(channel: ::fidl::AsyncChannel) -> Self {
178        let protocol_name = <MockPeerMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME;
179        Self { client: fidl::client::Client::new(channel, protocol_name) }
180    }
181
182    /// Get a Stream of events from the remote end of the protocol.
183    ///
184    /// # Panics
185    ///
186    /// Panics if the event stream was already taken.
187    pub fn take_event_stream(&self) -> MockPeerEventStream {
188        MockPeerEventStream { event_receiver: self.client.take_event_receiver() }
189    }
190
191    /// Connect a channel to the [`fuchsia.bluetooth.bredr.Profile`] protocol for
192    /// manipulation of the mock peer.
193    ///
194    /// It is valid to connect multiple proxies to a `MockPeer`.
195    ///
196    /// This parallels the current behavior of the bluetooth profile components.
197    /// Specifically, profiles internally use the [`fuchsia.bluetooth.bredr.Profile`]
198    /// service to register, search, and connect services. `ConnectProxy` provides a way
199    /// for the test client to do the same for a given mock peer.
200    ///
201    /// If the `interface` is not connectable, it will be dropped with an epitaph
202    /// signaling the failure.
203    ///
204    /// + request `interface` Interface to drive mock peer behavior.
205    pub fn r#connect_proxy_(
206        &self,
207        mut interface: fidl::endpoints::ServerEnd<fidl_fuchsia_bluetooth_bredr::ProfileMarker>,
208    ) -> fidl::client::QueryResponseFut<(), fidl::encoding::DefaultFuchsiaResourceDialect> {
209        MockPeerProxyInterface::r#connect_proxy_(self, interface)
210    }
211}
212
213impl MockPeerProxyInterface for MockPeerProxy {
214    type ConnectProxy_ResponseFut =
215        fidl::client::QueryResponseFut<(), fidl::encoding::DefaultFuchsiaResourceDialect>;
216    fn r#connect_proxy_(
217        &self,
218        mut interface: fidl::endpoints::ServerEnd<fidl_fuchsia_bluetooth_bredr::ProfileMarker>,
219    ) -> Self::ConnectProxy_ResponseFut {
220        fn _decode(
221            mut _buf: Result<<fidl::encoding::DefaultFuchsiaResourceDialect as fidl::encoding::ResourceDialect>::MessageBufEtc, fidl::Error>,
222        ) -> Result<(), fidl::Error> {
223            let _response = fidl::client::decode_transaction_body::<
224                fidl::encoding::EmptyPayload,
225                fidl::encoding::DefaultFuchsiaResourceDialect,
226                0x578ee1f7ee6dd9d8,
227            >(_buf?)?;
228            Ok(_response)
229        }
230        self.client.send_query_and_decode::<MockPeerConnectProxyRequest, ()>(
231            (interface,),
232            0x578ee1f7ee6dd9d8,
233            fidl::encoding::DynamicFlags::empty(),
234            _decode,
235        )
236    }
237}
238
239pub struct MockPeerEventStream {
240    event_receiver: fidl::client::EventReceiver<fidl::encoding::DefaultFuchsiaResourceDialect>,
241}
242
243impl std::marker::Unpin for MockPeerEventStream {}
244
245impl futures::stream::FusedStream for MockPeerEventStream {
246    fn is_terminated(&self) -> bool {
247        self.event_receiver.is_terminated()
248    }
249}
250
251impl futures::Stream for MockPeerEventStream {
252    type Item = Result<MockPeerEvent, fidl::Error>;
253
254    fn poll_next(
255        mut self: std::pin::Pin<&mut Self>,
256        cx: &mut std::task::Context<'_>,
257    ) -> std::task::Poll<Option<Self::Item>> {
258        match futures::ready!(futures::stream::StreamExt::poll_next_unpin(
259            &mut self.event_receiver,
260            cx
261        )?) {
262            Some(buf) => std::task::Poll::Ready(Some(MockPeerEvent::decode(buf))),
263            None => std::task::Poll::Ready(None),
264        }
265    }
266}
267
268#[derive(Debug)]
269pub enum MockPeerEvent {}
270
271impl MockPeerEvent {
272    /// Decodes a message buffer as a [`MockPeerEvent`].
273    fn decode(
274        mut buf: <fidl::encoding::DefaultFuchsiaResourceDialect as fidl::encoding::ResourceDialect>::MessageBufEtc,
275    ) -> Result<MockPeerEvent, fidl::Error> {
276        let (bytes, _handles) = buf.split_mut();
277        let (tx_header, _body_bytes) = fidl::encoding::decode_transaction_header(bytes)?;
278        debug_assert_eq!(tx_header.tx_id, 0);
279        match tx_header.ordinal {
280            _ => Err(fidl::Error::UnknownOrdinal {
281                ordinal: tx_header.ordinal,
282                protocol_name: <MockPeerMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME,
283            }),
284        }
285    }
286}
287
288/// A Stream of incoming requests for fuchsia.bluetooth.bredr.test/MockPeer.
289pub struct MockPeerRequestStream {
290    inner: std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>,
291    is_terminated: bool,
292}
293
294impl std::marker::Unpin for MockPeerRequestStream {}
295
296impl futures::stream::FusedStream for MockPeerRequestStream {
297    fn is_terminated(&self) -> bool {
298        self.is_terminated
299    }
300}
301
302impl fidl::endpoints::RequestStream for MockPeerRequestStream {
303    type Protocol = MockPeerMarker;
304    type ControlHandle = MockPeerControlHandle;
305
306    fn from_channel(channel: ::fidl::AsyncChannel) -> Self {
307        Self { inner: std::sync::Arc::new(fidl::ServeInner::new(channel)), is_terminated: false }
308    }
309
310    fn control_handle(&self) -> Self::ControlHandle {
311        MockPeerControlHandle { inner: self.inner.clone() }
312    }
313
314    fn into_inner(
315        self,
316    ) -> (::std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>, bool)
317    {
318        (self.inner, self.is_terminated)
319    }
320
321    fn from_inner(
322        inner: std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>,
323        is_terminated: bool,
324    ) -> Self {
325        Self { inner, is_terminated }
326    }
327}
328
329impl futures::Stream for MockPeerRequestStream {
330    type Item = Result<MockPeerRequest, fidl::Error>;
331
332    fn poll_next(
333        mut self: std::pin::Pin<&mut Self>,
334        cx: &mut std::task::Context<'_>,
335    ) -> std::task::Poll<Option<Self::Item>> {
336        let this = &mut *self;
337        if this.inner.check_shutdown(cx) {
338            this.is_terminated = true;
339            return std::task::Poll::Ready(None);
340        }
341        if this.is_terminated {
342            panic!("polled MockPeerRequestStream after completion");
343        }
344        fidl::encoding::with_tls_decode_buf::<_, fidl::encoding::DefaultFuchsiaResourceDialect>(
345            |bytes, handles| {
346                match this.inner.channel().read_etc(cx, bytes, handles) {
347                    std::task::Poll::Ready(Ok(())) => {}
348                    std::task::Poll::Pending => return std::task::Poll::Pending,
349                    std::task::Poll::Ready(Err(zx_status::Status::PEER_CLOSED)) => {
350                        this.is_terminated = true;
351                        return std::task::Poll::Ready(None);
352                    }
353                    std::task::Poll::Ready(Err(e)) => {
354                        return std::task::Poll::Ready(Some(Err(fidl::Error::ServerRequestRead(
355                            e.into(),
356                        ))));
357                    }
358                }
359
360                // A message has been received from the channel
361                let (header, _body_bytes) = fidl::encoding::decode_transaction_header(bytes)?;
362
363                std::task::Poll::Ready(Some(match header.ordinal {
364                    0x578ee1f7ee6dd9d8 => {
365                        header.validate_request_tx_id(fidl::MethodType::TwoWay)?;
366                        let mut req = fidl::new_empty!(
367                            MockPeerConnectProxyRequest,
368                            fidl::encoding::DefaultFuchsiaResourceDialect
369                        );
370                        fidl::encoding::Decoder::<fidl::encoding::DefaultFuchsiaResourceDialect>::decode_into::<MockPeerConnectProxyRequest>(&header, _body_bytes, handles, &mut req)?;
371                        let control_handle = MockPeerControlHandle { inner: this.inner.clone() };
372                        Ok(MockPeerRequest::ConnectProxy_ {
373                            interface: req.interface,
374
375                            responder: MockPeerConnectProxy_Responder {
376                                control_handle: std::mem::ManuallyDrop::new(control_handle),
377                                tx_id: header.tx_id,
378                            },
379                        })
380                    }
381                    _ => Err(fidl::Error::UnknownOrdinal {
382                        ordinal: header.ordinal,
383                        protocol_name:
384                            <MockPeerMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME,
385                    }),
386                }))
387            },
388        )
389    }
390}
391
392/// `MockPeer` provides an interface for managing the lifetime of a mock peer in the piconet.
393/// Dropping `MockPeer` will unregister the peer from the Profile Test Server database.
394///   - Any launched components associated with the mock peer will be terminated.
395///   - Any actively connected `ProfileProxy` will be disconnected and dropped.
396#[derive(Debug)]
397pub enum MockPeerRequest {
398    /// Connect a channel to the [`fuchsia.bluetooth.bredr.Profile`] protocol for
399    /// manipulation of the mock peer.
400    ///
401    /// It is valid to connect multiple proxies to a `MockPeer`.
402    ///
403    /// This parallels the current behavior of the bluetooth profile components.
404    /// Specifically, profiles internally use the [`fuchsia.bluetooth.bredr.Profile`]
405    /// service to register, search, and connect services. `ConnectProxy` provides a way
406    /// for the test client to do the same for a given mock peer.
407    ///
408    /// If the `interface` is not connectable, it will be dropped with an epitaph
409    /// signaling the failure.
410    ///
411    /// + request `interface` Interface to drive mock peer behavior.
412    ConnectProxy_ {
413        interface: fidl::endpoints::ServerEnd<fidl_fuchsia_bluetooth_bredr::ProfileMarker>,
414        responder: MockPeerConnectProxy_Responder,
415    },
416}
417
418impl MockPeerRequest {
419    #[allow(irrefutable_let_patterns)]
420    pub fn into_connect_proxy_(
421        self,
422    ) -> Option<(
423        fidl::endpoints::ServerEnd<fidl_fuchsia_bluetooth_bredr::ProfileMarker>,
424        MockPeerConnectProxy_Responder,
425    )> {
426        if let MockPeerRequest::ConnectProxy_ { interface, responder } = self {
427            Some((interface, responder))
428        } else {
429            None
430        }
431    }
432
433    /// Name of the method defined in FIDL
434    pub fn method_name(&self) -> &'static str {
435        match *self {
436            MockPeerRequest::ConnectProxy_ { .. } => "connect_proxy_",
437        }
438    }
439}
440
441#[derive(Debug, Clone)]
442pub struct MockPeerControlHandle {
443    inner: std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>,
444}
445
446impl MockPeerControlHandle {
447    pub fn shutdown_with_epitaph(&self, status: impl Into<fidl::Epitaph>) {
448        self.inner.shutdown_with_epitaph(status.into())
449    }
450}
451
452impl fidl::endpoints::ControlHandle for MockPeerControlHandle {
453    fn shutdown(&self) {
454        self.inner.shutdown()
455    }
456
457    fn shutdown_with_epitaph(&self, status: fidl::Epitaph) {
458        self.inner.shutdown_with_epitaph(status)
459    }
460
461    fn is_closed(&self) -> bool {
462        self.inner.channel().is_closed()
463    }
464    fn on_closed(&self) -> fidl::OnSignalsRef<'_> {
465        self.inner.channel().on_closed()
466    }
467
468    #[cfg(target_os = "fuchsia")]
469    fn signal_peer(
470        &self,
471        clear_mask: zx::Signals,
472        set_mask: zx::Signals,
473    ) -> Result<(), zx_status::Status> {
474        use fidl::Peered;
475        self.inner.channel().signal_peer(clear_mask, set_mask)
476    }
477}
478
479impl MockPeerControlHandle {}
480
481#[must_use = "FIDL methods require a response to be sent"]
482#[derive(Debug)]
483pub struct MockPeerConnectProxy_Responder {
484    control_handle: std::mem::ManuallyDrop<MockPeerControlHandle>,
485    tx_id: u32,
486}
487
488/// Set the the channel to be shutdown (see [`MockPeerControlHandle::shutdown`])
489/// if the responder is dropped without sending a response, so that the client
490/// doesn't hang. To prevent this behavior, call `drop_without_shutdown`.
491impl std::ops::Drop for MockPeerConnectProxy_Responder {
492    fn drop(&mut self) {
493        self.control_handle.shutdown();
494        // Safety: drops once, never accessed again
495        unsafe { std::mem::ManuallyDrop::drop(&mut self.control_handle) };
496    }
497}
498
499impl fidl::endpoints::Responder for MockPeerConnectProxy_Responder {
500    type ControlHandle = MockPeerControlHandle;
501
502    fn control_handle(&self) -> &MockPeerControlHandle {
503        &self.control_handle
504    }
505
506    fn drop_without_shutdown(mut self) {
507        // Safety: drops once, never accessed again due to mem::forget
508        unsafe { std::mem::ManuallyDrop::drop(&mut self.control_handle) };
509        // Prevent Drop from running (which would shut down the channel)
510        std::mem::forget(self);
511    }
512}
513
514impl MockPeerConnectProxy_Responder {
515    /// Sends a response to the FIDL transaction.
516    ///
517    /// Sets the channel to shutdown if an error occurs.
518    pub fn send(self) -> Result<(), fidl::Error> {
519        let _result = self.send_raw();
520        if _result.is_err() {
521            self.control_handle.shutdown();
522        }
523        self.drop_without_shutdown();
524        _result
525    }
526
527    /// Similar to "send" but does not shutdown the channel if an error occurs.
528    pub fn send_no_shutdown_on_err(self) -> Result<(), fidl::Error> {
529        let _result = self.send_raw();
530        self.drop_without_shutdown();
531        _result
532    }
533
534    fn send_raw(&self) -> Result<(), fidl::Error> {
535        self.control_handle.inner.send::<fidl::encoding::EmptyPayload>(
536            (),
537            self.tx_id,
538            0x578ee1f7ee6dd9d8,
539            fidl::encoding::DynamicFlags::empty(),
540        )
541    }
542}
543
544#[derive(Debug, Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Hash)]
545pub struct PeerObserverMarker;
546
547impl fidl::endpoints::ProtocolMarker for PeerObserverMarker {
548    type Proxy = PeerObserverProxy;
549    type RequestStream = PeerObserverRequestStream;
550    #[cfg(target_os = "fuchsia")]
551    type SynchronousProxy = PeerObserverSynchronousProxy;
552
553    const DEBUG_NAME: &'static str = "(anonymous) PeerObserver";
554}
555
556pub trait PeerObserverProxyInterface: Send + Sync {
557    type ServiceFoundResponseFut: std::future::Future<Output = Result<(), fidl::Error>> + Send;
558    fn r#service_found(
559        &self,
560        peer_id: &fidl_fuchsia_bluetooth::PeerId,
561        protocol: Option<&[fidl_fuchsia_bluetooth_bredr::ProtocolDescriptor]>,
562        attributes: &[fidl_fuchsia_bluetooth_bredr::Attribute],
563    ) -> Self::ServiceFoundResponseFut;
564    type PeerConnectedResponseFut: std::future::Future<Output = Result<(), fidl::Error>> + Send;
565    fn r#peer_connected(
566        &self,
567        peer_id: &fidl_fuchsia_bluetooth::PeerId,
568        protocol: &[fidl_fuchsia_bluetooth_bredr::ProtocolDescriptor],
569    ) -> Self::PeerConnectedResponseFut;
570}
571#[derive(Debug)]
572#[cfg(target_os = "fuchsia")]
573pub struct PeerObserverSynchronousProxy {
574    client: fidl::client::sync::Client,
575}
576
577#[cfg(target_os = "fuchsia")]
578impl fidl::endpoints::SynchronousProxy for PeerObserverSynchronousProxy {
579    type Proxy = PeerObserverProxy;
580    type Protocol = PeerObserverMarker;
581
582    fn from_channel(inner: fidl::Channel) -> Self {
583        Self::new(inner)
584    }
585
586    fn into_channel(self) -> fidl::Channel {
587        self.client.into_channel()
588    }
589
590    fn as_channel(&self) -> &fidl::Channel {
591        self.client.as_channel()
592    }
593}
594
595#[cfg(target_os = "fuchsia")]
596impl PeerObserverSynchronousProxy {
597    pub fn new(channel: fidl::Channel) -> Self {
598        Self { client: fidl::client::sync::Client::new(channel) }
599    }
600
601    pub fn into_channel(self) -> fidl::Channel {
602        self.client.into_channel()
603    }
604
605    /// Waits until an event arrives and returns it. It is safe for other
606    /// threads to make concurrent requests while waiting for an event.
607    pub fn wait_for_event(
608        &self,
609        deadline: zx::MonotonicInstant,
610    ) -> Result<PeerObserverEvent, fidl::Error> {
611        PeerObserverEvent::decode(self.client.wait_for_event::<PeerObserverMarker>(deadline)?)
612    }
613
614    /// The peer discovered the services of another peer in the piconet.
615    ///
616    /// + request `peer_id` The peer the service was found on.
617    /// + request `protocol` Includes the ProtocolDescriptorList in the service record.
618    /// + request `attributes` Contains all attributes requested from the search that
619    ///                        are present on the peer record.
620    pub fn r#service_found(
621        &self,
622        mut peer_id: &fidl_fuchsia_bluetooth::PeerId,
623        mut protocol: Option<&[fidl_fuchsia_bluetooth_bredr::ProtocolDescriptor]>,
624        mut attributes: &[fidl_fuchsia_bluetooth_bredr::Attribute],
625        ___deadline: zx::MonotonicInstant,
626    ) -> Result<(), fidl::Error> {
627        let _response = self.client.send_query::<
628            PeerObserverServiceFoundRequest,
629            fidl::encoding::EmptyPayload,
630            PeerObserverMarker,
631        >(
632            (peer_id, protocol, attributes,),
633            0x3b990da866718b5c,
634            fidl::encoding::DynamicFlags::empty(),
635            ___deadline,
636        )?;
637        Ok(_response)
638    }
639
640    /// Called when a peer has connected to a service.
641    ///
642    /// + request `peer_id` The peer that connected to the service.
643    /// + request `protocol` Contains the protocol list of the connection.
644    pub fn r#peer_connected(
645        &self,
646        mut peer_id: &fidl_fuchsia_bluetooth::PeerId,
647        mut protocol: &[fidl_fuchsia_bluetooth_bredr::ProtocolDescriptor],
648        ___deadline: zx::MonotonicInstant,
649    ) -> Result<(), fidl::Error> {
650        let _response = self.client.send_query::<
651            PeerObserverPeerConnectedRequest,
652            fidl::encoding::EmptyPayload,
653            PeerObserverMarker,
654        >(
655            (peer_id, protocol,),
656            0x77ce6712cb60d46c,
657            fidl::encoding::DynamicFlags::empty(),
658            ___deadline,
659        )?;
660        Ok(_response)
661    }
662}
663
664#[cfg(target_os = "fuchsia")]
665impl From<PeerObserverSynchronousProxy> for zx::NullableHandle {
666    fn from(value: PeerObserverSynchronousProxy) -> Self {
667        value.into_channel().into()
668    }
669}
670
671#[cfg(target_os = "fuchsia")]
672impl From<fidl::Channel> for PeerObserverSynchronousProxy {
673    fn from(value: fidl::Channel) -> Self {
674        Self::new(value)
675    }
676}
677
678#[cfg(target_os = "fuchsia")]
679impl fidl::endpoints::FromClient for PeerObserverSynchronousProxy {
680    type Protocol = PeerObserverMarker;
681
682    fn from_client(value: fidl::endpoints::ClientEnd<PeerObserverMarker>) -> Self {
683        Self::new(value.into_channel())
684    }
685}
686
687#[derive(Debug, Clone)]
688pub struct PeerObserverProxy {
689    client: fidl::client::Client<fidl::encoding::DefaultFuchsiaResourceDialect>,
690}
691
692impl fidl::endpoints::Proxy for PeerObserverProxy {
693    type Protocol = PeerObserverMarker;
694
695    fn from_channel(inner: ::fidl::AsyncChannel) -> Self {
696        Self::new(inner)
697    }
698
699    fn into_channel(self) -> Result<::fidl::AsyncChannel, Self> {
700        self.client.into_channel().map_err(|client| Self { client })
701    }
702
703    fn as_channel(&self) -> &::fidl::AsyncChannel {
704        self.client.as_channel()
705    }
706}
707
708impl PeerObserverProxy {
709    /// Create a new Proxy for fuchsia.bluetooth.bredr.test/PeerObserver.
710    pub fn new(channel: ::fidl::AsyncChannel) -> Self {
711        let protocol_name = <PeerObserverMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME;
712        Self { client: fidl::client::Client::new(channel, protocol_name) }
713    }
714
715    /// Get a Stream of events from the remote end of the protocol.
716    ///
717    /// # Panics
718    ///
719    /// Panics if the event stream was already taken.
720    pub fn take_event_stream(&self) -> PeerObserverEventStream {
721        PeerObserverEventStream { event_receiver: self.client.take_event_receiver() }
722    }
723
724    /// The peer discovered the services of another peer in the piconet.
725    ///
726    /// + request `peer_id` The peer the service was found on.
727    /// + request `protocol` Includes the ProtocolDescriptorList in the service record.
728    /// + request `attributes` Contains all attributes requested from the search that
729    ///                        are present on the peer record.
730    pub fn r#service_found(
731        &self,
732        mut peer_id: &fidl_fuchsia_bluetooth::PeerId,
733        mut protocol: Option<&[fidl_fuchsia_bluetooth_bredr::ProtocolDescriptor]>,
734        mut attributes: &[fidl_fuchsia_bluetooth_bredr::Attribute],
735    ) -> fidl::client::QueryResponseFut<(), fidl::encoding::DefaultFuchsiaResourceDialect> {
736        PeerObserverProxyInterface::r#service_found(self, peer_id, protocol, attributes)
737    }
738
739    /// Called when a peer has connected to a service.
740    ///
741    /// + request `peer_id` The peer that connected to the service.
742    /// + request `protocol` Contains the protocol list of the connection.
743    pub fn r#peer_connected(
744        &self,
745        mut peer_id: &fidl_fuchsia_bluetooth::PeerId,
746        mut protocol: &[fidl_fuchsia_bluetooth_bredr::ProtocolDescriptor],
747    ) -> fidl::client::QueryResponseFut<(), fidl::encoding::DefaultFuchsiaResourceDialect> {
748        PeerObserverProxyInterface::r#peer_connected(self, peer_id, protocol)
749    }
750}
751
752impl PeerObserverProxyInterface for PeerObserverProxy {
753    type ServiceFoundResponseFut =
754        fidl::client::QueryResponseFut<(), fidl::encoding::DefaultFuchsiaResourceDialect>;
755    fn r#service_found(
756        &self,
757        mut peer_id: &fidl_fuchsia_bluetooth::PeerId,
758        mut protocol: Option<&[fidl_fuchsia_bluetooth_bredr::ProtocolDescriptor]>,
759        mut attributes: &[fidl_fuchsia_bluetooth_bredr::Attribute],
760    ) -> Self::ServiceFoundResponseFut {
761        fn _decode(
762            mut _buf: Result<<fidl::encoding::DefaultFuchsiaResourceDialect as fidl::encoding::ResourceDialect>::MessageBufEtc, fidl::Error>,
763        ) -> Result<(), fidl::Error> {
764            let _response = fidl::client::decode_transaction_body::<
765                fidl::encoding::EmptyPayload,
766                fidl::encoding::DefaultFuchsiaResourceDialect,
767                0x3b990da866718b5c,
768            >(_buf?)?;
769            Ok(_response)
770        }
771        self.client.send_query_and_decode::<PeerObserverServiceFoundRequest, ()>(
772            (peer_id, protocol, attributes),
773            0x3b990da866718b5c,
774            fidl::encoding::DynamicFlags::empty(),
775            _decode,
776        )
777    }
778
779    type PeerConnectedResponseFut =
780        fidl::client::QueryResponseFut<(), fidl::encoding::DefaultFuchsiaResourceDialect>;
781    fn r#peer_connected(
782        &self,
783        mut peer_id: &fidl_fuchsia_bluetooth::PeerId,
784        mut protocol: &[fidl_fuchsia_bluetooth_bredr::ProtocolDescriptor],
785    ) -> Self::PeerConnectedResponseFut {
786        fn _decode(
787            mut _buf: Result<<fidl::encoding::DefaultFuchsiaResourceDialect as fidl::encoding::ResourceDialect>::MessageBufEtc, fidl::Error>,
788        ) -> Result<(), fidl::Error> {
789            let _response = fidl::client::decode_transaction_body::<
790                fidl::encoding::EmptyPayload,
791                fidl::encoding::DefaultFuchsiaResourceDialect,
792                0x77ce6712cb60d46c,
793            >(_buf?)?;
794            Ok(_response)
795        }
796        self.client.send_query_and_decode::<PeerObserverPeerConnectedRequest, ()>(
797            (peer_id, protocol),
798            0x77ce6712cb60d46c,
799            fidl::encoding::DynamicFlags::empty(),
800            _decode,
801        )
802    }
803}
804
805pub struct PeerObserverEventStream {
806    event_receiver: fidl::client::EventReceiver<fidl::encoding::DefaultFuchsiaResourceDialect>,
807}
808
809impl std::marker::Unpin for PeerObserverEventStream {}
810
811impl futures::stream::FusedStream for PeerObserverEventStream {
812    fn is_terminated(&self) -> bool {
813        self.event_receiver.is_terminated()
814    }
815}
816
817impl futures::Stream for PeerObserverEventStream {
818    type Item = Result<PeerObserverEvent, fidl::Error>;
819
820    fn poll_next(
821        mut self: std::pin::Pin<&mut Self>,
822        cx: &mut std::task::Context<'_>,
823    ) -> std::task::Poll<Option<Self::Item>> {
824        match futures::ready!(futures::stream::StreamExt::poll_next_unpin(
825            &mut self.event_receiver,
826            cx
827        )?) {
828            Some(buf) => std::task::Poll::Ready(Some(PeerObserverEvent::decode(buf))),
829            None => std::task::Poll::Ready(None),
830        }
831    }
832}
833
834#[derive(Debug)]
835pub enum PeerObserverEvent {}
836
837impl PeerObserverEvent {
838    /// Decodes a message buffer as a [`PeerObserverEvent`].
839    fn decode(
840        mut buf: <fidl::encoding::DefaultFuchsiaResourceDialect as fidl::encoding::ResourceDialect>::MessageBufEtc,
841    ) -> Result<PeerObserverEvent, fidl::Error> {
842        let (bytes, _handles) = buf.split_mut();
843        let (tx_header, _body_bytes) = fidl::encoding::decode_transaction_header(bytes)?;
844        debug_assert_eq!(tx_header.tx_id, 0);
845        match tx_header.ordinal {
846            _ => Err(fidl::Error::UnknownOrdinal {
847                ordinal: tx_header.ordinal,
848                protocol_name: <PeerObserverMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME,
849            }),
850        }
851    }
852}
853
854/// A Stream of incoming requests for fuchsia.bluetooth.bredr.test/PeerObserver.
855pub struct PeerObserverRequestStream {
856    inner: std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>,
857    is_terminated: bool,
858}
859
860impl std::marker::Unpin for PeerObserverRequestStream {}
861
862impl futures::stream::FusedStream for PeerObserverRequestStream {
863    fn is_terminated(&self) -> bool {
864        self.is_terminated
865    }
866}
867
868impl fidl::endpoints::RequestStream for PeerObserverRequestStream {
869    type Protocol = PeerObserverMarker;
870    type ControlHandle = PeerObserverControlHandle;
871
872    fn from_channel(channel: ::fidl::AsyncChannel) -> Self {
873        Self { inner: std::sync::Arc::new(fidl::ServeInner::new(channel)), is_terminated: false }
874    }
875
876    fn control_handle(&self) -> Self::ControlHandle {
877        PeerObserverControlHandle { inner: self.inner.clone() }
878    }
879
880    fn into_inner(
881        self,
882    ) -> (::std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>, bool)
883    {
884        (self.inner, self.is_terminated)
885    }
886
887    fn from_inner(
888        inner: std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>,
889        is_terminated: bool,
890    ) -> Self {
891        Self { inner, is_terminated }
892    }
893}
894
895impl futures::Stream for PeerObserverRequestStream {
896    type Item = Result<PeerObserverRequest, fidl::Error>;
897
898    fn poll_next(
899        mut self: std::pin::Pin<&mut Self>,
900        cx: &mut std::task::Context<'_>,
901    ) -> std::task::Poll<Option<Self::Item>> {
902        let this = &mut *self;
903        if this.inner.check_shutdown(cx) {
904            this.is_terminated = true;
905            return std::task::Poll::Ready(None);
906        }
907        if this.is_terminated {
908            panic!("polled PeerObserverRequestStream after completion");
909        }
910        fidl::encoding::with_tls_decode_buf::<_, fidl::encoding::DefaultFuchsiaResourceDialect>(
911            |bytes, handles| {
912                match this.inner.channel().read_etc(cx, bytes, handles) {
913                    std::task::Poll::Ready(Ok(())) => {}
914                    std::task::Poll::Pending => return std::task::Poll::Pending,
915                    std::task::Poll::Ready(Err(zx_status::Status::PEER_CLOSED)) => {
916                        this.is_terminated = true;
917                        return std::task::Poll::Ready(None);
918                    }
919                    std::task::Poll::Ready(Err(e)) => {
920                        return std::task::Poll::Ready(Some(Err(fidl::Error::ServerRequestRead(
921                            e.into(),
922                        ))));
923                    }
924                }
925
926                // A message has been received from the channel
927                let (header, _body_bytes) = fidl::encoding::decode_transaction_header(bytes)?;
928
929                std::task::Poll::Ready(Some(match header.ordinal {
930                    0x3b990da866718b5c => {
931                        header.validate_request_tx_id(fidl::MethodType::TwoWay)?;
932                        let mut req = fidl::new_empty!(
933                            PeerObserverServiceFoundRequest,
934                            fidl::encoding::DefaultFuchsiaResourceDialect
935                        );
936                        fidl::encoding::Decoder::<fidl::encoding::DefaultFuchsiaResourceDialect>::decode_into::<PeerObserverServiceFoundRequest>(&header, _body_bytes, handles, &mut req)?;
937                        let control_handle =
938                            PeerObserverControlHandle { inner: this.inner.clone() };
939                        Ok(PeerObserverRequest::ServiceFound {
940                            peer_id: req.peer_id,
941                            protocol: req.protocol,
942                            attributes: req.attributes,
943
944                            responder: PeerObserverServiceFoundResponder {
945                                control_handle: std::mem::ManuallyDrop::new(control_handle),
946                                tx_id: header.tx_id,
947                            },
948                        })
949                    }
950                    0x77ce6712cb60d46c => {
951                        header.validate_request_tx_id(fidl::MethodType::TwoWay)?;
952                        let mut req = fidl::new_empty!(
953                            PeerObserverPeerConnectedRequest,
954                            fidl::encoding::DefaultFuchsiaResourceDialect
955                        );
956                        fidl::encoding::Decoder::<fidl::encoding::DefaultFuchsiaResourceDialect>::decode_into::<PeerObserverPeerConnectedRequest>(&header, _body_bytes, handles, &mut req)?;
957                        let control_handle =
958                            PeerObserverControlHandle { inner: this.inner.clone() };
959                        Ok(PeerObserverRequest::PeerConnected {
960                            peer_id: req.peer_id,
961                            protocol: req.protocol,
962
963                            responder: PeerObserverPeerConnectedResponder {
964                                control_handle: std::mem::ManuallyDrop::new(control_handle),
965                                tx_id: header.tx_id,
966                            },
967                        })
968                    }
969                    _ => Err(fidl::Error::UnknownOrdinal {
970                        ordinal: header.ordinal,
971                        protocol_name:
972                            <PeerObserverMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME,
973                    }),
974                }))
975            },
976        )
977    }
978}
979
980/// `PeerObserver` provides the integration test client with a way to validate the
981/// behavior of a peer in the piconet.
982/// Dropping `PeerObserver` will stop any subsequent updates for the peer.
983#[derive(Debug)]
984pub enum PeerObserverRequest {
985    /// The peer discovered the services of another peer in the piconet.
986    ///
987    /// + request `peer_id` The peer the service was found on.
988    /// + request `protocol` Includes the ProtocolDescriptorList in the service record.
989    /// + request `attributes` Contains all attributes requested from the search that
990    ///                        are present on the peer record.
991    ServiceFound {
992        peer_id: fidl_fuchsia_bluetooth::PeerId,
993        protocol: Option<Vec<fidl_fuchsia_bluetooth_bredr::ProtocolDescriptor>>,
994        attributes: Vec<fidl_fuchsia_bluetooth_bredr::Attribute>,
995        responder: PeerObserverServiceFoundResponder,
996    },
997    /// Called when a peer has connected to a service.
998    ///
999    /// + request `peer_id` The peer that connected to the service.
1000    /// + request `protocol` Contains the protocol list of the connection.
1001    PeerConnected {
1002        peer_id: fidl_fuchsia_bluetooth::PeerId,
1003        protocol: Vec<fidl_fuchsia_bluetooth_bredr::ProtocolDescriptor>,
1004        responder: PeerObserverPeerConnectedResponder,
1005    },
1006}
1007
1008impl PeerObserverRequest {
1009    #[allow(irrefutable_let_patterns)]
1010    pub fn into_service_found(
1011        self,
1012    ) -> Option<(
1013        fidl_fuchsia_bluetooth::PeerId,
1014        Option<Vec<fidl_fuchsia_bluetooth_bredr::ProtocolDescriptor>>,
1015        Vec<fidl_fuchsia_bluetooth_bredr::Attribute>,
1016        PeerObserverServiceFoundResponder,
1017    )> {
1018        if let PeerObserverRequest::ServiceFound { peer_id, protocol, attributes, responder } = self
1019        {
1020            Some((peer_id, protocol, attributes, responder))
1021        } else {
1022            None
1023        }
1024    }
1025
1026    #[allow(irrefutable_let_patterns)]
1027    pub fn into_peer_connected(
1028        self,
1029    ) -> Option<(
1030        fidl_fuchsia_bluetooth::PeerId,
1031        Vec<fidl_fuchsia_bluetooth_bredr::ProtocolDescriptor>,
1032        PeerObserverPeerConnectedResponder,
1033    )> {
1034        if let PeerObserverRequest::PeerConnected { peer_id, protocol, responder } = self {
1035            Some((peer_id, protocol, responder))
1036        } else {
1037            None
1038        }
1039    }
1040
1041    /// Name of the method defined in FIDL
1042    pub fn method_name(&self) -> &'static str {
1043        match *self {
1044            PeerObserverRequest::ServiceFound { .. } => "service_found",
1045            PeerObserverRequest::PeerConnected { .. } => "peer_connected",
1046        }
1047    }
1048}
1049
1050#[derive(Debug, Clone)]
1051pub struct PeerObserverControlHandle {
1052    inner: std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>,
1053}
1054
1055impl PeerObserverControlHandle {
1056    pub fn shutdown_with_epitaph(&self, status: impl Into<fidl::Epitaph>) {
1057        self.inner.shutdown_with_epitaph(status.into())
1058    }
1059}
1060
1061impl fidl::endpoints::ControlHandle for PeerObserverControlHandle {
1062    fn shutdown(&self) {
1063        self.inner.shutdown()
1064    }
1065
1066    fn shutdown_with_epitaph(&self, status: fidl::Epitaph) {
1067        self.inner.shutdown_with_epitaph(status)
1068    }
1069
1070    fn is_closed(&self) -> bool {
1071        self.inner.channel().is_closed()
1072    }
1073    fn on_closed(&self) -> fidl::OnSignalsRef<'_> {
1074        self.inner.channel().on_closed()
1075    }
1076
1077    #[cfg(target_os = "fuchsia")]
1078    fn signal_peer(
1079        &self,
1080        clear_mask: zx::Signals,
1081        set_mask: zx::Signals,
1082    ) -> Result<(), zx_status::Status> {
1083        use fidl::Peered;
1084        self.inner.channel().signal_peer(clear_mask, set_mask)
1085    }
1086}
1087
1088impl PeerObserverControlHandle {}
1089
1090#[must_use = "FIDL methods require a response to be sent"]
1091#[derive(Debug)]
1092pub struct PeerObserverServiceFoundResponder {
1093    control_handle: std::mem::ManuallyDrop<PeerObserverControlHandle>,
1094    tx_id: u32,
1095}
1096
1097/// Set the the channel to be shutdown (see [`PeerObserverControlHandle::shutdown`])
1098/// if the responder is dropped without sending a response, so that the client
1099/// doesn't hang. To prevent this behavior, call `drop_without_shutdown`.
1100impl std::ops::Drop for PeerObserverServiceFoundResponder {
1101    fn drop(&mut self) {
1102        self.control_handle.shutdown();
1103        // Safety: drops once, never accessed again
1104        unsafe { std::mem::ManuallyDrop::drop(&mut self.control_handle) };
1105    }
1106}
1107
1108impl fidl::endpoints::Responder for PeerObserverServiceFoundResponder {
1109    type ControlHandle = PeerObserverControlHandle;
1110
1111    fn control_handle(&self) -> &PeerObserverControlHandle {
1112        &self.control_handle
1113    }
1114
1115    fn drop_without_shutdown(mut self) {
1116        // Safety: drops once, never accessed again due to mem::forget
1117        unsafe { std::mem::ManuallyDrop::drop(&mut self.control_handle) };
1118        // Prevent Drop from running (which would shut down the channel)
1119        std::mem::forget(self);
1120    }
1121}
1122
1123impl PeerObserverServiceFoundResponder {
1124    /// Sends a response to the FIDL transaction.
1125    ///
1126    /// Sets the channel to shutdown if an error occurs.
1127    pub fn send(self) -> Result<(), fidl::Error> {
1128        let _result = self.send_raw();
1129        if _result.is_err() {
1130            self.control_handle.shutdown();
1131        }
1132        self.drop_without_shutdown();
1133        _result
1134    }
1135
1136    /// Similar to "send" but does not shutdown the channel if an error occurs.
1137    pub fn send_no_shutdown_on_err(self) -> Result<(), fidl::Error> {
1138        let _result = self.send_raw();
1139        self.drop_without_shutdown();
1140        _result
1141    }
1142
1143    fn send_raw(&self) -> Result<(), fidl::Error> {
1144        self.control_handle.inner.send::<fidl::encoding::EmptyPayload>(
1145            (),
1146            self.tx_id,
1147            0x3b990da866718b5c,
1148            fidl::encoding::DynamicFlags::empty(),
1149        )
1150    }
1151}
1152
1153#[must_use = "FIDL methods require a response to be sent"]
1154#[derive(Debug)]
1155pub struct PeerObserverPeerConnectedResponder {
1156    control_handle: std::mem::ManuallyDrop<PeerObserverControlHandle>,
1157    tx_id: u32,
1158}
1159
1160/// Set the the channel to be shutdown (see [`PeerObserverControlHandle::shutdown`])
1161/// if the responder is dropped without sending a response, so that the client
1162/// doesn't hang. To prevent this behavior, call `drop_without_shutdown`.
1163impl std::ops::Drop for PeerObserverPeerConnectedResponder {
1164    fn drop(&mut self) {
1165        self.control_handle.shutdown();
1166        // Safety: drops once, never accessed again
1167        unsafe { std::mem::ManuallyDrop::drop(&mut self.control_handle) };
1168    }
1169}
1170
1171impl fidl::endpoints::Responder for PeerObserverPeerConnectedResponder {
1172    type ControlHandle = PeerObserverControlHandle;
1173
1174    fn control_handle(&self) -> &PeerObserverControlHandle {
1175        &self.control_handle
1176    }
1177
1178    fn drop_without_shutdown(mut self) {
1179        // Safety: drops once, never accessed again due to mem::forget
1180        unsafe { std::mem::ManuallyDrop::drop(&mut self.control_handle) };
1181        // Prevent Drop from running (which would shut down the channel)
1182        std::mem::forget(self);
1183    }
1184}
1185
1186impl PeerObserverPeerConnectedResponder {
1187    /// Sends a response to the FIDL transaction.
1188    ///
1189    /// Sets the channel to shutdown if an error occurs.
1190    pub fn send(self) -> Result<(), fidl::Error> {
1191        let _result = self.send_raw();
1192        if _result.is_err() {
1193            self.control_handle.shutdown();
1194        }
1195        self.drop_without_shutdown();
1196        _result
1197    }
1198
1199    /// Similar to "send" but does not shutdown the channel if an error occurs.
1200    pub fn send_no_shutdown_on_err(self) -> Result<(), fidl::Error> {
1201        let _result = self.send_raw();
1202        self.drop_without_shutdown();
1203        _result
1204    }
1205
1206    fn send_raw(&self) -> Result<(), fidl::Error> {
1207        self.control_handle.inner.send::<fidl::encoding::EmptyPayload>(
1208            (),
1209            self.tx_id,
1210            0x77ce6712cb60d46c,
1211            fidl::encoding::DynamicFlags::empty(),
1212        )
1213    }
1214}
1215
1216#[derive(Debug, Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Hash)]
1217pub struct ProfileTestMarker;
1218
1219impl fidl::endpoints::ProtocolMarker for ProfileTestMarker {
1220    type Proxy = ProfileTestProxy;
1221    type RequestStream = ProfileTestRequestStream;
1222    #[cfg(target_os = "fuchsia")]
1223    type SynchronousProxy = ProfileTestSynchronousProxy;
1224
1225    const DEBUG_NAME: &'static str = "fuchsia.bluetooth.bredr.test.ProfileTest";
1226}
1227impl fidl::endpoints::DiscoverableProtocolMarker for ProfileTestMarker {}
1228
1229pub trait ProfileTestProxyInterface: Send + Sync {
1230    type RegisterPeerResponseFut: std::future::Future<Output = Result<(), fidl::Error>> + Send;
1231    fn r#register_peer(
1232        &self,
1233        peer_id: &fidl_fuchsia_bluetooth::PeerId,
1234        peer: fidl::endpoints::ServerEnd<MockPeerMarker>,
1235        observer: fidl::endpoints::ClientEnd<PeerObserverMarker>,
1236    ) -> Self::RegisterPeerResponseFut;
1237}
1238#[derive(Debug)]
1239#[cfg(target_os = "fuchsia")]
1240pub struct ProfileTestSynchronousProxy {
1241    client: fidl::client::sync::Client,
1242}
1243
1244#[cfg(target_os = "fuchsia")]
1245impl fidl::endpoints::SynchronousProxy for ProfileTestSynchronousProxy {
1246    type Proxy = ProfileTestProxy;
1247    type Protocol = ProfileTestMarker;
1248
1249    fn from_channel(inner: fidl::Channel) -> Self {
1250        Self::new(inner)
1251    }
1252
1253    fn into_channel(self) -> fidl::Channel {
1254        self.client.into_channel()
1255    }
1256
1257    fn as_channel(&self) -> &fidl::Channel {
1258        self.client.as_channel()
1259    }
1260}
1261
1262#[cfg(target_os = "fuchsia")]
1263impl ProfileTestSynchronousProxy {
1264    pub fn new(channel: fidl::Channel) -> Self {
1265        Self { client: fidl::client::sync::Client::new(channel) }
1266    }
1267
1268    pub fn into_channel(self) -> fidl::Channel {
1269        self.client.into_channel()
1270    }
1271
1272    /// Waits until an event arrives and returns it. It is safe for other
1273    /// threads to make concurrent requests while waiting for an event.
1274    pub fn wait_for_event(
1275        &self,
1276        deadline: zx::MonotonicInstant,
1277    ) -> Result<ProfileTestEvent, fidl::Error> {
1278        ProfileTestEvent::decode(self.client.wait_for_event::<ProfileTestMarker>(deadline)?)
1279    }
1280
1281    /// Creates a new fake peer in the Profile Test Server database. An empty response is
1282    /// sent to indicate when registration is complete.
1283    ///
1284    /// Use the provided [`PeerObserver`] interface to observe behavior of the registered peer.
1285    /// Dropping the `observer` will cease the updates from the server for the associated peer.
1286    ///
1287    /// If registration is unsuccessful, the `peer` and `observer` will be closed.
1288    ///
1289    /// + request `peer_id` Identifier for the created peer.
1290    /// + request `peer` Handle that can be used to drive peer behavior using the
1291    ///                  [`fuchsia.blueooth.bredr.MockPeer`] interface.
1292    /// + request `observer` Relay for communicating updates from the mock peer.
1293    pub fn r#register_peer(
1294        &self,
1295        mut peer_id: &fidl_fuchsia_bluetooth::PeerId,
1296        mut peer: fidl::endpoints::ServerEnd<MockPeerMarker>,
1297        mut observer: fidl::endpoints::ClientEnd<PeerObserverMarker>,
1298        ___deadline: zx::MonotonicInstant,
1299    ) -> Result<(), fidl::Error> {
1300        let _response = self.client.send_query::<
1301            ProfileTestRegisterPeerRequest,
1302            fidl::encoding::EmptyPayload,
1303            ProfileTestMarker,
1304        >(
1305            (peer_id, peer, observer,),
1306            0x4cb156cd976ac1a8,
1307            fidl::encoding::DynamicFlags::empty(),
1308            ___deadline,
1309        )?;
1310        Ok(_response)
1311    }
1312}
1313
1314#[cfg(target_os = "fuchsia")]
1315impl From<ProfileTestSynchronousProxy> for zx::NullableHandle {
1316    fn from(value: ProfileTestSynchronousProxy) -> Self {
1317        value.into_channel().into()
1318    }
1319}
1320
1321#[cfg(target_os = "fuchsia")]
1322impl From<fidl::Channel> for ProfileTestSynchronousProxy {
1323    fn from(value: fidl::Channel) -> Self {
1324        Self::new(value)
1325    }
1326}
1327
1328#[cfg(target_os = "fuchsia")]
1329impl fidl::endpoints::FromClient for ProfileTestSynchronousProxy {
1330    type Protocol = ProfileTestMarker;
1331
1332    fn from_client(value: fidl::endpoints::ClientEnd<ProfileTestMarker>) -> Self {
1333        Self::new(value.into_channel())
1334    }
1335}
1336
1337#[derive(Debug, Clone)]
1338pub struct ProfileTestProxy {
1339    client: fidl::client::Client<fidl::encoding::DefaultFuchsiaResourceDialect>,
1340}
1341
1342impl fidl::endpoints::Proxy for ProfileTestProxy {
1343    type Protocol = ProfileTestMarker;
1344
1345    fn from_channel(inner: ::fidl::AsyncChannel) -> Self {
1346        Self::new(inner)
1347    }
1348
1349    fn into_channel(self) -> Result<::fidl::AsyncChannel, Self> {
1350        self.client.into_channel().map_err(|client| Self { client })
1351    }
1352
1353    fn as_channel(&self) -> &::fidl::AsyncChannel {
1354        self.client.as_channel()
1355    }
1356}
1357
1358impl ProfileTestProxy {
1359    /// Create a new Proxy for fuchsia.bluetooth.bredr.test/ProfileTest.
1360    pub fn new(channel: ::fidl::AsyncChannel) -> Self {
1361        let protocol_name = <ProfileTestMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME;
1362        Self { client: fidl::client::Client::new(channel, protocol_name) }
1363    }
1364
1365    /// Get a Stream of events from the remote end of the protocol.
1366    ///
1367    /// # Panics
1368    ///
1369    /// Panics if the event stream was already taken.
1370    pub fn take_event_stream(&self) -> ProfileTestEventStream {
1371        ProfileTestEventStream { event_receiver: self.client.take_event_receiver() }
1372    }
1373
1374    /// Creates a new fake peer in the Profile Test Server database. An empty response is
1375    /// sent to indicate when registration is complete.
1376    ///
1377    /// Use the provided [`PeerObserver`] interface to observe behavior of the registered peer.
1378    /// Dropping the `observer` will cease the updates from the server for the associated peer.
1379    ///
1380    /// If registration is unsuccessful, the `peer` and `observer` will be closed.
1381    ///
1382    /// + request `peer_id` Identifier for the created peer.
1383    /// + request `peer` Handle that can be used to drive peer behavior using the
1384    ///                  [`fuchsia.blueooth.bredr.MockPeer`] interface.
1385    /// + request `observer` Relay for communicating updates from the mock peer.
1386    pub fn r#register_peer(
1387        &self,
1388        mut peer_id: &fidl_fuchsia_bluetooth::PeerId,
1389        mut peer: fidl::endpoints::ServerEnd<MockPeerMarker>,
1390        mut observer: fidl::endpoints::ClientEnd<PeerObserverMarker>,
1391    ) -> fidl::client::QueryResponseFut<(), fidl::encoding::DefaultFuchsiaResourceDialect> {
1392        ProfileTestProxyInterface::r#register_peer(self, peer_id, peer, observer)
1393    }
1394}
1395
1396impl ProfileTestProxyInterface for ProfileTestProxy {
1397    type RegisterPeerResponseFut =
1398        fidl::client::QueryResponseFut<(), fidl::encoding::DefaultFuchsiaResourceDialect>;
1399    fn r#register_peer(
1400        &self,
1401        mut peer_id: &fidl_fuchsia_bluetooth::PeerId,
1402        mut peer: fidl::endpoints::ServerEnd<MockPeerMarker>,
1403        mut observer: fidl::endpoints::ClientEnd<PeerObserverMarker>,
1404    ) -> Self::RegisterPeerResponseFut {
1405        fn _decode(
1406            mut _buf: Result<<fidl::encoding::DefaultFuchsiaResourceDialect as fidl::encoding::ResourceDialect>::MessageBufEtc, fidl::Error>,
1407        ) -> Result<(), fidl::Error> {
1408            let _response = fidl::client::decode_transaction_body::<
1409                fidl::encoding::EmptyPayload,
1410                fidl::encoding::DefaultFuchsiaResourceDialect,
1411                0x4cb156cd976ac1a8,
1412            >(_buf?)?;
1413            Ok(_response)
1414        }
1415        self.client.send_query_and_decode::<ProfileTestRegisterPeerRequest, ()>(
1416            (peer_id, peer, observer),
1417            0x4cb156cd976ac1a8,
1418            fidl::encoding::DynamicFlags::empty(),
1419            _decode,
1420        )
1421    }
1422}
1423
1424pub struct ProfileTestEventStream {
1425    event_receiver: fidl::client::EventReceiver<fidl::encoding::DefaultFuchsiaResourceDialect>,
1426}
1427
1428impl std::marker::Unpin for ProfileTestEventStream {}
1429
1430impl futures::stream::FusedStream for ProfileTestEventStream {
1431    fn is_terminated(&self) -> bool {
1432        self.event_receiver.is_terminated()
1433    }
1434}
1435
1436impl futures::Stream for ProfileTestEventStream {
1437    type Item = Result<ProfileTestEvent, fidl::Error>;
1438
1439    fn poll_next(
1440        mut self: std::pin::Pin<&mut Self>,
1441        cx: &mut std::task::Context<'_>,
1442    ) -> std::task::Poll<Option<Self::Item>> {
1443        match futures::ready!(futures::stream::StreamExt::poll_next_unpin(
1444            &mut self.event_receiver,
1445            cx
1446        )?) {
1447            Some(buf) => std::task::Poll::Ready(Some(ProfileTestEvent::decode(buf))),
1448            None => std::task::Poll::Ready(None),
1449        }
1450    }
1451}
1452
1453#[derive(Debug)]
1454pub enum ProfileTestEvent {}
1455
1456impl ProfileTestEvent {
1457    /// Decodes a message buffer as a [`ProfileTestEvent`].
1458    fn decode(
1459        mut buf: <fidl::encoding::DefaultFuchsiaResourceDialect as fidl::encoding::ResourceDialect>::MessageBufEtc,
1460    ) -> Result<ProfileTestEvent, fidl::Error> {
1461        let (bytes, _handles) = buf.split_mut();
1462        let (tx_header, _body_bytes) = fidl::encoding::decode_transaction_header(bytes)?;
1463        debug_assert_eq!(tx_header.tx_id, 0);
1464        match tx_header.ordinal {
1465            _ => Err(fidl::Error::UnknownOrdinal {
1466                ordinal: tx_header.ordinal,
1467                protocol_name: <ProfileTestMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME,
1468            }),
1469        }
1470    }
1471}
1472
1473/// A Stream of incoming requests for fuchsia.bluetooth.bredr.test/ProfileTest.
1474pub struct ProfileTestRequestStream {
1475    inner: std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>,
1476    is_terminated: bool,
1477}
1478
1479impl std::marker::Unpin for ProfileTestRequestStream {}
1480
1481impl futures::stream::FusedStream for ProfileTestRequestStream {
1482    fn is_terminated(&self) -> bool {
1483        self.is_terminated
1484    }
1485}
1486
1487impl fidl::endpoints::RequestStream for ProfileTestRequestStream {
1488    type Protocol = ProfileTestMarker;
1489    type ControlHandle = ProfileTestControlHandle;
1490
1491    fn from_channel(channel: ::fidl::AsyncChannel) -> Self {
1492        Self { inner: std::sync::Arc::new(fidl::ServeInner::new(channel)), is_terminated: false }
1493    }
1494
1495    fn control_handle(&self) -> Self::ControlHandle {
1496        ProfileTestControlHandle { inner: self.inner.clone() }
1497    }
1498
1499    fn into_inner(
1500        self,
1501    ) -> (::std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>, bool)
1502    {
1503        (self.inner, self.is_terminated)
1504    }
1505
1506    fn from_inner(
1507        inner: std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>,
1508        is_terminated: bool,
1509    ) -> Self {
1510        Self { inner, is_terminated }
1511    }
1512}
1513
1514impl futures::Stream for ProfileTestRequestStream {
1515    type Item = Result<ProfileTestRequest, fidl::Error>;
1516
1517    fn poll_next(
1518        mut self: std::pin::Pin<&mut Self>,
1519        cx: &mut std::task::Context<'_>,
1520    ) -> std::task::Poll<Option<Self::Item>> {
1521        let this = &mut *self;
1522        if this.inner.check_shutdown(cx) {
1523            this.is_terminated = true;
1524            return std::task::Poll::Ready(None);
1525        }
1526        if this.is_terminated {
1527            panic!("polled ProfileTestRequestStream after completion");
1528        }
1529        fidl::encoding::with_tls_decode_buf::<_, fidl::encoding::DefaultFuchsiaResourceDialect>(
1530            |bytes, handles| {
1531                match this.inner.channel().read_etc(cx, bytes, handles) {
1532                    std::task::Poll::Ready(Ok(())) => {}
1533                    std::task::Poll::Pending => return std::task::Poll::Pending,
1534                    std::task::Poll::Ready(Err(zx_status::Status::PEER_CLOSED)) => {
1535                        this.is_terminated = true;
1536                        return std::task::Poll::Ready(None);
1537                    }
1538                    std::task::Poll::Ready(Err(e)) => {
1539                        return std::task::Poll::Ready(Some(Err(fidl::Error::ServerRequestRead(
1540                            e.into(),
1541                        ))));
1542                    }
1543                }
1544
1545                // A message has been received from the channel
1546                let (header, _body_bytes) = fidl::encoding::decode_transaction_header(bytes)?;
1547
1548                std::task::Poll::Ready(Some(match header.ordinal {
1549                    0x4cb156cd976ac1a8 => {
1550                        header.validate_request_tx_id(fidl::MethodType::TwoWay)?;
1551                        let mut req = fidl::new_empty!(
1552                            ProfileTestRegisterPeerRequest,
1553                            fidl::encoding::DefaultFuchsiaResourceDialect
1554                        );
1555                        fidl::encoding::Decoder::<fidl::encoding::DefaultFuchsiaResourceDialect>::decode_into::<ProfileTestRegisterPeerRequest>(&header, _body_bytes, handles, &mut req)?;
1556                        let control_handle = ProfileTestControlHandle { inner: this.inner.clone() };
1557                        Ok(ProfileTestRequest::RegisterPeer {
1558                            peer_id: req.peer_id,
1559                            peer: req.peer,
1560                            observer: req.observer,
1561
1562                            responder: ProfileTestRegisterPeerResponder {
1563                                control_handle: std::mem::ManuallyDrop::new(control_handle),
1564                                tx_id: header.tx_id,
1565                            },
1566                        })
1567                    }
1568                    _ => Err(fidl::Error::UnknownOrdinal {
1569                        ordinal: header.ordinal,
1570                        protocol_name:
1571                            <ProfileTestMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME,
1572                    }),
1573                }))
1574            },
1575        )
1576    }
1577}
1578
1579/// The `ProfileTest` interface should be used to validate behavior of Bluetooth Profiles
1580/// that use the [`fuchsia.bluetooth.bredr.Profile`] service.
1581///
1582/// The ProfileTest interface is used to create and manage fake peers.
1583/// A mock piconet is created in which registered peers can discover and interact with
1584/// each other.
1585#[derive(Debug)]
1586pub enum ProfileTestRequest {
1587    /// Creates a new fake peer in the Profile Test Server database. An empty response is
1588    /// sent to indicate when registration is complete.
1589    ///
1590    /// Use the provided [`PeerObserver`] interface to observe behavior of the registered peer.
1591    /// Dropping the `observer` will cease the updates from the server for the associated peer.
1592    ///
1593    /// If registration is unsuccessful, the `peer` and `observer` will be closed.
1594    ///
1595    /// + request `peer_id` Identifier for the created peer.
1596    /// + request `peer` Handle that can be used to drive peer behavior using the
1597    ///                  [`fuchsia.blueooth.bredr.MockPeer`] interface.
1598    /// + request `observer` Relay for communicating updates from the mock peer.
1599    RegisterPeer {
1600        peer_id: fidl_fuchsia_bluetooth::PeerId,
1601        peer: fidl::endpoints::ServerEnd<MockPeerMarker>,
1602        observer: fidl::endpoints::ClientEnd<PeerObserverMarker>,
1603        responder: ProfileTestRegisterPeerResponder,
1604    },
1605}
1606
1607impl ProfileTestRequest {
1608    #[allow(irrefutable_let_patterns)]
1609    pub fn into_register_peer(
1610        self,
1611    ) -> Option<(
1612        fidl_fuchsia_bluetooth::PeerId,
1613        fidl::endpoints::ServerEnd<MockPeerMarker>,
1614        fidl::endpoints::ClientEnd<PeerObserverMarker>,
1615        ProfileTestRegisterPeerResponder,
1616    )> {
1617        if let ProfileTestRequest::RegisterPeer { peer_id, peer, observer, responder } = self {
1618            Some((peer_id, peer, observer, responder))
1619        } else {
1620            None
1621        }
1622    }
1623
1624    /// Name of the method defined in FIDL
1625    pub fn method_name(&self) -> &'static str {
1626        match *self {
1627            ProfileTestRequest::RegisterPeer { .. } => "register_peer",
1628        }
1629    }
1630}
1631
1632#[derive(Debug, Clone)]
1633pub struct ProfileTestControlHandle {
1634    inner: std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>,
1635}
1636
1637impl ProfileTestControlHandle {
1638    pub fn shutdown_with_epitaph(&self, status: impl Into<fidl::Epitaph>) {
1639        self.inner.shutdown_with_epitaph(status.into())
1640    }
1641}
1642
1643impl fidl::endpoints::ControlHandle for ProfileTestControlHandle {
1644    fn shutdown(&self) {
1645        self.inner.shutdown()
1646    }
1647
1648    fn shutdown_with_epitaph(&self, status: fidl::Epitaph) {
1649        self.inner.shutdown_with_epitaph(status)
1650    }
1651
1652    fn is_closed(&self) -> bool {
1653        self.inner.channel().is_closed()
1654    }
1655    fn on_closed(&self) -> fidl::OnSignalsRef<'_> {
1656        self.inner.channel().on_closed()
1657    }
1658
1659    #[cfg(target_os = "fuchsia")]
1660    fn signal_peer(
1661        &self,
1662        clear_mask: zx::Signals,
1663        set_mask: zx::Signals,
1664    ) -> Result<(), zx_status::Status> {
1665        use fidl::Peered;
1666        self.inner.channel().signal_peer(clear_mask, set_mask)
1667    }
1668}
1669
1670impl ProfileTestControlHandle {}
1671
1672#[must_use = "FIDL methods require a response to be sent"]
1673#[derive(Debug)]
1674pub struct ProfileTestRegisterPeerResponder {
1675    control_handle: std::mem::ManuallyDrop<ProfileTestControlHandle>,
1676    tx_id: u32,
1677}
1678
1679/// Set the the channel to be shutdown (see [`ProfileTestControlHandle::shutdown`])
1680/// if the responder is dropped without sending a response, so that the client
1681/// doesn't hang. To prevent this behavior, call `drop_without_shutdown`.
1682impl std::ops::Drop for ProfileTestRegisterPeerResponder {
1683    fn drop(&mut self) {
1684        self.control_handle.shutdown();
1685        // Safety: drops once, never accessed again
1686        unsafe { std::mem::ManuallyDrop::drop(&mut self.control_handle) };
1687    }
1688}
1689
1690impl fidl::endpoints::Responder for ProfileTestRegisterPeerResponder {
1691    type ControlHandle = ProfileTestControlHandle;
1692
1693    fn control_handle(&self) -> &ProfileTestControlHandle {
1694        &self.control_handle
1695    }
1696
1697    fn drop_without_shutdown(mut self) {
1698        // Safety: drops once, never accessed again due to mem::forget
1699        unsafe { std::mem::ManuallyDrop::drop(&mut self.control_handle) };
1700        // Prevent Drop from running (which would shut down the channel)
1701        std::mem::forget(self);
1702    }
1703}
1704
1705impl ProfileTestRegisterPeerResponder {
1706    /// Sends a response to the FIDL transaction.
1707    ///
1708    /// Sets the channel to shutdown if an error occurs.
1709    pub fn send(self) -> Result<(), fidl::Error> {
1710        let _result = self.send_raw();
1711        if _result.is_err() {
1712            self.control_handle.shutdown();
1713        }
1714        self.drop_without_shutdown();
1715        _result
1716    }
1717
1718    /// Similar to "send" but does not shutdown the channel if an error occurs.
1719    pub fn send_no_shutdown_on_err(self) -> Result<(), fidl::Error> {
1720        let _result = self.send_raw();
1721        self.drop_without_shutdown();
1722        _result
1723    }
1724
1725    fn send_raw(&self) -> Result<(), fidl::Error> {
1726        self.control_handle.inner.send::<fidl::encoding::EmptyPayload>(
1727            (),
1728            self.tx_id,
1729            0x4cb156cd976ac1a8,
1730            fidl::encoding::DynamicFlags::empty(),
1731        )
1732    }
1733}
1734
1735mod internal {
1736    use super::*;
1737
1738    impl fidl::encoding::ResourceTypeMarker for MockPeerConnectProxyRequest {
1739        type Borrowed<'a> = &'a mut Self;
1740        fn take_or_borrow<'a>(
1741            value: &'a mut <Self as fidl::encoding::TypeMarker>::Owned,
1742        ) -> Self::Borrowed<'a> {
1743            value
1744        }
1745    }
1746
1747    unsafe impl fidl::encoding::TypeMarker for MockPeerConnectProxyRequest {
1748        type Owned = Self;
1749
1750        #[inline(always)]
1751        fn inline_align(_context: fidl::encoding::Context) -> usize {
1752            4
1753        }
1754
1755        #[inline(always)]
1756        fn inline_size(_context: fidl::encoding::Context) -> usize {
1757            4
1758        }
1759    }
1760
1761    unsafe impl
1762        fidl::encoding::Encode<
1763            MockPeerConnectProxyRequest,
1764            fidl::encoding::DefaultFuchsiaResourceDialect,
1765        > for &mut MockPeerConnectProxyRequest
1766    {
1767        #[inline]
1768        unsafe fn encode(
1769            self,
1770            encoder: &mut fidl::encoding::Encoder<
1771                '_,
1772                fidl::encoding::DefaultFuchsiaResourceDialect,
1773            >,
1774            offset: usize,
1775            _depth: fidl::encoding::Depth,
1776        ) -> fidl::Result<()> {
1777            encoder.debug_check_bounds::<MockPeerConnectProxyRequest>(offset);
1778            // Delegate to tuple encoding.
1779            fidl::encoding::Encode::<
1780                MockPeerConnectProxyRequest,
1781                fidl::encoding::DefaultFuchsiaResourceDialect,
1782            >::encode(
1783                (<fidl::encoding::Endpoint<
1784                    fidl::endpoints::ServerEnd<fidl_fuchsia_bluetooth_bredr::ProfileMarker>,
1785                > as fidl::encoding::ResourceTypeMarker>::take_or_borrow(
1786                    &mut self.interface
1787                ),),
1788                encoder,
1789                offset,
1790                _depth,
1791            )
1792        }
1793    }
1794    unsafe impl<
1795        T0: fidl::encoding::Encode<
1796                fidl::encoding::Endpoint<
1797                    fidl::endpoints::ServerEnd<fidl_fuchsia_bluetooth_bredr::ProfileMarker>,
1798                >,
1799                fidl::encoding::DefaultFuchsiaResourceDialect,
1800            >,
1801    >
1802        fidl::encoding::Encode<
1803            MockPeerConnectProxyRequest,
1804            fidl::encoding::DefaultFuchsiaResourceDialect,
1805        > for (T0,)
1806    {
1807        #[inline]
1808        unsafe fn encode(
1809            self,
1810            encoder: &mut fidl::encoding::Encoder<
1811                '_,
1812                fidl::encoding::DefaultFuchsiaResourceDialect,
1813            >,
1814            offset: usize,
1815            depth: fidl::encoding::Depth,
1816        ) -> fidl::Result<()> {
1817            encoder.debug_check_bounds::<MockPeerConnectProxyRequest>(offset);
1818            // Zero out padding regions. There's no need to apply masks
1819            // because the unmasked parts will be overwritten by fields.
1820            // Write the fields.
1821            self.0.encode(encoder, offset + 0, depth)?;
1822            Ok(())
1823        }
1824    }
1825
1826    impl fidl::encoding::Decode<Self, fidl::encoding::DefaultFuchsiaResourceDialect>
1827        for MockPeerConnectProxyRequest
1828    {
1829        #[inline(always)]
1830        fn new_empty() -> Self {
1831            Self {
1832                interface: fidl::new_empty!(
1833                    fidl::encoding::Endpoint<
1834                        fidl::endpoints::ServerEnd<fidl_fuchsia_bluetooth_bredr::ProfileMarker>,
1835                    >,
1836                    fidl::encoding::DefaultFuchsiaResourceDialect
1837                ),
1838            }
1839        }
1840
1841        #[inline]
1842        unsafe fn decode(
1843            &mut self,
1844            decoder: &mut fidl::encoding::Decoder<
1845                '_,
1846                fidl::encoding::DefaultFuchsiaResourceDialect,
1847            >,
1848            offset: usize,
1849            _depth: fidl::encoding::Depth,
1850        ) -> fidl::Result<()> {
1851            decoder.debug_check_bounds::<Self>(offset);
1852            // Verify that padding bytes are zero.
1853            fidl::decode!(
1854                fidl::encoding::Endpoint<
1855                    fidl::endpoints::ServerEnd<fidl_fuchsia_bluetooth_bredr::ProfileMarker>,
1856                >,
1857                fidl::encoding::DefaultFuchsiaResourceDialect,
1858                &mut self.interface,
1859                decoder,
1860                offset + 0,
1861                _depth
1862            )?;
1863            Ok(())
1864        }
1865    }
1866
1867    impl fidl::encoding::ResourceTypeMarker for ProfileTestRegisterPeerRequest {
1868        type Borrowed<'a> = &'a mut Self;
1869        fn take_or_borrow<'a>(
1870            value: &'a mut <Self as fidl::encoding::TypeMarker>::Owned,
1871        ) -> Self::Borrowed<'a> {
1872            value
1873        }
1874    }
1875
1876    unsafe impl fidl::encoding::TypeMarker for ProfileTestRegisterPeerRequest {
1877        type Owned = Self;
1878
1879        #[inline(always)]
1880        fn inline_align(_context: fidl::encoding::Context) -> usize {
1881            8
1882        }
1883
1884        #[inline(always)]
1885        fn inline_size(_context: fidl::encoding::Context) -> usize {
1886            16
1887        }
1888    }
1889
1890    unsafe impl
1891        fidl::encoding::Encode<
1892            ProfileTestRegisterPeerRequest,
1893            fidl::encoding::DefaultFuchsiaResourceDialect,
1894        > for &mut ProfileTestRegisterPeerRequest
1895    {
1896        #[inline]
1897        unsafe fn encode(
1898            self,
1899            encoder: &mut fidl::encoding::Encoder<
1900                '_,
1901                fidl::encoding::DefaultFuchsiaResourceDialect,
1902            >,
1903            offset: usize,
1904            _depth: fidl::encoding::Depth,
1905        ) -> fidl::Result<()> {
1906            encoder.debug_check_bounds::<ProfileTestRegisterPeerRequest>(offset);
1907            // Delegate to tuple encoding.
1908            fidl::encoding::Encode::<ProfileTestRegisterPeerRequest, fidl::encoding::DefaultFuchsiaResourceDialect>::encode(
1909                (
1910                    <fidl_fuchsia_bluetooth::PeerId as fidl::encoding::ValueTypeMarker>::borrow(&self.peer_id),
1911                    <fidl::encoding::Endpoint<fidl::endpoints::ServerEnd<MockPeerMarker>> as fidl::encoding::ResourceTypeMarker>::take_or_borrow(&mut self.peer),
1912                    <fidl::encoding::Endpoint<fidl::endpoints::ClientEnd<PeerObserverMarker>> as fidl::encoding::ResourceTypeMarker>::take_or_borrow(&mut self.observer),
1913                ),
1914                encoder, offset, _depth
1915            )
1916        }
1917    }
1918    unsafe impl<
1919        T0: fidl::encoding::Encode<
1920                fidl_fuchsia_bluetooth::PeerId,
1921                fidl::encoding::DefaultFuchsiaResourceDialect,
1922            >,
1923        T1: fidl::encoding::Encode<
1924                fidl::encoding::Endpoint<fidl::endpoints::ServerEnd<MockPeerMarker>>,
1925                fidl::encoding::DefaultFuchsiaResourceDialect,
1926            >,
1927        T2: fidl::encoding::Encode<
1928                fidl::encoding::Endpoint<fidl::endpoints::ClientEnd<PeerObserverMarker>>,
1929                fidl::encoding::DefaultFuchsiaResourceDialect,
1930            >,
1931    >
1932        fidl::encoding::Encode<
1933            ProfileTestRegisterPeerRequest,
1934            fidl::encoding::DefaultFuchsiaResourceDialect,
1935        > for (T0, T1, T2)
1936    {
1937        #[inline]
1938        unsafe fn encode(
1939            self,
1940            encoder: &mut fidl::encoding::Encoder<
1941                '_,
1942                fidl::encoding::DefaultFuchsiaResourceDialect,
1943            >,
1944            offset: usize,
1945            depth: fidl::encoding::Depth,
1946        ) -> fidl::Result<()> {
1947            encoder.debug_check_bounds::<ProfileTestRegisterPeerRequest>(offset);
1948            // Zero out padding regions. There's no need to apply masks
1949            // because the unmasked parts will be overwritten by fields.
1950            // Write the fields.
1951            self.0.encode(encoder, offset + 0, depth)?;
1952            self.1.encode(encoder, offset + 8, depth)?;
1953            self.2.encode(encoder, offset + 12, depth)?;
1954            Ok(())
1955        }
1956    }
1957
1958    impl fidl::encoding::Decode<Self, fidl::encoding::DefaultFuchsiaResourceDialect>
1959        for ProfileTestRegisterPeerRequest
1960    {
1961        #[inline(always)]
1962        fn new_empty() -> Self {
1963            Self {
1964                peer_id: fidl::new_empty!(
1965                    fidl_fuchsia_bluetooth::PeerId,
1966                    fidl::encoding::DefaultFuchsiaResourceDialect
1967                ),
1968                peer: fidl::new_empty!(
1969                    fidl::encoding::Endpoint<fidl::endpoints::ServerEnd<MockPeerMarker>>,
1970                    fidl::encoding::DefaultFuchsiaResourceDialect
1971                ),
1972                observer: fidl::new_empty!(
1973                    fidl::encoding::Endpoint<fidl::endpoints::ClientEnd<PeerObserverMarker>>,
1974                    fidl::encoding::DefaultFuchsiaResourceDialect
1975                ),
1976            }
1977        }
1978
1979        #[inline]
1980        unsafe fn decode(
1981            &mut self,
1982            decoder: &mut fidl::encoding::Decoder<
1983                '_,
1984                fidl::encoding::DefaultFuchsiaResourceDialect,
1985            >,
1986            offset: usize,
1987            _depth: fidl::encoding::Depth,
1988        ) -> fidl::Result<()> {
1989            decoder.debug_check_bounds::<Self>(offset);
1990            // Verify that padding bytes are zero.
1991            fidl::decode!(
1992                fidl_fuchsia_bluetooth::PeerId,
1993                fidl::encoding::DefaultFuchsiaResourceDialect,
1994                &mut self.peer_id,
1995                decoder,
1996                offset + 0,
1997                _depth
1998            )?;
1999            fidl::decode!(
2000                fidl::encoding::Endpoint<fidl::endpoints::ServerEnd<MockPeerMarker>>,
2001                fidl::encoding::DefaultFuchsiaResourceDialect,
2002                &mut self.peer,
2003                decoder,
2004                offset + 8,
2005                _depth
2006            )?;
2007            fidl::decode!(
2008                fidl::encoding::Endpoint<fidl::endpoints::ClientEnd<PeerObserverMarker>>,
2009                fidl::encoding::DefaultFuchsiaResourceDialect,
2010                &mut self.observer,
2011                decoder,
2012                offset + 12,
2013                _depth
2014            )?;
2015            Ok(())
2016        }
2017    }
2018}