fidl_fidl_test_schema_common/
fidl_fidl_test_schema_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, Default, PartialEq)]
12pub struct DataTable1 {
13    pub num: Option<i32>,
14    pub string: Option<String>,
15    #[doc(hidden)]
16    pub __source_breaking: fidl::marker::SourceBreaking,
17}
18
19impl fidl::Persistable for DataTable1 {}
20
21#[derive(Clone, Debug, Default, PartialEq)]
22pub struct DataTable2 {
23    pub num: Option<i32>,
24    pub string: Option<String>,
25    pub new_field: Option<String>,
26    #[doc(hidden)]
27    pub __source_breaking: fidl::marker::SourceBreaking,
28}
29
30impl fidl::Persistable for DataTable2 {}
31
32mod internal {
33    use super::*;
34
35    impl DataTable1 {
36        #[inline(always)]
37        fn max_ordinal_present(&self) -> u64 {
38            if let Some(_) = self.string {
39                return 2;
40            }
41            if let Some(_) = self.num {
42                return 1;
43            }
44            0
45        }
46    }
47
48    impl fidl::encoding::ValueTypeMarker for DataTable1 {
49        type Borrowed<'a> = &'a Self;
50        fn borrow(value: &<Self as fidl::encoding::TypeMarker>::Owned) -> Self::Borrowed<'_> {
51            value
52        }
53    }
54
55    unsafe impl fidl::encoding::TypeMarker for DataTable1 {
56        type Owned = Self;
57
58        #[inline(always)]
59        fn inline_align(_context: fidl::encoding::Context) -> usize {
60            8
61        }
62
63        #[inline(always)]
64        fn inline_size(_context: fidl::encoding::Context) -> usize {
65            16
66        }
67    }
68
69    unsafe impl<D: fidl::encoding::ResourceDialect> fidl::encoding::Encode<DataTable1, D>
70        for &DataTable1
71    {
72        unsafe fn encode(
73            self,
74            encoder: &mut fidl::encoding::Encoder<'_, D>,
75            offset: usize,
76            mut depth: fidl::encoding::Depth,
77        ) -> fidl::Result<()> {
78            encoder.debug_check_bounds::<DataTable1>(offset);
79            // Vector header
80            let max_ordinal: u64 = self.max_ordinal_present();
81            encoder.write_num(max_ordinal, offset);
82            encoder.write_num(fidl::encoding::ALLOC_PRESENT_U64, offset + 8);
83            // Calling encoder.out_of_line_offset(0) is not allowed.
84            if max_ordinal == 0 {
85                return Ok(());
86            }
87            depth.increment()?;
88            let envelope_size = 8;
89            let bytes_len = max_ordinal as usize * envelope_size;
90            #[allow(unused_variables)]
91            let offset = encoder.out_of_line_offset(bytes_len);
92            let mut _prev_end_offset: usize = 0;
93            if 1 > max_ordinal {
94                return Ok(());
95            }
96
97            // Write at offset+(ordinal-1)*envelope_size, since ordinals are one-based and envelopes
98            // are envelope_size bytes.
99            let cur_offset: usize = (1 - 1) * envelope_size;
100
101            // Zero reserved fields.
102            encoder.padding(offset + _prev_end_offset, cur_offset - _prev_end_offset);
103
104            // Safety:
105            // - bytes_len is calculated to fit envelope_size*max(member.ordinal).
106            // - Since cur_offset is envelope_size*(member.ordinal - 1) and the envelope takes
107            //   envelope_size bytes, there is always sufficient room.
108            fidl::encoding::encode_in_envelope_optional::<i32, D>(
109                self.num.as_ref().map(<i32 as fidl::encoding::ValueTypeMarker>::borrow),
110                encoder,
111                offset + cur_offset,
112                depth,
113            )?;
114
115            _prev_end_offset = cur_offset + envelope_size;
116            if 2 > max_ordinal {
117                return Ok(());
118            }
119
120            // Write at offset+(ordinal-1)*envelope_size, since ordinals are one-based and envelopes
121            // are envelope_size bytes.
122            let cur_offset: usize = (2 - 1) * envelope_size;
123
124            // Zero reserved fields.
125            encoder.padding(offset + _prev_end_offset, cur_offset - _prev_end_offset);
126
127            // Safety:
128            // - bytes_len is calculated to fit envelope_size*max(member.ordinal).
129            // - Since cur_offset is envelope_size*(member.ordinal - 1) and the envelope takes
130            //   envelope_size bytes, there is always sufficient room.
131            fidl::encoding::encode_in_envelope_optional::<fidl::encoding::UnboundedString, D>(
132                self.string.as_ref().map(
133                    <fidl::encoding::UnboundedString as fidl::encoding::ValueTypeMarker>::borrow,
134                ),
135                encoder,
136                offset + cur_offset,
137                depth,
138            )?;
139
140            _prev_end_offset = cur_offset + envelope_size;
141
142            Ok(())
143        }
144    }
145
146    impl<D: fidl::encoding::ResourceDialect> fidl::encoding::Decode<Self, D> for DataTable1 {
147        #[inline(always)]
148        fn new_empty() -> Self {
149            Self::default()
150        }
151
152        unsafe fn decode(
153            &mut self,
154            decoder: &mut fidl::encoding::Decoder<'_, D>,
155            offset: usize,
156            mut depth: fidl::encoding::Depth,
157        ) -> fidl::Result<()> {
158            decoder.debug_check_bounds::<Self>(offset);
159            let len = match fidl::encoding::decode_vector_header(decoder, offset)? {
160                None => return Err(fidl::Error::NotNullable),
161                Some(len) => len,
162            };
163            // Calling decoder.out_of_line_offset(0) is not allowed.
164            if len == 0 {
165                return Ok(());
166            };
167            depth.increment()?;
168            let envelope_size = 8;
169            let bytes_len = len * envelope_size;
170            let offset = decoder.out_of_line_offset(bytes_len)?;
171            // Decode the envelope for each type.
172            let mut _next_ordinal_to_read = 0;
173            let mut next_offset = offset;
174            let end_offset = offset + bytes_len;
175            _next_ordinal_to_read += 1;
176            if next_offset >= end_offset {
177                return Ok(());
178            }
179
180            // Decode unknown envelopes for gaps in ordinals.
181            while _next_ordinal_to_read < 1 {
182                fidl::encoding::decode_unknown_envelope(decoder, next_offset, depth)?;
183                _next_ordinal_to_read += 1;
184                next_offset += envelope_size;
185            }
186
187            let next_out_of_line = decoder.next_out_of_line();
188            let handles_before = decoder.remaining_handles();
189            if let Some((inlined, num_bytes, num_handles)) =
190                fidl::encoding::decode_envelope_header(decoder, next_offset)?
191            {
192                let member_inline_size =
193                    <i32 as fidl::encoding::TypeMarker>::inline_size(decoder.context);
194                if inlined != (member_inline_size <= 4) {
195                    return Err(fidl::Error::InvalidInlineBitInEnvelope);
196                }
197                let inner_offset;
198                let mut inner_depth = depth.clone();
199                if inlined {
200                    decoder.check_inline_envelope_padding(next_offset, member_inline_size)?;
201                    inner_offset = next_offset;
202                } else {
203                    inner_offset = decoder.out_of_line_offset(member_inline_size)?;
204                    inner_depth.increment()?;
205                }
206                let val_ref = self.num.get_or_insert_with(|| fidl::new_empty!(i32, D));
207                fidl::decode!(i32, D, val_ref, decoder, inner_offset, inner_depth)?;
208                if !inlined && decoder.next_out_of_line() != next_out_of_line + (num_bytes as usize)
209                {
210                    return Err(fidl::Error::InvalidNumBytesInEnvelope);
211                }
212                if handles_before != decoder.remaining_handles() + (num_handles as usize) {
213                    return Err(fidl::Error::InvalidNumHandlesInEnvelope);
214                }
215            }
216
217            next_offset += envelope_size;
218            _next_ordinal_to_read += 1;
219            if next_offset >= end_offset {
220                return Ok(());
221            }
222
223            // Decode unknown envelopes for gaps in ordinals.
224            while _next_ordinal_to_read < 2 {
225                fidl::encoding::decode_unknown_envelope(decoder, next_offset, depth)?;
226                _next_ordinal_to_read += 1;
227                next_offset += envelope_size;
228            }
229
230            let next_out_of_line = decoder.next_out_of_line();
231            let handles_before = decoder.remaining_handles();
232            if let Some((inlined, num_bytes, num_handles)) =
233                fidl::encoding::decode_envelope_header(decoder, next_offset)?
234            {
235                let member_inline_size =
236                    <fidl::encoding::UnboundedString as fidl::encoding::TypeMarker>::inline_size(
237                        decoder.context,
238                    );
239                if inlined != (member_inline_size <= 4) {
240                    return Err(fidl::Error::InvalidInlineBitInEnvelope);
241                }
242                let inner_offset;
243                let mut inner_depth = depth.clone();
244                if inlined {
245                    decoder.check_inline_envelope_padding(next_offset, member_inline_size)?;
246                    inner_offset = next_offset;
247                } else {
248                    inner_offset = decoder.out_of_line_offset(member_inline_size)?;
249                    inner_depth.increment()?;
250                }
251                let val_ref = self
252                    .string
253                    .get_or_insert_with(|| fidl::new_empty!(fidl::encoding::UnboundedString, D));
254                fidl::decode!(
255                    fidl::encoding::UnboundedString,
256                    D,
257                    val_ref,
258                    decoder,
259                    inner_offset,
260                    inner_depth
261                )?;
262                if !inlined && decoder.next_out_of_line() != next_out_of_line + (num_bytes as usize)
263                {
264                    return Err(fidl::Error::InvalidNumBytesInEnvelope);
265                }
266                if handles_before != decoder.remaining_handles() + (num_handles as usize) {
267                    return Err(fidl::Error::InvalidNumHandlesInEnvelope);
268                }
269            }
270
271            next_offset += envelope_size;
272
273            // Decode the remaining unknown envelopes.
274            while next_offset < end_offset {
275                _next_ordinal_to_read += 1;
276                fidl::encoding::decode_unknown_envelope(decoder, next_offset, depth)?;
277                next_offset += envelope_size;
278            }
279
280            Ok(())
281        }
282    }
283
284    impl DataTable2 {
285        #[inline(always)]
286        fn max_ordinal_present(&self) -> u64 {
287            if let Some(_) = self.new_field {
288                return 3;
289            }
290            if let Some(_) = self.string {
291                return 2;
292            }
293            if let Some(_) = self.num {
294                return 1;
295            }
296            0
297        }
298    }
299
300    impl fidl::encoding::ValueTypeMarker for DataTable2 {
301        type Borrowed<'a> = &'a Self;
302        fn borrow(value: &<Self as fidl::encoding::TypeMarker>::Owned) -> Self::Borrowed<'_> {
303            value
304        }
305    }
306
307    unsafe impl fidl::encoding::TypeMarker for DataTable2 {
308        type Owned = Self;
309
310        #[inline(always)]
311        fn inline_align(_context: fidl::encoding::Context) -> usize {
312            8
313        }
314
315        #[inline(always)]
316        fn inline_size(_context: fidl::encoding::Context) -> usize {
317            16
318        }
319    }
320
321    unsafe impl<D: fidl::encoding::ResourceDialect> fidl::encoding::Encode<DataTable2, D>
322        for &DataTable2
323    {
324        unsafe fn encode(
325            self,
326            encoder: &mut fidl::encoding::Encoder<'_, D>,
327            offset: usize,
328            mut depth: fidl::encoding::Depth,
329        ) -> fidl::Result<()> {
330            encoder.debug_check_bounds::<DataTable2>(offset);
331            // Vector header
332            let max_ordinal: u64 = self.max_ordinal_present();
333            encoder.write_num(max_ordinal, offset);
334            encoder.write_num(fidl::encoding::ALLOC_PRESENT_U64, offset + 8);
335            // Calling encoder.out_of_line_offset(0) is not allowed.
336            if max_ordinal == 0 {
337                return Ok(());
338            }
339            depth.increment()?;
340            let envelope_size = 8;
341            let bytes_len = max_ordinal as usize * envelope_size;
342            #[allow(unused_variables)]
343            let offset = encoder.out_of_line_offset(bytes_len);
344            let mut _prev_end_offset: usize = 0;
345            if 1 > max_ordinal {
346                return Ok(());
347            }
348
349            // Write at offset+(ordinal-1)*envelope_size, since ordinals are one-based and envelopes
350            // are envelope_size bytes.
351            let cur_offset: usize = (1 - 1) * envelope_size;
352
353            // Zero reserved fields.
354            encoder.padding(offset + _prev_end_offset, cur_offset - _prev_end_offset);
355
356            // Safety:
357            // - bytes_len is calculated to fit envelope_size*max(member.ordinal).
358            // - Since cur_offset is envelope_size*(member.ordinal - 1) and the envelope takes
359            //   envelope_size bytes, there is always sufficient room.
360            fidl::encoding::encode_in_envelope_optional::<i32, D>(
361                self.num.as_ref().map(<i32 as fidl::encoding::ValueTypeMarker>::borrow),
362                encoder,
363                offset + cur_offset,
364                depth,
365            )?;
366
367            _prev_end_offset = cur_offset + envelope_size;
368            if 2 > max_ordinal {
369                return Ok(());
370            }
371
372            // Write at offset+(ordinal-1)*envelope_size, since ordinals are one-based and envelopes
373            // are envelope_size bytes.
374            let cur_offset: usize = (2 - 1) * envelope_size;
375
376            // Zero reserved fields.
377            encoder.padding(offset + _prev_end_offset, cur_offset - _prev_end_offset);
378
379            // Safety:
380            // - bytes_len is calculated to fit envelope_size*max(member.ordinal).
381            // - Since cur_offset is envelope_size*(member.ordinal - 1) and the envelope takes
382            //   envelope_size bytes, there is always sufficient room.
383            fidl::encoding::encode_in_envelope_optional::<fidl::encoding::UnboundedString, D>(
384                self.string.as_ref().map(
385                    <fidl::encoding::UnboundedString as fidl::encoding::ValueTypeMarker>::borrow,
386                ),
387                encoder,
388                offset + cur_offset,
389                depth,
390            )?;
391
392            _prev_end_offset = cur_offset + envelope_size;
393            if 3 > max_ordinal {
394                return Ok(());
395            }
396
397            // Write at offset+(ordinal-1)*envelope_size, since ordinals are one-based and envelopes
398            // are envelope_size bytes.
399            let cur_offset: usize = (3 - 1) * envelope_size;
400
401            // Zero reserved fields.
402            encoder.padding(offset + _prev_end_offset, cur_offset - _prev_end_offset);
403
404            // Safety:
405            // - bytes_len is calculated to fit envelope_size*max(member.ordinal).
406            // - Since cur_offset is envelope_size*(member.ordinal - 1) and the envelope takes
407            //   envelope_size bytes, there is always sufficient room.
408            fidl::encoding::encode_in_envelope_optional::<fidl::encoding::UnboundedString, D>(
409                self.new_field.as_ref().map(
410                    <fidl::encoding::UnboundedString as fidl::encoding::ValueTypeMarker>::borrow,
411                ),
412                encoder,
413                offset + cur_offset,
414                depth,
415            )?;
416
417            _prev_end_offset = cur_offset + envelope_size;
418
419            Ok(())
420        }
421    }
422
423    impl<D: fidl::encoding::ResourceDialect> fidl::encoding::Decode<Self, D> for DataTable2 {
424        #[inline(always)]
425        fn new_empty() -> Self {
426            Self::default()
427        }
428
429        unsafe fn decode(
430            &mut self,
431            decoder: &mut fidl::encoding::Decoder<'_, D>,
432            offset: usize,
433            mut depth: fidl::encoding::Depth,
434        ) -> fidl::Result<()> {
435            decoder.debug_check_bounds::<Self>(offset);
436            let len = match fidl::encoding::decode_vector_header(decoder, offset)? {
437                None => return Err(fidl::Error::NotNullable),
438                Some(len) => len,
439            };
440            // Calling decoder.out_of_line_offset(0) is not allowed.
441            if len == 0 {
442                return Ok(());
443            };
444            depth.increment()?;
445            let envelope_size = 8;
446            let bytes_len = len * envelope_size;
447            let offset = decoder.out_of_line_offset(bytes_len)?;
448            // Decode the envelope for each type.
449            let mut _next_ordinal_to_read = 0;
450            let mut next_offset = offset;
451            let end_offset = offset + bytes_len;
452            _next_ordinal_to_read += 1;
453            if next_offset >= end_offset {
454                return Ok(());
455            }
456
457            // Decode unknown envelopes for gaps in ordinals.
458            while _next_ordinal_to_read < 1 {
459                fidl::encoding::decode_unknown_envelope(decoder, next_offset, depth)?;
460                _next_ordinal_to_read += 1;
461                next_offset += envelope_size;
462            }
463
464            let next_out_of_line = decoder.next_out_of_line();
465            let handles_before = decoder.remaining_handles();
466            if let Some((inlined, num_bytes, num_handles)) =
467                fidl::encoding::decode_envelope_header(decoder, next_offset)?
468            {
469                let member_inline_size =
470                    <i32 as fidl::encoding::TypeMarker>::inline_size(decoder.context);
471                if inlined != (member_inline_size <= 4) {
472                    return Err(fidl::Error::InvalidInlineBitInEnvelope);
473                }
474                let inner_offset;
475                let mut inner_depth = depth.clone();
476                if inlined {
477                    decoder.check_inline_envelope_padding(next_offset, member_inline_size)?;
478                    inner_offset = next_offset;
479                } else {
480                    inner_offset = decoder.out_of_line_offset(member_inline_size)?;
481                    inner_depth.increment()?;
482                }
483                let val_ref = self.num.get_or_insert_with(|| fidl::new_empty!(i32, D));
484                fidl::decode!(i32, D, val_ref, decoder, inner_offset, inner_depth)?;
485                if !inlined && decoder.next_out_of_line() != next_out_of_line + (num_bytes as usize)
486                {
487                    return Err(fidl::Error::InvalidNumBytesInEnvelope);
488                }
489                if handles_before != decoder.remaining_handles() + (num_handles as usize) {
490                    return Err(fidl::Error::InvalidNumHandlesInEnvelope);
491                }
492            }
493
494            next_offset += envelope_size;
495            _next_ordinal_to_read += 1;
496            if next_offset >= end_offset {
497                return Ok(());
498            }
499
500            // Decode unknown envelopes for gaps in ordinals.
501            while _next_ordinal_to_read < 2 {
502                fidl::encoding::decode_unknown_envelope(decoder, next_offset, depth)?;
503                _next_ordinal_to_read += 1;
504                next_offset += envelope_size;
505            }
506
507            let next_out_of_line = decoder.next_out_of_line();
508            let handles_before = decoder.remaining_handles();
509            if let Some((inlined, num_bytes, num_handles)) =
510                fidl::encoding::decode_envelope_header(decoder, next_offset)?
511            {
512                let member_inline_size =
513                    <fidl::encoding::UnboundedString as fidl::encoding::TypeMarker>::inline_size(
514                        decoder.context,
515                    );
516                if inlined != (member_inline_size <= 4) {
517                    return Err(fidl::Error::InvalidInlineBitInEnvelope);
518                }
519                let inner_offset;
520                let mut inner_depth = depth.clone();
521                if inlined {
522                    decoder.check_inline_envelope_padding(next_offset, member_inline_size)?;
523                    inner_offset = next_offset;
524                } else {
525                    inner_offset = decoder.out_of_line_offset(member_inline_size)?;
526                    inner_depth.increment()?;
527                }
528                let val_ref = self
529                    .string
530                    .get_or_insert_with(|| fidl::new_empty!(fidl::encoding::UnboundedString, D));
531                fidl::decode!(
532                    fidl::encoding::UnboundedString,
533                    D,
534                    val_ref,
535                    decoder,
536                    inner_offset,
537                    inner_depth
538                )?;
539                if !inlined && decoder.next_out_of_line() != next_out_of_line + (num_bytes as usize)
540                {
541                    return Err(fidl::Error::InvalidNumBytesInEnvelope);
542                }
543                if handles_before != decoder.remaining_handles() + (num_handles as usize) {
544                    return Err(fidl::Error::InvalidNumHandlesInEnvelope);
545                }
546            }
547
548            next_offset += envelope_size;
549            _next_ordinal_to_read += 1;
550            if next_offset >= end_offset {
551                return Ok(());
552            }
553
554            // Decode unknown envelopes for gaps in ordinals.
555            while _next_ordinal_to_read < 3 {
556                fidl::encoding::decode_unknown_envelope(decoder, next_offset, depth)?;
557                _next_ordinal_to_read += 1;
558                next_offset += envelope_size;
559            }
560
561            let next_out_of_line = decoder.next_out_of_line();
562            let handles_before = decoder.remaining_handles();
563            if let Some((inlined, num_bytes, num_handles)) =
564                fidl::encoding::decode_envelope_header(decoder, next_offset)?
565            {
566                let member_inline_size =
567                    <fidl::encoding::UnboundedString as fidl::encoding::TypeMarker>::inline_size(
568                        decoder.context,
569                    );
570                if inlined != (member_inline_size <= 4) {
571                    return Err(fidl::Error::InvalidInlineBitInEnvelope);
572                }
573                let inner_offset;
574                let mut inner_depth = depth.clone();
575                if inlined {
576                    decoder.check_inline_envelope_padding(next_offset, member_inline_size)?;
577                    inner_offset = next_offset;
578                } else {
579                    inner_offset = decoder.out_of_line_offset(member_inline_size)?;
580                    inner_depth.increment()?;
581                }
582                let val_ref = self
583                    .new_field
584                    .get_or_insert_with(|| fidl::new_empty!(fidl::encoding::UnboundedString, D));
585                fidl::decode!(
586                    fidl::encoding::UnboundedString,
587                    D,
588                    val_ref,
589                    decoder,
590                    inner_offset,
591                    inner_depth
592                )?;
593                if !inlined && decoder.next_out_of_line() != next_out_of_line + (num_bytes as usize)
594                {
595                    return Err(fidl::Error::InvalidNumBytesInEnvelope);
596                }
597                if handles_before != decoder.remaining_handles() + (num_handles as usize) {
598                    return Err(fidl::Error::InvalidNumHandlesInEnvelope);
599                }
600            }
601
602            next_offset += envelope_size;
603
604            // Decode the remaining unknown envelopes.
605            while next_offset < end_offset {
606                _next_ordinal_to_read += 1;
607                fidl::encoding::decode_unknown_envelope(decoder, next_offset, depth)?;
608                next_offset += envelope_size;
609            }
610
611            Ok(())
612        }
613    }
614}