fidl_fuchsia_driver_loader__common/
fidl_fuchsia_driver_loader__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/// ABI that exports the immutable dynamic linking data structures
12/// for the loaded modules.
13pub type DynamicLinkingPassiveAbi = u64;
14
15#[derive(Clone, Debug, Default, PartialEq)]
16pub struct DriverHostLoadDriverResponse {
17    /// The dynamic linking passive ABI for the loaded modules.
18    pub dynamic_linking_abi: Option<u64>,
19    #[doc(hidden)]
20    pub __source_breaking: fidl::marker::SourceBreaking,
21}
22
23impl fidl::Persistable for DriverHostLoadDriverResponse {}
24
25pub mod driver_host_ordinals {
26    pub const LOAD_DRIVER: u64 = 0x5c43a774b3fd4930;
27}
28
29pub mod driver_host_launcher_ordinals {
30    pub const LAUNCH: u64 = 0x3af75d84043eb730;
31}
32
33mod internal {
34    use super::*;
35
36    impl DriverHostLoadDriverResponse {
37        #[inline(always)]
38        fn max_ordinal_present(&self) -> u64 {
39            if let Some(_) = self.dynamic_linking_abi {
40                return 1;
41            }
42            0
43        }
44    }
45
46    impl fidl::encoding::ValueTypeMarker for DriverHostLoadDriverResponse {
47        type Borrowed<'a> = &'a Self;
48        fn borrow(value: &<Self as fidl::encoding::TypeMarker>::Owned) -> Self::Borrowed<'_> {
49            value
50        }
51    }
52
53    unsafe impl fidl::encoding::TypeMarker for DriverHostLoadDriverResponse {
54        type Owned = Self;
55
56        #[inline(always)]
57        fn inline_align(_context: fidl::encoding::Context) -> usize {
58            8
59        }
60
61        #[inline(always)]
62        fn inline_size(_context: fidl::encoding::Context) -> usize {
63            16
64        }
65    }
66
67    unsafe impl<D: fidl::encoding::ResourceDialect>
68        fidl::encoding::Encode<DriverHostLoadDriverResponse, D> for &DriverHostLoadDriverResponse
69    {
70        unsafe fn encode(
71            self,
72            encoder: &mut fidl::encoding::Encoder<'_, D>,
73            offset: usize,
74            mut depth: fidl::encoding::Depth,
75        ) -> fidl::Result<()> {
76            encoder.debug_check_bounds::<DriverHostLoadDriverResponse>(offset);
77            // Vector header
78            let max_ordinal: u64 = self.max_ordinal_present();
79            encoder.write_num(max_ordinal, offset);
80            encoder.write_num(fidl::encoding::ALLOC_PRESENT_U64, offset + 8);
81            // Calling encoder.out_of_line_offset(0) is not allowed.
82            if max_ordinal == 0 {
83                return Ok(());
84            }
85            depth.increment()?;
86            let envelope_size = 8;
87            let bytes_len = max_ordinal as usize * envelope_size;
88            #[allow(unused_variables)]
89            let offset = encoder.out_of_line_offset(bytes_len);
90            let mut _prev_end_offset: usize = 0;
91            if 1 > max_ordinal {
92                return Ok(());
93            }
94
95            // Write at offset+(ordinal-1)*envelope_size, since ordinals are one-based and envelopes
96            // are envelope_size bytes.
97            let cur_offset: usize = (1 - 1) * envelope_size;
98
99            // Zero reserved fields.
100            encoder.padding(offset + _prev_end_offset, cur_offset - _prev_end_offset);
101
102            // Safety:
103            // - bytes_len is calculated to fit envelope_size*max(member.ordinal).
104            // - Since cur_offset is envelope_size*(member.ordinal - 1) and the envelope takes
105            //   envelope_size bytes, there is always sufficient room.
106            fidl::encoding::encode_in_envelope_optional::<u64, D>(
107                self.dynamic_linking_abi
108                    .as_ref()
109                    .map(<u64 as fidl::encoding::ValueTypeMarker>::borrow),
110                encoder,
111                offset + cur_offset,
112                depth,
113            )?;
114
115            _prev_end_offset = cur_offset + envelope_size;
116
117            Ok(())
118        }
119    }
120
121    impl<D: fidl::encoding::ResourceDialect> fidl::encoding::Decode<Self, D>
122        for DriverHostLoadDriverResponse
123    {
124        #[inline(always)]
125        fn new_empty() -> Self {
126            Self::default()
127        }
128
129        unsafe fn decode(
130            &mut self,
131            decoder: &mut fidl::encoding::Decoder<'_, D>,
132            offset: usize,
133            mut depth: fidl::encoding::Depth,
134        ) -> fidl::Result<()> {
135            decoder.debug_check_bounds::<Self>(offset);
136            let len = match fidl::encoding::decode_vector_header(decoder, offset)? {
137                None => return Err(fidl::Error::NotNullable),
138                Some(len) => len,
139            };
140            // Calling decoder.out_of_line_offset(0) is not allowed.
141            if len == 0 {
142                return Ok(());
143            };
144            depth.increment()?;
145            let envelope_size = 8;
146            let bytes_len = len * envelope_size;
147            let offset = decoder.out_of_line_offset(bytes_len)?;
148            // Decode the envelope for each type.
149            let mut _next_ordinal_to_read = 0;
150            let mut next_offset = offset;
151            let end_offset = offset + bytes_len;
152            _next_ordinal_to_read += 1;
153            if next_offset >= end_offset {
154                return Ok(());
155            }
156
157            // Decode unknown envelopes for gaps in ordinals.
158            while _next_ordinal_to_read < 1 {
159                fidl::encoding::decode_unknown_envelope(decoder, next_offset, depth)?;
160                _next_ordinal_to_read += 1;
161                next_offset += envelope_size;
162            }
163
164            let next_out_of_line = decoder.next_out_of_line();
165            let handles_before = decoder.remaining_handles();
166            if let Some((inlined, num_bytes, num_handles)) =
167                fidl::encoding::decode_envelope_header(decoder, next_offset)?
168            {
169                let member_inline_size =
170                    <u64 as fidl::encoding::TypeMarker>::inline_size(decoder.context);
171                if inlined != (member_inline_size <= 4) {
172                    return Err(fidl::Error::InvalidInlineBitInEnvelope);
173                }
174                let inner_offset;
175                let mut inner_depth = depth.clone();
176                if inlined {
177                    decoder.check_inline_envelope_padding(next_offset, member_inline_size)?;
178                    inner_offset = next_offset;
179                } else {
180                    inner_offset = decoder.out_of_line_offset(member_inline_size)?;
181                    inner_depth.increment()?;
182                }
183                let val_ref =
184                    self.dynamic_linking_abi.get_or_insert_with(|| fidl::new_empty!(u64, D));
185                fidl::decode!(u64, D, val_ref, decoder, inner_offset, inner_depth)?;
186                if !inlined && decoder.next_out_of_line() != next_out_of_line + (num_bytes as usize)
187                {
188                    return Err(fidl::Error::InvalidNumBytesInEnvelope);
189                }
190                if handles_before != decoder.remaining_handles() + (num_handles as usize) {
191                    return Err(fidl::Error::InvalidNumHandlesInEnvelope);
192                }
193            }
194
195            next_offset += envelope_size;
196
197            // Decode the remaining unknown envelopes.
198            while next_offset < end_offset {
199                _next_ordinal_to_read += 1;
200                fidl::encoding::decode_unknown_envelope(decoder, next_offset, depth)?;
201                next_offset += envelope_size;
202            }
203
204            Ok(())
205        }
206    }
207}