fidl_test_sagcontrol_common/
fidl_test_sagcontrol_common.rs1#![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(Copy, Clone, Debug, Eq, PartialEq, Ord, PartialOrd, Hash)]
13#[repr(u32)]
14pub enum SetSystemActivityGovernorStateError {
15 NotSupported = 1,
18 Internal = 2,
20}
21
22impl SetSystemActivityGovernorStateError {
23 #[inline]
24 pub fn from_primitive(prim: u32) -> Option<Self> {
25 match prim {
26 1 => Some(Self::NotSupported),
27 2 => Some(Self::Internal),
28 _ => None,
29 }
30 }
31
32 #[inline]
33 pub const fn into_primitive(self) -> u32 {
34 self as u32
35 }
36
37 #[deprecated = "Strict enums should not use `is_unknown`"]
38 #[inline]
39 pub fn is_unknown(&self) -> bool {
40 false
41 }
42}
43
44#[derive(Clone, Debug, Default, PartialEq)]
45pub struct SystemActivityGovernorState {
46 pub execution_state_level: Option<fidl_fuchsia_power_system::ExecutionStateLevel>,
47 pub application_activity_level: Option<fidl_fuchsia_power_system::ApplicationActivityLevel>,
48 #[doc(hidden)]
49 pub __source_breaking: fidl::marker::SourceBreaking,
50}
51
52impl fidl::Persistable for SystemActivityGovernorState {}
53
54mod internal {
55 use super::*;
56 unsafe impl fidl::encoding::TypeMarker for SetSystemActivityGovernorStateError {
57 type Owned = Self;
58
59 #[inline(always)]
60 fn inline_align(_context: fidl::encoding::Context) -> usize {
61 std::mem::align_of::<u32>()
62 }
63
64 #[inline(always)]
65 fn inline_size(_context: fidl::encoding::Context) -> usize {
66 std::mem::size_of::<u32>()
67 }
68
69 #[inline(always)]
70 fn encode_is_copy() -> bool {
71 true
72 }
73
74 #[inline(always)]
75 fn decode_is_copy() -> bool {
76 false
77 }
78 }
79
80 impl fidl::encoding::ValueTypeMarker for SetSystemActivityGovernorStateError {
81 type Borrowed<'a> = Self;
82 #[inline(always)]
83 fn borrow(value: &<Self as fidl::encoding::TypeMarker>::Owned) -> Self::Borrowed<'_> {
84 *value
85 }
86 }
87
88 unsafe impl<D: fidl::encoding::ResourceDialect> fidl::encoding::Encode<Self, D>
89 for SetSystemActivityGovernorStateError
90 {
91 #[inline]
92 unsafe fn encode(
93 self,
94 encoder: &mut fidl::encoding::Encoder<'_, D>,
95 offset: usize,
96 _depth: fidl::encoding::Depth,
97 ) -> fidl::Result<()> {
98 encoder.debug_check_bounds::<Self>(offset);
99 encoder.write_num(self.into_primitive(), offset);
100 Ok(())
101 }
102 }
103
104 impl<D: fidl::encoding::ResourceDialect> fidl::encoding::Decode<Self, D>
105 for SetSystemActivityGovernorStateError
106 {
107 #[inline(always)]
108 fn new_empty() -> Self {
109 Self::NotSupported
110 }
111
112 #[inline]
113 unsafe fn decode(
114 &mut self,
115 decoder: &mut fidl::encoding::Decoder<'_, D>,
116 offset: usize,
117 _depth: fidl::encoding::Depth,
118 ) -> fidl::Result<()> {
119 decoder.debug_check_bounds::<Self>(offset);
120 let prim = decoder.read_num::<u32>(offset);
121
122 *self = Self::from_primitive(prim).ok_or(fidl::Error::InvalidEnumValue)?;
123 Ok(())
124 }
125 }
126
127 impl SystemActivityGovernorState {
128 #[inline(always)]
129 fn max_ordinal_present(&self) -> u64 {
130 if let Some(_) = self.application_activity_level {
131 return 2;
132 }
133 if let Some(_) = self.execution_state_level {
134 return 1;
135 }
136 0
137 }
138 }
139
140 impl fidl::encoding::ValueTypeMarker for SystemActivityGovernorState {
141 type Borrowed<'a> = &'a Self;
142 fn borrow(value: &<Self as fidl::encoding::TypeMarker>::Owned) -> Self::Borrowed<'_> {
143 value
144 }
145 }
146
147 unsafe impl fidl::encoding::TypeMarker for SystemActivityGovernorState {
148 type Owned = Self;
149
150 #[inline(always)]
151 fn inline_align(_context: fidl::encoding::Context) -> usize {
152 8
153 }
154
155 #[inline(always)]
156 fn inline_size(_context: fidl::encoding::Context) -> usize {
157 16
158 }
159 }
160
161 unsafe impl<D: fidl::encoding::ResourceDialect>
162 fidl::encoding::Encode<SystemActivityGovernorState, D> for &SystemActivityGovernorState
163 {
164 unsafe fn encode(
165 self,
166 encoder: &mut fidl::encoding::Encoder<'_, D>,
167 offset: usize,
168 mut depth: fidl::encoding::Depth,
169 ) -> fidl::Result<()> {
170 encoder.debug_check_bounds::<SystemActivityGovernorState>(offset);
171 let max_ordinal: u64 = self.max_ordinal_present();
173 encoder.write_num(max_ordinal, offset);
174 encoder.write_num(fidl::encoding::ALLOC_PRESENT_U64, offset + 8);
175 if max_ordinal == 0 {
177 return Ok(());
178 }
179 depth.increment()?;
180 let envelope_size = 8;
181 let bytes_len = max_ordinal as usize * envelope_size;
182 #[allow(unused_variables)]
183 let offset = encoder.out_of_line_offset(bytes_len);
184 let mut _prev_end_offset: usize = 0;
185 if 1 > max_ordinal {
186 return Ok(());
187 }
188
189 let cur_offset: usize = (1 - 1) * envelope_size;
192
193 encoder.padding(offset + _prev_end_offset, cur_offset - _prev_end_offset);
195
196 fidl::encoding::encode_in_envelope_optional::<fidl_fuchsia_power_system::ExecutionStateLevel, D>(
201 self.execution_state_level.as_ref().map(<fidl_fuchsia_power_system::ExecutionStateLevel as fidl::encoding::ValueTypeMarker>::borrow),
202 encoder, offset + cur_offset, depth
203 )?;
204
205 _prev_end_offset = cur_offset + envelope_size;
206 if 2 > max_ordinal {
207 return Ok(());
208 }
209
210 let cur_offset: usize = (2 - 1) * envelope_size;
213
214 encoder.padding(offset + _prev_end_offset, cur_offset - _prev_end_offset);
216
217 fidl::encoding::encode_in_envelope_optional::<fidl_fuchsia_power_system::ApplicationActivityLevel, D>(
222 self.application_activity_level.as_ref().map(<fidl_fuchsia_power_system::ApplicationActivityLevel as fidl::encoding::ValueTypeMarker>::borrow),
223 encoder, offset + cur_offset, depth
224 )?;
225
226 _prev_end_offset = cur_offset + envelope_size;
227
228 Ok(())
229 }
230 }
231
232 impl<D: fidl::encoding::ResourceDialect> fidl::encoding::Decode<Self, D>
233 for SystemActivityGovernorState
234 {
235 #[inline(always)]
236 fn new_empty() -> Self {
237 Self::default()
238 }
239
240 unsafe fn decode(
241 &mut self,
242 decoder: &mut fidl::encoding::Decoder<'_, D>,
243 offset: usize,
244 mut depth: fidl::encoding::Depth,
245 ) -> fidl::Result<()> {
246 decoder.debug_check_bounds::<Self>(offset);
247 let len = match fidl::encoding::decode_vector_header(decoder, offset)? {
248 None => return Err(fidl::Error::NotNullable),
249 Some(len) => len,
250 };
251 if len == 0 {
253 return Ok(());
254 };
255 depth.increment()?;
256 let envelope_size = 8;
257 let bytes_len = len * envelope_size;
258 let offset = decoder.out_of_line_offset(bytes_len)?;
259 let mut _next_ordinal_to_read = 0;
261 let mut next_offset = offset;
262 let end_offset = offset + bytes_len;
263 _next_ordinal_to_read += 1;
264 if next_offset >= end_offset {
265 return Ok(());
266 }
267
268 while _next_ordinal_to_read < 1 {
270 fidl::encoding::decode_unknown_envelope(decoder, next_offset, depth)?;
271 _next_ordinal_to_read += 1;
272 next_offset += envelope_size;
273 }
274
275 let next_out_of_line = decoder.next_out_of_line();
276 let handles_before = decoder.remaining_handles();
277 if let Some((inlined, num_bytes, num_handles)) =
278 fidl::encoding::decode_envelope_header(decoder, next_offset)?
279 {
280 let member_inline_size = <fidl_fuchsia_power_system::ExecutionStateLevel as fidl::encoding::TypeMarker>::inline_size(decoder.context);
281 if inlined != (member_inline_size <= 4) {
282 return Err(fidl::Error::InvalidInlineBitInEnvelope);
283 }
284 let inner_offset;
285 let mut inner_depth = depth.clone();
286 if inlined {
287 decoder.check_inline_envelope_padding(next_offset, member_inline_size)?;
288 inner_offset = next_offset;
289 } else {
290 inner_offset = decoder.out_of_line_offset(member_inline_size)?;
291 inner_depth.increment()?;
292 }
293 let val_ref = self.execution_state_level.get_or_insert_with(|| {
294 fidl::new_empty!(fidl_fuchsia_power_system::ExecutionStateLevel, D)
295 });
296 fidl::decode!(
297 fidl_fuchsia_power_system::ExecutionStateLevel,
298 D,
299 val_ref,
300 decoder,
301 inner_offset,
302 inner_depth
303 )?;
304 if !inlined && decoder.next_out_of_line() != next_out_of_line + (num_bytes as usize)
305 {
306 return Err(fidl::Error::InvalidNumBytesInEnvelope);
307 }
308 if handles_before != decoder.remaining_handles() + (num_handles as usize) {
309 return Err(fidl::Error::InvalidNumHandlesInEnvelope);
310 }
311 }
312
313 next_offset += envelope_size;
314 _next_ordinal_to_read += 1;
315 if next_offset >= end_offset {
316 return Ok(());
317 }
318
319 while _next_ordinal_to_read < 2 {
321 fidl::encoding::decode_unknown_envelope(decoder, next_offset, depth)?;
322 _next_ordinal_to_read += 1;
323 next_offset += envelope_size;
324 }
325
326 let next_out_of_line = decoder.next_out_of_line();
327 let handles_before = decoder.remaining_handles();
328 if let Some((inlined, num_bytes, num_handles)) =
329 fidl::encoding::decode_envelope_header(decoder, next_offset)?
330 {
331 let member_inline_size = <fidl_fuchsia_power_system::ApplicationActivityLevel as fidl::encoding::TypeMarker>::inline_size(decoder.context);
332 if inlined != (member_inline_size <= 4) {
333 return Err(fidl::Error::InvalidInlineBitInEnvelope);
334 }
335 let inner_offset;
336 let mut inner_depth = depth.clone();
337 if inlined {
338 decoder.check_inline_envelope_padding(next_offset, member_inline_size)?;
339 inner_offset = next_offset;
340 } else {
341 inner_offset = decoder.out_of_line_offset(member_inline_size)?;
342 inner_depth.increment()?;
343 }
344 let val_ref = self.application_activity_level.get_or_insert_with(|| {
345 fidl::new_empty!(fidl_fuchsia_power_system::ApplicationActivityLevel, D)
346 });
347 fidl::decode!(
348 fidl_fuchsia_power_system::ApplicationActivityLevel,
349 D,
350 val_ref,
351 decoder,
352 inner_offset,
353 inner_depth
354 )?;
355 if !inlined && decoder.next_out_of_line() != next_out_of_line + (num_bytes as usize)
356 {
357 return Err(fidl::Error::InvalidNumBytesInEnvelope);
358 }
359 if handles_before != decoder.remaining_handles() + (num_handles as usize) {
360 return Err(fidl::Error::InvalidNumHandlesInEnvelope);
361 }
362 }
363
364 next_offset += envelope_size;
365
366 while next_offset < end_offset {
368 _next_ordinal_to_read += 1;
369 fidl::encoding::decode_unknown_envelope(decoder, next_offset, depth)?;
370 next_offset += envelope_size;
371 }
372
373 Ok(())
374 }
375 }
376}