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