fidl_fuchsia_hardware_i2c__common/
fidl_fuchsia_hardware_i2c__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/// Used to return data from read transfers.
12pub type ReadData = Vec<u8>;
13
14/// The maximum number of transactions that can be specified in a call to `Transfer`.
15pub const MAX_COUNT_TRANSACTIONS: u32 = 256;
16
17/// Maximum length of the I2C Channel name.
18pub const MAX_I2_C_NAME_LEN: u32 = 64;
19
20/// Clients should be aware of the max channel message size when using large transfers or many
21/// transactions. It is possible to generate a message that uses values less than the limits below
22/// but is still too big for the channel.
23///
24/// The maximum number of bytes that can be read or written in a single `Transaction`.
25pub const MAX_TRANSFER_SIZE: u32 = 32768;
26
27#[derive(Clone, Debug, PartialEq)]
28pub struct DeviceTransferRequest {
29    pub transactions: Vec<Transaction>,
30}
31
32impl fidl::Persistable for DeviceTransferRequest {}
33
34#[derive(Clone, Debug, Eq, Hash, Ord, PartialEq, PartialOrd)]
35pub struct DeviceGetNameResponse {
36    pub name: String,
37}
38
39impl fidl::Persistable for DeviceGetNameResponse {}
40
41#[derive(Clone, Debug, Eq, Hash, Ord, PartialEq, PartialOrd)]
42pub struct DeviceTransferResponse {
43    pub read_data: Vec<Vec<u8>>,
44}
45
46impl fidl::Persistable for DeviceTransferResponse {}
47
48/// `data_transfer` is mandatory, and specifies whether this transaction has a read or a write
49/// transfer (see above).
50/// `stop` is optional, and specifies whether this transaction is terminated by a stop condition (if
51/// true) or by a repeated-start (if false or unspecified). If this transaction is the last in the
52/// list then a stop condition is generated regardless of the value of `stop`.
53#[derive(Clone, Debug, Default, PartialEq)]
54pub struct Transaction {
55    pub data_transfer: Option<DataTransfer>,
56    pub stop: Option<bool>,
57    #[doc(hidden)]
58    pub __source_breaking: fidl::marker::SourceBreaking,
59}
60
61impl fidl::Persistable for Transaction {}
62
63/// If `read_size` is set: This is a read transfer, and `read_size` bytes will be read from the
64/// target.
65/// If `write_data` is set: This is a write transfer, and `write_data` will be written to the
66/// target.
67#[derive(Clone, Debug)]
68pub enum DataTransfer {
69    ReadSize(u32),
70    WriteData(Vec<u8>),
71    #[doc(hidden)]
72    __SourceBreaking {
73        unknown_ordinal: u64,
74    },
75}
76
77/// Pattern that matches an unknown `DataTransfer` member.
78#[macro_export]
79macro_rules! DataTransferUnknown {
80    () => {
81        _
82    };
83}
84
85// Custom PartialEq so that unknown variants are not equal to themselves.
86impl PartialEq for DataTransfer {
87    fn eq(&self, other: &Self) -> bool {
88        match (self, other) {
89            (Self::ReadSize(x), Self::ReadSize(y)) => *x == *y,
90            (Self::WriteData(x), Self::WriteData(y)) => *x == *y,
91            _ => false,
92        }
93    }
94}
95
96impl DataTransfer {
97    #[inline]
98    pub fn ordinal(&self) -> u64 {
99        match *self {
100            Self::ReadSize(_) => 1,
101            Self::WriteData(_) => 2,
102            Self::__SourceBreaking { unknown_ordinal } => unknown_ordinal,
103        }
104    }
105
106    #[inline]
107    pub fn unknown_variant_for_testing() -> Self {
108        Self::__SourceBreaking { unknown_ordinal: 0 }
109    }
110
111    #[inline]
112    pub fn is_unknown(&self) -> bool {
113        match self {
114            Self::__SourceBreaking { .. } => true,
115            _ => false,
116        }
117    }
118}
119
120impl fidl::Persistable for DataTransfer {}
121
122pub mod device_ordinals {
123    pub const TRANSFER: u64 = 0xc169f6c7849333b;
124    pub const GET_NAME: u64 = 0x745268a50651f102;
125}
126
127mod internal {
128    use super::*;
129
130    impl fidl::encoding::ValueTypeMarker for DeviceTransferRequest {
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 DeviceTransferRequest {
138        type Owned = Self;
139
140        #[inline(always)]
141        fn inline_align(_context: fidl::encoding::Context) -> usize {
142            8
143        }
144
145        #[inline(always)]
146        fn inline_size(_context: fidl::encoding::Context) -> usize {
147            16
148        }
149    }
150
151    unsafe impl<D: fidl::encoding::ResourceDialect> fidl::encoding::Encode<DeviceTransferRequest, D>
152        for &DeviceTransferRequest
153    {
154        #[inline]
155        unsafe fn encode(
156            self,
157            encoder: &mut fidl::encoding::Encoder<'_, D>,
158            offset: usize,
159            _depth: fidl::encoding::Depth,
160        ) -> fidl::Result<()> {
161            encoder.debug_check_bounds::<DeviceTransferRequest>(offset);
162            // Delegate to tuple encoding.
163            fidl::encoding::Encode::<DeviceTransferRequest, D>::encode(
164                (
165                    <fidl::encoding::Vector<Transaction, 256> as fidl::encoding::ValueTypeMarker>::borrow(&self.transactions),
166                ),
167                encoder, offset, _depth
168            )
169        }
170    }
171    unsafe impl<
172            D: fidl::encoding::ResourceDialect,
173            T0: fidl::encoding::Encode<fidl::encoding::Vector<Transaction, 256>, D>,
174        > fidl::encoding::Encode<DeviceTransferRequest, D> for (T0,)
175    {
176        #[inline]
177        unsafe fn encode(
178            self,
179            encoder: &mut fidl::encoding::Encoder<'_, D>,
180            offset: usize,
181            depth: fidl::encoding::Depth,
182        ) -> fidl::Result<()> {
183            encoder.debug_check_bounds::<DeviceTransferRequest>(offset);
184            // Zero out padding regions. There's no need to apply masks
185            // because the unmasked parts will be overwritten by fields.
186            // Write the fields.
187            self.0.encode(encoder, offset + 0, depth)?;
188            Ok(())
189        }
190    }
191
192    impl<D: fidl::encoding::ResourceDialect> fidl::encoding::Decode<Self, D> for DeviceTransferRequest {
193        #[inline(always)]
194        fn new_empty() -> Self {
195            Self { transactions: fidl::new_empty!(fidl::encoding::Vector<Transaction, 256>, D) }
196        }
197
198        #[inline]
199        unsafe fn decode(
200            &mut self,
201            decoder: &mut fidl::encoding::Decoder<'_, D>,
202            offset: usize,
203            _depth: fidl::encoding::Depth,
204        ) -> fidl::Result<()> {
205            decoder.debug_check_bounds::<Self>(offset);
206            // Verify that padding bytes are zero.
207            fidl::decode!(fidl::encoding::Vector<Transaction, 256>, D, &mut self.transactions, decoder, offset + 0, _depth)?;
208            Ok(())
209        }
210    }
211
212    impl fidl::encoding::ValueTypeMarker for DeviceGetNameResponse {
213        type Borrowed<'a> = &'a Self;
214        fn borrow(value: &<Self as fidl::encoding::TypeMarker>::Owned) -> Self::Borrowed<'_> {
215            value
216        }
217    }
218
219    unsafe impl fidl::encoding::TypeMarker for DeviceGetNameResponse {
220        type Owned = Self;
221
222        #[inline(always)]
223        fn inline_align(_context: fidl::encoding::Context) -> usize {
224            8
225        }
226
227        #[inline(always)]
228        fn inline_size(_context: fidl::encoding::Context) -> usize {
229            16
230        }
231    }
232
233    unsafe impl<D: fidl::encoding::ResourceDialect> fidl::encoding::Encode<DeviceGetNameResponse, D>
234        for &DeviceGetNameResponse
235    {
236        #[inline]
237        unsafe fn encode(
238            self,
239            encoder: &mut fidl::encoding::Encoder<'_, D>,
240            offset: usize,
241            _depth: fidl::encoding::Depth,
242        ) -> fidl::Result<()> {
243            encoder.debug_check_bounds::<DeviceGetNameResponse>(offset);
244            // Delegate to tuple encoding.
245            fidl::encoding::Encode::<DeviceGetNameResponse, D>::encode(
246                (<fidl::encoding::BoundedString<64> as fidl::encoding::ValueTypeMarker>::borrow(
247                    &self.name,
248                ),),
249                encoder,
250                offset,
251                _depth,
252            )
253        }
254    }
255    unsafe impl<
256            D: fidl::encoding::ResourceDialect,
257            T0: fidl::encoding::Encode<fidl::encoding::BoundedString<64>, D>,
258        > fidl::encoding::Encode<DeviceGetNameResponse, D> for (T0,)
259    {
260        #[inline]
261        unsafe fn encode(
262            self,
263            encoder: &mut fidl::encoding::Encoder<'_, D>,
264            offset: usize,
265            depth: fidl::encoding::Depth,
266        ) -> fidl::Result<()> {
267            encoder.debug_check_bounds::<DeviceGetNameResponse>(offset);
268            // Zero out padding regions. There's no need to apply masks
269            // because the unmasked parts will be overwritten by fields.
270            // Write the fields.
271            self.0.encode(encoder, offset + 0, depth)?;
272            Ok(())
273        }
274    }
275
276    impl<D: fidl::encoding::ResourceDialect> fidl::encoding::Decode<Self, D> for DeviceGetNameResponse {
277        #[inline(always)]
278        fn new_empty() -> Self {
279            Self { name: fidl::new_empty!(fidl::encoding::BoundedString<64>, D) }
280        }
281
282        #[inline]
283        unsafe fn decode(
284            &mut self,
285            decoder: &mut fidl::encoding::Decoder<'_, D>,
286            offset: usize,
287            _depth: fidl::encoding::Depth,
288        ) -> fidl::Result<()> {
289            decoder.debug_check_bounds::<Self>(offset);
290            // Verify that padding bytes are zero.
291            fidl::decode!(
292                fidl::encoding::BoundedString<64>,
293                D,
294                &mut self.name,
295                decoder,
296                offset + 0,
297                _depth
298            )?;
299            Ok(())
300        }
301    }
302
303    impl fidl::encoding::ValueTypeMarker for DeviceTransferResponse {
304        type Borrowed<'a> = &'a Self;
305        fn borrow(value: &<Self as fidl::encoding::TypeMarker>::Owned) -> Self::Borrowed<'_> {
306            value
307        }
308    }
309
310    unsafe impl fidl::encoding::TypeMarker for DeviceTransferResponse {
311        type Owned = Self;
312
313        #[inline(always)]
314        fn inline_align(_context: fidl::encoding::Context) -> usize {
315            8
316        }
317
318        #[inline(always)]
319        fn inline_size(_context: fidl::encoding::Context) -> usize {
320            16
321        }
322    }
323
324    unsafe impl<D: fidl::encoding::ResourceDialect>
325        fidl::encoding::Encode<DeviceTransferResponse, D> for &DeviceTransferResponse
326    {
327        #[inline]
328        unsafe fn encode(
329            self,
330            encoder: &mut fidl::encoding::Encoder<'_, D>,
331            offset: usize,
332            _depth: fidl::encoding::Depth,
333        ) -> fidl::Result<()> {
334            encoder.debug_check_bounds::<DeviceTransferResponse>(offset);
335            // Delegate to tuple encoding.
336            fidl::encoding::Encode::<DeviceTransferResponse, D>::encode(
337                (
338                    <fidl::encoding::Vector<fidl::encoding::Vector<u8, 32768>, 256> as fidl::encoding::ValueTypeMarker>::borrow(&self.read_data),
339                ),
340                encoder, offset, _depth
341            )
342        }
343    }
344    unsafe impl<
345            D: fidl::encoding::ResourceDialect,
346            T0: fidl::encoding::Encode<
347                fidl::encoding::Vector<fidl::encoding::Vector<u8, 32768>, 256>,
348                D,
349            >,
350        > fidl::encoding::Encode<DeviceTransferResponse, D> for (T0,)
351    {
352        #[inline]
353        unsafe fn encode(
354            self,
355            encoder: &mut fidl::encoding::Encoder<'_, D>,
356            offset: usize,
357            depth: fidl::encoding::Depth,
358        ) -> fidl::Result<()> {
359            encoder.debug_check_bounds::<DeviceTransferResponse>(offset);
360            // Zero out padding regions. There's no need to apply masks
361            // because the unmasked parts will be overwritten by fields.
362            // Write the fields.
363            self.0.encode(encoder, offset + 0, depth)?;
364            Ok(())
365        }
366    }
367
368    impl<D: fidl::encoding::ResourceDialect> fidl::encoding::Decode<Self, D>
369        for DeviceTransferResponse
370    {
371        #[inline(always)]
372        fn new_empty() -> Self {
373            Self {
374                read_data: fidl::new_empty!(
375                    fidl::encoding::Vector<fidl::encoding::Vector<u8, 32768>, 256>,
376                    D
377                ),
378            }
379        }
380
381        #[inline]
382        unsafe fn decode(
383            &mut self,
384            decoder: &mut fidl::encoding::Decoder<'_, D>,
385            offset: usize,
386            _depth: fidl::encoding::Depth,
387        ) -> fidl::Result<()> {
388            decoder.debug_check_bounds::<Self>(offset);
389            // Verify that padding bytes are zero.
390            fidl::decode!(
391                fidl::encoding::Vector<fidl::encoding::Vector<u8, 32768>, 256>,
392                D,
393                &mut self.read_data,
394                decoder,
395                offset + 0,
396                _depth
397            )?;
398            Ok(())
399        }
400    }
401
402    impl Transaction {
403        #[inline(always)]
404        fn max_ordinal_present(&self) -> u64 {
405            if let Some(_) = self.stop {
406                return 2;
407            }
408            if let Some(_) = self.data_transfer {
409                return 1;
410            }
411            0
412        }
413    }
414
415    impl fidl::encoding::ValueTypeMarker for Transaction {
416        type Borrowed<'a> = &'a Self;
417        fn borrow(value: &<Self as fidl::encoding::TypeMarker>::Owned) -> Self::Borrowed<'_> {
418            value
419        }
420    }
421
422    unsafe impl fidl::encoding::TypeMarker for Transaction {
423        type Owned = Self;
424
425        #[inline(always)]
426        fn inline_align(_context: fidl::encoding::Context) -> usize {
427            8
428        }
429
430        #[inline(always)]
431        fn inline_size(_context: fidl::encoding::Context) -> usize {
432            16
433        }
434    }
435
436    unsafe impl<D: fidl::encoding::ResourceDialect> fidl::encoding::Encode<Transaction, D>
437        for &Transaction
438    {
439        unsafe fn encode(
440            self,
441            encoder: &mut fidl::encoding::Encoder<'_, D>,
442            offset: usize,
443            mut depth: fidl::encoding::Depth,
444        ) -> fidl::Result<()> {
445            encoder.debug_check_bounds::<Transaction>(offset);
446            // Vector header
447            let max_ordinal: u64 = self.max_ordinal_present();
448            encoder.write_num(max_ordinal, offset);
449            encoder.write_num(fidl::encoding::ALLOC_PRESENT_U64, offset + 8);
450            // Calling encoder.out_of_line_offset(0) is not allowed.
451            if max_ordinal == 0 {
452                return Ok(());
453            }
454            depth.increment()?;
455            let envelope_size = 8;
456            let bytes_len = max_ordinal as usize * envelope_size;
457            #[allow(unused_variables)]
458            let offset = encoder.out_of_line_offset(bytes_len);
459            let mut _prev_end_offset: usize = 0;
460            if 1 > max_ordinal {
461                return Ok(());
462            }
463
464            // Write at offset+(ordinal-1)*envelope_size, since ordinals are one-based and envelopes
465            // are envelope_size bytes.
466            let cur_offset: usize = (1 - 1) * envelope_size;
467
468            // Zero reserved fields.
469            encoder.padding(offset + _prev_end_offset, cur_offset - _prev_end_offset);
470
471            // Safety:
472            // - bytes_len is calculated to fit envelope_size*max(member.ordinal).
473            // - Since cur_offset is envelope_size*(member.ordinal - 1) and the envelope takes
474            //   envelope_size bytes, there is always sufficient room.
475            fidl::encoding::encode_in_envelope_optional::<DataTransfer, D>(
476                self.data_transfer
477                    .as_ref()
478                    .map(<DataTransfer as fidl::encoding::ValueTypeMarker>::borrow),
479                encoder,
480                offset + cur_offset,
481                depth,
482            )?;
483
484            _prev_end_offset = cur_offset + envelope_size;
485            if 2 > max_ordinal {
486                return Ok(());
487            }
488
489            // Write at offset+(ordinal-1)*envelope_size, since ordinals are one-based and envelopes
490            // are envelope_size bytes.
491            let cur_offset: usize = (2 - 1) * envelope_size;
492
493            // Zero reserved fields.
494            encoder.padding(offset + _prev_end_offset, cur_offset - _prev_end_offset);
495
496            // Safety:
497            // - bytes_len is calculated to fit envelope_size*max(member.ordinal).
498            // - Since cur_offset is envelope_size*(member.ordinal - 1) and the envelope takes
499            //   envelope_size bytes, there is always sufficient room.
500            fidl::encoding::encode_in_envelope_optional::<bool, D>(
501                self.stop.as_ref().map(<bool as fidl::encoding::ValueTypeMarker>::borrow),
502                encoder,
503                offset + cur_offset,
504                depth,
505            )?;
506
507            _prev_end_offset = cur_offset + envelope_size;
508
509            Ok(())
510        }
511    }
512
513    impl<D: fidl::encoding::ResourceDialect> fidl::encoding::Decode<Self, D> for Transaction {
514        #[inline(always)]
515        fn new_empty() -> Self {
516            Self::default()
517        }
518
519        unsafe fn decode(
520            &mut self,
521            decoder: &mut fidl::encoding::Decoder<'_, D>,
522            offset: usize,
523            mut depth: fidl::encoding::Depth,
524        ) -> fidl::Result<()> {
525            decoder.debug_check_bounds::<Self>(offset);
526            let len = match fidl::encoding::decode_vector_header(decoder, offset)? {
527                None => return Err(fidl::Error::NotNullable),
528                Some(len) => len,
529            };
530            // Calling decoder.out_of_line_offset(0) is not allowed.
531            if len == 0 {
532                return Ok(());
533            };
534            depth.increment()?;
535            let envelope_size = 8;
536            let bytes_len = len * envelope_size;
537            let offset = decoder.out_of_line_offset(bytes_len)?;
538            // Decode the envelope for each type.
539            let mut _next_ordinal_to_read = 0;
540            let mut next_offset = offset;
541            let end_offset = offset + bytes_len;
542            _next_ordinal_to_read += 1;
543            if next_offset >= end_offset {
544                return Ok(());
545            }
546
547            // Decode unknown envelopes for gaps in ordinals.
548            while _next_ordinal_to_read < 1 {
549                fidl::encoding::decode_unknown_envelope(decoder, next_offset, depth)?;
550                _next_ordinal_to_read += 1;
551                next_offset += envelope_size;
552            }
553
554            let next_out_of_line = decoder.next_out_of_line();
555            let handles_before = decoder.remaining_handles();
556            if let Some((inlined, num_bytes, num_handles)) =
557                fidl::encoding::decode_envelope_header(decoder, next_offset)?
558            {
559                let member_inline_size =
560                    <DataTransfer as fidl::encoding::TypeMarker>::inline_size(decoder.context);
561                if inlined != (member_inline_size <= 4) {
562                    return Err(fidl::Error::InvalidInlineBitInEnvelope);
563                }
564                let inner_offset;
565                let mut inner_depth = depth.clone();
566                if inlined {
567                    decoder.check_inline_envelope_padding(next_offset, member_inline_size)?;
568                    inner_offset = next_offset;
569                } else {
570                    inner_offset = decoder.out_of_line_offset(member_inline_size)?;
571                    inner_depth.increment()?;
572                }
573                let val_ref =
574                    self.data_transfer.get_or_insert_with(|| fidl::new_empty!(DataTransfer, D));
575                fidl::decode!(DataTransfer, D, val_ref, decoder, inner_offset, inner_depth)?;
576                if !inlined && decoder.next_out_of_line() != next_out_of_line + (num_bytes as usize)
577                {
578                    return Err(fidl::Error::InvalidNumBytesInEnvelope);
579                }
580                if handles_before != decoder.remaining_handles() + (num_handles as usize) {
581                    return Err(fidl::Error::InvalidNumHandlesInEnvelope);
582                }
583            }
584
585            next_offset += envelope_size;
586            _next_ordinal_to_read += 1;
587            if next_offset >= end_offset {
588                return Ok(());
589            }
590
591            // Decode unknown envelopes for gaps in ordinals.
592            while _next_ordinal_to_read < 2 {
593                fidl::encoding::decode_unknown_envelope(decoder, next_offset, depth)?;
594                _next_ordinal_to_read += 1;
595                next_offset += envelope_size;
596            }
597
598            let next_out_of_line = decoder.next_out_of_line();
599            let handles_before = decoder.remaining_handles();
600            if let Some((inlined, num_bytes, num_handles)) =
601                fidl::encoding::decode_envelope_header(decoder, next_offset)?
602            {
603                let member_inline_size =
604                    <bool as fidl::encoding::TypeMarker>::inline_size(decoder.context);
605                if inlined != (member_inline_size <= 4) {
606                    return Err(fidl::Error::InvalidInlineBitInEnvelope);
607                }
608                let inner_offset;
609                let mut inner_depth = depth.clone();
610                if inlined {
611                    decoder.check_inline_envelope_padding(next_offset, member_inline_size)?;
612                    inner_offset = next_offset;
613                } else {
614                    inner_offset = decoder.out_of_line_offset(member_inline_size)?;
615                    inner_depth.increment()?;
616                }
617                let val_ref = self.stop.get_or_insert_with(|| fidl::new_empty!(bool, D));
618                fidl::decode!(bool, D, val_ref, decoder, inner_offset, inner_depth)?;
619                if !inlined && decoder.next_out_of_line() != next_out_of_line + (num_bytes as usize)
620                {
621                    return Err(fidl::Error::InvalidNumBytesInEnvelope);
622                }
623                if handles_before != decoder.remaining_handles() + (num_handles as usize) {
624                    return Err(fidl::Error::InvalidNumHandlesInEnvelope);
625                }
626            }
627
628            next_offset += envelope_size;
629
630            // Decode the remaining unknown envelopes.
631            while next_offset < end_offset {
632                _next_ordinal_to_read += 1;
633                fidl::encoding::decode_unknown_envelope(decoder, next_offset, depth)?;
634                next_offset += envelope_size;
635            }
636
637            Ok(())
638        }
639    }
640
641    impl fidl::encoding::ValueTypeMarker for DataTransfer {
642        type Borrowed<'a> = &'a Self;
643        fn borrow(value: &<Self as fidl::encoding::TypeMarker>::Owned) -> Self::Borrowed<'_> {
644            value
645        }
646    }
647
648    unsafe impl fidl::encoding::TypeMarker for DataTransfer {
649        type Owned = Self;
650
651        #[inline(always)]
652        fn inline_align(_context: fidl::encoding::Context) -> usize {
653            8
654        }
655
656        #[inline(always)]
657        fn inline_size(_context: fidl::encoding::Context) -> usize {
658            16
659        }
660    }
661
662    unsafe impl<D: fidl::encoding::ResourceDialect> fidl::encoding::Encode<DataTransfer, D>
663        for &DataTransfer
664    {
665        #[inline]
666        unsafe fn encode(
667            self,
668            encoder: &mut fidl::encoding::Encoder<'_, D>,
669            offset: usize,
670            _depth: fidl::encoding::Depth,
671        ) -> fidl::Result<()> {
672            encoder.debug_check_bounds::<DataTransfer>(offset);
673            encoder.write_num::<u64>(self.ordinal(), offset);
674            match self {
675                DataTransfer::ReadSize(ref val) => fidl::encoding::encode_in_envelope::<u32, D>(
676                    <u32 as fidl::encoding::ValueTypeMarker>::borrow(val),
677                    encoder,
678                    offset + 8,
679                    _depth,
680                ),
681                DataTransfer::WriteData(ref val) => fidl::encoding::encode_in_envelope::<
682                    fidl::encoding::Vector<u8, 32768>,
683                    D,
684                >(
685                    <fidl::encoding::Vector<u8, 32768> as fidl::encoding::ValueTypeMarker>::borrow(
686                        val,
687                    ),
688                    encoder,
689                    offset + 8,
690                    _depth,
691                ),
692                DataTransfer::__SourceBreaking { .. } => Err(fidl::Error::UnknownUnionTag),
693            }
694        }
695    }
696
697    impl<D: fidl::encoding::ResourceDialect> fidl::encoding::Decode<Self, D> for DataTransfer {
698        #[inline(always)]
699        fn new_empty() -> Self {
700            Self::__SourceBreaking { unknown_ordinal: 0 }
701        }
702
703        #[inline]
704        unsafe fn decode(
705            &mut self,
706            decoder: &mut fidl::encoding::Decoder<'_, D>,
707            offset: usize,
708            mut depth: fidl::encoding::Depth,
709        ) -> fidl::Result<()> {
710            decoder.debug_check_bounds::<Self>(offset);
711            #[allow(unused_variables)]
712            let next_out_of_line = decoder.next_out_of_line();
713            let handles_before = decoder.remaining_handles();
714            let (ordinal, inlined, num_bytes, num_handles) =
715                fidl::encoding::decode_union_inline_portion(decoder, offset)?;
716
717            let member_inline_size = match ordinal {
718                1 => <u32 as fidl::encoding::TypeMarker>::inline_size(decoder.context),
719                2 => {
720                    <fidl::encoding::Vector<u8, 32768> as fidl::encoding::TypeMarker>::inline_size(
721                        decoder.context,
722                    )
723                }
724                0 => return Err(fidl::Error::UnknownUnionTag),
725                _ => num_bytes as usize,
726            };
727
728            if inlined != (member_inline_size <= 4) {
729                return Err(fidl::Error::InvalidInlineBitInEnvelope);
730            }
731            let _inner_offset;
732            if inlined {
733                decoder.check_inline_envelope_padding(offset + 8, member_inline_size)?;
734                _inner_offset = offset + 8;
735            } else {
736                depth.increment()?;
737                _inner_offset = decoder.out_of_line_offset(member_inline_size)?;
738            }
739            match ordinal {
740                1 => {
741                    #[allow(irrefutable_let_patterns)]
742                    if let DataTransfer::ReadSize(_) = self {
743                        // Do nothing, read the value into the object
744                    } else {
745                        // Initialize `self` to the right variant
746                        *self = DataTransfer::ReadSize(fidl::new_empty!(u32, D));
747                    }
748                    #[allow(irrefutable_let_patterns)]
749                    if let DataTransfer::ReadSize(ref mut val) = self {
750                        fidl::decode!(u32, D, val, decoder, _inner_offset, depth)?;
751                    } else {
752                        unreachable!()
753                    }
754                }
755                2 => {
756                    #[allow(irrefutable_let_patterns)]
757                    if let DataTransfer::WriteData(_) = self {
758                        // Do nothing, read the value into the object
759                    } else {
760                        // Initialize `self` to the right variant
761                        *self = DataTransfer::WriteData(
762                            fidl::new_empty!(fidl::encoding::Vector<u8, 32768>, D),
763                        );
764                    }
765                    #[allow(irrefutable_let_patterns)]
766                    if let DataTransfer::WriteData(ref mut val) = self {
767                        fidl::decode!(fidl::encoding::Vector<u8, 32768>, D, val, decoder, _inner_offset, depth)?;
768                    } else {
769                        unreachable!()
770                    }
771                }
772                #[allow(deprecated)]
773                ordinal => {
774                    for _ in 0..num_handles {
775                        decoder.drop_next_handle()?;
776                    }
777                    *self = DataTransfer::__SourceBreaking { unknown_ordinal: ordinal };
778                }
779            }
780            if !inlined && decoder.next_out_of_line() != next_out_of_line + (num_bytes as usize) {
781                return Err(fidl::Error::InvalidNumBytesInEnvelope);
782            }
783            if handles_before != decoder.remaining_handles() + (num_handles as usize) {
784                return Err(fidl::Error::InvalidNumHandlesInEnvelope);
785            }
786            Ok(())
787        }
788    }
789}