Skip to main content

fidl_fuchsia_audio/
fidl_fuchsia_audio.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_audio_common::*;
11use futures::future::{self, MaybeDone, TryFutureExt};
12use zx_status;
13
14/// A ring buffer of audio data.
15///
16/// Each ring buffer has a producer (who writes to the buffer) and a consumer
17/// (who reads from the buffer). Additionally, each ring buffer is associated
18/// with a reference clock that keeps time for the buffer.
19///
20/// ## PCM Data
21///
22/// A ring buffer of PCM audio is a window into a potentially-infinite sequence
23/// of frames. Each frame is assigned a "frame number" where the first frame in
24/// the infinite sequence is numbered 0. Frame `X` can be found at ring buffer
25/// offset `(X % RingBufferFrames) * BytesPerFrame`, where `RingBufferFrames` is
26/// the size of the ring buffer in frames and `BytesPerFrame` is the size of a
27/// single frame.
28///
29/// ## Concurrency Protocol
30///
31/// Each ring buffer has a single producer and a single consumer which are
32/// synchronized by time. At each point in time T according to the ring buffer's
33/// reference clock, we define two functions:
34///
35///   * `SafeWritePos(T)` is the lowest (oldest) frame number the producer is
36///     allowed to write. The producer can write to this frame or to any
37///     higher-numbered frame.
38///
39///   * `SafeReadPos(T)` is the highest (youngest) frame number the consumer is
40///     allowed to read. The consumer can read this frame or any lower-numbered
41///     frame.
42///
43/// To prevent conflicts, we define these to be offset by one:
44///
45/// ```
46/// SafeWritePos(T) = SafeReadPos(T) + 1
47/// ```
48///
49/// To avoid races, there must be a single producer, but there may be multiple
50/// consumers. Additionally, since the producer and consumer(s) are synchronized
51/// by *time*, we require explicit fences to ensure cache coherency: the
52/// producer must insert an appropriate fence after each write (to flush CPU
53/// caches and prevent compiler reordering of stores) and the consumer(s) must
54/// insert an appropriate fence before each read (to invalidate CPU caches and
55/// prevent compiler reordering of loads).
56///
57/// Since the buffer has finite size, the producer/consumer cannot write/read
58/// infinitely in the future/past. We allocate `P` frames to the producer and
59/// `C` frames to the consumer(s), where `P + C <= RingBufferFrames` and `P` and
60/// `C` are both chosen by whoever creates the ring buffer.
61///
62/// ## Deciding on `P` and `C`
63///
64/// In practice, producers/consumers typically write/read batches of frames
65/// on regular periods. For example, a producer might wake every `Dp`
66/// milliseconds to write `Dp*FrameRate` frames, where `FrameRate` is the PCM
67/// stream's frame rate. If a producer wakes at time T, it will spend up to the
68/// next `Dp` period writing those frames. This means the lowest frame number it
69/// can safely write to is `SafeWritePos(T+Dp)`, which is equivalent to
70/// `SafeWritePos(T) + Dp*FrameRate`. The producer writes `Dp*FrameRate` frames
71/// from the position onwards. This entire region, from `SafeWritePos(T)`
72/// through `2*Dp*FrameRate` must be allocated to the producer at time T. Making
73/// a similar argument for consumers, we arrive at the following constraints:
74///
75/// ```
76/// P >= 2*Dp*FrameRate
77/// C >= 2*Dc*FrameRate
78/// RingBufferFrames >= P + C
79/// ```
80///
81/// Hence, in practice, `P` and `C` can be derived from the batch sizes used by
82/// the producer and consumer, where the maximum batch sizes are limited by the
83/// ring buffer size.
84///
85/// ## Defining `SafeWritePos`
86///
87/// The definition of `SafeWritePos` (and, implicitly, `SafeReadPos`) must be
88/// provided out-of-band.
89///
90/// ## Non-PCM Data
91///
92/// Non-PCM data is handled similarly to PCM data, except positions are
93/// expressed as "byte offsets" instead of "frame numbers", where the infinite
94/// sequence starts at byte offset 0.
95#[derive(Debug, Default, PartialEq)]
96pub struct RingBuffer {
97    /// The actual ring buffer. The sum of `producer_bytes` and `consumer_bytes`
98    /// must be <= `buffer.size`.
99    ///
100    /// Required.
101    pub buffer: Option<fidl_fuchsia_mem::Buffer>,
102    /// Encoding of audio data in the buffer.
103    /// Required.
104    pub format: Option<Format>,
105    /// The number of bytes allocated to the producer.
106    ///
107    /// For PCM encodings, `P = producer_bytes / BytesPerFrame(format)`, where P
108    /// must be integral.
109    ///
110    /// For non-PCM encodings, there are no constraints, however individual encodings
111    /// may impose stricter requirements.
112    ///
113    /// Required.
114    pub producer_bytes: Option<u64>,
115    /// The number of bytes allocated to the consumer.
116    ///
117    /// For PCM encodings, `C = consumer_bytes / BytesPerFrame(format)`, where C
118    /// must be integral.
119    ///
120    /// For non-PCM encodings, there are no constraints, however individual encodings
121    /// may impose stricter requirements.
122    ///
123    /// Required.
124    pub consumer_bytes: Option<u64>,
125    /// Reference clock for the ring buffer.
126    ///
127    /// Required.
128    pub reference_clock: Option<fidl::Clock>,
129    /// Domain of `reference_clock`. See `fuchsia.hardware.audio.ClockDomain`.
130    ///
131    /// Optional. If not specified, defaults to `CLOCK_DOMAIN_EXTERNAL`.
132    pub reference_clock_domain: Option<u32>,
133    #[doc(hidden)]
134    pub __source_breaking: fidl::marker::SourceBreaking,
135}
136
137impl fidl::Standalone<fidl::encoding::DefaultFuchsiaResourceDialect> for RingBuffer {}
138
139#[derive(Debug, Default, PartialEq)]
140pub struct StreamSinkPutPacketRequest {
141    /// Describes the packet. This field is required.
142    pub packet: Option<Packet>,
143    /// Eventpair closed when the consumer is done with the packet and the buffer region
144    /// associated with the packet may be reused. Packets may be released in any order. The
145    /// release fence may be duplicated by the service, so it must be sent with right
146    /// `ZX_RIGHT_DUPLICATE`. This field is optional.
147    pub release_fence: Option<fidl::EventPair>,
148    #[doc(hidden)]
149    pub __source_breaking: fidl::marker::SourceBreaking,
150}
151
152impl fidl::Standalone<fidl::encoding::DefaultFuchsiaResourceDialect>
153    for StreamSinkPutPacketRequest
154{
155}
156
157#[derive(Debug, Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Hash)]
158pub struct DelayWatcherMarker;
159
160impl fidl::endpoints::ProtocolMarker for DelayWatcherMarker {
161    type Proxy = DelayWatcherProxy;
162    type RequestStream = DelayWatcherRequestStream;
163    #[cfg(target_os = "fuchsia")]
164    type SynchronousProxy = DelayWatcherSynchronousProxy;
165
166    const DEBUG_NAME: &'static str = "(anonymous) DelayWatcher";
167}
168
169pub trait DelayWatcherProxyInterface: Send + Sync {
170    type WatchDelayResponseFut: std::future::Future<Output = Result<DelayWatcherWatchDelayResponse, fidl::Error>>
171        + Send;
172    fn r#watch_delay(&self, payload: &DelayWatcherWatchDelayRequest)
173    -> Self::WatchDelayResponseFut;
174}
175#[derive(Debug)]
176#[cfg(target_os = "fuchsia")]
177pub struct DelayWatcherSynchronousProxy {
178    client: fidl::client::sync::Client,
179}
180
181#[cfg(target_os = "fuchsia")]
182impl fidl::endpoints::SynchronousProxy for DelayWatcherSynchronousProxy {
183    type Proxy = DelayWatcherProxy;
184    type Protocol = DelayWatcherMarker;
185
186    fn from_channel(inner: fidl::Channel) -> Self {
187        Self::new(inner)
188    }
189
190    fn into_channel(self) -> fidl::Channel {
191        self.client.into_channel()
192    }
193
194    fn as_channel(&self) -> &fidl::Channel {
195        self.client.as_channel()
196    }
197}
198
199#[cfg(target_os = "fuchsia")]
200impl DelayWatcherSynchronousProxy {
201    pub fn new(channel: fidl::Channel) -> Self {
202        Self { client: fidl::client::sync::Client::new(channel) }
203    }
204
205    pub fn into_channel(self) -> fidl::Channel {
206        self.client.into_channel()
207    }
208
209    /// Waits until an event arrives and returns it. It is safe for other
210    /// threads to make concurrent requests while waiting for an event.
211    pub fn wait_for_event(
212        &self,
213        deadline: zx::MonotonicInstant,
214    ) -> Result<DelayWatcherEvent, fidl::Error> {
215        DelayWatcherEvent::decode(self.client.wait_for_event::<DelayWatcherMarker>(deadline)?)
216    }
217
218    /// The first call returns immediately with the current delay, if known.
219    /// Subsequent calls block until the delay changes. There can be at most one
220    /// outstanding call, otherwise the channel may be closed.
221    pub fn r#watch_delay(
222        &self,
223        mut payload: &DelayWatcherWatchDelayRequest,
224        ___deadline: zx::MonotonicInstant,
225    ) -> Result<DelayWatcherWatchDelayResponse, fidl::Error> {
226        let _response = self.client.send_query::<
227            DelayWatcherWatchDelayRequest,
228            DelayWatcherWatchDelayResponse,
229            DelayWatcherMarker,
230        >(
231            payload,
232            0x3a90c91ee2f1644c,
233            fidl::encoding::DynamicFlags::empty(),
234            ___deadline,
235        )?;
236        Ok(_response)
237    }
238}
239
240#[cfg(target_os = "fuchsia")]
241impl From<DelayWatcherSynchronousProxy> for zx::NullableHandle {
242    fn from(value: DelayWatcherSynchronousProxy) -> Self {
243        value.into_channel().into()
244    }
245}
246
247#[cfg(target_os = "fuchsia")]
248impl From<fidl::Channel> for DelayWatcherSynchronousProxy {
249    fn from(value: fidl::Channel) -> Self {
250        Self::new(value)
251    }
252}
253
254#[cfg(target_os = "fuchsia")]
255impl fidl::endpoints::FromClient for DelayWatcherSynchronousProxy {
256    type Protocol = DelayWatcherMarker;
257
258    fn from_client(value: fidl::endpoints::ClientEnd<DelayWatcherMarker>) -> Self {
259        Self::new(value.into_channel())
260    }
261}
262
263#[derive(Debug, Clone)]
264pub struct DelayWatcherProxy {
265    client: fidl::client::Client<fidl::encoding::DefaultFuchsiaResourceDialect>,
266}
267
268impl fidl::endpoints::Proxy for DelayWatcherProxy {
269    type Protocol = DelayWatcherMarker;
270
271    fn from_channel(inner: ::fidl::AsyncChannel) -> Self {
272        Self::new(inner)
273    }
274
275    fn into_channel(self) -> Result<::fidl::AsyncChannel, Self> {
276        self.client.into_channel().map_err(|client| Self { client })
277    }
278
279    fn as_channel(&self) -> &::fidl::AsyncChannel {
280        self.client.as_channel()
281    }
282}
283
284impl DelayWatcherProxy {
285    /// Create a new Proxy for fuchsia.audio/DelayWatcher.
286    pub fn new(channel: ::fidl::AsyncChannel) -> Self {
287        let protocol_name = <DelayWatcherMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME;
288        Self { client: fidl::client::Client::new(channel, protocol_name) }
289    }
290
291    /// Get a Stream of events from the remote end of the protocol.
292    ///
293    /// # Panics
294    ///
295    /// Panics if the event stream was already taken.
296    pub fn take_event_stream(&self) -> DelayWatcherEventStream {
297        DelayWatcherEventStream { event_receiver: self.client.take_event_receiver() }
298    }
299
300    /// The first call returns immediately with the current delay, if known.
301    /// Subsequent calls block until the delay changes. There can be at most one
302    /// outstanding call, otherwise the channel may be closed.
303    pub fn r#watch_delay(
304        &self,
305        mut payload: &DelayWatcherWatchDelayRequest,
306    ) -> fidl::client::QueryResponseFut<
307        DelayWatcherWatchDelayResponse,
308        fidl::encoding::DefaultFuchsiaResourceDialect,
309    > {
310        DelayWatcherProxyInterface::r#watch_delay(self, payload)
311    }
312}
313
314impl DelayWatcherProxyInterface for DelayWatcherProxy {
315    type WatchDelayResponseFut = fidl::client::QueryResponseFut<
316        DelayWatcherWatchDelayResponse,
317        fidl::encoding::DefaultFuchsiaResourceDialect,
318    >;
319    fn r#watch_delay(
320        &self,
321        mut payload: &DelayWatcherWatchDelayRequest,
322    ) -> Self::WatchDelayResponseFut {
323        fn _decode(
324            mut _buf: Result<<fidl::encoding::DefaultFuchsiaResourceDialect as fidl::encoding::ResourceDialect>::MessageBufEtc, fidl::Error>,
325        ) -> Result<DelayWatcherWatchDelayResponse, fidl::Error> {
326            let _response = fidl::client::decode_transaction_body::<
327                DelayWatcherWatchDelayResponse,
328                fidl::encoding::DefaultFuchsiaResourceDialect,
329                0x3a90c91ee2f1644c,
330            >(_buf?)?;
331            Ok(_response)
332        }
333        self.client
334            .send_query_and_decode::<DelayWatcherWatchDelayRequest, DelayWatcherWatchDelayResponse>(
335                payload,
336                0x3a90c91ee2f1644c,
337                fidl::encoding::DynamicFlags::empty(),
338                _decode,
339            )
340    }
341}
342
343pub struct DelayWatcherEventStream {
344    event_receiver: fidl::client::EventReceiver<fidl::encoding::DefaultFuchsiaResourceDialect>,
345}
346
347impl std::marker::Unpin for DelayWatcherEventStream {}
348
349impl futures::stream::FusedStream for DelayWatcherEventStream {
350    fn is_terminated(&self) -> bool {
351        self.event_receiver.is_terminated()
352    }
353}
354
355impl futures::Stream for DelayWatcherEventStream {
356    type Item = Result<DelayWatcherEvent, fidl::Error>;
357
358    fn poll_next(
359        mut self: std::pin::Pin<&mut Self>,
360        cx: &mut std::task::Context<'_>,
361    ) -> std::task::Poll<Option<Self::Item>> {
362        match futures::ready!(futures::stream::StreamExt::poll_next_unpin(
363            &mut self.event_receiver,
364            cx
365        )?) {
366            Some(buf) => std::task::Poll::Ready(Some(DelayWatcherEvent::decode(buf))),
367            None => std::task::Poll::Ready(None),
368        }
369    }
370}
371
372#[derive(Debug)]
373pub enum DelayWatcherEvent {}
374
375impl DelayWatcherEvent {
376    /// Decodes a message buffer as a [`DelayWatcherEvent`].
377    fn decode(
378        mut buf: <fidl::encoding::DefaultFuchsiaResourceDialect as fidl::encoding::ResourceDialect>::MessageBufEtc,
379    ) -> Result<DelayWatcherEvent, fidl::Error> {
380        let (bytes, _handles) = buf.split_mut();
381        let (tx_header, _body_bytes) = fidl::encoding::decode_transaction_header(bytes)?;
382        debug_assert_eq!(tx_header.tx_id, 0);
383        match tx_header.ordinal {
384            _ => Err(fidl::Error::UnknownOrdinal {
385                ordinal: tx_header.ordinal,
386                protocol_name: <DelayWatcherMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME,
387            }),
388        }
389    }
390}
391
392/// A Stream of incoming requests for fuchsia.audio/DelayWatcher.
393pub struct DelayWatcherRequestStream {
394    inner: std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>,
395    is_terminated: bool,
396}
397
398impl std::marker::Unpin for DelayWatcherRequestStream {}
399
400impl futures::stream::FusedStream for DelayWatcherRequestStream {
401    fn is_terminated(&self) -> bool {
402        self.is_terminated
403    }
404}
405
406impl fidl::endpoints::RequestStream for DelayWatcherRequestStream {
407    type Protocol = DelayWatcherMarker;
408    type ControlHandle = DelayWatcherControlHandle;
409
410    fn from_channel(channel: ::fidl::AsyncChannel) -> Self {
411        Self { inner: std::sync::Arc::new(fidl::ServeInner::new(channel)), is_terminated: false }
412    }
413
414    fn control_handle(&self) -> Self::ControlHandle {
415        DelayWatcherControlHandle { inner: self.inner.clone() }
416    }
417
418    fn into_inner(
419        self,
420    ) -> (::std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>, bool)
421    {
422        (self.inner, self.is_terminated)
423    }
424
425    fn from_inner(
426        inner: std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>,
427        is_terminated: bool,
428    ) -> Self {
429        Self { inner, is_terminated }
430    }
431}
432
433impl futures::Stream for DelayWatcherRequestStream {
434    type Item = Result<DelayWatcherRequest, fidl::Error>;
435
436    fn poll_next(
437        mut self: std::pin::Pin<&mut Self>,
438        cx: &mut std::task::Context<'_>,
439    ) -> std::task::Poll<Option<Self::Item>> {
440        let this = &mut *self;
441        if this.inner.check_shutdown(cx) {
442            this.is_terminated = true;
443            return std::task::Poll::Ready(None);
444        }
445        if this.is_terminated {
446            panic!("polled DelayWatcherRequestStream after completion");
447        }
448        fidl::encoding::with_tls_decode_buf::<_, fidl::encoding::DefaultFuchsiaResourceDialect>(
449            |bytes, handles| {
450                match this.inner.channel().read_etc(cx, bytes, handles) {
451                    std::task::Poll::Ready(Ok(())) => {}
452                    std::task::Poll::Pending => return std::task::Poll::Pending,
453                    std::task::Poll::Ready(Err(zx_status::Status::PEER_CLOSED)) => {
454                        this.is_terminated = true;
455                        return std::task::Poll::Ready(None);
456                    }
457                    std::task::Poll::Ready(Err(e)) => {
458                        return std::task::Poll::Ready(Some(Err(fidl::Error::ServerRequestRead(
459                            e.into(),
460                        ))));
461                    }
462                }
463
464                // A message has been received from the channel
465                let (header, _body_bytes) = fidl::encoding::decode_transaction_header(bytes)?;
466
467                std::task::Poll::Ready(Some(match header.ordinal {
468                    0x3a90c91ee2f1644c => {
469                        header.validate_request_tx_id(fidl::MethodType::TwoWay)?;
470                        let mut req = fidl::new_empty!(
471                            DelayWatcherWatchDelayRequest,
472                            fidl::encoding::DefaultFuchsiaResourceDialect
473                        );
474                        fidl::encoding::Decoder::<fidl::encoding::DefaultFuchsiaResourceDialect>::decode_into::<DelayWatcherWatchDelayRequest>(&header, _body_bytes, handles, &mut req)?;
475                        let control_handle =
476                            DelayWatcherControlHandle { inner: this.inner.clone() };
477                        Ok(DelayWatcherRequest::WatchDelay {
478                            payload: req,
479                            responder: DelayWatcherWatchDelayResponder {
480                                control_handle: std::mem::ManuallyDrop::new(control_handle),
481                                tx_id: header.tx_id,
482                            },
483                        })
484                    }
485                    _ => Err(fidl::Error::UnknownOrdinal {
486                        ordinal: header.ordinal,
487                        protocol_name:
488                            <DelayWatcherMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME,
489                    }),
490                }))
491            },
492        )
493    }
494}
495
496/// Watches for a delay to change.
497#[derive(Debug)]
498pub enum DelayWatcherRequest {
499    /// The first call returns immediately with the current delay, if known.
500    /// Subsequent calls block until the delay changes. There can be at most one
501    /// outstanding call, otherwise the channel may be closed.
502    WatchDelay {
503        payload: DelayWatcherWatchDelayRequest,
504        responder: DelayWatcherWatchDelayResponder,
505    },
506}
507
508impl DelayWatcherRequest {
509    #[allow(irrefutable_let_patterns)]
510    pub fn into_watch_delay(
511        self,
512    ) -> Option<(DelayWatcherWatchDelayRequest, DelayWatcherWatchDelayResponder)> {
513        if let DelayWatcherRequest::WatchDelay { payload, responder } = self {
514            Some((payload, responder))
515        } else {
516            None
517        }
518    }
519
520    /// Name of the method defined in FIDL
521    pub fn method_name(&self) -> &'static str {
522        match *self {
523            DelayWatcherRequest::WatchDelay { .. } => "watch_delay",
524        }
525    }
526}
527
528#[derive(Debug, Clone)]
529pub struct DelayWatcherControlHandle {
530    inner: std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>,
531}
532
533impl DelayWatcherControlHandle {
534    pub fn shutdown_with_epitaph(&self, status: impl Into<fidl::Epitaph>) {
535        self.inner.shutdown_with_epitaph(status.into())
536    }
537}
538
539impl fidl::endpoints::ControlHandle for DelayWatcherControlHandle {
540    fn shutdown(&self) {
541        self.inner.shutdown()
542    }
543
544    fn shutdown_with_epitaph(&self, status: fidl::Epitaph) {
545        self.inner.shutdown_with_epitaph(status)
546    }
547
548    fn is_closed(&self) -> bool {
549        self.inner.channel().is_closed()
550    }
551    fn on_closed(&self) -> fidl::OnSignalsRef<'_> {
552        self.inner.channel().on_closed()
553    }
554
555    #[cfg(target_os = "fuchsia")]
556    fn signal_peer(
557        &self,
558        clear_mask: zx::Signals,
559        set_mask: zx::Signals,
560    ) -> Result<(), zx_status::Status> {
561        use fidl::Peered;
562        self.inner.channel().signal_peer(clear_mask, set_mask)
563    }
564}
565
566impl DelayWatcherControlHandle {}
567
568#[must_use = "FIDL methods require a response to be sent"]
569#[derive(Debug)]
570pub struct DelayWatcherWatchDelayResponder {
571    control_handle: std::mem::ManuallyDrop<DelayWatcherControlHandle>,
572    tx_id: u32,
573}
574
575/// Set the the channel to be shutdown (see [`DelayWatcherControlHandle::shutdown`])
576/// if the responder is dropped without sending a response, so that the client
577/// doesn't hang. To prevent this behavior, call `drop_without_shutdown`.
578impl std::ops::Drop for DelayWatcherWatchDelayResponder {
579    fn drop(&mut self) {
580        self.control_handle.shutdown();
581        // Safety: drops once, never accessed again
582        unsafe { std::mem::ManuallyDrop::drop(&mut self.control_handle) };
583    }
584}
585
586impl fidl::endpoints::Responder for DelayWatcherWatchDelayResponder {
587    type ControlHandle = DelayWatcherControlHandle;
588
589    fn control_handle(&self) -> &DelayWatcherControlHandle {
590        &self.control_handle
591    }
592
593    fn drop_without_shutdown(mut self) {
594        // Safety: drops once, never accessed again due to mem::forget
595        unsafe { std::mem::ManuallyDrop::drop(&mut self.control_handle) };
596        // Prevent Drop from running (which would shut down the channel)
597        std::mem::forget(self);
598    }
599}
600
601impl DelayWatcherWatchDelayResponder {
602    /// Sends a response to the FIDL transaction.
603    ///
604    /// Sets the channel to shutdown if an error occurs.
605    pub fn send(self, mut payload: &DelayWatcherWatchDelayResponse) -> Result<(), fidl::Error> {
606        let _result = self.send_raw(payload);
607        if _result.is_err() {
608            self.control_handle.shutdown();
609        }
610        self.drop_without_shutdown();
611        _result
612    }
613
614    /// Similar to "send" but does not shutdown the channel if an error occurs.
615    pub fn send_no_shutdown_on_err(
616        self,
617        mut payload: &DelayWatcherWatchDelayResponse,
618    ) -> Result<(), fidl::Error> {
619        let _result = self.send_raw(payload);
620        self.drop_without_shutdown();
621        _result
622    }
623
624    fn send_raw(&self, mut payload: &DelayWatcherWatchDelayResponse) -> Result<(), fidl::Error> {
625        self.control_handle.inner.send::<DelayWatcherWatchDelayResponse>(
626            payload,
627            self.tx_id,
628            0x3a90c91ee2f1644c,
629            fidl::encoding::DynamicFlags::empty(),
630        )
631    }
632}
633
634#[derive(Debug, Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Hash)]
635pub struct GainControlMarker;
636
637impl fidl::endpoints::ProtocolMarker for GainControlMarker {
638    type Proxy = GainControlProxy;
639    type RequestStream = GainControlRequestStream;
640    #[cfg(target_os = "fuchsia")]
641    type SynchronousProxy = GainControlSynchronousProxy;
642
643    const DEBUG_NAME: &'static str = "(anonymous) GainControl";
644}
645pub type GainControlSetGainResult = Result<GainControlSetGainResponse, GainError>;
646pub type GainControlSetMuteResult = Result<GainControlSetMuteResponse, GainError>;
647
648pub trait GainControlProxyInterface: Send + Sync {
649    type SetGainResponseFut: std::future::Future<Output = Result<GainControlSetGainResult, fidl::Error>>
650        + Send;
651    fn r#set_gain(&self, payload: &GainControlSetGainRequest) -> Self::SetGainResponseFut;
652    type SetMuteResponseFut: std::future::Future<Output = Result<GainControlSetMuteResult, fidl::Error>>
653        + Send;
654    fn r#set_mute(&self, payload: &GainControlSetMuteRequest) -> Self::SetMuteResponseFut;
655}
656#[derive(Debug)]
657#[cfg(target_os = "fuchsia")]
658pub struct GainControlSynchronousProxy {
659    client: fidl::client::sync::Client,
660}
661
662#[cfg(target_os = "fuchsia")]
663impl fidl::endpoints::SynchronousProxy for GainControlSynchronousProxy {
664    type Proxy = GainControlProxy;
665    type Protocol = GainControlMarker;
666
667    fn from_channel(inner: fidl::Channel) -> Self {
668        Self::new(inner)
669    }
670
671    fn into_channel(self) -> fidl::Channel {
672        self.client.into_channel()
673    }
674
675    fn as_channel(&self) -> &fidl::Channel {
676        self.client.as_channel()
677    }
678}
679
680#[cfg(target_os = "fuchsia")]
681impl GainControlSynchronousProxy {
682    pub fn new(channel: fidl::Channel) -> Self {
683        Self { client: fidl::client::sync::Client::new(channel) }
684    }
685
686    pub fn into_channel(self) -> fidl::Channel {
687        self.client.into_channel()
688    }
689
690    /// Waits until an event arrives and returns it. It is safe for other
691    /// threads to make concurrent requests while waiting for an event.
692    pub fn wait_for_event(
693        &self,
694        deadline: zx::MonotonicInstant,
695    ) -> Result<GainControlEvent, fidl::Error> {
696        GainControlEvent::decode(self.client.wait_for_event::<GainControlMarker>(deadline)?)
697    }
698
699    /// Sets the gain knob.
700    pub fn r#set_gain(
701        &self,
702        mut payload: &GainControlSetGainRequest,
703        ___deadline: zx::MonotonicInstant,
704    ) -> Result<GainControlSetGainResult, fidl::Error> {
705        let _response = self.client.send_query::<
706            GainControlSetGainRequest,
707            fidl::encoding::ResultType<GainControlSetGainResponse, GainError>,
708            GainControlMarker,
709        >(
710            payload,
711            0x6ece305e4a5823dc,
712            fidl::encoding::DynamicFlags::empty(),
713            ___deadline,
714        )?;
715        Ok(_response.map(|x| x))
716    }
717
718    /// Set the mute knob.
719    pub fn r#set_mute(
720        &self,
721        mut payload: &GainControlSetMuteRequest,
722        ___deadline: zx::MonotonicInstant,
723    ) -> Result<GainControlSetMuteResult, fidl::Error> {
724        let _response = self.client.send_query::<
725            GainControlSetMuteRequest,
726            fidl::encoding::ResultType<GainControlSetMuteResponse, GainError>,
727            GainControlMarker,
728        >(
729            payload,
730            0xed03d88ce4f8965,
731            fidl::encoding::DynamicFlags::empty(),
732            ___deadline,
733        )?;
734        Ok(_response.map(|x| x))
735    }
736}
737
738#[cfg(target_os = "fuchsia")]
739impl From<GainControlSynchronousProxy> for zx::NullableHandle {
740    fn from(value: GainControlSynchronousProxy) -> Self {
741        value.into_channel().into()
742    }
743}
744
745#[cfg(target_os = "fuchsia")]
746impl From<fidl::Channel> for GainControlSynchronousProxy {
747    fn from(value: fidl::Channel) -> Self {
748        Self::new(value)
749    }
750}
751
752#[cfg(target_os = "fuchsia")]
753impl fidl::endpoints::FromClient for GainControlSynchronousProxy {
754    type Protocol = GainControlMarker;
755
756    fn from_client(value: fidl::endpoints::ClientEnd<GainControlMarker>) -> Self {
757        Self::new(value.into_channel())
758    }
759}
760
761#[derive(Debug, Clone)]
762pub struct GainControlProxy {
763    client: fidl::client::Client<fidl::encoding::DefaultFuchsiaResourceDialect>,
764}
765
766impl fidl::endpoints::Proxy for GainControlProxy {
767    type Protocol = GainControlMarker;
768
769    fn from_channel(inner: ::fidl::AsyncChannel) -> Self {
770        Self::new(inner)
771    }
772
773    fn into_channel(self) -> Result<::fidl::AsyncChannel, Self> {
774        self.client.into_channel().map_err(|client| Self { client })
775    }
776
777    fn as_channel(&self) -> &::fidl::AsyncChannel {
778        self.client.as_channel()
779    }
780}
781
782impl GainControlProxy {
783    /// Create a new Proxy for fuchsia.audio/GainControl.
784    pub fn new(channel: ::fidl::AsyncChannel) -> Self {
785        let protocol_name = <GainControlMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME;
786        Self { client: fidl::client::Client::new(channel, protocol_name) }
787    }
788
789    /// Get a Stream of events from the remote end of the protocol.
790    ///
791    /// # Panics
792    ///
793    /// Panics if the event stream was already taken.
794    pub fn take_event_stream(&self) -> GainControlEventStream {
795        GainControlEventStream { event_receiver: self.client.take_event_receiver() }
796    }
797
798    /// Sets the gain knob.
799    pub fn r#set_gain(
800        &self,
801        mut payload: &GainControlSetGainRequest,
802    ) -> fidl::client::QueryResponseFut<
803        GainControlSetGainResult,
804        fidl::encoding::DefaultFuchsiaResourceDialect,
805    > {
806        GainControlProxyInterface::r#set_gain(self, payload)
807    }
808
809    /// Set the mute knob.
810    pub fn r#set_mute(
811        &self,
812        mut payload: &GainControlSetMuteRequest,
813    ) -> fidl::client::QueryResponseFut<
814        GainControlSetMuteResult,
815        fidl::encoding::DefaultFuchsiaResourceDialect,
816    > {
817        GainControlProxyInterface::r#set_mute(self, payload)
818    }
819}
820
821impl GainControlProxyInterface for GainControlProxy {
822    type SetGainResponseFut = fidl::client::QueryResponseFut<
823        GainControlSetGainResult,
824        fidl::encoding::DefaultFuchsiaResourceDialect,
825    >;
826    fn r#set_gain(&self, mut payload: &GainControlSetGainRequest) -> Self::SetGainResponseFut {
827        fn _decode(
828            mut _buf: Result<<fidl::encoding::DefaultFuchsiaResourceDialect as fidl::encoding::ResourceDialect>::MessageBufEtc, fidl::Error>,
829        ) -> Result<GainControlSetGainResult, fidl::Error> {
830            let _response = fidl::client::decode_transaction_body::<
831                fidl::encoding::ResultType<GainControlSetGainResponse, GainError>,
832                fidl::encoding::DefaultFuchsiaResourceDialect,
833                0x6ece305e4a5823dc,
834            >(_buf?)?;
835            Ok(_response.map(|x| x))
836        }
837        self.client.send_query_and_decode::<GainControlSetGainRequest, GainControlSetGainResult>(
838            payload,
839            0x6ece305e4a5823dc,
840            fidl::encoding::DynamicFlags::empty(),
841            _decode,
842        )
843    }
844
845    type SetMuteResponseFut = fidl::client::QueryResponseFut<
846        GainControlSetMuteResult,
847        fidl::encoding::DefaultFuchsiaResourceDialect,
848    >;
849    fn r#set_mute(&self, mut payload: &GainControlSetMuteRequest) -> Self::SetMuteResponseFut {
850        fn _decode(
851            mut _buf: Result<<fidl::encoding::DefaultFuchsiaResourceDialect as fidl::encoding::ResourceDialect>::MessageBufEtc, fidl::Error>,
852        ) -> Result<GainControlSetMuteResult, fidl::Error> {
853            let _response = fidl::client::decode_transaction_body::<
854                fidl::encoding::ResultType<GainControlSetMuteResponse, GainError>,
855                fidl::encoding::DefaultFuchsiaResourceDialect,
856                0xed03d88ce4f8965,
857            >(_buf?)?;
858            Ok(_response.map(|x| x))
859        }
860        self.client.send_query_and_decode::<GainControlSetMuteRequest, GainControlSetMuteResult>(
861            payload,
862            0xed03d88ce4f8965,
863            fidl::encoding::DynamicFlags::empty(),
864            _decode,
865        )
866    }
867}
868
869pub struct GainControlEventStream {
870    event_receiver: fidl::client::EventReceiver<fidl::encoding::DefaultFuchsiaResourceDialect>,
871}
872
873impl std::marker::Unpin for GainControlEventStream {}
874
875impl futures::stream::FusedStream for GainControlEventStream {
876    fn is_terminated(&self) -> bool {
877        self.event_receiver.is_terminated()
878    }
879}
880
881impl futures::Stream for GainControlEventStream {
882    type Item = Result<GainControlEvent, fidl::Error>;
883
884    fn poll_next(
885        mut self: std::pin::Pin<&mut Self>,
886        cx: &mut std::task::Context<'_>,
887    ) -> std::task::Poll<Option<Self::Item>> {
888        match futures::ready!(futures::stream::StreamExt::poll_next_unpin(
889            &mut self.event_receiver,
890            cx
891        )?) {
892            Some(buf) => std::task::Poll::Ready(Some(GainControlEvent::decode(buf))),
893            None => std::task::Poll::Ready(None),
894        }
895    }
896}
897
898#[derive(Debug)]
899pub enum GainControlEvent {}
900
901impl GainControlEvent {
902    /// Decodes a message buffer as a [`GainControlEvent`].
903    fn decode(
904        mut buf: <fidl::encoding::DefaultFuchsiaResourceDialect as fidl::encoding::ResourceDialect>::MessageBufEtc,
905    ) -> Result<GainControlEvent, fidl::Error> {
906        let (bytes, _handles) = buf.split_mut();
907        let (tx_header, _body_bytes) = fidl::encoding::decode_transaction_header(bytes)?;
908        debug_assert_eq!(tx_header.tx_id, 0);
909        match tx_header.ordinal {
910            _ => Err(fidl::Error::UnknownOrdinal {
911                ordinal: tx_header.ordinal,
912                protocol_name: <GainControlMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME,
913            }),
914        }
915    }
916}
917
918/// A Stream of incoming requests for fuchsia.audio/GainControl.
919pub struct GainControlRequestStream {
920    inner: std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>,
921    is_terminated: bool,
922}
923
924impl std::marker::Unpin for GainControlRequestStream {}
925
926impl futures::stream::FusedStream for GainControlRequestStream {
927    fn is_terminated(&self) -> bool {
928        self.is_terminated
929    }
930}
931
932impl fidl::endpoints::RequestStream for GainControlRequestStream {
933    type Protocol = GainControlMarker;
934    type ControlHandle = GainControlControlHandle;
935
936    fn from_channel(channel: ::fidl::AsyncChannel) -> Self {
937        Self { inner: std::sync::Arc::new(fidl::ServeInner::new(channel)), is_terminated: false }
938    }
939
940    fn control_handle(&self) -> Self::ControlHandle {
941        GainControlControlHandle { inner: self.inner.clone() }
942    }
943
944    fn into_inner(
945        self,
946    ) -> (::std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>, bool)
947    {
948        (self.inner, self.is_terminated)
949    }
950
951    fn from_inner(
952        inner: std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>,
953        is_terminated: bool,
954    ) -> Self {
955        Self { inner, is_terminated }
956    }
957}
958
959impl futures::Stream for GainControlRequestStream {
960    type Item = Result<GainControlRequest, fidl::Error>;
961
962    fn poll_next(
963        mut self: std::pin::Pin<&mut Self>,
964        cx: &mut std::task::Context<'_>,
965    ) -> std::task::Poll<Option<Self::Item>> {
966        let this = &mut *self;
967        if this.inner.check_shutdown(cx) {
968            this.is_terminated = true;
969            return std::task::Poll::Ready(None);
970        }
971        if this.is_terminated {
972            panic!("polled GainControlRequestStream after completion");
973        }
974        fidl::encoding::with_tls_decode_buf::<_, fidl::encoding::DefaultFuchsiaResourceDialect>(
975            |bytes, handles| {
976                match this.inner.channel().read_etc(cx, bytes, handles) {
977                    std::task::Poll::Ready(Ok(())) => {}
978                    std::task::Poll::Pending => return std::task::Poll::Pending,
979                    std::task::Poll::Ready(Err(zx_status::Status::PEER_CLOSED)) => {
980                        this.is_terminated = true;
981                        return std::task::Poll::Ready(None);
982                    }
983                    std::task::Poll::Ready(Err(e)) => {
984                        return std::task::Poll::Ready(Some(Err(fidl::Error::ServerRequestRead(
985                            e.into(),
986                        ))));
987                    }
988                }
989
990                // A message has been received from the channel
991                let (header, _body_bytes) = fidl::encoding::decode_transaction_header(bytes)?;
992
993                std::task::Poll::Ready(Some(match header.ordinal {
994                    0x6ece305e4a5823dc => {
995                        header.validate_request_tx_id(fidl::MethodType::TwoWay)?;
996                        let mut req = fidl::new_empty!(
997                            GainControlSetGainRequest,
998                            fidl::encoding::DefaultFuchsiaResourceDialect
999                        );
1000                        fidl::encoding::Decoder::<fidl::encoding::DefaultFuchsiaResourceDialect>::decode_into::<GainControlSetGainRequest>(&header, _body_bytes, handles, &mut req)?;
1001                        let control_handle = GainControlControlHandle { inner: this.inner.clone() };
1002                        Ok(GainControlRequest::SetGain {
1003                            payload: req,
1004                            responder: GainControlSetGainResponder {
1005                                control_handle: std::mem::ManuallyDrop::new(control_handle),
1006                                tx_id: header.tx_id,
1007                            },
1008                        })
1009                    }
1010                    0xed03d88ce4f8965 => {
1011                        header.validate_request_tx_id(fidl::MethodType::TwoWay)?;
1012                        let mut req = fidl::new_empty!(
1013                            GainControlSetMuteRequest,
1014                            fidl::encoding::DefaultFuchsiaResourceDialect
1015                        );
1016                        fidl::encoding::Decoder::<fidl::encoding::DefaultFuchsiaResourceDialect>::decode_into::<GainControlSetMuteRequest>(&header, _body_bytes, handles, &mut req)?;
1017                        let control_handle = GainControlControlHandle { inner: this.inner.clone() };
1018                        Ok(GainControlRequest::SetMute {
1019                            payload: req,
1020                            responder: GainControlSetMuteResponder {
1021                                control_handle: std::mem::ManuallyDrop::new(control_handle),
1022                                tx_id: header.tx_id,
1023                            },
1024                        })
1025                    }
1026                    _ => Err(fidl::Error::UnknownOrdinal {
1027                        ordinal: header.ordinal,
1028                        protocol_name:
1029                            <GainControlMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME,
1030                    }),
1031                }))
1032            },
1033        )
1034    }
1035}
1036
1037/// Enables control and monitoring of audio gain. This interface is typically a
1038/// tear-off of other interfaces.
1039///
1040/// ## Knobs
1041///
1042/// This interface exposes two orthogonal knobs:
1043///
1044/// * The *gain* knob controls a single value in "relative decibels". A value of
1045///   0 applies no gain, positive values increase gain, and negative values
1046///   decrease gain. Depending on context, gain may be applied relative to an
1047///   input stream or relative to some absolute reference point, such as the
1048///   maximum loudness of a speaker.
1049///
1050///   This knob has no defined maximum or minimum value. Individual
1051///   implementations may clamp to an implementation-defined maximum value or
1052///   treat all values below an implementation-defined minimum value equivalent
1053///   to "muted", but this behavior is not required.
1054///
1055/// * The *mute* knob controls a single boolean value. When `true`, the
1056///   GainControl is muted and the effective gain is negative infinity. When
1057///   `false`, gain is controlled by the *gain* knob.
1058///
1059/// ## Scheduling
1060///
1061/// Changes to the *gain* and *mute* knobs can be scheduled for a time in the
1062/// future. Scheduling happens on timestamps relative to a reference clock which
1063/// must be established when this protocol is created.
1064#[derive(Debug)]
1065pub enum GainControlRequest {
1066    /// Sets the gain knob.
1067    SetGain { payload: GainControlSetGainRequest, responder: GainControlSetGainResponder },
1068    /// Set the mute knob.
1069    SetMute { payload: GainControlSetMuteRequest, responder: GainControlSetMuteResponder },
1070}
1071
1072impl GainControlRequest {
1073    #[allow(irrefutable_let_patterns)]
1074    pub fn into_set_gain(self) -> Option<(GainControlSetGainRequest, GainControlSetGainResponder)> {
1075        if let GainControlRequest::SetGain { payload, responder } = self {
1076            Some((payload, responder))
1077        } else {
1078            None
1079        }
1080    }
1081
1082    #[allow(irrefutable_let_patterns)]
1083    pub fn into_set_mute(self) -> Option<(GainControlSetMuteRequest, GainControlSetMuteResponder)> {
1084        if let GainControlRequest::SetMute { payload, responder } = self {
1085            Some((payload, responder))
1086        } else {
1087            None
1088        }
1089    }
1090
1091    /// Name of the method defined in FIDL
1092    pub fn method_name(&self) -> &'static str {
1093        match *self {
1094            GainControlRequest::SetGain { .. } => "set_gain",
1095            GainControlRequest::SetMute { .. } => "set_mute",
1096        }
1097    }
1098}
1099
1100#[derive(Debug, Clone)]
1101pub struct GainControlControlHandle {
1102    inner: std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>,
1103}
1104
1105impl GainControlControlHandle {
1106    pub fn shutdown_with_epitaph(&self, status: impl Into<fidl::Epitaph>) {
1107        self.inner.shutdown_with_epitaph(status.into())
1108    }
1109}
1110
1111impl fidl::endpoints::ControlHandle for GainControlControlHandle {
1112    fn shutdown(&self) {
1113        self.inner.shutdown()
1114    }
1115
1116    fn shutdown_with_epitaph(&self, status: fidl::Epitaph) {
1117        self.inner.shutdown_with_epitaph(status)
1118    }
1119
1120    fn is_closed(&self) -> bool {
1121        self.inner.channel().is_closed()
1122    }
1123    fn on_closed(&self) -> fidl::OnSignalsRef<'_> {
1124        self.inner.channel().on_closed()
1125    }
1126
1127    #[cfg(target_os = "fuchsia")]
1128    fn signal_peer(
1129        &self,
1130        clear_mask: zx::Signals,
1131        set_mask: zx::Signals,
1132    ) -> Result<(), zx_status::Status> {
1133        use fidl::Peered;
1134        self.inner.channel().signal_peer(clear_mask, set_mask)
1135    }
1136}
1137
1138impl GainControlControlHandle {}
1139
1140#[must_use = "FIDL methods require a response to be sent"]
1141#[derive(Debug)]
1142pub struct GainControlSetGainResponder {
1143    control_handle: std::mem::ManuallyDrop<GainControlControlHandle>,
1144    tx_id: u32,
1145}
1146
1147/// Set the the channel to be shutdown (see [`GainControlControlHandle::shutdown`])
1148/// if the responder is dropped without sending a response, so that the client
1149/// doesn't hang. To prevent this behavior, call `drop_without_shutdown`.
1150impl std::ops::Drop for GainControlSetGainResponder {
1151    fn drop(&mut self) {
1152        self.control_handle.shutdown();
1153        // Safety: drops once, never accessed again
1154        unsafe { std::mem::ManuallyDrop::drop(&mut self.control_handle) };
1155    }
1156}
1157
1158impl fidl::endpoints::Responder for GainControlSetGainResponder {
1159    type ControlHandle = GainControlControlHandle;
1160
1161    fn control_handle(&self) -> &GainControlControlHandle {
1162        &self.control_handle
1163    }
1164
1165    fn drop_without_shutdown(mut self) {
1166        // Safety: drops once, never accessed again due to mem::forget
1167        unsafe { std::mem::ManuallyDrop::drop(&mut self.control_handle) };
1168        // Prevent Drop from running (which would shut down the channel)
1169        std::mem::forget(self);
1170    }
1171}
1172
1173impl GainControlSetGainResponder {
1174    /// Sends a response to the FIDL transaction.
1175    ///
1176    /// Sets the channel to shutdown if an error occurs.
1177    pub fn send(
1178        self,
1179        mut result: Result<&GainControlSetGainResponse, GainError>,
1180    ) -> Result<(), fidl::Error> {
1181        let _result = self.send_raw(result);
1182        if _result.is_err() {
1183            self.control_handle.shutdown();
1184        }
1185        self.drop_without_shutdown();
1186        _result
1187    }
1188
1189    /// Similar to "send" but does not shutdown the channel if an error occurs.
1190    pub fn send_no_shutdown_on_err(
1191        self,
1192        mut result: Result<&GainControlSetGainResponse, GainError>,
1193    ) -> Result<(), fidl::Error> {
1194        let _result = self.send_raw(result);
1195        self.drop_without_shutdown();
1196        _result
1197    }
1198
1199    fn send_raw(
1200        &self,
1201        mut result: Result<&GainControlSetGainResponse, GainError>,
1202    ) -> Result<(), fidl::Error> {
1203        self.control_handle
1204            .inner
1205            .send::<fidl::encoding::ResultType<GainControlSetGainResponse, GainError>>(
1206                result,
1207                self.tx_id,
1208                0x6ece305e4a5823dc,
1209                fidl::encoding::DynamicFlags::empty(),
1210            )
1211    }
1212}
1213
1214#[must_use = "FIDL methods require a response to be sent"]
1215#[derive(Debug)]
1216pub struct GainControlSetMuteResponder {
1217    control_handle: std::mem::ManuallyDrop<GainControlControlHandle>,
1218    tx_id: u32,
1219}
1220
1221/// Set the the channel to be shutdown (see [`GainControlControlHandle::shutdown`])
1222/// if the responder is dropped without sending a response, so that the client
1223/// doesn't hang. To prevent this behavior, call `drop_without_shutdown`.
1224impl std::ops::Drop for GainControlSetMuteResponder {
1225    fn drop(&mut self) {
1226        self.control_handle.shutdown();
1227        // Safety: drops once, never accessed again
1228        unsafe { std::mem::ManuallyDrop::drop(&mut self.control_handle) };
1229    }
1230}
1231
1232impl fidl::endpoints::Responder for GainControlSetMuteResponder {
1233    type ControlHandle = GainControlControlHandle;
1234
1235    fn control_handle(&self) -> &GainControlControlHandle {
1236        &self.control_handle
1237    }
1238
1239    fn drop_without_shutdown(mut self) {
1240        // Safety: drops once, never accessed again due to mem::forget
1241        unsafe { std::mem::ManuallyDrop::drop(&mut self.control_handle) };
1242        // Prevent Drop from running (which would shut down the channel)
1243        std::mem::forget(self);
1244    }
1245}
1246
1247impl GainControlSetMuteResponder {
1248    /// Sends a response to the FIDL transaction.
1249    ///
1250    /// Sets the channel to shutdown if an error occurs.
1251    pub fn send(
1252        self,
1253        mut result: Result<&GainControlSetMuteResponse, GainError>,
1254    ) -> Result<(), fidl::Error> {
1255        let _result = self.send_raw(result);
1256        if _result.is_err() {
1257            self.control_handle.shutdown();
1258        }
1259        self.drop_without_shutdown();
1260        _result
1261    }
1262
1263    /// Similar to "send" but does not shutdown the channel if an error occurs.
1264    pub fn send_no_shutdown_on_err(
1265        self,
1266        mut result: Result<&GainControlSetMuteResponse, GainError>,
1267    ) -> Result<(), fidl::Error> {
1268        let _result = self.send_raw(result);
1269        self.drop_without_shutdown();
1270        _result
1271    }
1272
1273    fn send_raw(
1274        &self,
1275        mut result: Result<&GainControlSetMuteResponse, GainError>,
1276    ) -> Result<(), fidl::Error> {
1277        self.control_handle
1278            .inner
1279            .send::<fidl::encoding::ResultType<GainControlSetMuteResponse, GainError>>(
1280                result,
1281                self.tx_id,
1282                0xed03d88ce4f8965,
1283                fidl::encoding::DynamicFlags::empty(),
1284            )
1285    }
1286}
1287
1288#[derive(Debug, Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Hash)]
1289pub struct StreamSinkMarker;
1290
1291impl fidl::endpoints::ProtocolMarker for StreamSinkMarker {
1292    type Proxy = StreamSinkProxy;
1293    type RequestStream = StreamSinkRequestStream;
1294    #[cfg(target_os = "fuchsia")]
1295    type SynchronousProxy = StreamSinkSynchronousProxy;
1296
1297    const DEBUG_NAME: &'static str = "(anonymous) StreamSink";
1298}
1299
1300pub trait StreamSinkProxyInterface: Send + Sync {
1301    fn r#put_packet(&self, payload: StreamSinkPutPacketRequest) -> Result<(), fidl::Error>;
1302    fn r#start_segment(&self, payload: &StreamSinkStartSegmentRequest) -> Result<(), fidl::Error>;
1303    fn r#end(&self) -> Result<(), fidl::Error>;
1304    fn r#will_close(&self, payload: &StreamSinkWillCloseRequest) -> Result<(), fidl::Error>;
1305}
1306#[derive(Debug)]
1307#[cfg(target_os = "fuchsia")]
1308pub struct StreamSinkSynchronousProxy {
1309    client: fidl::client::sync::Client,
1310}
1311
1312#[cfg(target_os = "fuchsia")]
1313impl fidl::endpoints::SynchronousProxy for StreamSinkSynchronousProxy {
1314    type Proxy = StreamSinkProxy;
1315    type Protocol = StreamSinkMarker;
1316
1317    fn from_channel(inner: fidl::Channel) -> Self {
1318        Self::new(inner)
1319    }
1320
1321    fn into_channel(self) -> fidl::Channel {
1322        self.client.into_channel()
1323    }
1324
1325    fn as_channel(&self) -> &fidl::Channel {
1326        self.client.as_channel()
1327    }
1328}
1329
1330#[cfg(target_os = "fuchsia")]
1331impl StreamSinkSynchronousProxy {
1332    pub fn new(channel: fidl::Channel) -> Self {
1333        Self { client: fidl::client::sync::Client::new(channel) }
1334    }
1335
1336    pub fn into_channel(self) -> fidl::Channel {
1337        self.client.into_channel()
1338    }
1339
1340    /// Waits until an event arrives and returns it. It is safe for other
1341    /// threads to make concurrent requests while waiting for an event.
1342    pub fn wait_for_event(
1343        &self,
1344        deadline: zx::MonotonicInstant,
1345    ) -> Result<StreamSinkEvent, fidl::Error> {
1346        StreamSinkEvent::decode(self.client.wait_for_event::<StreamSinkMarker>(deadline)?)
1347    }
1348
1349    /// Puts a packet to the sink.
1350    pub fn r#put_packet(&self, mut payload: StreamSinkPutPacketRequest) -> Result<(), fidl::Error> {
1351        self.client.send::<StreamSinkPutPacketRequest>(
1352            &mut payload,
1353            0x558d757afd726899,
1354            fidl::encoding::DynamicFlags::empty(),
1355        )
1356    }
1357
1358    /// Starts a new segment. Packets following this request and preceding the next such request
1359    /// are assigned to the segment.
1360    pub fn r#start_segment(
1361        &self,
1362        mut payload: &StreamSinkStartSegmentRequest,
1363    ) -> Result<(), fidl::Error> {
1364        self.client.send::<StreamSinkStartSegmentRequest>(
1365            payload,
1366            0x6dd9bc66aa9f715f,
1367            fidl::encoding::DynamicFlags::empty(),
1368        )
1369    }
1370
1371    /// Indicates that the end of the stream has been reached. Consumers such as audio renderers
1372    /// signal their clients when the last packet before end-of-stream has been rendered, so the
1373    /// client knows when to, for example, change the UI state of a player to let the user know the
1374    /// content is done playing. This method is logically scoped to the current segment. A
1375    /// `SetSegment` request and (typically) more packets may follow this request.
1376    pub fn r#end(&self) -> Result<(), fidl::Error> {
1377        self.client.send::<fidl::encoding::EmptyPayload>(
1378            (),
1379            0x1a3a528e83b32f6e,
1380            fidl::encoding::DynamicFlags::empty(),
1381        )
1382    }
1383
1384    /// Sent immediately before the producer closes to indicate why the producer is closing the
1385    /// connection. After sending this request, the producer must refrain from sending any more
1386    /// messages and close the connection promptly.
1387    pub fn r#will_close(
1388        &self,
1389        mut payload: &StreamSinkWillCloseRequest,
1390    ) -> Result<(), fidl::Error> {
1391        self.client.send::<StreamSinkWillCloseRequest>(
1392            payload,
1393            0x6303ee33dbb0fd11,
1394            fidl::encoding::DynamicFlags::empty(),
1395        )
1396    }
1397}
1398
1399#[cfg(target_os = "fuchsia")]
1400impl From<StreamSinkSynchronousProxy> for zx::NullableHandle {
1401    fn from(value: StreamSinkSynchronousProxy) -> Self {
1402        value.into_channel().into()
1403    }
1404}
1405
1406#[cfg(target_os = "fuchsia")]
1407impl From<fidl::Channel> for StreamSinkSynchronousProxy {
1408    fn from(value: fidl::Channel) -> Self {
1409        Self::new(value)
1410    }
1411}
1412
1413#[cfg(target_os = "fuchsia")]
1414impl fidl::endpoints::FromClient for StreamSinkSynchronousProxy {
1415    type Protocol = StreamSinkMarker;
1416
1417    fn from_client(value: fidl::endpoints::ClientEnd<StreamSinkMarker>) -> Self {
1418        Self::new(value.into_channel())
1419    }
1420}
1421
1422#[derive(Debug, Clone)]
1423pub struct StreamSinkProxy {
1424    client: fidl::client::Client<fidl::encoding::DefaultFuchsiaResourceDialect>,
1425}
1426
1427impl fidl::endpoints::Proxy for StreamSinkProxy {
1428    type Protocol = StreamSinkMarker;
1429
1430    fn from_channel(inner: ::fidl::AsyncChannel) -> Self {
1431        Self::new(inner)
1432    }
1433
1434    fn into_channel(self) -> Result<::fidl::AsyncChannel, Self> {
1435        self.client.into_channel().map_err(|client| Self { client })
1436    }
1437
1438    fn as_channel(&self) -> &::fidl::AsyncChannel {
1439        self.client.as_channel()
1440    }
1441}
1442
1443impl StreamSinkProxy {
1444    /// Create a new Proxy for fuchsia.audio/StreamSink.
1445    pub fn new(channel: ::fidl::AsyncChannel) -> Self {
1446        let protocol_name = <StreamSinkMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME;
1447        Self { client: fidl::client::Client::new(channel, protocol_name) }
1448    }
1449
1450    /// Get a Stream of events from the remote end of the protocol.
1451    ///
1452    /// # Panics
1453    ///
1454    /// Panics if the event stream was already taken.
1455    pub fn take_event_stream(&self) -> StreamSinkEventStream {
1456        StreamSinkEventStream { event_receiver: self.client.take_event_receiver() }
1457    }
1458
1459    /// Puts a packet to the sink.
1460    pub fn r#put_packet(&self, mut payload: StreamSinkPutPacketRequest) -> Result<(), fidl::Error> {
1461        StreamSinkProxyInterface::r#put_packet(self, payload)
1462    }
1463
1464    /// Starts a new segment. Packets following this request and preceding the next such request
1465    /// are assigned to the segment.
1466    pub fn r#start_segment(
1467        &self,
1468        mut payload: &StreamSinkStartSegmentRequest,
1469    ) -> Result<(), fidl::Error> {
1470        StreamSinkProxyInterface::r#start_segment(self, payload)
1471    }
1472
1473    /// Indicates that the end of the stream has been reached. Consumers such as audio renderers
1474    /// signal their clients when the last packet before end-of-stream has been rendered, so the
1475    /// client knows when to, for example, change the UI state of a player to let the user know the
1476    /// content is done playing. This method is logically scoped to the current segment. A
1477    /// `SetSegment` request and (typically) more packets may follow this request.
1478    pub fn r#end(&self) -> Result<(), fidl::Error> {
1479        StreamSinkProxyInterface::r#end(self)
1480    }
1481
1482    /// Sent immediately before the producer closes to indicate why the producer is closing the
1483    /// connection. After sending this request, the producer must refrain from sending any more
1484    /// messages and close the connection promptly.
1485    pub fn r#will_close(
1486        &self,
1487        mut payload: &StreamSinkWillCloseRequest,
1488    ) -> Result<(), fidl::Error> {
1489        StreamSinkProxyInterface::r#will_close(self, payload)
1490    }
1491}
1492
1493impl StreamSinkProxyInterface for StreamSinkProxy {
1494    fn r#put_packet(&self, mut payload: StreamSinkPutPacketRequest) -> Result<(), fidl::Error> {
1495        self.client.send::<StreamSinkPutPacketRequest>(
1496            &mut payload,
1497            0x558d757afd726899,
1498            fidl::encoding::DynamicFlags::empty(),
1499        )
1500    }
1501
1502    fn r#start_segment(
1503        &self,
1504        mut payload: &StreamSinkStartSegmentRequest,
1505    ) -> Result<(), fidl::Error> {
1506        self.client.send::<StreamSinkStartSegmentRequest>(
1507            payload,
1508            0x6dd9bc66aa9f715f,
1509            fidl::encoding::DynamicFlags::empty(),
1510        )
1511    }
1512
1513    fn r#end(&self) -> Result<(), fidl::Error> {
1514        self.client.send::<fidl::encoding::EmptyPayload>(
1515            (),
1516            0x1a3a528e83b32f6e,
1517            fidl::encoding::DynamicFlags::empty(),
1518        )
1519    }
1520
1521    fn r#will_close(&self, mut payload: &StreamSinkWillCloseRequest) -> Result<(), fidl::Error> {
1522        self.client.send::<StreamSinkWillCloseRequest>(
1523            payload,
1524            0x6303ee33dbb0fd11,
1525            fidl::encoding::DynamicFlags::empty(),
1526        )
1527    }
1528}
1529
1530pub struct StreamSinkEventStream {
1531    event_receiver: fidl::client::EventReceiver<fidl::encoding::DefaultFuchsiaResourceDialect>,
1532}
1533
1534impl std::marker::Unpin for StreamSinkEventStream {}
1535
1536impl futures::stream::FusedStream for StreamSinkEventStream {
1537    fn is_terminated(&self) -> bool {
1538        self.event_receiver.is_terminated()
1539    }
1540}
1541
1542impl futures::Stream for StreamSinkEventStream {
1543    type Item = Result<StreamSinkEvent, fidl::Error>;
1544
1545    fn poll_next(
1546        mut self: std::pin::Pin<&mut Self>,
1547        cx: &mut std::task::Context<'_>,
1548    ) -> std::task::Poll<Option<Self::Item>> {
1549        match futures::ready!(futures::stream::StreamExt::poll_next_unpin(
1550            &mut self.event_receiver,
1551            cx
1552        )?) {
1553            Some(buf) => std::task::Poll::Ready(Some(StreamSinkEvent::decode(buf))),
1554            None => std::task::Poll::Ready(None),
1555        }
1556    }
1557}
1558
1559#[derive(Debug)]
1560pub enum StreamSinkEvent {
1561    OnWillClose { payload: StreamSinkOnWillCloseRequest },
1562}
1563
1564impl StreamSinkEvent {
1565    #[allow(irrefutable_let_patterns)]
1566    pub fn into_on_will_close(self) -> Option<StreamSinkOnWillCloseRequest> {
1567        if let StreamSinkEvent::OnWillClose { payload } = self { Some((payload)) } else { None }
1568    }
1569
1570    /// Decodes a message buffer as a [`StreamSinkEvent`].
1571    fn decode(
1572        mut buf: <fidl::encoding::DefaultFuchsiaResourceDialect as fidl::encoding::ResourceDialect>::MessageBufEtc,
1573    ) -> Result<StreamSinkEvent, fidl::Error> {
1574        let (bytes, _handles) = buf.split_mut();
1575        let (tx_header, _body_bytes) = fidl::encoding::decode_transaction_header(bytes)?;
1576        debug_assert_eq!(tx_header.tx_id, 0);
1577        match tx_header.ordinal {
1578            0x77093453926bce5b => {
1579                let mut out = fidl::new_empty!(
1580                    StreamSinkOnWillCloseRequest,
1581                    fidl::encoding::DefaultFuchsiaResourceDialect
1582                );
1583                fidl::encoding::Decoder::<fidl::encoding::DefaultFuchsiaResourceDialect>::decode_into::<StreamSinkOnWillCloseRequest>(&tx_header, _body_bytes, _handles, &mut out)?;
1584                Ok((StreamSinkEvent::OnWillClose { payload: out }))
1585            }
1586            _ => Err(fidl::Error::UnknownOrdinal {
1587                ordinal: tx_header.ordinal,
1588                protocol_name: <StreamSinkMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME,
1589            }),
1590        }
1591    }
1592}
1593
1594/// A Stream of incoming requests for fuchsia.audio/StreamSink.
1595pub struct StreamSinkRequestStream {
1596    inner: std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>,
1597    is_terminated: bool,
1598}
1599
1600impl std::marker::Unpin for StreamSinkRequestStream {}
1601
1602impl futures::stream::FusedStream for StreamSinkRequestStream {
1603    fn is_terminated(&self) -> bool {
1604        self.is_terminated
1605    }
1606}
1607
1608impl fidl::endpoints::RequestStream for StreamSinkRequestStream {
1609    type Protocol = StreamSinkMarker;
1610    type ControlHandle = StreamSinkControlHandle;
1611
1612    fn from_channel(channel: ::fidl::AsyncChannel) -> Self {
1613        Self { inner: std::sync::Arc::new(fidl::ServeInner::new(channel)), is_terminated: false }
1614    }
1615
1616    fn control_handle(&self) -> Self::ControlHandle {
1617        StreamSinkControlHandle { inner: self.inner.clone() }
1618    }
1619
1620    fn into_inner(
1621        self,
1622    ) -> (::std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>, bool)
1623    {
1624        (self.inner, self.is_terminated)
1625    }
1626
1627    fn from_inner(
1628        inner: std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>,
1629        is_terminated: bool,
1630    ) -> Self {
1631        Self { inner, is_terminated }
1632    }
1633}
1634
1635impl futures::Stream for StreamSinkRequestStream {
1636    type Item = Result<StreamSinkRequest, fidl::Error>;
1637
1638    fn poll_next(
1639        mut self: std::pin::Pin<&mut Self>,
1640        cx: &mut std::task::Context<'_>,
1641    ) -> std::task::Poll<Option<Self::Item>> {
1642        let this = &mut *self;
1643        if this.inner.check_shutdown(cx) {
1644            this.is_terminated = true;
1645            return std::task::Poll::Ready(None);
1646        }
1647        if this.is_terminated {
1648            panic!("polled StreamSinkRequestStream after completion");
1649        }
1650        fidl::encoding::with_tls_decode_buf::<_, fidl::encoding::DefaultFuchsiaResourceDialect>(
1651            |bytes, handles| {
1652                match this.inner.channel().read_etc(cx, bytes, handles) {
1653                    std::task::Poll::Ready(Ok(())) => {}
1654                    std::task::Poll::Pending => return std::task::Poll::Pending,
1655                    std::task::Poll::Ready(Err(zx_status::Status::PEER_CLOSED)) => {
1656                        this.is_terminated = true;
1657                        return std::task::Poll::Ready(None);
1658                    }
1659                    std::task::Poll::Ready(Err(e)) => {
1660                        return std::task::Poll::Ready(Some(Err(fidl::Error::ServerRequestRead(
1661                            e.into(),
1662                        ))));
1663                    }
1664                }
1665
1666                // A message has been received from the channel
1667                let (header, _body_bytes) = fidl::encoding::decode_transaction_header(bytes)?;
1668
1669                std::task::Poll::Ready(Some(match header.ordinal {
1670                    0x558d757afd726899 => {
1671                        header.validate_request_tx_id(fidl::MethodType::OneWay)?;
1672                        let mut req = fidl::new_empty!(
1673                            StreamSinkPutPacketRequest,
1674                            fidl::encoding::DefaultFuchsiaResourceDialect
1675                        );
1676                        fidl::encoding::Decoder::<fidl::encoding::DefaultFuchsiaResourceDialect>::decode_into::<StreamSinkPutPacketRequest>(&header, _body_bytes, handles, &mut req)?;
1677                        let control_handle = StreamSinkControlHandle { inner: this.inner.clone() };
1678                        Ok(StreamSinkRequest::PutPacket { payload: req, control_handle })
1679                    }
1680                    0x6dd9bc66aa9f715f => {
1681                        header.validate_request_tx_id(fidl::MethodType::OneWay)?;
1682                        let mut req = fidl::new_empty!(
1683                            StreamSinkStartSegmentRequest,
1684                            fidl::encoding::DefaultFuchsiaResourceDialect
1685                        );
1686                        fidl::encoding::Decoder::<fidl::encoding::DefaultFuchsiaResourceDialect>::decode_into::<StreamSinkStartSegmentRequest>(&header, _body_bytes, handles, &mut req)?;
1687                        let control_handle = StreamSinkControlHandle { inner: this.inner.clone() };
1688                        Ok(StreamSinkRequest::StartSegment { payload: req, control_handle })
1689                    }
1690                    0x1a3a528e83b32f6e => {
1691                        header.validate_request_tx_id(fidl::MethodType::OneWay)?;
1692                        let mut req = fidl::new_empty!(
1693                            fidl::encoding::EmptyPayload,
1694                            fidl::encoding::DefaultFuchsiaResourceDialect
1695                        );
1696                        fidl::encoding::Decoder::<fidl::encoding::DefaultFuchsiaResourceDialect>::decode_into::<fidl::encoding::EmptyPayload>(&header, _body_bytes, handles, &mut req)?;
1697                        let control_handle = StreamSinkControlHandle { inner: this.inner.clone() };
1698                        Ok(StreamSinkRequest::End { control_handle })
1699                    }
1700                    0x6303ee33dbb0fd11 => {
1701                        header.validate_request_tx_id(fidl::MethodType::OneWay)?;
1702                        let mut req = fidl::new_empty!(
1703                            StreamSinkWillCloseRequest,
1704                            fidl::encoding::DefaultFuchsiaResourceDialect
1705                        );
1706                        fidl::encoding::Decoder::<fidl::encoding::DefaultFuchsiaResourceDialect>::decode_into::<StreamSinkWillCloseRequest>(&header, _body_bytes, handles, &mut req)?;
1707                        let control_handle = StreamSinkControlHandle { inner: this.inner.clone() };
1708                        Ok(StreamSinkRequest::WillClose { payload: req, control_handle })
1709                    }
1710                    _ => Err(fidl::Error::UnknownOrdinal {
1711                        ordinal: header.ordinal,
1712                        protocol_name:
1713                            <StreamSinkMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME,
1714                    }),
1715                }))
1716            },
1717        )
1718    }
1719}
1720
1721/// A packet sink for cross-process audio stream transport, implemented by audio consumers and used
1722/// by audio producers.
1723#[derive(Debug)]
1724pub enum StreamSinkRequest {
1725    /// Puts a packet to the sink.
1726    PutPacket { payload: StreamSinkPutPacketRequest, control_handle: StreamSinkControlHandle },
1727    /// Starts a new segment. Packets following this request and preceding the next such request
1728    /// are assigned to the segment.
1729    StartSegment { payload: StreamSinkStartSegmentRequest, control_handle: StreamSinkControlHandle },
1730    /// Indicates that the end of the stream has been reached. Consumers such as audio renderers
1731    /// signal their clients when the last packet before end-of-stream has been rendered, so the
1732    /// client knows when to, for example, change the UI state of a player to let the user know the
1733    /// content is done playing. This method is logically scoped to the current segment. A
1734    /// `SetSegment` request and (typically) more packets may follow this request.
1735    End { control_handle: StreamSinkControlHandle },
1736    /// Sent immediately before the producer closes to indicate why the producer is closing the
1737    /// connection. After sending this request, the producer must refrain from sending any more
1738    /// messages and close the connection promptly.
1739    WillClose { payload: StreamSinkWillCloseRequest, control_handle: StreamSinkControlHandle },
1740}
1741
1742impl StreamSinkRequest {
1743    #[allow(irrefutable_let_patterns)]
1744    pub fn into_put_packet(self) -> Option<(StreamSinkPutPacketRequest, StreamSinkControlHandle)> {
1745        if let StreamSinkRequest::PutPacket { payload, control_handle } = self {
1746            Some((payload, control_handle))
1747        } else {
1748            None
1749        }
1750    }
1751
1752    #[allow(irrefutable_let_patterns)]
1753    pub fn into_start_segment(
1754        self,
1755    ) -> Option<(StreamSinkStartSegmentRequest, StreamSinkControlHandle)> {
1756        if let StreamSinkRequest::StartSegment { payload, control_handle } = self {
1757            Some((payload, control_handle))
1758        } else {
1759            None
1760        }
1761    }
1762
1763    #[allow(irrefutable_let_patterns)]
1764    pub fn into_end(self) -> Option<(StreamSinkControlHandle)> {
1765        if let StreamSinkRequest::End { control_handle } = self {
1766            Some((control_handle))
1767        } else {
1768            None
1769        }
1770    }
1771
1772    #[allow(irrefutable_let_patterns)]
1773    pub fn into_will_close(self) -> Option<(StreamSinkWillCloseRequest, StreamSinkControlHandle)> {
1774        if let StreamSinkRequest::WillClose { payload, control_handle } = self {
1775            Some((payload, control_handle))
1776        } else {
1777            None
1778        }
1779    }
1780
1781    /// Name of the method defined in FIDL
1782    pub fn method_name(&self) -> &'static str {
1783        match *self {
1784            StreamSinkRequest::PutPacket { .. } => "put_packet",
1785            StreamSinkRequest::StartSegment { .. } => "start_segment",
1786            StreamSinkRequest::End { .. } => "end",
1787            StreamSinkRequest::WillClose { .. } => "will_close",
1788        }
1789    }
1790}
1791
1792#[derive(Debug, Clone)]
1793pub struct StreamSinkControlHandle {
1794    inner: std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>,
1795}
1796
1797impl StreamSinkControlHandle {
1798    pub fn shutdown_with_epitaph(&self, status: impl Into<fidl::Epitaph>) {
1799        self.inner.shutdown_with_epitaph(status.into())
1800    }
1801}
1802
1803impl fidl::endpoints::ControlHandle for StreamSinkControlHandle {
1804    fn shutdown(&self) {
1805        self.inner.shutdown()
1806    }
1807
1808    fn shutdown_with_epitaph(&self, status: fidl::Epitaph) {
1809        self.inner.shutdown_with_epitaph(status)
1810    }
1811
1812    fn is_closed(&self) -> bool {
1813        self.inner.channel().is_closed()
1814    }
1815    fn on_closed(&self) -> fidl::OnSignalsRef<'_> {
1816        self.inner.channel().on_closed()
1817    }
1818
1819    #[cfg(target_os = "fuchsia")]
1820    fn signal_peer(
1821        &self,
1822        clear_mask: zx::Signals,
1823        set_mask: zx::Signals,
1824    ) -> Result<(), zx_status::Status> {
1825        use fidl::Peered;
1826        self.inner.channel().signal_peer(clear_mask, set_mask)
1827    }
1828}
1829
1830impl StreamSinkControlHandle {
1831    pub fn send_on_will_close(
1832        &self,
1833        mut payload: &StreamSinkOnWillCloseRequest,
1834    ) -> Result<(), fidl::Error> {
1835        self.inner.send::<StreamSinkOnWillCloseRequest>(
1836            payload,
1837            0,
1838            0x77093453926bce5b,
1839            fidl::encoding::DynamicFlags::empty(),
1840        )
1841    }
1842}
1843
1844mod internal {
1845    use super::*;
1846
1847    impl RingBuffer {
1848        #[inline(always)]
1849        fn max_ordinal_present(&self) -> u64 {
1850            if let Some(_) = self.reference_clock_domain {
1851                return 6;
1852            }
1853            if let Some(_) = self.reference_clock {
1854                return 5;
1855            }
1856            if let Some(_) = self.consumer_bytes {
1857                return 4;
1858            }
1859            if let Some(_) = self.producer_bytes {
1860                return 3;
1861            }
1862            if let Some(_) = self.format {
1863                return 2;
1864            }
1865            if let Some(_) = self.buffer {
1866                return 1;
1867            }
1868            0
1869        }
1870    }
1871
1872    impl fidl::encoding::ResourceTypeMarker for RingBuffer {
1873        type Borrowed<'a> = &'a mut Self;
1874        fn take_or_borrow<'a>(
1875            value: &'a mut <Self as fidl::encoding::TypeMarker>::Owned,
1876        ) -> Self::Borrowed<'a> {
1877            value
1878        }
1879    }
1880
1881    unsafe impl fidl::encoding::TypeMarker for RingBuffer {
1882        type Owned = Self;
1883
1884        #[inline(always)]
1885        fn inline_align(_context: fidl::encoding::Context) -> usize {
1886            8
1887        }
1888
1889        #[inline(always)]
1890        fn inline_size(_context: fidl::encoding::Context) -> usize {
1891            16
1892        }
1893    }
1894
1895    unsafe impl fidl::encoding::Encode<RingBuffer, fidl::encoding::DefaultFuchsiaResourceDialect>
1896        for &mut RingBuffer
1897    {
1898        unsafe fn encode(
1899            self,
1900            encoder: &mut fidl::encoding::Encoder<
1901                '_,
1902                fidl::encoding::DefaultFuchsiaResourceDialect,
1903            >,
1904            offset: usize,
1905            mut depth: fidl::encoding::Depth,
1906        ) -> fidl::Result<()> {
1907            encoder.debug_check_bounds::<RingBuffer>(offset);
1908            // Vector header
1909            let max_ordinal: u64 = self.max_ordinal_present();
1910            encoder.write_num(max_ordinal, offset);
1911            encoder.write_num(fidl::encoding::ALLOC_PRESENT_U64, offset + 8);
1912            // Calling encoder.out_of_line_offset(0) is not allowed.
1913            if max_ordinal == 0 {
1914                return Ok(());
1915            }
1916            depth.increment()?;
1917            let envelope_size = 8;
1918            let bytes_len = max_ordinal as usize * envelope_size;
1919            #[allow(unused_variables)]
1920            let offset = encoder.out_of_line_offset(bytes_len);
1921            let mut _prev_end_offset: usize = 0;
1922            if 1 > max_ordinal {
1923                return Ok(());
1924            }
1925
1926            // Write at offset+(ordinal-1)*envelope_size, since ordinals are one-based and envelopes
1927            // are envelope_size bytes.
1928            let cur_offset: usize = (1 - 1) * envelope_size;
1929
1930            // Zero reserved fields.
1931            encoder.padding(offset + _prev_end_offset, cur_offset - _prev_end_offset);
1932
1933            // Safety:
1934            // - bytes_len is calculated to fit envelope_size*max(member.ordinal).
1935            // - Since cur_offset is envelope_size*(member.ordinal - 1) and the envelope takes
1936            //   envelope_size bytes, there is always sufficient room.
1937            fidl::encoding::encode_in_envelope_optional::<fidl_fuchsia_mem::Buffer, fidl::encoding::DefaultFuchsiaResourceDialect>(
1938            self.buffer.as_mut().map(<fidl_fuchsia_mem::Buffer as fidl::encoding::ResourceTypeMarker>::take_or_borrow),
1939            encoder, offset + cur_offset, depth
1940        )?;
1941
1942            _prev_end_offset = cur_offset + envelope_size;
1943            if 2 > max_ordinal {
1944                return Ok(());
1945            }
1946
1947            // Write at offset+(ordinal-1)*envelope_size, since ordinals are one-based and envelopes
1948            // are envelope_size bytes.
1949            let cur_offset: usize = (2 - 1) * envelope_size;
1950
1951            // Zero reserved fields.
1952            encoder.padding(offset + _prev_end_offset, cur_offset - _prev_end_offset);
1953
1954            // Safety:
1955            // - bytes_len is calculated to fit envelope_size*max(member.ordinal).
1956            // - Since cur_offset is envelope_size*(member.ordinal - 1) and the envelope takes
1957            //   envelope_size bytes, there is always sufficient room.
1958            fidl::encoding::encode_in_envelope_optional::<
1959                Format,
1960                fidl::encoding::DefaultFuchsiaResourceDialect,
1961            >(
1962                self.format.as_ref().map(<Format as fidl::encoding::ValueTypeMarker>::borrow),
1963                encoder,
1964                offset + cur_offset,
1965                depth,
1966            )?;
1967
1968            _prev_end_offset = cur_offset + envelope_size;
1969            if 3 > max_ordinal {
1970                return Ok(());
1971            }
1972
1973            // Write at offset+(ordinal-1)*envelope_size, since ordinals are one-based and envelopes
1974            // are envelope_size bytes.
1975            let cur_offset: usize = (3 - 1) * envelope_size;
1976
1977            // Zero reserved fields.
1978            encoder.padding(offset + _prev_end_offset, cur_offset - _prev_end_offset);
1979
1980            // Safety:
1981            // - bytes_len is calculated to fit envelope_size*max(member.ordinal).
1982            // - Since cur_offset is envelope_size*(member.ordinal - 1) and the envelope takes
1983            //   envelope_size bytes, there is always sufficient room.
1984            fidl::encoding::encode_in_envelope_optional::<
1985                u64,
1986                fidl::encoding::DefaultFuchsiaResourceDialect,
1987            >(
1988                self.producer_bytes.as_ref().map(<u64 as fidl::encoding::ValueTypeMarker>::borrow),
1989                encoder,
1990                offset + cur_offset,
1991                depth,
1992            )?;
1993
1994            _prev_end_offset = cur_offset + envelope_size;
1995            if 4 > max_ordinal {
1996                return Ok(());
1997            }
1998
1999            // Write at offset+(ordinal-1)*envelope_size, since ordinals are one-based and envelopes
2000            // are envelope_size bytes.
2001            let cur_offset: usize = (4 - 1) * envelope_size;
2002
2003            // Zero reserved fields.
2004            encoder.padding(offset + _prev_end_offset, cur_offset - _prev_end_offset);
2005
2006            // Safety:
2007            // - bytes_len is calculated to fit envelope_size*max(member.ordinal).
2008            // - Since cur_offset is envelope_size*(member.ordinal - 1) and the envelope takes
2009            //   envelope_size bytes, there is always sufficient room.
2010            fidl::encoding::encode_in_envelope_optional::<
2011                u64,
2012                fidl::encoding::DefaultFuchsiaResourceDialect,
2013            >(
2014                self.consumer_bytes.as_ref().map(<u64 as fidl::encoding::ValueTypeMarker>::borrow),
2015                encoder,
2016                offset + cur_offset,
2017                depth,
2018            )?;
2019
2020            _prev_end_offset = cur_offset + envelope_size;
2021            if 5 > max_ordinal {
2022                return Ok(());
2023            }
2024
2025            // Write at offset+(ordinal-1)*envelope_size, since ordinals are one-based and envelopes
2026            // are envelope_size bytes.
2027            let cur_offset: usize = (5 - 1) * envelope_size;
2028
2029            // Zero reserved fields.
2030            encoder.padding(offset + _prev_end_offset, cur_offset - _prev_end_offset);
2031
2032            // Safety:
2033            // - bytes_len is calculated to fit envelope_size*max(member.ordinal).
2034            // - Since cur_offset is envelope_size*(member.ordinal - 1) and the envelope takes
2035            //   envelope_size bytes, there is always sufficient room.
2036            fidl::encoding::encode_in_envelope_optional::<
2037                fidl::encoding::HandleType<
2038                    fidl::Clock,
2039                    { fidl::ObjectType::CLOCK.into_raw() },
2040                    2147483648,
2041                >,
2042                fidl::encoding::DefaultFuchsiaResourceDialect,
2043            >(
2044                self.reference_clock.as_mut().map(
2045                    <fidl::encoding::HandleType<
2046                        fidl::Clock,
2047                        { fidl::ObjectType::CLOCK.into_raw() },
2048                        2147483648,
2049                    > as fidl::encoding::ResourceTypeMarker>::take_or_borrow,
2050                ),
2051                encoder,
2052                offset + cur_offset,
2053                depth,
2054            )?;
2055
2056            _prev_end_offset = cur_offset + envelope_size;
2057            if 6 > max_ordinal {
2058                return Ok(());
2059            }
2060
2061            // Write at offset+(ordinal-1)*envelope_size, since ordinals are one-based and envelopes
2062            // are envelope_size bytes.
2063            let cur_offset: usize = (6 - 1) * envelope_size;
2064
2065            // Zero reserved fields.
2066            encoder.padding(offset + _prev_end_offset, cur_offset - _prev_end_offset);
2067
2068            // Safety:
2069            // - bytes_len is calculated to fit envelope_size*max(member.ordinal).
2070            // - Since cur_offset is envelope_size*(member.ordinal - 1) and the envelope takes
2071            //   envelope_size bytes, there is always sufficient room.
2072            fidl::encoding::encode_in_envelope_optional::<
2073                u32,
2074                fidl::encoding::DefaultFuchsiaResourceDialect,
2075            >(
2076                self.reference_clock_domain
2077                    .as_ref()
2078                    .map(<u32 as fidl::encoding::ValueTypeMarker>::borrow),
2079                encoder,
2080                offset + cur_offset,
2081                depth,
2082            )?;
2083
2084            _prev_end_offset = cur_offset + envelope_size;
2085
2086            Ok(())
2087        }
2088    }
2089
2090    impl fidl::encoding::Decode<Self, fidl::encoding::DefaultFuchsiaResourceDialect> for RingBuffer {
2091        #[inline(always)]
2092        fn new_empty() -> Self {
2093            Self::default()
2094        }
2095
2096        unsafe fn decode(
2097            &mut self,
2098            decoder: &mut fidl::encoding::Decoder<
2099                '_,
2100                fidl::encoding::DefaultFuchsiaResourceDialect,
2101            >,
2102            offset: usize,
2103            mut depth: fidl::encoding::Depth,
2104        ) -> fidl::Result<()> {
2105            decoder.debug_check_bounds::<Self>(offset);
2106            let len = match fidl::encoding::decode_vector_header(decoder, offset)? {
2107                None => return Err(fidl::Error::NotNullable),
2108                Some(len) => len,
2109            };
2110            // Calling decoder.out_of_line_offset(0) is not allowed.
2111            if len == 0 {
2112                return Ok(());
2113            };
2114            depth.increment()?;
2115            let envelope_size = 8;
2116            let bytes_len = len * envelope_size;
2117            let offset = decoder.out_of_line_offset(bytes_len)?;
2118            // Decode the envelope for each type.
2119            let mut _next_ordinal_to_read = 0;
2120            let mut next_offset = offset;
2121            let end_offset = offset + bytes_len;
2122            _next_ordinal_to_read += 1;
2123            if next_offset >= end_offset {
2124                return Ok(());
2125            }
2126
2127            // Decode unknown envelopes for gaps in ordinals.
2128            while _next_ordinal_to_read < 1 {
2129                fidl::encoding::decode_unknown_envelope(decoder, next_offset, depth)?;
2130                _next_ordinal_to_read += 1;
2131                next_offset += envelope_size;
2132            }
2133
2134            let next_out_of_line = decoder.next_out_of_line();
2135            let handles_before = decoder.remaining_handles();
2136            if let Some((inlined, num_bytes, num_handles)) =
2137                fidl::encoding::decode_envelope_header(decoder, next_offset)?
2138            {
2139                let member_inline_size =
2140                    <fidl_fuchsia_mem::Buffer as fidl::encoding::TypeMarker>::inline_size(
2141                        decoder.context,
2142                    );
2143                if inlined != (member_inline_size <= 4) {
2144                    return Err(fidl::Error::InvalidInlineBitInEnvelope);
2145                }
2146                let inner_offset;
2147                let mut inner_depth = depth.clone();
2148                if inlined {
2149                    decoder.check_inline_envelope_padding(next_offset, member_inline_size)?;
2150                    inner_offset = next_offset;
2151                } else {
2152                    inner_offset = decoder.out_of_line_offset(member_inline_size)?;
2153                    inner_depth.increment()?;
2154                }
2155                let val_ref = self.buffer.get_or_insert_with(|| {
2156                    fidl::new_empty!(
2157                        fidl_fuchsia_mem::Buffer,
2158                        fidl::encoding::DefaultFuchsiaResourceDialect
2159                    )
2160                });
2161                fidl::decode!(
2162                    fidl_fuchsia_mem::Buffer,
2163                    fidl::encoding::DefaultFuchsiaResourceDialect,
2164                    val_ref,
2165                    decoder,
2166                    inner_offset,
2167                    inner_depth
2168                )?;
2169                if !inlined && decoder.next_out_of_line() != next_out_of_line + (num_bytes as usize)
2170                {
2171                    return Err(fidl::Error::InvalidNumBytesInEnvelope);
2172                }
2173                if handles_before != decoder.remaining_handles() + (num_handles as usize) {
2174                    return Err(fidl::Error::InvalidNumHandlesInEnvelope);
2175                }
2176            }
2177
2178            next_offset += envelope_size;
2179            _next_ordinal_to_read += 1;
2180            if next_offset >= end_offset {
2181                return Ok(());
2182            }
2183
2184            // Decode unknown envelopes for gaps in ordinals.
2185            while _next_ordinal_to_read < 2 {
2186                fidl::encoding::decode_unknown_envelope(decoder, next_offset, depth)?;
2187                _next_ordinal_to_read += 1;
2188                next_offset += envelope_size;
2189            }
2190
2191            let next_out_of_line = decoder.next_out_of_line();
2192            let handles_before = decoder.remaining_handles();
2193            if let Some((inlined, num_bytes, num_handles)) =
2194                fidl::encoding::decode_envelope_header(decoder, next_offset)?
2195            {
2196                let member_inline_size =
2197                    <Format as fidl::encoding::TypeMarker>::inline_size(decoder.context);
2198                if inlined != (member_inline_size <= 4) {
2199                    return Err(fidl::Error::InvalidInlineBitInEnvelope);
2200                }
2201                let inner_offset;
2202                let mut inner_depth = depth.clone();
2203                if inlined {
2204                    decoder.check_inline_envelope_padding(next_offset, member_inline_size)?;
2205                    inner_offset = next_offset;
2206                } else {
2207                    inner_offset = decoder.out_of_line_offset(member_inline_size)?;
2208                    inner_depth.increment()?;
2209                }
2210                let val_ref = self.format.get_or_insert_with(|| {
2211                    fidl::new_empty!(Format, fidl::encoding::DefaultFuchsiaResourceDialect)
2212                });
2213                fidl::decode!(
2214                    Format,
2215                    fidl::encoding::DefaultFuchsiaResourceDialect,
2216                    val_ref,
2217                    decoder,
2218                    inner_offset,
2219                    inner_depth
2220                )?;
2221                if !inlined && decoder.next_out_of_line() != next_out_of_line + (num_bytes as usize)
2222                {
2223                    return Err(fidl::Error::InvalidNumBytesInEnvelope);
2224                }
2225                if handles_before != decoder.remaining_handles() + (num_handles as usize) {
2226                    return Err(fidl::Error::InvalidNumHandlesInEnvelope);
2227                }
2228            }
2229
2230            next_offset += envelope_size;
2231            _next_ordinal_to_read += 1;
2232            if next_offset >= end_offset {
2233                return Ok(());
2234            }
2235
2236            // Decode unknown envelopes for gaps in ordinals.
2237            while _next_ordinal_to_read < 3 {
2238                fidl::encoding::decode_unknown_envelope(decoder, next_offset, depth)?;
2239                _next_ordinal_to_read += 1;
2240                next_offset += envelope_size;
2241            }
2242
2243            let next_out_of_line = decoder.next_out_of_line();
2244            let handles_before = decoder.remaining_handles();
2245            if let Some((inlined, num_bytes, num_handles)) =
2246                fidl::encoding::decode_envelope_header(decoder, next_offset)?
2247            {
2248                let member_inline_size =
2249                    <u64 as fidl::encoding::TypeMarker>::inline_size(decoder.context);
2250                if inlined != (member_inline_size <= 4) {
2251                    return Err(fidl::Error::InvalidInlineBitInEnvelope);
2252                }
2253                let inner_offset;
2254                let mut inner_depth = depth.clone();
2255                if inlined {
2256                    decoder.check_inline_envelope_padding(next_offset, member_inline_size)?;
2257                    inner_offset = next_offset;
2258                } else {
2259                    inner_offset = decoder.out_of_line_offset(member_inline_size)?;
2260                    inner_depth.increment()?;
2261                }
2262                let val_ref = self.producer_bytes.get_or_insert_with(|| {
2263                    fidl::new_empty!(u64, fidl::encoding::DefaultFuchsiaResourceDialect)
2264                });
2265                fidl::decode!(
2266                    u64,
2267                    fidl::encoding::DefaultFuchsiaResourceDialect,
2268                    val_ref,
2269                    decoder,
2270                    inner_offset,
2271                    inner_depth
2272                )?;
2273                if !inlined && decoder.next_out_of_line() != next_out_of_line + (num_bytes as usize)
2274                {
2275                    return Err(fidl::Error::InvalidNumBytesInEnvelope);
2276                }
2277                if handles_before != decoder.remaining_handles() + (num_handles as usize) {
2278                    return Err(fidl::Error::InvalidNumHandlesInEnvelope);
2279                }
2280            }
2281
2282            next_offset += envelope_size;
2283            _next_ordinal_to_read += 1;
2284            if next_offset >= end_offset {
2285                return Ok(());
2286            }
2287
2288            // Decode unknown envelopes for gaps in ordinals.
2289            while _next_ordinal_to_read < 4 {
2290                fidl::encoding::decode_unknown_envelope(decoder, next_offset, depth)?;
2291                _next_ordinal_to_read += 1;
2292                next_offset += envelope_size;
2293            }
2294
2295            let next_out_of_line = decoder.next_out_of_line();
2296            let handles_before = decoder.remaining_handles();
2297            if let Some((inlined, num_bytes, num_handles)) =
2298                fidl::encoding::decode_envelope_header(decoder, next_offset)?
2299            {
2300                let member_inline_size =
2301                    <u64 as fidl::encoding::TypeMarker>::inline_size(decoder.context);
2302                if inlined != (member_inline_size <= 4) {
2303                    return Err(fidl::Error::InvalidInlineBitInEnvelope);
2304                }
2305                let inner_offset;
2306                let mut inner_depth = depth.clone();
2307                if inlined {
2308                    decoder.check_inline_envelope_padding(next_offset, member_inline_size)?;
2309                    inner_offset = next_offset;
2310                } else {
2311                    inner_offset = decoder.out_of_line_offset(member_inline_size)?;
2312                    inner_depth.increment()?;
2313                }
2314                let val_ref = self.consumer_bytes.get_or_insert_with(|| {
2315                    fidl::new_empty!(u64, fidl::encoding::DefaultFuchsiaResourceDialect)
2316                });
2317                fidl::decode!(
2318                    u64,
2319                    fidl::encoding::DefaultFuchsiaResourceDialect,
2320                    val_ref,
2321                    decoder,
2322                    inner_offset,
2323                    inner_depth
2324                )?;
2325                if !inlined && decoder.next_out_of_line() != next_out_of_line + (num_bytes as usize)
2326                {
2327                    return Err(fidl::Error::InvalidNumBytesInEnvelope);
2328                }
2329                if handles_before != decoder.remaining_handles() + (num_handles as usize) {
2330                    return Err(fidl::Error::InvalidNumHandlesInEnvelope);
2331                }
2332            }
2333
2334            next_offset += envelope_size;
2335            _next_ordinal_to_read += 1;
2336            if next_offset >= end_offset {
2337                return Ok(());
2338            }
2339
2340            // Decode unknown envelopes for gaps in ordinals.
2341            while _next_ordinal_to_read < 5 {
2342                fidl::encoding::decode_unknown_envelope(decoder, next_offset, depth)?;
2343                _next_ordinal_to_read += 1;
2344                next_offset += envelope_size;
2345            }
2346
2347            let next_out_of_line = decoder.next_out_of_line();
2348            let handles_before = decoder.remaining_handles();
2349            if let Some((inlined, num_bytes, num_handles)) =
2350                fidl::encoding::decode_envelope_header(decoder, next_offset)?
2351            {
2352                let member_inline_size = <fidl::encoding::HandleType<
2353                    fidl::Clock,
2354                    { fidl::ObjectType::CLOCK.into_raw() },
2355                    2147483648,
2356                > as fidl::encoding::TypeMarker>::inline_size(
2357                    decoder.context
2358                );
2359                if inlined != (member_inline_size <= 4) {
2360                    return Err(fidl::Error::InvalidInlineBitInEnvelope);
2361                }
2362                let inner_offset;
2363                let mut inner_depth = depth.clone();
2364                if inlined {
2365                    decoder.check_inline_envelope_padding(next_offset, member_inline_size)?;
2366                    inner_offset = next_offset;
2367                } else {
2368                    inner_offset = decoder.out_of_line_offset(member_inline_size)?;
2369                    inner_depth.increment()?;
2370                }
2371                let val_ref =
2372                self.reference_clock.get_or_insert_with(|| fidl::new_empty!(fidl::encoding::HandleType<fidl::Clock, { fidl::ObjectType::CLOCK.into_raw() }, 2147483648>, fidl::encoding::DefaultFuchsiaResourceDialect));
2373                fidl::decode!(fidl::encoding::HandleType<fidl::Clock, { fidl::ObjectType::CLOCK.into_raw() }, 2147483648>, fidl::encoding::DefaultFuchsiaResourceDialect, val_ref, decoder, inner_offset, inner_depth)?;
2374                if !inlined && decoder.next_out_of_line() != next_out_of_line + (num_bytes as usize)
2375                {
2376                    return Err(fidl::Error::InvalidNumBytesInEnvelope);
2377                }
2378                if handles_before != decoder.remaining_handles() + (num_handles as usize) {
2379                    return Err(fidl::Error::InvalidNumHandlesInEnvelope);
2380                }
2381            }
2382
2383            next_offset += envelope_size;
2384            _next_ordinal_to_read += 1;
2385            if next_offset >= end_offset {
2386                return Ok(());
2387            }
2388
2389            // Decode unknown envelopes for gaps in ordinals.
2390            while _next_ordinal_to_read < 6 {
2391                fidl::encoding::decode_unknown_envelope(decoder, next_offset, depth)?;
2392                _next_ordinal_to_read += 1;
2393                next_offset += envelope_size;
2394            }
2395
2396            let next_out_of_line = decoder.next_out_of_line();
2397            let handles_before = decoder.remaining_handles();
2398            if let Some((inlined, num_bytes, num_handles)) =
2399                fidl::encoding::decode_envelope_header(decoder, next_offset)?
2400            {
2401                let member_inline_size =
2402                    <u32 as fidl::encoding::TypeMarker>::inline_size(decoder.context);
2403                if inlined != (member_inline_size <= 4) {
2404                    return Err(fidl::Error::InvalidInlineBitInEnvelope);
2405                }
2406                let inner_offset;
2407                let mut inner_depth = depth.clone();
2408                if inlined {
2409                    decoder.check_inline_envelope_padding(next_offset, member_inline_size)?;
2410                    inner_offset = next_offset;
2411                } else {
2412                    inner_offset = decoder.out_of_line_offset(member_inline_size)?;
2413                    inner_depth.increment()?;
2414                }
2415                let val_ref = self.reference_clock_domain.get_or_insert_with(|| {
2416                    fidl::new_empty!(u32, fidl::encoding::DefaultFuchsiaResourceDialect)
2417                });
2418                fidl::decode!(
2419                    u32,
2420                    fidl::encoding::DefaultFuchsiaResourceDialect,
2421                    val_ref,
2422                    decoder,
2423                    inner_offset,
2424                    inner_depth
2425                )?;
2426                if !inlined && decoder.next_out_of_line() != next_out_of_line + (num_bytes as usize)
2427                {
2428                    return Err(fidl::Error::InvalidNumBytesInEnvelope);
2429                }
2430                if handles_before != decoder.remaining_handles() + (num_handles as usize) {
2431                    return Err(fidl::Error::InvalidNumHandlesInEnvelope);
2432                }
2433            }
2434
2435            next_offset += envelope_size;
2436
2437            // Decode the remaining unknown envelopes.
2438            while next_offset < end_offset {
2439                _next_ordinal_to_read += 1;
2440                fidl::encoding::decode_unknown_envelope(decoder, next_offset, depth)?;
2441                next_offset += envelope_size;
2442            }
2443
2444            Ok(())
2445        }
2446    }
2447
2448    impl StreamSinkPutPacketRequest {
2449        #[inline(always)]
2450        fn max_ordinal_present(&self) -> u64 {
2451            if let Some(_) = self.release_fence {
2452                return 2;
2453            }
2454            if let Some(_) = self.packet {
2455                return 1;
2456            }
2457            0
2458        }
2459    }
2460
2461    impl fidl::encoding::ResourceTypeMarker for StreamSinkPutPacketRequest {
2462        type Borrowed<'a> = &'a mut Self;
2463        fn take_or_borrow<'a>(
2464            value: &'a mut <Self as fidl::encoding::TypeMarker>::Owned,
2465        ) -> Self::Borrowed<'a> {
2466            value
2467        }
2468    }
2469
2470    unsafe impl fidl::encoding::TypeMarker for StreamSinkPutPacketRequest {
2471        type Owned = Self;
2472
2473        #[inline(always)]
2474        fn inline_align(_context: fidl::encoding::Context) -> usize {
2475            8
2476        }
2477
2478        #[inline(always)]
2479        fn inline_size(_context: fidl::encoding::Context) -> usize {
2480            16
2481        }
2482    }
2483
2484    unsafe impl
2485        fidl::encoding::Encode<
2486            StreamSinkPutPacketRequest,
2487            fidl::encoding::DefaultFuchsiaResourceDialect,
2488        > for &mut StreamSinkPutPacketRequest
2489    {
2490        unsafe fn encode(
2491            self,
2492            encoder: &mut fidl::encoding::Encoder<
2493                '_,
2494                fidl::encoding::DefaultFuchsiaResourceDialect,
2495            >,
2496            offset: usize,
2497            mut depth: fidl::encoding::Depth,
2498        ) -> fidl::Result<()> {
2499            encoder.debug_check_bounds::<StreamSinkPutPacketRequest>(offset);
2500            // Vector header
2501            let max_ordinal: u64 = self.max_ordinal_present();
2502            encoder.write_num(max_ordinal, offset);
2503            encoder.write_num(fidl::encoding::ALLOC_PRESENT_U64, offset + 8);
2504            // Calling encoder.out_of_line_offset(0) is not allowed.
2505            if max_ordinal == 0 {
2506                return Ok(());
2507            }
2508            depth.increment()?;
2509            let envelope_size = 8;
2510            let bytes_len = max_ordinal as usize * envelope_size;
2511            #[allow(unused_variables)]
2512            let offset = encoder.out_of_line_offset(bytes_len);
2513            let mut _prev_end_offset: usize = 0;
2514            if 1 > max_ordinal {
2515                return Ok(());
2516            }
2517
2518            // Write at offset+(ordinal-1)*envelope_size, since ordinals are one-based and envelopes
2519            // are envelope_size bytes.
2520            let cur_offset: usize = (1 - 1) * envelope_size;
2521
2522            // Zero reserved fields.
2523            encoder.padding(offset + _prev_end_offset, cur_offset - _prev_end_offset);
2524
2525            // Safety:
2526            // - bytes_len is calculated to fit envelope_size*max(member.ordinal).
2527            // - Since cur_offset is envelope_size*(member.ordinal - 1) and the envelope takes
2528            //   envelope_size bytes, there is always sufficient room.
2529            fidl::encoding::encode_in_envelope_optional::<
2530                Packet,
2531                fidl::encoding::DefaultFuchsiaResourceDialect,
2532            >(
2533                self.packet.as_ref().map(<Packet as fidl::encoding::ValueTypeMarker>::borrow),
2534                encoder,
2535                offset + cur_offset,
2536                depth,
2537            )?;
2538
2539            _prev_end_offset = cur_offset + envelope_size;
2540            if 2 > max_ordinal {
2541                return Ok(());
2542            }
2543
2544            // Write at offset+(ordinal-1)*envelope_size, since ordinals are one-based and envelopes
2545            // are envelope_size bytes.
2546            let cur_offset: usize = (2 - 1) * envelope_size;
2547
2548            // Zero reserved fields.
2549            encoder.padding(offset + _prev_end_offset, cur_offset - _prev_end_offset);
2550
2551            // Safety:
2552            // - bytes_len is calculated to fit envelope_size*max(member.ordinal).
2553            // - Since cur_offset is envelope_size*(member.ordinal - 1) and the envelope takes
2554            //   envelope_size bytes, there is always sufficient room.
2555            fidl::encoding::encode_in_envelope_optional::<
2556                fidl::encoding::HandleType<
2557                    fidl::EventPair,
2558                    { fidl::ObjectType::EVENTPAIR.into_raw() },
2559                    2147483648,
2560                >,
2561                fidl::encoding::DefaultFuchsiaResourceDialect,
2562            >(
2563                self.release_fence.as_mut().map(
2564                    <fidl::encoding::HandleType<
2565                        fidl::EventPair,
2566                        { fidl::ObjectType::EVENTPAIR.into_raw() },
2567                        2147483648,
2568                    > as fidl::encoding::ResourceTypeMarker>::take_or_borrow,
2569                ),
2570                encoder,
2571                offset + cur_offset,
2572                depth,
2573            )?;
2574
2575            _prev_end_offset = cur_offset + envelope_size;
2576
2577            Ok(())
2578        }
2579    }
2580
2581    impl fidl::encoding::Decode<Self, fidl::encoding::DefaultFuchsiaResourceDialect>
2582        for StreamSinkPutPacketRequest
2583    {
2584        #[inline(always)]
2585        fn new_empty() -> Self {
2586            Self::default()
2587        }
2588
2589        unsafe fn decode(
2590            &mut self,
2591            decoder: &mut fidl::encoding::Decoder<
2592                '_,
2593                fidl::encoding::DefaultFuchsiaResourceDialect,
2594            >,
2595            offset: usize,
2596            mut depth: fidl::encoding::Depth,
2597        ) -> fidl::Result<()> {
2598            decoder.debug_check_bounds::<Self>(offset);
2599            let len = match fidl::encoding::decode_vector_header(decoder, offset)? {
2600                None => return Err(fidl::Error::NotNullable),
2601                Some(len) => len,
2602            };
2603            // Calling decoder.out_of_line_offset(0) is not allowed.
2604            if len == 0 {
2605                return Ok(());
2606            };
2607            depth.increment()?;
2608            let envelope_size = 8;
2609            let bytes_len = len * envelope_size;
2610            let offset = decoder.out_of_line_offset(bytes_len)?;
2611            // Decode the envelope for each type.
2612            let mut _next_ordinal_to_read = 0;
2613            let mut next_offset = offset;
2614            let end_offset = offset + bytes_len;
2615            _next_ordinal_to_read += 1;
2616            if next_offset >= end_offset {
2617                return Ok(());
2618            }
2619
2620            // Decode unknown envelopes for gaps in ordinals.
2621            while _next_ordinal_to_read < 1 {
2622                fidl::encoding::decode_unknown_envelope(decoder, next_offset, depth)?;
2623                _next_ordinal_to_read += 1;
2624                next_offset += envelope_size;
2625            }
2626
2627            let next_out_of_line = decoder.next_out_of_line();
2628            let handles_before = decoder.remaining_handles();
2629            if let Some((inlined, num_bytes, num_handles)) =
2630                fidl::encoding::decode_envelope_header(decoder, next_offset)?
2631            {
2632                let member_inline_size =
2633                    <Packet as fidl::encoding::TypeMarker>::inline_size(decoder.context);
2634                if inlined != (member_inline_size <= 4) {
2635                    return Err(fidl::Error::InvalidInlineBitInEnvelope);
2636                }
2637                let inner_offset;
2638                let mut inner_depth = depth.clone();
2639                if inlined {
2640                    decoder.check_inline_envelope_padding(next_offset, member_inline_size)?;
2641                    inner_offset = next_offset;
2642                } else {
2643                    inner_offset = decoder.out_of_line_offset(member_inline_size)?;
2644                    inner_depth.increment()?;
2645                }
2646                let val_ref = self.packet.get_or_insert_with(|| {
2647                    fidl::new_empty!(Packet, fidl::encoding::DefaultFuchsiaResourceDialect)
2648                });
2649                fidl::decode!(
2650                    Packet,
2651                    fidl::encoding::DefaultFuchsiaResourceDialect,
2652                    val_ref,
2653                    decoder,
2654                    inner_offset,
2655                    inner_depth
2656                )?;
2657                if !inlined && decoder.next_out_of_line() != next_out_of_line + (num_bytes as usize)
2658                {
2659                    return Err(fidl::Error::InvalidNumBytesInEnvelope);
2660                }
2661                if handles_before != decoder.remaining_handles() + (num_handles as usize) {
2662                    return Err(fidl::Error::InvalidNumHandlesInEnvelope);
2663                }
2664            }
2665
2666            next_offset += envelope_size;
2667            _next_ordinal_to_read += 1;
2668            if next_offset >= end_offset {
2669                return Ok(());
2670            }
2671
2672            // Decode unknown envelopes for gaps in ordinals.
2673            while _next_ordinal_to_read < 2 {
2674                fidl::encoding::decode_unknown_envelope(decoder, next_offset, depth)?;
2675                _next_ordinal_to_read += 1;
2676                next_offset += envelope_size;
2677            }
2678
2679            let next_out_of_line = decoder.next_out_of_line();
2680            let handles_before = decoder.remaining_handles();
2681            if let Some((inlined, num_bytes, num_handles)) =
2682                fidl::encoding::decode_envelope_header(decoder, next_offset)?
2683            {
2684                let member_inline_size = <fidl::encoding::HandleType<
2685                    fidl::EventPair,
2686                    { fidl::ObjectType::EVENTPAIR.into_raw() },
2687                    2147483648,
2688                > as fidl::encoding::TypeMarker>::inline_size(
2689                    decoder.context
2690                );
2691                if inlined != (member_inline_size <= 4) {
2692                    return Err(fidl::Error::InvalidInlineBitInEnvelope);
2693                }
2694                let inner_offset;
2695                let mut inner_depth = depth.clone();
2696                if inlined {
2697                    decoder.check_inline_envelope_padding(next_offset, member_inline_size)?;
2698                    inner_offset = next_offset;
2699                } else {
2700                    inner_offset = decoder.out_of_line_offset(member_inline_size)?;
2701                    inner_depth.increment()?;
2702                }
2703                let val_ref =
2704                self.release_fence.get_or_insert_with(|| fidl::new_empty!(fidl::encoding::HandleType<fidl::EventPair, { fidl::ObjectType::EVENTPAIR.into_raw() }, 2147483648>, fidl::encoding::DefaultFuchsiaResourceDialect));
2705                fidl::decode!(fidl::encoding::HandleType<fidl::EventPair, { fidl::ObjectType::EVENTPAIR.into_raw() }, 2147483648>, fidl::encoding::DefaultFuchsiaResourceDialect, val_ref, decoder, inner_offset, inner_depth)?;
2706                if !inlined && decoder.next_out_of_line() != next_out_of_line + (num_bytes as usize)
2707                {
2708                    return Err(fidl::Error::InvalidNumBytesInEnvelope);
2709                }
2710                if handles_before != decoder.remaining_handles() + (num_handles as usize) {
2711                    return Err(fidl::Error::InvalidNumHandlesInEnvelope);
2712                }
2713            }
2714
2715            next_offset += envelope_size;
2716
2717            // Decode the remaining unknown envelopes.
2718            while next_offset < end_offset {
2719                _next_ordinal_to_read += 1;
2720                fidl::encoding::decode_unknown_envelope(decoder, next_offset, depth)?;
2721                next_offset += envelope_size;
2722            }
2723
2724            Ok(())
2725        }
2726    }
2727}