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