fidl_fuchsia_net_power__common/
fidl_fuchsia_net_power__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 const MAX_NAME_LEN: u8 = 255;
12
13#[derive(Clone, Copy, Debug, Eq, Hash, Ord, PartialEq, PartialOrd)]
14pub struct Empty;
15
16impl fidl::Persistable for Empty {}
17
18#[derive(Clone, Copy, Debug, Eq, Hash, Ord, PartialEq, PartialOrd)]
19pub struct WakeGroupArmResponse {
20    /// Whether or not the hanging get was successfully armed.
21    ///
22    /// This is provided so that the client can tell whether it is safe to
23    /// suspend and wait for a data notification, or if it needs to post a
24    /// new hanging get and arm it in order to be woken up.
25    ///
26    /// This is `false` if there is no hanging get pending at the time that
27    /// `Arm` is called. This can happen even with correct client behavior,
28    /// if the client's arming the hanging get races with the netstack's
29    /// responding to the hanging get to delegate a lease.
30    pub armed: bool,
31}
32
33impl fidl::Persistable for WakeGroupArmResponse {}
34
35#[derive(Clone, Debug, Default, PartialEq)]
36pub struct WakeGroupOptions {
37    /// A name to identify the wake group for the purposes of debugging.
38    ///
39    /// Optional. If absent, the netstack chooses a debug name.
40    ///
41    /// Note: the debug name is not required to be, nor is it guaranteed to be,
42    /// unique. Wake groups are uniquely identified by their
43    /// [`fuchsia.net.resources/WakeGroupToken`].
44    pub debug_name: Option<String>,
45    #[doc(hidden)]
46    pub __source_breaking: fidl::marker::SourceBreaking,
47}
48
49impl fidl::Persistable for WakeGroupOptions {}
50
51pub mod wake_group_ordinals {
52    pub const WAIT_FOR_DATA: u64 = 0x1b9ea0f8e92c2e79;
53    pub const ARM: u64 = 0x4339c3052501e712;
54}
55
56pub mod wake_group_provider_ordinals {
57    pub const CREATE_WAKE_GROUP: u64 = 0x3c6a15f6c6b1447f;
58}
59
60mod internal {
61    use super::*;
62
63    impl fidl::encoding::ValueTypeMarker for Empty {
64        type Borrowed<'a> = &'a Self;
65        fn borrow(value: &<Self as fidl::encoding::TypeMarker>::Owned) -> Self::Borrowed<'_> {
66            value
67        }
68    }
69
70    unsafe impl fidl::encoding::TypeMarker for Empty {
71        type Owned = Self;
72
73        #[inline(always)]
74        fn inline_align(_context: fidl::encoding::Context) -> usize {
75            1
76        }
77
78        #[inline(always)]
79        fn inline_size(_context: fidl::encoding::Context) -> usize {
80            1
81        }
82    }
83
84    unsafe impl<D: fidl::encoding::ResourceDialect> fidl::encoding::Encode<Empty, D> for &Empty {
85        #[inline]
86        unsafe fn encode(
87            self,
88            encoder: &mut fidl::encoding::Encoder<'_, D>,
89            offset: usize,
90            _depth: fidl::encoding::Depth,
91        ) -> fidl::Result<()> {
92            encoder.debug_check_bounds::<Empty>(offset);
93            encoder.write_num(0u8, offset);
94            Ok(())
95        }
96    }
97
98    impl<D: fidl::encoding::ResourceDialect> fidl::encoding::Decode<Self, D> for Empty {
99        #[inline(always)]
100        fn new_empty() -> Self {
101            Self
102        }
103
104        #[inline]
105        unsafe fn decode(
106            &mut self,
107            decoder: &mut fidl::encoding::Decoder<'_, D>,
108            offset: usize,
109            _depth: fidl::encoding::Depth,
110        ) -> fidl::Result<()> {
111            decoder.debug_check_bounds::<Self>(offset);
112            match decoder.read_num::<u8>(offset) {
113                0 => Ok(()),
114                _ => Err(fidl::Error::Invalid),
115            }
116        }
117    }
118
119    impl fidl::encoding::ValueTypeMarker for WakeGroupArmResponse {
120        type Borrowed<'a> = &'a Self;
121        fn borrow(value: &<Self as fidl::encoding::TypeMarker>::Owned) -> Self::Borrowed<'_> {
122            value
123        }
124    }
125
126    unsafe impl fidl::encoding::TypeMarker for WakeGroupArmResponse {
127        type Owned = Self;
128
129        #[inline(always)]
130        fn inline_align(_context: fidl::encoding::Context) -> usize {
131            1
132        }
133
134        #[inline(always)]
135        fn inline_size(_context: fidl::encoding::Context) -> usize {
136            1
137        }
138    }
139
140    unsafe impl<D: fidl::encoding::ResourceDialect> fidl::encoding::Encode<WakeGroupArmResponse, D>
141        for &WakeGroupArmResponse
142    {
143        #[inline]
144        unsafe fn encode(
145            self,
146            encoder: &mut fidl::encoding::Encoder<'_, D>,
147            offset: usize,
148            _depth: fidl::encoding::Depth,
149        ) -> fidl::Result<()> {
150            encoder.debug_check_bounds::<WakeGroupArmResponse>(offset);
151            // Delegate to tuple encoding.
152            fidl::encoding::Encode::<WakeGroupArmResponse, D>::encode(
153                (<bool as fidl::encoding::ValueTypeMarker>::borrow(&self.armed),),
154                encoder,
155                offset,
156                _depth,
157            )
158        }
159    }
160    unsafe impl<D: fidl::encoding::ResourceDialect, T0: fidl::encoding::Encode<bool, D>>
161        fidl::encoding::Encode<WakeGroupArmResponse, D> for (T0,)
162    {
163        #[inline]
164        unsafe fn encode(
165            self,
166            encoder: &mut fidl::encoding::Encoder<'_, D>,
167            offset: usize,
168            depth: fidl::encoding::Depth,
169        ) -> fidl::Result<()> {
170            encoder.debug_check_bounds::<WakeGroupArmResponse>(offset);
171            // Zero out padding regions. There's no need to apply masks
172            // because the unmasked parts will be overwritten by fields.
173            // Write the fields.
174            self.0.encode(encoder, offset + 0, depth)?;
175            Ok(())
176        }
177    }
178
179    impl<D: fidl::encoding::ResourceDialect> fidl::encoding::Decode<Self, D> for WakeGroupArmResponse {
180        #[inline(always)]
181        fn new_empty() -> Self {
182            Self { armed: fidl::new_empty!(bool, D) }
183        }
184
185        #[inline]
186        unsafe fn decode(
187            &mut self,
188            decoder: &mut fidl::encoding::Decoder<'_, D>,
189            offset: usize,
190            _depth: fidl::encoding::Depth,
191        ) -> fidl::Result<()> {
192            decoder.debug_check_bounds::<Self>(offset);
193            // Verify that padding bytes are zero.
194            fidl::decode!(bool, D, &mut self.armed, decoder, offset + 0, _depth)?;
195            Ok(())
196        }
197    }
198
199    impl WakeGroupOptions {
200        #[inline(always)]
201        fn max_ordinal_present(&self) -> u64 {
202            if let Some(_) = self.debug_name {
203                return 1;
204            }
205            0
206        }
207    }
208
209    impl fidl::encoding::ValueTypeMarker for WakeGroupOptions {
210        type Borrowed<'a> = &'a Self;
211        fn borrow(value: &<Self as fidl::encoding::TypeMarker>::Owned) -> Self::Borrowed<'_> {
212            value
213        }
214    }
215
216    unsafe impl fidl::encoding::TypeMarker for WakeGroupOptions {
217        type Owned = Self;
218
219        #[inline(always)]
220        fn inline_align(_context: fidl::encoding::Context) -> usize {
221            8
222        }
223
224        #[inline(always)]
225        fn inline_size(_context: fidl::encoding::Context) -> usize {
226            16
227        }
228    }
229
230    unsafe impl<D: fidl::encoding::ResourceDialect> fidl::encoding::Encode<WakeGroupOptions, D>
231        for &WakeGroupOptions
232    {
233        unsafe fn encode(
234            self,
235            encoder: &mut fidl::encoding::Encoder<'_, D>,
236            offset: usize,
237            mut depth: fidl::encoding::Depth,
238        ) -> fidl::Result<()> {
239            encoder.debug_check_bounds::<WakeGroupOptions>(offset);
240            // Vector header
241            let max_ordinal: u64 = self.max_ordinal_present();
242            encoder.write_num(max_ordinal, offset);
243            encoder.write_num(fidl::encoding::ALLOC_PRESENT_U64, offset + 8);
244            // Calling encoder.out_of_line_offset(0) is not allowed.
245            if max_ordinal == 0 {
246                return Ok(());
247            }
248            depth.increment()?;
249            let envelope_size = 8;
250            let bytes_len = max_ordinal as usize * envelope_size;
251            #[allow(unused_variables)]
252            let offset = encoder.out_of_line_offset(bytes_len);
253            let mut _prev_end_offset: usize = 0;
254            if 1 > max_ordinal {
255                return Ok(());
256            }
257
258            // Write at offset+(ordinal-1)*envelope_size, since ordinals are one-based and envelopes
259            // are envelope_size bytes.
260            let cur_offset: usize = (1 - 1) * envelope_size;
261
262            // Zero reserved fields.
263            encoder.padding(offset + _prev_end_offset, cur_offset - _prev_end_offset);
264
265            // Safety:
266            // - bytes_len is calculated to fit envelope_size*max(member.ordinal).
267            // - Since cur_offset is envelope_size*(member.ordinal - 1) and the envelope takes
268            //   envelope_size bytes, there is always sufficient room.
269            fidl::encoding::encode_in_envelope_optional::<fidl::encoding::BoundedString<255>, D>(
270                self.debug_name.as_ref().map(
271                    <fidl::encoding::BoundedString<255> as fidl::encoding::ValueTypeMarker>::borrow,
272                ),
273                encoder,
274                offset + cur_offset,
275                depth,
276            )?;
277
278            _prev_end_offset = cur_offset + envelope_size;
279
280            Ok(())
281        }
282    }
283
284    impl<D: fidl::encoding::ResourceDialect> fidl::encoding::Decode<Self, D> for WakeGroupOptions {
285        #[inline(always)]
286        fn new_empty() -> Self {
287            Self::default()
288        }
289
290        unsafe fn decode(
291            &mut self,
292            decoder: &mut fidl::encoding::Decoder<'_, D>,
293            offset: usize,
294            mut depth: fidl::encoding::Depth,
295        ) -> fidl::Result<()> {
296            decoder.debug_check_bounds::<Self>(offset);
297            let len = match fidl::encoding::decode_vector_header(decoder, offset)? {
298                None => return Err(fidl::Error::NotNullable),
299                Some(len) => len,
300            };
301            // Calling decoder.out_of_line_offset(0) is not allowed.
302            if len == 0 {
303                return Ok(());
304            };
305            depth.increment()?;
306            let envelope_size = 8;
307            let bytes_len = len * envelope_size;
308            let offset = decoder.out_of_line_offset(bytes_len)?;
309            // Decode the envelope for each type.
310            let mut _next_ordinal_to_read = 0;
311            let mut next_offset = offset;
312            let end_offset = offset + bytes_len;
313            _next_ordinal_to_read += 1;
314            if next_offset >= end_offset {
315                return Ok(());
316            }
317
318            // Decode unknown envelopes for gaps in ordinals.
319            while _next_ordinal_to_read < 1 {
320                fidl::encoding::decode_unknown_envelope(decoder, next_offset, depth)?;
321                _next_ordinal_to_read += 1;
322                next_offset += envelope_size;
323            }
324
325            let next_out_of_line = decoder.next_out_of_line();
326            let handles_before = decoder.remaining_handles();
327            if let Some((inlined, num_bytes, num_handles)) =
328                fidl::encoding::decode_envelope_header(decoder, next_offset)?
329            {
330                let member_inline_size =
331                    <fidl::encoding::BoundedString<255> as fidl::encoding::TypeMarker>::inline_size(
332                        decoder.context,
333                    );
334                if inlined != (member_inline_size <= 4) {
335                    return Err(fidl::Error::InvalidInlineBitInEnvelope);
336                }
337                let inner_offset;
338                let mut inner_depth = depth.clone();
339                if inlined {
340                    decoder.check_inline_envelope_padding(next_offset, member_inline_size)?;
341                    inner_offset = next_offset;
342                } else {
343                    inner_offset = decoder.out_of_line_offset(member_inline_size)?;
344                    inner_depth.increment()?;
345                }
346                let val_ref = self
347                    .debug_name
348                    .get_or_insert_with(|| fidl::new_empty!(fidl::encoding::BoundedString<255>, D));
349                fidl::decode!(
350                    fidl::encoding::BoundedString<255>,
351                    D,
352                    val_ref,
353                    decoder,
354                    inner_offset,
355                    inner_depth
356                )?;
357                if !inlined && decoder.next_out_of_line() != next_out_of_line + (num_bytes as usize)
358                {
359                    return Err(fidl::Error::InvalidNumBytesInEnvelope);
360                }
361                if handles_before != decoder.remaining_handles() + (num_handles as usize) {
362                    return Err(fidl::Error::InvalidNumHandlesInEnvelope);
363                }
364            }
365
366            next_offset += envelope_size;
367
368            // Decode the remaining unknown envelopes.
369            while next_offset < end_offset {
370                _next_ordinal_to_read += 1;
371                fidl::encoding::decode_unknown_envelope(decoder, next_offset, depth)?;
372                next_offset += envelope_size;
373            }
374
375            Ok(())
376        }
377    }
378}