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