fidl_fuchsia_bluetooth_a2dp__common/
fidl_fuchsia_bluetooth_a2dp__common.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::encoding::{MessageBufFor, ProxyChannelBox, ResourceDialect};
8use futures::future::{self, MaybeDone, TryFutureExt};
9use zx_status;
10
11/// Enum corresponding to the A2DP SRC/SNK roles as defined in the
12/// A2DP v1.3.2 profile specification, section 2.2.
13#[derive(Copy, Clone, Debug, Eq, PartialEq, Ord, PartialOrd, Hash)]
14#[repr(u32)]
15pub enum Role {
16    /// Act as a source of digital audio streams, sending audio to peers.
17    Source = 1,
18    /// Act as a sink of digital audio streams and play audio sent from peers.
19    Sink = 2,
20}
21
22impl Role {
23    #[inline]
24    pub fn from_primitive(prim: u32) -> Option<Self> {
25        match prim {
26            1 => Some(Self::Source),
27            2 => Some(Self::Sink),
28            _ => None,
29        }
30    }
31
32    #[inline]
33    pub const fn into_primitive(self) -> u32 {
34        self as u32
35    }
36}
37
38#[derive(Clone, Copy, Debug, Eq, Hash, Ord, PartialEq, PartialOrd)]
39pub struct AudioModeSetRoleRequest {
40    pub role: Role,
41}
42
43impl fidl::Persistable for AudioModeSetRoleRequest {}
44
45mod internal {
46    use super::*;
47    unsafe impl fidl::encoding::TypeMarker for Role {
48        type Owned = Self;
49
50        #[inline(always)]
51        fn inline_align(_context: fidl::encoding::Context) -> usize {
52            std::mem::align_of::<u32>()
53        }
54
55        #[inline(always)]
56        fn inline_size(_context: fidl::encoding::Context) -> usize {
57            std::mem::size_of::<u32>()
58        }
59
60        #[inline(always)]
61        fn encode_is_copy() -> bool {
62            true
63        }
64
65        #[inline(always)]
66        fn decode_is_copy() -> bool {
67            false
68        }
69    }
70
71    impl fidl::encoding::ValueTypeMarker for Role {
72        type Borrowed<'a> = Self;
73        #[inline(always)]
74        fn borrow(value: &<Self as fidl::encoding::TypeMarker>::Owned) -> Self::Borrowed<'_> {
75            *value
76        }
77    }
78
79    unsafe impl<D: fidl::encoding::ResourceDialect> fidl::encoding::Encode<Self, D> for Role {
80        #[inline]
81        unsafe fn encode(
82            self,
83            encoder: &mut fidl::encoding::Encoder<'_, D>,
84            offset: usize,
85            _depth: fidl::encoding::Depth,
86        ) -> fidl::Result<()> {
87            encoder.debug_check_bounds::<Self>(offset);
88            encoder.write_num(self.into_primitive(), offset);
89            Ok(())
90        }
91    }
92
93    impl<D: fidl::encoding::ResourceDialect> fidl::encoding::Decode<Self, D> for Role {
94        #[inline(always)]
95        fn new_empty() -> Self {
96            Self::Source
97        }
98
99        #[inline]
100        unsafe fn decode(
101            &mut self,
102            decoder: &mut fidl::encoding::Decoder<'_, D>,
103            offset: usize,
104            _depth: fidl::encoding::Depth,
105        ) -> fidl::Result<()> {
106            decoder.debug_check_bounds::<Self>(offset);
107            let prim = decoder.read_num::<u32>(offset);
108
109            *self = Self::from_primitive(prim).ok_or(fidl::Error::InvalidEnumValue)?;
110            Ok(())
111        }
112    }
113
114    impl fidl::encoding::ValueTypeMarker for AudioModeSetRoleRequest {
115        type Borrowed<'a> = &'a Self;
116        fn borrow(value: &<Self as fidl::encoding::TypeMarker>::Owned) -> Self::Borrowed<'_> {
117            value
118        }
119    }
120
121    unsafe impl fidl::encoding::TypeMarker for AudioModeSetRoleRequest {
122        type Owned = Self;
123
124        #[inline(always)]
125        fn inline_align(_context: fidl::encoding::Context) -> usize {
126            4
127        }
128
129        #[inline(always)]
130        fn inline_size(_context: fidl::encoding::Context) -> usize {
131            4
132        }
133    }
134
135    unsafe impl<D: fidl::encoding::ResourceDialect>
136        fidl::encoding::Encode<AudioModeSetRoleRequest, D> for &AudioModeSetRoleRequest
137    {
138        #[inline]
139        unsafe fn encode(
140            self,
141            encoder: &mut fidl::encoding::Encoder<'_, D>,
142            offset: usize,
143            _depth: fidl::encoding::Depth,
144        ) -> fidl::Result<()> {
145            encoder.debug_check_bounds::<AudioModeSetRoleRequest>(offset);
146            // Delegate to tuple encoding.
147            fidl::encoding::Encode::<AudioModeSetRoleRequest, D>::encode(
148                (<Role as fidl::encoding::ValueTypeMarker>::borrow(&self.role),),
149                encoder,
150                offset,
151                _depth,
152            )
153        }
154    }
155    unsafe impl<D: fidl::encoding::ResourceDialect, T0: fidl::encoding::Encode<Role, D>>
156        fidl::encoding::Encode<AudioModeSetRoleRequest, D> for (T0,)
157    {
158        #[inline]
159        unsafe fn encode(
160            self,
161            encoder: &mut fidl::encoding::Encoder<'_, D>,
162            offset: usize,
163            depth: fidl::encoding::Depth,
164        ) -> fidl::Result<()> {
165            encoder.debug_check_bounds::<AudioModeSetRoleRequest>(offset);
166            // Zero out padding regions. There's no need to apply masks
167            // because the unmasked parts will be overwritten by fields.
168            // Write the fields.
169            self.0.encode(encoder, offset + 0, depth)?;
170            Ok(())
171        }
172    }
173
174    impl<D: fidl::encoding::ResourceDialect> fidl::encoding::Decode<Self, D>
175        for AudioModeSetRoleRequest
176    {
177        #[inline(always)]
178        fn new_empty() -> Self {
179            Self { role: fidl::new_empty!(Role, D) }
180        }
181
182        #[inline]
183        unsafe fn decode(
184            &mut self,
185            decoder: &mut fidl::encoding::Decoder<'_, D>,
186            offset: usize,
187            _depth: fidl::encoding::Depth,
188        ) -> fidl::Result<()> {
189            decoder.debug_check_bounds::<Self>(offset);
190            // Verify that padding bytes are zero.
191            fidl::decode!(Role, D, &mut self.role, decoder, offset + 0, _depth)?;
192            Ok(())
193        }
194    }
195}