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