fidl_test_exampletester_common/
fidl_test_exampletester_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)]
12#[repr(C)]
13pub struct SimpleAddRequest {
14    pub augend: u8,
15    pub addend: u8,
16}
17
18impl fidl::Persistable for SimpleAddRequest {}
19
20#[derive(Clone, Copy, Debug, Eq, Hash, Ord, PartialEq, PartialOrd)]
21#[repr(C)]
22pub struct SimpleAddResponse {
23    pub sum: u16,
24}
25
26impl fidl::Persistable for SimpleAddResponse {}
27
28mod internal {
29    use super::*;
30
31    impl fidl::encoding::ValueTypeMarker for SimpleAddRequest {
32        type Borrowed<'a> = &'a Self;
33        fn borrow(value: &<Self as fidl::encoding::TypeMarker>::Owned) -> Self::Borrowed<'_> {
34            value
35        }
36    }
37
38    unsafe impl fidl::encoding::TypeMarker for SimpleAddRequest {
39        type Owned = Self;
40
41        #[inline(always)]
42        fn inline_align(_context: fidl::encoding::Context) -> usize {
43            1
44        }
45
46        #[inline(always)]
47        fn inline_size(_context: fidl::encoding::Context) -> usize {
48            2
49        }
50        #[inline(always)]
51        fn encode_is_copy() -> bool {
52            true
53        }
54
55        #[inline(always)]
56        fn decode_is_copy() -> bool {
57            true
58        }
59    }
60
61    unsafe impl<D: fidl::encoding::ResourceDialect> fidl::encoding::Encode<SimpleAddRequest, D>
62        for &SimpleAddRequest
63    {
64        #[inline]
65        unsafe fn encode(
66            self,
67            encoder: &mut fidl::encoding::Encoder<'_, D>,
68            offset: usize,
69            _depth: fidl::encoding::Depth,
70        ) -> fidl::Result<()> {
71            encoder.debug_check_bounds::<SimpleAddRequest>(offset);
72            unsafe {
73                // Copy the object into the buffer.
74                let buf_ptr = encoder.buf.as_mut_ptr().add(offset);
75                (buf_ptr as *mut SimpleAddRequest)
76                    .write_unaligned((self as *const SimpleAddRequest).read());
77                // Zero out padding regions. Unlike `fidl_struct_impl_noncopy!`, this must be
78                // done second because the memcpy will write garbage to these bytes.
79            }
80            Ok(())
81        }
82    }
83    unsafe impl<
84            D: fidl::encoding::ResourceDialect,
85            T0: fidl::encoding::Encode<u8, D>,
86            T1: fidl::encoding::Encode<u8, D>,
87        > fidl::encoding::Encode<SimpleAddRequest, D> for (T0, T1)
88    {
89        #[inline]
90        unsafe fn encode(
91            self,
92            encoder: &mut fidl::encoding::Encoder<'_, D>,
93            offset: usize,
94            depth: fidl::encoding::Depth,
95        ) -> fidl::Result<()> {
96            encoder.debug_check_bounds::<SimpleAddRequest>(offset);
97            // Zero out padding regions. There's no need to apply masks
98            // because the unmasked parts will be overwritten by fields.
99            // Write the fields.
100            self.0.encode(encoder, offset + 0, depth)?;
101            self.1.encode(encoder, offset + 1, depth)?;
102            Ok(())
103        }
104    }
105
106    impl<D: fidl::encoding::ResourceDialect> fidl::encoding::Decode<Self, D> for SimpleAddRequest {
107        #[inline(always)]
108        fn new_empty() -> Self {
109            Self { augend: fidl::new_empty!(u8, D), addend: fidl::new_empty!(u8, D) }
110        }
111
112        #[inline]
113        unsafe fn decode(
114            &mut self,
115            decoder: &mut fidl::encoding::Decoder<'_, D>,
116            offset: usize,
117            _depth: fidl::encoding::Depth,
118        ) -> fidl::Result<()> {
119            decoder.debug_check_bounds::<Self>(offset);
120            let buf_ptr = unsafe { decoder.buf.as_ptr().add(offset) };
121            // Verify that padding bytes are zero.
122            // Copy from the buffer into the object.
123            unsafe {
124                std::ptr::copy_nonoverlapping(buf_ptr, self as *mut Self as *mut u8, 2);
125            }
126            Ok(())
127        }
128    }
129
130    impl fidl::encoding::ValueTypeMarker for SimpleAddResponse {
131        type Borrowed<'a> = &'a Self;
132        fn borrow(value: &<Self as fidl::encoding::TypeMarker>::Owned) -> Self::Borrowed<'_> {
133            value
134        }
135    }
136
137    unsafe impl fidl::encoding::TypeMarker for SimpleAddResponse {
138        type Owned = Self;
139
140        #[inline(always)]
141        fn inline_align(_context: fidl::encoding::Context) -> usize {
142            2
143        }
144
145        #[inline(always)]
146        fn inline_size(_context: fidl::encoding::Context) -> usize {
147            2
148        }
149        #[inline(always)]
150        fn encode_is_copy() -> bool {
151            true
152        }
153
154        #[inline(always)]
155        fn decode_is_copy() -> bool {
156            true
157        }
158    }
159
160    unsafe impl<D: fidl::encoding::ResourceDialect> fidl::encoding::Encode<SimpleAddResponse, D>
161        for &SimpleAddResponse
162    {
163        #[inline]
164        unsafe fn encode(
165            self,
166            encoder: &mut fidl::encoding::Encoder<'_, D>,
167            offset: usize,
168            _depth: fidl::encoding::Depth,
169        ) -> fidl::Result<()> {
170            encoder.debug_check_bounds::<SimpleAddResponse>(offset);
171            unsafe {
172                // Copy the object into the buffer.
173                let buf_ptr = encoder.buf.as_mut_ptr().add(offset);
174                (buf_ptr as *mut SimpleAddResponse)
175                    .write_unaligned((self as *const SimpleAddResponse).read());
176                // Zero out padding regions. Unlike `fidl_struct_impl_noncopy!`, this must be
177                // done second because the memcpy will write garbage to these bytes.
178            }
179            Ok(())
180        }
181    }
182    unsafe impl<D: fidl::encoding::ResourceDialect, T0: fidl::encoding::Encode<u16, D>>
183        fidl::encoding::Encode<SimpleAddResponse, D> for (T0,)
184    {
185        #[inline]
186        unsafe fn encode(
187            self,
188            encoder: &mut fidl::encoding::Encoder<'_, D>,
189            offset: usize,
190            depth: fidl::encoding::Depth,
191        ) -> fidl::Result<()> {
192            encoder.debug_check_bounds::<SimpleAddResponse>(offset);
193            // Zero out padding regions. There's no need to apply masks
194            // because the unmasked parts will be overwritten by fields.
195            // Write the fields.
196            self.0.encode(encoder, offset + 0, depth)?;
197            Ok(())
198        }
199    }
200
201    impl<D: fidl::encoding::ResourceDialect> fidl::encoding::Decode<Self, D> for SimpleAddResponse {
202        #[inline(always)]
203        fn new_empty() -> Self {
204            Self { sum: fidl::new_empty!(u16, D) }
205        }
206
207        #[inline]
208        unsafe fn decode(
209            &mut self,
210            decoder: &mut fidl::encoding::Decoder<'_, D>,
211            offset: usize,
212            _depth: fidl::encoding::Depth,
213        ) -> fidl::Result<()> {
214            decoder.debug_check_bounds::<Self>(offset);
215            let buf_ptr = unsafe { decoder.buf.as_ptr().add(offset) };
216            // Verify that padding bytes are zero.
217            // Copy from the buffer into the object.
218            unsafe {
219                std::ptr::copy_nonoverlapping(buf_ptr, self as *mut Self as *mut u8, 2);
220            }
221            Ok(())
222        }
223    }
224}