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