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
11pub const POWER_STATE_CHARGING: u8 = 4;
12
13pub const POWER_STATE_CRITICAL: u8 = 8;
14
15pub const POWER_STATE_DISCHARGING: u8 = 2;
16
17pub const POWER_STATE_ONLINE: u8 = 1;
18
19#[derive(Copy, Clone, Debug, Eq, PartialEq, Ord, PartialOrd, Hash)]
20#[repr(u32)]
21pub enum BatteryUnit {
22 Mw = 0,
24 Ma = 1,
26}
27
28impl BatteryUnit {
29 #[inline]
30 pub fn from_primitive(prim: u32) -> Option<Self> {
31 match prim {
32 0 => Some(Self::Mw),
33 1 => Some(Self::Ma),
34 _ => None,
35 }
36 }
37
38 #[inline]
39 pub const fn into_primitive(self) -> u32 {
40 self as u32
41 }
42
43 #[deprecated = "Strict enums should not use `is_unknown`"]
44 #[inline]
45 pub fn is_unknown(&self) -> bool {
46 false
47 }
48}
49
50#[derive(Copy, Clone, Debug, Eq, PartialEq, Ord, PartialOrd, Hash)]
51#[repr(u8)]
52pub enum PowerType {
53 Ac = 0,
54 Battery = 1,
55}
56
57impl PowerType {
58 #[inline]
59 pub fn from_primitive(prim: u8) -> Option<Self> {
60 match prim {
61 0 => Some(Self::Ac),
62 1 => Some(Self::Battery),
63 _ => None,
64 }
65 }
66
67 #[inline]
68 pub const fn into_primitive(self) -> u8 {
69 self as u8
70 }
71
72 #[deprecated = "Strict enums should not use `is_unknown`"]
73 #[inline]
74 pub fn is_unknown(&self) -> bool {
75 false
76 }
77}
78
79#[derive(Clone, Debug, PartialEq)]
80pub struct BatteryInfo {
81 pub unit: BatteryUnit,
83 pub design_capacity: u32,
85 pub last_full_capacity: u32,
87 pub design_voltage: u32,
89 pub capacity_warning: u32,
91 pub capacity_low: u32,
93 pub capacity_granularity_low_warning: u32,
96 pub capacity_granularity_warning_full: u32,
99 pub present_rate: i32,
103 pub remaining_capacity: u32,
104 pub present_voltage: u32,
105 pub battery_spec: BatterySpec,
107}
108
109impl fidl::Persistable for BatteryInfo {}
110
111#[derive(Clone, Debug, PartialEq)]
112pub struct SourceGetBatteryInfoResponse {
113 pub status: i32,
114 pub info: BatteryInfo,
115}
116
117impl fidl::Persistable for SourceGetBatteryInfoResponse {}
118
119#[derive(Clone, Copy, Debug, Eq, Hash, Ord, PartialEq, PartialOrd)]
120pub struct SourceGetPowerInfoResponse {
121 pub status: i32,
122 pub info: SourceInfo,
123}
124
125impl fidl::Persistable for SourceGetPowerInfoResponse {}
126
127#[derive(Clone, Copy, Debug, Eq, Hash, Ord, PartialEq, PartialOrd)]
128pub struct SourceInfo {
129 pub type_: PowerType,
130 pub state: u8,
131}
132
133impl fidl::Persistable for SourceInfo {}
134
135#[derive(Clone, Debug, Default, PartialEq)]
137pub struct BatterySpec {
138 pub max_charging_current_ua: Option<i32>,
140 pub max_charnging_voltage_uv: Option<i32>,
142 pub design_capacity_uah: Option<i32>,
144 #[doc(hidden)]
145 pub __source_breaking: fidl::marker::SourceBreaking,
146}
147
148impl fidl::Persistable for BatterySpec {}
149
150mod internal {
151 use super::*;
152 unsafe impl fidl::encoding::TypeMarker for BatteryUnit {
153 type Owned = Self;
154
155 #[inline(always)]
156 fn inline_align(_context: fidl::encoding::Context) -> usize {
157 std::mem::align_of::<u32>()
158 }
159
160 #[inline(always)]
161 fn inline_size(_context: fidl::encoding::Context) -> usize {
162 std::mem::size_of::<u32>()
163 }
164
165 #[inline(always)]
166 fn encode_is_copy() -> bool {
167 true
168 }
169
170 #[inline(always)]
171 fn decode_is_copy() -> bool {
172 false
173 }
174 }
175
176 impl fidl::encoding::ValueTypeMarker for BatteryUnit {
177 type Borrowed<'a> = Self;
178 #[inline(always)]
179 fn borrow(value: &<Self as fidl::encoding::TypeMarker>::Owned) -> Self::Borrowed<'_> {
180 *value
181 }
182 }
183
184 unsafe impl<D: fidl::encoding::ResourceDialect> fidl::encoding::Encode<Self, D> for BatteryUnit {
185 #[inline]
186 unsafe fn encode(
187 self,
188 encoder: &mut fidl::encoding::Encoder<'_, D>,
189 offset: usize,
190 _depth: fidl::encoding::Depth,
191 ) -> fidl::Result<()> {
192 encoder.debug_check_bounds::<Self>(offset);
193 encoder.write_num(self.into_primitive(), offset);
194 Ok(())
195 }
196 }
197
198 impl<D: fidl::encoding::ResourceDialect> fidl::encoding::Decode<Self, D> for BatteryUnit {
199 #[inline(always)]
200 fn new_empty() -> Self {
201 Self::Mw
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 let prim = decoder.read_num::<u32>(offset);
213
214 *self = Self::from_primitive(prim).ok_or(fidl::Error::InvalidEnumValue)?;
215 Ok(())
216 }
217 }
218 unsafe impl fidl::encoding::TypeMarker for PowerType {
219 type Owned = Self;
220
221 #[inline(always)]
222 fn inline_align(_context: fidl::encoding::Context) -> usize {
223 std::mem::align_of::<u8>()
224 }
225
226 #[inline(always)]
227 fn inline_size(_context: fidl::encoding::Context) -> usize {
228 std::mem::size_of::<u8>()
229 }
230
231 #[inline(always)]
232 fn encode_is_copy() -> bool {
233 true
234 }
235
236 #[inline(always)]
237 fn decode_is_copy() -> bool {
238 false
239 }
240 }
241
242 impl fidl::encoding::ValueTypeMarker for PowerType {
243 type Borrowed<'a> = Self;
244 #[inline(always)]
245 fn borrow(value: &<Self as fidl::encoding::TypeMarker>::Owned) -> Self::Borrowed<'_> {
246 *value
247 }
248 }
249
250 unsafe impl<D: fidl::encoding::ResourceDialect> fidl::encoding::Encode<Self, D> for PowerType {
251 #[inline]
252 unsafe fn encode(
253 self,
254 encoder: &mut fidl::encoding::Encoder<'_, D>,
255 offset: usize,
256 _depth: fidl::encoding::Depth,
257 ) -> fidl::Result<()> {
258 encoder.debug_check_bounds::<Self>(offset);
259 encoder.write_num(self.into_primitive(), offset);
260 Ok(())
261 }
262 }
263
264 impl<D: fidl::encoding::ResourceDialect> fidl::encoding::Decode<Self, D> for PowerType {
265 #[inline(always)]
266 fn new_empty() -> Self {
267 Self::Ac
268 }
269
270 #[inline]
271 unsafe fn decode(
272 &mut self,
273 decoder: &mut fidl::encoding::Decoder<'_, D>,
274 offset: usize,
275 _depth: fidl::encoding::Depth,
276 ) -> fidl::Result<()> {
277 decoder.debug_check_bounds::<Self>(offset);
278 let prim = decoder.read_num::<u8>(offset);
279
280 *self = Self::from_primitive(prim).ok_or(fidl::Error::InvalidEnumValue)?;
281 Ok(())
282 }
283 }
284
285 impl fidl::encoding::ValueTypeMarker for BatteryInfo {
286 type Borrowed<'a> = &'a Self;
287 fn borrow(value: &<Self as fidl::encoding::TypeMarker>::Owned) -> Self::Borrowed<'_> {
288 value
289 }
290 }
291
292 unsafe impl fidl::encoding::TypeMarker for BatteryInfo {
293 type Owned = Self;
294
295 #[inline(always)]
296 fn inline_align(_context: fidl::encoding::Context) -> usize {
297 8
298 }
299
300 #[inline(always)]
301 fn inline_size(_context: fidl::encoding::Context) -> usize {
302 64
303 }
304 }
305
306 unsafe impl<D: fidl::encoding::ResourceDialect> fidl::encoding::Encode<BatteryInfo, D>
307 for &BatteryInfo
308 {
309 #[inline]
310 unsafe fn encode(
311 self,
312 encoder: &mut fidl::encoding::Encoder<'_, D>,
313 offset: usize,
314 _depth: fidl::encoding::Depth,
315 ) -> fidl::Result<()> {
316 encoder.debug_check_bounds::<BatteryInfo>(offset);
317 fidl::encoding::Encode::<BatteryInfo, D>::encode(
319 (
320 <BatteryUnit as fidl::encoding::ValueTypeMarker>::borrow(&self.unit),
321 <u32 as fidl::encoding::ValueTypeMarker>::borrow(&self.design_capacity),
322 <u32 as fidl::encoding::ValueTypeMarker>::borrow(&self.last_full_capacity),
323 <u32 as fidl::encoding::ValueTypeMarker>::borrow(&self.design_voltage),
324 <u32 as fidl::encoding::ValueTypeMarker>::borrow(&self.capacity_warning),
325 <u32 as fidl::encoding::ValueTypeMarker>::borrow(&self.capacity_low),
326 <u32 as fidl::encoding::ValueTypeMarker>::borrow(
327 &self.capacity_granularity_low_warning,
328 ),
329 <u32 as fidl::encoding::ValueTypeMarker>::borrow(
330 &self.capacity_granularity_warning_full,
331 ),
332 <i32 as fidl::encoding::ValueTypeMarker>::borrow(&self.present_rate),
333 <u32 as fidl::encoding::ValueTypeMarker>::borrow(&self.remaining_capacity),
334 <u32 as fidl::encoding::ValueTypeMarker>::borrow(&self.present_voltage),
335 <BatterySpec as fidl::encoding::ValueTypeMarker>::borrow(&self.battery_spec),
336 ),
337 encoder,
338 offset,
339 _depth,
340 )
341 }
342 }
343 unsafe impl<
344 D: fidl::encoding::ResourceDialect,
345 T0: fidl::encoding::Encode<BatteryUnit, D>,
346 T1: fidl::encoding::Encode<u32, D>,
347 T2: fidl::encoding::Encode<u32, D>,
348 T3: fidl::encoding::Encode<u32, D>,
349 T4: fidl::encoding::Encode<u32, D>,
350 T5: fidl::encoding::Encode<u32, D>,
351 T6: fidl::encoding::Encode<u32, D>,
352 T7: fidl::encoding::Encode<u32, D>,
353 T8: fidl::encoding::Encode<i32, D>,
354 T9: fidl::encoding::Encode<u32, D>,
355 T10: fidl::encoding::Encode<u32, D>,
356 T11: fidl::encoding::Encode<BatterySpec, D>,
357 > fidl::encoding::Encode<BatteryInfo, D>
358 for (T0, T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11)
359 {
360 #[inline]
361 unsafe fn encode(
362 self,
363 encoder: &mut fidl::encoding::Encoder<'_, D>,
364 offset: usize,
365 depth: fidl::encoding::Depth,
366 ) -> fidl::Result<()> {
367 encoder.debug_check_bounds::<BatteryInfo>(offset);
368 unsafe {
371 let ptr = encoder.buf.as_mut_ptr().add(offset).offset(40);
372 (ptr as *mut u64).write_unaligned(0);
373 }
374 self.0.encode(encoder, offset + 0, depth)?;
376 self.1.encode(encoder, offset + 4, depth)?;
377 self.2.encode(encoder, offset + 8, depth)?;
378 self.3.encode(encoder, offset + 12, depth)?;
379 self.4.encode(encoder, offset + 16, depth)?;
380 self.5.encode(encoder, offset + 20, depth)?;
381 self.6.encode(encoder, offset + 24, depth)?;
382 self.7.encode(encoder, offset + 28, depth)?;
383 self.8.encode(encoder, offset + 32, depth)?;
384 self.9.encode(encoder, offset + 36, depth)?;
385 self.10.encode(encoder, offset + 40, depth)?;
386 self.11.encode(encoder, offset + 48, depth)?;
387 Ok(())
388 }
389 }
390
391 impl<D: fidl::encoding::ResourceDialect> fidl::encoding::Decode<Self, D> for BatteryInfo {
392 #[inline(always)]
393 fn new_empty() -> Self {
394 Self {
395 unit: fidl::new_empty!(BatteryUnit, D),
396 design_capacity: fidl::new_empty!(u32, D),
397 last_full_capacity: fidl::new_empty!(u32, D),
398 design_voltage: fidl::new_empty!(u32, D),
399 capacity_warning: fidl::new_empty!(u32, D),
400 capacity_low: fidl::new_empty!(u32, D),
401 capacity_granularity_low_warning: fidl::new_empty!(u32, D),
402 capacity_granularity_warning_full: fidl::new_empty!(u32, D),
403 present_rate: fidl::new_empty!(i32, D),
404 remaining_capacity: fidl::new_empty!(u32, D),
405 present_voltage: fidl::new_empty!(u32, D),
406 battery_spec: fidl::new_empty!(BatterySpec, D),
407 }
408 }
409
410 #[inline]
411 unsafe fn decode(
412 &mut self,
413 decoder: &mut fidl::encoding::Decoder<'_, D>,
414 offset: usize,
415 _depth: fidl::encoding::Depth,
416 ) -> fidl::Result<()> {
417 decoder.debug_check_bounds::<Self>(offset);
418 let ptr = unsafe { decoder.buf.as_ptr().add(offset).offset(40) };
420 let padval = unsafe { (ptr as *const u64).read_unaligned() };
421 let mask = 0xffffffff00000000u64;
422 let maskedval = padval & mask;
423 if maskedval != 0 {
424 return Err(fidl::Error::NonZeroPadding {
425 padding_start: offset + 40 + ((mask as u64).trailing_zeros() / 8) as usize,
426 });
427 }
428 fidl::decode!(BatteryUnit, D, &mut self.unit, decoder, offset + 0, _depth)?;
429 fidl::decode!(u32, D, &mut self.design_capacity, decoder, offset + 4, _depth)?;
430 fidl::decode!(u32, D, &mut self.last_full_capacity, decoder, offset + 8, _depth)?;
431 fidl::decode!(u32, D, &mut self.design_voltage, decoder, offset + 12, _depth)?;
432 fidl::decode!(u32, D, &mut self.capacity_warning, decoder, offset + 16, _depth)?;
433 fidl::decode!(u32, D, &mut self.capacity_low, decoder, offset + 20, _depth)?;
434 fidl::decode!(
435 u32,
436 D,
437 &mut self.capacity_granularity_low_warning,
438 decoder,
439 offset + 24,
440 _depth
441 )?;
442 fidl::decode!(
443 u32,
444 D,
445 &mut self.capacity_granularity_warning_full,
446 decoder,
447 offset + 28,
448 _depth
449 )?;
450 fidl::decode!(i32, D, &mut self.present_rate, decoder, offset + 32, _depth)?;
451 fidl::decode!(u32, D, &mut self.remaining_capacity, decoder, offset + 36, _depth)?;
452 fidl::decode!(u32, D, &mut self.present_voltage, decoder, offset + 40, _depth)?;
453 fidl::decode!(BatterySpec, D, &mut self.battery_spec, decoder, offset + 48, _depth)?;
454 Ok(())
455 }
456 }
457
458 impl fidl::encoding::ValueTypeMarker for SourceGetBatteryInfoResponse {
459 type Borrowed<'a> = &'a Self;
460 fn borrow(value: &<Self as fidl::encoding::TypeMarker>::Owned) -> Self::Borrowed<'_> {
461 value
462 }
463 }
464
465 unsafe impl fidl::encoding::TypeMarker for SourceGetBatteryInfoResponse {
466 type Owned = Self;
467
468 #[inline(always)]
469 fn inline_align(_context: fidl::encoding::Context) -> usize {
470 8
471 }
472
473 #[inline(always)]
474 fn inline_size(_context: fidl::encoding::Context) -> usize {
475 72
476 }
477 }
478
479 unsafe impl<D: fidl::encoding::ResourceDialect>
480 fidl::encoding::Encode<SourceGetBatteryInfoResponse, D> for &SourceGetBatteryInfoResponse
481 {
482 #[inline]
483 unsafe fn encode(
484 self,
485 encoder: &mut fidl::encoding::Encoder<'_, D>,
486 offset: usize,
487 _depth: fidl::encoding::Depth,
488 ) -> fidl::Result<()> {
489 encoder.debug_check_bounds::<SourceGetBatteryInfoResponse>(offset);
490 fidl::encoding::Encode::<SourceGetBatteryInfoResponse, D>::encode(
492 (
493 <i32 as fidl::encoding::ValueTypeMarker>::borrow(&self.status),
494 <BatteryInfo as fidl::encoding::ValueTypeMarker>::borrow(&self.info),
495 ),
496 encoder,
497 offset,
498 _depth,
499 )
500 }
501 }
502 unsafe impl<
503 D: fidl::encoding::ResourceDialect,
504 T0: fidl::encoding::Encode<i32, D>,
505 T1: fidl::encoding::Encode<BatteryInfo, D>,
506 > fidl::encoding::Encode<SourceGetBatteryInfoResponse, D> for (T0, T1)
507 {
508 #[inline]
509 unsafe fn encode(
510 self,
511 encoder: &mut fidl::encoding::Encoder<'_, D>,
512 offset: usize,
513 depth: fidl::encoding::Depth,
514 ) -> fidl::Result<()> {
515 encoder.debug_check_bounds::<SourceGetBatteryInfoResponse>(offset);
516 unsafe {
519 let ptr = encoder.buf.as_mut_ptr().add(offset).offset(0);
520 (ptr as *mut u64).write_unaligned(0);
521 }
522 self.0.encode(encoder, offset + 0, depth)?;
524 self.1.encode(encoder, offset + 8, depth)?;
525 Ok(())
526 }
527 }
528
529 impl<D: fidl::encoding::ResourceDialect> fidl::encoding::Decode<Self, D>
530 for SourceGetBatteryInfoResponse
531 {
532 #[inline(always)]
533 fn new_empty() -> Self {
534 Self { status: fidl::new_empty!(i32, D), info: fidl::new_empty!(BatteryInfo, D) }
535 }
536
537 #[inline]
538 unsafe fn decode(
539 &mut self,
540 decoder: &mut fidl::encoding::Decoder<'_, D>,
541 offset: usize,
542 _depth: fidl::encoding::Depth,
543 ) -> fidl::Result<()> {
544 decoder.debug_check_bounds::<Self>(offset);
545 let ptr = unsafe { decoder.buf.as_ptr().add(offset).offset(0) };
547 let padval = unsafe { (ptr as *const u64).read_unaligned() };
548 let mask = 0xffffffff00000000u64;
549 let maskedval = padval & mask;
550 if maskedval != 0 {
551 return Err(fidl::Error::NonZeroPadding {
552 padding_start: offset + 0 + ((mask as u64).trailing_zeros() / 8) as usize,
553 });
554 }
555 fidl::decode!(i32, D, &mut self.status, decoder, offset + 0, _depth)?;
556 fidl::decode!(BatteryInfo, D, &mut self.info, decoder, offset + 8, _depth)?;
557 Ok(())
558 }
559 }
560
561 impl fidl::encoding::ValueTypeMarker for SourceGetPowerInfoResponse {
562 type Borrowed<'a> = &'a Self;
563 fn borrow(value: &<Self as fidl::encoding::TypeMarker>::Owned) -> Self::Borrowed<'_> {
564 value
565 }
566 }
567
568 unsafe impl fidl::encoding::TypeMarker for SourceGetPowerInfoResponse {
569 type Owned = Self;
570
571 #[inline(always)]
572 fn inline_align(_context: fidl::encoding::Context) -> usize {
573 4
574 }
575
576 #[inline(always)]
577 fn inline_size(_context: fidl::encoding::Context) -> usize {
578 8
579 }
580 }
581
582 unsafe impl<D: fidl::encoding::ResourceDialect>
583 fidl::encoding::Encode<SourceGetPowerInfoResponse, D> for &SourceGetPowerInfoResponse
584 {
585 #[inline]
586 unsafe fn encode(
587 self,
588 encoder: &mut fidl::encoding::Encoder<'_, D>,
589 offset: usize,
590 _depth: fidl::encoding::Depth,
591 ) -> fidl::Result<()> {
592 encoder.debug_check_bounds::<SourceGetPowerInfoResponse>(offset);
593 fidl::encoding::Encode::<SourceGetPowerInfoResponse, D>::encode(
595 (
596 <i32 as fidl::encoding::ValueTypeMarker>::borrow(&self.status),
597 <SourceInfo as fidl::encoding::ValueTypeMarker>::borrow(&self.info),
598 ),
599 encoder,
600 offset,
601 _depth,
602 )
603 }
604 }
605 unsafe impl<
606 D: fidl::encoding::ResourceDialect,
607 T0: fidl::encoding::Encode<i32, D>,
608 T1: fidl::encoding::Encode<SourceInfo, D>,
609 > fidl::encoding::Encode<SourceGetPowerInfoResponse, D> for (T0, T1)
610 {
611 #[inline]
612 unsafe fn encode(
613 self,
614 encoder: &mut fidl::encoding::Encoder<'_, D>,
615 offset: usize,
616 depth: fidl::encoding::Depth,
617 ) -> fidl::Result<()> {
618 encoder.debug_check_bounds::<SourceGetPowerInfoResponse>(offset);
619 unsafe {
622 let ptr = encoder.buf.as_mut_ptr().add(offset).offset(4);
623 (ptr as *mut u32).write_unaligned(0);
624 }
625 self.0.encode(encoder, offset + 0, depth)?;
627 self.1.encode(encoder, offset + 4, depth)?;
628 Ok(())
629 }
630 }
631
632 impl<D: fidl::encoding::ResourceDialect> fidl::encoding::Decode<Self, D>
633 for SourceGetPowerInfoResponse
634 {
635 #[inline(always)]
636 fn new_empty() -> Self {
637 Self { status: fidl::new_empty!(i32, D), info: fidl::new_empty!(SourceInfo, D) }
638 }
639
640 #[inline]
641 unsafe fn decode(
642 &mut self,
643 decoder: &mut fidl::encoding::Decoder<'_, D>,
644 offset: usize,
645 _depth: fidl::encoding::Depth,
646 ) -> fidl::Result<()> {
647 decoder.debug_check_bounds::<Self>(offset);
648 let ptr = unsafe { decoder.buf.as_ptr().add(offset).offset(4) };
650 let padval = unsafe { (ptr as *const u32).read_unaligned() };
651 let mask = 0xffff0000u32;
652 let maskedval = padval & mask;
653 if maskedval != 0 {
654 return Err(fidl::Error::NonZeroPadding {
655 padding_start: offset + 4 + ((mask as u64).trailing_zeros() / 8) as usize,
656 });
657 }
658 fidl::decode!(i32, D, &mut self.status, decoder, offset + 0, _depth)?;
659 fidl::decode!(SourceInfo, D, &mut self.info, decoder, offset + 4, _depth)?;
660 Ok(())
661 }
662 }
663
664 impl fidl::encoding::ValueTypeMarker for SourceInfo {
665 type Borrowed<'a> = &'a Self;
666 fn borrow(value: &<Self as fidl::encoding::TypeMarker>::Owned) -> Self::Borrowed<'_> {
667 value
668 }
669 }
670
671 unsafe impl fidl::encoding::TypeMarker for SourceInfo {
672 type Owned = Self;
673
674 #[inline(always)]
675 fn inline_align(_context: fidl::encoding::Context) -> usize {
676 1
677 }
678
679 #[inline(always)]
680 fn inline_size(_context: fidl::encoding::Context) -> usize {
681 2
682 }
683 }
684
685 unsafe impl<D: fidl::encoding::ResourceDialect> fidl::encoding::Encode<SourceInfo, D>
686 for &SourceInfo
687 {
688 #[inline]
689 unsafe fn encode(
690 self,
691 encoder: &mut fidl::encoding::Encoder<'_, D>,
692 offset: usize,
693 _depth: fidl::encoding::Depth,
694 ) -> fidl::Result<()> {
695 encoder.debug_check_bounds::<SourceInfo>(offset);
696 fidl::encoding::Encode::<SourceInfo, D>::encode(
698 (
699 <PowerType as fidl::encoding::ValueTypeMarker>::borrow(&self.type_),
700 <u8 as fidl::encoding::ValueTypeMarker>::borrow(&self.state),
701 ),
702 encoder,
703 offset,
704 _depth,
705 )
706 }
707 }
708 unsafe impl<
709 D: fidl::encoding::ResourceDialect,
710 T0: fidl::encoding::Encode<PowerType, D>,
711 T1: fidl::encoding::Encode<u8, D>,
712 > fidl::encoding::Encode<SourceInfo, D> for (T0, T1)
713 {
714 #[inline]
715 unsafe fn encode(
716 self,
717 encoder: &mut fidl::encoding::Encoder<'_, D>,
718 offset: usize,
719 depth: fidl::encoding::Depth,
720 ) -> fidl::Result<()> {
721 encoder.debug_check_bounds::<SourceInfo>(offset);
722 self.0.encode(encoder, offset + 0, depth)?;
726 self.1.encode(encoder, offset + 1, depth)?;
727 Ok(())
728 }
729 }
730
731 impl<D: fidl::encoding::ResourceDialect> fidl::encoding::Decode<Self, D> for SourceInfo {
732 #[inline(always)]
733 fn new_empty() -> Self {
734 Self { type_: fidl::new_empty!(PowerType, D), state: fidl::new_empty!(u8, D) }
735 }
736
737 #[inline]
738 unsafe fn decode(
739 &mut self,
740 decoder: &mut fidl::encoding::Decoder<'_, D>,
741 offset: usize,
742 _depth: fidl::encoding::Depth,
743 ) -> fidl::Result<()> {
744 decoder.debug_check_bounds::<Self>(offset);
745 fidl::decode!(PowerType, D, &mut self.type_, decoder, offset + 0, _depth)?;
747 fidl::decode!(u8, D, &mut self.state, decoder, offset + 1, _depth)?;
748 Ok(())
749 }
750 }
751
752 impl BatterySpec {
753 #[inline(always)]
754 fn max_ordinal_present(&self) -> u64 {
755 if let Some(_) = self.design_capacity_uah {
756 return 3;
757 }
758 if let Some(_) = self.max_charnging_voltage_uv {
759 return 2;
760 }
761 if let Some(_) = self.max_charging_current_ua {
762 return 1;
763 }
764 0
765 }
766 }
767
768 impl fidl::encoding::ValueTypeMarker for BatterySpec {
769 type Borrowed<'a> = &'a Self;
770 fn borrow(value: &<Self as fidl::encoding::TypeMarker>::Owned) -> Self::Borrowed<'_> {
771 value
772 }
773 }
774
775 unsafe impl fidl::encoding::TypeMarker for BatterySpec {
776 type Owned = Self;
777
778 #[inline(always)]
779 fn inline_align(_context: fidl::encoding::Context) -> usize {
780 8
781 }
782
783 #[inline(always)]
784 fn inline_size(_context: fidl::encoding::Context) -> usize {
785 16
786 }
787 }
788
789 unsafe impl<D: fidl::encoding::ResourceDialect> fidl::encoding::Encode<BatterySpec, D>
790 for &BatterySpec
791 {
792 unsafe fn encode(
793 self,
794 encoder: &mut fidl::encoding::Encoder<'_, D>,
795 offset: usize,
796 mut depth: fidl::encoding::Depth,
797 ) -> fidl::Result<()> {
798 encoder.debug_check_bounds::<BatterySpec>(offset);
799 let max_ordinal: u64 = self.max_ordinal_present();
801 encoder.write_num(max_ordinal, offset);
802 encoder.write_num(fidl::encoding::ALLOC_PRESENT_U64, offset + 8);
803 if max_ordinal == 0 {
805 return Ok(());
806 }
807 depth.increment()?;
808 let envelope_size = 8;
809 let bytes_len = max_ordinal as usize * envelope_size;
810 #[allow(unused_variables)]
811 let offset = encoder.out_of_line_offset(bytes_len);
812 let mut _prev_end_offset: usize = 0;
813 if 1 > max_ordinal {
814 return Ok(());
815 }
816
817 let cur_offset: usize = (1 - 1) * envelope_size;
820
821 encoder.padding(offset + _prev_end_offset, cur_offset - _prev_end_offset);
823
824 fidl::encoding::encode_in_envelope_optional::<i32, D>(
829 self.max_charging_current_ua
830 .as_ref()
831 .map(<i32 as fidl::encoding::ValueTypeMarker>::borrow),
832 encoder,
833 offset + cur_offset,
834 depth,
835 )?;
836
837 _prev_end_offset = cur_offset + envelope_size;
838 if 2 > max_ordinal {
839 return Ok(());
840 }
841
842 let cur_offset: usize = (2 - 1) * envelope_size;
845
846 encoder.padding(offset + _prev_end_offset, cur_offset - _prev_end_offset);
848
849 fidl::encoding::encode_in_envelope_optional::<i32, D>(
854 self.max_charnging_voltage_uv
855 .as_ref()
856 .map(<i32 as fidl::encoding::ValueTypeMarker>::borrow),
857 encoder,
858 offset + cur_offset,
859 depth,
860 )?;
861
862 _prev_end_offset = cur_offset + envelope_size;
863 if 3 > max_ordinal {
864 return Ok(());
865 }
866
867 let cur_offset: usize = (3 - 1) * envelope_size;
870
871 encoder.padding(offset + _prev_end_offset, cur_offset - _prev_end_offset);
873
874 fidl::encoding::encode_in_envelope_optional::<i32, D>(
879 self.design_capacity_uah
880 .as_ref()
881 .map(<i32 as fidl::encoding::ValueTypeMarker>::borrow),
882 encoder,
883 offset + cur_offset,
884 depth,
885 )?;
886
887 _prev_end_offset = cur_offset + envelope_size;
888
889 Ok(())
890 }
891 }
892
893 impl<D: fidl::encoding::ResourceDialect> fidl::encoding::Decode<Self, D> for BatterySpec {
894 #[inline(always)]
895 fn new_empty() -> Self {
896 Self::default()
897 }
898
899 unsafe fn decode(
900 &mut self,
901 decoder: &mut fidl::encoding::Decoder<'_, D>,
902 offset: usize,
903 mut depth: fidl::encoding::Depth,
904 ) -> fidl::Result<()> {
905 decoder.debug_check_bounds::<Self>(offset);
906 let len = match fidl::encoding::decode_vector_header(decoder, offset)? {
907 None => return Err(fidl::Error::NotNullable),
908 Some(len) => len,
909 };
910 if len == 0 {
912 return Ok(());
913 };
914 depth.increment()?;
915 let envelope_size = 8;
916 let bytes_len = len * envelope_size;
917 let offset = decoder.out_of_line_offset(bytes_len)?;
918 let mut _next_ordinal_to_read = 0;
920 let mut next_offset = offset;
921 let end_offset = offset + bytes_len;
922 _next_ordinal_to_read += 1;
923 if next_offset >= end_offset {
924 return Ok(());
925 }
926
927 while _next_ordinal_to_read < 1 {
929 fidl::encoding::decode_unknown_envelope(decoder, next_offset, depth)?;
930 _next_ordinal_to_read += 1;
931 next_offset += envelope_size;
932 }
933
934 let next_out_of_line = decoder.next_out_of_line();
935 let handles_before = decoder.remaining_handles();
936 if let Some((inlined, num_bytes, num_handles)) =
937 fidl::encoding::decode_envelope_header(decoder, next_offset)?
938 {
939 let member_inline_size =
940 <i32 as fidl::encoding::TypeMarker>::inline_size(decoder.context);
941 if inlined != (member_inline_size <= 4) {
942 return Err(fidl::Error::InvalidInlineBitInEnvelope);
943 }
944 let inner_offset;
945 let mut inner_depth = depth.clone();
946 if inlined {
947 decoder.check_inline_envelope_padding(next_offset, member_inline_size)?;
948 inner_offset = next_offset;
949 } else {
950 inner_offset = decoder.out_of_line_offset(member_inline_size)?;
951 inner_depth.increment()?;
952 }
953 let val_ref =
954 self.max_charging_current_ua.get_or_insert_with(|| fidl::new_empty!(i32, D));
955 fidl::decode!(i32, D, val_ref, decoder, inner_offset, inner_depth)?;
956 if !inlined && decoder.next_out_of_line() != next_out_of_line + (num_bytes as usize)
957 {
958 return Err(fidl::Error::InvalidNumBytesInEnvelope);
959 }
960 if handles_before != decoder.remaining_handles() + (num_handles as usize) {
961 return Err(fidl::Error::InvalidNumHandlesInEnvelope);
962 }
963 }
964
965 next_offset += envelope_size;
966 _next_ordinal_to_read += 1;
967 if next_offset >= end_offset {
968 return Ok(());
969 }
970
971 while _next_ordinal_to_read < 2 {
973 fidl::encoding::decode_unknown_envelope(decoder, next_offset, depth)?;
974 _next_ordinal_to_read += 1;
975 next_offset += envelope_size;
976 }
977
978 let next_out_of_line = decoder.next_out_of_line();
979 let handles_before = decoder.remaining_handles();
980 if let Some((inlined, num_bytes, num_handles)) =
981 fidl::encoding::decode_envelope_header(decoder, next_offset)?
982 {
983 let member_inline_size =
984 <i32 as fidl::encoding::TypeMarker>::inline_size(decoder.context);
985 if inlined != (member_inline_size <= 4) {
986 return Err(fidl::Error::InvalidInlineBitInEnvelope);
987 }
988 let inner_offset;
989 let mut inner_depth = depth.clone();
990 if inlined {
991 decoder.check_inline_envelope_padding(next_offset, member_inline_size)?;
992 inner_offset = next_offset;
993 } else {
994 inner_offset = decoder.out_of_line_offset(member_inline_size)?;
995 inner_depth.increment()?;
996 }
997 let val_ref =
998 self.max_charnging_voltage_uv.get_or_insert_with(|| fidl::new_empty!(i32, D));
999 fidl::decode!(i32, D, val_ref, decoder, inner_offset, inner_depth)?;
1000 if !inlined && decoder.next_out_of_line() != next_out_of_line + (num_bytes as usize)
1001 {
1002 return Err(fidl::Error::InvalidNumBytesInEnvelope);
1003 }
1004 if handles_before != decoder.remaining_handles() + (num_handles as usize) {
1005 return Err(fidl::Error::InvalidNumHandlesInEnvelope);
1006 }
1007 }
1008
1009 next_offset += envelope_size;
1010 _next_ordinal_to_read += 1;
1011 if next_offset >= end_offset {
1012 return Ok(());
1013 }
1014
1015 while _next_ordinal_to_read < 3 {
1017 fidl::encoding::decode_unknown_envelope(decoder, next_offset, depth)?;
1018 _next_ordinal_to_read += 1;
1019 next_offset += envelope_size;
1020 }
1021
1022 let next_out_of_line = decoder.next_out_of_line();
1023 let handles_before = decoder.remaining_handles();
1024 if let Some((inlined, num_bytes, num_handles)) =
1025 fidl::encoding::decode_envelope_header(decoder, next_offset)?
1026 {
1027 let member_inline_size =
1028 <i32 as fidl::encoding::TypeMarker>::inline_size(decoder.context);
1029 if inlined != (member_inline_size <= 4) {
1030 return Err(fidl::Error::InvalidInlineBitInEnvelope);
1031 }
1032 let inner_offset;
1033 let mut inner_depth = depth.clone();
1034 if inlined {
1035 decoder.check_inline_envelope_padding(next_offset, member_inline_size)?;
1036 inner_offset = next_offset;
1037 } else {
1038 inner_offset = decoder.out_of_line_offset(member_inline_size)?;
1039 inner_depth.increment()?;
1040 }
1041 let val_ref =
1042 self.design_capacity_uah.get_or_insert_with(|| fidl::new_empty!(i32, D));
1043 fidl::decode!(i32, D, val_ref, decoder, inner_offset, inner_depth)?;
1044 if !inlined && decoder.next_out_of_line() != next_out_of_line + (num_bytes as usize)
1045 {
1046 return Err(fidl::Error::InvalidNumBytesInEnvelope);
1047 }
1048 if handles_before != decoder.remaining_handles() + (num_handles as usize) {
1049 return Err(fidl::Error::InvalidNumHandlesInEnvelope);
1050 }
1051 }
1052
1053 next_offset += envelope_size;
1054
1055 while next_offset < end_offset {
1057 _next_ordinal_to_read += 1;
1058 fidl::encoding::decode_unknown_envelope(decoder, next_offset, depth)?;
1059 next_offset += envelope_size;
1060 }
1061
1062 Ok(())
1063 }
1064 }
1065}