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