fidl_fuchsia_power_clientlevel_common/
fidl_fuchsia_power_clientlevel_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/// A value that represents the type of client using the protocol.
12///
13/// `ClientType` is used as a parameter for:
14///   1) [`Connector.Connect`] to connect a [`Watcher`] to the power level of
15///   the specified client type
16///   2) [`fuchsia.power.systemmode/ClientConfigurator.Get`] and
17///   [`fuchsia.power.systemmode/ClientConfigurator.Set`] to update the power
18///   configuration of the specified client type
19#[derive(Copy, Clone, Debug, Eq, PartialEq, Ord, PartialOrd, Hash)]
20pub enum ClientType {
21    Wlan,
22    #[doc(hidden)]
23    __SourceBreaking {
24        unknown_ordinal: u32,
25    },
26}
27
28/// Pattern that matches an unknown `ClientType` member.
29#[macro_export]
30macro_rules! ClientTypeUnknown {
31    () => {
32        _
33    };
34}
35
36impl ClientType {
37    #[inline]
38    pub fn from_primitive(prim: u32) -> Option<Self> {
39        match prim {
40            1 => Some(Self::Wlan),
41            _ => None,
42        }
43    }
44
45    #[inline]
46    pub fn from_primitive_allow_unknown(prim: u32) -> Self {
47        match prim {
48            1 => Self::Wlan,
49            unknown_ordinal => Self::__SourceBreaking { unknown_ordinal },
50        }
51    }
52
53    #[inline]
54    pub fn unknown() -> Self {
55        Self::__SourceBreaking { unknown_ordinal: 0xffffffff }
56    }
57
58    #[inline]
59    pub const fn into_primitive(self) -> u32 {
60        match self {
61            Self::Wlan => 1,
62            Self::__SourceBreaking { unknown_ordinal } => unknown_ordinal,
63        }
64    }
65
66    #[inline]
67    pub fn is_unknown(&self) -> bool {
68        match self {
69            Self::__SourceBreaking { unknown_ordinal: _ } => true,
70            _ => false,
71        }
72    }
73}
74
75#[derive(Clone, Copy, Debug, Eq, Hash, Ord, PartialEq, PartialOrd)]
76#[repr(C)]
77pub struct WatcherWatchResponse {
78    pub level: u64,
79}
80
81impl fidl::Persistable for WatcherWatchResponse {}
82
83mod internal {
84    use super::*;
85    unsafe impl fidl::encoding::TypeMarker for ClientType {
86        type Owned = Self;
87
88        #[inline(always)]
89        fn inline_align(_context: fidl::encoding::Context) -> usize {
90            std::mem::align_of::<u32>()
91        }
92
93        #[inline(always)]
94        fn inline_size(_context: fidl::encoding::Context) -> usize {
95            std::mem::size_of::<u32>()
96        }
97
98        #[inline(always)]
99        fn encode_is_copy() -> bool {
100            false
101        }
102
103        #[inline(always)]
104        fn decode_is_copy() -> bool {
105            false
106        }
107    }
108
109    impl fidl::encoding::ValueTypeMarker for ClientType {
110        type Borrowed<'a> = Self;
111        #[inline(always)]
112        fn borrow(value: &<Self as fidl::encoding::TypeMarker>::Owned) -> Self::Borrowed<'_> {
113            *value
114        }
115    }
116
117    unsafe impl<D: fidl::encoding::ResourceDialect> fidl::encoding::Encode<Self, D> for ClientType {
118        #[inline]
119        unsafe fn encode(
120            self,
121            encoder: &mut fidl::encoding::Encoder<'_, D>,
122            offset: usize,
123            _depth: fidl::encoding::Depth,
124        ) -> fidl::Result<()> {
125            encoder.debug_check_bounds::<Self>(offset);
126            encoder.write_num(self.into_primitive(), offset);
127            Ok(())
128        }
129    }
130
131    impl<D: fidl::encoding::ResourceDialect> fidl::encoding::Decode<Self, D> for ClientType {
132        #[inline(always)]
133        fn new_empty() -> Self {
134            Self::unknown()
135        }
136
137        #[inline]
138        unsafe fn decode(
139            &mut self,
140            decoder: &mut fidl::encoding::Decoder<'_, D>,
141            offset: usize,
142            _depth: fidl::encoding::Depth,
143        ) -> fidl::Result<()> {
144            decoder.debug_check_bounds::<Self>(offset);
145            let prim = decoder.read_num::<u32>(offset);
146
147            *self = Self::from_primitive_allow_unknown(prim);
148            Ok(())
149        }
150    }
151
152    impl fidl::encoding::ValueTypeMarker for WatcherWatchResponse {
153        type Borrowed<'a> = &'a Self;
154        fn borrow(value: &<Self as fidl::encoding::TypeMarker>::Owned) -> Self::Borrowed<'_> {
155            value
156        }
157    }
158
159    unsafe impl fidl::encoding::TypeMarker for WatcherWatchResponse {
160        type Owned = Self;
161
162        #[inline(always)]
163        fn inline_align(_context: fidl::encoding::Context) -> usize {
164            8
165        }
166
167        #[inline(always)]
168        fn inline_size(_context: fidl::encoding::Context) -> usize {
169            8
170        }
171        #[inline(always)]
172        fn encode_is_copy() -> bool {
173            true
174        }
175
176        #[inline(always)]
177        fn decode_is_copy() -> bool {
178            true
179        }
180    }
181
182    unsafe impl<D: fidl::encoding::ResourceDialect> fidl::encoding::Encode<WatcherWatchResponse, D>
183        for &WatcherWatchResponse
184    {
185        #[inline]
186        unsafe fn encode(
187            self,
188            encoder: &mut fidl::encoding::Encoder<'_, D>,
189            offset: usize,
190            _depth: fidl::encoding::Depth,
191        ) -> fidl::Result<()> {
192            encoder.debug_check_bounds::<WatcherWatchResponse>(offset);
193            unsafe {
194                // Copy the object into the buffer.
195                let buf_ptr = encoder.buf.as_mut_ptr().add(offset);
196                (buf_ptr as *mut WatcherWatchResponse)
197                    .write_unaligned((self as *const WatcherWatchResponse).read());
198                // Zero out padding regions. Unlike `fidl_struct_impl_noncopy!`, this must be
199                // done second because the memcpy will write garbage to these bytes.
200            }
201            Ok(())
202        }
203    }
204    unsafe impl<D: fidl::encoding::ResourceDialect, T0: fidl::encoding::Encode<u64, D>>
205        fidl::encoding::Encode<WatcherWatchResponse, D> for (T0,)
206    {
207        #[inline]
208        unsafe fn encode(
209            self,
210            encoder: &mut fidl::encoding::Encoder<'_, D>,
211            offset: usize,
212            depth: fidl::encoding::Depth,
213        ) -> fidl::Result<()> {
214            encoder.debug_check_bounds::<WatcherWatchResponse>(offset);
215            // Zero out padding regions. There's no need to apply masks
216            // because the unmasked parts will be overwritten by fields.
217            // Write the fields.
218            self.0.encode(encoder, offset + 0, depth)?;
219            Ok(())
220        }
221    }
222
223    impl<D: fidl::encoding::ResourceDialect> fidl::encoding::Decode<Self, D> for WatcherWatchResponse {
224        #[inline(always)]
225        fn new_empty() -> Self {
226            Self { level: fidl::new_empty!(u64, D) }
227        }
228
229        #[inline]
230        unsafe fn decode(
231            &mut self,
232            decoder: &mut fidl::encoding::Decoder<'_, D>,
233            offset: usize,
234            _depth: fidl::encoding::Depth,
235        ) -> fidl::Result<()> {
236            decoder.debug_check_bounds::<Self>(offset);
237            let buf_ptr = unsafe { decoder.buf.as_ptr().add(offset) };
238            // Verify that padding bytes are zero.
239            // Copy from the buffer into the object.
240            unsafe {
241                std::ptr::copy_nonoverlapping(buf_ptr, self as *mut Self as *mut u8, 8);
242            }
243            Ok(())
244        }
245    }
246}