fidl_fuchsia_bluetooth_hfp_test_common/
fidl_fuchsia_bluetooth_hfp_test_common.rs1#![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#[derive(Clone, Debug, Default, PartialEq)]
28pub struct ConnectionBehavior {
29 pub autoconnect: Option<bool>,
32 #[doc(hidden)]
33 pub __source_breaking: fidl::marker::SourceBreaking,
34}
35
36impl fidl::Persistable for ConnectionBehavior {}
37
38mod internal {
39 use super::*;
40
41 impl fidl::encoding::ValueTypeMarker for HfpTestBatteryIndicatorRequest {
42 type Borrowed<'a> = &'a Self;
43 fn borrow(value: &<Self as fidl::encoding::TypeMarker>::Owned) -> Self::Borrowed<'_> {
44 value
45 }
46 }
47
48 unsafe impl fidl::encoding::TypeMarker for HfpTestBatteryIndicatorRequest {
49 type Owned = Self;
50
51 #[inline(always)]
52 fn inline_align(_context: fidl::encoding::Context) -> usize {
53 1
54 }
55
56 #[inline(always)]
57 fn inline_size(_context: fidl::encoding::Context) -> usize {
58 1
59 }
60 #[inline(always)]
61 fn encode_is_copy() -> bool {
62 true
63 }
64
65 #[inline(always)]
66 fn decode_is_copy() -> bool {
67 true
68 }
69 }
70
71 unsafe impl<D: fidl::encoding::ResourceDialect>
72 fidl::encoding::Encode<HfpTestBatteryIndicatorRequest, D>
73 for &HfpTestBatteryIndicatorRequest
74 {
75 #[inline]
76 unsafe fn encode(
77 self,
78 encoder: &mut fidl::encoding::Encoder<'_, D>,
79 offset: usize,
80 _depth: fidl::encoding::Depth,
81 ) -> fidl::Result<()> {
82 encoder.debug_check_bounds::<HfpTestBatteryIndicatorRequest>(offset);
83 unsafe {
84 let buf_ptr = encoder.buf.as_mut_ptr().add(offset);
86 (buf_ptr as *mut HfpTestBatteryIndicatorRequest)
87 .write_unaligned((self as *const HfpTestBatteryIndicatorRequest).read());
88 }
91 Ok(())
92 }
93 }
94 unsafe impl<D: fidl::encoding::ResourceDialect, T0: fidl::encoding::Encode<u8, D>>
95 fidl::encoding::Encode<HfpTestBatteryIndicatorRequest, D> for (T0,)
96 {
97 #[inline]
98 unsafe fn encode(
99 self,
100 encoder: &mut fidl::encoding::Encoder<'_, D>,
101 offset: usize,
102 depth: fidl::encoding::Depth,
103 ) -> fidl::Result<()> {
104 encoder.debug_check_bounds::<HfpTestBatteryIndicatorRequest>(offset);
105 self.0.encode(encoder, offset + 0, depth)?;
109 Ok(())
110 }
111 }
112
113 impl<D: fidl::encoding::ResourceDialect> fidl::encoding::Decode<Self, D>
114 for HfpTestBatteryIndicatorRequest
115 {
116 #[inline(always)]
117 fn new_empty() -> Self {
118 Self { level: fidl::new_empty!(u8, D) }
119 }
120
121 #[inline]
122 unsafe fn decode(
123 &mut self,
124 decoder: &mut fidl::encoding::Decoder<'_, D>,
125 offset: usize,
126 _depth: fidl::encoding::Depth,
127 ) -> fidl::Result<()> {
128 decoder.debug_check_bounds::<Self>(offset);
129 let buf_ptr = unsafe { decoder.buf.as_ptr().add(offset) };
130 unsafe {
133 std::ptr::copy_nonoverlapping(buf_ptr, self as *mut Self as *mut u8, 1);
134 }
135 Ok(())
136 }
137 }
138
139 impl fidl::encoding::ValueTypeMarker for HfpTestSetConnectionBehaviorRequest {
140 type Borrowed<'a> = &'a Self;
141 fn borrow(value: &<Self as fidl::encoding::TypeMarker>::Owned) -> Self::Borrowed<'_> {
142 value
143 }
144 }
145
146 unsafe impl fidl::encoding::TypeMarker for HfpTestSetConnectionBehaviorRequest {
147 type Owned = Self;
148
149 #[inline(always)]
150 fn inline_align(_context: fidl::encoding::Context) -> usize {
151 8
152 }
153
154 #[inline(always)]
155 fn inline_size(_context: fidl::encoding::Context) -> usize {
156 16
157 }
158 }
159
160 unsafe impl<D: fidl::encoding::ResourceDialect>
161 fidl::encoding::Encode<HfpTestSetConnectionBehaviorRequest, D>
162 for &HfpTestSetConnectionBehaviorRequest
163 {
164 #[inline]
165 unsafe fn encode(
166 self,
167 encoder: &mut fidl::encoding::Encoder<'_, D>,
168 offset: usize,
169 _depth: fidl::encoding::Depth,
170 ) -> fidl::Result<()> {
171 encoder.debug_check_bounds::<HfpTestSetConnectionBehaviorRequest>(offset);
172 fidl::encoding::Encode::<HfpTestSetConnectionBehaviorRequest, D>::encode(
174 (<ConnectionBehavior as fidl::encoding::ValueTypeMarker>::borrow(&self.behavior),),
175 encoder,
176 offset,
177 _depth,
178 )
179 }
180 }
181 unsafe impl<D: fidl::encoding::ResourceDialect, T0: fidl::encoding::Encode<ConnectionBehavior, D>>
182 fidl::encoding::Encode<HfpTestSetConnectionBehaviorRequest, D> for (T0,)
183 {
184 #[inline]
185 unsafe fn encode(
186 self,
187 encoder: &mut fidl::encoding::Encoder<'_, D>,
188 offset: usize,
189 depth: fidl::encoding::Depth,
190 ) -> fidl::Result<()> {
191 encoder.debug_check_bounds::<HfpTestSetConnectionBehaviorRequest>(offset);
192 self.0.encode(encoder, offset + 0, depth)?;
196 Ok(())
197 }
198 }
199
200 impl<D: fidl::encoding::ResourceDialect> fidl::encoding::Decode<Self, D>
201 for HfpTestSetConnectionBehaviorRequest
202 {
203 #[inline(always)]
204 fn new_empty() -> Self {
205 Self { behavior: fidl::new_empty!(ConnectionBehavior, D) }
206 }
207
208 #[inline]
209 unsafe fn decode(
210 &mut self,
211 decoder: &mut fidl::encoding::Decoder<'_, D>,
212 offset: usize,
213 _depth: fidl::encoding::Depth,
214 ) -> fidl::Result<()> {
215 decoder.debug_check_bounds::<Self>(offset);
216 fidl::decode!(ConnectionBehavior, D, &mut self.behavior, decoder, offset + 0, _depth)?;
218 Ok(())
219 }
220 }
221
222 impl ConnectionBehavior {
223 #[inline(always)]
224 fn max_ordinal_present(&self) -> u64 {
225 if let Some(_) = self.autoconnect {
226 return 1;
227 }
228 0
229 }
230 }
231
232 impl fidl::encoding::ValueTypeMarker for ConnectionBehavior {
233 type Borrowed<'a> = &'a Self;
234 fn borrow(value: &<Self as fidl::encoding::TypeMarker>::Owned) -> Self::Borrowed<'_> {
235 value
236 }
237 }
238
239 unsafe impl fidl::encoding::TypeMarker for ConnectionBehavior {
240 type Owned = Self;
241
242 #[inline(always)]
243 fn inline_align(_context: fidl::encoding::Context) -> usize {
244 8
245 }
246
247 #[inline(always)]
248 fn inline_size(_context: fidl::encoding::Context) -> usize {
249 16
250 }
251 }
252
253 unsafe impl<D: fidl::encoding::ResourceDialect> fidl::encoding::Encode<ConnectionBehavior, D>
254 for &ConnectionBehavior
255 {
256 unsafe fn encode(
257 self,
258 encoder: &mut fidl::encoding::Encoder<'_, D>,
259 offset: usize,
260 mut depth: fidl::encoding::Depth,
261 ) -> fidl::Result<()> {
262 encoder.debug_check_bounds::<ConnectionBehavior>(offset);
263 let max_ordinal: u64 = self.max_ordinal_present();
265 encoder.write_num(max_ordinal, offset);
266 encoder.write_num(fidl::encoding::ALLOC_PRESENT_U64, offset + 8);
267 if max_ordinal == 0 {
269 return Ok(());
270 }
271 depth.increment()?;
272 let envelope_size = 8;
273 let bytes_len = max_ordinal as usize * envelope_size;
274 #[allow(unused_variables)]
275 let offset = encoder.out_of_line_offset(bytes_len);
276 let mut _prev_end_offset: usize = 0;
277 if 1 > max_ordinal {
278 return Ok(());
279 }
280
281 let cur_offset: usize = (1 - 1) * envelope_size;
284
285 encoder.padding(offset + _prev_end_offset, cur_offset - _prev_end_offset);
287
288 fidl::encoding::encode_in_envelope_optional::<bool, D>(
293 self.autoconnect.as_ref().map(<bool as fidl::encoding::ValueTypeMarker>::borrow),
294 encoder,
295 offset + cur_offset,
296 depth,
297 )?;
298
299 _prev_end_offset = cur_offset + envelope_size;
300
301 Ok(())
302 }
303 }
304
305 impl<D: fidl::encoding::ResourceDialect> fidl::encoding::Decode<Self, D> for ConnectionBehavior {
306 #[inline(always)]
307 fn new_empty() -> Self {
308 Self::default()
309 }
310
311 unsafe fn decode(
312 &mut self,
313 decoder: &mut fidl::encoding::Decoder<'_, D>,
314 offset: usize,
315 mut depth: fidl::encoding::Depth,
316 ) -> fidl::Result<()> {
317 decoder.debug_check_bounds::<Self>(offset);
318 let len = match fidl::encoding::decode_vector_header(decoder, offset)? {
319 None => return Err(fidl::Error::NotNullable),
320 Some(len) => len,
321 };
322 if len == 0 {
324 return Ok(());
325 };
326 depth.increment()?;
327 let envelope_size = 8;
328 let bytes_len = len * envelope_size;
329 let offset = decoder.out_of_line_offset(bytes_len)?;
330 let mut _next_ordinal_to_read = 0;
332 let mut next_offset = offset;
333 let end_offset = offset + bytes_len;
334 _next_ordinal_to_read += 1;
335 if next_offset >= end_offset {
336 return Ok(());
337 }
338
339 while _next_ordinal_to_read < 1 {
341 fidl::encoding::decode_unknown_envelope(decoder, next_offset, depth)?;
342 _next_ordinal_to_read += 1;
343 next_offset += envelope_size;
344 }
345
346 let next_out_of_line = decoder.next_out_of_line();
347 let handles_before = decoder.remaining_handles();
348 if let Some((inlined, num_bytes, num_handles)) =
349 fidl::encoding::decode_envelope_header(decoder, next_offset)?
350 {
351 let member_inline_size =
352 <bool as fidl::encoding::TypeMarker>::inline_size(decoder.context);
353 if inlined != (member_inline_size <= 4) {
354 return Err(fidl::Error::InvalidInlineBitInEnvelope);
355 }
356 let inner_offset;
357 let mut inner_depth = depth.clone();
358 if inlined {
359 decoder.check_inline_envelope_padding(next_offset, member_inline_size)?;
360 inner_offset = next_offset;
361 } else {
362 inner_offset = decoder.out_of_line_offset(member_inline_size)?;
363 inner_depth.increment()?;
364 }
365 let val_ref = self.autoconnect.get_or_insert_with(|| fidl::new_empty!(bool, D));
366 fidl::decode!(bool, D, val_ref, decoder, inner_offset, inner_depth)?;
367 if !inlined && decoder.next_out_of_line() != next_out_of_line + (num_bytes as usize)
368 {
369 return Err(fidl::Error::InvalidNumBytesInEnvelope);
370 }
371 if handles_before != decoder.remaining_handles() + (num_handles as usize) {
372 return Err(fidl::Error::InvalidNumHandlesInEnvelope);
373 }
374 }
375
376 next_offset += envelope_size;
377
378 while next_offset < end_offset {
380 _next_ordinal_to_read += 1;
381 fidl::encoding::decode_unknown_envelope(decoder, next_offset, depth)?;
382 next_offset += envelope_size;
383 }
384
385 Ok(())
386 }
387 }
388}