fidl_fuchsia_bluetooth_hfp_test__common/
fidl_fuchsia_bluetooth_hfp_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#[derive(Clone, Copy, Debug, Eq, Hash, Ord, PartialEq, PartialOrd)]
12#[repr(C)]
13pub struct HfpTestBatteryIndicatorRequest {
14    pub level: u8,
15}
16
17impl fidl::Persistable for HfpTestBatteryIndicatorRequest {}
18
19#[derive(Clone, Debug, PartialEq)]
20pub struct HfpTestSetConnectionBehaviorRequest {
21    pub behavior: ConnectionBehavior,
22}
23
24impl fidl::Persistable for HfpTestSetConnectionBehaviorRequest {}
25
26/// Configure behavior for connections to remote peers.
27#[derive(Clone, Debug, Default, PartialEq)]
28pub struct ConnectionBehavior {
29    /// When true, HFP will immediately conenct to peers when they are
30    /// discovered. Defaults to true if missing.
31    pub autoconnect: Option<bool>,
32    #[doc(hidden)]
33    pub __source_breaking: fidl::marker::SourceBreaking,
34}
35
36impl fidl::Persistable for ConnectionBehavior {}
37
38pub mod hfp_test_ordinals {
39    pub const BATTERY_INDICATOR: u64 = 0x2e77903bc47766a;
40    pub const SET_CONNECTION_BEHAVIOR: u64 = 0x33ef757527a5bf07;
41}
42
43mod internal {
44    use super::*;
45
46    impl fidl::encoding::ValueTypeMarker for HfpTestBatteryIndicatorRequest {
47        type Borrowed<'a> = &'a Self;
48        fn borrow(value: &<Self as fidl::encoding::TypeMarker>::Owned) -> Self::Borrowed<'_> {
49            value
50        }
51    }
52
53    unsafe impl fidl::encoding::TypeMarker for HfpTestBatteryIndicatorRequest {
54        type Owned = Self;
55
56        #[inline(always)]
57        fn inline_align(_context: fidl::encoding::Context) -> usize {
58            1
59        }
60
61        #[inline(always)]
62        fn inline_size(_context: fidl::encoding::Context) -> usize {
63            1
64        }
65        #[inline(always)]
66        fn encode_is_copy() -> bool {
67            true
68        }
69
70        #[inline(always)]
71        fn decode_is_copy() -> bool {
72            true
73        }
74    }
75
76    unsafe impl<D: fidl::encoding::ResourceDialect>
77        fidl::encoding::Encode<HfpTestBatteryIndicatorRequest, D>
78        for &HfpTestBatteryIndicatorRequest
79    {
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::<HfpTestBatteryIndicatorRequest>(offset);
88            unsafe {
89                // Copy the object into the buffer.
90                let buf_ptr = encoder.buf.as_mut_ptr().add(offset);
91                (buf_ptr as *mut HfpTestBatteryIndicatorRequest)
92                    .write_unaligned((self as *const HfpTestBatteryIndicatorRequest).read());
93                // Zero out padding regions. Unlike `fidl_struct_impl_noncopy!`, this must be
94                // done second because the memcpy will write garbage to these bytes.
95            }
96            Ok(())
97        }
98    }
99    unsafe impl<D: fidl::encoding::ResourceDialect, T0: fidl::encoding::Encode<u8, D>>
100        fidl::encoding::Encode<HfpTestBatteryIndicatorRequest, D> for (T0,)
101    {
102        #[inline]
103        unsafe fn encode(
104            self,
105            encoder: &mut fidl::encoding::Encoder<'_, D>,
106            offset: usize,
107            depth: fidl::encoding::Depth,
108        ) -> fidl::Result<()> {
109            encoder.debug_check_bounds::<HfpTestBatteryIndicatorRequest>(offset);
110            // Zero out padding regions. There's no need to apply masks
111            // because the unmasked parts will be overwritten by fields.
112            // Write the fields.
113            self.0.encode(encoder, offset + 0, depth)?;
114            Ok(())
115        }
116    }
117
118    impl<D: fidl::encoding::ResourceDialect> fidl::encoding::Decode<Self, D>
119        for HfpTestBatteryIndicatorRequest
120    {
121        #[inline(always)]
122        fn new_empty() -> Self {
123            Self { level: fidl::new_empty!(u8, D) }
124        }
125
126        #[inline]
127        unsafe fn decode(
128            &mut self,
129            decoder: &mut fidl::encoding::Decoder<'_, D>,
130            offset: usize,
131            _depth: fidl::encoding::Depth,
132        ) -> fidl::Result<()> {
133            decoder.debug_check_bounds::<Self>(offset);
134            let buf_ptr = unsafe { decoder.buf.as_ptr().add(offset) };
135            // Verify that padding bytes are zero.
136            // Copy from the buffer into the object.
137            unsafe {
138                std::ptr::copy_nonoverlapping(buf_ptr, self as *mut Self as *mut u8, 1);
139            }
140            Ok(())
141        }
142    }
143
144    impl fidl::encoding::ValueTypeMarker for HfpTestSetConnectionBehaviorRequest {
145        type Borrowed<'a> = &'a Self;
146        fn borrow(value: &<Self as fidl::encoding::TypeMarker>::Owned) -> Self::Borrowed<'_> {
147            value
148        }
149    }
150
151    unsafe impl fidl::encoding::TypeMarker for HfpTestSetConnectionBehaviorRequest {
152        type Owned = Self;
153
154        #[inline(always)]
155        fn inline_align(_context: fidl::encoding::Context) -> usize {
156            8
157        }
158
159        #[inline(always)]
160        fn inline_size(_context: fidl::encoding::Context) -> usize {
161            16
162        }
163    }
164
165    unsafe impl<D: fidl::encoding::ResourceDialect>
166        fidl::encoding::Encode<HfpTestSetConnectionBehaviorRequest, D>
167        for &HfpTestSetConnectionBehaviorRequest
168    {
169        #[inline]
170        unsafe fn encode(
171            self,
172            encoder: &mut fidl::encoding::Encoder<'_, D>,
173            offset: usize,
174            _depth: fidl::encoding::Depth,
175        ) -> fidl::Result<()> {
176            encoder.debug_check_bounds::<HfpTestSetConnectionBehaviorRequest>(offset);
177            // Delegate to tuple encoding.
178            fidl::encoding::Encode::<HfpTestSetConnectionBehaviorRequest, D>::encode(
179                (<ConnectionBehavior as fidl::encoding::ValueTypeMarker>::borrow(&self.behavior),),
180                encoder,
181                offset,
182                _depth,
183            )
184        }
185    }
186    unsafe impl<
187        D: fidl::encoding::ResourceDialect,
188        T0: fidl::encoding::Encode<ConnectionBehavior, D>,
189    > fidl::encoding::Encode<HfpTestSetConnectionBehaviorRequest, D> for (T0,)
190    {
191        #[inline]
192        unsafe fn encode(
193            self,
194            encoder: &mut fidl::encoding::Encoder<'_, D>,
195            offset: usize,
196            depth: fidl::encoding::Depth,
197        ) -> fidl::Result<()> {
198            encoder.debug_check_bounds::<HfpTestSetConnectionBehaviorRequest>(offset);
199            // Zero out padding regions. There's no need to apply masks
200            // because the unmasked parts will be overwritten by fields.
201            // Write the fields.
202            self.0.encode(encoder, offset + 0, depth)?;
203            Ok(())
204        }
205    }
206
207    impl<D: fidl::encoding::ResourceDialect> fidl::encoding::Decode<Self, D>
208        for HfpTestSetConnectionBehaviorRequest
209    {
210        #[inline(always)]
211        fn new_empty() -> Self {
212            Self { behavior: fidl::new_empty!(ConnectionBehavior, D) }
213        }
214
215        #[inline]
216        unsafe fn decode(
217            &mut self,
218            decoder: &mut fidl::encoding::Decoder<'_, D>,
219            offset: usize,
220            _depth: fidl::encoding::Depth,
221        ) -> fidl::Result<()> {
222            decoder.debug_check_bounds::<Self>(offset);
223            // Verify that padding bytes are zero.
224            fidl::decode!(ConnectionBehavior, D, &mut self.behavior, decoder, offset + 0, _depth)?;
225            Ok(())
226        }
227    }
228
229    impl ConnectionBehavior {
230        #[inline(always)]
231        fn max_ordinal_present(&self) -> u64 {
232            if let Some(_) = self.autoconnect {
233                return 1;
234            }
235            0
236        }
237    }
238
239    impl fidl::encoding::ValueTypeMarker for ConnectionBehavior {
240        type Borrowed<'a> = &'a Self;
241        fn borrow(value: &<Self as fidl::encoding::TypeMarker>::Owned) -> Self::Borrowed<'_> {
242            value
243        }
244    }
245
246    unsafe impl fidl::encoding::TypeMarker for ConnectionBehavior {
247        type Owned = Self;
248
249        #[inline(always)]
250        fn inline_align(_context: fidl::encoding::Context) -> usize {
251            8
252        }
253
254        #[inline(always)]
255        fn inline_size(_context: fidl::encoding::Context) -> usize {
256            16
257        }
258    }
259
260    unsafe impl<D: fidl::encoding::ResourceDialect> fidl::encoding::Encode<ConnectionBehavior, D>
261        for &ConnectionBehavior
262    {
263        unsafe fn encode(
264            self,
265            encoder: &mut fidl::encoding::Encoder<'_, D>,
266            offset: usize,
267            mut depth: fidl::encoding::Depth,
268        ) -> fidl::Result<()> {
269            encoder.debug_check_bounds::<ConnectionBehavior>(offset);
270            // Vector header
271            let max_ordinal: u64 = self.max_ordinal_present();
272            encoder.write_num(max_ordinal, offset);
273            encoder.write_num(fidl::encoding::ALLOC_PRESENT_U64, offset + 8);
274            // Calling encoder.out_of_line_offset(0) is not allowed.
275            if max_ordinal == 0 {
276                return Ok(());
277            }
278            depth.increment()?;
279            let envelope_size = 8;
280            let bytes_len = max_ordinal as usize * envelope_size;
281            #[allow(unused_variables)]
282            let offset = encoder.out_of_line_offset(bytes_len);
283            let mut _prev_end_offset: usize = 0;
284            if 1 > max_ordinal {
285                return Ok(());
286            }
287
288            // Write at offset+(ordinal-1)*envelope_size, since ordinals are one-based and envelopes
289            // are envelope_size bytes.
290            let cur_offset: usize = (1 - 1) * envelope_size;
291
292            // Zero reserved fields.
293            encoder.padding(offset + _prev_end_offset, cur_offset - _prev_end_offset);
294
295            // Safety:
296            // - bytes_len is calculated to fit envelope_size*max(member.ordinal).
297            // - Since cur_offset is envelope_size*(member.ordinal - 1) and the envelope takes
298            //   envelope_size bytes, there is always sufficient room.
299            fidl::encoding::encode_in_envelope_optional::<bool, D>(
300                self.autoconnect.as_ref().map(<bool as fidl::encoding::ValueTypeMarker>::borrow),
301                encoder,
302                offset + cur_offset,
303                depth,
304            )?;
305
306            _prev_end_offset = cur_offset + envelope_size;
307
308            Ok(())
309        }
310    }
311
312    impl<D: fidl::encoding::ResourceDialect> fidl::encoding::Decode<Self, D> for ConnectionBehavior {
313        #[inline(always)]
314        fn new_empty() -> Self {
315            Self::default()
316        }
317
318        unsafe fn decode(
319            &mut self,
320            decoder: &mut fidl::encoding::Decoder<'_, D>,
321            offset: usize,
322            mut depth: fidl::encoding::Depth,
323        ) -> fidl::Result<()> {
324            decoder.debug_check_bounds::<Self>(offset);
325            let len = match fidl::encoding::decode_vector_header(decoder, offset)? {
326                None => return Err(fidl::Error::NotNullable),
327                Some(len) => len,
328            };
329            // Calling decoder.out_of_line_offset(0) is not allowed.
330            if len == 0 {
331                return Ok(());
332            };
333            depth.increment()?;
334            let envelope_size = 8;
335            let bytes_len = len * envelope_size;
336            let offset = decoder.out_of_line_offset(bytes_len)?;
337            // Decode the envelope for each type.
338            let mut _next_ordinal_to_read = 0;
339            let mut next_offset = offset;
340            let end_offset = offset + bytes_len;
341            _next_ordinal_to_read += 1;
342            if next_offset >= end_offset {
343                return Ok(());
344            }
345
346            // Decode unknown envelopes for gaps in ordinals.
347            while _next_ordinal_to_read < 1 {
348                fidl::encoding::decode_unknown_envelope(decoder, next_offset, depth)?;
349                _next_ordinal_to_read += 1;
350                next_offset += envelope_size;
351            }
352
353            let next_out_of_line = decoder.next_out_of_line();
354            let handles_before = decoder.remaining_handles();
355            if let Some((inlined, num_bytes, num_handles)) =
356                fidl::encoding::decode_envelope_header(decoder, next_offset)?
357            {
358                let member_inline_size =
359                    <bool as fidl::encoding::TypeMarker>::inline_size(decoder.context);
360                if inlined != (member_inline_size <= 4) {
361                    return Err(fidl::Error::InvalidInlineBitInEnvelope);
362                }
363                let inner_offset;
364                let mut inner_depth = depth.clone();
365                if inlined {
366                    decoder.check_inline_envelope_padding(next_offset, member_inline_size)?;
367                    inner_offset = next_offset;
368                } else {
369                    inner_offset = decoder.out_of_line_offset(member_inline_size)?;
370                    inner_depth.increment()?;
371                }
372                let val_ref = self.autoconnect.get_or_insert_with(|| fidl::new_empty!(bool, D));
373                fidl::decode!(bool, D, val_ref, decoder, inner_offset, inner_depth)?;
374                if !inlined && decoder.next_out_of_line() != next_out_of_line + (num_bytes as usize)
375                {
376                    return Err(fidl::Error::InvalidNumBytesInEnvelope);
377                }
378                if handles_before != decoder.remaining_handles() + (num_handles as usize) {
379                    return Err(fidl::Error::InvalidNumHandlesInEnvelope);
380                }
381            }
382
383            next_offset += envelope_size;
384
385            // Decode the remaining unknown envelopes.
386            while next_offset < end_offset {
387                _next_ordinal_to_read += 1;
388                fidl::encoding::decode_unknown_envelope(decoder, next_offset, depth)?;
389                next_offset += envelope_size;
390            }
391
392            Ok(())
393        }
394    }
395}