fidl_fuchsia_pkg_internal_common/
fidl_fuchsia_pkg_internal_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 PersistentEagerPackage {
13 pub url: Option<fidl_fuchsia_pkg::PackageUrl>,
14 pub cup: Option<fidl_fuchsia_pkg::CupData>,
15 #[doc(hidden)]
16 pub __source_breaking: fidl::marker::SourceBreaking,
17}
18
19impl fidl::Persistable for PersistentEagerPackage {}
20
21#[derive(Clone, Debug, Default, PartialEq)]
23pub struct PersistentEagerPackages {
24 pub packages: Option<Vec<PersistentEagerPackage>>,
25 #[doc(hidden)]
26 pub __source_breaking: fidl::marker::SourceBreaking,
27}
28
29impl fidl::Persistable for PersistentEagerPackages {}
30
31mod internal {
32 use super::*;
33
34 impl PersistentEagerPackage {
35 #[inline(always)]
36 fn max_ordinal_present(&self) -> u64 {
37 if let Some(_) = self.cup {
38 return 2;
39 }
40 if let Some(_) = self.url {
41 return 1;
42 }
43 0
44 }
45 }
46
47 impl fidl::encoding::ValueTypeMarker for PersistentEagerPackage {
48 type Borrowed<'a> = &'a Self;
49 fn borrow(value: &<Self as fidl::encoding::TypeMarker>::Owned) -> Self::Borrowed<'_> {
50 value
51 }
52 }
53
54 unsafe impl fidl::encoding::TypeMarker for PersistentEagerPackage {
55 type Owned = Self;
56
57 #[inline(always)]
58 fn inline_align(_context: fidl::encoding::Context) -> usize {
59 8
60 }
61
62 #[inline(always)]
63 fn inline_size(_context: fidl::encoding::Context) -> usize {
64 16
65 }
66 }
67
68 unsafe impl<D: fidl::encoding::ResourceDialect>
69 fidl::encoding::Encode<PersistentEagerPackage, D> for &PersistentEagerPackage
70 {
71 unsafe fn encode(
72 self,
73 encoder: &mut fidl::encoding::Encoder<'_, D>,
74 offset: usize,
75 mut depth: fidl::encoding::Depth,
76 ) -> fidl::Result<()> {
77 encoder.debug_check_bounds::<PersistentEagerPackage>(offset);
78 let max_ordinal: u64 = self.max_ordinal_present();
80 encoder.write_num(max_ordinal, offset);
81 encoder.write_num(fidl::encoding::ALLOC_PRESENT_U64, offset + 8);
82 if max_ordinal == 0 {
84 return Ok(());
85 }
86 depth.increment()?;
87 let envelope_size = 8;
88 let bytes_len = max_ordinal as usize * envelope_size;
89 #[allow(unused_variables)]
90 let offset = encoder.out_of_line_offset(bytes_len);
91 let mut _prev_end_offset: usize = 0;
92 if 1 > max_ordinal {
93 return Ok(());
94 }
95
96 let cur_offset: usize = (1 - 1) * envelope_size;
99
100 encoder.padding(offset + _prev_end_offset, cur_offset - _prev_end_offset);
102
103 fidl::encoding::encode_in_envelope_optional::<fidl_fuchsia_pkg::PackageUrl, D>(
108 self.url
109 .as_ref()
110 .map(<fidl_fuchsia_pkg::PackageUrl as fidl::encoding::ValueTypeMarker>::borrow),
111 encoder,
112 offset + cur_offset,
113 depth,
114 )?;
115
116 _prev_end_offset = cur_offset + envelope_size;
117 if 2 > max_ordinal {
118 return Ok(());
119 }
120
121 let cur_offset: usize = (2 - 1) * envelope_size;
124
125 encoder.padding(offset + _prev_end_offset, cur_offset - _prev_end_offset);
127
128 fidl::encoding::encode_in_envelope_optional::<fidl_fuchsia_pkg::CupData, D>(
133 self.cup
134 .as_ref()
135 .map(<fidl_fuchsia_pkg::CupData as fidl::encoding::ValueTypeMarker>::borrow),
136 encoder,
137 offset + cur_offset,
138 depth,
139 )?;
140
141 _prev_end_offset = cur_offset + envelope_size;
142
143 Ok(())
144 }
145 }
146
147 impl<D: fidl::encoding::ResourceDialect> fidl::encoding::Decode<Self, D>
148 for PersistentEagerPackage
149 {
150 #[inline(always)]
151 fn new_empty() -> Self {
152 Self::default()
153 }
154
155 unsafe fn decode(
156 &mut self,
157 decoder: &mut fidl::encoding::Decoder<'_, D>,
158 offset: usize,
159 mut depth: fidl::encoding::Depth,
160 ) -> fidl::Result<()> {
161 decoder.debug_check_bounds::<Self>(offset);
162 let len = match fidl::encoding::decode_vector_header(decoder, offset)? {
163 None => return Err(fidl::Error::NotNullable),
164 Some(len) => len,
165 };
166 if len == 0 {
168 return Ok(());
169 };
170 depth.increment()?;
171 let envelope_size = 8;
172 let bytes_len = len * envelope_size;
173 let offset = decoder.out_of_line_offset(bytes_len)?;
174 let mut _next_ordinal_to_read = 0;
176 let mut next_offset = offset;
177 let end_offset = offset + bytes_len;
178 _next_ordinal_to_read += 1;
179 if next_offset >= end_offset {
180 return Ok(());
181 }
182
183 while _next_ordinal_to_read < 1 {
185 fidl::encoding::decode_unknown_envelope(decoder, next_offset, depth)?;
186 _next_ordinal_to_read += 1;
187 next_offset += envelope_size;
188 }
189
190 let next_out_of_line = decoder.next_out_of_line();
191 let handles_before = decoder.remaining_handles();
192 if let Some((inlined, num_bytes, num_handles)) =
193 fidl::encoding::decode_envelope_header(decoder, next_offset)?
194 {
195 let member_inline_size =
196 <fidl_fuchsia_pkg::PackageUrl as fidl::encoding::TypeMarker>::inline_size(
197 decoder.context,
198 );
199 if inlined != (member_inline_size <= 4) {
200 return Err(fidl::Error::InvalidInlineBitInEnvelope);
201 }
202 let inner_offset;
203 let mut inner_depth = depth.clone();
204 if inlined {
205 decoder.check_inline_envelope_padding(next_offset, member_inline_size)?;
206 inner_offset = next_offset;
207 } else {
208 inner_offset = decoder.out_of_line_offset(member_inline_size)?;
209 inner_depth.increment()?;
210 }
211 let val_ref = self
212 .url
213 .get_or_insert_with(|| fidl::new_empty!(fidl_fuchsia_pkg::PackageUrl, D));
214 fidl::decode!(
215 fidl_fuchsia_pkg::PackageUrl,
216 D,
217 val_ref,
218 decoder,
219 inner_offset,
220 inner_depth
221 )?;
222 if !inlined && decoder.next_out_of_line() != next_out_of_line + (num_bytes as usize)
223 {
224 return Err(fidl::Error::InvalidNumBytesInEnvelope);
225 }
226 if handles_before != decoder.remaining_handles() + (num_handles as usize) {
227 return Err(fidl::Error::InvalidNumHandlesInEnvelope);
228 }
229 }
230
231 next_offset += envelope_size;
232 _next_ordinal_to_read += 1;
233 if next_offset >= end_offset {
234 return Ok(());
235 }
236
237 while _next_ordinal_to_read < 2 {
239 fidl::encoding::decode_unknown_envelope(decoder, next_offset, depth)?;
240 _next_ordinal_to_read += 1;
241 next_offset += envelope_size;
242 }
243
244 let next_out_of_line = decoder.next_out_of_line();
245 let handles_before = decoder.remaining_handles();
246 if let Some((inlined, num_bytes, num_handles)) =
247 fidl::encoding::decode_envelope_header(decoder, next_offset)?
248 {
249 let member_inline_size =
250 <fidl_fuchsia_pkg::CupData as fidl::encoding::TypeMarker>::inline_size(
251 decoder.context,
252 );
253 if inlined != (member_inline_size <= 4) {
254 return Err(fidl::Error::InvalidInlineBitInEnvelope);
255 }
256 let inner_offset;
257 let mut inner_depth = depth.clone();
258 if inlined {
259 decoder.check_inline_envelope_padding(next_offset, member_inline_size)?;
260 inner_offset = next_offset;
261 } else {
262 inner_offset = decoder.out_of_line_offset(member_inline_size)?;
263 inner_depth.increment()?;
264 }
265 let val_ref =
266 self.cup.get_or_insert_with(|| fidl::new_empty!(fidl_fuchsia_pkg::CupData, D));
267 fidl::decode!(
268 fidl_fuchsia_pkg::CupData,
269 D,
270 val_ref,
271 decoder,
272 inner_offset,
273 inner_depth
274 )?;
275 if !inlined && decoder.next_out_of_line() != next_out_of_line + (num_bytes as usize)
276 {
277 return Err(fidl::Error::InvalidNumBytesInEnvelope);
278 }
279 if handles_before != decoder.remaining_handles() + (num_handles as usize) {
280 return Err(fidl::Error::InvalidNumHandlesInEnvelope);
281 }
282 }
283
284 next_offset += envelope_size;
285
286 while next_offset < end_offset {
288 _next_ordinal_to_read += 1;
289 fidl::encoding::decode_unknown_envelope(decoder, next_offset, depth)?;
290 next_offset += envelope_size;
291 }
292
293 Ok(())
294 }
295 }
296
297 impl PersistentEagerPackages {
298 #[inline(always)]
299 fn max_ordinal_present(&self) -> u64 {
300 if let Some(_) = self.packages {
301 return 1;
302 }
303 0
304 }
305 }
306
307 impl fidl::encoding::ValueTypeMarker for PersistentEagerPackages {
308 type Borrowed<'a> = &'a Self;
309 fn borrow(value: &<Self as fidl::encoding::TypeMarker>::Owned) -> Self::Borrowed<'_> {
310 value
311 }
312 }
313
314 unsafe impl fidl::encoding::TypeMarker for PersistentEagerPackages {
315 type Owned = Self;
316
317 #[inline(always)]
318 fn inline_align(_context: fidl::encoding::Context) -> usize {
319 8
320 }
321
322 #[inline(always)]
323 fn inline_size(_context: fidl::encoding::Context) -> usize {
324 16
325 }
326 }
327
328 unsafe impl<D: fidl::encoding::ResourceDialect>
329 fidl::encoding::Encode<PersistentEagerPackages, D> for &PersistentEagerPackages
330 {
331 unsafe fn encode(
332 self,
333 encoder: &mut fidl::encoding::Encoder<'_, D>,
334 offset: usize,
335 mut depth: fidl::encoding::Depth,
336 ) -> fidl::Result<()> {
337 encoder.debug_check_bounds::<PersistentEagerPackages>(offset);
338 let max_ordinal: u64 = self.max_ordinal_present();
340 encoder.write_num(max_ordinal, offset);
341 encoder.write_num(fidl::encoding::ALLOC_PRESENT_U64, offset + 8);
342 if max_ordinal == 0 {
344 return Ok(());
345 }
346 depth.increment()?;
347 let envelope_size = 8;
348 let bytes_len = max_ordinal as usize * envelope_size;
349 #[allow(unused_variables)]
350 let offset = encoder.out_of_line_offset(bytes_len);
351 let mut _prev_end_offset: usize = 0;
352 if 1 > max_ordinal {
353 return Ok(());
354 }
355
356 let cur_offset: usize = (1 - 1) * envelope_size;
359
360 encoder.padding(offset + _prev_end_offset, cur_offset - _prev_end_offset);
362
363 fidl::encoding::encode_in_envelope_optional::<fidl::encoding::Vector<PersistentEagerPackage, 128>, D>(
368 self.packages.as_ref().map(<fidl::encoding::Vector<PersistentEagerPackage, 128> as fidl::encoding::ValueTypeMarker>::borrow),
369 encoder, offset + cur_offset, depth
370 )?;
371
372 _prev_end_offset = cur_offset + envelope_size;
373
374 Ok(())
375 }
376 }
377
378 impl<D: fidl::encoding::ResourceDialect> fidl::encoding::Decode<Self, D>
379 for PersistentEagerPackages
380 {
381 #[inline(always)]
382 fn new_empty() -> Self {
383 Self::default()
384 }
385
386 unsafe fn decode(
387 &mut self,
388 decoder: &mut fidl::encoding::Decoder<'_, D>,
389 offset: usize,
390 mut depth: fidl::encoding::Depth,
391 ) -> fidl::Result<()> {
392 decoder.debug_check_bounds::<Self>(offset);
393 let len = match fidl::encoding::decode_vector_header(decoder, offset)? {
394 None => return Err(fidl::Error::NotNullable),
395 Some(len) => len,
396 };
397 if len == 0 {
399 return Ok(());
400 };
401 depth.increment()?;
402 let envelope_size = 8;
403 let bytes_len = len * envelope_size;
404 let offset = decoder.out_of_line_offset(bytes_len)?;
405 let mut _next_ordinal_to_read = 0;
407 let mut next_offset = offset;
408 let end_offset = offset + bytes_len;
409 _next_ordinal_to_read += 1;
410 if next_offset >= end_offset {
411 return Ok(());
412 }
413
414 while _next_ordinal_to_read < 1 {
416 fidl::encoding::decode_unknown_envelope(decoder, next_offset, depth)?;
417 _next_ordinal_to_read += 1;
418 next_offset += envelope_size;
419 }
420
421 let next_out_of_line = decoder.next_out_of_line();
422 let handles_before = decoder.remaining_handles();
423 if let Some((inlined, num_bytes, num_handles)) =
424 fidl::encoding::decode_envelope_header(decoder, next_offset)?
425 {
426 let member_inline_size = <fidl::encoding::Vector<PersistentEagerPackage, 128> as fidl::encoding::TypeMarker>::inline_size(decoder.context);
427 if inlined != (member_inline_size <= 4) {
428 return Err(fidl::Error::InvalidInlineBitInEnvelope);
429 }
430 let inner_offset;
431 let mut inner_depth = depth.clone();
432 if inlined {
433 decoder.check_inline_envelope_padding(next_offset, member_inline_size)?;
434 inner_offset = next_offset;
435 } else {
436 inner_offset = decoder.out_of_line_offset(member_inline_size)?;
437 inner_depth.increment()?;
438 }
439 let val_ref = self.packages.get_or_insert_with(
440 || fidl::new_empty!(fidl::encoding::Vector<PersistentEagerPackage, 128>, D),
441 );
442 fidl::decode!(fidl::encoding::Vector<PersistentEagerPackage, 128>, D, val_ref, decoder, inner_offset, inner_depth)?;
443 if !inlined && decoder.next_out_of_line() != next_out_of_line + (num_bytes as usize)
444 {
445 return Err(fidl::Error::InvalidNumBytesInEnvelope);
446 }
447 if handles_before != decoder.remaining_handles() + (num_handles as usize) {
448 return Err(fidl::Error::InvalidNumHandlesInEnvelope);
449 }
450 }
451
452 next_offset += envelope_size;
453
454 while next_offset < end_offset {
456 _next_ordinal_to_read += 1;
457 fidl::encoding::decode_unknown_envelope(decoder, next_offset, depth)?;
458 next_offset += envelope_size;
459 }
460
461 Ok(())
462 }
463 }
464}