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
45pub mod audio_mode_ordinals {
46    pub const SET_ROLE: u64 = 0x55bc139643a166a6;
47}
48
49mod internal {
50    use super::*;
51    unsafe impl fidl::encoding::TypeMarker for Role {
52        type Owned = Self;
53
54        #[inline(always)]
55        fn inline_align(_context: fidl::encoding::Context) -> usize {
56            std::mem::align_of::<u32>()
57        }
58
59        #[inline(always)]
60        fn inline_size(_context: fidl::encoding::Context) -> usize {
61            std::mem::size_of::<u32>()
62        }
63
64        #[inline(always)]
65        fn encode_is_copy() -> bool {
66            true
67        }
68
69        #[inline(always)]
70        fn decode_is_copy() -> bool {
71            false
72        }
73    }
74
75    impl fidl::encoding::ValueTypeMarker for Role {
76        type Borrowed<'a> = Self;
77        #[inline(always)]
78        fn borrow(value: &<Self as fidl::encoding::TypeMarker>::Owned) -> Self::Borrowed<'_> {
79            *value
80        }
81    }
82
83    unsafe impl<D: fidl::encoding::ResourceDialect> fidl::encoding::Encode<Self, D> for Role {
84        #[inline]
85        unsafe fn encode(
86            self,
87            encoder: &mut fidl::encoding::Encoder<'_, D>,
88            offset: usize,
89            _depth: fidl::encoding::Depth,
90        ) -> fidl::Result<()> {
91            encoder.debug_check_bounds::<Self>(offset);
92            encoder.write_num(self.into_primitive(), offset);
93            Ok(())
94        }
95    }
96
97    impl<D: fidl::encoding::ResourceDialect> fidl::encoding::Decode<Self, D> for Role {
98        #[inline(always)]
99        fn new_empty() -> Self {
100            Self::Source
101        }
102
103        #[inline]
104        unsafe fn decode(
105            &mut self,
106            decoder: &mut fidl::encoding::Decoder<'_, D>,
107            offset: usize,
108            _depth: fidl::encoding::Depth,
109        ) -> fidl::Result<()> {
110            decoder.debug_check_bounds::<Self>(offset);
111            let prim = decoder.read_num::<u32>(offset);
112
113            *self = Self::from_primitive(prim).ok_or(fidl::Error::InvalidEnumValue)?;
114            Ok(())
115        }
116    }
117
118    impl fidl::encoding::ValueTypeMarker for AudioModeSetRoleRequest {
119        type Borrowed<'a> = &'a Self;
120        fn borrow(value: &<Self as fidl::encoding::TypeMarker>::Owned) -> Self::Borrowed<'_> {
121            value
122        }
123    }
124
125    unsafe impl fidl::encoding::TypeMarker for AudioModeSetRoleRequest {
126        type Owned = Self;
127
128        #[inline(always)]
129        fn inline_align(_context: fidl::encoding::Context) -> usize {
130            4
131        }
132
133        #[inline(always)]
134        fn inline_size(_context: fidl::encoding::Context) -> usize {
135            4
136        }
137    }
138
139    unsafe impl<D: fidl::encoding::ResourceDialect>
140        fidl::encoding::Encode<AudioModeSetRoleRequest, D> for &AudioModeSetRoleRequest
141    {
142        #[inline]
143        unsafe fn encode(
144            self,
145            encoder: &mut fidl::encoding::Encoder<'_, D>,
146            offset: usize,
147            _depth: fidl::encoding::Depth,
148        ) -> fidl::Result<()> {
149            encoder.debug_check_bounds::<AudioModeSetRoleRequest>(offset);
150            // Delegate to tuple encoding.
151            fidl::encoding::Encode::<AudioModeSetRoleRequest, D>::encode(
152                (<Role as fidl::encoding::ValueTypeMarker>::borrow(&self.role),),
153                encoder,
154                offset,
155                _depth,
156            )
157        }
158    }
159    unsafe impl<D: fidl::encoding::ResourceDialect, T0: fidl::encoding::Encode<Role, D>>
160        fidl::encoding::Encode<AudioModeSetRoleRequest, D> for (T0,)
161    {
162        #[inline]
163        unsafe fn encode(
164            self,
165            encoder: &mut fidl::encoding::Encoder<'_, D>,
166            offset: usize,
167            depth: fidl::encoding::Depth,
168        ) -> fidl::Result<()> {
169            encoder.debug_check_bounds::<AudioModeSetRoleRequest>(offset);
170            // Zero out padding regions. There's no need to apply masks
171            // because the unmasked parts will be overwritten by fields.
172            // Write the fields.
173            self.0.encode(encoder, offset + 0, depth)?;
174            Ok(())
175        }
176    }
177
178    impl<D: fidl::encoding::ResourceDialect> fidl::encoding::Decode<Self, D>
179        for AudioModeSetRoleRequest
180    {
181        #[inline(always)]
182        fn new_empty() -> Self {
183            Self { role: fidl::new_empty!(Role, D) }
184        }
185
186        #[inline]
187        unsafe fn decode(
188            &mut self,
189            decoder: &mut fidl::encoding::Decoder<'_, D>,
190            offset: usize,
191            _depth: fidl::encoding::Depth,
192        ) -> fidl::Result<()> {
193            decoder.debug_check_bounds::<Self>(offset);
194            // Verify that padding bytes are zero.
195            fidl::decode!(Role, D, &mut self.role, decoder, offset + 0, _depth)?;
196            Ok(())
197        }
198    }
199}