fidl_fuchsia_camera_test_virtualcamera_common/
fidl_fuchsia_camera_test_virtualcamera_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#[derive(Copy, Clone, Debug, Eq, PartialEq, Ord, PartialOrd, Hash)]
12#[repr(u32)]
13pub enum Error {
14    AlreadyAddedToDeviceWatcher = 1,
15}
16
17impl Error {
18    #[inline]
19    pub fn from_primitive(prim: u32) -> Option<Self> {
20        match prim {
21            1 => Some(Self::AlreadyAddedToDeviceWatcher),
22            _ => None,
23        }
24    }
25
26    #[inline]
27    pub const fn into_primitive(self) -> u32 {
28        self as u32
29    }
30
31    #[deprecated = "Strict enums should not use `is_unknown`"]
32    #[inline]
33    pub fn is_unknown(&self) -> bool {
34        false
35    }
36}
37
38#[derive(Clone, Debug, PartialEq)]
39pub struct VirtualCameraDeviceAddStreamConfigRequest {
40    pub index: u64,
41    pub config: StreamConfig,
42}
43
44impl fidl::Persistable for VirtualCameraDeviceAddStreamConfigRequest {}
45
46#[derive(Clone, Debug, Default, PartialEq)]
47pub struct StreamConfig {
48    pub width: Option<u32>,
49    pub height: Option<u32>,
50    #[doc(hidden)]
51    pub __source_breaking: fidl::marker::SourceBreaking,
52}
53
54impl fidl::Persistable for StreamConfig {}
55
56mod internal {
57    use super::*;
58    unsafe impl fidl::encoding::TypeMarker for Error {
59        type Owned = Self;
60
61        #[inline(always)]
62        fn inline_align(_context: fidl::encoding::Context) -> usize {
63            std::mem::align_of::<u32>()
64        }
65
66        #[inline(always)]
67        fn inline_size(_context: fidl::encoding::Context) -> usize {
68            std::mem::size_of::<u32>()
69        }
70
71        #[inline(always)]
72        fn encode_is_copy() -> bool {
73            true
74        }
75
76        #[inline(always)]
77        fn decode_is_copy() -> bool {
78            false
79        }
80    }
81
82    impl fidl::encoding::ValueTypeMarker for Error {
83        type Borrowed<'a> = Self;
84        #[inline(always)]
85        fn borrow(value: &<Self as fidl::encoding::TypeMarker>::Owned) -> Self::Borrowed<'_> {
86            *value
87        }
88    }
89
90    unsafe impl<D: fidl::encoding::ResourceDialect> fidl::encoding::Encode<Self, D> for Error {
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> for Error {
105        #[inline(always)]
106        fn new_empty() -> Self {
107            Self::AlreadyAddedToDeviceWatcher
108        }
109
110        #[inline]
111        unsafe fn decode(
112            &mut self,
113            decoder: &mut fidl::encoding::Decoder<'_, D>,
114            offset: usize,
115            _depth: fidl::encoding::Depth,
116        ) -> fidl::Result<()> {
117            decoder.debug_check_bounds::<Self>(offset);
118            let prim = decoder.read_num::<u32>(offset);
119
120            *self = Self::from_primitive(prim).ok_or(fidl::Error::InvalidEnumValue)?;
121            Ok(())
122        }
123    }
124
125    impl fidl::encoding::ValueTypeMarker for VirtualCameraDeviceAddStreamConfigRequest {
126        type Borrowed<'a> = &'a Self;
127        fn borrow(value: &<Self as fidl::encoding::TypeMarker>::Owned) -> Self::Borrowed<'_> {
128            value
129        }
130    }
131
132    unsafe impl fidl::encoding::TypeMarker for VirtualCameraDeviceAddStreamConfigRequest {
133        type Owned = Self;
134
135        #[inline(always)]
136        fn inline_align(_context: fidl::encoding::Context) -> usize {
137            8
138        }
139
140        #[inline(always)]
141        fn inline_size(_context: fidl::encoding::Context) -> usize {
142            24
143        }
144    }
145
146    unsafe impl<D: fidl::encoding::ResourceDialect>
147        fidl::encoding::Encode<VirtualCameraDeviceAddStreamConfigRequest, D>
148        for &VirtualCameraDeviceAddStreamConfigRequest
149    {
150        #[inline]
151        unsafe fn encode(
152            self,
153            encoder: &mut fidl::encoding::Encoder<'_, D>,
154            offset: usize,
155            _depth: fidl::encoding::Depth,
156        ) -> fidl::Result<()> {
157            encoder.debug_check_bounds::<VirtualCameraDeviceAddStreamConfigRequest>(offset);
158            // Delegate to tuple encoding.
159            fidl::encoding::Encode::<VirtualCameraDeviceAddStreamConfigRequest, D>::encode(
160                (
161                    <u64 as fidl::encoding::ValueTypeMarker>::borrow(&self.index),
162                    <StreamConfig as fidl::encoding::ValueTypeMarker>::borrow(&self.config),
163                ),
164                encoder,
165                offset,
166                _depth,
167            )
168        }
169    }
170    unsafe impl<
171            D: fidl::encoding::ResourceDialect,
172            T0: fidl::encoding::Encode<u64, D>,
173            T1: fidl::encoding::Encode<StreamConfig, D>,
174        > fidl::encoding::Encode<VirtualCameraDeviceAddStreamConfigRequest, D> for (T0, T1)
175    {
176        #[inline]
177        unsafe fn encode(
178            self,
179            encoder: &mut fidl::encoding::Encoder<'_, D>,
180            offset: usize,
181            depth: fidl::encoding::Depth,
182        ) -> fidl::Result<()> {
183            encoder.debug_check_bounds::<VirtualCameraDeviceAddStreamConfigRequest>(offset);
184            // Zero out padding regions. There's no need to apply masks
185            // because the unmasked parts will be overwritten by fields.
186            // Write the fields.
187            self.0.encode(encoder, offset + 0, depth)?;
188            self.1.encode(encoder, offset + 8, depth)?;
189            Ok(())
190        }
191    }
192
193    impl<D: fidl::encoding::ResourceDialect> fidl::encoding::Decode<Self, D>
194        for VirtualCameraDeviceAddStreamConfigRequest
195    {
196        #[inline(always)]
197        fn new_empty() -> Self {
198            Self { index: fidl::new_empty!(u64, D), config: fidl::new_empty!(StreamConfig, D) }
199        }
200
201        #[inline]
202        unsafe fn decode(
203            &mut self,
204            decoder: &mut fidl::encoding::Decoder<'_, D>,
205            offset: usize,
206            _depth: fidl::encoding::Depth,
207        ) -> fidl::Result<()> {
208            decoder.debug_check_bounds::<Self>(offset);
209            // Verify that padding bytes are zero.
210            fidl::decode!(u64, D, &mut self.index, decoder, offset + 0, _depth)?;
211            fidl::decode!(StreamConfig, D, &mut self.config, decoder, offset + 8, _depth)?;
212            Ok(())
213        }
214    }
215
216    impl StreamConfig {
217        #[inline(always)]
218        fn max_ordinal_present(&self) -> u64 {
219            if let Some(_) = self.height {
220                return 2;
221            }
222            if let Some(_) = self.width {
223                return 1;
224            }
225            0
226        }
227    }
228
229    impl fidl::encoding::ValueTypeMarker for StreamConfig {
230        type Borrowed<'a> = &'a Self;
231        fn borrow(value: &<Self as fidl::encoding::TypeMarker>::Owned) -> Self::Borrowed<'_> {
232            value
233        }
234    }
235
236    unsafe impl fidl::encoding::TypeMarker for StreamConfig {
237        type Owned = Self;
238
239        #[inline(always)]
240        fn inline_align(_context: fidl::encoding::Context) -> usize {
241            8
242        }
243
244        #[inline(always)]
245        fn inline_size(_context: fidl::encoding::Context) -> usize {
246            16
247        }
248    }
249
250    unsafe impl<D: fidl::encoding::ResourceDialect> fidl::encoding::Encode<StreamConfig, D>
251        for &StreamConfig
252    {
253        unsafe fn encode(
254            self,
255            encoder: &mut fidl::encoding::Encoder<'_, D>,
256            offset: usize,
257            mut depth: fidl::encoding::Depth,
258        ) -> fidl::Result<()> {
259            encoder.debug_check_bounds::<StreamConfig>(offset);
260            // Vector header
261            let max_ordinal: u64 = self.max_ordinal_present();
262            encoder.write_num(max_ordinal, offset);
263            encoder.write_num(fidl::encoding::ALLOC_PRESENT_U64, offset + 8);
264            // Calling encoder.out_of_line_offset(0) is not allowed.
265            if max_ordinal == 0 {
266                return Ok(());
267            }
268            depth.increment()?;
269            let envelope_size = 8;
270            let bytes_len = max_ordinal as usize * envelope_size;
271            #[allow(unused_variables)]
272            let offset = encoder.out_of_line_offset(bytes_len);
273            let mut _prev_end_offset: usize = 0;
274            if 1 > max_ordinal {
275                return Ok(());
276            }
277
278            // Write at offset+(ordinal-1)*envelope_size, since ordinals are one-based and envelopes
279            // are envelope_size bytes.
280            let cur_offset: usize = (1 - 1) * envelope_size;
281
282            // Zero reserved fields.
283            encoder.padding(offset + _prev_end_offset, cur_offset - _prev_end_offset);
284
285            // Safety:
286            // - bytes_len is calculated to fit envelope_size*max(member.ordinal).
287            // - Since cur_offset is envelope_size*(member.ordinal - 1) and the envelope takes
288            //   envelope_size bytes, there is always sufficient room.
289            fidl::encoding::encode_in_envelope_optional::<u32, D>(
290                self.width.as_ref().map(<u32 as fidl::encoding::ValueTypeMarker>::borrow),
291                encoder,
292                offset + cur_offset,
293                depth,
294            )?;
295
296            _prev_end_offset = cur_offset + envelope_size;
297            if 2 > max_ordinal {
298                return Ok(());
299            }
300
301            // Write at offset+(ordinal-1)*envelope_size, since ordinals are one-based and envelopes
302            // are envelope_size bytes.
303            let cur_offset: usize = (2 - 1) * envelope_size;
304
305            // Zero reserved fields.
306            encoder.padding(offset + _prev_end_offset, cur_offset - _prev_end_offset);
307
308            // Safety:
309            // - bytes_len is calculated to fit envelope_size*max(member.ordinal).
310            // - Since cur_offset is envelope_size*(member.ordinal - 1) and the envelope takes
311            //   envelope_size bytes, there is always sufficient room.
312            fidl::encoding::encode_in_envelope_optional::<u32, D>(
313                self.height.as_ref().map(<u32 as fidl::encoding::ValueTypeMarker>::borrow),
314                encoder,
315                offset + cur_offset,
316                depth,
317            )?;
318
319            _prev_end_offset = cur_offset + envelope_size;
320
321            Ok(())
322        }
323    }
324
325    impl<D: fidl::encoding::ResourceDialect> fidl::encoding::Decode<Self, D> for StreamConfig {
326        #[inline(always)]
327        fn new_empty() -> Self {
328            Self::default()
329        }
330
331        unsafe fn decode(
332            &mut self,
333            decoder: &mut fidl::encoding::Decoder<'_, D>,
334            offset: usize,
335            mut depth: fidl::encoding::Depth,
336        ) -> fidl::Result<()> {
337            decoder.debug_check_bounds::<Self>(offset);
338            let len = match fidl::encoding::decode_vector_header(decoder, offset)? {
339                None => return Err(fidl::Error::NotNullable),
340                Some(len) => len,
341            };
342            // Calling decoder.out_of_line_offset(0) is not allowed.
343            if len == 0 {
344                return Ok(());
345            };
346            depth.increment()?;
347            let envelope_size = 8;
348            let bytes_len = len * envelope_size;
349            let offset = decoder.out_of_line_offset(bytes_len)?;
350            // Decode the envelope for each type.
351            let mut _next_ordinal_to_read = 0;
352            let mut next_offset = offset;
353            let end_offset = offset + bytes_len;
354            _next_ordinal_to_read += 1;
355            if next_offset >= end_offset {
356                return Ok(());
357            }
358
359            // Decode unknown envelopes for gaps in ordinals.
360            while _next_ordinal_to_read < 1 {
361                fidl::encoding::decode_unknown_envelope(decoder, next_offset, depth)?;
362                _next_ordinal_to_read += 1;
363                next_offset += envelope_size;
364            }
365
366            let next_out_of_line = decoder.next_out_of_line();
367            let handles_before = decoder.remaining_handles();
368            if let Some((inlined, num_bytes, num_handles)) =
369                fidl::encoding::decode_envelope_header(decoder, next_offset)?
370            {
371                let member_inline_size =
372                    <u32 as fidl::encoding::TypeMarker>::inline_size(decoder.context);
373                if inlined != (member_inline_size <= 4) {
374                    return Err(fidl::Error::InvalidInlineBitInEnvelope);
375                }
376                let inner_offset;
377                let mut inner_depth = depth.clone();
378                if inlined {
379                    decoder.check_inline_envelope_padding(next_offset, member_inline_size)?;
380                    inner_offset = next_offset;
381                } else {
382                    inner_offset = decoder.out_of_line_offset(member_inline_size)?;
383                    inner_depth.increment()?;
384                }
385                let val_ref = self.width.get_or_insert_with(|| fidl::new_empty!(u32, D));
386                fidl::decode!(u32, D, val_ref, decoder, inner_offset, inner_depth)?;
387                if !inlined && decoder.next_out_of_line() != next_out_of_line + (num_bytes as usize)
388                {
389                    return Err(fidl::Error::InvalidNumBytesInEnvelope);
390                }
391                if handles_before != decoder.remaining_handles() + (num_handles as usize) {
392                    return Err(fidl::Error::InvalidNumHandlesInEnvelope);
393                }
394            }
395
396            next_offset += envelope_size;
397            _next_ordinal_to_read += 1;
398            if next_offset >= end_offset {
399                return Ok(());
400            }
401
402            // Decode unknown envelopes for gaps in ordinals.
403            while _next_ordinal_to_read < 2 {
404                fidl::encoding::decode_unknown_envelope(decoder, next_offset, depth)?;
405                _next_ordinal_to_read += 1;
406                next_offset += envelope_size;
407            }
408
409            let next_out_of_line = decoder.next_out_of_line();
410            let handles_before = decoder.remaining_handles();
411            if let Some((inlined, num_bytes, num_handles)) =
412                fidl::encoding::decode_envelope_header(decoder, next_offset)?
413            {
414                let member_inline_size =
415                    <u32 as fidl::encoding::TypeMarker>::inline_size(decoder.context);
416                if inlined != (member_inline_size <= 4) {
417                    return Err(fidl::Error::InvalidInlineBitInEnvelope);
418                }
419                let inner_offset;
420                let mut inner_depth = depth.clone();
421                if inlined {
422                    decoder.check_inline_envelope_padding(next_offset, member_inline_size)?;
423                    inner_offset = next_offset;
424                } else {
425                    inner_offset = decoder.out_of_line_offset(member_inline_size)?;
426                    inner_depth.increment()?;
427                }
428                let val_ref = self.height.get_or_insert_with(|| fidl::new_empty!(u32, D));
429                fidl::decode!(u32, D, val_ref, decoder, inner_offset, inner_depth)?;
430                if !inlined && decoder.next_out_of_line() != next_out_of_line + (num_bytes as usize)
431                {
432                    return Err(fidl::Error::InvalidNumBytesInEnvelope);
433                }
434                if handles_before != decoder.remaining_handles() + (num_handles as usize) {
435                    return Err(fidl::Error::InvalidNumHandlesInEnvelope);
436                }
437            }
438
439            next_offset += envelope_size;
440
441            // Decode the remaining unknown envelopes.
442            while next_offset < end_offset {
443                _next_ordinal_to_read += 1;
444                fidl::encoding::decode_unknown_envelope(decoder, next_offset, depth)?;
445                next_offset += envelope_size;
446            }
447
448            Ok(())
449        }
450    }
451}