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