fidl_fuchsia_hardware_hrtimer__common/
fidl_fuchsia_hardware_hrtimer__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/// Maximum count of resolutions supported by a given timer, arbitrary.
12pub const MAX_COUNT_RESOLUTIONS: u32 = 64;
13
14/// Maximum count of timers supported by this protocol, arbitrary.
15pub const MAX_COUNT_TIMERS: u32 = 64;
16
17/// Errors that this driver may return.
18#[derive(Copy, Clone, Debug, Eq, PartialEq, Ord, PartialOrd, Hash)]
19pub enum DriverError {
20    /// The driver encountered an otherwise unspecified error while performing the operation.
21    InternalError,
22    /// The operation is not implemented, supported, or enabled.
23    NotSupported,
24    /// An argument is invalid.
25    InvalidArgs,
26    /// The operation failed because the current state of the driver does not allow it, or a
27    /// precondition of the operation is not satisfied.
28    BadState,
29    /// The in-progress operation has been canceled.
30    Canceled,
31    #[doc(hidden)]
32    __SourceBreaking { unknown_ordinal: u32 },
33}
34
35/// Pattern that matches an unknown `DriverError` member.
36#[macro_export]
37macro_rules! DriverErrorUnknown {
38    () => {
39        _
40    };
41}
42
43impl DriverError {
44    #[inline]
45    pub fn from_primitive(prim: u32) -> Option<Self> {
46        match prim {
47            1 => Some(Self::InternalError),
48            2 => Some(Self::NotSupported),
49            3 => Some(Self::InvalidArgs),
50            4 => Some(Self::BadState),
51            5 => Some(Self::Canceled),
52            _ => None,
53        }
54    }
55
56    #[inline]
57    pub fn from_primitive_allow_unknown(prim: u32) -> Self {
58        match prim {
59            1 => Self::InternalError,
60            2 => Self::NotSupported,
61            3 => Self::InvalidArgs,
62            4 => Self::BadState,
63            5 => Self::Canceled,
64            unknown_ordinal => Self::__SourceBreaking { unknown_ordinal },
65        }
66    }
67
68    #[inline]
69    pub fn unknown() -> Self {
70        Self::__SourceBreaking { unknown_ordinal: 0xffffffff }
71    }
72
73    #[inline]
74    pub const fn into_primitive(self) -> u32 {
75        match self {
76            Self::InternalError => 1,
77            Self::NotSupported => 2,
78            Self::InvalidArgs => 3,
79            Self::BadState => 4,
80            Self::Canceled => 5,
81            Self::__SourceBreaking { unknown_ordinal } => unknown_ordinal,
82        }
83    }
84
85    #[inline]
86    pub fn is_unknown(&self) -> bool {
87        match self {
88            Self::__SourceBreaking { unknown_ordinal: _ } => true,
89            _ => false,
90        }
91    }
92}
93
94#[derive(Clone, Copy, Debug, Eq, Hash, Ord, PartialEq, PartialOrd)]
95#[repr(C)]
96pub struct DeviceGetTicksLeftRequest {
97    pub id: u64,
98}
99
100impl fidl::Persistable for DeviceGetTicksLeftRequest {}
101
102#[derive(Clone, Debug, PartialEq)]
103pub struct DeviceStartRequest {
104    pub id: u64,
105    pub resolution: Resolution,
106    pub ticks: u64,
107}
108
109impl fidl::Persistable for DeviceStartRequest {}
110
111#[derive(Clone, Copy, Debug, Eq, Hash, Ord, PartialEq, PartialOrd)]
112#[repr(C)]
113pub struct DeviceStopRequest {
114    pub id: u64,
115}
116
117impl fidl::Persistable for DeviceStopRequest {}
118
119#[derive(Clone, Copy, Debug, Eq, Hash, Ord, PartialEq, PartialOrd)]
120#[repr(C)]
121pub struct DeviceGetTicksLeftResponse {
122    pub ticks: u64,
123}
124
125impl fidl::Persistable for DeviceGetTicksLeftResponse {}
126
127/// Properties for a specific timer abstracted by the driver.
128#[derive(Clone, Debug, Default, PartialEq)]
129pub struct TimerProperties {
130    /// Unique identifier for this timer.
131    ///
132    /// The `id` is stable for a given timer, i.e. it does not change across different clients
133    /// or different connections from the same client.
134    ///
135    /// Required.
136    pub id: Option<u64>,
137    /// Retrieves the resolutions supported by this timer.
138    ///
139    /// Required.
140    pub supported_resolutions: Option<Vec<Resolution>>,
141    /// Range in ticks.
142    ///
143    /// This is the maximum amount of time that can be set in terms of ticks when a timer is
144    /// started. The maximum range in actual time (e.g. nanoseconds) depends on the resolution used.
145    ///
146    /// NOTE: The value reported here does not need to be identical to what
147    /// the hardware actually supports. The driver MAY provide the support for
148    /// the reported `max_ticks` that is greater than the largest value of ticks
149    /// that can be put into the device's hardware register. The driver supports
150    /// a greater value of `max_ticks` by re-programming the hardware counter multiple times
151    /// with its maximum supported interval, with an interrupt generated after
152    /// each re-programming. If you want as few re-programmings (and interrupts)
153    /// to happen as possible, as may be the case when using the hrtimer in a power-aware
154    /// context, select the coarsest available resolution from [supported_resolutions].
155    /// This will ensure the longest possible wall-clock time passes without a re-program.
156    ///
157    /// Required.
158    pub max_ticks: Option<u64>,
159    /// If true then the `SetEvent` method is supported, if false or not present it is not
160    /// supported.
161    ///
162    /// Optional.
163    pub supports_event: Option<bool>,
164    /// If true then the `StartAndWait` and `StartAndWait2` methods are supported, if false or
165    /// not present these methods are not supported.
166    ///
167    /// Optional.
168    pub supports_wait: Option<bool>,
169    #[doc(hidden)]
170    pub __source_breaking: fidl::marker::SourceBreaking,
171}
172
173impl fidl::Persistable for TimerProperties {}
174
175/// Amount of time for one tick of a timer.
176#[derive(Clone, Debug)]
177pub enum Resolution {
178    /// The resolution specified for one tick.
179    Duration(i64),
180    #[doc(hidden)]
181    __SourceBreaking { unknown_ordinal: u64 },
182}
183
184/// Pattern that matches an unknown `Resolution` member.
185#[macro_export]
186macro_rules! ResolutionUnknown {
187    () => {
188        _
189    };
190}
191
192// Custom PartialEq so that unknown variants are not equal to themselves.
193impl PartialEq for Resolution {
194    fn eq(&self, other: &Self) -> bool {
195        match (self, other) {
196            (Self::Duration(x), Self::Duration(y)) => *x == *y,
197            _ => false,
198        }
199    }
200}
201
202impl Resolution {
203    #[inline]
204    pub fn ordinal(&self) -> u64 {
205        match *self {
206            Self::Duration(_) => 1,
207            Self::__SourceBreaking { unknown_ordinal } => unknown_ordinal,
208        }
209    }
210
211    #[inline]
212    pub fn unknown_variant_for_testing() -> Self {
213        Self::__SourceBreaking { unknown_ordinal: 0 }
214    }
215
216    #[inline]
217    pub fn is_unknown(&self) -> bool {
218        match self {
219            Self::__SourceBreaking { .. } => true,
220            _ => false,
221        }
222    }
223}
224
225impl fidl::Persistable for Resolution {}
226
227pub mod device_ordinals {
228    pub const START: u64 = 0x5a0a193b0467cc8a;
229    pub const STOP: u64 = 0x77e4cd1c3841a0e2;
230    pub const GET_TICKS_LEFT: u64 = 0xde2a48ae7d4b4ea;
231    pub const SET_EVENT: u64 = 0x1027024d25ffa820;
232    pub const START_AND_WAIT: u64 = 0x716f415cdf234e0f;
233    pub const START_AND_WAIT2: u64 = 0x5f2aaf21254d3238;
234    pub const GET_PROPERTIES: u64 = 0x6bc22ab4c9396cbb;
235}
236
237mod internal {
238    use super::*;
239    unsafe impl fidl::encoding::TypeMarker for DriverError {
240        type Owned = Self;
241
242        #[inline(always)]
243        fn inline_align(_context: fidl::encoding::Context) -> usize {
244            std::mem::align_of::<u32>()
245        }
246
247        #[inline(always)]
248        fn inline_size(_context: fidl::encoding::Context) -> usize {
249            std::mem::size_of::<u32>()
250        }
251
252        #[inline(always)]
253        fn encode_is_copy() -> bool {
254            false
255        }
256
257        #[inline(always)]
258        fn decode_is_copy() -> bool {
259            false
260        }
261    }
262
263    impl fidl::encoding::ValueTypeMarker for DriverError {
264        type Borrowed<'a> = Self;
265        #[inline(always)]
266        fn borrow(value: &<Self as fidl::encoding::TypeMarker>::Owned) -> Self::Borrowed<'_> {
267            *value
268        }
269    }
270
271    unsafe impl<D: fidl::encoding::ResourceDialect> fidl::encoding::Encode<Self, D> for DriverError {
272        #[inline]
273        unsafe fn encode(
274            self,
275            encoder: &mut fidl::encoding::Encoder<'_, D>,
276            offset: usize,
277            _depth: fidl::encoding::Depth,
278        ) -> fidl::Result<()> {
279            encoder.debug_check_bounds::<Self>(offset);
280            encoder.write_num(self.into_primitive(), offset);
281            Ok(())
282        }
283    }
284
285    impl<D: fidl::encoding::ResourceDialect> fidl::encoding::Decode<Self, D> for DriverError {
286        #[inline(always)]
287        fn new_empty() -> Self {
288            Self::unknown()
289        }
290
291        #[inline]
292        unsafe fn decode(
293            &mut self,
294            decoder: &mut fidl::encoding::Decoder<'_, D>,
295            offset: usize,
296            _depth: fidl::encoding::Depth,
297        ) -> fidl::Result<()> {
298            decoder.debug_check_bounds::<Self>(offset);
299            let prim = decoder.read_num::<u32>(offset);
300
301            *self = Self::from_primitive_allow_unknown(prim);
302            Ok(())
303        }
304    }
305
306    impl fidl::encoding::ValueTypeMarker for DeviceGetTicksLeftRequest {
307        type Borrowed<'a> = &'a Self;
308        fn borrow(value: &<Self as fidl::encoding::TypeMarker>::Owned) -> Self::Borrowed<'_> {
309            value
310        }
311    }
312
313    unsafe impl fidl::encoding::TypeMarker for DeviceGetTicksLeftRequest {
314        type Owned = Self;
315
316        #[inline(always)]
317        fn inline_align(_context: fidl::encoding::Context) -> usize {
318            8
319        }
320
321        #[inline(always)]
322        fn inline_size(_context: fidl::encoding::Context) -> usize {
323            8
324        }
325        #[inline(always)]
326        fn encode_is_copy() -> bool {
327            true
328        }
329
330        #[inline(always)]
331        fn decode_is_copy() -> bool {
332            true
333        }
334    }
335
336    unsafe impl<D: fidl::encoding::ResourceDialect>
337        fidl::encoding::Encode<DeviceGetTicksLeftRequest, D> for &DeviceGetTicksLeftRequest
338    {
339        #[inline]
340        unsafe fn encode(
341            self,
342            encoder: &mut fidl::encoding::Encoder<'_, D>,
343            offset: usize,
344            _depth: fidl::encoding::Depth,
345        ) -> fidl::Result<()> {
346            encoder.debug_check_bounds::<DeviceGetTicksLeftRequest>(offset);
347            unsafe {
348                // Copy the object into the buffer.
349                let buf_ptr = encoder.buf.as_mut_ptr().add(offset);
350                (buf_ptr as *mut DeviceGetTicksLeftRequest)
351                    .write_unaligned((self as *const DeviceGetTicksLeftRequest).read());
352                // Zero out padding regions. Unlike `fidl_struct_impl_noncopy!`, this must be
353                // done second because the memcpy will write garbage to these bytes.
354            }
355            Ok(())
356        }
357    }
358    unsafe impl<D: fidl::encoding::ResourceDialect, T0: fidl::encoding::Encode<u64, D>>
359        fidl::encoding::Encode<DeviceGetTicksLeftRequest, D> for (T0,)
360    {
361        #[inline]
362        unsafe fn encode(
363            self,
364            encoder: &mut fidl::encoding::Encoder<'_, D>,
365            offset: usize,
366            depth: fidl::encoding::Depth,
367        ) -> fidl::Result<()> {
368            encoder.debug_check_bounds::<DeviceGetTicksLeftRequest>(offset);
369            // Zero out padding regions. There's no need to apply masks
370            // because the unmasked parts will be overwritten by fields.
371            // Write the fields.
372            self.0.encode(encoder, offset + 0, depth)?;
373            Ok(())
374        }
375    }
376
377    impl<D: fidl::encoding::ResourceDialect> fidl::encoding::Decode<Self, D>
378        for DeviceGetTicksLeftRequest
379    {
380        #[inline(always)]
381        fn new_empty() -> Self {
382            Self { id: fidl::new_empty!(u64, D) }
383        }
384
385        #[inline]
386        unsafe fn decode(
387            &mut self,
388            decoder: &mut fidl::encoding::Decoder<'_, D>,
389            offset: usize,
390            _depth: fidl::encoding::Depth,
391        ) -> fidl::Result<()> {
392            decoder.debug_check_bounds::<Self>(offset);
393            let buf_ptr = unsafe { decoder.buf.as_ptr().add(offset) };
394            // Verify that padding bytes are zero.
395            // Copy from the buffer into the object.
396            unsafe {
397                std::ptr::copy_nonoverlapping(buf_ptr, self as *mut Self as *mut u8, 8);
398            }
399            Ok(())
400        }
401    }
402
403    impl fidl::encoding::ValueTypeMarker for DeviceStartRequest {
404        type Borrowed<'a> = &'a Self;
405        fn borrow(value: &<Self as fidl::encoding::TypeMarker>::Owned) -> Self::Borrowed<'_> {
406            value
407        }
408    }
409
410    unsafe impl fidl::encoding::TypeMarker for DeviceStartRequest {
411        type Owned = Self;
412
413        #[inline(always)]
414        fn inline_align(_context: fidl::encoding::Context) -> usize {
415            8
416        }
417
418        #[inline(always)]
419        fn inline_size(_context: fidl::encoding::Context) -> usize {
420            32
421        }
422    }
423
424    unsafe impl<D: fidl::encoding::ResourceDialect> fidl::encoding::Encode<DeviceStartRequest, D>
425        for &DeviceStartRequest
426    {
427        #[inline]
428        unsafe fn encode(
429            self,
430            encoder: &mut fidl::encoding::Encoder<'_, D>,
431            offset: usize,
432            _depth: fidl::encoding::Depth,
433        ) -> fidl::Result<()> {
434            encoder.debug_check_bounds::<DeviceStartRequest>(offset);
435            // Delegate to tuple encoding.
436            fidl::encoding::Encode::<DeviceStartRequest, D>::encode(
437                (
438                    <u64 as fidl::encoding::ValueTypeMarker>::borrow(&self.id),
439                    <Resolution as fidl::encoding::ValueTypeMarker>::borrow(&self.resolution),
440                    <u64 as fidl::encoding::ValueTypeMarker>::borrow(&self.ticks),
441                ),
442                encoder,
443                offset,
444                _depth,
445            )
446        }
447    }
448    unsafe impl<
449            D: fidl::encoding::ResourceDialect,
450            T0: fidl::encoding::Encode<u64, D>,
451            T1: fidl::encoding::Encode<Resolution, D>,
452            T2: fidl::encoding::Encode<u64, D>,
453        > fidl::encoding::Encode<DeviceStartRequest, D> for (T0, T1, T2)
454    {
455        #[inline]
456        unsafe fn encode(
457            self,
458            encoder: &mut fidl::encoding::Encoder<'_, D>,
459            offset: usize,
460            depth: fidl::encoding::Depth,
461        ) -> fidl::Result<()> {
462            encoder.debug_check_bounds::<DeviceStartRequest>(offset);
463            // Zero out padding regions. There's no need to apply masks
464            // because the unmasked parts will be overwritten by fields.
465            // Write the fields.
466            self.0.encode(encoder, offset + 0, depth)?;
467            self.1.encode(encoder, offset + 8, depth)?;
468            self.2.encode(encoder, offset + 24, depth)?;
469            Ok(())
470        }
471    }
472
473    impl<D: fidl::encoding::ResourceDialect> fidl::encoding::Decode<Self, D> for DeviceStartRequest {
474        #[inline(always)]
475        fn new_empty() -> Self {
476            Self {
477                id: fidl::new_empty!(u64, D),
478                resolution: fidl::new_empty!(Resolution, D),
479                ticks: fidl::new_empty!(u64, D),
480            }
481        }
482
483        #[inline]
484        unsafe fn decode(
485            &mut self,
486            decoder: &mut fidl::encoding::Decoder<'_, D>,
487            offset: usize,
488            _depth: fidl::encoding::Depth,
489        ) -> fidl::Result<()> {
490            decoder.debug_check_bounds::<Self>(offset);
491            // Verify that padding bytes are zero.
492            fidl::decode!(u64, D, &mut self.id, decoder, offset + 0, _depth)?;
493            fidl::decode!(Resolution, D, &mut self.resolution, decoder, offset + 8, _depth)?;
494            fidl::decode!(u64, D, &mut self.ticks, decoder, offset + 24, _depth)?;
495            Ok(())
496        }
497    }
498
499    impl fidl::encoding::ValueTypeMarker for DeviceStopRequest {
500        type Borrowed<'a> = &'a Self;
501        fn borrow(value: &<Self as fidl::encoding::TypeMarker>::Owned) -> Self::Borrowed<'_> {
502            value
503        }
504    }
505
506    unsafe impl fidl::encoding::TypeMarker for DeviceStopRequest {
507        type Owned = Self;
508
509        #[inline(always)]
510        fn inline_align(_context: fidl::encoding::Context) -> usize {
511            8
512        }
513
514        #[inline(always)]
515        fn inline_size(_context: fidl::encoding::Context) -> usize {
516            8
517        }
518        #[inline(always)]
519        fn encode_is_copy() -> bool {
520            true
521        }
522
523        #[inline(always)]
524        fn decode_is_copy() -> bool {
525            true
526        }
527    }
528
529    unsafe impl<D: fidl::encoding::ResourceDialect> fidl::encoding::Encode<DeviceStopRequest, D>
530        for &DeviceStopRequest
531    {
532        #[inline]
533        unsafe fn encode(
534            self,
535            encoder: &mut fidl::encoding::Encoder<'_, D>,
536            offset: usize,
537            _depth: fidl::encoding::Depth,
538        ) -> fidl::Result<()> {
539            encoder.debug_check_bounds::<DeviceStopRequest>(offset);
540            unsafe {
541                // Copy the object into the buffer.
542                let buf_ptr = encoder.buf.as_mut_ptr().add(offset);
543                (buf_ptr as *mut DeviceStopRequest)
544                    .write_unaligned((self as *const DeviceStopRequest).read());
545                // Zero out padding regions. Unlike `fidl_struct_impl_noncopy!`, this must be
546                // done second because the memcpy will write garbage to these bytes.
547            }
548            Ok(())
549        }
550    }
551    unsafe impl<D: fidl::encoding::ResourceDialect, T0: fidl::encoding::Encode<u64, D>>
552        fidl::encoding::Encode<DeviceStopRequest, D> for (T0,)
553    {
554        #[inline]
555        unsafe fn encode(
556            self,
557            encoder: &mut fidl::encoding::Encoder<'_, D>,
558            offset: usize,
559            depth: fidl::encoding::Depth,
560        ) -> fidl::Result<()> {
561            encoder.debug_check_bounds::<DeviceStopRequest>(offset);
562            // Zero out padding regions. There's no need to apply masks
563            // because the unmasked parts will be overwritten by fields.
564            // Write the fields.
565            self.0.encode(encoder, offset + 0, depth)?;
566            Ok(())
567        }
568    }
569
570    impl<D: fidl::encoding::ResourceDialect> fidl::encoding::Decode<Self, D> for DeviceStopRequest {
571        #[inline(always)]
572        fn new_empty() -> Self {
573            Self { id: fidl::new_empty!(u64, D) }
574        }
575
576        #[inline]
577        unsafe fn decode(
578            &mut self,
579            decoder: &mut fidl::encoding::Decoder<'_, D>,
580            offset: usize,
581            _depth: fidl::encoding::Depth,
582        ) -> fidl::Result<()> {
583            decoder.debug_check_bounds::<Self>(offset);
584            let buf_ptr = unsafe { decoder.buf.as_ptr().add(offset) };
585            // Verify that padding bytes are zero.
586            // Copy from the buffer into the object.
587            unsafe {
588                std::ptr::copy_nonoverlapping(buf_ptr, self as *mut Self as *mut u8, 8);
589            }
590            Ok(())
591        }
592    }
593
594    impl fidl::encoding::ValueTypeMarker for DeviceGetTicksLeftResponse {
595        type Borrowed<'a> = &'a Self;
596        fn borrow(value: &<Self as fidl::encoding::TypeMarker>::Owned) -> Self::Borrowed<'_> {
597            value
598        }
599    }
600
601    unsafe impl fidl::encoding::TypeMarker for DeviceGetTicksLeftResponse {
602        type Owned = Self;
603
604        #[inline(always)]
605        fn inline_align(_context: fidl::encoding::Context) -> usize {
606            8
607        }
608
609        #[inline(always)]
610        fn inline_size(_context: fidl::encoding::Context) -> usize {
611            8
612        }
613        #[inline(always)]
614        fn encode_is_copy() -> bool {
615            true
616        }
617
618        #[inline(always)]
619        fn decode_is_copy() -> bool {
620            true
621        }
622    }
623
624    unsafe impl<D: fidl::encoding::ResourceDialect>
625        fidl::encoding::Encode<DeviceGetTicksLeftResponse, D> for &DeviceGetTicksLeftResponse
626    {
627        #[inline]
628        unsafe fn encode(
629            self,
630            encoder: &mut fidl::encoding::Encoder<'_, D>,
631            offset: usize,
632            _depth: fidl::encoding::Depth,
633        ) -> fidl::Result<()> {
634            encoder.debug_check_bounds::<DeviceGetTicksLeftResponse>(offset);
635            unsafe {
636                // Copy the object into the buffer.
637                let buf_ptr = encoder.buf.as_mut_ptr().add(offset);
638                (buf_ptr as *mut DeviceGetTicksLeftResponse)
639                    .write_unaligned((self as *const DeviceGetTicksLeftResponse).read());
640                // Zero out padding regions. Unlike `fidl_struct_impl_noncopy!`, this must be
641                // done second because the memcpy will write garbage to these bytes.
642            }
643            Ok(())
644        }
645    }
646    unsafe impl<D: fidl::encoding::ResourceDialect, T0: fidl::encoding::Encode<u64, D>>
647        fidl::encoding::Encode<DeviceGetTicksLeftResponse, D> for (T0,)
648    {
649        #[inline]
650        unsafe fn encode(
651            self,
652            encoder: &mut fidl::encoding::Encoder<'_, D>,
653            offset: usize,
654            depth: fidl::encoding::Depth,
655        ) -> fidl::Result<()> {
656            encoder.debug_check_bounds::<DeviceGetTicksLeftResponse>(offset);
657            // Zero out padding regions. There's no need to apply masks
658            // because the unmasked parts will be overwritten by fields.
659            // Write the fields.
660            self.0.encode(encoder, offset + 0, depth)?;
661            Ok(())
662        }
663    }
664
665    impl<D: fidl::encoding::ResourceDialect> fidl::encoding::Decode<Self, D>
666        for DeviceGetTicksLeftResponse
667    {
668        #[inline(always)]
669        fn new_empty() -> Self {
670            Self { ticks: fidl::new_empty!(u64, D) }
671        }
672
673        #[inline]
674        unsafe fn decode(
675            &mut self,
676            decoder: &mut fidl::encoding::Decoder<'_, D>,
677            offset: usize,
678            _depth: fidl::encoding::Depth,
679        ) -> fidl::Result<()> {
680            decoder.debug_check_bounds::<Self>(offset);
681            let buf_ptr = unsafe { decoder.buf.as_ptr().add(offset) };
682            // Verify that padding bytes are zero.
683            // Copy from the buffer into the object.
684            unsafe {
685                std::ptr::copy_nonoverlapping(buf_ptr, self as *mut Self as *mut u8, 8);
686            }
687            Ok(())
688        }
689    }
690
691    impl TimerProperties {
692        #[inline(always)]
693        fn max_ordinal_present(&self) -> u64 {
694            if let Some(_) = self.supports_wait {
695                return 5;
696            }
697            if let Some(_) = self.supports_event {
698                return 4;
699            }
700            if let Some(_) = self.max_ticks {
701                return 3;
702            }
703            if let Some(_) = self.supported_resolutions {
704                return 2;
705            }
706            if let Some(_) = self.id {
707                return 1;
708            }
709            0
710        }
711    }
712
713    impl fidl::encoding::ValueTypeMarker for TimerProperties {
714        type Borrowed<'a> = &'a Self;
715        fn borrow(value: &<Self as fidl::encoding::TypeMarker>::Owned) -> Self::Borrowed<'_> {
716            value
717        }
718    }
719
720    unsafe impl fidl::encoding::TypeMarker for TimerProperties {
721        type Owned = Self;
722
723        #[inline(always)]
724        fn inline_align(_context: fidl::encoding::Context) -> usize {
725            8
726        }
727
728        #[inline(always)]
729        fn inline_size(_context: fidl::encoding::Context) -> usize {
730            16
731        }
732    }
733
734    unsafe impl<D: fidl::encoding::ResourceDialect> fidl::encoding::Encode<TimerProperties, D>
735        for &TimerProperties
736    {
737        unsafe fn encode(
738            self,
739            encoder: &mut fidl::encoding::Encoder<'_, D>,
740            offset: usize,
741            mut depth: fidl::encoding::Depth,
742        ) -> fidl::Result<()> {
743            encoder.debug_check_bounds::<TimerProperties>(offset);
744            // Vector header
745            let max_ordinal: u64 = self.max_ordinal_present();
746            encoder.write_num(max_ordinal, offset);
747            encoder.write_num(fidl::encoding::ALLOC_PRESENT_U64, offset + 8);
748            // Calling encoder.out_of_line_offset(0) is not allowed.
749            if max_ordinal == 0 {
750                return Ok(());
751            }
752            depth.increment()?;
753            let envelope_size = 8;
754            let bytes_len = max_ordinal as usize * envelope_size;
755            #[allow(unused_variables)]
756            let offset = encoder.out_of_line_offset(bytes_len);
757            let mut _prev_end_offset: usize = 0;
758            if 1 > max_ordinal {
759                return Ok(());
760            }
761
762            // Write at offset+(ordinal-1)*envelope_size, since ordinals are one-based and envelopes
763            // are envelope_size bytes.
764            let cur_offset: usize = (1 - 1) * envelope_size;
765
766            // Zero reserved fields.
767            encoder.padding(offset + _prev_end_offset, cur_offset - _prev_end_offset);
768
769            // Safety:
770            // - bytes_len is calculated to fit envelope_size*max(member.ordinal).
771            // - Since cur_offset is envelope_size*(member.ordinal - 1) and the envelope takes
772            //   envelope_size bytes, there is always sufficient room.
773            fidl::encoding::encode_in_envelope_optional::<u64, D>(
774                self.id.as_ref().map(<u64 as fidl::encoding::ValueTypeMarker>::borrow),
775                encoder,
776                offset + cur_offset,
777                depth,
778            )?;
779
780            _prev_end_offset = cur_offset + envelope_size;
781            if 2 > max_ordinal {
782                return Ok(());
783            }
784
785            // Write at offset+(ordinal-1)*envelope_size, since ordinals are one-based and envelopes
786            // are envelope_size bytes.
787            let cur_offset: usize = (2 - 1) * envelope_size;
788
789            // Zero reserved fields.
790            encoder.padding(offset + _prev_end_offset, cur_offset - _prev_end_offset);
791
792            // Safety:
793            // - bytes_len is calculated to fit envelope_size*max(member.ordinal).
794            // - Since cur_offset is envelope_size*(member.ordinal - 1) and the envelope takes
795            //   envelope_size bytes, there is always sufficient room.
796            fidl::encoding::encode_in_envelope_optional::<fidl::encoding::Vector<Resolution, 64>, D>(
797            self.supported_resolutions.as_ref().map(<fidl::encoding::Vector<Resolution, 64> as fidl::encoding::ValueTypeMarker>::borrow),
798            encoder, offset + cur_offset, depth
799        )?;
800
801            _prev_end_offset = cur_offset + envelope_size;
802            if 3 > max_ordinal {
803                return Ok(());
804            }
805
806            // Write at offset+(ordinal-1)*envelope_size, since ordinals are one-based and envelopes
807            // are envelope_size bytes.
808            let cur_offset: usize = (3 - 1) * envelope_size;
809
810            // Zero reserved fields.
811            encoder.padding(offset + _prev_end_offset, cur_offset - _prev_end_offset);
812
813            // Safety:
814            // - bytes_len is calculated to fit envelope_size*max(member.ordinal).
815            // - Since cur_offset is envelope_size*(member.ordinal - 1) and the envelope takes
816            //   envelope_size bytes, there is always sufficient room.
817            fidl::encoding::encode_in_envelope_optional::<u64, D>(
818                self.max_ticks.as_ref().map(<u64 as fidl::encoding::ValueTypeMarker>::borrow),
819                encoder,
820                offset + cur_offset,
821                depth,
822            )?;
823
824            _prev_end_offset = cur_offset + envelope_size;
825            if 4 > max_ordinal {
826                return Ok(());
827            }
828
829            // Write at offset+(ordinal-1)*envelope_size, since ordinals are one-based and envelopes
830            // are envelope_size bytes.
831            let cur_offset: usize = (4 - 1) * envelope_size;
832
833            // Zero reserved fields.
834            encoder.padding(offset + _prev_end_offset, cur_offset - _prev_end_offset);
835
836            // Safety:
837            // - bytes_len is calculated to fit envelope_size*max(member.ordinal).
838            // - Since cur_offset is envelope_size*(member.ordinal - 1) and the envelope takes
839            //   envelope_size bytes, there is always sufficient room.
840            fidl::encoding::encode_in_envelope_optional::<bool, D>(
841                self.supports_event.as_ref().map(<bool as fidl::encoding::ValueTypeMarker>::borrow),
842                encoder,
843                offset + cur_offset,
844                depth,
845            )?;
846
847            _prev_end_offset = cur_offset + envelope_size;
848            if 5 > max_ordinal {
849                return Ok(());
850            }
851
852            // Write at offset+(ordinal-1)*envelope_size, since ordinals are one-based and envelopes
853            // are envelope_size bytes.
854            let cur_offset: usize = (5 - 1) * envelope_size;
855
856            // Zero reserved fields.
857            encoder.padding(offset + _prev_end_offset, cur_offset - _prev_end_offset);
858
859            // Safety:
860            // - bytes_len is calculated to fit envelope_size*max(member.ordinal).
861            // - Since cur_offset is envelope_size*(member.ordinal - 1) and the envelope takes
862            //   envelope_size bytes, there is always sufficient room.
863            fidl::encoding::encode_in_envelope_optional::<bool, D>(
864                self.supports_wait.as_ref().map(<bool as fidl::encoding::ValueTypeMarker>::borrow),
865                encoder,
866                offset + cur_offset,
867                depth,
868            )?;
869
870            _prev_end_offset = cur_offset + envelope_size;
871
872            Ok(())
873        }
874    }
875
876    impl<D: fidl::encoding::ResourceDialect> fidl::encoding::Decode<Self, D> for TimerProperties {
877        #[inline(always)]
878        fn new_empty() -> Self {
879            Self::default()
880        }
881
882        unsafe fn decode(
883            &mut self,
884            decoder: &mut fidl::encoding::Decoder<'_, D>,
885            offset: usize,
886            mut depth: fidl::encoding::Depth,
887        ) -> fidl::Result<()> {
888            decoder.debug_check_bounds::<Self>(offset);
889            let len = match fidl::encoding::decode_vector_header(decoder, offset)? {
890                None => return Err(fidl::Error::NotNullable),
891                Some(len) => len,
892            };
893            // Calling decoder.out_of_line_offset(0) is not allowed.
894            if len == 0 {
895                return Ok(());
896            };
897            depth.increment()?;
898            let envelope_size = 8;
899            let bytes_len = len * envelope_size;
900            let offset = decoder.out_of_line_offset(bytes_len)?;
901            // Decode the envelope for each type.
902            let mut _next_ordinal_to_read = 0;
903            let mut next_offset = offset;
904            let end_offset = offset + bytes_len;
905            _next_ordinal_to_read += 1;
906            if next_offset >= end_offset {
907                return Ok(());
908            }
909
910            // Decode unknown envelopes for gaps in ordinals.
911            while _next_ordinal_to_read < 1 {
912                fidl::encoding::decode_unknown_envelope(decoder, next_offset, depth)?;
913                _next_ordinal_to_read += 1;
914                next_offset += envelope_size;
915            }
916
917            let next_out_of_line = decoder.next_out_of_line();
918            let handles_before = decoder.remaining_handles();
919            if let Some((inlined, num_bytes, num_handles)) =
920                fidl::encoding::decode_envelope_header(decoder, next_offset)?
921            {
922                let member_inline_size =
923                    <u64 as fidl::encoding::TypeMarker>::inline_size(decoder.context);
924                if inlined != (member_inline_size <= 4) {
925                    return Err(fidl::Error::InvalidInlineBitInEnvelope);
926                }
927                let inner_offset;
928                let mut inner_depth = depth.clone();
929                if inlined {
930                    decoder.check_inline_envelope_padding(next_offset, member_inline_size)?;
931                    inner_offset = next_offset;
932                } else {
933                    inner_offset = decoder.out_of_line_offset(member_inline_size)?;
934                    inner_depth.increment()?;
935                }
936                let val_ref = self.id.get_or_insert_with(|| fidl::new_empty!(u64, D));
937                fidl::decode!(u64, D, val_ref, decoder, inner_offset, inner_depth)?;
938                if !inlined && decoder.next_out_of_line() != next_out_of_line + (num_bytes as usize)
939                {
940                    return Err(fidl::Error::InvalidNumBytesInEnvelope);
941                }
942                if handles_before != decoder.remaining_handles() + (num_handles as usize) {
943                    return Err(fidl::Error::InvalidNumHandlesInEnvelope);
944                }
945            }
946
947            next_offset += envelope_size;
948            _next_ordinal_to_read += 1;
949            if next_offset >= end_offset {
950                return Ok(());
951            }
952
953            // Decode unknown envelopes for gaps in ordinals.
954            while _next_ordinal_to_read < 2 {
955                fidl::encoding::decode_unknown_envelope(decoder, next_offset, depth)?;
956                _next_ordinal_to_read += 1;
957                next_offset += envelope_size;
958            }
959
960            let next_out_of_line = decoder.next_out_of_line();
961            let handles_before = decoder.remaining_handles();
962            if let Some((inlined, num_bytes, num_handles)) =
963                fidl::encoding::decode_envelope_header(decoder, next_offset)?
964            {
965                let member_inline_size = <fidl::encoding::Vector<Resolution, 64> as fidl::encoding::TypeMarker>::inline_size(decoder.context);
966                if inlined != (member_inline_size <= 4) {
967                    return Err(fidl::Error::InvalidInlineBitInEnvelope);
968                }
969                let inner_offset;
970                let mut inner_depth = depth.clone();
971                if inlined {
972                    decoder.check_inline_envelope_padding(next_offset, member_inline_size)?;
973                    inner_offset = next_offset;
974                } else {
975                    inner_offset = decoder.out_of_line_offset(member_inline_size)?;
976                    inner_depth.increment()?;
977                }
978                let val_ref = self.supported_resolutions.get_or_insert_with(
979                    || fidl::new_empty!(fidl::encoding::Vector<Resolution, 64>, D),
980                );
981                fidl::decode!(fidl::encoding::Vector<Resolution, 64>, D, val_ref, decoder, inner_offset, inner_depth)?;
982                if !inlined && decoder.next_out_of_line() != next_out_of_line + (num_bytes as usize)
983                {
984                    return Err(fidl::Error::InvalidNumBytesInEnvelope);
985                }
986                if handles_before != decoder.remaining_handles() + (num_handles as usize) {
987                    return Err(fidl::Error::InvalidNumHandlesInEnvelope);
988                }
989            }
990
991            next_offset += envelope_size;
992            _next_ordinal_to_read += 1;
993            if next_offset >= end_offset {
994                return Ok(());
995            }
996
997            // Decode unknown envelopes for gaps in ordinals.
998            while _next_ordinal_to_read < 3 {
999                fidl::encoding::decode_unknown_envelope(decoder, next_offset, depth)?;
1000                _next_ordinal_to_read += 1;
1001                next_offset += envelope_size;
1002            }
1003
1004            let next_out_of_line = decoder.next_out_of_line();
1005            let handles_before = decoder.remaining_handles();
1006            if let Some((inlined, num_bytes, num_handles)) =
1007                fidl::encoding::decode_envelope_header(decoder, next_offset)?
1008            {
1009                let member_inline_size =
1010                    <u64 as fidl::encoding::TypeMarker>::inline_size(decoder.context);
1011                if inlined != (member_inline_size <= 4) {
1012                    return Err(fidl::Error::InvalidInlineBitInEnvelope);
1013                }
1014                let inner_offset;
1015                let mut inner_depth = depth.clone();
1016                if inlined {
1017                    decoder.check_inline_envelope_padding(next_offset, member_inline_size)?;
1018                    inner_offset = next_offset;
1019                } else {
1020                    inner_offset = decoder.out_of_line_offset(member_inline_size)?;
1021                    inner_depth.increment()?;
1022                }
1023                let val_ref = self.max_ticks.get_or_insert_with(|| fidl::new_empty!(u64, D));
1024                fidl::decode!(u64, D, val_ref, decoder, inner_offset, inner_depth)?;
1025                if !inlined && decoder.next_out_of_line() != next_out_of_line + (num_bytes as usize)
1026                {
1027                    return Err(fidl::Error::InvalidNumBytesInEnvelope);
1028                }
1029                if handles_before != decoder.remaining_handles() + (num_handles as usize) {
1030                    return Err(fidl::Error::InvalidNumHandlesInEnvelope);
1031                }
1032            }
1033
1034            next_offset += envelope_size;
1035            _next_ordinal_to_read += 1;
1036            if next_offset >= end_offset {
1037                return Ok(());
1038            }
1039
1040            // Decode unknown envelopes for gaps in ordinals.
1041            while _next_ordinal_to_read < 4 {
1042                fidl::encoding::decode_unknown_envelope(decoder, next_offset, depth)?;
1043                _next_ordinal_to_read += 1;
1044                next_offset += envelope_size;
1045            }
1046
1047            let next_out_of_line = decoder.next_out_of_line();
1048            let handles_before = decoder.remaining_handles();
1049            if let Some((inlined, num_bytes, num_handles)) =
1050                fidl::encoding::decode_envelope_header(decoder, next_offset)?
1051            {
1052                let member_inline_size =
1053                    <bool as fidl::encoding::TypeMarker>::inline_size(decoder.context);
1054                if inlined != (member_inline_size <= 4) {
1055                    return Err(fidl::Error::InvalidInlineBitInEnvelope);
1056                }
1057                let inner_offset;
1058                let mut inner_depth = depth.clone();
1059                if inlined {
1060                    decoder.check_inline_envelope_padding(next_offset, member_inline_size)?;
1061                    inner_offset = next_offset;
1062                } else {
1063                    inner_offset = decoder.out_of_line_offset(member_inline_size)?;
1064                    inner_depth.increment()?;
1065                }
1066                let val_ref = self.supports_event.get_or_insert_with(|| fidl::new_empty!(bool, D));
1067                fidl::decode!(bool, D, val_ref, decoder, inner_offset, inner_depth)?;
1068                if !inlined && decoder.next_out_of_line() != next_out_of_line + (num_bytes as usize)
1069                {
1070                    return Err(fidl::Error::InvalidNumBytesInEnvelope);
1071                }
1072                if handles_before != decoder.remaining_handles() + (num_handles as usize) {
1073                    return Err(fidl::Error::InvalidNumHandlesInEnvelope);
1074                }
1075            }
1076
1077            next_offset += envelope_size;
1078            _next_ordinal_to_read += 1;
1079            if next_offset >= end_offset {
1080                return Ok(());
1081            }
1082
1083            // Decode unknown envelopes for gaps in ordinals.
1084            while _next_ordinal_to_read < 5 {
1085                fidl::encoding::decode_unknown_envelope(decoder, next_offset, depth)?;
1086                _next_ordinal_to_read += 1;
1087                next_offset += envelope_size;
1088            }
1089
1090            let next_out_of_line = decoder.next_out_of_line();
1091            let handles_before = decoder.remaining_handles();
1092            if let Some((inlined, num_bytes, num_handles)) =
1093                fidl::encoding::decode_envelope_header(decoder, next_offset)?
1094            {
1095                let member_inline_size =
1096                    <bool as fidl::encoding::TypeMarker>::inline_size(decoder.context);
1097                if inlined != (member_inline_size <= 4) {
1098                    return Err(fidl::Error::InvalidInlineBitInEnvelope);
1099                }
1100                let inner_offset;
1101                let mut inner_depth = depth.clone();
1102                if inlined {
1103                    decoder.check_inline_envelope_padding(next_offset, member_inline_size)?;
1104                    inner_offset = next_offset;
1105                } else {
1106                    inner_offset = decoder.out_of_line_offset(member_inline_size)?;
1107                    inner_depth.increment()?;
1108                }
1109                let val_ref = self.supports_wait.get_or_insert_with(|| fidl::new_empty!(bool, D));
1110                fidl::decode!(bool, D, val_ref, decoder, inner_offset, inner_depth)?;
1111                if !inlined && decoder.next_out_of_line() != next_out_of_line + (num_bytes as usize)
1112                {
1113                    return Err(fidl::Error::InvalidNumBytesInEnvelope);
1114                }
1115                if handles_before != decoder.remaining_handles() + (num_handles as usize) {
1116                    return Err(fidl::Error::InvalidNumHandlesInEnvelope);
1117                }
1118            }
1119
1120            next_offset += envelope_size;
1121
1122            // Decode the remaining unknown envelopes.
1123            while next_offset < end_offset {
1124                _next_ordinal_to_read += 1;
1125                fidl::encoding::decode_unknown_envelope(decoder, next_offset, depth)?;
1126                next_offset += envelope_size;
1127            }
1128
1129            Ok(())
1130        }
1131    }
1132
1133    impl fidl::encoding::ValueTypeMarker for Resolution {
1134        type Borrowed<'a> = &'a Self;
1135        fn borrow(value: &<Self as fidl::encoding::TypeMarker>::Owned) -> Self::Borrowed<'_> {
1136            value
1137        }
1138    }
1139
1140    unsafe impl fidl::encoding::TypeMarker for Resolution {
1141        type Owned = Self;
1142
1143        #[inline(always)]
1144        fn inline_align(_context: fidl::encoding::Context) -> usize {
1145            8
1146        }
1147
1148        #[inline(always)]
1149        fn inline_size(_context: fidl::encoding::Context) -> usize {
1150            16
1151        }
1152    }
1153
1154    unsafe impl<D: fidl::encoding::ResourceDialect> fidl::encoding::Encode<Resolution, D>
1155        for &Resolution
1156    {
1157        #[inline]
1158        unsafe fn encode(
1159            self,
1160            encoder: &mut fidl::encoding::Encoder<'_, D>,
1161            offset: usize,
1162            _depth: fidl::encoding::Depth,
1163        ) -> fidl::Result<()> {
1164            encoder.debug_check_bounds::<Resolution>(offset);
1165            encoder.write_num::<u64>(self.ordinal(), offset);
1166            match self {
1167                Resolution::Duration(ref val) => fidl::encoding::encode_in_envelope::<i64, D>(
1168                    <i64 as fidl::encoding::ValueTypeMarker>::borrow(val),
1169                    encoder,
1170                    offset + 8,
1171                    _depth,
1172                ),
1173                Resolution::__SourceBreaking { .. } => Err(fidl::Error::UnknownUnionTag),
1174            }
1175        }
1176    }
1177
1178    impl<D: fidl::encoding::ResourceDialect> fidl::encoding::Decode<Self, D> for Resolution {
1179        #[inline(always)]
1180        fn new_empty() -> Self {
1181            Self::__SourceBreaking { unknown_ordinal: 0 }
1182        }
1183
1184        #[inline]
1185        unsafe fn decode(
1186            &mut self,
1187            decoder: &mut fidl::encoding::Decoder<'_, D>,
1188            offset: usize,
1189            mut depth: fidl::encoding::Depth,
1190        ) -> fidl::Result<()> {
1191            decoder.debug_check_bounds::<Self>(offset);
1192            #[allow(unused_variables)]
1193            let next_out_of_line = decoder.next_out_of_line();
1194            let handles_before = decoder.remaining_handles();
1195            let (ordinal, inlined, num_bytes, num_handles) =
1196                fidl::encoding::decode_union_inline_portion(decoder, offset)?;
1197
1198            let member_inline_size = match ordinal {
1199                1 => <i64 as fidl::encoding::TypeMarker>::inline_size(decoder.context),
1200                0 => return Err(fidl::Error::UnknownUnionTag),
1201                _ => num_bytes as usize,
1202            };
1203
1204            if inlined != (member_inline_size <= 4) {
1205                return Err(fidl::Error::InvalidInlineBitInEnvelope);
1206            }
1207            let _inner_offset;
1208            if inlined {
1209                decoder.check_inline_envelope_padding(offset + 8, member_inline_size)?;
1210                _inner_offset = offset + 8;
1211            } else {
1212                depth.increment()?;
1213                _inner_offset = decoder.out_of_line_offset(member_inline_size)?;
1214            }
1215            match ordinal {
1216                1 => {
1217                    #[allow(irrefutable_let_patterns)]
1218                    if let Resolution::Duration(_) = self {
1219                        // Do nothing, read the value into the object
1220                    } else {
1221                        // Initialize `self` to the right variant
1222                        *self = Resolution::Duration(fidl::new_empty!(i64, D));
1223                    }
1224                    #[allow(irrefutable_let_patterns)]
1225                    if let Resolution::Duration(ref mut val) = self {
1226                        fidl::decode!(i64, D, val, decoder, _inner_offset, depth)?;
1227                    } else {
1228                        unreachable!()
1229                    }
1230                }
1231                #[allow(deprecated)]
1232                ordinal => {
1233                    for _ in 0..num_handles {
1234                        decoder.drop_next_handle()?;
1235                    }
1236                    *self = Resolution::__SourceBreaking { unknown_ordinal: ordinal };
1237                }
1238            }
1239            if !inlined && decoder.next_out_of_line() != next_out_of_line + (num_bytes as usize) {
1240                return Err(fidl::Error::InvalidNumBytesInEnvelope);
1241            }
1242            if handles_before != decoder.remaining_handles() + (num_handles as usize) {
1243                return Err(fidl::Error::InvalidNumHandlesInEnvelope);
1244            }
1245            Ok(())
1246        }
1247    }
1248}