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