fidl_fuchsia_scheduler_common/
fidl_fuchsia_scheduler_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_LENGTH: i32 = 2048;
12
13pub const MAX_PARAMETER_COUNT: i32 = 512;
14
15pub const MAX_PARAMETER_KEY_LENGTH: i32 = 512;
16
17pub const MAX_PARAMETER_VALUE_LENGTH: i32 = 2048;
18
19#[derive(Clone, Debug, PartialEq)]
20pub struct Parameter {
21    pub key: String,
22    pub value: ParameterValue,
23}
24
25impl fidl::Persistable for Parameter {}
26
27#[derive(Clone, Debug, Eq, Hash, Ord, PartialEq, PartialOrd)]
28pub struct RoleName {
29    pub role: String,
30}
31
32impl fidl::Persistable for RoleName {}
33
34#[derive(Clone, Debug)]
35pub enum ParameterValue {
36    FloatValue(f64),
37    IntValue(i64),
38    StringValue(String),
39    #[doc(hidden)]
40    __SourceBreaking {
41        unknown_ordinal: u64,
42    },
43}
44
45/// Pattern that matches an unknown `ParameterValue` member.
46#[macro_export]
47macro_rules! ParameterValueUnknown {
48    () => {
49        _
50    };
51}
52
53// Custom PartialEq so that unknown variants are not equal to themselves.
54impl PartialEq for ParameterValue {
55    fn eq(&self, other: &Self) -> bool {
56        match (self, other) {
57            (Self::FloatValue(x), Self::FloatValue(y)) => *x == *y,
58            (Self::IntValue(x), Self::IntValue(y)) => *x == *y,
59            (Self::StringValue(x), Self::StringValue(y)) => *x == *y,
60            _ => false,
61        }
62    }
63}
64
65impl ParameterValue {
66    #[inline]
67    pub fn ordinal(&self) -> u64 {
68        match *self {
69            Self::FloatValue(_) => 1,
70            Self::IntValue(_) => 2,
71            Self::StringValue(_) => 3,
72            Self::__SourceBreaking { unknown_ordinal } => unknown_ordinal,
73        }
74    }
75
76    #[inline]
77    pub fn unknown_variant_for_testing() -> Self {
78        Self::__SourceBreaking { unknown_ordinal: 0 }
79    }
80
81    #[inline]
82    pub fn is_unknown(&self) -> bool {
83        match self {
84            Self::__SourceBreaking { .. } => true,
85            _ => false,
86        }
87    }
88}
89
90impl fidl::Persistable for ParameterValue {}
91
92mod internal {
93    use super::*;
94
95    impl fidl::encoding::ValueTypeMarker for Parameter {
96        type Borrowed<'a> = &'a Self;
97        fn borrow(value: &<Self as fidl::encoding::TypeMarker>::Owned) -> Self::Borrowed<'_> {
98            value
99        }
100    }
101
102    unsafe impl fidl::encoding::TypeMarker for Parameter {
103        type Owned = Self;
104
105        #[inline(always)]
106        fn inline_align(_context: fidl::encoding::Context) -> usize {
107            8
108        }
109
110        #[inline(always)]
111        fn inline_size(_context: fidl::encoding::Context) -> usize {
112            32
113        }
114    }
115
116    unsafe impl<D: fidl::encoding::ResourceDialect> fidl::encoding::Encode<Parameter, D>
117        for &Parameter
118    {
119        #[inline]
120        unsafe fn encode(
121            self,
122            encoder: &mut fidl::encoding::Encoder<'_, D>,
123            offset: usize,
124            _depth: fidl::encoding::Depth,
125        ) -> fidl::Result<()> {
126            encoder.debug_check_bounds::<Parameter>(offset);
127            // Delegate to tuple encoding.
128            fidl::encoding::Encode::<Parameter, D>::encode(
129                (
130                    <fidl::encoding::BoundedString<512> as fidl::encoding::ValueTypeMarker>::borrow(
131                        &self.key,
132                    ),
133                    <ParameterValue as fidl::encoding::ValueTypeMarker>::borrow(&self.value),
134                ),
135                encoder,
136                offset,
137                _depth,
138            )
139        }
140    }
141    unsafe impl<
142            D: fidl::encoding::ResourceDialect,
143            T0: fidl::encoding::Encode<fidl::encoding::BoundedString<512>, D>,
144            T1: fidl::encoding::Encode<ParameterValue, D>,
145        > fidl::encoding::Encode<Parameter, D> for (T0, T1)
146    {
147        #[inline]
148        unsafe fn encode(
149            self,
150            encoder: &mut fidl::encoding::Encoder<'_, D>,
151            offset: usize,
152            depth: fidl::encoding::Depth,
153        ) -> fidl::Result<()> {
154            encoder.debug_check_bounds::<Parameter>(offset);
155            // Zero out padding regions. There's no need to apply masks
156            // because the unmasked parts will be overwritten by fields.
157            // Write the fields.
158            self.0.encode(encoder, offset + 0, depth)?;
159            self.1.encode(encoder, offset + 16, depth)?;
160            Ok(())
161        }
162    }
163
164    impl<D: fidl::encoding::ResourceDialect> fidl::encoding::Decode<Self, D> for Parameter {
165        #[inline(always)]
166        fn new_empty() -> Self {
167            Self {
168                key: fidl::new_empty!(fidl::encoding::BoundedString<512>, D),
169                value: fidl::new_empty!(ParameterValue, D),
170            }
171        }
172
173        #[inline]
174        unsafe fn decode(
175            &mut self,
176            decoder: &mut fidl::encoding::Decoder<'_, D>,
177            offset: usize,
178            _depth: fidl::encoding::Depth,
179        ) -> fidl::Result<()> {
180            decoder.debug_check_bounds::<Self>(offset);
181            // Verify that padding bytes are zero.
182            fidl::decode!(
183                fidl::encoding::BoundedString<512>,
184                D,
185                &mut self.key,
186                decoder,
187                offset + 0,
188                _depth
189            )?;
190            fidl::decode!(ParameterValue, D, &mut self.value, decoder, offset + 16, _depth)?;
191            Ok(())
192        }
193    }
194
195    impl fidl::encoding::ValueTypeMarker for RoleName {
196        type Borrowed<'a> = &'a Self;
197        fn borrow(value: &<Self as fidl::encoding::TypeMarker>::Owned) -> Self::Borrowed<'_> {
198            value
199        }
200    }
201
202    unsafe impl fidl::encoding::TypeMarker for RoleName {
203        type Owned = Self;
204
205        #[inline(always)]
206        fn inline_align(_context: fidl::encoding::Context) -> usize {
207            8
208        }
209
210        #[inline(always)]
211        fn inline_size(_context: fidl::encoding::Context) -> usize {
212            16
213        }
214    }
215
216    unsafe impl<D: fidl::encoding::ResourceDialect> fidl::encoding::Encode<RoleName, D> for &RoleName {
217        #[inline]
218        unsafe fn encode(
219            self,
220            encoder: &mut fidl::encoding::Encoder<'_, D>,
221            offset: usize,
222            _depth: fidl::encoding::Depth,
223        ) -> fidl::Result<()> {
224            encoder.debug_check_bounds::<RoleName>(offset);
225            // Delegate to tuple encoding.
226            fidl::encoding::Encode::<RoleName, D>::encode(
227                (<fidl::encoding::BoundedString<2048> as fidl::encoding::ValueTypeMarker>::borrow(
228                    &self.role,
229                ),),
230                encoder,
231                offset,
232                _depth,
233            )
234        }
235    }
236    unsafe impl<
237            D: fidl::encoding::ResourceDialect,
238            T0: fidl::encoding::Encode<fidl::encoding::BoundedString<2048>, D>,
239        > fidl::encoding::Encode<RoleName, D> for (T0,)
240    {
241        #[inline]
242        unsafe fn encode(
243            self,
244            encoder: &mut fidl::encoding::Encoder<'_, D>,
245            offset: usize,
246            depth: fidl::encoding::Depth,
247        ) -> fidl::Result<()> {
248            encoder.debug_check_bounds::<RoleName>(offset);
249            // Zero out padding regions. There's no need to apply masks
250            // because the unmasked parts will be overwritten by fields.
251            // Write the fields.
252            self.0.encode(encoder, offset + 0, depth)?;
253            Ok(())
254        }
255    }
256
257    impl<D: fidl::encoding::ResourceDialect> fidl::encoding::Decode<Self, D> for RoleName {
258        #[inline(always)]
259        fn new_empty() -> Self {
260            Self { role: fidl::new_empty!(fidl::encoding::BoundedString<2048>, D) }
261        }
262
263        #[inline]
264        unsafe fn decode(
265            &mut self,
266            decoder: &mut fidl::encoding::Decoder<'_, D>,
267            offset: usize,
268            _depth: fidl::encoding::Depth,
269        ) -> fidl::Result<()> {
270            decoder.debug_check_bounds::<Self>(offset);
271            // Verify that padding bytes are zero.
272            fidl::decode!(
273                fidl::encoding::BoundedString<2048>,
274                D,
275                &mut self.role,
276                decoder,
277                offset + 0,
278                _depth
279            )?;
280            Ok(())
281        }
282    }
283
284    impl fidl::encoding::ValueTypeMarker for ParameterValue {
285        type Borrowed<'a> = &'a Self;
286        fn borrow(value: &<Self as fidl::encoding::TypeMarker>::Owned) -> Self::Borrowed<'_> {
287            value
288        }
289    }
290
291    unsafe impl fidl::encoding::TypeMarker for ParameterValue {
292        type Owned = Self;
293
294        #[inline(always)]
295        fn inline_align(_context: fidl::encoding::Context) -> usize {
296            8
297        }
298
299        #[inline(always)]
300        fn inline_size(_context: fidl::encoding::Context) -> usize {
301            16
302        }
303    }
304
305    unsafe impl<D: fidl::encoding::ResourceDialect> fidl::encoding::Encode<ParameterValue, D>
306        for &ParameterValue
307    {
308        #[inline]
309        unsafe fn encode(
310            self,
311            encoder: &mut fidl::encoding::Encoder<'_, D>,
312            offset: usize,
313            _depth: fidl::encoding::Depth,
314        ) -> fidl::Result<()> {
315            encoder.debug_check_bounds::<ParameterValue>(offset);
316            encoder.write_num::<u64>(self.ordinal(), offset);
317            match self {
318            ParameterValue::FloatValue(ref val) => {
319                fidl::encoding::encode_in_envelope::<f64, D>(
320                    <f64 as fidl::encoding::ValueTypeMarker>::borrow(val),
321                    encoder, offset + 8, _depth
322                )
323            }
324            ParameterValue::IntValue(ref val) => {
325                fidl::encoding::encode_in_envelope::<i64, D>(
326                    <i64 as fidl::encoding::ValueTypeMarker>::borrow(val),
327                    encoder, offset + 8, _depth
328                )
329            }
330            ParameterValue::StringValue(ref val) => {
331                fidl::encoding::encode_in_envelope::<fidl::encoding::BoundedString<2048>, D>(
332                    <fidl::encoding::BoundedString<2048> as fidl::encoding::ValueTypeMarker>::borrow(val),
333                    encoder, offset + 8, _depth
334                )
335            }
336            ParameterValue::__SourceBreaking { .. } => Err(fidl::Error::UnknownUnionTag),
337        }
338        }
339    }
340
341    impl<D: fidl::encoding::ResourceDialect> fidl::encoding::Decode<Self, D> for ParameterValue {
342        #[inline(always)]
343        fn new_empty() -> Self {
344            Self::__SourceBreaking { unknown_ordinal: 0 }
345        }
346
347        #[inline]
348        unsafe fn decode(
349            &mut self,
350            decoder: &mut fidl::encoding::Decoder<'_, D>,
351            offset: usize,
352            mut depth: fidl::encoding::Depth,
353        ) -> fidl::Result<()> {
354            decoder.debug_check_bounds::<Self>(offset);
355            #[allow(unused_variables)]
356            let next_out_of_line = decoder.next_out_of_line();
357            let handles_before = decoder.remaining_handles();
358            let (ordinal, inlined, num_bytes, num_handles) =
359                fidl::encoding::decode_union_inline_portion(decoder, offset)?;
360
361            let member_inline_size = match ordinal {
362                1 => <f64 as fidl::encoding::TypeMarker>::inline_size(decoder.context),
363                2 => <i64 as fidl::encoding::TypeMarker>::inline_size(decoder.context),
364                3 => {
365                    <fidl::encoding::BoundedString<2048> as fidl::encoding::TypeMarker>::inline_size(
366                        decoder.context,
367                    )
368                }
369                0 => return Err(fidl::Error::UnknownUnionTag),
370                _ => num_bytes as usize,
371            };
372
373            if inlined != (member_inline_size <= 4) {
374                return Err(fidl::Error::InvalidInlineBitInEnvelope);
375            }
376            let _inner_offset;
377            if inlined {
378                decoder.check_inline_envelope_padding(offset + 8, member_inline_size)?;
379                _inner_offset = offset + 8;
380            } else {
381                depth.increment()?;
382                _inner_offset = decoder.out_of_line_offset(member_inline_size)?;
383            }
384            match ordinal {
385                1 => {
386                    #[allow(irrefutable_let_patterns)]
387                    if let ParameterValue::FloatValue(_) = self {
388                        // Do nothing, read the value into the object
389                    } else {
390                        // Initialize `self` to the right variant
391                        *self = ParameterValue::FloatValue(fidl::new_empty!(f64, D));
392                    }
393                    #[allow(irrefutable_let_patterns)]
394                    if let ParameterValue::FloatValue(ref mut val) = self {
395                        fidl::decode!(f64, D, val, decoder, _inner_offset, depth)?;
396                    } else {
397                        unreachable!()
398                    }
399                }
400                2 => {
401                    #[allow(irrefutable_let_patterns)]
402                    if let ParameterValue::IntValue(_) = self {
403                        // Do nothing, read the value into the object
404                    } else {
405                        // Initialize `self` to the right variant
406                        *self = ParameterValue::IntValue(fidl::new_empty!(i64, D));
407                    }
408                    #[allow(irrefutable_let_patterns)]
409                    if let ParameterValue::IntValue(ref mut val) = self {
410                        fidl::decode!(i64, D, val, decoder, _inner_offset, depth)?;
411                    } else {
412                        unreachable!()
413                    }
414                }
415                3 => {
416                    #[allow(irrefutable_let_patterns)]
417                    if let ParameterValue::StringValue(_) = self {
418                        // Do nothing, read the value into the object
419                    } else {
420                        // Initialize `self` to the right variant
421                        *self = ParameterValue::StringValue(fidl::new_empty!(
422                            fidl::encoding::BoundedString<2048>,
423                            D
424                        ));
425                    }
426                    #[allow(irrefutable_let_patterns)]
427                    if let ParameterValue::StringValue(ref mut val) = self {
428                        fidl::decode!(
429                            fidl::encoding::BoundedString<2048>,
430                            D,
431                            val,
432                            decoder,
433                            _inner_offset,
434                            depth
435                        )?;
436                    } else {
437                        unreachable!()
438                    }
439                }
440                #[allow(deprecated)]
441                ordinal => {
442                    for _ in 0..num_handles {
443                        decoder.drop_next_handle()?;
444                    }
445                    *self = ParameterValue::__SourceBreaking { unknown_ordinal: ordinal };
446                }
447            }
448            if !inlined && decoder.next_out_of_line() != next_out_of_line + (num_bytes as usize) {
449                return Err(fidl::Error::InvalidNumBytesInEnvelope);
450            }
451            if handles_before != decoder.remaining_handles() + (num_handles as usize) {
452                return Err(fidl::Error::InvalidNumHandlesInEnvelope);
453            }
454            Ok(())
455        }
456    }
457}