Skip to main content

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