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<fidl::encoding::Vector<fidl::encoding::Vector<u8, 32768>, 256>, D>,
347    > fidl::encoding::Encode<DeviceTransferResponse, D> for (T0,)
348    {
349        #[inline]
350        unsafe fn encode(
351            self,
352            encoder: &mut fidl::encoding::Encoder<'_, D>,
353            offset: usize,
354            depth: fidl::encoding::Depth,
355        ) -> fidl::Result<()> {
356            encoder.debug_check_bounds::<DeviceTransferResponse>(offset);
357            // Zero out padding regions. There's no need to apply masks
358            // because the unmasked parts will be overwritten by fields.
359            // Write the fields.
360            self.0.encode(encoder, offset + 0, depth)?;
361            Ok(())
362        }
363    }
364
365    impl<D: fidl::encoding::ResourceDialect> fidl::encoding::Decode<Self, D>
366        for DeviceTransferResponse
367    {
368        #[inline(always)]
369        fn new_empty() -> Self {
370            Self {
371                read_data: fidl::new_empty!(
372                    fidl::encoding::Vector<fidl::encoding::Vector<u8, 32768>, 256>,
373                    D
374                ),
375            }
376        }
377
378        #[inline]
379        unsafe fn decode(
380            &mut self,
381            decoder: &mut fidl::encoding::Decoder<'_, D>,
382            offset: usize,
383            _depth: fidl::encoding::Depth,
384        ) -> fidl::Result<()> {
385            decoder.debug_check_bounds::<Self>(offset);
386            // Verify that padding bytes are zero.
387            fidl::decode!(
388                fidl::encoding::Vector<fidl::encoding::Vector<u8, 32768>, 256>,
389                D,
390                &mut self.read_data,
391                decoder,
392                offset + 0,
393                _depth
394            )?;
395            Ok(())
396        }
397    }
398
399    impl Transaction {
400        #[inline(always)]
401        fn max_ordinal_present(&self) -> u64 {
402            if let Some(_) = self.stop {
403                return 2;
404            }
405            if let Some(_) = self.data_transfer {
406                return 1;
407            }
408            0
409        }
410    }
411
412    impl fidl::encoding::ValueTypeMarker for Transaction {
413        type Borrowed<'a> = &'a Self;
414        fn borrow(value: &<Self as fidl::encoding::TypeMarker>::Owned) -> Self::Borrowed<'_> {
415            value
416        }
417    }
418
419    unsafe impl fidl::encoding::TypeMarker for Transaction {
420        type Owned = Self;
421
422        #[inline(always)]
423        fn inline_align(_context: fidl::encoding::Context) -> usize {
424            8
425        }
426
427        #[inline(always)]
428        fn inline_size(_context: fidl::encoding::Context) -> usize {
429            16
430        }
431    }
432
433    unsafe impl<D: fidl::encoding::ResourceDialect> fidl::encoding::Encode<Transaction, D>
434        for &Transaction
435    {
436        unsafe fn encode(
437            self,
438            encoder: &mut fidl::encoding::Encoder<'_, D>,
439            offset: usize,
440            mut depth: fidl::encoding::Depth,
441        ) -> fidl::Result<()> {
442            encoder.debug_check_bounds::<Transaction>(offset);
443            // Vector header
444            let max_ordinal: u64 = self.max_ordinal_present();
445            encoder.write_num(max_ordinal, offset);
446            encoder.write_num(fidl::encoding::ALLOC_PRESENT_U64, offset + 8);
447            // Calling encoder.out_of_line_offset(0) is not allowed.
448            if max_ordinal == 0 {
449                return Ok(());
450            }
451            depth.increment()?;
452            let envelope_size = 8;
453            let bytes_len = max_ordinal as usize * envelope_size;
454            #[allow(unused_variables)]
455            let offset = encoder.out_of_line_offset(bytes_len);
456            let mut _prev_end_offset: usize = 0;
457            if 1 > max_ordinal {
458                return Ok(());
459            }
460
461            // Write at offset+(ordinal-1)*envelope_size, since ordinals are one-based and envelopes
462            // are envelope_size bytes.
463            let cur_offset: usize = (1 - 1) * envelope_size;
464
465            // Zero reserved fields.
466            encoder.padding(offset + _prev_end_offset, cur_offset - _prev_end_offset);
467
468            // Safety:
469            // - bytes_len is calculated to fit envelope_size*max(member.ordinal).
470            // - Since cur_offset is envelope_size*(member.ordinal - 1) and the envelope takes
471            //   envelope_size bytes, there is always sufficient room.
472            fidl::encoding::encode_in_envelope_optional::<DataTransfer, D>(
473                self.data_transfer
474                    .as_ref()
475                    .map(<DataTransfer as fidl::encoding::ValueTypeMarker>::borrow),
476                encoder,
477                offset + cur_offset,
478                depth,
479            )?;
480
481            _prev_end_offset = cur_offset + envelope_size;
482            if 2 > max_ordinal {
483                return Ok(());
484            }
485
486            // Write at offset+(ordinal-1)*envelope_size, since ordinals are one-based and envelopes
487            // are envelope_size bytes.
488            let cur_offset: usize = (2 - 1) * envelope_size;
489
490            // Zero reserved fields.
491            encoder.padding(offset + _prev_end_offset, cur_offset - _prev_end_offset);
492
493            // Safety:
494            // - bytes_len is calculated to fit envelope_size*max(member.ordinal).
495            // - Since cur_offset is envelope_size*(member.ordinal - 1) and the envelope takes
496            //   envelope_size bytes, there is always sufficient room.
497            fidl::encoding::encode_in_envelope_optional::<bool, D>(
498                self.stop.as_ref().map(<bool as fidl::encoding::ValueTypeMarker>::borrow),
499                encoder,
500                offset + cur_offset,
501                depth,
502            )?;
503
504            _prev_end_offset = cur_offset + envelope_size;
505
506            Ok(())
507        }
508    }
509
510    impl<D: fidl::encoding::ResourceDialect> fidl::encoding::Decode<Self, D> for Transaction {
511        #[inline(always)]
512        fn new_empty() -> Self {
513            Self::default()
514        }
515
516        unsafe fn decode(
517            &mut self,
518            decoder: &mut fidl::encoding::Decoder<'_, D>,
519            offset: usize,
520            mut depth: fidl::encoding::Depth,
521        ) -> fidl::Result<()> {
522            decoder.debug_check_bounds::<Self>(offset);
523            let len = match fidl::encoding::decode_vector_header(decoder, offset)? {
524                None => return Err(fidl::Error::NotNullable),
525                Some(len) => len,
526            };
527            // Calling decoder.out_of_line_offset(0) is not allowed.
528            if len == 0 {
529                return Ok(());
530            };
531            depth.increment()?;
532            let envelope_size = 8;
533            let bytes_len = len * envelope_size;
534            let offset = decoder.out_of_line_offset(bytes_len)?;
535            // Decode the envelope for each type.
536            let mut _next_ordinal_to_read = 0;
537            let mut next_offset = offset;
538            let end_offset = offset + bytes_len;
539            _next_ordinal_to_read += 1;
540            if next_offset >= end_offset {
541                return Ok(());
542            }
543
544            // Decode unknown envelopes for gaps in ordinals.
545            while _next_ordinal_to_read < 1 {
546                fidl::encoding::decode_unknown_envelope(decoder, next_offset, depth)?;
547                _next_ordinal_to_read += 1;
548                next_offset += envelope_size;
549            }
550
551            let next_out_of_line = decoder.next_out_of_line();
552            let handles_before = decoder.remaining_handles();
553            if let Some((inlined, num_bytes, num_handles)) =
554                fidl::encoding::decode_envelope_header(decoder, next_offset)?
555            {
556                let member_inline_size =
557                    <DataTransfer as fidl::encoding::TypeMarker>::inline_size(decoder.context);
558                if inlined != (member_inline_size <= 4) {
559                    return Err(fidl::Error::InvalidInlineBitInEnvelope);
560                }
561                let inner_offset;
562                let mut inner_depth = depth.clone();
563                if inlined {
564                    decoder.check_inline_envelope_padding(next_offset, member_inline_size)?;
565                    inner_offset = next_offset;
566                } else {
567                    inner_offset = decoder.out_of_line_offset(member_inline_size)?;
568                    inner_depth.increment()?;
569                }
570                let val_ref =
571                    self.data_transfer.get_or_insert_with(|| fidl::new_empty!(DataTransfer, D));
572                fidl::decode!(DataTransfer, D, val_ref, decoder, inner_offset, inner_depth)?;
573                if !inlined && decoder.next_out_of_line() != next_out_of_line + (num_bytes as usize)
574                {
575                    return Err(fidl::Error::InvalidNumBytesInEnvelope);
576                }
577                if handles_before != decoder.remaining_handles() + (num_handles as usize) {
578                    return Err(fidl::Error::InvalidNumHandlesInEnvelope);
579                }
580            }
581
582            next_offset += envelope_size;
583            _next_ordinal_to_read += 1;
584            if next_offset >= end_offset {
585                return Ok(());
586            }
587
588            // Decode unknown envelopes for gaps in ordinals.
589            while _next_ordinal_to_read < 2 {
590                fidl::encoding::decode_unknown_envelope(decoder, next_offset, depth)?;
591                _next_ordinal_to_read += 1;
592                next_offset += envelope_size;
593            }
594
595            let next_out_of_line = decoder.next_out_of_line();
596            let handles_before = decoder.remaining_handles();
597            if let Some((inlined, num_bytes, num_handles)) =
598                fidl::encoding::decode_envelope_header(decoder, next_offset)?
599            {
600                let member_inline_size =
601                    <bool as fidl::encoding::TypeMarker>::inline_size(decoder.context);
602                if inlined != (member_inline_size <= 4) {
603                    return Err(fidl::Error::InvalidInlineBitInEnvelope);
604                }
605                let inner_offset;
606                let mut inner_depth = depth.clone();
607                if inlined {
608                    decoder.check_inline_envelope_padding(next_offset, member_inline_size)?;
609                    inner_offset = next_offset;
610                } else {
611                    inner_offset = decoder.out_of_line_offset(member_inline_size)?;
612                    inner_depth.increment()?;
613                }
614                let val_ref = self.stop.get_or_insert_with(|| fidl::new_empty!(bool, D));
615                fidl::decode!(bool, D, val_ref, decoder, inner_offset, inner_depth)?;
616                if !inlined && decoder.next_out_of_line() != next_out_of_line + (num_bytes as usize)
617                {
618                    return Err(fidl::Error::InvalidNumBytesInEnvelope);
619                }
620                if handles_before != decoder.remaining_handles() + (num_handles as usize) {
621                    return Err(fidl::Error::InvalidNumHandlesInEnvelope);
622                }
623            }
624
625            next_offset += envelope_size;
626
627            // Decode the remaining unknown envelopes.
628            while next_offset < end_offset {
629                _next_ordinal_to_read += 1;
630                fidl::encoding::decode_unknown_envelope(decoder, next_offset, depth)?;
631                next_offset += envelope_size;
632            }
633
634            Ok(())
635        }
636    }
637
638    impl fidl::encoding::ValueTypeMarker for DataTransfer {
639        type Borrowed<'a> = &'a Self;
640        fn borrow(value: &<Self as fidl::encoding::TypeMarker>::Owned) -> Self::Borrowed<'_> {
641            value
642        }
643    }
644
645    unsafe impl fidl::encoding::TypeMarker for DataTransfer {
646        type Owned = Self;
647
648        #[inline(always)]
649        fn inline_align(_context: fidl::encoding::Context) -> usize {
650            8
651        }
652
653        #[inline(always)]
654        fn inline_size(_context: fidl::encoding::Context) -> usize {
655            16
656        }
657    }
658
659    unsafe impl<D: fidl::encoding::ResourceDialect> fidl::encoding::Encode<DataTransfer, D>
660        for &DataTransfer
661    {
662        #[inline]
663        unsafe fn encode(
664            self,
665            encoder: &mut fidl::encoding::Encoder<'_, D>,
666            offset: usize,
667            _depth: fidl::encoding::Depth,
668        ) -> fidl::Result<()> {
669            encoder.debug_check_bounds::<DataTransfer>(offset);
670            encoder.write_num::<u64>(self.ordinal(), offset);
671            match self {
672                DataTransfer::ReadSize(ref val) => fidl::encoding::encode_in_envelope::<u32, D>(
673                    <u32 as fidl::encoding::ValueTypeMarker>::borrow(val),
674                    encoder,
675                    offset + 8,
676                    _depth,
677                ),
678                DataTransfer::WriteData(ref val) => fidl::encoding::encode_in_envelope::<
679                    fidl::encoding::Vector<u8, 32768>,
680                    D,
681                >(
682                    <fidl::encoding::Vector<u8, 32768> as fidl::encoding::ValueTypeMarker>::borrow(
683                        val,
684                    ),
685                    encoder,
686                    offset + 8,
687                    _depth,
688                ),
689                DataTransfer::__SourceBreaking { .. } => Err(fidl::Error::UnknownUnionTag),
690            }
691        }
692    }
693
694    impl<D: fidl::encoding::ResourceDialect> fidl::encoding::Decode<Self, D> for DataTransfer {
695        #[inline(always)]
696        fn new_empty() -> Self {
697            Self::__SourceBreaking { unknown_ordinal: 0 }
698        }
699
700        #[inline]
701        unsafe fn decode(
702            &mut self,
703            decoder: &mut fidl::encoding::Decoder<'_, D>,
704            offset: usize,
705            mut depth: fidl::encoding::Depth,
706        ) -> fidl::Result<()> {
707            decoder.debug_check_bounds::<Self>(offset);
708            #[allow(unused_variables)]
709            let next_out_of_line = decoder.next_out_of_line();
710            let handles_before = decoder.remaining_handles();
711            let (ordinal, inlined, num_bytes, num_handles) =
712                fidl::encoding::decode_union_inline_portion(decoder, offset)?;
713
714            let member_inline_size = match ordinal {
715                1 => <u32 as fidl::encoding::TypeMarker>::inline_size(decoder.context),
716                2 => {
717                    <fidl::encoding::Vector<u8, 32768> as fidl::encoding::TypeMarker>::inline_size(
718                        decoder.context,
719                    )
720                }
721                0 => return Err(fidl::Error::UnknownUnionTag),
722                _ => num_bytes as usize,
723            };
724
725            if inlined != (member_inline_size <= 4) {
726                return Err(fidl::Error::InvalidInlineBitInEnvelope);
727            }
728            let _inner_offset;
729            if inlined {
730                decoder.check_inline_envelope_padding(offset + 8, member_inline_size)?;
731                _inner_offset = offset + 8;
732            } else {
733                depth.increment()?;
734                _inner_offset = decoder.out_of_line_offset(member_inline_size)?;
735            }
736            match ordinal {
737                1 => {
738                    #[allow(irrefutable_let_patterns)]
739                    if let DataTransfer::ReadSize(_) = self {
740                        // Do nothing, read the value into the object
741                    } else {
742                        // Initialize `self` to the right variant
743                        *self = DataTransfer::ReadSize(fidl::new_empty!(u32, D));
744                    }
745                    #[allow(irrefutable_let_patterns)]
746                    if let DataTransfer::ReadSize(ref mut val) = self {
747                        fidl::decode!(u32, D, val, decoder, _inner_offset, depth)?;
748                    } else {
749                        unreachable!()
750                    }
751                }
752                2 => {
753                    #[allow(irrefutable_let_patterns)]
754                    if let DataTransfer::WriteData(_) = self {
755                        // Do nothing, read the value into the object
756                    } else {
757                        // Initialize `self` to the right variant
758                        *self = DataTransfer::WriteData(
759                            fidl::new_empty!(fidl::encoding::Vector<u8, 32768>, D),
760                        );
761                    }
762                    #[allow(irrefutable_let_patterns)]
763                    if let DataTransfer::WriteData(ref mut val) = self {
764                        fidl::decode!(fidl::encoding::Vector<u8, 32768>, D, val, decoder, _inner_offset, depth)?;
765                    } else {
766                        unreachable!()
767                    }
768                }
769                #[allow(deprecated)]
770                ordinal => {
771                    for _ in 0..num_handles {
772                        decoder.drop_next_handle()?;
773                    }
774                    *self = DataTransfer::__SourceBreaking { unknown_ordinal: ordinal };
775                }
776            }
777            if !inlined && decoder.next_out_of_line() != next_out_of_line + (num_bytes as usize) {
778                return Err(fidl::Error::InvalidNumBytesInEnvelope);
779            }
780            if handles_before != decoder.remaining_handles() + (num_handles as usize) {
781                return Err(fidl::Error::InvalidNumHandlesInEnvelope);
782            }
783            Ok(())
784        }
785    }
786}