1#![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)]
12pub struct LocalDevice;
13
14impl fidl::Persistable for LocalDevice {}
15
16#[derive(Clone, Debug, PartialEq)]
17pub struct WatcherWatchRequest {
18 pub ids: Vec<Identifier>,
19}
20
21impl fidl::Persistable for WatcherWatchRequest {}
22
23#[derive(Clone, Debug, PartialEq)]
24pub struct WatcherWatchResponse {
25 pub peripherals: Vec<Information>,
26}
27
28impl fidl::Persistable for WatcherWatchResponse {}
29
30#[derive(Clone, Debug, Default, PartialEq)]
32pub struct Information {
33 pub identifier: Option<Identifier>,
35 pub battery_info: Option<fidl_fuchsia_power_battery::BatteryInfo>,
42 #[doc(hidden)]
43 pub __source_breaking: fidl::marker::SourceBreaking,
44}
45
46impl fidl::Persistable for Information {}
47
48#[derive(Clone, Debug)]
50pub enum Identifier {
51 LocalDevice(LocalDevice),
52 PeerId(fidl_fuchsia_bluetooth::PeerId),
53 #[doc(hidden)]
54 __SourceBreaking {
55 unknown_ordinal: u64,
56 },
57}
58
59#[macro_export]
61macro_rules! IdentifierUnknown {
62 () => {
63 _
64 };
65}
66
67impl PartialEq for Identifier {
69 fn eq(&self, other: &Self) -> bool {
70 match (self, other) {
71 (Self::LocalDevice(x), Self::LocalDevice(y)) => *x == *y,
72 (Self::PeerId(x), Self::PeerId(y)) => *x == *y,
73 _ => false,
74 }
75 }
76}
77
78impl Identifier {
79 #[inline]
80 pub fn ordinal(&self) -> u64 {
81 match *self {
82 Self::LocalDevice(_) => 1,
83 Self::PeerId(_) => 2,
84 Self::__SourceBreaking { unknown_ordinal } => unknown_ordinal,
85 }
86 }
87
88 #[inline]
89 pub fn unknown_variant_for_testing() -> Self {
90 Self::__SourceBreaking { unknown_ordinal: 0 }
91 }
92
93 #[inline]
94 pub fn is_unknown(&self) -> bool {
95 match self {
96 Self::__SourceBreaking { .. } => true,
97 _ => false,
98 }
99 }
100}
101
102impl fidl::Persistable for Identifier {}
103
104mod internal {
105 use super::*;
106
107 impl fidl::encoding::ValueTypeMarker for LocalDevice {
108 type Borrowed<'a> = &'a Self;
109 fn borrow(value: &<Self as fidl::encoding::TypeMarker>::Owned) -> Self::Borrowed<'_> {
110 value
111 }
112 }
113
114 unsafe impl fidl::encoding::TypeMarker for LocalDevice {
115 type Owned = Self;
116
117 #[inline(always)]
118 fn inline_align(_context: fidl::encoding::Context) -> usize {
119 1
120 }
121
122 #[inline(always)]
123 fn inline_size(_context: fidl::encoding::Context) -> usize {
124 1
125 }
126 }
127
128 unsafe impl<D: fidl::encoding::ResourceDialect> fidl::encoding::Encode<LocalDevice, D>
129 for &LocalDevice
130 {
131 #[inline]
132 unsafe fn encode(
133 self,
134 encoder: &mut fidl::encoding::Encoder<'_, D>,
135 offset: usize,
136 _depth: fidl::encoding::Depth,
137 ) -> fidl::Result<()> {
138 encoder.debug_check_bounds::<LocalDevice>(offset);
139 encoder.write_num(0u8, offset);
140 Ok(())
141 }
142 }
143
144 impl<D: fidl::encoding::ResourceDialect> fidl::encoding::Decode<Self, D> for LocalDevice {
145 #[inline(always)]
146 fn new_empty() -> Self {
147 Self
148 }
149
150 #[inline]
151 unsafe fn decode(
152 &mut self,
153 decoder: &mut fidl::encoding::Decoder<'_, D>,
154 offset: usize,
155 _depth: fidl::encoding::Depth,
156 ) -> fidl::Result<()> {
157 decoder.debug_check_bounds::<Self>(offset);
158 match decoder.read_num::<u8>(offset) {
159 0 => Ok(()),
160 _ => Err(fidl::Error::Invalid),
161 }
162 }
163 }
164
165 impl fidl::encoding::ValueTypeMarker for WatcherWatchRequest {
166 type Borrowed<'a> = &'a Self;
167 fn borrow(value: &<Self as fidl::encoding::TypeMarker>::Owned) -> Self::Borrowed<'_> {
168 value
169 }
170 }
171
172 unsafe impl fidl::encoding::TypeMarker for WatcherWatchRequest {
173 type Owned = Self;
174
175 #[inline(always)]
176 fn inline_align(_context: fidl::encoding::Context) -> usize {
177 8
178 }
179
180 #[inline(always)]
181 fn inline_size(_context: fidl::encoding::Context) -> usize {
182 16
183 }
184 }
185
186 unsafe impl<D: fidl::encoding::ResourceDialect> fidl::encoding::Encode<WatcherWatchRequest, D>
187 for &WatcherWatchRequest
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::<WatcherWatchRequest>(offset);
197 fidl::encoding::Encode::<WatcherWatchRequest, D>::encode(
199 (
200 <fidl::encoding::UnboundedVector<Identifier> as fidl::encoding::ValueTypeMarker>::borrow(&self.ids),
201 ),
202 encoder, offset, _depth
203 )
204 }
205 }
206 unsafe impl<
207 D: fidl::encoding::ResourceDialect,
208 T0: fidl::encoding::Encode<fidl::encoding::UnboundedVector<Identifier>, D>,
209 > fidl::encoding::Encode<WatcherWatchRequest, D> for (T0,)
210 {
211 #[inline]
212 unsafe fn encode(
213 self,
214 encoder: &mut fidl::encoding::Encoder<'_, D>,
215 offset: usize,
216 depth: fidl::encoding::Depth,
217 ) -> fidl::Result<()> {
218 encoder.debug_check_bounds::<WatcherWatchRequest>(offset);
219 self.0.encode(encoder, offset + 0, depth)?;
223 Ok(())
224 }
225 }
226
227 impl<D: fidl::encoding::ResourceDialect> fidl::encoding::Decode<Self, D> for WatcherWatchRequest {
228 #[inline(always)]
229 fn new_empty() -> Self {
230 Self { ids: fidl::new_empty!(fidl::encoding::UnboundedVector<Identifier>, D) }
231 }
232
233 #[inline]
234 unsafe fn decode(
235 &mut self,
236 decoder: &mut fidl::encoding::Decoder<'_, D>,
237 offset: usize,
238 _depth: fidl::encoding::Depth,
239 ) -> fidl::Result<()> {
240 decoder.debug_check_bounds::<Self>(offset);
241 fidl::decode!(
243 fidl::encoding::UnboundedVector<Identifier>,
244 D,
245 &mut self.ids,
246 decoder,
247 offset + 0,
248 _depth
249 )?;
250 Ok(())
251 }
252 }
253
254 impl fidl::encoding::ValueTypeMarker for WatcherWatchResponse {
255 type Borrowed<'a> = &'a Self;
256 fn borrow(value: &<Self as fidl::encoding::TypeMarker>::Owned) -> Self::Borrowed<'_> {
257 value
258 }
259 }
260
261 unsafe impl fidl::encoding::TypeMarker for WatcherWatchResponse {
262 type Owned = Self;
263
264 #[inline(always)]
265 fn inline_align(_context: fidl::encoding::Context) -> usize {
266 8
267 }
268
269 #[inline(always)]
270 fn inline_size(_context: fidl::encoding::Context) -> usize {
271 16
272 }
273 }
274
275 unsafe impl<D: fidl::encoding::ResourceDialect> fidl::encoding::Encode<WatcherWatchResponse, D>
276 for &WatcherWatchResponse
277 {
278 #[inline]
279 unsafe fn encode(
280 self,
281 encoder: &mut fidl::encoding::Encoder<'_, D>,
282 offset: usize,
283 _depth: fidl::encoding::Depth,
284 ) -> fidl::Result<()> {
285 encoder.debug_check_bounds::<WatcherWatchResponse>(offset);
286 fidl::encoding::Encode::<WatcherWatchResponse, D>::encode(
288 (
289 <fidl::encoding::UnboundedVector<Information> as fidl::encoding::ValueTypeMarker>::borrow(&self.peripherals),
290 ),
291 encoder, offset, _depth
292 )
293 }
294 }
295 unsafe impl<
296 D: fidl::encoding::ResourceDialect,
297 T0: fidl::encoding::Encode<fidl::encoding::UnboundedVector<Information>, D>,
298 > fidl::encoding::Encode<WatcherWatchResponse, D> for (T0,)
299 {
300 #[inline]
301 unsafe fn encode(
302 self,
303 encoder: &mut fidl::encoding::Encoder<'_, D>,
304 offset: usize,
305 depth: fidl::encoding::Depth,
306 ) -> fidl::Result<()> {
307 encoder.debug_check_bounds::<WatcherWatchResponse>(offset);
308 self.0.encode(encoder, offset + 0, depth)?;
312 Ok(())
313 }
314 }
315
316 impl<D: fidl::encoding::ResourceDialect> fidl::encoding::Decode<Self, D> for WatcherWatchResponse {
317 #[inline(always)]
318 fn new_empty() -> Self {
319 Self { peripherals: fidl::new_empty!(fidl::encoding::UnboundedVector<Information>, D) }
320 }
321
322 #[inline]
323 unsafe fn decode(
324 &mut self,
325 decoder: &mut fidl::encoding::Decoder<'_, D>,
326 offset: usize,
327 _depth: fidl::encoding::Depth,
328 ) -> fidl::Result<()> {
329 decoder.debug_check_bounds::<Self>(offset);
330 fidl::decode!(
332 fidl::encoding::UnboundedVector<Information>,
333 D,
334 &mut self.peripherals,
335 decoder,
336 offset + 0,
337 _depth
338 )?;
339 Ok(())
340 }
341 }
342
343 impl Information {
344 #[inline(always)]
345 fn max_ordinal_present(&self) -> u64 {
346 if let Some(_) = self.battery_info {
347 return 2;
348 }
349 if let Some(_) = self.identifier {
350 return 1;
351 }
352 0
353 }
354 }
355
356 impl fidl::encoding::ValueTypeMarker for Information {
357 type Borrowed<'a> = &'a Self;
358 fn borrow(value: &<Self as fidl::encoding::TypeMarker>::Owned) -> Self::Borrowed<'_> {
359 value
360 }
361 }
362
363 unsafe impl fidl::encoding::TypeMarker for Information {
364 type Owned = Self;
365
366 #[inline(always)]
367 fn inline_align(_context: fidl::encoding::Context) -> usize {
368 8
369 }
370
371 #[inline(always)]
372 fn inline_size(_context: fidl::encoding::Context) -> usize {
373 16
374 }
375 }
376
377 unsafe impl<D: fidl::encoding::ResourceDialect> fidl::encoding::Encode<Information, D>
378 for &Information
379 {
380 unsafe fn encode(
381 self,
382 encoder: &mut fidl::encoding::Encoder<'_, D>,
383 offset: usize,
384 mut depth: fidl::encoding::Depth,
385 ) -> fidl::Result<()> {
386 encoder.debug_check_bounds::<Information>(offset);
387 let max_ordinal: u64 = self.max_ordinal_present();
389 encoder.write_num(max_ordinal, offset);
390 encoder.write_num(fidl::encoding::ALLOC_PRESENT_U64, offset + 8);
391 if max_ordinal == 0 {
393 return Ok(());
394 }
395 depth.increment()?;
396 let envelope_size = 8;
397 let bytes_len = max_ordinal as usize * envelope_size;
398 #[allow(unused_variables)]
399 let offset = encoder.out_of_line_offset(bytes_len);
400 let mut _prev_end_offset: usize = 0;
401 if 1 > max_ordinal {
402 return Ok(());
403 }
404
405 let cur_offset: usize = (1 - 1) * envelope_size;
408
409 encoder.padding(offset + _prev_end_offset, cur_offset - _prev_end_offset);
411
412 fidl::encoding::encode_in_envelope_optional::<Identifier, D>(
417 self.identifier
418 .as_ref()
419 .map(<Identifier as fidl::encoding::ValueTypeMarker>::borrow),
420 encoder,
421 offset + cur_offset,
422 depth,
423 )?;
424
425 _prev_end_offset = cur_offset + envelope_size;
426 if 2 > max_ordinal {
427 return Ok(());
428 }
429
430 let cur_offset: usize = (2 - 1) * envelope_size;
433
434 encoder.padding(offset + _prev_end_offset, cur_offset - _prev_end_offset);
436
437 fidl::encoding::encode_in_envelope_optional::<fidl_fuchsia_power_battery::BatteryInfo, D>(
442 self.battery_info.as_ref().map(<fidl_fuchsia_power_battery::BatteryInfo as fidl::encoding::ValueTypeMarker>::borrow),
443 encoder, offset + cur_offset, depth
444 )?;
445
446 _prev_end_offset = cur_offset + envelope_size;
447
448 Ok(())
449 }
450 }
451
452 impl<D: fidl::encoding::ResourceDialect> fidl::encoding::Decode<Self, D> for Information {
453 #[inline(always)]
454 fn new_empty() -> Self {
455 Self::default()
456 }
457
458 unsafe fn decode(
459 &mut self,
460 decoder: &mut fidl::encoding::Decoder<'_, D>,
461 offset: usize,
462 mut depth: fidl::encoding::Depth,
463 ) -> fidl::Result<()> {
464 decoder.debug_check_bounds::<Self>(offset);
465 let len = match fidl::encoding::decode_vector_header(decoder, offset)? {
466 None => return Err(fidl::Error::NotNullable),
467 Some(len) => len,
468 };
469 if len == 0 {
471 return Ok(());
472 };
473 depth.increment()?;
474 let envelope_size = 8;
475 let bytes_len = len * envelope_size;
476 let offset = decoder.out_of_line_offset(bytes_len)?;
477 let mut _next_ordinal_to_read = 0;
479 let mut next_offset = offset;
480 let end_offset = offset + bytes_len;
481 _next_ordinal_to_read += 1;
482 if next_offset >= end_offset {
483 return Ok(());
484 }
485
486 while _next_ordinal_to_read < 1 {
488 fidl::encoding::decode_unknown_envelope(decoder, next_offset, depth)?;
489 _next_ordinal_to_read += 1;
490 next_offset += envelope_size;
491 }
492
493 let next_out_of_line = decoder.next_out_of_line();
494 let handles_before = decoder.remaining_handles();
495 if let Some((inlined, num_bytes, num_handles)) =
496 fidl::encoding::decode_envelope_header(decoder, next_offset)?
497 {
498 let member_inline_size =
499 <Identifier as fidl::encoding::TypeMarker>::inline_size(decoder.context);
500 if inlined != (member_inline_size <= 4) {
501 return Err(fidl::Error::InvalidInlineBitInEnvelope);
502 }
503 let inner_offset;
504 let mut inner_depth = depth.clone();
505 if inlined {
506 decoder.check_inline_envelope_padding(next_offset, member_inline_size)?;
507 inner_offset = next_offset;
508 } else {
509 inner_offset = decoder.out_of_line_offset(member_inline_size)?;
510 inner_depth.increment()?;
511 }
512 let val_ref =
513 self.identifier.get_or_insert_with(|| fidl::new_empty!(Identifier, D));
514 fidl::decode!(Identifier, D, val_ref, decoder, inner_offset, inner_depth)?;
515 if !inlined && decoder.next_out_of_line() != next_out_of_line + (num_bytes as usize)
516 {
517 return Err(fidl::Error::InvalidNumBytesInEnvelope);
518 }
519 if handles_before != decoder.remaining_handles() + (num_handles as usize) {
520 return Err(fidl::Error::InvalidNumHandlesInEnvelope);
521 }
522 }
523
524 next_offset += envelope_size;
525 _next_ordinal_to_read += 1;
526 if next_offset >= end_offset {
527 return Ok(());
528 }
529
530 while _next_ordinal_to_read < 2 {
532 fidl::encoding::decode_unknown_envelope(decoder, next_offset, depth)?;
533 _next_ordinal_to_read += 1;
534 next_offset += envelope_size;
535 }
536
537 let next_out_of_line = decoder.next_out_of_line();
538 let handles_before = decoder.remaining_handles();
539 if let Some((inlined, num_bytes, num_handles)) =
540 fidl::encoding::decode_envelope_header(decoder, next_offset)?
541 {
542 let member_inline_size = <fidl_fuchsia_power_battery::BatteryInfo as fidl::encoding::TypeMarker>::inline_size(decoder.context);
543 if inlined != (member_inline_size <= 4) {
544 return Err(fidl::Error::InvalidInlineBitInEnvelope);
545 }
546 let inner_offset;
547 let mut inner_depth = depth.clone();
548 if inlined {
549 decoder.check_inline_envelope_padding(next_offset, member_inline_size)?;
550 inner_offset = next_offset;
551 } else {
552 inner_offset = decoder.out_of_line_offset(member_inline_size)?;
553 inner_depth.increment()?;
554 }
555 let val_ref = self.battery_info.get_or_insert_with(|| {
556 fidl::new_empty!(fidl_fuchsia_power_battery::BatteryInfo, D)
557 });
558 fidl::decode!(
559 fidl_fuchsia_power_battery::BatteryInfo,
560 D,
561 val_ref,
562 decoder,
563 inner_offset,
564 inner_depth
565 )?;
566 if !inlined && decoder.next_out_of_line() != next_out_of_line + (num_bytes as usize)
567 {
568 return Err(fidl::Error::InvalidNumBytesInEnvelope);
569 }
570 if handles_before != decoder.remaining_handles() + (num_handles as usize) {
571 return Err(fidl::Error::InvalidNumHandlesInEnvelope);
572 }
573 }
574
575 next_offset += envelope_size;
576
577 while next_offset < end_offset {
579 _next_ordinal_to_read += 1;
580 fidl::encoding::decode_unknown_envelope(decoder, next_offset, depth)?;
581 next_offset += envelope_size;
582 }
583
584 Ok(())
585 }
586 }
587
588 impl fidl::encoding::ValueTypeMarker for Identifier {
589 type Borrowed<'a> = &'a Self;
590 fn borrow(value: &<Self as fidl::encoding::TypeMarker>::Owned) -> Self::Borrowed<'_> {
591 value
592 }
593 }
594
595 unsafe impl fidl::encoding::TypeMarker for Identifier {
596 type Owned = Self;
597
598 #[inline(always)]
599 fn inline_align(_context: fidl::encoding::Context) -> usize {
600 8
601 }
602
603 #[inline(always)]
604 fn inline_size(_context: fidl::encoding::Context) -> usize {
605 16
606 }
607 }
608
609 unsafe impl<D: fidl::encoding::ResourceDialect> fidl::encoding::Encode<Identifier, D>
610 for &Identifier
611 {
612 #[inline]
613 unsafe fn encode(
614 self,
615 encoder: &mut fidl::encoding::Encoder<'_, D>,
616 offset: usize,
617 _depth: fidl::encoding::Depth,
618 ) -> fidl::Result<()> {
619 encoder.debug_check_bounds::<Identifier>(offset);
620 encoder.write_num::<u64>(self.ordinal(), offset);
621 match self {
622 Identifier::LocalDevice(ref val) => {
623 fidl::encoding::encode_in_envelope::<LocalDevice, D>(
624 <LocalDevice as fidl::encoding::ValueTypeMarker>::borrow(val),
625 encoder,
626 offset + 8,
627 _depth,
628 )
629 }
630 Identifier::PeerId(ref val) => {
631 fidl::encoding::encode_in_envelope::<fidl_fuchsia_bluetooth::PeerId, D>(
632 <fidl_fuchsia_bluetooth::PeerId as fidl::encoding::ValueTypeMarker>::borrow(
633 val,
634 ),
635 encoder,
636 offset + 8,
637 _depth,
638 )
639 }
640 Identifier::__SourceBreaking { .. } => Err(fidl::Error::UnknownUnionTag),
641 }
642 }
643 }
644
645 impl<D: fidl::encoding::ResourceDialect> fidl::encoding::Decode<Self, D> for Identifier {
646 #[inline(always)]
647 fn new_empty() -> Self {
648 Self::__SourceBreaking { unknown_ordinal: 0 }
649 }
650
651 #[inline]
652 unsafe fn decode(
653 &mut self,
654 decoder: &mut fidl::encoding::Decoder<'_, D>,
655 offset: usize,
656 mut depth: fidl::encoding::Depth,
657 ) -> fidl::Result<()> {
658 decoder.debug_check_bounds::<Self>(offset);
659 #[allow(unused_variables)]
660 let next_out_of_line = decoder.next_out_of_line();
661 let handles_before = decoder.remaining_handles();
662 let (ordinal, inlined, num_bytes, num_handles) =
663 fidl::encoding::decode_union_inline_portion(decoder, offset)?;
664
665 let member_inline_size = match ordinal {
666 1 => <LocalDevice as fidl::encoding::TypeMarker>::inline_size(decoder.context),
667 2 => <fidl_fuchsia_bluetooth::PeerId as fidl::encoding::TypeMarker>::inline_size(
668 decoder.context,
669 ),
670 0 => return Err(fidl::Error::UnknownUnionTag),
671 _ => num_bytes as usize,
672 };
673
674 if inlined != (member_inline_size <= 4) {
675 return Err(fidl::Error::InvalidInlineBitInEnvelope);
676 }
677 let _inner_offset;
678 if inlined {
679 decoder.check_inline_envelope_padding(offset + 8, member_inline_size)?;
680 _inner_offset = offset + 8;
681 } else {
682 depth.increment()?;
683 _inner_offset = decoder.out_of_line_offset(member_inline_size)?;
684 }
685 match ordinal {
686 1 => {
687 #[allow(irrefutable_let_patterns)]
688 if let Identifier::LocalDevice(_) = self {
689 } else {
691 *self = Identifier::LocalDevice(fidl::new_empty!(LocalDevice, D));
693 }
694 #[allow(irrefutable_let_patterns)]
695 if let Identifier::LocalDevice(ref mut val) = self {
696 fidl::decode!(LocalDevice, D, val, decoder, _inner_offset, depth)?;
697 } else {
698 unreachable!()
699 }
700 }
701 2 => {
702 #[allow(irrefutable_let_patterns)]
703 if let Identifier::PeerId(_) = self {
704 } else {
706 *self =
708 Identifier::PeerId(fidl::new_empty!(fidl_fuchsia_bluetooth::PeerId, D));
709 }
710 #[allow(irrefutable_let_patterns)]
711 if let Identifier::PeerId(ref mut val) = self {
712 fidl::decode!(
713 fidl_fuchsia_bluetooth::PeerId,
714 D,
715 val,
716 decoder,
717 _inner_offset,
718 depth
719 )?;
720 } else {
721 unreachable!()
722 }
723 }
724 #[allow(deprecated)]
725 ordinal => {
726 for _ in 0..num_handles {
727 decoder.drop_next_handle()?;
728 }
729 *self = Identifier::__SourceBreaking { unknown_ordinal: ordinal };
730 }
731 }
732 if !inlined && decoder.next_out_of_line() != next_out_of_line + (num_bytes as usize) {
733 return Err(fidl::Error::InvalidNumBytesInEnvelope);
734 }
735 if handles_before != decoder.remaining_handles() + (num_handles as usize) {
736 return Err(fidl::Error::InvalidNumHandlesInEnvelope);
737 }
738 Ok(())
739 }
740 }
741}