fidl_fuchsia_starnix_binder_common/
fidl_fuchsia_starnix_binder_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
11pub type Fd = i32;
12
13pub const MAX_HANDLE_COUNT: u64 = 8;
14
15pub const MAX_PATH_LENGTH: u64 = 4095;
16
17pub const MAX_REQUEST_COUNT: u64 = 16;
18
19pub const UNIX_DOMAIN_SOCKET_PROTOCOL_NAME: &str = "fuchsia.starnix.binder/UnixDomainSocket";
20
21bitflags! {
22    /// The flags associated with an opened file.
23    #[derive(Clone, Copy, Debug, Default, PartialEq, Eq, PartialOrd, Ord, Hash)]
24    pub struct FileFlags: u64 {
25        /// The owner can read the file.
26        const RIGHT_READABLE = 1;
27        /// The owner can write to fhe file.
28        const RIGHT_WRITABLE = 2;
29        /// The file is a directory.
30        const DIRECTORY = 4096;
31    }
32}
33
34impl FileFlags {
35    #[inline(always)]
36    pub fn from_bits_allow_unknown(bits: u64) -> Self {
37        Self::from_bits_retain(bits)
38    }
39
40    #[inline(always)]
41    pub fn has_unknown_bits(&self) -> bool {
42        self.get_unknown_bits() != 0
43    }
44
45    #[inline(always)]
46    pub fn get_unknown_bits(&self) -> u64 {
47        self.bits() & !Self::all().bits()
48    }
49}
50
51bitflags! {
52    /// The flags when reading from an unix domain socket
53    #[derive(Clone, Copy, Debug, Default, PartialEq, Eq, PartialOrd, Ord, Hash)]
54    pub struct ReadFlags: u64 {
55        /// When set, the data must not be removed from the queue and the next read
56        /// must resend the same data.
57        const PEEK = 1;
58    }
59}
60
61impl ReadFlags {
62    #[inline(always)]
63    pub fn from_bits_allow_unknown(bits: u64) -> Self {
64        Self::from_bits_retain(bits)
65    }
66
67    #[inline(always)]
68    pub fn has_unknown_bits(&self) -> bool {
69        self.get_unknown_bits() != 0
70    }
71
72    #[inline(always)]
73    pub fn get_unknown_bits(&self) -> u64 {
74        self.bits() & !Self::all().bits()
75    }
76}
77
78#[derive(Clone, Copy, Debug, Eq, Hash, Ord, PartialEq, PartialOrd)]
79#[repr(C)]
80pub struct BinderIoctlRequest {
81    pub tid: u64,
82    pub request: u32,
83    pub parameter: u64,
84}
85
86impl fidl::Persistable for BinderIoctlRequest {}
87
88#[derive(Clone, Debug, Default, PartialEq)]
89pub struct UnixDomainSocketGetEventRequest {
90    #[doc(hidden)]
91    pub __source_breaking: fidl::marker::SourceBreaking,
92}
93
94impl fidl::Persistable for UnixDomainSocketGetEventRequest {}
95
96#[derive(Clone, Debug, Default, PartialEq)]
97pub struct UnixDomainSocketReadRequest {
98    pub count: Option<u64>,
99    pub flags: Option<ReadFlags>,
100    #[doc(hidden)]
101    pub __source_breaking: fidl::marker::SourceBreaking,
102}
103
104impl fidl::Persistable for UnixDomainSocketReadRequest {}
105
106#[derive(Clone, Debug, Default, PartialEq)]
107pub struct UnixDomainSocketWriteResponse {
108    pub actual_count: Option<u64>,
109    #[doc(hidden)]
110    pub __source_breaking: fidl::marker::SourceBreaking,
111}
112
113impl fidl::Persistable for UnixDomainSocketWriteResponse {}
114
115mod internal {
116    use super::*;
117    unsafe impl fidl::encoding::TypeMarker for FileFlags {
118        type Owned = Self;
119
120        #[inline(always)]
121        fn inline_align(_context: fidl::encoding::Context) -> usize {
122            8
123        }
124
125        #[inline(always)]
126        fn inline_size(_context: fidl::encoding::Context) -> usize {
127            8
128        }
129    }
130
131    impl fidl::encoding::ValueTypeMarker for FileFlags {
132        type Borrowed<'a> = Self;
133        #[inline(always)]
134        fn borrow(value: &<Self as fidl::encoding::TypeMarker>::Owned) -> Self::Borrowed<'_> {
135            *value
136        }
137    }
138
139    unsafe impl<D: fidl::encoding::ResourceDialect> fidl::encoding::Encode<Self, D> for FileFlags {
140        #[inline]
141        unsafe fn encode(
142            self,
143            encoder: &mut fidl::encoding::Encoder<'_, D>,
144            offset: usize,
145            _depth: fidl::encoding::Depth,
146        ) -> fidl::Result<()> {
147            encoder.debug_check_bounds::<Self>(offset);
148            encoder.write_num(self.bits(), offset);
149            Ok(())
150        }
151    }
152
153    impl<D: fidl::encoding::ResourceDialect> fidl::encoding::Decode<Self, D> for FileFlags {
154        #[inline(always)]
155        fn new_empty() -> Self {
156            Self::empty()
157        }
158
159        #[inline]
160        unsafe fn decode(
161            &mut self,
162            decoder: &mut fidl::encoding::Decoder<'_, D>,
163            offset: usize,
164            _depth: fidl::encoding::Depth,
165        ) -> fidl::Result<()> {
166            decoder.debug_check_bounds::<Self>(offset);
167            let prim = decoder.read_num::<u64>(offset);
168            *self = Self::from_bits_allow_unknown(prim);
169            Ok(())
170        }
171    }
172    unsafe impl fidl::encoding::TypeMarker for ReadFlags {
173        type Owned = Self;
174
175        #[inline(always)]
176        fn inline_align(_context: fidl::encoding::Context) -> usize {
177            8
178        }
179
180        #[inline(always)]
181        fn inline_size(_context: fidl::encoding::Context) -> usize {
182            8
183        }
184    }
185
186    impl fidl::encoding::ValueTypeMarker for ReadFlags {
187        type Borrowed<'a> = Self;
188        #[inline(always)]
189        fn borrow(value: &<Self as fidl::encoding::TypeMarker>::Owned) -> Self::Borrowed<'_> {
190            *value
191        }
192    }
193
194    unsafe impl<D: fidl::encoding::ResourceDialect> fidl::encoding::Encode<Self, D> for ReadFlags {
195        #[inline]
196        unsafe fn encode(
197            self,
198            encoder: &mut fidl::encoding::Encoder<'_, D>,
199            offset: usize,
200            _depth: fidl::encoding::Depth,
201        ) -> fidl::Result<()> {
202            encoder.debug_check_bounds::<Self>(offset);
203            encoder.write_num(self.bits(), offset);
204            Ok(())
205        }
206    }
207
208    impl<D: fidl::encoding::ResourceDialect> fidl::encoding::Decode<Self, D> for ReadFlags {
209        #[inline(always)]
210        fn new_empty() -> Self {
211            Self::empty()
212        }
213
214        #[inline]
215        unsafe fn decode(
216            &mut self,
217            decoder: &mut fidl::encoding::Decoder<'_, D>,
218            offset: usize,
219            _depth: fidl::encoding::Depth,
220        ) -> fidl::Result<()> {
221            decoder.debug_check_bounds::<Self>(offset);
222            let prim = decoder.read_num::<u64>(offset);
223            *self = Self::from_bits_allow_unknown(prim);
224            Ok(())
225        }
226    }
227
228    impl fidl::encoding::ValueTypeMarker for BinderIoctlRequest {
229        type Borrowed<'a> = &'a Self;
230        fn borrow(value: &<Self as fidl::encoding::TypeMarker>::Owned) -> Self::Borrowed<'_> {
231            value
232        }
233    }
234
235    unsafe impl fidl::encoding::TypeMarker for BinderIoctlRequest {
236        type Owned = Self;
237
238        #[inline(always)]
239        fn inline_align(_context: fidl::encoding::Context) -> usize {
240            8
241        }
242
243        #[inline(always)]
244        fn inline_size(_context: fidl::encoding::Context) -> usize {
245            24
246        }
247    }
248
249    unsafe impl<D: fidl::encoding::ResourceDialect> fidl::encoding::Encode<BinderIoctlRequest, D>
250        for &BinderIoctlRequest
251    {
252        #[inline]
253        unsafe fn encode(
254            self,
255            encoder: &mut fidl::encoding::Encoder<'_, D>,
256            offset: usize,
257            _depth: fidl::encoding::Depth,
258        ) -> fidl::Result<()> {
259            encoder.debug_check_bounds::<BinderIoctlRequest>(offset);
260            unsafe {
261                // Copy the object into the buffer.
262                let buf_ptr = encoder.buf.as_mut_ptr().add(offset);
263                (buf_ptr as *mut BinderIoctlRequest)
264                    .write_unaligned((self as *const BinderIoctlRequest).read());
265                // Zero out padding regions. Unlike `fidl_struct_impl_noncopy!`, this must be
266                // done second because the memcpy will write garbage to these bytes.
267                let padding_ptr = buf_ptr.offset(8) as *mut u64;
268                let padding_mask = 0xffffffff00000000u64;
269                padding_ptr.write_unaligned(padding_ptr.read_unaligned() & !padding_mask);
270            }
271            Ok(())
272        }
273    }
274    unsafe impl<
275            D: fidl::encoding::ResourceDialect,
276            T0: fidl::encoding::Encode<u64, D>,
277            T1: fidl::encoding::Encode<u32, D>,
278            T2: fidl::encoding::Encode<u64, D>,
279        > fidl::encoding::Encode<BinderIoctlRequest, D> for (T0, T1, T2)
280    {
281        #[inline]
282        unsafe fn encode(
283            self,
284            encoder: &mut fidl::encoding::Encoder<'_, D>,
285            offset: usize,
286            depth: fidl::encoding::Depth,
287        ) -> fidl::Result<()> {
288            encoder.debug_check_bounds::<BinderIoctlRequest>(offset);
289            // Zero out padding regions. There's no need to apply masks
290            // because the unmasked parts will be overwritten by fields.
291            unsafe {
292                let ptr = encoder.buf.as_mut_ptr().add(offset).offset(8);
293                (ptr as *mut u64).write_unaligned(0);
294            }
295            // Write the fields.
296            self.0.encode(encoder, offset + 0, depth)?;
297            self.1.encode(encoder, offset + 8, depth)?;
298            self.2.encode(encoder, offset + 16, depth)?;
299            Ok(())
300        }
301    }
302
303    impl<D: fidl::encoding::ResourceDialect> fidl::encoding::Decode<Self, D> for BinderIoctlRequest {
304        #[inline(always)]
305        fn new_empty() -> Self {
306            Self {
307                tid: fidl::new_empty!(u64, D),
308                request: fidl::new_empty!(u32, D),
309                parameter: fidl::new_empty!(u64, D),
310            }
311        }
312
313        #[inline]
314        unsafe fn decode(
315            &mut self,
316            decoder: &mut fidl::encoding::Decoder<'_, D>,
317            offset: usize,
318            _depth: fidl::encoding::Depth,
319        ) -> fidl::Result<()> {
320            decoder.debug_check_bounds::<Self>(offset);
321            let buf_ptr = unsafe { decoder.buf.as_ptr().add(offset) };
322            // Verify that padding bytes are zero.
323            let ptr = unsafe { buf_ptr.offset(8) };
324            let padval = unsafe { (ptr as *const u64).read_unaligned() };
325            let mask = 0xffffffff00000000u64;
326            let maskedval = padval & mask;
327            if maskedval != 0 {
328                return Err(fidl::Error::NonZeroPadding {
329                    padding_start: offset + 8 + ((mask as u64).trailing_zeros() / 8) as usize,
330                });
331            }
332            // Copy from the buffer into the object.
333            unsafe {
334                std::ptr::copy_nonoverlapping(buf_ptr, self as *mut Self as *mut u8, 24);
335            }
336            Ok(())
337        }
338    }
339
340    impl UnixDomainSocketGetEventRequest {
341        #[inline(always)]
342        fn max_ordinal_present(&self) -> u64 {
343            0
344        }
345    }
346
347    impl fidl::encoding::ValueTypeMarker for UnixDomainSocketGetEventRequest {
348        type Borrowed<'a> = &'a Self;
349        fn borrow(value: &<Self as fidl::encoding::TypeMarker>::Owned) -> Self::Borrowed<'_> {
350            value
351        }
352    }
353
354    unsafe impl fidl::encoding::TypeMarker for UnixDomainSocketGetEventRequest {
355        type Owned = Self;
356
357        #[inline(always)]
358        fn inline_align(_context: fidl::encoding::Context) -> usize {
359            8
360        }
361
362        #[inline(always)]
363        fn inline_size(_context: fidl::encoding::Context) -> usize {
364            16
365        }
366    }
367
368    unsafe impl<D: fidl::encoding::ResourceDialect>
369        fidl::encoding::Encode<UnixDomainSocketGetEventRequest, D>
370        for &UnixDomainSocketGetEventRequest
371    {
372        unsafe fn encode(
373            self,
374            encoder: &mut fidl::encoding::Encoder<'_, D>,
375            offset: usize,
376            mut depth: fidl::encoding::Depth,
377        ) -> fidl::Result<()> {
378            encoder.debug_check_bounds::<UnixDomainSocketGetEventRequest>(offset);
379            // Vector header
380            let max_ordinal: u64 = self.max_ordinal_present();
381            encoder.write_num(max_ordinal, offset);
382            encoder.write_num(fidl::encoding::ALLOC_PRESENT_U64, offset + 8);
383            // Calling encoder.out_of_line_offset(0) is not allowed.
384            if max_ordinal == 0 {
385                return Ok(());
386            }
387            depth.increment()?;
388            let envelope_size = 8;
389            let bytes_len = max_ordinal as usize * envelope_size;
390            #[allow(unused_variables)]
391            let offset = encoder.out_of_line_offset(bytes_len);
392            let mut _prev_end_offset: usize = 0;
393
394            Ok(())
395        }
396    }
397
398    impl<D: fidl::encoding::ResourceDialect> fidl::encoding::Decode<Self, D>
399        for UnixDomainSocketGetEventRequest
400    {
401        #[inline(always)]
402        fn new_empty() -> Self {
403            Self::default()
404        }
405
406        unsafe fn decode(
407            &mut self,
408            decoder: &mut fidl::encoding::Decoder<'_, D>,
409            offset: usize,
410            mut depth: fidl::encoding::Depth,
411        ) -> fidl::Result<()> {
412            decoder.debug_check_bounds::<Self>(offset);
413            let len = match fidl::encoding::decode_vector_header(decoder, offset)? {
414                None => return Err(fidl::Error::NotNullable),
415                Some(len) => len,
416            };
417            // Calling decoder.out_of_line_offset(0) is not allowed.
418            if len == 0 {
419                return Ok(());
420            };
421            depth.increment()?;
422            let envelope_size = 8;
423            let bytes_len = len * envelope_size;
424            let offset = decoder.out_of_line_offset(bytes_len)?;
425            // Decode the envelope for each type.
426            let mut _next_ordinal_to_read = 0;
427            let mut next_offset = offset;
428            let end_offset = offset + bytes_len;
429
430            // Decode the remaining unknown envelopes.
431            while next_offset < end_offset {
432                _next_ordinal_to_read += 1;
433                fidl::encoding::decode_unknown_envelope(decoder, next_offset, depth)?;
434                next_offset += envelope_size;
435            }
436
437            Ok(())
438        }
439    }
440
441    impl UnixDomainSocketReadRequest {
442        #[inline(always)]
443        fn max_ordinal_present(&self) -> u64 {
444            if let Some(_) = self.flags {
445                return 2;
446            }
447            if let Some(_) = self.count {
448                return 1;
449            }
450            0
451        }
452    }
453
454    impl fidl::encoding::ValueTypeMarker for UnixDomainSocketReadRequest {
455        type Borrowed<'a> = &'a Self;
456        fn borrow(value: &<Self as fidl::encoding::TypeMarker>::Owned) -> Self::Borrowed<'_> {
457            value
458        }
459    }
460
461    unsafe impl fidl::encoding::TypeMarker for UnixDomainSocketReadRequest {
462        type Owned = Self;
463
464        #[inline(always)]
465        fn inline_align(_context: fidl::encoding::Context) -> usize {
466            8
467        }
468
469        #[inline(always)]
470        fn inline_size(_context: fidl::encoding::Context) -> usize {
471            16
472        }
473    }
474
475    unsafe impl<D: fidl::encoding::ResourceDialect>
476        fidl::encoding::Encode<UnixDomainSocketReadRequest, D> for &UnixDomainSocketReadRequest
477    {
478        unsafe fn encode(
479            self,
480            encoder: &mut fidl::encoding::Encoder<'_, D>,
481            offset: usize,
482            mut depth: fidl::encoding::Depth,
483        ) -> fidl::Result<()> {
484            encoder.debug_check_bounds::<UnixDomainSocketReadRequest>(offset);
485            // Vector header
486            let max_ordinal: u64 = self.max_ordinal_present();
487            encoder.write_num(max_ordinal, offset);
488            encoder.write_num(fidl::encoding::ALLOC_PRESENT_U64, offset + 8);
489            // Calling encoder.out_of_line_offset(0) is not allowed.
490            if max_ordinal == 0 {
491                return Ok(());
492            }
493            depth.increment()?;
494            let envelope_size = 8;
495            let bytes_len = max_ordinal as usize * envelope_size;
496            #[allow(unused_variables)]
497            let offset = encoder.out_of_line_offset(bytes_len);
498            let mut _prev_end_offset: usize = 0;
499            if 1 > max_ordinal {
500                return Ok(());
501            }
502
503            // Write at offset+(ordinal-1)*envelope_size, since ordinals are one-based and envelopes
504            // are envelope_size bytes.
505            let cur_offset: usize = (1 - 1) * envelope_size;
506
507            // Zero reserved fields.
508            encoder.padding(offset + _prev_end_offset, cur_offset - _prev_end_offset);
509
510            // Safety:
511            // - bytes_len is calculated to fit envelope_size*max(member.ordinal).
512            // - Since cur_offset is envelope_size*(member.ordinal - 1) and the envelope takes
513            //   envelope_size bytes, there is always sufficient room.
514            fidl::encoding::encode_in_envelope_optional::<u64, D>(
515                self.count.as_ref().map(<u64 as fidl::encoding::ValueTypeMarker>::borrow),
516                encoder,
517                offset + cur_offset,
518                depth,
519            )?;
520
521            _prev_end_offset = cur_offset + envelope_size;
522            if 2 > max_ordinal {
523                return Ok(());
524            }
525
526            // Write at offset+(ordinal-1)*envelope_size, since ordinals are one-based and envelopes
527            // are envelope_size bytes.
528            let cur_offset: usize = (2 - 1) * envelope_size;
529
530            // Zero reserved fields.
531            encoder.padding(offset + _prev_end_offset, cur_offset - _prev_end_offset);
532
533            // Safety:
534            // - bytes_len is calculated to fit envelope_size*max(member.ordinal).
535            // - Since cur_offset is envelope_size*(member.ordinal - 1) and the envelope takes
536            //   envelope_size bytes, there is always sufficient room.
537            fidl::encoding::encode_in_envelope_optional::<ReadFlags, D>(
538                self.flags.as_ref().map(<ReadFlags as fidl::encoding::ValueTypeMarker>::borrow),
539                encoder,
540                offset + cur_offset,
541                depth,
542            )?;
543
544            _prev_end_offset = cur_offset + envelope_size;
545
546            Ok(())
547        }
548    }
549
550    impl<D: fidl::encoding::ResourceDialect> fidl::encoding::Decode<Self, D>
551        for UnixDomainSocketReadRequest
552    {
553        #[inline(always)]
554        fn new_empty() -> Self {
555            Self::default()
556        }
557
558        unsafe fn decode(
559            &mut self,
560            decoder: &mut fidl::encoding::Decoder<'_, D>,
561            offset: usize,
562            mut depth: fidl::encoding::Depth,
563        ) -> fidl::Result<()> {
564            decoder.debug_check_bounds::<Self>(offset);
565            let len = match fidl::encoding::decode_vector_header(decoder, offset)? {
566                None => return Err(fidl::Error::NotNullable),
567                Some(len) => len,
568            };
569            // Calling decoder.out_of_line_offset(0) is not allowed.
570            if len == 0 {
571                return Ok(());
572            };
573            depth.increment()?;
574            let envelope_size = 8;
575            let bytes_len = len * envelope_size;
576            let offset = decoder.out_of_line_offset(bytes_len)?;
577            // Decode the envelope for each type.
578            let mut _next_ordinal_to_read = 0;
579            let mut next_offset = offset;
580            let end_offset = offset + bytes_len;
581            _next_ordinal_to_read += 1;
582            if next_offset >= end_offset {
583                return Ok(());
584            }
585
586            // Decode unknown envelopes for gaps in ordinals.
587            while _next_ordinal_to_read < 1 {
588                fidl::encoding::decode_unknown_envelope(decoder, next_offset, depth)?;
589                _next_ordinal_to_read += 1;
590                next_offset += envelope_size;
591            }
592
593            let next_out_of_line = decoder.next_out_of_line();
594            let handles_before = decoder.remaining_handles();
595            if let Some((inlined, num_bytes, num_handles)) =
596                fidl::encoding::decode_envelope_header(decoder, next_offset)?
597            {
598                let member_inline_size =
599                    <u64 as fidl::encoding::TypeMarker>::inline_size(decoder.context);
600                if inlined != (member_inline_size <= 4) {
601                    return Err(fidl::Error::InvalidInlineBitInEnvelope);
602                }
603                let inner_offset;
604                let mut inner_depth = depth.clone();
605                if inlined {
606                    decoder.check_inline_envelope_padding(next_offset, member_inline_size)?;
607                    inner_offset = next_offset;
608                } else {
609                    inner_offset = decoder.out_of_line_offset(member_inline_size)?;
610                    inner_depth.increment()?;
611                }
612                let val_ref = self.count.get_or_insert_with(|| fidl::new_empty!(u64, D));
613                fidl::decode!(u64, D, val_ref, decoder, inner_offset, inner_depth)?;
614                if !inlined && decoder.next_out_of_line() != next_out_of_line + (num_bytes as usize)
615                {
616                    return Err(fidl::Error::InvalidNumBytesInEnvelope);
617                }
618                if handles_before != decoder.remaining_handles() + (num_handles as usize) {
619                    return Err(fidl::Error::InvalidNumHandlesInEnvelope);
620                }
621            }
622
623            next_offset += envelope_size;
624            _next_ordinal_to_read += 1;
625            if next_offset >= end_offset {
626                return Ok(());
627            }
628
629            // Decode unknown envelopes for gaps in ordinals.
630            while _next_ordinal_to_read < 2 {
631                fidl::encoding::decode_unknown_envelope(decoder, next_offset, depth)?;
632                _next_ordinal_to_read += 1;
633                next_offset += envelope_size;
634            }
635
636            let next_out_of_line = decoder.next_out_of_line();
637            let handles_before = decoder.remaining_handles();
638            if let Some((inlined, num_bytes, num_handles)) =
639                fidl::encoding::decode_envelope_header(decoder, next_offset)?
640            {
641                let member_inline_size =
642                    <ReadFlags as fidl::encoding::TypeMarker>::inline_size(decoder.context);
643                if inlined != (member_inline_size <= 4) {
644                    return Err(fidl::Error::InvalidInlineBitInEnvelope);
645                }
646                let inner_offset;
647                let mut inner_depth = depth.clone();
648                if inlined {
649                    decoder.check_inline_envelope_padding(next_offset, member_inline_size)?;
650                    inner_offset = next_offset;
651                } else {
652                    inner_offset = decoder.out_of_line_offset(member_inline_size)?;
653                    inner_depth.increment()?;
654                }
655                let val_ref = self.flags.get_or_insert_with(|| fidl::new_empty!(ReadFlags, D));
656                fidl::decode!(ReadFlags, D, val_ref, decoder, inner_offset, inner_depth)?;
657                if !inlined && decoder.next_out_of_line() != next_out_of_line + (num_bytes as usize)
658                {
659                    return Err(fidl::Error::InvalidNumBytesInEnvelope);
660                }
661                if handles_before != decoder.remaining_handles() + (num_handles as usize) {
662                    return Err(fidl::Error::InvalidNumHandlesInEnvelope);
663                }
664            }
665
666            next_offset += envelope_size;
667
668            // Decode the remaining unknown envelopes.
669            while next_offset < end_offset {
670                _next_ordinal_to_read += 1;
671                fidl::encoding::decode_unknown_envelope(decoder, next_offset, depth)?;
672                next_offset += envelope_size;
673            }
674
675            Ok(())
676        }
677    }
678
679    impl UnixDomainSocketWriteResponse {
680        #[inline(always)]
681        fn max_ordinal_present(&self) -> u64 {
682            if let Some(_) = self.actual_count {
683                return 1;
684            }
685            0
686        }
687    }
688
689    impl fidl::encoding::ValueTypeMarker for UnixDomainSocketWriteResponse {
690        type Borrowed<'a> = &'a Self;
691        fn borrow(value: &<Self as fidl::encoding::TypeMarker>::Owned) -> Self::Borrowed<'_> {
692            value
693        }
694    }
695
696    unsafe impl fidl::encoding::TypeMarker for UnixDomainSocketWriteResponse {
697        type Owned = Self;
698
699        #[inline(always)]
700        fn inline_align(_context: fidl::encoding::Context) -> usize {
701            8
702        }
703
704        #[inline(always)]
705        fn inline_size(_context: fidl::encoding::Context) -> usize {
706            16
707        }
708    }
709
710    unsafe impl<D: fidl::encoding::ResourceDialect>
711        fidl::encoding::Encode<UnixDomainSocketWriteResponse, D>
712        for &UnixDomainSocketWriteResponse
713    {
714        unsafe fn encode(
715            self,
716            encoder: &mut fidl::encoding::Encoder<'_, D>,
717            offset: usize,
718            mut depth: fidl::encoding::Depth,
719        ) -> fidl::Result<()> {
720            encoder.debug_check_bounds::<UnixDomainSocketWriteResponse>(offset);
721            // Vector header
722            let max_ordinal: u64 = self.max_ordinal_present();
723            encoder.write_num(max_ordinal, offset);
724            encoder.write_num(fidl::encoding::ALLOC_PRESENT_U64, offset + 8);
725            // Calling encoder.out_of_line_offset(0) is not allowed.
726            if max_ordinal == 0 {
727                return Ok(());
728            }
729            depth.increment()?;
730            let envelope_size = 8;
731            let bytes_len = max_ordinal as usize * envelope_size;
732            #[allow(unused_variables)]
733            let offset = encoder.out_of_line_offset(bytes_len);
734            let mut _prev_end_offset: usize = 0;
735            if 1 > max_ordinal {
736                return Ok(());
737            }
738
739            // Write at offset+(ordinal-1)*envelope_size, since ordinals are one-based and envelopes
740            // are envelope_size bytes.
741            let cur_offset: usize = (1 - 1) * envelope_size;
742
743            // Zero reserved fields.
744            encoder.padding(offset + _prev_end_offset, cur_offset - _prev_end_offset);
745
746            // Safety:
747            // - bytes_len is calculated to fit envelope_size*max(member.ordinal).
748            // - Since cur_offset is envelope_size*(member.ordinal - 1) and the envelope takes
749            //   envelope_size bytes, there is always sufficient room.
750            fidl::encoding::encode_in_envelope_optional::<u64, D>(
751                self.actual_count.as_ref().map(<u64 as fidl::encoding::ValueTypeMarker>::borrow),
752                encoder,
753                offset + cur_offset,
754                depth,
755            )?;
756
757            _prev_end_offset = cur_offset + envelope_size;
758
759            Ok(())
760        }
761    }
762
763    impl<D: fidl::encoding::ResourceDialect> fidl::encoding::Decode<Self, D>
764        for UnixDomainSocketWriteResponse
765    {
766        #[inline(always)]
767        fn new_empty() -> Self {
768            Self::default()
769        }
770
771        unsafe fn decode(
772            &mut self,
773            decoder: &mut fidl::encoding::Decoder<'_, D>,
774            offset: usize,
775            mut depth: fidl::encoding::Depth,
776        ) -> fidl::Result<()> {
777            decoder.debug_check_bounds::<Self>(offset);
778            let len = match fidl::encoding::decode_vector_header(decoder, offset)? {
779                None => return Err(fidl::Error::NotNullable),
780                Some(len) => len,
781            };
782            // Calling decoder.out_of_line_offset(0) is not allowed.
783            if len == 0 {
784                return Ok(());
785            };
786            depth.increment()?;
787            let envelope_size = 8;
788            let bytes_len = len * envelope_size;
789            let offset = decoder.out_of_line_offset(bytes_len)?;
790            // Decode the envelope for each type.
791            let mut _next_ordinal_to_read = 0;
792            let mut next_offset = offset;
793            let end_offset = offset + bytes_len;
794            _next_ordinal_to_read += 1;
795            if next_offset >= end_offset {
796                return Ok(());
797            }
798
799            // Decode unknown envelopes for gaps in ordinals.
800            while _next_ordinal_to_read < 1 {
801                fidl::encoding::decode_unknown_envelope(decoder, next_offset, depth)?;
802                _next_ordinal_to_read += 1;
803                next_offset += envelope_size;
804            }
805
806            let next_out_of_line = decoder.next_out_of_line();
807            let handles_before = decoder.remaining_handles();
808            if let Some((inlined, num_bytes, num_handles)) =
809                fidl::encoding::decode_envelope_header(decoder, next_offset)?
810            {
811                let member_inline_size =
812                    <u64 as fidl::encoding::TypeMarker>::inline_size(decoder.context);
813                if inlined != (member_inline_size <= 4) {
814                    return Err(fidl::Error::InvalidInlineBitInEnvelope);
815                }
816                let inner_offset;
817                let mut inner_depth = depth.clone();
818                if inlined {
819                    decoder.check_inline_envelope_padding(next_offset, member_inline_size)?;
820                    inner_offset = next_offset;
821                } else {
822                    inner_offset = decoder.out_of_line_offset(member_inline_size)?;
823                    inner_depth.increment()?;
824                }
825                let val_ref = self.actual_count.get_or_insert_with(|| fidl::new_empty!(u64, D));
826                fidl::decode!(u64, D, val_ref, decoder, inner_offset, inner_depth)?;
827                if !inlined && decoder.next_out_of_line() != next_out_of_line + (num_bytes as usize)
828                {
829                    return Err(fidl::Error::InvalidNumBytesInEnvelope);
830                }
831                if handles_before != decoder.remaining_handles() + (num_handles as usize) {
832                    return Err(fidl::Error::InvalidNumHandlesInEnvelope);
833                }
834            }
835
836            next_offset += envelope_size;
837
838            // Decode the remaining unknown envelopes.
839            while next_offset < end_offset {
840                _next_ordinal_to_read += 1;
841                fidl::encoding::decode_unknown_envelope(decoder, next_offset, depth)?;
842                next_offset += envelope_size;
843            }
844
845            Ok(())
846        }
847    }
848}