fidl_fuchsia_bluetooth_rfcomm_test__common/
fidl_fuchsia_bluetooth_rfcomm_test__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/// The status of the line.
12///
13/// These are defined in GSM 07.10 Section 5.4.6.3.10.
14#[derive(Copy, Clone, Debug, Eq, PartialEq, Ord, PartialOrd, Hash)]
15#[repr(u32)]
16pub enum Status {
17    Ok = 0,
18    OverrunError = 1,
19    ParityError = 2,
20    FramingError = 3,
21}
22
23impl Status {
24    #[inline]
25    pub fn from_primitive(prim: u32) -> Option<Self> {
26        match prim {
27            0 => Some(Self::Ok),
28            1 => Some(Self::OverrunError),
29            2 => Some(Self::ParityError),
30            3 => Some(Self::FramingError),
31            _ => None,
32        }
33    }
34
35    #[inline]
36    pub const fn into_primitive(self) -> u32 {
37        self as u32
38    }
39}
40
41#[derive(Clone, Debug, PartialEq)]
42pub struct RfcommTestDisconnectRequest {
43    pub id: fidl_fuchsia_bluetooth__common::PeerId,
44}
45
46impl fidl::Persistable for RfcommTestDisconnectRequest {}
47
48#[derive(Clone, Debug, PartialEq)]
49pub struct RfcommTestRemoteLineStatusRequest {
50    pub id: fidl_fuchsia_bluetooth__common::PeerId,
51    pub channel_number: u8,
52    pub status: Status,
53}
54
55impl fidl::Persistable for RfcommTestRemoteLineStatusRequest {}
56
57mod internal {
58    use super::*;
59    unsafe impl fidl::encoding::TypeMarker for Status {
60        type Owned = Self;
61
62        #[inline(always)]
63        fn inline_align(_context: fidl::encoding::Context) -> usize {
64            std::mem::align_of::<u32>()
65        }
66
67        #[inline(always)]
68        fn inline_size(_context: fidl::encoding::Context) -> usize {
69            std::mem::size_of::<u32>()
70        }
71
72        #[inline(always)]
73        fn encode_is_copy() -> bool {
74            true
75        }
76
77        #[inline(always)]
78        fn decode_is_copy() -> bool {
79            false
80        }
81    }
82
83    impl fidl::encoding::ValueTypeMarker for Status {
84        type Borrowed<'a> = Self;
85        #[inline(always)]
86        fn borrow(value: &<Self as fidl::encoding::TypeMarker>::Owned) -> Self::Borrowed<'_> {
87            *value
88        }
89    }
90
91    unsafe impl<D: fidl::encoding::ResourceDialect> fidl::encoding::Encode<Self, D> for Status {
92        #[inline]
93        unsafe fn encode(
94            self,
95            encoder: &mut fidl::encoding::Encoder<'_, D>,
96            offset: usize,
97            _depth: fidl::encoding::Depth,
98        ) -> fidl::Result<()> {
99            encoder.debug_check_bounds::<Self>(offset);
100            encoder.write_num(self.into_primitive(), offset);
101            Ok(())
102        }
103    }
104
105    impl<D: fidl::encoding::ResourceDialect> fidl::encoding::Decode<Self, D> for Status {
106        #[inline(always)]
107        fn new_empty() -> Self {
108            Self::Ok
109        }
110
111        #[inline]
112        unsafe fn decode(
113            &mut self,
114            decoder: &mut fidl::encoding::Decoder<'_, D>,
115            offset: usize,
116            _depth: fidl::encoding::Depth,
117        ) -> fidl::Result<()> {
118            decoder.debug_check_bounds::<Self>(offset);
119            let prim = decoder.read_num::<u32>(offset);
120
121            *self = Self::from_primitive(prim).ok_or(fidl::Error::InvalidEnumValue)?;
122            Ok(())
123        }
124    }
125
126    impl fidl::encoding::ValueTypeMarker for RfcommTestDisconnectRequest {
127        type Borrowed<'a> = &'a Self;
128        fn borrow(value: &<Self as fidl::encoding::TypeMarker>::Owned) -> Self::Borrowed<'_> {
129            value
130        }
131    }
132
133    unsafe impl fidl::encoding::TypeMarker for RfcommTestDisconnectRequest {
134        type Owned = Self;
135
136        #[inline(always)]
137        fn inline_align(_context: fidl::encoding::Context) -> usize {
138            8
139        }
140
141        #[inline(always)]
142        fn inline_size(_context: fidl::encoding::Context) -> usize {
143            8
144        }
145    }
146
147    unsafe impl<D: fidl::encoding::ResourceDialect>
148        fidl::encoding::Encode<RfcommTestDisconnectRequest, D> for &RfcommTestDisconnectRequest
149    {
150        #[inline]
151        unsafe fn encode(
152            self,
153            encoder: &mut fidl::encoding::Encoder<'_, D>,
154            offset: usize,
155            _depth: fidl::encoding::Depth,
156        ) -> fidl::Result<()> {
157            encoder.debug_check_bounds::<RfcommTestDisconnectRequest>(offset);
158            // Delegate to tuple encoding.
159            fidl::encoding::Encode::<RfcommTestDisconnectRequest, D>::encode(
160                (
161                    <fidl_fuchsia_bluetooth__common::PeerId as fidl::encoding::ValueTypeMarker>::borrow(&self.id),
162                ),
163                encoder, offset, _depth
164            )
165        }
166    }
167    unsafe impl<
168            D: fidl::encoding::ResourceDialect,
169            T0: fidl::encoding::Encode<fidl_fuchsia_bluetooth__common::PeerId, D>,
170        > fidl::encoding::Encode<RfcommTestDisconnectRequest, D> for (T0,)
171    {
172        #[inline]
173        unsafe fn encode(
174            self,
175            encoder: &mut fidl::encoding::Encoder<'_, D>,
176            offset: usize,
177            depth: fidl::encoding::Depth,
178        ) -> fidl::Result<()> {
179            encoder.debug_check_bounds::<RfcommTestDisconnectRequest>(offset);
180            // Zero out padding regions. There's no need to apply masks
181            // because the unmasked parts will be overwritten by fields.
182            // Write the fields.
183            self.0.encode(encoder, offset + 0, depth)?;
184            Ok(())
185        }
186    }
187
188    impl<D: fidl::encoding::ResourceDialect> fidl::encoding::Decode<Self, D>
189        for RfcommTestDisconnectRequest
190    {
191        #[inline(always)]
192        fn new_empty() -> Self {
193            Self { id: fidl::new_empty!(fidl_fuchsia_bluetooth__common::PeerId, D) }
194        }
195
196        #[inline]
197        unsafe fn decode(
198            &mut self,
199            decoder: &mut fidl::encoding::Decoder<'_, D>,
200            offset: usize,
201            _depth: fidl::encoding::Depth,
202        ) -> fidl::Result<()> {
203            decoder.debug_check_bounds::<Self>(offset);
204            // Verify that padding bytes are zero.
205            fidl::decode!(
206                fidl_fuchsia_bluetooth__common::PeerId,
207                D,
208                &mut self.id,
209                decoder,
210                offset + 0,
211                _depth
212            )?;
213            Ok(())
214        }
215    }
216
217    impl fidl::encoding::ValueTypeMarker for RfcommTestRemoteLineStatusRequest {
218        type Borrowed<'a> = &'a Self;
219        fn borrow(value: &<Self as fidl::encoding::TypeMarker>::Owned) -> Self::Borrowed<'_> {
220            value
221        }
222    }
223
224    unsafe impl fidl::encoding::TypeMarker for RfcommTestRemoteLineStatusRequest {
225        type Owned = Self;
226
227        #[inline(always)]
228        fn inline_align(_context: fidl::encoding::Context) -> usize {
229            8
230        }
231
232        #[inline(always)]
233        fn inline_size(_context: fidl::encoding::Context) -> usize {
234            16
235        }
236    }
237
238    unsafe impl<D: fidl::encoding::ResourceDialect>
239        fidl::encoding::Encode<RfcommTestRemoteLineStatusRequest, D>
240        for &RfcommTestRemoteLineStatusRequest
241    {
242        #[inline]
243        unsafe fn encode(
244            self,
245            encoder: &mut fidl::encoding::Encoder<'_, D>,
246            offset: usize,
247            _depth: fidl::encoding::Depth,
248        ) -> fidl::Result<()> {
249            encoder.debug_check_bounds::<RfcommTestRemoteLineStatusRequest>(offset);
250            // Delegate to tuple encoding.
251            fidl::encoding::Encode::<RfcommTestRemoteLineStatusRequest, D>::encode(
252                (
253                    <fidl_fuchsia_bluetooth__common::PeerId as fidl::encoding::ValueTypeMarker>::borrow(&self.id),
254                    <u8 as fidl::encoding::ValueTypeMarker>::borrow(&self.channel_number),
255                    <Status as fidl::encoding::ValueTypeMarker>::borrow(&self.status),
256                ),
257                encoder, offset, _depth
258            )
259        }
260    }
261    unsafe impl<
262            D: fidl::encoding::ResourceDialect,
263            T0: fidl::encoding::Encode<fidl_fuchsia_bluetooth__common::PeerId, D>,
264            T1: fidl::encoding::Encode<u8, D>,
265            T2: fidl::encoding::Encode<Status, D>,
266        > fidl::encoding::Encode<RfcommTestRemoteLineStatusRequest, D> for (T0, T1, T2)
267    {
268        #[inline]
269        unsafe fn encode(
270            self,
271            encoder: &mut fidl::encoding::Encoder<'_, D>,
272            offset: usize,
273            depth: fidl::encoding::Depth,
274        ) -> fidl::Result<()> {
275            encoder.debug_check_bounds::<RfcommTestRemoteLineStatusRequest>(offset);
276            // Zero out padding regions. There's no need to apply masks
277            // because the unmasked parts will be overwritten by fields.
278            unsafe {
279                let ptr = encoder.buf.as_mut_ptr().add(offset).offset(8);
280                (ptr as *mut u64).write_unaligned(0);
281            }
282            // Write the fields.
283            self.0.encode(encoder, offset + 0, depth)?;
284            self.1.encode(encoder, offset + 8, depth)?;
285            self.2.encode(encoder, offset + 12, depth)?;
286            Ok(())
287        }
288    }
289
290    impl<D: fidl::encoding::ResourceDialect> fidl::encoding::Decode<Self, D>
291        for RfcommTestRemoteLineStatusRequest
292    {
293        #[inline(always)]
294        fn new_empty() -> Self {
295            Self {
296                id: fidl::new_empty!(fidl_fuchsia_bluetooth__common::PeerId, D),
297                channel_number: fidl::new_empty!(u8, D),
298                status: fidl::new_empty!(Status, D),
299            }
300        }
301
302        #[inline]
303        unsafe fn decode(
304            &mut self,
305            decoder: &mut fidl::encoding::Decoder<'_, D>,
306            offset: usize,
307            _depth: fidl::encoding::Depth,
308        ) -> fidl::Result<()> {
309            decoder.debug_check_bounds::<Self>(offset);
310            // Verify that padding bytes are zero.
311            let ptr = unsafe { decoder.buf.as_ptr().add(offset).offset(8) };
312            let padval = unsafe { (ptr as *const u64).read_unaligned() };
313            let mask = 0xffffff00u64;
314            let maskedval = padval & mask;
315            if maskedval != 0 {
316                return Err(fidl::Error::NonZeroPadding {
317                    padding_start: offset + 8 + ((mask as u64).trailing_zeros() / 8) as usize,
318                });
319            }
320            fidl::decode!(
321                fidl_fuchsia_bluetooth__common::PeerId,
322                D,
323                &mut self.id,
324                decoder,
325                offset + 0,
326                _depth
327            )?;
328            fidl::decode!(u8, D, &mut self.channel_number, decoder, offset + 8, _depth)?;
329            fidl::decode!(Status, D, &mut self.status, decoder, offset + 12, _depth)?;
330            Ok(())
331        }
332    }
333}