Skip to main content

fidl_fuchsia_audio/
fidl_fuchsia_audio.rs

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