fidl_fuchsia_bluetooth_power/
fidl_fuchsia_bluetooth_power.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 _};
10use futures::future::{self, MaybeDone, TryFutureExt};
11use zx_status;
12
13#[derive(Clone, Copy, Debug, Eq, Hash, Ord, PartialEq, PartialOrd)]
14pub struct LocalDevice;
15
16impl fidl::Persistable for LocalDevice {}
17
18#[derive(Debug, PartialEq)]
19pub struct ReporterReportRequest {
20    pub info: Information,
21}
22
23impl fidl::Standalone<fidl::encoding::DefaultFuchsiaResourceDialect> for ReporterReportRequest {}
24
25#[derive(Clone, Debug, PartialEq)]
26pub struct WatcherWatchRequest {
27    pub ids: Vec<Identifier>,
28}
29
30impl fidl::Persistable for WatcherWatchRequest {}
31
32#[derive(Clone, Debug, PartialEq)]
33pub struct WatcherWatchResponse {
34    pub peripherals: Vec<Information>,
35}
36
37impl fidl::Persistable for WatcherWatchResponse {}
38
39/// Information about a peripheral.
40#[derive(Clone, Debug, Default, PartialEq)]
41pub struct Information {
42    /// Mandatory - unique identifier assigned by the system for the peripheral.
43    pub identifier: Option<Identifier>,
44    /// Mandatory - Describes the current battery information of the peripheral.
45    ///
46    /// `level_percent` will always be present.
47    /// `level_status` is optional.
48    ///
49    /// The remaining fields in `BatteryInfo` are ignored.
50    pub battery_info: Option<fidl_fuchsia_power_battery::BatteryInfo>,
51    #[doc(hidden)]
52    pub __source_breaking: fidl::marker::SourceBreaking,
53}
54
55impl fidl::Persistable for Information {}
56
57/// An identifier of a peripheral that is assigned by the system.
58#[derive(Clone, Debug)]
59pub enum Identifier {
60    LocalDevice(LocalDevice),
61    PeerId(fidl_fuchsia_bluetooth::PeerId),
62    #[doc(hidden)]
63    __SourceBreaking {
64        unknown_ordinal: u64,
65    },
66}
67
68/// Pattern that matches an unknown `Identifier` member.
69#[macro_export]
70macro_rules! IdentifierUnknown {
71    () => {
72        _
73    };
74}
75
76// Custom PartialEq so that unknown variants are not equal to themselves.
77impl PartialEq for Identifier {
78    fn eq(&self, other: &Self) -> bool {
79        match (self, other) {
80            (Self::LocalDevice(x), Self::LocalDevice(y)) => *x == *y,
81            (Self::PeerId(x), Self::PeerId(y)) => *x == *y,
82            _ => false,
83        }
84    }
85}
86
87impl Identifier {
88    #[inline]
89    pub fn ordinal(&self) -> u64 {
90        match *self {
91            Self::LocalDevice(_) => 1,
92            Self::PeerId(_) => 2,
93            Self::__SourceBreaking { unknown_ordinal } => unknown_ordinal,
94        }
95    }
96
97    #[inline]
98    pub fn unknown_variant_for_testing() -> Self {
99        Self::__SourceBreaking { unknown_ordinal: 0 }
100    }
101
102    #[inline]
103    pub fn is_unknown(&self) -> bool {
104        match self {
105            Self::__SourceBreaking { .. } => true,
106            _ => false,
107        }
108    }
109}
110
111impl fidl::Persistable for Identifier {}
112
113#[derive(Debug, Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Hash)]
114pub struct ReporterMarker;
115
116impl fidl::endpoints::ProtocolMarker for ReporterMarker {
117    type Proxy = ReporterProxy;
118    type RequestStream = ReporterRequestStream;
119    #[cfg(target_os = "fuchsia")]
120    type SynchronousProxy = ReporterSynchronousProxy;
121
122    const DEBUG_NAME: &'static str = "fuchsia.bluetooth.power.Reporter";
123}
124impl fidl::endpoints::DiscoverableProtocolMarker for ReporterMarker {}
125pub type ReporterReportResult = Result<(), i32>;
126
127pub trait ReporterProxyInterface: Send + Sync {
128    type ReportResponseFut: std::future::Future<Output = Result<ReporterReportResult, fidl::Error>>
129        + Send;
130    fn r#report(&self, info: &Information) -> Self::ReportResponseFut;
131}
132#[derive(Debug)]
133#[cfg(target_os = "fuchsia")]
134pub struct ReporterSynchronousProxy {
135    client: fidl::client::sync::Client,
136}
137
138#[cfg(target_os = "fuchsia")]
139impl fidl::endpoints::SynchronousProxy for ReporterSynchronousProxy {
140    type Proxy = ReporterProxy;
141    type Protocol = ReporterMarker;
142
143    fn from_channel(inner: fidl::Channel) -> Self {
144        Self::new(inner)
145    }
146
147    fn into_channel(self) -> fidl::Channel {
148        self.client.into_channel()
149    }
150
151    fn as_channel(&self) -> &fidl::Channel {
152        self.client.as_channel()
153    }
154}
155
156#[cfg(target_os = "fuchsia")]
157impl ReporterSynchronousProxy {
158    pub fn new(channel: fidl::Channel) -> Self {
159        let protocol_name = <ReporterMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME;
160        Self { client: fidl::client::sync::Client::new(channel, protocol_name) }
161    }
162
163    pub fn into_channel(self) -> fidl::Channel {
164        self.client.into_channel()
165    }
166
167    /// Waits until an event arrives and returns it. It is safe for other
168    /// threads to make concurrent requests while waiting for an event.
169    pub fn wait_for_event(
170        &self,
171        deadline: zx::MonotonicInstant,
172    ) -> Result<ReporterEvent, fidl::Error> {
173        ReporterEvent::decode(self.client.wait_for_event(deadline)?)
174    }
175
176    /// Report information about a connected peripheral.
177    ///
178    /// Each `Report` request will be acknowledged. The client shall wait for the acknowledgement
179    /// before sending a subsequent request.
180    ///
181    /// + request `info` is the current information associated with the peripheral.
182    /// - response An empty response will be sent when the server has processed the request.
183    /// * error Returns `ZX_ERR_INVALID_ARGS` if the provided `info` is invalidly formatted.
184    pub fn r#report(
185        &self,
186        mut info: &Information,
187        ___deadline: zx::MonotonicInstant,
188    ) -> Result<ReporterReportResult, fidl::Error> {
189        let _response = self.client.send_query::<
190            ReporterReportRequest,
191            fidl::encoding::ResultType<fidl::encoding::EmptyStruct, i32>,
192        >(
193            (info,),
194            0x282927fd7363f17f,
195            fidl::encoding::DynamicFlags::empty(),
196            ___deadline,
197        )?;
198        Ok(_response.map(|x| x))
199    }
200}
201
202#[derive(Debug, Clone)]
203pub struct ReporterProxy {
204    client: fidl::client::Client<fidl::encoding::DefaultFuchsiaResourceDialect>,
205}
206
207impl fidl::endpoints::Proxy for ReporterProxy {
208    type Protocol = ReporterMarker;
209
210    fn from_channel(inner: ::fidl::AsyncChannel) -> Self {
211        Self::new(inner)
212    }
213
214    fn into_channel(self) -> Result<::fidl::AsyncChannel, Self> {
215        self.client.into_channel().map_err(|client| Self { client })
216    }
217
218    fn as_channel(&self) -> &::fidl::AsyncChannel {
219        self.client.as_channel()
220    }
221}
222
223impl ReporterProxy {
224    /// Create a new Proxy for fuchsia.bluetooth.power/Reporter.
225    pub fn new(channel: ::fidl::AsyncChannel) -> Self {
226        let protocol_name = <ReporterMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME;
227        Self { client: fidl::client::Client::new(channel, protocol_name) }
228    }
229
230    /// Get a Stream of events from the remote end of the protocol.
231    ///
232    /// # Panics
233    ///
234    /// Panics if the event stream was already taken.
235    pub fn take_event_stream(&self) -> ReporterEventStream {
236        ReporterEventStream { event_receiver: self.client.take_event_receiver() }
237    }
238
239    /// Report information about a connected peripheral.
240    ///
241    /// Each `Report` request will be acknowledged. The client shall wait for the acknowledgement
242    /// before sending a subsequent request.
243    ///
244    /// + request `info` is the current information associated with the peripheral.
245    /// - response An empty response will be sent when the server has processed the request.
246    /// * error Returns `ZX_ERR_INVALID_ARGS` if the provided `info` is invalidly formatted.
247    pub fn r#report(
248        &self,
249        mut info: &Information,
250    ) -> fidl::client::QueryResponseFut<
251        ReporterReportResult,
252        fidl::encoding::DefaultFuchsiaResourceDialect,
253    > {
254        ReporterProxyInterface::r#report(self, info)
255    }
256}
257
258impl ReporterProxyInterface for ReporterProxy {
259    type ReportResponseFut = fidl::client::QueryResponseFut<
260        ReporterReportResult,
261        fidl::encoding::DefaultFuchsiaResourceDialect,
262    >;
263    fn r#report(&self, mut info: &Information) -> Self::ReportResponseFut {
264        fn _decode(
265            mut _buf: Result<<fidl::encoding::DefaultFuchsiaResourceDialect as fidl::encoding::ResourceDialect>::MessageBufEtc, fidl::Error>,
266        ) -> Result<ReporterReportResult, fidl::Error> {
267            let _response = fidl::client::decode_transaction_body::<
268                fidl::encoding::ResultType<fidl::encoding::EmptyStruct, i32>,
269                fidl::encoding::DefaultFuchsiaResourceDialect,
270                0x282927fd7363f17f,
271            >(_buf?)?;
272            Ok(_response.map(|x| x))
273        }
274        self.client.send_query_and_decode::<ReporterReportRequest, ReporterReportResult>(
275            (info,),
276            0x282927fd7363f17f,
277            fidl::encoding::DynamicFlags::empty(),
278            _decode,
279        )
280    }
281}
282
283pub struct ReporterEventStream {
284    event_receiver: fidl::client::EventReceiver<fidl::encoding::DefaultFuchsiaResourceDialect>,
285}
286
287impl std::marker::Unpin for ReporterEventStream {}
288
289impl futures::stream::FusedStream for ReporterEventStream {
290    fn is_terminated(&self) -> bool {
291        self.event_receiver.is_terminated()
292    }
293}
294
295impl futures::Stream for ReporterEventStream {
296    type Item = Result<ReporterEvent, fidl::Error>;
297
298    fn poll_next(
299        mut self: std::pin::Pin<&mut Self>,
300        cx: &mut std::task::Context<'_>,
301    ) -> std::task::Poll<Option<Self::Item>> {
302        match futures::ready!(futures::stream::StreamExt::poll_next_unpin(
303            &mut self.event_receiver,
304            cx
305        )?) {
306            Some(buf) => std::task::Poll::Ready(Some(ReporterEvent::decode(buf))),
307            None => std::task::Poll::Ready(None),
308        }
309    }
310}
311
312#[derive(Debug)]
313pub enum ReporterEvent {}
314
315impl ReporterEvent {
316    /// Decodes a message buffer as a [`ReporterEvent`].
317    fn decode(
318        mut buf: <fidl::encoding::DefaultFuchsiaResourceDialect as fidl::encoding::ResourceDialect>::MessageBufEtc,
319    ) -> Result<ReporterEvent, fidl::Error> {
320        let (bytes, _handles) = buf.split_mut();
321        let (tx_header, _body_bytes) = fidl::encoding::decode_transaction_header(bytes)?;
322        debug_assert_eq!(tx_header.tx_id, 0);
323        match tx_header.ordinal {
324            _ => Err(fidl::Error::UnknownOrdinal {
325                ordinal: tx_header.ordinal,
326                protocol_name: <ReporterMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME,
327            }),
328        }
329    }
330}
331
332/// A Stream of incoming requests for fuchsia.bluetooth.power/Reporter.
333pub struct ReporterRequestStream {
334    inner: std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>,
335    is_terminated: bool,
336}
337
338impl std::marker::Unpin for ReporterRequestStream {}
339
340impl futures::stream::FusedStream for ReporterRequestStream {
341    fn is_terminated(&self) -> bool {
342        self.is_terminated
343    }
344}
345
346impl fidl::endpoints::RequestStream for ReporterRequestStream {
347    type Protocol = ReporterMarker;
348    type ControlHandle = ReporterControlHandle;
349
350    fn from_channel(channel: ::fidl::AsyncChannel) -> Self {
351        Self { inner: std::sync::Arc::new(fidl::ServeInner::new(channel)), is_terminated: false }
352    }
353
354    fn control_handle(&self) -> Self::ControlHandle {
355        ReporterControlHandle { inner: self.inner.clone() }
356    }
357
358    fn into_inner(
359        self,
360    ) -> (::std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>, bool)
361    {
362        (self.inner, self.is_terminated)
363    }
364
365    fn from_inner(
366        inner: std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>,
367        is_terminated: bool,
368    ) -> Self {
369        Self { inner, is_terminated }
370    }
371}
372
373impl futures::Stream for ReporterRequestStream {
374    type Item = Result<ReporterRequest, fidl::Error>;
375
376    fn poll_next(
377        mut self: std::pin::Pin<&mut Self>,
378        cx: &mut std::task::Context<'_>,
379    ) -> std::task::Poll<Option<Self::Item>> {
380        let this = &mut *self;
381        if this.inner.check_shutdown(cx) {
382            this.is_terminated = true;
383            return std::task::Poll::Ready(None);
384        }
385        if this.is_terminated {
386            panic!("polled ReporterRequestStream after completion");
387        }
388        fidl::encoding::with_tls_decode_buf::<_, fidl::encoding::DefaultFuchsiaResourceDialect>(
389            |bytes, handles| {
390                match this.inner.channel().read_etc(cx, bytes, handles) {
391                    std::task::Poll::Ready(Ok(())) => {}
392                    std::task::Poll::Pending => return std::task::Poll::Pending,
393                    std::task::Poll::Ready(Err(zx_status::Status::PEER_CLOSED)) => {
394                        this.is_terminated = true;
395                        return std::task::Poll::Ready(None);
396                    }
397                    std::task::Poll::Ready(Err(e)) => {
398                        return std::task::Poll::Ready(Some(Err(fidl::Error::ServerRequestRead(
399                            e.into(),
400                        ))))
401                    }
402                }
403
404                // A message has been received from the channel
405                let (header, _body_bytes) = fidl::encoding::decode_transaction_header(bytes)?;
406
407                std::task::Poll::Ready(Some(match header.ordinal {
408                    0x282927fd7363f17f => {
409                        header.validate_request_tx_id(fidl::MethodType::TwoWay)?;
410                        let mut req = fidl::new_empty!(
411                            ReporterReportRequest,
412                            fidl::encoding::DefaultFuchsiaResourceDialect
413                        );
414                        fidl::encoding::Decoder::<fidl::encoding::DefaultFuchsiaResourceDialect>::decode_into::<ReporterReportRequest>(&header, _body_bytes, handles, &mut req)?;
415                        let control_handle = ReporterControlHandle { inner: this.inner.clone() };
416                        Ok(ReporterRequest::Report {
417                            info: req.info,
418
419                            responder: ReporterReportResponder {
420                                control_handle: std::mem::ManuallyDrop::new(control_handle),
421                                tx_id: header.tx_id,
422                            },
423                        })
424                    }
425                    _ => Err(fidl::Error::UnknownOrdinal {
426                        ordinal: header.ordinal,
427                        protocol_name:
428                            <ReporterMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME,
429                    }),
430                }))
431            },
432        )
433    }
434}
435
436/// A protocol used to report information about a peripheral to the system.
437#[derive(Debug)]
438pub enum ReporterRequest {
439    /// Report information about a connected peripheral.
440    ///
441    /// Each `Report` request will be acknowledged. The client shall wait for the acknowledgement
442    /// before sending a subsequent request.
443    ///
444    /// + request `info` is the current information associated with the peripheral.
445    /// - response An empty response will be sent when the server has processed the request.
446    /// * error Returns `ZX_ERR_INVALID_ARGS` if the provided `info` is invalidly formatted.
447    Report { info: Information, responder: ReporterReportResponder },
448}
449
450impl ReporterRequest {
451    #[allow(irrefutable_let_patterns)]
452    pub fn into_report(self) -> Option<(Information, ReporterReportResponder)> {
453        if let ReporterRequest::Report { info, responder } = self {
454            Some((info, responder))
455        } else {
456            None
457        }
458    }
459
460    /// Name of the method defined in FIDL
461    pub fn method_name(&self) -> &'static str {
462        match *self {
463            ReporterRequest::Report { .. } => "report",
464        }
465    }
466}
467
468#[derive(Debug, Clone)]
469pub struct ReporterControlHandle {
470    inner: std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>,
471}
472
473impl fidl::endpoints::ControlHandle for ReporterControlHandle {
474    fn shutdown(&self) {
475        self.inner.shutdown()
476    }
477    fn shutdown_with_epitaph(&self, status: zx_status::Status) {
478        self.inner.shutdown_with_epitaph(status)
479    }
480
481    fn is_closed(&self) -> bool {
482        self.inner.channel().is_closed()
483    }
484    fn on_closed(&self) -> fidl::OnSignalsRef<'_> {
485        self.inner.channel().on_closed()
486    }
487
488    #[cfg(target_os = "fuchsia")]
489    fn signal_peer(
490        &self,
491        clear_mask: zx::Signals,
492        set_mask: zx::Signals,
493    ) -> Result<(), zx_status::Status> {
494        use fidl::Peered;
495        self.inner.channel().signal_peer(clear_mask, set_mask)
496    }
497}
498
499impl ReporterControlHandle {}
500
501#[must_use = "FIDL methods require a response to be sent"]
502#[derive(Debug)]
503pub struct ReporterReportResponder {
504    control_handle: std::mem::ManuallyDrop<ReporterControlHandle>,
505    tx_id: u32,
506}
507
508/// Set the the channel to be shutdown (see [`ReporterControlHandle::shutdown`])
509/// if the responder is dropped without sending a response, so that the client
510/// doesn't hang. To prevent this behavior, call `drop_without_shutdown`.
511impl std::ops::Drop for ReporterReportResponder {
512    fn drop(&mut self) {
513        self.control_handle.shutdown();
514        // Safety: drops once, never accessed again
515        unsafe { std::mem::ManuallyDrop::drop(&mut self.control_handle) };
516    }
517}
518
519impl fidl::endpoints::Responder for ReporterReportResponder {
520    type ControlHandle = ReporterControlHandle;
521
522    fn control_handle(&self) -> &ReporterControlHandle {
523        &self.control_handle
524    }
525
526    fn drop_without_shutdown(mut self) {
527        // Safety: drops once, never accessed again due to mem::forget
528        unsafe { std::mem::ManuallyDrop::drop(&mut self.control_handle) };
529        // Prevent Drop from running (which would shut down the channel)
530        std::mem::forget(self);
531    }
532}
533
534impl ReporterReportResponder {
535    /// Sends a response to the FIDL transaction.
536    ///
537    /// Sets the channel to shutdown if an error occurs.
538    pub fn send(self, mut result: Result<(), i32>) -> Result<(), fidl::Error> {
539        let _result = self.send_raw(result);
540        if _result.is_err() {
541            self.control_handle.shutdown();
542        }
543        self.drop_without_shutdown();
544        _result
545    }
546
547    /// Similar to "send" but does not shutdown the channel if an error occurs.
548    pub fn send_no_shutdown_on_err(self, mut result: Result<(), i32>) -> Result<(), fidl::Error> {
549        let _result = self.send_raw(result);
550        self.drop_without_shutdown();
551        _result
552    }
553
554    fn send_raw(&self, mut result: Result<(), i32>) -> Result<(), fidl::Error> {
555        self.control_handle
556            .inner
557            .send::<fidl::encoding::ResultType<fidl::encoding::EmptyStruct, i32>>(
558                result,
559                self.tx_id,
560                0x282927fd7363f17f,
561                fidl::encoding::DynamicFlags::empty(),
562            )
563    }
564}
565
566#[derive(Debug, Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Hash)]
567pub struct WatcherMarker;
568
569impl fidl::endpoints::ProtocolMarker for WatcherMarker {
570    type Proxy = WatcherProxy;
571    type RequestStream = WatcherRequestStream;
572    #[cfg(target_os = "fuchsia")]
573    type SynchronousProxy = WatcherSynchronousProxy;
574
575    const DEBUG_NAME: &'static str = "fuchsia.bluetooth.power.Watcher";
576}
577impl fidl::endpoints::DiscoverableProtocolMarker for WatcherMarker {}
578
579pub trait WatcherProxyInterface: Send + Sync {
580    type WatchResponseFut: std::future::Future<Output = Result<Vec<Information>, fidl::Error>>
581        + Send;
582    fn r#watch(&self, ids: &[Identifier]) -> Self::WatchResponseFut;
583}
584#[derive(Debug)]
585#[cfg(target_os = "fuchsia")]
586pub struct WatcherSynchronousProxy {
587    client: fidl::client::sync::Client,
588}
589
590#[cfg(target_os = "fuchsia")]
591impl fidl::endpoints::SynchronousProxy for WatcherSynchronousProxy {
592    type Proxy = WatcherProxy;
593    type Protocol = WatcherMarker;
594
595    fn from_channel(inner: fidl::Channel) -> Self {
596        Self::new(inner)
597    }
598
599    fn into_channel(self) -> fidl::Channel {
600        self.client.into_channel()
601    }
602
603    fn as_channel(&self) -> &fidl::Channel {
604        self.client.as_channel()
605    }
606}
607
608#[cfg(target_os = "fuchsia")]
609impl WatcherSynchronousProxy {
610    pub fn new(channel: fidl::Channel) -> Self {
611        let protocol_name = <WatcherMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME;
612        Self { client: fidl::client::sync::Client::new(channel, protocol_name) }
613    }
614
615    pub fn into_channel(self) -> fidl::Channel {
616        self.client.into_channel()
617    }
618
619    /// Waits until an event arrives and returns it. It is safe for other
620    /// threads to make concurrent requests while waiting for an event.
621    pub fn wait_for_event(
622        &self,
623        deadline: zx::MonotonicInstant,
624    ) -> Result<WatcherEvent, fidl::Error> {
625        WatcherEvent::decode(self.client.wait_for_event(deadline)?)
626    }
627
628    /// A hanging get to obtain a list of discovered peripherals and their information.
629    ///
630    /// A response is sent only if this list has changed since the last time the client has sent
631    /// this message. The first call to `Watch` will resolve immediately with the initial set of
632    /// peripheral information.
633    ///
634    ///
635    /// + request `ids` is a list of identifiers to filter the peripheral information on. Use an
636    ///          empty list to receive updates about all peripherals.
637    /// - response `peripherals` is a list of information about the requested peripherals.
638    pub fn r#watch(
639        &self,
640        mut ids: &[Identifier],
641        ___deadline: zx::MonotonicInstant,
642    ) -> Result<Vec<Information>, fidl::Error> {
643        let _response = self.client.send_query::<WatcherWatchRequest, WatcherWatchResponse>(
644            (ids,),
645            0x7cc4d24741dddb85,
646            fidl::encoding::DynamicFlags::empty(),
647            ___deadline,
648        )?;
649        Ok(_response.peripherals)
650    }
651}
652
653#[derive(Debug, Clone)]
654pub struct WatcherProxy {
655    client: fidl::client::Client<fidl::encoding::DefaultFuchsiaResourceDialect>,
656}
657
658impl fidl::endpoints::Proxy for WatcherProxy {
659    type Protocol = WatcherMarker;
660
661    fn from_channel(inner: ::fidl::AsyncChannel) -> Self {
662        Self::new(inner)
663    }
664
665    fn into_channel(self) -> Result<::fidl::AsyncChannel, Self> {
666        self.client.into_channel().map_err(|client| Self { client })
667    }
668
669    fn as_channel(&self) -> &::fidl::AsyncChannel {
670        self.client.as_channel()
671    }
672}
673
674impl WatcherProxy {
675    /// Create a new Proxy for fuchsia.bluetooth.power/Watcher.
676    pub fn new(channel: ::fidl::AsyncChannel) -> Self {
677        let protocol_name = <WatcherMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME;
678        Self { client: fidl::client::Client::new(channel, protocol_name) }
679    }
680
681    /// Get a Stream of events from the remote end of the protocol.
682    ///
683    /// # Panics
684    ///
685    /// Panics if the event stream was already taken.
686    pub fn take_event_stream(&self) -> WatcherEventStream {
687        WatcherEventStream { event_receiver: self.client.take_event_receiver() }
688    }
689
690    /// A hanging get to obtain a list of discovered peripherals and their information.
691    ///
692    /// A response is sent only if this list has changed since the last time the client has sent
693    /// this message. The first call to `Watch` will resolve immediately with the initial set of
694    /// peripheral information.
695    ///
696    ///
697    /// + request `ids` is a list of identifiers to filter the peripheral information on. Use an
698    ///          empty list to receive updates about all peripherals.
699    /// - response `peripherals` is a list of information about the requested peripherals.
700    pub fn r#watch(
701        &self,
702        mut ids: &[Identifier],
703    ) -> fidl::client::QueryResponseFut<
704        Vec<Information>,
705        fidl::encoding::DefaultFuchsiaResourceDialect,
706    > {
707        WatcherProxyInterface::r#watch(self, ids)
708    }
709}
710
711impl WatcherProxyInterface for WatcherProxy {
712    type WatchResponseFut = fidl::client::QueryResponseFut<
713        Vec<Information>,
714        fidl::encoding::DefaultFuchsiaResourceDialect,
715    >;
716    fn r#watch(&self, mut ids: &[Identifier]) -> Self::WatchResponseFut {
717        fn _decode(
718            mut _buf: Result<<fidl::encoding::DefaultFuchsiaResourceDialect as fidl::encoding::ResourceDialect>::MessageBufEtc, fidl::Error>,
719        ) -> Result<Vec<Information>, fidl::Error> {
720            let _response = fidl::client::decode_transaction_body::<
721                WatcherWatchResponse,
722                fidl::encoding::DefaultFuchsiaResourceDialect,
723                0x7cc4d24741dddb85,
724            >(_buf?)?;
725            Ok(_response.peripherals)
726        }
727        self.client.send_query_and_decode::<WatcherWatchRequest, Vec<Information>>(
728            (ids,),
729            0x7cc4d24741dddb85,
730            fidl::encoding::DynamicFlags::empty(),
731            _decode,
732        )
733    }
734}
735
736pub struct WatcherEventStream {
737    event_receiver: fidl::client::EventReceiver<fidl::encoding::DefaultFuchsiaResourceDialect>,
738}
739
740impl std::marker::Unpin for WatcherEventStream {}
741
742impl futures::stream::FusedStream for WatcherEventStream {
743    fn is_terminated(&self) -> bool {
744        self.event_receiver.is_terminated()
745    }
746}
747
748impl futures::Stream for WatcherEventStream {
749    type Item = Result<WatcherEvent, fidl::Error>;
750
751    fn poll_next(
752        mut self: std::pin::Pin<&mut Self>,
753        cx: &mut std::task::Context<'_>,
754    ) -> std::task::Poll<Option<Self::Item>> {
755        match futures::ready!(futures::stream::StreamExt::poll_next_unpin(
756            &mut self.event_receiver,
757            cx
758        )?) {
759            Some(buf) => std::task::Poll::Ready(Some(WatcherEvent::decode(buf))),
760            None => std::task::Poll::Ready(None),
761        }
762    }
763}
764
765#[derive(Debug)]
766pub enum WatcherEvent {}
767
768impl WatcherEvent {
769    /// Decodes a message buffer as a [`WatcherEvent`].
770    fn decode(
771        mut buf: <fidl::encoding::DefaultFuchsiaResourceDialect as fidl::encoding::ResourceDialect>::MessageBufEtc,
772    ) -> Result<WatcherEvent, fidl::Error> {
773        let (bytes, _handles) = buf.split_mut();
774        let (tx_header, _body_bytes) = fidl::encoding::decode_transaction_header(bytes)?;
775        debug_assert_eq!(tx_header.tx_id, 0);
776        match tx_header.ordinal {
777            _ => Err(fidl::Error::UnknownOrdinal {
778                ordinal: tx_header.ordinal,
779                protocol_name: <WatcherMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME,
780            }),
781        }
782    }
783}
784
785/// A Stream of incoming requests for fuchsia.bluetooth.power/Watcher.
786pub struct WatcherRequestStream {
787    inner: std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>,
788    is_terminated: bool,
789}
790
791impl std::marker::Unpin for WatcherRequestStream {}
792
793impl futures::stream::FusedStream for WatcherRequestStream {
794    fn is_terminated(&self) -> bool {
795        self.is_terminated
796    }
797}
798
799impl fidl::endpoints::RequestStream for WatcherRequestStream {
800    type Protocol = WatcherMarker;
801    type ControlHandle = WatcherControlHandle;
802
803    fn from_channel(channel: ::fidl::AsyncChannel) -> Self {
804        Self { inner: std::sync::Arc::new(fidl::ServeInner::new(channel)), is_terminated: false }
805    }
806
807    fn control_handle(&self) -> Self::ControlHandle {
808        WatcherControlHandle { inner: self.inner.clone() }
809    }
810
811    fn into_inner(
812        self,
813    ) -> (::std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>, bool)
814    {
815        (self.inner, self.is_terminated)
816    }
817
818    fn from_inner(
819        inner: std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>,
820        is_terminated: bool,
821    ) -> Self {
822        Self { inner, is_terminated }
823    }
824}
825
826impl futures::Stream for WatcherRequestStream {
827    type Item = Result<WatcherRequest, fidl::Error>;
828
829    fn poll_next(
830        mut self: std::pin::Pin<&mut Self>,
831        cx: &mut std::task::Context<'_>,
832    ) -> std::task::Poll<Option<Self::Item>> {
833        let this = &mut *self;
834        if this.inner.check_shutdown(cx) {
835            this.is_terminated = true;
836            return std::task::Poll::Ready(None);
837        }
838        if this.is_terminated {
839            panic!("polled WatcherRequestStream after completion");
840        }
841        fidl::encoding::with_tls_decode_buf::<_, fidl::encoding::DefaultFuchsiaResourceDialect>(
842            |bytes, handles| {
843                match this.inner.channel().read_etc(cx, bytes, handles) {
844                    std::task::Poll::Ready(Ok(())) => {}
845                    std::task::Poll::Pending => return std::task::Poll::Pending,
846                    std::task::Poll::Ready(Err(zx_status::Status::PEER_CLOSED)) => {
847                        this.is_terminated = true;
848                        return std::task::Poll::Ready(None);
849                    }
850                    std::task::Poll::Ready(Err(e)) => {
851                        return std::task::Poll::Ready(Some(Err(fidl::Error::ServerRequestRead(
852                            e.into(),
853                        ))))
854                    }
855                }
856
857                // A message has been received from the channel
858                let (header, _body_bytes) = fidl::encoding::decode_transaction_header(bytes)?;
859
860                std::task::Poll::Ready(Some(match header.ordinal {
861                    0x7cc4d24741dddb85 => {
862                        header.validate_request_tx_id(fidl::MethodType::TwoWay)?;
863                        let mut req = fidl::new_empty!(
864                            WatcherWatchRequest,
865                            fidl::encoding::DefaultFuchsiaResourceDialect
866                        );
867                        fidl::encoding::Decoder::<fidl::encoding::DefaultFuchsiaResourceDialect>::decode_into::<WatcherWatchRequest>(&header, _body_bytes, handles, &mut req)?;
868                        let control_handle = WatcherControlHandle { inner: this.inner.clone() };
869                        Ok(WatcherRequest::Watch {
870                            ids: req.ids,
871
872                            responder: WatcherWatchResponder {
873                                control_handle: std::mem::ManuallyDrop::new(control_handle),
874                                tx_id: header.tx_id,
875                            },
876                        })
877                    }
878                    _ => Err(fidl::Error::UnknownOrdinal {
879                        ordinal: header.ordinal,
880                        protocol_name:
881                            <WatcherMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME,
882                    }),
883                }))
884            },
885        )
886    }
887}
888
889/// Protocol used to observe peripherals owned & discovered by the system.
890#[derive(Debug)]
891pub enum WatcherRequest {
892    /// A hanging get to obtain a list of discovered peripherals and their information.
893    ///
894    /// A response is sent only if this list has changed since the last time the client has sent
895    /// this message. The first call to `Watch` will resolve immediately with the initial set of
896    /// peripheral information.
897    ///
898    ///
899    /// + request `ids` is a list of identifiers to filter the peripheral information on. Use an
900    ///          empty list to receive updates about all peripherals.
901    /// - response `peripherals` is a list of information about the requested peripherals.
902    Watch { ids: Vec<Identifier>, responder: WatcherWatchResponder },
903}
904
905impl WatcherRequest {
906    #[allow(irrefutable_let_patterns)]
907    pub fn into_watch(self) -> Option<(Vec<Identifier>, WatcherWatchResponder)> {
908        if let WatcherRequest::Watch { ids, responder } = self {
909            Some((ids, responder))
910        } else {
911            None
912        }
913    }
914
915    /// Name of the method defined in FIDL
916    pub fn method_name(&self) -> &'static str {
917        match *self {
918            WatcherRequest::Watch { .. } => "watch",
919        }
920    }
921}
922
923#[derive(Debug, Clone)]
924pub struct WatcherControlHandle {
925    inner: std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>,
926}
927
928impl fidl::endpoints::ControlHandle for WatcherControlHandle {
929    fn shutdown(&self) {
930        self.inner.shutdown()
931    }
932    fn shutdown_with_epitaph(&self, status: zx_status::Status) {
933        self.inner.shutdown_with_epitaph(status)
934    }
935
936    fn is_closed(&self) -> bool {
937        self.inner.channel().is_closed()
938    }
939    fn on_closed(&self) -> fidl::OnSignalsRef<'_> {
940        self.inner.channel().on_closed()
941    }
942
943    #[cfg(target_os = "fuchsia")]
944    fn signal_peer(
945        &self,
946        clear_mask: zx::Signals,
947        set_mask: zx::Signals,
948    ) -> Result<(), zx_status::Status> {
949        use fidl::Peered;
950        self.inner.channel().signal_peer(clear_mask, set_mask)
951    }
952}
953
954impl WatcherControlHandle {}
955
956#[must_use = "FIDL methods require a response to be sent"]
957#[derive(Debug)]
958pub struct WatcherWatchResponder {
959    control_handle: std::mem::ManuallyDrop<WatcherControlHandle>,
960    tx_id: u32,
961}
962
963/// Set the the channel to be shutdown (see [`WatcherControlHandle::shutdown`])
964/// if the responder is dropped without sending a response, so that the client
965/// doesn't hang. To prevent this behavior, call `drop_without_shutdown`.
966impl std::ops::Drop for WatcherWatchResponder {
967    fn drop(&mut self) {
968        self.control_handle.shutdown();
969        // Safety: drops once, never accessed again
970        unsafe { std::mem::ManuallyDrop::drop(&mut self.control_handle) };
971    }
972}
973
974impl fidl::endpoints::Responder for WatcherWatchResponder {
975    type ControlHandle = WatcherControlHandle;
976
977    fn control_handle(&self) -> &WatcherControlHandle {
978        &self.control_handle
979    }
980
981    fn drop_without_shutdown(mut self) {
982        // Safety: drops once, never accessed again due to mem::forget
983        unsafe { std::mem::ManuallyDrop::drop(&mut self.control_handle) };
984        // Prevent Drop from running (which would shut down the channel)
985        std::mem::forget(self);
986    }
987}
988
989impl WatcherWatchResponder {
990    /// Sends a response to the FIDL transaction.
991    ///
992    /// Sets the channel to shutdown if an error occurs.
993    pub fn send(self, mut peripherals: &[Information]) -> Result<(), fidl::Error> {
994        let _result = self.send_raw(peripherals);
995        if _result.is_err() {
996            self.control_handle.shutdown();
997        }
998        self.drop_without_shutdown();
999        _result
1000    }
1001
1002    /// Similar to "send" but does not shutdown the channel if an error occurs.
1003    pub fn send_no_shutdown_on_err(
1004        self,
1005        mut peripherals: &[Information],
1006    ) -> Result<(), fidl::Error> {
1007        let _result = self.send_raw(peripherals);
1008        self.drop_without_shutdown();
1009        _result
1010    }
1011
1012    fn send_raw(&self, mut peripherals: &[Information]) -> Result<(), fidl::Error> {
1013        self.control_handle.inner.send::<WatcherWatchResponse>(
1014            (peripherals,),
1015            self.tx_id,
1016            0x7cc4d24741dddb85,
1017            fidl::encoding::DynamicFlags::empty(),
1018        )
1019    }
1020}
1021
1022mod internal {
1023    use super::*;
1024
1025    impl fidl::encoding::ValueTypeMarker for LocalDevice {
1026        type Borrowed<'a> = &'a Self;
1027        fn borrow(value: &<Self as fidl::encoding::TypeMarker>::Owned) -> Self::Borrowed<'_> {
1028            value
1029        }
1030    }
1031
1032    unsafe impl fidl::encoding::TypeMarker for LocalDevice {
1033        type Owned = Self;
1034
1035        #[inline(always)]
1036        fn inline_align(_context: fidl::encoding::Context) -> usize {
1037            1
1038        }
1039
1040        #[inline(always)]
1041        fn inline_size(_context: fidl::encoding::Context) -> usize {
1042            1
1043        }
1044    }
1045
1046    unsafe impl<D: fidl::encoding::ResourceDialect> fidl::encoding::Encode<LocalDevice, D>
1047        for &LocalDevice
1048    {
1049        #[inline]
1050        unsafe fn encode(
1051            self,
1052            encoder: &mut fidl::encoding::Encoder<'_, D>,
1053            offset: usize,
1054            _depth: fidl::encoding::Depth,
1055        ) -> fidl::Result<()> {
1056            encoder.debug_check_bounds::<LocalDevice>(offset);
1057            encoder.write_num(0u8, offset);
1058            Ok(())
1059        }
1060    }
1061
1062    impl<D: fidl::encoding::ResourceDialect> fidl::encoding::Decode<Self, D> for LocalDevice {
1063        #[inline(always)]
1064        fn new_empty() -> Self {
1065            Self
1066        }
1067
1068        #[inline]
1069        unsafe fn decode(
1070            &mut self,
1071            decoder: &mut fidl::encoding::Decoder<'_, D>,
1072            offset: usize,
1073            _depth: fidl::encoding::Depth,
1074        ) -> fidl::Result<()> {
1075            decoder.debug_check_bounds::<Self>(offset);
1076            match decoder.read_num::<u8>(offset) {
1077                0 => Ok(()),
1078                _ => Err(fidl::Error::Invalid),
1079            }
1080        }
1081    }
1082
1083    impl fidl::encoding::ResourceTypeMarker for ReporterReportRequest {
1084        type Borrowed<'a> = &'a mut Self;
1085        fn take_or_borrow<'a>(
1086            value: &'a mut <Self as fidl::encoding::TypeMarker>::Owned,
1087        ) -> Self::Borrowed<'a> {
1088            value
1089        }
1090    }
1091
1092    unsafe impl fidl::encoding::TypeMarker for ReporterReportRequest {
1093        type Owned = Self;
1094
1095        #[inline(always)]
1096        fn inline_align(_context: fidl::encoding::Context) -> usize {
1097            8
1098        }
1099
1100        #[inline(always)]
1101        fn inline_size(_context: fidl::encoding::Context) -> usize {
1102            16
1103        }
1104    }
1105
1106    unsafe impl
1107        fidl::encoding::Encode<ReporterReportRequest, fidl::encoding::DefaultFuchsiaResourceDialect>
1108        for &mut ReporterReportRequest
1109    {
1110        #[inline]
1111        unsafe fn encode(
1112            self,
1113            encoder: &mut fidl::encoding::Encoder<
1114                '_,
1115                fidl::encoding::DefaultFuchsiaResourceDialect,
1116            >,
1117            offset: usize,
1118            _depth: fidl::encoding::Depth,
1119        ) -> fidl::Result<()> {
1120            encoder.debug_check_bounds::<ReporterReportRequest>(offset);
1121            // Delegate to tuple encoding.
1122            fidl::encoding::Encode::<
1123                ReporterReportRequest,
1124                fidl::encoding::DefaultFuchsiaResourceDialect,
1125            >::encode(
1126                (<Information as fidl::encoding::ValueTypeMarker>::borrow(&self.info),),
1127                encoder,
1128                offset,
1129                _depth,
1130            )
1131        }
1132    }
1133    unsafe impl<
1134            T0: fidl::encoding::Encode<Information, fidl::encoding::DefaultFuchsiaResourceDialect>,
1135        >
1136        fidl::encoding::Encode<ReporterReportRequest, fidl::encoding::DefaultFuchsiaResourceDialect>
1137        for (T0,)
1138    {
1139        #[inline]
1140        unsafe fn encode(
1141            self,
1142            encoder: &mut fidl::encoding::Encoder<
1143                '_,
1144                fidl::encoding::DefaultFuchsiaResourceDialect,
1145            >,
1146            offset: usize,
1147            depth: fidl::encoding::Depth,
1148        ) -> fidl::Result<()> {
1149            encoder.debug_check_bounds::<ReporterReportRequest>(offset);
1150            // Zero out padding regions. There's no need to apply masks
1151            // because the unmasked parts will be overwritten by fields.
1152            // Write the fields.
1153            self.0.encode(encoder, offset + 0, depth)?;
1154            Ok(())
1155        }
1156    }
1157
1158    impl fidl::encoding::Decode<Self, fidl::encoding::DefaultFuchsiaResourceDialect>
1159        for ReporterReportRequest
1160    {
1161        #[inline(always)]
1162        fn new_empty() -> Self {
1163            Self {
1164                info: fidl::new_empty!(Information, fidl::encoding::DefaultFuchsiaResourceDialect),
1165            }
1166        }
1167
1168        #[inline]
1169        unsafe fn decode(
1170            &mut self,
1171            decoder: &mut fidl::encoding::Decoder<
1172                '_,
1173                fidl::encoding::DefaultFuchsiaResourceDialect,
1174            >,
1175            offset: usize,
1176            _depth: fidl::encoding::Depth,
1177        ) -> fidl::Result<()> {
1178            decoder.debug_check_bounds::<Self>(offset);
1179            // Verify that padding bytes are zero.
1180            fidl::decode!(
1181                Information,
1182                fidl::encoding::DefaultFuchsiaResourceDialect,
1183                &mut self.info,
1184                decoder,
1185                offset + 0,
1186                _depth
1187            )?;
1188            Ok(())
1189        }
1190    }
1191
1192    impl fidl::encoding::ValueTypeMarker for WatcherWatchRequest {
1193        type Borrowed<'a> = &'a Self;
1194        fn borrow(value: &<Self as fidl::encoding::TypeMarker>::Owned) -> Self::Borrowed<'_> {
1195            value
1196        }
1197    }
1198
1199    unsafe impl fidl::encoding::TypeMarker for WatcherWatchRequest {
1200        type Owned = Self;
1201
1202        #[inline(always)]
1203        fn inline_align(_context: fidl::encoding::Context) -> usize {
1204            8
1205        }
1206
1207        #[inline(always)]
1208        fn inline_size(_context: fidl::encoding::Context) -> usize {
1209            16
1210        }
1211    }
1212
1213    unsafe impl<D: fidl::encoding::ResourceDialect> fidl::encoding::Encode<WatcherWatchRequest, D>
1214        for &WatcherWatchRequest
1215    {
1216        #[inline]
1217        unsafe fn encode(
1218            self,
1219            encoder: &mut fidl::encoding::Encoder<'_, D>,
1220            offset: usize,
1221            _depth: fidl::encoding::Depth,
1222        ) -> fidl::Result<()> {
1223            encoder.debug_check_bounds::<WatcherWatchRequest>(offset);
1224            // Delegate to tuple encoding.
1225            fidl::encoding::Encode::<WatcherWatchRequest, D>::encode(
1226                (
1227                    <fidl::encoding::UnboundedVector<Identifier> as fidl::encoding::ValueTypeMarker>::borrow(&self.ids),
1228                ),
1229                encoder, offset, _depth
1230            )
1231        }
1232    }
1233    unsafe impl<
1234            D: fidl::encoding::ResourceDialect,
1235            T0: fidl::encoding::Encode<fidl::encoding::UnboundedVector<Identifier>, D>,
1236        > fidl::encoding::Encode<WatcherWatchRequest, D> for (T0,)
1237    {
1238        #[inline]
1239        unsafe fn encode(
1240            self,
1241            encoder: &mut fidl::encoding::Encoder<'_, D>,
1242            offset: usize,
1243            depth: fidl::encoding::Depth,
1244        ) -> fidl::Result<()> {
1245            encoder.debug_check_bounds::<WatcherWatchRequest>(offset);
1246            // Zero out padding regions. There's no need to apply masks
1247            // because the unmasked parts will be overwritten by fields.
1248            // Write the fields.
1249            self.0.encode(encoder, offset + 0, depth)?;
1250            Ok(())
1251        }
1252    }
1253
1254    impl<D: fidl::encoding::ResourceDialect> fidl::encoding::Decode<Self, D> for WatcherWatchRequest {
1255        #[inline(always)]
1256        fn new_empty() -> Self {
1257            Self { ids: fidl::new_empty!(fidl::encoding::UnboundedVector<Identifier>, D) }
1258        }
1259
1260        #[inline]
1261        unsafe fn decode(
1262            &mut self,
1263            decoder: &mut fidl::encoding::Decoder<'_, D>,
1264            offset: usize,
1265            _depth: fidl::encoding::Depth,
1266        ) -> fidl::Result<()> {
1267            decoder.debug_check_bounds::<Self>(offset);
1268            // Verify that padding bytes are zero.
1269            fidl::decode!(
1270                fidl::encoding::UnboundedVector<Identifier>,
1271                D,
1272                &mut self.ids,
1273                decoder,
1274                offset + 0,
1275                _depth
1276            )?;
1277            Ok(())
1278        }
1279    }
1280
1281    impl fidl::encoding::ValueTypeMarker for WatcherWatchResponse {
1282        type Borrowed<'a> = &'a Self;
1283        fn borrow(value: &<Self as fidl::encoding::TypeMarker>::Owned) -> Self::Borrowed<'_> {
1284            value
1285        }
1286    }
1287
1288    unsafe impl fidl::encoding::TypeMarker for WatcherWatchResponse {
1289        type Owned = Self;
1290
1291        #[inline(always)]
1292        fn inline_align(_context: fidl::encoding::Context) -> usize {
1293            8
1294        }
1295
1296        #[inline(always)]
1297        fn inline_size(_context: fidl::encoding::Context) -> usize {
1298            16
1299        }
1300    }
1301
1302    unsafe impl<D: fidl::encoding::ResourceDialect> fidl::encoding::Encode<WatcherWatchResponse, D>
1303        for &WatcherWatchResponse
1304    {
1305        #[inline]
1306        unsafe fn encode(
1307            self,
1308            encoder: &mut fidl::encoding::Encoder<'_, D>,
1309            offset: usize,
1310            _depth: fidl::encoding::Depth,
1311        ) -> fidl::Result<()> {
1312            encoder.debug_check_bounds::<WatcherWatchResponse>(offset);
1313            // Delegate to tuple encoding.
1314            fidl::encoding::Encode::<WatcherWatchResponse, D>::encode(
1315                (
1316                    <fidl::encoding::UnboundedVector<Information> as fidl::encoding::ValueTypeMarker>::borrow(&self.peripherals),
1317                ),
1318                encoder, offset, _depth
1319            )
1320        }
1321    }
1322    unsafe impl<
1323            D: fidl::encoding::ResourceDialect,
1324            T0: fidl::encoding::Encode<fidl::encoding::UnboundedVector<Information>, D>,
1325        > fidl::encoding::Encode<WatcherWatchResponse, D> for (T0,)
1326    {
1327        #[inline]
1328        unsafe fn encode(
1329            self,
1330            encoder: &mut fidl::encoding::Encoder<'_, D>,
1331            offset: usize,
1332            depth: fidl::encoding::Depth,
1333        ) -> fidl::Result<()> {
1334            encoder.debug_check_bounds::<WatcherWatchResponse>(offset);
1335            // Zero out padding regions. There's no need to apply masks
1336            // because the unmasked parts will be overwritten by fields.
1337            // Write the fields.
1338            self.0.encode(encoder, offset + 0, depth)?;
1339            Ok(())
1340        }
1341    }
1342
1343    impl<D: fidl::encoding::ResourceDialect> fidl::encoding::Decode<Self, D> for WatcherWatchResponse {
1344        #[inline(always)]
1345        fn new_empty() -> Self {
1346            Self { peripherals: fidl::new_empty!(fidl::encoding::UnboundedVector<Information>, D) }
1347        }
1348
1349        #[inline]
1350        unsafe fn decode(
1351            &mut self,
1352            decoder: &mut fidl::encoding::Decoder<'_, D>,
1353            offset: usize,
1354            _depth: fidl::encoding::Depth,
1355        ) -> fidl::Result<()> {
1356            decoder.debug_check_bounds::<Self>(offset);
1357            // Verify that padding bytes are zero.
1358            fidl::decode!(
1359                fidl::encoding::UnboundedVector<Information>,
1360                D,
1361                &mut self.peripherals,
1362                decoder,
1363                offset + 0,
1364                _depth
1365            )?;
1366            Ok(())
1367        }
1368    }
1369
1370    impl Information {
1371        #[inline(always)]
1372        fn max_ordinal_present(&self) -> u64 {
1373            if let Some(_) = self.battery_info {
1374                return 2;
1375            }
1376            if let Some(_) = self.identifier {
1377                return 1;
1378            }
1379            0
1380        }
1381    }
1382
1383    impl fidl::encoding::ValueTypeMarker for Information {
1384        type Borrowed<'a> = &'a Self;
1385        fn borrow(value: &<Self as fidl::encoding::TypeMarker>::Owned) -> Self::Borrowed<'_> {
1386            value
1387        }
1388    }
1389
1390    unsafe impl fidl::encoding::TypeMarker for Information {
1391        type Owned = Self;
1392
1393        #[inline(always)]
1394        fn inline_align(_context: fidl::encoding::Context) -> usize {
1395            8
1396        }
1397
1398        #[inline(always)]
1399        fn inline_size(_context: fidl::encoding::Context) -> usize {
1400            16
1401        }
1402    }
1403
1404    unsafe impl<D: fidl::encoding::ResourceDialect> fidl::encoding::Encode<Information, D>
1405        for &Information
1406    {
1407        unsafe fn encode(
1408            self,
1409            encoder: &mut fidl::encoding::Encoder<'_, D>,
1410            offset: usize,
1411            mut depth: fidl::encoding::Depth,
1412        ) -> fidl::Result<()> {
1413            encoder.debug_check_bounds::<Information>(offset);
1414            // Vector header
1415            let max_ordinal: u64 = self.max_ordinal_present();
1416            encoder.write_num(max_ordinal, offset);
1417            encoder.write_num(fidl::encoding::ALLOC_PRESENT_U64, offset + 8);
1418            // Calling encoder.out_of_line_offset(0) is not allowed.
1419            if max_ordinal == 0 {
1420                return Ok(());
1421            }
1422            depth.increment()?;
1423            let envelope_size = 8;
1424            let bytes_len = max_ordinal as usize * envelope_size;
1425            #[allow(unused_variables)]
1426            let offset = encoder.out_of_line_offset(bytes_len);
1427            let mut _prev_end_offset: usize = 0;
1428            if 1 > max_ordinal {
1429                return Ok(());
1430            }
1431
1432            // Write at offset+(ordinal-1)*envelope_size, since ordinals are one-based and envelopes
1433            // are envelope_size bytes.
1434            let cur_offset: usize = (1 - 1) * envelope_size;
1435
1436            // Zero reserved fields.
1437            encoder.padding(offset + _prev_end_offset, cur_offset - _prev_end_offset);
1438
1439            // Safety:
1440            // - bytes_len is calculated to fit envelope_size*max(member.ordinal).
1441            // - Since cur_offset is envelope_size*(member.ordinal - 1) and the envelope takes
1442            //   envelope_size bytes, there is always sufficient room.
1443            fidl::encoding::encode_in_envelope_optional::<Identifier, D>(
1444                self.identifier
1445                    .as_ref()
1446                    .map(<Identifier as fidl::encoding::ValueTypeMarker>::borrow),
1447                encoder,
1448                offset + cur_offset,
1449                depth,
1450            )?;
1451
1452            _prev_end_offset = cur_offset + envelope_size;
1453            if 2 > max_ordinal {
1454                return Ok(());
1455            }
1456
1457            // Write at offset+(ordinal-1)*envelope_size, since ordinals are one-based and envelopes
1458            // are envelope_size bytes.
1459            let cur_offset: usize = (2 - 1) * envelope_size;
1460
1461            // Zero reserved fields.
1462            encoder.padding(offset + _prev_end_offset, cur_offset - _prev_end_offset);
1463
1464            // Safety:
1465            // - bytes_len is calculated to fit envelope_size*max(member.ordinal).
1466            // - Since cur_offset is envelope_size*(member.ordinal - 1) and the envelope takes
1467            //   envelope_size bytes, there is always sufficient room.
1468            fidl::encoding::encode_in_envelope_optional::<fidl_fuchsia_power_battery::BatteryInfo, D>(
1469            self.battery_info.as_ref().map(<fidl_fuchsia_power_battery::BatteryInfo as fidl::encoding::ValueTypeMarker>::borrow),
1470            encoder, offset + cur_offset, depth
1471        )?;
1472
1473            _prev_end_offset = cur_offset + envelope_size;
1474
1475            Ok(())
1476        }
1477    }
1478
1479    impl<D: fidl::encoding::ResourceDialect> fidl::encoding::Decode<Self, D> for Information {
1480        #[inline(always)]
1481        fn new_empty() -> Self {
1482            Self::default()
1483        }
1484
1485        unsafe fn decode(
1486            &mut self,
1487            decoder: &mut fidl::encoding::Decoder<'_, D>,
1488            offset: usize,
1489            mut depth: fidl::encoding::Depth,
1490        ) -> fidl::Result<()> {
1491            decoder.debug_check_bounds::<Self>(offset);
1492            let len = match fidl::encoding::decode_vector_header(decoder, offset)? {
1493                None => return Err(fidl::Error::NotNullable),
1494                Some(len) => len,
1495            };
1496            // Calling decoder.out_of_line_offset(0) is not allowed.
1497            if len == 0 {
1498                return Ok(());
1499            };
1500            depth.increment()?;
1501            let envelope_size = 8;
1502            let bytes_len = len * envelope_size;
1503            let offset = decoder.out_of_line_offset(bytes_len)?;
1504            // Decode the envelope for each type.
1505            let mut _next_ordinal_to_read = 0;
1506            let mut next_offset = offset;
1507            let end_offset = offset + bytes_len;
1508            _next_ordinal_to_read += 1;
1509            if next_offset >= end_offset {
1510                return Ok(());
1511            }
1512
1513            // Decode unknown envelopes for gaps in ordinals.
1514            while _next_ordinal_to_read < 1 {
1515                fidl::encoding::decode_unknown_envelope(decoder, next_offset, depth)?;
1516                _next_ordinal_to_read += 1;
1517                next_offset += envelope_size;
1518            }
1519
1520            let next_out_of_line = decoder.next_out_of_line();
1521            let handles_before = decoder.remaining_handles();
1522            if let Some((inlined, num_bytes, num_handles)) =
1523                fidl::encoding::decode_envelope_header(decoder, next_offset)?
1524            {
1525                let member_inline_size =
1526                    <Identifier as fidl::encoding::TypeMarker>::inline_size(decoder.context);
1527                if inlined != (member_inline_size <= 4) {
1528                    return Err(fidl::Error::InvalidInlineBitInEnvelope);
1529                }
1530                let inner_offset;
1531                let mut inner_depth = depth.clone();
1532                if inlined {
1533                    decoder.check_inline_envelope_padding(next_offset, member_inline_size)?;
1534                    inner_offset = next_offset;
1535                } else {
1536                    inner_offset = decoder.out_of_line_offset(member_inline_size)?;
1537                    inner_depth.increment()?;
1538                }
1539                let val_ref =
1540                    self.identifier.get_or_insert_with(|| fidl::new_empty!(Identifier, D));
1541                fidl::decode!(Identifier, D, val_ref, decoder, inner_offset, inner_depth)?;
1542                if !inlined && decoder.next_out_of_line() != next_out_of_line + (num_bytes as usize)
1543                {
1544                    return Err(fidl::Error::InvalidNumBytesInEnvelope);
1545                }
1546                if handles_before != decoder.remaining_handles() + (num_handles as usize) {
1547                    return Err(fidl::Error::InvalidNumHandlesInEnvelope);
1548                }
1549            }
1550
1551            next_offset += envelope_size;
1552            _next_ordinal_to_read += 1;
1553            if next_offset >= end_offset {
1554                return Ok(());
1555            }
1556
1557            // Decode unknown envelopes for gaps in ordinals.
1558            while _next_ordinal_to_read < 2 {
1559                fidl::encoding::decode_unknown_envelope(decoder, next_offset, depth)?;
1560                _next_ordinal_to_read += 1;
1561                next_offset += envelope_size;
1562            }
1563
1564            let next_out_of_line = decoder.next_out_of_line();
1565            let handles_before = decoder.remaining_handles();
1566            if let Some((inlined, num_bytes, num_handles)) =
1567                fidl::encoding::decode_envelope_header(decoder, next_offset)?
1568            {
1569                let member_inline_size = <fidl_fuchsia_power_battery::BatteryInfo as fidl::encoding::TypeMarker>::inline_size(decoder.context);
1570                if inlined != (member_inline_size <= 4) {
1571                    return Err(fidl::Error::InvalidInlineBitInEnvelope);
1572                }
1573                let inner_offset;
1574                let mut inner_depth = depth.clone();
1575                if inlined {
1576                    decoder.check_inline_envelope_padding(next_offset, member_inline_size)?;
1577                    inner_offset = next_offset;
1578                } else {
1579                    inner_offset = decoder.out_of_line_offset(member_inline_size)?;
1580                    inner_depth.increment()?;
1581                }
1582                let val_ref = self.battery_info.get_or_insert_with(|| {
1583                    fidl::new_empty!(fidl_fuchsia_power_battery::BatteryInfo, D)
1584                });
1585                fidl::decode!(
1586                    fidl_fuchsia_power_battery::BatteryInfo,
1587                    D,
1588                    val_ref,
1589                    decoder,
1590                    inner_offset,
1591                    inner_depth
1592                )?;
1593                if !inlined && decoder.next_out_of_line() != next_out_of_line + (num_bytes as usize)
1594                {
1595                    return Err(fidl::Error::InvalidNumBytesInEnvelope);
1596                }
1597                if handles_before != decoder.remaining_handles() + (num_handles as usize) {
1598                    return Err(fidl::Error::InvalidNumHandlesInEnvelope);
1599                }
1600            }
1601
1602            next_offset += envelope_size;
1603
1604            // Decode the remaining unknown envelopes.
1605            while next_offset < end_offset {
1606                _next_ordinal_to_read += 1;
1607                fidl::encoding::decode_unknown_envelope(decoder, next_offset, depth)?;
1608                next_offset += envelope_size;
1609            }
1610
1611            Ok(())
1612        }
1613    }
1614
1615    impl fidl::encoding::ValueTypeMarker for Identifier {
1616        type Borrowed<'a> = &'a Self;
1617        fn borrow(value: &<Self as fidl::encoding::TypeMarker>::Owned) -> Self::Borrowed<'_> {
1618            value
1619        }
1620    }
1621
1622    unsafe impl fidl::encoding::TypeMarker for Identifier {
1623        type Owned = Self;
1624
1625        #[inline(always)]
1626        fn inline_align(_context: fidl::encoding::Context) -> usize {
1627            8
1628        }
1629
1630        #[inline(always)]
1631        fn inline_size(_context: fidl::encoding::Context) -> usize {
1632            16
1633        }
1634    }
1635
1636    unsafe impl<D: fidl::encoding::ResourceDialect> fidl::encoding::Encode<Identifier, D>
1637        for &Identifier
1638    {
1639        #[inline]
1640        unsafe fn encode(
1641            self,
1642            encoder: &mut fidl::encoding::Encoder<'_, D>,
1643            offset: usize,
1644            _depth: fidl::encoding::Depth,
1645        ) -> fidl::Result<()> {
1646            encoder.debug_check_bounds::<Identifier>(offset);
1647            encoder.write_num::<u64>(self.ordinal(), offset);
1648            match self {
1649                Identifier::LocalDevice(ref val) => {
1650                    fidl::encoding::encode_in_envelope::<LocalDevice, D>(
1651                        <LocalDevice as fidl::encoding::ValueTypeMarker>::borrow(val),
1652                        encoder,
1653                        offset + 8,
1654                        _depth,
1655                    )
1656                }
1657                Identifier::PeerId(ref val) => {
1658                    fidl::encoding::encode_in_envelope::<fidl_fuchsia_bluetooth::PeerId, D>(
1659                        <fidl_fuchsia_bluetooth::PeerId as fidl::encoding::ValueTypeMarker>::borrow(
1660                            val,
1661                        ),
1662                        encoder,
1663                        offset + 8,
1664                        _depth,
1665                    )
1666                }
1667                Identifier::__SourceBreaking { .. } => Err(fidl::Error::UnknownUnionTag),
1668            }
1669        }
1670    }
1671
1672    impl<D: fidl::encoding::ResourceDialect> fidl::encoding::Decode<Self, D> for Identifier {
1673        #[inline(always)]
1674        fn new_empty() -> Self {
1675            Self::__SourceBreaking { unknown_ordinal: 0 }
1676        }
1677
1678        #[inline]
1679        unsafe fn decode(
1680            &mut self,
1681            decoder: &mut fidl::encoding::Decoder<'_, D>,
1682            offset: usize,
1683            mut depth: fidl::encoding::Depth,
1684        ) -> fidl::Result<()> {
1685            decoder.debug_check_bounds::<Self>(offset);
1686            #[allow(unused_variables)]
1687            let next_out_of_line = decoder.next_out_of_line();
1688            let handles_before = decoder.remaining_handles();
1689            let (ordinal, inlined, num_bytes, num_handles) =
1690                fidl::encoding::decode_union_inline_portion(decoder, offset)?;
1691
1692            let member_inline_size = match ordinal {
1693                1 => <LocalDevice as fidl::encoding::TypeMarker>::inline_size(decoder.context),
1694                2 => <fidl_fuchsia_bluetooth::PeerId as fidl::encoding::TypeMarker>::inline_size(
1695                    decoder.context,
1696                ),
1697                0 => return Err(fidl::Error::UnknownUnionTag),
1698                _ => num_bytes as usize,
1699            };
1700
1701            if inlined != (member_inline_size <= 4) {
1702                return Err(fidl::Error::InvalidInlineBitInEnvelope);
1703            }
1704            let _inner_offset;
1705            if inlined {
1706                decoder.check_inline_envelope_padding(offset + 8, member_inline_size)?;
1707                _inner_offset = offset + 8;
1708            } else {
1709                depth.increment()?;
1710                _inner_offset = decoder.out_of_line_offset(member_inline_size)?;
1711            }
1712            match ordinal {
1713                1 => {
1714                    #[allow(irrefutable_let_patterns)]
1715                    if let Identifier::LocalDevice(_) = self {
1716                        // Do nothing, read the value into the object
1717                    } else {
1718                        // Initialize `self` to the right variant
1719                        *self = Identifier::LocalDevice(fidl::new_empty!(LocalDevice, D));
1720                    }
1721                    #[allow(irrefutable_let_patterns)]
1722                    if let Identifier::LocalDevice(ref mut val) = self {
1723                        fidl::decode!(LocalDevice, D, val, decoder, _inner_offset, depth)?;
1724                    } else {
1725                        unreachable!()
1726                    }
1727                }
1728                2 => {
1729                    #[allow(irrefutable_let_patterns)]
1730                    if let Identifier::PeerId(_) = self {
1731                        // Do nothing, read the value into the object
1732                    } else {
1733                        // Initialize `self` to the right variant
1734                        *self =
1735                            Identifier::PeerId(fidl::new_empty!(fidl_fuchsia_bluetooth::PeerId, D));
1736                    }
1737                    #[allow(irrefutable_let_patterns)]
1738                    if let Identifier::PeerId(ref mut val) = self {
1739                        fidl::decode!(
1740                            fidl_fuchsia_bluetooth::PeerId,
1741                            D,
1742                            val,
1743                            decoder,
1744                            _inner_offset,
1745                            depth
1746                        )?;
1747                    } else {
1748                        unreachable!()
1749                    }
1750                }
1751                #[allow(deprecated)]
1752                ordinal => {
1753                    for _ in 0..num_handles {
1754                        decoder.drop_next_handle()?;
1755                    }
1756                    *self = Identifier::__SourceBreaking { unknown_ordinal: ordinal };
1757                }
1758            }
1759            if !inlined && decoder.next_out_of_line() != next_out_of_line + (num_bytes as usize) {
1760                return Err(fidl::Error::InvalidNumBytesInEnvelope);
1761            }
1762            if handles_before != decoder.remaining_handles() + (num_handles as usize) {
1763                return Err(fidl::Error::InvalidNumHandlesInEnvelope);
1764            }
1765            Ok(())
1766        }
1767    }
1768}