Skip to main content

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