Skip to main content

fidl_fuchsia_hardware_power_battery_common/
fidl_fuchsia_hardware_power_battery_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
11/// Errors returned by the battery protocol.
12#[derive(Copy, Clone, Debug, Eq, PartialEq, Ord, PartialOrd, Hash)]
13pub enum Error {
14    /// An unexpected error occurred within the driver.
15    Internal,
16    /// The requested operation, field, or mode is not supported by this hardware.
17    NotSupported,
18    /// One or more arguments provided to the method were invalid, or a requested value lies
19    /// outside the range the hardware can program.
20    InvalidArgs,
21    /// Communication with the battery hardware failed (e.g. a bus transfer error).
22    Io,
23    /// A `Watch` call is already pending on this connection.
24    AlreadyWatching,
25    #[doc(hidden)]
26    __SourceBreaking { unknown_ordinal: u32 },
27}
28
29/// Pattern that matches an unknown `Error` member.
30#[macro_export]
31macro_rules! ErrorUnknown {
32    () => {
33        _
34    };
35}
36
37impl Error {
38    #[inline]
39    pub fn from_primitive(prim: u32) -> Option<Self> {
40        match prim {
41            1 => Some(Self::Internal),
42            2 => Some(Self::NotSupported),
43            3 => Some(Self::InvalidArgs),
44            4 => Some(Self::Io),
45            5 => Some(Self::AlreadyWatching),
46            _ => None,
47        }
48    }
49
50    #[inline]
51    pub fn from_primitive_allow_unknown(prim: u32) -> Self {
52        match prim {
53            1 => Self::Internal,
54            2 => Self::NotSupported,
55            3 => Self::InvalidArgs,
56            4 => Self::Io,
57            5 => Self::AlreadyWatching,
58            unknown_ordinal => Self::__SourceBreaking { unknown_ordinal },
59        }
60    }
61
62    #[inline]
63    pub fn unknown() -> Self {
64        Self::__SourceBreaking { unknown_ordinal: 0xffffffff }
65    }
66
67    #[inline]
68    pub const fn into_primitive(self) -> u32 {
69        match self {
70            Self::Internal => 1,
71            Self::NotSupported => 2,
72            Self::InvalidArgs => 3,
73            Self::Io => 4,
74            Self::AlreadyWatching => 5,
75            Self::__SourceBreaking { unknown_ordinal } => unknown_ordinal,
76        }
77    }
78
79    #[inline]
80    pub fn is_unknown(&self) -> bool {
81        match self {
82            Self::__SourceBreaking { unknown_ordinal: _ } => true,
83            _ => false,
84        }
85    }
86}
87
88/// Battery health and safety status, including JEITA temperature regions and fault conditions.
89///
90/// Each value describes whether the pack may be charged and whether it can still supply power to
91/// the system. Unless a value states otherwise, the battery can still supply power.
92#[derive(Copy, Clone, Debug, Eq, PartialEq, Ord, PartialOrd, Hash)]
93pub enum HealthStatus {
94    /// Normal operating temperature and healthy battery condition.
95    /// Both charging and discharging are permitted.
96    Good,
97    /// Battery temperature is below safe charging threshold (charging prohibited).
98    /// The battery can still supply power, though available capacity and peak current are
99    /// typically reduced.
100    Cold,
101    /// Battery temperature is low (charging current or voltage may be restricted).
102    /// The battery can still supply power.
103    Cool,
104    /// Battery temperature is elevated (charging current or voltage may be restricted).
105    /// The battery can still supply power.
106    Warm,
107    /// Battery temperature exceeded safety threshold (charging prohibited).
108    /// The battery can usually still supply power, but hardware protection may open the discharge
109    /// path if the temperature continues to rise.
110    Hot,
111    /// Battery pack voltage is below operating threshold or cell is dead.
112    /// The battery cannot supply usable power to the system.
113    Dead,
114    /// Battery voltage exceeded hardware safety limit (charging prohibited).
115    /// The battery can still supply power; discharging is the expected recovery path.
116    OverVoltage,
117    /// Unspecified hardware or fuel gauge safety fault.
118    /// Whether the pack may be charged, or can supply power at all, is indeterminate.
119    UnspecifiedFailure,
120    #[doc(hidden)]
121    __SourceBreaking { unknown_ordinal: u32 },
122}
123
124/// Pattern that matches an unknown `HealthStatus` member.
125#[macro_export]
126macro_rules! HealthStatusUnknown {
127    () => {
128        _
129    };
130}
131
132impl HealthStatus {
133    #[inline]
134    pub fn from_primitive(prim: u32) -> Option<Self> {
135        match prim {
136            1 => Some(Self::Good),
137            2 => Some(Self::Cold),
138            3 => Some(Self::Cool),
139            4 => Some(Self::Warm),
140            5 => Some(Self::Hot),
141            6 => Some(Self::Dead),
142            7 => Some(Self::OverVoltage),
143            8 => Some(Self::UnspecifiedFailure),
144            _ => None,
145        }
146    }
147
148    #[inline]
149    pub fn from_primitive_allow_unknown(prim: u32) -> Self {
150        match prim {
151            1 => Self::Good,
152            2 => Self::Cold,
153            3 => Self::Cool,
154            4 => Self::Warm,
155            5 => Self::Hot,
156            6 => Self::Dead,
157            7 => Self::OverVoltage,
158            8 => Self::UnspecifiedFailure,
159            unknown_ordinal => Self::__SourceBreaking { unknown_ordinal },
160        }
161    }
162
163    #[inline]
164    pub fn unknown() -> Self {
165        Self::__SourceBreaking { unknown_ordinal: 0xffffffff }
166    }
167
168    #[inline]
169    pub const fn into_primitive(self) -> u32 {
170        match self {
171            Self::Good => 1,
172            Self::Cold => 2,
173            Self::Cool => 3,
174            Self::Warm => 4,
175            Self::Hot => 5,
176            Self::Dead => 6,
177            Self::OverVoltage => 7,
178            Self::UnspecifiedFailure => 8,
179            Self::__SourceBreaking { unknown_ordinal } => unknown_ordinal,
180        }
181    }
182
183    #[inline]
184    pub fn is_unknown(&self) -> bool {
185        match self {
186            Self::__SourceBreaking { unknown_ordinal: _ } => true,
187            _ => false,
188        }
189    }
190}
191
192#[derive(Clone, Debug, PartialEq)]
193pub struct BatteryConfigureWatchRequest {
194    pub options: WatchOptions,
195}
196
197impl fidl::Persistable for BatteryConfigureWatchRequest {}
198
199#[derive(Clone, Debug, PartialEq)]
200pub struct BatteryConfigureWatchResponse {
201    pub effective_options: WatchOptions,
202}
203
204impl fidl::Persistable for BatteryConfigureWatchResponse {}
205
206#[derive(Clone, Debug, PartialEq)]
207pub struct BatteryGetSpecResponse {
208    pub spec: Spec,
209}
210
211impl fidl::Persistable for BatteryGetSpecResponse {}
212
213#[derive(Clone, Debug, PartialEq)]
214pub struct BatteryGetStatusResponse {
215    pub status: Status,
216}
217
218impl fidl::Persistable for BatteryGetStatusResponse {}
219
220/// Static hardware characteristics and driver capabilities.
221#[derive(Clone, Debug, Default, PartialEq)]
222pub struct Spec {
223    /// Optional. Design capacity in microamp-hours.
224    /// Omitted if unsupported by hardware.
225    pub design_capacity_uah: Option<u32>,
226    /// Optional. Nominal design voltage in microvolts.
227    /// Omitted if unsupported by hardware.
228    pub design_voltage_uv: Option<u32>,
229    /// Optional. Informational battery chemistry description (e.g. "Li-ion", "LiFePO4", "NiMH").
230    /// Omitted if unknown or unprogrammed in hardware.
231    pub chemistry: Option<String>,
232    /// Optional. Informational battery model string or manufacturer part number.
233    /// Omitted if unknown or unprogrammed in hardware.
234    pub model: Option<String>,
235    /// Required. The interest and wake options supported by this driver/hardware.
236    ///
237    /// Drivers must populate this table so clients know which fields support active change
238    /// notifications. If omitted by the driver, clients should assume no active interrupt watching
239    /// is supported.
240    ///
241    /// - `supported_options.interest`: Telemetry fields that can actively trigger hanging-get watch
242    ///   notifications on change. Fields omitted are passive measurements that do not generate
243    ///   hardware interrupts; their freshest values are returned during active state changes or via
244    ///   [`Battery.GetStatus`].
245    /// - `supported_options.wake_on`: Telemetry fields capable of actively waking the system from
246    ///   suspend via hardware interrupt lines etc.
247    pub supported_options: Option<WatchOptions>,
248    #[doc(hidden)]
249    pub __source_breaking: fidl::marker::SourceBreaking,
250}
251
252impl fidl::Persistable for Spec {}
253
254/// Primary telemetry snapshot from the battery fuel gauge.
255///
256/// All fields are optional. Each returned `Status` represents a complete snapshot, not a sparse
257/// delta; fields omitted by the driver indicate that the metric is unsupported by the hardware fuel
258/// gauge or currently unavailable/indeterminate.
259///
260/// NOTE: Some fields (e.g. instantaneous `voltage_uv` and `current_ua`) may be passive measurements
261/// that do not generate hardware interrupts on change. Refer to [`Spec.supported_options`] for the
262/// options that can actively trigger change notifications.
263#[derive(Clone, Debug, Default, PartialEq)]
264pub struct Status {
265    /// Whether the battery pack is physically present and connected.
266    /// If false, the battery is detached/missing. Omitted if presence is indeterminate.
267    pub present: Option<bool>,
268    /// Present terminal voltage in microvolts.
269    /// Omitted if unsupported by hardware or unavailable.
270    pub voltage_uv: Option<u32>,
271    /// Present current in microamps: positive (+) for charging, negative (-) for discharging.
272    /// Omitted if unsupported by hardware or unavailable.
273    pub current_ua: Option<i32>,
274    /// State of charge percentage in the range [0.0, 100.0].
275    /// Omitted if indeterminate or unsupported by hardware.
276    pub level_percent: Option<f32>,
277    /// Internal battery temperature in Celsius.
278    /// Omitted if temperature sensing is unsupported or unavailable.
279    pub temp_celsius: Option<f32>,
280    /// Estimated remaining usable capacity in microamp-hours.
281    /// Omitted if indeterminate or unsupported by hardware.
282    pub remaining_capacity_uah: Option<u32>,
283    /// Estimated full charge capacity in microamp-hours, reflecting pack aging.
284    /// Omitted if indeterminate or unsupported by hardware.
285    pub full_charge_capacity_uah: Option<u32>,
286    /// Health condition or safety trip status.
287    /// Omitted if health diagnostics are unsupported by hardware.
288    pub health: Option<HealthStatus>,
289    /// Total charge-discharge cycle count.
290    /// Omitted if cycle tracking is unsupported by hardware.
291    pub cycle_count: Option<u32>,
292    /// Estimated duration remaining until fully empty (discharging) or fully charged (charging).
293    /// Omitted if indeterminate, unsupported, or if the battery is idle.
294    pub time_remaining: Option<i64>,
295    #[doc(hidden)]
296    pub __source_breaking: fidl::marker::SourceBreaking,
297}
298
299impl fidl::Persistable for Status {}
300
301/// Configuration options for battery state watching.
302///
303/// Both fields are optional masks. In both `interest` and `wake_on`, the actual field values within
304/// the `Status` table are ignored; only field presence (set vs. unset) determines the mask.
305///
306/// An absent mask means "use this field's default"; a present but empty mask means "no fields".
307/// The two defaults differ because the safe choice differs: `interest` defaults to everything the
308/// driver supports watching, so a client that never configures anything still makes progress,
309/// while `wake_on` defaults to nothing, since waking the system is a cost a client must opt into.
310#[derive(Clone, Debug, Default, PartialEq)]
311pub struct WatchOptions {
312    /// Fields the client wants to receive change notifications for.
313    /// Defaults to every field the driver supports watching, as reported by
314    /// `Spec.supported_options`. Pass an explicitly empty table to be notified only for the
315    /// fields named in `wake_on`.
316    pub interest: Option<Status>,
317    /// Fields that should actively wake the system from suspend.
318    /// Any field present in `wake_on` is implicitly included in `interest`.
319    /// Defaults to no fields: changes occurring during suspend are deferred until the next system
320    /// wakeup and do not wake the device.
321    pub wake_on: Option<Status>,
322    #[doc(hidden)]
323    pub __source_breaking: fidl::marker::SourceBreaking,
324}
325
326impl fidl::Persistable for WatchOptions {}
327
328pub mod battery_ordinals {
329    pub const GET_SPEC: u64 = 0x235609229653654f;
330    pub const GET_STATUS: u64 = 0x2e0c03524d47095a;
331    pub const CONFIGURE_WATCH: u64 = 0x71fc28fbfc1f88c7;
332    pub const WATCH: u64 = 0x7386830cdd9e3390;
333}
334
335mod internal {
336    use super::*;
337    unsafe impl fidl::encoding::TypeMarker for Error {
338        type Owned = Self;
339
340        #[inline(always)]
341        fn inline_align(_context: fidl::encoding::Context) -> usize {
342            std::mem::align_of::<u32>()
343        }
344
345        #[inline(always)]
346        fn inline_size(_context: fidl::encoding::Context) -> usize {
347            std::mem::size_of::<u32>()
348        }
349
350        #[inline(always)]
351        fn encode_is_copy() -> bool {
352            false
353        }
354
355        #[inline(always)]
356        fn decode_is_copy() -> bool {
357            false
358        }
359    }
360
361    impl fidl::encoding::ValueTypeMarker for Error {
362        type Borrowed<'a> = Self;
363        #[inline(always)]
364        fn borrow(value: &<Self as fidl::encoding::TypeMarker>::Owned) -> Self::Borrowed<'_> {
365            *value
366        }
367    }
368
369    unsafe impl<D: fidl::encoding::ResourceDialect> fidl::encoding::Encode<Self, D> for Error {
370        #[inline]
371        unsafe fn encode(
372            self,
373            encoder: &mut fidl::encoding::Encoder<'_, D>,
374            offset: usize,
375            _depth: fidl::encoding::Depth,
376        ) -> fidl::Result<()> {
377            encoder.debug_check_bounds::<Self>(offset);
378            encoder.write_num(self.into_primitive(), offset);
379            Ok(())
380        }
381    }
382
383    impl<D: fidl::encoding::ResourceDialect> fidl::encoding::Decode<Self, D> for Error {
384        #[inline(always)]
385        fn new_empty() -> Self {
386            Self::unknown()
387        }
388
389        #[inline]
390        unsafe fn decode(
391            &mut self,
392            decoder: &mut fidl::encoding::Decoder<'_, D>,
393            offset: usize,
394            _depth: fidl::encoding::Depth,
395        ) -> fidl::Result<()> {
396            decoder.debug_check_bounds::<Self>(offset);
397            let prim = decoder.read_num::<u32>(offset);
398
399            *self = Self::from_primitive_allow_unknown(prim);
400            Ok(())
401        }
402    }
403    unsafe impl fidl::encoding::TypeMarker for HealthStatus {
404        type Owned = Self;
405
406        #[inline(always)]
407        fn inline_align(_context: fidl::encoding::Context) -> usize {
408            std::mem::align_of::<u32>()
409        }
410
411        #[inline(always)]
412        fn inline_size(_context: fidl::encoding::Context) -> usize {
413            std::mem::size_of::<u32>()
414        }
415
416        #[inline(always)]
417        fn encode_is_copy() -> bool {
418            false
419        }
420
421        #[inline(always)]
422        fn decode_is_copy() -> bool {
423            false
424        }
425    }
426
427    impl fidl::encoding::ValueTypeMarker for HealthStatus {
428        type Borrowed<'a> = Self;
429        #[inline(always)]
430        fn borrow(value: &<Self as fidl::encoding::TypeMarker>::Owned) -> Self::Borrowed<'_> {
431            *value
432        }
433    }
434
435    unsafe impl<D: fidl::encoding::ResourceDialect> fidl::encoding::Encode<Self, D> for HealthStatus {
436        #[inline]
437        unsafe fn encode(
438            self,
439            encoder: &mut fidl::encoding::Encoder<'_, D>,
440            offset: usize,
441            _depth: fidl::encoding::Depth,
442        ) -> fidl::Result<()> {
443            encoder.debug_check_bounds::<Self>(offset);
444            encoder.write_num(self.into_primitive(), offset);
445            Ok(())
446        }
447    }
448
449    impl<D: fidl::encoding::ResourceDialect> fidl::encoding::Decode<Self, D> for HealthStatus {
450        #[inline(always)]
451        fn new_empty() -> Self {
452            Self::unknown()
453        }
454
455        #[inline]
456        unsafe fn decode(
457            &mut self,
458            decoder: &mut fidl::encoding::Decoder<'_, D>,
459            offset: usize,
460            _depth: fidl::encoding::Depth,
461        ) -> fidl::Result<()> {
462            decoder.debug_check_bounds::<Self>(offset);
463            let prim = decoder.read_num::<u32>(offset);
464
465            *self = Self::from_primitive_allow_unknown(prim);
466            Ok(())
467        }
468    }
469
470    impl fidl::encoding::ValueTypeMarker for BatteryConfigureWatchRequest {
471        type Borrowed<'a> = &'a Self;
472        fn borrow(value: &<Self as fidl::encoding::TypeMarker>::Owned) -> Self::Borrowed<'_> {
473            value
474        }
475    }
476
477    unsafe impl fidl::encoding::TypeMarker for BatteryConfigureWatchRequest {
478        type Owned = Self;
479
480        #[inline(always)]
481        fn inline_align(_context: fidl::encoding::Context) -> usize {
482            8
483        }
484
485        #[inline(always)]
486        fn inline_size(_context: fidl::encoding::Context) -> usize {
487            16
488        }
489    }
490
491    unsafe impl<D: fidl::encoding::ResourceDialect>
492        fidl::encoding::Encode<BatteryConfigureWatchRequest, D> for &BatteryConfigureWatchRequest
493    {
494        #[inline]
495        unsafe fn encode(
496            self,
497            encoder: &mut fidl::encoding::Encoder<'_, D>,
498            offset: usize,
499            _depth: fidl::encoding::Depth,
500        ) -> fidl::Result<()> {
501            encoder.debug_check_bounds::<BatteryConfigureWatchRequest>(offset);
502            // Delegate to tuple encoding.
503            fidl::encoding::Encode::<BatteryConfigureWatchRequest, D>::encode(
504                (<WatchOptions as fidl::encoding::ValueTypeMarker>::borrow(&self.options),),
505                encoder,
506                offset,
507                _depth,
508            )
509        }
510    }
511    unsafe impl<D: fidl::encoding::ResourceDialect, T0: fidl::encoding::Encode<WatchOptions, D>>
512        fidl::encoding::Encode<BatteryConfigureWatchRequest, D> for (T0,)
513    {
514        #[inline]
515        unsafe fn encode(
516            self,
517            encoder: &mut fidl::encoding::Encoder<'_, D>,
518            offset: usize,
519            depth: fidl::encoding::Depth,
520        ) -> fidl::Result<()> {
521            encoder.debug_check_bounds::<BatteryConfigureWatchRequest>(offset);
522            // Zero out padding regions. There's no need to apply masks
523            // because the unmasked parts will be overwritten by fields.
524            // Write the fields.
525            self.0.encode(encoder, offset + 0, depth)?;
526            Ok(())
527        }
528    }
529
530    impl<D: fidl::encoding::ResourceDialect> fidl::encoding::Decode<Self, D>
531        for BatteryConfigureWatchRequest
532    {
533        #[inline(always)]
534        fn new_empty() -> Self {
535            Self { options: fidl::new_empty!(WatchOptions, D) }
536        }
537
538        #[inline]
539        unsafe fn decode(
540            &mut self,
541            decoder: &mut fidl::encoding::Decoder<'_, D>,
542            offset: usize,
543            _depth: fidl::encoding::Depth,
544        ) -> fidl::Result<()> {
545            decoder.debug_check_bounds::<Self>(offset);
546            // Verify that padding bytes are zero.
547            fidl::decode!(WatchOptions, D, &mut self.options, decoder, offset + 0, _depth)?;
548            Ok(())
549        }
550    }
551
552    impl fidl::encoding::ValueTypeMarker for BatteryConfigureWatchResponse {
553        type Borrowed<'a> = &'a Self;
554        fn borrow(value: &<Self as fidl::encoding::TypeMarker>::Owned) -> Self::Borrowed<'_> {
555            value
556        }
557    }
558
559    unsafe impl fidl::encoding::TypeMarker for BatteryConfigureWatchResponse {
560        type Owned = Self;
561
562        #[inline(always)]
563        fn inline_align(_context: fidl::encoding::Context) -> usize {
564            8
565        }
566
567        #[inline(always)]
568        fn inline_size(_context: fidl::encoding::Context) -> usize {
569            16
570        }
571    }
572
573    unsafe impl<D: fidl::encoding::ResourceDialect>
574        fidl::encoding::Encode<BatteryConfigureWatchResponse, D>
575        for &BatteryConfigureWatchResponse
576    {
577        #[inline]
578        unsafe fn encode(
579            self,
580            encoder: &mut fidl::encoding::Encoder<'_, D>,
581            offset: usize,
582            _depth: fidl::encoding::Depth,
583        ) -> fidl::Result<()> {
584            encoder.debug_check_bounds::<BatteryConfigureWatchResponse>(offset);
585            // Delegate to tuple encoding.
586            fidl::encoding::Encode::<BatteryConfigureWatchResponse, D>::encode(
587                (<WatchOptions as fidl::encoding::ValueTypeMarker>::borrow(
588                    &self.effective_options,
589                ),),
590                encoder,
591                offset,
592                _depth,
593            )
594        }
595    }
596    unsafe impl<D: fidl::encoding::ResourceDialect, T0: fidl::encoding::Encode<WatchOptions, D>>
597        fidl::encoding::Encode<BatteryConfigureWatchResponse, D> for (T0,)
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::<BatteryConfigureWatchResponse>(offset);
607            // Zero out padding regions. There's no need to apply masks
608            // because the unmasked parts will be overwritten by fields.
609            // Write the fields.
610            self.0.encode(encoder, offset + 0, depth)?;
611            Ok(())
612        }
613    }
614
615    impl<D: fidl::encoding::ResourceDialect> fidl::encoding::Decode<Self, D>
616        for BatteryConfigureWatchResponse
617    {
618        #[inline(always)]
619        fn new_empty() -> Self {
620            Self { effective_options: fidl::new_empty!(WatchOptions, D) }
621        }
622
623        #[inline]
624        unsafe fn decode(
625            &mut self,
626            decoder: &mut fidl::encoding::Decoder<'_, D>,
627            offset: usize,
628            _depth: fidl::encoding::Depth,
629        ) -> fidl::Result<()> {
630            decoder.debug_check_bounds::<Self>(offset);
631            // Verify that padding bytes are zero.
632            fidl::decode!(
633                WatchOptions,
634                D,
635                &mut self.effective_options,
636                decoder,
637                offset + 0,
638                _depth
639            )?;
640            Ok(())
641        }
642    }
643
644    impl fidl::encoding::ValueTypeMarker for BatteryGetSpecResponse {
645        type Borrowed<'a> = &'a Self;
646        fn borrow(value: &<Self as fidl::encoding::TypeMarker>::Owned) -> Self::Borrowed<'_> {
647            value
648        }
649    }
650
651    unsafe impl fidl::encoding::TypeMarker for BatteryGetSpecResponse {
652        type Owned = Self;
653
654        #[inline(always)]
655        fn inline_align(_context: fidl::encoding::Context) -> usize {
656            8
657        }
658
659        #[inline(always)]
660        fn inline_size(_context: fidl::encoding::Context) -> usize {
661            16
662        }
663    }
664
665    unsafe impl<D: fidl::encoding::ResourceDialect>
666        fidl::encoding::Encode<BatteryGetSpecResponse, D> for &BatteryGetSpecResponse
667    {
668        #[inline]
669        unsafe fn encode(
670            self,
671            encoder: &mut fidl::encoding::Encoder<'_, D>,
672            offset: usize,
673            _depth: fidl::encoding::Depth,
674        ) -> fidl::Result<()> {
675            encoder.debug_check_bounds::<BatteryGetSpecResponse>(offset);
676            // Delegate to tuple encoding.
677            fidl::encoding::Encode::<BatteryGetSpecResponse, D>::encode(
678                (<Spec as fidl::encoding::ValueTypeMarker>::borrow(&self.spec),),
679                encoder,
680                offset,
681                _depth,
682            )
683        }
684    }
685    unsafe impl<D: fidl::encoding::ResourceDialect, T0: fidl::encoding::Encode<Spec, D>>
686        fidl::encoding::Encode<BatteryGetSpecResponse, D> for (T0,)
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::<BatteryGetSpecResponse>(offset);
696            // Zero out padding regions. There's no need to apply masks
697            // because the unmasked parts will be overwritten by fields.
698            // Write the fields.
699            self.0.encode(encoder, offset + 0, depth)?;
700            Ok(())
701        }
702    }
703
704    impl<D: fidl::encoding::ResourceDialect> fidl::encoding::Decode<Self, D>
705        for BatteryGetSpecResponse
706    {
707        #[inline(always)]
708        fn new_empty() -> Self {
709            Self { spec: fidl::new_empty!(Spec, D) }
710        }
711
712        #[inline]
713        unsafe fn decode(
714            &mut self,
715            decoder: &mut fidl::encoding::Decoder<'_, D>,
716            offset: usize,
717            _depth: fidl::encoding::Depth,
718        ) -> fidl::Result<()> {
719            decoder.debug_check_bounds::<Self>(offset);
720            // Verify that padding bytes are zero.
721            fidl::decode!(Spec, D, &mut self.spec, decoder, offset + 0, _depth)?;
722            Ok(())
723        }
724    }
725
726    impl fidl::encoding::ValueTypeMarker for BatteryGetStatusResponse {
727        type Borrowed<'a> = &'a Self;
728        fn borrow(value: &<Self as fidl::encoding::TypeMarker>::Owned) -> Self::Borrowed<'_> {
729            value
730        }
731    }
732
733    unsafe impl fidl::encoding::TypeMarker for BatteryGetStatusResponse {
734        type Owned = Self;
735
736        #[inline(always)]
737        fn inline_align(_context: fidl::encoding::Context) -> usize {
738            8
739        }
740
741        #[inline(always)]
742        fn inline_size(_context: fidl::encoding::Context) -> usize {
743            16
744        }
745    }
746
747    unsafe impl<D: fidl::encoding::ResourceDialect>
748        fidl::encoding::Encode<BatteryGetStatusResponse, D> for &BatteryGetStatusResponse
749    {
750        #[inline]
751        unsafe fn encode(
752            self,
753            encoder: &mut fidl::encoding::Encoder<'_, D>,
754            offset: usize,
755            _depth: fidl::encoding::Depth,
756        ) -> fidl::Result<()> {
757            encoder.debug_check_bounds::<BatteryGetStatusResponse>(offset);
758            // Delegate to tuple encoding.
759            fidl::encoding::Encode::<BatteryGetStatusResponse, D>::encode(
760                (<Status as fidl::encoding::ValueTypeMarker>::borrow(&self.status),),
761                encoder,
762                offset,
763                _depth,
764            )
765        }
766    }
767    unsafe impl<D: fidl::encoding::ResourceDialect, T0: fidl::encoding::Encode<Status, D>>
768        fidl::encoding::Encode<BatteryGetStatusResponse, D> for (T0,)
769    {
770        #[inline]
771        unsafe fn encode(
772            self,
773            encoder: &mut fidl::encoding::Encoder<'_, D>,
774            offset: usize,
775            depth: fidl::encoding::Depth,
776        ) -> fidl::Result<()> {
777            encoder.debug_check_bounds::<BatteryGetStatusResponse>(offset);
778            // Zero out padding regions. There's no need to apply masks
779            // because the unmasked parts will be overwritten by fields.
780            // Write the fields.
781            self.0.encode(encoder, offset + 0, depth)?;
782            Ok(())
783        }
784    }
785
786    impl<D: fidl::encoding::ResourceDialect> fidl::encoding::Decode<Self, D>
787        for BatteryGetStatusResponse
788    {
789        #[inline(always)]
790        fn new_empty() -> Self {
791            Self { status: fidl::new_empty!(Status, D) }
792        }
793
794        #[inline]
795        unsafe fn decode(
796            &mut self,
797            decoder: &mut fidl::encoding::Decoder<'_, D>,
798            offset: usize,
799            _depth: fidl::encoding::Depth,
800        ) -> fidl::Result<()> {
801            decoder.debug_check_bounds::<Self>(offset);
802            // Verify that padding bytes are zero.
803            fidl::decode!(Status, D, &mut self.status, decoder, offset + 0, _depth)?;
804            Ok(())
805        }
806    }
807
808    impl Spec {
809        #[inline(always)]
810        fn max_ordinal_present(&self) -> u64 {
811            if let Some(_) = self.supported_options {
812                return 5;
813            }
814            if let Some(_) = self.model {
815                return 4;
816            }
817            if let Some(_) = self.chemistry {
818                return 3;
819            }
820            if let Some(_) = self.design_voltage_uv {
821                return 2;
822            }
823            if let Some(_) = self.design_capacity_uah {
824                return 1;
825            }
826            0
827        }
828    }
829
830    impl fidl::encoding::ValueTypeMarker for Spec {
831        type Borrowed<'a> = &'a Self;
832        fn borrow(value: &<Self as fidl::encoding::TypeMarker>::Owned) -> Self::Borrowed<'_> {
833            value
834        }
835    }
836
837    unsafe impl fidl::encoding::TypeMarker for Spec {
838        type Owned = Self;
839
840        #[inline(always)]
841        fn inline_align(_context: fidl::encoding::Context) -> usize {
842            8
843        }
844
845        #[inline(always)]
846        fn inline_size(_context: fidl::encoding::Context) -> usize {
847            16
848        }
849    }
850
851    unsafe impl<D: fidl::encoding::ResourceDialect> fidl::encoding::Encode<Spec, D> for &Spec {
852        unsafe fn encode(
853            self,
854            encoder: &mut fidl::encoding::Encoder<'_, D>,
855            offset: usize,
856            mut depth: fidl::encoding::Depth,
857        ) -> fidl::Result<()> {
858            encoder.debug_check_bounds::<Spec>(offset);
859            // Vector header
860            let max_ordinal: u64 = self.max_ordinal_present();
861            encoder.write_num(max_ordinal, offset);
862            encoder.write_num(fidl::encoding::ALLOC_PRESENT_U64, offset + 8);
863            // Calling encoder.out_of_line_offset(0) is not allowed.
864            if max_ordinal == 0 {
865                return Ok(());
866            }
867            depth.increment()?;
868            let envelope_size = 8;
869            let bytes_len = max_ordinal as usize * envelope_size;
870            #[allow(unused_variables)]
871            let offset = encoder.out_of_line_offset(bytes_len);
872            let mut _prev_end_offset: usize = 0;
873            if 1 > max_ordinal {
874                return Ok(());
875            }
876
877            // Write at offset+(ordinal-1)*envelope_size, since ordinals are one-based and envelopes
878            // are envelope_size bytes.
879            let cur_offset: usize = (1 - 1) * envelope_size;
880
881            // Zero reserved fields.
882            encoder.padding(offset + _prev_end_offset, cur_offset - _prev_end_offset);
883
884            // Safety:
885            // - bytes_len is calculated to fit envelope_size*max(member.ordinal).
886            // - Since cur_offset is envelope_size*(member.ordinal - 1) and the envelope takes
887            //   envelope_size bytes, there is always sufficient room.
888            fidl::encoding::encode_in_envelope_optional::<u32, D>(
889                self.design_capacity_uah
890                    .as_ref()
891                    .map(<u32 as fidl::encoding::ValueTypeMarker>::borrow),
892                encoder,
893                offset + cur_offset,
894                depth,
895            )?;
896
897            _prev_end_offset = cur_offset + envelope_size;
898            if 2 > max_ordinal {
899                return Ok(());
900            }
901
902            // Write at offset+(ordinal-1)*envelope_size, since ordinals are one-based and envelopes
903            // are envelope_size bytes.
904            let cur_offset: usize = (2 - 1) * envelope_size;
905
906            // Zero reserved fields.
907            encoder.padding(offset + _prev_end_offset, cur_offset - _prev_end_offset);
908
909            // Safety:
910            // - bytes_len is calculated to fit envelope_size*max(member.ordinal).
911            // - Since cur_offset is envelope_size*(member.ordinal - 1) and the envelope takes
912            //   envelope_size bytes, there is always sufficient room.
913            fidl::encoding::encode_in_envelope_optional::<u32, D>(
914                self.design_voltage_uv
915                    .as_ref()
916                    .map(<u32 as fidl::encoding::ValueTypeMarker>::borrow),
917                encoder,
918                offset + cur_offset,
919                depth,
920            )?;
921
922            _prev_end_offset = cur_offset + envelope_size;
923            if 3 > max_ordinal {
924                return Ok(());
925            }
926
927            // Write at offset+(ordinal-1)*envelope_size, since ordinals are one-based and envelopes
928            // are envelope_size bytes.
929            let cur_offset: usize = (3 - 1) * envelope_size;
930
931            // Zero reserved fields.
932            encoder.padding(offset + _prev_end_offset, cur_offset - _prev_end_offset);
933
934            // Safety:
935            // - bytes_len is calculated to fit envelope_size*max(member.ordinal).
936            // - Since cur_offset is envelope_size*(member.ordinal - 1) and the envelope takes
937            //   envelope_size bytes, there is always sufficient room.
938            fidl::encoding::encode_in_envelope_optional::<fidl::encoding::BoundedString<128>, D>(
939                self.chemistry.as_ref().map(
940                    <fidl::encoding::BoundedString<128> as fidl::encoding::ValueTypeMarker>::borrow,
941                ),
942                encoder,
943                offset + cur_offset,
944                depth,
945            )?;
946
947            _prev_end_offset = cur_offset + envelope_size;
948            if 4 > max_ordinal {
949                return Ok(());
950            }
951
952            // Write at offset+(ordinal-1)*envelope_size, since ordinals are one-based and envelopes
953            // are envelope_size bytes.
954            let cur_offset: usize = (4 - 1) * envelope_size;
955
956            // Zero reserved fields.
957            encoder.padding(offset + _prev_end_offset, cur_offset - _prev_end_offset);
958
959            // Safety:
960            // - bytes_len is calculated to fit envelope_size*max(member.ordinal).
961            // - Since cur_offset is envelope_size*(member.ordinal - 1) and the envelope takes
962            //   envelope_size bytes, there is always sufficient room.
963            fidl::encoding::encode_in_envelope_optional::<fidl::encoding::BoundedString<128>, D>(
964                self.model.as_ref().map(
965                    <fidl::encoding::BoundedString<128> as fidl::encoding::ValueTypeMarker>::borrow,
966                ),
967                encoder,
968                offset + cur_offset,
969                depth,
970            )?;
971
972            _prev_end_offset = cur_offset + envelope_size;
973            if 5 > max_ordinal {
974                return Ok(());
975            }
976
977            // Write at offset+(ordinal-1)*envelope_size, since ordinals are one-based and envelopes
978            // are envelope_size bytes.
979            let cur_offset: usize = (5 - 1) * envelope_size;
980
981            // Zero reserved fields.
982            encoder.padding(offset + _prev_end_offset, cur_offset - _prev_end_offset);
983
984            // Safety:
985            // - bytes_len is calculated to fit envelope_size*max(member.ordinal).
986            // - Since cur_offset is envelope_size*(member.ordinal - 1) and the envelope takes
987            //   envelope_size bytes, there is always sufficient room.
988            fidl::encoding::encode_in_envelope_optional::<WatchOptions, D>(
989                self.supported_options
990                    .as_ref()
991                    .map(<WatchOptions as fidl::encoding::ValueTypeMarker>::borrow),
992                encoder,
993                offset + cur_offset,
994                depth,
995            )?;
996
997            _prev_end_offset = cur_offset + envelope_size;
998
999            Ok(())
1000        }
1001    }
1002
1003    impl<D: fidl::encoding::ResourceDialect> fidl::encoding::Decode<Self, D> for Spec {
1004        #[inline(always)]
1005        fn new_empty() -> Self {
1006            Self::default()
1007        }
1008
1009        unsafe fn decode(
1010            &mut self,
1011            decoder: &mut fidl::encoding::Decoder<'_, D>,
1012            offset: usize,
1013            mut depth: fidl::encoding::Depth,
1014        ) -> fidl::Result<()> {
1015            decoder.debug_check_bounds::<Self>(offset);
1016            let len = match fidl::encoding::decode_vector_header(decoder, offset)? {
1017                None => return Err(fidl::Error::NotNullable),
1018                Some(len) => len,
1019            };
1020            // Calling decoder.out_of_line_offset(0) is not allowed.
1021            if len == 0 {
1022                return Ok(());
1023            };
1024            depth.increment()?;
1025            let envelope_size = 8;
1026            let bytes_len = len * envelope_size;
1027            let offset = decoder.out_of_line_offset(bytes_len)?;
1028            // Decode the envelope for each type.
1029            let mut _next_ordinal_to_read = 0;
1030            let mut next_offset = offset;
1031            let end_offset = offset + bytes_len;
1032            _next_ordinal_to_read += 1;
1033            if next_offset >= end_offset {
1034                return Ok(());
1035            }
1036
1037            // Decode unknown envelopes for gaps in ordinals.
1038            while _next_ordinal_to_read < 1 {
1039                fidl::encoding::decode_unknown_envelope(decoder, next_offset, depth)?;
1040                _next_ordinal_to_read += 1;
1041                next_offset += envelope_size;
1042            }
1043
1044            let next_out_of_line = decoder.next_out_of_line();
1045            let handles_before = decoder.remaining_handles();
1046            if let Some((inlined, num_bytes, num_handles)) =
1047                fidl::encoding::decode_envelope_header(decoder, next_offset)?
1048            {
1049                let member_inline_size =
1050                    <u32 as fidl::encoding::TypeMarker>::inline_size(decoder.context);
1051                if inlined != (member_inline_size <= 4) {
1052                    return Err(fidl::Error::InvalidInlineBitInEnvelope);
1053                }
1054                let inner_offset;
1055                let mut inner_depth = depth.clone();
1056                if inlined {
1057                    decoder.check_inline_envelope_padding(next_offset, member_inline_size)?;
1058                    inner_offset = next_offset;
1059                } else {
1060                    inner_offset = decoder.out_of_line_offset(member_inline_size)?;
1061                    inner_depth.increment()?;
1062                }
1063                let val_ref =
1064                    self.design_capacity_uah.get_or_insert_with(|| fidl::new_empty!(u32, D));
1065                fidl::decode!(u32, D, val_ref, decoder, inner_offset, inner_depth)?;
1066                if !inlined && decoder.next_out_of_line() != next_out_of_line + (num_bytes as usize)
1067                {
1068                    return Err(fidl::Error::InvalidNumBytesInEnvelope);
1069                }
1070                if handles_before != decoder.remaining_handles() + (num_handles as usize) {
1071                    return Err(fidl::Error::InvalidNumHandlesInEnvelope);
1072                }
1073            }
1074
1075            next_offset += envelope_size;
1076            _next_ordinal_to_read += 1;
1077            if next_offset >= end_offset {
1078                return Ok(());
1079            }
1080
1081            // Decode unknown envelopes for gaps in ordinals.
1082            while _next_ordinal_to_read < 2 {
1083                fidl::encoding::decode_unknown_envelope(decoder, next_offset, depth)?;
1084                _next_ordinal_to_read += 1;
1085                next_offset += envelope_size;
1086            }
1087
1088            let next_out_of_line = decoder.next_out_of_line();
1089            let handles_before = decoder.remaining_handles();
1090            if let Some((inlined, num_bytes, num_handles)) =
1091                fidl::encoding::decode_envelope_header(decoder, next_offset)?
1092            {
1093                let member_inline_size =
1094                    <u32 as fidl::encoding::TypeMarker>::inline_size(decoder.context);
1095                if inlined != (member_inline_size <= 4) {
1096                    return Err(fidl::Error::InvalidInlineBitInEnvelope);
1097                }
1098                let inner_offset;
1099                let mut inner_depth = depth.clone();
1100                if inlined {
1101                    decoder.check_inline_envelope_padding(next_offset, member_inline_size)?;
1102                    inner_offset = next_offset;
1103                } else {
1104                    inner_offset = decoder.out_of_line_offset(member_inline_size)?;
1105                    inner_depth.increment()?;
1106                }
1107                let val_ref =
1108                    self.design_voltage_uv.get_or_insert_with(|| fidl::new_empty!(u32, D));
1109                fidl::decode!(u32, D, val_ref, decoder, inner_offset, inner_depth)?;
1110                if !inlined && decoder.next_out_of_line() != next_out_of_line + (num_bytes as usize)
1111                {
1112                    return Err(fidl::Error::InvalidNumBytesInEnvelope);
1113                }
1114                if handles_before != decoder.remaining_handles() + (num_handles as usize) {
1115                    return Err(fidl::Error::InvalidNumHandlesInEnvelope);
1116                }
1117            }
1118
1119            next_offset += envelope_size;
1120            _next_ordinal_to_read += 1;
1121            if next_offset >= end_offset {
1122                return Ok(());
1123            }
1124
1125            // Decode unknown envelopes for gaps in ordinals.
1126            while _next_ordinal_to_read < 3 {
1127                fidl::encoding::decode_unknown_envelope(decoder, next_offset, depth)?;
1128                _next_ordinal_to_read += 1;
1129                next_offset += envelope_size;
1130            }
1131
1132            let next_out_of_line = decoder.next_out_of_line();
1133            let handles_before = decoder.remaining_handles();
1134            if let Some((inlined, num_bytes, num_handles)) =
1135                fidl::encoding::decode_envelope_header(decoder, next_offset)?
1136            {
1137                let member_inline_size =
1138                    <fidl::encoding::BoundedString<128> as fidl::encoding::TypeMarker>::inline_size(
1139                        decoder.context,
1140                    );
1141                if inlined != (member_inline_size <= 4) {
1142                    return Err(fidl::Error::InvalidInlineBitInEnvelope);
1143                }
1144                let inner_offset;
1145                let mut inner_depth = depth.clone();
1146                if inlined {
1147                    decoder.check_inline_envelope_padding(next_offset, member_inline_size)?;
1148                    inner_offset = next_offset;
1149                } else {
1150                    inner_offset = decoder.out_of_line_offset(member_inline_size)?;
1151                    inner_depth.increment()?;
1152                }
1153                let val_ref = self
1154                    .chemistry
1155                    .get_or_insert_with(|| fidl::new_empty!(fidl::encoding::BoundedString<128>, D));
1156                fidl::decode!(
1157                    fidl::encoding::BoundedString<128>,
1158                    D,
1159                    val_ref,
1160                    decoder,
1161                    inner_offset,
1162                    inner_depth
1163                )?;
1164                if !inlined && decoder.next_out_of_line() != next_out_of_line + (num_bytes as usize)
1165                {
1166                    return Err(fidl::Error::InvalidNumBytesInEnvelope);
1167                }
1168                if handles_before != decoder.remaining_handles() + (num_handles as usize) {
1169                    return Err(fidl::Error::InvalidNumHandlesInEnvelope);
1170                }
1171            }
1172
1173            next_offset += envelope_size;
1174            _next_ordinal_to_read += 1;
1175            if next_offset >= end_offset {
1176                return Ok(());
1177            }
1178
1179            // Decode unknown envelopes for gaps in ordinals.
1180            while _next_ordinal_to_read < 4 {
1181                fidl::encoding::decode_unknown_envelope(decoder, next_offset, depth)?;
1182                _next_ordinal_to_read += 1;
1183                next_offset += envelope_size;
1184            }
1185
1186            let next_out_of_line = decoder.next_out_of_line();
1187            let handles_before = decoder.remaining_handles();
1188            if let Some((inlined, num_bytes, num_handles)) =
1189                fidl::encoding::decode_envelope_header(decoder, next_offset)?
1190            {
1191                let member_inline_size =
1192                    <fidl::encoding::BoundedString<128> as fidl::encoding::TypeMarker>::inline_size(
1193                        decoder.context,
1194                    );
1195                if inlined != (member_inline_size <= 4) {
1196                    return Err(fidl::Error::InvalidInlineBitInEnvelope);
1197                }
1198                let inner_offset;
1199                let mut inner_depth = depth.clone();
1200                if inlined {
1201                    decoder.check_inline_envelope_padding(next_offset, member_inline_size)?;
1202                    inner_offset = next_offset;
1203                } else {
1204                    inner_offset = decoder.out_of_line_offset(member_inline_size)?;
1205                    inner_depth.increment()?;
1206                }
1207                let val_ref = self
1208                    .model
1209                    .get_or_insert_with(|| fidl::new_empty!(fidl::encoding::BoundedString<128>, D));
1210                fidl::decode!(
1211                    fidl::encoding::BoundedString<128>,
1212                    D,
1213                    val_ref,
1214                    decoder,
1215                    inner_offset,
1216                    inner_depth
1217                )?;
1218                if !inlined && decoder.next_out_of_line() != next_out_of_line + (num_bytes as usize)
1219                {
1220                    return Err(fidl::Error::InvalidNumBytesInEnvelope);
1221                }
1222                if handles_before != decoder.remaining_handles() + (num_handles as usize) {
1223                    return Err(fidl::Error::InvalidNumHandlesInEnvelope);
1224                }
1225            }
1226
1227            next_offset += envelope_size;
1228            _next_ordinal_to_read += 1;
1229            if next_offset >= end_offset {
1230                return Ok(());
1231            }
1232
1233            // Decode unknown envelopes for gaps in ordinals.
1234            while _next_ordinal_to_read < 5 {
1235                fidl::encoding::decode_unknown_envelope(decoder, next_offset, depth)?;
1236                _next_ordinal_to_read += 1;
1237                next_offset += envelope_size;
1238            }
1239
1240            let next_out_of_line = decoder.next_out_of_line();
1241            let handles_before = decoder.remaining_handles();
1242            if let Some((inlined, num_bytes, num_handles)) =
1243                fidl::encoding::decode_envelope_header(decoder, next_offset)?
1244            {
1245                let member_inline_size =
1246                    <WatchOptions as fidl::encoding::TypeMarker>::inline_size(decoder.context);
1247                if inlined != (member_inline_size <= 4) {
1248                    return Err(fidl::Error::InvalidInlineBitInEnvelope);
1249                }
1250                let inner_offset;
1251                let mut inner_depth = depth.clone();
1252                if inlined {
1253                    decoder.check_inline_envelope_padding(next_offset, member_inline_size)?;
1254                    inner_offset = next_offset;
1255                } else {
1256                    inner_offset = decoder.out_of_line_offset(member_inline_size)?;
1257                    inner_depth.increment()?;
1258                }
1259                let val_ref =
1260                    self.supported_options.get_or_insert_with(|| fidl::new_empty!(WatchOptions, D));
1261                fidl::decode!(WatchOptions, D, val_ref, decoder, inner_offset, inner_depth)?;
1262                if !inlined && decoder.next_out_of_line() != next_out_of_line + (num_bytes as usize)
1263                {
1264                    return Err(fidl::Error::InvalidNumBytesInEnvelope);
1265                }
1266                if handles_before != decoder.remaining_handles() + (num_handles as usize) {
1267                    return Err(fidl::Error::InvalidNumHandlesInEnvelope);
1268                }
1269            }
1270
1271            next_offset += envelope_size;
1272
1273            // Decode the remaining unknown envelopes.
1274            while next_offset < end_offset {
1275                _next_ordinal_to_read += 1;
1276                fidl::encoding::decode_unknown_envelope(decoder, next_offset, depth)?;
1277                next_offset += envelope_size;
1278            }
1279
1280            Ok(())
1281        }
1282    }
1283
1284    impl Status {
1285        #[inline(always)]
1286        fn max_ordinal_present(&self) -> u64 {
1287            if let Some(_) = self.time_remaining {
1288                return 10;
1289            }
1290            if let Some(_) = self.cycle_count {
1291                return 9;
1292            }
1293            if let Some(_) = self.health {
1294                return 8;
1295            }
1296            if let Some(_) = self.full_charge_capacity_uah {
1297                return 7;
1298            }
1299            if let Some(_) = self.remaining_capacity_uah {
1300                return 6;
1301            }
1302            if let Some(_) = self.temp_celsius {
1303                return 5;
1304            }
1305            if let Some(_) = self.level_percent {
1306                return 4;
1307            }
1308            if let Some(_) = self.current_ua {
1309                return 3;
1310            }
1311            if let Some(_) = self.voltage_uv {
1312                return 2;
1313            }
1314            if let Some(_) = self.present {
1315                return 1;
1316            }
1317            0
1318        }
1319    }
1320
1321    impl fidl::encoding::ValueTypeMarker for Status {
1322        type Borrowed<'a> = &'a Self;
1323        fn borrow(value: &<Self as fidl::encoding::TypeMarker>::Owned) -> Self::Borrowed<'_> {
1324            value
1325        }
1326    }
1327
1328    unsafe impl fidl::encoding::TypeMarker for Status {
1329        type Owned = Self;
1330
1331        #[inline(always)]
1332        fn inline_align(_context: fidl::encoding::Context) -> usize {
1333            8
1334        }
1335
1336        #[inline(always)]
1337        fn inline_size(_context: fidl::encoding::Context) -> usize {
1338            16
1339        }
1340    }
1341
1342    unsafe impl<D: fidl::encoding::ResourceDialect> fidl::encoding::Encode<Status, D> for &Status {
1343        unsafe fn encode(
1344            self,
1345            encoder: &mut fidl::encoding::Encoder<'_, D>,
1346            offset: usize,
1347            mut depth: fidl::encoding::Depth,
1348        ) -> fidl::Result<()> {
1349            encoder.debug_check_bounds::<Status>(offset);
1350            // Vector header
1351            let max_ordinal: u64 = self.max_ordinal_present();
1352            encoder.write_num(max_ordinal, offset);
1353            encoder.write_num(fidl::encoding::ALLOC_PRESENT_U64, offset + 8);
1354            // Calling encoder.out_of_line_offset(0) is not allowed.
1355            if max_ordinal == 0 {
1356                return Ok(());
1357            }
1358            depth.increment()?;
1359            let envelope_size = 8;
1360            let bytes_len = max_ordinal as usize * envelope_size;
1361            #[allow(unused_variables)]
1362            let offset = encoder.out_of_line_offset(bytes_len);
1363            let mut _prev_end_offset: usize = 0;
1364            if 1 > max_ordinal {
1365                return Ok(());
1366            }
1367
1368            // Write at offset+(ordinal-1)*envelope_size, since ordinals are one-based and envelopes
1369            // are envelope_size bytes.
1370            let cur_offset: usize = (1 - 1) * envelope_size;
1371
1372            // Zero reserved fields.
1373            encoder.padding(offset + _prev_end_offset, cur_offset - _prev_end_offset);
1374
1375            // Safety:
1376            // - bytes_len is calculated to fit envelope_size*max(member.ordinal).
1377            // - Since cur_offset is envelope_size*(member.ordinal - 1) and the envelope takes
1378            //   envelope_size bytes, there is always sufficient room.
1379            fidl::encoding::encode_in_envelope_optional::<bool, D>(
1380                self.present.as_ref().map(<bool as fidl::encoding::ValueTypeMarker>::borrow),
1381                encoder,
1382                offset + cur_offset,
1383                depth,
1384            )?;
1385
1386            _prev_end_offset = cur_offset + envelope_size;
1387            if 2 > max_ordinal {
1388                return Ok(());
1389            }
1390
1391            // Write at offset+(ordinal-1)*envelope_size, since ordinals are one-based and envelopes
1392            // are envelope_size bytes.
1393            let cur_offset: usize = (2 - 1) * envelope_size;
1394
1395            // Zero reserved fields.
1396            encoder.padding(offset + _prev_end_offset, cur_offset - _prev_end_offset);
1397
1398            // Safety:
1399            // - bytes_len is calculated to fit envelope_size*max(member.ordinal).
1400            // - Since cur_offset is envelope_size*(member.ordinal - 1) and the envelope takes
1401            //   envelope_size bytes, there is always sufficient room.
1402            fidl::encoding::encode_in_envelope_optional::<u32, D>(
1403                self.voltage_uv.as_ref().map(<u32 as fidl::encoding::ValueTypeMarker>::borrow),
1404                encoder,
1405                offset + cur_offset,
1406                depth,
1407            )?;
1408
1409            _prev_end_offset = cur_offset + envelope_size;
1410            if 3 > max_ordinal {
1411                return Ok(());
1412            }
1413
1414            // Write at offset+(ordinal-1)*envelope_size, since ordinals are one-based and envelopes
1415            // are envelope_size bytes.
1416            let cur_offset: usize = (3 - 1) * envelope_size;
1417
1418            // Zero reserved fields.
1419            encoder.padding(offset + _prev_end_offset, cur_offset - _prev_end_offset);
1420
1421            // Safety:
1422            // - bytes_len is calculated to fit envelope_size*max(member.ordinal).
1423            // - Since cur_offset is envelope_size*(member.ordinal - 1) and the envelope takes
1424            //   envelope_size bytes, there is always sufficient room.
1425            fidl::encoding::encode_in_envelope_optional::<i32, D>(
1426                self.current_ua.as_ref().map(<i32 as fidl::encoding::ValueTypeMarker>::borrow),
1427                encoder,
1428                offset + cur_offset,
1429                depth,
1430            )?;
1431
1432            _prev_end_offset = cur_offset + envelope_size;
1433            if 4 > max_ordinal {
1434                return Ok(());
1435            }
1436
1437            // Write at offset+(ordinal-1)*envelope_size, since ordinals are one-based and envelopes
1438            // are envelope_size bytes.
1439            let cur_offset: usize = (4 - 1) * envelope_size;
1440
1441            // Zero reserved fields.
1442            encoder.padding(offset + _prev_end_offset, cur_offset - _prev_end_offset);
1443
1444            // Safety:
1445            // - bytes_len is calculated to fit envelope_size*max(member.ordinal).
1446            // - Since cur_offset is envelope_size*(member.ordinal - 1) and the envelope takes
1447            //   envelope_size bytes, there is always sufficient room.
1448            fidl::encoding::encode_in_envelope_optional::<f32, D>(
1449                self.level_percent.as_ref().map(<f32 as fidl::encoding::ValueTypeMarker>::borrow),
1450                encoder,
1451                offset + cur_offset,
1452                depth,
1453            )?;
1454
1455            _prev_end_offset = cur_offset + envelope_size;
1456            if 5 > max_ordinal {
1457                return Ok(());
1458            }
1459
1460            // Write at offset+(ordinal-1)*envelope_size, since ordinals are one-based and envelopes
1461            // are envelope_size bytes.
1462            let cur_offset: usize = (5 - 1) * envelope_size;
1463
1464            // Zero reserved fields.
1465            encoder.padding(offset + _prev_end_offset, cur_offset - _prev_end_offset);
1466
1467            // Safety:
1468            // - bytes_len is calculated to fit envelope_size*max(member.ordinal).
1469            // - Since cur_offset is envelope_size*(member.ordinal - 1) and the envelope takes
1470            //   envelope_size bytes, there is always sufficient room.
1471            fidl::encoding::encode_in_envelope_optional::<f32, D>(
1472                self.temp_celsius.as_ref().map(<f32 as fidl::encoding::ValueTypeMarker>::borrow),
1473                encoder,
1474                offset + cur_offset,
1475                depth,
1476            )?;
1477
1478            _prev_end_offset = cur_offset + envelope_size;
1479            if 6 > max_ordinal {
1480                return Ok(());
1481            }
1482
1483            // Write at offset+(ordinal-1)*envelope_size, since ordinals are one-based and envelopes
1484            // are envelope_size bytes.
1485            let cur_offset: usize = (6 - 1) * envelope_size;
1486
1487            // Zero reserved fields.
1488            encoder.padding(offset + _prev_end_offset, cur_offset - _prev_end_offset);
1489
1490            // Safety:
1491            // - bytes_len is calculated to fit envelope_size*max(member.ordinal).
1492            // - Since cur_offset is envelope_size*(member.ordinal - 1) and the envelope takes
1493            //   envelope_size bytes, there is always sufficient room.
1494            fidl::encoding::encode_in_envelope_optional::<u32, D>(
1495                self.remaining_capacity_uah
1496                    .as_ref()
1497                    .map(<u32 as fidl::encoding::ValueTypeMarker>::borrow),
1498                encoder,
1499                offset + cur_offset,
1500                depth,
1501            )?;
1502
1503            _prev_end_offset = cur_offset + envelope_size;
1504            if 7 > max_ordinal {
1505                return Ok(());
1506            }
1507
1508            // Write at offset+(ordinal-1)*envelope_size, since ordinals are one-based and envelopes
1509            // are envelope_size bytes.
1510            let cur_offset: usize = (7 - 1) * envelope_size;
1511
1512            // Zero reserved fields.
1513            encoder.padding(offset + _prev_end_offset, cur_offset - _prev_end_offset);
1514
1515            // Safety:
1516            // - bytes_len is calculated to fit envelope_size*max(member.ordinal).
1517            // - Since cur_offset is envelope_size*(member.ordinal - 1) and the envelope takes
1518            //   envelope_size bytes, there is always sufficient room.
1519            fidl::encoding::encode_in_envelope_optional::<u32, D>(
1520                self.full_charge_capacity_uah
1521                    .as_ref()
1522                    .map(<u32 as fidl::encoding::ValueTypeMarker>::borrow),
1523                encoder,
1524                offset + cur_offset,
1525                depth,
1526            )?;
1527
1528            _prev_end_offset = cur_offset + envelope_size;
1529            if 8 > max_ordinal {
1530                return Ok(());
1531            }
1532
1533            // Write at offset+(ordinal-1)*envelope_size, since ordinals are one-based and envelopes
1534            // are envelope_size bytes.
1535            let cur_offset: usize = (8 - 1) * envelope_size;
1536
1537            // Zero reserved fields.
1538            encoder.padding(offset + _prev_end_offset, cur_offset - _prev_end_offset);
1539
1540            // Safety:
1541            // - bytes_len is calculated to fit envelope_size*max(member.ordinal).
1542            // - Since cur_offset is envelope_size*(member.ordinal - 1) and the envelope takes
1543            //   envelope_size bytes, there is always sufficient room.
1544            fidl::encoding::encode_in_envelope_optional::<HealthStatus, D>(
1545                self.health.as_ref().map(<HealthStatus as fidl::encoding::ValueTypeMarker>::borrow),
1546                encoder,
1547                offset + cur_offset,
1548                depth,
1549            )?;
1550
1551            _prev_end_offset = cur_offset + envelope_size;
1552            if 9 > max_ordinal {
1553                return Ok(());
1554            }
1555
1556            // Write at offset+(ordinal-1)*envelope_size, since ordinals are one-based and envelopes
1557            // are envelope_size bytes.
1558            let cur_offset: usize = (9 - 1) * envelope_size;
1559
1560            // Zero reserved fields.
1561            encoder.padding(offset + _prev_end_offset, cur_offset - _prev_end_offset);
1562
1563            // Safety:
1564            // - bytes_len is calculated to fit envelope_size*max(member.ordinal).
1565            // - Since cur_offset is envelope_size*(member.ordinal - 1) and the envelope takes
1566            //   envelope_size bytes, there is always sufficient room.
1567            fidl::encoding::encode_in_envelope_optional::<u32, D>(
1568                self.cycle_count.as_ref().map(<u32 as fidl::encoding::ValueTypeMarker>::borrow),
1569                encoder,
1570                offset + cur_offset,
1571                depth,
1572            )?;
1573
1574            _prev_end_offset = cur_offset + envelope_size;
1575            if 10 > max_ordinal {
1576                return Ok(());
1577            }
1578
1579            // Write at offset+(ordinal-1)*envelope_size, since ordinals are one-based and envelopes
1580            // are envelope_size bytes.
1581            let cur_offset: usize = (10 - 1) * envelope_size;
1582
1583            // Zero reserved fields.
1584            encoder.padding(offset + _prev_end_offset, cur_offset - _prev_end_offset);
1585
1586            // Safety:
1587            // - bytes_len is calculated to fit envelope_size*max(member.ordinal).
1588            // - Since cur_offset is envelope_size*(member.ordinal - 1) and the envelope takes
1589            //   envelope_size bytes, there is always sufficient room.
1590            fidl::encoding::encode_in_envelope_optional::<i64, D>(
1591                self.time_remaining.as_ref().map(<i64 as fidl::encoding::ValueTypeMarker>::borrow),
1592                encoder,
1593                offset + cur_offset,
1594                depth,
1595            )?;
1596
1597            _prev_end_offset = cur_offset + envelope_size;
1598
1599            Ok(())
1600        }
1601    }
1602
1603    impl<D: fidl::encoding::ResourceDialect> fidl::encoding::Decode<Self, D> for Status {
1604        #[inline(always)]
1605        fn new_empty() -> Self {
1606            Self::default()
1607        }
1608
1609        unsafe fn decode(
1610            &mut self,
1611            decoder: &mut fidl::encoding::Decoder<'_, D>,
1612            offset: usize,
1613            mut depth: fidl::encoding::Depth,
1614        ) -> fidl::Result<()> {
1615            decoder.debug_check_bounds::<Self>(offset);
1616            let len = match fidl::encoding::decode_vector_header(decoder, offset)? {
1617                None => return Err(fidl::Error::NotNullable),
1618                Some(len) => len,
1619            };
1620            // Calling decoder.out_of_line_offset(0) is not allowed.
1621            if len == 0 {
1622                return Ok(());
1623            };
1624            depth.increment()?;
1625            let envelope_size = 8;
1626            let bytes_len = len * envelope_size;
1627            let offset = decoder.out_of_line_offset(bytes_len)?;
1628            // Decode the envelope for each type.
1629            let mut _next_ordinal_to_read = 0;
1630            let mut next_offset = offset;
1631            let end_offset = offset + bytes_len;
1632            _next_ordinal_to_read += 1;
1633            if next_offset >= end_offset {
1634                return Ok(());
1635            }
1636
1637            // Decode unknown envelopes for gaps in ordinals.
1638            while _next_ordinal_to_read < 1 {
1639                fidl::encoding::decode_unknown_envelope(decoder, next_offset, depth)?;
1640                _next_ordinal_to_read += 1;
1641                next_offset += envelope_size;
1642            }
1643
1644            let next_out_of_line = decoder.next_out_of_line();
1645            let handles_before = decoder.remaining_handles();
1646            if let Some((inlined, num_bytes, num_handles)) =
1647                fidl::encoding::decode_envelope_header(decoder, next_offset)?
1648            {
1649                let member_inline_size =
1650                    <bool as fidl::encoding::TypeMarker>::inline_size(decoder.context);
1651                if inlined != (member_inline_size <= 4) {
1652                    return Err(fidl::Error::InvalidInlineBitInEnvelope);
1653                }
1654                let inner_offset;
1655                let mut inner_depth = depth.clone();
1656                if inlined {
1657                    decoder.check_inline_envelope_padding(next_offset, member_inline_size)?;
1658                    inner_offset = next_offset;
1659                } else {
1660                    inner_offset = decoder.out_of_line_offset(member_inline_size)?;
1661                    inner_depth.increment()?;
1662                }
1663                let val_ref = self.present.get_or_insert_with(|| fidl::new_empty!(bool, D));
1664                fidl::decode!(bool, D, val_ref, decoder, inner_offset, inner_depth)?;
1665                if !inlined && decoder.next_out_of_line() != next_out_of_line + (num_bytes as usize)
1666                {
1667                    return Err(fidl::Error::InvalidNumBytesInEnvelope);
1668                }
1669                if handles_before != decoder.remaining_handles() + (num_handles as usize) {
1670                    return Err(fidl::Error::InvalidNumHandlesInEnvelope);
1671                }
1672            }
1673
1674            next_offset += envelope_size;
1675            _next_ordinal_to_read += 1;
1676            if next_offset >= end_offset {
1677                return Ok(());
1678            }
1679
1680            // Decode unknown envelopes for gaps in ordinals.
1681            while _next_ordinal_to_read < 2 {
1682                fidl::encoding::decode_unknown_envelope(decoder, next_offset, depth)?;
1683                _next_ordinal_to_read += 1;
1684                next_offset += envelope_size;
1685            }
1686
1687            let next_out_of_line = decoder.next_out_of_line();
1688            let handles_before = decoder.remaining_handles();
1689            if let Some((inlined, num_bytes, num_handles)) =
1690                fidl::encoding::decode_envelope_header(decoder, next_offset)?
1691            {
1692                let member_inline_size =
1693                    <u32 as fidl::encoding::TypeMarker>::inline_size(decoder.context);
1694                if inlined != (member_inline_size <= 4) {
1695                    return Err(fidl::Error::InvalidInlineBitInEnvelope);
1696                }
1697                let inner_offset;
1698                let mut inner_depth = depth.clone();
1699                if inlined {
1700                    decoder.check_inline_envelope_padding(next_offset, member_inline_size)?;
1701                    inner_offset = next_offset;
1702                } else {
1703                    inner_offset = decoder.out_of_line_offset(member_inline_size)?;
1704                    inner_depth.increment()?;
1705                }
1706                let val_ref = self.voltage_uv.get_or_insert_with(|| fidl::new_empty!(u32, D));
1707                fidl::decode!(u32, D, val_ref, decoder, inner_offset, inner_depth)?;
1708                if !inlined && decoder.next_out_of_line() != next_out_of_line + (num_bytes as usize)
1709                {
1710                    return Err(fidl::Error::InvalidNumBytesInEnvelope);
1711                }
1712                if handles_before != decoder.remaining_handles() + (num_handles as usize) {
1713                    return Err(fidl::Error::InvalidNumHandlesInEnvelope);
1714                }
1715            }
1716
1717            next_offset += envelope_size;
1718            _next_ordinal_to_read += 1;
1719            if next_offset >= end_offset {
1720                return Ok(());
1721            }
1722
1723            // Decode unknown envelopes for gaps in ordinals.
1724            while _next_ordinal_to_read < 3 {
1725                fidl::encoding::decode_unknown_envelope(decoder, next_offset, depth)?;
1726                _next_ordinal_to_read += 1;
1727                next_offset += envelope_size;
1728            }
1729
1730            let next_out_of_line = decoder.next_out_of_line();
1731            let handles_before = decoder.remaining_handles();
1732            if let Some((inlined, num_bytes, num_handles)) =
1733                fidl::encoding::decode_envelope_header(decoder, next_offset)?
1734            {
1735                let member_inline_size =
1736                    <i32 as fidl::encoding::TypeMarker>::inline_size(decoder.context);
1737                if inlined != (member_inline_size <= 4) {
1738                    return Err(fidl::Error::InvalidInlineBitInEnvelope);
1739                }
1740                let inner_offset;
1741                let mut inner_depth = depth.clone();
1742                if inlined {
1743                    decoder.check_inline_envelope_padding(next_offset, member_inline_size)?;
1744                    inner_offset = next_offset;
1745                } else {
1746                    inner_offset = decoder.out_of_line_offset(member_inline_size)?;
1747                    inner_depth.increment()?;
1748                }
1749                let val_ref = self.current_ua.get_or_insert_with(|| fidl::new_empty!(i32, D));
1750                fidl::decode!(i32, D, val_ref, decoder, inner_offset, inner_depth)?;
1751                if !inlined && decoder.next_out_of_line() != next_out_of_line + (num_bytes as usize)
1752                {
1753                    return Err(fidl::Error::InvalidNumBytesInEnvelope);
1754                }
1755                if handles_before != decoder.remaining_handles() + (num_handles as usize) {
1756                    return Err(fidl::Error::InvalidNumHandlesInEnvelope);
1757                }
1758            }
1759
1760            next_offset += envelope_size;
1761            _next_ordinal_to_read += 1;
1762            if next_offset >= end_offset {
1763                return Ok(());
1764            }
1765
1766            // Decode unknown envelopes for gaps in ordinals.
1767            while _next_ordinal_to_read < 4 {
1768                fidl::encoding::decode_unknown_envelope(decoder, next_offset, depth)?;
1769                _next_ordinal_to_read += 1;
1770                next_offset += envelope_size;
1771            }
1772
1773            let next_out_of_line = decoder.next_out_of_line();
1774            let handles_before = decoder.remaining_handles();
1775            if let Some((inlined, num_bytes, num_handles)) =
1776                fidl::encoding::decode_envelope_header(decoder, next_offset)?
1777            {
1778                let member_inline_size =
1779                    <f32 as fidl::encoding::TypeMarker>::inline_size(decoder.context);
1780                if inlined != (member_inline_size <= 4) {
1781                    return Err(fidl::Error::InvalidInlineBitInEnvelope);
1782                }
1783                let inner_offset;
1784                let mut inner_depth = depth.clone();
1785                if inlined {
1786                    decoder.check_inline_envelope_padding(next_offset, member_inline_size)?;
1787                    inner_offset = next_offset;
1788                } else {
1789                    inner_offset = decoder.out_of_line_offset(member_inline_size)?;
1790                    inner_depth.increment()?;
1791                }
1792                let val_ref = self.level_percent.get_or_insert_with(|| fidl::new_empty!(f32, D));
1793                fidl::decode!(f32, D, val_ref, decoder, inner_offset, inner_depth)?;
1794                if !inlined && decoder.next_out_of_line() != next_out_of_line + (num_bytes as usize)
1795                {
1796                    return Err(fidl::Error::InvalidNumBytesInEnvelope);
1797                }
1798                if handles_before != decoder.remaining_handles() + (num_handles as usize) {
1799                    return Err(fidl::Error::InvalidNumHandlesInEnvelope);
1800                }
1801            }
1802
1803            next_offset += envelope_size;
1804            _next_ordinal_to_read += 1;
1805            if next_offset >= end_offset {
1806                return Ok(());
1807            }
1808
1809            // Decode unknown envelopes for gaps in ordinals.
1810            while _next_ordinal_to_read < 5 {
1811                fidl::encoding::decode_unknown_envelope(decoder, next_offset, depth)?;
1812                _next_ordinal_to_read += 1;
1813                next_offset += envelope_size;
1814            }
1815
1816            let next_out_of_line = decoder.next_out_of_line();
1817            let handles_before = decoder.remaining_handles();
1818            if let Some((inlined, num_bytes, num_handles)) =
1819                fidl::encoding::decode_envelope_header(decoder, next_offset)?
1820            {
1821                let member_inline_size =
1822                    <f32 as fidl::encoding::TypeMarker>::inline_size(decoder.context);
1823                if inlined != (member_inline_size <= 4) {
1824                    return Err(fidl::Error::InvalidInlineBitInEnvelope);
1825                }
1826                let inner_offset;
1827                let mut inner_depth = depth.clone();
1828                if inlined {
1829                    decoder.check_inline_envelope_padding(next_offset, member_inline_size)?;
1830                    inner_offset = next_offset;
1831                } else {
1832                    inner_offset = decoder.out_of_line_offset(member_inline_size)?;
1833                    inner_depth.increment()?;
1834                }
1835                let val_ref = self.temp_celsius.get_or_insert_with(|| fidl::new_empty!(f32, D));
1836                fidl::decode!(f32, D, val_ref, decoder, inner_offset, inner_depth)?;
1837                if !inlined && decoder.next_out_of_line() != next_out_of_line + (num_bytes as usize)
1838                {
1839                    return Err(fidl::Error::InvalidNumBytesInEnvelope);
1840                }
1841                if handles_before != decoder.remaining_handles() + (num_handles as usize) {
1842                    return Err(fidl::Error::InvalidNumHandlesInEnvelope);
1843                }
1844            }
1845
1846            next_offset += envelope_size;
1847            _next_ordinal_to_read += 1;
1848            if next_offset >= end_offset {
1849                return Ok(());
1850            }
1851
1852            // Decode unknown envelopes for gaps in ordinals.
1853            while _next_ordinal_to_read < 6 {
1854                fidl::encoding::decode_unknown_envelope(decoder, next_offset, depth)?;
1855                _next_ordinal_to_read += 1;
1856                next_offset += envelope_size;
1857            }
1858
1859            let next_out_of_line = decoder.next_out_of_line();
1860            let handles_before = decoder.remaining_handles();
1861            if let Some((inlined, num_bytes, num_handles)) =
1862                fidl::encoding::decode_envelope_header(decoder, next_offset)?
1863            {
1864                let member_inline_size =
1865                    <u32 as fidl::encoding::TypeMarker>::inline_size(decoder.context);
1866                if inlined != (member_inline_size <= 4) {
1867                    return Err(fidl::Error::InvalidInlineBitInEnvelope);
1868                }
1869                let inner_offset;
1870                let mut inner_depth = depth.clone();
1871                if inlined {
1872                    decoder.check_inline_envelope_padding(next_offset, member_inline_size)?;
1873                    inner_offset = next_offset;
1874                } else {
1875                    inner_offset = decoder.out_of_line_offset(member_inline_size)?;
1876                    inner_depth.increment()?;
1877                }
1878                let val_ref =
1879                    self.remaining_capacity_uah.get_or_insert_with(|| fidl::new_empty!(u32, D));
1880                fidl::decode!(u32, D, val_ref, decoder, inner_offset, inner_depth)?;
1881                if !inlined && decoder.next_out_of_line() != next_out_of_line + (num_bytes as usize)
1882                {
1883                    return Err(fidl::Error::InvalidNumBytesInEnvelope);
1884                }
1885                if handles_before != decoder.remaining_handles() + (num_handles as usize) {
1886                    return Err(fidl::Error::InvalidNumHandlesInEnvelope);
1887                }
1888            }
1889
1890            next_offset += envelope_size;
1891            _next_ordinal_to_read += 1;
1892            if next_offset >= end_offset {
1893                return Ok(());
1894            }
1895
1896            // Decode unknown envelopes for gaps in ordinals.
1897            while _next_ordinal_to_read < 7 {
1898                fidl::encoding::decode_unknown_envelope(decoder, next_offset, depth)?;
1899                _next_ordinal_to_read += 1;
1900                next_offset += envelope_size;
1901            }
1902
1903            let next_out_of_line = decoder.next_out_of_line();
1904            let handles_before = decoder.remaining_handles();
1905            if let Some((inlined, num_bytes, num_handles)) =
1906                fidl::encoding::decode_envelope_header(decoder, next_offset)?
1907            {
1908                let member_inline_size =
1909                    <u32 as fidl::encoding::TypeMarker>::inline_size(decoder.context);
1910                if inlined != (member_inline_size <= 4) {
1911                    return Err(fidl::Error::InvalidInlineBitInEnvelope);
1912                }
1913                let inner_offset;
1914                let mut inner_depth = depth.clone();
1915                if inlined {
1916                    decoder.check_inline_envelope_padding(next_offset, member_inline_size)?;
1917                    inner_offset = next_offset;
1918                } else {
1919                    inner_offset = decoder.out_of_line_offset(member_inline_size)?;
1920                    inner_depth.increment()?;
1921                }
1922                let val_ref =
1923                    self.full_charge_capacity_uah.get_or_insert_with(|| fidl::new_empty!(u32, D));
1924                fidl::decode!(u32, D, val_ref, decoder, inner_offset, inner_depth)?;
1925                if !inlined && decoder.next_out_of_line() != next_out_of_line + (num_bytes as usize)
1926                {
1927                    return Err(fidl::Error::InvalidNumBytesInEnvelope);
1928                }
1929                if handles_before != decoder.remaining_handles() + (num_handles as usize) {
1930                    return Err(fidl::Error::InvalidNumHandlesInEnvelope);
1931                }
1932            }
1933
1934            next_offset += envelope_size;
1935            _next_ordinal_to_read += 1;
1936            if next_offset >= end_offset {
1937                return Ok(());
1938            }
1939
1940            // Decode unknown envelopes for gaps in ordinals.
1941            while _next_ordinal_to_read < 8 {
1942                fidl::encoding::decode_unknown_envelope(decoder, next_offset, depth)?;
1943                _next_ordinal_to_read += 1;
1944                next_offset += envelope_size;
1945            }
1946
1947            let next_out_of_line = decoder.next_out_of_line();
1948            let handles_before = decoder.remaining_handles();
1949            if let Some((inlined, num_bytes, num_handles)) =
1950                fidl::encoding::decode_envelope_header(decoder, next_offset)?
1951            {
1952                let member_inline_size =
1953                    <HealthStatus as fidl::encoding::TypeMarker>::inline_size(decoder.context);
1954                if inlined != (member_inline_size <= 4) {
1955                    return Err(fidl::Error::InvalidInlineBitInEnvelope);
1956                }
1957                let inner_offset;
1958                let mut inner_depth = depth.clone();
1959                if inlined {
1960                    decoder.check_inline_envelope_padding(next_offset, member_inline_size)?;
1961                    inner_offset = next_offset;
1962                } else {
1963                    inner_offset = decoder.out_of_line_offset(member_inline_size)?;
1964                    inner_depth.increment()?;
1965                }
1966                let val_ref = self.health.get_or_insert_with(|| fidl::new_empty!(HealthStatus, D));
1967                fidl::decode!(HealthStatus, D, val_ref, decoder, inner_offset, inner_depth)?;
1968                if !inlined && decoder.next_out_of_line() != next_out_of_line + (num_bytes as usize)
1969                {
1970                    return Err(fidl::Error::InvalidNumBytesInEnvelope);
1971                }
1972                if handles_before != decoder.remaining_handles() + (num_handles as usize) {
1973                    return Err(fidl::Error::InvalidNumHandlesInEnvelope);
1974                }
1975            }
1976
1977            next_offset += envelope_size;
1978            _next_ordinal_to_read += 1;
1979            if next_offset >= end_offset {
1980                return Ok(());
1981            }
1982
1983            // Decode unknown envelopes for gaps in ordinals.
1984            while _next_ordinal_to_read < 9 {
1985                fidl::encoding::decode_unknown_envelope(decoder, next_offset, depth)?;
1986                _next_ordinal_to_read += 1;
1987                next_offset += envelope_size;
1988            }
1989
1990            let next_out_of_line = decoder.next_out_of_line();
1991            let handles_before = decoder.remaining_handles();
1992            if let Some((inlined, num_bytes, num_handles)) =
1993                fidl::encoding::decode_envelope_header(decoder, next_offset)?
1994            {
1995                let member_inline_size =
1996                    <u32 as fidl::encoding::TypeMarker>::inline_size(decoder.context);
1997                if inlined != (member_inline_size <= 4) {
1998                    return Err(fidl::Error::InvalidInlineBitInEnvelope);
1999                }
2000                let inner_offset;
2001                let mut inner_depth = depth.clone();
2002                if inlined {
2003                    decoder.check_inline_envelope_padding(next_offset, member_inline_size)?;
2004                    inner_offset = next_offset;
2005                } else {
2006                    inner_offset = decoder.out_of_line_offset(member_inline_size)?;
2007                    inner_depth.increment()?;
2008                }
2009                let val_ref = self.cycle_count.get_or_insert_with(|| fidl::new_empty!(u32, D));
2010                fidl::decode!(u32, D, val_ref, decoder, inner_offset, inner_depth)?;
2011                if !inlined && decoder.next_out_of_line() != next_out_of_line + (num_bytes as usize)
2012                {
2013                    return Err(fidl::Error::InvalidNumBytesInEnvelope);
2014                }
2015                if handles_before != decoder.remaining_handles() + (num_handles as usize) {
2016                    return Err(fidl::Error::InvalidNumHandlesInEnvelope);
2017                }
2018            }
2019
2020            next_offset += envelope_size;
2021            _next_ordinal_to_read += 1;
2022            if next_offset >= end_offset {
2023                return Ok(());
2024            }
2025
2026            // Decode unknown envelopes for gaps in ordinals.
2027            while _next_ordinal_to_read < 10 {
2028                fidl::encoding::decode_unknown_envelope(decoder, next_offset, depth)?;
2029                _next_ordinal_to_read += 1;
2030                next_offset += envelope_size;
2031            }
2032
2033            let next_out_of_line = decoder.next_out_of_line();
2034            let handles_before = decoder.remaining_handles();
2035            if let Some((inlined, num_bytes, num_handles)) =
2036                fidl::encoding::decode_envelope_header(decoder, next_offset)?
2037            {
2038                let member_inline_size =
2039                    <i64 as fidl::encoding::TypeMarker>::inline_size(decoder.context);
2040                if inlined != (member_inline_size <= 4) {
2041                    return Err(fidl::Error::InvalidInlineBitInEnvelope);
2042                }
2043                let inner_offset;
2044                let mut inner_depth = depth.clone();
2045                if inlined {
2046                    decoder.check_inline_envelope_padding(next_offset, member_inline_size)?;
2047                    inner_offset = next_offset;
2048                } else {
2049                    inner_offset = decoder.out_of_line_offset(member_inline_size)?;
2050                    inner_depth.increment()?;
2051                }
2052                let val_ref = self.time_remaining.get_or_insert_with(|| fidl::new_empty!(i64, D));
2053                fidl::decode!(i64, D, val_ref, decoder, inner_offset, inner_depth)?;
2054                if !inlined && decoder.next_out_of_line() != next_out_of_line + (num_bytes as usize)
2055                {
2056                    return Err(fidl::Error::InvalidNumBytesInEnvelope);
2057                }
2058                if handles_before != decoder.remaining_handles() + (num_handles as usize) {
2059                    return Err(fidl::Error::InvalidNumHandlesInEnvelope);
2060                }
2061            }
2062
2063            next_offset += envelope_size;
2064
2065            // Decode the remaining unknown envelopes.
2066            while next_offset < end_offset {
2067                _next_ordinal_to_read += 1;
2068                fidl::encoding::decode_unknown_envelope(decoder, next_offset, depth)?;
2069                next_offset += envelope_size;
2070            }
2071
2072            Ok(())
2073        }
2074    }
2075
2076    impl WatchOptions {
2077        #[inline(always)]
2078        fn max_ordinal_present(&self) -> u64 {
2079            if let Some(_) = self.wake_on {
2080                return 2;
2081            }
2082            if let Some(_) = self.interest {
2083                return 1;
2084            }
2085            0
2086        }
2087    }
2088
2089    impl fidl::encoding::ValueTypeMarker for WatchOptions {
2090        type Borrowed<'a> = &'a Self;
2091        fn borrow(value: &<Self as fidl::encoding::TypeMarker>::Owned) -> Self::Borrowed<'_> {
2092            value
2093        }
2094    }
2095
2096    unsafe impl fidl::encoding::TypeMarker for WatchOptions {
2097        type Owned = Self;
2098
2099        #[inline(always)]
2100        fn inline_align(_context: fidl::encoding::Context) -> usize {
2101            8
2102        }
2103
2104        #[inline(always)]
2105        fn inline_size(_context: fidl::encoding::Context) -> usize {
2106            16
2107        }
2108    }
2109
2110    unsafe impl<D: fidl::encoding::ResourceDialect> fidl::encoding::Encode<WatchOptions, D>
2111        for &WatchOptions
2112    {
2113        unsafe fn encode(
2114            self,
2115            encoder: &mut fidl::encoding::Encoder<'_, D>,
2116            offset: usize,
2117            mut depth: fidl::encoding::Depth,
2118        ) -> fidl::Result<()> {
2119            encoder.debug_check_bounds::<WatchOptions>(offset);
2120            // Vector header
2121            let max_ordinal: u64 = self.max_ordinal_present();
2122            encoder.write_num(max_ordinal, offset);
2123            encoder.write_num(fidl::encoding::ALLOC_PRESENT_U64, offset + 8);
2124            // Calling encoder.out_of_line_offset(0) is not allowed.
2125            if max_ordinal == 0 {
2126                return Ok(());
2127            }
2128            depth.increment()?;
2129            let envelope_size = 8;
2130            let bytes_len = max_ordinal as usize * envelope_size;
2131            #[allow(unused_variables)]
2132            let offset = encoder.out_of_line_offset(bytes_len);
2133            let mut _prev_end_offset: usize = 0;
2134            if 1 > max_ordinal {
2135                return Ok(());
2136            }
2137
2138            // Write at offset+(ordinal-1)*envelope_size, since ordinals are one-based and envelopes
2139            // are envelope_size bytes.
2140            let cur_offset: usize = (1 - 1) * envelope_size;
2141
2142            // Zero reserved fields.
2143            encoder.padding(offset + _prev_end_offset, cur_offset - _prev_end_offset);
2144
2145            // Safety:
2146            // - bytes_len is calculated to fit envelope_size*max(member.ordinal).
2147            // - Since cur_offset is envelope_size*(member.ordinal - 1) and the envelope takes
2148            //   envelope_size bytes, there is always sufficient room.
2149            fidl::encoding::encode_in_envelope_optional::<Status, D>(
2150                self.interest.as_ref().map(<Status as fidl::encoding::ValueTypeMarker>::borrow),
2151                encoder,
2152                offset + cur_offset,
2153                depth,
2154            )?;
2155
2156            _prev_end_offset = cur_offset + envelope_size;
2157            if 2 > max_ordinal {
2158                return Ok(());
2159            }
2160
2161            // Write at offset+(ordinal-1)*envelope_size, since ordinals are one-based and envelopes
2162            // are envelope_size bytes.
2163            let cur_offset: usize = (2 - 1) * envelope_size;
2164
2165            // Zero reserved fields.
2166            encoder.padding(offset + _prev_end_offset, cur_offset - _prev_end_offset);
2167
2168            // Safety:
2169            // - bytes_len is calculated to fit envelope_size*max(member.ordinal).
2170            // - Since cur_offset is envelope_size*(member.ordinal - 1) and the envelope takes
2171            //   envelope_size bytes, there is always sufficient room.
2172            fidl::encoding::encode_in_envelope_optional::<Status, D>(
2173                self.wake_on.as_ref().map(<Status as fidl::encoding::ValueTypeMarker>::borrow),
2174                encoder,
2175                offset + cur_offset,
2176                depth,
2177            )?;
2178
2179            _prev_end_offset = cur_offset + envelope_size;
2180
2181            Ok(())
2182        }
2183    }
2184
2185    impl<D: fidl::encoding::ResourceDialect> fidl::encoding::Decode<Self, D> for WatchOptions {
2186        #[inline(always)]
2187        fn new_empty() -> Self {
2188            Self::default()
2189        }
2190
2191        unsafe fn decode(
2192            &mut self,
2193            decoder: &mut fidl::encoding::Decoder<'_, D>,
2194            offset: usize,
2195            mut depth: fidl::encoding::Depth,
2196        ) -> fidl::Result<()> {
2197            decoder.debug_check_bounds::<Self>(offset);
2198            let len = match fidl::encoding::decode_vector_header(decoder, offset)? {
2199                None => return Err(fidl::Error::NotNullable),
2200                Some(len) => len,
2201            };
2202            // Calling decoder.out_of_line_offset(0) is not allowed.
2203            if len == 0 {
2204                return Ok(());
2205            };
2206            depth.increment()?;
2207            let envelope_size = 8;
2208            let bytes_len = len * envelope_size;
2209            let offset = decoder.out_of_line_offset(bytes_len)?;
2210            // Decode the envelope for each type.
2211            let mut _next_ordinal_to_read = 0;
2212            let mut next_offset = offset;
2213            let end_offset = offset + bytes_len;
2214            _next_ordinal_to_read += 1;
2215            if next_offset >= end_offset {
2216                return Ok(());
2217            }
2218
2219            // Decode unknown envelopes for gaps in ordinals.
2220            while _next_ordinal_to_read < 1 {
2221                fidl::encoding::decode_unknown_envelope(decoder, next_offset, depth)?;
2222                _next_ordinal_to_read += 1;
2223                next_offset += envelope_size;
2224            }
2225
2226            let next_out_of_line = decoder.next_out_of_line();
2227            let handles_before = decoder.remaining_handles();
2228            if let Some((inlined, num_bytes, num_handles)) =
2229                fidl::encoding::decode_envelope_header(decoder, next_offset)?
2230            {
2231                let member_inline_size =
2232                    <Status as fidl::encoding::TypeMarker>::inline_size(decoder.context);
2233                if inlined != (member_inline_size <= 4) {
2234                    return Err(fidl::Error::InvalidInlineBitInEnvelope);
2235                }
2236                let inner_offset;
2237                let mut inner_depth = depth.clone();
2238                if inlined {
2239                    decoder.check_inline_envelope_padding(next_offset, member_inline_size)?;
2240                    inner_offset = next_offset;
2241                } else {
2242                    inner_offset = decoder.out_of_line_offset(member_inline_size)?;
2243                    inner_depth.increment()?;
2244                }
2245                let val_ref = self.interest.get_or_insert_with(|| fidl::new_empty!(Status, D));
2246                fidl::decode!(Status, D, val_ref, decoder, inner_offset, inner_depth)?;
2247                if !inlined && decoder.next_out_of_line() != next_out_of_line + (num_bytes as usize)
2248                {
2249                    return Err(fidl::Error::InvalidNumBytesInEnvelope);
2250                }
2251                if handles_before != decoder.remaining_handles() + (num_handles as usize) {
2252                    return Err(fidl::Error::InvalidNumHandlesInEnvelope);
2253                }
2254            }
2255
2256            next_offset += envelope_size;
2257            _next_ordinal_to_read += 1;
2258            if next_offset >= end_offset {
2259                return Ok(());
2260            }
2261
2262            // Decode unknown envelopes for gaps in ordinals.
2263            while _next_ordinal_to_read < 2 {
2264                fidl::encoding::decode_unknown_envelope(decoder, next_offset, depth)?;
2265                _next_ordinal_to_read += 1;
2266                next_offset += envelope_size;
2267            }
2268
2269            let next_out_of_line = decoder.next_out_of_line();
2270            let handles_before = decoder.remaining_handles();
2271            if let Some((inlined, num_bytes, num_handles)) =
2272                fidl::encoding::decode_envelope_header(decoder, next_offset)?
2273            {
2274                let member_inline_size =
2275                    <Status as fidl::encoding::TypeMarker>::inline_size(decoder.context);
2276                if inlined != (member_inline_size <= 4) {
2277                    return Err(fidl::Error::InvalidInlineBitInEnvelope);
2278                }
2279                let inner_offset;
2280                let mut inner_depth = depth.clone();
2281                if inlined {
2282                    decoder.check_inline_envelope_padding(next_offset, member_inline_size)?;
2283                    inner_offset = next_offset;
2284                } else {
2285                    inner_offset = decoder.out_of_line_offset(member_inline_size)?;
2286                    inner_depth.increment()?;
2287                }
2288                let val_ref = self.wake_on.get_or_insert_with(|| fidl::new_empty!(Status, D));
2289                fidl::decode!(Status, D, val_ref, decoder, inner_offset, inner_depth)?;
2290                if !inlined && decoder.next_out_of_line() != next_out_of_line + (num_bytes as usize)
2291                {
2292                    return Err(fidl::Error::InvalidNumBytesInEnvelope);
2293                }
2294                if handles_before != decoder.remaining_handles() + (num_handles as usize) {
2295                    return Err(fidl::Error::InvalidNumHandlesInEnvelope);
2296                }
2297            }
2298
2299            next_offset += envelope_size;
2300
2301            // Decode the remaining unknown envelopes.
2302            while next_offset < end_offset {
2303                _next_ordinal_to_read += 1;
2304                fidl::encoding::decode_unknown_envelope(decoder, next_offset, depth)?;
2305                next_offset += envelope_size;
2306            }
2307
2308            Ok(())
2309        }
2310    }
2311}