fidl_fuchsia_ui_focus_common/
fidl_fuchsia_ui_focus_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#[derive(Clone, Debug, Default, PartialEq)]
12pub struct FocusChainProviderWatchFocusKoidChainRequest {
13    #[doc(hidden)]
14    pub __source_breaking: fidl::marker::SourceBreaking,
15}
16
17impl fidl::Persistable for FocusChainProviderWatchFocusKoidChainRequest {}
18
19/// A `FocusKoidChain` serves almost the same purpose as a `FocusChain`, but is
20/// intended for applications that merely need to identify views in the chain
21/// and do not need to watch their state.
22#[derive(Clone, Debug, Default, PartialEq)]
23pub struct FocusKoidChain {
24    pub focus_chain: Option<Vec<u64>>,
25    #[doc(hidden)]
26    pub __source_breaking: fidl::marker::SourceBreaking,
27}
28
29impl fidl::Persistable for FocusKoidChain {}
30
31mod internal {
32    use super::*;
33
34    impl FocusChainProviderWatchFocusKoidChainRequest {
35        #[inline(always)]
36        fn max_ordinal_present(&self) -> u64 {
37            0
38        }
39    }
40
41    impl fidl::encoding::ValueTypeMarker for FocusChainProviderWatchFocusKoidChainRequest {
42        type Borrowed<'a> = &'a Self;
43        fn borrow(value: &<Self as fidl::encoding::TypeMarker>::Owned) -> Self::Borrowed<'_> {
44            value
45        }
46    }
47
48    unsafe impl fidl::encoding::TypeMarker for FocusChainProviderWatchFocusKoidChainRequest {
49        type Owned = Self;
50
51        #[inline(always)]
52        fn inline_align(_context: fidl::encoding::Context) -> usize {
53            8
54        }
55
56        #[inline(always)]
57        fn inline_size(_context: fidl::encoding::Context) -> usize {
58            16
59        }
60    }
61
62    unsafe impl<D: fidl::encoding::ResourceDialect>
63        fidl::encoding::Encode<FocusChainProviderWatchFocusKoidChainRequest, D>
64        for &FocusChainProviderWatchFocusKoidChainRequest
65    {
66        unsafe fn encode(
67            self,
68            encoder: &mut fidl::encoding::Encoder<'_, D>,
69            offset: usize,
70            mut depth: fidl::encoding::Depth,
71        ) -> fidl::Result<()> {
72            encoder.debug_check_bounds::<FocusChainProviderWatchFocusKoidChainRequest>(offset);
73            // Vector header
74            let max_ordinal: u64 = self.max_ordinal_present();
75            encoder.write_num(max_ordinal, offset);
76            encoder.write_num(fidl::encoding::ALLOC_PRESENT_U64, offset + 8);
77            // Calling encoder.out_of_line_offset(0) is not allowed.
78            if max_ordinal == 0 {
79                return Ok(());
80            }
81            depth.increment()?;
82            let envelope_size = 8;
83            let bytes_len = max_ordinal as usize * envelope_size;
84            #[allow(unused_variables)]
85            let offset = encoder.out_of_line_offset(bytes_len);
86            let mut _prev_end_offset: usize = 0;
87
88            Ok(())
89        }
90    }
91
92    impl<D: fidl::encoding::ResourceDialect> fidl::encoding::Decode<Self, D>
93        for FocusChainProviderWatchFocusKoidChainRequest
94    {
95        #[inline(always)]
96        fn new_empty() -> Self {
97            Self::default()
98        }
99
100        unsafe fn decode(
101            &mut self,
102            decoder: &mut fidl::encoding::Decoder<'_, D>,
103            offset: usize,
104            mut depth: fidl::encoding::Depth,
105        ) -> fidl::Result<()> {
106            decoder.debug_check_bounds::<Self>(offset);
107            let len = match fidl::encoding::decode_vector_header(decoder, offset)? {
108                None => return Err(fidl::Error::NotNullable),
109                Some(len) => len,
110            };
111            // Calling decoder.out_of_line_offset(0) is not allowed.
112            if len == 0 {
113                return Ok(());
114            };
115            depth.increment()?;
116            let envelope_size = 8;
117            let bytes_len = len * envelope_size;
118            let offset = decoder.out_of_line_offset(bytes_len)?;
119            // Decode the envelope for each type.
120            let mut _next_ordinal_to_read = 0;
121            let mut next_offset = offset;
122            let end_offset = offset + bytes_len;
123
124            // Decode the remaining unknown envelopes.
125            while next_offset < end_offset {
126                _next_ordinal_to_read += 1;
127                fidl::encoding::decode_unknown_envelope(decoder, next_offset, depth)?;
128                next_offset += envelope_size;
129            }
130
131            Ok(())
132        }
133    }
134
135    impl FocusKoidChain {
136        #[inline(always)]
137        fn max_ordinal_present(&self) -> u64 {
138            if let Some(_) = self.focus_chain {
139                return 1;
140            }
141            0
142        }
143    }
144
145    impl fidl::encoding::ValueTypeMarker for FocusKoidChain {
146        type Borrowed<'a> = &'a Self;
147        fn borrow(value: &<Self as fidl::encoding::TypeMarker>::Owned) -> Self::Borrowed<'_> {
148            value
149        }
150    }
151
152    unsafe impl fidl::encoding::TypeMarker for FocusKoidChain {
153        type Owned = Self;
154
155        #[inline(always)]
156        fn inline_align(_context: fidl::encoding::Context) -> usize {
157            8
158        }
159
160        #[inline(always)]
161        fn inline_size(_context: fidl::encoding::Context) -> usize {
162            16
163        }
164    }
165
166    unsafe impl<D: fidl::encoding::ResourceDialect> fidl::encoding::Encode<FocusKoidChain, D>
167        for &FocusKoidChain
168    {
169        unsafe fn encode(
170            self,
171            encoder: &mut fidl::encoding::Encoder<'_, D>,
172            offset: usize,
173            mut depth: fidl::encoding::Depth,
174        ) -> fidl::Result<()> {
175            encoder.debug_check_bounds::<FocusKoidChain>(offset);
176            // Vector header
177            let max_ordinal: u64 = self.max_ordinal_present();
178            encoder.write_num(max_ordinal, offset);
179            encoder.write_num(fidl::encoding::ALLOC_PRESENT_U64, offset + 8);
180            // Calling encoder.out_of_line_offset(0) is not allowed.
181            if max_ordinal == 0 {
182                return Ok(());
183            }
184            depth.increment()?;
185            let envelope_size = 8;
186            let bytes_len = max_ordinal as usize * envelope_size;
187            #[allow(unused_variables)]
188            let offset = encoder.out_of_line_offset(bytes_len);
189            let mut _prev_end_offset: usize = 0;
190            if 1 > max_ordinal {
191                return Ok(());
192            }
193
194            // Write at offset+(ordinal-1)*envelope_size, since ordinals are one-based and envelopes
195            // are envelope_size bytes.
196            let cur_offset: usize = (1 - 1) * envelope_size;
197
198            // Zero reserved fields.
199            encoder.padding(offset + _prev_end_offset, cur_offset - _prev_end_offset);
200
201            // Safety:
202            // - bytes_len is calculated to fit envelope_size*max(member.ordinal).
203            // - Since cur_offset is envelope_size*(member.ordinal - 1) and the envelope takes
204            //   envelope_size bytes, there is always sufficient room.
205            fidl::encoding::encode_in_envelope_optional::<fidl::encoding::UnboundedVector<u64>, D>(
206            self.focus_chain.as_ref().map(<fidl::encoding::UnboundedVector<u64> as fidl::encoding::ValueTypeMarker>::borrow),
207            encoder, offset + cur_offset, depth
208        )?;
209
210            _prev_end_offset = cur_offset + envelope_size;
211
212            Ok(())
213        }
214    }
215
216    impl<D: fidl::encoding::ResourceDialect> fidl::encoding::Decode<Self, D> for FocusKoidChain {
217        #[inline(always)]
218        fn new_empty() -> Self {
219            Self::default()
220        }
221
222        unsafe fn decode(
223            &mut self,
224            decoder: &mut fidl::encoding::Decoder<'_, D>,
225            offset: usize,
226            mut depth: fidl::encoding::Depth,
227        ) -> fidl::Result<()> {
228            decoder.debug_check_bounds::<Self>(offset);
229            let len = match fidl::encoding::decode_vector_header(decoder, offset)? {
230                None => return Err(fidl::Error::NotNullable),
231                Some(len) => len,
232            };
233            // Calling decoder.out_of_line_offset(0) is not allowed.
234            if len == 0 {
235                return Ok(());
236            };
237            depth.increment()?;
238            let envelope_size = 8;
239            let bytes_len = len * envelope_size;
240            let offset = decoder.out_of_line_offset(bytes_len)?;
241            // Decode the envelope for each type.
242            let mut _next_ordinal_to_read = 0;
243            let mut next_offset = offset;
244            let end_offset = offset + bytes_len;
245            _next_ordinal_to_read += 1;
246            if next_offset >= end_offset {
247                return Ok(());
248            }
249
250            // Decode unknown envelopes for gaps in ordinals.
251            while _next_ordinal_to_read < 1 {
252                fidl::encoding::decode_unknown_envelope(decoder, next_offset, depth)?;
253                _next_ordinal_to_read += 1;
254                next_offset += envelope_size;
255            }
256
257            let next_out_of_line = decoder.next_out_of_line();
258            let handles_before = decoder.remaining_handles();
259            if let Some((inlined, num_bytes, num_handles)) =
260                fidl::encoding::decode_envelope_header(decoder, next_offset)?
261            {
262                let member_inline_size = <fidl::encoding::UnboundedVector<u64> as fidl::encoding::TypeMarker>::inline_size(decoder.context);
263                if inlined != (member_inline_size <= 4) {
264                    return Err(fidl::Error::InvalidInlineBitInEnvelope);
265                }
266                let inner_offset;
267                let mut inner_depth = depth.clone();
268                if inlined {
269                    decoder.check_inline_envelope_padding(next_offset, member_inline_size)?;
270                    inner_offset = next_offset;
271                } else {
272                    inner_offset = decoder.out_of_line_offset(member_inline_size)?;
273                    inner_depth.increment()?;
274                }
275                let val_ref = self.focus_chain.get_or_insert_with(|| {
276                    fidl::new_empty!(fidl::encoding::UnboundedVector<u64>, D)
277                });
278                fidl::decode!(
279                    fidl::encoding::UnboundedVector<u64>,
280                    D,
281                    val_ref,
282                    decoder,
283                    inner_offset,
284                    inner_depth
285                )?;
286                if !inlined && decoder.next_out_of_line() != next_out_of_line + (num_bytes as usize)
287                {
288                    return Err(fidl::Error::InvalidNumBytesInEnvelope);
289                }
290                if handles_before != decoder.remaining_handles() + (num_handles as usize) {
291                    return Err(fidl::Error::InvalidNumHandlesInEnvelope);
292                }
293            }
294
295            next_offset += envelope_size;
296
297            // Decode the remaining unknown envelopes.
298            while next_offset < end_offset {
299                _next_ordinal_to_read += 1;
300                fidl::encoding::decode_unknown_envelope(decoder, next_offset, depth)?;
301                next_offset += envelope_size;
302            }
303
304            Ok(())
305        }
306    }
307}