fidl_fuchsia_audio/
fidl_fuchsia_audio.rs

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