fidl_cf_sc_internal_counterconfig_common/
fidl_cf_sc_internal_counterconfig_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#[derive(Clone, Copy, Debug, Eq, Hash, Ord, PartialEq, PartialOrd)]
12pub struct Config {
13    pub routed_config: bool,
14    pub starting_value: u32,
15}
16
17impl fidl::Persistable for Config {}
18
19mod internal {
20    use super::*;
21
22    impl fidl::encoding::ValueTypeMarker for Config {
23        type Borrowed<'a> = &'a Self;
24        fn borrow(value: &<Self as fidl::encoding::TypeMarker>::Owned) -> Self::Borrowed<'_> {
25            value
26        }
27    }
28
29    unsafe impl fidl::encoding::TypeMarker for Config {
30        type Owned = Self;
31
32        #[inline(always)]
33        fn inline_align(_context: fidl::encoding::Context) -> usize {
34            4
35        }
36
37        #[inline(always)]
38        fn inline_size(_context: fidl::encoding::Context) -> usize {
39            8
40        }
41    }
42
43    unsafe impl<D: fidl::encoding::ResourceDialect> fidl::encoding::Encode<Config, D> for &Config {
44        #[inline]
45        unsafe fn encode(
46            self,
47            encoder: &mut fidl::encoding::Encoder<'_, D>,
48            offset: usize,
49            _depth: fidl::encoding::Depth,
50        ) -> fidl::Result<()> {
51            encoder.debug_check_bounds::<Config>(offset);
52            // Delegate to tuple encoding.
53            fidl::encoding::Encode::<Config, D>::encode(
54                (
55                    <bool as fidl::encoding::ValueTypeMarker>::borrow(&self.routed_config),
56                    <u32 as fidl::encoding::ValueTypeMarker>::borrow(&self.starting_value),
57                ),
58                encoder,
59                offset,
60                _depth,
61            )
62        }
63    }
64    unsafe impl<
65            D: fidl::encoding::ResourceDialect,
66            T0: fidl::encoding::Encode<bool, D>,
67            T1: fidl::encoding::Encode<u32, D>,
68        > fidl::encoding::Encode<Config, D> for (T0, T1)
69    {
70        #[inline]
71        unsafe fn encode(
72            self,
73            encoder: &mut fidl::encoding::Encoder<'_, D>,
74            offset: usize,
75            depth: fidl::encoding::Depth,
76        ) -> fidl::Result<()> {
77            encoder.debug_check_bounds::<Config>(offset);
78            // Zero out padding regions. There's no need to apply masks
79            // because the unmasked parts will be overwritten by fields.
80            unsafe {
81                let ptr = encoder.buf.as_mut_ptr().add(offset).offset(0);
82                (ptr as *mut u32).write_unaligned(0);
83            }
84            // Write the fields.
85            self.0.encode(encoder, offset + 0, depth)?;
86            self.1.encode(encoder, offset + 4, depth)?;
87            Ok(())
88        }
89    }
90
91    impl<D: fidl::encoding::ResourceDialect> fidl::encoding::Decode<Self, D> for Config {
92        #[inline(always)]
93        fn new_empty() -> Self {
94            Self {
95                routed_config: fidl::new_empty!(bool, D),
96                starting_value: fidl::new_empty!(u32, D),
97            }
98        }
99
100        #[inline]
101        unsafe fn decode(
102            &mut self,
103            decoder: &mut fidl::encoding::Decoder<'_, D>,
104            offset: usize,
105            _depth: fidl::encoding::Depth,
106        ) -> fidl::Result<()> {
107            decoder.debug_check_bounds::<Self>(offset);
108            // Verify that padding bytes are zero.
109            let ptr = unsafe { decoder.buf.as_ptr().add(offset).offset(0) };
110            let padval = unsafe { (ptr as *const u32).read_unaligned() };
111            let mask = 0xffffff00u32;
112            let maskedval = padval & mask;
113            if maskedval != 0 {
114                return Err(fidl::Error::NonZeroPadding {
115                    padding_start: offset + 0 + ((mask as u64).trailing_zeros() / 8) as usize,
116                });
117            }
118            fidl::decode!(bool, D, &mut self.routed_config, decoder, offset + 0, _depth)?;
119            fidl::decode!(u32, D, &mut self.starting_value, decoder, offset + 4, _depth)?;
120            Ok(())
121        }
122    }
123}