fidl_fuchsia_runtime_test_common/
fidl_fuchsia_runtime_test_common.rs1#![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, Default, PartialEq)]
12pub struct WrappedValue {
13 pub value: Option<u32>,
14 #[doc(hidden)]
15 pub __source_breaking: fidl::marker::SourceBreaking,
16}
17
18impl fidl::Persistable for WrappedValue {}
19
20mod internal {
21 use super::*;
22
23 impl WrappedValue {
24 #[inline(always)]
25 fn max_ordinal_present(&self) -> u64 {
26 if let Some(_) = self.value {
27 return 1;
28 }
29 0
30 }
31 }
32
33 impl fidl::encoding::ValueTypeMarker for WrappedValue {
34 type Borrowed<'a> = &'a Self;
35 fn borrow(value: &<Self as fidl::encoding::TypeMarker>::Owned) -> Self::Borrowed<'_> {
36 value
37 }
38 }
39
40 unsafe impl fidl::encoding::TypeMarker for WrappedValue {
41 type Owned = Self;
42
43 #[inline(always)]
44 fn inline_align(_context: fidl::encoding::Context) -> usize {
45 8
46 }
47
48 #[inline(always)]
49 fn inline_size(_context: fidl::encoding::Context) -> usize {
50 16
51 }
52 }
53
54 unsafe impl<D: fidl::encoding::ResourceDialect> fidl::encoding::Encode<WrappedValue, D>
55 for &WrappedValue
56 {
57 unsafe fn encode(
58 self,
59 encoder: &mut fidl::encoding::Encoder<'_, D>,
60 offset: usize,
61 mut depth: fidl::encoding::Depth,
62 ) -> fidl::Result<()> {
63 encoder.debug_check_bounds::<WrappedValue>(offset);
64 let max_ordinal: u64 = self.max_ordinal_present();
66 encoder.write_num(max_ordinal, offset);
67 encoder.write_num(fidl::encoding::ALLOC_PRESENT_U64, offset + 8);
68 if max_ordinal == 0 {
70 return Ok(());
71 }
72 depth.increment()?;
73 let envelope_size = 8;
74 let bytes_len = max_ordinal as usize * envelope_size;
75 #[allow(unused_variables)]
76 let offset = encoder.out_of_line_offset(bytes_len);
77 let mut _prev_end_offset: usize = 0;
78 if 1 > max_ordinal {
79 return Ok(());
80 }
81
82 let cur_offset: usize = (1 - 1) * envelope_size;
85
86 encoder.padding(offset + _prev_end_offset, cur_offset - _prev_end_offset);
88
89 fidl::encoding::encode_in_envelope_optional::<u32, D>(
94 self.value.as_ref().map(<u32 as fidl::encoding::ValueTypeMarker>::borrow),
95 encoder,
96 offset + cur_offset,
97 depth,
98 )?;
99
100 _prev_end_offset = cur_offset + envelope_size;
101
102 Ok(())
103 }
104 }
105
106 impl<D: fidl::encoding::ResourceDialect> fidl::encoding::Decode<Self, D> for WrappedValue {
107 #[inline(always)]
108 fn new_empty() -> Self {
109 Self::default()
110 }
111
112 unsafe fn decode(
113 &mut self,
114 decoder: &mut fidl::encoding::Decoder<'_, D>,
115 offset: usize,
116 mut depth: fidl::encoding::Depth,
117 ) -> fidl::Result<()> {
118 decoder.debug_check_bounds::<Self>(offset);
119 let len = match fidl::encoding::decode_vector_header(decoder, offset)? {
120 None => return Err(fidl::Error::NotNullable),
121 Some(len) => len,
122 };
123 if len == 0 {
125 return Ok(());
126 };
127 depth.increment()?;
128 let envelope_size = 8;
129 let bytes_len = len * envelope_size;
130 let offset = decoder.out_of_line_offset(bytes_len)?;
131 let mut _next_ordinal_to_read = 0;
133 let mut next_offset = offset;
134 let end_offset = offset + bytes_len;
135 _next_ordinal_to_read += 1;
136 if next_offset >= end_offset {
137 return Ok(());
138 }
139
140 while _next_ordinal_to_read < 1 {
142 fidl::encoding::decode_unknown_envelope(decoder, next_offset, depth)?;
143 _next_ordinal_to_read += 1;
144 next_offset += envelope_size;
145 }
146
147 let next_out_of_line = decoder.next_out_of_line();
148 let handles_before = decoder.remaining_handles();
149 if let Some((inlined, num_bytes, num_handles)) =
150 fidl::encoding::decode_envelope_header(decoder, next_offset)?
151 {
152 let member_inline_size =
153 <u32 as fidl::encoding::TypeMarker>::inline_size(decoder.context);
154 if inlined != (member_inline_size <= 4) {
155 return Err(fidl::Error::InvalidInlineBitInEnvelope);
156 }
157 let inner_offset;
158 let mut inner_depth = depth.clone();
159 if inlined {
160 decoder.check_inline_envelope_padding(next_offset, member_inline_size)?;
161 inner_offset = next_offset;
162 } else {
163 inner_offset = decoder.out_of_line_offset(member_inline_size)?;
164 inner_depth.increment()?;
165 }
166 let val_ref = self.value.get_or_insert_with(|| fidl::new_empty!(u32, D));
167 fidl::decode!(u32, D, val_ref, decoder, inner_offset, inner_depth)?;
168 if !inlined && decoder.next_out_of_line() != next_out_of_line + (num_bytes as usize)
169 {
170 return Err(fidl::Error::InvalidNumBytesInEnvelope);
171 }
172 if handles_before != decoder.remaining_handles() + (num_handles as usize) {
173 return Err(fidl::Error::InvalidNumHandlesInEnvelope);
174 }
175 }
176
177 next_offset += envelope_size;
178
179 while next_offset < end_offset {
181 _next_ordinal_to_read += 1;
182 fidl::encoding::decode_unknown_envelope(decoder, next_offset, depth)?;
183 next_offset += envelope_size;
184 }
185
186 Ok(())
187 }
188 }
189}