fidl_fuchsia_bluetooth_snoop/
fidl_fuchsia_bluetooth_snoop.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_snoop_common::*;
11use futures::future::{self, MaybeDone, TryFutureExt};
12use zx_status;
13
14#[derive(Debug, Default, PartialEq)]
15pub struct SnoopStartRequest {
16    pub follow: Option<bool>,
17    pub host_device: Option<String>,
18    pub client: Option<fidl::endpoints::ClientEnd<PacketObserverMarker>>,
19    #[doc(hidden)]
20    pub __source_breaking: fidl::marker::SourceBreaking,
21}
22
23impl fidl::Standalone<fidl::encoding::DefaultFuchsiaResourceDialect> for SnoopStartRequest {}
24
25#[derive(Debug, Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Hash)]
26pub struct PacketObserverMarker;
27
28impl fidl::endpoints::ProtocolMarker for PacketObserverMarker {
29    type Proxy = PacketObserverProxy;
30    type RequestStream = PacketObserverRequestStream;
31    #[cfg(target_os = "fuchsia")]
32    type SynchronousProxy = PacketObserverSynchronousProxy;
33
34    const DEBUG_NAME: &'static str = "(anonymous) PacketObserver";
35}
36
37pub trait PacketObserverProxyInterface: Send + Sync {
38    type ObserveResponseFut: std::future::Future<Output = Result<(), fidl::Error>> + Send;
39    fn r#observe(&self, payload: &DevicePackets) -> Self::ObserveResponseFut;
40    fn r#error(&self, payload: &CaptureError) -> Result<(), fidl::Error>;
41}
42#[derive(Debug)]
43#[cfg(target_os = "fuchsia")]
44pub struct PacketObserverSynchronousProxy {
45    client: fidl::client::sync::Client,
46}
47
48#[cfg(target_os = "fuchsia")]
49impl fidl::endpoints::SynchronousProxy for PacketObserverSynchronousProxy {
50    type Proxy = PacketObserverProxy;
51    type Protocol = PacketObserverMarker;
52
53    fn from_channel(inner: fidl::Channel) -> Self {
54        Self::new(inner)
55    }
56
57    fn into_channel(self) -> fidl::Channel {
58        self.client.into_channel()
59    }
60
61    fn as_channel(&self) -> &fidl::Channel {
62        self.client.as_channel()
63    }
64}
65
66#[cfg(target_os = "fuchsia")]
67impl PacketObserverSynchronousProxy {
68    pub fn new(channel: fidl::Channel) -> Self {
69        let protocol_name = <PacketObserverMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME;
70        Self { client: fidl::client::sync::Client::new(channel, protocol_name) }
71    }
72
73    pub fn into_channel(self) -> fidl::Channel {
74        self.client.into_channel()
75    }
76
77    /// Waits until an event arrives and returns it. It is safe for other
78    /// threads to make concurrent requests while waiting for an event.
79    pub fn wait_for_event(
80        &self,
81        deadline: zx::MonotonicInstant,
82    ) -> Result<PacketObserverEvent, fidl::Error> {
83        PacketObserverEvent::decode(self.client.wait_for_event(deadline)?)
84    }
85
86    /// Observe some packets which have been transmitted over HCI.
87    /// Return ack is used for flow control.
88    pub fn r#observe(
89        &self,
90        mut payload: &DevicePackets,
91        ___deadline: zx::MonotonicInstant,
92    ) -> Result<(), fidl::Error> {
93        let _response = self
94            .client
95            .send_query::<DevicePackets, fidl::encoding::FlexibleType<fidl::encoding::EmptyStruct>>(
96                payload,
97                0x2a82a5a9a18b79c9,
98                fidl::encoding::DynamicFlags::FLEXIBLE,
99                ___deadline,
100            )?
101            .into_result::<PacketObserverMarker>("observe")?;
102        Ok(_response)
103    }
104
105    /// Called when an error occurs either during capture or while starting
106    /// capture.  The protocol will be closed after this is sent.
107    pub fn r#error(&self, mut payload: &CaptureError) -> Result<(), fidl::Error> {
108        self.client.send::<CaptureError>(
109            payload,
110            0x6596e43f4f0761e4,
111            fidl::encoding::DynamicFlags::FLEXIBLE,
112        )
113    }
114}
115
116#[derive(Debug, Clone)]
117pub struct PacketObserverProxy {
118    client: fidl::client::Client<fidl::encoding::DefaultFuchsiaResourceDialect>,
119}
120
121impl fidl::endpoints::Proxy for PacketObserverProxy {
122    type Protocol = PacketObserverMarker;
123
124    fn from_channel(inner: ::fidl::AsyncChannel) -> Self {
125        Self::new(inner)
126    }
127
128    fn into_channel(self) -> Result<::fidl::AsyncChannel, Self> {
129        self.client.into_channel().map_err(|client| Self { client })
130    }
131
132    fn as_channel(&self) -> &::fidl::AsyncChannel {
133        self.client.as_channel()
134    }
135}
136
137impl PacketObserverProxy {
138    /// Create a new Proxy for fuchsia.bluetooth.snoop/PacketObserver.
139    pub fn new(channel: ::fidl::AsyncChannel) -> Self {
140        let protocol_name = <PacketObserverMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME;
141        Self { client: fidl::client::Client::new(channel, protocol_name) }
142    }
143
144    /// Get a Stream of events from the remote end of the protocol.
145    ///
146    /// # Panics
147    ///
148    /// Panics if the event stream was already taken.
149    pub fn take_event_stream(&self) -> PacketObserverEventStream {
150        PacketObserverEventStream { event_receiver: self.client.take_event_receiver() }
151    }
152
153    /// Observe some packets which have been transmitted over HCI.
154    /// Return ack is used for flow control.
155    pub fn r#observe(
156        &self,
157        mut payload: &DevicePackets,
158    ) -> fidl::client::QueryResponseFut<(), fidl::encoding::DefaultFuchsiaResourceDialect> {
159        PacketObserverProxyInterface::r#observe(self, payload)
160    }
161
162    /// Called when an error occurs either during capture or while starting
163    /// capture.  The protocol will be closed after this is sent.
164    pub fn r#error(&self, mut payload: &CaptureError) -> Result<(), fidl::Error> {
165        PacketObserverProxyInterface::r#error(self, payload)
166    }
167}
168
169impl PacketObserverProxyInterface for PacketObserverProxy {
170    type ObserveResponseFut =
171        fidl::client::QueryResponseFut<(), fidl::encoding::DefaultFuchsiaResourceDialect>;
172    fn r#observe(&self, mut payload: &DevicePackets) -> Self::ObserveResponseFut {
173        fn _decode(
174            mut _buf: Result<<fidl::encoding::DefaultFuchsiaResourceDialect as fidl::encoding::ResourceDialect>::MessageBufEtc, fidl::Error>,
175        ) -> Result<(), fidl::Error> {
176            let _response = fidl::client::decode_transaction_body::<
177                fidl::encoding::FlexibleType<fidl::encoding::EmptyStruct>,
178                fidl::encoding::DefaultFuchsiaResourceDialect,
179                0x2a82a5a9a18b79c9,
180            >(_buf?)?
181            .into_result::<PacketObserverMarker>("observe")?;
182            Ok(_response)
183        }
184        self.client.send_query_and_decode::<DevicePackets, ()>(
185            payload,
186            0x2a82a5a9a18b79c9,
187            fidl::encoding::DynamicFlags::FLEXIBLE,
188            _decode,
189        )
190    }
191
192    fn r#error(&self, mut payload: &CaptureError) -> Result<(), fidl::Error> {
193        self.client.send::<CaptureError>(
194            payload,
195            0x6596e43f4f0761e4,
196            fidl::encoding::DynamicFlags::FLEXIBLE,
197        )
198    }
199}
200
201pub struct PacketObserverEventStream {
202    event_receiver: fidl::client::EventReceiver<fidl::encoding::DefaultFuchsiaResourceDialect>,
203}
204
205impl std::marker::Unpin for PacketObserverEventStream {}
206
207impl futures::stream::FusedStream for PacketObserverEventStream {
208    fn is_terminated(&self) -> bool {
209        self.event_receiver.is_terminated()
210    }
211}
212
213impl futures::Stream for PacketObserverEventStream {
214    type Item = Result<PacketObserverEvent, fidl::Error>;
215
216    fn poll_next(
217        mut self: std::pin::Pin<&mut Self>,
218        cx: &mut std::task::Context<'_>,
219    ) -> std::task::Poll<Option<Self::Item>> {
220        match futures::ready!(futures::stream::StreamExt::poll_next_unpin(
221            &mut self.event_receiver,
222            cx
223        )?) {
224            Some(buf) => std::task::Poll::Ready(Some(PacketObserverEvent::decode(buf))),
225            None => std::task::Poll::Ready(None),
226        }
227    }
228}
229
230#[derive(Debug)]
231pub enum PacketObserverEvent {
232    #[non_exhaustive]
233    _UnknownEvent {
234        /// Ordinal of the event that was sent.
235        ordinal: u64,
236    },
237}
238
239impl PacketObserverEvent {
240    /// Decodes a message buffer as a [`PacketObserverEvent`].
241    fn decode(
242        mut buf: <fidl::encoding::DefaultFuchsiaResourceDialect as fidl::encoding::ResourceDialect>::MessageBufEtc,
243    ) -> Result<PacketObserverEvent, fidl::Error> {
244        let (bytes, _handles) = buf.split_mut();
245        let (tx_header, _body_bytes) = fidl::encoding::decode_transaction_header(bytes)?;
246        debug_assert_eq!(tx_header.tx_id, 0);
247        match tx_header.ordinal {
248            _ if tx_header.dynamic_flags().contains(fidl::encoding::DynamicFlags::FLEXIBLE) => {
249                Ok(PacketObserverEvent::_UnknownEvent { ordinal: tx_header.ordinal })
250            }
251            _ => Err(fidl::Error::UnknownOrdinal {
252                ordinal: tx_header.ordinal,
253                protocol_name:
254                    <PacketObserverMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME,
255            }),
256        }
257    }
258}
259
260/// A Stream of incoming requests for fuchsia.bluetooth.snoop/PacketObserver.
261pub struct PacketObserverRequestStream {
262    inner: std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>,
263    is_terminated: bool,
264}
265
266impl std::marker::Unpin for PacketObserverRequestStream {}
267
268impl futures::stream::FusedStream for PacketObserverRequestStream {
269    fn is_terminated(&self) -> bool {
270        self.is_terminated
271    }
272}
273
274impl fidl::endpoints::RequestStream for PacketObserverRequestStream {
275    type Protocol = PacketObserverMarker;
276    type ControlHandle = PacketObserverControlHandle;
277
278    fn from_channel(channel: ::fidl::AsyncChannel) -> Self {
279        Self { inner: std::sync::Arc::new(fidl::ServeInner::new(channel)), is_terminated: false }
280    }
281
282    fn control_handle(&self) -> Self::ControlHandle {
283        PacketObserverControlHandle { inner: self.inner.clone() }
284    }
285
286    fn into_inner(
287        self,
288    ) -> (::std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>, bool)
289    {
290        (self.inner, self.is_terminated)
291    }
292
293    fn from_inner(
294        inner: std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>,
295        is_terminated: bool,
296    ) -> Self {
297        Self { inner, is_terminated }
298    }
299}
300
301impl futures::Stream for PacketObserverRequestStream {
302    type Item = Result<PacketObserverRequest, fidl::Error>;
303
304    fn poll_next(
305        mut self: std::pin::Pin<&mut Self>,
306        cx: &mut std::task::Context<'_>,
307    ) -> std::task::Poll<Option<Self::Item>> {
308        let this = &mut *self;
309        if this.inner.check_shutdown(cx) {
310            this.is_terminated = true;
311            return std::task::Poll::Ready(None);
312        }
313        if this.is_terminated {
314            panic!("polled PacketObserverRequestStream after completion");
315        }
316        fidl::encoding::with_tls_decode_buf::<_, fidl::encoding::DefaultFuchsiaResourceDialect>(
317            |bytes, handles| {
318                match this.inner.channel().read_etc(cx, bytes, handles) {
319                    std::task::Poll::Ready(Ok(())) => {}
320                    std::task::Poll::Pending => return std::task::Poll::Pending,
321                    std::task::Poll::Ready(Err(zx_status::Status::PEER_CLOSED)) => {
322                        this.is_terminated = true;
323                        return std::task::Poll::Ready(None);
324                    }
325                    std::task::Poll::Ready(Err(e)) => {
326                        return std::task::Poll::Ready(Some(Err(fidl::Error::ServerRequestRead(
327                            e.into(),
328                        ))))
329                    }
330                }
331
332                // A message has been received from the channel
333                let (header, _body_bytes) = fidl::encoding::decode_transaction_header(bytes)?;
334
335                std::task::Poll::Ready(Some(match header.ordinal {
336                    0x2a82a5a9a18b79c9 => {
337                        header.validate_request_tx_id(fidl::MethodType::TwoWay)?;
338                        let mut req = fidl::new_empty!(
339                            DevicePackets,
340                            fidl::encoding::DefaultFuchsiaResourceDialect
341                        );
342                        fidl::encoding::Decoder::<fidl::encoding::DefaultFuchsiaResourceDialect>::decode_into::<DevicePackets>(&header, _body_bytes, handles, &mut req)?;
343                        let control_handle =
344                            PacketObserverControlHandle { inner: this.inner.clone() };
345                        Ok(PacketObserverRequest::Observe {
346                            payload: req,
347                            responder: PacketObserverObserveResponder {
348                                control_handle: std::mem::ManuallyDrop::new(control_handle),
349                                tx_id: header.tx_id,
350                            },
351                        })
352                    }
353                    0x6596e43f4f0761e4 => {
354                        header.validate_request_tx_id(fidl::MethodType::OneWay)?;
355                        let mut req = fidl::new_empty!(
356                            CaptureError,
357                            fidl::encoding::DefaultFuchsiaResourceDialect
358                        );
359                        fidl::encoding::Decoder::<fidl::encoding::DefaultFuchsiaResourceDialect>::decode_into::<CaptureError>(&header, _body_bytes, handles, &mut req)?;
360                        let control_handle =
361                            PacketObserverControlHandle { inner: this.inner.clone() };
362                        Ok(PacketObserverRequest::Error { payload: req, control_handle })
363                    }
364                    _ if header.tx_id == 0
365                        && header
366                            .dynamic_flags()
367                            .contains(fidl::encoding::DynamicFlags::FLEXIBLE) =>
368                    {
369                        Ok(PacketObserverRequest::_UnknownMethod {
370                            ordinal: header.ordinal,
371                            control_handle: PacketObserverControlHandle {
372                                inner: this.inner.clone(),
373                            },
374                            method_type: fidl::MethodType::OneWay,
375                        })
376                    }
377                    _ if header
378                        .dynamic_flags()
379                        .contains(fidl::encoding::DynamicFlags::FLEXIBLE) =>
380                    {
381                        this.inner.send_framework_err(
382                            fidl::encoding::FrameworkErr::UnknownMethod,
383                            header.tx_id,
384                            header.ordinal,
385                            header.dynamic_flags(),
386                            (bytes, handles),
387                        )?;
388                        Ok(PacketObserverRequest::_UnknownMethod {
389                            ordinal: header.ordinal,
390                            control_handle: PacketObserverControlHandle {
391                                inner: this.inner.clone(),
392                            },
393                            method_type: fidl::MethodType::TwoWay,
394                        })
395                    }
396                    _ => Err(fidl::Error::UnknownOrdinal {
397                        ordinal: header.ordinal,
398                        protocol_name:
399                            <PacketObserverMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME,
400                    }),
401                }))
402            },
403        )
404    }
405}
406
407#[derive(Debug)]
408pub enum PacketObserverRequest {
409    /// Observe some packets which have been transmitted over HCI.
410    /// Return ack is used for flow control.
411    Observe { payload: DevicePackets, responder: PacketObserverObserveResponder },
412    /// Called when an error occurs either during capture or while starting
413    /// capture.  The protocol will be closed after this is sent.
414    Error { payload: CaptureError, control_handle: PacketObserverControlHandle },
415    /// An interaction was received which does not match any known method.
416    #[non_exhaustive]
417    _UnknownMethod {
418        /// Ordinal of the method that was called.
419        ordinal: u64,
420        control_handle: PacketObserverControlHandle,
421        method_type: fidl::MethodType,
422    },
423}
424
425impl PacketObserverRequest {
426    #[allow(irrefutable_let_patterns)]
427    pub fn into_observe(self) -> Option<(DevicePackets, PacketObserverObserveResponder)> {
428        if let PacketObserverRequest::Observe { payload, responder } = self {
429            Some((payload, responder))
430        } else {
431            None
432        }
433    }
434
435    #[allow(irrefutable_let_patterns)]
436    pub fn into_error(self) -> Option<(CaptureError, PacketObserverControlHandle)> {
437        if let PacketObserverRequest::Error { payload, control_handle } = self {
438            Some((payload, control_handle))
439        } else {
440            None
441        }
442    }
443
444    /// Name of the method defined in FIDL
445    pub fn method_name(&self) -> &'static str {
446        match *self {
447            PacketObserverRequest::Observe { .. } => "observe",
448            PacketObserverRequest::Error { .. } => "error",
449            PacketObserverRequest::_UnknownMethod {
450                method_type: fidl::MethodType::OneWay, ..
451            } => "unknown one-way method",
452            PacketObserverRequest::_UnknownMethod {
453                method_type: fidl::MethodType::TwoWay, ..
454            } => "unknown two-way method",
455        }
456    }
457}
458
459#[derive(Debug, Clone)]
460pub struct PacketObserverControlHandle {
461    inner: std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>,
462}
463
464impl fidl::endpoints::ControlHandle for PacketObserverControlHandle {
465    fn shutdown(&self) {
466        self.inner.shutdown()
467    }
468    fn shutdown_with_epitaph(&self, status: zx_status::Status) {
469        self.inner.shutdown_with_epitaph(status)
470    }
471
472    fn is_closed(&self) -> bool {
473        self.inner.channel().is_closed()
474    }
475    fn on_closed(&self) -> fidl::OnSignalsRef<'_> {
476        self.inner.channel().on_closed()
477    }
478
479    #[cfg(target_os = "fuchsia")]
480    fn signal_peer(
481        &self,
482        clear_mask: zx::Signals,
483        set_mask: zx::Signals,
484    ) -> Result<(), zx_status::Status> {
485        use fidl::Peered;
486        self.inner.channel().signal_peer(clear_mask, set_mask)
487    }
488}
489
490impl PacketObserverControlHandle {}
491
492#[must_use = "FIDL methods require a response to be sent"]
493#[derive(Debug)]
494pub struct PacketObserverObserveResponder {
495    control_handle: std::mem::ManuallyDrop<PacketObserverControlHandle>,
496    tx_id: u32,
497}
498
499/// Set the the channel to be shutdown (see [`PacketObserverControlHandle::shutdown`])
500/// if the responder is dropped without sending a response, so that the client
501/// doesn't hang. To prevent this behavior, call `drop_without_shutdown`.
502impl std::ops::Drop for PacketObserverObserveResponder {
503    fn drop(&mut self) {
504        self.control_handle.shutdown();
505        // Safety: drops once, never accessed again
506        unsafe { std::mem::ManuallyDrop::drop(&mut self.control_handle) };
507    }
508}
509
510impl fidl::endpoints::Responder for PacketObserverObserveResponder {
511    type ControlHandle = PacketObserverControlHandle;
512
513    fn control_handle(&self) -> &PacketObserverControlHandle {
514        &self.control_handle
515    }
516
517    fn drop_without_shutdown(mut self) {
518        // Safety: drops once, never accessed again due to mem::forget
519        unsafe { std::mem::ManuallyDrop::drop(&mut self.control_handle) };
520        // Prevent Drop from running (which would shut down the channel)
521        std::mem::forget(self);
522    }
523}
524
525impl PacketObserverObserveResponder {
526    /// Sends a response to the FIDL transaction.
527    ///
528    /// Sets the channel to shutdown if an error occurs.
529    pub fn send(self) -> Result<(), fidl::Error> {
530        let _result = self.send_raw();
531        if _result.is_err() {
532            self.control_handle.shutdown();
533        }
534        self.drop_without_shutdown();
535        _result
536    }
537
538    /// Similar to "send" but does not shutdown the channel if an error occurs.
539    pub fn send_no_shutdown_on_err(self) -> Result<(), fidl::Error> {
540        let _result = self.send_raw();
541        self.drop_without_shutdown();
542        _result
543    }
544
545    fn send_raw(&self) -> Result<(), fidl::Error> {
546        self.control_handle.inner.send::<fidl::encoding::FlexibleType<fidl::encoding::EmptyStruct>>(
547            fidl::encoding::Flexible::new(()),
548            self.tx_id,
549            0x2a82a5a9a18b79c9,
550            fidl::encoding::DynamicFlags::FLEXIBLE,
551        )
552    }
553}
554
555#[derive(Debug, Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Hash)]
556pub struct SnoopMarker;
557
558impl fidl::endpoints::ProtocolMarker for SnoopMarker {
559    type Proxy = SnoopProxy;
560    type RequestStream = SnoopRequestStream;
561    #[cfg(target_os = "fuchsia")]
562    type SynchronousProxy = SnoopSynchronousProxy;
563
564    const DEBUG_NAME: &'static str = "fuchsia.bluetooth.snoop.Snoop";
565}
566impl fidl::endpoints::DiscoverableProtocolMarker for SnoopMarker {}
567
568pub trait SnoopProxyInterface: Send + Sync {
569    fn r#start(&self, payload: SnoopStartRequest) -> Result<(), fidl::Error>;
570}
571#[derive(Debug)]
572#[cfg(target_os = "fuchsia")]
573pub struct SnoopSynchronousProxy {
574    client: fidl::client::sync::Client,
575}
576
577#[cfg(target_os = "fuchsia")]
578impl fidl::endpoints::SynchronousProxy for SnoopSynchronousProxy {
579    type Proxy = SnoopProxy;
580    type Protocol = SnoopMarker;
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 SnoopSynchronousProxy {
597    pub fn new(channel: fidl::Channel) -> Self {
598        let protocol_name = <SnoopMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME;
599        Self { client: fidl::client::sync::Client::new(channel, protocol_name) }
600    }
601
602    pub fn into_channel(self) -> fidl::Channel {
603        self.client.into_channel()
604    }
605
606    /// Waits until an event arrives and returns it. It is safe for other
607    /// threads to make concurrent requests while waiting for an event.
608    pub fn wait_for_event(
609        &self,
610        deadline: zx::MonotonicInstant,
611    ) -> Result<SnoopEvent, fidl::Error> {
612        SnoopEvent::decode(self.client.wait_for_event(deadline)?)
613    }
614
615    /// Subscribe to receive packets from the server. Packets that have been recorded are sent
616    /// first.
617    ///
618    /// If `follow` is true, the protocol stays open and packets are returned to the client as
619    /// the snoop server receives them. If `follow` is missing or false, the client is closed
620    /// when all currently recorded packets have been sent.
621    ///
622    /// A `host_device` name may be provided; if so, only events from that host are sent.
623    /// If `host_device` is absent, packets from all host devices are sent.
624    ///
625    /// Errors are reported through the client.
626    pub fn r#start(&self, mut payload: SnoopStartRequest) -> Result<(), fidl::Error> {
627        self.client.send::<SnoopStartRequest>(
628            &mut payload,
629            0xa520491a4a82f24,
630            fidl::encoding::DynamicFlags::FLEXIBLE,
631        )
632    }
633}
634
635#[derive(Debug, Clone)]
636pub struct SnoopProxy {
637    client: fidl::client::Client<fidl::encoding::DefaultFuchsiaResourceDialect>,
638}
639
640impl fidl::endpoints::Proxy for SnoopProxy {
641    type Protocol = SnoopMarker;
642
643    fn from_channel(inner: ::fidl::AsyncChannel) -> Self {
644        Self::new(inner)
645    }
646
647    fn into_channel(self) -> Result<::fidl::AsyncChannel, Self> {
648        self.client.into_channel().map_err(|client| Self { client })
649    }
650
651    fn as_channel(&self) -> &::fidl::AsyncChannel {
652        self.client.as_channel()
653    }
654}
655
656impl SnoopProxy {
657    /// Create a new Proxy for fuchsia.bluetooth.snoop/Snoop.
658    pub fn new(channel: ::fidl::AsyncChannel) -> Self {
659        let protocol_name = <SnoopMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME;
660        Self { client: fidl::client::Client::new(channel, protocol_name) }
661    }
662
663    /// Get a Stream of events from the remote end of the protocol.
664    ///
665    /// # Panics
666    ///
667    /// Panics if the event stream was already taken.
668    pub fn take_event_stream(&self) -> SnoopEventStream {
669        SnoopEventStream { event_receiver: self.client.take_event_receiver() }
670    }
671
672    /// Subscribe to receive packets from the server. Packets that have been recorded are sent
673    /// first.
674    ///
675    /// If `follow` is true, the protocol stays open and packets are returned to the client as
676    /// the snoop server receives them. If `follow` is missing or false, the client is closed
677    /// when all currently recorded packets have been sent.
678    ///
679    /// A `host_device` name may be provided; if so, only events from that host are sent.
680    /// If `host_device` is absent, packets from all host devices are sent.
681    ///
682    /// Errors are reported through the client.
683    pub fn r#start(&self, mut payload: SnoopStartRequest) -> Result<(), fidl::Error> {
684        SnoopProxyInterface::r#start(self, payload)
685    }
686}
687
688impl SnoopProxyInterface for SnoopProxy {
689    fn r#start(&self, mut payload: SnoopStartRequest) -> Result<(), fidl::Error> {
690        self.client.send::<SnoopStartRequest>(
691            &mut payload,
692            0xa520491a4a82f24,
693            fidl::encoding::DynamicFlags::FLEXIBLE,
694        )
695    }
696}
697
698pub struct SnoopEventStream {
699    event_receiver: fidl::client::EventReceiver<fidl::encoding::DefaultFuchsiaResourceDialect>,
700}
701
702impl std::marker::Unpin for SnoopEventStream {}
703
704impl futures::stream::FusedStream for SnoopEventStream {
705    fn is_terminated(&self) -> bool {
706        self.event_receiver.is_terminated()
707    }
708}
709
710impl futures::Stream for SnoopEventStream {
711    type Item = Result<SnoopEvent, fidl::Error>;
712
713    fn poll_next(
714        mut self: std::pin::Pin<&mut Self>,
715        cx: &mut std::task::Context<'_>,
716    ) -> std::task::Poll<Option<Self::Item>> {
717        match futures::ready!(futures::stream::StreamExt::poll_next_unpin(
718            &mut self.event_receiver,
719            cx
720        )?) {
721            Some(buf) => std::task::Poll::Ready(Some(SnoopEvent::decode(buf))),
722            None => std::task::Poll::Ready(None),
723        }
724    }
725}
726
727#[derive(Debug)]
728pub enum SnoopEvent {
729    #[non_exhaustive]
730    _UnknownEvent {
731        /// Ordinal of the event that was sent.
732        ordinal: u64,
733    },
734}
735
736impl SnoopEvent {
737    /// Decodes a message buffer as a [`SnoopEvent`].
738    fn decode(
739        mut buf: <fidl::encoding::DefaultFuchsiaResourceDialect as fidl::encoding::ResourceDialect>::MessageBufEtc,
740    ) -> Result<SnoopEvent, fidl::Error> {
741        let (bytes, _handles) = buf.split_mut();
742        let (tx_header, _body_bytes) = fidl::encoding::decode_transaction_header(bytes)?;
743        debug_assert_eq!(tx_header.tx_id, 0);
744        match tx_header.ordinal {
745            _ if tx_header.dynamic_flags().contains(fidl::encoding::DynamicFlags::FLEXIBLE) => {
746                Ok(SnoopEvent::_UnknownEvent { ordinal: tx_header.ordinal })
747            }
748            _ => Err(fidl::Error::UnknownOrdinal {
749                ordinal: tx_header.ordinal,
750                protocol_name: <SnoopMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME,
751            }),
752        }
753    }
754}
755
756/// A Stream of incoming requests for fuchsia.bluetooth.snoop/Snoop.
757pub struct SnoopRequestStream {
758    inner: std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>,
759    is_terminated: bool,
760}
761
762impl std::marker::Unpin for SnoopRequestStream {}
763
764impl futures::stream::FusedStream for SnoopRequestStream {
765    fn is_terminated(&self) -> bool {
766        self.is_terminated
767    }
768}
769
770impl fidl::endpoints::RequestStream for SnoopRequestStream {
771    type Protocol = SnoopMarker;
772    type ControlHandle = SnoopControlHandle;
773
774    fn from_channel(channel: ::fidl::AsyncChannel) -> Self {
775        Self { inner: std::sync::Arc::new(fidl::ServeInner::new(channel)), is_terminated: false }
776    }
777
778    fn control_handle(&self) -> Self::ControlHandle {
779        SnoopControlHandle { inner: self.inner.clone() }
780    }
781
782    fn into_inner(
783        self,
784    ) -> (::std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>, bool)
785    {
786        (self.inner, self.is_terminated)
787    }
788
789    fn from_inner(
790        inner: std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>,
791        is_terminated: bool,
792    ) -> Self {
793        Self { inner, is_terminated }
794    }
795}
796
797impl futures::Stream for SnoopRequestStream {
798    type Item = Result<SnoopRequest, fidl::Error>;
799
800    fn poll_next(
801        mut self: std::pin::Pin<&mut Self>,
802        cx: &mut std::task::Context<'_>,
803    ) -> std::task::Poll<Option<Self::Item>> {
804        let this = &mut *self;
805        if this.inner.check_shutdown(cx) {
806            this.is_terminated = true;
807            return std::task::Poll::Ready(None);
808        }
809        if this.is_terminated {
810            panic!("polled SnoopRequestStream after completion");
811        }
812        fidl::encoding::with_tls_decode_buf::<_, fidl::encoding::DefaultFuchsiaResourceDialect>(
813            |bytes, handles| {
814                match this.inner.channel().read_etc(cx, bytes, handles) {
815                    std::task::Poll::Ready(Ok(())) => {}
816                    std::task::Poll::Pending => return std::task::Poll::Pending,
817                    std::task::Poll::Ready(Err(zx_status::Status::PEER_CLOSED)) => {
818                        this.is_terminated = true;
819                        return std::task::Poll::Ready(None);
820                    }
821                    std::task::Poll::Ready(Err(e)) => {
822                        return std::task::Poll::Ready(Some(Err(fidl::Error::ServerRequestRead(
823                            e.into(),
824                        ))))
825                    }
826                }
827
828                // A message has been received from the channel
829                let (header, _body_bytes) = fidl::encoding::decode_transaction_header(bytes)?;
830
831                std::task::Poll::Ready(Some(match header.ordinal {
832                    0xa520491a4a82f24 => {
833                        header.validate_request_tx_id(fidl::MethodType::OneWay)?;
834                        let mut req = fidl::new_empty!(
835                            SnoopStartRequest,
836                            fidl::encoding::DefaultFuchsiaResourceDialect
837                        );
838                        fidl::encoding::Decoder::<fidl::encoding::DefaultFuchsiaResourceDialect>::decode_into::<SnoopStartRequest>(&header, _body_bytes, handles, &mut req)?;
839                        let control_handle = SnoopControlHandle { inner: this.inner.clone() };
840                        Ok(SnoopRequest::Start { payload: req, control_handle })
841                    }
842                    _ if header.tx_id == 0
843                        && header
844                            .dynamic_flags()
845                            .contains(fidl::encoding::DynamicFlags::FLEXIBLE) =>
846                    {
847                        Ok(SnoopRequest::_UnknownMethod {
848                            ordinal: header.ordinal,
849                            control_handle: SnoopControlHandle { inner: this.inner.clone() },
850                            method_type: fidl::MethodType::OneWay,
851                        })
852                    }
853                    _ if header
854                        .dynamic_flags()
855                        .contains(fidl::encoding::DynamicFlags::FLEXIBLE) =>
856                    {
857                        this.inner.send_framework_err(
858                            fidl::encoding::FrameworkErr::UnknownMethod,
859                            header.tx_id,
860                            header.ordinal,
861                            header.dynamic_flags(),
862                            (bytes, handles),
863                        )?;
864                        Ok(SnoopRequest::_UnknownMethod {
865                            ordinal: header.ordinal,
866                            control_handle: SnoopControlHandle { inner: this.inner.clone() },
867                            method_type: fidl::MethodType::TwoWay,
868                        })
869                    }
870                    _ => Err(fidl::Error::UnknownOrdinal {
871                        ordinal: header.ordinal,
872                        protocol_name: <SnoopMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME,
873                    }),
874                }))
875            },
876        )
877    }
878}
879
880/// Interface to receive packets recorded as received or transmitted for a Bluetooth host.
881#[derive(Debug)]
882pub enum SnoopRequest {
883    /// Subscribe to receive packets from the server. Packets that have been recorded are sent
884    /// first.
885    ///
886    /// If `follow` is true, the protocol stays open and packets are returned to the client as
887    /// the snoop server receives them. If `follow` is missing or false, the client is closed
888    /// when all currently recorded packets have been sent.
889    ///
890    /// A `host_device` name may be provided; if so, only events from that host are sent.
891    /// If `host_device` is absent, packets from all host devices are sent.
892    ///
893    /// Errors are reported through the client.
894    Start { payload: SnoopStartRequest, control_handle: SnoopControlHandle },
895    /// An interaction was received which does not match any known method.
896    #[non_exhaustive]
897    _UnknownMethod {
898        /// Ordinal of the method that was called.
899        ordinal: u64,
900        control_handle: SnoopControlHandle,
901        method_type: fidl::MethodType,
902    },
903}
904
905impl SnoopRequest {
906    #[allow(irrefutable_let_patterns)]
907    pub fn into_start(self) -> Option<(SnoopStartRequest, SnoopControlHandle)> {
908        if let SnoopRequest::Start { payload, control_handle } = self {
909            Some((payload, control_handle))
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            SnoopRequest::Start { .. } => "start",
919            SnoopRequest::_UnknownMethod { method_type: fidl::MethodType::OneWay, .. } => {
920                "unknown one-way method"
921            }
922            SnoopRequest::_UnknownMethod { method_type: fidl::MethodType::TwoWay, .. } => {
923                "unknown two-way method"
924            }
925        }
926    }
927}
928
929#[derive(Debug, Clone)]
930pub struct SnoopControlHandle {
931    inner: std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>,
932}
933
934impl fidl::endpoints::ControlHandle for SnoopControlHandle {
935    fn shutdown(&self) {
936        self.inner.shutdown()
937    }
938    fn shutdown_with_epitaph(&self, status: zx_status::Status) {
939        self.inner.shutdown_with_epitaph(status)
940    }
941
942    fn is_closed(&self) -> bool {
943        self.inner.channel().is_closed()
944    }
945    fn on_closed(&self) -> fidl::OnSignalsRef<'_> {
946        self.inner.channel().on_closed()
947    }
948
949    #[cfg(target_os = "fuchsia")]
950    fn signal_peer(
951        &self,
952        clear_mask: zx::Signals,
953        set_mask: zx::Signals,
954    ) -> Result<(), zx_status::Status> {
955        use fidl::Peered;
956        self.inner.channel().signal_peer(clear_mask, set_mask)
957    }
958}
959
960impl SnoopControlHandle {}
961
962mod internal {
963    use super::*;
964
965    impl SnoopStartRequest {
966        #[inline(always)]
967        fn max_ordinal_present(&self) -> u64 {
968            if let Some(_) = self.client {
969                return 3;
970            }
971            if let Some(_) = self.host_device {
972                return 2;
973            }
974            if let Some(_) = self.follow {
975                return 1;
976            }
977            0
978        }
979    }
980
981    impl fidl::encoding::ResourceTypeMarker for SnoopStartRequest {
982        type Borrowed<'a> = &'a mut Self;
983        fn take_or_borrow<'a>(
984            value: &'a mut <Self as fidl::encoding::TypeMarker>::Owned,
985        ) -> Self::Borrowed<'a> {
986            value
987        }
988    }
989
990    unsafe impl fidl::encoding::TypeMarker for SnoopStartRequest {
991        type Owned = Self;
992
993        #[inline(always)]
994        fn inline_align(_context: fidl::encoding::Context) -> usize {
995            8
996        }
997
998        #[inline(always)]
999        fn inline_size(_context: fidl::encoding::Context) -> usize {
1000            16
1001        }
1002    }
1003
1004    unsafe impl
1005        fidl::encoding::Encode<SnoopStartRequest, fidl::encoding::DefaultFuchsiaResourceDialect>
1006        for &mut SnoopStartRequest
1007    {
1008        unsafe fn encode(
1009            self,
1010            encoder: &mut fidl::encoding::Encoder<
1011                '_,
1012                fidl::encoding::DefaultFuchsiaResourceDialect,
1013            >,
1014            offset: usize,
1015            mut depth: fidl::encoding::Depth,
1016        ) -> fidl::Result<()> {
1017            encoder.debug_check_bounds::<SnoopStartRequest>(offset);
1018            // Vector header
1019            let max_ordinal: u64 = self.max_ordinal_present();
1020            encoder.write_num(max_ordinal, offset);
1021            encoder.write_num(fidl::encoding::ALLOC_PRESENT_U64, offset + 8);
1022            // Calling encoder.out_of_line_offset(0) is not allowed.
1023            if max_ordinal == 0 {
1024                return Ok(());
1025            }
1026            depth.increment()?;
1027            let envelope_size = 8;
1028            let bytes_len = max_ordinal as usize * envelope_size;
1029            #[allow(unused_variables)]
1030            let offset = encoder.out_of_line_offset(bytes_len);
1031            let mut _prev_end_offset: usize = 0;
1032            if 1 > max_ordinal {
1033                return Ok(());
1034            }
1035
1036            // Write at offset+(ordinal-1)*envelope_size, since ordinals are one-based and envelopes
1037            // are envelope_size bytes.
1038            let cur_offset: usize = (1 - 1) * envelope_size;
1039
1040            // Zero reserved fields.
1041            encoder.padding(offset + _prev_end_offset, cur_offset - _prev_end_offset);
1042
1043            // Safety:
1044            // - bytes_len is calculated to fit envelope_size*max(member.ordinal).
1045            // - Since cur_offset is envelope_size*(member.ordinal - 1) and the envelope takes
1046            //   envelope_size bytes, there is always sufficient room.
1047            fidl::encoding::encode_in_envelope_optional::<
1048                bool,
1049                fidl::encoding::DefaultFuchsiaResourceDialect,
1050            >(
1051                self.follow.as_ref().map(<bool as fidl::encoding::ValueTypeMarker>::borrow),
1052                encoder,
1053                offset + cur_offset,
1054                depth,
1055            )?;
1056
1057            _prev_end_offset = cur_offset + envelope_size;
1058            if 2 > max_ordinal {
1059                return Ok(());
1060            }
1061
1062            // Write at offset+(ordinal-1)*envelope_size, since ordinals are one-based and envelopes
1063            // are envelope_size bytes.
1064            let cur_offset: usize = (2 - 1) * envelope_size;
1065
1066            // Zero reserved fields.
1067            encoder.padding(offset + _prev_end_offset, cur_offset - _prev_end_offset);
1068
1069            // Safety:
1070            // - bytes_len is calculated to fit envelope_size*max(member.ordinal).
1071            // - Since cur_offset is envelope_size*(member.ordinal - 1) and the envelope takes
1072            //   envelope_size bytes, there is always sufficient room.
1073            fidl::encoding::encode_in_envelope_optional::<
1074                fidl::encoding::BoundedString<255>,
1075                fidl::encoding::DefaultFuchsiaResourceDialect,
1076            >(
1077                self.host_device.as_ref().map(
1078                    <fidl::encoding::BoundedString<255> as fidl::encoding::ValueTypeMarker>::borrow,
1079                ),
1080                encoder,
1081                offset + cur_offset,
1082                depth,
1083            )?;
1084
1085            _prev_end_offset = cur_offset + envelope_size;
1086            if 3 > max_ordinal {
1087                return Ok(());
1088            }
1089
1090            // Write at offset+(ordinal-1)*envelope_size, since ordinals are one-based and envelopes
1091            // are envelope_size bytes.
1092            let cur_offset: usize = (3 - 1) * envelope_size;
1093
1094            // Zero reserved fields.
1095            encoder.padding(offset + _prev_end_offset, cur_offset - _prev_end_offset);
1096
1097            // Safety:
1098            // - bytes_len is calculated to fit envelope_size*max(member.ordinal).
1099            // - Since cur_offset is envelope_size*(member.ordinal - 1) and the envelope takes
1100            //   envelope_size bytes, there is always sufficient room.
1101            fidl::encoding::encode_in_envelope_optional::<fidl::encoding::Endpoint<fidl::endpoints::ClientEnd<PacketObserverMarker>>, fidl::encoding::DefaultFuchsiaResourceDialect>(
1102            self.client.as_mut().map(<fidl::encoding::Endpoint<fidl::endpoints::ClientEnd<PacketObserverMarker>> as fidl::encoding::ResourceTypeMarker>::take_or_borrow),
1103            encoder, offset + cur_offset, depth
1104        )?;
1105
1106            _prev_end_offset = cur_offset + envelope_size;
1107
1108            Ok(())
1109        }
1110    }
1111
1112    impl fidl::encoding::Decode<Self, fidl::encoding::DefaultFuchsiaResourceDialect>
1113        for SnoopStartRequest
1114    {
1115        #[inline(always)]
1116        fn new_empty() -> Self {
1117            Self::default()
1118        }
1119
1120        unsafe fn decode(
1121            &mut self,
1122            decoder: &mut fidl::encoding::Decoder<
1123                '_,
1124                fidl::encoding::DefaultFuchsiaResourceDialect,
1125            >,
1126            offset: usize,
1127            mut depth: fidl::encoding::Depth,
1128        ) -> fidl::Result<()> {
1129            decoder.debug_check_bounds::<Self>(offset);
1130            let len = match fidl::encoding::decode_vector_header(decoder, offset)? {
1131                None => return Err(fidl::Error::NotNullable),
1132                Some(len) => len,
1133            };
1134            // Calling decoder.out_of_line_offset(0) is not allowed.
1135            if len == 0 {
1136                return Ok(());
1137            };
1138            depth.increment()?;
1139            let envelope_size = 8;
1140            let bytes_len = len * envelope_size;
1141            let offset = decoder.out_of_line_offset(bytes_len)?;
1142            // Decode the envelope for each type.
1143            let mut _next_ordinal_to_read = 0;
1144            let mut next_offset = offset;
1145            let end_offset = offset + bytes_len;
1146            _next_ordinal_to_read += 1;
1147            if next_offset >= end_offset {
1148                return Ok(());
1149            }
1150
1151            // Decode unknown envelopes for gaps in ordinals.
1152            while _next_ordinal_to_read < 1 {
1153                fidl::encoding::decode_unknown_envelope(decoder, next_offset, depth)?;
1154                _next_ordinal_to_read += 1;
1155                next_offset += envelope_size;
1156            }
1157
1158            let next_out_of_line = decoder.next_out_of_line();
1159            let handles_before = decoder.remaining_handles();
1160            if let Some((inlined, num_bytes, num_handles)) =
1161                fidl::encoding::decode_envelope_header(decoder, next_offset)?
1162            {
1163                let member_inline_size =
1164                    <bool as fidl::encoding::TypeMarker>::inline_size(decoder.context);
1165                if inlined != (member_inline_size <= 4) {
1166                    return Err(fidl::Error::InvalidInlineBitInEnvelope);
1167                }
1168                let inner_offset;
1169                let mut inner_depth = depth.clone();
1170                if inlined {
1171                    decoder.check_inline_envelope_padding(next_offset, member_inline_size)?;
1172                    inner_offset = next_offset;
1173                } else {
1174                    inner_offset = decoder.out_of_line_offset(member_inline_size)?;
1175                    inner_depth.increment()?;
1176                }
1177                let val_ref = self.follow.get_or_insert_with(|| {
1178                    fidl::new_empty!(bool, fidl::encoding::DefaultFuchsiaResourceDialect)
1179                });
1180                fidl::decode!(
1181                    bool,
1182                    fidl::encoding::DefaultFuchsiaResourceDialect,
1183                    val_ref,
1184                    decoder,
1185                    inner_offset,
1186                    inner_depth
1187                )?;
1188                if !inlined && decoder.next_out_of_line() != next_out_of_line + (num_bytes as usize)
1189                {
1190                    return Err(fidl::Error::InvalidNumBytesInEnvelope);
1191                }
1192                if handles_before != decoder.remaining_handles() + (num_handles as usize) {
1193                    return Err(fidl::Error::InvalidNumHandlesInEnvelope);
1194                }
1195            }
1196
1197            next_offset += envelope_size;
1198            _next_ordinal_to_read += 1;
1199            if next_offset >= end_offset {
1200                return Ok(());
1201            }
1202
1203            // Decode unknown envelopes for gaps in ordinals.
1204            while _next_ordinal_to_read < 2 {
1205                fidl::encoding::decode_unknown_envelope(decoder, next_offset, depth)?;
1206                _next_ordinal_to_read += 1;
1207                next_offset += envelope_size;
1208            }
1209
1210            let next_out_of_line = decoder.next_out_of_line();
1211            let handles_before = decoder.remaining_handles();
1212            if let Some((inlined, num_bytes, num_handles)) =
1213                fidl::encoding::decode_envelope_header(decoder, next_offset)?
1214            {
1215                let member_inline_size =
1216                    <fidl::encoding::BoundedString<255> as fidl::encoding::TypeMarker>::inline_size(
1217                        decoder.context,
1218                    );
1219                if inlined != (member_inline_size <= 4) {
1220                    return Err(fidl::Error::InvalidInlineBitInEnvelope);
1221                }
1222                let inner_offset;
1223                let mut inner_depth = depth.clone();
1224                if inlined {
1225                    decoder.check_inline_envelope_padding(next_offset, member_inline_size)?;
1226                    inner_offset = next_offset;
1227                } else {
1228                    inner_offset = decoder.out_of_line_offset(member_inline_size)?;
1229                    inner_depth.increment()?;
1230                }
1231                let val_ref = self.host_device.get_or_insert_with(|| {
1232                    fidl::new_empty!(
1233                        fidl::encoding::BoundedString<255>,
1234                        fidl::encoding::DefaultFuchsiaResourceDialect
1235                    )
1236                });
1237                fidl::decode!(
1238                    fidl::encoding::BoundedString<255>,
1239                    fidl::encoding::DefaultFuchsiaResourceDialect,
1240                    val_ref,
1241                    decoder,
1242                    inner_offset,
1243                    inner_depth
1244                )?;
1245                if !inlined && decoder.next_out_of_line() != next_out_of_line + (num_bytes as usize)
1246                {
1247                    return Err(fidl::Error::InvalidNumBytesInEnvelope);
1248                }
1249                if handles_before != decoder.remaining_handles() + (num_handles as usize) {
1250                    return Err(fidl::Error::InvalidNumHandlesInEnvelope);
1251                }
1252            }
1253
1254            next_offset += envelope_size;
1255            _next_ordinal_to_read += 1;
1256            if next_offset >= end_offset {
1257                return Ok(());
1258            }
1259
1260            // Decode unknown envelopes for gaps in ordinals.
1261            while _next_ordinal_to_read < 3 {
1262                fidl::encoding::decode_unknown_envelope(decoder, next_offset, depth)?;
1263                _next_ordinal_to_read += 1;
1264                next_offset += envelope_size;
1265            }
1266
1267            let next_out_of_line = decoder.next_out_of_line();
1268            let handles_before = decoder.remaining_handles();
1269            if let Some((inlined, num_bytes, num_handles)) =
1270                fidl::encoding::decode_envelope_header(decoder, next_offset)?
1271            {
1272                let member_inline_size = <fidl::encoding::Endpoint<
1273                    fidl::endpoints::ClientEnd<PacketObserverMarker>,
1274                > as fidl::encoding::TypeMarker>::inline_size(
1275                    decoder.context
1276                );
1277                if inlined != (member_inline_size <= 4) {
1278                    return Err(fidl::Error::InvalidInlineBitInEnvelope);
1279                }
1280                let inner_offset;
1281                let mut inner_depth = depth.clone();
1282                if inlined {
1283                    decoder.check_inline_envelope_padding(next_offset, member_inline_size)?;
1284                    inner_offset = next_offset;
1285                } else {
1286                    inner_offset = decoder.out_of_line_offset(member_inline_size)?;
1287                    inner_depth.increment()?;
1288                }
1289                let val_ref = self.client.get_or_insert_with(|| {
1290                    fidl::new_empty!(
1291                        fidl::encoding::Endpoint<fidl::endpoints::ClientEnd<PacketObserverMarker>>,
1292                        fidl::encoding::DefaultFuchsiaResourceDialect
1293                    )
1294                });
1295                fidl::decode!(
1296                    fidl::encoding::Endpoint<fidl::endpoints::ClientEnd<PacketObserverMarker>>,
1297                    fidl::encoding::DefaultFuchsiaResourceDialect,
1298                    val_ref,
1299                    decoder,
1300                    inner_offset,
1301                    inner_depth
1302                )?;
1303                if !inlined && decoder.next_out_of_line() != next_out_of_line + (num_bytes as usize)
1304                {
1305                    return Err(fidl::Error::InvalidNumBytesInEnvelope);
1306                }
1307                if handles_before != decoder.remaining_handles() + (num_handles as usize) {
1308                    return Err(fidl::Error::InvalidNumHandlesInEnvelope);
1309                }
1310            }
1311
1312            next_offset += envelope_size;
1313
1314            // Decode the remaining unknown envelopes.
1315            while next_offset < end_offset {
1316                _next_ordinal_to_read += 1;
1317                fidl::encoding::decode_unknown_envelope(decoder, next_offset, depth)?;
1318                next_offset += envelope_size;
1319            }
1320
1321            Ok(())
1322        }
1323    }
1324}