fidl_fuchsia_audio/
fidl_fuchsia_audio.rs

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