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 DelayWatcherControlHandle {
443    pub fn shutdown_with_epitaph(&self, status: impl Into<fidl::Epitaph>) {
444        self.inner.shutdown_with_epitaph(status.into())
445    }
446}
447
448impl fdomain_client::fidl::ControlHandle for DelayWatcherControlHandle {
449    fn shutdown(&self) {
450        self.inner.shutdown()
451    }
452
453    fn shutdown_with_epitaph(&self, status: fidl::Epitaph) {
454        self.inner.shutdown_with_epitaph(status)
455    }
456
457    fn is_closed(&self) -> bool {
458        self.inner.channel().is_closed()
459    }
460    fn on_closed(&self) -> fdomain_client::OnFDomainSignals {
461        self.inner.channel().on_closed()
462    }
463}
464
465impl DelayWatcherControlHandle {}
466
467#[must_use = "FIDL methods require a response to be sent"]
468#[derive(Debug)]
469pub struct DelayWatcherWatchDelayResponder {
470    control_handle: std::mem::ManuallyDrop<DelayWatcherControlHandle>,
471    tx_id: u32,
472}
473
474/// Set the the channel to be shutdown (see [`DelayWatcherControlHandle::shutdown`])
475/// if the responder is dropped without sending a response, so that the client
476/// doesn't hang. To prevent this behavior, call `drop_without_shutdown`.
477impl std::ops::Drop for DelayWatcherWatchDelayResponder {
478    fn drop(&mut self) {
479        self.control_handle.shutdown();
480        // Safety: drops once, never accessed again
481        unsafe { std::mem::ManuallyDrop::drop(&mut self.control_handle) };
482    }
483}
484
485impl fdomain_client::fidl::Responder for DelayWatcherWatchDelayResponder {
486    type ControlHandle = DelayWatcherControlHandle;
487
488    fn control_handle(&self) -> &DelayWatcherControlHandle {
489        &self.control_handle
490    }
491
492    fn drop_without_shutdown(mut self) {
493        // Safety: drops once, never accessed again due to mem::forget
494        unsafe { std::mem::ManuallyDrop::drop(&mut self.control_handle) };
495        // Prevent Drop from running (which would shut down the channel)
496        std::mem::forget(self);
497    }
498}
499
500impl DelayWatcherWatchDelayResponder {
501    /// Sends a response to the FIDL transaction.
502    ///
503    /// Sets the channel to shutdown if an error occurs.
504    pub fn send(self, mut payload: &DelayWatcherWatchDelayResponse) -> Result<(), fidl::Error> {
505        let _result = self.send_raw(payload);
506        if _result.is_err() {
507            self.control_handle.shutdown();
508        }
509        self.drop_without_shutdown();
510        _result
511    }
512
513    /// Similar to "send" but does not shutdown the channel if an error occurs.
514    pub fn send_no_shutdown_on_err(
515        self,
516        mut payload: &DelayWatcherWatchDelayResponse,
517    ) -> Result<(), fidl::Error> {
518        let _result = self.send_raw(payload);
519        self.drop_without_shutdown();
520        _result
521    }
522
523    fn send_raw(&self, mut payload: &DelayWatcherWatchDelayResponse) -> Result<(), fidl::Error> {
524        self.control_handle.inner.send::<DelayWatcherWatchDelayResponse>(
525            payload,
526            self.tx_id,
527            0x3a90c91ee2f1644c,
528            fidl::encoding::DynamicFlags::empty(),
529        )
530    }
531}
532
533#[derive(Debug, Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Hash)]
534pub struct GainControlMarker;
535
536impl fdomain_client::fidl::ProtocolMarker for GainControlMarker {
537    type Proxy = GainControlProxy;
538    type RequestStream = GainControlRequestStream;
539
540    const DEBUG_NAME: &'static str = "(anonymous) GainControl";
541}
542pub type GainControlSetGainResult = Result<GainControlSetGainResponse, GainError>;
543pub type GainControlSetMuteResult = Result<GainControlSetMuteResponse, GainError>;
544
545pub trait GainControlProxyInterface: Send + Sync {
546    type SetGainResponseFut: std::future::Future<Output = Result<GainControlSetGainResult, fidl::Error>>
547        + Send;
548    fn r#set_gain(&self, payload: &GainControlSetGainRequest) -> Self::SetGainResponseFut;
549    type SetMuteResponseFut: std::future::Future<Output = Result<GainControlSetMuteResult, fidl::Error>>
550        + Send;
551    fn r#set_mute(&self, payload: &GainControlSetMuteRequest) -> Self::SetMuteResponseFut;
552}
553
554#[derive(Debug, Clone)]
555pub struct GainControlProxy {
556    client: fidl::client::Client<fdomain_client::fidl::FDomainResourceDialect>,
557}
558
559impl fdomain_client::fidl::Proxy for GainControlProxy {
560    type Protocol = GainControlMarker;
561
562    fn from_channel(inner: fdomain_client::Channel) -> Self {
563        Self::new(inner)
564    }
565
566    fn into_channel(self) -> Result<fdomain_client::Channel, Self> {
567        self.client.into_channel().map_err(|client| Self { client })
568    }
569
570    fn as_channel(&self) -> &fdomain_client::Channel {
571        self.client.as_channel()
572    }
573}
574
575impl GainControlProxy {
576    /// Create a new Proxy for fuchsia.audio/GainControl.
577    pub fn new(channel: fdomain_client::Channel) -> Self {
578        let protocol_name = <GainControlMarker as fdomain_client::fidl::ProtocolMarker>::DEBUG_NAME;
579        Self { client: fidl::client::Client::new(channel, protocol_name) }
580    }
581
582    /// Get a Stream of events from the remote end of the protocol.
583    ///
584    /// # Panics
585    ///
586    /// Panics if the event stream was already taken.
587    pub fn take_event_stream(&self) -> GainControlEventStream {
588        GainControlEventStream { event_receiver: self.client.take_event_receiver() }
589    }
590
591    /// Sets the gain knob.
592    pub fn r#set_gain(
593        &self,
594        mut payload: &GainControlSetGainRequest,
595    ) -> fidl::client::QueryResponseFut<
596        GainControlSetGainResult,
597        fdomain_client::fidl::FDomainResourceDialect,
598    > {
599        GainControlProxyInterface::r#set_gain(self, payload)
600    }
601
602    /// Set the mute knob.
603    pub fn r#set_mute(
604        &self,
605        mut payload: &GainControlSetMuteRequest,
606    ) -> fidl::client::QueryResponseFut<
607        GainControlSetMuteResult,
608        fdomain_client::fidl::FDomainResourceDialect,
609    > {
610        GainControlProxyInterface::r#set_mute(self, payload)
611    }
612}
613
614impl GainControlProxyInterface for GainControlProxy {
615    type SetGainResponseFut = fidl::client::QueryResponseFut<
616        GainControlSetGainResult,
617        fdomain_client::fidl::FDomainResourceDialect,
618    >;
619    fn r#set_gain(&self, mut payload: &GainControlSetGainRequest) -> Self::SetGainResponseFut {
620        fn _decode(
621            mut _buf: Result<<fdomain_client::fidl::FDomainResourceDialect as fidl::encoding::ResourceDialect>::MessageBufEtc, fidl::Error>,
622        ) -> Result<GainControlSetGainResult, fidl::Error> {
623            let _response = fidl::client::decode_transaction_body::<
624                fidl::encoding::ResultType<GainControlSetGainResponse, GainError>,
625                fdomain_client::fidl::FDomainResourceDialect,
626                0x6ece305e4a5823dc,
627            >(_buf?)?;
628            Ok(_response.map(|x| x))
629        }
630        self.client.send_query_and_decode::<GainControlSetGainRequest, GainControlSetGainResult>(
631            payload,
632            0x6ece305e4a5823dc,
633            fidl::encoding::DynamicFlags::empty(),
634            _decode,
635        )
636    }
637
638    type SetMuteResponseFut = fidl::client::QueryResponseFut<
639        GainControlSetMuteResult,
640        fdomain_client::fidl::FDomainResourceDialect,
641    >;
642    fn r#set_mute(&self, mut payload: &GainControlSetMuteRequest) -> Self::SetMuteResponseFut {
643        fn _decode(
644            mut _buf: Result<<fdomain_client::fidl::FDomainResourceDialect as fidl::encoding::ResourceDialect>::MessageBufEtc, fidl::Error>,
645        ) -> Result<GainControlSetMuteResult, fidl::Error> {
646            let _response = fidl::client::decode_transaction_body::<
647                fidl::encoding::ResultType<GainControlSetMuteResponse, GainError>,
648                fdomain_client::fidl::FDomainResourceDialect,
649                0xed03d88ce4f8965,
650            >(_buf?)?;
651            Ok(_response.map(|x| x))
652        }
653        self.client.send_query_and_decode::<GainControlSetMuteRequest, GainControlSetMuteResult>(
654            payload,
655            0xed03d88ce4f8965,
656            fidl::encoding::DynamicFlags::empty(),
657            _decode,
658        )
659    }
660}
661
662pub struct GainControlEventStream {
663    event_receiver: fidl::client::EventReceiver<fdomain_client::fidl::FDomainResourceDialect>,
664}
665
666impl std::marker::Unpin for GainControlEventStream {}
667
668impl futures::stream::FusedStream for GainControlEventStream {
669    fn is_terminated(&self) -> bool {
670        self.event_receiver.is_terminated()
671    }
672}
673
674impl futures::Stream for GainControlEventStream {
675    type Item = Result<GainControlEvent, fidl::Error>;
676
677    fn poll_next(
678        mut self: std::pin::Pin<&mut Self>,
679        cx: &mut std::task::Context<'_>,
680    ) -> std::task::Poll<Option<Self::Item>> {
681        match futures::ready!(futures::stream::StreamExt::poll_next_unpin(
682            &mut self.event_receiver,
683            cx
684        )?) {
685            Some(buf) => std::task::Poll::Ready(Some(GainControlEvent::decode(buf))),
686            None => std::task::Poll::Ready(None),
687        }
688    }
689}
690
691#[derive(Debug)]
692pub enum GainControlEvent {}
693
694impl GainControlEvent {
695    /// Decodes a message buffer as a [`GainControlEvent`].
696    fn decode(
697        mut buf: <fdomain_client::fidl::FDomainResourceDialect as fidl::encoding::ResourceDialect>::MessageBufEtc,
698    ) -> Result<GainControlEvent, fidl::Error> {
699        let (bytes, _handles) = buf.split_mut();
700        let (tx_header, _body_bytes) = fidl::encoding::decode_transaction_header(bytes)?;
701        debug_assert_eq!(tx_header.tx_id, 0);
702        match tx_header.ordinal {
703            _ => Err(fidl::Error::UnknownOrdinal {
704                ordinal: tx_header.ordinal,
705                protocol_name:
706                    <GainControlMarker as fdomain_client::fidl::ProtocolMarker>::DEBUG_NAME,
707            }),
708        }
709    }
710}
711
712/// A Stream of incoming requests for fuchsia.audio/GainControl.
713pub struct GainControlRequestStream {
714    inner: std::sync::Arc<fidl::ServeInner<fdomain_client::fidl::FDomainResourceDialect>>,
715    is_terminated: bool,
716}
717
718impl std::marker::Unpin for GainControlRequestStream {}
719
720impl futures::stream::FusedStream for GainControlRequestStream {
721    fn is_terminated(&self) -> bool {
722        self.is_terminated
723    }
724}
725
726impl fdomain_client::fidl::RequestStream for GainControlRequestStream {
727    type Protocol = GainControlMarker;
728    type ControlHandle = GainControlControlHandle;
729
730    fn from_channel(channel: fdomain_client::Channel) -> Self {
731        Self { inner: std::sync::Arc::new(fidl::ServeInner::new(channel)), is_terminated: false }
732    }
733
734    fn control_handle(&self) -> Self::ControlHandle {
735        GainControlControlHandle { inner: self.inner.clone() }
736    }
737
738    fn into_inner(
739        self,
740    ) -> (::std::sync::Arc<fidl::ServeInner<fdomain_client::fidl::FDomainResourceDialect>>, bool)
741    {
742        (self.inner, self.is_terminated)
743    }
744
745    fn from_inner(
746        inner: std::sync::Arc<fidl::ServeInner<fdomain_client::fidl::FDomainResourceDialect>>,
747        is_terminated: bool,
748    ) -> Self {
749        Self { inner, is_terminated }
750    }
751}
752
753impl futures::Stream for GainControlRequestStream {
754    type Item = Result<GainControlRequest, fidl::Error>;
755
756    fn poll_next(
757        mut self: std::pin::Pin<&mut Self>,
758        cx: &mut std::task::Context<'_>,
759    ) -> std::task::Poll<Option<Self::Item>> {
760        let this = &mut *self;
761        if this.inner.check_shutdown(cx) {
762            this.is_terminated = true;
763            return std::task::Poll::Ready(None);
764        }
765        if this.is_terminated {
766            panic!("polled GainControlRequestStream after completion");
767        }
768        fidl::encoding::with_tls_decode_buf::<_, fdomain_client::fidl::FDomainResourceDialect>(
769            |bytes, handles| {
770                match this.inner.channel().read_etc(cx, bytes, handles) {
771                    std::task::Poll::Ready(Ok(())) => {}
772                    std::task::Poll::Pending => return std::task::Poll::Pending,
773                    std::task::Poll::Ready(Err(None)) => {
774                        this.is_terminated = true;
775                        return std::task::Poll::Ready(None);
776                    }
777                    std::task::Poll::Ready(Err(Some(e))) => {
778                        return std::task::Poll::Ready(Some(Err(fidl::Error::ServerRequestRead(
779                            e.into(),
780                        ))));
781                    }
782                }
783
784                // A message has been received from the channel
785                let (header, _body_bytes) = fidl::encoding::decode_transaction_header(bytes)?;
786
787                std::task::Poll::Ready(Some(match header.ordinal {
788                    0x6ece305e4a5823dc => {
789                        header.validate_request_tx_id(fidl::MethodType::TwoWay)?;
790                        let mut req = fidl::new_empty!(
791                            GainControlSetGainRequest,
792                            fdomain_client::fidl::FDomainResourceDialect
793                        );
794                        fidl::encoding::Decoder::<fdomain_client::fidl::FDomainResourceDialect>::decode_into::<GainControlSetGainRequest>(&header, _body_bytes, handles, &mut req)?;
795                        let control_handle = GainControlControlHandle { inner: this.inner.clone() };
796                        Ok(GainControlRequest::SetGain {
797                            payload: req,
798                            responder: GainControlSetGainResponder {
799                                control_handle: std::mem::ManuallyDrop::new(control_handle),
800                                tx_id: header.tx_id,
801                            },
802                        })
803                    }
804                    0xed03d88ce4f8965 => {
805                        header.validate_request_tx_id(fidl::MethodType::TwoWay)?;
806                        let mut req = fidl::new_empty!(
807                            GainControlSetMuteRequest,
808                            fdomain_client::fidl::FDomainResourceDialect
809                        );
810                        fidl::encoding::Decoder::<fdomain_client::fidl::FDomainResourceDialect>::decode_into::<GainControlSetMuteRequest>(&header, _body_bytes, handles, &mut req)?;
811                        let control_handle = GainControlControlHandle { inner: this.inner.clone() };
812                        Ok(GainControlRequest::SetMute {
813                            payload: req,
814                            responder: GainControlSetMuteResponder {
815                                control_handle: std::mem::ManuallyDrop::new(control_handle),
816                                tx_id: header.tx_id,
817                            },
818                        })
819                    }
820                    _ => Err(fidl::Error::UnknownOrdinal {
821                        ordinal: header.ordinal,
822                        protocol_name:
823                            <GainControlMarker as fdomain_client::fidl::ProtocolMarker>::DEBUG_NAME,
824                    }),
825                }))
826            },
827        )
828    }
829}
830
831/// Enables control and monitoring of audio gain. This interface is typically a
832/// tear-off of other interfaces.
833///
834/// ## Knobs
835///
836/// This interface exposes two orthogonal knobs:
837///
838/// * The *gain* knob controls a single value in "relative decibels". A value of
839///   0 applies no gain, positive values increase gain, and negative values
840///   decrease gain. Depending on context, gain may be applied relative to an
841///   input stream or relative to some absolute reference point, such as the
842///   maximum loudness of a speaker.
843///
844///   This knob has no defined maximum or minimum value. Individual
845///   implementations may clamp to an implementation-defined maximum value or
846///   treat all values below an implementation-defined minimum value equivalent
847///   to "muted", but this behavior is not required.
848///
849/// * The *mute* knob controls a single boolean value. When `true`, the
850///   GainControl is muted and the effective gain is negative infinity. When
851///   `false`, gain is controlled by the *gain* knob.
852///
853/// ## Scheduling
854///
855/// Changes to the *gain* and *mute* knobs can be scheduled for a time in the
856/// future. Scheduling happens on timestamps relative to a reference clock which
857/// must be established when this protocol is created.
858#[derive(Debug)]
859pub enum GainControlRequest {
860    /// Sets the gain knob.
861    SetGain { payload: GainControlSetGainRequest, responder: GainControlSetGainResponder },
862    /// Set the mute knob.
863    SetMute { payload: GainControlSetMuteRequest, responder: GainControlSetMuteResponder },
864}
865
866impl GainControlRequest {
867    #[allow(irrefutable_let_patterns)]
868    pub fn into_set_gain(self) -> Option<(GainControlSetGainRequest, GainControlSetGainResponder)> {
869        if let GainControlRequest::SetGain { payload, responder } = self {
870            Some((payload, responder))
871        } else {
872            None
873        }
874    }
875
876    #[allow(irrefutable_let_patterns)]
877    pub fn into_set_mute(self) -> Option<(GainControlSetMuteRequest, GainControlSetMuteResponder)> {
878        if let GainControlRequest::SetMute { payload, responder } = self {
879            Some((payload, responder))
880        } else {
881            None
882        }
883    }
884
885    /// Name of the method defined in FIDL
886    pub fn method_name(&self) -> &'static str {
887        match *self {
888            GainControlRequest::SetGain { .. } => "set_gain",
889            GainControlRequest::SetMute { .. } => "set_mute",
890        }
891    }
892}
893
894#[derive(Debug, Clone)]
895pub struct GainControlControlHandle {
896    inner: std::sync::Arc<fidl::ServeInner<fdomain_client::fidl::FDomainResourceDialect>>,
897}
898
899impl GainControlControlHandle {
900    pub fn shutdown_with_epitaph(&self, status: impl Into<fidl::Epitaph>) {
901        self.inner.shutdown_with_epitaph(status.into())
902    }
903}
904
905impl fdomain_client::fidl::ControlHandle for GainControlControlHandle {
906    fn shutdown(&self) {
907        self.inner.shutdown()
908    }
909
910    fn shutdown_with_epitaph(&self, status: fidl::Epitaph) {
911        self.inner.shutdown_with_epitaph(status)
912    }
913
914    fn is_closed(&self) -> bool {
915        self.inner.channel().is_closed()
916    }
917    fn on_closed(&self) -> fdomain_client::OnFDomainSignals {
918        self.inner.channel().on_closed()
919    }
920}
921
922impl GainControlControlHandle {}
923
924#[must_use = "FIDL methods require a response to be sent"]
925#[derive(Debug)]
926pub struct GainControlSetGainResponder {
927    control_handle: std::mem::ManuallyDrop<GainControlControlHandle>,
928    tx_id: u32,
929}
930
931/// Set the the channel to be shutdown (see [`GainControlControlHandle::shutdown`])
932/// if the responder is dropped without sending a response, so that the client
933/// doesn't hang. To prevent this behavior, call `drop_without_shutdown`.
934impl std::ops::Drop for GainControlSetGainResponder {
935    fn drop(&mut self) {
936        self.control_handle.shutdown();
937        // Safety: drops once, never accessed again
938        unsafe { std::mem::ManuallyDrop::drop(&mut self.control_handle) };
939    }
940}
941
942impl fdomain_client::fidl::Responder for GainControlSetGainResponder {
943    type ControlHandle = GainControlControlHandle;
944
945    fn control_handle(&self) -> &GainControlControlHandle {
946        &self.control_handle
947    }
948
949    fn drop_without_shutdown(mut self) {
950        // Safety: drops once, never accessed again due to mem::forget
951        unsafe { std::mem::ManuallyDrop::drop(&mut self.control_handle) };
952        // Prevent Drop from running (which would shut down the channel)
953        std::mem::forget(self);
954    }
955}
956
957impl GainControlSetGainResponder {
958    /// Sends a response to the FIDL transaction.
959    ///
960    /// Sets the channel to shutdown if an error occurs.
961    pub fn send(
962        self,
963        mut result: Result<&GainControlSetGainResponse, GainError>,
964    ) -> Result<(), fidl::Error> {
965        let _result = self.send_raw(result);
966        if _result.is_err() {
967            self.control_handle.shutdown();
968        }
969        self.drop_without_shutdown();
970        _result
971    }
972
973    /// Similar to "send" but does not shutdown the channel if an error occurs.
974    pub fn send_no_shutdown_on_err(
975        self,
976        mut result: Result<&GainControlSetGainResponse, GainError>,
977    ) -> Result<(), fidl::Error> {
978        let _result = self.send_raw(result);
979        self.drop_without_shutdown();
980        _result
981    }
982
983    fn send_raw(
984        &self,
985        mut result: Result<&GainControlSetGainResponse, GainError>,
986    ) -> Result<(), fidl::Error> {
987        self.control_handle
988            .inner
989            .send::<fidl::encoding::ResultType<GainControlSetGainResponse, GainError>>(
990                result,
991                self.tx_id,
992                0x6ece305e4a5823dc,
993                fidl::encoding::DynamicFlags::empty(),
994            )
995    }
996}
997
998#[must_use = "FIDL methods require a response to be sent"]
999#[derive(Debug)]
1000pub struct GainControlSetMuteResponder {
1001    control_handle: std::mem::ManuallyDrop<GainControlControlHandle>,
1002    tx_id: u32,
1003}
1004
1005/// Set the the channel to be shutdown (see [`GainControlControlHandle::shutdown`])
1006/// if the responder is dropped without sending a response, so that the client
1007/// doesn't hang. To prevent this behavior, call `drop_without_shutdown`.
1008impl std::ops::Drop for GainControlSetMuteResponder {
1009    fn drop(&mut self) {
1010        self.control_handle.shutdown();
1011        // Safety: drops once, never accessed again
1012        unsafe { std::mem::ManuallyDrop::drop(&mut self.control_handle) };
1013    }
1014}
1015
1016impl fdomain_client::fidl::Responder for GainControlSetMuteResponder {
1017    type ControlHandle = GainControlControlHandle;
1018
1019    fn control_handle(&self) -> &GainControlControlHandle {
1020        &self.control_handle
1021    }
1022
1023    fn drop_without_shutdown(mut self) {
1024        // Safety: drops once, never accessed again due to mem::forget
1025        unsafe { std::mem::ManuallyDrop::drop(&mut self.control_handle) };
1026        // Prevent Drop from running (which would shut down the channel)
1027        std::mem::forget(self);
1028    }
1029}
1030
1031impl GainControlSetMuteResponder {
1032    /// Sends a response to the FIDL transaction.
1033    ///
1034    /// Sets the channel to shutdown if an error occurs.
1035    pub fn send(
1036        self,
1037        mut result: Result<&GainControlSetMuteResponse, GainError>,
1038    ) -> Result<(), fidl::Error> {
1039        let _result = self.send_raw(result);
1040        if _result.is_err() {
1041            self.control_handle.shutdown();
1042        }
1043        self.drop_without_shutdown();
1044        _result
1045    }
1046
1047    /// Similar to "send" but does not shutdown the channel if an error occurs.
1048    pub fn send_no_shutdown_on_err(
1049        self,
1050        mut result: Result<&GainControlSetMuteResponse, GainError>,
1051    ) -> Result<(), fidl::Error> {
1052        let _result = self.send_raw(result);
1053        self.drop_without_shutdown();
1054        _result
1055    }
1056
1057    fn send_raw(
1058        &self,
1059        mut result: Result<&GainControlSetMuteResponse, GainError>,
1060    ) -> Result<(), fidl::Error> {
1061        self.control_handle
1062            .inner
1063            .send::<fidl::encoding::ResultType<GainControlSetMuteResponse, GainError>>(
1064                result,
1065                self.tx_id,
1066                0xed03d88ce4f8965,
1067                fidl::encoding::DynamicFlags::empty(),
1068            )
1069    }
1070}
1071
1072#[derive(Debug, Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Hash)]
1073pub struct StreamSinkMarker;
1074
1075impl fdomain_client::fidl::ProtocolMarker for StreamSinkMarker {
1076    type Proxy = StreamSinkProxy;
1077    type RequestStream = StreamSinkRequestStream;
1078
1079    const DEBUG_NAME: &'static str = "(anonymous) StreamSink";
1080}
1081
1082pub trait StreamSinkProxyInterface: Send + Sync {
1083    fn r#put_packet(&self, payload: StreamSinkPutPacketRequest) -> Result<(), fidl::Error>;
1084    fn r#start_segment(&self, payload: &StreamSinkStartSegmentRequest) -> Result<(), fidl::Error>;
1085    fn r#end(&self) -> Result<(), fidl::Error>;
1086    fn r#will_close(&self, payload: &StreamSinkWillCloseRequest) -> Result<(), fidl::Error>;
1087}
1088
1089#[derive(Debug, Clone)]
1090pub struct StreamSinkProxy {
1091    client: fidl::client::Client<fdomain_client::fidl::FDomainResourceDialect>,
1092}
1093
1094impl fdomain_client::fidl::Proxy for StreamSinkProxy {
1095    type Protocol = StreamSinkMarker;
1096
1097    fn from_channel(inner: fdomain_client::Channel) -> Self {
1098        Self::new(inner)
1099    }
1100
1101    fn into_channel(self) -> Result<fdomain_client::Channel, Self> {
1102        self.client.into_channel().map_err(|client| Self { client })
1103    }
1104
1105    fn as_channel(&self) -> &fdomain_client::Channel {
1106        self.client.as_channel()
1107    }
1108}
1109
1110impl StreamSinkProxy {
1111    /// Create a new Proxy for fuchsia.audio/StreamSink.
1112    pub fn new(channel: fdomain_client::Channel) -> Self {
1113        let protocol_name = <StreamSinkMarker as fdomain_client::fidl::ProtocolMarker>::DEBUG_NAME;
1114        Self { client: fidl::client::Client::new(channel, protocol_name) }
1115    }
1116
1117    /// Get a Stream of events from the remote end of the protocol.
1118    ///
1119    /// # Panics
1120    ///
1121    /// Panics if the event stream was already taken.
1122    pub fn take_event_stream(&self) -> StreamSinkEventStream {
1123        StreamSinkEventStream { event_receiver: self.client.take_event_receiver() }
1124    }
1125
1126    /// Puts a packet to the sink.
1127    pub fn r#put_packet(&self, mut payload: StreamSinkPutPacketRequest) -> Result<(), fidl::Error> {
1128        StreamSinkProxyInterface::r#put_packet(self, payload)
1129    }
1130
1131    /// Starts a new segment. Packets following this request and preceding the next such request
1132    /// are assigned to the segment.
1133    pub fn r#start_segment(
1134        &self,
1135        mut payload: &StreamSinkStartSegmentRequest,
1136    ) -> Result<(), fidl::Error> {
1137        StreamSinkProxyInterface::r#start_segment(self, payload)
1138    }
1139
1140    /// Indicates that the end of the stream has been reached. Consumers such as audio renderers
1141    /// signal their clients when the last packet before end-of-stream has been rendered, so the
1142    /// client knows when to, for example, change the UI state of a player to let the user know the
1143    /// content is done playing. This method is logically scoped to the current segment. A
1144    /// `SetSegment` request and (typically) more packets may follow this request.
1145    pub fn r#end(&self) -> Result<(), fidl::Error> {
1146        StreamSinkProxyInterface::r#end(self)
1147    }
1148
1149    /// Sent immediately before the producer closes to indicate why the producer is closing the
1150    /// connection. After sending this request, the producer must refrain from sending any more
1151    /// messages and close the connection promptly.
1152    pub fn r#will_close(
1153        &self,
1154        mut payload: &StreamSinkWillCloseRequest,
1155    ) -> Result<(), fidl::Error> {
1156        StreamSinkProxyInterface::r#will_close(self, payload)
1157    }
1158}
1159
1160impl StreamSinkProxyInterface for StreamSinkProxy {
1161    fn r#put_packet(&self, mut payload: StreamSinkPutPacketRequest) -> Result<(), fidl::Error> {
1162        self.client.send::<StreamSinkPutPacketRequest>(
1163            &mut payload,
1164            0x558d757afd726899,
1165            fidl::encoding::DynamicFlags::empty(),
1166        )
1167    }
1168
1169    fn r#start_segment(
1170        &self,
1171        mut payload: &StreamSinkStartSegmentRequest,
1172    ) -> Result<(), fidl::Error> {
1173        self.client.send::<StreamSinkStartSegmentRequest>(
1174            payload,
1175            0x6dd9bc66aa9f715f,
1176            fidl::encoding::DynamicFlags::empty(),
1177        )
1178    }
1179
1180    fn r#end(&self) -> Result<(), fidl::Error> {
1181        self.client.send::<fidl::encoding::EmptyPayload>(
1182            (),
1183            0x1a3a528e83b32f6e,
1184            fidl::encoding::DynamicFlags::empty(),
1185        )
1186    }
1187
1188    fn r#will_close(&self, mut payload: &StreamSinkWillCloseRequest) -> Result<(), fidl::Error> {
1189        self.client.send::<StreamSinkWillCloseRequest>(
1190            payload,
1191            0x6303ee33dbb0fd11,
1192            fidl::encoding::DynamicFlags::empty(),
1193        )
1194    }
1195}
1196
1197pub struct StreamSinkEventStream {
1198    event_receiver: fidl::client::EventReceiver<fdomain_client::fidl::FDomainResourceDialect>,
1199}
1200
1201impl std::marker::Unpin for StreamSinkEventStream {}
1202
1203impl futures::stream::FusedStream for StreamSinkEventStream {
1204    fn is_terminated(&self) -> bool {
1205        self.event_receiver.is_terminated()
1206    }
1207}
1208
1209impl futures::Stream for StreamSinkEventStream {
1210    type Item = Result<StreamSinkEvent, fidl::Error>;
1211
1212    fn poll_next(
1213        mut self: std::pin::Pin<&mut Self>,
1214        cx: &mut std::task::Context<'_>,
1215    ) -> std::task::Poll<Option<Self::Item>> {
1216        match futures::ready!(futures::stream::StreamExt::poll_next_unpin(
1217            &mut self.event_receiver,
1218            cx
1219        )?) {
1220            Some(buf) => std::task::Poll::Ready(Some(StreamSinkEvent::decode(buf))),
1221            None => std::task::Poll::Ready(None),
1222        }
1223    }
1224}
1225
1226#[derive(Debug)]
1227pub enum StreamSinkEvent {
1228    OnWillClose { payload: StreamSinkOnWillCloseRequest },
1229}
1230
1231impl StreamSinkEvent {
1232    #[allow(irrefutable_let_patterns)]
1233    pub fn into_on_will_close(self) -> Option<StreamSinkOnWillCloseRequest> {
1234        if let StreamSinkEvent::OnWillClose { payload } = self { Some((payload)) } else { None }
1235    }
1236
1237    /// Decodes a message buffer as a [`StreamSinkEvent`].
1238    fn decode(
1239        mut buf: <fdomain_client::fidl::FDomainResourceDialect as fidl::encoding::ResourceDialect>::MessageBufEtc,
1240    ) -> Result<StreamSinkEvent, fidl::Error> {
1241        let (bytes, _handles) = buf.split_mut();
1242        let (tx_header, _body_bytes) = fidl::encoding::decode_transaction_header(bytes)?;
1243        debug_assert_eq!(tx_header.tx_id, 0);
1244        match tx_header.ordinal {
1245            0x77093453926bce5b => {
1246                let mut out = fidl::new_empty!(
1247                    StreamSinkOnWillCloseRequest,
1248                    fdomain_client::fidl::FDomainResourceDialect
1249                );
1250                fidl::encoding::Decoder::<fdomain_client::fidl::FDomainResourceDialect>::decode_into::<StreamSinkOnWillCloseRequest>(&tx_header, _body_bytes, _handles, &mut out)?;
1251                Ok((StreamSinkEvent::OnWillClose { payload: out }))
1252            }
1253            _ => Err(fidl::Error::UnknownOrdinal {
1254                ordinal: tx_header.ordinal,
1255                protocol_name:
1256                    <StreamSinkMarker as fdomain_client::fidl::ProtocolMarker>::DEBUG_NAME,
1257            }),
1258        }
1259    }
1260}
1261
1262/// A Stream of incoming requests for fuchsia.audio/StreamSink.
1263pub struct StreamSinkRequestStream {
1264    inner: std::sync::Arc<fidl::ServeInner<fdomain_client::fidl::FDomainResourceDialect>>,
1265    is_terminated: bool,
1266}
1267
1268impl std::marker::Unpin for StreamSinkRequestStream {}
1269
1270impl futures::stream::FusedStream for StreamSinkRequestStream {
1271    fn is_terminated(&self) -> bool {
1272        self.is_terminated
1273    }
1274}
1275
1276impl fdomain_client::fidl::RequestStream for StreamSinkRequestStream {
1277    type Protocol = StreamSinkMarker;
1278    type ControlHandle = StreamSinkControlHandle;
1279
1280    fn from_channel(channel: fdomain_client::Channel) -> Self {
1281        Self { inner: std::sync::Arc::new(fidl::ServeInner::new(channel)), is_terminated: false }
1282    }
1283
1284    fn control_handle(&self) -> Self::ControlHandle {
1285        StreamSinkControlHandle { inner: self.inner.clone() }
1286    }
1287
1288    fn into_inner(
1289        self,
1290    ) -> (::std::sync::Arc<fidl::ServeInner<fdomain_client::fidl::FDomainResourceDialect>>, bool)
1291    {
1292        (self.inner, self.is_terminated)
1293    }
1294
1295    fn from_inner(
1296        inner: std::sync::Arc<fidl::ServeInner<fdomain_client::fidl::FDomainResourceDialect>>,
1297        is_terminated: bool,
1298    ) -> Self {
1299        Self { inner, is_terminated }
1300    }
1301}
1302
1303impl futures::Stream for StreamSinkRequestStream {
1304    type Item = Result<StreamSinkRequest, fidl::Error>;
1305
1306    fn poll_next(
1307        mut self: std::pin::Pin<&mut Self>,
1308        cx: &mut std::task::Context<'_>,
1309    ) -> std::task::Poll<Option<Self::Item>> {
1310        let this = &mut *self;
1311        if this.inner.check_shutdown(cx) {
1312            this.is_terminated = true;
1313            return std::task::Poll::Ready(None);
1314        }
1315        if this.is_terminated {
1316            panic!("polled StreamSinkRequestStream after completion");
1317        }
1318        fidl::encoding::with_tls_decode_buf::<_, fdomain_client::fidl::FDomainResourceDialect>(
1319            |bytes, handles| {
1320                match this.inner.channel().read_etc(cx, bytes, handles) {
1321                    std::task::Poll::Ready(Ok(())) => {}
1322                    std::task::Poll::Pending => return std::task::Poll::Pending,
1323                    std::task::Poll::Ready(Err(None)) => {
1324                        this.is_terminated = true;
1325                        return std::task::Poll::Ready(None);
1326                    }
1327                    std::task::Poll::Ready(Err(Some(e))) => {
1328                        return std::task::Poll::Ready(Some(Err(fidl::Error::ServerRequestRead(
1329                            e.into(),
1330                        ))));
1331                    }
1332                }
1333
1334                // A message has been received from the channel
1335                let (header, _body_bytes) = fidl::encoding::decode_transaction_header(bytes)?;
1336
1337                std::task::Poll::Ready(Some(match header.ordinal {
1338                    0x558d757afd726899 => {
1339                        header.validate_request_tx_id(fidl::MethodType::OneWay)?;
1340                        let mut req = fidl::new_empty!(
1341                            StreamSinkPutPacketRequest,
1342                            fdomain_client::fidl::FDomainResourceDialect
1343                        );
1344                        fidl::encoding::Decoder::<fdomain_client::fidl::FDomainResourceDialect>::decode_into::<StreamSinkPutPacketRequest>(&header, _body_bytes, handles, &mut req)?;
1345                        let control_handle = StreamSinkControlHandle { inner: this.inner.clone() };
1346                        Ok(StreamSinkRequest::PutPacket { payload: req, control_handle })
1347                    }
1348                    0x6dd9bc66aa9f715f => {
1349                        header.validate_request_tx_id(fidl::MethodType::OneWay)?;
1350                        let mut req = fidl::new_empty!(
1351                            StreamSinkStartSegmentRequest,
1352                            fdomain_client::fidl::FDomainResourceDialect
1353                        );
1354                        fidl::encoding::Decoder::<fdomain_client::fidl::FDomainResourceDialect>::decode_into::<StreamSinkStartSegmentRequest>(&header, _body_bytes, handles, &mut req)?;
1355                        let control_handle = StreamSinkControlHandle { inner: this.inner.clone() };
1356                        Ok(StreamSinkRequest::StartSegment { payload: req, control_handle })
1357                    }
1358                    0x1a3a528e83b32f6e => {
1359                        header.validate_request_tx_id(fidl::MethodType::OneWay)?;
1360                        let mut req = fidl::new_empty!(
1361                            fidl::encoding::EmptyPayload,
1362                            fdomain_client::fidl::FDomainResourceDialect
1363                        );
1364                        fidl::encoding::Decoder::<fdomain_client::fidl::FDomainResourceDialect>::decode_into::<fidl::encoding::EmptyPayload>(&header, _body_bytes, handles, &mut req)?;
1365                        let control_handle = StreamSinkControlHandle { inner: this.inner.clone() };
1366                        Ok(StreamSinkRequest::End { control_handle })
1367                    }
1368                    0x6303ee33dbb0fd11 => {
1369                        header.validate_request_tx_id(fidl::MethodType::OneWay)?;
1370                        let mut req = fidl::new_empty!(
1371                            StreamSinkWillCloseRequest,
1372                            fdomain_client::fidl::FDomainResourceDialect
1373                        );
1374                        fidl::encoding::Decoder::<fdomain_client::fidl::FDomainResourceDialect>::decode_into::<StreamSinkWillCloseRequest>(&header, _body_bytes, handles, &mut req)?;
1375                        let control_handle = StreamSinkControlHandle { inner: this.inner.clone() };
1376                        Ok(StreamSinkRequest::WillClose { payload: req, control_handle })
1377                    }
1378                    _ => Err(fidl::Error::UnknownOrdinal {
1379                        ordinal: header.ordinal,
1380                        protocol_name:
1381                            <StreamSinkMarker as fdomain_client::fidl::ProtocolMarker>::DEBUG_NAME,
1382                    }),
1383                }))
1384            },
1385        )
1386    }
1387}
1388
1389/// A packet sink for cross-process audio stream transport, implemented by audio consumers and used
1390/// by audio producers.
1391#[derive(Debug)]
1392pub enum StreamSinkRequest {
1393    /// Puts a packet to the sink.
1394    PutPacket { payload: StreamSinkPutPacketRequest, control_handle: StreamSinkControlHandle },
1395    /// Starts a new segment. Packets following this request and preceding the next such request
1396    /// are assigned to the segment.
1397    StartSegment { payload: StreamSinkStartSegmentRequest, control_handle: StreamSinkControlHandle },
1398    /// Indicates that the end of the stream has been reached. Consumers such as audio renderers
1399    /// signal their clients when the last packet before end-of-stream has been rendered, so the
1400    /// client knows when to, for example, change the UI state of a player to let the user know the
1401    /// content is done playing. This method is logically scoped to the current segment. A
1402    /// `SetSegment` request and (typically) more packets may follow this request.
1403    End { control_handle: StreamSinkControlHandle },
1404    /// Sent immediately before the producer closes to indicate why the producer is closing the
1405    /// connection. After sending this request, the producer must refrain from sending any more
1406    /// messages and close the connection promptly.
1407    WillClose { payload: StreamSinkWillCloseRequest, control_handle: StreamSinkControlHandle },
1408}
1409
1410impl StreamSinkRequest {
1411    #[allow(irrefutable_let_patterns)]
1412    pub fn into_put_packet(self) -> Option<(StreamSinkPutPacketRequest, StreamSinkControlHandle)> {
1413        if let StreamSinkRequest::PutPacket { payload, control_handle } = self {
1414            Some((payload, control_handle))
1415        } else {
1416            None
1417        }
1418    }
1419
1420    #[allow(irrefutable_let_patterns)]
1421    pub fn into_start_segment(
1422        self,
1423    ) -> Option<(StreamSinkStartSegmentRequest, StreamSinkControlHandle)> {
1424        if let StreamSinkRequest::StartSegment { payload, control_handle } = self {
1425            Some((payload, control_handle))
1426        } else {
1427            None
1428        }
1429    }
1430
1431    #[allow(irrefutable_let_patterns)]
1432    pub fn into_end(self) -> Option<(StreamSinkControlHandle)> {
1433        if let StreamSinkRequest::End { control_handle } = self {
1434            Some((control_handle))
1435        } else {
1436            None
1437        }
1438    }
1439
1440    #[allow(irrefutable_let_patterns)]
1441    pub fn into_will_close(self) -> Option<(StreamSinkWillCloseRequest, StreamSinkControlHandle)> {
1442        if let StreamSinkRequest::WillClose { payload, control_handle } = self {
1443            Some((payload, control_handle))
1444        } else {
1445            None
1446        }
1447    }
1448
1449    /// Name of the method defined in FIDL
1450    pub fn method_name(&self) -> &'static str {
1451        match *self {
1452            StreamSinkRequest::PutPacket { .. } => "put_packet",
1453            StreamSinkRequest::StartSegment { .. } => "start_segment",
1454            StreamSinkRequest::End { .. } => "end",
1455            StreamSinkRequest::WillClose { .. } => "will_close",
1456        }
1457    }
1458}
1459
1460#[derive(Debug, Clone)]
1461pub struct StreamSinkControlHandle {
1462    inner: std::sync::Arc<fidl::ServeInner<fdomain_client::fidl::FDomainResourceDialect>>,
1463}
1464
1465impl StreamSinkControlHandle {
1466    pub fn shutdown_with_epitaph(&self, status: impl Into<fidl::Epitaph>) {
1467        self.inner.shutdown_with_epitaph(status.into())
1468    }
1469}
1470
1471impl fdomain_client::fidl::ControlHandle for StreamSinkControlHandle {
1472    fn shutdown(&self) {
1473        self.inner.shutdown()
1474    }
1475
1476    fn shutdown_with_epitaph(&self, status: fidl::Epitaph) {
1477        self.inner.shutdown_with_epitaph(status)
1478    }
1479
1480    fn is_closed(&self) -> bool {
1481        self.inner.channel().is_closed()
1482    }
1483    fn on_closed(&self) -> fdomain_client::OnFDomainSignals {
1484        self.inner.channel().on_closed()
1485    }
1486}
1487
1488impl StreamSinkControlHandle {
1489    pub fn send_on_will_close(
1490        &self,
1491        mut payload: &StreamSinkOnWillCloseRequest,
1492    ) -> Result<(), fidl::Error> {
1493        self.inner.send::<StreamSinkOnWillCloseRequest>(
1494            payload,
1495            0,
1496            0x77093453926bce5b,
1497            fidl::encoding::DynamicFlags::empty(),
1498        )
1499    }
1500}
1501
1502mod internal {
1503    use super::*;
1504
1505    impl RingBuffer {
1506        #[inline(always)]
1507        fn max_ordinal_present(&self) -> u64 {
1508            if let Some(_) = self.reference_clock_domain {
1509                return 6;
1510            }
1511            if let Some(_) = self.reference_clock {
1512                return 5;
1513            }
1514            if let Some(_) = self.consumer_bytes {
1515                return 4;
1516            }
1517            if let Some(_) = self.producer_bytes {
1518                return 3;
1519            }
1520            if let Some(_) = self.format {
1521                return 2;
1522            }
1523            if let Some(_) = self.buffer {
1524                return 1;
1525            }
1526            0
1527        }
1528    }
1529
1530    impl fidl::encoding::ResourceTypeMarker for RingBuffer {
1531        type Borrowed<'a> = &'a mut Self;
1532        fn take_or_borrow<'a>(
1533            value: &'a mut <Self as fidl::encoding::TypeMarker>::Owned,
1534        ) -> Self::Borrowed<'a> {
1535            value
1536        }
1537    }
1538
1539    unsafe impl fidl::encoding::TypeMarker for RingBuffer {
1540        type Owned = Self;
1541
1542        #[inline(always)]
1543        fn inline_align(_context: fidl::encoding::Context) -> usize {
1544            8
1545        }
1546
1547        #[inline(always)]
1548        fn inline_size(_context: fidl::encoding::Context) -> usize {
1549            16
1550        }
1551    }
1552
1553    unsafe impl fidl::encoding::Encode<RingBuffer, fdomain_client::fidl::FDomainResourceDialect>
1554        for &mut RingBuffer
1555    {
1556        unsafe fn encode(
1557            self,
1558            encoder: &mut fidl::encoding::Encoder<'_, fdomain_client::fidl::FDomainResourceDialect>,
1559            offset: usize,
1560            mut depth: fidl::encoding::Depth,
1561        ) -> fidl::Result<()> {
1562            encoder.debug_check_bounds::<RingBuffer>(offset);
1563            // Vector header
1564            let max_ordinal: u64 = self.max_ordinal_present();
1565            encoder.write_num(max_ordinal, offset);
1566            encoder.write_num(fidl::encoding::ALLOC_PRESENT_U64, offset + 8);
1567            // Calling encoder.out_of_line_offset(0) is not allowed.
1568            if max_ordinal == 0 {
1569                return Ok(());
1570            }
1571            depth.increment()?;
1572            let envelope_size = 8;
1573            let bytes_len = max_ordinal as usize * envelope_size;
1574            #[allow(unused_variables)]
1575            let offset = encoder.out_of_line_offset(bytes_len);
1576            let mut _prev_end_offset: usize = 0;
1577            if 1 > max_ordinal {
1578                return Ok(());
1579            }
1580
1581            // Write at offset+(ordinal-1)*envelope_size, since ordinals are one-based and envelopes
1582            // are envelope_size bytes.
1583            let cur_offset: usize = (1 - 1) * envelope_size;
1584
1585            // Zero reserved fields.
1586            encoder.padding(offset + _prev_end_offset, cur_offset - _prev_end_offset);
1587
1588            // Safety:
1589            // - bytes_len is calculated to fit envelope_size*max(member.ordinal).
1590            // - Since cur_offset is envelope_size*(member.ordinal - 1) and the envelope takes
1591            //   envelope_size bytes, there is always sufficient room.
1592            fidl::encoding::encode_in_envelope_optional::<fdomain_fuchsia_mem::Buffer, fdomain_client::fidl::FDomainResourceDialect>(
1593            self.buffer.as_mut().map(<fdomain_fuchsia_mem::Buffer as fidl::encoding::ResourceTypeMarker>::take_or_borrow),
1594            encoder, offset + cur_offset, depth
1595        )?;
1596
1597            _prev_end_offset = cur_offset + envelope_size;
1598            if 2 > max_ordinal {
1599                return Ok(());
1600            }
1601
1602            // Write at offset+(ordinal-1)*envelope_size, since ordinals are one-based and envelopes
1603            // are envelope_size bytes.
1604            let cur_offset: usize = (2 - 1) * envelope_size;
1605
1606            // Zero reserved fields.
1607            encoder.padding(offset + _prev_end_offset, cur_offset - _prev_end_offset);
1608
1609            // Safety:
1610            // - bytes_len is calculated to fit envelope_size*max(member.ordinal).
1611            // - Since cur_offset is envelope_size*(member.ordinal - 1) and the envelope takes
1612            //   envelope_size bytes, there is always sufficient room.
1613            fidl::encoding::encode_in_envelope_optional::<
1614                Format,
1615                fdomain_client::fidl::FDomainResourceDialect,
1616            >(
1617                self.format.as_ref().map(<Format as fidl::encoding::ValueTypeMarker>::borrow),
1618                encoder,
1619                offset + cur_offset,
1620                depth,
1621            )?;
1622
1623            _prev_end_offset = cur_offset + envelope_size;
1624            if 3 > max_ordinal {
1625                return Ok(());
1626            }
1627
1628            // Write at offset+(ordinal-1)*envelope_size, since ordinals are one-based and envelopes
1629            // are envelope_size bytes.
1630            let cur_offset: usize = (3 - 1) * envelope_size;
1631
1632            // Zero reserved fields.
1633            encoder.padding(offset + _prev_end_offset, cur_offset - _prev_end_offset);
1634
1635            // Safety:
1636            // - bytes_len is calculated to fit envelope_size*max(member.ordinal).
1637            // - Since cur_offset is envelope_size*(member.ordinal - 1) and the envelope takes
1638            //   envelope_size bytes, there is always sufficient room.
1639            fidl::encoding::encode_in_envelope_optional::<
1640                u64,
1641                fdomain_client::fidl::FDomainResourceDialect,
1642            >(
1643                self.producer_bytes.as_ref().map(<u64 as fidl::encoding::ValueTypeMarker>::borrow),
1644                encoder,
1645                offset + cur_offset,
1646                depth,
1647            )?;
1648
1649            _prev_end_offset = cur_offset + envelope_size;
1650            if 4 > max_ordinal {
1651                return Ok(());
1652            }
1653
1654            // Write at offset+(ordinal-1)*envelope_size, since ordinals are one-based and envelopes
1655            // are envelope_size bytes.
1656            let cur_offset: usize = (4 - 1) * envelope_size;
1657
1658            // Zero reserved fields.
1659            encoder.padding(offset + _prev_end_offset, cur_offset - _prev_end_offset);
1660
1661            // Safety:
1662            // - bytes_len is calculated to fit envelope_size*max(member.ordinal).
1663            // - Since cur_offset is envelope_size*(member.ordinal - 1) and the envelope takes
1664            //   envelope_size bytes, there is always sufficient room.
1665            fidl::encoding::encode_in_envelope_optional::<
1666                u64,
1667                fdomain_client::fidl::FDomainResourceDialect,
1668            >(
1669                self.consumer_bytes.as_ref().map(<u64 as fidl::encoding::ValueTypeMarker>::borrow),
1670                encoder,
1671                offset + cur_offset,
1672                depth,
1673            )?;
1674
1675            _prev_end_offset = cur_offset + envelope_size;
1676            if 5 > max_ordinal {
1677                return Ok(());
1678            }
1679
1680            // Write at offset+(ordinal-1)*envelope_size, since ordinals are one-based and envelopes
1681            // are envelope_size bytes.
1682            let cur_offset: usize = (5 - 1) * envelope_size;
1683
1684            // Zero reserved fields.
1685            encoder.padding(offset + _prev_end_offset, cur_offset - _prev_end_offset);
1686
1687            // Safety:
1688            // - bytes_len is calculated to fit envelope_size*max(member.ordinal).
1689            // - Since cur_offset is envelope_size*(member.ordinal - 1) and the envelope takes
1690            //   envelope_size bytes, there is always sufficient room.
1691            fidl::encoding::encode_in_envelope_optional::<
1692                fidl::encoding::HandleType<
1693                    fdomain_client::Clock,
1694                    { fidl::ObjectType::CLOCK.into_raw() },
1695                    2147483648,
1696                >,
1697                fdomain_client::fidl::FDomainResourceDialect,
1698            >(
1699                self.reference_clock.as_mut().map(
1700                    <fidl::encoding::HandleType<
1701                        fdomain_client::Clock,
1702                        { fidl::ObjectType::CLOCK.into_raw() },
1703                        2147483648,
1704                    > as fidl::encoding::ResourceTypeMarker>::take_or_borrow,
1705                ),
1706                encoder,
1707                offset + cur_offset,
1708                depth,
1709            )?;
1710
1711            _prev_end_offset = cur_offset + envelope_size;
1712            if 6 > max_ordinal {
1713                return Ok(());
1714            }
1715
1716            // Write at offset+(ordinal-1)*envelope_size, since ordinals are one-based and envelopes
1717            // are envelope_size bytes.
1718            let cur_offset: usize = (6 - 1) * envelope_size;
1719
1720            // Zero reserved fields.
1721            encoder.padding(offset + _prev_end_offset, cur_offset - _prev_end_offset);
1722
1723            // Safety:
1724            // - bytes_len is calculated to fit envelope_size*max(member.ordinal).
1725            // - Since cur_offset is envelope_size*(member.ordinal - 1) and the envelope takes
1726            //   envelope_size bytes, there is always sufficient room.
1727            fidl::encoding::encode_in_envelope_optional::<
1728                u32,
1729                fdomain_client::fidl::FDomainResourceDialect,
1730            >(
1731                self.reference_clock_domain
1732                    .as_ref()
1733                    .map(<u32 as fidl::encoding::ValueTypeMarker>::borrow),
1734                encoder,
1735                offset + cur_offset,
1736                depth,
1737            )?;
1738
1739            _prev_end_offset = cur_offset + envelope_size;
1740
1741            Ok(())
1742        }
1743    }
1744
1745    impl fidl::encoding::Decode<Self, fdomain_client::fidl::FDomainResourceDialect> for RingBuffer {
1746        #[inline(always)]
1747        fn new_empty() -> Self {
1748            Self::default()
1749        }
1750
1751        unsafe fn decode(
1752            &mut self,
1753            decoder: &mut fidl::encoding::Decoder<'_, fdomain_client::fidl::FDomainResourceDialect>,
1754            offset: usize,
1755            mut depth: fidl::encoding::Depth,
1756        ) -> fidl::Result<()> {
1757            decoder.debug_check_bounds::<Self>(offset);
1758            let len = match fidl::encoding::decode_vector_header(decoder, offset)? {
1759                None => return Err(fidl::Error::NotNullable),
1760                Some(len) => len,
1761            };
1762            // Calling decoder.out_of_line_offset(0) is not allowed.
1763            if len == 0 {
1764                return Ok(());
1765            };
1766            depth.increment()?;
1767            let envelope_size = 8;
1768            let bytes_len = len * envelope_size;
1769            let offset = decoder.out_of_line_offset(bytes_len)?;
1770            // Decode the envelope for each type.
1771            let mut _next_ordinal_to_read = 0;
1772            let mut next_offset = offset;
1773            let end_offset = offset + bytes_len;
1774            _next_ordinal_to_read += 1;
1775            if next_offset >= end_offset {
1776                return Ok(());
1777            }
1778
1779            // Decode unknown envelopes for gaps in ordinals.
1780            while _next_ordinal_to_read < 1 {
1781                fidl::encoding::decode_unknown_envelope(decoder, next_offset, depth)?;
1782                _next_ordinal_to_read += 1;
1783                next_offset += envelope_size;
1784            }
1785
1786            let next_out_of_line = decoder.next_out_of_line();
1787            let handles_before = decoder.remaining_handles();
1788            if let Some((inlined, num_bytes, num_handles)) =
1789                fidl::encoding::decode_envelope_header(decoder, next_offset)?
1790            {
1791                let member_inline_size =
1792                    <fdomain_fuchsia_mem::Buffer as fidl::encoding::TypeMarker>::inline_size(
1793                        decoder.context,
1794                    );
1795                if inlined != (member_inline_size <= 4) {
1796                    return Err(fidl::Error::InvalidInlineBitInEnvelope);
1797                }
1798                let inner_offset;
1799                let mut inner_depth = depth.clone();
1800                if inlined {
1801                    decoder.check_inline_envelope_padding(next_offset, member_inline_size)?;
1802                    inner_offset = next_offset;
1803                } else {
1804                    inner_offset = decoder.out_of_line_offset(member_inline_size)?;
1805                    inner_depth.increment()?;
1806                }
1807                let val_ref = self.buffer.get_or_insert_with(|| {
1808                    fidl::new_empty!(
1809                        fdomain_fuchsia_mem::Buffer,
1810                        fdomain_client::fidl::FDomainResourceDialect
1811                    )
1812                });
1813                fidl::decode!(
1814                    fdomain_fuchsia_mem::Buffer,
1815                    fdomain_client::fidl::FDomainResourceDialect,
1816                    val_ref,
1817                    decoder,
1818                    inner_offset,
1819                    inner_depth
1820                )?;
1821                if !inlined && decoder.next_out_of_line() != next_out_of_line + (num_bytes as usize)
1822                {
1823                    return Err(fidl::Error::InvalidNumBytesInEnvelope);
1824                }
1825                if handles_before != decoder.remaining_handles() + (num_handles as usize) {
1826                    return Err(fidl::Error::InvalidNumHandlesInEnvelope);
1827                }
1828            }
1829
1830            next_offset += envelope_size;
1831            _next_ordinal_to_read += 1;
1832            if next_offset >= end_offset {
1833                return Ok(());
1834            }
1835
1836            // Decode unknown envelopes for gaps in ordinals.
1837            while _next_ordinal_to_read < 2 {
1838                fidl::encoding::decode_unknown_envelope(decoder, next_offset, depth)?;
1839                _next_ordinal_to_read += 1;
1840                next_offset += envelope_size;
1841            }
1842
1843            let next_out_of_line = decoder.next_out_of_line();
1844            let handles_before = decoder.remaining_handles();
1845            if let Some((inlined, num_bytes, num_handles)) =
1846                fidl::encoding::decode_envelope_header(decoder, next_offset)?
1847            {
1848                let member_inline_size =
1849                    <Format as fidl::encoding::TypeMarker>::inline_size(decoder.context);
1850                if inlined != (member_inline_size <= 4) {
1851                    return Err(fidl::Error::InvalidInlineBitInEnvelope);
1852                }
1853                let inner_offset;
1854                let mut inner_depth = depth.clone();
1855                if inlined {
1856                    decoder.check_inline_envelope_padding(next_offset, member_inline_size)?;
1857                    inner_offset = next_offset;
1858                } else {
1859                    inner_offset = decoder.out_of_line_offset(member_inline_size)?;
1860                    inner_depth.increment()?;
1861                }
1862                let val_ref = self.format.get_or_insert_with(|| {
1863                    fidl::new_empty!(Format, fdomain_client::fidl::FDomainResourceDialect)
1864                });
1865                fidl::decode!(
1866                    Format,
1867                    fdomain_client::fidl::FDomainResourceDialect,
1868                    val_ref,
1869                    decoder,
1870                    inner_offset,
1871                    inner_depth
1872                )?;
1873                if !inlined && decoder.next_out_of_line() != next_out_of_line + (num_bytes as usize)
1874                {
1875                    return Err(fidl::Error::InvalidNumBytesInEnvelope);
1876                }
1877                if handles_before != decoder.remaining_handles() + (num_handles as usize) {
1878                    return Err(fidl::Error::InvalidNumHandlesInEnvelope);
1879                }
1880            }
1881
1882            next_offset += envelope_size;
1883            _next_ordinal_to_read += 1;
1884            if next_offset >= end_offset {
1885                return Ok(());
1886            }
1887
1888            // Decode unknown envelopes for gaps in ordinals.
1889            while _next_ordinal_to_read < 3 {
1890                fidl::encoding::decode_unknown_envelope(decoder, next_offset, depth)?;
1891                _next_ordinal_to_read += 1;
1892                next_offset += envelope_size;
1893            }
1894
1895            let next_out_of_line = decoder.next_out_of_line();
1896            let handles_before = decoder.remaining_handles();
1897            if let Some((inlined, num_bytes, num_handles)) =
1898                fidl::encoding::decode_envelope_header(decoder, next_offset)?
1899            {
1900                let member_inline_size =
1901                    <u64 as fidl::encoding::TypeMarker>::inline_size(decoder.context);
1902                if inlined != (member_inline_size <= 4) {
1903                    return Err(fidl::Error::InvalidInlineBitInEnvelope);
1904                }
1905                let inner_offset;
1906                let mut inner_depth = depth.clone();
1907                if inlined {
1908                    decoder.check_inline_envelope_padding(next_offset, member_inline_size)?;
1909                    inner_offset = next_offset;
1910                } else {
1911                    inner_offset = decoder.out_of_line_offset(member_inline_size)?;
1912                    inner_depth.increment()?;
1913                }
1914                let val_ref = self.producer_bytes.get_or_insert_with(|| {
1915                    fidl::new_empty!(u64, fdomain_client::fidl::FDomainResourceDialect)
1916                });
1917                fidl::decode!(
1918                    u64,
1919                    fdomain_client::fidl::FDomainResourceDialect,
1920                    val_ref,
1921                    decoder,
1922                    inner_offset,
1923                    inner_depth
1924                )?;
1925                if !inlined && decoder.next_out_of_line() != next_out_of_line + (num_bytes as usize)
1926                {
1927                    return Err(fidl::Error::InvalidNumBytesInEnvelope);
1928                }
1929                if handles_before != decoder.remaining_handles() + (num_handles as usize) {
1930                    return Err(fidl::Error::InvalidNumHandlesInEnvelope);
1931                }
1932            }
1933
1934            next_offset += envelope_size;
1935            _next_ordinal_to_read += 1;
1936            if next_offset >= end_offset {
1937                return Ok(());
1938            }
1939
1940            // Decode unknown envelopes for gaps in ordinals.
1941            while _next_ordinal_to_read < 4 {
1942                fidl::encoding::decode_unknown_envelope(decoder, next_offset, depth)?;
1943                _next_ordinal_to_read += 1;
1944                next_offset += envelope_size;
1945            }
1946
1947            let next_out_of_line = decoder.next_out_of_line();
1948            let handles_before = decoder.remaining_handles();
1949            if let Some((inlined, num_bytes, num_handles)) =
1950                fidl::encoding::decode_envelope_header(decoder, next_offset)?
1951            {
1952                let member_inline_size =
1953                    <u64 as fidl::encoding::TypeMarker>::inline_size(decoder.context);
1954                if inlined != (member_inline_size <= 4) {
1955                    return Err(fidl::Error::InvalidInlineBitInEnvelope);
1956                }
1957                let inner_offset;
1958                let mut inner_depth = depth.clone();
1959                if inlined {
1960                    decoder.check_inline_envelope_padding(next_offset, member_inline_size)?;
1961                    inner_offset = next_offset;
1962                } else {
1963                    inner_offset = decoder.out_of_line_offset(member_inline_size)?;
1964                    inner_depth.increment()?;
1965                }
1966                let val_ref = self.consumer_bytes.get_or_insert_with(|| {
1967                    fidl::new_empty!(u64, fdomain_client::fidl::FDomainResourceDialect)
1968                });
1969                fidl::decode!(
1970                    u64,
1971                    fdomain_client::fidl::FDomainResourceDialect,
1972                    val_ref,
1973                    decoder,
1974                    inner_offset,
1975                    inner_depth
1976                )?;
1977                if !inlined && decoder.next_out_of_line() != next_out_of_line + (num_bytes as usize)
1978                {
1979                    return Err(fidl::Error::InvalidNumBytesInEnvelope);
1980                }
1981                if handles_before != decoder.remaining_handles() + (num_handles as usize) {
1982                    return Err(fidl::Error::InvalidNumHandlesInEnvelope);
1983                }
1984            }
1985
1986            next_offset += envelope_size;
1987            _next_ordinal_to_read += 1;
1988            if next_offset >= end_offset {
1989                return Ok(());
1990            }
1991
1992            // Decode unknown envelopes for gaps in ordinals.
1993            while _next_ordinal_to_read < 5 {
1994                fidl::encoding::decode_unknown_envelope(decoder, next_offset, depth)?;
1995                _next_ordinal_to_read += 1;
1996                next_offset += envelope_size;
1997            }
1998
1999            let next_out_of_line = decoder.next_out_of_line();
2000            let handles_before = decoder.remaining_handles();
2001            if let Some((inlined, num_bytes, num_handles)) =
2002                fidl::encoding::decode_envelope_header(decoder, next_offset)?
2003            {
2004                let member_inline_size = <fidl::encoding::HandleType<
2005                    fdomain_client::Clock,
2006                    { fidl::ObjectType::CLOCK.into_raw() },
2007                    2147483648,
2008                > as fidl::encoding::TypeMarker>::inline_size(
2009                    decoder.context
2010                );
2011                if inlined != (member_inline_size <= 4) {
2012                    return Err(fidl::Error::InvalidInlineBitInEnvelope);
2013                }
2014                let inner_offset;
2015                let mut inner_depth = depth.clone();
2016                if inlined {
2017                    decoder.check_inline_envelope_padding(next_offset, member_inline_size)?;
2018                    inner_offset = next_offset;
2019                } else {
2020                    inner_offset = decoder.out_of_line_offset(member_inline_size)?;
2021                    inner_depth.increment()?;
2022                }
2023                let val_ref =
2024                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));
2025                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)?;
2026                if !inlined && decoder.next_out_of_line() != next_out_of_line + (num_bytes as usize)
2027                {
2028                    return Err(fidl::Error::InvalidNumBytesInEnvelope);
2029                }
2030                if handles_before != decoder.remaining_handles() + (num_handles as usize) {
2031                    return Err(fidl::Error::InvalidNumHandlesInEnvelope);
2032                }
2033            }
2034
2035            next_offset += envelope_size;
2036            _next_ordinal_to_read += 1;
2037            if next_offset >= end_offset {
2038                return Ok(());
2039            }
2040
2041            // Decode unknown envelopes for gaps in ordinals.
2042            while _next_ordinal_to_read < 6 {
2043                fidl::encoding::decode_unknown_envelope(decoder, next_offset, depth)?;
2044                _next_ordinal_to_read += 1;
2045                next_offset += envelope_size;
2046            }
2047
2048            let next_out_of_line = decoder.next_out_of_line();
2049            let handles_before = decoder.remaining_handles();
2050            if let Some((inlined, num_bytes, num_handles)) =
2051                fidl::encoding::decode_envelope_header(decoder, next_offset)?
2052            {
2053                let member_inline_size =
2054                    <u32 as fidl::encoding::TypeMarker>::inline_size(decoder.context);
2055                if inlined != (member_inline_size <= 4) {
2056                    return Err(fidl::Error::InvalidInlineBitInEnvelope);
2057                }
2058                let inner_offset;
2059                let mut inner_depth = depth.clone();
2060                if inlined {
2061                    decoder.check_inline_envelope_padding(next_offset, member_inline_size)?;
2062                    inner_offset = next_offset;
2063                } else {
2064                    inner_offset = decoder.out_of_line_offset(member_inline_size)?;
2065                    inner_depth.increment()?;
2066                }
2067                let val_ref = self.reference_clock_domain.get_or_insert_with(|| {
2068                    fidl::new_empty!(u32, fdomain_client::fidl::FDomainResourceDialect)
2069                });
2070                fidl::decode!(
2071                    u32,
2072                    fdomain_client::fidl::FDomainResourceDialect,
2073                    val_ref,
2074                    decoder,
2075                    inner_offset,
2076                    inner_depth
2077                )?;
2078                if !inlined && decoder.next_out_of_line() != next_out_of_line + (num_bytes as usize)
2079                {
2080                    return Err(fidl::Error::InvalidNumBytesInEnvelope);
2081                }
2082                if handles_before != decoder.remaining_handles() + (num_handles as usize) {
2083                    return Err(fidl::Error::InvalidNumHandlesInEnvelope);
2084                }
2085            }
2086
2087            next_offset += envelope_size;
2088
2089            // Decode the remaining unknown envelopes.
2090            while next_offset < end_offset {
2091                _next_ordinal_to_read += 1;
2092                fidl::encoding::decode_unknown_envelope(decoder, next_offset, depth)?;
2093                next_offset += envelope_size;
2094            }
2095
2096            Ok(())
2097        }
2098    }
2099
2100    impl StreamSinkPutPacketRequest {
2101        #[inline(always)]
2102        fn max_ordinal_present(&self) -> u64 {
2103            if let Some(_) = self.release_fence {
2104                return 2;
2105            }
2106            if let Some(_) = self.packet {
2107                return 1;
2108            }
2109            0
2110        }
2111    }
2112
2113    impl fidl::encoding::ResourceTypeMarker for StreamSinkPutPacketRequest {
2114        type Borrowed<'a> = &'a mut Self;
2115        fn take_or_borrow<'a>(
2116            value: &'a mut <Self as fidl::encoding::TypeMarker>::Owned,
2117        ) -> Self::Borrowed<'a> {
2118            value
2119        }
2120    }
2121
2122    unsafe impl fidl::encoding::TypeMarker for StreamSinkPutPacketRequest {
2123        type Owned = Self;
2124
2125        #[inline(always)]
2126        fn inline_align(_context: fidl::encoding::Context) -> usize {
2127            8
2128        }
2129
2130        #[inline(always)]
2131        fn inline_size(_context: fidl::encoding::Context) -> usize {
2132            16
2133        }
2134    }
2135
2136    unsafe impl
2137        fidl::encoding::Encode<
2138            StreamSinkPutPacketRequest,
2139            fdomain_client::fidl::FDomainResourceDialect,
2140        > for &mut StreamSinkPutPacketRequest
2141    {
2142        unsafe fn encode(
2143            self,
2144            encoder: &mut fidl::encoding::Encoder<'_, fdomain_client::fidl::FDomainResourceDialect>,
2145            offset: usize,
2146            mut depth: fidl::encoding::Depth,
2147        ) -> fidl::Result<()> {
2148            encoder.debug_check_bounds::<StreamSinkPutPacketRequest>(offset);
2149            // Vector header
2150            let max_ordinal: u64 = self.max_ordinal_present();
2151            encoder.write_num(max_ordinal, offset);
2152            encoder.write_num(fidl::encoding::ALLOC_PRESENT_U64, offset + 8);
2153            // Calling encoder.out_of_line_offset(0) is not allowed.
2154            if max_ordinal == 0 {
2155                return Ok(());
2156            }
2157            depth.increment()?;
2158            let envelope_size = 8;
2159            let bytes_len = max_ordinal as usize * envelope_size;
2160            #[allow(unused_variables)]
2161            let offset = encoder.out_of_line_offset(bytes_len);
2162            let mut _prev_end_offset: usize = 0;
2163            if 1 > max_ordinal {
2164                return Ok(());
2165            }
2166
2167            // Write at offset+(ordinal-1)*envelope_size, since ordinals are one-based and envelopes
2168            // are envelope_size bytes.
2169            let cur_offset: usize = (1 - 1) * envelope_size;
2170
2171            // Zero reserved fields.
2172            encoder.padding(offset + _prev_end_offset, cur_offset - _prev_end_offset);
2173
2174            // Safety:
2175            // - bytes_len is calculated to fit envelope_size*max(member.ordinal).
2176            // - Since cur_offset is envelope_size*(member.ordinal - 1) and the envelope takes
2177            //   envelope_size bytes, there is always sufficient room.
2178            fidl::encoding::encode_in_envelope_optional::<
2179                Packet,
2180                fdomain_client::fidl::FDomainResourceDialect,
2181            >(
2182                self.packet.as_ref().map(<Packet as fidl::encoding::ValueTypeMarker>::borrow),
2183                encoder,
2184                offset + cur_offset,
2185                depth,
2186            )?;
2187
2188            _prev_end_offset = cur_offset + envelope_size;
2189            if 2 > max_ordinal {
2190                return Ok(());
2191            }
2192
2193            // Write at offset+(ordinal-1)*envelope_size, since ordinals are one-based and envelopes
2194            // are envelope_size bytes.
2195            let cur_offset: usize = (2 - 1) * envelope_size;
2196
2197            // Zero reserved fields.
2198            encoder.padding(offset + _prev_end_offset, cur_offset - _prev_end_offset);
2199
2200            // Safety:
2201            // - bytes_len is calculated to fit envelope_size*max(member.ordinal).
2202            // - Since cur_offset is envelope_size*(member.ordinal - 1) and the envelope takes
2203            //   envelope_size bytes, there is always sufficient room.
2204            fidl::encoding::encode_in_envelope_optional::<
2205                fidl::encoding::HandleType<
2206                    fdomain_client::EventPair,
2207                    { fidl::ObjectType::EVENTPAIR.into_raw() },
2208                    2147483648,
2209                >,
2210                fdomain_client::fidl::FDomainResourceDialect,
2211            >(
2212                self.release_fence.as_mut().map(
2213                    <fidl::encoding::HandleType<
2214                        fdomain_client::EventPair,
2215                        { fidl::ObjectType::EVENTPAIR.into_raw() },
2216                        2147483648,
2217                    > as fidl::encoding::ResourceTypeMarker>::take_or_borrow,
2218                ),
2219                encoder,
2220                offset + cur_offset,
2221                depth,
2222            )?;
2223
2224            _prev_end_offset = cur_offset + envelope_size;
2225
2226            Ok(())
2227        }
2228    }
2229
2230    impl fidl::encoding::Decode<Self, fdomain_client::fidl::FDomainResourceDialect>
2231        for StreamSinkPutPacketRequest
2232    {
2233        #[inline(always)]
2234        fn new_empty() -> Self {
2235            Self::default()
2236        }
2237
2238        unsafe fn decode(
2239            &mut self,
2240            decoder: &mut fidl::encoding::Decoder<'_, fdomain_client::fidl::FDomainResourceDialect>,
2241            offset: usize,
2242            mut depth: fidl::encoding::Depth,
2243        ) -> fidl::Result<()> {
2244            decoder.debug_check_bounds::<Self>(offset);
2245            let len = match fidl::encoding::decode_vector_header(decoder, offset)? {
2246                None => return Err(fidl::Error::NotNullable),
2247                Some(len) => len,
2248            };
2249            // Calling decoder.out_of_line_offset(0) is not allowed.
2250            if len == 0 {
2251                return Ok(());
2252            };
2253            depth.increment()?;
2254            let envelope_size = 8;
2255            let bytes_len = len * envelope_size;
2256            let offset = decoder.out_of_line_offset(bytes_len)?;
2257            // Decode the envelope for each type.
2258            let mut _next_ordinal_to_read = 0;
2259            let mut next_offset = offset;
2260            let end_offset = offset + bytes_len;
2261            _next_ordinal_to_read += 1;
2262            if next_offset >= end_offset {
2263                return Ok(());
2264            }
2265
2266            // Decode unknown envelopes for gaps in ordinals.
2267            while _next_ordinal_to_read < 1 {
2268                fidl::encoding::decode_unknown_envelope(decoder, next_offset, depth)?;
2269                _next_ordinal_to_read += 1;
2270                next_offset += envelope_size;
2271            }
2272
2273            let next_out_of_line = decoder.next_out_of_line();
2274            let handles_before = decoder.remaining_handles();
2275            if let Some((inlined, num_bytes, num_handles)) =
2276                fidl::encoding::decode_envelope_header(decoder, next_offset)?
2277            {
2278                let member_inline_size =
2279                    <Packet as fidl::encoding::TypeMarker>::inline_size(decoder.context);
2280                if inlined != (member_inline_size <= 4) {
2281                    return Err(fidl::Error::InvalidInlineBitInEnvelope);
2282                }
2283                let inner_offset;
2284                let mut inner_depth = depth.clone();
2285                if inlined {
2286                    decoder.check_inline_envelope_padding(next_offset, member_inline_size)?;
2287                    inner_offset = next_offset;
2288                } else {
2289                    inner_offset = decoder.out_of_line_offset(member_inline_size)?;
2290                    inner_depth.increment()?;
2291                }
2292                let val_ref = self.packet.get_or_insert_with(|| {
2293                    fidl::new_empty!(Packet, fdomain_client::fidl::FDomainResourceDialect)
2294                });
2295                fidl::decode!(
2296                    Packet,
2297                    fdomain_client::fidl::FDomainResourceDialect,
2298                    val_ref,
2299                    decoder,
2300                    inner_offset,
2301                    inner_depth
2302                )?;
2303                if !inlined && decoder.next_out_of_line() != next_out_of_line + (num_bytes as usize)
2304                {
2305                    return Err(fidl::Error::InvalidNumBytesInEnvelope);
2306                }
2307                if handles_before != decoder.remaining_handles() + (num_handles as usize) {
2308                    return Err(fidl::Error::InvalidNumHandlesInEnvelope);
2309                }
2310            }
2311
2312            next_offset += envelope_size;
2313            _next_ordinal_to_read += 1;
2314            if next_offset >= end_offset {
2315                return Ok(());
2316            }
2317
2318            // Decode unknown envelopes for gaps in ordinals.
2319            while _next_ordinal_to_read < 2 {
2320                fidl::encoding::decode_unknown_envelope(decoder, next_offset, depth)?;
2321                _next_ordinal_to_read += 1;
2322                next_offset += envelope_size;
2323            }
2324
2325            let next_out_of_line = decoder.next_out_of_line();
2326            let handles_before = decoder.remaining_handles();
2327            if let Some((inlined, num_bytes, num_handles)) =
2328                fidl::encoding::decode_envelope_header(decoder, next_offset)?
2329            {
2330                let member_inline_size = <fidl::encoding::HandleType<
2331                    fdomain_client::EventPair,
2332                    { fidl::ObjectType::EVENTPAIR.into_raw() },
2333                    2147483648,
2334                > as fidl::encoding::TypeMarker>::inline_size(
2335                    decoder.context
2336                );
2337                if inlined != (member_inline_size <= 4) {
2338                    return Err(fidl::Error::InvalidInlineBitInEnvelope);
2339                }
2340                let inner_offset;
2341                let mut inner_depth = depth.clone();
2342                if inlined {
2343                    decoder.check_inline_envelope_padding(next_offset, member_inline_size)?;
2344                    inner_offset = next_offset;
2345                } else {
2346                    inner_offset = decoder.out_of_line_offset(member_inline_size)?;
2347                    inner_depth.increment()?;
2348                }
2349                let val_ref =
2350                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));
2351                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)?;
2352                if !inlined && decoder.next_out_of_line() != next_out_of_line + (num_bytes as usize)
2353                {
2354                    return Err(fidl::Error::InvalidNumBytesInEnvelope);
2355                }
2356                if handles_before != decoder.remaining_handles() + (num_handles as usize) {
2357                    return Err(fidl::Error::InvalidNumHandlesInEnvelope);
2358                }
2359            }
2360
2361            next_offset += envelope_size;
2362
2363            // Decode the remaining unknown envelopes.
2364            while next_offset < end_offset {
2365                _next_ordinal_to_read += 1;
2366                fidl::encoding::decode_unknown_envelope(decoder, next_offset, depth)?;
2367                next_offset += envelope_size;
2368            }
2369
2370            Ok(())
2371        }
2372    }
2373}