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<D: fidl::encoding::ResourceDialect, T0: fidl::encoding::Encode<ConnectionBehavior, D>>
187        fidl::encoding::Encode<HfpTestSetConnectionBehaviorRequest, D> for (T0,)
188    {
189        #[inline]
190        unsafe fn encode(
191            self,
192            encoder: &mut fidl::encoding::Encoder<'_, D>,
193            offset: usize,
194            depth: fidl::encoding::Depth,
195        ) -> fidl::Result<()> {
196            encoder.debug_check_bounds::<HfpTestSetConnectionBehaviorRequest>(offset);
197            // Zero out padding regions. There's no need to apply masks
198            // because the unmasked parts will be overwritten by fields.
199            // Write the fields.
200            self.0.encode(encoder, offset + 0, depth)?;
201            Ok(())
202        }
203    }
204
205    impl<D: fidl::encoding::ResourceDialect> fidl::encoding::Decode<Self, D>
206        for HfpTestSetConnectionBehaviorRequest
207    {
208        #[inline(always)]
209        fn new_empty() -> Self {
210            Self { behavior: fidl::new_empty!(ConnectionBehavior, D) }
211        }
212
213        #[inline]
214        unsafe fn decode(
215            &mut self,
216            decoder: &mut fidl::encoding::Decoder<'_, D>,
217            offset: usize,
218            _depth: fidl::encoding::Depth,
219        ) -> fidl::Result<()> {
220            decoder.debug_check_bounds::<Self>(offset);
221            // Verify that padding bytes are zero.
222            fidl::decode!(ConnectionBehavior, D, &mut self.behavior, decoder, offset + 0, _depth)?;
223            Ok(())
224        }
225    }
226
227    impl ConnectionBehavior {
228        #[inline(always)]
229        fn max_ordinal_present(&self) -> u64 {
230            if let Some(_) = self.autoconnect {
231                return 1;
232            }
233            0
234        }
235    }
236
237    impl fidl::encoding::ValueTypeMarker for ConnectionBehavior {
238        type Borrowed<'a> = &'a Self;
239        fn borrow(value: &<Self as fidl::encoding::TypeMarker>::Owned) -> Self::Borrowed<'_> {
240            value
241        }
242    }
243
244    unsafe impl fidl::encoding::TypeMarker for ConnectionBehavior {
245        type Owned = Self;
246
247        #[inline(always)]
248        fn inline_align(_context: fidl::encoding::Context) -> usize {
249            8
250        }
251
252        #[inline(always)]
253        fn inline_size(_context: fidl::encoding::Context) -> usize {
254            16
255        }
256    }
257
258    unsafe impl<D: fidl::encoding::ResourceDialect> fidl::encoding::Encode<ConnectionBehavior, D>
259        for &ConnectionBehavior
260    {
261        unsafe fn encode(
262            self,
263            encoder: &mut fidl::encoding::Encoder<'_, D>,
264            offset: usize,
265            mut depth: fidl::encoding::Depth,
266        ) -> fidl::Result<()> {
267            encoder.debug_check_bounds::<ConnectionBehavior>(offset);
268            // Vector header
269            let max_ordinal: u64 = self.max_ordinal_present();
270            encoder.write_num(max_ordinal, offset);
271            encoder.write_num(fidl::encoding::ALLOC_PRESENT_U64, offset + 8);
272            // Calling encoder.out_of_line_offset(0) is not allowed.
273            if max_ordinal == 0 {
274                return Ok(());
275            }
276            depth.increment()?;
277            let envelope_size = 8;
278            let bytes_len = max_ordinal as usize * envelope_size;
279            #[allow(unused_variables)]
280            let offset = encoder.out_of_line_offset(bytes_len);
281            let mut _prev_end_offset: usize = 0;
282            if 1 > max_ordinal {
283                return Ok(());
284            }
285
286            // Write at offset+(ordinal-1)*envelope_size, since ordinals are one-based and envelopes
287            // are envelope_size bytes.
288            let cur_offset: usize = (1 - 1) * envelope_size;
289
290            // Zero reserved fields.
291            encoder.padding(offset + _prev_end_offset, cur_offset - _prev_end_offset);
292
293            // Safety:
294            // - bytes_len is calculated to fit envelope_size*max(member.ordinal).
295            // - Since cur_offset is envelope_size*(member.ordinal - 1) and the envelope takes
296            //   envelope_size bytes, there is always sufficient room.
297            fidl::encoding::encode_in_envelope_optional::<bool, D>(
298                self.autoconnect.as_ref().map(<bool as fidl::encoding::ValueTypeMarker>::borrow),
299                encoder,
300                offset + cur_offset,
301                depth,
302            )?;
303
304            _prev_end_offset = cur_offset + envelope_size;
305
306            Ok(())
307        }
308    }
309
310    impl<D: fidl::encoding::ResourceDialect> fidl::encoding::Decode<Self, D> for ConnectionBehavior {
311        #[inline(always)]
312        fn new_empty() -> Self {
313            Self::default()
314        }
315
316        unsafe fn decode(
317            &mut self,
318            decoder: &mut fidl::encoding::Decoder<'_, D>,
319            offset: usize,
320            mut depth: fidl::encoding::Depth,
321        ) -> fidl::Result<()> {
322            decoder.debug_check_bounds::<Self>(offset);
323            let len = match fidl::encoding::decode_vector_header(decoder, offset)? {
324                None => return Err(fidl::Error::NotNullable),
325                Some(len) => len,
326            };
327            // Calling decoder.out_of_line_offset(0) is not allowed.
328            if len == 0 {
329                return Ok(());
330            };
331            depth.increment()?;
332            let envelope_size = 8;
333            let bytes_len = len * envelope_size;
334            let offset = decoder.out_of_line_offset(bytes_len)?;
335            // Decode the envelope for each type.
336            let mut _next_ordinal_to_read = 0;
337            let mut next_offset = offset;
338            let end_offset = offset + bytes_len;
339            _next_ordinal_to_read += 1;
340            if next_offset >= end_offset {
341                return Ok(());
342            }
343
344            // Decode unknown envelopes for gaps in ordinals.
345            while _next_ordinal_to_read < 1 {
346                fidl::encoding::decode_unknown_envelope(decoder, next_offset, depth)?;
347                _next_ordinal_to_read += 1;
348                next_offset += envelope_size;
349            }
350
351            let next_out_of_line = decoder.next_out_of_line();
352            let handles_before = decoder.remaining_handles();
353            if let Some((inlined, num_bytes, num_handles)) =
354                fidl::encoding::decode_envelope_header(decoder, next_offset)?
355            {
356                let member_inline_size =
357                    <bool as fidl::encoding::TypeMarker>::inline_size(decoder.context);
358                if inlined != (member_inline_size <= 4) {
359                    return Err(fidl::Error::InvalidInlineBitInEnvelope);
360                }
361                let inner_offset;
362                let mut inner_depth = depth.clone();
363                if inlined {
364                    decoder.check_inline_envelope_padding(next_offset, member_inline_size)?;
365                    inner_offset = next_offset;
366                } else {
367                    inner_offset = decoder.out_of_line_offset(member_inline_size)?;
368                    inner_depth.increment()?;
369                }
370                let val_ref = self.autoconnect.get_or_insert_with(|| fidl::new_empty!(bool, D));
371                fidl::decode!(bool, D, val_ref, decoder, inner_offset, inner_depth)?;
372                if !inlined && decoder.next_out_of_line() != next_out_of_line + (num_bytes as usize)
373                {
374                    return Err(fidl::Error::InvalidNumBytesInEnvelope);
375                }
376                if handles_before != decoder.remaining_handles() + (num_handles as usize) {
377                    return Err(fidl::Error::InvalidNumHandlesInEnvelope);
378                }
379            }
380
381            next_offset += envelope_size;
382
383            // Decode the remaining unknown envelopes.
384            while next_offset < end_offset {
385                _next_ordinal_to_read += 1;
386                fidl::encoding::decode_unknown_envelope(decoder, next_offset, depth)?;
387                next_offset += envelope_size;
388            }
389
390            Ok(())
391        }
392    }
393}